]> git.ipfire.org Git - people/ms/ipfire-3.x.git/blob - pkgs/kernel/patches/grsecurity-2.2.2-2.6.39-201105231910.patch
Change file layout of the makefiles.
[people/ms/ipfire-3.x.git] / pkgs / kernel / patches / grsecurity-2.2.2-2.6.39-201105231910.patch
1 diff -urNp linux-2.6.39/arch/alpha/include/asm/dma-mapping.h linux-2.6.39/arch/alpha/include/asm/dma-mapping.h
2 --- linux-2.6.39/arch/alpha/include/asm/dma-mapping.h 2011-05-19 00:06:34.000000000 -0400
3 +++ linux-2.6.39/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/arch/alpha/include/asm/elf.h linux-2.6.39/arch/alpha/include/asm/elf.h
17 --- linux-2.6.39/arch/alpha/include/asm/elf.h 2011-05-19 00:06:34.000000000 -0400
18 +++ linux-2.6.39/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/arch/alpha/include/asm/pgtable.h linux-2.6.39/arch/alpha/include/asm/pgtable.h
34 --- linux-2.6.39/arch/alpha/include/asm/pgtable.h 2011-05-19 00:06:34.000000000 -0400
35 +++ linux-2.6.39/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/arch/alpha/kernel/core_apecs.c linux-2.6.39/arch/alpha/kernel/core_apecs.c
55 --- linux-2.6.39/arch/alpha/kernel/core_apecs.c 2011-05-19 00:06:34.000000000 -0400
56 +++ linux-2.6.39/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/arch/alpha/kernel/core_cia.c linux-2.6.39/arch/alpha/kernel/core_cia.c
67 --- linux-2.6.39/arch/alpha/kernel/core_cia.c 2011-05-19 00:06:34.000000000 -0400
68 +++ linux-2.6.39/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/arch/alpha/kernel/core_irongate.c linux-2.6.39/arch/alpha/kernel/core_irongate.c
79 --- linux-2.6.39/arch/alpha/kernel/core_irongate.c 2011-05-19 00:06:34.000000000 -0400
80 +++ linux-2.6.39/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/arch/alpha/kernel/core_lca.c linux-2.6.39/arch/alpha/kernel/core_lca.c
91 --- linux-2.6.39/arch/alpha/kernel/core_lca.c 2011-05-19 00:06:34.000000000 -0400
92 +++ linux-2.6.39/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/arch/alpha/kernel/core_marvel.c linux-2.6.39/arch/alpha/kernel/core_marvel.c
103 --- linux-2.6.39/arch/alpha/kernel/core_marvel.c 2011-05-19 00:06:34.000000000 -0400
104 +++ linux-2.6.39/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/arch/alpha/kernel/core_mcpcia.c linux-2.6.39/arch/alpha/kernel/core_mcpcia.c
115 --- linux-2.6.39/arch/alpha/kernel/core_mcpcia.c 2011-05-19 00:06:34.000000000 -0400
116 +++ linux-2.6.39/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/arch/alpha/kernel/core_polaris.c linux-2.6.39/arch/alpha/kernel/core_polaris.c
127 --- linux-2.6.39/arch/alpha/kernel/core_polaris.c 2011-05-19 00:06:34.000000000 -0400
128 +++ linux-2.6.39/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/arch/alpha/kernel/core_t2.c linux-2.6.39/arch/alpha/kernel/core_t2.c
139 --- linux-2.6.39/arch/alpha/kernel/core_t2.c 2011-05-19 00:06:34.000000000 -0400
140 +++ linux-2.6.39/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/arch/alpha/kernel/core_titan.c linux-2.6.39/arch/alpha/kernel/core_titan.c
151 --- linux-2.6.39/arch/alpha/kernel/core_titan.c 2011-05-19 00:06:34.000000000 -0400
152 +++ linux-2.6.39/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/arch/alpha/kernel/core_tsunami.c linux-2.6.39/arch/alpha/kernel/core_tsunami.c
163 --- linux-2.6.39/arch/alpha/kernel/core_tsunami.c 2011-05-19 00:06:34.000000000 -0400
164 +++ linux-2.6.39/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/arch/alpha/kernel/core_wildfire.c linux-2.6.39/arch/alpha/kernel/core_wildfire.c
175 --- linux-2.6.39/arch/alpha/kernel/core_wildfire.c 2011-05-19 00:06:34.000000000 -0400
176 +++ linux-2.6.39/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/arch/alpha/kernel/module.c linux-2.6.39/arch/alpha/kernel/module.c
187 --- linux-2.6.39/arch/alpha/kernel/module.c 2011-05-19 00:06:34.000000000 -0400
188 +++ linux-2.6.39/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/arch/alpha/kernel/osf_sys.c linux-2.6.39/arch/alpha/kernel/osf_sys.c
199 --- linux-2.6.39/arch/alpha/kernel/osf_sys.c 2011-05-19 00:06:34.000000000 -0400
200 +++ linux-2.6.39/arch/alpha/kernel/osf_sys.c 2011-05-22 19:36:30.000000000 -0400
201 @@ -1142,7 +1142,7 @@ arch_get_unmapped_area_1(unsigned long a
202 /* At this point: (!vma || addr < vma->vm_end). */
203 if (limit - len < addr)
204 return -ENOMEM;
205 - if (!vma || addr + len <= vma->vm_start)
206 + if (check_heap_stack_gap(vma, addr, len))
207 return addr;
208 addr = vma->vm_end;
209 vma = vma->vm_next;
210 @@ -1178,6 +1178,10 @@ arch_get_unmapped_area(struct file *filp
211 merely specific addresses, but regions of memory -- perhaps
212 this feature should be incorporated into all ports? */
213
214 +#ifdef CONFIG_PAX_RANDMMAP
215 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
216 +#endif
217 +
218 if (addr) {
219 addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
220 if (addr != (unsigned long) -ENOMEM)
221 @@ -1185,8 +1189,8 @@ arch_get_unmapped_area(struct file *filp
222 }
223
224 /* Next, try allocating at TASK_UNMAPPED_BASE. */
225 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
226 - len, limit);
227 + addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
228 +
229 if (addr != (unsigned long) -ENOMEM)
230 return addr;
231
232 diff -urNp linux-2.6.39/arch/alpha/kernel/pci_iommu.c linux-2.6.39/arch/alpha/kernel/pci_iommu.c
233 --- linux-2.6.39/arch/alpha/kernel/pci_iommu.c 2011-05-19 00:06:34.000000000 -0400
234 +++ linux-2.6.39/arch/alpha/kernel/pci_iommu.c 2011-05-22 19:36:30.000000000 -0400
235 @@ -950,7 +950,7 @@ static int alpha_pci_set_mask(struct dev
236 return 0;
237 }
238
239 -struct dma_map_ops alpha_pci_ops = {
240 +const struct dma_map_ops alpha_pci_ops = {
241 .alloc_coherent = alpha_pci_alloc_coherent,
242 .free_coherent = alpha_pci_free_coherent,
243 .map_page = alpha_pci_map_page,
244 @@ -962,5 +962,5 @@ struct dma_map_ops alpha_pci_ops = {
245 .set_dma_mask = alpha_pci_set_mask,
246 };
247
248 -struct dma_map_ops *dma_ops = &alpha_pci_ops;
249 +const struct dma_map_ops *dma_ops = &alpha_pci_ops;
250 EXPORT_SYMBOL(dma_ops);
251 diff -urNp linux-2.6.39/arch/alpha/kernel/pci-noop.c linux-2.6.39/arch/alpha/kernel/pci-noop.c
252 --- linux-2.6.39/arch/alpha/kernel/pci-noop.c 2011-05-19 00:06:34.000000000 -0400
253 +++ linux-2.6.39/arch/alpha/kernel/pci-noop.c 2011-05-22 19:36:30.000000000 -0400
254 @@ -173,7 +173,7 @@ static int alpha_noop_set_mask(struct de
255 return 0;
256 }
257
258 -struct dma_map_ops alpha_noop_ops = {
259 +const struct dma_map_ops alpha_noop_ops = {
260 .alloc_coherent = alpha_noop_alloc_coherent,
261 .free_coherent = alpha_noop_free_coherent,
262 .map_page = alpha_noop_map_page,
263 @@ -183,7 +183,7 @@ struct dma_map_ops alpha_noop_ops = {
264 .set_dma_mask = alpha_noop_set_mask,
265 };
266
267 -struct dma_map_ops *dma_ops = &alpha_noop_ops;
268 +const struct dma_map_ops *dma_ops = &alpha_noop_ops;
269 EXPORT_SYMBOL(dma_ops);
270
271 void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
272 diff -urNp linux-2.6.39/arch/alpha/kernel/proto.h linux-2.6.39/arch/alpha/kernel/proto.h
273 --- linux-2.6.39/arch/alpha/kernel/proto.h 2011-05-19 00:06:34.000000000 -0400
274 +++ linux-2.6.39/arch/alpha/kernel/proto.h 2011-05-22 19:36:30.000000000 -0400
275 @@ -17,14 +17,14 @@ struct pci_dev;
276 struct pci_controller;
277
278 /* core_apecs.c */
279 -extern struct pci_ops apecs_pci_ops;
280 +extern const struct pci_ops apecs_pci_ops;
281 extern void apecs_init_arch(void);
282 extern void apecs_pci_clr_err(void);
283 extern void apecs_machine_check(unsigned long vector, unsigned long la_ptr);
284 extern void apecs_pci_tbi(struct pci_controller *, dma_addr_t, dma_addr_t);
285
286 /* core_cia.c */
287 -extern struct pci_ops cia_pci_ops;
288 +extern const struct pci_ops cia_pci_ops;
289 extern void cia_init_pci(void);
290 extern void cia_init_arch(void);
291 extern void pyxis_init_arch(void);
292 @@ -33,19 +33,19 @@ extern void cia_machine_check(unsigned l
293 extern void cia_pci_tbi(struct pci_controller *, dma_addr_t, dma_addr_t);
294
295 /* core_irongate.c */
296 -extern struct pci_ops irongate_pci_ops;
297 +extern const struct pci_ops irongate_pci_ops;
298 extern int irongate_pci_clr_err(void);
299 extern void irongate_init_arch(void);
300 #define irongate_pci_tbi ((void *)0)
301
302 /* core_lca.c */
303 -extern struct pci_ops lca_pci_ops;
304 +extern const struct pci_ops lca_pci_ops;
305 extern void lca_init_arch(void);
306 extern void lca_machine_check(unsigned long vector, unsigned long la_ptr);
307 extern void lca_pci_tbi(struct pci_controller *, dma_addr_t, dma_addr_t);
308
309 /* core_marvel.c */
310 -extern struct pci_ops marvel_pci_ops;
311 +extern const struct pci_ops marvel_pci_ops;
312 extern void marvel_init_arch(void);
313 extern void marvel_kill_arch(int);
314 extern void marvel_machine_check(unsigned long, unsigned long);
315 @@ -60,14 +60,14 @@ struct io7 *marvel_next_io7(struct io7 *
316 void io7_clear_errors(struct io7 *io7);
317
318 /* core_mcpcia.c */
319 -extern struct pci_ops mcpcia_pci_ops;
320 +extern const struct pci_ops mcpcia_pci_ops;
321 extern void mcpcia_init_arch(void);
322 extern void mcpcia_init_hoses(void);
323 extern void mcpcia_machine_check(unsigned long vector, unsigned long la_ptr);
324 extern void mcpcia_pci_tbi(struct pci_controller *, dma_addr_t, dma_addr_t);
325
326 /* core_polaris.c */
327 -extern struct pci_ops polaris_pci_ops;
328 +extern const struct pci_ops polaris_pci_ops;
329 extern int polaris_read_config_dword(struct pci_dev *, int, u32 *);
330 extern int polaris_write_config_dword(struct pci_dev *, int, u32);
331 extern void polaris_init_arch(void);
332 @@ -75,14 +75,14 @@ extern void polaris_machine_check(unsign
333 #define polaris_pci_tbi ((void *)0)
334
335 /* core_t2.c */
336 -extern struct pci_ops t2_pci_ops;
337 +extern const struct pci_ops t2_pci_ops;
338 extern void t2_init_arch(void);
339 extern void t2_kill_arch(int);
340 extern void t2_machine_check(unsigned long vector, unsigned long la_ptr);
341 extern void t2_pci_tbi(struct pci_controller *, dma_addr_t, dma_addr_t);
342
343 /* core_titan.c */
344 -extern struct pci_ops titan_pci_ops;
345 +extern const struct pci_ops titan_pci_ops;
346 extern void titan_init_arch(void);
347 extern void titan_kill_arch(int);
348 extern void titan_machine_check(unsigned long, unsigned long);
349 @@ -90,14 +90,14 @@ extern void titan_pci_tbi(struct pci_con
350 extern struct _alpha_agp_info *titan_agp_info(void);
351
352 /* core_tsunami.c */
353 -extern struct pci_ops tsunami_pci_ops;
354 +extern const struct pci_ops tsunami_pci_ops;
355 extern void tsunami_init_arch(void);
356 extern void tsunami_kill_arch(int);
357 extern void tsunami_machine_check(unsigned long vector, unsigned long la_ptr);
358 extern void tsunami_pci_tbi(struct pci_controller *, dma_addr_t, dma_addr_t);
359
360 /* core_wildfire.c */
361 -extern struct pci_ops wildfire_pci_ops;
362 +extern const struct pci_ops wildfire_pci_ops;
363 extern void wildfire_init_arch(void);
364 extern void wildfire_kill_arch(int);
365 extern void wildfire_machine_check(unsigned long vector, unsigned long la_ptr);
366 diff -urNp linux-2.6.39/arch/alpha/mm/fault.c linux-2.6.39/arch/alpha/mm/fault.c
367 --- linux-2.6.39/arch/alpha/mm/fault.c 2011-05-19 00:06:34.000000000 -0400
368 +++ linux-2.6.39/arch/alpha/mm/fault.c 2011-05-22 19:36:30.000000000 -0400
369 @@ -54,6 +54,124 @@ __load_new_mm_context(struct mm_struct *
370 __reload_thread(pcb);
371 }
372
373 +#ifdef CONFIG_PAX_PAGEEXEC
374 +/*
375 + * PaX: decide what to do with offenders (regs->pc = fault address)
376 + *
377 + * returns 1 when task should be killed
378 + * 2 when patched PLT trampoline was detected
379 + * 3 when unpatched PLT trampoline was detected
380 + */
381 +static int pax_handle_fetch_fault(struct pt_regs *regs)
382 +{
383 +
384 +#ifdef CONFIG_PAX_EMUPLT
385 + int err;
386 +
387 + do { /* PaX: patched PLT emulation #1 */
388 + unsigned int ldah, ldq, jmp;
389 +
390 + err = get_user(ldah, (unsigned int *)regs->pc);
391 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
392 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
393 +
394 + if (err)
395 + break;
396 +
397 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
398 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
399 + jmp == 0x6BFB0000U)
400 + {
401 + unsigned long r27, addr;
402 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
403 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
404 +
405 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
406 + err = get_user(r27, (unsigned long *)addr);
407 + if (err)
408 + break;
409 +
410 + regs->r27 = r27;
411 + regs->pc = r27;
412 + return 2;
413 + }
414 + } while (0);
415 +
416 + do { /* PaX: patched PLT emulation #2 */
417 + unsigned int ldah, lda, br;
418 +
419 + err = get_user(ldah, (unsigned int *)regs->pc);
420 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
421 + err |= get_user(br, (unsigned int *)(regs->pc+8));
422 +
423 + if (err)
424 + break;
425 +
426 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
427 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
428 + (br & 0xFFE00000U) == 0xC3E00000U)
429 + {
430 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
431 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
432 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
433 +
434 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
435 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
436 + return 2;
437 + }
438 + } while (0);
439 +
440 + do { /* PaX: unpatched PLT emulation */
441 + unsigned int br;
442 +
443 + err = get_user(br, (unsigned int *)regs->pc);
444 +
445 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
446 + unsigned int br2, ldq, nop, jmp;
447 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
448 +
449 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
450 + err = get_user(br2, (unsigned int *)addr);
451 + err |= get_user(ldq, (unsigned int *)(addr+4));
452 + err |= get_user(nop, (unsigned int *)(addr+8));
453 + err |= get_user(jmp, (unsigned int *)(addr+12));
454 + err |= get_user(resolver, (unsigned long *)(addr+16));
455 +
456 + if (err)
457 + break;
458 +
459 + if (br2 == 0xC3600000U &&
460 + ldq == 0xA77B000CU &&
461 + nop == 0x47FF041FU &&
462 + jmp == 0x6B7B0000U)
463 + {
464 + regs->r28 = regs->pc+4;
465 + regs->r27 = addr+16;
466 + regs->pc = resolver;
467 + return 3;
468 + }
469 + }
470 + } while (0);
471 +#endif
472 +
473 + return 1;
474 +}
475 +
476 +void pax_report_insns(void *pc, void *sp)
477 +{
478 + unsigned long i;
479 +
480 + printk(KERN_ERR "PAX: bytes at PC: ");
481 + for (i = 0; i < 5; i++) {
482 + unsigned int c;
483 + if (get_user(c, (unsigned int *)pc+i))
484 + printk(KERN_CONT "???????? ");
485 + else
486 + printk(KERN_CONT "%08x ", c);
487 + }
488 + printk("\n");
489 +}
490 +#endif
491
492 /*
493 * This routine handles page faults. It determines the address,
494 @@ -131,8 +249,29 @@ do_page_fault(unsigned long address, uns
495 good_area:
496 si_code = SEGV_ACCERR;
497 if (cause < 0) {
498 - if (!(vma->vm_flags & VM_EXEC))
499 + if (!(vma->vm_flags & VM_EXEC)) {
500 +
501 +#ifdef CONFIG_PAX_PAGEEXEC
502 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
503 + goto bad_area;
504 +
505 + up_read(&mm->mmap_sem);
506 + switch (pax_handle_fetch_fault(regs)) {
507 +
508 +#ifdef CONFIG_PAX_EMUPLT
509 + case 2:
510 + case 3:
511 + return;
512 +#endif
513 +
514 + }
515 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
516 + do_group_exit(SIGKILL);
517 +#else
518 goto bad_area;
519 +#endif
520 +
521 + }
522 } else if (!cause) {
523 /* Allow reads even for write-only mappings */
524 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
525 diff -urNp linux-2.6.39/arch/arm/common/it8152.c linux-2.6.39/arch/arm/common/it8152.c
526 --- linux-2.6.39/arch/arm/common/it8152.c 2011-05-19 00:06:34.000000000 -0400
527 +++ linux-2.6.39/arch/arm/common/it8152.c 2011-05-22 19:36:30.000000000 -0400
528 @@ -221,7 +221,7 @@ static int it8152_pci_write_config(struc
529 return PCIBIOS_SUCCESSFUL;
530 }
531
532 -static struct pci_ops it8152_ops = {
533 +static const struct pci_ops it8152_ops = {
534 .read = it8152_pci_read_config,
535 .write = it8152_pci_write_config,
536 };
537 diff -urNp linux-2.6.39/arch/arm/common/via82c505.c linux-2.6.39/arch/arm/common/via82c505.c
538 --- linux-2.6.39/arch/arm/common/via82c505.c 2011-05-19 00:06:34.000000000 -0400
539 +++ linux-2.6.39/arch/arm/common/via82c505.c 2011-05-22 19:36:30.000000000 -0400
540 @@ -52,7 +52,7 @@ via82c505_write_config(struct pci_bus *b
541 return PCIBIOS_SUCCESSFUL;
542 }
543
544 -static struct pci_ops via82c505_ops = {
545 +static const struct pci_ops via82c505_ops = {
546 .read = via82c505_read_config,
547 .write = via82c505_write_config,
548 };
549 diff -urNp linux-2.6.39/arch/arm/include/asm/cacheflush.h linux-2.6.39/arch/arm/include/asm/cacheflush.h
550 --- linux-2.6.39/arch/arm/include/asm/cacheflush.h 2011-05-19 00:06:34.000000000 -0400
551 +++ linux-2.6.39/arch/arm/include/asm/cacheflush.h 2011-05-22 19:36:30.000000000 -0400
552 @@ -115,7 +115,7 @@ struct cpu_cache_fns {
553 */
554 #ifdef MULTI_CACHE
555
556 -extern struct cpu_cache_fns cpu_cache;
557 +extern const struct cpu_cache_fns cpu_cache;
558
559 #define __cpuc_flush_icache_all cpu_cache.flush_icache_all
560 #define __cpuc_flush_kern_all cpu_cache.flush_kern_all
561 diff -urNp linux-2.6.39/arch/arm/include/asm/elf.h linux-2.6.39/arch/arm/include/asm/elf.h
562 --- linux-2.6.39/arch/arm/include/asm/elf.h 2011-05-19 00:06:34.000000000 -0400
563 +++ linux-2.6.39/arch/arm/include/asm/elf.h 2011-05-22 19:36:30.000000000 -0400
564 @@ -115,7 +115,14 @@ int dump_task_regs(struct task_struct *t
565 the loader. We need to make sure that it is out of the way of the program
566 that it will "exec", and that there is sufficient room for the brk. */
567
568 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
569 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
570 +
571 +#ifdef CONFIG_PAX_ASLR
572 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
573 +
574 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
575 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
576 +#endif
577
578 /* When the program starts, a1 contains a pointer to a function to be
579 registered with atexit, as per the SVR4 ABI. A value of 0 means we
580 @@ -125,10 +132,6 @@ int dump_task_regs(struct task_struct *t
581 extern void elf_set_personality(const struct elf32_hdr *);
582 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
583
584 -struct mm_struct;
585 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
586 -#define arch_randomize_brk arch_randomize_brk
587 -
588 extern int vectors_user_mapping(void);
589 #define arch_setup_additional_pages(bprm, uses_interp) vectors_user_mapping()
590 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES
591 diff -urNp linux-2.6.39/arch/arm/include/asm/kmap_types.h linux-2.6.39/arch/arm/include/asm/kmap_types.h
592 --- linux-2.6.39/arch/arm/include/asm/kmap_types.h 2011-05-19 00:06:34.000000000 -0400
593 +++ linux-2.6.39/arch/arm/include/asm/kmap_types.h 2011-05-22 19:36:30.000000000 -0400
594 @@ -21,6 +21,7 @@ enum km_type {
595 KM_L1_CACHE,
596 KM_L2_CACHE,
597 KM_KDB,
598 + KM_CLEARPAGE,
599 KM_TYPE_NR
600 };
601
602 diff -urNp linux-2.6.39/arch/arm/include/asm/outercache.h linux-2.6.39/arch/arm/include/asm/outercache.h
603 --- linux-2.6.39/arch/arm/include/asm/outercache.h 2011-05-19 00:06:34.000000000 -0400
604 +++ linux-2.6.39/arch/arm/include/asm/outercache.h 2011-05-22 19:36:30.000000000 -0400
605 @@ -38,7 +38,7 @@ struct outer_cache_fns {
606
607 #ifdef CONFIG_OUTER_CACHE
608
609 -extern struct outer_cache_fns outer_cache;
610 +extern const struct outer_cache_fns outer_cache;
611
612 static inline void outer_inv_range(phys_addr_t start, phys_addr_t end)
613 {
614 diff -urNp linux-2.6.39/arch/arm/include/asm/page.h linux-2.6.39/arch/arm/include/asm/page.h
615 --- linux-2.6.39/arch/arm/include/asm/page.h 2011-05-19 00:06:34.000000000 -0400
616 +++ linux-2.6.39/arch/arm/include/asm/page.h 2011-05-22 19:36:30.000000000 -0400
617 @@ -126,7 +126,7 @@ struct cpu_user_fns {
618 };
619
620 #ifdef MULTI_USER
621 -extern struct cpu_user_fns cpu_user;
622 +extern const struct cpu_user_fns cpu_user;
623
624 #define __cpu_clear_user_highpage cpu_user.cpu_clear_user_highpage
625 #define __cpu_copy_user_highpage cpu_user.cpu_copy_user_highpage
626 diff -urNp linux-2.6.39/arch/arm/include/asm/uaccess.h linux-2.6.39/arch/arm/include/asm/uaccess.h
627 --- linux-2.6.39/arch/arm/include/asm/uaccess.h 2011-05-19 00:06:34.000000000 -0400
628 +++ linux-2.6.39/arch/arm/include/asm/uaccess.h 2011-05-22 19:36:30.000000000 -0400
629 @@ -403,6 +403,9 @@ extern unsigned long __must_check __strn
630
631 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
632 {
633 + if ((long)n < 0)
634 + return n;
635 +
636 if (access_ok(VERIFY_READ, from, n))
637 n = __copy_from_user(to, from, n);
638 else /* security hole - plug it */
639 @@ -412,6 +415,9 @@ static inline unsigned long __must_check
640
641 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
642 {
643 + if ((long)n < 0)
644 + return n;
645 +
646 if (access_ok(VERIFY_WRITE, to, n))
647 n = __copy_to_user(to, from, n);
648 return n;
649 diff -urNp linux-2.6.39/arch/arm/kernel/kgdb.c linux-2.6.39/arch/arm/kernel/kgdb.c
650 --- linux-2.6.39/arch/arm/kernel/kgdb.c 2011-05-19 00:06:34.000000000 -0400
651 +++ linux-2.6.39/arch/arm/kernel/kgdb.c 2011-05-22 19:36:30.000000000 -0400
652 @@ -246,7 +246,7 @@ void kgdb_arch_exit(void)
653 * and we handle the normal undef case within the do_undefinstr
654 * handler.
655 */
656 -struct kgdb_arch arch_kgdb_ops = {
657 +const struct kgdb_arch arch_kgdb_ops = {
658 #ifndef __ARMEB__
659 .gdb_bpt_instr = {0xfe, 0xde, 0xff, 0xe7}
660 #else /* ! __ARMEB__ */
661 diff -urNp linux-2.6.39/arch/arm/kernel/process.c linux-2.6.39/arch/arm/kernel/process.c
662 --- linux-2.6.39/arch/arm/kernel/process.c 2011-05-19 00:06:34.000000000 -0400
663 +++ linux-2.6.39/arch/arm/kernel/process.c 2011-05-22 19:36:30.000000000 -0400
664 @@ -28,7 +28,6 @@
665 #include <linux/tick.h>
666 #include <linux/utsname.h>
667 #include <linux/uaccess.h>
668 -#include <linux/random.h>
669 #include <linux/hw_breakpoint.h>
670
671 #include <asm/cacheflush.h>
672 @@ -479,12 +478,6 @@ unsigned long get_wchan(struct task_stru
673 return 0;
674 }
675
676 -unsigned long arch_randomize_brk(struct mm_struct *mm)
677 -{
678 - unsigned long range_end = mm->brk + 0x02000000;
679 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
680 -}
681 -
682 #ifdef CONFIG_MMU
683 /*
684 * The vectors page is always readable from user space for the
685 diff -urNp linux-2.6.39/arch/arm/mach-cns3xxx/pcie.c linux-2.6.39/arch/arm/mach-cns3xxx/pcie.c
686 --- linux-2.6.39/arch/arm/mach-cns3xxx/pcie.c 2011-05-19 00:06:34.000000000 -0400
687 +++ linux-2.6.39/arch/arm/mach-cns3xxx/pcie.c 2011-05-22 19:36:30.000000000 -0400
688 @@ -162,7 +162,7 @@ static int cns3xxx_pci_setup(int nr, str
689 return 1;
690 }
691
692 -static struct pci_ops cns3xxx_pcie_ops = {
693 +static const struct pci_ops cns3xxx_pcie_ops = {
694 .read = cns3xxx_pci_read_config,
695 .write = cns3xxx_pci_write_config,
696 };
697 diff -urNp linux-2.6.39/arch/arm/mach-dove/pcie.c linux-2.6.39/arch/arm/mach-dove/pcie.c
698 --- linux-2.6.39/arch/arm/mach-dove/pcie.c 2011-05-19 00:06:34.000000000 -0400
699 +++ linux-2.6.39/arch/arm/mach-dove/pcie.c 2011-05-22 19:36:30.000000000 -0400
700 @@ -155,7 +155,7 @@ static int pcie_wr_conf(struct pci_bus *
701 return ret;
702 }
703
704 -static struct pci_ops pcie_ops = {
705 +static const struct pci_ops pcie_ops = {
706 .read = pcie_rd_conf,
707 .write = pcie_wr_conf,
708 };
709 diff -urNp linux-2.6.39/arch/arm/mach-footbridge/dc21285.c linux-2.6.39/arch/arm/mach-footbridge/dc21285.c
710 --- linux-2.6.39/arch/arm/mach-footbridge/dc21285.c 2011-05-19 00:06:34.000000000 -0400
711 +++ linux-2.6.39/arch/arm/mach-footbridge/dc21285.c 2011-05-22 19:36:30.000000000 -0400
712 @@ -129,7 +129,7 @@ dc21285_write_config(struct pci_bus *bus
713 return PCIBIOS_SUCCESSFUL;
714 }
715
716 -static struct pci_ops dc21285_ops = {
717 +static const struct pci_ops dc21285_ops = {
718 .read = dc21285_read_config,
719 .write = dc21285_write_config,
720 };
721 diff -urNp linux-2.6.39/arch/arm/mach-integrator/pci_v3.c linux-2.6.39/arch/arm/mach-integrator/pci_v3.c
722 --- linux-2.6.39/arch/arm/mach-integrator/pci_v3.c 2011-05-19 00:06:34.000000000 -0400
723 +++ linux-2.6.39/arch/arm/mach-integrator/pci_v3.c 2011-05-22 19:36:30.000000000 -0400
724 @@ -340,7 +340,7 @@ static int v3_write_config(struct pci_bu
725 return PCIBIOS_SUCCESSFUL;
726 }
727
728 -static struct pci_ops pci_v3_ops = {
729 +static const struct pci_ops pci_v3_ops = {
730 .read = v3_read_config,
731 .write = v3_write_config,
732 };
733 diff -urNp linux-2.6.39/arch/arm/mach-iop13xx/pci.c linux-2.6.39/arch/arm/mach-iop13xx/pci.c
734 --- linux-2.6.39/arch/arm/mach-iop13xx/pci.c 2011-05-19 00:06:34.000000000 -0400
735 +++ linux-2.6.39/arch/arm/mach-iop13xx/pci.c 2011-05-22 19:36:30.000000000 -0400
736 @@ -324,7 +324,7 @@ iop13xx_atux_write_config(struct pci_bus
737 return PCIBIOS_SUCCESSFUL;
738 }
739
740 -static struct pci_ops iop13xx_atux_ops = {
741 +static const struct pci_ops iop13xx_atux_ops = {
742 .read = iop13xx_atux_read_config,
743 .write = iop13xx_atux_write_config,
744 };
745 @@ -471,7 +471,7 @@ iop13xx_atue_write_config(struct pci_bus
746 return PCIBIOS_SUCCESSFUL;
747 }
748
749 -static struct pci_ops iop13xx_atue_ops = {
750 +static const struct pci_ops iop13xx_atue_ops = {
751 .read = iop13xx_atue_read_config,
752 .write = iop13xx_atue_write_config,
753 };
754 diff -urNp linux-2.6.39/arch/arm/mach-ixp2000/enp2611.c linux-2.6.39/arch/arm/mach-ixp2000/enp2611.c
755 --- linux-2.6.39/arch/arm/mach-ixp2000/enp2611.c 2011-05-19 00:06:34.000000000 -0400
756 +++ linux-2.6.39/arch/arm/mach-ixp2000/enp2611.c 2011-05-22 19:36:30.000000000 -0400
757 @@ -137,7 +137,7 @@ static int enp2611_pci_write_config(stru
758 return PCIBIOS_DEVICE_NOT_FOUND;
759 }
760
761 -static struct pci_ops enp2611_pci_ops = {
762 +static const struct pci_ops enp2611_pci_ops = {
763 .read = enp2611_pci_read_config,
764 .write = enp2611_pci_write_config
765 };
766 diff -urNp linux-2.6.39/arch/arm/mach-ixp2000/pci.c linux-2.6.39/arch/arm/mach-ixp2000/pci.c
767 --- linux-2.6.39/arch/arm/mach-ixp2000/pci.c 2011-05-19 00:06:34.000000000 -0400
768 +++ linux-2.6.39/arch/arm/mach-ixp2000/pci.c 2011-05-22 19:36:30.000000000 -0400
769 @@ -125,7 +125,7 @@ int ixp2000_pci_write_config(struct pci_
770 }
771
772
773 -static struct pci_ops ixp2000_pci_ops = {
774 +static const struct pci_ops ixp2000_pci_ops = {
775 .read = ixp2000_pci_read_config,
776 .write = ixp2000_pci_write_config
777 };
778 diff -urNp linux-2.6.39/arch/arm/mach-ixp23xx/pci.c linux-2.6.39/arch/arm/mach-ixp23xx/pci.c
779 --- linux-2.6.39/arch/arm/mach-ixp23xx/pci.c 2011-05-19 00:06:34.000000000 -0400
780 +++ linux-2.6.39/arch/arm/mach-ixp23xx/pci.c 2011-05-22 19:36:30.000000000 -0400
781 @@ -136,7 +136,7 @@ static int ixp23xx_pci_write_config(stru
782 return PCIBIOS_SUCCESSFUL;
783 }
784
785 -struct pci_ops ixp23xx_pci_ops = {
786 +const struct pci_ops ixp23xx_pci_ops = {
787 .read = ixp23xx_pci_read_config,
788 .write = ixp23xx_pci_write_config,
789 };
790 diff -urNp linux-2.6.39/arch/arm/mach-ixp4xx/common-pci.c linux-2.6.39/arch/arm/mach-ixp4xx/common-pci.c
791 --- linux-2.6.39/arch/arm/mach-ixp4xx/common-pci.c 2011-05-19 00:06:34.000000000 -0400
792 +++ linux-2.6.39/arch/arm/mach-ixp4xx/common-pci.c 2011-05-22 19:36:30.000000000 -0400
793 @@ -283,7 +283,7 @@ static int ixp4xx_pci_write_config(struc
794 return PCIBIOS_SUCCESSFUL;
795 }
796
797 -struct pci_ops ixp4xx_ops = {
798 +const struct pci_ops ixp4xx_ops = {
799 .read = ixp4xx_pci_read_config,
800 .write = ixp4xx_pci_write_config,
801 };
802 diff -urNp linux-2.6.39/arch/arm/mach-kirkwood/pcie.c linux-2.6.39/arch/arm/mach-kirkwood/pcie.c
803 --- linux-2.6.39/arch/arm/mach-kirkwood/pcie.c 2011-05-19 00:06:34.000000000 -0400
804 +++ linux-2.6.39/arch/arm/mach-kirkwood/pcie.c 2011-05-22 19:36:30.000000000 -0400
805 @@ -111,7 +111,7 @@ static int pcie_wr_conf(struct pci_bus *
806 return ret;
807 }
808
809 -static struct pci_ops pcie_ops = {
810 +static const struct pci_ops pcie_ops = {
811 .read = pcie_rd_conf,
812 .write = pcie_wr_conf,
813 };
814 diff -urNp linux-2.6.39/arch/arm/mach-ks8695/pci.c linux-2.6.39/arch/arm/mach-ks8695/pci.c
815 --- linux-2.6.39/arch/arm/mach-ks8695/pci.c 2011-05-19 00:06:34.000000000 -0400
816 +++ linux-2.6.39/arch/arm/mach-ks8695/pci.c 2011-05-22 19:36:30.000000000 -0400
817 @@ -136,7 +136,7 @@ static void ks8695_local_writeconfig(int
818 __raw_writel(value, KS8695_PCI_VA + KS8695_PBCD);
819 }
820
821 -static struct pci_ops ks8695_pci_ops = {
822 +static const struct pci_ops ks8695_pci_ops = {
823 .read = ks8695_pci_readconfig,
824 .write = ks8695_pci_writeconfig,
825 };
826 diff -urNp linux-2.6.39/arch/arm/mach-mmp/clock.c linux-2.6.39/arch/arm/mach-mmp/clock.c
827 --- linux-2.6.39/arch/arm/mach-mmp/clock.c 2011-05-19 00:06:34.000000000 -0400
828 +++ linux-2.6.39/arch/arm/mach-mmp/clock.c 2011-05-22 19:36:30.000000000 -0400
829 @@ -29,7 +29,7 @@ static void apbc_clk_disable(struct clk
830 __raw_writel(0, clk->clk_rst);
831 }
832
833 -struct clkops apbc_clk_ops = {
834 +const struct clkops apbc_clk_ops = {
835 .enable = apbc_clk_enable,
836 .disable = apbc_clk_disable,
837 };
838 @@ -44,7 +44,7 @@ static void apmu_clk_disable(struct clk
839 __raw_writel(0, clk->clk_rst);
840 }
841
842 -struct clkops apmu_clk_ops = {
843 +const struct clkops apmu_clk_ops = {
844 .enable = apmu_clk_enable,
845 .disable = apmu_clk_disable,
846 };
847 diff -urNp linux-2.6.39/arch/arm/mach-msm/iommu.c linux-2.6.39/arch/arm/mach-msm/iommu.c
848 --- linux-2.6.39/arch/arm/mach-msm/iommu.c 2011-05-19 00:06:34.000000000 -0400
849 +++ linux-2.6.39/arch/arm/mach-msm/iommu.c 2011-05-22 19:36:30.000000000 -0400
850 @@ -669,7 +669,7 @@ fail:
851 return 0;
852 }
853
854 -static struct iommu_ops msm_iommu_ops = {
855 +static const struct iommu_ops msm_iommu_ops = {
856 .domain_init = msm_iommu_domain_init,
857 .domain_destroy = msm_iommu_domain_destroy,
858 .attach_dev = msm_iommu_attach_dev,
859 diff -urNp linux-2.6.39/arch/arm/mach-msm/last_radio_log.c linux-2.6.39/arch/arm/mach-msm/last_radio_log.c
860 --- linux-2.6.39/arch/arm/mach-msm/last_radio_log.c 2011-05-19 00:06:34.000000000 -0400
861 +++ linux-2.6.39/arch/arm/mach-msm/last_radio_log.c 2011-05-22 19:36:30.000000000 -0400
862 @@ -48,6 +48,7 @@ static ssize_t last_radio_log_read(struc
863 }
864
865 static struct file_operations last_radio_log_fops = {
866 + /* cannot be const, see msm_init_last_radio_log */
867 .read = last_radio_log_read,
868 .llseek = default_llseek,
869 };
870 diff -urNp linux-2.6.39/arch/arm/mach-mv78xx0/pcie.c linux-2.6.39/arch/arm/mach-mv78xx0/pcie.c
871 --- linux-2.6.39/arch/arm/mach-mv78xx0/pcie.c 2011-05-19 00:06:34.000000000 -0400
872 +++ linux-2.6.39/arch/arm/mach-mv78xx0/pcie.c 2011-05-22 19:36:30.000000000 -0400
873 @@ -222,7 +222,7 @@ static int pcie_wr_conf(struct pci_bus *
874 return ret;
875 }
876
877 -static struct pci_ops pcie_ops = {
878 +static const struct pci_ops pcie_ops = {
879 .read = pcie_rd_conf,
880 .write = pcie_wr_conf,
881 };
882 diff -urNp linux-2.6.39/arch/arm/mach-orion5x/pci.c linux-2.6.39/arch/arm/mach-orion5x/pci.c
883 --- linux-2.6.39/arch/arm/mach-orion5x/pci.c 2011-05-19 00:06:34.000000000 -0400
884 +++ linux-2.6.39/arch/arm/mach-orion5x/pci.c 2011-05-22 19:36:30.000000000 -0400
885 @@ -130,7 +130,7 @@ static int pcie_wr_conf(struct pci_bus *
886 return ret;
887 }
888
889 -static struct pci_ops pcie_ops = {
890 +static const struct pci_ops pcie_ops = {
891 .read = pcie_rd_conf,
892 .write = pcie_wr_conf,
893 };
894 @@ -368,7 +368,7 @@ static int orion5x_pci_wr_conf(struct pc
895 PCI_FUNC(devfn), where, size, val);
896 }
897
898 -static struct pci_ops pci_ops = {
899 +static const struct pci_ops pci_ops = {
900 .read = orion5x_pci_rd_conf,
901 .write = orion5x_pci_wr_conf,
902 };
903 diff -urNp linux-2.6.39/arch/arm/mach-sa1100/pci-nanoengine.c linux-2.6.39/arch/arm/mach-sa1100/pci-nanoengine.c
904 --- linux-2.6.39/arch/arm/mach-sa1100/pci-nanoengine.c 2011-05-19 00:06:34.000000000 -0400
905 +++ linux-2.6.39/arch/arm/mach-sa1100/pci-nanoengine.c 2011-05-22 19:36:30.000000000 -0400
906 @@ -117,7 +117,7 @@ static int nanoengine_write_config(struc
907 return PCIBIOS_SUCCESSFUL;
908 }
909
910 -static struct pci_ops pci_nano_ops = {
911 +static const struct pci_ops pci_nano_ops = {
912 .read = nanoengine_read_config,
913 .write = nanoengine_write_config,
914 };
915 diff -urNp linux-2.6.39/arch/arm/mach-tegra/pcie.c linux-2.6.39/arch/arm/mach-tegra/pcie.c
916 --- linux-2.6.39/arch/arm/mach-tegra/pcie.c 2011-05-19 00:06:34.000000000 -0400
917 +++ linux-2.6.39/arch/arm/mach-tegra/pcie.c 2011-05-22 19:36:30.000000000 -0400
918 @@ -336,7 +336,7 @@ static int tegra_pcie_write_conf(struct
919 return PCIBIOS_SUCCESSFUL;
920 }
921
922 -static struct pci_ops tegra_pcie_ops = {
923 +static const struct pci_ops tegra_pcie_ops = {
924 .read = tegra_pcie_read_conf,
925 .write = tegra_pcie_write_conf,
926 };
927 diff -urNp linux-2.6.39/arch/arm/mach-ux500/mbox-db5500.c linux-2.6.39/arch/arm/mach-ux500/mbox-db5500.c
928 --- linux-2.6.39/arch/arm/mach-ux500/mbox-db5500.c 2011-05-19 00:06:34.000000000 -0400
929 +++ linux-2.6.39/arch/arm/mach-ux500/mbox-db5500.c 2011-05-22 19:41:32.000000000 -0400
930 @@ -168,7 +168,7 @@ static ssize_t mbox_read_fifo(struct dev
931 return sprintf(buf, "0x%X\n", mbox_value);
932 }
933
934 -static DEVICE_ATTR(fifo, S_IWUGO | S_IRUGO, mbox_read_fifo, mbox_write_fifo);
935 +static DEVICE_ATTR(fifo, S_IWUSR | S_IRUGO, mbox_read_fifo, mbox_write_fifo);
936
937 static int mbox_show(struct seq_file *s, void *data)
938 {
939 diff -urNp linux-2.6.39/arch/arm/mach-versatile/pci.c linux-2.6.39/arch/arm/mach-versatile/pci.c
940 --- linux-2.6.39/arch/arm/mach-versatile/pci.c 2011-05-19 00:06:34.000000000 -0400
941 +++ linux-2.6.39/arch/arm/mach-versatile/pci.c 2011-05-22 19:36:30.000000000 -0400
942 @@ -165,7 +165,7 @@ static int versatile_write_config(struct
943 return PCIBIOS_SUCCESSFUL;
944 }
945
946 -static struct pci_ops pci_versatile_ops = {
947 +static const struct pci_ops pci_versatile_ops = {
948 .read = versatile_read_config,
949 .write = versatile_write_config,
950 };
951 diff -urNp linux-2.6.39/arch/arm/mm/fault.c linux-2.6.39/arch/arm/mm/fault.c
952 --- linux-2.6.39/arch/arm/mm/fault.c 2011-05-19 00:06:34.000000000 -0400
953 +++ linux-2.6.39/arch/arm/mm/fault.c 2011-05-22 19:36:30.000000000 -0400
954 @@ -182,6 +182,13 @@ __do_user_fault(struct task_struct *tsk,
955 }
956 #endif
957
958 +#ifdef CONFIG_PAX_PAGEEXEC
959 + if (fsr & FSR_LNX_PF) {
960 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
961 + do_group_exit(SIGKILL);
962 + }
963 +#endif
964 +
965 tsk->thread.address = addr;
966 tsk->thread.error_code = fsr;
967 tsk->thread.trap_no = 14;
968 @@ -379,6 +386,33 @@ do_page_fault(unsigned long addr, unsign
969 }
970 #endif /* CONFIG_MMU */
971
972 +#ifdef CONFIG_PAX_PAGEEXEC
973 +void pax_report_insns(void *pc, void *sp)
974 +{
975 + long i;
976 +
977 + printk(KERN_ERR "PAX: bytes at PC: ");
978 + for (i = 0; i < 20; i++) {
979 + unsigned char c;
980 + if (get_user(c, (__force unsigned char __user *)pc+i))
981 + printk(KERN_CONT "?? ");
982 + else
983 + printk(KERN_CONT "%02x ", c);
984 + }
985 + printk("\n");
986 +
987 + printk(KERN_ERR "PAX: bytes at SP-4: ");
988 + for (i = -1; i < 20; i++) {
989 + unsigned long c;
990 + if (get_user(c, (__force unsigned long __user *)sp+i))
991 + printk(KERN_CONT "???????? ");
992 + else
993 + printk(KERN_CONT "%08lx ", c);
994 + }
995 + printk("\n");
996 +}
997 +#endif
998 +
999 /*
1000 * First Level Translation Fault Handler
1001 *
1002 diff -urNp linux-2.6.39/arch/arm/mm/mmap.c linux-2.6.39/arch/arm/mm/mmap.c
1003 --- linux-2.6.39/arch/arm/mm/mmap.c 2011-05-19 00:06:34.000000000 -0400
1004 +++ linux-2.6.39/arch/arm/mm/mmap.c 2011-05-22 19:36:30.000000000 -0400
1005 @@ -65,6 +65,10 @@ arch_get_unmapped_area(struct file *filp
1006 if (len > TASK_SIZE)
1007 return -ENOMEM;
1008
1009 +#ifdef CONFIG_PAX_RANDMMAP
1010 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
1011 +#endif
1012 +
1013 if (addr) {
1014 if (do_align)
1015 addr = COLOUR_ALIGN(addr, pgoff);
1016 @@ -72,15 +76,14 @@ arch_get_unmapped_area(struct file *filp
1017 addr = PAGE_ALIGN(addr);
1018
1019 vma = find_vma(mm, addr);
1020 - if (TASK_SIZE - len >= addr &&
1021 - (!vma || addr + len <= vma->vm_start))
1022 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1023 return addr;
1024 }
1025 if (len > mm->cached_hole_size) {
1026 - start_addr = addr = mm->free_area_cache;
1027 + start_addr = addr = mm->free_area_cache;
1028 } else {
1029 - start_addr = addr = TASK_UNMAPPED_BASE;
1030 - mm->cached_hole_size = 0;
1031 + start_addr = addr = mm->mmap_base;
1032 + mm->cached_hole_size = 0;
1033 }
1034 /* 8 bits of randomness in 20 address space bits */
1035 if ((current->flags & PF_RANDOMIZE) &&
1036 @@ -100,14 +103,14 @@ full_search:
1037 * Start a new search - just in case we missed
1038 * some holes.
1039 */
1040 - if (start_addr != TASK_UNMAPPED_BASE) {
1041 - start_addr = addr = TASK_UNMAPPED_BASE;
1042 + if (start_addr != mm->mmap_base) {
1043 + start_addr = addr = mm->mmap_base;
1044 mm->cached_hole_size = 0;
1045 goto full_search;
1046 }
1047 return -ENOMEM;
1048 }
1049 - if (!vma || addr + len <= vma->vm_start) {
1050 + if (check_heap_stack_gap(vma, addr, len)) {
1051 /*
1052 * Remember the place where we stopped the search:
1053 */
1054 diff -urNp linux-2.6.39/arch/arm/plat-iop/pci.c linux-2.6.39/arch/arm/plat-iop/pci.c
1055 --- linux-2.6.39/arch/arm/plat-iop/pci.c 2011-05-19 00:06:34.000000000 -0400
1056 +++ linux-2.6.39/arch/arm/plat-iop/pci.c 2011-05-22 19:36:30.000000000 -0400
1057 @@ -161,7 +161,7 @@ iop3xx_write_config(struct pci_bus *bus,
1058 return PCIBIOS_SUCCESSFUL;
1059 }
1060
1061 -static struct pci_ops iop3xx_ops = {
1062 +static const struct pci_ops iop3xx_ops = {
1063 .read = iop3xx_read_config,
1064 .write = iop3xx_write_config,
1065 };
1066 diff -urNp linux-2.6.39/arch/avr32/include/asm/elf.h linux-2.6.39/arch/avr32/include/asm/elf.h
1067 --- linux-2.6.39/arch/avr32/include/asm/elf.h 2011-05-19 00:06:34.000000000 -0400
1068 +++ linux-2.6.39/arch/avr32/include/asm/elf.h 2011-05-22 19:36:30.000000000 -0400
1069 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpreg
1070 the loader. We need to make sure that it is out of the way of the program
1071 that it will "exec", and that there is sufficient room for the brk. */
1072
1073 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1074 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1075
1076 +#ifdef CONFIG_PAX_ASLR
1077 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
1078 +
1079 +#define PAX_DELTA_MMAP_LEN 15
1080 +#define PAX_DELTA_STACK_LEN 15
1081 +#endif
1082
1083 /* This yields a mask that user programs can use to figure out what
1084 instruction set this CPU supports. This could be done in user space,
1085 diff -urNp linux-2.6.39/arch/avr32/include/asm/kmap_types.h linux-2.6.39/arch/avr32/include/asm/kmap_types.h
1086 --- linux-2.6.39/arch/avr32/include/asm/kmap_types.h 2011-05-19 00:06:34.000000000 -0400
1087 +++ linux-2.6.39/arch/avr32/include/asm/kmap_types.h 2011-05-22 19:36:30.000000000 -0400
1088 @@ -22,7 +22,8 @@ D(10) KM_IRQ0,
1089 D(11) KM_IRQ1,
1090 D(12) KM_SOFTIRQ0,
1091 D(13) KM_SOFTIRQ1,
1092 -D(14) KM_TYPE_NR
1093 +D(14) KM_CLEARPAGE,
1094 +D(15) KM_TYPE_NR
1095 };
1096
1097 #undef D
1098 diff -urNp linux-2.6.39/arch/avr32/mm/fault.c linux-2.6.39/arch/avr32/mm/fault.c
1099 --- linux-2.6.39/arch/avr32/mm/fault.c 2011-05-19 00:06:34.000000000 -0400
1100 +++ linux-2.6.39/arch/avr32/mm/fault.c 2011-05-22 19:36:30.000000000 -0400
1101 @@ -41,6 +41,23 @@ static inline int notify_page_fault(stru
1102
1103 int exception_trace = 1;
1104
1105 +#ifdef CONFIG_PAX_PAGEEXEC
1106 +void pax_report_insns(void *pc, void *sp)
1107 +{
1108 + unsigned long i;
1109 +
1110 + printk(KERN_ERR "PAX: bytes at PC: ");
1111 + for (i = 0; i < 20; i++) {
1112 + unsigned char c;
1113 + if (get_user(c, (unsigned char *)pc+i))
1114 + printk(KERN_CONT "???????? ");
1115 + else
1116 + printk(KERN_CONT "%02x ", c);
1117 + }
1118 + printk("\n");
1119 +}
1120 +#endif
1121 +
1122 /*
1123 * This routine handles page faults. It determines the address and the
1124 * problem, and then passes it off to one of the appropriate routines.
1125 @@ -156,6 +173,16 @@ bad_area:
1126 up_read(&mm->mmap_sem);
1127
1128 if (user_mode(regs)) {
1129 +
1130 +#ifdef CONFIG_PAX_PAGEEXEC
1131 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
1132 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
1133 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
1134 + do_group_exit(SIGKILL);
1135 + }
1136 + }
1137 +#endif
1138 +
1139 if (exception_trace && printk_ratelimit())
1140 printk("%s%s[%d]: segfault at %08lx pc %08lx "
1141 "sp %08lx ecr %lu\n",
1142 diff -urNp linux-2.6.39/arch/blackfin/kernel/kgdb.c linux-2.6.39/arch/blackfin/kernel/kgdb.c
1143 --- linux-2.6.39/arch/blackfin/kernel/kgdb.c 2011-05-19 00:06:34.000000000 -0400
1144 +++ linux-2.6.39/arch/blackfin/kernel/kgdb.c 2011-05-22 19:36:30.000000000 -0400
1145 @@ -420,7 +420,7 @@ int kgdb_arch_handle_exception(int vecto
1146 return -1; /* this means that we do not want to exit from the handler */
1147 }
1148
1149 -struct kgdb_arch arch_kgdb_ops = {
1150 +const struct kgdb_arch arch_kgdb_ops = {
1151 .gdb_bpt_instr = {0xa1},
1152 .flags = KGDB_HW_BREAKPOINT,
1153 .set_hw_breakpoint = bfin_set_hw_break,
1154 diff -urNp linux-2.6.39/arch/blackfin/mm/maccess.c linux-2.6.39/arch/blackfin/mm/maccess.c
1155 --- linux-2.6.39/arch/blackfin/mm/maccess.c 2011-05-19 00:06:34.000000000 -0400
1156 +++ linux-2.6.39/arch/blackfin/mm/maccess.c 2011-05-22 19:36:30.000000000 -0400
1157 @@ -16,7 +16,7 @@ static int validate_memory_access_addres
1158 return bfin_mem_access_type(addr, size);
1159 }
1160
1161 -long probe_kernel_read(void *dst, void *src, size_t size)
1162 +long probe_kernel_read(void *dst, const void *src, size_t size)
1163 {
1164 unsigned long lsrc = (unsigned long)src;
1165 int mem_type;
1166 @@ -55,7 +55,7 @@ long probe_kernel_read(void *dst, void *
1167 return -EFAULT;
1168 }
1169
1170 -long probe_kernel_write(void *dst, void *src, size_t size)
1171 +long probe_kernel_write(void *dst, const void *src, size_t size)
1172 {
1173 unsigned long ldst = (unsigned long)dst;
1174 int mem_type;
1175 diff -urNp linux-2.6.39/arch/frv/include/asm/kmap_types.h linux-2.6.39/arch/frv/include/asm/kmap_types.h
1176 --- linux-2.6.39/arch/frv/include/asm/kmap_types.h 2011-05-19 00:06:34.000000000 -0400
1177 +++ linux-2.6.39/arch/frv/include/asm/kmap_types.h 2011-05-22 19:36:30.000000000 -0400
1178 @@ -23,6 +23,7 @@ enum km_type {
1179 KM_IRQ1,
1180 KM_SOFTIRQ0,
1181 KM_SOFTIRQ1,
1182 + KM_CLEARPAGE,
1183 KM_TYPE_NR
1184 };
1185
1186 diff -urNp linux-2.6.39/arch/frv/mb93090-mb00/pci-frv.h linux-2.6.39/arch/frv/mb93090-mb00/pci-frv.h
1187 --- linux-2.6.39/arch/frv/mb93090-mb00/pci-frv.h 2011-05-19 00:06:34.000000000 -0400
1188 +++ linux-2.6.39/arch/frv/mb93090-mb00/pci-frv.h 2011-05-22 19:36:30.000000000 -0400
1189 @@ -34,7 +34,7 @@ void pcibios_resource_survey(void);
1190
1191 extern int __nongpreldata pcibios_last_bus;
1192 extern struct pci_bus *__nongpreldata pci_root_bus;
1193 -extern struct pci_ops *__nongpreldata pci_root_ops;
1194 +extern const struct pci_ops *__nongpreldata pci_root_ops;
1195
1196 /* pci-irq.c */
1197 extern unsigned int pcibios_irq_mask;
1198 diff -urNp linux-2.6.39/arch/frv/mb93090-mb00/pci-vdk.c linux-2.6.39/arch/frv/mb93090-mb00/pci-vdk.c
1199 --- linux-2.6.39/arch/frv/mb93090-mb00/pci-vdk.c 2011-05-19 00:06:34.000000000 -0400
1200 +++ linux-2.6.39/arch/frv/mb93090-mb00/pci-vdk.c 2011-05-22 19:36:30.000000000 -0400
1201 @@ -27,7 +27,7 @@ unsigned int __nongpreldata pci_probe =
1202
1203 int __nongpreldata pcibios_last_bus = -1;
1204 struct pci_bus *__nongpreldata pci_root_bus;
1205 -struct pci_ops *__nongpreldata pci_root_ops;
1206 +const struct pci_ops *__nongpreldata pci_root_ops;
1207
1208 /*
1209 * The accessible PCI window does not cover the entire CPU address space, but
1210 @@ -169,7 +169,7 @@ static int pci_frv_write_config(struct p
1211 return PCIBIOS_SUCCESSFUL;
1212 }
1213
1214 -static struct pci_ops pci_direct_frv = {
1215 +static const struct pci_ops pci_direct_frv = {
1216 pci_frv_read_config,
1217 pci_frv_write_config,
1218 };
1219 @@ -356,7 +356,7 @@ void __init pcibios_fixup_bus(struct pci
1220
1221 int __init pcibios_init(void)
1222 {
1223 - struct pci_ops *dir = NULL;
1224 + const struct pci_ops *dir = NULL;
1225
1226 if (!mb93090_mb00_detected)
1227 return -ENXIO;
1228 diff -urNp linux-2.6.39/arch/frv/mm/elf-fdpic.c linux-2.6.39/arch/frv/mm/elf-fdpic.c
1229 --- linux-2.6.39/arch/frv/mm/elf-fdpic.c 2011-05-19 00:06:34.000000000 -0400
1230 +++ linux-2.6.39/arch/frv/mm/elf-fdpic.c 2011-05-22 19:36:30.000000000 -0400
1231 @@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(str
1232 if (addr) {
1233 addr = PAGE_ALIGN(addr);
1234 vma = find_vma(current->mm, addr);
1235 - if (TASK_SIZE - len >= addr &&
1236 - (!vma || addr + len <= vma->vm_start))
1237 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1238 goto success;
1239 }
1240
1241 @@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(str
1242 for (; vma; vma = vma->vm_next) {
1243 if (addr > limit)
1244 break;
1245 - if (addr + len <= vma->vm_start)
1246 + if (check_heap_stack_gap(vma, addr, len))
1247 goto success;
1248 addr = vma->vm_end;
1249 }
1250 @@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(str
1251 for (; vma; vma = vma->vm_next) {
1252 if (addr > limit)
1253 break;
1254 - if (addr + len <= vma->vm_start)
1255 + if (check_heap_stack_gap(vma, addr, len))
1256 goto success;
1257 addr = vma->vm_end;
1258 }
1259 diff -urNp linux-2.6.39/arch/ia64/hp/common/hwsw_iommu.c linux-2.6.39/arch/ia64/hp/common/hwsw_iommu.c
1260 --- linux-2.6.39/arch/ia64/hp/common/hwsw_iommu.c 2011-05-19 00:06:34.000000000 -0400
1261 +++ linux-2.6.39/arch/ia64/hp/common/hwsw_iommu.c 2011-05-22 19:36:30.000000000 -0400
1262 @@ -17,7 +17,7 @@
1263 #include <linux/swiotlb.h>
1264 #include <asm/machvec.h>
1265
1266 -extern struct dma_map_ops sba_dma_ops, swiotlb_dma_ops;
1267 +extern const struct dma_map_ops sba_dma_ops, swiotlb_dma_ops;
1268
1269 /* swiotlb declarations & definitions: */
1270 extern int swiotlb_late_init_with_default_size (size_t size);
1271 @@ -33,7 +33,7 @@ static inline int use_swiotlb(struct dev
1272 !sba_dma_ops.dma_supported(dev, *dev->dma_mask);
1273 }
1274
1275 -struct dma_map_ops *hwsw_dma_get_ops(struct device *dev)
1276 +const struct dma_map_ops *hwsw_dma_get_ops(struct device *dev)
1277 {
1278 if (use_swiotlb(dev))
1279 return &swiotlb_dma_ops;
1280 diff -urNp linux-2.6.39/arch/ia64/hp/common/sba_iommu.c linux-2.6.39/arch/ia64/hp/common/sba_iommu.c
1281 --- linux-2.6.39/arch/ia64/hp/common/sba_iommu.c 2011-05-19 00:06:34.000000000 -0400
1282 +++ linux-2.6.39/arch/ia64/hp/common/sba_iommu.c 2011-05-22 19:36:30.000000000 -0400
1283 @@ -2097,7 +2097,7 @@ static struct acpi_driver acpi_sba_ioc_d
1284 },
1285 };
1286
1287 -extern struct dma_map_ops swiotlb_dma_ops;
1288 +extern const struct dma_map_ops swiotlb_dma_ops;
1289
1290 static int __init
1291 sba_init(void)
1292 @@ -2211,7 +2211,7 @@ sba_page_override(char *str)
1293
1294 __setup("sbapagesize=",sba_page_override);
1295
1296 -struct dma_map_ops sba_dma_ops = {
1297 +const struct dma_map_ops sba_dma_ops = {
1298 .alloc_coherent = sba_alloc_coherent,
1299 .free_coherent = sba_free_coherent,
1300 .map_page = sba_map_page,
1301 diff -urNp linux-2.6.39/arch/ia64/include/asm/dma-mapping.h linux-2.6.39/arch/ia64/include/asm/dma-mapping.h
1302 --- linux-2.6.39/arch/ia64/include/asm/dma-mapping.h 2011-05-19 00:06:34.000000000 -0400
1303 +++ linux-2.6.39/arch/ia64/include/asm/dma-mapping.h 2011-05-22 19:36:30.000000000 -0400
1304 @@ -14,7 +14,7 @@
1305
1306 #define DMA_ERROR_CODE 0
1307
1308 -extern struct dma_map_ops *dma_ops;
1309 +extern const struct dma_map_ops *dma_ops;
1310 extern struct ia64_machine_vector ia64_mv;
1311 extern void set_iommu_machvec(void);
1312
1313 @@ -26,7 +26,7 @@ extern void machvec_dma_sync_sg(struct d
1314 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
1315 dma_addr_t *daddr, gfp_t gfp)
1316 {
1317 - struct dma_map_ops *ops = platform_dma_get_ops(dev);
1318 + const struct dma_map_ops *ops = platform_dma_get_ops(dev);
1319 void *caddr;
1320
1321 caddr = ops->alloc_coherent(dev, size, daddr, gfp);
1322 @@ -37,7 +37,7 @@ static inline void *dma_alloc_coherent(s
1323 static inline void dma_free_coherent(struct device *dev, size_t size,
1324 void *caddr, dma_addr_t daddr)
1325 {
1326 - struct dma_map_ops *ops = platform_dma_get_ops(dev);
1327 + const struct dma_map_ops *ops = platform_dma_get_ops(dev);
1328 debug_dma_free_coherent(dev, size, caddr, daddr);
1329 ops->free_coherent(dev, size, caddr, daddr);
1330 }
1331 @@ -51,13 +51,13 @@ static inline void dma_free_coherent(str
1332
1333 static inline int dma_mapping_error(struct device *dev, dma_addr_t daddr)
1334 {
1335 - struct dma_map_ops *ops = platform_dma_get_ops(dev);
1336 + const struct dma_map_ops *ops = platform_dma_get_ops(dev);
1337 return ops->mapping_error(dev, daddr);
1338 }
1339
1340 static inline int dma_supported(struct device *dev, u64 mask)
1341 {
1342 - struct dma_map_ops *ops = platform_dma_get_ops(dev);
1343 + const struct dma_map_ops *ops = platform_dma_get_ops(dev);
1344 return ops->dma_supported(dev, mask);
1345 }
1346
1347 diff -urNp linux-2.6.39/arch/ia64/include/asm/elf.h linux-2.6.39/arch/ia64/include/asm/elf.h
1348 --- linux-2.6.39/arch/ia64/include/asm/elf.h 2011-05-19 00:06:34.000000000 -0400
1349 +++ linux-2.6.39/arch/ia64/include/asm/elf.h 2011-05-22 19:36:30.000000000 -0400
1350 @@ -42,6 +42,13 @@
1351 */
1352 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
1353
1354 +#ifdef CONFIG_PAX_ASLR
1355 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
1356 +
1357 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
1358 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
1359 +#endif
1360 +
1361 #define PT_IA_64_UNWIND 0x70000001
1362
1363 /* IA-64 relocations: */
1364 diff -urNp linux-2.6.39/arch/ia64/include/asm/machvec.h linux-2.6.39/arch/ia64/include/asm/machvec.h
1365 --- linux-2.6.39/arch/ia64/include/asm/machvec.h 2011-05-19 00:06:34.000000000 -0400
1366 +++ linux-2.6.39/arch/ia64/include/asm/machvec.h 2011-05-22 19:36:30.000000000 -0400
1367 @@ -45,7 +45,7 @@ typedef void ia64_mv_kernel_launch_event
1368 /* DMA-mapping interface: */
1369 typedef void ia64_mv_dma_init (void);
1370 typedef u64 ia64_mv_dma_get_required_mask (struct device *);
1371 -typedef struct dma_map_ops *ia64_mv_dma_get_ops(struct device *);
1372 +typedef const struct dma_map_ops *ia64_mv_dma_get_ops(struct device *);
1373
1374 /*
1375 * WARNING: The legacy I/O space is _architected_. Platforms are
1376 @@ -251,7 +251,7 @@ extern void machvec_init_from_cmdline(co
1377 # endif /* CONFIG_IA64_GENERIC */
1378
1379 extern void swiotlb_dma_init(void);
1380 -extern struct dma_map_ops *dma_get_ops(struct device *);
1381 +extern const struct dma_map_ops *dma_get_ops(struct device *);
1382
1383 /*
1384 * Define default versions so we can extend machvec for new platforms without having
1385 diff -urNp linux-2.6.39/arch/ia64/include/asm/pgtable.h linux-2.6.39/arch/ia64/include/asm/pgtable.h
1386 --- linux-2.6.39/arch/ia64/include/asm/pgtable.h 2011-05-19 00:06:34.000000000 -0400
1387 +++ linux-2.6.39/arch/ia64/include/asm/pgtable.h 2011-05-22 19:36:30.000000000 -0400
1388 @@ -12,7 +12,7 @@
1389 * David Mosberger-Tang <davidm@hpl.hp.com>
1390 */
1391
1392 -
1393 +#include <linux/const.h>
1394 #include <asm/mman.h>
1395 #include <asm/page.h>
1396 #include <asm/processor.h>
1397 @@ -143,6 +143,17 @@
1398 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1399 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1400 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
1401 +
1402 +#ifdef CONFIG_PAX_PAGEEXEC
1403 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
1404 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1405 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1406 +#else
1407 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
1408 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
1409 +# define PAGE_COPY_NOEXEC PAGE_COPY
1410 +#endif
1411 +
1412 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
1413 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
1414 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
1415 diff -urNp linux-2.6.39/arch/ia64/include/asm/spinlock.h linux-2.6.39/arch/ia64/include/asm/spinlock.h
1416 --- linux-2.6.39/arch/ia64/include/asm/spinlock.h 2011-05-19 00:06:34.000000000 -0400
1417 +++ linux-2.6.39/arch/ia64/include/asm/spinlock.h 2011-05-22 19:36:30.000000000 -0400
1418 @@ -72,7 +72,7 @@ static __always_inline void __ticket_spi
1419 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
1420
1421 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
1422 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
1423 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
1424 }
1425
1426 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
1427 diff -urNp linux-2.6.39/arch/ia64/include/asm/uaccess.h linux-2.6.39/arch/ia64/include/asm/uaccess.h
1428 --- linux-2.6.39/arch/ia64/include/asm/uaccess.h 2011-05-19 00:06:34.000000000 -0400
1429 +++ linux-2.6.39/arch/ia64/include/asm/uaccess.h 2011-05-22 19:36:30.000000000 -0400
1430 @@ -257,7 +257,7 @@ __copy_from_user (void *to, const void _
1431 const void *__cu_from = (from); \
1432 long __cu_len = (n); \
1433 \
1434 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
1435 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \
1436 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
1437 __cu_len; \
1438 })
1439 @@ -269,7 +269,7 @@ __copy_from_user (void *to, const void _
1440 long __cu_len = (n); \
1441 \
1442 __chk_user_ptr(__cu_from); \
1443 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
1444 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \
1445 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
1446 __cu_len; \
1447 })
1448 diff -urNp linux-2.6.39/arch/ia64/kernel/dma-mapping.c linux-2.6.39/arch/ia64/kernel/dma-mapping.c
1449 --- linux-2.6.39/arch/ia64/kernel/dma-mapping.c 2011-05-19 00:06:34.000000000 -0400
1450 +++ linux-2.6.39/arch/ia64/kernel/dma-mapping.c 2011-05-22 19:36:30.000000000 -0400
1451 @@ -3,7 +3,7 @@
1452 /* Set this to 1 if there is a HW IOMMU in the system */
1453 int iommu_detected __read_mostly;
1454
1455 -struct dma_map_ops *dma_ops;
1456 +const struct dma_map_ops *dma_ops;
1457 EXPORT_SYMBOL(dma_ops);
1458
1459 #define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16)
1460 @@ -16,7 +16,7 @@ static int __init dma_init(void)
1461 }
1462 fs_initcall(dma_init);
1463
1464 -struct dma_map_ops *dma_get_ops(struct device *dev)
1465 +const struct dma_map_ops *dma_get_ops(struct device *dev)
1466 {
1467 return dma_ops;
1468 }
1469 diff -urNp linux-2.6.39/arch/ia64/kernel/module.c linux-2.6.39/arch/ia64/kernel/module.c
1470 --- linux-2.6.39/arch/ia64/kernel/module.c 2011-05-19 00:06:34.000000000 -0400
1471 +++ linux-2.6.39/arch/ia64/kernel/module.c 2011-05-22 19:36:30.000000000 -0400
1472 @@ -315,8 +315,7 @@ module_alloc (unsigned long size)
1473 void
1474 module_free (struct module *mod, void *module_region)
1475 {
1476 - if (mod && mod->arch.init_unw_table &&
1477 - module_region == mod->module_init) {
1478 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
1479 unw_remove_unwind_table(mod->arch.init_unw_table);
1480 mod->arch.init_unw_table = NULL;
1481 }
1482 @@ -502,15 +501,39 @@ module_frob_arch_sections (Elf_Ehdr *ehd
1483 }
1484
1485 static inline int
1486 +in_init_rx (const struct module *mod, uint64_t addr)
1487 +{
1488 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
1489 +}
1490 +
1491 +static inline int
1492 +in_init_rw (const struct module *mod, uint64_t addr)
1493 +{
1494 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
1495 +}
1496 +
1497 +static inline int
1498 in_init (const struct module *mod, uint64_t addr)
1499 {
1500 - return addr - (uint64_t) mod->module_init < mod->init_size;
1501 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
1502 +}
1503 +
1504 +static inline int
1505 +in_core_rx (const struct module *mod, uint64_t addr)
1506 +{
1507 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
1508 +}
1509 +
1510 +static inline int
1511 +in_core_rw (const struct module *mod, uint64_t addr)
1512 +{
1513 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
1514 }
1515
1516 static inline int
1517 in_core (const struct module *mod, uint64_t addr)
1518 {
1519 - return addr - (uint64_t) mod->module_core < mod->core_size;
1520 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
1521 }
1522
1523 static inline int
1524 @@ -693,7 +716,14 @@ do_reloc (struct module *mod, uint8_t r_
1525 break;
1526
1527 case RV_BDREL:
1528 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
1529 + if (in_init_rx(mod, val))
1530 + val -= (uint64_t) mod->module_init_rx;
1531 + else if (in_init_rw(mod, val))
1532 + val -= (uint64_t) mod->module_init_rw;
1533 + else if (in_core_rx(mod, val))
1534 + val -= (uint64_t) mod->module_core_rx;
1535 + else if (in_core_rw(mod, val))
1536 + val -= (uint64_t) mod->module_core_rw;
1537 break;
1538
1539 case RV_LTV:
1540 @@ -828,15 +858,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs,
1541 * addresses have been selected...
1542 */
1543 uint64_t gp;
1544 - if (mod->core_size > MAX_LTOFF)
1545 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
1546 /*
1547 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
1548 * at the end of the module.
1549 */
1550 - gp = mod->core_size - MAX_LTOFF / 2;
1551 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
1552 else
1553 - gp = mod->core_size / 2;
1554 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
1555 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
1556 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
1557 mod->arch.gp = gp;
1558 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
1559 }
1560 diff -urNp linux-2.6.39/arch/ia64/kernel/pci-dma.c linux-2.6.39/arch/ia64/kernel/pci-dma.c
1561 --- linux-2.6.39/arch/ia64/kernel/pci-dma.c 2011-05-19 00:06:34.000000000 -0400
1562 +++ linux-2.6.39/arch/ia64/kernel/pci-dma.c 2011-05-22 19:36:30.000000000 -0400
1563 @@ -43,7 +43,7 @@ struct device fallback_dev = {
1564 .dma_mask = &fallback_dev.coherent_dma_mask,
1565 };
1566
1567 -extern struct dma_map_ops intel_dma_ops;
1568 +extern const struct dma_map_ops intel_dma_ops;
1569
1570 static int __init pci_iommu_init(void)
1571 {
1572 diff -urNp linux-2.6.39/arch/ia64/kernel/pci-swiotlb.c linux-2.6.39/arch/ia64/kernel/pci-swiotlb.c
1573 --- linux-2.6.39/arch/ia64/kernel/pci-swiotlb.c 2011-05-19 00:06:34.000000000 -0400
1574 +++ linux-2.6.39/arch/ia64/kernel/pci-swiotlb.c 2011-05-22 19:36:30.000000000 -0400
1575 @@ -22,7 +22,7 @@ static void *ia64_swiotlb_alloc_coherent
1576 return swiotlb_alloc_coherent(dev, size, dma_handle, gfp);
1577 }
1578
1579 -struct dma_map_ops swiotlb_dma_ops = {
1580 +const struct dma_map_ops swiotlb_dma_ops = {
1581 .alloc_coherent = ia64_swiotlb_alloc_coherent,
1582 .free_coherent = swiotlb_free_coherent,
1583 .map_page = swiotlb_map_page,
1584 diff -urNp linux-2.6.39/arch/ia64/kernel/sys_ia64.c linux-2.6.39/arch/ia64/kernel/sys_ia64.c
1585 --- linux-2.6.39/arch/ia64/kernel/sys_ia64.c 2011-05-19 00:06:34.000000000 -0400
1586 +++ linux-2.6.39/arch/ia64/kernel/sys_ia64.c 2011-05-22 19:36:30.000000000 -0400
1587 @@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *fil
1588 if (REGION_NUMBER(addr) == RGN_HPAGE)
1589 addr = 0;
1590 #endif
1591 +
1592 +#ifdef CONFIG_PAX_RANDMMAP
1593 + if (mm->pax_flags & MF_PAX_RANDMMAP)
1594 + addr = mm->free_area_cache;
1595 + else
1596 +#endif
1597 +
1598 if (!addr)
1599 addr = mm->free_area_cache;
1600
1601 @@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *fil
1602 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
1603 /* At this point: (!vma || addr < vma->vm_end). */
1604 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
1605 - if (start_addr != TASK_UNMAPPED_BASE) {
1606 + if (start_addr != mm->mmap_base) {
1607 /* Start a new search --- just in case we missed some holes. */
1608 - addr = TASK_UNMAPPED_BASE;
1609 + addr = mm->mmap_base;
1610 goto full_search;
1611 }
1612 return -ENOMEM;
1613 }
1614 - if (!vma || addr + len <= vma->vm_start) {
1615 + if (check_heap_stack_gap(vma, addr, len)) {
1616 /* Remember the address where we stopped this search: */
1617 mm->free_area_cache = addr + len;
1618 return addr;
1619 diff -urNp linux-2.6.39/arch/ia64/kernel/vmlinux.lds.S linux-2.6.39/arch/ia64/kernel/vmlinux.lds.S
1620 --- linux-2.6.39/arch/ia64/kernel/vmlinux.lds.S 2011-05-19 00:06:34.000000000 -0400
1621 +++ linux-2.6.39/arch/ia64/kernel/vmlinux.lds.S 2011-05-22 19:36:30.000000000 -0400
1622 @@ -199,7 +199,7 @@ SECTIONS {
1623 /* Per-cpu data: */
1624 . = ALIGN(PERCPU_PAGE_SIZE);
1625 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
1626 - __phys_per_cpu_start = __per_cpu_load;
1627 + __phys_per_cpu_start = per_cpu_load;
1628 /*
1629 * ensure percpu data fits
1630 * into percpu page size
1631 diff -urNp linux-2.6.39/arch/ia64/mm/fault.c linux-2.6.39/arch/ia64/mm/fault.c
1632 --- linux-2.6.39/arch/ia64/mm/fault.c 2011-05-19 00:06:34.000000000 -0400
1633 +++ linux-2.6.39/arch/ia64/mm/fault.c 2011-05-22 19:36:30.000000000 -0400
1634 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned
1635 return pte_present(pte);
1636 }
1637
1638 +#ifdef CONFIG_PAX_PAGEEXEC
1639 +void pax_report_insns(void *pc, void *sp)
1640 +{
1641 + unsigned long i;
1642 +
1643 + printk(KERN_ERR "PAX: bytes at PC: ");
1644 + for (i = 0; i < 8; i++) {
1645 + unsigned int c;
1646 + if (get_user(c, (unsigned int *)pc+i))
1647 + printk(KERN_CONT "???????? ");
1648 + else
1649 + printk(KERN_CONT "%08x ", c);
1650 + }
1651 + printk("\n");
1652 +}
1653 +#endif
1654 +
1655 void __kprobes
1656 ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *regs)
1657 {
1658 @@ -145,9 +162,23 @@ ia64_do_page_fault (unsigned long addres
1659 mask = ( (((isr >> IA64_ISR_X_BIT) & 1UL) << VM_EXEC_BIT)
1660 | (((isr >> IA64_ISR_W_BIT) & 1UL) << VM_WRITE_BIT));
1661
1662 - if ((vma->vm_flags & mask) != mask)
1663 + if ((vma->vm_flags & mask) != mask) {
1664 +
1665 +#ifdef CONFIG_PAX_PAGEEXEC
1666 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
1667 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
1668 + goto bad_area;
1669 +
1670 + up_read(&mm->mmap_sem);
1671 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
1672 + do_group_exit(SIGKILL);
1673 + }
1674 +#endif
1675 +
1676 goto bad_area;
1677
1678 + }
1679 +
1680 /*
1681 * If for any reason at all we couldn't handle the fault, make
1682 * sure we exit gracefully rather than endlessly redo the
1683 diff -urNp linux-2.6.39/arch/ia64/mm/hugetlbpage.c linux-2.6.39/arch/ia64/mm/hugetlbpage.c
1684 --- linux-2.6.39/arch/ia64/mm/hugetlbpage.c 2011-05-19 00:06:34.000000000 -0400
1685 +++ linux-2.6.39/arch/ia64/mm/hugetlbpage.c 2011-05-22 19:36:30.000000000 -0400
1686 @@ -171,7 +171,7 @@ unsigned long hugetlb_get_unmapped_area(
1687 /* At this point: (!vmm || addr < vmm->vm_end). */
1688 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
1689 return -ENOMEM;
1690 - if (!vmm || (addr + len) <= vmm->vm_start)
1691 + if (check_heap_stack_gap(vmm, addr, len))
1692 return addr;
1693 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
1694 }
1695 diff -urNp linux-2.6.39/arch/ia64/mm/init.c linux-2.6.39/arch/ia64/mm/init.c
1696 --- linux-2.6.39/arch/ia64/mm/init.c 2011-05-19 00:06:34.000000000 -0400
1697 +++ linux-2.6.39/arch/ia64/mm/init.c 2011-05-22 19:36:30.000000000 -0400
1698 @@ -122,6 +122,19 @@ ia64_init_addr_space (void)
1699 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
1700 vma->vm_end = vma->vm_start + PAGE_SIZE;
1701 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
1702 +
1703 +#ifdef CONFIG_PAX_PAGEEXEC
1704 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
1705 + vma->vm_flags &= ~VM_EXEC;
1706 +
1707 +#ifdef CONFIG_PAX_MPROTECT
1708 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
1709 + vma->vm_flags &= ~VM_MAYEXEC;
1710 +#endif
1711 +
1712 + }
1713 +#endif
1714 +
1715 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
1716 down_write(&current->mm->mmap_sem);
1717 if (insert_vm_struct(current->mm, vma)) {
1718 diff -urNp linux-2.6.39/arch/ia64/pci/pci.c linux-2.6.39/arch/ia64/pci/pci.c
1719 --- linux-2.6.39/arch/ia64/pci/pci.c 2011-05-19 00:06:34.000000000 -0400
1720 +++ linux-2.6.39/arch/ia64/pci/pci.c 2011-05-22 19:36:30.000000000 -0400
1721 @@ -109,7 +109,7 @@ static int pci_write(struct pci_bus *bus
1722 devfn, where, size, value);
1723 }
1724
1725 -struct pci_ops pci_root_ops = {
1726 +const struct pci_ops pci_root_ops = {
1727 .read = pci_read,
1728 .write = pci_write,
1729 };
1730 diff -urNp linux-2.6.39/arch/ia64/sn/pci/pci_dma.c linux-2.6.39/arch/ia64/sn/pci/pci_dma.c
1731 --- linux-2.6.39/arch/ia64/sn/pci/pci_dma.c 2011-05-19 00:06:34.000000000 -0400
1732 +++ linux-2.6.39/arch/ia64/sn/pci/pci_dma.c 2011-05-22 19:36:30.000000000 -0400
1733 @@ -465,7 +465,7 @@ int sn_pci_legacy_write(struct pci_bus *
1734 return ret;
1735 }
1736
1737 -static struct dma_map_ops sn_dma_ops = {
1738 +static const struct dma_map_ops sn_dma_ops = {
1739 .alloc_coherent = sn_dma_alloc_coherent,
1740 .free_coherent = sn_dma_free_coherent,
1741 .map_page = sn_dma_map_page,
1742 diff -urNp linux-2.6.39/arch/m32r/lib/usercopy.c linux-2.6.39/arch/m32r/lib/usercopy.c
1743 --- linux-2.6.39/arch/m32r/lib/usercopy.c 2011-05-19 00:06:34.000000000 -0400
1744 +++ linux-2.6.39/arch/m32r/lib/usercopy.c 2011-05-22 19:36:30.000000000 -0400
1745 @@ -14,6 +14,9 @@
1746 unsigned long
1747 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
1748 {
1749 + if ((long)n < 0)
1750 + return n;
1751 +
1752 prefetch(from);
1753 if (access_ok(VERIFY_WRITE, to, n))
1754 __copy_user(to,from,n);
1755 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to,
1756 unsigned long
1757 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
1758 {
1759 + if ((long)n < 0)
1760 + return n;
1761 +
1762 prefetchw(to);
1763 if (access_ok(VERIFY_READ, from, n))
1764 __copy_user_zeroing(to,from,n);
1765 diff -urNp linux-2.6.39/arch/microblaze/include/asm/device.h linux-2.6.39/arch/microblaze/include/asm/device.h
1766 --- linux-2.6.39/arch/microblaze/include/asm/device.h 2011-05-19 00:06:34.000000000 -0400
1767 +++ linux-2.6.39/arch/microblaze/include/asm/device.h 2011-05-22 19:36:30.000000000 -0400
1768 @@ -13,7 +13,7 @@ struct device_node;
1769
1770 struct dev_archdata {
1771 /* DMA operations on that device */
1772 - struct dma_map_ops *dma_ops;
1773 + const struct dma_map_ops *dma_ops;
1774 void *dma_data;
1775 };
1776
1777 diff -urNp linux-2.6.39/arch/microblaze/include/asm/dma-mapping.h linux-2.6.39/arch/microblaze/include/asm/dma-mapping.h
1778 --- linux-2.6.39/arch/microblaze/include/asm/dma-mapping.h 2011-05-19 00:06:34.000000000 -0400
1779 +++ linux-2.6.39/arch/microblaze/include/asm/dma-mapping.h 2011-05-22 19:36:30.000000000 -0400
1780 @@ -43,14 +43,14 @@ static inline unsigned long device_to_ma
1781 return 0xfffffffful;
1782 }
1783
1784 -extern struct dma_map_ops *dma_ops;
1785 +extern const struct dma_map_ops *dma_ops;
1786
1787 /*
1788 * Available generic sets of operations
1789 */
1790 -extern struct dma_map_ops dma_direct_ops;
1791 +extern const struct dma_map_ops dma_direct_ops;
1792
1793 -static inline struct dma_map_ops *get_dma_ops(struct device *dev)
1794 +static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
1795 {
1796 /* We don't handle the NULL dev case for ISA for now. We could
1797 * do it via an out of line call but it is not needed for now. The
1798 @@ -63,14 +63,14 @@ static inline struct dma_map_ops *get_dm
1799 return dev->archdata.dma_ops;
1800 }
1801
1802 -static inline void set_dma_ops(struct device *dev, struct dma_map_ops *ops)
1803 +static inline void set_dma_ops(struct device *dev, const struct dma_map_ops *ops)
1804 {
1805 dev->archdata.dma_ops = ops;
1806 }
1807
1808 static inline int dma_supported(struct device *dev, u64 mask)
1809 {
1810 - struct dma_map_ops *ops = get_dma_ops(dev);
1811 + const struct dma_map_ops *ops = get_dma_ops(dev);
1812
1813 if (unlikely(!ops))
1814 return 0;
1815 @@ -81,7 +81,7 @@ static inline int dma_supported(struct d
1816
1817 static inline int dma_set_mask(struct device *dev, u64 dma_mask)
1818 {
1819 - struct dma_map_ops *ops = get_dma_ops(dev);
1820 + const struct dma_map_ops *ops = get_dma_ops(dev);
1821
1822 if (unlikely(ops == NULL))
1823 return -EIO;
1824 @@ -97,7 +97,7 @@ static inline int dma_set_mask(struct de
1825
1826 static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
1827 {
1828 - struct dma_map_ops *ops = get_dma_ops(dev);
1829 + const struct dma_map_ops *ops = get_dma_ops(dev);
1830 if (ops->mapping_error)
1831 return ops->mapping_error(dev, dma_addr);
1832
1833 @@ -110,7 +110,7 @@ static inline int dma_mapping_error(stru
1834 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
1835 dma_addr_t *dma_handle, gfp_t flag)
1836 {
1837 - struct dma_map_ops *ops = get_dma_ops(dev);
1838 + const struct dma_map_ops *ops = get_dma_ops(dev);
1839 void *memory;
1840
1841 BUG_ON(!ops);
1842 @@ -124,7 +124,7 @@ static inline void *dma_alloc_coherent(s
1843 static inline void dma_free_coherent(struct device *dev, size_t size,
1844 void *cpu_addr, dma_addr_t dma_handle)
1845 {
1846 - struct dma_map_ops *ops = get_dma_ops(dev);
1847 + const struct dma_map_ops *ops = get_dma_ops(dev);
1848
1849 BUG_ON(!ops);
1850 debug_dma_free_coherent(dev, size, cpu_addr, dma_handle);
1851 diff -urNp linux-2.6.39/arch/microblaze/include/asm/pci.h linux-2.6.39/arch/microblaze/include/asm/pci.h
1852 --- linux-2.6.39/arch/microblaze/include/asm/pci.h 2011-05-19 00:06:34.000000000 -0400
1853 +++ linux-2.6.39/arch/microblaze/include/asm/pci.h 2011-05-22 19:36:30.000000000 -0400
1854 @@ -54,8 +54,8 @@ static inline void pcibios_penalize_isa_
1855 }
1856
1857 #ifdef CONFIG_PCI
1858 -extern void set_pci_dma_ops(struct dma_map_ops *dma_ops);
1859 -extern struct dma_map_ops *get_pci_dma_ops(void);
1860 +extern void set_pci_dma_ops(const struct dma_map_ops *dma_ops);
1861 +extern const struct dma_map_ops *get_pci_dma_ops(void);
1862 #else /* CONFIG_PCI */
1863 #define set_pci_dma_ops(d)
1864 #define get_pci_dma_ops() NULL
1865 diff -urNp linux-2.6.39/arch/microblaze/kernel/dma.c linux-2.6.39/arch/microblaze/kernel/dma.c
1866 --- linux-2.6.39/arch/microblaze/kernel/dma.c 2011-05-19 00:06:34.000000000 -0400
1867 +++ linux-2.6.39/arch/microblaze/kernel/dma.c 2011-05-22 19:36:30.000000000 -0400
1868 @@ -134,7 +134,7 @@ static inline void dma_direct_unmap_page
1869 __dma_sync_page(dma_address, 0 , size, direction);
1870 }
1871
1872 -struct dma_map_ops dma_direct_ops = {
1873 +const struct dma_map_ops dma_direct_ops = {
1874 .alloc_coherent = dma_direct_alloc_coherent,
1875 .free_coherent = dma_direct_free_coherent,
1876 .map_sg = dma_direct_map_sg,
1877 diff -urNp linux-2.6.39/arch/microblaze/kernel/kgdb.c linux-2.6.39/arch/microblaze/kernel/kgdb.c
1878 --- linux-2.6.39/arch/microblaze/kernel/kgdb.c 2011-05-19 00:06:34.000000000 -0400
1879 +++ linux-2.6.39/arch/microblaze/kernel/kgdb.c 2011-05-22 19:36:30.000000000 -0400
1880 @@ -141,7 +141,7 @@ void kgdb_arch_exit(void)
1881 /*
1882 * Global data
1883 */
1884 -struct kgdb_arch arch_kgdb_ops = {
1885 +const struct kgdb_arch arch_kgdb_ops = {
1886 #ifdef __MICROBLAZEEL__
1887 .gdb_bpt_instr = {0x18, 0x00, 0x0c, 0xba}, /* brki r16, 0x18 */
1888 #else
1889 diff -urNp linux-2.6.39/arch/microblaze/pci/indirect_pci.c linux-2.6.39/arch/microblaze/pci/indirect_pci.c
1890 --- linux-2.6.39/arch/microblaze/pci/indirect_pci.c 2011-05-19 00:06:34.000000000 -0400
1891 +++ linux-2.6.39/arch/microblaze/pci/indirect_pci.c 2011-05-22 19:36:30.000000000 -0400
1892 @@ -140,7 +140,7 @@ indirect_write_config(struct pci_bus *bu
1893 return PCIBIOS_SUCCESSFUL;
1894 }
1895
1896 -static struct pci_ops indirect_pci_ops = {
1897 +static const struct pci_ops indirect_pci_ops = {
1898 .read = indirect_read_config,
1899 .write = indirect_write_config,
1900 };
1901 diff -urNp linux-2.6.39/arch/microblaze/pci/pci-common.c linux-2.6.39/arch/microblaze/pci/pci-common.c
1902 --- linux-2.6.39/arch/microblaze/pci/pci-common.c 2011-05-19 00:06:34.000000000 -0400
1903 +++ linux-2.6.39/arch/microblaze/pci/pci-common.c 2011-05-22 19:36:30.000000000 -0400
1904 @@ -48,14 +48,14 @@ resource_size_t isa_mem_base;
1905 /* Default PCI flags is 0 on ppc32, modified at boot on ppc64 */
1906 unsigned int pci_flags;
1907
1908 -static struct dma_map_ops *pci_dma_ops = &dma_direct_ops;
1909 +static const struct dma_map_ops *pci_dma_ops = &dma_direct_ops;
1910
1911 -void set_pci_dma_ops(struct dma_map_ops *dma_ops)
1912 +void set_pci_dma_ops(const struct dma_map_ops *dma_ops)
1913 {
1914 pci_dma_ops = dma_ops;
1915 }
1916
1917 -struct dma_map_ops *get_pci_dma_ops(void)
1918 +const struct dma_map_ops *get_pci_dma_ops(void)
1919 {
1920 return pci_dma_ops;
1921 }
1922 @@ -1583,7 +1583,7 @@ null_write_config(struct pci_bus *bus, u
1923 return PCIBIOS_DEVICE_NOT_FOUND;
1924 }
1925
1926 -static struct pci_ops null_pci_ops = {
1927 +static const struct pci_ops null_pci_ops = {
1928 .read = null_read_config,
1929 .write = null_write_config,
1930 };
1931 diff -urNp linux-2.6.39/arch/mips/alchemy/common/pci.c linux-2.6.39/arch/mips/alchemy/common/pci.c
1932 --- linux-2.6.39/arch/mips/alchemy/common/pci.c 2011-05-19 00:06:34.000000000 -0400
1933 +++ linux-2.6.39/arch/mips/alchemy/common/pci.c 2011-05-22 19:36:30.000000000 -0400
1934 @@ -51,7 +51,7 @@ static struct resource pci_mem_resource
1935 .flags = IORESOURCE_MEM
1936 };
1937
1938 -extern struct pci_ops au1x_pci_ops;
1939 +extern const struct pci_ops au1x_pci_ops;
1940
1941 static struct pci_controller au1x_controller = {
1942 .pci_ops = &au1x_pci_ops,
1943 diff -urNp linux-2.6.39/arch/mips/cavium-octeon/dma-octeon.c linux-2.6.39/arch/mips/cavium-octeon/dma-octeon.c
1944 --- linux-2.6.39/arch/mips/cavium-octeon/dma-octeon.c 2011-05-19 00:06:34.000000000 -0400
1945 +++ linux-2.6.39/arch/mips/cavium-octeon/dma-octeon.c 2011-05-22 19:36:30.000000000 -0400
1946 @@ -202,7 +202,7 @@ static phys_addr_t octeon_unity_dma_to_p
1947 }
1948
1949 struct octeon_dma_map_ops {
1950 - struct dma_map_ops dma_map_ops;
1951 + const struct dma_map_ops dma_map_ops;
1952 dma_addr_t (*phys_to_dma)(struct device *dev, phys_addr_t paddr);
1953 phys_addr_t (*dma_to_phys)(struct device *dev, dma_addr_t daddr);
1954 };
1955 @@ -324,7 +324,7 @@ static struct octeon_dma_map_ops _octeon
1956 },
1957 };
1958
1959 -struct dma_map_ops *octeon_pci_dma_map_ops;
1960 +const struct dma_map_ops *octeon_pci_dma_map_ops;
1961
1962 void __init octeon_pci_dma_init(void)
1963 {
1964 diff -urNp linux-2.6.39/arch/mips/cobalt/pci.c linux-2.6.39/arch/mips/cobalt/pci.c
1965 --- linux-2.6.39/arch/mips/cobalt/pci.c 2011-05-19 00:06:34.000000000 -0400
1966 +++ linux-2.6.39/arch/mips/cobalt/pci.c 2011-05-22 19:36:30.000000000 -0400
1967 @@ -14,7 +14,7 @@
1968
1969 #include <asm/gt64120.h>
1970
1971 -extern struct pci_ops gt64xxx_pci0_ops;
1972 +extern const struct pci_ops gt64xxx_pci0_ops;
1973
1974 static struct resource cobalt_mem_resource = {
1975 .start = GT_DEF_PCI0_MEM0_BASE,
1976 diff -urNp linux-2.6.39/arch/mips/include/asm/device.h linux-2.6.39/arch/mips/include/asm/device.h
1977 --- linux-2.6.39/arch/mips/include/asm/device.h 2011-05-19 00:06:34.000000000 -0400
1978 +++ linux-2.6.39/arch/mips/include/asm/device.h 2011-05-22 19:36:30.000000000 -0400
1979 @@ -10,7 +10,7 @@ struct dma_map_ops;
1980
1981 struct dev_archdata {
1982 /* DMA operations on that device */
1983 - struct dma_map_ops *dma_ops;
1984 + const struct dma_map_ops *dma_ops;
1985 };
1986
1987 struct pdev_archdata {
1988 diff -urNp linux-2.6.39/arch/mips/include/asm/dma-mapping.h linux-2.6.39/arch/mips/include/asm/dma-mapping.h
1989 --- linux-2.6.39/arch/mips/include/asm/dma-mapping.h 2011-05-19 00:06:34.000000000 -0400
1990 +++ linux-2.6.39/arch/mips/include/asm/dma-mapping.h 2011-05-22 19:36:30.000000000 -0400
1991 @@ -9,9 +9,9 @@
1992 #include <dma-coherence.h>
1993 #endif
1994
1995 -extern struct dma_map_ops *mips_dma_map_ops;
1996 +extern const struct dma_map_ops *mips_dma_map_ops;
1997
1998 -static inline struct dma_map_ops *get_dma_ops(struct device *dev)
1999 +static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
2000 {
2001 if (dev && dev->archdata.dma_ops)
2002 return dev->archdata.dma_ops;
2003 @@ -33,13 +33,13 @@ static inline void dma_mark_clean(void *
2004
2005 static inline int dma_supported(struct device *dev, u64 mask)
2006 {
2007 - struct dma_map_ops *ops = get_dma_ops(dev);
2008 + const struct dma_map_ops *ops = get_dma_ops(dev);
2009 return ops->dma_supported(dev, mask);
2010 }
2011
2012 static inline int dma_mapping_error(struct device *dev, u64 mask)
2013 {
2014 - struct dma_map_ops *ops = get_dma_ops(dev);
2015 + const struct dma_map_ops *ops = get_dma_ops(dev);
2016 return ops->mapping_error(dev, mask);
2017 }
2018
2019 @@ -61,7 +61,7 @@ static inline void *dma_alloc_coherent(s
2020 dma_addr_t *dma_handle, gfp_t gfp)
2021 {
2022 void *ret;
2023 - struct dma_map_ops *ops = get_dma_ops(dev);
2024 + const struct dma_map_ops *ops = get_dma_ops(dev);
2025
2026 ret = ops->alloc_coherent(dev, size, dma_handle, gfp);
2027
2028 @@ -73,7 +73,7 @@ static inline void *dma_alloc_coherent(s
2029 static inline void dma_free_coherent(struct device *dev, size_t size,
2030 void *vaddr, dma_addr_t dma_handle)
2031 {
2032 - struct dma_map_ops *ops = get_dma_ops(dev);
2033 + const struct dma_map_ops *ops = get_dma_ops(dev);
2034
2035 ops->free_coherent(dev, size, vaddr, dma_handle);
2036
2037 diff -urNp linux-2.6.39/arch/mips/include/asm/elf.h linux-2.6.39/arch/mips/include/asm/elf.h
2038 --- linux-2.6.39/arch/mips/include/asm/elf.h 2011-05-19 00:06:34.000000000 -0400
2039 +++ linux-2.6.39/arch/mips/include/asm/elf.h 2011-05-22 19:36:30.000000000 -0400
2040 @@ -372,13 +372,16 @@ extern const char *__elf_platform;
2041 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2042 #endif
2043
2044 +#ifdef CONFIG_PAX_ASLR
2045 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2046 +
2047 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2048 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2049 +#endif
2050 +
2051 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
2052 struct linux_binprm;
2053 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
2054 int uses_interp);
2055
2056 -struct mm_struct;
2057 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2058 -#define arch_randomize_brk arch_randomize_brk
2059 -
2060 #endif /* _ASM_ELF_H */
2061 diff -urNp linux-2.6.39/arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h linux-2.6.39/arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h
2062 --- linux-2.6.39/arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h 2011-05-19 00:06:34.000000000 -0400
2063 +++ linux-2.6.39/arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h 2011-05-22 19:36:30.000000000 -0400
2064 @@ -66,7 +66,7 @@ dma_addr_t phys_to_dma(struct device *de
2065 phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr);
2066
2067 struct dma_map_ops;
2068 -extern struct dma_map_ops *octeon_pci_dma_map_ops;
2069 +extern const struct dma_map_ops *octeon_pci_dma_map_ops;
2070 extern char *octeon_swiotlb;
2071
2072 #endif /* __ASM_MACH_CAVIUM_OCTEON_DMA_COHERENCE_H */
2073 diff -urNp linux-2.6.39/arch/mips/include/asm/page.h linux-2.6.39/arch/mips/include/asm/page.h
2074 --- linux-2.6.39/arch/mips/include/asm/page.h 2011-05-19 00:06:34.000000000 -0400
2075 +++ linux-2.6.39/arch/mips/include/asm/page.h 2011-05-22 19:36:30.000000000 -0400
2076 @@ -93,7 +93,7 @@ extern void copy_user_highpage(struct pa
2077 #ifdef CONFIG_CPU_MIPS32
2078 typedef struct { unsigned long pte_low, pte_high; } pte_t;
2079 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
2080 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
2081 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
2082 #else
2083 typedef struct { unsigned long long pte; } pte_t;
2084 #define pte_val(x) ((x).pte)
2085 diff -urNp linux-2.6.39/arch/mips/include/asm/pci/bridge.h linux-2.6.39/arch/mips/include/asm/pci/bridge.h
2086 --- linux-2.6.39/arch/mips/include/asm/pci/bridge.h 2011-05-19 00:06:34.000000000 -0400
2087 +++ linux-2.6.39/arch/mips/include/asm/pci/bridge.h 2011-05-22 19:36:30.000000000 -0400
2088 @@ -849,6 +849,6 @@ struct bridge_controller {
2089 extern void register_bridge_irq(unsigned int irq);
2090 extern int request_bridge_irq(struct bridge_controller *bc);
2091
2092 -extern struct pci_ops bridge_pci_ops;
2093 +extern const struct pci_ops bridge_pci_ops;
2094
2095 #endif /* _ASM_PCI_BRIDGE_H */
2096 diff -urNp linux-2.6.39/arch/mips/include/asm/system.h linux-2.6.39/arch/mips/include/asm/system.h
2097 --- linux-2.6.39/arch/mips/include/asm/system.h 2011-05-19 00:06:34.000000000 -0400
2098 +++ linux-2.6.39/arch/mips/include/asm/system.h 2011-05-22 19:36:30.000000000 -0400
2099 @@ -230,6 +230,6 @@ extern void per_cpu_trap_init(void);
2100 */
2101 #define __ARCH_WANT_UNLOCKED_CTXSW
2102
2103 -extern unsigned long arch_align_stack(unsigned long sp);
2104 +#define arch_align_stack(x) ((x) & ~0xfUL)
2105
2106 #endif /* _ASM_SYSTEM_H */
2107 diff -urNp linux-2.6.39/arch/mips/kernel/binfmt_elfn32.c linux-2.6.39/arch/mips/kernel/binfmt_elfn32.c
2108 --- linux-2.6.39/arch/mips/kernel/binfmt_elfn32.c 2011-05-19 00:06:34.000000000 -0400
2109 +++ linux-2.6.39/arch/mips/kernel/binfmt_elfn32.c 2011-05-22 19:36:30.000000000 -0400
2110 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_N
2111 #undef ELF_ET_DYN_BASE
2112 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2113
2114 +#ifdef CONFIG_PAX_ASLR
2115 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2116 +
2117 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2118 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2119 +#endif
2120 +
2121 #include <asm/processor.h>
2122 #include <linux/module.h>
2123 #include <linux/elfcore.h>
2124 diff -urNp linux-2.6.39/arch/mips/kernel/binfmt_elfo32.c linux-2.6.39/arch/mips/kernel/binfmt_elfo32.c
2125 --- linux-2.6.39/arch/mips/kernel/binfmt_elfo32.c 2011-05-19 00:06:34.000000000 -0400
2126 +++ linux-2.6.39/arch/mips/kernel/binfmt_elfo32.c 2011-05-22 19:36:30.000000000 -0400
2127 @@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_N
2128 #undef ELF_ET_DYN_BASE
2129 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2130
2131 +#ifdef CONFIG_PAX_ASLR
2132 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2133 +
2134 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2135 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2136 +#endif
2137 +
2138 #include <asm/processor.h>
2139
2140 /*
2141 diff -urNp linux-2.6.39/arch/mips/kernel/kgdb.c linux-2.6.39/arch/mips/kernel/kgdb.c
2142 --- linux-2.6.39/arch/mips/kernel/kgdb.c 2011-05-19 00:06:34.000000000 -0400
2143 +++ linux-2.6.39/arch/mips/kernel/kgdb.c 2011-05-22 19:36:30.000000000 -0400
2144 @@ -351,7 +351,7 @@ int kgdb_arch_handle_exception(int vecto
2145 return -1;
2146 }
2147
2148 -struct kgdb_arch arch_kgdb_ops;
2149 +struct kgdb_arch arch_kgdb_ops; /* cannot be const, see kgdb_arch_init */
2150
2151 /*
2152 * We use kgdb_early_setup so that functions we need to call now don't
2153 diff -urNp linux-2.6.39/arch/mips/kernel/process.c linux-2.6.39/arch/mips/kernel/process.c
2154 --- linux-2.6.39/arch/mips/kernel/process.c 2011-05-19 00:06:34.000000000 -0400
2155 +++ linux-2.6.39/arch/mips/kernel/process.c 2011-05-22 19:36:30.000000000 -0400
2156 @@ -473,15 +473,3 @@ unsigned long get_wchan(struct task_stru
2157 out:
2158 return pc;
2159 }
2160 -
2161 -/*
2162 - * Don't forget that the stack pointer must be aligned on a 8 bytes
2163 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
2164 - */
2165 -unsigned long arch_align_stack(unsigned long sp)
2166 -{
2167 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
2168 - sp -= get_random_int() & ~PAGE_MASK;
2169 -
2170 - return sp & ALMASK;
2171 -}
2172 diff -urNp linux-2.6.39/arch/mips/kernel/syscall.c linux-2.6.39/arch/mips/kernel/syscall.c
2173 --- linux-2.6.39/arch/mips/kernel/syscall.c 2011-05-19 00:06:34.000000000 -0400
2174 +++ linux-2.6.39/arch/mips/kernel/syscall.c 2011-05-22 19:36:30.000000000 -0400
2175 @@ -108,14 +108,18 @@ unsigned long arch_get_unmapped_area(str
2176 do_color_align = 0;
2177 if (filp || (flags & MAP_SHARED))
2178 do_color_align = 1;
2179 +
2180 +#ifdef CONFIG_PAX_RANDMMAP
2181 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
2182 +#endif
2183 +
2184 if (addr) {
2185 if (do_color_align)
2186 addr = COLOUR_ALIGN(addr, pgoff);
2187 else
2188 addr = PAGE_ALIGN(addr);
2189 vmm = find_vma(current->mm, addr);
2190 - if (task_size - len >= addr &&
2191 - (!vmm || addr + len <= vmm->vm_start))
2192 + if (task_size - len >= addr && check_heap_stack_gap(vmm, addr, len))
2193 return addr;
2194 }
2195 addr = current->mm->mmap_base;
2196 @@ -128,7 +132,7 @@ unsigned long arch_get_unmapped_area(str
2197 /* At this point: (!vmm || addr < vmm->vm_end). */
2198 if (task_size - len < addr)
2199 return -ENOMEM;
2200 - if (!vmm || addr + len <= vmm->vm_start)
2201 + if (check_heap_stack_gap(vmm, addr, len))
2202 return addr;
2203 addr = vmm->vm_end;
2204 if (do_color_align)
2205 @@ -154,33 +158,6 @@ void arch_pick_mmap_layout(struct mm_str
2206 mm->unmap_area = arch_unmap_area;
2207 }
2208
2209 -static inline unsigned long brk_rnd(void)
2210 -{
2211 - unsigned long rnd = get_random_int();
2212 -
2213 - rnd = rnd << PAGE_SHIFT;
2214 - /* 8MB for 32bit, 256MB for 64bit */
2215 - if (TASK_IS_32BIT_ADDR)
2216 - rnd = rnd & 0x7ffffful;
2217 - else
2218 - rnd = rnd & 0xffffffful;
2219 -
2220 - return rnd;
2221 -}
2222 -
2223 -unsigned long arch_randomize_brk(struct mm_struct *mm)
2224 -{
2225 - unsigned long base = mm->brk;
2226 - unsigned long ret;
2227 -
2228 - ret = PAGE_ALIGN(base + brk_rnd());
2229 -
2230 - if (ret < mm->brk)
2231 - return mm->brk;
2232 -
2233 - return ret;
2234 -}
2235 -
2236 SYSCALL_DEFINE6(mips_mmap, unsigned long, addr, unsigned long, len,
2237 unsigned long, prot, unsigned long, flags, unsigned long,
2238 fd, off_t, offset)
2239 diff -urNp linux-2.6.39/arch/mips/mm/dma-default.c linux-2.6.39/arch/mips/mm/dma-default.c
2240 --- linux-2.6.39/arch/mips/mm/dma-default.c 2011-05-19 00:06:34.000000000 -0400
2241 +++ linux-2.6.39/arch/mips/mm/dma-default.c 2011-05-22 19:36:30.000000000 -0400
2242 @@ -300,7 +300,7 @@ void dma_cache_sync(struct device *dev,
2243
2244 EXPORT_SYMBOL(dma_cache_sync);
2245
2246 -static struct dma_map_ops mips_default_dma_map_ops = {
2247 +static const struct dma_map_ops mips_default_dma_map_ops = {
2248 .alloc_coherent = mips_dma_alloc_coherent,
2249 .free_coherent = mips_dma_free_coherent,
2250 .map_page = mips_dma_map_page,
2251 @@ -315,7 +315,7 @@ static struct dma_map_ops mips_default_d
2252 .dma_supported = mips_dma_supported
2253 };
2254
2255 -struct dma_map_ops *mips_dma_map_ops = &mips_default_dma_map_ops;
2256 +const struct dma_map_ops *mips_dma_map_ops = &mips_default_dma_map_ops;
2257 EXPORT_SYMBOL(mips_dma_map_ops);
2258
2259 #define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16)
2260 diff -urNp linux-2.6.39/arch/mips/mm/fault.c linux-2.6.39/arch/mips/mm/fault.c
2261 --- linux-2.6.39/arch/mips/mm/fault.c 2011-05-19 00:06:34.000000000 -0400
2262 +++ linux-2.6.39/arch/mips/mm/fault.c 2011-05-22 19:36:30.000000000 -0400
2263 @@ -28,6 +28,23 @@
2264 #include <asm/highmem.h> /* For VMALLOC_END */
2265 #include <linux/kdebug.h>
2266
2267 +#ifdef CONFIG_PAX_PAGEEXEC
2268 +void pax_report_insns(void *pc, void *sp)
2269 +{
2270 + unsigned long i;
2271 +
2272 + printk(KERN_ERR "PAX: bytes at PC: ");
2273 + for (i = 0; i < 5; i++) {
2274 + unsigned int c;
2275 + if (get_user(c, (unsigned int *)pc+i))
2276 + printk(KERN_CONT "???????? ");
2277 + else
2278 + printk(KERN_CONT "%08x ", c);
2279 + }
2280 + printk("\n");
2281 +}
2282 +#endif
2283 +
2284 /*
2285 * This routine handles page faults. It determines the address,
2286 * and the problem, and then passes it off to one of the appropriate
2287 diff -urNp linux-2.6.39/arch/mips/mti-malta/malta-pci.c linux-2.6.39/arch/mips/mti-malta/malta-pci.c
2288 --- linux-2.6.39/arch/mips/mti-malta/malta-pci.c 2011-05-19 00:06:34.000000000 -0400
2289 +++ linux-2.6.39/arch/mips/mti-malta/malta-pci.c 2011-05-22 19:36:30.000000000 -0400
2290 @@ -64,9 +64,9 @@ static struct resource msc_io_resource =
2291 .flags = IORESOURCE_IO,
2292 };
2293
2294 -extern struct pci_ops bonito64_pci_ops;
2295 -extern struct pci_ops gt64xxx_pci0_ops;
2296 -extern struct pci_ops msc_pci_ops;
2297 +extern const struct pci_ops bonito64_pci_ops;
2298 +extern const struct pci_ops gt64xxx_pci0_ops;
2299 +extern const struct pci_ops msc_pci_ops;
2300
2301 static struct pci_controller bonito64_controller = {
2302 .pci_ops = &bonito64_pci_ops,
2303 diff -urNp linux-2.6.39/arch/mips/nxp/pnx8550/common/pci.c linux-2.6.39/arch/mips/nxp/pnx8550/common/pci.c
2304 --- linux-2.6.39/arch/mips/nxp/pnx8550/common/pci.c 2011-05-19 00:06:34.000000000 -0400
2305 +++ linux-2.6.39/arch/mips/nxp/pnx8550/common/pci.c 2011-05-22 19:36:30.000000000 -0400
2306 @@ -40,7 +40,7 @@ static struct resource pci_mem_resource
2307 .flags = IORESOURCE_MEM
2308 };
2309
2310 -extern struct pci_ops pnx8550_pci_ops;
2311 +extern const struct pci_ops pnx8550_pci_ops;
2312
2313 static struct pci_controller pnx8550_controller = {
2314 .pci_ops = &pnx8550_pci_ops,
2315 diff -urNp linux-2.6.39/arch/mips/pci/ops-au1000.c linux-2.6.39/arch/mips/pci/ops-au1000.c
2316 --- linux-2.6.39/arch/mips/pci/ops-au1000.c 2011-05-19 00:06:34.000000000 -0400
2317 +++ linux-2.6.39/arch/mips/pci/ops-au1000.c 2011-05-22 19:36:30.000000000 -0400
2318 @@ -302,7 +302,7 @@ static int config_write(struct pci_bus *
2319 }
2320 }
2321
2322 -struct pci_ops au1x_pci_ops = {
2323 +const struct pci_ops au1x_pci_ops = {
2324 config_read,
2325 config_write
2326 };
2327 diff -urNp linux-2.6.39/arch/mips/pci/ops-bcm63xx.c linux-2.6.39/arch/mips/pci/ops-bcm63xx.c
2328 --- linux-2.6.39/arch/mips/pci/ops-bcm63xx.c 2011-05-19 00:06:34.000000000 -0400
2329 +++ linux-2.6.39/arch/mips/pci/ops-bcm63xx.c 2011-05-22 19:36:30.000000000 -0400
2330 @@ -173,7 +173,7 @@ static int bcm63xx_pci_write(struct pci_
2331 where, size, val);
2332 }
2333
2334 -struct pci_ops bcm63xx_pci_ops = {
2335 +const struct pci_ops bcm63xx_pci_ops = {
2336 .read = bcm63xx_pci_read,
2337 .write = bcm63xx_pci_write
2338 };
2339 @@ -402,7 +402,7 @@ static int bcm63xx_cb_write(struct pci_b
2340 return PCIBIOS_DEVICE_NOT_FOUND;
2341 }
2342
2343 -struct pci_ops bcm63xx_cb_ops = {
2344 +const struct pci_ops bcm63xx_cb_ops = {
2345 .read = bcm63xx_cb_read,
2346 .write = bcm63xx_cb_write,
2347 };
2348 diff -urNp linux-2.6.39/arch/mips/pci/ops-bonito64.c linux-2.6.39/arch/mips/pci/ops-bonito64.c
2349 --- linux-2.6.39/arch/mips/pci/ops-bonito64.c 2011-05-19 00:06:34.000000000 -0400
2350 +++ linux-2.6.39/arch/mips/pci/ops-bonito64.c 2011-05-22 19:36:30.000000000 -0400
2351 @@ -155,7 +155,7 @@ static int bonito64_pcibios_write(struct
2352 return PCIBIOS_SUCCESSFUL;
2353 }
2354
2355 -struct pci_ops bonito64_pci_ops = {
2356 +const struct pci_ops bonito64_pci_ops = {
2357 .read = bonito64_pcibios_read,
2358 .write = bonito64_pcibios_write
2359 };
2360 diff -urNp linux-2.6.39/arch/mips/pci/ops-bridge.c linux-2.6.39/arch/mips/pci/ops-bridge.c
2361 --- linux-2.6.39/arch/mips/pci/ops-bridge.c 2011-05-19 00:06:34.000000000 -0400
2362 +++ linux-2.6.39/arch/mips/pci/ops-bridge.c 2011-05-22 19:36:30.000000000 -0400
2363 @@ -316,7 +316,7 @@ static int pci_write_config(struct pci_b
2364 return pci_conf0_write_config(bus, devfn, where, size, value);
2365 }
2366
2367 -struct pci_ops bridge_pci_ops = {
2368 +const struct pci_ops bridge_pci_ops = {
2369 .read = pci_read_config,
2370 .write = pci_write_config,
2371 };
2372 diff -urNp linux-2.6.39/arch/mips/pci/ops-emma2rh.c linux-2.6.39/arch/mips/pci/ops-emma2rh.c
2373 --- linux-2.6.39/arch/mips/pci/ops-emma2rh.c 2011-05-19 00:06:34.000000000 -0400
2374 +++ linux-2.6.39/arch/mips/pci/ops-emma2rh.c 2011-05-22 19:36:30.000000000 -0400
2375 @@ -176,7 +176,7 @@ static int pci_config_write(struct pci_b
2376 return PCIBIOS_SUCCESSFUL;
2377 }
2378
2379 -struct pci_ops emma2rh_pci_ops = {
2380 +const struct pci_ops emma2rh_pci_ops = {
2381 .read = pci_config_read,
2382 .write = pci_config_write,
2383 };
2384 diff -urNp linux-2.6.39/arch/mips/pci/ops-gt64xxx_pci0.c linux-2.6.39/arch/mips/pci/ops-gt64xxx_pci0.c
2385 --- linux-2.6.39/arch/mips/pci/ops-gt64xxx_pci0.c 2011-05-19 00:06:34.000000000 -0400
2386 +++ linux-2.6.39/arch/mips/pci/ops-gt64xxx_pci0.c 2011-05-22 19:36:30.000000000 -0400
2387 @@ -146,7 +146,7 @@ static int gt64xxx_pci0_pcibios_write(st
2388 return PCIBIOS_SUCCESSFUL;
2389 }
2390
2391 -struct pci_ops gt64xxx_pci0_ops = {
2392 +const struct pci_ops gt64xxx_pci0_ops = {
2393 .read = gt64xxx_pci0_pcibios_read,
2394 .write = gt64xxx_pci0_pcibios_write
2395 };
2396 diff -urNp linux-2.6.39/arch/mips/pci/ops-loongson2.c linux-2.6.39/arch/mips/pci/ops-loongson2.c
2397 --- linux-2.6.39/arch/mips/pci/ops-loongson2.c 2011-05-19 00:06:34.000000000 -0400
2398 +++ linux-2.6.39/arch/mips/pci/ops-loongson2.c 2011-05-22 19:36:30.000000000 -0400
2399 @@ -174,7 +174,7 @@ static int loongson_pcibios_write(struct
2400 return PCIBIOS_SUCCESSFUL;
2401 }
2402
2403 -struct pci_ops loongson_pci_ops = {
2404 +const struct pci_ops loongson_pci_ops = {
2405 .read = loongson_pcibios_read,
2406 .write = loongson_pcibios_write
2407 };
2408 diff -urNp linux-2.6.39/arch/mips/pci/ops-mace.c linux-2.6.39/arch/mips/pci/ops-mace.c
2409 --- linux-2.6.39/arch/mips/pci/ops-mace.c 2011-05-19 00:06:34.000000000 -0400
2410 +++ linux-2.6.39/arch/mips/pci/ops-mace.c 2011-05-22 19:36:30.000000000 -0400
2411 @@ -96,7 +96,7 @@ mace_pci_write_config(struct pci_bus *bu
2412 return PCIBIOS_SUCCESSFUL;
2413 }
2414
2415 -struct pci_ops mace_pci_ops = {
2416 +const struct pci_ops mace_pci_ops = {
2417 .read = mace_pci_read_config,
2418 .write = mace_pci_write_config,
2419 };
2420 diff -urNp linux-2.6.39/arch/mips/pci/ops-msc.c linux-2.6.39/arch/mips/pci/ops-msc.c
2421 --- linux-2.6.39/arch/mips/pci/ops-msc.c 2011-05-19 00:06:34.000000000 -0400
2422 +++ linux-2.6.39/arch/mips/pci/ops-msc.c 2011-05-22 19:36:30.000000000 -0400
2423 @@ -142,7 +142,7 @@ static int msc_pcibios_write(struct pci_
2424 return PCIBIOS_SUCCESSFUL;
2425 }
2426
2427 -struct pci_ops msc_pci_ops = {
2428 +const struct pci_ops msc_pci_ops = {
2429 .read = msc_pcibios_read,
2430 .write = msc_pcibios_write
2431 };
2432 diff -urNp linux-2.6.39/arch/mips/pci/ops-nile4.c linux-2.6.39/arch/mips/pci/ops-nile4.c
2433 --- linux-2.6.39/arch/mips/pci/ops-nile4.c 2011-05-19 00:06:34.000000000 -0400
2434 +++ linux-2.6.39/arch/mips/pci/ops-nile4.c 2011-05-22 19:36:30.000000000 -0400
2435 @@ -141,7 +141,7 @@ static int nile4_pcibios_write(struct pc
2436 return PCIBIOS_SUCCESSFUL;
2437 }
2438
2439 -struct pci_ops nile4_pci_ops = {
2440 +const struct pci_ops nile4_pci_ops = {
2441 .read = nile4_pcibios_read,
2442 .write = nile4_pcibios_write,
2443 };
2444 diff -urNp linux-2.6.39/arch/mips/pci/ops-pmcmsp.c linux-2.6.39/arch/mips/pci/ops-pmcmsp.c
2445 --- linux-2.6.39/arch/mips/pci/ops-pmcmsp.c 2011-05-19 00:06:34.000000000 -0400
2446 +++ linux-2.6.39/arch/mips/pci/ops-pmcmsp.c 2011-05-22 19:36:30.000000000 -0400
2447 @@ -904,7 +904,7 @@ msp_pcibios_write_config(struct pci_bus
2448 * write - function for Linux to generate PCI Configuration writes.
2449 *
2450 ****************************************************************************/
2451 -struct pci_ops msp_pci_ops = {
2452 +const struct pci_ops msp_pci_ops = {
2453 .read = msp_pcibios_read_config,
2454 .write = msp_pcibios_write_config
2455 };
2456 diff -urNp linux-2.6.39/arch/mips/pci/ops-pnx8550.c linux-2.6.39/arch/mips/pci/ops-pnx8550.c
2457 --- linux-2.6.39/arch/mips/pci/ops-pnx8550.c 2011-05-19 00:06:34.000000000 -0400
2458 +++ linux-2.6.39/arch/mips/pci/ops-pnx8550.c 2011-05-22 19:36:30.000000000 -0400
2459 @@ -276,7 +276,7 @@ static int config_write(struct pci_bus *
2460 }
2461 }
2462
2463 -struct pci_ops pnx8550_pci_ops = {
2464 +const struct pci_ops pnx8550_pci_ops = {
2465 config_read,
2466 config_write
2467 };
2468 diff -urNp linux-2.6.39/arch/mips/pci/ops-rc32434.c linux-2.6.39/arch/mips/pci/ops-rc32434.c
2469 --- linux-2.6.39/arch/mips/pci/ops-rc32434.c 2011-05-19 00:06:34.000000000 -0400
2470 +++ linux-2.6.39/arch/mips/pci/ops-rc32434.c 2011-05-22 19:36:30.000000000 -0400
2471 @@ -201,7 +201,7 @@ static int pci_config_write(struct pci_b
2472 }
2473 }
2474
2475 -struct pci_ops rc32434_pci_ops = {
2476 +const struct pci_ops rc32434_pci_ops = {
2477 .read = pci_config_read,
2478 .write = pci_config_write,
2479 };
2480 diff -urNp linux-2.6.39/arch/mips/pci/ops-sni.c linux-2.6.39/arch/mips/pci/ops-sni.c
2481 --- linux-2.6.39/arch/mips/pci/ops-sni.c 2011-05-19 00:06:34.000000000 -0400
2482 +++ linux-2.6.39/arch/mips/pci/ops-sni.c 2011-05-22 19:36:30.000000000 -0400
2483 @@ -83,7 +83,7 @@ static int pcimt_write(struct pci_bus *b
2484 return 0;
2485 }
2486
2487 -struct pci_ops sni_pcimt_ops = {
2488 +const struct pci_ops sni_pcimt_ops = {
2489 .read = pcimt_read,
2490 .write = pcimt_write,
2491 };
2492 @@ -158,7 +158,7 @@ static int pcit_write(struct pci_bus *bu
2493 }
2494
2495
2496 -struct pci_ops sni_pcit_ops = {
2497 +const struct pci_ops sni_pcit_ops = {
2498 .read = pcit_read,
2499 .write = pcit_write,
2500 };
2501 diff -urNp linux-2.6.39/arch/mips/pci/ops-titan.c linux-2.6.39/arch/mips/pci/ops-titan.c
2502 --- linux-2.6.39/arch/mips/pci/ops-titan.c 2011-05-19 00:06:34.000000000 -0400
2503 +++ linux-2.6.39/arch/mips/pci/ops-titan.c 2011-05-22 19:36:30.000000000 -0400
2504 @@ -105,7 +105,7 @@ static int titan_write_config(struct pci
2505 /*
2506 * Titan PCI structure
2507 */
2508 -struct pci_ops titan_pci_ops = {
2509 +const struct pci_ops titan_pci_ops = {
2510 titan_read_config,
2511 titan_write_config,
2512 };
2513 diff -urNp linux-2.6.39/arch/mips/pci/ops-titan-ht.c linux-2.6.39/arch/mips/pci/ops-titan-ht.c
2514 --- linux-2.6.39/arch/mips/pci/ops-titan-ht.c 2011-05-19 00:06:34.000000000 -0400
2515 +++ linux-2.6.39/arch/mips/pci/ops-titan-ht.c 2011-05-22 19:36:30.000000000 -0400
2516 @@ -118,7 +118,7 @@ static int titan_ht_config_write(struct
2517 return PCIBIOS_SUCCESSFUL;
2518 }
2519
2520 -struct pci_ops titan_ht_pci_ops = {
2521 +const struct pci_ops titan_ht_pci_ops = {
2522 .read = titan_ht_config_read,
2523 .write = titan_ht_config_write,
2524 };
2525 diff -urNp linux-2.6.39/arch/mips/pci/ops-tx3927.c linux-2.6.39/arch/mips/pci/ops-tx3927.c
2526 --- linux-2.6.39/arch/mips/pci/ops-tx3927.c 2011-05-19 00:06:34.000000000 -0400
2527 +++ linux-2.6.39/arch/mips/pci/ops-tx3927.c 2011-05-22 19:36:30.000000000 -0400
2528 @@ -121,7 +121,7 @@ static int tx3927_pci_write_config(struc
2529 return check_abort();
2530 }
2531
2532 -static struct pci_ops tx3927_pci_ops = {
2533 +static const struct pci_ops tx3927_pci_ops = {
2534 .read = tx3927_pci_read_config,
2535 .write = tx3927_pci_write_config,
2536 };
2537 diff -urNp linux-2.6.39/arch/mips/pci/ops-vr41xx.c linux-2.6.39/arch/mips/pci/ops-vr41xx.c
2538 --- linux-2.6.39/arch/mips/pci/ops-vr41xx.c 2011-05-19 00:06:34.000000000 -0400
2539 +++ linux-2.6.39/arch/mips/pci/ops-vr41xx.c 2011-05-22 19:36:30.000000000 -0400
2540 @@ -120,7 +120,7 @@ static int pci_config_write(struct pci_b
2541 return PCIBIOS_SUCCESSFUL;
2542 }
2543
2544 -struct pci_ops vr41xx_pci_ops = {
2545 +const struct pci_ops vr41xx_pci_ops = {
2546 .read = pci_config_read,
2547 .write = pci_config_write,
2548 };
2549 diff -urNp linux-2.6.39/arch/mips/pci/pci-bcm1480.c linux-2.6.39/arch/mips/pci/pci-bcm1480.c
2550 --- linux-2.6.39/arch/mips/pci/pci-bcm1480.c 2011-05-19 00:06:34.000000000 -0400
2551 +++ linux-2.6.39/arch/mips/pci/pci-bcm1480.c 2011-05-22 19:36:30.000000000 -0400
2552 @@ -171,7 +171,7 @@ static int bcm1480_pcibios_write(struct
2553 return PCIBIOS_SUCCESSFUL;
2554 }
2555
2556 -struct pci_ops bcm1480_pci_ops = {
2557 +const struct pci_ops bcm1480_pci_ops = {
2558 bcm1480_pcibios_read,
2559 bcm1480_pcibios_write,
2560 };
2561 diff -urNp linux-2.6.39/arch/mips/pci/pci-bcm1480ht.c linux-2.6.39/arch/mips/pci/pci-bcm1480ht.c
2562 --- linux-2.6.39/arch/mips/pci/pci-bcm1480ht.c 2011-05-19 00:06:34.000000000 -0400
2563 +++ linux-2.6.39/arch/mips/pci/pci-bcm1480ht.c 2011-05-22 19:36:30.000000000 -0400
2564 @@ -166,7 +166,7 @@ static int bcm1480ht_pcibios_get_busno(v
2565 return 0;
2566 }
2567
2568 -struct pci_ops bcm1480ht_pci_ops = {
2569 +const struct pci_ops bcm1480ht_pci_ops = {
2570 .read = bcm1480ht_pcibios_read,
2571 .write = bcm1480ht_pcibios_write,
2572 };
2573 diff -urNp linux-2.6.39/arch/mips/pci/pci-bcm63xx.h linux-2.6.39/arch/mips/pci/pci-bcm63xx.h
2574 --- linux-2.6.39/arch/mips/pci/pci-bcm63xx.h 2011-05-19 00:06:34.000000000 -0400
2575 +++ linux-2.6.39/arch/mips/pci/pci-bcm63xx.h 2011-05-22 19:36:30.000000000 -0400
2576 @@ -16,8 +16,8 @@
2577 /*
2578 * defined in ops-bcm63xx.c
2579 */
2580 -extern struct pci_ops bcm63xx_pci_ops;
2581 -extern struct pci_ops bcm63xx_cb_ops;
2582 +extern const struct pci_ops bcm63xx_pci_ops;
2583 +extern const struct pci_ops bcm63xx_cb_ops;
2584
2585 /*
2586 * defined in pci-bcm63xx.c
2587 diff -urNp linux-2.6.39/arch/mips/pci/pci-emma2rh.c linux-2.6.39/arch/mips/pci/pci-emma2rh.c
2588 --- linux-2.6.39/arch/mips/pci/pci-emma2rh.c 2011-05-19 00:06:34.000000000 -0400
2589 +++ linux-2.6.39/arch/mips/pci/pci-emma2rh.c 2011-05-22 19:36:30.000000000 -0400
2590 @@ -43,7 +43,7 @@ static struct resource pci_mem_resource
2591 .flags = IORESOURCE_MEM,
2592 };
2593
2594 -extern struct pci_ops emma2rh_pci_ops;
2595 +extern const struct pci_ops emma2rh_pci_ops;
2596
2597 static struct pci_controller emma2rh_pci_controller = {
2598 .pci_ops = &emma2rh_pci_ops,
2599 diff -urNp linux-2.6.39/arch/mips/pci/pcie-octeon.c linux-2.6.39/arch/mips/pci/pcie-octeon.c
2600 --- linux-2.6.39/arch/mips/pci/pcie-octeon.c 2011-05-19 00:06:34.000000000 -0400
2601 +++ linux-2.6.39/arch/mips/pci/pcie-octeon.c 2011-05-22 19:36:30.000000000 -0400
2602 @@ -1237,7 +1237,7 @@ static int octeon_pcie1_write_config(str
2603 return octeon_pcie_write_config(1, bus, devfn, reg, size, val);
2604 }
2605
2606 -static struct pci_ops octeon_pcie0_ops = {
2607 +static const struct pci_ops octeon_pcie0_ops = {
2608 octeon_pcie0_read_config,
2609 octeon_pcie0_write_config,
2610 };
2611 @@ -1258,7 +1258,7 @@ static struct pci_controller octeon_pcie
2612 .io_resource = &octeon_pcie0_io_resource,
2613 };
2614
2615 -static struct pci_ops octeon_pcie1_ops = {
2616 +static const struct pci_ops octeon_pcie1_ops = {
2617 octeon_pcie1_read_config,
2618 octeon_pcie1_write_config,
2619 };
2620 diff -urNp linux-2.6.39/arch/mips/pci/pci-ip27.c linux-2.6.39/arch/mips/pci/pci-ip27.c
2621 --- linux-2.6.39/arch/mips/pci/pci-ip27.c 2011-05-19 00:06:34.000000000 -0400
2622 +++ linux-2.6.39/arch/mips/pci/pci-ip27.c 2011-05-22 19:36:30.000000000 -0400
2623 @@ -39,7 +39,7 @@ static struct bridge_controller bridges[
2624 struct bridge_controller *irq_to_bridge[MAX_PCI_BUSSES * MAX_DEVICES_PER_PCIBUS];
2625 int irq_to_slot[MAX_PCI_BUSSES * MAX_DEVICES_PER_PCIBUS];
2626
2627 -extern struct pci_ops bridge_pci_ops;
2628 +extern const struct pci_ops bridge_pci_ops;
2629
2630 int __cpuinit bridge_probe(nasid_t nasid, int widget_id, int masterwid)
2631 {
2632 diff -urNp linux-2.6.39/arch/mips/pci/pci-ip32.c linux-2.6.39/arch/mips/pci/pci-ip32.c
2633 --- linux-2.6.39/arch/mips/pci/pci-ip32.c 2011-05-19 00:06:34.000000000 -0400
2634 +++ linux-2.6.39/arch/mips/pci/pci-ip32.c 2011-05-22 19:36:30.000000000 -0400
2635 @@ -82,7 +82,7 @@ static irqreturn_t macepci_error(int irq
2636 }
2637
2638
2639 -extern struct pci_ops mace_pci_ops;
2640 +extern const struct pci_ops mace_pci_ops;
2641 #ifdef CONFIG_64BIT
2642 static struct resource mace_pci_mem_resource = {
2643 .name = "SGI O2 PCI MEM",
2644 diff -urNp linux-2.6.39/arch/mips/pci/pci-lasat.c linux-2.6.39/arch/mips/pci/pci-lasat.c
2645 --- linux-2.6.39/arch/mips/pci/pci-lasat.c 2011-05-19 00:06:34.000000000 -0400
2646 +++ linux-2.6.39/arch/mips/pci/pci-lasat.c 2011-05-22 19:36:30.000000000 -0400
2647 @@ -14,8 +14,8 @@
2648
2649 #include <irq.h>
2650
2651 -extern struct pci_ops nile4_pci_ops;
2652 -extern struct pci_ops gt64xxx_pci0_ops;
2653 +extern const struct pci_ops nile4_pci_ops;
2654 +extern const struct pci_ops gt64xxx_pci0_ops;
2655 static struct resource lasat_pci_mem_resource = {
2656 .name = "LASAT PCI MEM",
2657 .start = 0x18000000,
2658 diff -urNp linux-2.6.39/arch/mips/pci/pci-octeon.c linux-2.6.39/arch/mips/pci/pci-octeon.c
2659 --- linux-2.6.39/arch/mips/pci/pci-octeon.c 2011-05-19 00:06:34.000000000 -0400
2660 +++ linux-2.6.39/arch/mips/pci/pci-octeon.c 2011-05-22 19:36:30.000000000 -0400
2661 @@ -334,7 +334,7 @@ static int octeon_write_config(struct pc
2662 }
2663
2664
2665 -static struct pci_ops octeon_pci_ops = {
2666 +static const struct pci_ops octeon_pci_ops = {
2667 octeon_read_config,
2668 octeon_write_config,
2669 };
2670 diff -urNp linux-2.6.39/arch/mips/pci/pci-rc32434.c linux-2.6.39/arch/mips/pci/pci-rc32434.c
2671 --- linux-2.6.39/arch/mips/pci/pci-rc32434.c 2011-05-19 00:06:34.000000000 -0400
2672 +++ linux-2.6.39/arch/mips/pci/pci-rc32434.c 2011-05-22 19:36:30.000000000 -0400
2673 @@ -75,7 +75,7 @@ static struct resource rc32434_res_pci_i
2674 .flags = IORESOURCE_IO,
2675 };
2676
2677 -extern struct pci_ops rc32434_pci_ops;
2678 +extern const struct pci_ops rc32434_pci_ops;
2679
2680 #define PCI_MEM1_START PCI_ADDR_START
2681 #define PCI_MEM1_END (PCI_ADDR_START + CPUTOPCI_MEM_WIN - 1)
2682 diff -urNp linux-2.6.39/arch/mips/pci/pci-sb1250.c linux-2.6.39/arch/mips/pci/pci-sb1250.c
2683 --- linux-2.6.39/arch/mips/pci/pci-sb1250.c 2011-05-19 00:06:34.000000000 -0400
2684 +++ linux-2.6.39/arch/mips/pci/pci-sb1250.c 2011-05-22 19:36:30.000000000 -0400
2685 @@ -181,7 +181,7 @@ static int sb1250_pcibios_write(struct p
2686 return PCIBIOS_SUCCESSFUL;
2687 }
2688
2689 -struct pci_ops sb1250_pci_ops = {
2690 +const struct pci_ops sb1250_pci_ops = {
2691 .read = sb1250_pcibios_read,
2692 .write = sb1250_pcibios_write,
2693 };
2694 diff -urNp linux-2.6.39/arch/mips/pci/pci-vr41xx.c linux-2.6.39/arch/mips/pci/pci-vr41xx.c
2695 --- linux-2.6.39/arch/mips/pci/pci-vr41xx.c 2011-05-19 00:06:34.000000000 -0400
2696 +++ linux-2.6.39/arch/mips/pci/pci-vr41xx.c 2011-05-22 19:36:30.000000000 -0400
2697 @@ -36,7 +36,7 @@
2698
2699 #include "pci-vr41xx.h"
2700
2701 -extern struct pci_ops vr41xx_pci_ops;
2702 +extern const struct pci_ops vr41xx_pci_ops;
2703
2704 static void __iomem *pciu_base;
2705
2706 diff -urNp linux-2.6.39/arch/mips/pci/pci-yosemite.c linux-2.6.39/arch/mips/pci/pci-yosemite.c
2707 --- linux-2.6.39/arch/mips/pci/pci-yosemite.c 2011-05-19 00:06:34.000000000 -0400
2708 +++ linux-2.6.39/arch/mips/pci/pci-yosemite.c 2011-05-22 19:36:30.000000000 -0400
2709 @@ -11,7 +11,7 @@
2710 #include <linux/pci.h>
2711 #include <asm/titan_dep.h>
2712
2713 -extern struct pci_ops titan_pci_ops;
2714 +extern const struct pci_ops titan_pci_ops;
2715
2716 static struct resource py_mem_resource = {
2717 .start = 0xe0000000UL,
2718 diff -urNp linux-2.6.39/arch/mips/pmc-sierra/yosemite/ht.c linux-2.6.39/arch/mips/pmc-sierra/yosemite/ht.c
2719 --- linux-2.6.39/arch/mips/pmc-sierra/yosemite/ht.c 2011-05-19 00:06:34.000000000 -0400
2720 +++ linux-2.6.39/arch/mips/pmc-sierra/yosemite/ht.c 2011-05-22 19:36:30.000000000 -0400
2721 @@ -366,7 +366,7 @@ resource_size_t pcibios_align_resource(v
2722 return start;
2723 }
2724
2725 -struct pci_ops titan_pci_ops = {
2726 +const struct pci_ops titan_pci_ops = {
2727 titan_ht_config_read_byte,
2728 titan_ht_config_read_word,
2729 titan_ht_config_read_dword,
2730 diff -urNp linux-2.6.39/arch/mips/pnx8550/common/pci.c linux-2.6.39/arch/mips/pnx8550/common/pci.c
2731 --- linux-2.6.39/arch/mips/pnx8550/common/pci.c 2011-05-19 00:06:34.000000000 -0400
2732 +++ linux-2.6.39/arch/mips/pnx8550/common/pci.c 2011-05-22 19:36:30.000000000 -0400
2733 @@ -40,7 +40,7 @@ static struct resource pci_mem_resource
2734 .flags = IORESOURCE_MEM
2735 };
2736
2737 -extern struct pci_ops pnx8550_pci_ops;
2738 +extern const struct pci_ops pnx8550_pci_ops;
2739
2740 static struct pci_controller pnx8550_controller = {
2741 .pci_ops = &pnx8550_pci_ops,
2742 diff -urNp linux-2.6.39/arch/mips/sni/pcimt.c linux-2.6.39/arch/mips/sni/pcimt.c
2743 --- linux-2.6.39/arch/mips/sni/pcimt.c 2011-05-19 00:06:34.000000000 -0400
2744 +++ linux-2.6.39/arch/mips/sni/pcimt.c 2011-05-22 19:36:30.000000000 -0400
2745 @@ -183,7 +183,7 @@ static void __init sni_pcimt_resource_in
2746 request_resource(&sni_mem_resource, pcimt_mem_resources + i);
2747 }
2748
2749 -extern struct pci_ops sni_pcimt_ops;
2750 +extern const struct pci_ops sni_pcimt_ops;
2751
2752 static struct pci_controller sni_controller = {
2753 .pci_ops = &sni_pcimt_ops,
2754 diff -urNp linux-2.6.39/arch/mips/sni/pcit.c linux-2.6.39/arch/mips/sni/pcit.c
2755 --- linux-2.6.39/arch/mips/sni/pcit.c 2011-05-19 00:06:34.000000000 -0400
2756 +++ linux-2.6.39/arch/mips/sni/pcit.c 2011-05-22 19:36:30.000000000 -0400
2757 @@ -145,7 +145,7 @@ static void __init sni_pcit_resource_ini
2758 }
2759
2760
2761 -extern struct pci_ops sni_pcit_ops;
2762 +extern const struct pci_ops sni_pcit_ops;
2763
2764 static struct pci_controller sni_pcit_controller = {
2765 .pci_ops = &sni_pcit_ops,
2766 diff -urNp linux-2.6.39/arch/mips/wrppmc/pci.c linux-2.6.39/arch/mips/wrppmc/pci.c
2767 --- linux-2.6.39/arch/mips/wrppmc/pci.c 2011-05-19 00:06:34.000000000 -0400
2768 +++ linux-2.6.39/arch/mips/wrppmc/pci.c 2011-05-22 19:36:30.000000000 -0400
2769 @@ -14,7 +14,7 @@
2770
2771 #include <asm/gt64120.h>
2772
2773 -extern struct pci_ops gt64xxx_pci0_ops;
2774 +extern const struct pci_ops gt64xxx_pci0_ops;
2775
2776 static struct resource pci0_io_resource = {
2777 .name = "pci_0 io",
2778 diff -urNp linux-2.6.39/arch/mn10300/unit-asb2305/pci-asb2305.h linux-2.6.39/arch/mn10300/unit-asb2305/pci-asb2305.h
2779 --- linux-2.6.39/arch/mn10300/unit-asb2305/pci-asb2305.h 2011-05-19 00:06:34.000000000 -0400
2780 +++ linux-2.6.39/arch/mn10300/unit-asb2305/pci-asb2305.h 2011-05-22 19:36:30.000000000 -0400
2781 @@ -39,7 +39,7 @@ extern void pcibios_resource_survey(void
2782
2783 extern int pcibios_last_bus;
2784 extern struct pci_bus *pci_root_bus;
2785 -extern struct pci_ops *pci_root_ops;
2786 +extern const struct pci_ops *pci_root_ops;
2787
2788 extern struct irq_routing_table *pcibios_get_irq_routing_table(void);
2789 extern int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq);
2790 diff -urNp linux-2.6.39/arch/mn10300/unit-asb2305/pci.c linux-2.6.39/arch/mn10300/unit-asb2305/pci.c
2791 --- linux-2.6.39/arch/mn10300/unit-asb2305/pci.c 2011-05-19 00:06:34.000000000 -0400
2792 +++ linux-2.6.39/arch/mn10300/unit-asb2305/pci.c 2011-05-22 19:36:30.000000000 -0400
2793 @@ -24,7 +24,7 @@ unsigned int pci_probe = 1;
2794
2795 int pcibios_last_bus = -1;
2796 struct pci_bus *pci_root_bus;
2797 -struct pci_ops *pci_root_ops;
2798 +const struct pci_ops *pci_root_ops;
2799
2800 /*
2801 * The accessible PCI window does not cover the entire CPU address space, but
2802 @@ -274,7 +274,7 @@ static int pci_ampci_write_config(struct
2803 }
2804 }
2805
2806 -static struct pci_ops pci_direct_ampci = {
2807 +static const struct pci_ops pci_direct_ampci = {
2808 pci_ampci_read_config,
2809 pci_ampci_write_config,
2810 };
2811 @@ -289,7 +289,7 @@ static struct pci_ops pci_direct_ampci =
2812 * This should be close to trivial, but it isn't, because there are buggy
2813 * chipsets (yes, you guessed it, by Intel and Compaq) that have no class ID.
2814 */
2815 -static int __init pci_sanity_check(struct pci_ops *o)
2816 +static int __init pci_sanity_check(const struct pci_ops *o)
2817 {
2818 struct pci_bus bus; /* Fake bus and device */
2819 u32 x;
2820 diff -urNp linux-2.6.39/arch/parisc/include/asm/elf.h linux-2.6.39/arch/parisc/include/asm/elf.h
2821 --- linux-2.6.39/arch/parisc/include/asm/elf.h 2011-05-19 00:06:34.000000000 -0400
2822 +++ linux-2.6.39/arch/parisc/include/asm/elf.h 2011-05-22 19:36:30.000000000 -0400
2823 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration..
2824
2825 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
2826
2827 +#ifdef CONFIG_PAX_ASLR
2828 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
2829 +
2830 +#define PAX_DELTA_MMAP_LEN 16
2831 +#define PAX_DELTA_STACK_LEN 16
2832 +#endif
2833 +
2834 /* This yields a mask that user programs can use to figure out what
2835 instruction set this CPU supports. This could be done in user space,
2836 but it's not easy, and we've already done it here. */
2837 diff -urNp linux-2.6.39/arch/parisc/include/asm/pgtable.h linux-2.6.39/arch/parisc/include/asm/pgtable.h
2838 --- linux-2.6.39/arch/parisc/include/asm/pgtable.h 2011-05-19 00:06:34.000000000 -0400
2839 +++ linux-2.6.39/arch/parisc/include/asm/pgtable.h 2011-05-22 19:36:30.000000000 -0400
2840 @@ -207,6 +207,17 @@ struct vm_area_struct;
2841 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
2842 #define PAGE_COPY PAGE_EXECREAD
2843 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
2844 +
2845 +#ifdef CONFIG_PAX_PAGEEXEC
2846 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
2847 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
2848 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
2849 +#else
2850 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
2851 +# define PAGE_COPY_NOEXEC PAGE_COPY
2852 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
2853 +#endif
2854 +
2855 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
2856 #define PAGE_KERNEL_RO __pgprot(_PAGE_KERNEL & ~_PAGE_WRITE)
2857 #define PAGE_KERNEL_UNC __pgprot(_PAGE_KERNEL | _PAGE_NO_CACHE)
2858 diff -urNp linux-2.6.39/arch/parisc/kernel/module.c linux-2.6.39/arch/parisc/kernel/module.c
2859 --- linux-2.6.39/arch/parisc/kernel/module.c 2011-05-19 00:06:34.000000000 -0400
2860 +++ linux-2.6.39/arch/parisc/kernel/module.c 2011-05-22 19:36:30.000000000 -0400
2861 @@ -96,16 +96,38 @@
2862
2863 /* three functions to determine where in the module core
2864 * or init pieces the location is */
2865 +static inline int in_init_rx(struct module *me, void *loc)
2866 +{
2867 + return (loc >= me->module_init_rx &&
2868 + loc < (me->module_init_rx + me->init_size_rx));
2869 +}
2870 +
2871 +static inline int in_init_rw(struct module *me, void *loc)
2872 +{
2873 + return (loc >= me->module_init_rw &&
2874 + loc < (me->module_init_rw + me->init_size_rw));
2875 +}
2876 +
2877 static inline int in_init(struct module *me, void *loc)
2878 {
2879 - return (loc >= me->module_init &&
2880 - loc <= (me->module_init + me->init_size));
2881 + return in_init_rx(me, loc) || in_init_rw(me, loc);
2882 +}
2883 +
2884 +static inline int in_core_rx(struct module *me, void *loc)
2885 +{
2886 + return (loc >= me->module_core_rx &&
2887 + loc < (me->module_core_rx + me->core_size_rx));
2888 +}
2889 +
2890 +static inline int in_core_rw(struct module *me, void *loc)
2891 +{
2892 + return (loc >= me->module_core_rw &&
2893 + loc < (me->module_core_rw + me->core_size_rw));
2894 }
2895
2896 static inline int in_core(struct module *me, void *loc)
2897 {
2898 - return (loc >= me->module_core &&
2899 - loc <= (me->module_core + me->core_size));
2900 + return in_core_rx(me, loc) || in_core_rw(me, loc);
2901 }
2902
2903 static inline int in_local(struct module *me, void *loc)
2904 @@ -365,13 +387,13 @@ int module_frob_arch_sections(CONST Elf_
2905 }
2906
2907 /* align things a bit */
2908 - me->core_size = ALIGN(me->core_size, 16);
2909 - me->arch.got_offset = me->core_size;
2910 - me->core_size += gots * sizeof(struct got_entry);
2911 -
2912 - me->core_size = ALIGN(me->core_size, 16);
2913 - me->arch.fdesc_offset = me->core_size;
2914 - me->core_size += fdescs * sizeof(Elf_Fdesc);
2915 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
2916 + me->arch.got_offset = me->core_size_rw;
2917 + me->core_size_rw += gots * sizeof(struct got_entry);
2918 +
2919 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
2920 + me->arch.fdesc_offset = me->core_size_rw;
2921 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
2922
2923 me->arch.got_max = gots;
2924 me->arch.fdesc_max = fdescs;
2925 @@ -389,7 +411,7 @@ static Elf64_Word get_got(struct module
2926
2927 BUG_ON(value == 0);
2928
2929 - got = me->module_core + me->arch.got_offset;
2930 + got = me->module_core_rw + me->arch.got_offset;
2931 for (i = 0; got[i].addr; i++)
2932 if (got[i].addr == value)
2933 goto out;
2934 @@ -407,7 +429,7 @@ static Elf64_Word get_got(struct module
2935 #ifdef CONFIG_64BIT
2936 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
2937 {
2938 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
2939 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
2940
2941 if (!value) {
2942 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
2943 @@ -425,7 +447,7 @@ static Elf_Addr get_fdesc(struct module
2944
2945 /* Create new one */
2946 fdesc->addr = value;
2947 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
2948 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
2949 return (Elf_Addr)fdesc;
2950 }
2951 #endif /* CONFIG_64BIT */
2952 @@ -849,7 +871,7 @@ register_unwind_table(struct module *me,
2953
2954 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
2955 end = table + sechdrs[me->arch.unwind_section].sh_size;
2956 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
2957 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
2958
2959 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
2960 me->arch.unwind_section, table, end, gp);
2961 diff -urNp linux-2.6.39/arch/parisc/kernel/sys_parisc.c linux-2.6.39/arch/parisc/kernel/sys_parisc.c
2962 --- linux-2.6.39/arch/parisc/kernel/sys_parisc.c 2011-05-19 00:06:34.000000000 -0400
2963 +++ linux-2.6.39/arch/parisc/kernel/sys_parisc.c 2011-05-22 19:36:30.000000000 -0400
2964 @@ -43,7 +43,7 @@ static unsigned long get_unshared_area(u
2965 /* At this point: (!vma || addr < vma->vm_end). */
2966 if (TASK_SIZE - len < addr)
2967 return -ENOMEM;
2968 - if (!vma || addr + len <= vma->vm_start)
2969 + if (check_heap_stack_gap(vma, addr, len))
2970 return addr;
2971 addr = vma->vm_end;
2972 }
2973 @@ -79,7 +79,7 @@ static unsigned long get_shared_area(str
2974 /* At this point: (!vma || addr < vma->vm_end). */
2975 if (TASK_SIZE - len < addr)
2976 return -ENOMEM;
2977 - if (!vma || addr + len <= vma->vm_start)
2978 + if (check_heap_stack_gap(vma, addr, len))
2979 return addr;
2980 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
2981 if (addr < vma->vm_end) /* handle wraparound */
2982 @@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(str
2983 if (flags & MAP_FIXED)
2984 return addr;
2985 if (!addr)
2986 - addr = TASK_UNMAPPED_BASE;
2987 + addr = current->mm->mmap_base;
2988
2989 if (filp) {
2990 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
2991 diff -urNp linux-2.6.39/arch/parisc/kernel/traps.c linux-2.6.39/arch/parisc/kernel/traps.c
2992 --- linux-2.6.39/arch/parisc/kernel/traps.c 2011-05-19 00:06:34.000000000 -0400
2993 +++ linux-2.6.39/arch/parisc/kernel/traps.c 2011-05-22 19:36:30.000000000 -0400
2994 @@ -733,9 +733,7 @@ void notrace handle_interruption(int cod
2995
2996 down_read(&current->mm->mmap_sem);
2997 vma = find_vma(current->mm,regs->iaoq[0]);
2998 - if (vma && (regs->iaoq[0] >= vma->vm_start)
2999 - && (vma->vm_flags & VM_EXEC)) {
3000 -
3001 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
3002 fault_address = regs->iaoq[0];
3003 fault_space = regs->iasq[0];
3004
3005 diff -urNp linux-2.6.39/arch/parisc/mm/fault.c linux-2.6.39/arch/parisc/mm/fault.c
3006 --- linux-2.6.39/arch/parisc/mm/fault.c 2011-05-19 00:06:34.000000000 -0400
3007 +++ linux-2.6.39/arch/parisc/mm/fault.c 2011-05-22 19:36:30.000000000 -0400
3008 @@ -15,6 +15,7 @@
3009 #include <linux/sched.h>
3010 #include <linux/interrupt.h>
3011 #include <linux/module.h>
3012 +#include <linux/unistd.h>
3013
3014 #include <asm/uaccess.h>
3015 #include <asm/traps.h>
3016 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, ex
3017 static unsigned long
3018 parisc_acctyp(unsigned long code, unsigned int inst)
3019 {
3020 - if (code == 6 || code == 16)
3021 + if (code == 6 || code == 7 || code == 16)
3022 return VM_EXEC;
3023
3024 switch (inst & 0xf0000000) {
3025 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsign
3026 }
3027 #endif
3028
3029 +#ifdef CONFIG_PAX_PAGEEXEC
3030 +/*
3031 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
3032 + *
3033 + * returns 1 when task should be killed
3034 + * 2 when rt_sigreturn trampoline was detected
3035 + * 3 when unpatched PLT trampoline was detected
3036 + */
3037 +static int pax_handle_fetch_fault(struct pt_regs *regs)
3038 +{
3039 +
3040 +#ifdef CONFIG_PAX_EMUPLT
3041 + int err;
3042 +
3043 + do { /* PaX: unpatched PLT emulation */
3044 + unsigned int bl, depwi;
3045 +
3046 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
3047 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
3048 +
3049 + if (err)
3050 + break;
3051 +
3052 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
3053 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
3054 +
3055 + err = get_user(ldw, (unsigned int *)addr);
3056 + err |= get_user(bv, (unsigned int *)(addr+4));
3057 + err |= get_user(ldw2, (unsigned int *)(addr+8));
3058 +
3059 + if (err)
3060 + break;
3061 +
3062 + if (ldw == 0x0E801096U &&
3063 + bv == 0xEAC0C000U &&
3064 + ldw2 == 0x0E881095U)
3065 + {
3066 + unsigned int resolver, map;
3067 +
3068 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
3069 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
3070 + if (err)
3071 + break;
3072 +
3073 + regs->gr[20] = instruction_pointer(regs)+8;
3074 + regs->gr[21] = map;
3075 + regs->gr[22] = resolver;
3076 + regs->iaoq[0] = resolver | 3UL;
3077 + regs->iaoq[1] = regs->iaoq[0] + 4;
3078 + return 3;
3079 + }
3080 + }
3081 + } while (0);
3082 +#endif
3083 +
3084 +#ifdef CONFIG_PAX_EMUTRAMP
3085 +
3086 +#ifndef CONFIG_PAX_EMUSIGRT
3087 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
3088 + return 1;
3089 +#endif
3090 +
3091 + do { /* PaX: rt_sigreturn emulation */
3092 + unsigned int ldi1, ldi2, bel, nop;
3093 +
3094 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
3095 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
3096 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
3097 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
3098 +
3099 + if (err)
3100 + break;
3101 +
3102 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
3103 + ldi2 == 0x3414015AU &&
3104 + bel == 0xE4008200U &&
3105 + nop == 0x08000240U)
3106 + {
3107 + regs->gr[25] = (ldi1 & 2) >> 1;
3108 + regs->gr[20] = __NR_rt_sigreturn;
3109 + regs->gr[31] = regs->iaoq[1] + 16;
3110 + regs->sr[0] = regs->iasq[1];
3111 + regs->iaoq[0] = 0x100UL;
3112 + regs->iaoq[1] = regs->iaoq[0] + 4;
3113 + regs->iasq[0] = regs->sr[2];
3114 + regs->iasq[1] = regs->sr[2];
3115 + return 2;
3116 + }
3117 + } while (0);
3118 +#endif
3119 +
3120 + return 1;
3121 +}
3122 +
3123 +void pax_report_insns(void *pc, void *sp)
3124 +{
3125 + unsigned long i;
3126 +
3127 + printk(KERN_ERR "PAX: bytes at PC: ");
3128 + for (i = 0; i < 5; i++) {
3129 + unsigned int c;
3130 + if (get_user(c, (unsigned int *)pc+i))
3131 + printk(KERN_CONT "???????? ");
3132 + else
3133 + printk(KERN_CONT "%08x ", c);
3134 + }
3135 + printk("\n");
3136 +}
3137 +#endif
3138 +
3139 int fixup_exception(struct pt_regs *regs)
3140 {
3141 const struct exception_table_entry *fix;
3142 @@ -192,8 +303,33 @@ good_area:
3143
3144 acc_type = parisc_acctyp(code,regs->iir);
3145
3146 - if ((vma->vm_flags & acc_type) != acc_type)
3147 + if ((vma->vm_flags & acc_type) != acc_type) {
3148 +
3149 +#ifdef CONFIG_PAX_PAGEEXEC
3150 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
3151 + (address & ~3UL) == instruction_pointer(regs))
3152 + {
3153 + up_read(&mm->mmap_sem);
3154 + switch (pax_handle_fetch_fault(regs)) {
3155 +
3156 +#ifdef CONFIG_PAX_EMUPLT
3157 + case 3:
3158 + return;
3159 +#endif
3160 +
3161 +#ifdef CONFIG_PAX_EMUTRAMP
3162 + case 2:
3163 + return;
3164 +#endif
3165 +
3166 + }
3167 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
3168 + do_group_exit(SIGKILL);
3169 + }
3170 +#endif
3171 +
3172 goto bad_area;
3173 + }
3174
3175 /*
3176 * If for any reason at all we couldn't handle the fault, make
3177 diff -urNp linux-2.6.39/arch/powerpc/include/asm/device.h linux-2.6.39/arch/powerpc/include/asm/device.h
3178 --- linux-2.6.39/arch/powerpc/include/asm/device.h 2011-05-19 00:06:34.000000000 -0400
3179 +++ linux-2.6.39/arch/powerpc/include/asm/device.h 2011-05-22 19:36:30.000000000 -0400
3180 @@ -17,7 +17,7 @@ struct device_node;
3181 */
3182 struct dev_archdata {
3183 /* DMA operations on that device */
3184 - struct dma_map_ops *dma_ops;
3185 + const struct dma_map_ops *dma_ops;
3186
3187 /*
3188 * When an iommu is in use, dma_data is used as a ptr to the base of the
3189 diff -urNp linux-2.6.39/arch/powerpc/include/asm/dma-mapping.h linux-2.6.39/arch/powerpc/include/asm/dma-mapping.h
3190 --- linux-2.6.39/arch/powerpc/include/asm/dma-mapping.h 2011-05-19 00:06:34.000000000 -0400
3191 +++ linux-2.6.39/arch/powerpc/include/asm/dma-mapping.h 2011-05-22 19:36:30.000000000 -0400
3192 @@ -67,12 +67,13 @@ static inline unsigned long device_to_ma
3193 /*
3194 * Available generic sets of operations
3195 */
3196 +/* cannot be const */
3197 #ifdef CONFIG_PPC64
3198 -extern struct dma_map_ops dma_iommu_ops;
3199 +extern const struct dma_map_ops dma_iommu_ops;
3200 #endif
3201 -extern struct dma_map_ops dma_direct_ops;
3202 +extern const struct dma_map_ops dma_direct_ops;
3203
3204 -static inline struct dma_map_ops *get_dma_ops(struct device *dev)
3205 +static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
3206 {
3207 /* We don't handle the NULL dev case for ISA for now. We could
3208 * do it via an out of line call but it is not needed for now. The
3209 @@ -85,7 +86,7 @@ static inline struct dma_map_ops *get_dm
3210 return dev->archdata.dma_ops;
3211 }
3212
3213 -static inline void set_dma_ops(struct device *dev, struct dma_map_ops *ops)
3214 +static inline void set_dma_ops(struct device *dev, const struct dma_map_ops *ops)
3215 {
3216 dev->archdata.dma_ops = ops;
3217 }
3218 @@ -119,7 +120,7 @@ static inline void set_dma_offset(struct
3219
3220 static inline int dma_supported(struct device *dev, u64 mask)
3221 {
3222 - struct dma_map_ops *dma_ops = get_dma_ops(dev);
3223 + const struct dma_map_ops *dma_ops = get_dma_ops(dev);
3224
3225 if (unlikely(dma_ops == NULL))
3226 return 0;
3227 @@ -133,7 +134,7 @@ extern int dma_set_mask(struct device *d
3228 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
3229 dma_addr_t *dma_handle, gfp_t flag)
3230 {
3231 - struct dma_map_ops *dma_ops = get_dma_ops(dev);
3232 + const struct dma_map_ops *dma_ops = get_dma_ops(dev);
3233 void *cpu_addr;
3234
3235 BUG_ON(!dma_ops);
3236 @@ -148,7 +149,7 @@ static inline void *dma_alloc_coherent(s
3237 static inline void dma_free_coherent(struct device *dev, size_t size,
3238 void *cpu_addr, dma_addr_t dma_handle)
3239 {
3240 - struct dma_map_ops *dma_ops = get_dma_ops(dev);
3241 + const struct dma_map_ops *dma_ops = get_dma_ops(dev);
3242
3243 BUG_ON(!dma_ops);
3244
3245 @@ -159,7 +160,7 @@ static inline void dma_free_coherent(str
3246
3247 static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
3248 {
3249 - struct dma_map_ops *dma_ops = get_dma_ops(dev);
3250 + const struct dma_map_ops *dma_ops = get_dma_ops(dev);
3251
3252 if (dma_ops->mapping_error)
3253 return dma_ops->mapping_error(dev, dma_addr);
3254 diff -urNp linux-2.6.39/arch/powerpc/include/asm/elf.h linux-2.6.39/arch/powerpc/include/asm/elf.h
3255 --- linux-2.6.39/arch/powerpc/include/asm/elf.h 2011-05-19 00:06:34.000000000 -0400
3256 +++ linux-2.6.39/arch/powerpc/include/asm/elf.h 2011-05-22 19:36:30.000000000 -0400
3257 @@ -178,8 +178,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[E
3258 the loader. We need to make sure that it is out of the way of the program
3259 that it will "exec", and that there is sufficient room for the brk. */
3260
3261 -extern unsigned long randomize_et_dyn(unsigned long base);
3262 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
3263 +#define ELF_ET_DYN_BASE (0x20000000)
3264 +
3265 +#ifdef CONFIG_PAX_ASLR
3266 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
3267 +
3268 +#ifdef __powerpc64__
3269 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
3270 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
3271 +#else
3272 +#define PAX_DELTA_MMAP_LEN 15
3273 +#define PAX_DELTA_STACK_LEN 15
3274 +#endif
3275 +#endif
3276
3277 /*
3278 * Our registers are always unsigned longs, whether we're a 32 bit
3279 @@ -274,9 +285,6 @@ extern int arch_setup_additional_pages(s
3280 (0x7ff >> (PAGE_SHIFT - 12)) : \
3281 (0x3ffff >> (PAGE_SHIFT - 12)))
3282
3283 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3284 -#define arch_randomize_brk arch_randomize_brk
3285 -
3286 #endif /* __KERNEL__ */
3287
3288 /*
3289 diff -urNp linux-2.6.39/arch/powerpc/include/asm/iommu.h linux-2.6.39/arch/powerpc/include/asm/iommu.h
3290 --- linux-2.6.39/arch/powerpc/include/asm/iommu.h 2011-05-19 00:06:34.000000000 -0400
3291 +++ linux-2.6.39/arch/powerpc/include/asm/iommu.h 2011-05-22 19:36:30.000000000 -0400
3292 @@ -116,6 +116,9 @@ extern void iommu_init_early_iSeries(voi
3293 extern void iommu_init_early_dart(void);
3294 extern void iommu_init_early_pasemi(void);
3295
3296 +/* dma-iommu.c */
3297 +extern int dma_iommu_dma_supported(struct device *dev, u64 mask);
3298 +
3299 #ifdef CONFIG_PCI
3300 extern void pci_iommu_init(void);
3301 extern void pci_direct_iommu_init(void);
3302 diff -urNp linux-2.6.39/arch/powerpc/include/asm/kmap_types.h linux-2.6.39/arch/powerpc/include/asm/kmap_types.h
3303 --- linux-2.6.39/arch/powerpc/include/asm/kmap_types.h 2011-05-19 00:06:34.000000000 -0400
3304 +++ linux-2.6.39/arch/powerpc/include/asm/kmap_types.h 2011-05-22 19:36:30.000000000 -0400
3305 @@ -27,6 +27,7 @@ enum km_type {
3306 KM_PPC_SYNC_PAGE,
3307 KM_PPC_SYNC_ICACHE,
3308 KM_KDB,
3309 + KM_CLEARPAGE,
3310 KM_TYPE_NR
3311 };
3312
3313 diff -urNp linux-2.6.39/arch/powerpc/include/asm/page_64.h linux-2.6.39/arch/powerpc/include/asm/page_64.h
3314 --- linux-2.6.39/arch/powerpc/include/asm/page_64.h 2011-05-19 00:06:34.000000000 -0400
3315 +++ linux-2.6.39/arch/powerpc/include/asm/page_64.h 2011-05-22 19:36:30.000000000 -0400
3316 @@ -172,15 +172,18 @@ do { \
3317 * stack by default, so in the absence of a PT_GNU_STACK program header
3318 * we turn execute permission off.
3319 */
3320 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3321 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3322 +#define VM_STACK_DEFAULT_FLAGS32 \
3323 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3324 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3325
3326 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3327 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3328
3329 +#ifndef CONFIG_PAX_PAGEEXEC
3330 #define VM_STACK_DEFAULT_FLAGS \
3331 (is_32bit_task() ? \
3332 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
3333 +#endif
3334
3335 #include <asm-generic/getorder.h>
3336
3337 diff -urNp linux-2.6.39/arch/powerpc/include/asm/page.h linux-2.6.39/arch/powerpc/include/asm/page.h
3338 --- linux-2.6.39/arch/powerpc/include/asm/page.h 2011-05-19 00:06:34.000000000 -0400
3339 +++ linux-2.6.39/arch/powerpc/include/asm/page.h 2011-05-22 19:36:30.000000000 -0400
3340 @@ -129,8 +129,9 @@ extern phys_addr_t kernstart_addr;
3341 * and needs to be executable. This means the whole heap ends
3342 * up being executable.
3343 */
3344 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3345 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3346 +#define VM_DATA_DEFAULT_FLAGS32 \
3347 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3348 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3349
3350 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3351 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3352 @@ -158,6 +159,9 @@ extern phys_addr_t kernstart_addr;
3353 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
3354 #endif
3355
3356 +#define ktla_ktva(addr) (addr)
3357 +#define ktva_ktla(addr) (addr)
3358 +
3359 #ifndef __ASSEMBLY__
3360
3361 #undef STRICT_MM_TYPECHECKS
3362 diff -urNp linux-2.6.39/arch/powerpc/include/asm/pci.h linux-2.6.39/arch/powerpc/include/asm/pci.h
3363 --- linux-2.6.39/arch/powerpc/include/asm/pci.h 2011-05-19 00:06:34.000000000 -0400
3364 +++ linux-2.6.39/arch/powerpc/include/asm/pci.h 2011-05-22 19:36:30.000000000 -0400
3365 @@ -65,8 +65,8 @@ static inline int pci_get_legacy_ide_irq
3366 }
3367
3368 #ifdef CONFIG_PCI
3369 -extern void set_pci_dma_ops(struct dma_map_ops *dma_ops);
3370 -extern struct dma_map_ops *get_pci_dma_ops(void);
3371 +extern void set_pci_dma_ops(const struct dma_map_ops *dma_ops);
3372 +extern const struct dma_map_ops *get_pci_dma_ops(void);
3373 #else /* CONFIG_PCI */
3374 #define set_pci_dma_ops(d)
3375 #define get_pci_dma_ops() NULL
3376 diff -urNp linux-2.6.39/arch/powerpc/include/asm/pgtable.h linux-2.6.39/arch/powerpc/include/asm/pgtable.h
3377 --- linux-2.6.39/arch/powerpc/include/asm/pgtable.h 2011-05-19 00:06:34.000000000 -0400
3378 +++ linux-2.6.39/arch/powerpc/include/asm/pgtable.h 2011-05-22 19:36:30.000000000 -0400
3379 @@ -2,6 +2,7 @@
3380 #define _ASM_POWERPC_PGTABLE_H
3381 #ifdef __KERNEL__
3382
3383 +#include <linux/const.h>
3384 #ifndef __ASSEMBLY__
3385 #include <asm/processor.h> /* For TASK_SIZE */
3386 #include <asm/mmu.h>
3387 diff -urNp linux-2.6.39/arch/powerpc/include/asm/pte-hash32.h linux-2.6.39/arch/powerpc/include/asm/pte-hash32.h
3388 --- linux-2.6.39/arch/powerpc/include/asm/pte-hash32.h 2011-05-19 00:06:34.000000000 -0400
3389 +++ linux-2.6.39/arch/powerpc/include/asm/pte-hash32.h 2011-05-22 19:36:30.000000000 -0400
3390 @@ -21,6 +21,7 @@
3391 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
3392 #define _PAGE_USER 0x004 /* usermode access allowed */
3393 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
3394 +#define _PAGE_EXEC _PAGE_GUARDED
3395 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
3396 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
3397 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
3398 diff -urNp linux-2.6.39/arch/powerpc/include/asm/reg.h linux-2.6.39/arch/powerpc/include/asm/reg.h
3399 --- linux-2.6.39/arch/powerpc/include/asm/reg.h 2011-05-19 00:06:34.000000000 -0400
3400 +++ linux-2.6.39/arch/powerpc/include/asm/reg.h 2011-05-22 19:36:30.000000000 -0400
3401 @@ -201,6 +201,7 @@
3402 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
3403 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
3404 #define DSISR_NOHPTE 0x40000000 /* no translation found */
3405 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
3406 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
3407 #define DSISR_ISSTORE 0x02000000 /* access was a store */
3408 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
3409 diff -urNp linux-2.6.39/arch/powerpc/include/asm/swiotlb.h linux-2.6.39/arch/powerpc/include/asm/swiotlb.h
3410 --- linux-2.6.39/arch/powerpc/include/asm/swiotlb.h 2011-05-19 00:06:34.000000000 -0400
3411 +++ linux-2.6.39/arch/powerpc/include/asm/swiotlb.h 2011-05-22 19:36:30.000000000 -0400
3412 @@ -13,7 +13,7 @@
3413
3414 #include <linux/swiotlb.h>
3415
3416 -extern struct dma_map_ops swiotlb_dma_ops;
3417 +extern const struct dma_map_ops swiotlb_dma_ops;
3418
3419 static inline void dma_mark_clean(void *addr, size_t size) {}
3420
3421 diff -urNp linux-2.6.39/arch/powerpc/include/asm/system.h linux-2.6.39/arch/powerpc/include/asm/system.h
3422 --- linux-2.6.39/arch/powerpc/include/asm/system.h 2011-05-19 00:06:34.000000000 -0400
3423 +++ linux-2.6.39/arch/powerpc/include/asm/system.h 2011-05-22 19:36:30.000000000 -0400
3424 @@ -533,7 +533,7 @@ __cmpxchg_local(volatile void *ptr, unsi
3425 #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
3426 #endif
3427
3428 -extern unsigned long arch_align_stack(unsigned long sp);
3429 +#define arch_align_stack(x) ((x) & ~0xfUL)
3430
3431 /* Used in very early kernel initialization. */
3432 extern unsigned long reloc_offset(void);
3433 diff -urNp linux-2.6.39/arch/powerpc/include/asm/uaccess.h linux-2.6.39/arch/powerpc/include/asm/uaccess.h
3434 --- linux-2.6.39/arch/powerpc/include/asm/uaccess.h 2011-05-19 00:06:34.000000000 -0400
3435 +++ linux-2.6.39/arch/powerpc/include/asm/uaccess.h 2011-05-22 19:36:30.000000000 -0400
3436 @@ -13,6 +13,8 @@
3437 #define VERIFY_READ 0
3438 #define VERIFY_WRITE 1
3439
3440 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
3441 +
3442 /*
3443 * The fs value determines whether argument validity checking should be
3444 * performed or not. If get_fs() == USER_DS, checking is performed, with
3445 @@ -327,52 +329,6 @@ do { \
3446 extern unsigned long __copy_tofrom_user(void __user *to,
3447 const void __user *from, unsigned long size);
3448
3449 -#ifndef __powerpc64__
3450 -
3451 -static inline unsigned long copy_from_user(void *to,
3452 - const void __user *from, unsigned long n)
3453 -{
3454 - unsigned long over;
3455 -
3456 - if (access_ok(VERIFY_READ, from, n))
3457 - return __copy_tofrom_user((__force void __user *)to, from, n);
3458 - if ((unsigned long)from < TASK_SIZE) {
3459 - over = (unsigned long)from + n - TASK_SIZE;
3460 - return __copy_tofrom_user((__force void __user *)to, from,
3461 - n - over) + over;
3462 - }
3463 - return n;
3464 -}
3465 -
3466 -static inline unsigned long copy_to_user(void __user *to,
3467 - const void *from, unsigned long n)
3468 -{
3469 - unsigned long over;
3470 -
3471 - if (access_ok(VERIFY_WRITE, to, n))
3472 - return __copy_tofrom_user(to, (__force void __user *)from, n);
3473 - if ((unsigned long)to < TASK_SIZE) {
3474 - over = (unsigned long)to + n - TASK_SIZE;
3475 - return __copy_tofrom_user(to, (__force void __user *)from,
3476 - n - over) + over;
3477 - }
3478 - return n;
3479 -}
3480 -
3481 -#else /* __powerpc64__ */
3482 -
3483 -#define __copy_in_user(to, from, size) \
3484 - __copy_tofrom_user((to), (from), (size))
3485 -
3486 -extern unsigned long copy_from_user(void *to, const void __user *from,
3487 - unsigned long n);
3488 -extern unsigned long copy_to_user(void __user *to, const void *from,
3489 - unsigned long n);
3490 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
3491 - unsigned long n);
3492 -
3493 -#endif /* __powerpc64__ */
3494 -
3495 static inline unsigned long __copy_from_user_inatomic(void *to,
3496 const void __user *from, unsigned long n)
3497 {
3498 @@ -396,6 +352,10 @@ static inline unsigned long __copy_from_
3499 if (ret == 0)
3500 return 0;
3501 }
3502 +
3503 + if (!__builtin_constant_p(n))
3504 + check_object_size(to, n, false);
3505 +
3506 return __copy_tofrom_user((__force void __user *)to, from, n);
3507 }
3508
3509 @@ -422,6 +382,10 @@ static inline unsigned long __copy_to_us
3510 if (ret == 0)
3511 return 0;
3512 }
3513 +
3514 + if (!__builtin_constant_p(n))
3515 + check_object_size(from, n, true);
3516 +
3517 return __copy_tofrom_user(to, (__force const void __user *)from, n);
3518 }
3519
3520 @@ -439,6 +403,92 @@ static inline unsigned long __copy_to_us
3521 return __copy_to_user_inatomic(to, from, size);
3522 }
3523
3524 +#ifndef __powerpc64__
3525 +
3526 +static inline unsigned long __must_check copy_from_user(void *to,
3527 + const void __user *from, unsigned long n)
3528 +{
3529 + unsigned long over;
3530 +
3531 + if ((long)n < 0)
3532 + return n;
3533 +
3534 + if (access_ok(VERIFY_READ, from, n)) {
3535 + if (!__builtin_constant_p(n))
3536 + check_object_size(to, n, false);
3537 + return __copy_tofrom_user((__force void __user *)to, from, n);
3538 + }
3539 + if ((unsigned long)from < TASK_SIZE) {
3540 + over = (unsigned long)from + n - TASK_SIZE;
3541 + if (!__builtin_constant_p(n - over))
3542 + check_object_size(to, n - over, false);
3543 + return __copy_tofrom_user((__force void __user *)to, from,
3544 + n - over) + over;
3545 + }
3546 + return n;
3547 +}
3548 +
3549 +static inline unsigned long __must_check copy_to_user(void __user *to,
3550 + const void *from, unsigned long n)
3551 +{
3552 + unsigned long over;
3553 +
3554 + if ((long)n < 0)
3555 + return n;
3556 +
3557 + if (access_ok(VERIFY_WRITE, to, n)) {
3558 + if (!__builtin_constant_p(n))
3559 + check_object_size(from, n, true);
3560 + return __copy_tofrom_user(to, (__force void __user *)from, n);
3561 + }
3562 + if ((unsigned long)to < TASK_SIZE) {
3563 + over = (unsigned long)to + n - TASK_SIZE;
3564 + if (!__builtin_constant_p(n))
3565 + check_object_size(from, n - over, true);
3566 + return __copy_tofrom_user(to, (__force void __user *)from,
3567 + n - over) + over;
3568 + }
3569 + return n;
3570 +}
3571 +
3572 +#else /* __powerpc64__ */
3573 +
3574 +#define __copy_in_user(to, from, size) \
3575 + __copy_tofrom_user((to), (from), (size))
3576 +
3577 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
3578 +{
3579 + if ((long)n < 0 || n > INT_MAX)
3580 + return n;
3581 +
3582 + if (!__builtin_constant_p(n))
3583 + check_object_size(to, n, false);
3584 +
3585 + if (likely(access_ok(VERIFY_READ, from, n)))
3586 + n = __copy_from_user(to, from, n);
3587 + else
3588 + memset(to, 0, n);
3589 + return n;
3590 +}
3591 +
3592 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
3593 +{
3594 + if ((long)n < 0 || n > INT_MAX)
3595 + return n;
3596 +
3597 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
3598 + if (!__builtin_constant_p(n))
3599 + check_object_size(from, n, true);
3600 + n = __copy_to_user(to, from, n);
3601 + }
3602 + return n;
3603 +}
3604 +
3605 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
3606 + unsigned long n);
3607 +
3608 +#endif /* __powerpc64__ */
3609 +
3610 extern unsigned long __clear_user(void __user *addr, unsigned long size);
3611
3612 static inline unsigned long clear_user(void __user *addr, unsigned long size)
3613 diff -urNp linux-2.6.39/arch/powerpc/kernel/dma.c linux-2.6.39/arch/powerpc/kernel/dma.c
3614 --- linux-2.6.39/arch/powerpc/kernel/dma.c 2011-05-19 00:06:34.000000000 -0400
3615 +++ linux-2.6.39/arch/powerpc/kernel/dma.c 2011-05-22 19:36:30.000000000 -0400
3616 @@ -136,7 +136,7 @@ static inline void dma_direct_sync_singl
3617 }
3618 #endif
3619
3620 -struct dma_map_ops dma_direct_ops = {
3621 +const struct dma_map_ops dma_direct_ops = {
3622 .alloc_coherent = dma_direct_alloc_coherent,
3623 .free_coherent = dma_direct_free_coherent,
3624 .map_sg = dma_direct_map_sg,
3625 @@ -157,7 +157,7 @@ EXPORT_SYMBOL(dma_direct_ops);
3626
3627 int dma_set_mask(struct device *dev, u64 dma_mask)
3628 {
3629 - struct dma_map_ops *dma_ops = get_dma_ops(dev);
3630 + const struct dma_map_ops *dma_ops = get_dma_ops(dev);
3631
3632 if (ppc_md.dma_set_mask)
3633 return ppc_md.dma_set_mask(dev, dma_mask);
3634 diff -urNp linux-2.6.39/arch/powerpc/kernel/dma-iommu.c linux-2.6.39/arch/powerpc/kernel/dma-iommu.c
3635 --- linux-2.6.39/arch/powerpc/kernel/dma-iommu.c 2011-05-19 00:06:34.000000000 -0400
3636 +++ linux-2.6.39/arch/powerpc/kernel/dma-iommu.c 2011-05-22 19:36:30.000000000 -0400
3637 @@ -70,7 +70,7 @@ static void dma_iommu_unmap_sg(struct de
3638 }
3639
3640 /* We support DMA to/from any memory page via the iommu */
3641 -static int dma_iommu_dma_supported(struct device *dev, u64 mask)
3642 +int dma_iommu_dma_supported(struct device *dev, u64 mask)
3643 {
3644 struct iommu_table *tbl = get_iommu_table_base(dev);
3645
3646 @@ -90,7 +90,7 @@ static int dma_iommu_dma_supported(struc
3647 return 1;
3648 }
3649
3650 -struct dma_map_ops dma_iommu_ops = {
3651 +struct dma_map_ops dma_iommu_ops = { /* cannot be const, see arch/powerpc/platforms/cell/iommu.c */
3652 .alloc_coherent = dma_iommu_alloc_coherent,
3653 .free_coherent = dma_iommu_free_coherent,
3654 .map_sg = dma_iommu_map_sg,
3655 diff -urNp linux-2.6.39/arch/powerpc/kernel/dma-swiotlb.c linux-2.6.39/arch/powerpc/kernel/dma-swiotlb.c
3656 --- linux-2.6.39/arch/powerpc/kernel/dma-swiotlb.c 2011-05-19 00:06:34.000000000 -0400
3657 +++ linux-2.6.39/arch/powerpc/kernel/dma-swiotlb.c 2011-05-22 19:36:30.000000000 -0400
3658 @@ -31,7 +31,7 @@ unsigned int ppc_swiotlb_enable;
3659 * map_page, and unmap_page on highmem, use normal dma_ops
3660 * for everything else.
3661 */
3662 -struct dma_map_ops swiotlb_dma_ops = {
3663 +const struct dma_map_ops swiotlb_dma_ops = {
3664 .alloc_coherent = dma_direct_alloc_coherent,
3665 .free_coherent = dma_direct_free_coherent,
3666 .map_sg = swiotlb_map_sg_attrs,
3667 diff -urNp linux-2.6.39/arch/powerpc/kernel/exceptions-64e.S linux-2.6.39/arch/powerpc/kernel/exceptions-64e.S
3668 --- linux-2.6.39/arch/powerpc/kernel/exceptions-64e.S 2011-05-19 00:06:34.000000000 -0400
3669 +++ linux-2.6.39/arch/powerpc/kernel/exceptions-64e.S 2011-05-22 19:36:30.000000000 -0400
3670 @@ -495,6 +495,7 @@ storage_fault_common:
3671 std r14,_DAR(r1)
3672 std r15,_DSISR(r1)
3673 addi r3,r1,STACK_FRAME_OVERHEAD
3674 + bl .save_nvgprs
3675 mr r4,r14
3676 mr r5,r15
3677 ld r14,PACA_EXGEN+EX_R14(r13)
3678 @@ -504,8 +505,7 @@ storage_fault_common:
3679 cmpdi r3,0
3680 bne- 1f
3681 b .ret_from_except_lite
3682 -1: bl .save_nvgprs
3683 - mr r5,r3
3684 +1: mr r5,r3
3685 addi r3,r1,STACK_FRAME_OVERHEAD
3686 ld r4,_DAR(r1)
3687 bl .bad_page_fault
3688 diff -urNp linux-2.6.39/arch/powerpc/kernel/exceptions-64s.S linux-2.6.39/arch/powerpc/kernel/exceptions-64s.S
3689 --- linux-2.6.39/arch/powerpc/kernel/exceptions-64s.S 2011-05-19 00:06:34.000000000 -0400
3690 +++ linux-2.6.39/arch/powerpc/kernel/exceptions-64s.S 2011-05-22 19:36:30.000000000 -0400
3691 @@ -848,10 +848,10 @@ handle_page_fault:
3692 11: ld r4,_DAR(r1)
3693 ld r5,_DSISR(r1)
3694 addi r3,r1,STACK_FRAME_OVERHEAD
3695 + bl .save_nvgprs
3696 bl .do_page_fault
3697 cmpdi r3,0
3698 beq+ 13f
3699 - bl .save_nvgprs
3700 mr r5,r3
3701 addi r3,r1,STACK_FRAME_OVERHEAD
3702 lwz r4,_DAR(r1)
3703 diff -urNp linux-2.6.39/arch/powerpc/kernel/ibmebus.c linux-2.6.39/arch/powerpc/kernel/ibmebus.c
3704 --- linux-2.6.39/arch/powerpc/kernel/ibmebus.c 2011-05-19 00:06:34.000000000 -0400
3705 +++ linux-2.6.39/arch/powerpc/kernel/ibmebus.c 2011-05-22 19:36:30.000000000 -0400
3706 @@ -128,7 +128,7 @@ static int ibmebus_dma_supported(struct
3707 return 1;
3708 }
3709
3710 -static struct dma_map_ops ibmebus_dma_ops = {
3711 +static const struct dma_map_ops ibmebus_dma_ops = {
3712 .alloc_coherent = ibmebus_alloc_coherent,
3713 .free_coherent = ibmebus_free_coherent,
3714 .map_sg = ibmebus_map_sg,
3715 diff -urNp linux-2.6.39/arch/powerpc/kernel/kgdb.c linux-2.6.39/arch/powerpc/kernel/kgdb.c
3716 --- linux-2.6.39/arch/powerpc/kernel/kgdb.c 2011-05-19 00:06:34.000000000 -0400
3717 +++ linux-2.6.39/arch/powerpc/kernel/kgdb.c 2011-05-22 19:36:30.000000000 -0400
3718 @@ -422,7 +422,7 @@ int kgdb_arch_handle_exception(int vecto
3719 /*
3720 * Global data
3721 */
3722 -struct kgdb_arch arch_kgdb_ops = {
3723 +const struct kgdb_arch arch_kgdb_ops = {
3724 .gdb_bpt_instr = {0x7d, 0x82, 0x10, 0x08},
3725 };
3726
3727 diff -urNp linux-2.6.39/arch/powerpc/kernel/module_32.c linux-2.6.39/arch/powerpc/kernel/module_32.c
3728 --- linux-2.6.39/arch/powerpc/kernel/module_32.c 2011-05-19 00:06:34.000000000 -0400
3729 +++ linux-2.6.39/arch/powerpc/kernel/module_32.c 2011-05-22 19:36:30.000000000 -0400
3730 @@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr
3731 me->arch.core_plt_section = i;
3732 }
3733 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
3734 - printk("Module doesn't contain .plt or .init.plt sections.\n");
3735 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
3736 return -ENOEXEC;
3737 }
3738
3739 @@ -203,11 +203,16 @@ static uint32_t do_plt_call(void *locati
3740
3741 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
3742 /* Init, or core PLT? */
3743 - if (location >= mod->module_core
3744 - && location < mod->module_core + mod->core_size)
3745 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
3746 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
3747 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
3748 - else
3749 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
3750 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
3751 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
3752 + else {
3753 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
3754 + return ~0UL;
3755 + }
3756
3757 /* Find this entry, or if that fails, the next avail. entry */
3758 while (entry->jump[0]) {
3759 diff -urNp linux-2.6.39/arch/powerpc/kernel/module.c linux-2.6.39/arch/powerpc/kernel/module.c
3760 --- linux-2.6.39/arch/powerpc/kernel/module.c 2011-05-19 00:06:34.000000000 -0400
3761 +++ linux-2.6.39/arch/powerpc/kernel/module.c 2011-05-22 19:36:30.000000000 -0400
3762 @@ -31,11 +31,24 @@
3763
3764 LIST_HEAD(module_bug_list);
3765
3766 +#ifdef CONFIG_PAX_KERNEXEC
3767 void *module_alloc(unsigned long size)
3768 {
3769 if (size == 0)
3770 return NULL;
3771
3772 + return vmalloc(size);
3773 +}
3774 +
3775 +void *module_alloc_exec(unsigned long size)
3776 +#else
3777 +void *module_alloc(unsigned long size)
3778 +#endif
3779 +
3780 +{
3781 + if (size == 0)
3782 + return NULL;
3783 +
3784 return vmalloc_exec(size);
3785 }
3786
3787 @@ -45,6 +58,13 @@ void module_free(struct module *mod, voi
3788 vfree(module_region);
3789 }
3790
3791 +#ifdef CONFIG_PAX_KERNEXEC
3792 +void module_free_exec(struct module *mod, void *module_region)
3793 +{
3794 + module_free(mod, module_region);
3795 +}
3796 +#endif
3797 +
3798 static const Elf_Shdr *find_section(const Elf_Ehdr *hdr,
3799 const Elf_Shdr *sechdrs,
3800 const char *name)
3801 diff -urNp linux-2.6.39/arch/powerpc/kernel/pci-common.c linux-2.6.39/arch/powerpc/kernel/pci-common.c
3802 --- linux-2.6.39/arch/powerpc/kernel/pci-common.c 2011-05-19 00:06:34.000000000 -0400
3803 +++ linux-2.6.39/arch/powerpc/kernel/pci-common.c 2011-05-22 19:36:30.000000000 -0400
3804 @@ -53,14 +53,14 @@ resource_size_t isa_mem_base;
3805 unsigned int ppc_pci_flags = 0;
3806
3807
3808 -static struct dma_map_ops *pci_dma_ops = &dma_direct_ops;
3809 +static const struct dma_map_ops *pci_dma_ops = &dma_direct_ops;
3810
3811 -void set_pci_dma_ops(struct dma_map_ops *dma_ops)
3812 +void set_pci_dma_ops(const struct dma_map_ops *dma_ops)
3813 {
3814 pci_dma_ops = dma_ops;
3815 }
3816
3817 -struct dma_map_ops *get_pci_dma_ops(void)
3818 +const struct dma_map_ops *get_pci_dma_ops(void)
3819 {
3820 return pci_dma_ops;
3821 }
3822 @@ -1639,7 +1639,7 @@ null_write_config(struct pci_bus *bus, u
3823 return PCIBIOS_DEVICE_NOT_FOUND;
3824 }
3825
3826 -static struct pci_ops null_pci_ops =
3827 +static const struct pci_ops null_pci_ops =
3828 {
3829 .read = null_read_config,
3830 .write = null_write_config,
3831 diff -urNp linux-2.6.39/arch/powerpc/kernel/process.c linux-2.6.39/arch/powerpc/kernel/process.c
3832 --- linux-2.6.39/arch/powerpc/kernel/process.c 2011-05-19 00:06:34.000000000 -0400
3833 +++ linux-2.6.39/arch/powerpc/kernel/process.c 2011-05-22 19:41:32.000000000 -0400
3834 @@ -655,8 +655,8 @@ void show_regs(struct pt_regs * regs)
3835 * Lookup NIP late so we have the best change of getting the
3836 * above info out without failing
3837 */
3838 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
3839 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
3840 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
3841 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
3842 #endif
3843 show_stack(current, (unsigned long *) regs->gpr[1]);
3844 if (!user_mode(regs))
3845 @@ -1146,10 +1146,10 @@ void show_stack(struct task_struct *tsk,
3846 newsp = stack[0];
3847 ip = stack[STACK_FRAME_LR_SAVE];
3848 if (!firstframe || ip != lr) {
3849 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
3850 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
3851 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
3852 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
3853 - printk(" (%pS)",
3854 + printk(" (%pA)",
3855 (void *)current->ret_stack[curr_frame].ret);
3856 curr_frame--;
3857 }
3858 @@ -1169,7 +1169,7 @@ void show_stack(struct task_struct *tsk,
3859 struct pt_regs *regs = (struct pt_regs *)
3860 (sp + STACK_FRAME_OVERHEAD);
3861 lr = regs->link;
3862 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
3863 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
3864 regs->trap, (void *)regs->nip, (void *)lr);
3865 firstframe = 1;
3866 }
3867 @@ -1244,58 +1244,3 @@ void thread_info_cache_init(void)
3868 }
3869
3870 #endif /* THREAD_SHIFT < PAGE_SHIFT */
3871 -
3872 -unsigned long arch_align_stack(unsigned long sp)
3873 -{
3874 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
3875 - sp -= get_random_int() & ~PAGE_MASK;
3876 - return sp & ~0xf;
3877 -}
3878 -
3879 -static inline unsigned long brk_rnd(void)
3880 -{
3881 - unsigned long rnd = 0;
3882 -
3883 - /* 8MB for 32bit, 1GB for 64bit */
3884 - if (is_32bit_task())
3885 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
3886 - else
3887 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
3888 -
3889 - return rnd << PAGE_SHIFT;
3890 -}
3891 -
3892 -unsigned long arch_randomize_brk(struct mm_struct *mm)
3893 -{
3894 - unsigned long base = mm->brk;
3895 - unsigned long ret;
3896 -
3897 -#ifdef CONFIG_PPC_STD_MMU_64
3898 - /*
3899 - * If we are using 1TB segments and we are allowed to randomise
3900 - * the heap, we can put it above 1TB so it is backed by a 1TB
3901 - * segment. Otherwise the heap will be in the bottom 1TB
3902 - * which always uses 256MB segments and this may result in a
3903 - * performance penalty.
3904 - */
3905 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
3906 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
3907 -#endif
3908 -
3909 - ret = PAGE_ALIGN(base + brk_rnd());
3910 -
3911 - if (ret < mm->brk)
3912 - return mm->brk;
3913 -
3914 - return ret;
3915 -}
3916 -
3917 -unsigned long randomize_et_dyn(unsigned long base)
3918 -{
3919 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
3920 -
3921 - if (ret < base)
3922 - return base;
3923 -
3924 - return ret;
3925 -}
3926 diff -urNp linux-2.6.39/arch/powerpc/kernel/rtas_pci.c linux-2.6.39/arch/powerpc/kernel/rtas_pci.c
3927 --- linux-2.6.39/arch/powerpc/kernel/rtas_pci.c 2011-05-19 00:06:34.000000000 -0400
3928 +++ linux-2.6.39/arch/powerpc/kernel/rtas_pci.c 2011-05-22 19:36:30.000000000 -0400
3929 @@ -149,7 +149,7 @@ static int rtas_pci_write_config(struct
3930 return PCIBIOS_DEVICE_NOT_FOUND;
3931 }
3932
3933 -static struct pci_ops rtas_pci_ops = {
3934 +static const struct pci_ops rtas_pci_ops = {
3935 .read = rtas_pci_read_config,
3936 .write = rtas_pci_write_config,
3937 };
3938 diff -urNp linux-2.6.39/arch/powerpc/kernel/signal_32.c linux-2.6.39/arch/powerpc/kernel/signal_32.c
3939 --- linux-2.6.39/arch/powerpc/kernel/signal_32.c 2011-05-19 00:06:34.000000000 -0400
3940 +++ linux-2.6.39/arch/powerpc/kernel/signal_32.c 2011-05-22 19:36:30.000000000 -0400
3941 @@ -858,7 +858,7 @@ int handle_rt_signal32(unsigned long sig
3942 /* Save user registers on the stack */
3943 frame = &rt_sf->uc.uc_mcontext;
3944 addr = frame;
3945 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
3946 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
3947 if (save_user_regs(regs, frame, 0, 1))
3948 goto badframe;
3949 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
3950 diff -urNp linux-2.6.39/arch/powerpc/kernel/signal_64.c linux-2.6.39/arch/powerpc/kernel/signal_64.c
3951 --- linux-2.6.39/arch/powerpc/kernel/signal_64.c 2011-05-19 00:06:34.000000000 -0400
3952 +++ linux-2.6.39/arch/powerpc/kernel/signal_64.c 2011-05-22 19:36:30.000000000 -0400
3953 @@ -429,7 +429,7 @@ int handle_rt_signal64(int signr, struct
3954 current->thread.fpscr.val = 0;
3955
3956 /* Set up to return from userspace. */
3957 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
3958 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
3959 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
3960 } else {
3961 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
3962 diff -urNp linux-2.6.39/arch/powerpc/kernel/vdso.c linux-2.6.39/arch/powerpc/kernel/vdso.c
3963 --- linux-2.6.39/arch/powerpc/kernel/vdso.c 2011-05-19 00:06:34.000000000 -0400
3964 +++ linux-2.6.39/arch/powerpc/kernel/vdso.c 2011-05-22 19:36:30.000000000 -0400
3965 @@ -36,6 +36,7 @@
3966 #include <asm/firmware.h>
3967 #include <asm/vdso.h>
3968 #include <asm/vdso_datapage.h>
3969 +#include <asm/mman.h>
3970
3971 #include "setup.h"
3972
3973 @@ -220,7 +221,7 @@ int arch_setup_additional_pages(struct l
3974 vdso_base = VDSO32_MBASE;
3975 #endif
3976
3977 - current->mm->context.vdso_base = 0;
3978 + current->mm->context.vdso_base = ~0UL;
3979
3980 /* vDSO has a problem and was disabled, just don't "enable" it for the
3981 * process
3982 @@ -240,7 +241,7 @@ int arch_setup_additional_pages(struct l
3983 vdso_base = get_unmapped_area(NULL, vdso_base,
3984 (vdso_pages << PAGE_SHIFT) +
3985 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
3986 - 0, 0);
3987 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
3988 if (IS_ERR_VALUE(vdso_base)) {
3989 rc = vdso_base;
3990 goto fail_mmapsem;
3991 diff -urNp linux-2.6.39/arch/powerpc/kernel/vio.c linux-2.6.39/arch/powerpc/kernel/vio.c
3992 --- linux-2.6.39/arch/powerpc/kernel/vio.c 2011-05-19 00:06:34.000000000 -0400
3993 +++ linux-2.6.39/arch/powerpc/kernel/vio.c 2011-05-22 19:36:30.000000000 -0400
3994 @@ -605,11 +605,12 @@ static int vio_dma_iommu_dma_supported(s
3995 return dma_iommu_ops.dma_supported(dev, mask);
3996 }
3997
3998 -struct dma_map_ops vio_dma_mapping_ops = {
3999 +const struct dma_map_ops vio_dma_mapping_ops = {
4000 .alloc_coherent = vio_dma_iommu_alloc_coherent,
4001 .free_coherent = vio_dma_iommu_free_coherent,
4002 .map_sg = vio_dma_iommu_map_sg,
4003 .unmap_sg = vio_dma_iommu_unmap_sg,
4004 + .dma_supported = dma_iommu_dma_supported,
4005 .map_page = vio_dma_iommu_map_page,
4006 .unmap_page = vio_dma_iommu_unmap_page,
4007 .dma_supported = vio_dma_iommu_dma_supported,
4008 diff -urNp linux-2.6.39/arch/powerpc/lib/usercopy_64.c linux-2.6.39/arch/powerpc/lib/usercopy_64.c
4009 --- linux-2.6.39/arch/powerpc/lib/usercopy_64.c 2011-05-19 00:06:34.000000000 -0400
4010 +++ linux-2.6.39/arch/powerpc/lib/usercopy_64.c 2011-05-22 19:36:30.000000000 -0400
4011 @@ -9,22 +9,6 @@
4012 #include <linux/module.h>
4013 #include <asm/uaccess.h>
4014
4015 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
4016 -{
4017 - if (likely(access_ok(VERIFY_READ, from, n)))
4018 - n = __copy_from_user(to, from, n);
4019 - else
4020 - memset(to, 0, n);
4021 - return n;
4022 -}
4023 -
4024 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
4025 -{
4026 - if (likely(access_ok(VERIFY_WRITE, to, n)))
4027 - n = __copy_to_user(to, from, n);
4028 - return n;
4029 -}
4030 -
4031 unsigned long copy_in_user(void __user *to, const void __user *from,
4032 unsigned long n)
4033 {
4034 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *
4035 return n;
4036 }
4037
4038 -EXPORT_SYMBOL(copy_from_user);
4039 -EXPORT_SYMBOL(copy_to_user);
4040 EXPORT_SYMBOL(copy_in_user);
4041
4042 diff -urNp linux-2.6.39/arch/powerpc/mm/fault.c linux-2.6.39/arch/powerpc/mm/fault.c
4043 --- linux-2.6.39/arch/powerpc/mm/fault.c 2011-05-19 00:06:34.000000000 -0400
4044 +++ linux-2.6.39/arch/powerpc/mm/fault.c 2011-05-22 19:36:30.000000000 -0400
4045 @@ -31,6 +31,10 @@
4046 #include <linux/kdebug.h>
4047 #include <linux/perf_event.h>
4048 #include <linux/magic.h>
4049 +#include <linux/slab.h>
4050 +#include <linux/pagemap.h>
4051 +#include <linux/compiler.h>
4052 +#include <linux/unistd.h>
4053
4054 #include <asm/firmware.h>
4055 #include <asm/page.h>
4056 @@ -42,6 +46,7 @@
4057 #include <asm/tlbflush.h>
4058 #include <asm/siginfo.h>
4059 #include <mm/mmu_decl.h>
4060 +#include <asm/ptrace.h>
4061
4062 #ifdef CONFIG_KPROBES
4063 static inline int notify_page_fault(struct pt_regs *regs)
4064 @@ -65,6 +70,33 @@ static inline int notify_page_fault(stru
4065 }
4066 #endif
4067
4068 +#ifdef CONFIG_PAX_PAGEEXEC
4069 +/*
4070 + * PaX: decide what to do with offenders (regs->nip = fault address)
4071 + *
4072 + * returns 1 when task should be killed
4073 + */
4074 +static int pax_handle_fetch_fault(struct pt_regs *regs)
4075 +{
4076 + return 1;
4077 +}
4078 +
4079 +void pax_report_insns(void *pc, void *sp)
4080 +{
4081 + unsigned long i;
4082 +
4083 + printk(KERN_ERR "PAX: bytes at PC: ");
4084 + for (i = 0; i < 5; i++) {
4085 + unsigned int c;
4086 + if (get_user(c, (unsigned int __user *)pc+i))
4087 + printk(KERN_CONT "???????? ");
4088 + else
4089 + printk(KERN_CONT "%08x ", c);
4090 + }
4091 + printk("\n");
4092 +}
4093 +#endif
4094 +
4095 /*
4096 * Check whether the instruction at regs->nip is a store using
4097 * an update addressing form which will update r1.
4098 @@ -135,7 +167,7 @@ int __kprobes do_page_fault(struct pt_re
4099 * indicate errors in DSISR but can validly be set in SRR1.
4100 */
4101 if (trap == 0x400)
4102 - error_code &= 0x48200000;
4103 + error_code &= 0x58200000;
4104 else
4105 is_write = error_code & DSISR_ISSTORE;
4106 #else
4107 @@ -258,7 +290,7 @@ good_area:
4108 * "undefined". Of those that can be set, this is the only
4109 * one which seems bad.
4110 */
4111 - if (error_code & 0x10000000)
4112 + if (error_code & DSISR_GUARDED)
4113 /* Guarded storage error. */
4114 goto bad_area;
4115 #endif /* CONFIG_8xx */
4116 @@ -273,7 +305,7 @@ good_area:
4117 * processors use the same I/D cache coherency mechanism
4118 * as embedded.
4119 */
4120 - if (error_code & DSISR_PROTFAULT)
4121 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
4122 goto bad_area;
4123 #endif /* CONFIG_PPC_STD_MMU */
4124
4125 @@ -342,6 +374,23 @@ bad_area:
4126 bad_area_nosemaphore:
4127 /* User mode accesses cause a SIGSEGV */
4128 if (user_mode(regs)) {
4129 +
4130 +#ifdef CONFIG_PAX_PAGEEXEC
4131 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4132 +#ifdef CONFIG_PPC_STD_MMU
4133 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
4134 +#else
4135 + if (is_exec && regs->nip == address) {
4136 +#endif
4137 + switch (pax_handle_fetch_fault(regs)) {
4138 + }
4139 +
4140 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
4141 + do_group_exit(SIGKILL);
4142 + }
4143 + }
4144 +#endif
4145 +
4146 _exception(SIGSEGV, regs, code, address);
4147 return 0;
4148 }
4149 diff -urNp linux-2.6.39/arch/powerpc/mm/mmap_64.c linux-2.6.39/arch/powerpc/mm/mmap_64.c
4150 --- linux-2.6.39/arch/powerpc/mm/mmap_64.c 2011-05-19 00:06:34.000000000 -0400
4151 +++ linux-2.6.39/arch/powerpc/mm/mmap_64.c 2011-05-22 19:36:30.000000000 -0400
4152 @@ -99,10 +99,22 @@ void arch_pick_mmap_layout(struct mm_str
4153 */
4154 if (mmap_is_legacy()) {
4155 mm->mmap_base = TASK_UNMAPPED_BASE;
4156 +
4157 +#ifdef CONFIG_PAX_RANDMMAP
4158 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4159 + mm->mmap_base += mm->delta_mmap;
4160 +#endif
4161 +
4162 mm->get_unmapped_area = arch_get_unmapped_area;
4163 mm->unmap_area = arch_unmap_area;
4164 } else {
4165 mm->mmap_base = mmap_base();
4166 +
4167 +#ifdef CONFIG_PAX_RANDMMAP
4168 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4169 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4170 +#endif
4171 +
4172 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4173 mm->unmap_area = arch_unmap_area_topdown;
4174 }
4175 diff -urNp linux-2.6.39/arch/powerpc/mm/slice.c linux-2.6.39/arch/powerpc/mm/slice.c
4176 --- linux-2.6.39/arch/powerpc/mm/slice.c 2011-05-19 00:06:34.000000000 -0400
4177 +++ linux-2.6.39/arch/powerpc/mm/slice.c 2011-05-22 19:36:30.000000000 -0400
4178 @@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_
4179 if ((mm->task_size - len) < addr)
4180 return 0;
4181 vma = find_vma(mm, addr);
4182 - return (!vma || (addr + len) <= vma->vm_start);
4183 + return check_heap_stack_gap(vma, addr, len);
4184 }
4185
4186 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
4187 @@ -256,7 +256,7 @@ full_search:
4188 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
4189 continue;
4190 }
4191 - if (!vma || addr + len <= vma->vm_start) {
4192 + if (check_heap_stack_gap(vma, addr, len)) {
4193 /*
4194 * Remember the place where we stopped the search:
4195 */
4196 @@ -313,10 +313,14 @@ static unsigned long slice_find_area_top
4197 }
4198 }
4199
4200 - addr = mm->mmap_base;
4201 - while (addr > len) {
4202 + if (mm->mmap_base < len)
4203 + addr = -ENOMEM;
4204 + else
4205 + addr = mm->mmap_base - len;
4206 +
4207 + while (!IS_ERR_VALUE(addr)) {
4208 /* Go down by chunk size */
4209 - addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
4210 + addr = _ALIGN_DOWN(addr, 1ul << pshift);
4211
4212 /* Check for hit with different page size */
4213 mask = slice_range_to_mask(addr, len);
4214 @@ -336,7 +340,7 @@ static unsigned long slice_find_area_top
4215 * return with success:
4216 */
4217 vma = find_vma(mm, addr);
4218 - if (!vma || (addr + len) <= vma->vm_start) {
4219 + if (check_heap_stack_gap(vma, addr, len)) {
4220 /* remember the address as a hint for next time */
4221 if (use_cache)
4222 mm->free_area_cache = addr;
4223 @@ -348,7 +352,7 @@ static unsigned long slice_find_area_top
4224 mm->cached_hole_size = vma->vm_start - addr;
4225
4226 /* try just below the current vma->vm_start */
4227 - addr = vma->vm_start;
4228 + addr = skip_heap_stack_gap(vma, len);
4229 }
4230
4231 /*
4232 @@ -426,6 +430,11 @@ unsigned long slice_get_unmapped_area(un
4233 if (fixed && addr > (mm->task_size - len))
4234 return -EINVAL;
4235
4236 +#ifdef CONFIG_PAX_RANDMMAP
4237 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
4238 + addr = 0;
4239 +#endif
4240 +
4241 /* If hint, make sure it matches our alignment restrictions */
4242 if (!fixed && addr) {
4243 addr = _ALIGN_UP(addr, 1ul << pshift);
4244 diff -urNp linux-2.6.39/arch/powerpc/platforms/52xx/efika.c linux-2.6.39/arch/powerpc/platforms/52xx/efika.c
4245 --- linux-2.6.39/arch/powerpc/platforms/52xx/efika.c 2011-05-19 00:06:34.000000000 -0400
4246 +++ linux-2.6.39/arch/powerpc/platforms/52xx/efika.c 2011-05-22 19:36:30.000000000 -0400
4247 @@ -60,7 +60,7 @@ static int rtas_write_config(struct pci_
4248 return rval ? PCIBIOS_DEVICE_NOT_FOUND : PCIBIOS_SUCCESSFUL;
4249 }
4250
4251 -static struct pci_ops rtas_pci_ops = {
4252 +static const struct pci_ops rtas_pci_ops = {
4253 .read = rtas_read_config,
4254 .write = rtas_write_config,
4255 };
4256 diff -urNp linux-2.6.39/arch/powerpc/platforms/cell/celleb_pci.c linux-2.6.39/arch/powerpc/platforms/cell/celleb_pci.c
4257 --- linux-2.6.39/arch/powerpc/platforms/cell/celleb_pci.c 2011-05-19 00:06:34.000000000 -0400
4258 +++ linux-2.6.39/arch/powerpc/platforms/cell/celleb_pci.c 2011-05-22 19:36:30.000000000 -0400
4259 @@ -234,7 +234,7 @@ static int celleb_fake_pci_write_config(
4260 return PCIBIOS_SUCCESSFUL;
4261 }
4262
4263 -static struct pci_ops celleb_fake_pci_ops = {
4264 +static const struct pci_ops celleb_fake_pci_ops = {
4265 .read = celleb_fake_pci_read_config,
4266 .write = celleb_fake_pci_write_config,
4267 };
4268 diff -urNp linux-2.6.39/arch/powerpc/platforms/cell/celleb_scc_epci.c linux-2.6.39/arch/powerpc/platforms/cell/celleb_scc_epci.c
4269 --- linux-2.6.39/arch/powerpc/platforms/cell/celleb_scc_epci.c 2011-05-19 00:06:34.000000000 -0400
4270 +++ linux-2.6.39/arch/powerpc/platforms/cell/celleb_scc_epci.c 2011-05-22 19:36:30.000000000 -0400
4271 @@ -245,7 +245,7 @@ static int celleb_epci_write_config(stru
4272 return celleb_epci_check_abort(hose, addr);
4273 }
4274
4275 -struct pci_ops celleb_epci_ops = {
4276 +const struct pci_ops celleb_epci_ops = {
4277 .read = celleb_epci_read_config,
4278 .write = celleb_epci_write_config,
4279 };
4280 diff -urNp linux-2.6.39/arch/powerpc/platforms/cell/celleb_scc_pciex.c linux-2.6.39/arch/powerpc/platforms/cell/celleb_scc_pciex.c
4281 --- linux-2.6.39/arch/powerpc/platforms/cell/celleb_scc_pciex.c 2011-05-19 00:06:34.000000000 -0400
4282 +++ linux-2.6.39/arch/powerpc/platforms/cell/celleb_scc_pciex.c 2011-05-22 19:36:30.000000000 -0400
4283 @@ -399,7 +399,7 @@ static int scc_pciex_write_config(struct
4284 return PCIBIOS_SUCCESSFUL;
4285 }
4286
4287 -static struct pci_ops scc_pciex_pci_ops = {
4288 +static const struct pci_ops scc_pciex_pci_ops = {
4289 scc_pciex_read_config,
4290 scc_pciex_write_config,
4291 };
4292 diff -urNp linux-2.6.39/arch/powerpc/platforms/cell/iommu.c linux-2.6.39/arch/powerpc/platforms/cell/iommu.c
4293 --- linux-2.6.39/arch/powerpc/platforms/cell/iommu.c 2011-05-19 00:06:34.000000000 -0400
4294 +++ linux-2.6.39/arch/powerpc/platforms/cell/iommu.c 2011-05-22 19:36:30.000000000 -0400
4295 @@ -642,7 +642,7 @@ static int dma_fixed_dma_supported(struc
4296
4297 static int dma_set_mask_and_switch(struct device *dev, u64 dma_mask);
4298
4299 -struct dma_map_ops dma_iommu_fixed_ops = {
4300 +const struct dma_map_ops dma_iommu_fixed_ops = {
4301 .alloc_coherent = dma_fixed_alloc_coherent,
4302 .free_coherent = dma_fixed_free_coherent,
4303 .map_sg = dma_fixed_map_sg,
4304 diff -urNp linux-2.6.39/arch/powerpc/platforms/chrp/pci.c linux-2.6.39/arch/powerpc/platforms/chrp/pci.c
4305 --- linux-2.6.39/arch/powerpc/platforms/chrp/pci.c 2011-05-19 00:06:34.000000000 -0400
4306 +++ linux-2.6.39/arch/powerpc/platforms/chrp/pci.c 2011-05-22 19:36:30.000000000 -0400
4307 @@ -84,7 +84,7 @@ int gg2_write_config(struct pci_bus *bus
4308 return PCIBIOS_SUCCESSFUL;
4309 }
4310
4311 -static struct pci_ops gg2_pci_ops =
4312 +static const struct pci_ops gg2_pci_ops =
4313 {
4314 .read = gg2_read_config,
4315 .write = gg2_write_config,
4316 @@ -122,7 +122,7 @@ int rtas_write_config(struct pci_bus *bu
4317 return rval? PCIBIOS_DEVICE_NOT_FOUND: PCIBIOS_SUCCESSFUL;
4318 }
4319
4320 -static struct pci_ops rtas_pci_ops =
4321 +static const struct pci_ops rtas_pci_ops =
4322 {
4323 .read = rtas_read_config,
4324 .write = rtas_write_config,
4325 diff -urNp linux-2.6.39/arch/powerpc/platforms/iseries/pci.c linux-2.6.39/arch/powerpc/platforms/iseries/pci.c
4326 --- linux-2.6.39/arch/powerpc/platforms/iseries/pci.c 2011-05-19 00:06:34.000000000 -0400
4327 +++ linux-2.6.39/arch/powerpc/platforms/iseries/pci.c 2011-05-22 19:36:30.000000000 -0400
4328 @@ -533,7 +533,7 @@ static int iSeries_pci_write_config(stru
4329 return 0;
4330 }
4331
4332 -static struct pci_ops iSeries_pci_ops = {
4333 +static const struct pci_ops iSeries_pci_ops = {
4334 .read = iSeries_pci_read_config,
4335 .write = iSeries_pci_write_config
4336 };
4337 diff -urNp linux-2.6.39/arch/powerpc/platforms/maple/pci.c linux-2.6.39/arch/powerpc/platforms/maple/pci.c
4338 --- linux-2.6.39/arch/powerpc/platforms/maple/pci.c 2011-05-19 00:06:34.000000000 -0400
4339 +++ linux-2.6.39/arch/powerpc/platforms/maple/pci.c 2011-05-22 19:36:30.000000000 -0400
4340 @@ -180,7 +180,7 @@ static int u3_agp_write_config(struct pc
4341 return PCIBIOS_SUCCESSFUL;
4342 }
4343
4344 -static struct pci_ops u3_agp_pci_ops =
4345 +static const struct pci_ops u3_agp_pci_ops =
4346 {
4347 .read = u3_agp_read_config,
4348 .write = u3_agp_write_config,
4349 @@ -276,7 +276,7 @@ static int u3_ht_write_config(struct pci
4350 return PCIBIOS_SUCCESSFUL;
4351 }
4352
4353 -static struct pci_ops u3_ht_pci_ops =
4354 +static const struct pci_ops u3_ht_pci_ops =
4355 {
4356 .read = u3_ht_read_config,
4357 .write = u3_ht_write_config,
4358 @@ -381,7 +381,7 @@ static int u4_pcie_write_config(struct p
4359 return PCIBIOS_SUCCESSFUL;
4360 }
4361
4362 -static struct pci_ops u4_pcie_pci_ops =
4363 +static const struct pci_ops u4_pcie_pci_ops =
4364 {
4365 .read = u4_pcie_read_config,
4366 .write = u4_pcie_write_config,
4367 diff -urNp linux-2.6.39/arch/powerpc/platforms/pasemi/pci.c linux-2.6.39/arch/powerpc/platforms/pasemi/pci.c
4368 --- linux-2.6.39/arch/powerpc/platforms/pasemi/pci.c 2011-05-19 00:06:34.000000000 -0400
4369 +++ linux-2.6.39/arch/powerpc/platforms/pasemi/pci.c 2011-05-22 19:36:30.000000000 -0400
4370 @@ -176,7 +176,7 @@ static int pa_pxp_write_config(struct pc
4371 return PCIBIOS_SUCCESSFUL;
4372 }
4373
4374 -static struct pci_ops pa_pxp_ops = {
4375 +static const struct pci_ops pa_pxp_ops = {
4376 .read = pa_pxp_read_config,
4377 .write = pa_pxp_write_config,
4378 };
4379 diff -urNp linux-2.6.39/arch/powerpc/platforms/powermac/pci.c linux-2.6.39/arch/powerpc/platforms/powermac/pci.c
4380 --- linux-2.6.39/arch/powerpc/platforms/powermac/pci.c 2011-05-19 00:06:34.000000000 -0400
4381 +++ linux-2.6.39/arch/powerpc/platforms/powermac/pci.c 2011-05-22 19:36:30.000000000 -0400
4382 @@ -218,7 +218,7 @@ static int macrisc_write_config(struct p
4383 return PCIBIOS_SUCCESSFUL;
4384 }
4385
4386 -static struct pci_ops macrisc_pci_ops =
4387 +static const struct pci_ops macrisc_pci_ops =
4388 {
4389 .read = macrisc_read_config,
4390 .write = macrisc_write_config,
4391 @@ -273,7 +273,7 @@ chaos_write_config(struct pci_bus *bus,
4392 return macrisc_write_config(bus, devfn, offset, len, val);
4393 }
4394
4395 -static struct pci_ops chaos_pci_ops =
4396 +static const struct pci_ops chaos_pci_ops =
4397 {
4398 .read = chaos_read_config,
4399 .write = chaos_write_config,
4400 diff -urNp linux-2.6.39/arch/powerpc/platforms/ps3/system-bus.c linux-2.6.39/arch/powerpc/platforms/ps3/system-bus.c
4401 --- linux-2.6.39/arch/powerpc/platforms/ps3/system-bus.c 2011-05-19 00:06:34.000000000 -0400
4402 +++ linux-2.6.39/arch/powerpc/platforms/ps3/system-bus.c 2011-05-22 19:36:30.000000000 -0400
4403 @@ -695,7 +695,7 @@ static int ps3_dma_supported(struct devi
4404 return mask >= DMA_BIT_MASK(32);
4405 }
4406
4407 -static struct dma_map_ops ps3_sb_dma_ops = {
4408 +static const struct dma_map_ops ps3_sb_dma_ops = {
4409 .alloc_coherent = ps3_alloc_coherent,
4410 .free_coherent = ps3_free_coherent,
4411 .map_sg = ps3_sb_map_sg,
4412 @@ -705,7 +705,7 @@ static struct dma_map_ops ps3_sb_dma_ops
4413 .unmap_page = ps3_unmap_page,
4414 };
4415
4416 -static struct dma_map_ops ps3_ioc0_dma_ops = {
4417 +static const struct dma_map_ops ps3_ioc0_dma_ops = {
4418 .alloc_coherent = ps3_alloc_coherent,
4419 .free_coherent = ps3_free_coherent,
4420 .map_sg = ps3_ioc0_map_sg,
4421 diff -urNp linux-2.6.39/arch/powerpc/sysdev/fsl_pci.c linux-2.6.39/arch/powerpc/sysdev/fsl_pci.c
4422 --- linux-2.6.39/arch/powerpc/sysdev/fsl_pci.c 2011-05-19 00:06:34.000000000 -0400
4423 +++ linux-2.6.39/arch/powerpc/sysdev/fsl_pci.c 2011-05-22 19:36:30.000000000 -0400
4424 @@ -573,7 +573,7 @@ static int mpc83xx_pcie_write_config(str
4425 return PCIBIOS_SUCCESSFUL;
4426 }
4427
4428 -static struct pci_ops mpc83xx_pcie_ops = {
4429 +static const struct pci_ops mpc83xx_pcie_ops = {
4430 .read = mpc83xx_pcie_read_config,
4431 .write = mpc83xx_pcie_write_config,
4432 };
4433 diff -urNp linux-2.6.39/arch/powerpc/sysdev/indirect_pci.c linux-2.6.39/arch/powerpc/sysdev/indirect_pci.c
4434 --- linux-2.6.39/arch/powerpc/sysdev/indirect_pci.c 2011-05-19 00:06:34.000000000 -0400
4435 +++ linux-2.6.39/arch/powerpc/sysdev/indirect_pci.c 2011-05-22 19:36:30.000000000 -0400
4436 @@ -148,7 +148,7 @@ indirect_write_config(struct pci_bus *bu
4437 return PCIBIOS_SUCCESSFUL;
4438 }
4439
4440 -static struct pci_ops indirect_pci_ops =
4441 +static const struct pci_ops indirect_pci_ops =
4442 {
4443 .read = indirect_read_config,
4444 .write = indirect_write_config,
4445 diff -urNp linux-2.6.39/arch/powerpc/sysdev/ppc4xx_pci.c linux-2.6.39/arch/powerpc/sysdev/ppc4xx_pci.c
4446 --- linux-2.6.39/arch/powerpc/sysdev/ppc4xx_pci.c 2011-05-19 00:06:34.000000000 -0400
4447 +++ linux-2.6.39/arch/powerpc/sysdev/ppc4xx_pci.c 2011-05-22 19:36:30.000000000 -0400
4448 @@ -1514,7 +1514,7 @@ static int ppc4xx_pciex_write_config(str
4449 return PCIBIOS_SUCCESSFUL;
4450 }
4451
4452 -static struct pci_ops ppc4xx_pciex_pci_ops =
4453 +static const struct pci_ops ppc4xx_pciex_pci_ops =
4454 {
4455 .read = ppc4xx_pciex_read_config,
4456 .write = ppc4xx_pciex_write_config,
4457 diff -urNp linux-2.6.39/arch/powerpc/sysdev/tsi108_pci.c linux-2.6.39/arch/powerpc/sysdev/tsi108_pci.c
4458 --- linux-2.6.39/arch/powerpc/sysdev/tsi108_pci.c 2011-05-19 00:06:34.000000000 -0400
4459 +++ linux-2.6.39/arch/powerpc/sysdev/tsi108_pci.c 2011-05-22 19:36:30.000000000 -0400
4460 @@ -190,7 +190,7 @@ void tsi108_clear_pci_cfg_error(void)
4461 tsi108_clear_pci_error(tsi108_pci_cfg_phys);
4462 }
4463
4464 -static struct pci_ops tsi108_direct_pci_ops = {
4465 +static const struct pci_ops tsi108_direct_pci_ops = {
4466 .read = tsi108_direct_read_config,
4467 .write = tsi108_direct_write_config,
4468 };
4469 diff -urNp linux-2.6.39/arch/s390/include/asm/elf.h linux-2.6.39/arch/s390/include/asm/elf.h
4470 --- linux-2.6.39/arch/s390/include/asm/elf.h 2011-05-19 00:06:34.000000000 -0400
4471 +++ linux-2.6.39/arch/s390/include/asm/elf.h 2011-05-22 19:36:30.000000000 -0400
4472 @@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
4473 the loader. We need to make sure that it is out of the way of the program
4474 that it will "exec", and that there is sufficient room for the brk. */
4475
4476 -extern unsigned long randomize_et_dyn(unsigned long base);
4477 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
4478 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
4479 +
4480 +#ifdef CONFIG_PAX_ASLR
4481 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
4482 +
4483 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26 )
4484 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26 )
4485 +#endif
4486
4487 /* This yields a mask that user programs can use to figure out what
4488 instruction set this CPU supports. */
4489 @@ -222,7 +228,4 @@ struct linux_binprm;
4490 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
4491 int arch_setup_additional_pages(struct linux_binprm *, int);
4492
4493 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4494 -#define arch_randomize_brk arch_randomize_brk
4495 -
4496 #endif
4497 diff -urNp linux-2.6.39/arch/s390/include/asm/system.h linux-2.6.39/arch/s390/include/asm/system.h
4498 --- linux-2.6.39/arch/s390/include/asm/system.h 2011-05-19 00:06:34.000000000 -0400
4499 +++ linux-2.6.39/arch/s390/include/asm/system.h 2011-05-22 19:36:30.000000000 -0400
4500 @@ -255,7 +255,7 @@ extern void (*_machine_restart)(char *co
4501 extern void (*_machine_halt)(void);
4502 extern void (*_machine_power_off)(void);
4503
4504 -extern unsigned long arch_align_stack(unsigned long sp);
4505 +#define arch_align_stack(x) ((x) & ~0xfUL)
4506
4507 static inline int tprot(unsigned long addr)
4508 {
4509 diff -urNp linux-2.6.39/arch/s390/include/asm/uaccess.h linux-2.6.39/arch/s390/include/asm/uaccess.h
4510 --- linux-2.6.39/arch/s390/include/asm/uaccess.h 2011-05-19 00:06:34.000000000 -0400
4511 +++ linux-2.6.39/arch/s390/include/asm/uaccess.h 2011-05-22 19:36:30.000000000 -0400
4512 @@ -234,6 +234,10 @@ static inline unsigned long __must_check
4513 copy_to_user(void __user *to, const void *from, unsigned long n)
4514 {
4515 might_fault();
4516 +
4517 + if ((long)n < 0)
4518 + return n;
4519 +
4520 if (access_ok(VERIFY_WRITE, to, n))
4521 n = __copy_to_user(to, from, n);
4522 return n;
4523 @@ -259,6 +263,9 @@ copy_to_user(void __user *to, const void
4524 static inline unsigned long __must_check
4525 __copy_from_user(void *to, const void __user *from, unsigned long n)
4526 {
4527 + if ((long)n < 0)
4528 + return n;
4529 +
4530 if (__builtin_constant_p(n) && (n <= 256))
4531 return uaccess.copy_from_user_small(n, from, to);
4532 else
4533 @@ -293,6 +300,10 @@ copy_from_user(void *to, const void __us
4534 unsigned int sz = __compiletime_object_size(to);
4535
4536 might_fault();
4537 +
4538 + if ((long)n < 0)
4539 + return n;
4540 +
4541 if (unlikely(sz != -1 && sz < n)) {
4542 copy_from_user_overflow();
4543 return n;
4544 diff -urNp linux-2.6.39/arch/s390/Kconfig linux-2.6.39/arch/s390/Kconfig
4545 --- linux-2.6.39/arch/s390/Kconfig 2011-05-19 00:06:34.000000000 -0400
4546 +++ linux-2.6.39/arch/s390/Kconfig 2011-05-22 19:36:30.000000000 -0400
4547 @@ -234,11 +234,9 @@ config S390_EXEC_PROTECT
4548 prompt "Data execute protection"
4549 help
4550 This option allows to enable a buffer overflow protection for user
4551 - space programs and it also selects the addressing mode option above.
4552 - The kernel parameter noexec=on will enable this feature and also
4553 - switch the addressing modes, default is disabled. Enabling this (via
4554 - kernel parameter) on machines earlier than IBM System z9 this will
4555 - reduce system performance.
4556 + space programs.
4557 + Enabling this (via kernel parameter) on machines earlier than IBM
4558 + System z9 this will reduce system performance.
4559
4560 comment "Code generation options"
4561
4562 diff -urNp linux-2.6.39/arch/s390/kernel/module.c linux-2.6.39/arch/s390/kernel/module.c
4563 --- linux-2.6.39/arch/s390/kernel/module.c 2011-05-19 00:06:34.000000000 -0400
4564 +++ linux-2.6.39/arch/s390/kernel/module.c 2011-05-22 19:36:30.000000000 -0400
4565 @@ -168,11 +168,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr,
4566
4567 /* Increase core size by size of got & plt and set start
4568 offsets for got and plt. */
4569 - me->core_size = ALIGN(me->core_size, 4);
4570 - me->arch.got_offset = me->core_size;
4571 - me->core_size += me->arch.got_size;
4572 - me->arch.plt_offset = me->core_size;
4573 - me->core_size += me->arch.plt_size;
4574 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
4575 + me->arch.got_offset = me->core_size_rw;
4576 + me->core_size_rw += me->arch.got_size;
4577 + me->arch.plt_offset = me->core_size_rx;
4578 + me->core_size_rx += me->arch.plt_size;
4579 return 0;
4580 }
4581
4582 @@ -258,7 +258,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
4583 if (info->got_initialized == 0) {
4584 Elf_Addr *gotent;
4585
4586 - gotent = me->module_core + me->arch.got_offset +
4587 + gotent = me->module_core_rw + me->arch.got_offset +
4588 info->got_offset;
4589 *gotent = val;
4590 info->got_initialized = 1;
4591 @@ -282,7 +282,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
4592 else if (r_type == R_390_GOTENT ||
4593 r_type == R_390_GOTPLTENT)
4594 *(unsigned int *) loc =
4595 - (val + (Elf_Addr) me->module_core - loc) >> 1;
4596 + (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
4597 else if (r_type == R_390_GOT64 ||
4598 r_type == R_390_GOTPLT64)
4599 *(unsigned long *) loc = val;
4600 @@ -296,7 +296,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
4601 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
4602 if (info->plt_initialized == 0) {
4603 unsigned int *ip;
4604 - ip = me->module_core + me->arch.plt_offset +
4605 + ip = me->module_core_rx + me->arch.plt_offset +
4606 info->plt_offset;
4607 #ifndef CONFIG_64BIT
4608 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
4609 @@ -321,7 +321,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
4610 val - loc + 0xffffUL < 0x1ffffeUL) ||
4611 (r_type == R_390_PLT32DBL &&
4612 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
4613 - val = (Elf_Addr) me->module_core +
4614 + val = (Elf_Addr) me->module_core_rx +
4615 me->arch.plt_offset +
4616 info->plt_offset;
4617 val += rela->r_addend - loc;
4618 @@ -343,7 +343,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
4619 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
4620 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
4621 val = val + rela->r_addend -
4622 - ((Elf_Addr) me->module_core + me->arch.got_offset);
4623 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
4624 if (r_type == R_390_GOTOFF16)
4625 *(unsigned short *) loc = val;
4626 else if (r_type == R_390_GOTOFF32)
4627 @@ -353,7 +353,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
4628 break;
4629 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
4630 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
4631 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
4632 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
4633 rela->r_addend - loc;
4634 if (r_type == R_390_GOTPC)
4635 *(unsigned int *) loc = val;
4636 diff -urNp linux-2.6.39/arch/s390/kernel/process.c linux-2.6.39/arch/s390/kernel/process.c
4637 --- linux-2.6.39/arch/s390/kernel/process.c 2011-05-19 00:06:34.000000000 -0400
4638 +++ linux-2.6.39/arch/s390/kernel/process.c 2011-05-22 19:36:30.000000000 -0400
4639 @@ -334,39 +334,3 @@ unsigned long get_wchan(struct task_stru
4640 }
4641 return 0;
4642 }
4643 -
4644 -unsigned long arch_align_stack(unsigned long sp)
4645 -{
4646 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4647 - sp -= get_random_int() & ~PAGE_MASK;
4648 - return sp & ~0xf;
4649 -}
4650 -
4651 -static inline unsigned long brk_rnd(void)
4652 -{
4653 - /* 8MB for 32bit, 1GB for 64bit */
4654 - if (is_32bit_task())
4655 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
4656 - else
4657 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
4658 -}
4659 -
4660 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4661 -{
4662 - unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
4663 -
4664 - if (ret < mm->brk)
4665 - return mm->brk;
4666 - return ret;
4667 -}
4668 -
4669 -unsigned long randomize_et_dyn(unsigned long base)
4670 -{
4671 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4672 -
4673 - if (!(current->flags & PF_RANDOMIZE))
4674 - return base;
4675 - if (ret < base)
4676 - return base;
4677 - return ret;
4678 -}
4679 diff -urNp linux-2.6.39/arch/s390/kernel/setup.c linux-2.6.39/arch/s390/kernel/setup.c
4680 --- linux-2.6.39/arch/s390/kernel/setup.c 2011-05-19 00:06:34.000000000 -0400
4681 +++ linux-2.6.39/arch/s390/kernel/setup.c 2011-05-22 19:36:30.000000000 -0400
4682 @@ -271,7 +271,7 @@ static int __init early_parse_mem(char *
4683 }
4684 early_param("mem", early_parse_mem);
4685
4686 -unsigned int user_mode = HOME_SPACE_MODE;
4687 +unsigned int user_mode = SECONDARY_SPACE_MODE;
4688 EXPORT_SYMBOL_GPL(user_mode);
4689
4690 static int set_amode_and_uaccess(unsigned long user_amode,
4691 @@ -300,17 +300,6 @@ static int set_amode_and_uaccess(unsigne
4692 }
4693 }
4694
4695 -/*
4696 - * Switch kernel/user addressing modes?
4697 - */
4698 -static int __init early_parse_switch_amode(char *p)
4699 -{
4700 - if (user_mode != SECONDARY_SPACE_MODE)
4701 - user_mode = PRIMARY_SPACE_MODE;
4702 - return 0;
4703 -}
4704 -early_param("switch_amode", early_parse_switch_amode);
4705 -
4706 static int __init early_parse_user_mode(char *p)
4707 {
4708 if (p && strcmp(p, "primary") == 0)
4709 @@ -327,20 +316,6 @@ static int __init early_parse_user_mode(
4710 }
4711 early_param("user_mode", early_parse_user_mode);
4712
4713 -#ifdef CONFIG_S390_EXEC_PROTECT
4714 -/*
4715 - * Enable execute protection?
4716 - */
4717 -static int __init early_parse_noexec(char *p)
4718 -{
4719 - if (!strncmp(p, "off", 3))
4720 - return 0;
4721 - user_mode = SECONDARY_SPACE_MODE;
4722 - return 0;
4723 -}
4724 -early_param("noexec", early_parse_noexec);
4725 -#endif /* CONFIG_S390_EXEC_PROTECT */
4726 -
4727 static void setup_addressing_mode(void)
4728 {
4729 if (user_mode == SECONDARY_SPACE_MODE) {
4730 diff -urNp linux-2.6.39/arch/s390/mm/maccess.c linux-2.6.39/arch/s390/mm/maccess.c
4731 --- linux-2.6.39/arch/s390/mm/maccess.c 2011-05-19 00:06:34.000000000 -0400
4732 +++ linux-2.6.39/arch/s390/mm/maccess.c 2011-05-22 19:36:30.000000000 -0400
4733 @@ -45,7 +45,7 @@ static long probe_kernel_write_odd(void
4734 return rc ? rc : count;
4735 }
4736
4737 -long probe_kernel_write(void *dst, void *src, size_t size)
4738 +long probe_kernel_write(void *dst, const void *src, size_t size)
4739 {
4740 long copied = 0;
4741
4742 diff -urNp linux-2.6.39/arch/s390/mm/mmap.c linux-2.6.39/arch/s390/mm/mmap.c
4743 --- linux-2.6.39/arch/s390/mm/mmap.c 2011-05-19 00:06:34.000000000 -0400
4744 +++ linux-2.6.39/arch/s390/mm/mmap.c 2011-05-22 19:36:30.000000000 -0400
4745 @@ -91,10 +91,22 @@ void arch_pick_mmap_layout(struct mm_str
4746 */
4747 if (mmap_is_legacy()) {
4748 mm->mmap_base = TASK_UNMAPPED_BASE;
4749 +
4750 +#ifdef CONFIG_PAX_RANDMMAP
4751 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4752 + mm->mmap_base += mm->delta_mmap;
4753 +#endif
4754 +
4755 mm->get_unmapped_area = arch_get_unmapped_area;
4756 mm->unmap_area = arch_unmap_area;
4757 } else {
4758 mm->mmap_base = mmap_base();
4759 +
4760 +#ifdef CONFIG_PAX_RANDMMAP
4761 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4762 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4763 +#endif
4764 +
4765 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4766 mm->unmap_area = arch_unmap_area_topdown;
4767 }
4768 @@ -166,10 +178,22 @@ void arch_pick_mmap_layout(struct mm_str
4769 */
4770 if (mmap_is_legacy()) {
4771 mm->mmap_base = TASK_UNMAPPED_BASE;
4772 +
4773 +#ifdef CONFIG_PAX_RANDMMAP
4774 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4775 + mm->mmap_base += mm->delta_mmap;
4776 +#endif
4777 +
4778 mm->get_unmapped_area = s390_get_unmapped_area;
4779 mm->unmap_area = arch_unmap_area;
4780 } else {
4781 mm->mmap_base = mmap_base();
4782 +
4783 +#ifdef CONFIG_PAX_RANDMMAP
4784 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4785 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4786 +#endif
4787 +
4788 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
4789 mm->unmap_area = arch_unmap_area_topdown;
4790 }
4791 diff -urNp linux-2.6.39/arch/score/include/asm/system.h linux-2.6.39/arch/score/include/asm/system.h
4792 --- linux-2.6.39/arch/score/include/asm/system.h 2011-05-19 00:06:34.000000000 -0400
4793 +++ linux-2.6.39/arch/score/include/asm/system.h 2011-05-22 19:36:30.000000000 -0400
4794 @@ -17,7 +17,7 @@ do { \
4795 #define finish_arch_switch(prev) do {} while (0)
4796
4797 typedef void (*vi_handler_t)(void);
4798 -extern unsigned long arch_align_stack(unsigned long sp);
4799 +#define arch_align_stack(x) (x)
4800
4801 #define mb() barrier()
4802 #define rmb() barrier()
4803 diff -urNp linux-2.6.39/arch/score/kernel/process.c linux-2.6.39/arch/score/kernel/process.c
4804 --- linux-2.6.39/arch/score/kernel/process.c 2011-05-19 00:06:34.000000000 -0400
4805 +++ linux-2.6.39/arch/score/kernel/process.c 2011-05-22 19:36:30.000000000 -0400
4806 @@ -161,8 +161,3 @@ unsigned long get_wchan(struct task_stru
4807
4808 return task_pt_regs(task)->cp0_epc;
4809 }
4810 -
4811 -unsigned long arch_align_stack(unsigned long sp)
4812 -{
4813 - return sp;
4814 -}
4815 diff -urNp linux-2.6.39/arch/sh/drivers/pci/ops-dreamcast.c linux-2.6.39/arch/sh/drivers/pci/ops-dreamcast.c
4816 --- linux-2.6.39/arch/sh/drivers/pci/ops-dreamcast.c 2011-05-19 00:06:34.000000000 -0400
4817 +++ linux-2.6.39/arch/sh/drivers/pci/ops-dreamcast.c 2011-05-22 19:36:30.000000000 -0400
4818 @@ -76,7 +76,7 @@ static int gapspci_write(struct pci_bus
4819 return PCIBIOS_SUCCESSFUL;
4820 }
4821
4822 -struct pci_ops gapspci_pci_ops = {
4823 +const struct pci_ops gapspci_pci_ops = {
4824 .read = gapspci_read,
4825 .write = gapspci_write,
4826 };
4827 diff -urNp linux-2.6.39/arch/sh/drivers/pci/ops-sh4.c linux-2.6.39/arch/sh/drivers/pci/ops-sh4.c
4828 --- linux-2.6.39/arch/sh/drivers/pci/ops-sh4.c 2011-05-19 00:06:34.000000000 -0400
4829 +++ linux-2.6.39/arch/sh/drivers/pci/ops-sh4.c 2011-05-22 19:36:30.000000000 -0400
4830 @@ -96,7 +96,7 @@ static int sh4_pci_write(struct pci_bus
4831 return PCIBIOS_SUCCESSFUL;
4832 }
4833
4834 -struct pci_ops sh4_pci_ops = {
4835 +const struct pci_ops sh4_pci_ops = {
4836 .read = sh4_pci_read,
4837 .write = sh4_pci_write,
4838 };
4839 diff -urNp linux-2.6.39/arch/sh/drivers/pci/ops-sh5.c linux-2.6.39/arch/sh/drivers/pci/ops-sh5.c
4840 --- linux-2.6.39/arch/sh/drivers/pci/ops-sh5.c 2011-05-19 00:06:34.000000000 -0400
4841 +++ linux-2.6.39/arch/sh/drivers/pci/ops-sh5.c 2011-05-22 19:36:30.000000000 -0400
4842 @@ -62,7 +62,7 @@ static int sh5pci_write(struct pci_bus *
4843 return PCIBIOS_SUCCESSFUL;
4844 }
4845
4846 -struct pci_ops sh5_pci_ops = {
4847 +const struct pci_ops sh5_pci_ops = {
4848 .read = sh5pci_read,
4849 .write = sh5pci_write,
4850 };
4851 diff -urNp linux-2.6.39/arch/sh/drivers/pci/ops-sh7786.c linux-2.6.39/arch/sh/drivers/pci/ops-sh7786.c
4852 --- linux-2.6.39/arch/sh/drivers/pci/ops-sh7786.c 2011-05-19 00:06:34.000000000 -0400
4853 +++ linux-2.6.39/arch/sh/drivers/pci/ops-sh7786.c 2011-05-22 19:36:30.000000000 -0400
4854 @@ -165,7 +165,7 @@ out:
4855 return ret;
4856 }
4857
4858 -struct pci_ops sh7786_pci_ops = {
4859 +const struct pci_ops sh7786_pci_ops = {
4860 .read = sh7786_pcie_read,
4861 .write = sh7786_pcie_write,
4862 };
4863 diff -urNp linux-2.6.39/arch/sh/drivers/pci/pcie-sh7786.c linux-2.6.39/arch/sh/drivers/pci/pcie-sh7786.c
4864 --- linux-2.6.39/arch/sh/drivers/pci/pcie-sh7786.c 2011-05-19 00:06:34.000000000 -0400
4865 +++ linux-2.6.39/arch/sh/drivers/pci/pcie-sh7786.c 2011-05-22 19:36:30.000000000 -0400
4866 @@ -109,7 +109,7 @@ static struct resource sh7786_pci2_resou
4867 },
4868 };
4869
4870 -extern struct pci_ops sh7786_pci_ops;
4871 +extern const struct pci_ops sh7786_pci_ops;
4872
4873 #define DEFINE_CONTROLLER(start, idx) \
4874 { \
4875 diff -urNp linux-2.6.39/arch/sh/drivers/pci/pci-sh4.h linux-2.6.39/arch/sh/drivers/pci/pci-sh4.h
4876 --- linux-2.6.39/arch/sh/drivers/pci/pci-sh4.h 2011-05-19 00:06:34.000000000 -0400
4877 +++ linux-2.6.39/arch/sh/drivers/pci/pci-sh4.h 2011-05-22 19:36:30.000000000 -0400
4878 @@ -161,7 +161,7 @@
4879 #define SH4_PCIPDR 0x220 /* Port IO Data Register */
4880
4881 /* arch/sh/kernel/drivers/pci/ops-sh4.c */
4882 -extern struct pci_ops sh4_pci_ops;
4883 +extern const struct pci_ops sh4_pci_ops;
4884 int pci_fixup_pcic(struct pci_channel *chan);
4885
4886 struct sh4_pci_address_space {
4887 diff -urNp linux-2.6.39/arch/sh/drivers/pci/pci-sh5.h linux-2.6.39/arch/sh/drivers/pci/pci-sh5.h
4888 --- linux-2.6.39/arch/sh/drivers/pci/pci-sh5.h 2011-05-19 00:06:34.000000000 -0400
4889 +++ linux-2.6.39/arch/sh/drivers/pci/pci-sh5.h 2011-05-22 19:36:30.000000000 -0400
4890 @@ -105,6 +105,6 @@ extern unsigned long pcicr_virt;
4891 #define PCISH5_MEM_SIZCONV(x) (((x / 0x40000) - 1) << 18)
4892 #define PCISH5_IO_SIZCONV(x) (((x / 0x40000) - 1) << 18)
4893
4894 -extern struct pci_ops sh5_pci_ops;
4895 +extern const struct pci_ops sh5_pci_ops;
4896
4897 #endif /* __PCI_SH5_H */
4898 diff -urNp linux-2.6.39/arch/sh/include/asm/dma-mapping.h linux-2.6.39/arch/sh/include/asm/dma-mapping.h
4899 --- linux-2.6.39/arch/sh/include/asm/dma-mapping.h 2011-05-19 00:06:34.000000000 -0400
4900 +++ linux-2.6.39/arch/sh/include/asm/dma-mapping.h 2011-05-22 19:36:30.000000000 -0400
4901 @@ -1,10 +1,10 @@
4902 #ifndef __ASM_SH_DMA_MAPPING_H
4903 #define __ASM_SH_DMA_MAPPING_H
4904
4905 -extern struct dma_map_ops *dma_ops;
4906 +extern const struct dma_map_ops *dma_ops;
4907 extern void no_iommu_init(void);
4908
4909 -static inline struct dma_map_ops *get_dma_ops(struct device *dev)
4910 +static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
4911 {
4912 return dma_ops;
4913 }
4914 @@ -14,7 +14,7 @@ static inline struct dma_map_ops *get_dm
4915
4916 static inline int dma_supported(struct device *dev, u64 mask)
4917 {
4918 - struct dma_map_ops *ops = get_dma_ops(dev);
4919 + const struct dma_map_ops *ops = get_dma_ops(dev);
4920
4921 if (ops->dma_supported)
4922 return ops->dma_supported(dev, mask);
4923 @@ -24,7 +24,7 @@ static inline int dma_supported(struct d
4924
4925 static inline int dma_set_mask(struct device *dev, u64 mask)
4926 {
4927 - struct dma_map_ops *ops = get_dma_ops(dev);
4928 + const struct dma_map_ops *ops = get_dma_ops(dev);
4929
4930 if (!dev->dma_mask || !dma_supported(dev, mask))
4931 return -EIO;
4932 @@ -44,7 +44,7 @@ void dma_cache_sync(struct device *dev,
4933
4934 static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
4935 {
4936 - struct dma_map_ops *ops = get_dma_ops(dev);
4937 + const struct dma_map_ops *ops = get_dma_ops(dev);
4938
4939 if (ops->mapping_error)
4940 return ops->mapping_error(dev, dma_addr);
4941 @@ -55,7 +55,7 @@ static inline int dma_mapping_error(stru
4942 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
4943 dma_addr_t *dma_handle, gfp_t gfp)
4944 {
4945 - struct dma_map_ops *ops = get_dma_ops(dev);
4946 + const struct dma_map_ops *ops = get_dma_ops(dev);
4947 void *memory;
4948
4949 if (dma_alloc_from_coherent(dev, size, dma_handle, &memory))
4950 @@ -72,7 +72,7 @@ static inline void *dma_alloc_coherent(s
4951 static inline void dma_free_coherent(struct device *dev, size_t size,
4952 void *vaddr, dma_addr_t dma_handle)
4953 {
4954 - struct dma_map_ops *ops = get_dma_ops(dev);
4955 + const struct dma_map_ops *ops = get_dma_ops(dev);
4956
4957 if (dma_release_from_coherent(dev, get_order(size), vaddr))
4958 return;
4959 diff -urNp linux-2.6.39/arch/sh/kernel/dma-nommu.c linux-2.6.39/arch/sh/kernel/dma-nommu.c
4960 --- linux-2.6.39/arch/sh/kernel/dma-nommu.c 2011-05-19 00:06:34.000000000 -0400
4961 +++ linux-2.6.39/arch/sh/kernel/dma-nommu.c 2011-05-22 19:36:30.000000000 -0400
4962 @@ -62,7 +62,7 @@ static void nommu_sync_sg(struct device
4963 }
4964 #endif
4965
4966 -struct dma_map_ops nommu_dma_ops = {
4967 +const struct dma_map_ops nommu_dma_ops = {
4968 .alloc_coherent = dma_generic_alloc_coherent,
4969 .free_coherent = dma_generic_free_coherent,
4970 .map_page = nommu_map_page,
4971 diff -urNp linux-2.6.39/arch/sh/kernel/kgdb.c linux-2.6.39/arch/sh/kernel/kgdb.c
4972 --- linux-2.6.39/arch/sh/kernel/kgdb.c 2011-05-19 00:06:34.000000000 -0400
4973 +++ linux-2.6.39/arch/sh/kernel/kgdb.c 2011-05-22 19:36:30.000000000 -0400
4974 @@ -319,7 +319,7 @@ void kgdb_arch_exit(void)
4975 unregister_die_notifier(&kgdb_notifier);
4976 }
4977
4978 -struct kgdb_arch arch_kgdb_ops = {
4979 +const struct kgdb_arch arch_kgdb_ops = {
4980 /* Breakpoint instruction: trapa #0x3c */
4981 #ifdef CONFIG_CPU_LITTLE_ENDIAN
4982 .gdb_bpt_instr = { 0x3c, 0xc3 },
4983 diff -urNp linux-2.6.39/arch/sh/mm/consistent.c linux-2.6.39/arch/sh/mm/consistent.c
4984 --- linux-2.6.39/arch/sh/mm/consistent.c 2011-05-19 00:06:34.000000000 -0400
4985 +++ linux-2.6.39/arch/sh/mm/consistent.c 2011-05-22 19:36:30.000000000 -0400
4986 @@ -22,7 +22,7 @@
4987
4988 #define PREALLOC_DMA_DEBUG_ENTRIES 4096
4989
4990 -struct dma_map_ops *dma_ops;
4991 +const struct dma_map_ops *dma_ops;
4992 EXPORT_SYMBOL(dma_ops);
4993
4994 static int __init dma_init(void)
4995 diff -urNp linux-2.6.39/arch/sh/mm/mmap.c linux-2.6.39/arch/sh/mm/mmap.c
4996 --- linux-2.6.39/arch/sh/mm/mmap.c 2011-05-19 00:06:34.000000000 -0400
4997 +++ linux-2.6.39/arch/sh/mm/mmap.c 2011-05-22 19:36:30.000000000 -0400
4998 @@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(str
4999 addr = PAGE_ALIGN(addr);
5000
5001 vma = find_vma(mm, addr);
5002 - if (TASK_SIZE - len >= addr &&
5003 - (!vma || addr + len <= vma->vm_start))
5004 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5005 return addr;
5006 }
5007
5008 @@ -106,7 +105,7 @@ full_search:
5009 }
5010 return -ENOMEM;
5011 }
5012 - if (likely(!vma || addr + len <= vma->vm_start)) {
5013 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5014 /*
5015 * Remember the place where we stopped the search:
5016 */
5017 @@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct fi
5018 addr = PAGE_ALIGN(addr);
5019
5020 vma = find_vma(mm, addr);
5021 - if (TASK_SIZE - len >= addr &&
5022 - (!vma || addr + len <= vma->vm_start))
5023 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5024 return addr;
5025 }
5026
5027 @@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct fi
5028 /* make sure it can fit in the remaining address space */
5029 if (likely(addr > len)) {
5030 vma = find_vma(mm, addr-len);
5031 - if (!vma || addr <= vma->vm_start) {
5032 + if (check_heap_stack_gap(vma, addr - len, len)) {
5033 /* remember the address as a hint for next time */
5034 return (mm->free_area_cache = addr-len);
5035 }
5036 @@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct fi
5037 if (unlikely(mm->mmap_base < len))
5038 goto bottomup;
5039
5040 - addr = mm->mmap_base-len;
5041 - if (do_colour_align)
5042 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5043 + addr = mm->mmap_base - len;
5044
5045 do {
5046 + if (do_colour_align)
5047 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5048 /*
5049 * Lookup failure means no vma is above this address,
5050 * else if new region fits below vma->vm_start,
5051 * return with success:
5052 */
5053 vma = find_vma(mm, addr);
5054 - if (likely(!vma || addr+len <= vma->vm_start)) {
5055 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5056 /* remember the address as a hint for next time */
5057 return (mm->free_area_cache = addr);
5058 }
5059 @@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct fi
5060 mm->cached_hole_size = vma->vm_start - addr;
5061
5062 /* try just below the current vma->vm_start */
5063 - addr = vma->vm_start-len;
5064 - if (do_colour_align)
5065 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5066 - } while (likely(len < vma->vm_start));
5067 + addr = skip_heap_stack_gap(vma, len);
5068 + } while (!IS_ERR_VALUE(addr));
5069
5070 bottomup:
5071 /*
5072 diff -urNp linux-2.6.39/arch/sparc/include/asm/atomic_64.h linux-2.6.39/arch/sparc/include/asm/atomic_64.h
5073 --- linux-2.6.39/arch/sparc/include/asm/atomic_64.h 2011-05-19 00:06:34.000000000 -0400
5074 +++ linux-2.6.39/arch/sparc/include/asm/atomic_64.h 2011-05-22 19:36:30.000000000 -0400
5075 @@ -14,18 +14,40 @@
5076 #define ATOMIC64_INIT(i) { (i) }
5077
5078 #define atomic_read(v) (*(volatile int *)&(v)->counter)
5079 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5080 +{
5081 + return v->counter;
5082 +}
5083 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
5084 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5085 +{
5086 + return v->counter;
5087 +}
5088
5089 #define atomic_set(v, i) (((v)->counter) = i)
5090 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5091 +{
5092 + v->counter = i;
5093 +}
5094 #define atomic64_set(v, i) (((v)->counter) = i)
5095 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5096 +{
5097 + v->counter = i;
5098 +}
5099
5100 extern void atomic_add(int, atomic_t *);
5101 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
5102 extern void atomic64_add(long, atomic64_t *);
5103 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
5104 extern void atomic_sub(int, atomic_t *);
5105 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
5106 extern void atomic64_sub(long, atomic64_t *);
5107 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
5108
5109 extern int atomic_add_ret(int, atomic_t *);
5110 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
5111 extern long atomic64_add_ret(long, atomic64_t *);
5112 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
5113 extern int atomic_sub_ret(int, atomic_t *);
5114 extern long atomic64_sub_ret(long, atomic64_t *);
5115
5116 @@ -33,12 +55,24 @@ extern long atomic64_sub_ret(long, atomi
5117 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
5118
5119 #define atomic_inc_return(v) atomic_add_ret(1, v)
5120 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5121 +{
5122 + return atomic_add_ret_unchecked(1, v);
5123 +}
5124 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
5125 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
5126 +{
5127 + return atomic64_add_ret_unchecked(1, v);
5128 +}
5129
5130 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
5131 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
5132
5133 #define atomic_add_return(i, v) atomic_add_ret(i, v)
5134 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5135 +{
5136 + return atomic_add_ret_unchecked(i, v);
5137 +}
5138 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
5139
5140 /*
5141 @@ -50,6 +84,7 @@ extern long atomic64_sub_ret(long, atomi
5142 * other cases.
5143 */
5144 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5145 +#define atomic_inc_and_test_unchecked(v) (atomic_inc_return_unchecked(v) == 0)
5146 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
5147
5148 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
5149 @@ -59,30 +94,59 @@ extern long atomic64_sub_ret(long, atomi
5150 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
5151
5152 #define atomic_inc(v) atomic_add(1, v)
5153 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
5154 +{
5155 + atomic_add_unchecked(1, v);
5156 +}
5157 #define atomic64_inc(v) atomic64_add(1, v)
5158 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
5159 +{
5160 + atomic64_add_unchecked(1, v);
5161 +}
5162
5163 #define atomic_dec(v) atomic_sub(1, v)
5164 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
5165 +{
5166 + atomic_sub_unchecked(1, v);
5167 +}
5168 #define atomic64_dec(v) atomic64_sub(1, v)
5169 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
5170 +{
5171 + atomic64_sub_unchecked(1, v);
5172 +}
5173
5174 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
5175 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
5176
5177 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5178 +#define atomic_cmpxchg_unchecked(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5179 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
5180 +#define atomic_xchg_unchecked(v, new) (xchg(&((v)->counter), new))
5181
5182 static inline int atomic_add_unless(atomic_t *v, int a, int u)
5183 {
5184 - int c, old;
5185 + int c, old, new;
5186 c = atomic_read(v);
5187 for (;;) {
5188 - if (unlikely(c == (u)))
5189 + if (unlikely(c == u))
5190 break;
5191 - old = atomic_cmpxchg((v), c, c + (a));
5192 +
5193 + asm volatile("addcc %2, %0, %0\n"
5194 +
5195 +#ifdef CONFIG_PAX_REFCOUNT
5196 + "tvs %%icc, 6\n"
5197 +#endif
5198 +
5199 + : "=r" (new)
5200 + : "0" (c), "ir" (a)
5201 + : "cc");
5202 +
5203 + old = atomic_cmpxchg(v, c, new);
5204 if (likely(old == c))
5205 break;
5206 c = old;
5207 }
5208 - return c != (u);
5209 + return c != u;
5210 }
5211
5212 #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
5213 @@ -93,17 +157,28 @@ static inline int atomic_add_unless(atom
5214
5215 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
5216 {
5217 - long c, old;
5218 + long c, old, new;
5219 c = atomic64_read(v);
5220 for (;;) {
5221 - if (unlikely(c == (u)))
5222 + if (unlikely(c == u))
5223 break;
5224 - old = atomic64_cmpxchg((v), c, c + (a));
5225 +
5226 + asm volatile("addcc %2, %0, %0\n"
5227 +
5228 +#ifdef CONFIG_PAX_REFCOUNT
5229 + "tvs %%xcc, 6\n"
5230 +#endif
5231 +
5232 + : "=r" (new)
5233 + : "0" (c), "ir" (a)
5234 + : "cc");
5235 +
5236 + old = atomic64_cmpxchg(v, c, new);
5237 if (likely(old == c))
5238 break;
5239 c = old;
5240 }
5241 - return c != (u);
5242 + return c != u;
5243 }
5244
5245 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5246 diff -urNp linux-2.6.39/arch/sparc/include/asm/cache.h linux-2.6.39/arch/sparc/include/asm/cache.h
5247 --- linux-2.6.39/arch/sparc/include/asm/cache.h 2011-05-19 00:06:34.000000000 -0400
5248 +++ linux-2.6.39/arch/sparc/include/asm/cache.h 2011-05-22 19:36:30.000000000 -0400
5249 @@ -10,7 +10,7 @@
5250 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
5251
5252 #define L1_CACHE_SHIFT 5
5253 -#define L1_CACHE_BYTES 32
5254 +#define L1_CACHE_BYTES 32U
5255
5256 #ifdef CONFIG_SPARC32
5257 #define SMP_CACHE_BYTES_SHIFT 5
5258 diff -urNp linux-2.6.39/arch/sparc/include/asm/dma-mapping.h linux-2.6.39/arch/sparc/include/asm/dma-mapping.h
5259 --- linux-2.6.39/arch/sparc/include/asm/dma-mapping.h 2011-05-19 00:06:34.000000000 -0400
5260 +++ linux-2.6.39/arch/sparc/include/asm/dma-mapping.h 2011-05-22 19:36:30.000000000 -0400
5261 @@ -12,10 +12,10 @@ extern int dma_supported(struct device *
5262 #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
5263 #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
5264
5265 -extern struct dma_map_ops *dma_ops, pci32_dma_ops;
5266 +extern const struct dma_map_ops *dma_ops, pci32_dma_ops;
5267 extern struct bus_type pci_bus_type;
5268
5269 -static inline struct dma_map_ops *get_dma_ops(struct device *dev)
5270 +static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
5271 {
5272 #if defined(CONFIG_SPARC32) && defined(CONFIG_PCI)
5273 if (dev->bus == &pci_bus_type)
5274 @@ -29,7 +29,7 @@ static inline struct dma_map_ops *get_dm
5275 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
5276 dma_addr_t *dma_handle, gfp_t flag)
5277 {
5278 - struct dma_map_ops *ops = get_dma_ops(dev);
5279 + const struct dma_map_ops *ops = get_dma_ops(dev);
5280 void *cpu_addr;
5281
5282 cpu_addr = ops->alloc_coherent(dev, size, dma_handle, flag);
5283 @@ -40,7 +40,7 @@ static inline void *dma_alloc_coherent(s
5284 static inline void dma_free_coherent(struct device *dev, size_t size,
5285 void *cpu_addr, dma_addr_t dma_handle)
5286 {
5287 - struct dma_map_ops *ops = get_dma_ops(dev);
5288 + const struct dma_map_ops *ops = get_dma_ops(dev);
5289
5290 debug_dma_free_coherent(dev, size, cpu_addr, dma_handle);
5291 ops->free_coherent(dev, size, cpu_addr, dma_handle);
5292 diff -urNp linux-2.6.39/arch/sparc/include/asm/elf_32.h linux-2.6.39/arch/sparc/include/asm/elf_32.h
5293 --- linux-2.6.39/arch/sparc/include/asm/elf_32.h 2011-05-19 00:06:34.000000000 -0400
5294 +++ linux-2.6.39/arch/sparc/include/asm/elf_32.h 2011-05-22 19:36:30.000000000 -0400
5295 @@ -114,6 +114,13 @@ typedef struct {
5296
5297 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
5298
5299 +#ifdef CONFIG_PAX_ASLR
5300 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
5301 +
5302 +#define PAX_DELTA_MMAP_LEN 16
5303 +#define PAX_DELTA_STACK_LEN 16
5304 +#endif
5305 +
5306 /* This yields a mask that user programs can use to figure out what
5307 instruction set this cpu supports. This can NOT be done in userspace
5308 on Sparc. */
5309 diff -urNp linux-2.6.39/arch/sparc/include/asm/elf_64.h linux-2.6.39/arch/sparc/include/asm/elf_64.h
5310 --- linux-2.6.39/arch/sparc/include/asm/elf_64.h 2011-05-19 00:06:34.000000000 -0400
5311 +++ linux-2.6.39/arch/sparc/include/asm/elf_64.h 2011-05-22 19:36:30.000000000 -0400
5312 @@ -162,6 +162,12 @@ typedef struct {
5313 #define ELF_ET_DYN_BASE 0x0000010000000000UL
5314 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
5315
5316 +#ifdef CONFIG_PAX_ASLR
5317 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
5318 +
5319 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
5320 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
5321 +#endif
5322
5323 /* This yields a mask that user programs can use to figure out what
5324 instruction set this cpu supports. */
5325 diff -urNp linux-2.6.39/arch/sparc/include/asm/pgtable_32.h linux-2.6.39/arch/sparc/include/asm/pgtable_32.h
5326 --- linux-2.6.39/arch/sparc/include/asm/pgtable_32.h 2011-05-19 00:06:34.000000000 -0400
5327 +++ linux-2.6.39/arch/sparc/include/asm/pgtable_32.h 2011-05-22 19:36:30.000000000 -0400
5328 @@ -43,6 +43,13 @@ BTFIXUPDEF_SIMM13(user_ptrs_per_pgd)
5329 BTFIXUPDEF_INT(page_none)
5330 BTFIXUPDEF_INT(page_copy)
5331 BTFIXUPDEF_INT(page_readonly)
5332 +
5333 +#ifdef CONFIG_PAX_PAGEEXEC
5334 +BTFIXUPDEF_INT(page_shared_noexec)
5335 +BTFIXUPDEF_INT(page_copy_noexec)
5336 +BTFIXUPDEF_INT(page_readonly_noexec)
5337 +#endif
5338 +
5339 BTFIXUPDEF_INT(page_kernel)
5340
5341 #define PMD_SHIFT SUN4C_PMD_SHIFT
5342 @@ -64,6 +71,16 @@ extern pgprot_t PAGE_SHARED;
5343 #define PAGE_COPY __pgprot(BTFIXUP_INT(page_copy))
5344 #define PAGE_READONLY __pgprot(BTFIXUP_INT(page_readonly))
5345
5346 +#ifdef CONFIG_PAX_PAGEEXEC
5347 +extern pgprot_t PAGE_SHARED_NOEXEC;
5348 +# define PAGE_COPY_NOEXEC __pgprot(BTFIXUP_INT(page_copy_noexec))
5349 +# define PAGE_READONLY_NOEXEC __pgprot(BTFIXUP_INT(page_readonly_noexec))
5350 +#else
5351 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
5352 +# define PAGE_COPY_NOEXEC PAGE_COPY
5353 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
5354 +#endif
5355 +
5356 extern unsigned long page_kernel;
5357
5358 #ifdef MODULE
5359 diff -urNp linux-2.6.39/arch/sparc/include/asm/pgtsrmmu.h linux-2.6.39/arch/sparc/include/asm/pgtsrmmu.h
5360 --- linux-2.6.39/arch/sparc/include/asm/pgtsrmmu.h 2011-05-19 00:06:34.000000000 -0400
5361 +++ linux-2.6.39/arch/sparc/include/asm/pgtsrmmu.h 2011-05-22 19:36:30.000000000 -0400
5362 @@ -115,6 +115,13 @@
5363 SRMMU_EXEC | SRMMU_REF)
5364 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
5365 SRMMU_EXEC | SRMMU_REF)
5366 +
5367 +#ifdef CONFIG_PAX_PAGEEXEC
5368 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
5369 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5370 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5371 +#endif
5372 +
5373 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
5374 SRMMU_DIRTY | SRMMU_REF)
5375
5376 diff -urNp linux-2.6.39/arch/sparc/include/asm/spinlock_64.h linux-2.6.39/arch/sparc/include/asm/spinlock_64.h
5377 --- linux-2.6.39/arch/sparc/include/asm/spinlock_64.h 2011-05-19 00:06:34.000000000 -0400
5378 +++ linux-2.6.39/arch/sparc/include/asm/spinlock_64.h 2011-05-22 19:36:30.000000000 -0400
5379 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(
5380
5381 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
5382
5383 -static void inline arch_read_lock(arch_rwlock_t *lock)
5384 +static inline void arch_read_lock(arch_rwlock_t *lock)
5385 {
5386 unsigned long tmp1, tmp2;
5387
5388 __asm__ __volatile__ (
5389 "1: ldsw [%2], %0\n"
5390 " brlz,pn %0, 2f\n"
5391 -"4: add %0, 1, %1\n"
5392 +"4: addcc %0, 1, %1\n"
5393 +
5394 +#ifdef CONFIG_PAX_REFCOUNT
5395 +" tvs %%icc, 6\n"
5396 +#endif
5397 +
5398 " cas [%2], %0, %1\n"
5399 " cmp %0, %1\n"
5400 " bne,pn %%icc, 1b\n"
5401 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_r
5402 " .previous"
5403 : "=&r" (tmp1), "=&r" (tmp2)
5404 : "r" (lock)
5405 - : "memory");
5406 + : "memory", "cc");
5407 }
5408
5409 -static int inline arch_read_trylock(arch_rwlock_t *lock)
5410 +static inline int arch_read_trylock(arch_rwlock_t *lock)
5411 {
5412 int tmp1, tmp2;
5413
5414 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch
5415 "1: ldsw [%2], %0\n"
5416 " brlz,a,pn %0, 2f\n"
5417 " mov 0, %0\n"
5418 -" add %0, 1, %1\n"
5419 +" addcc %0, 1, %1\n"
5420 +
5421 +#ifdef CONFIG_PAX_REFCOUNT
5422 +" tvs %%icc, 6\n"
5423 +#endif
5424 +
5425 " cas [%2], %0, %1\n"
5426 " cmp %0, %1\n"
5427 " bne,pn %%icc, 1b\n"
5428 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch
5429 return tmp1;
5430 }
5431
5432 -static void inline arch_read_unlock(arch_rwlock_t *lock)
5433 +static inline void arch_read_unlock(arch_rwlock_t *lock)
5434 {
5435 unsigned long tmp1, tmp2;
5436
5437 __asm__ __volatile__(
5438 "1: lduw [%2], %0\n"
5439 -" sub %0, 1, %1\n"
5440 +" subcc %0, 1, %1\n"
5441 +
5442 +#ifdef CONFIG_PAX_REFCOUNT
5443 +" tvs %%icc, 6\n"
5444 +#endif
5445 +
5446 " cas [%2], %0, %1\n"
5447 " cmp %0, %1\n"
5448 " bne,pn %%xcc, 1b\n"
5449 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch
5450 : "memory");
5451 }
5452
5453 -static void inline arch_write_lock(arch_rwlock_t *lock)
5454 +static inline void arch_write_lock(arch_rwlock_t *lock)
5455 {
5456 unsigned long mask, tmp1, tmp2;
5457
5458 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_
5459 : "memory");
5460 }
5461
5462 -static void inline arch_write_unlock(arch_rwlock_t *lock)
5463 +static inline void arch_write_unlock(arch_rwlock_t *lock)
5464 {
5465 __asm__ __volatile__(
5466 " stw %%g0, [%0]"
5467 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arc
5468 : "memory");
5469 }
5470
5471 -static int inline arch_write_trylock(arch_rwlock_t *lock)
5472 +static inline int arch_write_trylock(arch_rwlock_t *lock)
5473 {
5474 unsigned long mask, tmp1, tmp2, result;
5475
5476 diff -urNp linux-2.6.39/arch/sparc/include/asm/uaccess_32.h linux-2.6.39/arch/sparc/include/asm/uaccess_32.h
5477 --- linux-2.6.39/arch/sparc/include/asm/uaccess_32.h 2011-05-19 00:06:34.000000000 -0400
5478 +++ linux-2.6.39/arch/sparc/include/asm/uaccess_32.h 2011-05-22 19:36:30.000000000 -0400
5479 @@ -249,27 +249,46 @@ extern unsigned long __copy_user(void __
5480
5481 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5482 {
5483 - if (n && __access_ok((unsigned long) to, n))
5484 + if ((long)n < 0)
5485 + return n;
5486 +
5487 + if (n && __access_ok((unsigned long) to, n)) {
5488 + if (!__builtin_constant_p(n))
5489 + check_object_size(from, n, true);
5490 return __copy_user(to, (__force void __user *) from, n);
5491 - else
5492 + } else
5493 return n;
5494 }
5495
5496 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
5497 {
5498 + if ((long)n < 0)
5499 + return n;
5500 +
5501 + if (!__builtin_constant_p(n))
5502 + check_object_size(from, n, true);
5503 +
5504 return __copy_user(to, (__force void __user *) from, n);
5505 }
5506
5507 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5508 {
5509 - if (n && __access_ok((unsigned long) from, n))
5510 + if ((long)n < 0)
5511 + return n;
5512 +
5513 + if (n && __access_ok((unsigned long) from, n)) {
5514 + if (!__builtin_constant_p(n))
5515 + check_object_size(to, n, false);
5516 return __copy_user((__force void __user *) to, from, n);
5517 - else
5518 + } else
5519 return n;
5520 }
5521
5522 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
5523 {
5524 + if ((long)n < 0)
5525 + return n;
5526 +
5527 return __copy_user((__force void __user *) to, from, n);
5528 }
5529
5530 diff -urNp linux-2.6.39/arch/sparc/include/asm/uaccess_64.h linux-2.6.39/arch/sparc/include/asm/uaccess_64.h
5531 --- linux-2.6.39/arch/sparc/include/asm/uaccess_64.h 2011-05-19 00:06:34.000000000 -0400
5532 +++ linux-2.6.39/arch/sparc/include/asm/uaccess_64.h 2011-05-22 19:36:30.000000000 -0400
5533 @@ -10,6 +10,7 @@
5534 #include <linux/compiler.h>
5535 #include <linux/string.h>
5536 #include <linux/thread_info.h>
5537 +#include <linux/kernel.h>
5538 #include <asm/asi.h>
5539 #include <asm/system.h>
5540 #include <asm/spitfire.h>
5541 @@ -213,8 +214,15 @@ extern unsigned long copy_from_user_fixu
5542 static inline unsigned long __must_check
5543 copy_from_user(void *to, const void __user *from, unsigned long size)
5544 {
5545 - unsigned long ret = ___copy_from_user(to, from, size);
5546 + unsigned long ret;
5547
5548 + if ((long)size < 0 || size > INT_MAX)
5549 + return size;
5550 +
5551 + if (!__builtin_constant_p(size))
5552 + check_object_size(to, size, false);
5553 +
5554 + ret = ___copy_from_user(to, from, size);
5555 if (unlikely(ret))
5556 ret = copy_from_user_fixup(to, from, size);
5557
5558 @@ -230,8 +238,15 @@ extern unsigned long copy_to_user_fixup(
5559 static inline unsigned long __must_check
5560 copy_to_user(void __user *to, const void *from, unsigned long size)
5561 {
5562 - unsigned long ret = ___copy_to_user(to, from, size);
5563 + unsigned long ret;
5564 +
5565 + if ((long)size < 0 || size > INT_MAX)
5566 + return size;
5567 +
5568 + if (!__builtin_constant_p(size))
5569 + check_object_size(from, size, true);
5570
5571 + ret = ___copy_to_user(to, from, size);
5572 if (unlikely(ret))
5573 ret = copy_to_user_fixup(to, from, size);
5574 return ret;
5575 diff -urNp linux-2.6.39/arch/sparc/include/asm/uaccess.h linux-2.6.39/arch/sparc/include/asm/uaccess.h
5576 --- linux-2.6.39/arch/sparc/include/asm/uaccess.h 2011-05-19 00:06:34.000000000 -0400
5577 +++ linux-2.6.39/arch/sparc/include/asm/uaccess.h 2011-05-22 19:36:30.000000000 -0400
5578 @@ -1,5 +1,13 @@
5579 #ifndef ___ASM_SPARC_UACCESS_H
5580 #define ___ASM_SPARC_UACCESS_H
5581 +
5582 +#ifdef __KERNEL__
5583 +#ifndef __ASSEMBLY__
5584 +#include <linux/types.h>
5585 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
5586 +#endif
5587 +#endif
5588 +
5589 #if defined(__sparc__) && defined(__arch64__)
5590 #include <asm/uaccess_64.h>
5591 #else
5592 diff -urNp linux-2.6.39/arch/sparc/kernel/iommu.c linux-2.6.39/arch/sparc/kernel/iommu.c
5593 --- linux-2.6.39/arch/sparc/kernel/iommu.c 2011-05-19 00:06:34.000000000 -0400
5594 +++ linux-2.6.39/arch/sparc/kernel/iommu.c 2011-05-22 19:36:30.000000000 -0400
5595 @@ -824,7 +824,7 @@ static void dma_4u_sync_sg_for_cpu(struc
5596 spin_unlock_irqrestore(&iommu->lock, flags);
5597 }
5598
5599 -static struct dma_map_ops sun4u_dma_ops = {
5600 +static const struct dma_map_ops sun4u_dma_ops = {
5601 .alloc_coherent = dma_4u_alloc_coherent,
5602 .free_coherent = dma_4u_free_coherent,
5603 .map_page = dma_4u_map_page,
5604 @@ -835,7 +835,7 @@ static struct dma_map_ops sun4u_dma_ops
5605 .sync_sg_for_cpu = dma_4u_sync_sg_for_cpu,
5606 };
5607
5608 -struct dma_map_ops *dma_ops = &sun4u_dma_ops;
5609 +const struct dma_map_ops *dma_ops = &sun4u_dma_ops;
5610 EXPORT_SYMBOL(dma_ops);
5611
5612 extern int pci64_dma_supported(struct pci_dev *pdev, u64 device_mask);
5613 diff -urNp linux-2.6.39/arch/sparc/kernel/ioport.c linux-2.6.39/arch/sparc/kernel/ioport.c
5614 --- linux-2.6.39/arch/sparc/kernel/ioport.c 2011-05-19 00:06:34.000000000 -0400
5615 +++ linux-2.6.39/arch/sparc/kernel/ioport.c 2011-05-22 19:36:30.000000000 -0400
5616 @@ -402,7 +402,7 @@ static void sbus_sync_sg_for_device(stru
5617 BUG();
5618 }
5619
5620 -struct dma_map_ops sbus_dma_ops = {
5621 +const struct dma_map_ops sbus_dma_ops = {
5622 .alloc_coherent = sbus_alloc_coherent,
5623 .free_coherent = sbus_free_coherent,
5624 .map_page = sbus_map_page,
5625 @@ -653,7 +653,7 @@ static void pci32_sync_sg_for_device(str
5626 }
5627 }
5628
5629 -struct dma_map_ops pci32_dma_ops = {
5630 +const struct dma_map_ops pci32_dma_ops = {
5631 .alloc_coherent = pci32_alloc_coherent,
5632 .free_coherent = pci32_free_coherent,
5633 .map_page = pci32_map_page,
5634 diff -urNp linux-2.6.39/arch/sparc/kernel/kgdb_32.c linux-2.6.39/arch/sparc/kernel/kgdb_32.c
5635 --- linux-2.6.39/arch/sparc/kernel/kgdb_32.c 2011-05-19 00:06:34.000000000 -0400
5636 +++ linux-2.6.39/arch/sparc/kernel/kgdb_32.c 2011-05-22 19:36:30.000000000 -0400
5637 @@ -164,7 +164,7 @@ void kgdb_arch_set_pc(struct pt_regs *re
5638 regs->npc = regs->pc + 4;
5639 }
5640
5641 -struct kgdb_arch arch_kgdb_ops = {
5642 +const struct kgdb_arch arch_kgdb_ops = {
5643 /* Breakpoint instruction: ta 0x7d */
5644 .gdb_bpt_instr = { 0x91, 0xd0, 0x20, 0x7d },
5645 };
5646 diff -urNp linux-2.6.39/arch/sparc/kernel/kgdb_64.c linux-2.6.39/arch/sparc/kernel/kgdb_64.c
5647 --- linux-2.6.39/arch/sparc/kernel/kgdb_64.c 2011-05-19 00:06:34.000000000 -0400
5648 +++ linux-2.6.39/arch/sparc/kernel/kgdb_64.c 2011-05-22 19:36:30.000000000 -0400
5649 @@ -187,7 +187,7 @@ void kgdb_arch_set_pc(struct pt_regs *re
5650 regs->tnpc = regs->tpc + 4;
5651 }
5652
5653 -struct kgdb_arch arch_kgdb_ops = {
5654 +const struct kgdb_arch arch_kgdb_ops = {
5655 /* Breakpoint instruction: ta 0x72 */
5656 .gdb_bpt_instr = { 0x91, 0xd0, 0x20, 0x72 },
5657 };
5658 diff -urNp linux-2.6.39/arch/sparc/kernel/Makefile linux-2.6.39/arch/sparc/kernel/Makefile
5659 --- linux-2.6.39/arch/sparc/kernel/Makefile 2011-05-19 00:06:34.000000000 -0400
5660 +++ linux-2.6.39/arch/sparc/kernel/Makefile 2011-05-22 19:36:30.000000000 -0400
5661 @@ -3,7 +3,7 @@
5662 #
5663
5664 asflags-y := -ansi
5665 -ccflags-y := -Werror
5666 +#ccflags-y := -Werror
5667
5668 extra-y := head_$(BITS).o
5669 extra-y += init_task.o
5670 diff -urNp linux-2.6.39/arch/sparc/kernel/pcic.c linux-2.6.39/arch/sparc/kernel/pcic.c
5671 --- linux-2.6.39/arch/sparc/kernel/pcic.c 2011-05-19 00:06:34.000000000 -0400
5672 +++ linux-2.6.39/arch/sparc/kernel/pcic.c 2011-05-22 19:36:30.000000000 -0400
5673 @@ -268,7 +268,7 @@ static int pcic_write_config(struct pci_
5674 return -EINVAL;
5675 }
5676
5677 -static struct pci_ops pcic_ops = {
5678 +static const struct pci_ops pcic_ops = {
5679 .read = pcic_read_config,
5680 .write = pcic_write_config,
5681 };
5682 diff -urNp linux-2.6.39/arch/sparc/kernel/pci_common.c linux-2.6.39/arch/sparc/kernel/pci_common.c
5683 --- linux-2.6.39/arch/sparc/kernel/pci_common.c 2011-05-19 00:06:34.000000000 -0400
5684 +++ linux-2.6.39/arch/sparc/kernel/pci_common.c 2011-05-22 19:36:30.000000000 -0400
5685 @@ -249,7 +249,7 @@ static int sun4u_write_pci_cfg(struct pc
5686 return PCIBIOS_SUCCESSFUL;
5687 }
5688
5689 -struct pci_ops sun4u_pci_ops = {
5690 +const struct pci_ops sun4u_pci_ops = {
5691 .read = sun4u_read_pci_cfg,
5692 .write = sun4u_write_pci_cfg,
5693 };
5694 @@ -310,7 +310,7 @@ static int sun4v_write_pci_cfg(struct pc
5695 return PCIBIOS_SUCCESSFUL;
5696 }
5697
5698 -struct pci_ops sun4v_pci_ops = {
5699 +const struct pci_ops sun4v_pci_ops = {
5700 .read = sun4v_read_pci_cfg,
5701 .write = sun4v_write_pci_cfg,
5702 };
5703 diff -urNp linux-2.6.39/arch/sparc/kernel/pci_impl.h linux-2.6.39/arch/sparc/kernel/pci_impl.h
5704 --- linux-2.6.39/arch/sparc/kernel/pci_impl.h 2011-05-19 00:06:34.000000000 -0400
5705 +++ linux-2.6.39/arch/sparc/kernel/pci_impl.h 2011-05-22 19:36:30.000000000 -0400
5706 @@ -175,8 +175,8 @@ extern void pci_config_write8(u8 *addr,
5707 extern void pci_config_write16(u16 *addr, u16 val);
5708 extern void pci_config_write32(u32 *addr, u32 val);
5709
5710 -extern struct pci_ops sun4u_pci_ops;
5711 -extern struct pci_ops sun4v_pci_ops;
5712 +extern const struct pci_ops sun4u_pci_ops;
5713 +extern const struct pci_ops sun4v_pci_ops;
5714
5715 extern volatile int pci_poke_in_progress;
5716 extern volatile int pci_poke_cpu;
5717 diff -urNp linux-2.6.39/arch/sparc/kernel/pci_sun4v.c linux-2.6.39/arch/sparc/kernel/pci_sun4v.c
5718 --- linux-2.6.39/arch/sparc/kernel/pci_sun4v.c 2011-05-19 00:06:34.000000000 -0400
5719 +++ linux-2.6.39/arch/sparc/kernel/pci_sun4v.c 2011-05-22 19:36:30.000000000 -0400
5720 @@ -525,7 +525,7 @@ static void dma_4v_unmap_sg(struct devic
5721 spin_unlock_irqrestore(&iommu->lock, flags);
5722 }
5723
5724 -static struct dma_map_ops sun4v_dma_ops = {
5725 +static const struct dma_map_ops sun4v_dma_ops = {
5726 .alloc_coherent = dma_4v_alloc_coherent,
5727 .free_coherent = dma_4v_free_coherent,
5728 .map_page = dma_4v_map_page,
5729 diff -urNp linux-2.6.39/arch/sparc/kernel/process_32.c linux-2.6.39/arch/sparc/kernel/process_32.c
5730 --- linux-2.6.39/arch/sparc/kernel/process_32.c 2011-05-19 00:06:34.000000000 -0400
5731 +++ linux-2.6.39/arch/sparc/kernel/process_32.c 2011-05-22 19:41:32.000000000 -0400
5732 @@ -196,7 +196,7 @@ void __show_backtrace(unsigned long fp)
5733 rw->ins[4], rw->ins[5],
5734 rw->ins[6],
5735 rw->ins[7]);
5736 - printk("%pS\n", (void *) rw->ins[7]);
5737 + printk("%pA\n", (void *) rw->ins[7]);
5738 rw = (struct reg_window32 *) rw->ins[6];
5739 }
5740 spin_unlock_irqrestore(&sparc_backtrace_lock, flags);
5741 @@ -263,14 +263,14 @@ void show_regs(struct pt_regs *r)
5742
5743 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
5744 r->psr, r->pc, r->npc, r->y, print_tainted());
5745 - printk("PC: <%pS>\n", (void *) r->pc);
5746 + printk("PC: <%pA>\n", (void *) r->pc);
5747 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5748 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
5749 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
5750 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5751 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
5752 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
5753 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
5754 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
5755
5756 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5757 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
5758 @@ -305,7 +305,7 @@ void show_stack(struct task_struct *tsk,
5759 rw = (struct reg_window32 *) fp;
5760 pc = rw->ins[7];
5761 printk("[%08lx : ", pc);
5762 - printk("%pS ] ", (void *) pc);
5763 + printk("%pA ] ", (void *) pc);
5764 fp = rw->ins[6];
5765 } while (++count < 16);
5766 printk("\n");
5767 diff -urNp linux-2.6.39/arch/sparc/kernel/process_64.c linux-2.6.39/arch/sparc/kernel/process_64.c
5768 --- linux-2.6.39/arch/sparc/kernel/process_64.c 2011-05-19 00:06:34.000000000 -0400
5769 +++ linux-2.6.39/arch/sparc/kernel/process_64.c 2011-05-22 19:41:32.000000000 -0400
5770 @@ -180,14 +180,14 @@ static void show_regwindow(struct pt_reg
5771 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
5772 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
5773 if (regs->tstate & TSTATE_PRIV)
5774 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
5775 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
5776 }
5777
5778 void show_regs(struct pt_regs *regs)
5779 {
5780 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
5781 regs->tpc, regs->tnpc, regs->y, print_tainted());
5782 - printk("TPC: <%pS>\n", (void *) regs->tpc);
5783 + printk("TPC: <%pA>\n", (void *) regs->tpc);
5784 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
5785 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
5786 regs->u_regs[3]);
5787 @@ -200,7 +200,7 @@ void show_regs(struct pt_regs *regs)
5788 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
5789 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
5790 regs->u_regs[15]);
5791 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
5792 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
5793 show_regwindow(regs);
5794 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
5795 }
5796 @@ -285,7 +285,7 @@ void arch_trigger_all_cpu_backtrace(void
5797 ((tp && tp->task) ? tp->task->pid : -1));
5798
5799 if (gp->tstate & TSTATE_PRIV) {
5800 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
5801 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
5802 (void *) gp->tpc,
5803 (void *) gp->o7,
5804 (void *) gp->i7,
5805 diff -urNp linux-2.6.39/arch/sparc/kernel/sys_sparc_32.c linux-2.6.39/arch/sparc/kernel/sys_sparc_32.c
5806 --- linux-2.6.39/arch/sparc/kernel/sys_sparc_32.c 2011-05-19 00:06:34.000000000 -0400
5807 +++ linux-2.6.39/arch/sparc/kernel/sys_sparc_32.c 2011-05-22 19:36:30.000000000 -0400
5808 @@ -56,7 +56,7 @@ unsigned long arch_get_unmapped_area(str
5809 if (ARCH_SUN4C && len > 0x20000000)
5810 return -ENOMEM;
5811 if (!addr)
5812 - addr = TASK_UNMAPPED_BASE;
5813 + addr = current->mm->mmap_base;
5814
5815 if (flags & MAP_SHARED)
5816 addr = COLOUR_ALIGN(addr);
5817 @@ -71,7 +71,7 @@ unsigned long arch_get_unmapped_area(str
5818 }
5819 if (TASK_SIZE - PAGE_SIZE - len < addr)
5820 return -ENOMEM;
5821 - if (!vmm || addr + len <= vmm->vm_start)
5822 + if (check_heap_stack_gap(vmm, addr, len))
5823 return addr;
5824 addr = vmm->vm_end;
5825 if (flags & MAP_SHARED)
5826 diff -urNp linux-2.6.39/arch/sparc/kernel/sys_sparc_64.c linux-2.6.39/arch/sparc/kernel/sys_sparc_64.c
5827 --- linux-2.6.39/arch/sparc/kernel/sys_sparc_64.c 2011-05-19 00:06:34.000000000 -0400
5828 +++ linux-2.6.39/arch/sparc/kernel/sys_sparc_64.c 2011-05-22 19:36:30.000000000 -0400
5829 @@ -124,7 +124,7 @@ unsigned long arch_get_unmapped_area(str
5830 /* We do not accept a shared mapping if it would violate
5831 * cache aliasing constraints.
5832 */
5833 - if ((flags & MAP_SHARED) &&
5834 + if ((filp || (flags & MAP_SHARED)) &&
5835 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5836 return -EINVAL;
5837 return addr;
5838 @@ -139,6 +139,10 @@ unsigned long arch_get_unmapped_area(str
5839 if (filp || (flags & MAP_SHARED))
5840 do_color_align = 1;
5841
5842 +#ifdef CONFIG_PAX_RANDMMAP
5843 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5844 +#endif
5845 +
5846 if (addr) {
5847 if (do_color_align)
5848 addr = COLOUR_ALIGN(addr, pgoff);
5849 @@ -146,15 +150,14 @@ unsigned long arch_get_unmapped_area(str
5850 addr = PAGE_ALIGN(addr);
5851
5852 vma = find_vma(mm, addr);
5853 - if (task_size - len >= addr &&
5854 - (!vma || addr + len <= vma->vm_start))
5855 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5856 return addr;
5857 }
5858
5859 if (len > mm->cached_hole_size) {
5860 - start_addr = addr = mm->free_area_cache;
5861 + start_addr = addr = mm->free_area_cache;
5862 } else {
5863 - start_addr = addr = TASK_UNMAPPED_BASE;
5864 + start_addr = addr = mm->mmap_base;
5865 mm->cached_hole_size = 0;
5866 }
5867
5868 @@ -174,14 +177,14 @@ full_search:
5869 vma = find_vma(mm, VA_EXCLUDE_END);
5870 }
5871 if (unlikely(task_size < addr)) {
5872 - if (start_addr != TASK_UNMAPPED_BASE) {
5873 - start_addr = addr = TASK_UNMAPPED_BASE;
5874 + if (start_addr != mm->mmap_base) {
5875 + start_addr = addr = mm->mmap_base;
5876 mm->cached_hole_size = 0;
5877 goto full_search;
5878 }
5879 return -ENOMEM;
5880 }
5881 - if (likely(!vma || addr + len <= vma->vm_start)) {
5882 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5883 /*
5884 * Remember the place where we stopped the search:
5885 */
5886 @@ -215,7 +218,7 @@ arch_get_unmapped_area_topdown(struct fi
5887 /* We do not accept a shared mapping if it would violate
5888 * cache aliasing constraints.
5889 */
5890 - if ((flags & MAP_SHARED) &&
5891 + if ((filp || (flags & MAP_SHARED)) &&
5892 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5893 return -EINVAL;
5894 return addr;
5895 @@ -236,8 +239,7 @@ arch_get_unmapped_area_topdown(struct fi
5896 addr = PAGE_ALIGN(addr);
5897
5898 vma = find_vma(mm, addr);
5899 - if (task_size - len >= addr &&
5900 - (!vma || addr + len <= vma->vm_start))
5901 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5902 return addr;
5903 }
5904
5905 @@ -258,7 +260,7 @@ arch_get_unmapped_area_topdown(struct fi
5906 /* make sure it can fit in the remaining address space */
5907 if (likely(addr > len)) {
5908 vma = find_vma(mm, addr-len);
5909 - if (!vma || addr <= vma->vm_start) {
5910 + if (check_heap_stack_gap(vma, addr - len, len)) {
5911 /* remember the address as a hint for next time */
5912 return (mm->free_area_cache = addr-len);
5913 }
5914 @@ -267,18 +269,18 @@ arch_get_unmapped_area_topdown(struct fi
5915 if (unlikely(mm->mmap_base < len))
5916 goto bottomup;
5917
5918 - addr = mm->mmap_base-len;
5919 - if (do_color_align)
5920 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5921 + addr = mm->mmap_base - len;
5922
5923 do {
5924 + if (do_color_align)
5925 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5926 /*
5927 * Lookup failure means no vma is above this address,
5928 * else if new region fits below vma->vm_start,
5929 * return with success:
5930 */
5931 vma = find_vma(mm, addr);
5932 - if (likely(!vma || addr+len <= vma->vm_start)) {
5933 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5934 /* remember the address as a hint for next time */
5935 return (mm->free_area_cache = addr);
5936 }
5937 @@ -288,10 +290,8 @@ arch_get_unmapped_area_topdown(struct fi
5938 mm->cached_hole_size = vma->vm_start - addr;
5939
5940 /* try just below the current vma->vm_start */
5941 - addr = vma->vm_start-len;
5942 - if (do_color_align)
5943 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5944 - } while (likely(len < vma->vm_start));
5945 + addr = skip_heap_stack_gap(vma, len);
5946 + } while (!IS_ERR_VALUE(addr));
5947
5948 bottomup:
5949 /*
5950 @@ -390,6 +390,12 @@ void arch_pick_mmap_layout(struct mm_str
5951 gap == RLIM_INFINITY ||
5952 sysctl_legacy_va_layout) {
5953 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5954 +
5955 +#ifdef CONFIG_PAX_RANDMMAP
5956 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5957 + mm->mmap_base += mm->delta_mmap;
5958 +#endif
5959 +
5960 mm->get_unmapped_area = arch_get_unmapped_area;
5961 mm->unmap_area = arch_unmap_area;
5962 } else {
5963 @@ -402,6 +408,12 @@ void arch_pick_mmap_layout(struct mm_str
5964 gap = (task_size / 6 * 5);
5965
5966 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
5967 +
5968 +#ifdef CONFIG_PAX_RANDMMAP
5969 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5970 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5971 +#endif
5972 +
5973 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5974 mm->unmap_area = arch_unmap_area_topdown;
5975 }
5976 diff -urNp linux-2.6.39/arch/sparc/kernel/traps_32.c linux-2.6.39/arch/sparc/kernel/traps_32.c
5977 --- linux-2.6.39/arch/sparc/kernel/traps_32.c 2011-05-19 00:06:34.000000000 -0400
5978 +++ linux-2.6.39/arch/sparc/kernel/traps_32.c 2011-05-22 19:41:32.000000000 -0400
5979 @@ -76,7 +76,7 @@ void die_if_kernel(char *str, struct pt_
5980 count++ < 30 &&
5981 (((unsigned long) rw) >= PAGE_OFFSET) &&
5982 !(((unsigned long) rw) & 0x7)) {
5983 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
5984 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
5985 (void *) rw->ins[7]);
5986 rw = (struct reg_window32 *)rw->ins[6];
5987 }
5988 diff -urNp linux-2.6.39/arch/sparc/kernel/traps_64.c linux-2.6.39/arch/sparc/kernel/traps_64.c
5989 --- linux-2.6.39/arch/sparc/kernel/traps_64.c 2011-05-19 00:06:34.000000000 -0400
5990 +++ linux-2.6.39/arch/sparc/kernel/traps_64.c 2011-05-22 19:41:32.000000000 -0400
5991 @@ -75,7 +75,7 @@ static void dump_tl1_traplog(struct tl1_
5992 i + 1,
5993 p->trapstack[i].tstate, p->trapstack[i].tpc,
5994 p->trapstack[i].tnpc, p->trapstack[i].tt);
5995 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
5996 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
5997 }
5998 }
5999
6000 @@ -95,6 +95,12 @@ void bad_trap(struct pt_regs *regs, long
6001
6002 lvl -= 0x100;
6003 if (regs->tstate & TSTATE_PRIV) {
6004 +
6005 +#ifdef CONFIG_PAX_REFCOUNT
6006 + if (lvl == 6)
6007 + pax_report_refcount_overflow(regs);
6008 +#endif
6009 +
6010 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
6011 die_if_kernel(buffer, regs);
6012 }
6013 @@ -113,11 +119,16 @@ void bad_trap(struct pt_regs *regs, long
6014 void bad_trap_tl1(struct pt_regs *regs, long lvl)
6015 {
6016 char buffer[32];
6017 -
6018 +
6019 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
6020 0, lvl, SIGTRAP) == NOTIFY_STOP)
6021 return;
6022
6023 +#ifdef CONFIG_PAX_REFCOUNT
6024 + if (lvl == 6)
6025 + pax_report_refcount_overflow(regs);
6026 +#endif
6027 +
6028 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
6029
6030 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
6031 @@ -1141,7 +1152,7 @@ static void cheetah_log_errors(struct pt
6032 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
6033 printk("%s" "ERROR(%d): ",
6034 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
6035 - printk("TPC<%pS>\n", (void *) regs->tpc);
6036 + printk("TPC<%pA>\n", (void *) regs->tpc);
6037 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
6038 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
6039 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
6040 @@ -1748,7 +1759,7 @@ void cheetah_plus_parity_error(int type,
6041 smp_processor_id(),
6042 (type & 0x1) ? 'I' : 'D',
6043 regs->tpc);
6044 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
6045 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
6046 panic("Irrecoverable Cheetah+ parity error.");
6047 }
6048
6049 @@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type,
6050 smp_processor_id(),
6051 (type & 0x1) ? 'I' : 'D',
6052 regs->tpc);
6053 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
6054 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
6055 }
6056
6057 struct sun4v_error_entry {
6058 @@ -1963,9 +1974,9 @@ void sun4v_itlb_error_report(struct pt_r
6059
6060 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
6061 regs->tpc, tl);
6062 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
6063 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
6064 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6065 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
6066 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
6067 (void *) regs->u_regs[UREG_I7]);
6068 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
6069 "pte[%lx] error[%lx]\n",
6070 @@ -1987,9 +1998,9 @@ void sun4v_dtlb_error_report(struct pt_r
6071
6072 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
6073 regs->tpc, tl);
6074 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
6075 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
6076 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6077 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
6078 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
6079 (void *) regs->u_regs[UREG_I7]);
6080 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
6081 "pte[%lx] error[%lx]\n",
6082 @@ -2195,13 +2206,13 @@ void show_stack(struct task_struct *tsk,
6083 fp = (unsigned long)sf->fp + STACK_BIAS;
6084 }
6085
6086 - printk(" [%016lx] %pS\n", pc, (void *) pc);
6087 + printk(" [%016lx] %pA\n", pc, (void *) pc);
6088 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6089 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
6090 int index = tsk->curr_ret_stack;
6091 if (tsk->ret_stack && index >= graph) {
6092 pc = tsk->ret_stack[index - graph].ret;
6093 - printk(" [%016lx] %pS\n", pc, (void *) pc);
6094 + printk(" [%016lx] %pA\n", pc, (void *) pc);
6095 graph++;
6096 }
6097 }
6098 @@ -2254,7 +2265,7 @@ void die_if_kernel(char *str, struct pt_
6099 while (rw &&
6100 count++ < 30 &&
6101 kstack_valid(tp, (unsigned long) rw)) {
6102 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
6103 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
6104 (void *) rw->ins[7]);
6105
6106 rw = kernel_stack_up(rw);
6107 diff -urNp linux-2.6.39/arch/sparc/kernel/unaligned_64.c linux-2.6.39/arch/sparc/kernel/unaligned_64.c
6108 --- linux-2.6.39/arch/sparc/kernel/unaligned_64.c 2011-05-19 00:06:34.000000000 -0400
6109 +++ linux-2.6.39/arch/sparc/kernel/unaligned_64.c 2011-05-22 19:41:32.000000000 -0400
6110 @@ -278,7 +278,7 @@ static void log_unaligned(struct pt_regs
6111 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
6112
6113 if (__ratelimit(&ratelimit)) {
6114 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
6115 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
6116 regs->tpc, (void *) regs->tpc);
6117 }
6118 }
6119 diff -urNp linux-2.6.39/arch/sparc/lib/atomic_64.S linux-2.6.39/arch/sparc/lib/atomic_64.S
6120 --- linux-2.6.39/arch/sparc/lib/atomic_64.S 2011-05-19 00:06:34.000000000 -0400
6121 +++ linux-2.6.39/arch/sparc/lib/atomic_64.S 2011-05-22 19:36:30.000000000 -0400
6122 @@ -18,7 +18,12 @@
6123 atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
6124 BACKOFF_SETUP(%o2)
6125 1: lduw [%o1], %g1
6126 - add %g1, %o0, %g7
6127 + addcc %g1, %o0, %g7
6128 +
6129 +#ifdef CONFIG_PAX_REFCOUNT
6130 + tvs %icc, 6
6131 +#endif
6132 +
6133 cas [%o1], %g1, %g7
6134 cmp %g1, %g7
6135 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6136 @@ -28,12 +33,32 @@ atomic_add: /* %o0 = increment, %o1 = at
6137 2: BACKOFF_SPIN(%o2, %o3, 1b)
6138 .size atomic_add, .-atomic_add
6139
6140 + .globl atomic_add_unchecked
6141 + .type atomic_add_unchecked,#function
6142 +atomic_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6143 + BACKOFF_SETUP(%o2)
6144 +1: lduw [%o1], %g1
6145 + add %g1, %o0, %g7
6146 + cas [%o1], %g1, %g7
6147 + cmp %g1, %g7
6148 + bne,pn %icc, 2f
6149 + nop
6150 + retl
6151 + nop
6152 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6153 + .size atomic_add_unchecked, .-atomic_add_unchecked
6154 +
6155 .globl atomic_sub
6156 .type atomic_sub,#function
6157 atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
6158 BACKOFF_SETUP(%o2)
6159 1: lduw [%o1], %g1
6160 - sub %g1, %o0, %g7
6161 + subcc %g1, %o0, %g7
6162 +
6163 +#ifdef CONFIG_PAX_REFCOUNT
6164 + tvs %icc, 6
6165 +#endif
6166 +
6167 cas [%o1], %g1, %g7
6168 cmp %g1, %g7
6169 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6170 @@ -43,12 +68,32 @@ atomic_sub: /* %o0 = decrement, %o1 = at
6171 2: BACKOFF_SPIN(%o2, %o3, 1b)
6172 .size atomic_sub, .-atomic_sub
6173
6174 + .globl atomic_sub_unchecked
6175 + .type atomic_sub_unchecked,#function
6176 +atomic_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
6177 + BACKOFF_SETUP(%o2)
6178 +1: lduw [%o1], %g1
6179 + sub %g1, %o0, %g7
6180 + cas [%o1], %g1, %g7
6181 + cmp %g1, %g7
6182 + bne,pn %icc, 2f
6183 + nop
6184 + retl
6185 + nop
6186 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6187 + .size atomic_sub_unchecked, .-atomic_sub_unchecked
6188 +
6189 .globl atomic_add_ret
6190 .type atomic_add_ret,#function
6191 atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
6192 BACKOFF_SETUP(%o2)
6193 1: lduw [%o1], %g1
6194 - add %g1, %o0, %g7
6195 + addcc %g1, %o0, %g7
6196 +
6197 +#ifdef CONFIG_PAX_REFCOUNT
6198 + tvs %icc, 6
6199 +#endif
6200 +
6201 cas [%o1], %g1, %g7
6202 cmp %g1, %g7
6203 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6204 @@ -58,12 +103,33 @@ atomic_add_ret: /* %o0 = increment, %o1
6205 2: BACKOFF_SPIN(%o2, %o3, 1b)
6206 .size atomic_add_ret, .-atomic_add_ret
6207
6208 + .globl atomic_add_ret_unchecked
6209 + .type atomic_add_ret_unchecked,#function
6210 +atomic_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6211 + BACKOFF_SETUP(%o2)
6212 +1: lduw [%o1], %g1
6213 + addcc %g1, %o0, %g7
6214 + cas [%o1], %g1, %g7
6215 + cmp %g1, %g7
6216 + bne,pn %icc, 2f
6217 + add %g7, %o0, %g7
6218 + sra %g7, 0, %o0
6219 + retl
6220 + nop
6221 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6222 + .size atomic_add_ret_unchecked, .-atomic_add_ret_unchecked
6223 +
6224 .globl atomic_sub_ret
6225 .type atomic_sub_ret,#function
6226 atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
6227 BACKOFF_SETUP(%o2)
6228 1: lduw [%o1], %g1
6229 - sub %g1, %o0, %g7
6230 + subcc %g1, %o0, %g7
6231 +
6232 +#ifdef CONFIG_PAX_REFCOUNT
6233 + tvs %icc, 6
6234 +#endif
6235 +
6236 cas [%o1], %g1, %g7
6237 cmp %g1, %g7
6238 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6239 @@ -78,7 +144,12 @@ atomic_sub_ret: /* %o0 = decrement, %o1
6240 atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
6241 BACKOFF_SETUP(%o2)
6242 1: ldx [%o1], %g1
6243 - add %g1, %o0, %g7
6244 + addcc %g1, %o0, %g7
6245 +
6246 +#ifdef CONFIG_PAX_REFCOUNT
6247 + tvs %xcc, 6
6248 +#endif
6249 +
6250 casx [%o1], %g1, %g7
6251 cmp %g1, %g7
6252 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6253 @@ -88,12 +159,32 @@ atomic64_add: /* %o0 = increment, %o1 =
6254 2: BACKOFF_SPIN(%o2, %o3, 1b)
6255 .size atomic64_add, .-atomic64_add
6256
6257 + .globl atomic64_add_unchecked
6258 + .type atomic64_add_unchecked,#function
6259 +atomic64_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6260 + BACKOFF_SETUP(%o2)
6261 +1: ldx [%o1], %g1
6262 + addcc %g1, %o0, %g7
6263 + casx [%o1], %g1, %g7
6264 + cmp %g1, %g7
6265 + bne,pn %xcc, 2f
6266 + nop
6267 + retl
6268 + nop
6269 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6270 + .size atomic64_add_unchecked, .-atomic64_add_unchecked
6271 +
6272 .globl atomic64_sub
6273 .type atomic64_sub,#function
6274 atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
6275 BACKOFF_SETUP(%o2)
6276 1: ldx [%o1], %g1
6277 - sub %g1, %o0, %g7
6278 + subcc %g1, %o0, %g7
6279 +
6280 +#ifdef CONFIG_PAX_REFCOUNT
6281 + tvs %xcc, 6
6282 +#endif
6283 +
6284 casx [%o1], %g1, %g7
6285 cmp %g1, %g7
6286 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6287 @@ -103,12 +194,32 @@ atomic64_sub: /* %o0 = decrement, %o1 =
6288 2: BACKOFF_SPIN(%o2, %o3, 1b)
6289 .size atomic64_sub, .-atomic64_sub
6290
6291 + .globl atomic64_sub_unchecked
6292 + .type atomic64_sub_unchecked,#function
6293 +atomic64_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
6294 + BACKOFF_SETUP(%o2)
6295 +1: ldx [%o1], %g1
6296 + subcc %g1, %o0, %g7
6297 + casx [%o1], %g1, %g7
6298 + cmp %g1, %g7
6299 + bne,pn %xcc, 2f
6300 + nop
6301 + retl
6302 + nop
6303 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6304 + .size atomic64_sub_unchecked, .-atomic64_sub_unchecked
6305 +
6306 .globl atomic64_add_ret
6307 .type atomic64_add_ret,#function
6308 atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
6309 BACKOFF_SETUP(%o2)
6310 1: ldx [%o1], %g1
6311 - add %g1, %o0, %g7
6312 + addcc %g1, %o0, %g7
6313 +
6314 +#ifdef CONFIG_PAX_REFCOUNT
6315 + tvs %xcc, 6
6316 +#endif
6317 +
6318 casx [%o1], %g1, %g7
6319 cmp %g1, %g7
6320 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6321 @@ -118,12 +229,33 @@ atomic64_add_ret: /* %o0 = increment, %o
6322 2: BACKOFF_SPIN(%o2, %o3, 1b)
6323 .size atomic64_add_ret, .-atomic64_add_ret
6324
6325 + .globl atomic64_add_ret_unchecked
6326 + .type atomic64_add_ret_unchecked,#function
6327 +atomic64_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6328 + BACKOFF_SETUP(%o2)
6329 +1: ldx [%o1], %g1
6330 + addcc %g1, %o0, %g7
6331 + casx [%o1], %g1, %g7
6332 + cmp %g1, %g7
6333 + bne,pn %xcc, 2f
6334 + add %g7, %o0, %g7
6335 + mov %g7, %o0
6336 + retl
6337 + nop
6338 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6339 + .size atomic64_add_ret_unchecked, .-atomic64_add_ret_unchecked
6340 +
6341 .globl atomic64_sub_ret
6342 .type atomic64_sub_ret,#function
6343 atomic64_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
6344 BACKOFF_SETUP(%o2)
6345 1: ldx [%o1], %g1
6346 - sub %g1, %o0, %g7
6347 + subcc %g1, %o0, %g7
6348 +
6349 +#ifdef CONFIG_PAX_REFCOUNT
6350 + tvs %xcc, 6
6351 +#endif
6352 +
6353 casx [%o1], %g1, %g7
6354 cmp %g1, %g7
6355 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6356 diff -urNp linux-2.6.39/arch/sparc/lib/ksyms.c linux-2.6.39/arch/sparc/lib/ksyms.c
6357 --- linux-2.6.39/arch/sparc/lib/ksyms.c 2011-05-19 00:06:34.000000000 -0400
6358 +++ linux-2.6.39/arch/sparc/lib/ksyms.c 2011-05-22 19:36:30.000000000 -0400
6359 @@ -142,12 +142,17 @@ EXPORT_SYMBOL(__downgrade_write);
6360
6361 /* Atomic counter implementation. */
6362 EXPORT_SYMBOL(atomic_add);
6363 +EXPORT_SYMBOL(atomic_add_unchecked);
6364 EXPORT_SYMBOL(atomic_add_ret);
6365 EXPORT_SYMBOL(atomic_sub);
6366 +EXPORT_SYMBOL(atomic_sub_unchecked);
6367 EXPORT_SYMBOL(atomic_sub_ret);
6368 EXPORT_SYMBOL(atomic64_add);
6369 +EXPORT_SYMBOL(atomic64_add_unchecked);
6370 EXPORT_SYMBOL(atomic64_add_ret);
6371 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
6372 EXPORT_SYMBOL(atomic64_sub);
6373 +EXPORT_SYMBOL(atomic64_sub_unchecked);
6374 EXPORT_SYMBOL(atomic64_sub_ret);
6375
6376 /* Atomic bit operations. */
6377 diff -urNp linux-2.6.39/arch/sparc/lib/Makefile linux-2.6.39/arch/sparc/lib/Makefile
6378 --- linux-2.6.39/arch/sparc/lib/Makefile 2011-05-19 00:06:34.000000000 -0400
6379 +++ linux-2.6.39/arch/sparc/lib/Makefile 2011-05-22 19:36:30.000000000 -0400
6380 @@ -2,7 +2,7 @@
6381 #
6382
6383 asflags-y := -ansi -DST_DIV0=0x02
6384 -ccflags-y := -Werror
6385 +#ccflags-y := -Werror
6386
6387 lib-$(CONFIG_SPARC32) += mul.o rem.o sdiv.o udiv.o umul.o urem.o ashrdi3.o
6388 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
6389 diff -urNp linux-2.6.39/arch/sparc/Makefile linux-2.6.39/arch/sparc/Makefile
6390 --- linux-2.6.39/arch/sparc/Makefile 2011-05-19 00:06:34.000000000 -0400
6391 +++ linux-2.6.39/arch/sparc/Makefile 2011-05-22 19:41:32.000000000 -0400
6392 @@ -75,7 +75,7 @@ drivers-$(CONFIG_OPROFILE) += arch/sparc
6393 # Export what is needed by arch/sparc/boot/Makefile
6394 export VMLINUX_INIT VMLINUX_MAIN
6395 VMLINUX_INIT := $(head-y) $(init-y)
6396 -VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/
6397 +VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
6398 VMLINUX_MAIN += $(patsubst %/, %/lib.a, $(libs-y)) $(libs-y)
6399 VMLINUX_MAIN += $(drivers-y) $(net-y)
6400
6401 diff -urNp linux-2.6.39/arch/sparc/mm/fault_32.c linux-2.6.39/arch/sparc/mm/fault_32.c
6402 --- linux-2.6.39/arch/sparc/mm/fault_32.c 2011-05-19 00:06:34.000000000 -0400
6403 +++ linux-2.6.39/arch/sparc/mm/fault_32.c 2011-05-22 19:36:30.000000000 -0400
6404 @@ -22,6 +22,9 @@
6405 #include <linux/interrupt.h>
6406 #include <linux/module.h>
6407 #include <linux/kdebug.h>
6408 +#include <linux/slab.h>
6409 +#include <linux/pagemap.h>
6410 +#include <linux/compiler.h>
6411
6412 #include <asm/system.h>
6413 #include <asm/page.h>
6414 @@ -209,6 +212,268 @@ static unsigned long compute_si_addr(str
6415 return safe_compute_effective_address(regs, insn);
6416 }
6417
6418 +#ifdef CONFIG_PAX_PAGEEXEC
6419 +#ifdef CONFIG_PAX_DLRESOLVE
6420 +static void pax_emuplt_close(struct vm_area_struct *vma)
6421 +{
6422 + vma->vm_mm->call_dl_resolve = 0UL;
6423 +}
6424 +
6425 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6426 +{
6427 + unsigned int *kaddr;
6428 +
6429 + vmf->page = alloc_page(GFP_HIGHUSER);
6430 + if (!vmf->page)
6431 + return VM_FAULT_OOM;
6432 +
6433 + kaddr = kmap(vmf->page);
6434 + memset(kaddr, 0, PAGE_SIZE);
6435 + kaddr[0] = 0x9DE3BFA8U; /* save */
6436 + flush_dcache_page(vmf->page);
6437 + kunmap(vmf->page);
6438 + return VM_FAULT_MAJOR;
6439 +}
6440 +
6441 +static const struct vm_operations_struct pax_vm_ops = {
6442 + .close = pax_emuplt_close,
6443 + .fault = pax_emuplt_fault
6444 +};
6445 +
6446 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6447 +{
6448 + int ret;
6449 +
6450 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6451 + vma->vm_mm = current->mm;
6452 + vma->vm_start = addr;
6453 + vma->vm_end = addr + PAGE_SIZE;
6454 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6455 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6456 + vma->vm_ops = &pax_vm_ops;
6457 +
6458 + ret = insert_vm_struct(current->mm, vma);
6459 + if (ret)
6460 + return ret;
6461 +
6462 + ++current->mm->total_vm;
6463 + return 0;
6464 +}
6465 +#endif
6466 +
6467 +/*
6468 + * PaX: decide what to do with offenders (regs->pc = fault address)
6469 + *
6470 + * returns 1 when task should be killed
6471 + * 2 when patched PLT trampoline was detected
6472 + * 3 when unpatched PLT trampoline was detected
6473 + */
6474 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6475 +{
6476 +
6477 +#ifdef CONFIG_PAX_EMUPLT
6478 + int err;
6479 +
6480 + do { /* PaX: patched PLT emulation #1 */
6481 + unsigned int sethi1, sethi2, jmpl;
6482 +
6483 + err = get_user(sethi1, (unsigned int *)regs->pc);
6484 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
6485 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
6486 +
6487 + if (err)
6488 + break;
6489 +
6490 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6491 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6492 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6493 + {
6494 + unsigned int addr;
6495 +
6496 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6497 + addr = regs->u_regs[UREG_G1];
6498 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6499 + regs->pc = addr;
6500 + regs->npc = addr+4;
6501 + return 2;
6502 + }
6503 + } while (0);
6504 +
6505 + { /* PaX: patched PLT emulation #2 */
6506 + unsigned int ba;
6507 +
6508 + err = get_user(ba, (unsigned int *)regs->pc);
6509 +
6510 + if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
6511 + unsigned int addr;
6512 +
6513 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6514 + regs->pc = addr;
6515 + regs->npc = addr+4;
6516 + return 2;
6517 + }
6518 + }
6519 +
6520 + do { /* PaX: patched PLT emulation #3 */
6521 + unsigned int sethi, jmpl, nop;
6522 +
6523 + err = get_user(sethi, (unsigned int *)regs->pc);
6524 + err |= get_user(jmpl, (unsigned int *)(regs->pc+4));
6525 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6526 +
6527 + if (err)
6528 + break;
6529 +
6530 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6531 + (jmpl & 0xFFFFE000U) == 0x81C06000U &&
6532 + nop == 0x01000000U)
6533 + {
6534 + unsigned int addr;
6535 +
6536 + addr = (sethi & 0x003FFFFFU) << 10;
6537 + regs->u_regs[UREG_G1] = addr;
6538 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6539 + regs->pc = addr;
6540 + regs->npc = addr+4;
6541 + return 2;
6542 + }
6543 + } while (0);
6544 +
6545 + do { /* PaX: unpatched PLT emulation step 1 */
6546 + unsigned int sethi, ba, nop;
6547 +
6548 + err = get_user(sethi, (unsigned int *)regs->pc);
6549 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
6550 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6551 +
6552 + if (err)
6553 + break;
6554 +
6555 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6556 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6557 + nop == 0x01000000U)
6558 + {
6559 + unsigned int addr, save, call;
6560 +
6561 + if ((ba & 0xFFC00000U) == 0x30800000U)
6562 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6563 + else
6564 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6565 +
6566 + err = get_user(save, (unsigned int *)addr);
6567 + err |= get_user(call, (unsigned int *)(addr+4));
6568 + err |= get_user(nop, (unsigned int *)(addr+8));
6569 + if (err)
6570 + break;
6571 +
6572 +#ifdef CONFIG_PAX_DLRESOLVE
6573 + if (save == 0x9DE3BFA8U &&
6574 + (call & 0xC0000000U) == 0x40000000U &&
6575 + nop == 0x01000000U)
6576 + {
6577 + struct vm_area_struct *vma;
6578 + unsigned long call_dl_resolve;
6579 +
6580 + down_read(&current->mm->mmap_sem);
6581 + call_dl_resolve = current->mm->call_dl_resolve;
6582 + up_read(&current->mm->mmap_sem);
6583 + if (likely(call_dl_resolve))
6584 + goto emulate;
6585 +
6586 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6587 +
6588 + down_write(&current->mm->mmap_sem);
6589 + if (current->mm->call_dl_resolve) {
6590 + call_dl_resolve = current->mm->call_dl_resolve;
6591 + up_write(&current->mm->mmap_sem);
6592 + if (vma)
6593 + kmem_cache_free(vm_area_cachep, vma);
6594 + goto emulate;
6595 + }
6596 +
6597 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6598 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6599 + up_write(&current->mm->mmap_sem);
6600 + if (vma)
6601 + kmem_cache_free(vm_area_cachep, vma);
6602 + return 1;
6603 + }
6604 +
6605 + if (pax_insert_vma(vma, call_dl_resolve)) {
6606 + up_write(&current->mm->mmap_sem);
6607 + kmem_cache_free(vm_area_cachep, vma);
6608 + return 1;
6609 + }
6610 +
6611 + current->mm->call_dl_resolve = call_dl_resolve;
6612 + up_write(&current->mm->mmap_sem);
6613 +
6614 +emulate:
6615 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6616 + regs->pc = call_dl_resolve;
6617 + regs->npc = addr+4;
6618 + return 3;
6619 + }
6620 +#endif
6621 +
6622 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6623 + if ((save & 0xFFC00000U) == 0x05000000U &&
6624 + (call & 0xFFFFE000U) == 0x85C0A000U &&
6625 + nop == 0x01000000U)
6626 + {
6627 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6628 + regs->u_regs[UREG_G2] = addr + 4;
6629 + addr = (save & 0x003FFFFFU) << 10;
6630 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6631 + regs->pc = addr;
6632 + regs->npc = addr+4;
6633 + return 3;
6634 + }
6635 + }
6636 + } while (0);
6637 +
6638 + do { /* PaX: unpatched PLT emulation step 2 */
6639 + unsigned int save, call, nop;
6640 +
6641 + err = get_user(save, (unsigned int *)(regs->pc-4));
6642 + err |= get_user(call, (unsigned int *)regs->pc);
6643 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
6644 + if (err)
6645 + break;
6646 +
6647 + if (save == 0x9DE3BFA8U &&
6648 + (call & 0xC0000000U) == 0x40000000U &&
6649 + nop == 0x01000000U)
6650 + {
6651 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
6652 +
6653 + regs->u_regs[UREG_RETPC] = regs->pc;
6654 + regs->pc = dl_resolve;
6655 + regs->npc = dl_resolve+4;
6656 + return 3;
6657 + }
6658 + } while (0);
6659 +#endif
6660 +
6661 + return 1;
6662 +}
6663 +
6664 +void pax_report_insns(void *pc, void *sp)
6665 +{
6666 + unsigned long i;
6667 +
6668 + printk(KERN_ERR "PAX: bytes at PC: ");
6669 + for (i = 0; i < 8; i++) {
6670 + unsigned int c;
6671 + if (get_user(c, (unsigned int *)pc+i))
6672 + printk(KERN_CONT "???????? ");
6673 + else
6674 + printk(KERN_CONT "%08x ", c);
6675 + }
6676 + printk("\n");
6677 +}
6678 +#endif
6679 +
6680 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
6681 int text_fault)
6682 {
6683 @@ -281,6 +546,24 @@ good_area:
6684 if(!(vma->vm_flags & VM_WRITE))
6685 goto bad_area;
6686 } else {
6687 +
6688 +#ifdef CONFIG_PAX_PAGEEXEC
6689 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
6690 + up_read(&mm->mmap_sem);
6691 + switch (pax_handle_fetch_fault(regs)) {
6692 +
6693 +#ifdef CONFIG_PAX_EMUPLT
6694 + case 2:
6695 + case 3:
6696 + return;
6697 +#endif
6698 +
6699 + }
6700 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
6701 + do_group_exit(SIGKILL);
6702 + }
6703 +#endif
6704 +
6705 /* Allow reads even for write-only mappings */
6706 if(!(vma->vm_flags & (VM_READ | VM_EXEC)))
6707 goto bad_area;
6708 diff -urNp linux-2.6.39/arch/sparc/mm/fault_64.c linux-2.6.39/arch/sparc/mm/fault_64.c
6709 --- linux-2.6.39/arch/sparc/mm/fault_64.c 2011-05-19 00:06:34.000000000 -0400
6710 +++ linux-2.6.39/arch/sparc/mm/fault_64.c 2011-05-22 19:41:32.000000000 -0400
6711 @@ -21,6 +21,9 @@
6712 #include <linux/kprobes.h>
6713 #include <linux/kdebug.h>
6714 #include <linux/percpu.h>
6715 +#include <linux/slab.h>
6716 +#include <linux/pagemap.h>
6717 +#include <linux/compiler.h>
6718
6719 #include <asm/page.h>
6720 #include <asm/pgtable.h>
6721 @@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(stru
6722 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
6723 regs->tpc);
6724 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
6725 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
6726 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
6727 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
6728 dump_stack();
6729 unhandled_fault(regs->tpc, current, regs);
6730 @@ -272,6 +275,457 @@ static void noinline __kprobes bogus_32b
6731 show_regs(regs);
6732 }
6733
6734 +#ifdef CONFIG_PAX_PAGEEXEC
6735 +#ifdef CONFIG_PAX_DLRESOLVE
6736 +static void pax_emuplt_close(struct vm_area_struct *vma)
6737 +{
6738 + vma->vm_mm->call_dl_resolve = 0UL;
6739 +}
6740 +
6741 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6742 +{
6743 + unsigned int *kaddr;
6744 +
6745 + vmf->page = alloc_page(GFP_HIGHUSER);
6746 + if (!vmf->page)
6747 + return VM_FAULT_OOM;
6748 +
6749 + kaddr = kmap(vmf->page);
6750 + memset(kaddr, 0, PAGE_SIZE);
6751 + kaddr[0] = 0x9DE3BFA8U; /* save */
6752 + flush_dcache_page(vmf->page);
6753 + kunmap(vmf->page);
6754 + return VM_FAULT_MAJOR;
6755 +}
6756 +
6757 +static const struct vm_operations_struct pax_vm_ops = {
6758 + .close = pax_emuplt_close,
6759 + .fault = pax_emuplt_fault
6760 +};
6761 +
6762 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6763 +{
6764 + int ret;
6765 +
6766 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6767 + vma->vm_mm = current->mm;
6768 + vma->vm_start = addr;
6769 + vma->vm_end = addr + PAGE_SIZE;
6770 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6771 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6772 + vma->vm_ops = &pax_vm_ops;
6773 +
6774 + ret = insert_vm_struct(current->mm, vma);
6775 + if (ret)
6776 + return ret;
6777 +
6778 + ++current->mm->total_vm;
6779 + return 0;
6780 +}
6781 +#endif
6782 +
6783 +/*
6784 + * PaX: decide what to do with offenders (regs->tpc = fault address)
6785 + *
6786 + * returns 1 when task should be killed
6787 + * 2 when patched PLT trampoline was detected
6788 + * 3 when unpatched PLT trampoline was detected
6789 + */
6790 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6791 +{
6792 +
6793 +#ifdef CONFIG_PAX_EMUPLT
6794 + int err;
6795 +
6796 + do { /* PaX: patched PLT emulation #1 */
6797 + unsigned int sethi1, sethi2, jmpl;
6798 +
6799 + err = get_user(sethi1, (unsigned int *)regs->tpc);
6800 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
6801 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
6802 +
6803 + if (err)
6804 + break;
6805 +
6806 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6807 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6808 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6809 + {
6810 + unsigned long addr;
6811 +
6812 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6813 + addr = regs->u_regs[UREG_G1];
6814 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6815 +
6816 + if (test_thread_flag(TIF_32BIT))
6817 + addr &= 0xFFFFFFFFUL;
6818 +
6819 + regs->tpc = addr;
6820 + regs->tnpc = addr+4;
6821 + return 2;
6822 + }
6823 + } while (0);
6824 +
6825 + { /* PaX: patched PLT emulation #2 */
6826 + unsigned int ba;
6827 +
6828 + err = get_user(ba, (unsigned int *)regs->tpc);
6829 +
6830 + if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
6831 + unsigned long addr;
6832 +
6833 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6834 +
6835 + if (test_thread_flag(TIF_32BIT))
6836 + addr &= 0xFFFFFFFFUL;
6837 +
6838 + regs->tpc = addr;
6839 + regs->tnpc = addr+4;
6840 + return 2;
6841 + }
6842 + }
6843 +
6844 + do { /* PaX: patched PLT emulation #3 */
6845 + unsigned int sethi, jmpl, nop;
6846 +
6847 + err = get_user(sethi, (unsigned int *)regs->tpc);
6848 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+4));
6849 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6850 +
6851 + if (err)
6852 + break;
6853 +
6854 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6855 + (jmpl & 0xFFFFE000U) == 0x81C06000U &&
6856 + nop == 0x01000000U)
6857 + {
6858 + unsigned long addr;
6859 +
6860 + addr = (sethi & 0x003FFFFFU) << 10;
6861 + regs->u_regs[UREG_G1] = addr;
6862 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6863 +
6864 + if (test_thread_flag(TIF_32BIT))
6865 + addr &= 0xFFFFFFFFUL;
6866 +
6867 + regs->tpc = addr;
6868 + regs->tnpc = addr+4;
6869 + return 2;
6870 + }
6871 + } while (0);
6872 +
6873 + do { /* PaX: patched PLT emulation #4 */
6874 + unsigned int sethi, mov1, call, mov2;
6875 +
6876 + err = get_user(sethi, (unsigned int *)regs->tpc);
6877 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
6878 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
6879 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
6880 +
6881 + if (err)
6882 + break;
6883 +
6884 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6885 + mov1 == 0x8210000FU &&
6886 + (call & 0xC0000000U) == 0x40000000U &&
6887 + mov2 == 0x9E100001U)
6888 + {
6889 + unsigned long addr;
6890 +
6891 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
6892 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
6893 +
6894 + if (test_thread_flag(TIF_32BIT))
6895 + addr &= 0xFFFFFFFFUL;
6896 +
6897 + regs->tpc = addr;
6898 + regs->tnpc = addr+4;
6899 + return 2;
6900 + }
6901 + } while (0);
6902 +
6903 + do { /* PaX: patched PLT emulation #5 */
6904 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
6905 +
6906 + err = get_user(sethi, (unsigned int *)regs->tpc);
6907 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
6908 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
6909 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
6910 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
6911 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
6912 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
6913 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
6914 +
6915 + if (err)
6916 + break;
6917 +
6918 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6919 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
6920 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
6921 + (or1 & 0xFFFFE000U) == 0x82106000U &&
6922 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
6923 + sllx == 0x83287020U &&
6924 + jmpl == 0x81C04005U &&
6925 + nop == 0x01000000U)
6926 + {
6927 + unsigned long addr;
6928 +
6929 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
6930 + regs->u_regs[UREG_G1] <<= 32;
6931 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
6932 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
6933 + regs->tpc = addr;
6934 + regs->tnpc = addr+4;
6935 + return 2;
6936 + }
6937 + } while (0);
6938 +
6939 + do { /* PaX: patched PLT emulation #6 */
6940 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
6941 +
6942 + err = get_user(sethi, (unsigned int *)regs->tpc);
6943 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
6944 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
6945 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
6946 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
6947 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
6948 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
6949 +
6950 + if (err)
6951 + break;
6952 +
6953 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6954 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
6955 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
6956 + sllx == 0x83287020U &&
6957 + (or & 0xFFFFE000U) == 0x8A116000U &&
6958 + jmpl == 0x81C04005U &&
6959 + nop == 0x01000000U)
6960 + {
6961 + unsigned long addr;
6962 +
6963 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
6964 + regs->u_regs[UREG_G1] <<= 32;
6965 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
6966 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
6967 + regs->tpc = addr;
6968 + regs->tnpc = addr+4;
6969 + return 2;
6970 + }
6971 + } while (0);
6972 +
6973 + do { /* PaX: unpatched PLT emulation step 1 */
6974 + unsigned int sethi, ba, nop;
6975 +
6976 + err = get_user(sethi, (unsigned int *)regs->tpc);
6977 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
6978 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6979 +
6980 + if (err)
6981 + break;
6982 +
6983 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6984 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6985 + nop == 0x01000000U)
6986 + {
6987 + unsigned long addr;
6988 + unsigned int save, call;
6989 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
6990 +
6991 + if ((ba & 0xFFC00000U) == 0x30800000U)
6992 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6993 + else
6994 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6995 +
6996 + if (test_thread_flag(TIF_32BIT))
6997 + addr &= 0xFFFFFFFFUL;
6998 +
6999 + err = get_user(save, (unsigned int *)addr);
7000 + err |= get_user(call, (unsigned int *)(addr+4));
7001 + err |= get_user(nop, (unsigned int *)(addr+8));
7002 + if (err)
7003 + break;
7004 +
7005 +#ifdef CONFIG_PAX_DLRESOLVE
7006 + if (save == 0x9DE3BFA8U &&
7007 + (call & 0xC0000000U) == 0x40000000U &&
7008 + nop == 0x01000000U)
7009 + {
7010 + struct vm_area_struct *vma;
7011 + unsigned long call_dl_resolve;
7012 +
7013 + down_read(&current->mm->mmap_sem);
7014 + call_dl_resolve = current->mm->call_dl_resolve;
7015 + up_read(&current->mm->mmap_sem);
7016 + if (likely(call_dl_resolve))
7017 + goto emulate;
7018 +
7019 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
7020 +
7021 + down_write(&current->mm->mmap_sem);
7022 + if (current->mm->call_dl_resolve) {
7023 + call_dl_resolve = current->mm->call_dl_resolve;
7024 + up_write(&current->mm->mmap_sem);
7025 + if (vma)
7026 + kmem_cache_free(vm_area_cachep, vma);
7027 + goto emulate;
7028 + }
7029 +
7030 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
7031 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
7032 + up_write(&current->mm->mmap_sem);
7033 + if (vma)
7034 + kmem_cache_free(vm_area_cachep, vma);
7035 + return 1;
7036 + }
7037 +
7038 + if (pax_insert_vma(vma, call_dl_resolve)) {
7039 + up_write(&current->mm->mmap_sem);
7040 + kmem_cache_free(vm_area_cachep, vma);
7041 + return 1;
7042 + }
7043 +
7044 + current->mm->call_dl_resolve = call_dl_resolve;
7045 + up_write(&current->mm->mmap_sem);
7046 +
7047 +emulate:
7048 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7049 + regs->tpc = call_dl_resolve;
7050 + regs->tnpc = addr+4;
7051 + return 3;
7052 + }
7053 +#endif
7054 +
7055 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
7056 + if ((save & 0xFFC00000U) == 0x05000000U &&
7057 + (call & 0xFFFFE000U) == 0x85C0A000U &&
7058 + nop == 0x01000000U)
7059 + {
7060 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7061 + regs->u_regs[UREG_G2] = addr + 4;
7062 + addr = (save & 0x003FFFFFU) << 10;
7063 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7064 +
7065 + if (test_thread_flag(TIF_32BIT))
7066 + addr &= 0xFFFFFFFFUL;
7067 +
7068 + regs->tpc = addr;
7069 + regs->tnpc = addr+4;
7070 + return 3;
7071 + }
7072 +
7073 + /* PaX: 64-bit PLT stub */
7074 + err = get_user(sethi1, (unsigned int *)addr);
7075 + err |= get_user(sethi2, (unsigned int *)(addr+4));
7076 + err |= get_user(or1, (unsigned int *)(addr+8));
7077 + err |= get_user(or2, (unsigned int *)(addr+12));
7078 + err |= get_user(sllx, (unsigned int *)(addr+16));
7079 + err |= get_user(add, (unsigned int *)(addr+20));
7080 + err |= get_user(jmpl, (unsigned int *)(addr+24));
7081 + err |= get_user(nop, (unsigned int *)(addr+28));
7082 + if (err)
7083 + break;
7084 +
7085 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
7086 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7087 + (or1 & 0xFFFFE000U) == 0x88112000U &&
7088 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
7089 + sllx == 0x89293020U &&
7090 + add == 0x8A010005U &&
7091 + jmpl == 0x89C14000U &&
7092 + nop == 0x01000000U)
7093 + {
7094 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7095 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7096 + regs->u_regs[UREG_G4] <<= 32;
7097 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7098 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
7099 + regs->u_regs[UREG_G4] = addr + 24;
7100 + addr = regs->u_regs[UREG_G5];
7101 + regs->tpc = addr;
7102 + regs->tnpc = addr+4;
7103 + return 3;
7104 + }
7105 + }
7106 + } while (0);
7107 +
7108 +#ifdef CONFIG_PAX_DLRESOLVE
7109 + do { /* PaX: unpatched PLT emulation step 2 */
7110 + unsigned int save, call, nop;
7111 +
7112 + err = get_user(save, (unsigned int *)(regs->tpc-4));
7113 + err |= get_user(call, (unsigned int *)regs->tpc);
7114 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
7115 + if (err)
7116 + break;
7117 +
7118 + if (save == 0x9DE3BFA8U &&
7119 + (call & 0xC0000000U) == 0x40000000U &&
7120 + nop == 0x01000000U)
7121 + {
7122 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7123 +
7124 + if (test_thread_flag(TIF_32BIT))
7125 + dl_resolve &= 0xFFFFFFFFUL;
7126 +
7127 + regs->u_regs[UREG_RETPC] = regs->tpc;
7128 + regs->tpc = dl_resolve;
7129 + regs->tnpc = dl_resolve+4;
7130 + return 3;
7131 + }
7132 + } while (0);
7133 +#endif
7134 +
7135 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
7136 + unsigned int sethi, ba, nop;
7137 +
7138 + err = get_user(sethi, (unsigned int *)regs->tpc);
7139 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7140 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7141 +
7142 + if (err)
7143 + break;
7144 +
7145 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7146 + (ba & 0xFFF00000U) == 0x30600000U &&
7147 + nop == 0x01000000U)
7148 + {
7149 + unsigned long addr;
7150 +
7151 + addr = (sethi & 0x003FFFFFU) << 10;
7152 + regs->u_regs[UREG_G1] = addr;
7153 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7154 +
7155 + if (test_thread_flag(TIF_32BIT))
7156 + addr &= 0xFFFFFFFFUL;
7157 +
7158 + regs->tpc = addr;
7159 + regs->tnpc = addr+4;
7160 + return 2;
7161 + }
7162 + } while (0);
7163 +
7164 +#endif
7165 +
7166 + return 1;
7167 +}
7168 +
7169 +void pax_report_insns(void *pc, void *sp)
7170 +{
7171 + unsigned long i;
7172 +
7173 + printk(KERN_ERR "PAX: bytes at PC: ");
7174 + for (i = 0; i < 8; i++) {
7175 + unsigned int c;
7176 + if (get_user(c, (unsigned int *)pc+i))
7177 + printk(KERN_CONT "???????? ");
7178 + else
7179 + printk(KERN_CONT "%08x ", c);
7180 + }
7181 + printk("\n");
7182 +}
7183 +#endif
7184 +
7185 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
7186 {
7187 struct mm_struct *mm = current->mm;
7188 @@ -340,6 +794,29 @@ asmlinkage void __kprobes do_sparc64_fau
7189 if (!vma)
7190 goto bad_area;
7191
7192 +#ifdef CONFIG_PAX_PAGEEXEC
7193 + /* PaX: detect ITLB misses on non-exec pages */
7194 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
7195 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
7196 + {
7197 + if (address != regs->tpc)
7198 + goto good_area;
7199 +
7200 + up_read(&mm->mmap_sem);
7201 + switch (pax_handle_fetch_fault(regs)) {
7202 +
7203 +#ifdef CONFIG_PAX_EMUPLT
7204 + case 2:
7205 + case 3:
7206 + return;
7207 +#endif
7208 +
7209 + }
7210 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
7211 + do_group_exit(SIGKILL);
7212 + }
7213 +#endif
7214 +
7215 /* Pure DTLB misses do not tell us whether the fault causing
7216 * load/store/atomic was a write or not, it only says that there
7217 * was no match. So in such a case we (carefully) read the
7218 diff -urNp linux-2.6.39/arch/sparc/mm/hugetlbpage.c linux-2.6.39/arch/sparc/mm/hugetlbpage.c
7219 --- linux-2.6.39/arch/sparc/mm/hugetlbpage.c 2011-05-19 00:06:34.000000000 -0400
7220 +++ linux-2.6.39/arch/sparc/mm/hugetlbpage.c 2011-05-22 19:36:30.000000000 -0400
7221 @@ -68,7 +68,7 @@ full_search:
7222 }
7223 return -ENOMEM;
7224 }
7225 - if (likely(!vma || addr + len <= vma->vm_start)) {
7226 + if (likely(check_heap_stack_gap(vma, addr, len))) {
7227 /*
7228 * Remember the place where we stopped the search:
7229 */
7230 @@ -107,7 +107,7 @@ hugetlb_get_unmapped_area_topdown(struct
7231 /* make sure it can fit in the remaining address space */
7232 if (likely(addr > len)) {
7233 vma = find_vma(mm, addr-len);
7234 - if (!vma || addr <= vma->vm_start) {
7235 + if (check_heap_stack_gap(vma, addr - len, len)) {
7236 /* remember the address as a hint for next time */
7237 return (mm->free_area_cache = addr-len);
7238 }
7239 @@ -116,16 +116,17 @@ hugetlb_get_unmapped_area_topdown(struct
7240 if (unlikely(mm->mmap_base < len))
7241 goto bottomup;
7242
7243 - addr = (mm->mmap_base-len) & HPAGE_MASK;
7244 + addr = mm->mmap_base - len;
7245
7246 do {
7247 + addr &= HPAGE_MASK;
7248 /*
7249 * Lookup failure means no vma is above this address,
7250 * else if new region fits below vma->vm_start,
7251 * return with success:
7252 */
7253 vma = find_vma(mm, addr);
7254 - if (likely(!vma || addr+len <= vma->vm_start)) {
7255 + if (likely(check_heap_stack_gap(vma, addr, len))) {
7256 /* remember the address as a hint for next time */
7257 return (mm->free_area_cache = addr);
7258 }
7259 @@ -135,8 +136,8 @@ hugetlb_get_unmapped_area_topdown(struct
7260 mm->cached_hole_size = vma->vm_start - addr;
7261
7262 /* try just below the current vma->vm_start */
7263 - addr = (vma->vm_start-len) & HPAGE_MASK;
7264 - } while (likely(len < vma->vm_start));
7265 + addr = skip_heap_stack_gap(vma, len);
7266 + } while (!IS_ERR_VALUE(addr));
7267
7268 bottomup:
7269 /*
7270 @@ -182,8 +183,7 @@ hugetlb_get_unmapped_area(struct file *f
7271 if (addr) {
7272 addr = ALIGN(addr, HPAGE_SIZE);
7273 vma = find_vma(mm, addr);
7274 - if (task_size - len >= addr &&
7275 - (!vma || addr + len <= vma->vm_start))
7276 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
7277 return addr;
7278 }
7279 if (mm->get_unmapped_area == arch_get_unmapped_area)
7280 diff -urNp linux-2.6.39/arch/sparc/mm/init_32.c linux-2.6.39/arch/sparc/mm/init_32.c
7281 --- linux-2.6.39/arch/sparc/mm/init_32.c 2011-05-19 00:06:34.000000000 -0400
7282 +++ linux-2.6.39/arch/sparc/mm/init_32.c 2011-05-22 19:36:30.000000000 -0400
7283 @@ -318,6 +318,9 @@ extern void device_scan(void);
7284 pgprot_t PAGE_SHARED __read_mostly;
7285 EXPORT_SYMBOL(PAGE_SHARED);
7286
7287 +pgprot_t PAGE_SHARED_NOEXEC __read_mostly;
7288 +EXPORT_SYMBOL(PAGE_SHARED_NOEXEC);
7289 +
7290 void __init paging_init(void)
7291 {
7292 switch(sparc_cpu_model) {
7293 @@ -346,17 +349,17 @@ void __init paging_init(void)
7294
7295 /* Initialize the protection map with non-constant, MMU dependent values. */
7296 protection_map[0] = PAGE_NONE;
7297 - protection_map[1] = PAGE_READONLY;
7298 - protection_map[2] = PAGE_COPY;
7299 - protection_map[3] = PAGE_COPY;
7300 + protection_map[1] = PAGE_READONLY_NOEXEC;
7301 + protection_map[2] = PAGE_COPY_NOEXEC;
7302 + protection_map[3] = PAGE_COPY_NOEXEC;
7303 protection_map[4] = PAGE_READONLY;
7304 protection_map[5] = PAGE_READONLY;
7305 protection_map[6] = PAGE_COPY;
7306 protection_map[7] = PAGE_COPY;
7307 protection_map[8] = PAGE_NONE;
7308 - protection_map[9] = PAGE_READONLY;
7309 - protection_map[10] = PAGE_SHARED;
7310 - protection_map[11] = PAGE_SHARED;
7311 + protection_map[9] = PAGE_READONLY_NOEXEC;
7312 + protection_map[10] = PAGE_SHARED_NOEXEC;
7313 + protection_map[11] = PAGE_SHARED_NOEXEC;
7314 protection_map[12] = PAGE_READONLY;
7315 protection_map[13] = PAGE_READONLY;
7316 protection_map[14] = PAGE_SHARED;
7317 diff -urNp linux-2.6.39/arch/sparc/mm/Makefile linux-2.6.39/arch/sparc/mm/Makefile
7318 --- linux-2.6.39/arch/sparc/mm/Makefile 2011-05-19 00:06:34.000000000 -0400
7319 +++ linux-2.6.39/arch/sparc/mm/Makefile 2011-05-22 19:36:30.000000000 -0400
7320 @@ -2,7 +2,7 @@
7321 #
7322
7323 asflags-y := -ansi
7324 -ccflags-y := -Werror
7325 +#ccflags-y := -Werror
7326
7327 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o
7328 obj-y += fault_$(BITS).o
7329 diff -urNp linux-2.6.39/arch/sparc/mm/srmmu.c linux-2.6.39/arch/sparc/mm/srmmu.c
7330 --- linux-2.6.39/arch/sparc/mm/srmmu.c 2011-05-19 00:06:34.000000000 -0400
7331 +++ linux-2.6.39/arch/sparc/mm/srmmu.c 2011-05-22 19:36:30.000000000 -0400
7332 @@ -2200,6 +2200,13 @@ void __init ld_mmu_srmmu(void)
7333 PAGE_SHARED = pgprot_val(SRMMU_PAGE_SHARED);
7334 BTFIXUPSET_INT(page_copy, pgprot_val(SRMMU_PAGE_COPY));
7335 BTFIXUPSET_INT(page_readonly, pgprot_val(SRMMU_PAGE_RDONLY));
7336 +
7337 +#ifdef CONFIG_PAX_PAGEEXEC
7338 + PAGE_SHARED_NOEXEC = pgprot_val(SRMMU_PAGE_SHARED_NOEXEC);
7339 + BTFIXUPSET_INT(page_copy_noexec, pgprot_val(SRMMU_PAGE_COPY_NOEXEC));
7340 + BTFIXUPSET_INT(page_readonly_noexec, pgprot_val(SRMMU_PAGE_RDONLY_NOEXEC));
7341 +#endif
7342 +
7343 BTFIXUPSET_INT(page_kernel, pgprot_val(SRMMU_PAGE_KERNEL));
7344 page_kernel = pgprot_val(SRMMU_PAGE_KERNEL);
7345
7346 diff -urNp linux-2.6.39/arch/tile/kernel/pci.c linux-2.6.39/arch/tile/kernel/pci.c
7347 --- linux-2.6.39/arch/tile/kernel/pci.c 2011-05-19 00:06:34.000000000 -0400
7348 +++ linux-2.6.39/arch/tile/kernel/pci.c 2011-05-22 19:36:30.000000000 -0400
7349 @@ -60,7 +60,7 @@ int __write_once tile_plx_gen1;
7350 static struct pci_controller controllers[TILE_NUM_PCIE];
7351 static int num_controllers;
7352
7353 -static struct pci_ops tile_cfg_ops;
7354 +static const struct pci_ops tile_cfg_ops;
7355
7356
7357 /*
7358 @@ -564,7 +564,7 @@ static int __devinit tile_cfg_write(stru
7359 }
7360
7361
7362 -static struct pci_ops tile_cfg_ops = {
7363 +static const struct pci_ops tile_cfg_ops = {
7364 .read = tile_cfg_read,
7365 .write = tile_cfg_write,
7366 };
7367 diff -urNp linux-2.6.39/arch/um/include/asm/kmap_types.h linux-2.6.39/arch/um/include/asm/kmap_types.h
7368 --- linux-2.6.39/arch/um/include/asm/kmap_types.h 2011-05-19 00:06:34.000000000 -0400
7369 +++ linux-2.6.39/arch/um/include/asm/kmap_types.h 2011-05-22 19:36:30.000000000 -0400
7370 @@ -23,6 +23,7 @@ enum km_type {
7371 KM_IRQ1,
7372 KM_SOFTIRQ0,
7373 KM_SOFTIRQ1,
7374 + KM_CLEARPAGE,
7375 KM_TYPE_NR
7376 };
7377
7378 diff -urNp linux-2.6.39/arch/um/include/asm/page.h linux-2.6.39/arch/um/include/asm/page.h
7379 --- linux-2.6.39/arch/um/include/asm/page.h 2011-05-19 00:06:34.000000000 -0400
7380 +++ linux-2.6.39/arch/um/include/asm/page.h 2011-05-22 19:36:30.000000000 -0400
7381 @@ -14,6 +14,9 @@
7382 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
7383 #define PAGE_MASK (~(PAGE_SIZE-1))
7384
7385 +#define ktla_ktva(addr) (addr)
7386 +#define ktva_ktla(addr) (addr)
7387 +
7388 #ifndef __ASSEMBLY__
7389
7390 struct page;
7391 diff -urNp linux-2.6.39/arch/um/kernel/process.c linux-2.6.39/arch/um/kernel/process.c
7392 --- linux-2.6.39/arch/um/kernel/process.c 2011-05-19 00:06:34.000000000 -0400
7393 +++ linux-2.6.39/arch/um/kernel/process.c 2011-05-22 19:36:30.000000000 -0400
7394 @@ -404,22 +404,6 @@ int singlestepping(void * t)
7395 return 2;
7396 }
7397
7398 -/*
7399 - * Only x86 and x86_64 have an arch_align_stack().
7400 - * All other arches have "#define arch_align_stack(x) (x)"
7401 - * in their asm/system.h
7402 - * As this is included in UML from asm-um/system-generic.h,
7403 - * we can use it to behave as the subarch does.
7404 - */
7405 -#ifndef arch_align_stack
7406 -unsigned long arch_align_stack(unsigned long sp)
7407 -{
7408 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7409 - sp -= get_random_int() % 8192;
7410 - return sp & ~0xf;
7411 -}
7412 -#endif
7413 -
7414 unsigned long get_wchan(struct task_struct *p)
7415 {
7416 unsigned long stack_page, sp, ip;
7417 diff -urNp linux-2.6.39/arch/um/sys-i386/syscalls.c linux-2.6.39/arch/um/sys-i386/syscalls.c
7418 --- linux-2.6.39/arch/um/sys-i386/syscalls.c 2011-05-19 00:06:34.000000000 -0400
7419 +++ linux-2.6.39/arch/um/sys-i386/syscalls.c 2011-05-22 19:36:30.000000000 -0400
7420 @@ -11,6 +11,21 @@
7421 #include "asm/uaccess.h"
7422 #include "asm/unistd.h"
7423
7424 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
7425 +{
7426 + unsigned long pax_task_size = TASK_SIZE;
7427 +
7428 +#ifdef CONFIG_PAX_SEGMEXEC
7429 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
7430 + pax_task_size = SEGMEXEC_TASK_SIZE;
7431 +#endif
7432 +
7433 + if (len > pax_task_size || addr > pax_task_size - len)
7434 + return -EINVAL;
7435 +
7436 + return 0;
7437 +}
7438 +
7439 /*
7440 * The prototype on i386 is:
7441 *
7442 diff -urNp linux-2.6.39/arch/unicore32/kernel/pci.c linux-2.6.39/arch/unicore32/kernel/pci.c
7443 --- linux-2.6.39/arch/unicore32/kernel/pci.c 2011-05-19 00:06:34.000000000 -0400
7444 +++ linux-2.6.39/arch/unicore32/kernel/pci.c 2011-05-22 19:36:30.000000000 -0400
7445 @@ -66,7 +66,7 @@ puv3_write_config(struct pci_bus *bus, u
7446 return PCIBIOS_SUCCESSFUL;
7447 }
7448
7449 -struct pci_ops pci_puv3_ops = {
7450 +const struct pci_ops pci_puv3_ops = {
7451 .read = puv3_read_config,
7452 .write = puv3_write_config,
7453 };
7454 diff -urNp linux-2.6.39/arch/x86/boot/bitops.h linux-2.6.39/arch/x86/boot/bitops.h
7455 --- linux-2.6.39/arch/x86/boot/bitops.h 2011-05-19 00:06:34.000000000 -0400
7456 +++ linux-2.6.39/arch/x86/boot/bitops.h 2011-05-22 19:36:30.000000000 -0400
7457 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int
7458 u8 v;
7459 const u32 *p = (const u32 *)addr;
7460
7461 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7462 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7463 return v;
7464 }
7465
7466 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int
7467
7468 static inline void set_bit(int nr, void *addr)
7469 {
7470 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7471 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7472 }
7473
7474 #endif /* BOOT_BITOPS_H */
7475 diff -urNp linux-2.6.39/arch/x86/boot/boot.h linux-2.6.39/arch/x86/boot/boot.h
7476 --- linux-2.6.39/arch/x86/boot/boot.h 2011-05-19 00:06:34.000000000 -0400
7477 +++ linux-2.6.39/arch/x86/boot/boot.h 2011-05-22 19:36:30.000000000 -0400
7478 @@ -85,7 +85,7 @@ static inline void io_delay(void)
7479 static inline u16 ds(void)
7480 {
7481 u16 seg;
7482 - asm("movw %%ds,%0" : "=rm" (seg));
7483 + asm volatile("movw %%ds,%0" : "=rm" (seg));
7484 return seg;
7485 }
7486
7487 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t
7488 static inline int memcmp(const void *s1, const void *s2, size_t len)
7489 {
7490 u8 diff;
7491 - asm("repe; cmpsb; setnz %0"
7492 + asm volatile("repe; cmpsb; setnz %0"
7493 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
7494 return diff;
7495 }
7496 diff -urNp linux-2.6.39/arch/x86/boot/compressed/head_32.S linux-2.6.39/arch/x86/boot/compressed/head_32.S
7497 --- linux-2.6.39/arch/x86/boot/compressed/head_32.S 2011-05-19 00:06:34.000000000 -0400
7498 +++ linux-2.6.39/arch/x86/boot/compressed/head_32.S 2011-05-22 19:36:30.000000000 -0400
7499 @@ -76,7 +76,7 @@ ENTRY(startup_32)
7500 notl %eax
7501 andl %eax, %ebx
7502 #else
7503 - movl $LOAD_PHYSICAL_ADDR, %ebx
7504 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7505 #endif
7506
7507 /* Target address to relocate to for decompression */
7508 @@ -162,7 +162,7 @@ relocated:
7509 * and where it was actually loaded.
7510 */
7511 movl %ebp, %ebx
7512 - subl $LOAD_PHYSICAL_ADDR, %ebx
7513 + subl $____LOAD_PHYSICAL_ADDR, %ebx
7514 jz 2f /* Nothing to be done if loaded at compiled addr. */
7515 /*
7516 * Process relocations.
7517 @@ -170,8 +170,7 @@ relocated:
7518
7519 1: subl $4, %edi
7520 movl (%edi), %ecx
7521 - testl %ecx, %ecx
7522 - jz 2f
7523 + jecxz 2f
7524 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
7525 jmp 1b
7526 2:
7527 diff -urNp linux-2.6.39/arch/x86/boot/compressed/head_64.S linux-2.6.39/arch/x86/boot/compressed/head_64.S
7528 --- linux-2.6.39/arch/x86/boot/compressed/head_64.S 2011-05-19 00:06:34.000000000 -0400
7529 +++ linux-2.6.39/arch/x86/boot/compressed/head_64.S 2011-05-22 19:36:30.000000000 -0400
7530 @@ -91,7 +91,7 @@ ENTRY(startup_32)
7531 notl %eax
7532 andl %eax, %ebx
7533 #else
7534 - movl $LOAD_PHYSICAL_ADDR, %ebx
7535 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7536 #endif
7537
7538 /* Target address to relocate to for decompression */
7539 @@ -233,7 +233,7 @@ ENTRY(startup_64)
7540 notq %rax
7541 andq %rax, %rbp
7542 #else
7543 - movq $LOAD_PHYSICAL_ADDR, %rbp
7544 + movq $____LOAD_PHYSICAL_ADDR, %rbp
7545 #endif
7546
7547 /* Target address to relocate to for decompression */
7548 diff -urNp linux-2.6.39/arch/x86/boot/compressed/misc.c linux-2.6.39/arch/x86/boot/compressed/misc.c
7549 --- linux-2.6.39/arch/x86/boot/compressed/misc.c 2011-05-19 00:06:34.000000000 -0400
7550 +++ linux-2.6.39/arch/x86/boot/compressed/misc.c 2011-05-22 19:36:30.000000000 -0400
7551 @@ -310,7 +310,7 @@ static void parse_elf(void *output)
7552 case PT_LOAD:
7553 #ifdef CONFIG_RELOCATABLE
7554 dest = output;
7555 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
7556 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
7557 #else
7558 dest = (void *)(phdr->p_paddr);
7559 #endif
7560 @@ -363,7 +363,7 @@ asmlinkage void decompress_kernel(void *
7561 error("Destination address too large");
7562 #endif
7563 #ifndef CONFIG_RELOCATABLE
7564 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
7565 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
7566 error("Wrong destination address");
7567 #endif
7568
7569 diff -urNp linux-2.6.39/arch/x86/boot/compressed/relocs.c linux-2.6.39/arch/x86/boot/compressed/relocs.c
7570 --- linux-2.6.39/arch/x86/boot/compressed/relocs.c 2011-05-19 00:06:34.000000000 -0400
7571 +++ linux-2.6.39/arch/x86/boot/compressed/relocs.c 2011-05-22 19:36:30.000000000 -0400
7572 @@ -13,8 +13,11 @@
7573
7574 static void die(char *fmt, ...);
7575
7576 +#include "../../../../include/generated/autoconf.h"
7577 +
7578 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
7579 static Elf32_Ehdr ehdr;
7580 +static Elf32_Phdr *phdr;
7581 static unsigned long reloc_count, reloc_idx;
7582 static unsigned long *relocs;
7583
7584 @@ -270,9 +273,39 @@ static void read_ehdr(FILE *fp)
7585 }
7586 }
7587
7588 +static void read_phdrs(FILE *fp)
7589 +{
7590 + unsigned int i;
7591 +
7592 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
7593 + if (!phdr) {
7594 + die("Unable to allocate %d program headers\n",
7595 + ehdr.e_phnum);
7596 + }
7597 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
7598 + die("Seek to %d failed: %s\n",
7599 + ehdr.e_phoff, strerror(errno));
7600 + }
7601 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
7602 + die("Cannot read ELF program headers: %s\n",
7603 + strerror(errno));
7604 + }
7605 + for(i = 0; i < ehdr.e_phnum; i++) {
7606 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
7607 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
7608 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
7609 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
7610 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
7611 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
7612 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
7613 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
7614 + }
7615 +
7616 +}
7617 +
7618 static void read_shdrs(FILE *fp)
7619 {
7620 - int i;
7621 + unsigned int i;
7622 Elf32_Shdr shdr;
7623
7624 secs = calloc(ehdr.e_shnum, sizeof(struct section));
7625 @@ -307,7 +340,7 @@ static void read_shdrs(FILE *fp)
7626
7627 static void read_strtabs(FILE *fp)
7628 {
7629 - int i;
7630 + unsigned int i;
7631 for (i = 0; i < ehdr.e_shnum; i++) {
7632 struct section *sec = &secs[i];
7633 if (sec->shdr.sh_type != SHT_STRTAB) {
7634 @@ -332,7 +365,7 @@ static void read_strtabs(FILE *fp)
7635
7636 static void read_symtabs(FILE *fp)
7637 {
7638 - int i,j;
7639 + unsigned int i,j;
7640 for (i = 0; i < ehdr.e_shnum; i++) {
7641 struct section *sec = &secs[i];
7642 if (sec->shdr.sh_type != SHT_SYMTAB) {
7643 @@ -365,7 +398,9 @@ static void read_symtabs(FILE *fp)
7644
7645 static void read_relocs(FILE *fp)
7646 {
7647 - int i,j;
7648 + unsigned int i,j;
7649 + uint32_t base;
7650 +
7651 for (i = 0; i < ehdr.e_shnum; i++) {
7652 struct section *sec = &secs[i];
7653 if (sec->shdr.sh_type != SHT_REL) {
7654 @@ -385,9 +420,18 @@ static void read_relocs(FILE *fp)
7655 die("Cannot read symbol table: %s\n",
7656 strerror(errno));
7657 }
7658 + base = 0;
7659 + for (j = 0; j < ehdr.e_phnum; j++) {
7660 + if (phdr[j].p_type != PT_LOAD )
7661 + continue;
7662 + 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)
7663 + continue;
7664 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
7665 + break;
7666 + }
7667 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
7668 Elf32_Rel *rel = &sec->reltab[j];
7669 - rel->r_offset = elf32_to_cpu(rel->r_offset);
7670 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
7671 rel->r_info = elf32_to_cpu(rel->r_info);
7672 }
7673 }
7674 @@ -396,14 +440,14 @@ static void read_relocs(FILE *fp)
7675
7676 static void print_absolute_symbols(void)
7677 {
7678 - int i;
7679 + unsigned int i;
7680 printf("Absolute symbols\n");
7681 printf(" Num: Value Size Type Bind Visibility Name\n");
7682 for (i = 0; i < ehdr.e_shnum; i++) {
7683 struct section *sec = &secs[i];
7684 char *sym_strtab;
7685 Elf32_Sym *sh_symtab;
7686 - int j;
7687 + unsigned int j;
7688
7689 if (sec->shdr.sh_type != SHT_SYMTAB) {
7690 continue;
7691 @@ -431,14 +475,14 @@ static void print_absolute_symbols(void)
7692
7693 static void print_absolute_relocs(void)
7694 {
7695 - int i, printed = 0;
7696 + unsigned int i, printed = 0;
7697
7698 for (i = 0; i < ehdr.e_shnum; i++) {
7699 struct section *sec = &secs[i];
7700 struct section *sec_applies, *sec_symtab;
7701 char *sym_strtab;
7702 Elf32_Sym *sh_symtab;
7703 - int j;
7704 + unsigned int j;
7705 if (sec->shdr.sh_type != SHT_REL) {
7706 continue;
7707 }
7708 @@ -499,13 +543,13 @@ static void print_absolute_relocs(void)
7709
7710 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym))
7711 {
7712 - int i;
7713 + unsigned int i;
7714 /* Walk through the relocations */
7715 for (i = 0; i < ehdr.e_shnum; i++) {
7716 char *sym_strtab;
7717 Elf32_Sym *sh_symtab;
7718 struct section *sec_applies, *sec_symtab;
7719 - int j;
7720 + unsigned int j;
7721 struct section *sec = &secs[i];
7722
7723 if (sec->shdr.sh_type != SHT_REL) {
7724 @@ -530,6 +574,22 @@ static void walk_relocs(void (*visit)(El
7725 !is_rel_reloc(sym_name(sym_strtab, sym))) {
7726 continue;
7727 }
7728 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
7729 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
7730 + continue;
7731 +
7732 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
7733 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
7734 + if (!strcmp(sec_name(sym->st_shndx), ".module.text") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
7735 + continue;
7736 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
7737 + continue;
7738 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
7739 + continue;
7740 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
7741 + continue;
7742 +#endif
7743 +
7744 switch (r_type) {
7745 case R_386_NONE:
7746 case R_386_PC32:
7747 @@ -571,7 +631,7 @@ static int cmp_relocs(const void *va, co
7748
7749 static void emit_relocs(int as_text)
7750 {
7751 - int i;
7752 + unsigned int i;
7753 /* Count how many relocations I have and allocate space for them. */
7754 reloc_count = 0;
7755 walk_relocs(count_reloc);
7756 @@ -665,6 +725,7 @@ int main(int argc, char **argv)
7757 fname, strerror(errno));
7758 }
7759 read_ehdr(fp);
7760 + read_phdrs(fp);
7761 read_shdrs(fp);
7762 read_strtabs(fp);
7763 read_symtabs(fp);
7764 diff -urNp linux-2.6.39/arch/x86/boot/cpucheck.c linux-2.6.39/arch/x86/boot/cpucheck.c
7765 --- linux-2.6.39/arch/x86/boot/cpucheck.c 2011-05-19 00:06:34.000000000 -0400
7766 +++ linux-2.6.39/arch/x86/boot/cpucheck.c 2011-05-22 19:36:30.000000000 -0400
7767 @@ -74,7 +74,7 @@ static int has_fpu(void)
7768 u16 fcw = -1, fsw = -1;
7769 u32 cr0;
7770
7771 - asm("movl %%cr0,%0" : "=r" (cr0));
7772 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
7773 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
7774 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
7775 asm volatile("movl %0,%%cr0" : : "r" (cr0));
7776 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
7777 {
7778 u32 f0, f1;
7779
7780 - asm("pushfl ; "
7781 + asm volatile("pushfl ; "
7782 "pushfl ; "
7783 "popl %0 ; "
7784 "movl %0,%1 ; "
7785 @@ -115,7 +115,7 @@ static void get_flags(void)
7786 set_bit(X86_FEATURE_FPU, cpu.flags);
7787
7788 if (has_eflag(X86_EFLAGS_ID)) {
7789 - asm("cpuid"
7790 + asm volatile("cpuid"
7791 : "=a" (max_intel_level),
7792 "=b" (cpu_vendor[0]),
7793 "=d" (cpu_vendor[1]),
7794 @@ -124,7 +124,7 @@ static void get_flags(void)
7795
7796 if (max_intel_level >= 0x00000001 &&
7797 max_intel_level <= 0x0000ffff) {
7798 - asm("cpuid"
7799 + asm volatile("cpuid"
7800 : "=a" (tfms),
7801 "=c" (cpu.flags[4]),
7802 "=d" (cpu.flags[0])
7803 @@ -136,7 +136,7 @@ static void get_flags(void)
7804 cpu.model += ((tfms >> 16) & 0xf) << 4;
7805 }
7806
7807 - asm("cpuid"
7808 + asm volatile("cpuid"
7809 : "=a" (max_amd_level)
7810 : "a" (0x80000000)
7811 : "ebx", "ecx", "edx");
7812 @@ -144,7 +144,7 @@ static void get_flags(void)
7813 if (max_amd_level >= 0x80000001 &&
7814 max_amd_level <= 0x8000ffff) {
7815 u32 eax = 0x80000001;
7816 - asm("cpuid"
7817 + asm volatile("cpuid"
7818 : "+a" (eax),
7819 "=c" (cpu.flags[6]),
7820 "=d" (cpu.flags[1])
7821 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *r
7822 u32 ecx = MSR_K7_HWCR;
7823 u32 eax, edx;
7824
7825 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7826 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7827 eax &= ~(1 << 15);
7828 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7829 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7830
7831 get_flags(); /* Make sure it really did something */
7832 err = check_flags();
7833 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *r
7834 u32 ecx = MSR_VIA_FCR;
7835 u32 eax, edx;
7836
7837 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7838 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7839 eax |= (1<<1)|(1<<7);
7840 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7841 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7842
7843 set_bit(X86_FEATURE_CX8, cpu.flags);
7844 err = check_flags();
7845 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *r
7846 u32 eax, edx;
7847 u32 level = 1;
7848
7849 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7850 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7851 - asm("cpuid"
7852 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7853 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7854 + asm volatile("cpuid"
7855 : "+a" (level), "=d" (cpu.flags[0])
7856 : : "ecx", "ebx");
7857 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7858 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7859
7860 err = check_flags();
7861 }
7862 diff -urNp linux-2.6.39/arch/x86/boot/header.S linux-2.6.39/arch/x86/boot/header.S
7863 --- linux-2.6.39/arch/x86/boot/header.S 2011-05-19 00:06:34.000000000 -0400
7864 +++ linux-2.6.39/arch/x86/boot/header.S 2011-05-22 19:36:30.000000000 -0400
7865 @@ -224,7 +224,7 @@ setup_data: .quad 0 # 64-bit physical
7866 # single linked list of
7867 # struct setup_data
7868
7869 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
7870 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
7871
7872 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
7873 #define VO_INIT_SIZE (VO__end - VO__text)
7874 diff -urNp linux-2.6.39/arch/x86/boot/memory.c linux-2.6.39/arch/x86/boot/memory.c
7875 --- linux-2.6.39/arch/x86/boot/memory.c 2011-05-19 00:06:34.000000000 -0400
7876 +++ linux-2.6.39/arch/x86/boot/memory.c 2011-05-22 19:36:30.000000000 -0400
7877 @@ -19,7 +19,7 @@
7878
7879 static int detect_memory_e820(void)
7880 {
7881 - int count = 0;
7882 + unsigned int count = 0;
7883 struct biosregs ireg, oreg;
7884 struct e820entry *desc = boot_params.e820_map;
7885 static struct e820entry buf; /* static so it is zeroed */
7886 diff -urNp linux-2.6.39/arch/x86/boot/video.c linux-2.6.39/arch/x86/boot/video.c
7887 --- linux-2.6.39/arch/x86/boot/video.c 2011-05-19 00:06:34.000000000 -0400
7888 +++ linux-2.6.39/arch/x86/boot/video.c 2011-05-22 19:36:30.000000000 -0400
7889 @@ -96,7 +96,7 @@ static void store_mode_params(void)
7890 static unsigned int get_entry(void)
7891 {
7892 char entry_buf[4];
7893 - int i, len = 0;
7894 + unsigned int i, len = 0;
7895 int key;
7896 unsigned int v;
7897
7898 diff -urNp linux-2.6.39/arch/x86/boot/video-vesa.c linux-2.6.39/arch/x86/boot/video-vesa.c
7899 --- linux-2.6.39/arch/x86/boot/video-vesa.c 2011-05-19 00:06:34.000000000 -0400
7900 +++ linux-2.6.39/arch/x86/boot/video-vesa.c 2011-05-22 19:36:30.000000000 -0400
7901 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
7902
7903 boot_params.screen_info.vesapm_seg = oreg.es;
7904 boot_params.screen_info.vesapm_off = oreg.di;
7905 + boot_params.screen_info.vesapm_size = oreg.cx;
7906 }
7907
7908 /*
7909 diff -urNp linux-2.6.39/arch/x86/ia32/ia32_aout.c linux-2.6.39/arch/x86/ia32/ia32_aout.c
7910 --- linux-2.6.39/arch/x86/ia32/ia32_aout.c 2011-05-19 00:06:34.000000000 -0400
7911 +++ linux-2.6.39/arch/x86/ia32/ia32_aout.c 2011-05-22 19:41:32.000000000 -0400
7912 @@ -162,6 +162,8 @@ static int aout_core_dump(long signr, st
7913 unsigned long dump_start, dump_size;
7914 struct user32 dump;
7915
7916 + memset(&dump, 0, sizeof(dump));
7917 +
7918 fs = get_fs();
7919 set_fs(KERNEL_DS);
7920 has_dumped = 1;
7921 diff -urNp linux-2.6.39/arch/x86/ia32/ia32entry.S linux-2.6.39/arch/x86/ia32/ia32entry.S
7922 --- linux-2.6.39/arch/x86/ia32/ia32entry.S 2011-05-19 00:06:34.000000000 -0400
7923 +++ linux-2.6.39/arch/x86/ia32/ia32entry.S 2011-05-23 17:16:01.000000000 -0400
7924 @@ -13,6 +13,7 @@
7925 #include <asm/thread_info.h>
7926 #include <asm/segment.h>
7927 #include <asm/irqflags.h>
7928 +#include <asm/pgtable.h>
7929 #include <linux/linkage.h>
7930
7931 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
7932 @@ -95,6 +96,32 @@ ENTRY(native_irq_enable_sysexit)
7933 ENDPROC(native_irq_enable_sysexit)
7934 #endif
7935
7936 + .macro pax_enter_kernel_user
7937 +#ifdef CONFIG_PAX_MEMORY_UDEREF
7938 + call pax_enter_kernel_user
7939 +#endif
7940 + .endm
7941 +
7942 + .macro pax_exit_kernel_user
7943 +#ifdef CONFIG_PAX_MEMORY_UDEREF
7944 + call pax_exit_kernel_user
7945 +#endif
7946 +#ifdef CONFIG_PAX_RANDKSTACK
7947 + pushq %rax
7948 + call pax_randomize_kstack
7949 + popq %rax
7950 +#endif
7951 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
7952 + call pax_erase_kstack
7953 +#endif
7954 + .endm
7955 +
7956 + .macro pax_erase_kstack
7957 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
7958 + call pax_erase_kstack
7959 +#endif
7960 + .endm
7961 +
7962 /*
7963 * 32bit SYSENTER instruction entry.
7964 *
7965 @@ -121,7 +148,7 @@ ENTRY(ia32_sysenter_target)
7966 CFI_REGISTER rsp,rbp
7967 SWAPGS_UNSAFE_STACK
7968 movq PER_CPU_VAR(kernel_stack), %rsp
7969 - addq $(KERNEL_STACK_OFFSET),%rsp
7970 + pax_enter_kernel_user
7971 /*
7972 * No need to follow this irqs on/off section: the syscall
7973 * disabled irqs, here we enable it straight after entry:
7974 @@ -134,7 +161,8 @@ ENTRY(ia32_sysenter_target)
7975 CFI_REL_OFFSET rsp,0
7976 pushfq_cfi
7977 /*CFI_REL_OFFSET rflags,0*/
7978 - movl 8*3-THREAD_SIZE+TI_sysenter_return(%rsp), %r10d
7979 + GET_THREAD_INFO(%r10)
7980 + movl TI_sysenter_return(%r10), %r10d
7981 CFI_REGISTER rip,r10
7982 pushq_cfi $__USER32_CS
7983 /*CFI_REL_OFFSET cs,0*/
7984 @@ -146,6 +174,12 @@ ENTRY(ia32_sysenter_target)
7985 SAVE_ARGS 0,0,1
7986 /* no need to do an access_ok check here because rbp has been
7987 32bit zero extended */
7988 +
7989 +#ifdef CONFIG_PAX_MEMORY_UDEREF
7990 + mov $PAX_USER_SHADOW_BASE,%r10
7991 + add %r10,%rbp
7992 +#endif
7993 +
7994 1: movl (%rbp),%ebp
7995 .section __ex_table,"a"
7996 .quad 1b,ia32_badarg
7997 @@ -168,6 +202,7 @@ sysenter_dispatch:
7998 testl $_TIF_ALLWORK_MASK,TI_flags(%r10)
7999 jnz sysexit_audit
8000 sysexit_from_sys_call:
8001 + pax_exit_kernel_user
8002 andl $~TS_COMPAT,TI_status(%r10)
8003 /* clear IF, that popfq doesn't enable interrupts early */
8004 andl $~0x200,EFLAGS-R11(%rsp)
8005 @@ -194,6 +229,9 @@ sysexit_from_sys_call:
8006 movl %eax,%esi /* 2nd arg: syscall number */
8007 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
8008 call audit_syscall_entry
8009 +
8010 + pax_erase_kstack
8011 +
8012 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
8013 cmpq $(IA32_NR_syscalls-1),%rax
8014 ja ia32_badsys
8015 @@ -246,6 +284,9 @@ sysenter_tracesys:
8016 movq $-ENOSYS,RAX(%rsp)/* ptrace can change this for a bad syscall */
8017 movq %rsp,%rdi /* &pt_regs -> arg1 */
8018 call syscall_trace_enter
8019 +
8020 + pax_erase_kstack
8021 +
8022 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8023 RESTORE_REST
8024 cmpq $(IA32_NR_syscalls-1),%rax
8025 @@ -277,19 +318,24 @@ ENDPROC(ia32_sysenter_target)
8026 ENTRY(ia32_cstar_target)
8027 CFI_STARTPROC32 simple
8028 CFI_SIGNAL_FRAME
8029 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
8030 + CFI_DEF_CFA rsp,0
8031 CFI_REGISTER rip,rcx
8032 /*CFI_REGISTER rflags,r11*/
8033 SWAPGS_UNSAFE_STACK
8034 movl %esp,%r8d
8035 CFI_REGISTER rsp,r8
8036 movq PER_CPU_VAR(kernel_stack),%rsp
8037 +
8038 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8039 + pax_enter_kernel_user
8040 +#endif
8041 +
8042 /*
8043 * No need to follow this irqs on/off section: the syscall
8044 * disabled irqs and here we enable it straight after entry:
8045 */
8046 ENABLE_INTERRUPTS(CLBR_NONE)
8047 - SAVE_ARGS 8,1,1
8048 + SAVE_ARGS 8*6,1,1
8049 movl %eax,%eax /* zero extension */
8050 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
8051 movq %rcx,RIP-ARGOFFSET(%rsp)
8052 @@ -305,6 +351,12 @@ ENTRY(ia32_cstar_target)
8053 /* no need to do an access_ok check here because r8 has been
8054 32bit zero extended */
8055 /* hardware stack frame is complete now */
8056 +
8057 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8058 + mov $PAX_USER_SHADOW_BASE,%r10
8059 + add %r10,%r8
8060 +#endif
8061 +
8062 1: movl (%r8),%r9d
8063 .section __ex_table,"a"
8064 .quad 1b,ia32_badarg
8065 @@ -327,6 +379,7 @@ cstar_dispatch:
8066 testl $_TIF_ALLWORK_MASK,TI_flags(%r10)
8067 jnz sysretl_audit
8068 sysretl_from_sys_call:
8069 + pax_exit_kernel_user
8070 andl $~TS_COMPAT,TI_status(%r10)
8071 RESTORE_ARGS 1,-ARG_SKIP,1,1,1
8072 movl RIP-ARGOFFSET(%rsp),%ecx
8073 @@ -364,6 +417,9 @@ cstar_tracesys:
8074 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8075 movq %rsp,%rdi /* &pt_regs -> arg1 */
8076 call syscall_trace_enter
8077 +
8078 + pax_erase_kstack
8079 +
8080 LOAD_ARGS32 ARGOFFSET, 1 /* reload args from stack in case ptrace changed it */
8081 RESTORE_REST
8082 xchgl %ebp,%r9d
8083 @@ -409,6 +465,7 @@ ENTRY(ia32_syscall)
8084 CFI_REL_OFFSET rip,RIP-RIP
8085 PARAVIRT_ADJUST_EXCEPTION_FRAME
8086 SWAPGS
8087 + pax_enter_kernel_user
8088 /*
8089 * No need to follow this irqs on/off section: the syscall
8090 * disabled irqs and here we enable it straight after entry:
8091 @@ -441,6 +498,9 @@ ia32_tracesys:
8092 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8093 movq %rsp,%rdi /* &pt_regs -> arg1 */
8094 call syscall_trace_enter
8095 +
8096 + pax_erase_kstack
8097 +
8098 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8099 RESTORE_REST
8100 cmpq $(IA32_NR_syscalls-1),%rax
8101 diff -urNp linux-2.6.39/arch/x86/ia32/ia32_signal.c linux-2.6.39/arch/x86/ia32/ia32_signal.c
8102 --- linux-2.6.39/arch/x86/ia32/ia32_signal.c 2011-05-19 00:06:34.000000000 -0400
8103 +++ linux-2.6.39/arch/x86/ia32/ia32_signal.c 2011-05-22 19:36:30.000000000 -0400
8104 @@ -403,7 +403,7 @@ static void __user *get_sigframe(struct
8105 sp -= frame_size;
8106 /* Align the stack pointer according to the i386 ABI,
8107 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
8108 - sp = ((sp + 4) & -16ul) - 4;
8109 + sp = ((sp - 12) & -16ul) - 4;
8110 return (void __user *) sp;
8111 }
8112
8113 @@ -461,7 +461,7 @@ int ia32_setup_frame(int sig, struct k_s
8114 * These are actually not used anymore, but left because some
8115 * gdb versions depend on them as a marker.
8116 */
8117 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8118 + put_user_ex(*((const u64 *)&code), (u64 *)frame->retcode);
8119 } put_user_catch(err);
8120
8121 if (err)
8122 @@ -503,7 +503,7 @@ int ia32_setup_rt_frame(int sig, struct
8123 0xb8,
8124 __NR_ia32_rt_sigreturn,
8125 0x80cd,
8126 - 0,
8127 + 0
8128 };
8129
8130 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
8131 @@ -533,16 +533,18 @@ int ia32_setup_rt_frame(int sig, struct
8132
8133 if (ka->sa.sa_flags & SA_RESTORER)
8134 restorer = ka->sa.sa_restorer;
8135 + else if (current->mm->context.vdso)
8136 + /* Return stub is in 32bit vsyscall page */
8137 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
8138 else
8139 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
8140 - rt_sigreturn);
8141 + restorer = &frame->retcode;
8142 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
8143
8144 /*
8145 * Not actually used anymore, but left because some gdb
8146 * versions need it.
8147 */
8148 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8149 + put_user_ex(*((const u64 *)&code), (u64 *)frame->retcode);
8150 } put_user_catch(err);
8151
8152 if (err)
8153 diff -urNp linux-2.6.39/arch/x86/include/asm/alternative.h linux-2.6.39/arch/x86/include/asm/alternative.h
8154 --- linux-2.6.39/arch/x86/include/asm/alternative.h 2011-05-19 00:06:34.000000000 -0400
8155 +++ linux-2.6.39/arch/x86/include/asm/alternative.h 2011-05-22 19:36:30.000000000 -0400
8156 @@ -94,7 +94,7 @@ static inline int alternatives_text_rese
8157 ".section .discard,\"aw\",@progbits\n" \
8158 " .byte 0xff + (664f-663f) - (662b-661b)\n" /* rlen <= slen */ \
8159 ".previous\n" \
8160 - ".section .altinstr_replacement, \"ax\"\n" \
8161 + ".section .altinstr_replacement, \"a\"\n" \
8162 "663:\n\t" newinstr "\n664:\n" /* replacement */ \
8163 ".previous"
8164
8165 diff -urNp linux-2.6.39/arch/x86/include/asm/apm.h linux-2.6.39/arch/x86/include/asm/apm.h
8166 --- linux-2.6.39/arch/x86/include/asm/apm.h 2011-05-19 00:06:34.000000000 -0400
8167 +++ linux-2.6.39/arch/x86/include/asm/apm.h 2011-05-22 19:36:30.000000000 -0400
8168 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32
8169 __asm__ __volatile__(APM_DO_ZERO_SEGS
8170 "pushl %%edi\n\t"
8171 "pushl %%ebp\n\t"
8172 - "lcall *%%cs:apm_bios_entry\n\t"
8173 + "lcall *%%ss:apm_bios_entry\n\t"
8174 "setc %%al\n\t"
8175 "popl %%ebp\n\t"
8176 "popl %%edi\n\t"
8177 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_as
8178 __asm__ __volatile__(APM_DO_ZERO_SEGS
8179 "pushl %%edi\n\t"
8180 "pushl %%ebp\n\t"
8181 - "lcall *%%cs:apm_bios_entry\n\t"
8182 + "lcall *%%ss:apm_bios_entry\n\t"
8183 "setc %%bl\n\t"
8184 "popl %%ebp\n\t"
8185 "popl %%edi\n\t"
8186 diff -urNp linux-2.6.39/arch/x86/include/asm/atomic64_32.h linux-2.6.39/arch/x86/include/asm/atomic64_32.h
8187 --- linux-2.6.39/arch/x86/include/asm/atomic64_32.h 2011-05-19 00:06:34.000000000 -0400
8188 +++ linux-2.6.39/arch/x86/include/asm/atomic64_32.h 2011-05-22 19:36:30.000000000 -0400
8189 @@ -12,6 +12,14 @@ typedef struct {
8190 u64 __aligned(8) counter;
8191 } atomic64_t;
8192
8193 +#ifdef CONFIG_PAX_REFCOUNT
8194 +typedef struct {
8195 + u64 __aligned(8) counter;
8196 +} atomic64_unchecked_t;
8197 +#else
8198 +typedef atomic64_t atomic64_unchecked_t;
8199 +#endif
8200 +
8201 #define ATOMIC64_INIT(val) { (val) }
8202
8203 #ifdef CONFIG_X86_CMPXCHG64
8204 @@ -38,6 +46,21 @@ static inline long long atomic64_cmpxchg
8205 }
8206
8207 /**
8208 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
8209 + * @p: pointer to type atomic64_unchecked_t
8210 + * @o: expected value
8211 + * @n: new value
8212 + *
8213 + * Atomically sets @v to @n if it was equal to @o and returns
8214 + * the old value.
8215 + */
8216 +
8217 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
8218 +{
8219 + return cmpxchg64(&v->counter, o, n);
8220 +}
8221 +
8222 +/**
8223 * atomic64_xchg - xchg atomic64 variable
8224 * @v: pointer to type atomic64_t
8225 * @n: value to assign
8226 @@ -77,6 +100,24 @@ static inline void atomic64_set(atomic64
8227 }
8228
8229 /**
8230 + * atomic64_set_unchecked - set atomic64 variable
8231 + * @v: pointer to type atomic64_unchecked_t
8232 + * @n: value to assign
8233 + *
8234 + * Atomically sets the value of @v to @n.
8235 + */
8236 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
8237 +{
8238 + unsigned high = (unsigned)(i >> 32);
8239 + unsigned low = (unsigned)i;
8240 + asm volatile(ATOMIC64_ALTERNATIVE(set)
8241 + : "+b" (low), "+c" (high)
8242 + : "S" (v)
8243 + : "eax", "edx", "memory"
8244 + );
8245 +}
8246 +
8247 +/**
8248 * atomic64_read - read atomic64 variable
8249 * @v: pointer to type atomic64_t
8250 *
8251 @@ -93,6 +134,22 @@ static inline long long atomic64_read(at
8252 }
8253
8254 /**
8255 + * atomic64_read_unchecked - read atomic64 variable
8256 + * @v: pointer to type atomic64_unchecked_t
8257 + *
8258 + * Atomically reads the value of @v and returns it.
8259 + */
8260 +static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
8261 +{
8262 + long long r;
8263 + asm volatile(ATOMIC64_ALTERNATIVE(read_unchecked)
8264 + : "=A" (r), "+c" (v)
8265 + : : "memory"
8266 + );
8267 + return r;
8268 + }
8269 +
8270 +/**
8271 * atomic64_add_return - add and return
8272 * @i: integer value to add
8273 * @v: pointer to type atomic64_t
8274 @@ -108,6 +165,22 @@ static inline long long atomic64_add_ret
8275 return i;
8276 }
8277
8278 +/**
8279 + * atomic64_add_return_unchecked - add and return
8280 + * @i: integer value to add
8281 + * @v: pointer to type atomic64_unchecked_t
8282 + *
8283 + * Atomically adds @i to @v and returns @i + *@v
8284 + */
8285 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
8286 +{
8287 + asm volatile(ATOMIC64_ALTERNATIVE(add_return_unchecked)
8288 + : "+A" (i), "+c" (v)
8289 + : : "memory"
8290 + );
8291 + return i;
8292 +}
8293 +
8294 /*
8295 * Other variants with different arithmetic operators:
8296 */
8297 @@ -131,6 +204,17 @@ static inline long long atomic64_inc_ret
8298 return a;
8299 }
8300
8301 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
8302 +{
8303 + long long a;
8304 + asm volatile(ATOMIC64_ALTERNATIVE(inc_return_unchecked)
8305 + : "=A" (a)
8306 + : "S" (v)
8307 + : "memory", "ecx"
8308 + );
8309 + return a;
8310 +}
8311 +
8312 static inline long long atomic64_dec_return(atomic64_t *v)
8313 {
8314 long long a;
8315 @@ -159,6 +243,22 @@ static inline long long atomic64_add(lon
8316 }
8317
8318 /**
8319 + * atomic64_add_unchecked - add integer to atomic64 variable
8320 + * @i: integer value to add
8321 + * @v: pointer to type atomic64_unchecked_t
8322 + *
8323 + * Atomically adds @i to @v.
8324 + */
8325 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
8326 +{
8327 + asm volatile(ATOMIC64_ALTERNATIVE_(add_unchecked, add_return_unchecked)
8328 + : "+A" (i), "+c" (v)
8329 + : : "memory"
8330 + );
8331 + return i;
8332 +}
8333 +
8334 +/**
8335 * atomic64_sub - subtract the atomic64 variable
8336 * @i: integer value to subtract
8337 * @v: pointer to type atomic64_t
8338 diff -urNp linux-2.6.39/arch/x86/include/asm/atomic64_64.h linux-2.6.39/arch/x86/include/asm/atomic64_64.h
8339 --- linux-2.6.39/arch/x86/include/asm/atomic64_64.h 2011-05-19 00:06:34.000000000 -0400
8340 +++ linux-2.6.39/arch/x86/include/asm/atomic64_64.h 2011-05-22 19:36:30.000000000 -0400
8341 @@ -18,7 +18,19 @@
8342 */
8343 static inline long atomic64_read(const atomic64_t *v)
8344 {
8345 - return (*(volatile long *)&(v)->counter);
8346 + return (*(volatile const long *)&(v)->counter);
8347 +}
8348 +
8349 +/**
8350 + * atomic64_read_unchecked - read atomic64 variable
8351 + * @v: pointer of type atomic64_unchecked_t
8352 + *
8353 + * Atomically reads the value of @v.
8354 + * Doesn't imply a read memory barrier.
8355 + */
8356 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
8357 +{
8358 + return (*(volatile const long *)&(v)->counter);
8359 }
8360
8361 /**
8362 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64
8363 }
8364
8365 /**
8366 + * atomic64_set_unchecked - set atomic64 variable
8367 + * @v: pointer to type atomic64_unchecked_t
8368 + * @i: required value
8369 + *
8370 + * Atomically sets the value of @v to @i.
8371 + */
8372 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
8373 +{
8374 + v->counter = i;
8375 +}
8376 +
8377 +/**
8378 * atomic64_add - add integer to atomic64 variable
8379 * @i: integer value to add
8380 * @v: pointer to type atomic64_t
8381 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64
8382 */
8383 static inline void atomic64_add(long i, atomic64_t *v)
8384 {
8385 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
8386 +
8387 +#ifdef CONFIG_PAX_REFCOUNT
8388 + "jno 0f\n"
8389 + LOCK_PREFIX "subq %1,%0\n"
8390 + "int $4\n0:\n"
8391 + _ASM_EXTABLE(0b, 0b)
8392 +#endif
8393 +
8394 + : "=m" (v->counter)
8395 + : "er" (i), "m" (v->counter));
8396 +}
8397 +
8398 +/**
8399 + * atomic64_add_unchecked - add integer to atomic64 variable
8400 + * @i: integer value to add
8401 + * @v: pointer to type atomic64_unchecked_t
8402 + *
8403 + * Atomically adds @i to @v.
8404 + */
8405 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
8406 +{
8407 asm volatile(LOCK_PREFIX "addq %1,%0"
8408 : "=m" (v->counter)
8409 : "er" (i), "m" (v->counter));
8410 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i,
8411 */
8412 static inline void atomic64_sub(long i, atomic64_t *v)
8413 {
8414 - asm volatile(LOCK_PREFIX "subq %1,%0"
8415 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
8416 +
8417 +#ifdef CONFIG_PAX_REFCOUNT
8418 + "jno 0f\n"
8419 + LOCK_PREFIX "addq %1,%0\n"
8420 + "int $4\n0:\n"
8421 + _ASM_EXTABLE(0b, 0b)
8422 +#endif
8423 +
8424 + : "=m" (v->counter)
8425 + : "er" (i), "m" (v->counter));
8426 +}
8427 +
8428 +/**
8429 + * atomic64_sub_unchecked - subtract the atomic64 variable
8430 + * @i: integer value to subtract
8431 + * @v: pointer to type atomic64_unchecked_t
8432 + *
8433 + * Atomically subtracts @i from @v.
8434 + */
8435 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
8436 +{
8437 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
8438 : "=m" (v->counter)
8439 : "er" (i), "m" (v->counter));
8440 }
8441 @@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(
8442 {
8443 unsigned char c;
8444
8445 - asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
8446 + asm volatile(LOCK_PREFIX "subq %2,%0\n"
8447 +
8448 +#ifdef CONFIG_PAX_REFCOUNT
8449 + "jno 0f\n"
8450 + LOCK_PREFIX "addq %2,%0\n"
8451 + "int $4\n0:\n"
8452 + _ASM_EXTABLE(0b, 0b)
8453 +#endif
8454 +
8455 + "sete %1\n"
8456 : "=m" (v->counter), "=qm" (c)
8457 : "er" (i), "m" (v->counter) : "memory");
8458 return c;
8459 @@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(
8460 */
8461 static inline void atomic64_inc(atomic64_t *v)
8462 {
8463 + asm volatile(LOCK_PREFIX "incq %0\n"
8464 +
8465 +#ifdef CONFIG_PAX_REFCOUNT
8466 + "jno 0f\n"
8467 + LOCK_PREFIX "decq %0\n"
8468 + "int $4\n0:\n"
8469 + _ASM_EXTABLE(0b, 0b)
8470 +#endif
8471 +
8472 + : "=m" (v->counter)
8473 + : "m" (v->counter));
8474 +}
8475 +
8476 +/**
8477 + * atomic64_inc_unchecked - increment atomic64 variable
8478 + * @v: pointer to type atomic64_unchecked_t
8479 + *
8480 + * Atomically increments @v by 1.
8481 + */
8482 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
8483 +{
8484 asm volatile(LOCK_PREFIX "incq %0"
8485 : "=m" (v->counter)
8486 : "m" (v->counter));
8487 @@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64
8488 */
8489 static inline void atomic64_dec(atomic64_t *v)
8490 {
8491 - asm volatile(LOCK_PREFIX "decq %0"
8492 + asm volatile(LOCK_PREFIX "decq %0\n"
8493 +
8494 +#ifdef CONFIG_PAX_REFCOUNT
8495 + "jno 0f\n"
8496 + LOCK_PREFIX "incq %0\n"
8497 + "int $4\n0:\n"
8498 + _ASM_EXTABLE(0b, 0b)
8499 +#endif
8500 +
8501 + : "=m" (v->counter)
8502 + : "m" (v->counter));
8503 +}
8504 +
8505 +/**
8506 + * atomic64_dec_unchecked - decrement atomic64 variable
8507 + * @v: pointer to type atomic64_t
8508 + *
8509 + * Atomically decrements @v by 1.
8510 + */
8511 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
8512 +{
8513 + asm volatile(LOCK_PREFIX "decq %0\n"
8514 : "=m" (v->counter)
8515 : "m" (v->counter));
8516 }
8517 @@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(
8518 {
8519 unsigned char c;
8520
8521 - asm volatile(LOCK_PREFIX "decq %0; sete %1"
8522 + asm volatile(LOCK_PREFIX "decq %0\n"
8523 +
8524 +#ifdef CONFIG_PAX_REFCOUNT
8525 + "jno 0f\n"
8526 + LOCK_PREFIX "incq %0\n"
8527 + "int $4\n0:\n"
8528 + _ASM_EXTABLE(0b, 0b)
8529 +#endif
8530 +
8531 + "sete %1\n"
8532 : "=m" (v->counter), "=qm" (c)
8533 : "m" (v->counter) : "memory");
8534 return c != 0;
8535 @@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(
8536 {
8537 unsigned char c;
8538
8539 - asm volatile(LOCK_PREFIX "incq %0; sete %1"
8540 + asm volatile(LOCK_PREFIX "incq %0\n"
8541 +
8542 +#ifdef CONFIG_PAX_REFCOUNT
8543 + "jno 0f\n"
8544 + LOCK_PREFIX "decq %0\n"
8545 + "int $4\n0:\n"
8546 + _ASM_EXTABLE(0b, 0b)
8547 +#endif
8548 +
8549 + "sete %1\n"
8550 : "=m" (v->counter), "=qm" (c)
8551 : "m" (v->counter) : "memory");
8552 return c != 0;
8553 @@ -155,7 +292,16 @@ static inline int atomic64_add_negative(
8554 {
8555 unsigned char c;
8556
8557 - asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
8558 + asm volatile(LOCK_PREFIX "addq %2,%0\n"
8559 +
8560 +#ifdef CONFIG_PAX_REFCOUNT
8561 + "jno 0f\n"
8562 + LOCK_PREFIX "subq %2,%0\n"
8563 + "int $4\n0:\n"
8564 + _ASM_EXTABLE(0b, 0b)
8565 +#endif
8566 +
8567 + "sets %1\n"
8568 : "=m" (v->counter), "=qm" (c)
8569 : "er" (i), "m" (v->counter) : "memory");
8570 return c;
8571 @@ -171,7 +317,31 @@ static inline int atomic64_add_negative(
8572 static inline long atomic64_add_return(long i, atomic64_t *v)
8573 {
8574 long __i = i;
8575 - asm volatile(LOCK_PREFIX "xaddq %0, %1;"
8576 + asm volatile(LOCK_PREFIX "xaddq %0, %1\n"
8577 +
8578 +#ifdef CONFIG_PAX_REFCOUNT
8579 + "jno 0f\n"
8580 + "movq %0, %1\n"
8581 + "int $4\n0:\n"
8582 + _ASM_EXTABLE(0b, 0b)
8583 +#endif
8584 +
8585 + : "+r" (i), "+m" (v->counter)
8586 + : : "memory");
8587 + return i + __i;
8588 +}
8589 +
8590 +/**
8591 + * atomic64_add_return_unchecked - add and return
8592 + * @i: integer value to add
8593 + * @v: pointer to type atomic64_unchecked_t
8594 + *
8595 + * Atomically adds @i to @v and returns @i + @v
8596 + */
8597 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
8598 +{
8599 + long __i = i;
8600 + asm volatile(LOCK_PREFIX "xaddq %0, %1"
8601 : "+r" (i), "+m" (v->counter)
8602 : : "memory");
8603 return i + __i;
8604 @@ -183,6 +353,10 @@ static inline long atomic64_sub_return(l
8605 }
8606
8607 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
8608 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
8609 +{
8610 + return atomic64_add_return_unchecked(1, v);
8611 +}
8612 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
8613
8614 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
8615 @@ -190,6 +364,11 @@ static inline long atomic64_cmpxchg(atom
8616 return cmpxchg(&v->counter, old, new);
8617 }
8618
8619 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
8620 +{
8621 + return cmpxchg(&v->counter, old, new);
8622 +}
8623 +
8624 static inline long atomic64_xchg(atomic64_t *v, long new)
8625 {
8626 return xchg(&v->counter, new);
8627 @@ -206,17 +385,30 @@ static inline long atomic64_xchg(atomic6
8628 */
8629 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
8630 {
8631 - long c, old;
8632 + long c, old, new;
8633 c = atomic64_read(v);
8634 for (;;) {
8635 - if (unlikely(c == (u)))
8636 + if (unlikely(c == u))
8637 break;
8638 - old = atomic64_cmpxchg((v), c, c + (a));
8639 +
8640 + asm volatile("add %2,%0\n"
8641 +
8642 +#ifdef CONFIG_PAX_REFCOUNT
8643 + "jno 0f\n"
8644 + "sub %2,%0\n"
8645 + "int $4\n0:\n"
8646 + _ASM_EXTABLE(0b, 0b)
8647 +#endif
8648 +
8649 + : "=r" (new)
8650 + : "0" (c), "ir" (a));
8651 +
8652 + old = atomic64_cmpxchg(v, c, new);
8653 if (likely(old == c))
8654 break;
8655 c = old;
8656 }
8657 - return c != (u);
8658 + return c != u;
8659 }
8660
8661 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
8662 diff -urNp linux-2.6.39/arch/x86/include/asm/atomic.h linux-2.6.39/arch/x86/include/asm/atomic.h
8663 --- linux-2.6.39/arch/x86/include/asm/atomic.h 2011-05-19 00:06:34.000000000 -0400
8664 +++ linux-2.6.39/arch/x86/include/asm/atomic.h 2011-05-22 19:36:30.000000000 -0400
8665 @@ -22,7 +22,18 @@
8666 */
8667 static inline int atomic_read(const atomic_t *v)
8668 {
8669 - return (*(volatile int *)&(v)->counter);
8670 + return (*(volatile const int *)&(v)->counter);
8671 +}
8672 +
8673 +/**
8674 + * atomic_read_unchecked - read atomic variable
8675 + * @v: pointer of type atomic_unchecked_t
8676 + *
8677 + * Atomically reads the value of @v.
8678 + */
8679 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
8680 +{
8681 + return (*(volatile const int *)&(v)->counter);
8682 }
8683
8684 /**
8685 @@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *
8686 }
8687
8688 /**
8689 + * atomic_set_unchecked - set atomic variable
8690 + * @v: pointer of type atomic_unchecked_t
8691 + * @i: required value
8692 + *
8693 + * Atomically sets the value of @v to @i.
8694 + */
8695 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
8696 +{
8697 + v->counter = i;
8698 +}
8699 +
8700 +/**
8701 * atomic_add - add integer to atomic variable
8702 * @i: integer value to add
8703 * @v: pointer of type atomic_t
8704 @@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *
8705 */
8706 static inline void atomic_add(int i, atomic_t *v)
8707 {
8708 - asm volatile(LOCK_PREFIX "addl %1,%0"
8709 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
8710 +
8711 +#ifdef CONFIG_PAX_REFCOUNT
8712 + "jno 0f\n"
8713 + LOCK_PREFIX "subl %1,%0\n"
8714 + "int $4\n0:\n"
8715 + _ASM_EXTABLE(0b, 0b)
8716 +#endif
8717 +
8718 + : "+m" (v->counter)
8719 + : "ir" (i));
8720 +}
8721 +
8722 +/**
8723 + * atomic_add_unchecked - add integer to atomic variable
8724 + * @i: integer value to add
8725 + * @v: pointer of type atomic_unchecked_t
8726 + *
8727 + * Atomically adds @i to @v.
8728 + */
8729 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
8730 +{
8731 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
8732 : "+m" (v->counter)
8733 : "ir" (i));
8734 }
8735 @@ -60,7 +105,29 @@ static inline void atomic_add(int i, ato
8736 */
8737 static inline void atomic_sub(int i, atomic_t *v)
8738 {
8739 - asm volatile(LOCK_PREFIX "subl %1,%0"
8740 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
8741 +
8742 +#ifdef CONFIG_PAX_REFCOUNT
8743 + "jno 0f\n"
8744 + LOCK_PREFIX "addl %1,%0\n"
8745 + "int $4\n0:\n"
8746 + _ASM_EXTABLE(0b, 0b)
8747 +#endif
8748 +
8749 + : "+m" (v->counter)
8750 + : "ir" (i));
8751 +}
8752 +
8753 +/**
8754 + * atomic_sub_unchecked - subtract integer from atomic variable
8755 + * @i: integer value to subtract
8756 + * @v: pointer of type atomic_unchecked_t
8757 + *
8758 + * Atomically subtracts @i from @v.
8759 + */
8760 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
8761 +{
8762 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
8763 : "+m" (v->counter)
8764 : "ir" (i));
8765 }
8766 @@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(in
8767 {
8768 unsigned char c;
8769
8770 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
8771 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
8772 +
8773 +#ifdef CONFIG_PAX_REFCOUNT
8774 + "jno 0f\n"
8775 + LOCK_PREFIX "addl %2,%0\n"
8776 + "int $4\n0:\n"
8777 + _ASM_EXTABLE(0b, 0b)
8778 +#endif
8779 +
8780 + "sete %1\n"
8781 : "+m" (v->counter), "=qm" (c)
8782 : "ir" (i) : "memory");
8783 return c;
8784 @@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(in
8785 */
8786 static inline void atomic_inc(atomic_t *v)
8787 {
8788 - asm volatile(LOCK_PREFIX "incl %0"
8789 + asm volatile(LOCK_PREFIX "incl %0\n"
8790 +
8791 +#ifdef CONFIG_PAX_REFCOUNT
8792 + "jno 0f\n"
8793 + LOCK_PREFIX "decl %0\n"
8794 + "int $4\n0:\n"
8795 + _ASM_EXTABLE(0b, 0b)
8796 +#endif
8797 +
8798 + : "+m" (v->counter));
8799 +}
8800 +
8801 +/**
8802 + * atomic_inc_unchecked - increment atomic variable
8803 + * @v: pointer of type atomic_unchecked_t
8804 + *
8805 + * Atomically increments @v by 1.
8806 + */
8807 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
8808 +{
8809 + asm volatile(LOCK_PREFIX "incl %0\n"
8810 : "+m" (v->counter));
8811 }
8812
8813 @@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *
8814 */
8815 static inline void atomic_dec(atomic_t *v)
8816 {
8817 - asm volatile(LOCK_PREFIX "decl %0"
8818 + asm volatile(LOCK_PREFIX "decl %0\n"
8819 +
8820 +#ifdef CONFIG_PAX_REFCOUNT
8821 + "jno 0f\n"
8822 + LOCK_PREFIX "incl %0\n"
8823 + "int $4\n0:\n"
8824 + _ASM_EXTABLE(0b, 0b)
8825 +#endif
8826 +
8827 + : "+m" (v->counter));
8828 +}
8829 +
8830 +/**
8831 + * atomic_dec_unchecked - decrement atomic variable
8832 + * @v: pointer of type atomic_unchecked_t
8833 + *
8834 + * Atomically decrements @v by 1.
8835 + */
8836 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
8837 +{
8838 + asm volatile(LOCK_PREFIX "decl %0\n"
8839 : "+m" (v->counter));
8840 }
8841
8842 @@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(at
8843 {
8844 unsigned char c;
8845
8846 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
8847 + asm volatile(LOCK_PREFIX "decl %0\n"
8848 +
8849 +#ifdef CONFIG_PAX_REFCOUNT
8850 + "jno 0f\n"
8851 + LOCK_PREFIX "incl %0\n"
8852 + "int $4\n0:\n"
8853 + _ASM_EXTABLE(0b, 0b)
8854 +#endif
8855 +
8856 + "sete %1\n"
8857 : "+m" (v->counter), "=qm" (c)
8858 : : "memory");
8859 return c != 0;
8860 @@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(at
8861 {
8862 unsigned char c;
8863
8864 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
8865 + asm volatile(LOCK_PREFIX "incl %0\n"
8866 +
8867 +#ifdef CONFIG_PAX_REFCOUNT
8868 + "jno 0f\n"
8869 + LOCK_PREFIX "decl %0\n"
8870 + "int $4\n0:\n"
8871 + _ASM_EXTABLE(0b, 0b)
8872 +#endif
8873 +
8874 + "sete %1\n"
8875 + : "+m" (v->counter), "=qm" (c)
8876 + : : "memory");
8877 + return c != 0;
8878 +}
8879 +
8880 +/**
8881 + * atomic_inc_and_test_unchecked - increment and test
8882 + * @v: pointer of type atomic_unchecked_t
8883 + *
8884 + * Atomically increments @v by 1
8885 + * and returns true if the result is zero, or false for all
8886 + * other cases.
8887 + */
8888 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
8889 +{
8890 + unsigned char c;
8891 +
8892 + asm volatile(LOCK_PREFIX "incl %0\n"
8893 + "sete %1\n"
8894 : "+m" (v->counter), "=qm" (c)
8895 : : "memory");
8896 return c != 0;
8897 @@ -157,7 +310,16 @@ static inline int atomic_add_negative(in
8898 {
8899 unsigned char c;
8900
8901 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
8902 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
8903 +
8904 +#ifdef CONFIG_PAX_REFCOUNT
8905 + "jno 0f\n"
8906 + LOCK_PREFIX "subl %2,%0\n"
8907 + "int $4\n0:\n"
8908 + _ASM_EXTABLE(0b, 0b)
8909 +#endif
8910 +
8911 + "sets %1\n"
8912 : "+m" (v->counter), "=qm" (c)
8913 : "ir" (i) : "memory");
8914 return c;
8915 @@ -180,6 +342,46 @@ static inline int atomic_add_return(int
8916 #endif
8917 /* Modern 486+ processor */
8918 __i = i;
8919 + asm volatile(LOCK_PREFIX "xaddl %0, %1\n"
8920 +
8921 +#ifdef CONFIG_PAX_REFCOUNT
8922 + "jno 0f\n"
8923 + "movl %0, %1\n"
8924 + "int $4\n0:\n"
8925 + _ASM_EXTABLE(0b, 0b)
8926 +#endif
8927 +
8928 + : "+r" (i), "+m" (v->counter)
8929 + : : "memory");
8930 + return i + __i;
8931 +
8932 +#ifdef CONFIG_M386
8933 +no_xadd: /* Legacy 386 processor */
8934 + local_irq_save(flags);
8935 + __i = atomic_read(v);
8936 + atomic_set(v, i + __i);
8937 + local_irq_restore(flags);
8938 + return i + __i;
8939 +#endif
8940 +}
8941 +
8942 +/**
8943 + * atomic_add_return_unchecked - add integer and return
8944 + * @v: pointer of type atomic_unchecked_t
8945 + * @i: integer value to add
8946 + *
8947 + * Atomically adds @i to @v and returns @i + @v
8948 + */
8949 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
8950 +{
8951 + int __i;
8952 +#ifdef CONFIG_M386
8953 + unsigned long flags;
8954 + if (unlikely(boot_cpu_data.x86 <= 3))
8955 + goto no_xadd;
8956 +#endif
8957 + /* Modern 486+ processor */
8958 + __i = i;
8959 asm volatile(LOCK_PREFIX "xaddl %0, %1"
8960 : "+r" (i), "+m" (v->counter)
8961 : : "memory");
8962 @@ -208,6 +410,10 @@ static inline int atomic_sub_return(int
8963 }
8964
8965 #define atomic_inc_return(v) (atomic_add_return(1, v))
8966 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
8967 +{
8968 + return atomic_add_return_unchecked(1, v);
8969 +}
8970 #define atomic_dec_return(v) (atomic_sub_return(1, v))
8971
8972 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
8973 @@ -215,11 +421,21 @@ static inline int atomic_cmpxchg(atomic_
8974 return cmpxchg(&v->counter, old, new);
8975 }
8976
8977 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
8978 +{
8979 + return cmpxchg(&v->counter, old, new);
8980 +}
8981 +
8982 static inline int atomic_xchg(atomic_t *v, int new)
8983 {
8984 return xchg(&v->counter, new);
8985 }
8986
8987 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
8988 +{
8989 + return xchg(&v->counter, new);
8990 +}
8991 +
8992 /**
8993 * atomic_add_unless - add unless the number is already a given value
8994 * @v: pointer of type atomic_t
8995 @@ -231,21 +447,77 @@ static inline int atomic_xchg(atomic_t *
8996 */
8997 static inline int atomic_add_unless(atomic_t *v, int a, int u)
8998 {
8999 - int c, old;
9000 + int c, old, new;
9001 c = atomic_read(v);
9002 for (;;) {
9003 - if (unlikely(c == (u)))
9004 + if (unlikely(c == u))
9005 break;
9006 - old = atomic_cmpxchg((v), c, c + (a));
9007 +
9008 + asm volatile("addl %2,%0\n"
9009 +
9010 +#ifdef CONFIG_PAX_REFCOUNT
9011 + "jno 0f\n"
9012 + "subl %2,%0\n"
9013 + "int $4\n0:\n"
9014 + _ASM_EXTABLE(0b, 0b)
9015 +#endif
9016 +
9017 + : "=r" (new)
9018 + : "0" (c), "ir" (a));
9019 +
9020 + old = atomic_cmpxchg(v, c, new);
9021 if (likely(old == c))
9022 break;
9023 c = old;
9024 }
9025 - return c != (u);
9026 + return c != u;
9027 }
9028
9029 #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
9030
9031 +/**
9032 + * atomic_inc_not_zero_hint - increment if not null
9033 + * @v: pointer of type atomic_t
9034 + * @hint: probable value of the atomic before the increment
9035 + *
9036 + * This version of atomic_inc_not_zero() gives a hint of probable
9037 + * value of the atomic. This helps processor to not read the memory
9038 + * before doing the atomic read/modify/write cycle, lowering
9039 + * number of bus transactions on some arches.
9040 + *
9041 + * Returns: 0 if increment was not done, 1 otherwise.
9042 + */
9043 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
9044 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
9045 +{
9046 + int val, c = hint, new;
9047 +
9048 + /* sanity test, should be removed by compiler if hint is a constant */
9049 + if (!hint)
9050 + return atomic_inc_not_zero(v);
9051 +
9052 + do {
9053 + asm volatile("incl %0\n"
9054 +
9055 +#ifdef CONFIG_PAX_REFCOUNT
9056 + "jno 0f\n"
9057 + "decl %0\n"
9058 + "int $4\n0:\n"
9059 + _ASM_EXTABLE(0b, 0b)
9060 +#endif
9061 +
9062 + : "=r" (new)
9063 + : "0" (c));
9064 +
9065 + val = atomic_cmpxchg(v, c, new);
9066 + if (val == c)
9067 + return 1;
9068 + c = val;
9069 + } while (c);
9070 +
9071 + return 0;
9072 +}
9073 +
9074 /*
9075 * atomic_dec_if_positive - decrement by 1 if old value positive
9076 * @v: pointer of type atomic_t
9077 diff -urNp linux-2.6.39/arch/x86/include/asm/bitops.h linux-2.6.39/arch/x86/include/asm/bitops.h
9078 --- linux-2.6.39/arch/x86/include/asm/bitops.h 2011-05-19 00:06:34.000000000 -0400
9079 +++ linux-2.6.39/arch/x86/include/asm/bitops.h 2011-05-22 19:36:30.000000000 -0400
9080 @@ -38,7 +38,7 @@
9081 * a mask operation on a byte.
9082 */
9083 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
9084 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
9085 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
9086 #define CONST_MASK(nr) (1 << ((nr) & 7))
9087
9088 /**
9089 diff -urNp linux-2.6.39/arch/x86/include/asm/boot.h linux-2.6.39/arch/x86/include/asm/boot.h
9090 --- linux-2.6.39/arch/x86/include/asm/boot.h 2011-05-19 00:06:34.000000000 -0400
9091 +++ linux-2.6.39/arch/x86/include/asm/boot.h 2011-05-22 19:36:30.000000000 -0400
9092 @@ -11,10 +11,15 @@
9093 #include <asm/pgtable_types.h>
9094
9095 /* Physical address where kernel should be loaded. */
9096 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
9097 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
9098 + (CONFIG_PHYSICAL_ALIGN - 1)) \
9099 & ~(CONFIG_PHYSICAL_ALIGN - 1))
9100
9101 +#ifndef __ASSEMBLY__
9102 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
9103 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
9104 +#endif
9105 +
9106 /* Minimum kernel alignment, as a power of two */
9107 #ifdef CONFIG_X86_64
9108 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
9109 diff -urNp linux-2.6.39/arch/x86/include/asm/cacheflush.h linux-2.6.39/arch/x86/include/asm/cacheflush.h
9110 --- linux-2.6.39/arch/x86/include/asm/cacheflush.h 2011-05-19 00:06:34.000000000 -0400
9111 +++ linux-2.6.39/arch/x86/include/asm/cacheflush.h 2011-05-22 19:36:30.000000000 -0400
9112 @@ -26,7 +26,7 @@ static inline unsigned long get_page_mem
9113 unsigned long pg_flags = pg->flags & _PGMT_MASK;
9114
9115 if (pg_flags == _PGMT_DEFAULT)
9116 - return -1;
9117 + return ~0UL;
9118 else if (pg_flags == _PGMT_WC)
9119 return _PAGE_CACHE_WC;
9120 else if (pg_flags == _PGMT_UC_MINUS)
9121 diff -urNp linux-2.6.39/arch/x86/include/asm/cache.h linux-2.6.39/arch/x86/include/asm/cache.h
9122 --- linux-2.6.39/arch/x86/include/asm/cache.h 2011-05-19 00:06:34.000000000 -0400
9123 +++ linux-2.6.39/arch/x86/include/asm/cache.h 2011-05-22 19:36:30.000000000 -0400
9124 @@ -5,12 +5,13 @@
9125
9126 /* L1 cache line size */
9127 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
9128 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9129 +#define L1_CACHE_BYTES (_AC(1,U) << L1_CACHE_SHIFT)
9130
9131 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9132 +#define __read_only __attribute__((__section__(".data..read_only")))
9133
9134 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
9135 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
9136 +#define INTERNODE_CACHE_BYTES (_AC(1,U) << INTERNODE_CACHE_SHIFT)
9137
9138 #ifdef CONFIG_X86_VSMP
9139 #ifdef CONFIG_SMP
9140 diff -urNp linux-2.6.39/arch/x86/include/asm/checksum_32.h linux-2.6.39/arch/x86/include/asm/checksum_32.h
9141 --- linux-2.6.39/arch/x86/include/asm/checksum_32.h 2011-05-19 00:06:34.000000000 -0400
9142 +++ linux-2.6.39/arch/x86/include/asm/checksum_32.h 2011-05-22 19:36:30.000000000 -0400
9143 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_gene
9144 int len, __wsum sum,
9145 int *src_err_ptr, int *dst_err_ptr);
9146
9147 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
9148 + int len, __wsum sum,
9149 + int *src_err_ptr, int *dst_err_ptr);
9150 +
9151 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
9152 + int len, __wsum sum,
9153 + int *src_err_ptr, int *dst_err_ptr);
9154 +
9155 /*
9156 * Note: when you get a NULL pointer exception here this means someone
9157 * passed in an incorrect kernel address to one of these functions.
9158 @@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_f
9159 int *err_ptr)
9160 {
9161 might_sleep();
9162 - return csum_partial_copy_generic((__force void *)src, dst,
9163 + return csum_partial_copy_generic_from_user((__force void *)src, dst,
9164 len, sum, err_ptr, NULL);
9165 }
9166
9167 @@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_us
9168 {
9169 might_sleep();
9170 if (access_ok(VERIFY_WRITE, dst, len))
9171 - return csum_partial_copy_generic(src, (__force void *)dst,
9172 + return csum_partial_copy_generic_to_user(src, (__force void *)dst,
9173 len, sum, NULL, err_ptr);
9174
9175 if (len)
9176 diff -urNp linux-2.6.39/arch/x86/include/asm/cpufeature.h linux-2.6.39/arch/x86/include/asm/cpufeature.h
9177 --- linux-2.6.39/arch/x86/include/asm/cpufeature.h 2011-05-19 00:06:34.000000000 -0400
9178 +++ linux-2.6.39/arch/x86/include/asm/cpufeature.h 2011-05-22 19:36:30.000000000 -0400
9179 @@ -351,7 +351,7 @@ static __always_inline __pure bool __sta
9180 ".section .discard,\"aw\",@progbits\n"
9181 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
9182 ".previous\n"
9183 - ".section .altinstr_replacement,\"ax\"\n"
9184 + ".section .altinstr_replacement,\"a\"\n"
9185 "3: movb $1,%0\n"
9186 "4:\n"
9187 ".previous\n"
9188 diff -urNp linux-2.6.39/arch/x86/include/asm/desc_defs.h linux-2.6.39/arch/x86/include/asm/desc_defs.h
9189 --- linux-2.6.39/arch/x86/include/asm/desc_defs.h 2011-05-19 00:06:34.000000000 -0400
9190 +++ linux-2.6.39/arch/x86/include/asm/desc_defs.h 2011-05-22 19:36:30.000000000 -0400
9191 @@ -31,6 +31,12 @@ struct desc_struct {
9192 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
9193 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
9194 };
9195 + struct {
9196 + u16 offset_low;
9197 + u16 seg;
9198 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
9199 + unsigned offset_high: 16;
9200 + } gate;
9201 };
9202 } __attribute__((packed));
9203
9204 diff -urNp linux-2.6.39/arch/x86/include/asm/desc.h linux-2.6.39/arch/x86/include/asm/desc.h
9205 --- linux-2.6.39/arch/x86/include/asm/desc.h 2011-05-19 00:06:34.000000000 -0400
9206 +++ linux-2.6.39/arch/x86/include/asm/desc.h 2011-05-22 19:36:30.000000000 -0400
9207 @@ -4,6 +4,7 @@
9208 #include <asm/desc_defs.h>
9209 #include <asm/ldt.h>
9210 #include <asm/mmu.h>
9211 +#include <asm/pgtable.h>
9212 #include <linux/smp.h>
9213
9214 static inline void fill_ldt(struct desc_struct *desc,
9215 @@ -15,6 +16,7 @@ static inline void fill_ldt(struct desc_
9216 desc->base1 = (info->base_addr & 0x00ff0000) >> 16;
9217 desc->type = (info->read_exec_only ^ 1) << 1;
9218 desc->type |= info->contents << 2;
9219 + desc->type |= info->seg_not_present ^ 1;
9220 desc->s = 1;
9221 desc->dpl = 0x3;
9222 desc->p = info->seg_not_present ^ 1;
9223 @@ -31,16 +33,12 @@ static inline void fill_ldt(struct desc_
9224 }
9225
9226 extern struct desc_ptr idt_descr;
9227 -extern gate_desc idt_table[];
9228 -
9229 -struct gdt_page {
9230 - struct desc_struct gdt[GDT_ENTRIES];
9231 -} __attribute__((aligned(PAGE_SIZE)));
9232 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
9233 +extern gate_desc idt_table[256];
9234
9235 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
9236 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
9237 {
9238 - return per_cpu(gdt_page, cpu).gdt;
9239 + return cpu_gdt_table[cpu];
9240 }
9241
9242 #ifdef CONFIG_X86_64
9243 @@ -65,9 +63,14 @@ static inline void pack_gate(gate_desc *
9244 unsigned long base, unsigned dpl, unsigned flags,
9245 unsigned short seg)
9246 {
9247 - gate->a = (seg << 16) | (base & 0xffff);
9248 - gate->b = (base & 0xffff0000) |
9249 - (((0x80 | type | (dpl << 5)) & 0xff) << 8);
9250 + gate->gate.offset_low = base;
9251 + gate->gate.seg = seg;
9252 + gate->gate.reserved = 0;
9253 + gate->gate.type = type;
9254 + gate->gate.s = 0;
9255 + gate->gate.dpl = dpl;
9256 + gate->gate.p = 1;
9257 + gate->gate.offset_high = base >> 16;
9258 }
9259
9260 #endif
9261 @@ -115,13 +118,17 @@ static inline void paravirt_free_ldt(str
9262 static inline void native_write_idt_entry(gate_desc *idt, int entry,
9263 const gate_desc *gate)
9264 {
9265 + pax_open_kernel();
9266 memcpy(&idt[entry], gate, sizeof(*gate));
9267 + pax_close_kernel();
9268 }
9269
9270 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry,
9271 const void *desc)
9272 {
9273 + pax_open_kernel();
9274 memcpy(&ldt[entry], desc, 8);
9275 + pax_close_kernel();
9276 }
9277
9278 static inline void native_write_gdt_entry(struct desc_struct *gdt, int entry,
9279 @@ -139,7 +146,10 @@ static inline void native_write_gdt_entr
9280 size = sizeof(struct desc_struct);
9281 break;
9282 }
9283 +
9284 + pax_open_kernel();
9285 memcpy(&gdt[entry], desc, size);
9286 + pax_close_kernel();
9287 }
9288
9289 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
9290 @@ -211,7 +221,9 @@ static inline void native_set_ldt(const
9291
9292 static inline void native_load_tr_desc(void)
9293 {
9294 + pax_open_kernel();
9295 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
9296 + pax_close_kernel();
9297 }
9298
9299 static inline void native_load_gdt(const struct desc_ptr *dtr)
9300 @@ -246,8 +258,10 @@ static inline void native_load_tls(struc
9301 unsigned int i;
9302 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
9303
9304 + pax_open_kernel();
9305 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
9306 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
9307 + pax_close_kernel();
9308 }
9309
9310 #define _LDT_empty(info) \
9311 @@ -309,7 +323,7 @@ static inline void set_desc_limit(struct
9312 desc->limit = (limit >> 16) & 0xf;
9313 }
9314
9315 -static inline void _set_gate(int gate, unsigned type, void *addr,
9316 +static inline void _set_gate(int gate, unsigned type, const void *addr,
9317 unsigned dpl, unsigned ist, unsigned seg)
9318 {
9319 gate_desc s;
9320 @@ -327,7 +341,7 @@ static inline void _set_gate(int gate, u
9321 * Pentium F0 0F bugfix can have resulted in the mapped
9322 * IDT being write-protected.
9323 */
9324 -static inline void set_intr_gate(unsigned int n, void *addr)
9325 +static inline void set_intr_gate(unsigned int n, const void *addr)
9326 {
9327 BUG_ON((unsigned)n > 0xFF);
9328 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
9329 @@ -356,19 +370,19 @@ static inline void alloc_intr_gate(unsig
9330 /*
9331 * This routine sets up an interrupt gate at directory privilege level 3.
9332 */
9333 -static inline void set_system_intr_gate(unsigned int n, void *addr)
9334 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
9335 {
9336 BUG_ON((unsigned)n > 0xFF);
9337 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
9338 }
9339
9340 -static inline void set_system_trap_gate(unsigned int n, void *addr)
9341 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
9342 {
9343 BUG_ON((unsigned)n > 0xFF);
9344 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
9345 }
9346
9347 -static inline void set_trap_gate(unsigned int n, void *addr)
9348 +static inline void set_trap_gate(unsigned int n, const void *addr)
9349 {
9350 BUG_ON((unsigned)n > 0xFF);
9351 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
9352 @@ -377,19 +391,31 @@ static inline void set_trap_gate(unsigne
9353 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
9354 {
9355 BUG_ON((unsigned)n > 0xFF);
9356 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
9357 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
9358 }
9359
9360 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
9361 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
9362 {
9363 BUG_ON((unsigned)n > 0xFF);
9364 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
9365 }
9366
9367 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
9368 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
9369 {
9370 BUG_ON((unsigned)n > 0xFF);
9371 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
9372 }
9373
9374 +#ifdef CONFIG_X86_32
9375 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
9376 +{
9377 + struct desc_struct d;
9378 +
9379 + if (likely(limit))
9380 + limit = (limit - 1UL) >> PAGE_SHIFT;
9381 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
9382 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
9383 +}
9384 +#endif
9385 +
9386 #endif /* _ASM_X86_DESC_H */
9387 diff -urNp linux-2.6.39/arch/x86/include/asm/device.h linux-2.6.39/arch/x86/include/asm/device.h
9388 --- linux-2.6.39/arch/x86/include/asm/device.h 2011-05-19 00:06:34.000000000 -0400
9389 +++ linux-2.6.39/arch/x86/include/asm/device.h 2011-05-22 19:36:30.000000000 -0400
9390 @@ -6,7 +6,7 @@ struct dev_archdata {
9391 void *acpi_handle;
9392 #endif
9393 #ifdef CONFIG_X86_64
9394 -struct dma_map_ops *dma_ops;
9395 + const struct dma_map_ops *dma_ops;
9396 #endif
9397 #if defined(CONFIG_DMAR) || defined(CONFIG_AMD_IOMMU)
9398 void *iommu; /* hook for IOMMU specific extension */
9399 diff -urNp linux-2.6.39/arch/x86/include/asm/dma-mapping.h linux-2.6.39/arch/x86/include/asm/dma-mapping.h
9400 --- linux-2.6.39/arch/x86/include/asm/dma-mapping.h 2011-05-19 00:06:34.000000000 -0400
9401 +++ linux-2.6.39/arch/x86/include/asm/dma-mapping.h 2011-05-22 19:36:30.000000000 -0400
9402 @@ -26,9 +26,9 @@ extern int iommu_merge;
9403 extern struct device x86_dma_fallback_dev;
9404 extern int panic_on_overflow;
9405
9406 -extern struct dma_map_ops *dma_ops;
9407 +extern const struct dma_map_ops *dma_ops;
9408
9409 -static inline struct dma_map_ops *get_dma_ops(struct device *dev)
9410 +static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
9411 {
9412 #ifdef CONFIG_X86_32
9413 return dma_ops;
9414 @@ -45,7 +45,7 @@ static inline struct dma_map_ops *get_dm
9415 /* Make sure we keep the same behaviour */
9416 static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
9417 {
9418 - struct dma_map_ops *ops = get_dma_ops(dev);
9419 + const struct dma_map_ops *ops = get_dma_ops(dev);
9420 if (ops->mapping_error)
9421 return ops->mapping_error(dev, dma_addr);
9422
9423 @@ -115,7 +115,7 @@ static inline void *
9424 dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
9425 gfp_t gfp)
9426 {
9427 - struct dma_map_ops *ops = get_dma_ops(dev);
9428 + const struct dma_map_ops *ops = get_dma_ops(dev);
9429 void *memory;
9430
9431 gfp &= ~(__GFP_DMA | __GFP_HIGHMEM | __GFP_DMA32);
9432 @@ -142,7 +142,7 @@ dma_alloc_coherent(struct device *dev, s
9433 static inline void dma_free_coherent(struct device *dev, size_t size,
9434 void *vaddr, dma_addr_t bus)
9435 {
9436 - struct dma_map_ops *ops = get_dma_ops(dev);
9437 + const struct dma_map_ops *ops = get_dma_ops(dev);
9438
9439 WARN_ON(irqs_disabled()); /* for portability */
9440
9441 diff -urNp linux-2.6.39/arch/x86/include/asm/e820.h linux-2.6.39/arch/x86/include/asm/e820.h
9442 --- linux-2.6.39/arch/x86/include/asm/e820.h 2011-05-19 00:06:34.000000000 -0400
9443 +++ linux-2.6.39/arch/x86/include/asm/e820.h 2011-05-22 19:36:30.000000000 -0400
9444 @@ -69,7 +69,7 @@ struct e820map {
9445 #define ISA_START_ADDRESS 0xa0000
9446 #define ISA_END_ADDRESS 0x100000
9447
9448 -#define BIOS_BEGIN 0x000a0000
9449 +#define BIOS_BEGIN 0x000c0000
9450 #define BIOS_END 0x00100000
9451
9452 #define BIOS_ROM_BASE 0xffe00000
9453 diff -urNp linux-2.6.39/arch/x86/include/asm/elf.h linux-2.6.39/arch/x86/include/asm/elf.h
9454 --- linux-2.6.39/arch/x86/include/asm/elf.h 2011-05-19 00:06:34.000000000 -0400
9455 +++ linux-2.6.39/arch/x86/include/asm/elf.h 2011-05-22 19:36:30.000000000 -0400
9456 @@ -237,7 +237,25 @@ extern int force_personality32;
9457 the loader. We need to make sure that it is out of the way of the program
9458 that it will "exec", and that there is sufficient room for the brk. */
9459
9460 +#ifdef CONFIG_PAX_SEGMEXEC
9461 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
9462 +#else
9463 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
9464 +#endif
9465 +
9466 +#ifdef CONFIG_PAX_ASLR
9467 +#ifdef CONFIG_X86_32
9468 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
9469 +
9470 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
9471 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
9472 +#else
9473 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
9474 +
9475 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
9476 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
9477 +#endif
9478 +#endif
9479
9480 /* This yields a mask that user programs can use to figure out what
9481 instruction set this CPU supports. This could be done in user space,
9482 @@ -291,8 +309,7 @@ do { \
9483 #define ARCH_DLINFO \
9484 do { \
9485 if (vdso_enabled) \
9486 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
9487 - (unsigned long)current->mm->context.vdso); \
9488 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso);\
9489 } while (0)
9490
9491 #define AT_SYSINFO 32
9492 @@ -303,7 +320,7 @@ do { \
9493
9494 #endif /* !CONFIG_X86_32 */
9495
9496 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
9497 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
9498
9499 #define VDSO_ENTRY \
9500 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
9501 @@ -317,7 +334,4 @@ extern int arch_setup_additional_pages(s
9502 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
9503 #define compat_arch_setup_additional_pages syscall32_setup_pages
9504
9505 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
9506 -#define arch_randomize_brk arch_randomize_brk
9507 -
9508 #endif /* _ASM_X86_ELF_H */
9509 diff -urNp linux-2.6.39/arch/x86/include/asm/emergency-restart.h linux-2.6.39/arch/x86/include/asm/emergency-restart.h
9510 --- linux-2.6.39/arch/x86/include/asm/emergency-restart.h 2011-05-19 00:06:34.000000000 -0400
9511 +++ linux-2.6.39/arch/x86/include/asm/emergency-restart.h 2011-05-22 19:36:30.000000000 -0400
9512 @@ -15,6 +15,6 @@ enum reboot_type {
9513
9514 extern enum reboot_type reboot_type;
9515
9516 -extern void machine_emergency_restart(void);
9517 +extern void machine_emergency_restart(void) __noreturn;
9518
9519 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
9520 diff -urNp linux-2.6.39/arch/x86/include/asm/futex.h linux-2.6.39/arch/x86/include/asm/futex.h
9521 --- linux-2.6.39/arch/x86/include/asm/futex.h 2011-05-19 00:06:34.000000000 -0400
9522 +++ linux-2.6.39/arch/x86/include/asm/futex.h 2011-05-22 19:36:30.000000000 -0400
9523 @@ -12,16 +12,18 @@
9524 #include <asm/system.h>
9525
9526 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
9527 + typecheck(u32 *, uaddr); \
9528 asm volatile("1:\t" insn "\n" \
9529 "2:\t.section .fixup,\"ax\"\n" \
9530 "3:\tmov\t%3, %1\n" \
9531 "\tjmp\t2b\n" \
9532 "\t.previous\n" \
9533 _ASM_EXTABLE(1b, 3b) \
9534 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
9535 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 *)____m(uaddr))\
9536 : "i" (-EFAULT), "0" (oparg), "1" (0))
9537
9538 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
9539 + typecheck(u32 *, uaddr); \
9540 asm volatile("1:\tmovl %2, %0\n" \
9541 "\tmovl\t%0, %3\n" \
9542 "\t" insn "\n" \
9543 @@ -34,7 +36,7 @@
9544 _ASM_EXTABLE(1b, 4b) \
9545 _ASM_EXTABLE(2b, 4b) \
9546 : "=&a" (oldval), "=&r" (ret), \
9547 - "+m" (*uaddr), "=&r" (tem) \
9548 + "+m" (*(u32 *)____m(uaddr)), "=&r" (tem) \
9549 : "r" (oparg), "i" (-EFAULT), "1" (0))
9550
9551 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
9552 @@ -61,10 +63,10 @@ static inline int futex_atomic_op_inuser
9553
9554 switch (op) {
9555 case FUTEX_OP_SET:
9556 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
9557 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
9558 break;
9559 case FUTEX_OP_ADD:
9560 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
9561 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
9562 uaddr, oparg);
9563 break;
9564 case FUTEX_OP_OR:
9565 @@ -123,13 +125,13 @@ static inline int futex_atomic_cmpxchg_i
9566 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
9567 return -EFAULT;
9568
9569 - asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
9570 + asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
9571 "2:\t.section .fixup, \"ax\"\n"
9572 "3:\tmov %3, %0\n"
9573 "\tjmp 2b\n"
9574 "\t.previous\n"
9575 _ASM_EXTABLE(1b, 3b)
9576 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
9577 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 *)____m(uaddr))
9578 : "i" (-EFAULT), "r" (newval), "1" (oldval)
9579 : "memory"
9580 );
9581 diff -urNp linux-2.6.39/arch/x86/include/asm/hw_irq.h linux-2.6.39/arch/x86/include/asm/hw_irq.h
9582 --- linux-2.6.39/arch/x86/include/asm/hw_irq.h 2011-05-19 00:06:34.000000000 -0400
9583 +++ linux-2.6.39/arch/x86/include/asm/hw_irq.h 2011-05-22 19:36:30.000000000 -0400
9584 @@ -137,8 +137,8 @@ extern void setup_ioapic_dest(void);
9585 extern void enable_IO_APIC(void);
9586
9587 /* Statistics */
9588 -extern atomic_t irq_err_count;
9589 -extern atomic_t irq_mis_count;
9590 +extern atomic_unchecked_t irq_err_count;
9591 +extern atomic_unchecked_t irq_mis_count;
9592
9593 /* EISA */
9594 extern void eisa_set_level_irq(unsigned int irq);
9595 diff -urNp linux-2.6.39/arch/x86/include/asm/i387.h linux-2.6.39/arch/x86/include/asm/i387.h
9596 --- linux-2.6.39/arch/x86/include/asm/i387.h 2011-05-19 00:06:34.000000000 -0400
9597 +++ linux-2.6.39/arch/x86/include/asm/i387.h 2011-05-22 19:36:30.000000000 -0400
9598 @@ -92,6 +92,11 @@ static inline int fxrstor_checking(struc
9599 {
9600 int err;
9601
9602 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
9603 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
9604 + fx = (struct i387_fxsave_struct *)((void *)fx + PAX_USER_SHADOW_BASE);
9605 +#endif
9606 +
9607 /* See comment in fxsave() below. */
9608 #ifdef CONFIG_AS_FXSAVEQ
9609 asm volatile("1: fxrstorq %[fx]\n\t"
9610 @@ -121,6 +126,11 @@ static inline int fxsave_user(struct i38
9611 {
9612 int err;
9613
9614 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
9615 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
9616 + fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
9617 +#endif
9618 +
9619 /*
9620 * Clear the bytes not touched by the fxsave and reserved
9621 * for the SW usage.
9622 @@ -213,13 +223,8 @@ static inline void fpu_fxsave(struct fpu
9623 #endif /* CONFIG_X86_64 */
9624
9625 /* We need a safe address that is cheap to find and that is already
9626 - in L1 during context switch. The best choices are unfortunately
9627 - different for UP and SMP */
9628 -#ifdef CONFIG_SMP
9629 -#define safe_address (__per_cpu_offset[0])
9630 -#else
9631 -#define safe_address (kstat_cpu(0).cpustat.user)
9632 -#endif
9633 + in L1 during context switch. */
9634 +#define safe_address (init_tss[smp_processor_id()].x86_tss.sp0)
9635
9636 /*
9637 * These must be called with preempt disabled
9638 @@ -312,7 +317,7 @@ static inline void kernel_fpu_begin(void
9639 struct thread_info *me = current_thread_info();
9640 preempt_disable();
9641 if (me->status & TS_USEDFPU)
9642 - __save_init_fpu(me->task);
9643 + __save_init_fpu(current);
9644 else
9645 clts();
9646 }
9647 diff -urNp linux-2.6.39/arch/x86/include/asm/io.h linux-2.6.39/arch/x86/include/asm/io.h
9648 --- linux-2.6.39/arch/x86/include/asm/io.h 2011-05-19 00:06:34.000000000 -0400
9649 +++ linux-2.6.39/arch/x86/include/asm/io.h 2011-05-22 19:36:30.000000000 -0400
9650 @@ -216,6 +216,17 @@ extern void set_iounmap_nonlazy(void);
9651
9652 #include <linux/vmalloc.h>
9653
9654 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
9655 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
9656 +{
9657 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
9658 +}
9659 +
9660 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
9661 +{
9662 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
9663 +}
9664 +
9665 /*
9666 * Convert a virtual cached pointer to an uncached pointer
9667 */
9668 diff -urNp linux-2.6.39/arch/x86/include/asm/iommu.h linux-2.6.39/arch/x86/include/asm/iommu.h
9669 --- linux-2.6.39/arch/x86/include/asm/iommu.h 2011-05-19 00:06:34.000000000 -0400
9670 +++ linux-2.6.39/arch/x86/include/asm/iommu.h 2011-05-22 19:36:30.000000000 -0400
9671 @@ -1,7 +1,7 @@
9672 #ifndef _ASM_X86_IOMMU_H
9673 #define _ASM_X86_IOMMU_H
9674
9675 -extern struct dma_map_ops nommu_dma_ops;
9676 +extern const struct dma_map_ops nommu_dma_ops;
9677 extern int force_iommu, no_iommu;
9678 extern int iommu_detected;
9679 extern int iommu_pass_through;
9680 diff -urNp linux-2.6.39/arch/x86/include/asm/irqflags.h linux-2.6.39/arch/x86/include/asm/irqflags.h
9681 --- linux-2.6.39/arch/x86/include/asm/irqflags.h 2011-05-19 00:06:34.000000000 -0400
9682 +++ linux-2.6.39/arch/x86/include/asm/irqflags.h 2011-05-22 19:36:30.000000000 -0400
9683 @@ -140,6 +140,11 @@ static inline unsigned long arch_local_i
9684 sti; \
9685 sysexit
9686
9687 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
9688 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
9689 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
9690 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
9691 +
9692 #else
9693 #define INTERRUPT_RETURN iret
9694 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
9695 diff -urNp linux-2.6.39/arch/x86/include/asm/kprobes.h linux-2.6.39/arch/x86/include/asm/kprobes.h
9696 --- linux-2.6.39/arch/x86/include/asm/kprobes.h 2011-05-19 00:06:34.000000000 -0400
9697 +++ linux-2.6.39/arch/x86/include/asm/kprobes.h 2011-05-22 19:36:30.000000000 -0400
9698 @@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
9699 #define RELATIVEJUMP_SIZE 5
9700 #define RELATIVECALL_OPCODE 0xe8
9701 #define RELATIVE_ADDR_SIZE 4
9702 -#define MAX_STACK_SIZE 64
9703 -#define MIN_STACK_SIZE(ADDR) \
9704 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
9705 - THREAD_SIZE - (unsigned long)(ADDR))) \
9706 - ? (MAX_STACK_SIZE) \
9707 - : (((unsigned long)current_thread_info()) + \
9708 - THREAD_SIZE - (unsigned long)(ADDR)))
9709 +#define MAX_STACK_SIZE 64UL
9710 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
9711
9712 #define flush_insn_slot(p) do { } while (0)
9713
9714 diff -urNp linux-2.6.39/arch/x86/include/asm/kvm_host.h linux-2.6.39/arch/x86/include/asm/kvm_host.h
9715 --- linux-2.6.39/arch/x86/include/asm/kvm_host.h 2011-05-19 00:06:34.000000000 -0400
9716 +++ linux-2.6.39/arch/x86/include/asm/kvm_host.h 2011-05-22 19:36:30.000000000 -0400
9717 @@ -419,7 +419,7 @@ struct kvm_arch {
9718 unsigned int n_used_mmu_pages;
9719 unsigned int n_requested_mmu_pages;
9720 unsigned int n_max_mmu_pages;
9721 - atomic_t invlpg_counter;
9722 + atomic_unchecked_t invlpg_counter;
9723 struct hlist_head mmu_page_hash[KVM_NUM_MMU_PAGES];
9724 /*
9725 * Hash table of struct kvm_mmu_page.
9726 @@ -599,7 +599,7 @@ struct kvm_arch_async_pf {
9727 bool direct_map;
9728 };
9729
9730 -extern struct kvm_x86_ops *kvm_x86_ops;
9731 +extern const struct kvm_x86_ops *kvm_x86_ops;
9732
9733 int kvm_mmu_module_init(void);
9734 void kvm_mmu_module_exit(void);
9735 diff -urNp linux-2.6.39/arch/x86/include/asm/local.h linux-2.6.39/arch/x86/include/asm/local.h
9736 --- linux-2.6.39/arch/x86/include/asm/local.h 2011-05-19 00:06:34.000000000 -0400
9737 +++ linux-2.6.39/arch/x86/include/asm/local.h 2011-05-22 19:36:30.000000000 -0400
9738 @@ -18,26 +18,58 @@ typedef struct {
9739
9740 static inline void local_inc(local_t *l)
9741 {
9742 - asm volatile(_ASM_INC "%0"
9743 + asm volatile(_ASM_INC "%0\n"
9744 +
9745 +#ifdef CONFIG_PAX_REFCOUNT
9746 + "jno 0f\n"
9747 + _ASM_DEC "%0\n"
9748 + "int $4\n0:\n"
9749 + _ASM_EXTABLE(0b, 0b)
9750 +#endif
9751 +
9752 : "+m" (l->a.counter));
9753 }
9754
9755 static inline void local_dec(local_t *l)
9756 {
9757 - asm volatile(_ASM_DEC "%0"
9758 + asm volatile(_ASM_DEC "%0\n"
9759 +
9760 +#ifdef CONFIG_PAX_REFCOUNT
9761 + "jno 0f\n"
9762 + _ASM_INC "%0\n"
9763 + "int $4\n0:\n"
9764 + _ASM_EXTABLE(0b, 0b)
9765 +#endif
9766 +
9767 : "+m" (l->a.counter));
9768 }
9769
9770 static inline void local_add(long i, local_t *l)
9771 {
9772 - asm volatile(_ASM_ADD "%1,%0"
9773 + asm volatile(_ASM_ADD "%1,%0\n"
9774 +
9775 +#ifdef CONFIG_PAX_REFCOUNT
9776 + "jno 0f\n"
9777 + _ASM_SUB "%1,%0\n"
9778 + "int $4\n0:\n"
9779 + _ASM_EXTABLE(0b, 0b)
9780 +#endif
9781 +
9782 : "+m" (l->a.counter)
9783 : "ir" (i));
9784 }
9785
9786 static inline void local_sub(long i, local_t *l)
9787 {
9788 - asm volatile(_ASM_SUB "%1,%0"
9789 + asm volatile(_ASM_SUB "%1,%0\n"
9790 +
9791 +#ifdef CONFIG_PAX_REFCOUNT
9792 + "jno 0f\n"
9793 + _ASM_ADD "%1,%0\n"
9794 + "int $4\n0:\n"
9795 + _ASM_EXTABLE(0b, 0b)
9796 +#endif
9797 +
9798 : "+m" (l->a.counter)
9799 : "ir" (i));
9800 }
9801 @@ -55,7 +87,16 @@ static inline int local_sub_and_test(lon
9802 {
9803 unsigned char c;
9804
9805 - asm volatile(_ASM_SUB "%2,%0; sete %1"
9806 + asm volatile(_ASM_SUB "%2,%0\n"
9807 +
9808 +#ifdef CONFIG_PAX_REFCOUNT
9809 + "jno 0f\n"
9810 + _ASM_ADD "%2,%0\n"
9811 + "int $4\n0:\n"
9812 + _ASM_EXTABLE(0b, 0b)
9813 +#endif
9814 +
9815 + "sete %1\n"
9816 : "+m" (l->a.counter), "=qm" (c)
9817 : "ir" (i) : "memory");
9818 return c;
9819 @@ -73,7 +114,16 @@ static inline int local_dec_and_test(loc
9820 {
9821 unsigned char c;
9822
9823 - asm volatile(_ASM_DEC "%0; sete %1"
9824 + asm volatile(_ASM_DEC "%0\n"
9825 +
9826 +#ifdef CONFIG_PAX_REFCOUNT
9827 + "jno 0f\n"
9828 + _ASM_INC "%0\n"
9829 + "int $4\n0:\n"
9830 + _ASM_EXTABLE(0b, 0b)
9831 +#endif
9832 +
9833 + "sete %1\n"
9834 : "+m" (l->a.counter), "=qm" (c)
9835 : : "memory");
9836 return c != 0;
9837 @@ -91,7 +141,16 @@ static inline int local_inc_and_test(loc
9838 {
9839 unsigned char c;
9840
9841 - asm volatile(_ASM_INC "%0; sete %1"
9842 + asm volatile(_ASM_INC "%0\n"
9843 +
9844 +#ifdef CONFIG_PAX_REFCOUNT
9845 + "jno 0f\n"
9846 + _ASM_DEC "%0\n"
9847 + "int $4\n0:\n"
9848 + _ASM_EXTABLE(0b, 0b)
9849 +#endif
9850 +
9851 + "sete %1\n"
9852 : "+m" (l->a.counter), "=qm" (c)
9853 : : "memory");
9854 return c != 0;
9855 @@ -110,7 +169,16 @@ static inline int local_add_negative(lon
9856 {
9857 unsigned char c;
9858
9859 - asm volatile(_ASM_ADD "%2,%0; sets %1"
9860 + asm volatile(_ASM_ADD "%2,%0\n"
9861 +
9862 +#ifdef CONFIG_PAX_REFCOUNT
9863 + "jno 0f\n"
9864 + _ASM_SUB "%2,%0\n"
9865 + "int $4\n0:\n"
9866 + _ASM_EXTABLE(0b, 0b)
9867 +#endif
9868 +
9869 + "sets %1\n"
9870 : "+m" (l->a.counter), "=qm" (c)
9871 : "ir" (i) : "memory");
9872 return c;
9873 @@ -133,7 +201,15 @@ static inline long local_add_return(long
9874 #endif
9875 /* Modern 486+ processor */
9876 __i = i;
9877 - asm volatile(_ASM_XADD "%0, %1;"
9878 + asm volatile(_ASM_XADD "%0, %1\n"
9879 +
9880 +#ifdef CONFIG_PAX_REFCOUNT
9881 + "jno 0f\n"
9882 + _ASM_MOV "%0,%1\n"
9883 + "int $4\n0:\n"
9884 + _ASM_EXTABLE(0b, 0b)
9885 +#endif
9886 +
9887 : "+r" (i), "+m" (l->a.counter)
9888 : : "memory");
9889 return i + __i;
9890 diff -urNp linux-2.6.39/arch/x86/include/asm/mce.h linux-2.6.39/arch/x86/include/asm/mce.h
9891 --- linux-2.6.39/arch/x86/include/asm/mce.h 2011-05-19 00:06:34.000000000 -0400
9892 +++ linux-2.6.39/arch/x86/include/asm/mce.h 2011-05-22 19:36:30.000000000 -0400
9893 @@ -198,7 +198,7 @@ int mce_notify_irq(void);
9894 void mce_notify_process(void);
9895
9896 DECLARE_PER_CPU(struct mce, injectm);
9897 -extern struct file_operations mce_chrdev_ops;
9898 +extern struct file_operations mce_chrdev_ops; /* cannot be const, see arch/x86/kernel/cpu/mcheck/mce. */
9899
9900 /*
9901 * Exception handler
9902 diff -urNp linux-2.6.39/arch/x86/include/asm/microcode.h linux-2.6.39/arch/x86/include/asm/microcode.h
9903 --- linux-2.6.39/arch/x86/include/asm/microcode.h 2011-05-19 00:06:34.000000000 -0400
9904 +++ linux-2.6.39/arch/x86/include/asm/microcode.h 2011-05-22 19:36:30.000000000 -0400
9905 @@ -12,13 +12,13 @@ struct device;
9906 enum ucode_state { UCODE_ERROR, UCODE_OK, UCODE_NFOUND };
9907
9908 struct microcode_ops {
9909 - enum ucode_state (*request_microcode_user) (int cpu,
9910 + enum ucode_state (* const request_microcode_user) (int cpu,
9911 const void __user *buf, size_t size);
9912
9913 - enum ucode_state (*request_microcode_fw) (int cpu,
9914 + enum ucode_state (* const request_microcode_fw) (int cpu,
9915 struct device *device);
9916
9917 - void (*microcode_fini_cpu) (int cpu);
9918 + void (* const microcode_fini_cpu) (int cpu);
9919
9920 /*
9921 * The generic 'microcode_core' part guarantees that
9922 @@ -38,16 +38,16 @@ struct ucode_cpu_info {
9923 extern struct ucode_cpu_info ucode_cpu_info[];
9924
9925 #ifdef CONFIG_MICROCODE_INTEL
9926 -extern struct microcode_ops * __init init_intel_microcode(void);
9927 +extern const struct microcode_ops * __init init_intel_microcode(void);
9928 #else
9929 -static inline struct microcode_ops * __init init_intel_microcode(void)
9930 +static inline const struct microcode_ops * __init init_intel_microcode(void)
9931 {
9932 return NULL;
9933 }
9934 #endif /* CONFIG_MICROCODE_INTEL */
9935
9936 #ifdef CONFIG_MICROCODE_AMD
9937 -extern struct microcode_ops * __init init_amd_microcode(void);
9938 +extern const struct microcode_ops * __init init_amd_microcode(void);
9939
9940 static inline void get_ucode_data(void *to, const u8 *from, size_t n)
9941 {
9942 @@ -55,7 +55,7 @@ static inline void get_ucode_data(void *
9943 }
9944
9945 #else
9946 -static inline struct microcode_ops * __init init_amd_microcode(void)
9947 +static inline const struct microcode_ops * __init init_amd_microcode(void)
9948 {
9949 return NULL;
9950 }
9951 diff -urNp linux-2.6.39/arch/x86/include/asm/mman.h linux-2.6.39/arch/x86/include/asm/mman.h
9952 --- linux-2.6.39/arch/x86/include/asm/mman.h 2011-05-19 00:06:34.000000000 -0400
9953 +++ linux-2.6.39/arch/x86/include/asm/mman.h 2011-05-22 19:36:30.000000000 -0400
9954 @@ -5,4 +5,14 @@
9955
9956 #include <asm-generic/mman.h>
9957
9958 +#ifdef __KERNEL__
9959 +#ifndef __ASSEMBLY__
9960 +#ifdef CONFIG_X86_32
9961 +#define arch_mmap_check i386_mmap_check
9962 +int i386_mmap_check(unsigned long addr, unsigned long len,
9963 + unsigned long flags);
9964 +#endif
9965 +#endif
9966 +#endif
9967 +
9968 #endif /* _ASM_X86_MMAN_H */
9969 diff -urNp linux-2.6.39/arch/x86/include/asm/mmu_context.h linux-2.6.39/arch/x86/include/asm/mmu_context.h
9970 --- linux-2.6.39/arch/x86/include/asm/mmu_context.h 2011-05-19 00:06:34.000000000 -0400
9971 +++ linux-2.6.39/arch/x86/include/asm/mmu_context.h 2011-05-22 19:36:30.000000000 -0400
9972 @@ -24,6 +24,21 @@ void destroy_context(struct mm_struct *m
9973
9974 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
9975 {
9976 +
9977 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
9978 + unsigned int i;
9979 + pgd_t *pgd;
9980 +
9981 + pax_open_kernel();
9982 + pgd = get_cpu_pgd(smp_processor_id());
9983 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
9984 + if (paravirt_enabled())
9985 + set_pgd(pgd+i, native_make_pgd(0));
9986 + else
9987 + pgd[i] = native_make_pgd(0);
9988 + pax_close_kernel();
9989 +#endif
9990 +
9991 #ifdef CONFIG_SMP
9992 if (percpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
9993 percpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
9994 @@ -34,16 +49,30 @@ static inline void switch_mm(struct mm_s
9995 struct task_struct *tsk)
9996 {
9997 unsigned cpu = smp_processor_id();
9998 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP)
9999 + int tlbstate = TLBSTATE_OK;
10000 +#endif
10001
10002 if (likely(prev != next)) {
10003 #ifdef CONFIG_SMP
10004 +#ifdef CONFIG_X86_32
10005 + tlbstate = percpu_read(cpu_tlbstate.state);
10006 +#endif
10007 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10008 percpu_write(cpu_tlbstate.active_mm, next);
10009 #endif
10010 cpumask_set_cpu(cpu, mm_cpumask(next));
10011
10012 /* Re-load page tables */
10013 +#ifdef CONFIG_PAX_PER_CPU_PGD
10014 + pax_open_kernel();
10015 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
10016 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
10017 + pax_close_kernel();
10018 + load_cr3(get_cpu_pgd(cpu));
10019 +#else
10020 load_cr3(next->pgd);
10021 +#endif
10022
10023 /* stop flush ipis for the previous mm */
10024 cpumask_clear_cpu(cpu, mm_cpumask(prev));
10025 @@ -53,9 +82,38 @@ static inline void switch_mm(struct mm_s
10026 */
10027 if (unlikely(prev->context.ldt != next->context.ldt))
10028 load_LDT_nolock(&next->context);
10029 - }
10030 +
10031 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10032 + if (!(__supported_pte_mask & _PAGE_NX)) {
10033 + smp_mb__before_clear_bit();
10034 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
10035 + smp_mb__after_clear_bit();
10036 + cpu_set(cpu, next->context.cpu_user_cs_mask);
10037 + }
10038 +#endif
10039 +
10040 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10041 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
10042 + prev->context.user_cs_limit != next->context.user_cs_limit))
10043 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10044 #ifdef CONFIG_SMP
10045 + else if (unlikely(tlbstate != TLBSTATE_OK))
10046 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10047 +#endif
10048 +#endif
10049 +
10050 + }
10051 else {
10052 +
10053 +#ifdef CONFIG_PAX_PER_CPU_PGD
10054 + pax_open_kernel();
10055 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
10056 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
10057 + pax_close_kernel();
10058 + load_cr3(get_cpu_pgd(cpu));
10059 +#endif
10060 +
10061 +#ifdef CONFIG_SMP
10062 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10063 BUG_ON(percpu_read(cpu_tlbstate.active_mm) != next);
10064
10065 @@ -64,11 +122,28 @@ static inline void switch_mm(struct mm_s
10066 * tlb flush IPI delivery. We must reload CR3
10067 * to make sure to use no freed page tables.
10068 */
10069 +
10070 +#ifndef CONFIG_PAX_PER_CPU_PGD
10071 load_cr3(next->pgd);
10072 +#endif
10073 +
10074 load_LDT_nolock(&next->context);
10075 +
10076 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
10077 + if (!(__supported_pte_mask & _PAGE_NX))
10078 + cpu_set(cpu, next->context.cpu_user_cs_mask);
10079 +#endif
10080 +
10081 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10082 +#ifdef CONFIG_PAX_PAGEEXEC
10083 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
10084 +#endif
10085 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10086 +#endif
10087 +
10088 }
10089 - }
10090 #endif
10091 + }
10092 }
10093
10094 #define activate_mm(prev, next) \
10095 diff -urNp linux-2.6.39/arch/x86/include/asm/mmu.h linux-2.6.39/arch/x86/include/asm/mmu.h
10096 --- linux-2.6.39/arch/x86/include/asm/mmu.h 2011-05-19 00:06:34.000000000 -0400
10097 +++ linux-2.6.39/arch/x86/include/asm/mmu.h 2011-05-22 19:36:30.000000000 -0400
10098 @@ -9,10 +9,22 @@
10099 * we put the segment information here.
10100 */
10101 typedef struct {
10102 - void *ldt;
10103 + struct desc_struct *ldt;
10104 int size;
10105 struct mutex lock;
10106 - void *vdso;
10107 + unsigned long vdso;
10108 +
10109 +#ifdef CONFIG_X86_32
10110 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10111 + unsigned long user_cs_base;
10112 + unsigned long user_cs_limit;
10113 +
10114 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10115 + cpumask_t cpu_user_cs_mask;
10116 +#endif
10117 +
10118 +#endif
10119 +#endif
10120
10121 #ifdef CONFIG_X86_64
10122 /* True if mm supports a task running in 32 bit compatibility mode. */
10123 diff -urNp linux-2.6.39/arch/x86/include/asm/module.h linux-2.6.39/arch/x86/include/asm/module.h
10124 --- linux-2.6.39/arch/x86/include/asm/module.h 2011-05-19 00:06:34.000000000 -0400
10125 +++ linux-2.6.39/arch/x86/include/asm/module.h 2011-05-22 19:41:32.000000000 -0400
10126 @@ -5,6 +5,7 @@
10127
10128 #ifdef CONFIG_X86_64
10129 /* X86_64 does not define MODULE_PROC_FAMILY */
10130 +#define MODULE_PROC_FAMILY ""
10131 #elif defined CONFIG_M386
10132 #define MODULE_PROC_FAMILY "386 "
10133 #elif defined CONFIG_M486
10134 @@ -59,8 +60,30 @@
10135 #error unknown processor family
10136 #endif
10137
10138 -#ifdef CONFIG_X86_32
10139 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
10140 +#ifdef CONFIG_PAX_MEMORY_UDEREF
10141 +#define MODULE_PAX_UDEREF "UDEREF "
10142 +#else
10143 +#define MODULE_PAX_UDEREF ""
10144 +#endif
10145 +
10146 +#ifdef CONFIG_PAX_KERNEXEC
10147 +#define MODULE_PAX_KERNEXEC "KERNEXEC "
10148 +#else
10149 +#define MODULE_PAX_KERNEXEC ""
10150 #endif
10151
10152 +#ifdef CONFIG_PAX_REFCOUNT
10153 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
10154 +#else
10155 +#define MODULE_PAX_REFCOUNT ""
10156 +#endif
10157 +
10158 +#ifdef CONFIG_GRKERNSEC
10159 +#define MODULE_GRSEC "GRSECURITY "
10160 +#else
10161 +#define MODULE_GRSEC ""
10162 +#endif
10163 +
10164 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_GRSEC MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF MODULE_PAX_REFCOUNT
10165 +
10166 #endif /* _ASM_X86_MODULE_H */
10167 diff -urNp linux-2.6.39/arch/x86/include/asm/page_64_types.h linux-2.6.39/arch/x86/include/asm/page_64_types.h
10168 --- linux-2.6.39/arch/x86/include/asm/page_64_types.h 2011-05-19 00:06:34.000000000 -0400
10169 +++ linux-2.6.39/arch/x86/include/asm/page_64_types.h 2011-05-22 19:36:30.000000000 -0400
10170 @@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
10171
10172 /* duplicated to the one in bootmem.h */
10173 extern unsigned long max_pfn;
10174 -extern unsigned long phys_base;
10175 +extern const unsigned long phys_base;
10176
10177 extern unsigned long __phys_addr(unsigned long);
10178 #define __phys_reloc_hide(x) (x)
10179 diff -urNp linux-2.6.39/arch/x86/include/asm/paravirt.h linux-2.6.39/arch/x86/include/asm/paravirt.h
10180 --- linux-2.6.39/arch/x86/include/asm/paravirt.h 2011-05-19 00:06:34.000000000 -0400
10181 +++ linux-2.6.39/arch/x86/include/asm/paravirt.h 2011-05-22 19:36:30.000000000 -0400
10182 @@ -739,6 +739,21 @@ static inline void __set_fixmap(unsigned
10183 pv_mmu_ops.set_fixmap(idx, phys, flags);
10184 }
10185
10186 +#ifdef CONFIG_PAX_KERNEXEC
10187 +static inline unsigned long pax_open_kernel(void)
10188 +{
10189 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
10190 +}
10191 +
10192 +static inline unsigned long pax_close_kernel(void)
10193 +{
10194 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
10195 +}
10196 +#else
10197 +static inline unsigned long pax_open_kernel(void) { return 0; }
10198 +static inline unsigned long pax_close_kernel(void) { return 0; }
10199 +#endif
10200 +
10201 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
10202
10203 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
10204 @@ -955,7 +970,7 @@ extern void default_banner(void);
10205
10206 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
10207 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
10208 -#define PARA_INDIRECT(addr) *%cs:addr
10209 +#define PARA_INDIRECT(addr) *%ss:addr
10210 #endif
10211
10212 #define INTERRUPT_RETURN \
10213 @@ -1032,6 +1047,21 @@ extern void default_banner(void);
10214 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
10215 CLBR_NONE, \
10216 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
10217 +
10218 +#define GET_CR0_INTO_RDI \
10219 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
10220 + mov %rax,%rdi
10221 +
10222 +#define SET_RDI_INTO_CR0 \
10223 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
10224 +
10225 +#define GET_CR3_INTO_RDI \
10226 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
10227 + mov %rax,%rdi
10228 +
10229 +#define SET_RDI_INTO_CR3 \
10230 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
10231 +
10232 #endif /* CONFIG_X86_32 */
10233
10234 #endif /* __ASSEMBLY__ */
10235 diff -urNp linux-2.6.39/arch/x86/include/asm/paravirt_types.h linux-2.6.39/arch/x86/include/asm/paravirt_types.h
10236 --- linux-2.6.39/arch/x86/include/asm/paravirt_types.h 2011-05-19 00:06:34.000000000 -0400
10237 +++ linux-2.6.39/arch/x86/include/asm/paravirt_types.h 2011-05-22 19:36:30.000000000 -0400
10238 @@ -317,6 +317,12 @@ struct pv_mmu_ops {
10239 an mfn. We can tell which is which from the index. */
10240 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
10241 phys_addr_t phys, pgprot_t flags);
10242 +
10243 +#ifdef CONFIG_PAX_KERNEXEC
10244 + unsigned long (*pax_open_kernel)(void);
10245 + unsigned long (*pax_close_kernel)(void);
10246 +#endif
10247 +
10248 };
10249
10250 struct arch_spinlock;
10251 diff -urNp linux-2.6.39/arch/x86/include/asm/pci_x86.h linux-2.6.39/arch/x86/include/asm/pci_x86.h
10252 --- linux-2.6.39/arch/x86/include/asm/pci_x86.h 2011-05-19 00:06:34.000000000 -0400
10253 +++ linux-2.6.39/arch/x86/include/asm/pci_x86.h 2011-05-22 19:36:30.000000000 -0400
10254 @@ -93,16 +93,16 @@ extern int (*pcibios_enable_irq)(struct
10255 extern void (*pcibios_disable_irq)(struct pci_dev *dev);
10256
10257 struct pci_raw_ops {
10258 - int (*read)(unsigned int domain, unsigned int bus, unsigned int devfn,
10259 + int (* const read)(unsigned int domain, unsigned int bus, unsigned int devfn,
10260 int reg, int len, u32 *val);
10261 - int (*write)(unsigned int domain, unsigned int bus, unsigned int devfn,
10262 + int (* const write)(unsigned int domain, unsigned int bus, unsigned int devfn,
10263 int reg, int len, u32 val);
10264 };
10265
10266 -extern struct pci_raw_ops *raw_pci_ops;
10267 -extern struct pci_raw_ops *raw_pci_ext_ops;
10268 +extern const struct pci_raw_ops *raw_pci_ops;
10269 +extern const struct pci_raw_ops *raw_pci_ext_ops;
10270
10271 -extern struct pci_raw_ops pci_direct_conf1;
10272 +extern const struct pci_raw_ops pci_direct_conf1;
10273 extern bool port_cf9_safe;
10274
10275 /* arch_initcall level */
10276 diff -urNp linux-2.6.39/arch/x86/include/asm/pgalloc.h linux-2.6.39/arch/x86/include/asm/pgalloc.h
10277 --- linux-2.6.39/arch/x86/include/asm/pgalloc.h 2011-05-19 00:06:34.000000000 -0400
10278 +++ linux-2.6.39/arch/x86/include/asm/pgalloc.h 2011-05-22 19:36:30.000000000 -0400
10279 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(s
10280 pmd_t *pmd, pte_t *pte)
10281 {
10282 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
10283 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
10284 +}
10285 +
10286 +static inline void pmd_populate_user(struct mm_struct *mm,
10287 + pmd_t *pmd, pte_t *pte)
10288 +{
10289 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
10290 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
10291 }
10292
10293 diff -urNp linux-2.6.39/arch/x86/include/asm/pgtable-2level.h linux-2.6.39/arch/x86/include/asm/pgtable-2level.h
10294 --- linux-2.6.39/arch/x86/include/asm/pgtable-2level.h 2011-05-19 00:06:34.000000000 -0400
10295 +++ linux-2.6.39/arch/x86/include/asm/pgtable-2level.h 2011-05-22 19:36:30.000000000 -0400
10296 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t
10297
10298 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
10299 {
10300 + pax_open_kernel();
10301 *pmdp = pmd;
10302 + pax_close_kernel();
10303 }
10304
10305 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
10306 diff -urNp linux-2.6.39/arch/x86/include/asm/pgtable_32.h linux-2.6.39/arch/x86/include/asm/pgtable_32.h
10307 --- linux-2.6.39/arch/x86/include/asm/pgtable_32.h 2011-05-19 00:06:34.000000000 -0400
10308 +++ linux-2.6.39/arch/x86/include/asm/pgtable_32.h 2011-05-22 19:36:30.000000000 -0400
10309 @@ -25,9 +25,6 @@
10310 struct mm_struct;
10311 struct vm_area_struct;
10312
10313 -extern pgd_t swapper_pg_dir[1024];
10314 -extern pgd_t initial_page_table[1024];
10315 -
10316 static inline void pgtable_cache_init(void) { }
10317 static inline void check_pgt_cache(void) { }
10318 void paging_init(void);
10319 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, u
10320 # include <asm/pgtable-2level.h>
10321 #endif
10322
10323 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
10324 +extern pgd_t initial_page_table[PTRS_PER_PGD];
10325 +#ifdef CONFIG_X86_PAE
10326 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
10327 +#endif
10328 +
10329 #if defined(CONFIG_HIGHPTE)
10330 #define pte_offset_map(dir, address) \
10331 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
10332 @@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, u
10333 /* Clear a kernel PTE and flush it from the TLB */
10334 #define kpte_clear_flush(ptep, vaddr) \
10335 do { \
10336 + pax_open_kernel(); \
10337 pte_clear(&init_mm, (vaddr), (ptep)); \
10338 + pax_close_kernel(); \
10339 __flush_tlb_one((vaddr)); \
10340 } while (0)
10341
10342 @@ -74,6 +79,9 @@ do { \
10343
10344 #endif /* !__ASSEMBLY__ */
10345
10346 +#define HAVE_ARCH_UNMAPPED_AREA
10347 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
10348 +
10349 /*
10350 * kern_addr_valid() is (1) for FLATMEM and (0) for
10351 * SPARSEMEM and DISCONTIGMEM
10352 diff -urNp linux-2.6.39/arch/x86/include/asm/pgtable_32_types.h linux-2.6.39/arch/x86/include/asm/pgtable_32_types.h
10353 --- linux-2.6.39/arch/x86/include/asm/pgtable_32_types.h 2011-05-19 00:06:34.000000000 -0400
10354 +++ linux-2.6.39/arch/x86/include/asm/pgtable_32_types.h 2011-05-22 19:36:30.000000000 -0400
10355 @@ -8,7 +8,7 @@
10356 */
10357 #ifdef CONFIG_X86_PAE
10358 # include <asm/pgtable-3level_types.h>
10359 -# define PMD_SIZE (1UL << PMD_SHIFT)
10360 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
10361 # define PMD_MASK (~(PMD_SIZE - 1))
10362 #else
10363 # include <asm/pgtable-2level_types.h>
10364 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set
10365 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
10366 #endif
10367
10368 +#ifdef CONFIG_PAX_KERNEXEC
10369 +#ifndef __ASSEMBLY__
10370 +extern unsigned char MODULES_EXEC_VADDR[];
10371 +extern unsigned char MODULES_EXEC_END[];
10372 +#endif
10373 +#include <asm/boot.h>
10374 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
10375 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
10376 +#else
10377 +#define ktla_ktva(addr) (addr)
10378 +#define ktva_ktla(addr) (addr)
10379 +#endif
10380 +
10381 #define MODULES_VADDR VMALLOC_START
10382 #define MODULES_END VMALLOC_END
10383 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
10384 diff -urNp linux-2.6.39/arch/x86/include/asm/pgtable-3level.h linux-2.6.39/arch/x86/include/asm/pgtable-3level.h
10385 --- linux-2.6.39/arch/x86/include/asm/pgtable-3level.h 2011-05-19 00:06:34.000000000 -0400
10386 +++ linux-2.6.39/arch/x86/include/asm/pgtable-3level.h 2011-05-22 19:36:30.000000000 -0400
10387 @@ -38,12 +38,16 @@ static inline void native_set_pte_atomic
10388
10389 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
10390 {
10391 + pax_open_kernel();
10392 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
10393 + pax_close_kernel();
10394 }
10395
10396 static inline void native_set_pud(pud_t *pudp, pud_t pud)
10397 {
10398 + pax_open_kernel();
10399 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
10400 + pax_close_kernel();
10401 }
10402
10403 /*
10404 diff -urNp linux-2.6.39/arch/x86/include/asm/pgtable_64.h linux-2.6.39/arch/x86/include/asm/pgtable_64.h
10405 --- linux-2.6.39/arch/x86/include/asm/pgtable_64.h 2011-05-19 00:06:34.000000000 -0400
10406 +++ linux-2.6.39/arch/x86/include/asm/pgtable_64.h 2011-05-22 19:36:30.000000000 -0400
10407 @@ -16,10 +16,13 @@
10408
10409 extern pud_t level3_kernel_pgt[512];
10410 extern pud_t level3_ident_pgt[512];
10411 +extern pud_t level3_vmalloc_pgt[512];
10412 +extern pud_t level3_vmemmap_pgt[512];
10413 +extern pud_t level2_vmemmap_pgt[512];
10414 extern pmd_t level2_kernel_pgt[512];
10415 extern pmd_t level2_fixmap_pgt[512];
10416 -extern pmd_t level2_ident_pgt[512];
10417 -extern pgd_t init_level4_pgt[];
10418 +extern pmd_t level2_ident_pgt[512*2];
10419 +extern pgd_t init_level4_pgt[512];
10420
10421 #define swapper_pg_dir init_level4_pgt
10422
10423 @@ -61,7 +64,9 @@ static inline void native_set_pte_atomic
10424
10425 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
10426 {
10427 + pax_open_kernel();
10428 *pmdp = pmd;
10429 + pax_close_kernel();
10430 }
10431
10432 static inline void native_pmd_clear(pmd_t *pmd)
10433 @@ -107,7 +112,9 @@ static inline void native_pud_clear(pud_
10434
10435 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
10436 {
10437 + pax_open_kernel();
10438 *pgdp = pgd;
10439 + pax_close_kernel();
10440 }
10441
10442 static inline void native_pgd_clear(pgd_t *pgd)
10443 diff -urNp linux-2.6.39/arch/x86/include/asm/pgtable_64_types.h linux-2.6.39/arch/x86/include/asm/pgtable_64_types.h
10444 --- linux-2.6.39/arch/x86/include/asm/pgtable_64_types.h 2011-05-19 00:06:34.000000000 -0400
10445 +++ linux-2.6.39/arch/x86/include/asm/pgtable_64_types.h 2011-05-22 19:36:30.000000000 -0400
10446 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
10447 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
10448 #define MODULES_END _AC(0xffffffffff000000, UL)
10449 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
10450 +#define MODULES_EXEC_VADDR MODULES_VADDR
10451 +#define MODULES_EXEC_END MODULES_END
10452 +
10453 +#define ktla_ktva(addr) (addr)
10454 +#define ktva_ktla(addr) (addr)
10455
10456 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
10457 diff -urNp linux-2.6.39/arch/x86/include/asm/pgtable.h linux-2.6.39/arch/x86/include/asm/pgtable.h
10458 --- linux-2.6.39/arch/x86/include/asm/pgtable.h 2011-05-19 00:06:34.000000000 -0400
10459 +++ linux-2.6.39/arch/x86/include/asm/pgtable.h 2011-05-22 19:36:30.000000000 -0400
10460 @@ -81,12 +81,51 @@ extern struct mm_struct *pgd_page_get_mm
10461
10462 #define arch_end_context_switch(prev) do {} while(0)
10463
10464 +#define pax_open_kernel() native_pax_open_kernel()
10465 +#define pax_close_kernel() native_pax_close_kernel()
10466 #endif /* CONFIG_PARAVIRT */
10467
10468 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
10469 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
10470 +
10471 +#ifdef CONFIG_PAX_KERNEXEC
10472 +static inline unsigned long native_pax_open_kernel(void)
10473 +{
10474 + unsigned long cr0;
10475 +
10476 + preempt_disable();
10477 + barrier();
10478 + cr0 = read_cr0() ^ X86_CR0_WP;
10479 + BUG_ON(unlikely(cr0 & X86_CR0_WP));
10480 + write_cr0(cr0);
10481 + return cr0 ^ X86_CR0_WP;
10482 +}
10483 +
10484 +static inline unsigned long native_pax_close_kernel(void)
10485 +{
10486 + unsigned long cr0;
10487 +
10488 + cr0 = read_cr0() ^ X86_CR0_WP;
10489 + BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
10490 + write_cr0(cr0);
10491 + barrier();
10492 + preempt_enable_no_resched();
10493 + return cr0 ^ X86_CR0_WP;
10494 +}
10495 +#else
10496 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
10497 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
10498 +#endif
10499 +
10500 /*
10501 * The following only work if pte_present() is true.
10502 * Undefined behaviour if not..
10503 */
10504 +static inline int pte_user(pte_t pte)
10505 +{
10506 + return pte_val(pte) & _PAGE_USER;
10507 +}
10508 +
10509 static inline int pte_dirty(pte_t pte)
10510 {
10511 return pte_flags(pte) & _PAGE_DIRTY;
10512 @@ -196,9 +235,29 @@ static inline pte_t pte_wrprotect(pte_t
10513 return pte_clear_flags(pte, _PAGE_RW);
10514 }
10515
10516 +static inline pte_t pte_mkread(pte_t pte)
10517 +{
10518 + return __pte(pte_val(pte) | _PAGE_USER);
10519 +}
10520 +
10521 static inline pte_t pte_mkexec(pte_t pte)
10522 {
10523 - return pte_clear_flags(pte, _PAGE_NX);
10524 +#ifdef CONFIG_X86_PAE
10525 + if (__supported_pte_mask & _PAGE_NX)
10526 + return pte_clear_flags(pte, _PAGE_NX);
10527 + else
10528 +#endif
10529 + return pte_set_flags(pte, _PAGE_USER);
10530 +}
10531 +
10532 +static inline pte_t pte_exprotect(pte_t pte)
10533 +{
10534 +#ifdef CONFIG_X86_PAE
10535 + if (__supported_pte_mask & _PAGE_NX)
10536 + return pte_set_flags(pte, _PAGE_NX);
10537 + else
10538 +#endif
10539 + return pte_clear_flags(pte, _PAGE_USER);
10540 }
10541
10542 static inline pte_t pte_mkdirty(pte_t pte)
10543 @@ -390,6 +449,15 @@ pte_t *populate_extra_pte(unsigned long
10544 #endif
10545
10546 #ifndef __ASSEMBLY__
10547 +
10548 +#ifdef CONFIG_PAX_PER_CPU_PGD
10549 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
10550 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
10551 +{
10552 + return cpu_pgd[cpu];
10553 +}
10554 +#endif
10555 +
10556 #include <linux/mm_types.h>
10557
10558 static inline int pte_none(pte_t pte)
10559 @@ -560,7 +628,7 @@ static inline pud_t *pud_offset(pgd_t *p
10560
10561 static inline int pgd_bad(pgd_t pgd)
10562 {
10563 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
10564 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
10565 }
10566
10567 static inline int pgd_none(pgd_t pgd)
10568 @@ -583,7 +651,12 @@ static inline int pgd_none(pgd_t pgd)
10569 * pgd_offset() returns a (pgd_t *)
10570 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
10571 */
10572 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
10573 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
10574 +
10575 +#ifdef CONFIG_PAX_PER_CPU_PGD
10576 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
10577 +#endif
10578 +
10579 /*
10580 * a shortcut which implies the use of the kernel's pgd, instead
10581 * of a process's
10582 @@ -594,6 +667,20 @@ static inline int pgd_none(pgd_t pgd)
10583 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
10584 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
10585
10586 +#ifdef CONFIG_X86_32
10587 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
10588 +#else
10589 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
10590 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
10591 +
10592 +#ifdef CONFIG_PAX_MEMORY_UDEREF
10593 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
10594 +#else
10595 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
10596 +#endif
10597 +
10598 +#endif
10599 +
10600 #ifndef __ASSEMBLY__
10601
10602 extern int direct_gbpages;
10603 @@ -758,11 +845,23 @@ static inline void pmdp_set_wrprotect(st
10604 * dst and src can be on the same page, but the range must not overlap,
10605 * and must not cross a page boundary.
10606 */
10607 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
10608 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
10609 {
10610 - memcpy(dst, src, count * sizeof(pgd_t));
10611 + pax_open_kernel();
10612 + while (count--)
10613 + *dst++ = *src++;
10614 + pax_close_kernel();
10615 }
10616
10617 +#ifdef CONFIG_PAX_PER_CPU_PGD
10618 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count);
10619 +#endif
10620 +
10621 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10622 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count);
10623 +#else
10624 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count) {}
10625 +#endif
10626
10627 #include <asm-generic/pgtable.h>
10628 #endif /* __ASSEMBLY__ */
10629 diff -urNp linux-2.6.39/arch/x86/include/asm/pgtable_types.h linux-2.6.39/arch/x86/include/asm/pgtable_types.h
10630 --- linux-2.6.39/arch/x86/include/asm/pgtable_types.h 2011-05-19 00:06:34.000000000 -0400
10631 +++ linux-2.6.39/arch/x86/include/asm/pgtable_types.h 2011-05-22 19:36:30.000000000 -0400
10632 @@ -16,13 +16,12 @@
10633 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
10634 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
10635 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
10636 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
10637 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
10638 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
10639 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
10640 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
10641 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
10642 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
10643 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
10644 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
10645 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
10646 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
10647
10648 /* If _PAGE_BIT_PRESENT is clear, we use these: */
10649 @@ -40,7 +39,6 @@
10650 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
10651 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
10652 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
10653 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
10654 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
10655 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
10656 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
10657 @@ -57,8 +55,10 @@
10658
10659 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
10660 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
10661 -#else
10662 +#elif defined(CONFIG_KMEMCHECK)
10663 #define _PAGE_NX (_AT(pteval_t, 0))
10664 +#else
10665 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
10666 #endif
10667
10668 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
10669 @@ -96,6 +96,9 @@
10670 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
10671 _PAGE_ACCESSED)
10672
10673 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
10674 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
10675 +
10676 #define __PAGE_KERNEL_EXEC \
10677 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
10678 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
10679 @@ -106,8 +109,8 @@
10680 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
10681 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
10682 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
10683 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
10684 -#define __PAGE_KERNEL_VSYSCALL_NOCACHE (__PAGE_KERNEL_VSYSCALL | _PAGE_PCD | _PAGE_PWT)
10685 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
10686 +#define __PAGE_KERNEL_VSYSCALL_NOCACHE (__PAGE_KERNEL_RO | _PAGE_PCD | _PAGE_PWT | _PAGE_USER)
10687 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
10688 #define __PAGE_KERNEL_LARGE_NOCACHE (__PAGE_KERNEL | _PAGE_CACHE_UC | _PAGE_PSE)
10689 #define __PAGE_KERNEL_LARGE_EXEC (__PAGE_KERNEL_EXEC | _PAGE_PSE)
10690 @@ -166,8 +169,8 @@
10691 * bits are combined, this will alow user to access the high address mapped
10692 * VDSO in the presence of CONFIG_COMPAT_VDSO
10693 */
10694 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
10695 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
10696 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
10697 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
10698 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
10699 #endif
10700
10701 @@ -205,7 +208,17 @@ static inline pgdval_t pgd_flags(pgd_t p
10702 {
10703 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
10704 }
10705 +#endif
10706
10707 +#if PAGETABLE_LEVELS == 3
10708 +#include <asm-generic/pgtable-nopud.h>
10709 +#endif
10710 +
10711 +#if PAGETABLE_LEVELS == 2
10712 +#include <asm-generic/pgtable-nopmd.h>
10713 +#endif
10714 +
10715 +#ifndef __ASSEMBLY__
10716 #if PAGETABLE_LEVELS > 3
10717 typedef struct { pudval_t pud; } pud_t;
10718
10719 @@ -219,8 +232,6 @@ static inline pudval_t native_pud_val(pu
10720 return pud.pud;
10721 }
10722 #else
10723 -#include <asm-generic/pgtable-nopud.h>
10724 -
10725 static inline pudval_t native_pud_val(pud_t pud)
10726 {
10727 return native_pgd_val(pud.pgd);
10728 @@ -240,8 +251,6 @@ static inline pmdval_t native_pmd_val(pm
10729 return pmd.pmd;
10730 }
10731 #else
10732 -#include <asm-generic/pgtable-nopmd.h>
10733 -
10734 static inline pmdval_t native_pmd_val(pmd_t pmd)
10735 {
10736 return native_pgd_val(pmd.pud.pgd);
10737 @@ -281,7 +290,6 @@ typedef struct page *pgtable_t;
10738
10739 extern pteval_t __supported_pte_mask;
10740 extern void set_nx(void);
10741 -extern int nx_enabled;
10742
10743 #define pgprot_writecombine pgprot_writecombine
10744 extern pgprot_t pgprot_writecombine(pgprot_t prot);
10745 diff -urNp linux-2.6.39/arch/x86/include/asm/processor.h linux-2.6.39/arch/x86/include/asm/processor.h
10746 --- linux-2.6.39/arch/x86/include/asm/processor.h 2011-05-19 00:06:34.000000000 -0400
10747 +++ linux-2.6.39/arch/x86/include/asm/processor.h 2011-05-22 19:36:30.000000000 -0400
10748 @@ -266,7 +266,7 @@ struct tss_struct {
10749
10750 } ____cacheline_aligned;
10751
10752 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
10753 +extern struct tss_struct init_tss[NR_CPUS];
10754
10755 /*
10756 * Save the original ist values for checking stack pointers during debugging
10757 @@ -860,11 +860,18 @@ static inline void spin_lock_prefetch(co
10758 */
10759 #define TASK_SIZE PAGE_OFFSET
10760 #define TASK_SIZE_MAX TASK_SIZE
10761 +
10762 +#ifdef CONFIG_PAX_SEGMEXEC
10763 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
10764 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
10765 +#else
10766 #define STACK_TOP TASK_SIZE
10767 -#define STACK_TOP_MAX STACK_TOP
10768 +#endif
10769 +
10770 +#define STACK_TOP_MAX TASK_SIZE
10771
10772 #define INIT_THREAD { \
10773 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
10774 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
10775 .vm86_info = NULL, \
10776 .sysenter_cs = __KERNEL_CS, \
10777 .io_bitmap_ptr = NULL, \
10778 @@ -878,7 +885,7 @@ static inline void spin_lock_prefetch(co
10779 */
10780 #define INIT_TSS { \
10781 .x86_tss = { \
10782 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
10783 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
10784 .ss0 = __KERNEL_DS, \
10785 .ss1 = __KERNEL_CS, \
10786 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
10787 @@ -889,11 +896,7 @@ static inline void spin_lock_prefetch(co
10788 extern unsigned long thread_saved_pc(struct task_struct *tsk);
10789
10790 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
10791 -#define KSTK_TOP(info) \
10792 -({ \
10793 - unsigned long *__ptr = (unsigned long *)(info); \
10794 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
10795 -})
10796 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
10797
10798 /*
10799 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
10800 @@ -908,7 +911,7 @@ extern unsigned long thread_saved_pc(str
10801 #define task_pt_regs(task) \
10802 ({ \
10803 struct pt_regs *__regs__; \
10804 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
10805 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
10806 __regs__ - 1; \
10807 })
10808
10809 @@ -918,13 +921,13 @@ extern unsigned long thread_saved_pc(str
10810 /*
10811 * User space process size. 47bits minus one guard page.
10812 */
10813 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
10814 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
10815
10816 /* This decides where the kernel will search for a free chunk of vm
10817 * space during mmap's.
10818 */
10819 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
10820 - 0xc0000000 : 0xFFFFe000)
10821 + 0xc0000000 : 0xFFFFf000)
10822
10823 #define TASK_SIZE (test_thread_flag(TIF_IA32) ? \
10824 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
10825 @@ -935,11 +938,11 @@ extern unsigned long thread_saved_pc(str
10826 #define STACK_TOP_MAX TASK_SIZE_MAX
10827
10828 #define INIT_THREAD { \
10829 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
10830 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
10831 }
10832
10833 #define INIT_TSS { \
10834 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
10835 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
10836 }
10837
10838 /*
10839 @@ -961,6 +964,10 @@ extern void start_thread(struct pt_regs
10840 */
10841 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
10842
10843 +#ifdef CONFIG_PAX_SEGMEXEC
10844 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
10845 +#endif
10846 +
10847 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
10848
10849 /* Get/set a process' ability to use the timestamp counter instruction */
10850 diff -urNp linux-2.6.39/arch/x86/include/asm/ptrace.h linux-2.6.39/arch/x86/include/asm/ptrace.h
10851 --- linux-2.6.39/arch/x86/include/asm/ptrace.h 2011-05-19 00:06:34.000000000 -0400
10852 +++ linux-2.6.39/arch/x86/include/asm/ptrace.h 2011-05-22 19:36:30.000000000 -0400
10853 @@ -152,28 +152,29 @@ static inline unsigned long regs_return_
10854 }
10855
10856 /*
10857 - * user_mode_vm(regs) determines whether a register set came from user mode.
10858 + * user_mode(regs) determines whether a register set came from user mode.
10859 * This is true if V8086 mode was enabled OR if the register set was from
10860 * protected mode with RPL-3 CS value. This tricky test checks that with
10861 * one comparison. Many places in the kernel can bypass this full check
10862 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
10863 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
10864 + * be used.
10865 */
10866 -static inline int user_mode(struct pt_regs *regs)
10867 +static inline int user_mode_novm(struct pt_regs *regs)
10868 {
10869 #ifdef CONFIG_X86_32
10870 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
10871 #else
10872 - return !!(regs->cs & 3);
10873 + return !!(regs->cs & SEGMENT_RPL_MASK);
10874 #endif
10875 }
10876
10877 -static inline int user_mode_vm(struct pt_regs *regs)
10878 +static inline int user_mode(struct pt_regs *regs)
10879 {
10880 #ifdef CONFIG_X86_32
10881 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
10882 USER_RPL;
10883 #else
10884 - return user_mode(regs);
10885 + return user_mode_novm(regs);
10886 #endif
10887 }
10888
10889 diff -urNp linux-2.6.39/arch/x86/include/asm/reboot.h linux-2.6.39/arch/x86/include/asm/reboot.h
10890 --- linux-2.6.39/arch/x86/include/asm/reboot.h 2011-05-19 00:06:34.000000000 -0400
10891 +++ linux-2.6.39/arch/x86/include/asm/reboot.h 2011-05-22 19:36:30.000000000 -0400
10892 @@ -6,19 +6,19 @@
10893 struct pt_regs;
10894
10895 struct machine_ops {
10896 - void (*restart)(char *cmd);
10897 - void (*halt)(void);
10898 - void (*power_off)(void);
10899 + void (* __noreturn restart)(char *cmd);
10900 + void (* __noreturn halt)(void);
10901 + void (* __noreturn power_off)(void);
10902 void (*shutdown)(void);
10903 void (*crash_shutdown)(struct pt_regs *);
10904 - void (*emergency_restart)(void);
10905 + void (* __noreturn emergency_restart)(void);
10906 };
10907
10908 extern struct machine_ops machine_ops;
10909
10910 void native_machine_crash_shutdown(struct pt_regs *regs);
10911 void native_machine_shutdown(void);
10912 -void machine_real_restart(unsigned int type);
10913 +void machine_real_restart(unsigned int type) __noreturn;
10914 /* These must match dispatch_table in reboot_32.S */
10915 #define MRR_BIOS 0
10916 #define MRR_APM 1
10917 diff -urNp linux-2.6.39/arch/x86/include/asm/rwsem.h linux-2.6.39/arch/x86/include/asm/rwsem.h
10918 --- linux-2.6.39/arch/x86/include/asm/rwsem.h 2011-05-19 00:06:34.000000000 -0400
10919 +++ linux-2.6.39/arch/x86/include/asm/rwsem.h 2011-05-22 19:36:30.000000000 -0400
10920 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw
10921 {
10922 asm volatile("# beginning down_read\n\t"
10923 LOCK_PREFIX _ASM_INC "(%1)\n\t"
10924 +
10925 +#ifdef CONFIG_PAX_REFCOUNT
10926 + "jno 0f\n"
10927 + LOCK_PREFIX _ASM_DEC "(%1)\n"
10928 + "int $4\n0:\n"
10929 + _ASM_EXTABLE(0b, 0b)
10930 +#endif
10931 +
10932 /* adds 0x00000001 */
10933 " jns 1f\n"
10934 " call call_rwsem_down_read_failed\n"
10935 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(st
10936 "1:\n\t"
10937 " mov %1,%2\n\t"
10938 " add %3,%2\n\t"
10939 +
10940 +#ifdef CONFIG_PAX_REFCOUNT
10941 + "jno 0f\n"
10942 + "sub %3,%2\n"
10943 + "int $4\n0:\n"
10944 + _ASM_EXTABLE(0b, 0b)
10945 +#endif
10946 +
10947 " jle 2f\n\t"
10948 LOCK_PREFIX " cmpxchg %2,%0\n\t"
10949 " jnz 1b\n\t"
10950 @@ -104,6 +120,14 @@ static inline void __down_write_nested(s
10951 long tmp;
10952 asm volatile("# beginning down_write\n\t"
10953 LOCK_PREFIX " xadd %1,(%2)\n\t"
10954 +
10955 +#ifdef CONFIG_PAX_REFCOUNT
10956 + "jno 0f\n"
10957 + "mov %1,(%2)\n"
10958 + "int $4\n0:\n"
10959 + _ASM_EXTABLE(0b, 0b)
10960 +#endif
10961 +
10962 /* adds 0xffff0001, returns the old value */
10963 " test %1,%1\n\t"
10964 /* was the count 0 before? */
10965 @@ -141,6 +165,14 @@ static inline void __up_read(struct rw_s
10966 long tmp;
10967 asm volatile("# beginning __up_read\n\t"
10968 LOCK_PREFIX " xadd %1,(%2)\n\t"
10969 +
10970 +#ifdef CONFIG_PAX_REFCOUNT
10971 + "jno 0f\n"
10972 + "mov %1,(%2)\n"
10973 + "int $4\n0:\n"
10974 + _ASM_EXTABLE(0b, 0b)
10975 +#endif
10976 +
10977 /* subtracts 1, returns the old value */
10978 " jns 1f\n\t"
10979 " call call_rwsem_wake\n" /* expects old value in %edx */
10980 @@ -159,6 +191,14 @@ static inline void __up_write(struct rw_
10981 long tmp;
10982 asm volatile("# beginning __up_write\n\t"
10983 LOCK_PREFIX " xadd %1,(%2)\n\t"
10984 +
10985 +#ifdef CONFIG_PAX_REFCOUNT
10986 + "jno 0f\n"
10987 + "mov %1,(%2)\n"
10988 + "int $4\n0:\n"
10989 + _ASM_EXTABLE(0b, 0b)
10990 +#endif
10991 +
10992 /* subtracts 0xffff0001, returns the old value */
10993 " jns 1f\n\t"
10994 " call call_rwsem_wake\n" /* expects old value in %edx */
10995 @@ -176,6 +216,14 @@ static inline void __downgrade_write(str
10996 {
10997 asm volatile("# beginning __downgrade_write\n\t"
10998 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
10999 +
11000 +#ifdef CONFIG_PAX_REFCOUNT
11001 + "jno 0f\n"
11002 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
11003 + "int $4\n0:\n"
11004 + _ASM_EXTABLE(0b, 0b)
11005 +#endif
11006 +
11007 /*
11008 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
11009 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
11010 @@ -194,7 +242,15 @@ static inline void __downgrade_write(str
11011 */
11012 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
11013 {
11014 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
11015 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
11016 +
11017 +#ifdef CONFIG_PAX_REFCOUNT
11018 + "jno 0f\n"
11019 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
11020 + "int $4\n0:\n"
11021 + _ASM_EXTABLE(0b, 0b)
11022 +#endif
11023 +
11024 : "+m" (sem->count)
11025 : "er" (delta));
11026 }
11027 @@ -206,7 +262,15 @@ static inline long rwsem_atomic_update(l
11028 {
11029 long tmp = delta;
11030
11031 - asm volatile(LOCK_PREFIX "xadd %0,%1"
11032 + asm volatile(LOCK_PREFIX "xadd %0,%1\n"
11033 +
11034 +#ifdef CONFIG_PAX_REFCOUNT
11035 + "jno 0f\n"
11036 + "mov %0,%1\n"
11037 + "int $4\n0:\n"
11038 + _ASM_EXTABLE(0b, 0b)
11039 +#endif
11040 +
11041 : "+r" (tmp), "+m" (sem->count)
11042 : : "memory");
11043
11044 diff -urNp linux-2.6.39/arch/x86/include/asm/segment.h linux-2.6.39/arch/x86/include/asm/segment.h
11045 --- linux-2.6.39/arch/x86/include/asm/segment.h 2011-05-19 00:06:34.000000000 -0400
11046 +++ linux-2.6.39/arch/x86/include/asm/segment.h 2011-05-22 19:36:30.000000000 -0400
11047 @@ -64,8 +64,8 @@
11048 * 26 - ESPFIX small SS
11049 * 27 - per-cpu [ offset to per-cpu data area ]
11050 * 28 - stack_canary-20 [ for stack protector ]
11051 - * 29 - unused
11052 - * 30 - unused
11053 + * 29 - PCI BIOS CS
11054 + * 30 - PCI BIOS DS
11055 * 31 - TSS for double fault handler
11056 */
11057 #define GDT_ENTRY_TLS_MIN 6
11058 @@ -79,6 +79,8 @@
11059
11060 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
11061
11062 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
11063 +
11064 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
11065
11066 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
11067 @@ -104,6 +106,12 @@
11068 #define __KERNEL_STACK_CANARY 0
11069 #endif
11070
11071 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
11072 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
11073 +
11074 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
11075 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
11076 +
11077 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
11078
11079 /*
11080 @@ -141,7 +149,7 @@
11081 */
11082
11083 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
11084 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
11085 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
11086
11087
11088 #else
11089 @@ -165,6 +173,8 @@
11090 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS * 8 + 3)
11091 #define __USER32_DS __USER_DS
11092
11093 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
11094 +
11095 #define GDT_ENTRY_TSS 8 /* needs two entries */
11096 #define GDT_ENTRY_LDT 10 /* needs two entries */
11097 #define GDT_ENTRY_TLS_MIN 12
11098 @@ -185,6 +195,7 @@
11099 #endif
11100
11101 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
11102 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
11103 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
11104 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
11105 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
11106 diff -urNp linux-2.6.39/arch/x86/include/asm/smp.h linux-2.6.39/arch/x86/include/asm/smp.h
11107 --- linux-2.6.39/arch/x86/include/asm/smp.h 2011-05-19 00:06:34.000000000 -0400
11108 +++ linux-2.6.39/arch/x86/include/asm/smp.h 2011-05-22 19:36:30.000000000 -0400
11109 @@ -36,7 +36,7 @@ DECLARE_PER_CPU(cpumask_var_t, cpu_core_
11110 /* cpus sharing the last level cache: */
11111 DECLARE_PER_CPU(cpumask_var_t, cpu_llc_shared_map);
11112 DECLARE_PER_CPU(u16, cpu_llc_id);
11113 -DECLARE_PER_CPU(int, cpu_number);
11114 +DECLARE_PER_CPU(unsigned int, cpu_number);
11115
11116 static inline struct cpumask *cpu_sibling_mask(int cpu)
11117 {
11118 @@ -192,14 +192,8 @@ extern unsigned disabled_cpus __cpuinitd
11119 extern int safe_smp_processor_id(void);
11120
11121 #elif defined(CONFIG_X86_64_SMP)
11122 -#define raw_smp_processor_id() (percpu_read(cpu_number))
11123 -
11124 -#define stack_smp_processor_id() \
11125 -({ \
11126 - struct thread_info *ti; \
11127 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
11128 - ti->cpu; \
11129 -})
11130 +#define raw_smp_processor_id() (percpu_read(cpu_number))
11131 +#define stack_smp_processor_id() raw_smp_processor_id()
11132 #define safe_smp_processor_id() smp_processor_id()
11133
11134 #endif
11135 diff -urNp linux-2.6.39/arch/x86/include/asm/spinlock.h linux-2.6.39/arch/x86/include/asm/spinlock.h
11136 --- linux-2.6.39/arch/x86/include/asm/spinlock.h 2011-05-19 00:06:34.000000000 -0400
11137 +++ linux-2.6.39/arch/x86/include/asm/spinlock.h 2011-05-22 19:36:30.000000000 -0400
11138 @@ -249,6 +249,14 @@ static inline int arch_write_can_lock(ar
11139 static inline void arch_read_lock(arch_rwlock_t *rw)
11140 {
11141 asm volatile(LOCK_PREFIX " subl $1,(%0)\n\t"
11142 +
11143 +#ifdef CONFIG_PAX_REFCOUNT
11144 + "jno 0f\n"
11145 + LOCK_PREFIX " addl $1,(%0)\n"
11146 + "int $4\n0:\n"
11147 + _ASM_EXTABLE(0b, 0b)
11148 +#endif
11149 +
11150 "jns 1f\n"
11151 "call __read_lock_failed\n\t"
11152 "1:\n"
11153 @@ -258,6 +266,14 @@ static inline void arch_read_lock(arch_r
11154 static inline void arch_write_lock(arch_rwlock_t *rw)
11155 {
11156 asm volatile(LOCK_PREFIX " subl %1,(%0)\n\t"
11157 +
11158 +#ifdef CONFIG_PAX_REFCOUNT
11159 + "jno 0f\n"
11160 + LOCK_PREFIX " addl %1,(%0)\n"
11161 + "int $4\n0:\n"
11162 + _ASM_EXTABLE(0b, 0b)
11163 +#endif
11164 +
11165 "jz 1f\n"
11166 "call __write_lock_failed\n\t"
11167 "1:\n"
11168 @@ -286,12 +302,29 @@ static inline int arch_write_trylock(arc
11169
11170 static inline void arch_read_unlock(arch_rwlock_t *rw)
11171 {
11172 - asm volatile(LOCK_PREFIX "incl %0" :"+m" (rw->lock) : : "memory");
11173 + asm volatile(LOCK_PREFIX "incl %0\n"
11174 +
11175 +#ifdef CONFIG_PAX_REFCOUNT
11176 + "jno 0f\n"
11177 + LOCK_PREFIX "decl %0\n"
11178 + "int $4\n0:\n"
11179 + _ASM_EXTABLE(0b, 0b)
11180 +#endif
11181 +
11182 + :"+m" (rw->lock) : : "memory");
11183 }
11184
11185 static inline void arch_write_unlock(arch_rwlock_t *rw)
11186 {
11187 - asm volatile(LOCK_PREFIX "addl %1, %0"
11188 + asm volatile(LOCK_PREFIX "addl %1, %0\n"
11189 +
11190 +#ifdef CONFIG_PAX_REFCOUNT
11191 + "jno 0f\n"
11192 + LOCK_PREFIX "subl %1, %0\n"
11193 + "int $4\n0:\n"
11194 + _ASM_EXTABLE(0b, 0b)
11195 +#endif
11196 +
11197 : "+m" (rw->lock) : "i" (RW_LOCK_BIAS) : "memory");
11198 }
11199
11200 diff -urNp linux-2.6.39/arch/x86/include/asm/stackprotector.h linux-2.6.39/arch/x86/include/asm/stackprotector.h
11201 --- linux-2.6.39/arch/x86/include/asm/stackprotector.h 2011-05-19 00:06:34.000000000 -0400
11202 +++ linux-2.6.39/arch/x86/include/asm/stackprotector.h 2011-05-22 19:36:30.000000000 -0400
11203 @@ -113,7 +113,7 @@ static inline void setup_stack_canary_se
11204
11205 static inline void load_stack_canary_segment(void)
11206 {
11207 -#ifdef CONFIG_X86_32
11208 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
11209 asm volatile ("mov %0, %%gs" : : "r" (0));
11210 #endif
11211 }
11212 diff -urNp linux-2.6.39/arch/x86/include/asm/stacktrace.h linux-2.6.39/arch/x86/include/asm/stacktrace.h
11213 --- linux-2.6.39/arch/x86/include/asm/stacktrace.h 2011-05-19 00:06:34.000000000 -0400
11214 +++ linux-2.6.39/arch/x86/include/asm/stacktrace.h 2011-05-22 19:36:30.000000000 -0400
11215 @@ -11,28 +11,20 @@
11216
11217 extern int kstack_depth_to_print;
11218
11219 -struct thread_info;
11220 +struct task_struct;
11221 struct stacktrace_ops;
11222
11223 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
11224 - unsigned long *stack,
11225 - unsigned long bp,
11226 - const struct stacktrace_ops *ops,
11227 - void *data,
11228 - unsigned long *end,
11229 - int *graph);
11230 -
11231 -extern unsigned long
11232 -print_context_stack(struct thread_info *tinfo,
11233 - unsigned long *stack, unsigned long bp,
11234 - const struct stacktrace_ops *ops, void *data,
11235 - unsigned long *end, int *graph);
11236 -
11237 -extern unsigned long
11238 -print_context_stack_bp(struct thread_info *tinfo,
11239 - unsigned long *stack, unsigned long bp,
11240 - const struct stacktrace_ops *ops, void *data,
11241 - unsigned long *end, int *graph);
11242 +typedef unsigned long walk_stack_t(struct task_struct *task,
11243 + void *stack_start,
11244 + unsigned long *stack,
11245 + unsigned long bp,
11246 + const struct stacktrace_ops *ops,
11247 + void *data,
11248 + unsigned long *end,
11249 + int *graph);
11250 +
11251 +extern walk_stack_t print_context_stack;
11252 +extern walk_stack_t print_context_stack_bp;
11253
11254 /* Generic stack tracer with callbacks */
11255
11256 @@ -43,7 +35,7 @@ struct stacktrace_ops {
11257 void (*address)(void *data, unsigned long address, int reliable);
11258 /* On negative return stop dumping */
11259 int (*stack)(void *data, char *name);
11260 - walk_stack_t walk_stack;
11261 + walk_stack_t *walk_stack;
11262 };
11263
11264 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
11265 diff -urNp linux-2.6.39/arch/x86/include/asm/system.h linux-2.6.39/arch/x86/include/asm/system.h
11266 --- linux-2.6.39/arch/x86/include/asm/system.h 2011-05-19 00:06:34.000000000 -0400
11267 +++ linux-2.6.39/arch/x86/include/asm/system.h 2011-05-22 19:36:30.000000000 -0400
11268 @@ -129,7 +129,7 @@ do { \
11269 "call __switch_to\n\t" \
11270 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
11271 __switch_canary \
11272 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
11273 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
11274 "movq %%rax,%%rdi\n\t" \
11275 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
11276 "jnz ret_from_fork\n\t" \
11277 @@ -140,7 +140,7 @@ do { \
11278 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
11279 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
11280 [_tif_fork] "i" (_TIF_FORK), \
11281 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
11282 + [thread_info] "m" (current_tinfo), \
11283 [current_task] "m" (current_task) \
11284 __switch_canary_iparam \
11285 : "memory", "cc" __EXTRA_CLOBBER)
11286 @@ -200,7 +200,7 @@ static inline unsigned long get_limit(un
11287 {
11288 unsigned long __limit;
11289 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
11290 - return __limit + 1;
11291 + return __limit;
11292 }
11293
11294 static inline void native_clts(void)
11295 @@ -340,12 +340,12 @@ void enable_hlt(void);
11296
11297 void cpu_idle_wait(void);
11298
11299 -extern unsigned long arch_align_stack(unsigned long sp);
11300 +#define arch_align_stack(x) ((x) & ~0xfUL)
11301 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
11302
11303 void default_idle(void);
11304
11305 -void stop_this_cpu(void *dummy);
11306 +void stop_this_cpu(void *dummy) __noreturn;
11307
11308 /*
11309 * Force strict CPU ordering.
11310 diff -urNp linux-2.6.39/arch/x86/include/asm/thread_info.h linux-2.6.39/arch/x86/include/asm/thread_info.h
11311 --- linux-2.6.39/arch/x86/include/asm/thread_info.h 2011-05-19 00:06:34.000000000 -0400
11312 +++ linux-2.6.39/arch/x86/include/asm/thread_info.h 2011-05-22 19:36:30.000000000 -0400
11313 @@ -10,6 +10,7 @@
11314 #include <linux/compiler.h>
11315 #include <asm/page.h>
11316 #include <asm/types.h>
11317 +#include <asm/percpu.h>
11318
11319 /*
11320 * low level task data that entry.S needs immediate access to
11321 @@ -24,7 +25,6 @@ struct exec_domain;
11322 #include <asm/atomic.h>
11323
11324 struct thread_info {
11325 - struct task_struct *task; /* main task structure */
11326 struct exec_domain *exec_domain; /* execution domain */
11327 __u32 flags; /* low level flags */
11328 __u32 status; /* thread synchronous flags */
11329 @@ -34,18 +34,12 @@ struct thread_info {
11330 mm_segment_t addr_limit;
11331 struct restart_block restart_block;
11332 void __user *sysenter_return;
11333 -#ifdef CONFIG_X86_32
11334 - unsigned long previous_esp; /* ESP of the previous stack in
11335 - case of nested (IRQ) stacks
11336 - */
11337 - __u8 supervisor_stack[0];
11338 -#endif
11339 + unsigned long lowest_stack;
11340 int uaccess_err;
11341 };
11342
11343 -#define INIT_THREAD_INFO(tsk) \
11344 +#define INIT_THREAD_INFO \
11345 { \
11346 - .task = &tsk, \
11347 .exec_domain = &default_exec_domain, \
11348 .flags = 0, \
11349 .cpu = 0, \
11350 @@ -56,7 +50,7 @@ struct thread_info {
11351 }, \
11352 }
11353
11354 -#define init_thread_info (init_thread_union.thread_info)
11355 +#define init_thread_info (init_thread_union.stack)
11356 #define init_stack (init_thread_union.stack)
11357
11358 #else /* !__ASSEMBLY__ */
11359 @@ -170,6 +164,23 @@ struct thread_info {
11360 ret; \
11361 })
11362
11363 +#ifdef __ASSEMBLY__
11364 +/* how to get the thread information struct from ASM */
11365 +#define GET_THREAD_INFO(reg) \
11366 + mov PER_CPU_VAR(current_tinfo), reg
11367 +
11368 +/* use this one if reg already contains %esp */
11369 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
11370 +#else
11371 +/* how to get the thread information struct from C */
11372 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
11373 +
11374 +static __always_inline struct thread_info *current_thread_info(void)
11375 +{
11376 + return percpu_read_stable(current_tinfo);
11377 +}
11378 +#endif
11379 +
11380 #ifdef CONFIG_X86_32
11381
11382 #define STACK_WARN (THREAD_SIZE/8)
11383 @@ -180,35 +191,13 @@ struct thread_info {
11384 */
11385 #ifndef __ASSEMBLY__
11386
11387 -
11388 /* how to get the current stack pointer from C */
11389 register unsigned long current_stack_pointer asm("esp") __used;
11390
11391 -/* how to get the thread information struct from C */
11392 -static inline struct thread_info *current_thread_info(void)
11393 -{
11394 - return (struct thread_info *)
11395 - (current_stack_pointer & ~(THREAD_SIZE - 1));
11396 -}
11397 -
11398 -#else /* !__ASSEMBLY__ */
11399 -
11400 -/* how to get the thread information struct from ASM */
11401 -#define GET_THREAD_INFO(reg) \
11402 - movl $-THREAD_SIZE, reg; \
11403 - andl %esp, reg
11404 -
11405 -/* use this one if reg already contains %esp */
11406 -#define GET_THREAD_INFO_WITH_ESP(reg) \
11407 - andl $-THREAD_SIZE, reg
11408 -
11409 #endif
11410
11411 #else /* X86_32 */
11412
11413 -#include <asm/percpu.h>
11414 -#define KERNEL_STACK_OFFSET (5*8)
11415 -
11416 /*
11417 * macros/functions for gaining access to the thread information structure
11418 * preempt_count needs to be 1 initially, until the scheduler is functional.
11419 @@ -216,21 +205,8 @@ static inline struct thread_info *curren
11420 #ifndef __ASSEMBLY__
11421 DECLARE_PER_CPU(unsigned long, kernel_stack);
11422
11423 -static inline struct thread_info *current_thread_info(void)
11424 -{
11425 - struct thread_info *ti;
11426 - ti = (void *)(percpu_read_stable(kernel_stack) +
11427 - KERNEL_STACK_OFFSET - THREAD_SIZE);
11428 - return ti;
11429 -}
11430 -
11431 -#else /* !__ASSEMBLY__ */
11432 -
11433 -/* how to get the thread information struct from ASM */
11434 -#define GET_THREAD_INFO(reg) \
11435 - movq PER_CPU_VAR(kernel_stack),reg ; \
11436 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
11437 -
11438 +/* how to get the current stack pointer from C */
11439 +register unsigned long current_stack_pointer asm("rsp") __used;
11440 #endif
11441
11442 #endif /* !X86_32 */
11443 @@ -266,5 +242,16 @@ extern void arch_task_cache_init(void);
11444 extern void free_thread_info(struct thread_info *ti);
11445 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
11446 #define arch_task_cache_init arch_task_cache_init
11447 +
11448 +#define __HAVE_THREAD_FUNCTIONS
11449 +#define task_thread_info(task) (&(task)->tinfo)
11450 +#define task_stack_page(task) ((task)->stack)
11451 +#define setup_thread_stack(p, org) do {} while (0)
11452 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
11453 +
11454 +#define __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
11455 +extern struct task_struct *alloc_task_struct_node(int node);
11456 +extern void free_task_struct(struct task_struct *);
11457 +
11458 #endif
11459 #endif /* _ASM_X86_THREAD_INFO_H */
11460 diff -urNp linux-2.6.39/arch/x86/include/asm/uaccess_32.h linux-2.6.39/arch/x86/include/asm/uaccess_32.h
11461 --- linux-2.6.39/arch/x86/include/asm/uaccess_32.h 2011-05-19 00:06:34.000000000 -0400
11462 +++ linux-2.6.39/arch/x86/include/asm/uaccess_32.h 2011-05-22 19:36:30.000000000 -0400
11463 @@ -44,6 +44,11 @@ unsigned long __must_check __copy_from_u
11464 static __always_inline unsigned long __must_check
11465 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
11466 {
11467 + pax_track_stack();
11468 +
11469 + if ((long)n < 0)
11470 + return n;
11471 +
11472 if (__builtin_constant_p(n)) {
11473 unsigned long ret;
11474
11475 @@ -62,6 +67,8 @@ __copy_to_user_inatomic(void __user *to,
11476 return ret;
11477 }
11478 }
11479 + if (!__builtin_constant_p(n))
11480 + check_object_size(from, n, true);
11481 return __copy_to_user_ll(to, from, n);
11482 }
11483
11484 @@ -83,12 +90,16 @@ static __always_inline unsigned long __m
11485 __copy_to_user(void __user *to, const void *from, unsigned long n)
11486 {
11487 might_fault();
11488 +
11489 return __copy_to_user_inatomic(to, from, n);
11490 }
11491
11492 static __always_inline unsigned long
11493 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
11494 {
11495 + if ((long)n < 0)
11496 + return n;
11497 +
11498 /* Avoid zeroing the tail if the copy fails..
11499 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
11500 * but as the zeroing behaviour is only significant when n is not
11501 @@ -138,6 +149,12 @@ static __always_inline unsigned long
11502 __copy_from_user(void *to, const void __user *from, unsigned long n)
11503 {
11504 might_fault();
11505 +
11506 + pax_track_stack();
11507 +
11508 + if ((long)n < 0)
11509 + return n;
11510 +
11511 if (__builtin_constant_p(n)) {
11512 unsigned long ret;
11513
11514 @@ -153,6 +170,8 @@ __copy_from_user(void *to, const void __
11515 return ret;
11516 }
11517 }
11518 + if (!__builtin_constant_p(n))
11519 + check_object_size(to, n, false);
11520 return __copy_from_user_ll(to, from, n);
11521 }
11522
11523 @@ -160,6 +179,10 @@ static __always_inline unsigned long __c
11524 const void __user *from, unsigned long n)
11525 {
11526 might_fault();
11527 +
11528 + if ((long)n < 0)
11529 + return n;
11530 +
11531 if (__builtin_constant_p(n)) {
11532 unsigned long ret;
11533
11534 @@ -182,15 +205,19 @@ static __always_inline unsigned long
11535 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
11536 unsigned long n)
11537 {
11538 - return __copy_from_user_ll_nocache_nozero(to, from, n);
11539 -}
11540 + if ((long)n < 0)
11541 + return n;
11542
11543 -unsigned long __must_check copy_to_user(void __user *to,
11544 - const void *from, unsigned long n);
11545 -unsigned long __must_check _copy_from_user(void *to,
11546 - const void __user *from,
11547 - unsigned long n);
11548 + return __copy_from_user_ll_nocache_nozero(to, from, n);
11549 +}
11550
11551 +extern void copy_to_user_overflow(void)
11552 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
11553 + __compiletime_error("copy_to_user() buffer size is not provably correct")
11554 +#else
11555 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
11556 +#endif
11557 +;
11558
11559 extern void copy_from_user_overflow(void)
11560 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
11561 @@ -200,17 +227,61 @@ extern void copy_from_user_overflow(void
11562 #endif
11563 ;
11564
11565 -static inline unsigned long __must_check copy_from_user(void *to,
11566 - const void __user *from,
11567 - unsigned long n)
11568 +/**
11569 + * copy_to_user: - Copy a block of data into user space.
11570 + * @to: Destination address, in user space.
11571 + * @from: Source address, in kernel space.
11572 + * @n: Number of bytes to copy.
11573 + *
11574 + * Context: User context only. This function may sleep.
11575 + *
11576 + * Copy data from kernel space to user space.
11577 + *
11578 + * Returns number of bytes that could not be copied.
11579 + * On success, this will be zero.
11580 + */
11581 +static inline unsigned long __must_check
11582 +copy_to_user(void __user *to, const void *from, unsigned long n)
11583 +{
11584 + int sz = __compiletime_object_size(from);
11585 +
11586 + if (unlikely(sz != -1 && sz < n))
11587 + copy_to_user_overflow();
11588 + else if (access_ok(VERIFY_WRITE, to, n))
11589 + n = __copy_to_user(to, from, n);
11590 + return n;
11591 +}
11592 +
11593 +/**
11594 + * copy_from_user: - Copy a block of data from user space.
11595 + * @to: Destination address, in kernel space.
11596 + * @from: Source address, in user space.
11597 + * @n: Number of bytes to copy.
11598 + *
11599 + * Context: User context only. This function may sleep.
11600 + *
11601 + * Copy data from user space to kernel space.
11602 + *
11603 + * Returns number of bytes that could not be copied.
11604 + * On success, this will be zero.
11605 + *
11606 + * If some data could not be copied, this function will pad the copied
11607 + * data to the requested size using zero bytes.
11608 + */
11609 +static inline unsigned long __must_check
11610 +copy_from_user(void *to, const void __user *from, unsigned long n)
11611 {
11612 int sz = __compiletime_object_size(to);
11613
11614 - if (likely(sz == -1 || sz >= n))
11615 - n = _copy_from_user(to, from, n);
11616 - else
11617 + if (unlikely(sz != -1 && sz < n))
11618 copy_from_user_overflow();
11619 -
11620 + else if (access_ok(VERIFY_READ, from, n))
11621 + n = __copy_from_user(to, from, n);
11622 + else if ((long)n > 0) {
11623 + if (!__builtin_constant_p(n))
11624 + check_object_size(to, n, false);
11625 + memset(to, 0, n);
11626 + }
11627 return n;
11628 }
11629
11630 diff -urNp linux-2.6.39/arch/x86/include/asm/uaccess_64.h linux-2.6.39/arch/x86/include/asm/uaccess_64.h
11631 --- linux-2.6.39/arch/x86/include/asm/uaccess_64.h 2011-05-19 00:06:34.000000000 -0400
11632 +++ linux-2.6.39/arch/x86/include/asm/uaccess_64.h 2011-05-22 19:36:30.000000000 -0400
11633 @@ -11,6 +11,9 @@
11634 #include <asm/alternative.h>
11635 #include <asm/cpufeature.h>
11636 #include <asm/page.h>
11637 +#include <asm/pgtable.h>
11638 +
11639 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
11640
11641 /*
11642 * Copy To/From Userspace
11643 @@ -37,26 +40,26 @@ copy_user_generic(void *to, const void *
11644 return ret;
11645 }
11646
11647 -__must_check unsigned long
11648 -_copy_to_user(void __user *to, const void *from, unsigned len);
11649 -__must_check unsigned long
11650 -_copy_from_user(void *to, const void __user *from, unsigned len);
11651 +static __always_inline __must_check unsigned long
11652 +__copy_to_user(void __user *to, const void *from, unsigned len);
11653 +static __always_inline __must_check unsigned long
11654 +__copy_from_user(void *to, const void __user *from, unsigned len);
11655 __must_check unsigned long
11656 copy_in_user(void __user *to, const void __user *from, unsigned len);
11657
11658 static inline unsigned long __must_check copy_from_user(void *to,
11659 const void __user *from,
11660 - unsigned long n)
11661 + unsigned n)
11662 {
11663 - int sz = __compiletime_object_size(to);
11664 -
11665 might_fault();
11666 - if (likely(sz == -1 || sz >= n))
11667 - n = _copy_from_user(to, from, n);
11668 -#ifdef CONFIG_DEBUG_VM
11669 - else
11670 - WARN(1, "Buffer overflow detected!\n");
11671 -#endif
11672 +
11673 + if (access_ok(VERIFY_READ, from, n))
11674 + n = __copy_from_user(to, from, n);
11675 + else if ((int)n > 0) {
11676 + if (!__builtin_constant_p(n))
11677 + check_object_size(to, n, false);
11678 + memset(to, 0, n);
11679 + }
11680 return n;
11681 }
11682
11683 @@ -65,110 +68,198 @@ int copy_to_user(void __user *dst, const
11684 {
11685 might_fault();
11686
11687 - return _copy_to_user(dst, src, size);
11688 + if (access_ok(VERIFY_WRITE, dst, size))
11689 + size = __copy_to_user(dst, src, size);
11690 + return size;
11691 }
11692
11693 static __always_inline __must_check
11694 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
11695 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned size)
11696 {
11697 - int ret = 0;
11698 + int sz = __compiletime_object_size(dst);
11699 + unsigned ret = 0;
11700
11701 might_fault();
11702 - if (!__builtin_constant_p(size))
11703 - return copy_user_generic(dst, (__force void *)src, size);
11704 +
11705 + pax_track_stack();
11706 +
11707 + if ((int)size < 0)
11708 + return size;
11709 +
11710 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11711 + if (!__access_ok(VERIFY_READ, src, size))
11712 + return size;
11713 +#endif
11714 +
11715 + if (unlikely(sz != -1 && sz < size)) {
11716 +#ifdef CONFIG_DEBUG_VM
11717 + WARN(1, "Buffer overflow detected!\n");
11718 +#endif
11719 + return size;
11720 + }
11721 +
11722 + if (!__builtin_constant_p(size)) {
11723 + check_object_size(dst, size, false);
11724 +
11725 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11726 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
11727 + src += PAX_USER_SHADOW_BASE;
11728 +#endif
11729 +
11730 + return copy_user_generic(dst, (__force const void *)src, size);
11731 + }
11732 switch (size) {
11733 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
11734 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
11735 ret, "b", "b", "=q", 1);
11736 return ret;
11737 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
11738 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
11739 ret, "w", "w", "=r", 2);
11740 return ret;
11741 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
11742 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
11743 ret, "l", "k", "=r", 4);
11744 return ret;
11745 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
11746 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
11747 ret, "q", "", "=r", 8);
11748 return ret;
11749 case 10:
11750 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
11751 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
11752 ret, "q", "", "=r", 10);
11753 if (unlikely(ret))
11754 return ret;
11755 __get_user_asm(*(u16 *)(8 + (char *)dst),
11756 - (u16 __user *)(8 + (char __user *)src),
11757 + (const u16 __user *)(8 + (const char __user *)src),
11758 ret, "w", "w", "=r", 2);
11759 return ret;
11760 case 16:
11761 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
11762 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
11763 ret, "q", "", "=r", 16);
11764 if (unlikely(ret))
11765 return ret;
11766 __get_user_asm(*(u64 *)(8 + (char *)dst),
11767 - (u64 __user *)(8 + (char __user *)src),
11768 + (const u64 __user *)(8 + (const char __user *)src),
11769 ret, "q", "", "=r", 8);
11770 return ret;
11771 default:
11772 - return copy_user_generic(dst, (__force void *)src, size);
11773 +
11774 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11775 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
11776 + src += PAX_USER_SHADOW_BASE;
11777 +#endif
11778 +
11779 + return copy_user_generic(dst, (__force const void *)src, size);
11780 }
11781 }
11782
11783 static __always_inline __must_check
11784 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
11785 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned size)
11786 {
11787 - int ret = 0;
11788 + int sz = __compiletime_object_size(src);
11789 + unsigned ret = 0;
11790
11791 might_fault();
11792 - if (!__builtin_constant_p(size))
11793 +
11794 + pax_track_stack();
11795 +
11796 + if ((int)size < 0)
11797 + return size;
11798 +
11799 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11800 + if (!__access_ok(VERIFY_WRITE, dst, size))
11801 + return size;
11802 +#endif
11803 +
11804 + if (unlikely(sz != -1 && sz < size)) {
11805 +#ifdef CONFIG_DEBUG_VM
11806 + WARN(1, "Buffer overflow detected!\n");
11807 +#endif
11808 + return size;
11809 + }
11810 +
11811 + if (!__builtin_constant_p(size)) {
11812 + check_object_size(src, size, true);
11813 +
11814 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11815 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
11816 + dst += PAX_USER_SHADOW_BASE;
11817 +#endif
11818 +
11819 return copy_user_generic((__force void *)dst, src, size);
11820 + }
11821 switch (size) {
11822 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
11823 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
11824 ret, "b", "b", "iq", 1);
11825 return ret;
11826 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
11827 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
11828 ret, "w", "w", "ir", 2);
11829 return ret;
11830 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
11831 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
11832 ret, "l", "k", "ir", 4);
11833 return ret;
11834 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
11835 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
11836 ret, "q", "", "er", 8);
11837 return ret;
11838 case 10:
11839 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
11840 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
11841 ret, "q", "", "er", 10);
11842 if (unlikely(ret))
11843 return ret;
11844 asm("":::"memory");
11845 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
11846 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
11847 ret, "w", "w", "ir", 2);
11848 return ret;
11849 case 16:
11850 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
11851 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
11852 ret, "q", "", "er", 16);
11853 if (unlikely(ret))
11854 return ret;
11855 asm("":::"memory");
11856 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
11857 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
11858 ret, "q", "", "er", 8);
11859 return ret;
11860 default:
11861 +
11862 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11863 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
11864 + dst += PAX_USER_SHADOW_BASE;
11865 +#endif
11866 +
11867 return copy_user_generic((__force void *)dst, src, size);
11868 }
11869 }
11870
11871 static __always_inline __must_check
11872 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
11873 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
11874 {
11875 - int ret = 0;
11876 + unsigned ret = 0;
11877
11878 might_fault();
11879 - if (!__builtin_constant_p(size))
11880 +
11881 + if ((int)size < 0)
11882 + return size;
11883 +
11884 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11885 + if (!__access_ok(VERIFY_READ, src, size))
11886 + return size;
11887 + if (!__access_ok(VERIFY_WRITE, dst, size))
11888 + return size;
11889 +#endif
11890 +
11891 + if (!__builtin_constant_p(size)) {
11892 +
11893 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11894 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
11895 + src += PAX_USER_SHADOW_BASE;
11896 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
11897 + dst += PAX_USER_SHADOW_BASE;
11898 +#endif
11899 +
11900 return copy_user_generic((__force void *)dst,
11901 - (__force void *)src, size);
11902 + (__force const void *)src, size);
11903 + }
11904 switch (size) {
11905 case 1: {
11906 u8 tmp;
11907 - __get_user_asm(tmp, (u8 __user *)src,
11908 + __get_user_asm(tmp, (const u8 __user *)src,
11909 ret, "b", "b", "=q", 1);
11910 if (likely(!ret))
11911 __put_user_asm(tmp, (u8 __user *)dst,
11912 @@ -177,7 +268,7 @@ int __copy_in_user(void __user *dst, con
11913 }
11914 case 2: {
11915 u16 tmp;
11916 - __get_user_asm(tmp, (u16 __user *)src,
11917 + __get_user_asm(tmp, (const u16 __user *)src,
11918 ret, "w", "w", "=r", 2);
11919 if (likely(!ret))
11920 __put_user_asm(tmp, (u16 __user *)dst,
11921 @@ -187,7 +278,7 @@ int __copy_in_user(void __user *dst, con
11922
11923 case 4: {
11924 u32 tmp;
11925 - __get_user_asm(tmp, (u32 __user *)src,
11926 + __get_user_asm(tmp, (const u32 __user *)src,
11927 ret, "l", "k", "=r", 4);
11928 if (likely(!ret))
11929 __put_user_asm(tmp, (u32 __user *)dst,
11930 @@ -196,7 +287,7 @@ int __copy_in_user(void __user *dst, con
11931 }
11932 case 8: {
11933 u64 tmp;
11934 - __get_user_asm(tmp, (u64 __user *)src,
11935 + __get_user_asm(tmp, (const u64 __user *)src,
11936 ret, "q", "", "=r", 8);
11937 if (likely(!ret))
11938 __put_user_asm(tmp, (u64 __user *)dst,
11939 @@ -204,8 +295,16 @@ int __copy_in_user(void __user *dst, con
11940 return ret;
11941 }
11942 default:
11943 +
11944 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11945 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
11946 + src += PAX_USER_SHADOW_BASE;
11947 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
11948 + dst += PAX_USER_SHADOW_BASE;
11949 +#endif
11950 +
11951 return copy_user_generic((__force void *)dst,
11952 - (__force void *)src, size);
11953 + (__force const void *)src, size);
11954 }
11955 }
11956
11957 @@ -222,33 +321,72 @@ __must_check unsigned long __clear_user(
11958 static __must_check __always_inline int
11959 __copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
11960 {
11961 + pax_track_stack();
11962 +
11963 + if ((int)size < 0)
11964 + return size;
11965 +
11966 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11967 + if (!__access_ok(VERIFY_READ, src, size))
11968 + return size;
11969 +
11970 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
11971 + src += PAX_USER_SHADOW_BASE;
11972 +#endif
11973 +
11974 return copy_user_generic(dst, (__force const void *)src, size);
11975 }
11976
11977 -static __must_check __always_inline int
11978 +static __must_check __always_inline unsigned long
11979 __copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
11980 {
11981 + if ((int)size < 0)
11982 + return size;
11983 +
11984 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11985 + if (!__access_ok(VERIFY_WRITE, dst, size))
11986 + return size;
11987 +
11988 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
11989 + dst += PAX_USER_SHADOW_BASE;
11990 +#endif
11991 +
11992 return copy_user_generic((__force void *)dst, src, size);
11993 }
11994
11995 -extern long __copy_user_nocache(void *dst, const void __user *src,
11996 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
11997 unsigned size, int zerorest);
11998
11999 -static inline int
12000 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
12001 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
12002 {
12003 might_sleep();
12004 +
12005 + if ((int)size < 0)
12006 + return size;
12007 +
12008 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12009 + if (!__access_ok(VERIFY_READ, src, size))
12010 + return size;
12011 +#endif
12012 +
12013 return __copy_user_nocache(dst, src, size, 1);
12014 }
12015
12016 -static inline int
12017 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
12018 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
12019 unsigned size)
12020 {
12021 + if ((int)size < 0)
12022 + return size;
12023 +
12024 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12025 + if (!__access_ok(VERIFY_READ, src, size))
12026 + return size;
12027 +#endif
12028 +
12029 return __copy_user_nocache(dst, src, size, 0);
12030 }
12031
12032 -unsigned long
12033 +extern unsigned long
12034 copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
12035
12036 #endif /* _ASM_X86_UACCESS_64_H */
12037 diff -urNp linux-2.6.39/arch/x86/include/asm/uaccess.h linux-2.6.39/arch/x86/include/asm/uaccess.h
12038 --- linux-2.6.39/arch/x86/include/asm/uaccess.h 2011-05-19 00:06:34.000000000 -0400
12039 +++ linux-2.6.39/arch/x86/include/asm/uaccess.h 2011-05-22 19:36:30.000000000 -0400
12040 @@ -8,12 +8,15 @@
12041 #include <linux/thread_info.h>
12042 #include <linux/prefetch.h>
12043 #include <linux/string.h>
12044 +#include <linux/sched.h>
12045 #include <asm/asm.h>
12046 #include <asm/page.h>
12047
12048 #define VERIFY_READ 0
12049 #define VERIFY_WRITE 1
12050
12051 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
12052 +
12053 /*
12054 * The fs value determines whether argument validity checking should be
12055 * performed or not. If get_fs() == USER_DS, checking is performed, with
12056 @@ -29,7 +32,12 @@
12057
12058 #define get_ds() (KERNEL_DS)
12059 #define get_fs() (current_thread_info()->addr_limit)
12060 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12061 +void __set_fs(mm_segment_t x);
12062 +void set_fs(mm_segment_t x);
12063 +#else
12064 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12065 +#endif
12066
12067 #define segment_eq(a, b) ((a).seg == (b).seg)
12068
12069 @@ -77,7 +85,33 @@
12070 * checks that the pointer is in the user space range - after calling
12071 * this function, memory access functions may still return -EFAULT.
12072 */
12073 -#define access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12074 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12075 +#define access_ok(type, addr, size) \
12076 +({ \
12077 + long __size = size; \
12078 + unsigned long __addr = (unsigned long)addr; \
12079 + unsigned long __addr_ao = __addr & PAGE_MASK; \
12080 + unsigned long __end_ao = __addr + __size - 1; \
12081 + bool __ret_ao = __range_not_ok(__addr, __size) == 0; \
12082 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12083 + while(__addr_ao <= __end_ao) { \
12084 + char __c_ao; \
12085 + __addr_ao += PAGE_SIZE; \
12086 + if (__size > PAGE_SIZE) \
12087 + cond_resched(); \
12088 + if (__get_user(__c_ao, (char __user *)__addr)) \
12089 + break; \
12090 + if (type != VERIFY_WRITE) { \
12091 + __addr = __addr_ao; \
12092 + continue; \
12093 + } \
12094 + if (__put_user(__c_ao, (char __user *)__addr)) \
12095 + break; \
12096 + __addr = __addr_ao; \
12097 + } \
12098 + } \
12099 + __ret_ao; \
12100 +})
12101
12102 /*
12103 * The exception table consists of pairs of addresses: the first is the
12104 @@ -183,12 +217,20 @@ extern int __get_user_bad(void);
12105 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12106 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12107
12108 -
12109 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12110 +#define __copyuser_seg "gs;"
12111 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12112 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12113 +#else
12114 +#define __copyuser_seg
12115 +#define __COPYUSER_SET_ES
12116 +#define __COPYUSER_RESTORE_ES
12117 +#endif
12118
12119 #ifdef CONFIG_X86_32
12120 #define __put_user_asm_u64(x, addr, err, errret) \
12121 - asm volatile("1: movl %%eax,0(%2)\n" \
12122 - "2: movl %%edx,4(%2)\n" \
12123 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12124 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12125 "3:\n" \
12126 ".section .fixup,\"ax\"\n" \
12127 "4: movl %3,%0\n" \
12128 @@ -200,8 +242,8 @@ extern int __get_user_bad(void);
12129 : "A" (x), "r" (addr), "i" (errret), "0" (err))
12130
12131 #define __put_user_asm_ex_u64(x, addr) \
12132 - asm volatile("1: movl %%eax,0(%1)\n" \
12133 - "2: movl %%edx,4(%1)\n" \
12134 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12135 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12136 "3:\n" \
12137 _ASM_EXTABLE(1b, 2b - 1b) \
12138 _ASM_EXTABLE(2b, 3b - 2b) \
12139 @@ -374,7 +416,7 @@ do { \
12140 } while (0)
12141
12142 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12143 - asm volatile("1: mov"itype" %2,%"rtype"1\n" \
12144 + asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12145 "2:\n" \
12146 ".section .fixup,\"ax\"\n" \
12147 "3: mov %3,%0\n" \
12148 @@ -382,7 +424,7 @@ do { \
12149 " jmp 2b\n" \
12150 ".previous\n" \
12151 _ASM_EXTABLE(1b, 3b) \
12152 - : "=r" (err), ltype(x) \
12153 + : "=r" (err), ltype (x) \
12154 : "m" (__m(addr)), "i" (errret), "0" (err))
12155
12156 #define __get_user_size_ex(x, ptr, size) \
12157 @@ -407,7 +449,7 @@ do { \
12158 } while (0)
12159
12160 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12161 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12162 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12163 "2:\n" \
12164 _ASM_EXTABLE(1b, 2b - 1b) \
12165 : ltype(x) : "m" (__m(addr)))
12166 @@ -424,13 +466,24 @@ do { \
12167 int __gu_err; \
12168 unsigned long __gu_val; \
12169 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12170 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
12171 + (x) = (__typeof__(*(ptr)))__gu_val; \
12172 __gu_err; \
12173 })
12174
12175 /* FIXME: this hack is definitely wrong -AK */
12176 struct __large_struct { unsigned long buf[100]; };
12177 -#define __m(x) (*(struct __large_struct __user *)(x))
12178 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12179 +#define ____m(x) \
12180 +({ \
12181 + unsigned long ____x = (unsigned long)(x); \
12182 + if (____x < PAX_USER_SHADOW_BASE) \
12183 + ____x += PAX_USER_SHADOW_BASE; \
12184 + (void __user *)____x; \
12185 +})
12186 +#else
12187 +#define ____m(x) (x)
12188 +#endif
12189 +#define __m(x) (*(struct __large_struct __user *)____m(x))
12190
12191 /*
12192 * Tell gcc we read from memory instead of writing: this is because
12193 @@ -438,7 +491,7 @@ struct __large_struct { unsigned long bu
12194 * aliasing issues.
12195 */
12196 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12197 - asm volatile("1: mov"itype" %"rtype"1,%2\n" \
12198 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
12199 "2:\n" \
12200 ".section .fixup,\"ax\"\n" \
12201 "3: mov %3,%0\n" \
12202 @@ -446,10 +499,10 @@ struct __large_struct { unsigned long bu
12203 ".previous\n" \
12204 _ASM_EXTABLE(1b, 3b) \
12205 : "=r"(err) \
12206 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
12207 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
12208
12209 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
12210 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
12211 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
12212 "2:\n" \
12213 _ASM_EXTABLE(1b, 2b - 1b) \
12214 : : ltype(x), "m" (__m(addr)))
12215 @@ -488,8 +541,12 @@ struct __large_struct { unsigned long bu
12216 * On error, the variable @x is set to zero.
12217 */
12218
12219 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12220 +#define __get_user(x, ptr) get_user((x), (ptr))
12221 +#else
12222 #define __get_user(x, ptr) \
12223 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
12224 +#endif
12225
12226 /**
12227 * __put_user: - Write a simple value into user space, with less checking.
12228 @@ -511,8 +568,12 @@ struct __large_struct { unsigned long bu
12229 * Returns zero on success, or -EFAULT on error.
12230 */
12231
12232 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12233 +#define __put_user(x, ptr) put_user((x), (ptr))
12234 +#else
12235 #define __put_user(x, ptr) \
12236 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
12237 +#endif
12238
12239 #define __get_user_unaligned __get_user
12240 #define __put_user_unaligned __put_user
12241 @@ -530,7 +591,7 @@ struct __large_struct { unsigned long bu
12242 #define get_user_ex(x, ptr) do { \
12243 unsigned long __gue_val; \
12244 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
12245 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
12246 + (x) = (__typeof__(*(ptr)))__gue_val; \
12247 } while (0)
12248
12249 #ifdef CONFIG_X86_WP_WORKS_OK
12250 @@ -567,6 +628,7 @@ extern struct movsl_mask {
12251
12252 #define ARCH_HAS_NOCACHE_UACCESS 1
12253
12254 +#define ARCH_HAS_SORT_EXTABLE
12255 #ifdef CONFIG_X86_32
12256 # include "uaccess_32.h"
12257 #else
12258 diff -urNp linux-2.6.39/arch/x86/include/asm/vgtod.h linux-2.6.39/arch/x86/include/asm/vgtod.h
12259 --- linux-2.6.39/arch/x86/include/asm/vgtod.h 2011-05-19 00:06:34.000000000 -0400
12260 +++ linux-2.6.39/arch/x86/include/asm/vgtod.h 2011-05-22 19:36:30.000000000 -0400
12261 @@ -14,6 +14,7 @@ struct vsyscall_gtod_data {
12262 int sysctl_enabled;
12263 struct timezone sys_tz;
12264 struct { /* extract of a clocksource struct */
12265 + char name[8];
12266 cycle_t (*vread)(void);
12267 cycle_t cycle_last;
12268 cycle_t mask;
12269 diff -urNp linux-2.6.39/arch/x86/include/asm/vsyscall.h linux-2.6.39/arch/x86/include/asm/vsyscall.h
12270 --- linux-2.6.39/arch/x86/include/asm/vsyscall.h 2011-05-19 00:06:34.000000000 -0400
12271 +++ linux-2.6.39/arch/x86/include/asm/vsyscall.h 2011-05-22 19:36:30.000000000 -0400
12272 @@ -15,9 +15,10 @@ enum vsyscall_num {
12273
12274 #ifdef __KERNEL__
12275 #include <linux/seqlock.h>
12276 +#include <linux/getcpu.h>
12277 +#include <linux/time.h>
12278
12279 #define __section_vgetcpu_mode __attribute__ ((unused, __section__ (".vgetcpu_mode"), aligned(16)))
12280 -#define __section_jiffies __attribute__ ((unused, __section__ (".jiffies"), aligned(16)))
12281
12282 /* Definitions for CONFIG_GENERIC_TIME definitions */
12283 #define __section_vsyscall_gtod_data __attribute__ \
12284 @@ -31,7 +32,6 @@ enum vsyscall_num {
12285 #define VGETCPU_LSL 2
12286
12287 extern int __vgetcpu_mode;
12288 -extern volatile unsigned long __jiffies;
12289
12290 /* kernel space (writeable) */
12291 extern int vgetcpu_mode;
12292 @@ -39,6 +39,9 @@ extern struct timezone sys_tz;
12293
12294 extern void map_vsyscall(void);
12295
12296 +extern int vgettimeofday(struct timeval * tv, struct timezone * tz);
12297 +extern time_t vtime(time_t *t);
12298 +extern long vgetcpu(unsigned *cpu, unsigned *node, struct getcpu_cache *tcache);
12299 #endif /* __KERNEL__ */
12300
12301 #endif /* _ASM_X86_VSYSCALL_H */
12302 diff -urNp linux-2.6.39/arch/x86/include/asm/xen/pci.h linux-2.6.39/arch/x86/include/asm/xen/pci.h
12303 --- linux-2.6.39/arch/x86/include/asm/xen/pci.h 2011-05-19 00:06:34.000000000 -0400
12304 +++ linux-2.6.39/arch/x86/include/asm/xen/pci.h 2011-05-22 19:36:30.000000000 -0400
12305 @@ -33,7 +33,7 @@ struct xen_pci_frontend_ops {
12306 void (*disable_msix)(struct pci_dev *dev);
12307 };
12308
12309 -extern struct xen_pci_frontend_ops *xen_pci_frontend;
12310 +extern const struct xen_pci_frontend_ops *xen_pci_frontend;
12311
12312 static inline int xen_pci_frontend_enable_msi(struct pci_dev *dev,
12313 int vectors[])
12314 diff -urNp linux-2.6.39/arch/x86/include/asm/xsave.h linux-2.6.39/arch/x86/include/asm/xsave.h
12315 --- linux-2.6.39/arch/x86/include/asm/xsave.h 2011-05-19 00:06:34.000000000 -0400
12316 +++ linux-2.6.39/arch/x86/include/asm/xsave.h 2011-05-22 19:36:30.000000000 -0400
12317 @@ -65,6 +65,11 @@ static inline int xsave_user(struct xsav
12318 {
12319 int err;
12320
12321 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12322 + if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
12323 + buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
12324 +#endif
12325 +
12326 /*
12327 * Clear the xsave header first, so that reserved fields are
12328 * initialized to zero.
12329 @@ -100,6 +105,11 @@ static inline int xrestore_user(struct x
12330 u32 lmask = mask;
12331 u32 hmask = mask >> 32;
12332
12333 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12334 + if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
12335 + xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
12336 +#endif
12337 +
12338 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
12339 "2:\n"
12340 ".section .fixup,\"ax\"\n"
12341 diff -urNp linux-2.6.39/arch/x86/Kconfig linux-2.6.39/arch/x86/Kconfig
12342 --- linux-2.6.39/arch/x86/Kconfig 2011-05-19 00:06:34.000000000 -0400
12343 +++ linux-2.6.39/arch/x86/Kconfig 2011-05-22 19:41:32.000000000 -0400
12344 @@ -224,7 +224,7 @@ config X86_HT
12345
12346 config X86_32_LAZY_GS
12347 def_bool y
12348 - depends on X86_32 && !CC_STACKPROTECTOR
12349 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
12350
12351 config ARCH_HWEIGHT_CFLAGS
12352 string
12353 @@ -1022,7 +1022,7 @@ choice
12354
12355 config NOHIGHMEM
12356 bool "off"
12357 - depends on !X86_NUMAQ
12358 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12359 ---help---
12360 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
12361 However, the address space of 32-bit x86 processors is only 4
12362 @@ -1059,7 +1059,7 @@ config NOHIGHMEM
12363
12364 config HIGHMEM4G
12365 bool "4GB"
12366 - depends on !X86_NUMAQ
12367 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12368 ---help---
12369 Select this if you have a 32-bit processor and between 1 and 4
12370 gigabytes of physical RAM.
12371 @@ -1113,7 +1113,7 @@ config PAGE_OFFSET
12372 hex
12373 default 0xB0000000 if VMSPLIT_3G_OPT
12374 default 0x80000000 if VMSPLIT_2G
12375 - default 0x78000000 if VMSPLIT_2G_OPT
12376 + default 0x70000000 if VMSPLIT_2G_OPT
12377 default 0x40000000 if VMSPLIT_1G
12378 default 0xC0000000
12379 depends on X86_32
12380 @@ -1457,7 +1457,7 @@ config ARCH_USES_PG_UNCACHED
12381
12382 config EFI
12383 bool "EFI runtime service support"
12384 - depends on ACPI
12385 + depends on ACPI && !PAX_KERNEXEC
12386 ---help---
12387 This enables the kernel to use EFI runtime services that are
12388 available (such as the EFI variable services).
12389 @@ -1487,6 +1487,7 @@ config SECCOMP
12390
12391 config CC_STACKPROTECTOR
12392 bool "Enable -fstack-protector buffer overflow detection (EXPERIMENTAL)"
12393 + depends on X86_64 || !PAX_MEMORY_UDEREF
12394 ---help---
12395 This option turns on the -fstack-protector GCC feature. This
12396 feature puts, at the beginning of functions, a canary value on
12397 @@ -1544,6 +1545,7 @@ config KEXEC_JUMP
12398 config PHYSICAL_START
12399 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
12400 default "0x1000000"
12401 + range 0x400000 0x40000000
12402 ---help---
12403 This gives the physical address where the kernel is loaded.
12404
12405 @@ -1607,6 +1609,7 @@ config X86_NEED_RELOCS
12406 config PHYSICAL_ALIGN
12407 hex "Alignment value to which kernel should be aligned" if X86_32
12408 default "0x1000000"
12409 + range 0x400000 0x1000000 if PAX_KERNEXEC
12410 range 0x2000 0x1000000
12411 ---help---
12412 This value puts the alignment restrictions on physical address
12413 @@ -1638,9 +1641,10 @@ config HOTPLUG_CPU
12414 Say N if you want to disable CPU hotplug.
12415
12416 config COMPAT_VDSO
12417 - def_bool y
12418 + def_bool n
12419 prompt "Compat VDSO support"
12420 depends on X86_32 || IA32_EMULATION
12421 + depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
12422 ---help---
12423 Map the 32-bit VDSO to the predictable old-style address too.
12424
12425 diff -urNp linux-2.6.39/arch/x86/Kconfig.cpu linux-2.6.39/arch/x86/Kconfig.cpu
12426 --- linux-2.6.39/arch/x86/Kconfig.cpu 2011-05-19 00:06:34.000000000 -0400
12427 +++ linux-2.6.39/arch/x86/Kconfig.cpu 2011-05-22 19:36:30.000000000 -0400
12428 @@ -334,7 +334,7 @@ config X86_PPRO_FENCE
12429
12430 config X86_F00F_BUG
12431 def_bool y
12432 - depends on M586MMX || M586TSC || M586 || M486 || M386
12433 + depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
12434
12435 config X86_INVD_BUG
12436 def_bool y
12437 @@ -358,7 +358,7 @@ config X86_POPAD_OK
12438
12439 config X86_ALIGNMENT_16
12440 def_bool y
12441 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12442 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12443
12444 config X86_INTEL_USERCOPY
12445 def_bool y
12446 @@ -404,7 +404,7 @@ config X86_CMPXCHG64
12447 # generates cmov.
12448 config X86_CMOV
12449 def_bool y
12450 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12451 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12452
12453 config X86_MINIMUM_CPU_FAMILY
12454 int
12455 diff -urNp linux-2.6.39/arch/x86/Kconfig.debug linux-2.6.39/arch/x86/Kconfig.debug
12456 --- linux-2.6.39/arch/x86/Kconfig.debug 2011-05-19 00:06:34.000000000 -0400
12457 +++ linux-2.6.39/arch/x86/Kconfig.debug 2011-05-22 19:36:30.000000000 -0400
12458 @@ -101,7 +101,7 @@ config X86_PTDUMP
12459 config DEBUG_RODATA
12460 bool "Write protect kernel read-only data structures"
12461 default y
12462 - depends on DEBUG_KERNEL
12463 + depends on DEBUG_KERNEL && BROKEN
12464 ---help---
12465 Mark the kernel read-only data as write-protected in the pagetables,
12466 in order to catch accidental (and incorrect) writes to such const
12467 @@ -119,7 +119,7 @@ config DEBUG_RODATA_TEST
12468
12469 config DEBUG_SET_MODULE_RONX
12470 bool "Set loadable kernel module data as NX and text as RO"
12471 - depends on MODULES
12472 + depends on MODULES && BROKEN
12473 ---help---
12474 This option helps catch unintended modifications to loadable
12475 kernel module's text and read-only data. It also prevents execution
12476 diff -urNp linux-2.6.39/arch/x86/kernel/acpi/sleep.c linux-2.6.39/arch/x86/kernel/acpi/sleep.c
12477 --- linux-2.6.39/arch/x86/kernel/acpi/sleep.c 2011-05-19 00:06:34.000000000 -0400
12478 +++ linux-2.6.39/arch/x86/kernel/acpi/sleep.c 2011-05-22 19:36:30.000000000 -0400
12479 @@ -88,8 +88,12 @@ int acpi_suspend_lowlevel(void)
12480 header->trampoline_segment = trampoline_address() >> 4;
12481 #ifdef CONFIG_SMP
12482 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
12483 +
12484 + pax_open_kernel();
12485 early_gdt_descr.address =
12486 (unsigned long)get_cpu_gdt_table(smp_processor_id());
12487 + pax_close_kernel();
12488 +
12489 initial_gs = per_cpu_offset(smp_processor_id());
12490 #endif
12491 initial_code = (unsigned long)wakeup_long64;
12492 diff -urNp linux-2.6.39/arch/x86/kernel/acpi/wakeup_32.S linux-2.6.39/arch/x86/kernel/acpi/wakeup_32.S
12493 --- linux-2.6.39/arch/x86/kernel/acpi/wakeup_32.S 2011-05-19 00:06:34.000000000 -0400
12494 +++ linux-2.6.39/arch/x86/kernel/acpi/wakeup_32.S 2011-05-22 19:36:30.000000000 -0400
12495 @@ -30,13 +30,11 @@ wakeup_pmode_return:
12496 # and restore the stack ... but you need gdt for this to work
12497 movl saved_context_esp, %esp
12498
12499 - movl %cs:saved_magic, %eax
12500 - cmpl $0x12345678, %eax
12501 + cmpl $0x12345678, saved_magic
12502 jne bogus_magic
12503
12504 # jump to place where we left off
12505 - movl saved_eip, %eax
12506 - jmp *%eax
12507 + jmp *(saved_eip)
12508
12509 bogus_magic:
12510 jmp bogus_magic
12511 diff -urNp linux-2.6.39/arch/x86/kernel/alternative.c linux-2.6.39/arch/x86/kernel/alternative.c
12512 --- linux-2.6.39/arch/x86/kernel/alternative.c 2011-05-19 00:06:34.000000000 -0400
12513 +++ linux-2.6.39/arch/x86/kernel/alternative.c 2011-05-22 19:36:30.000000000 -0400
12514 @@ -248,7 +248,7 @@ static void alternatives_smp_lock(const
12515 if (!*poff || ptr < text || ptr >= text_end)
12516 continue;
12517 /* turn DS segment override prefix into lock prefix */
12518 - if (*ptr == 0x3e)
12519 + if (*ktla_ktva(ptr) == 0x3e)
12520 text_poke(ptr, ((unsigned char []){0xf0}), 1);
12521 };
12522 mutex_unlock(&text_mutex);
12523 @@ -269,7 +269,7 @@ static void alternatives_smp_unlock(cons
12524 if (!*poff || ptr < text || ptr >= text_end)
12525 continue;
12526 /* turn lock prefix into DS segment override prefix */
12527 - if (*ptr == 0xf0)
12528 + if (*ktla_ktva(ptr) == 0xf0)
12529 text_poke(ptr, ((unsigned char []){0x3E}), 1);
12530 };
12531 mutex_unlock(&text_mutex);
12532 @@ -438,7 +438,7 @@ void __init_or_module apply_paravirt(str
12533
12534 BUG_ON(p->len > MAX_PATCH_LEN);
12535 /* prep the buffer with the original instructions */
12536 - memcpy(insnbuf, p->instr, p->len);
12537 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
12538 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
12539 (unsigned long)p->instr, p->len);
12540
12541 @@ -506,7 +506,7 @@ void __init alternative_instructions(voi
12542 if (smp_alt_once)
12543 free_init_pages("SMP alternatives",
12544 (unsigned long)__smp_locks,
12545 - (unsigned long)__smp_locks_end);
12546 + PAGE_ALIGN((unsigned long)__smp_locks_end));
12547
12548 restart_nmi();
12549 }
12550 @@ -523,13 +523,17 @@ void __init alternative_instructions(voi
12551 * instructions. And on the local CPU you need to be protected again NMI or MCE
12552 * handlers seeing an inconsistent instruction while you patch.
12553 */
12554 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
12555 +void *__kprobes text_poke_early(void *addr, const void *opcode,
12556 size_t len)
12557 {
12558 unsigned long flags;
12559 local_irq_save(flags);
12560 - memcpy(addr, opcode, len);
12561 +
12562 + pax_open_kernel();
12563 + memcpy(ktla_ktva(addr), opcode, len);
12564 sync_core();
12565 + pax_close_kernel();
12566 +
12567 local_irq_restore(flags);
12568 /* Could also do a CLFLUSH here to speed up CPU recovery; but
12569 that causes hangs on some VIA CPUs. */
12570 @@ -551,36 +555,22 @@ void *__init_or_module text_poke_early(v
12571 */
12572 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
12573 {
12574 - unsigned long flags;
12575 - char *vaddr;
12576 + unsigned char *vaddr = ktla_ktva(addr);
12577 struct page *pages[2];
12578 - int i;
12579 + size_t i;
12580
12581 if (!core_kernel_text((unsigned long)addr)) {
12582 - pages[0] = vmalloc_to_page(addr);
12583 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
12584 + pages[0] = vmalloc_to_page(vaddr);
12585 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
12586 } else {
12587 - pages[0] = virt_to_page(addr);
12588 + pages[0] = virt_to_page(vaddr);
12589 WARN_ON(!PageReserved(pages[0]));
12590 - pages[1] = virt_to_page(addr + PAGE_SIZE);
12591 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
12592 }
12593 BUG_ON(!pages[0]);
12594 - local_irq_save(flags);
12595 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
12596 - if (pages[1])
12597 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
12598 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
12599 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
12600 - clear_fixmap(FIX_TEXT_POKE0);
12601 - if (pages[1])
12602 - clear_fixmap(FIX_TEXT_POKE1);
12603 - local_flush_tlb();
12604 - sync_core();
12605 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
12606 - that causes hangs on some VIA CPUs. */
12607 + text_poke_early(addr, opcode, len);
12608 for (i = 0; i < len; i++)
12609 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
12610 - local_irq_restore(flags);
12611 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
12612 return addr;
12613 }
12614
12615 @@ -682,9 +672,9 @@ void __kprobes text_poke_smp_batch(struc
12616 #if defined(CONFIG_DYNAMIC_FTRACE) || defined(HAVE_JUMP_LABEL)
12617
12618 #ifdef CONFIG_X86_64
12619 -unsigned char ideal_nop5[5] = { 0x66, 0x66, 0x66, 0x66, 0x90 };
12620 +unsigned char ideal_nop5[5] __read_only = { 0x66, 0x66, 0x66, 0x66, 0x90 };
12621 #else
12622 -unsigned char ideal_nop5[5] = { 0x3e, 0x8d, 0x74, 0x26, 0x00 };
12623 +unsigned char ideal_nop5[5] __read_only = { 0x3e, 0x8d, 0x74, 0x26, 0x00 };
12624 #endif
12625
12626 void __init arch_init_ideal_nop5(void)
12627 diff -urNp linux-2.6.39/arch/x86/kernel/amd_iommu.c linux-2.6.39/arch/x86/kernel/amd_iommu.c
12628 --- linux-2.6.39/arch/x86/kernel/amd_iommu.c 2011-05-19 00:06:34.000000000 -0400
12629 +++ linux-2.6.39/arch/x86/kernel/amd_iommu.c 2011-05-22 19:36:30.000000000 -0400
12630 @@ -48,7 +48,7 @@ static DEFINE_SPINLOCK(iommu_pd_list_loc
12631 */
12632 static struct protection_domain *pt_domain;
12633
12634 -static struct iommu_ops amd_iommu_ops;
12635 +static const struct iommu_ops amd_iommu_ops;
12636
12637 /*
12638 * general struct to manage commands send to an IOMMU
12639 @@ -2286,7 +2286,7 @@ static void prealloc_protection_domains(
12640 }
12641 }
12642
12643 -static struct dma_map_ops amd_iommu_dma_ops = {
12644 +static const struct dma_map_ops amd_iommu_dma_ops = {
12645 .alloc_coherent = alloc_coherent,
12646 .free_coherent = free_coherent,
12647 .map_page = map_page,
12648 @@ -2582,7 +2582,7 @@ static int amd_iommu_domain_has_cap(stru
12649 return 0;
12650 }
12651
12652 -static struct iommu_ops amd_iommu_ops = {
12653 +static const struct iommu_ops amd_iommu_ops = {
12654 .domain_init = amd_iommu_domain_init,
12655 .domain_destroy = amd_iommu_domain_destroy,
12656 .attach_dev = amd_iommu_attach_device,
12657 diff -urNp linux-2.6.39/arch/x86/kernel/apic/apic.c linux-2.6.39/arch/x86/kernel/apic/apic.c
12658 --- linux-2.6.39/arch/x86/kernel/apic/apic.c 2011-05-19 00:06:34.000000000 -0400
12659 +++ linux-2.6.39/arch/x86/kernel/apic/apic.c 2011-05-22 19:36:30.000000000 -0400
12660 @@ -1821,7 +1821,7 @@ void smp_error_interrupt(struct pt_regs
12661 apic_write(APIC_ESR, 0);
12662 v1 = apic_read(APIC_ESR);
12663 ack_APIC_irq();
12664 - atomic_inc(&irq_err_count);
12665 + atomic_inc_unchecked(&irq_err_count);
12666
12667 /*
12668 * Here is what the APIC error bits mean:
12669 @@ -2204,6 +2204,8 @@ static int __cpuinit apic_cluster_num(vo
12670 u16 *bios_cpu_apicid;
12671 DECLARE_BITMAP(clustermap, NUM_APIC_CLUSTERS);
12672
12673 + pax_track_stack();
12674 +
12675 bios_cpu_apicid = early_per_cpu_ptr(x86_bios_cpu_apicid);
12676 bitmap_zero(clustermap, NUM_APIC_CLUSTERS);
12677
12678 diff -urNp linux-2.6.39/arch/x86/kernel/apic/io_apic.c linux-2.6.39/arch/x86/kernel/apic/io_apic.c
12679 --- linux-2.6.39/arch/x86/kernel/apic/io_apic.c 2011-05-19 00:06:34.000000000 -0400
12680 +++ linux-2.6.39/arch/x86/kernel/apic/io_apic.c 2011-05-22 19:36:30.000000000 -0400
12681 @@ -623,7 +623,7 @@ struct IO_APIC_route_entry **alloc_ioapi
12682 ioapic_entries = kzalloc(sizeof(*ioapic_entries) * nr_ioapics,
12683 GFP_KERNEL);
12684 if (!ioapic_entries)
12685 - return 0;
12686 + return NULL;
12687
12688 for (apic = 0; apic < nr_ioapics; apic++) {
12689 ioapic_entries[apic] =
12690 @@ -640,7 +640,7 @@ nomem:
12691 kfree(ioapic_entries[apic]);
12692 kfree(ioapic_entries);
12693
12694 - return 0;
12695 + return NULL;
12696 }
12697
12698 /*
12699 @@ -1040,7 +1040,7 @@ int IO_APIC_get_PCI_irq_vector(int bus,
12700 }
12701 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
12702
12703 -void lock_vector_lock(void)
12704 +void lock_vector_lock(void) __acquires(vector_lock)
12705 {
12706 /* Used to the online set of cpus does not change
12707 * during assign_irq_vector.
12708 @@ -1048,7 +1048,7 @@ void lock_vector_lock(void)
12709 raw_spin_lock(&vector_lock);
12710 }
12711
12712 -void unlock_vector_lock(void)
12713 +void unlock_vector_lock(void) __releases(vector_lock)
12714 {
12715 raw_spin_unlock(&vector_lock);
12716 }
12717 @@ -2379,7 +2379,7 @@ static void ack_apic_edge(struct irq_dat
12718 ack_APIC_irq();
12719 }
12720
12721 -atomic_t irq_mis_count;
12722 +atomic_unchecked_t irq_mis_count;
12723
12724 /*
12725 * IO-APIC versions below 0x20 don't support EOI register.
12726 @@ -2487,7 +2487,7 @@ static void ack_apic_level(struct irq_da
12727 * at the cpu.
12728 */
12729 if (!(v & (1 << (i & 0x1f)))) {
12730 - atomic_inc(&irq_mis_count);
12731 + atomic_inc_unchecked(&irq_mis_count);
12732
12733 eoi_ioapic_irq(irq, cfg);
12734 }
12735 diff -urNp linux-2.6.39/arch/x86/kernel/apm_32.c linux-2.6.39/arch/x86/kernel/apm_32.c
12736 --- linux-2.6.39/arch/x86/kernel/apm_32.c 2011-05-19 00:06:34.000000000 -0400
12737 +++ linux-2.6.39/arch/x86/kernel/apm_32.c 2011-05-22 19:36:30.000000000 -0400
12738 @@ -412,7 +412,7 @@ static DEFINE_MUTEX(apm_mutex);
12739 * This is for buggy BIOS's that refer to (real mode) segment 0x40
12740 * even though they are called in protected mode.
12741 */
12742 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
12743 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
12744 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
12745
12746 static const char driver_version[] = "1.16ac"; /* no spaces */
12747 @@ -590,7 +590,10 @@ static long __apm_bios_call(void *_call)
12748 BUG_ON(cpu != 0);
12749 gdt = get_cpu_gdt_table(cpu);
12750 save_desc_40 = gdt[0x40 / 8];
12751 +
12752 + pax_open_kernel();
12753 gdt[0x40 / 8] = bad_bios_desc;
12754 + pax_close_kernel();
12755
12756 apm_irq_save(flags);
12757 APM_DO_SAVE_SEGS;
12758 @@ -599,7 +602,11 @@ static long __apm_bios_call(void *_call)
12759 &call->esi);
12760 APM_DO_RESTORE_SEGS;
12761 apm_irq_restore(flags);
12762 +
12763 + pax_open_kernel();
12764 gdt[0x40 / 8] = save_desc_40;
12765 + pax_close_kernel();
12766 +
12767 put_cpu();
12768
12769 return call->eax & 0xff;
12770 @@ -666,7 +673,10 @@ static long __apm_bios_call_simple(void
12771 BUG_ON(cpu != 0);
12772 gdt = get_cpu_gdt_table(cpu);
12773 save_desc_40 = gdt[0x40 / 8];
12774 +
12775 + pax_open_kernel();
12776 gdt[0x40 / 8] = bad_bios_desc;
12777 + pax_close_kernel();
12778
12779 apm_irq_save(flags);
12780 APM_DO_SAVE_SEGS;
12781 @@ -674,7 +684,11 @@ static long __apm_bios_call_simple(void
12782 &call->eax);
12783 APM_DO_RESTORE_SEGS;
12784 apm_irq_restore(flags);
12785 +
12786 + pax_open_kernel();
12787 gdt[0x40 / 8] = save_desc_40;
12788 + pax_close_kernel();
12789 +
12790 put_cpu();
12791 return error;
12792 }
12793 @@ -2351,12 +2365,15 @@ static int __init apm_init(void)
12794 * code to that CPU.
12795 */
12796 gdt = get_cpu_gdt_table(0);
12797 +
12798 + pax_open_kernel();
12799 set_desc_base(&gdt[APM_CS >> 3],
12800 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
12801 set_desc_base(&gdt[APM_CS_16 >> 3],
12802 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
12803 set_desc_base(&gdt[APM_DS >> 3],
12804 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
12805 + pax_close_kernel();
12806
12807 proc_create("apm", 0, NULL, &apm_file_ops);
12808
12809 diff -urNp linux-2.6.39/arch/x86/kernel/asm-offsets_64.c linux-2.6.39/arch/x86/kernel/asm-offsets_64.c
12810 --- linux-2.6.39/arch/x86/kernel/asm-offsets_64.c 2011-05-19 00:06:34.000000000 -0400
12811 +++ linux-2.6.39/arch/x86/kernel/asm-offsets_64.c 2011-05-22 19:36:30.000000000 -0400
12812 @@ -69,6 +69,7 @@ int main(void)
12813 BLANK();
12814 #undef ENTRY
12815
12816 + DEFINE(TSS_size, sizeof(struct tss_struct));
12817 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
12818 BLANK();
12819
12820 diff -urNp linux-2.6.39/arch/x86/kernel/asm-offsets.c linux-2.6.39/arch/x86/kernel/asm-offsets.c
12821 --- linux-2.6.39/arch/x86/kernel/asm-offsets.c 2011-05-19 00:06:34.000000000 -0400
12822 +++ linux-2.6.39/arch/x86/kernel/asm-offsets.c 2011-05-22 19:36:30.000000000 -0400
12823 @@ -33,6 +33,8 @@ void common(void) {
12824 OFFSET(TI_status, thread_info, status);
12825 OFFSET(TI_addr_limit, thread_info, addr_limit);
12826 OFFSET(TI_preempt_count, thread_info, preempt_count);
12827 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
12828 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
12829
12830 BLANK();
12831 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
12832 @@ -53,8 +55,24 @@ void common(void) {
12833 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
12834 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
12835 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
12836 +
12837 +#ifdef CONFIG_PAX_KERNEXEC
12838 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
12839 +#endif
12840 +
12841 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12842 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
12843 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
12844 + OFFSET(PV_MMU_set_pgd, pv_mmu_ops, set_pgd);
12845 #endif
12846
12847 +#endif
12848 +
12849 + BLANK();
12850 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
12851 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
12852 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
12853 +
12854 #ifdef CONFIG_XEN
12855 BLANK();
12856 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
12857 diff -urNp linux-2.6.39/arch/x86/kernel/cpu/amd.c linux-2.6.39/arch/x86/kernel/cpu/amd.c
12858 --- linux-2.6.39/arch/x86/kernel/cpu/amd.c 2011-05-19 00:06:34.000000000 -0400
12859 +++ linux-2.6.39/arch/x86/kernel/cpu/amd.c 2011-05-22 19:36:30.000000000 -0400
12860 @@ -641,7 +641,7 @@ static unsigned int __cpuinit amd_size_c
12861 unsigned int size)
12862 {
12863 /* AMD errata T13 (order #21922) */
12864 - if ((c->x86 == 6)) {
12865 + if (c->x86 == 6) {
12866 /* Duron Rev A0 */
12867 if (c->x86_model == 3 && c->x86_mask == 0)
12868 size = 64;
12869 diff -urNp linux-2.6.39/arch/x86/kernel/cpu/common.c linux-2.6.39/arch/x86/kernel/cpu/common.c
12870 --- linux-2.6.39/arch/x86/kernel/cpu/common.c 2011-05-19 00:06:34.000000000 -0400
12871 +++ linux-2.6.39/arch/x86/kernel/cpu/common.c 2011-05-22 19:36:30.000000000 -0400
12872 @@ -83,60 +83,6 @@ static const struct cpu_dev __cpuinitcon
12873
12874 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
12875
12876 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
12877 -#ifdef CONFIG_X86_64
12878 - /*
12879 - * We need valid kernel segments for data and code in long mode too
12880 - * IRET will check the segment types kkeil 2000/10/28
12881 - * Also sysret mandates a special GDT layout
12882 - *
12883 - * TLS descriptors are currently at a different place compared to i386.
12884 - * Hopefully nobody expects them at a fixed place (Wine?)
12885 - */
12886 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
12887 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
12888 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
12889 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
12890 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
12891 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
12892 -#else
12893 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
12894 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
12895 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
12896 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
12897 - /*
12898 - * Segments used for calling PnP BIOS have byte granularity.
12899 - * They code segments and data segments have fixed 64k limits,
12900 - * the transfer segment sizes are set at run time.
12901 - */
12902 - /* 32-bit code */
12903 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
12904 - /* 16-bit code */
12905 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
12906 - /* 16-bit data */
12907 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
12908 - /* 16-bit data */
12909 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
12910 - /* 16-bit data */
12911 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
12912 - /*
12913 - * The APM segments have byte granularity and their bases
12914 - * are set at run time. All have 64k limits.
12915 - */
12916 - /* 32-bit code */
12917 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
12918 - /* 16-bit code */
12919 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
12920 - /* data */
12921 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
12922 -
12923 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
12924 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
12925 - GDT_STACK_CANARY_INIT
12926 -#endif
12927 -} };
12928 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
12929 -
12930 static int __init x86_xsave_setup(char *s)
12931 {
12932 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
12933 @@ -352,7 +298,7 @@ void switch_to_new_gdt(int cpu)
12934 {
12935 struct desc_ptr gdt_descr;
12936
12937 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
12938 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
12939 gdt_descr.size = GDT_SIZE - 1;
12940 load_gdt(&gdt_descr);
12941 /* Reload the per-cpu base */
12942 @@ -825,6 +771,10 @@ static void __cpuinit identify_cpu(struc
12943 /* Filter out anything that depends on CPUID levels we don't have */
12944 filter_cpuid_features(c, true);
12945
12946 +#if defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || (defined(CONFIG_PAX_MEMORY_UDEREF) && defined(CONFIG_X86_32))
12947 + setup_clear_cpu_cap(X86_FEATURE_SEP);
12948 +#endif
12949 +
12950 /* If the model name is still unset, do table lookup. */
12951 if (!c->x86_model_id[0]) {
12952 const char *p;
12953 @@ -1004,6 +954,9 @@ static __init int setup_disablecpuid(cha
12954 }
12955 __setup("clearcpuid=", setup_disablecpuid);
12956
12957 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
12958 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
12959 +
12960 #ifdef CONFIG_X86_64
12961 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
12962
12963 @@ -1019,7 +972,7 @@ DEFINE_PER_CPU(struct task_struct *, cur
12964 EXPORT_PER_CPU_SYMBOL(current_task);
12965
12966 DEFINE_PER_CPU(unsigned long, kernel_stack) =
12967 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
12968 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
12969 EXPORT_PER_CPU_SYMBOL(kernel_stack);
12970
12971 DEFINE_PER_CPU(char *, irq_stack_ptr) =
12972 @@ -1084,7 +1037,7 @@ struct pt_regs * __cpuinit idle_regs(str
12973 {
12974 memset(regs, 0, sizeof(struct pt_regs));
12975 regs->fs = __KERNEL_PERCPU;
12976 - regs->gs = __KERNEL_STACK_CANARY;
12977 + savesegment(gs, regs->gs);
12978
12979 return regs;
12980 }
12981 @@ -1139,7 +1092,7 @@ void __cpuinit cpu_init(void)
12982 int i;
12983
12984 cpu = stack_smp_processor_id();
12985 - t = &per_cpu(init_tss, cpu);
12986 + t = init_tss + cpu;
12987 oist = &per_cpu(orig_ist, cpu);
12988
12989 #ifdef CONFIG_NUMA
12990 @@ -1165,7 +1118,7 @@ void __cpuinit cpu_init(void)
12991 switch_to_new_gdt(cpu);
12992 loadsegment(fs, 0);
12993
12994 - load_idt((const struct desc_ptr *)&idt_descr);
12995 + load_idt(&idt_descr);
12996
12997 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
12998 syscall_init();
12999 @@ -1174,7 +1127,6 @@ void __cpuinit cpu_init(void)
13000 wrmsrl(MSR_KERNEL_GS_BASE, 0);
13001 barrier();
13002
13003 - x86_configure_nx();
13004 if (cpu != 0)
13005 enable_x2apic();
13006
13007 @@ -1228,7 +1180,7 @@ void __cpuinit cpu_init(void)
13008 {
13009 int cpu = smp_processor_id();
13010 struct task_struct *curr = current;
13011 - struct tss_struct *t = &per_cpu(init_tss, cpu);
13012 + struct tss_struct *t = init_tss + cpu;
13013 struct thread_struct *thread = &curr->thread;
13014
13015 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
13016 diff -urNp linux-2.6.39/arch/x86/kernel/cpu/intel.c linux-2.6.39/arch/x86/kernel/cpu/intel.c
13017 --- linux-2.6.39/arch/x86/kernel/cpu/intel.c 2011-05-19 00:06:34.000000000 -0400
13018 +++ linux-2.6.39/arch/x86/kernel/cpu/intel.c 2011-05-22 19:36:30.000000000 -0400
13019 @@ -161,7 +161,7 @@ static void __cpuinit trap_init_f00f_bug
13020 * Update the IDT descriptor and reload the IDT so that
13021 * it uses the read-only mapped virtual address.
13022 */
13023 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
13024 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
13025 load_idt(&idt_descr);
13026 }
13027 #endif
13028 diff -urNp linux-2.6.39/arch/x86/kernel/cpu/Makefile linux-2.6.39/arch/x86/kernel/cpu/Makefile
13029 --- linux-2.6.39/arch/x86/kernel/cpu/Makefile 2011-05-19 00:06:34.000000000 -0400
13030 +++ linux-2.6.39/arch/x86/kernel/cpu/Makefile 2011-05-22 19:36:30.000000000 -0400
13031 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
13032 CFLAGS_REMOVE_perf_event.o = -pg
13033 endif
13034
13035 -# Make sure load_percpu_segment has no stackprotector
13036 -nostackp := $(call cc-option, -fno-stack-protector)
13037 -CFLAGS_common.o := $(nostackp)
13038 -
13039 obj-y := intel_cacheinfo.o scattered.o topology.o
13040 obj-y += proc.o capflags.o powerflags.o common.o
13041 obj-y += vmware.o hypervisor.o sched.o mshyperv.o
13042 diff -urNp linux-2.6.39/arch/x86/kernel/cpu/mcheck/mce.c linux-2.6.39/arch/x86/kernel/cpu/mcheck/mce.c
13043 --- linux-2.6.39/arch/x86/kernel/cpu/mcheck/mce.c 2011-05-19 00:06:34.000000000 -0400
13044 +++ linux-2.6.39/arch/x86/kernel/cpu/mcheck/mce.c 2011-05-22 19:36:30.000000000 -0400
13045 @@ -46,6 +46,7 @@
13046 #include <asm/ipi.h>
13047 #include <asm/mce.h>
13048 #include <asm/msr.h>
13049 +#include <asm/local.h>
13050
13051 #include "mce-internal.h"
13052
13053 @@ -220,7 +221,7 @@ static void print_mce(struct mce *m)
13054 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
13055 m->cs, m->ip);
13056
13057 - if (m->cs == __KERNEL_CS)
13058 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
13059 print_symbol("{%s}", m->ip);
13060 pr_cont("\n");
13061 }
13062 @@ -244,10 +245,10 @@ static void print_mce(struct mce *m)
13063
13064 #define PANIC_TIMEOUT 5 /* 5 seconds */
13065
13066 -static atomic_t mce_paniced;
13067 +static atomic_unchecked_t mce_paniced;
13068
13069 static int fake_panic;
13070 -static atomic_t mce_fake_paniced;
13071 +static atomic_unchecked_t mce_fake_paniced;
13072
13073 /* Panic in progress. Enable interrupts and wait for final IPI */
13074 static void wait_for_panic(void)
13075 @@ -271,7 +272,7 @@ static void mce_panic(char *msg, struct
13076 /*
13077 * Make sure only one CPU runs in machine check panic
13078 */
13079 - if (atomic_inc_return(&mce_paniced) > 1)
13080 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
13081 wait_for_panic();
13082 barrier();
13083
13084 @@ -279,7 +280,7 @@ static void mce_panic(char *msg, struct
13085 console_verbose();
13086 } else {
13087 /* Don't log too much for fake panic */
13088 - if (atomic_inc_return(&mce_fake_paniced) > 1)
13089 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
13090 return;
13091 }
13092 /* First print corrected ones that are still unlogged */
13093 @@ -647,7 +648,7 @@ static int mce_timed_out(u64 *t)
13094 * might have been modified by someone else.
13095 */
13096 rmb();
13097 - if (atomic_read(&mce_paniced))
13098 + if (atomic_read_unchecked(&mce_paniced))
13099 wait_for_panic();
13100 if (!monarch_timeout)
13101 goto out;
13102 @@ -1461,14 +1462,14 @@ void __cpuinit mcheck_cpu_init(struct cp
13103 */
13104
13105 static DEFINE_SPINLOCK(mce_state_lock);
13106 -static int open_count; /* #times opened */
13107 +static local_t open_count; /* #times opened */
13108 static int open_exclu; /* already open exclusive? */
13109
13110 static int mce_open(struct inode *inode, struct file *file)
13111 {
13112 spin_lock(&mce_state_lock);
13113
13114 - if (open_exclu || (open_count && (file->f_flags & O_EXCL))) {
13115 + if (open_exclu || (local_read(&open_count) && (file->f_flags & O_EXCL))) {
13116 spin_unlock(&mce_state_lock);
13117
13118 return -EBUSY;
13119 @@ -1476,7 +1477,7 @@ static int mce_open(struct inode *inode,
13120
13121 if (file->f_flags & O_EXCL)
13122 open_exclu = 1;
13123 - open_count++;
13124 + local_inc(&open_count);
13125
13126 spin_unlock(&mce_state_lock);
13127
13128 @@ -1487,7 +1488,7 @@ static int mce_release(struct inode *ino
13129 {
13130 spin_lock(&mce_state_lock);
13131
13132 - open_count--;
13133 + local_dec(&open_count);
13134 open_exclu = 0;
13135
13136 spin_unlock(&mce_state_lock);
13137 @@ -2174,7 +2175,7 @@ struct dentry *mce_get_debugfs_dir(void)
13138 static void mce_reset(void)
13139 {
13140 cpu_missing = 0;
13141 - atomic_set(&mce_fake_paniced, 0);
13142 + atomic_set_unchecked(&mce_fake_paniced, 0);
13143 atomic_set(&mce_executing, 0);
13144 atomic_set(&mce_callin, 0);
13145 atomic_set(&global_nwo, 0);
13146 diff -urNp linux-2.6.39/arch/x86/kernel/cpu/mtrr/main.c linux-2.6.39/arch/x86/kernel/cpu/mtrr/main.c
13147 --- linux-2.6.39/arch/x86/kernel/cpu/mtrr/main.c 2011-05-19 00:06:34.000000000 -0400
13148 +++ linux-2.6.39/arch/x86/kernel/cpu/mtrr/main.c 2011-05-22 19:36:30.000000000 -0400
13149 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
13150 u64 size_or_mask, size_and_mask;
13151 static bool mtrr_aps_delayed_init;
13152
13153 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
13154 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
13155
13156 const struct mtrr_ops *mtrr_if;
13157
13158 diff -urNp linux-2.6.39/arch/x86/kernel/cpu/mtrr/mtrr.h linux-2.6.39/arch/x86/kernel/cpu/mtrr/mtrr.h
13159 --- linux-2.6.39/arch/x86/kernel/cpu/mtrr/mtrr.h 2011-05-19 00:06:34.000000000 -0400
13160 +++ linux-2.6.39/arch/x86/kernel/cpu/mtrr/mtrr.h 2011-05-22 19:36:30.000000000 -0400
13161 @@ -12,19 +12,19 @@
13162 extern unsigned int mtrr_usage_table[MTRR_MAX_VAR_RANGES];
13163
13164 struct mtrr_ops {
13165 - u32 vendor;
13166 - u32 use_intel_if;
13167 - void (*set)(unsigned int reg, unsigned long base,
13168 + const u32 vendor;
13169 + const u32 use_intel_if;
13170 + void (* const set)(unsigned int reg, unsigned long base,
13171 unsigned long size, mtrr_type type);
13172 - void (*set_all)(void);
13173 + void (* const set_all)(void);
13174
13175 - void (*get)(unsigned int reg, unsigned long *base,
13176 + void (* const get)(unsigned int reg, unsigned long *base,
13177 unsigned long *size, mtrr_type *type);
13178 - int (*get_free_region)(unsigned long base, unsigned long size,
13179 + int (* const get_free_region)(unsigned long base, unsigned long size,
13180 int replace_reg);
13181 - int (*validate_add_page)(unsigned long base, unsigned long size,
13182 + int (* const validate_add_page)(unsigned long base, unsigned long size,
13183 unsigned int type);
13184 - int (*have_wrcomb)(void);
13185 + int (* const have_wrcomb)(void);
13186 };
13187
13188 extern int generic_get_free_region(unsigned long base, unsigned long size,
13189 diff -urNp linux-2.6.39/arch/x86/kernel/cpu/perf_event.c linux-2.6.39/arch/x86/kernel/cpu/perf_event.c
13190 --- linux-2.6.39/arch/x86/kernel/cpu/perf_event.c 2011-05-19 00:06:34.000000000 -0400
13191 +++ linux-2.6.39/arch/x86/kernel/cpu/perf_event.c 2011-05-22 19:36:30.000000000 -0400
13192 @@ -774,6 +774,8 @@ static int x86_schedule_events(struct cp
13193 int i, j, w, wmax, num = 0;
13194 struct hw_perf_event *hwc;
13195
13196 + pax_track_stack();
13197 +
13198 bitmap_zero(used_mask, X86_PMC_IDX_MAX);
13199
13200 for (i = 0; i < n; i++) {
13201 @@ -1878,7 +1880,7 @@ perf_callchain_user(struct perf_callchai
13202 break;
13203
13204 perf_callchain_store(entry, frame.return_address);
13205 - fp = frame.next_frame;
13206 + fp = (__force const void __user *)frame.next_frame;
13207 }
13208 }
13209
13210 diff -urNp linux-2.6.39/arch/x86/kernel/crash.c linux-2.6.39/arch/x86/kernel/crash.c
13211 --- linux-2.6.39/arch/x86/kernel/crash.c 2011-05-19 00:06:34.000000000 -0400
13212 +++ linux-2.6.39/arch/x86/kernel/crash.c 2011-05-22 19:36:30.000000000 -0400
13213 @@ -42,7 +42,7 @@ static void kdump_nmi_callback(int cpu,
13214 regs = args->regs;
13215
13216 #ifdef CONFIG_X86_32
13217 - if (!user_mode_vm(regs)) {
13218 + if (!user_mode(regs)) {
13219 crash_fixup_ss_esp(&fixed_regs, regs);
13220 regs = &fixed_regs;
13221 }
13222 diff -urNp linux-2.6.39/arch/x86/kernel/doublefault_32.c linux-2.6.39/arch/x86/kernel/doublefault_32.c
13223 --- linux-2.6.39/arch/x86/kernel/doublefault_32.c 2011-05-19 00:06:34.000000000 -0400
13224 +++ linux-2.6.39/arch/x86/kernel/doublefault_32.c 2011-05-22 19:36:30.000000000 -0400
13225 @@ -11,7 +11,7 @@
13226
13227 #define DOUBLEFAULT_STACKSIZE (1024)
13228 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
13229 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
13230 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
13231
13232 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
13233
13234 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
13235 unsigned long gdt, tss;
13236
13237 store_gdt(&gdt_desc);
13238 - gdt = gdt_desc.address;
13239 + gdt = (unsigned long)gdt_desc.address;
13240
13241 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
13242
13243 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cach
13244 /* 0x2 bit is always set */
13245 .flags = X86_EFLAGS_SF | 0x2,
13246 .sp = STACK_START,
13247 - .es = __USER_DS,
13248 + .es = __KERNEL_DS,
13249 .cs = __KERNEL_CS,
13250 .ss = __KERNEL_DS,
13251 - .ds = __USER_DS,
13252 + .ds = __KERNEL_DS,
13253 .fs = __KERNEL_PERCPU,
13254
13255 .__cr3 = __pa_nodebug(swapper_pg_dir),
13256 diff -urNp linux-2.6.39/arch/x86/kernel/dumpstack_32.c linux-2.6.39/arch/x86/kernel/dumpstack_32.c
13257 --- linux-2.6.39/arch/x86/kernel/dumpstack_32.c 2011-05-19 00:06:34.000000000 -0400
13258 +++ linux-2.6.39/arch/x86/kernel/dumpstack_32.c 2011-05-22 19:36:30.000000000 -0400
13259 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task
13260 bp = stack_frame(task, regs);
13261
13262 for (;;) {
13263 - struct thread_info *context;
13264 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
13265
13266 - context = (struct thread_info *)
13267 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
13268 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
13269 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
13270
13271 - stack = (unsigned long *)context->previous_esp;
13272 - if (!stack)
13273 + if (stack_start == task_stack_page(task))
13274 break;
13275 + stack = *(unsigned long **)stack_start;
13276 if (ops->stack(data, "IRQ") < 0)
13277 break;
13278 touch_nmi_watchdog();
13279 @@ -96,21 +94,22 @@ void show_registers(struct pt_regs *regs
13280 * When in-kernel, we also print out the stack and code at the
13281 * time of the fault..
13282 */
13283 - if (!user_mode_vm(regs)) {
13284 + if (!user_mode(regs)) {
13285 unsigned int code_prologue = code_bytes * 43 / 64;
13286 unsigned int code_len = code_bytes;
13287 unsigned char c;
13288 u8 *ip;
13289 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
13290
13291 printk(KERN_EMERG "Stack:\n");
13292 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
13293
13294 printk(KERN_EMERG "Code: ");
13295
13296 - ip = (u8 *)regs->ip - code_prologue;
13297 + ip = (u8 *)regs->ip - code_prologue + cs_base;
13298 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
13299 /* try starting at IP */
13300 - ip = (u8 *)regs->ip;
13301 + ip = (u8 *)regs->ip + cs_base;
13302 code_len = code_len - code_prologue + 1;
13303 }
13304 for (i = 0; i < code_len; i++, ip++) {
13305 @@ -119,7 +118,7 @@ void show_registers(struct pt_regs *regs
13306 printk(" Bad EIP value.");
13307 break;
13308 }
13309 - if (ip == (u8 *)regs->ip)
13310 + if (ip == (u8 *)regs->ip + cs_base)
13311 printk("<%02x> ", c);
13312 else
13313 printk("%02x ", c);
13314 @@ -132,6 +131,7 @@ int is_valid_bugaddr(unsigned long ip)
13315 {
13316 unsigned short ud2;
13317
13318 + ip = ktla_ktva(ip);
13319 if (ip < PAGE_OFFSET)
13320 return 0;
13321 if (probe_kernel_address((unsigned short *)ip, ud2))
13322 diff -urNp linux-2.6.39/arch/x86/kernel/dumpstack_64.c linux-2.6.39/arch/x86/kernel/dumpstack_64.c
13323 --- linux-2.6.39/arch/x86/kernel/dumpstack_64.c 2011-05-19 00:06:34.000000000 -0400
13324 +++ linux-2.6.39/arch/x86/kernel/dumpstack_64.c 2011-05-22 19:36:30.000000000 -0400
13325 @@ -147,9 +147,9 @@ void dump_trace(struct task_struct *task
13326 unsigned long *irq_stack_end =
13327 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
13328 unsigned used = 0;
13329 - struct thread_info *tinfo;
13330 int graph = 0;
13331 unsigned long dummy;
13332 + void *stack_start;
13333
13334 if (!task)
13335 task = current;
13336 @@ -167,10 +167,10 @@ void dump_trace(struct task_struct *task
13337 * current stack address. If the stacks consist of nested
13338 * exceptions
13339 */
13340 - tinfo = task_thread_info(task);
13341 for (;;) {
13342 char *id;
13343 unsigned long *estack_end;
13344 +
13345 estack_end = in_exception_stack(cpu, (unsigned long)stack,
13346 &used, &id);
13347
13348 @@ -178,7 +178,7 @@ void dump_trace(struct task_struct *task
13349 if (ops->stack(data, id) < 0)
13350 break;
13351
13352 - bp = ops->walk_stack(tinfo, stack, bp, ops,
13353 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
13354 data, estack_end, &graph);
13355 ops->stack(data, "<EOE>");
13356 /*
13357 @@ -197,7 +197,7 @@ void dump_trace(struct task_struct *task
13358 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
13359 if (ops->stack(data, "IRQ") < 0)
13360 break;
13361 - bp = ops->walk_stack(tinfo, stack, bp,
13362 + bp = ops->walk_stack(task, irq_stack, stack, bp,
13363 ops, data, irq_stack_end, &graph);
13364 /*
13365 * We link to the next stack (which would be
13366 @@ -218,7 +218,8 @@ void dump_trace(struct task_struct *task
13367 /*
13368 * This handles the process stack:
13369 */
13370 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
13371 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
13372 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
13373 put_cpu();
13374 }
13375 EXPORT_SYMBOL(dump_trace);
13376 diff -urNp linux-2.6.39/arch/x86/kernel/dumpstack.c linux-2.6.39/arch/x86/kernel/dumpstack.c
13377 --- linux-2.6.39/arch/x86/kernel/dumpstack.c 2011-05-19 00:06:34.000000000 -0400
13378 +++ linux-2.6.39/arch/x86/kernel/dumpstack.c 2011-05-22 19:41:32.000000000 -0400
13379 @@ -2,6 +2,9 @@
13380 * Copyright (C) 1991, 1992 Linus Torvalds
13381 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
13382 */
13383 +#ifdef CONFIG_GRKERNSEC_HIDESYM
13384 +#define __INCLUDED_BY_HIDESYM 1
13385 +#endif
13386 #include <linux/kallsyms.h>
13387 #include <linux/kprobes.h>
13388 #include <linux/uaccess.h>
13389 @@ -35,9 +38,8 @@ void printk_address(unsigned long addres
13390 static void
13391 print_ftrace_graph_addr(unsigned long addr, void *data,
13392 const struct stacktrace_ops *ops,
13393 - struct thread_info *tinfo, int *graph)
13394 + struct task_struct *task, int *graph)
13395 {
13396 - struct task_struct *task = tinfo->task;
13397 unsigned long ret_addr;
13398 int index = task->curr_ret_stack;
13399
13400 @@ -58,7 +60,7 @@ print_ftrace_graph_addr(unsigned long ad
13401 static inline void
13402 print_ftrace_graph_addr(unsigned long addr, void *data,
13403 const struct stacktrace_ops *ops,
13404 - struct thread_info *tinfo, int *graph)
13405 + struct task_struct *task, int *graph)
13406 { }
13407 #endif
13408
13409 @@ -69,10 +71,8 @@ print_ftrace_graph_addr(unsigned long ad
13410 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
13411 */
13412
13413 -static inline int valid_stack_ptr(struct thread_info *tinfo,
13414 - void *p, unsigned int size, void *end)
13415 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
13416 {
13417 - void *t = tinfo;
13418 if (end) {
13419 if (p < end && p >= (end-THREAD_SIZE))
13420 return 1;
13421 @@ -83,14 +83,14 @@ static inline int valid_stack_ptr(struct
13422 }
13423
13424 unsigned long
13425 -print_context_stack(struct thread_info *tinfo,
13426 +print_context_stack(struct task_struct *task, void *stack_start,
13427 unsigned long *stack, unsigned long bp,
13428 const struct stacktrace_ops *ops, void *data,
13429 unsigned long *end, int *graph)
13430 {
13431 struct stack_frame *frame = (struct stack_frame *)bp;
13432
13433 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
13434 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
13435 unsigned long addr;
13436
13437 addr = *stack;
13438 @@ -102,7 +102,7 @@ print_context_stack(struct thread_info *
13439 } else {
13440 ops->address(data, addr, 0);
13441 }
13442 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
13443 + print_ftrace_graph_addr(addr, data, ops, task, graph);
13444 }
13445 stack++;
13446 }
13447 @@ -111,7 +111,7 @@ print_context_stack(struct thread_info *
13448 EXPORT_SYMBOL_GPL(print_context_stack);
13449
13450 unsigned long
13451 -print_context_stack_bp(struct thread_info *tinfo,
13452 +print_context_stack_bp(struct task_struct *task, void *stack_start,
13453 unsigned long *stack, unsigned long bp,
13454 const struct stacktrace_ops *ops, void *data,
13455 unsigned long *end, int *graph)
13456 @@ -119,7 +119,7 @@ print_context_stack_bp(struct thread_inf
13457 struct stack_frame *frame = (struct stack_frame *)bp;
13458 unsigned long *ret_addr = &frame->return_address;
13459
13460 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
13461 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
13462 unsigned long addr = *ret_addr;
13463
13464 if (!__kernel_text_address(addr))
13465 @@ -128,7 +128,7 @@ print_context_stack_bp(struct thread_inf
13466 ops->address(data, addr, 1);
13467 frame = frame->next_frame;
13468 ret_addr = &frame->return_address;
13469 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
13470 + print_ftrace_graph_addr(addr, data, ops, task, graph);
13471 }
13472
13473 return (unsigned long)frame;
13474 @@ -202,7 +202,7 @@ void dump_stack(void)
13475
13476 bp = stack_frame(current, NULL);
13477 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
13478 - current->pid, current->comm, print_tainted(),
13479 + task_pid_nr(current), current->comm, print_tainted(),
13480 init_utsname()->release,
13481 (int)strcspn(init_utsname()->version, " "),
13482 init_utsname()->version);
13483 @@ -238,6 +238,8 @@ unsigned __kprobes long oops_begin(void)
13484 }
13485 EXPORT_SYMBOL_GPL(oops_begin);
13486
13487 +extern void gr_handle_kernel_exploit(void);
13488 +
13489 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
13490 {
13491 if (regs && kexec_should_crash(current))
13492 @@ -259,7 +261,10 @@ void __kprobes oops_end(unsigned long fl
13493 panic("Fatal exception in interrupt");
13494 if (panic_on_oops)
13495 panic("Fatal exception");
13496 - do_exit(signr);
13497 +
13498 + gr_handle_kernel_exploit();
13499 +
13500 + do_group_exit(signr);
13501 }
13502
13503 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
13504 @@ -286,7 +291,7 @@ int __kprobes __die(const char *str, str
13505
13506 show_registers(regs);
13507 #ifdef CONFIG_X86_32
13508 - if (user_mode_vm(regs)) {
13509 + if (user_mode(regs)) {
13510 sp = regs->sp;
13511 ss = regs->ss & 0xffff;
13512 } else {
13513 @@ -314,7 +319,7 @@ void die(const char *str, struct pt_regs
13514 unsigned long flags = oops_begin();
13515 int sig = SIGSEGV;
13516
13517 - if (!user_mode_vm(regs))
13518 + if (!user_mode(regs))
13519 report_bug(regs->ip, regs);
13520
13521 if (__die(str, regs, err))
13522 diff -urNp linux-2.6.39/arch/x86/kernel/early_printk.c linux-2.6.39/arch/x86/kernel/early_printk.c
13523 --- linux-2.6.39/arch/x86/kernel/early_printk.c 2011-05-19 00:06:34.000000000 -0400
13524 +++ linux-2.6.39/arch/x86/kernel/early_printk.c 2011-05-22 19:36:30.000000000 -0400
13525 @@ -7,6 +7,7 @@
13526 #include <linux/pci_regs.h>
13527 #include <linux/pci_ids.h>
13528 #include <linux/errno.h>
13529 +#include <linux/sched.h>
13530 #include <asm/io.h>
13531 #include <asm/processor.h>
13532 #include <asm/fcntl.h>
13533 @@ -179,6 +180,8 @@ asmlinkage void early_printk(const char
13534 int n;
13535 va_list ap;
13536
13537 + pax_track_stack();
13538 +
13539 va_start(ap, fmt);
13540 n = vscnprintf(buf, sizeof(buf), fmt, ap);
13541 early_console->write(early_console, buf, n);
13542 diff -urNp linux-2.6.39/arch/x86/kernel/entry_32.S linux-2.6.39/arch/x86/kernel/entry_32.S
13543 --- linux-2.6.39/arch/x86/kernel/entry_32.S 2011-05-19 00:06:34.000000000 -0400
13544 +++ linux-2.6.39/arch/x86/kernel/entry_32.S 2011-05-23 17:07:00.000000000 -0400
13545 @@ -185,13 +185,146 @@
13546 /*CFI_REL_OFFSET gs, PT_GS*/
13547 .endm
13548 .macro SET_KERNEL_GS reg
13549 +
13550 +#ifdef CONFIG_CC_STACKPROTECTOR
13551 movl $(__KERNEL_STACK_CANARY), \reg
13552 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
13553 + movl $(__USER_DS), \reg
13554 +#else
13555 + xorl \reg, \reg
13556 +#endif
13557 +
13558 movl \reg, %gs
13559 .endm
13560
13561 #endif /* CONFIG_X86_32_LAZY_GS */
13562
13563 -.macro SAVE_ALL
13564 +.macro pax_enter_kernel
13565 +#ifdef CONFIG_PAX_KERNEXEC
13566 + call pax_enter_kernel
13567 +#endif
13568 +.endm
13569 +
13570 +.macro pax_exit_kernel
13571 +#ifdef CONFIG_PAX_KERNEXEC
13572 + call pax_exit_kernel
13573 +#endif
13574 +.endm
13575 +
13576 +#ifdef CONFIG_PAX_KERNEXEC
13577 +ENTRY(pax_enter_kernel)
13578 +#ifdef CONFIG_PARAVIRT
13579 + pushl %eax
13580 + pushl %ecx
13581 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
13582 + mov %eax, %esi
13583 +#else
13584 + mov %cr0, %esi
13585 +#endif
13586 + bts $16, %esi
13587 + jnc 1f
13588 + mov %cs, %esi
13589 + cmp $__KERNEL_CS, %esi
13590 + jz 3f
13591 + ljmp $__KERNEL_CS, $3f
13592 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
13593 +2:
13594 +#ifdef CONFIG_PARAVIRT
13595 + mov %esi, %eax
13596 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
13597 +#else
13598 + mov %esi, %cr0
13599 +#endif
13600 +3:
13601 +#ifdef CONFIG_PARAVIRT
13602 + popl %ecx
13603 + popl %eax
13604 +#endif
13605 + ret
13606 +ENDPROC(pax_enter_kernel)
13607 +
13608 +ENTRY(pax_exit_kernel)
13609 +#ifdef CONFIG_PARAVIRT
13610 + pushl %eax
13611 + pushl %ecx
13612 +#endif
13613 + mov %cs, %esi
13614 + cmp $__KERNEXEC_KERNEL_CS, %esi
13615 + jnz 2f
13616 +#ifdef CONFIG_PARAVIRT
13617 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
13618 + mov %eax, %esi
13619 +#else
13620 + mov %cr0, %esi
13621 +#endif
13622 + btr $16, %esi
13623 + ljmp $__KERNEL_CS, $1f
13624 +1:
13625 +#ifdef CONFIG_PARAVIRT
13626 + mov %esi, %eax
13627 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
13628 +#else
13629 + mov %esi, %cr0
13630 +#endif
13631 +2:
13632 +#ifdef CONFIG_PARAVIRT
13633 + popl %ecx
13634 + popl %eax
13635 +#endif
13636 + ret
13637 +ENDPROC(pax_exit_kernel)
13638 +#endif
13639 +
13640 +.macro pax_erase_kstack
13641 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
13642 + call pax_erase_kstack
13643 +#endif
13644 +.endm
13645 +
13646 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
13647 +/*
13648 + * ebp: thread_info
13649 + * ecx, edx: can be clobbered
13650 + */
13651 +ENTRY(pax_erase_kstack)
13652 + pushl %edi
13653 + pushl %eax
13654 +
13655 + mov TI_lowest_stack(%ebp), %edi
13656 + mov $-0xBEEF, %eax
13657 + std
13658 +
13659 +1: mov %edi, %ecx
13660 + and $THREAD_SIZE_asm - 1, %ecx
13661 + shr $2, %ecx
13662 + repne scasl
13663 + jecxz 2f
13664 +
13665 + cmp $2*16, %ecx
13666 + jc 2f
13667 +
13668 + mov $2*16, %ecx
13669 + repe scasl
13670 + jecxz 2f
13671 + jne 1b
13672 +
13673 +2: cld
13674 + mov %esp, %ecx
13675 + sub %edi, %ecx
13676 + shr $2, %ecx
13677 + rep stosl
13678 +
13679 + mov TI_task_thread_sp0(%ebp), %edi
13680 + sub $128, %edi
13681 + mov %edi, TI_lowest_stack(%ebp)
13682 +
13683 + popl %eax
13684 + popl %edi
13685 + ret
13686 +ENDPROC(pax_erase_kstack)
13687 +#endif
13688 +
13689 +.macro __SAVE_ALL _DS
13690 cld
13691 PUSH_GS
13692 pushl_cfi %fs
13693 @@ -214,7 +347,7 @@
13694 CFI_REL_OFFSET ecx, 0
13695 pushl_cfi %ebx
13696 CFI_REL_OFFSET ebx, 0
13697 - movl $(__USER_DS), %edx
13698 + movl $\_DS, %edx
13699 movl %edx, %ds
13700 movl %edx, %es
13701 movl $(__KERNEL_PERCPU), %edx
13702 @@ -222,6 +355,15 @@
13703 SET_KERNEL_GS %edx
13704 .endm
13705
13706 +.macro SAVE_ALL
13707 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
13708 + __SAVE_ALL __KERNEL_DS
13709 + pax_enter_kernel
13710 +#else
13711 + __SAVE_ALL __USER_DS
13712 +#endif
13713 +.endm
13714 +
13715 .macro RESTORE_INT_REGS
13716 popl_cfi %ebx
13717 CFI_RESTORE ebx
13718 @@ -332,7 +474,15 @@ check_userspace:
13719 movb PT_CS(%esp), %al
13720 andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax
13721 cmpl $USER_RPL, %eax
13722 +
13723 +#ifdef CONFIG_PAX_KERNEXEC
13724 + jae resume_userspace
13725 +
13726 + PAX_EXIT_KERNEL
13727 + jmp resume_kernel
13728 +#else
13729 jb resume_kernel # not returning to v8086 or userspace
13730 +#endif
13731
13732 ENTRY(resume_userspace)
13733 LOCKDEP_SYS_EXIT
13734 @@ -344,7 +494,7 @@ ENTRY(resume_userspace)
13735 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
13736 # int/exception return?
13737 jne work_pending
13738 - jmp restore_all
13739 + jmp restore_all_pax
13740 END(ret_from_exception)
13741
13742 #ifdef CONFIG_PREEMPT
13743 @@ -394,23 +544,34 @@ sysenter_past_esp:
13744 /*CFI_REL_OFFSET cs, 0*/
13745 /*
13746 * Push current_thread_info()->sysenter_return to the stack.
13747 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
13748 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
13749 */
13750 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
13751 + pushl_cfi $0
13752 CFI_REL_OFFSET eip, 0
13753
13754 pushl_cfi %eax
13755 SAVE_ALL
13756 + GET_THREAD_INFO(%ebp)
13757 + movl TI_sysenter_return(%ebp),%ebp
13758 + movl %ebp,PT_EIP(%esp)
13759 ENABLE_INTERRUPTS(CLBR_NONE)
13760
13761 /*
13762 * Load the potential sixth argument from user stack.
13763 * Careful about security.
13764 */
13765 + movl PT_OLDESP(%esp),%ebp
13766 +
13767 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13768 + mov PT_OLDSS(%esp),%ds
13769 +1: movl %ds:(%ebp),%ebp
13770 + push %ss
13771 + pop %ds
13772 +#else
13773 cmpl $__PAGE_OFFSET-3,%ebp
13774 jae syscall_fault
13775 1: movl (%ebp),%ebp
13776 +#endif
13777 +
13778 movl %ebp,PT_EBP(%esp)
13779 .section __ex_table,"a"
13780 .align 4
13781 @@ -433,12 +594,23 @@ sysenter_do_call:
13782 testl $_TIF_ALLWORK_MASK, %ecx
13783 jne sysexit_audit
13784 sysenter_exit:
13785 +
13786 +#ifdef CONFIG_PAX_RANDKSTACK
13787 + pushl_cfi %eax
13788 + call pax_randomize_kstack
13789 + popl_cfi %eax
13790 +#endif
13791 +
13792 + pax_erase_kstack
13793 +
13794 /* if something modifies registers it must also disable sysexit */
13795 movl PT_EIP(%esp), %edx
13796 movl PT_OLDESP(%esp), %ecx
13797 xorl %ebp,%ebp
13798 TRACE_IRQS_ON
13799 1: mov PT_FS(%esp), %fs
13800 +2: mov PT_DS(%esp), %ds
13801 +3: mov PT_ES(%esp), %es
13802 PTGS_TO_GS
13803 ENABLE_INTERRUPTS_SYSEXIT
13804
13805 @@ -455,6 +627,9 @@ sysenter_audit:
13806 movl %eax,%edx /* 2nd arg: syscall number */
13807 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
13808 call audit_syscall_entry
13809 +
13810 + pax_erase_kstack
13811 +
13812 pushl_cfi %ebx
13813 movl PT_EAX(%esp),%eax /* reload syscall number */
13814 jmp sysenter_do_call
13815 @@ -481,11 +656,17 @@ sysexit_audit:
13816
13817 CFI_ENDPROC
13818 .pushsection .fixup,"ax"
13819 -2: movl $0,PT_FS(%esp)
13820 +4: movl $0,PT_FS(%esp)
13821 + jmp 1b
13822 +5: movl $0,PT_DS(%esp)
13823 + jmp 1b
13824 +6: movl $0,PT_ES(%esp)
13825 jmp 1b
13826 .section __ex_table,"a"
13827 .align 4
13828 - .long 1b,2b
13829 + .long 1b,4b
13830 + .long 2b,5b
13831 + .long 3b,6b
13832 .popsection
13833 PTGS_TO_GS_EX
13834 ENDPROC(ia32_sysenter_target)
13835 @@ -518,6 +699,14 @@ syscall_exit:
13836 testl $_TIF_ALLWORK_MASK, %ecx # current->work
13837 jne syscall_exit_work
13838
13839 +restore_all_pax:
13840 +
13841 +#ifdef CONFIG_PAX_RANDKSTACK
13842 + call pax_randomize_kstack
13843 +#endif
13844 +
13845 + pax_erase_kstack
13846 +
13847 restore_all:
13848 TRACE_IRQS_IRET
13849 restore_all_notrace:
13850 @@ -577,14 +766,21 @@ ldt_ss:
13851 * compensating for the offset by changing to the ESPFIX segment with
13852 * a base address that matches for the difference.
13853 */
13854 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
13855 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
13856 mov %esp, %edx /* load kernel esp */
13857 mov PT_OLDESP(%esp), %eax /* load userspace esp */
13858 mov %dx, %ax /* eax: new kernel esp */
13859 sub %eax, %edx /* offset (low word is 0) */
13860 +#ifdef CONFIG_SMP
13861 + movl PER_CPU_VAR(cpu_number), %ebx
13862 + shll $PAGE_SHIFT_asm, %ebx
13863 + addl $cpu_gdt_table, %ebx
13864 +#else
13865 + movl $cpu_gdt_table, %ebx
13866 +#endif
13867 shr $16, %edx
13868 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
13869 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
13870 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
13871 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
13872 pushl_cfi $__ESPFIX_SS
13873 pushl_cfi %eax /* new kernel esp */
13874 /* Disable interrupts, but do not irqtrace this section: we
13875 @@ -613,29 +809,23 @@ work_resched:
13876 movl TI_flags(%ebp), %ecx
13877 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
13878 # than syscall tracing?
13879 - jz restore_all
13880 + jz restore_all_pax
13881 testb $_TIF_NEED_RESCHED, %cl
13882 jnz work_resched
13883
13884 work_notifysig: # deal with pending signals and
13885 # notify-resume requests
13886 + movl %esp, %eax
13887 #ifdef CONFIG_VM86
13888 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
13889 - movl %esp, %eax
13890 - jne work_notifysig_v86 # returning to kernel-space or
13891 + jz 1f # returning to kernel-space or
13892 # vm86-space
13893 - xorl %edx, %edx
13894 - call do_notify_resume
13895 - jmp resume_userspace_sig
13896
13897 - ALIGN
13898 -work_notifysig_v86:
13899 pushl_cfi %ecx # save ti_flags for do_notify_resume
13900 call save_v86_state # %eax contains pt_regs pointer
13901 popl_cfi %ecx
13902 movl %eax, %esp
13903 -#else
13904 - movl %esp, %eax
13905 +1:
13906 #endif
13907 xorl %edx, %edx
13908 call do_notify_resume
13909 @@ -648,6 +838,9 @@ syscall_trace_entry:
13910 movl $-ENOSYS,PT_EAX(%esp)
13911 movl %esp, %eax
13912 call syscall_trace_enter
13913 +
13914 + pax_erase_kstack
13915 +
13916 /* What it returned is what we'll actually use. */
13917 cmpl $(nr_syscalls), %eax
13918 jnae syscall_call
13919 @@ -670,6 +863,10 @@ END(syscall_exit_work)
13920
13921 RING0_INT_FRAME # can't unwind into user space anyway
13922 syscall_fault:
13923 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13924 + push %ss
13925 + pop %ds
13926 +#endif
13927 GET_THREAD_INFO(%ebp)
13928 movl $-EFAULT,PT_EAX(%esp)
13929 jmp resume_userspace
13930 @@ -752,6 +949,36 @@ ptregs_clone:
13931 CFI_ENDPROC
13932 ENDPROC(ptregs_clone)
13933
13934 + ALIGN;
13935 +ENTRY(kernel_execve)
13936 + CFI_STARTPROC
13937 + pushl_cfi %ebp
13938 + sub $PT_OLDSS+4,%esp
13939 + pushl_cfi %edi
13940 + pushl_cfi %ecx
13941 + pushl_cfi %eax
13942 + lea 3*4(%esp),%edi
13943 + mov $PT_OLDSS/4+1,%ecx
13944 + xorl %eax,%eax
13945 + rep stosl
13946 + popl_cfi %eax
13947 + popl_cfi %ecx
13948 + popl_cfi %edi
13949 + movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
13950 + pushl_cfi %esp
13951 + call sys_execve
13952 + add $4,%esp
13953 + CFI_ADJUST_CFA_OFFSET -4
13954 + GET_THREAD_INFO(%ebp)
13955 + test %eax,%eax
13956 + jz syscall_exit
13957 + add $PT_OLDSS+4,%esp
13958 + CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
13959 + popl_cfi %ebp
13960 + ret
13961 + CFI_ENDPROC
13962 +ENDPROC(kernel_execve)
13963 +
13964 .macro FIXUP_ESPFIX_STACK
13965 /*
13966 * Switch back for ESPFIX stack to the normal zerobased stack
13967 @@ -761,8 +988,15 @@ ENDPROC(ptregs_clone)
13968 * normal stack and adjusts ESP with the matching offset.
13969 */
13970 /* fixup the stack */
13971 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
13972 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
13973 +#ifdef CONFIG_SMP
13974 + movl PER_CPU_VAR(cpu_number), %ebx
13975 + shll $PAGE_SHIFT_asm, %ebx
13976 + addl $cpu_gdt_table, %ebx
13977 +#else
13978 + movl $cpu_gdt_table, %ebx
13979 +#endif
13980 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
13981 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
13982 shl $16, %eax
13983 addl %esp, %eax /* the adjusted stack pointer */
13984 pushl_cfi $__KERNEL_DS
13985 @@ -1213,7 +1447,6 @@ return_to_handler:
13986 jmp *%ecx
13987 #endif
13988
13989 -.section .rodata,"a"
13990 #include "syscall_table_32.S"
13991
13992 syscall_table_size=(.-sys_call_table)
13993 @@ -1259,9 +1492,12 @@ error_code:
13994 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
13995 REG_TO_PTGS %ecx
13996 SET_KERNEL_GS %ecx
13997 - movl $(__USER_DS), %ecx
13998 + movl $(__KERNEL_DS), %ecx
13999 movl %ecx, %ds
14000 movl %ecx, %es
14001 +
14002 + pax_enter_kernel
14003 +
14004 TRACE_IRQS_OFF
14005 movl %esp,%eax # pt_regs pointer
14006 call *%edi
14007 @@ -1346,6 +1582,9 @@ nmi_stack_correct:
14008 xorl %edx,%edx # zero error code
14009 movl %esp,%eax # pt_regs pointer
14010 call do_nmi
14011 +
14012 + pax_exit_kernel
14013 +
14014 jmp restore_all_notrace
14015 CFI_ENDPROC
14016
14017 @@ -1382,6 +1621,9 @@ nmi_espfix_stack:
14018 FIXUP_ESPFIX_STACK # %eax == %esp
14019 xorl %edx,%edx # zero error code
14020 call do_nmi
14021 +
14022 + pax_exit_kernel
14023 +
14024 RESTORE_REGS
14025 lss 12+4(%esp), %esp # back to espfix stack
14026 CFI_ADJUST_CFA_OFFSET -24
14027 diff -urNp linux-2.6.39/arch/x86/kernel/entry_64.S linux-2.6.39/arch/x86/kernel/entry_64.S
14028 --- linux-2.6.39/arch/x86/kernel/entry_64.S 2011-05-19 00:06:34.000000000 -0400
14029 +++ linux-2.6.39/arch/x86/kernel/entry_64.S 2011-05-23 17:10:49.000000000 -0400
14030 @@ -53,6 +53,7 @@
14031 #include <asm/paravirt.h>
14032 #include <asm/ftrace.h>
14033 #include <asm/percpu.h>
14034 +#include <asm/pgtable.h>
14035
14036 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
14037 #include <linux/elf-em.h>
14038 @@ -176,6 +177,259 @@ ENTRY(native_usergs_sysret64)
14039 ENDPROC(native_usergs_sysret64)
14040 #endif /* CONFIG_PARAVIRT */
14041
14042 + .macro ljmpq sel, off
14043 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
14044 + .byte 0x48; ljmp *1234f(%rip)
14045 + .pushsection .rodata
14046 + .align 16
14047 + 1234: .quad \off; .word \sel
14048 + .popsection
14049 +#else
14050 + pushq $\sel
14051 + pushq $\off
14052 + lretq
14053 +#endif
14054 + .endm
14055 +
14056 + .macro pax_enter_kernel
14057 +#ifdef CONFIG_PAX_KERNEXEC
14058 + call pax_enter_kernel
14059 +#endif
14060 + .endm
14061 +
14062 + .macro pax_exit_kernel
14063 +#ifdef CONFIG_PAX_KERNEXEC
14064 + call pax_exit_kernel
14065 +#endif
14066 + .endm
14067 +
14068 +#ifdef CONFIG_PAX_KERNEXEC
14069 +ENTRY(pax_enter_kernel)
14070 + pushq %rdi
14071 +
14072 +#ifdef CONFIG_PARAVIRT
14073 + PV_SAVE_REGS(CLBR_RDI)
14074 +#endif
14075 +
14076 + GET_CR0_INTO_RDI
14077 + bts $16,%rdi
14078 + jnc 1f
14079 + mov %cs,%edi
14080 + cmp $__KERNEL_CS,%edi
14081 + jz 3f
14082 + ljmpq __KERNEL_CS,3f
14083 +1: ljmpq __KERNEXEC_KERNEL_CS,2f
14084 +2: SET_RDI_INTO_CR0
14085 +3:
14086 +
14087 +#ifdef CONFIG_PARAVIRT
14088 + PV_RESTORE_REGS(CLBR_RDI)
14089 +#endif
14090 +
14091 + popq %rdi
14092 + retq
14093 +ENDPROC(pax_enter_kernel)
14094 +
14095 +ENTRY(pax_exit_kernel)
14096 + pushq %rdi
14097 +
14098 +#ifdef CONFIG_PARAVIRT
14099 + PV_SAVE_REGS(CLBR_RDI)
14100 +#endif
14101 +
14102 + mov %cs,%rdi
14103 + cmp $__KERNEXEC_KERNEL_CS,%edi
14104 + jnz 2f
14105 + GET_CR0_INTO_RDI
14106 + btr $16,%rdi
14107 + ljmpq __KERNEL_CS,1f
14108 +1: SET_RDI_INTO_CR0
14109 +2:
14110 +
14111 +#ifdef CONFIG_PARAVIRT
14112 + PV_RESTORE_REGS(CLBR_RDI);
14113 +#endif
14114 +
14115 + popq %rdi
14116 + retq
14117 +ENDPROC(pax_exit_kernel)
14118 +#endif
14119 +
14120 + .macro pax_enter_kernel_user
14121 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14122 + call pax_enter_kernel_user
14123 +#endif
14124 + .endm
14125 +
14126 + .macro pax_exit_kernel_user
14127 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14128 + call pax_exit_kernel_user
14129 +#endif
14130 +#ifdef CONFIG_PAX_RANDKSTACK
14131 + push %rax
14132 + call pax_randomize_kstack
14133 + pop %rax
14134 +#endif
14135 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14136 + call pax_erase_kstack
14137 +#endif
14138 + .endm
14139 +
14140 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14141 +ENTRY(pax_enter_kernel_user)
14142 + pushq %rdi
14143 + pushq %rbx
14144 +
14145 +#ifdef CONFIG_PARAVIRT
14146 + PV_SAVE_REGS(CLBR_RDI)
14147 +#endif
14148 +
14149 + GET_CR3_INTO_RDI
14150 + mov %rdi,%rbx
14151 + add $__START_KERNEL_map,%rbx
14152 + sub phys_base(%rip),%rbx
14153 +
14154 +#ifdef CONFIG_PARAVIRT
14155 + pushq %rdi
14156 + cmpl $0, pv_info+PARAVIRT_enabled
14157 + jz 1f
14158 + i = 0
14159 + .rept USER_PGD_PTRS
14160 + mov i*8(%rbx),%rsi
14161 + mov $0,%sil
14162 + lea i*8(%rbx),%rdi
14163 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd)
14164 + i = i + 1
14165 + .endr
14166 + jmp 2f
14167 +1:
14168 +#endif
14169 +
14170 + i = 0
14171 + .rept USER_PGD_PTRS
14172 + movb $0,i*8(%rbx)
14173 + i = i + 1
14174 + .endr
14175 +
14176 +#ifdef CONFIG_PARAVIRT
14177 +2: popq %rdi
14178 +#endif
14179 + SET_RDI_INTO_CR3
14180 +
14181 +#ifdef CONFIG_PAX_KERNEXEC
14182 + GET_CR0_INTO_RDI
14183 + bts $16,%rdi
14184 + SET_RDI_INTO_CR0
14185 +#endif
14186 +
14187 +#ifdef CONFIG_PARAVIRT
14188 + PV_RESTORE_REGS(CLBR_RDI)
14189 +#endif
14190 +
14191 + popq %rbx
14192 + popq %rdi
14193 + retq
14194 +ENDPROC(pax_enter_kernel_user)
14195 +
14196 +ENTRY(pax_exit_kernel_user)
14197 + push %rdi
14198 +
14199 +#ifdef CONFIG_PARAVIRT
14200 + pushq %rbx
14201 + PV_SAVE_REGS(CLBR_RDI)
14202 +#endif
14203 +
14204 +#ifdef CONFIG_PAX_KERNEXEC
14205 + GET_CR0_INTO_RDI
14206 + btr $16,%rdi
14207 + SET_RDI_INTO_CR0
14208 +#endif
14209 +
14210 + GET_CR3_INTO_RDI
14211 + add $__START_KERNEL_map,%rdi
14212 + sub phys_base(%rip),%rdi
14213 +
14214 +#ifdef CONFIG_PARAVIRT
14215 + cmpl $0, pv_info+PARAVIRT_enabled
14216 + jz 1f
14217 + mov %rdi,%rbx
14218 + i = 0
14219 + .rept USER_PGD_PTRS
14220 + mov i*8(%rbx),%rsi
14221 + mov $0x67,%sil
14222 + lea i*8(%rbx),%rdi
14223 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd)
14224 + i = i + 1
14225 + .endr
14226 + jmp 2f
14227 +1:
14228 +#endif
14229 +
14230 + i = 0
14231 + .rept USER_PGD_PTRS
14232 + movb $0x67,i*8(%rdi)
14233 + i = i + 1
14234 + .endr
14235 +
14236 +#ifdef CONFIG_PARAVIRT
14237 +2: PV_RESTORE_REGS(CLBR_RDI)
14238 + popq %rbx
14239 +#endif
14240 +
14241 + popq %rdi
14242 + retq
14243 +ENDPROC(pax_exit_kernel_user)
14244 +#endif
14245 +
14246 + .macro pax_erase_kstack
14247 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14248 + call pax_erase_kstack
14249 +#endif
14250 + .endm
14251 +
14252 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14253 +/*
14254 + * r10: thread_info
14255 + * rcx, rdx: can be clobbered
14256 + */
14257 +ENTRY(pax_erase_kstack)
14258 + pushq %rdi
14259 + pushq %rax
14260 +
14261 + GET_THREAD_INFO(%r10)
14262 + mov TI_lowest_stack(%r10), %rdi
14263 + mov $-0xBEEF, %rax
14264 + std
14265 +
14266 +1: mov %edi, %ecx
14267 + and $THREAD_SIZE_asm - 1, %ecx
14268 + shr $3, %ecx
14269 + repne scasq
14270 + jecxz 2f
14271 +
14272 + cmp $2*8, %ecx
14273 + jc 2f
14274 +
14275 + mov $2*8, %ecx
14276 + repe scasq
14277 + jecxz 2f
14278 + jne 1b
14279 +
14280 +2: cld
14281 + mov %esp, %ecx
14282 + sub %edi, %ecx
14283 + shr $3, %ecx
14284 + rep stosq
14285 +
14286 + mov TI_task_thread_sp0(%r10), %rdi
14287 + sub $256, %rdi
14288 + mov %rdi, TI_lowest_stack(%r10)
14289 +
14290 + popq %rax
14291 + popq %rdi
14292 + ret
14293 +ENDPROC(pax_erase_kstack)
14294 +#endif
14295
14296 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
14297 #ifdef CONFIG_TRACE_IRQFLAGS
14298 @@ -318,7 +572,7 @@ ENTRY(save_args)
14299 leaq -RBP+8(%rsp),%rdi /* arg1 for handler */
14300 movq_cfi rbp, 8 /* push %rbp */
14301 leaq 8(%rsp), %rbp /* mov %rsp, %ebp */
14302 - testl $3, CS(%rdi)
14303 + testb $3, CS(%rdi)
14304 je 1f
14305 SWAPGS
14306 /*
14307 @@ -409,7 +663,7 @@ ENTRY(ret_from_fork)
14308
14309 RESTORE_REST
14310
14311 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
14312 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
14313 je int_ret_from_sys_call
14314
14315 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
14316 @@ -455,7 +709,7 @@ END(ret_from_fork)
14317 ENTRY(system_call)
14318 CFI_STARTPROC simple
14319 CFI_SIGNAL_FRAME
14320 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
14321 + CFI_DEF_CFA rsp,0
14322 CFI_REGISTER rip,rcx
14323 /*CFI_REGISTER rflags,r11*/
14324 SWAPGS_UNSAFE_STACK
14325 @@ -468,12 +722,13 @@ ENTRY(system_call_after_swapgs)
14326
14327 movq %rsp,PER_CPU_VAR(old_rsp)
14328 movq PER_CPU_VAR(kernel_stack),%rsp
14329 + pax_enter_kernel_user
14330 /*
14331 * No need to follow this irqs off/on section - it's straight
14332 * and short:
14333 */
14334 ENABLE_INTERRUPTS(CLBR_NONE)
14335 - SAVE_ARGS 8,1
14336 + SAVE_ARGS 8*6,1
14337 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
14338 movq %rcx,RIP-ARGOFFSET(%rsp)
14339 CFI_REL_OFFSET rip,RIP-ARGOFFSET
14340 @@ -502,6 +757,7 @@ sysret_check:
14341 andl %edi,%edx
14342 jnz sysret_careful
14343 CFI_REMEMBER_STATE
14344 + pax_exit_kernel_user
14345 /*
14346 * sysretq will re-enable interrupts:
14347 */
14348 @@ -560,6 +816,9 @@ auditsys:
14349 movq %rax,%rsi /* 2nd arg: syscall number */
14350 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
14351 call audit_syscall_entry
14352 +
14353 + pax_erase_kstack
14354 +
14355 LOAD_ARGS 0 /* reload call-clobbered registers */
14356 jmp system_call_fastpath
14357
14358 @@ -590,6 +849,9 @@ tracesys:
14359 FIXUP_TOP_OF_STACK %rdi
14360 movq %rsp,%rdi
14361 call syscall_trace_enter
14362 +
14363 + pax_erase_kstack
14364 +
14365 /*
14366 * Reload arg registers from stack in case ptrace changed them.
14367 * We don't reload %rax because syscall_trace_enter() returned
14368 @@ -611,7 +873,7 @@ tracesys:
14369 GLOBAL(int_ret_from_sys_call)
14370 DISABLE_INTERRUPTS(CLBR_NONE)
14371 TRACE_IRQS_OFF
14372 - testl $3,CS-ARGOFFSET(%rsp)
14373 + testb $3,CS-ARGOFFSET(%rsp)
14374 je retint_restore_args
14375 movl $_TIF_ALLWORK_MASK,%edi
14376 /* edi: mask to check */
14377 @@ -793,6 +1055,16 @@ END(interrupt)
14378 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
14379 call save_args
14380 PARTIAL_FRAME 0
14381 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14382 + testb $3, CS(%rdi)
14383 + jnz 1f
14384 + pax_enter_kernel
14385 + jmp 2f
14386 +1: pax_enter_kernel_user
14387 +2:
14388 +#else
14389 + pax_enter_kernel
14390 +#endif
14391 call \func
14392 .endm
14393
14394 @@ -825,7 +1097,7 @@ ret_from_intr:
14395 CFI_ADJUST_CFA_OFFSET -8
14396 exit_intr:
14397 GET_THREAD_INFO(%rcx)
14398 - testl $3,CS-ARGOFFSET(%rsp)
14399 + testb $3,CS-ARGOFFSET(%rsp)
14400 je retint_kernel
14401
14402 /* Interrupt came from user space */
14403 @@ -847,12 +1119,14 @@ retint_swapgs: /* return to user-space
14404 * The iretq could re-enable interrupts:
14405 */
14406 DISABLE_INTERRUPTS(CLBR_ANY)
14407 + pax_exit_kernel_user
14408 TRACE_IRQS_IRETQ
14409 SWAPGS
14410 jmp restore_args
14411
14412 retint_restore_args: /* return to kernel space */
14413 DISABLE_INTERRUPTS(CLBR_ANY)
14414 + pax_exit_kernel
14415 /*
14416 * The iretq could re-enable interrupts:
14417 */
14418 @@ -1027,6 +1301,16 @@ ENTRY(\sym)
14419 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
14420 call error_entry
14421 DEFAULT_FRAME 0
14422 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14423 + testb $3, CS(%rsp)
14424 + jnz 1f
14425 + pax_enter_kernel
14426 + jmp 2f
14427 +1: pax_enter_kernel_user
14428 +2:
14429 +#else
14430 + pax_enter_kernel
14431 +#endif
14432 movq %rsp,%rdi /* pt_regs pointer */
14433 xorl %esi,%esi /* no error code */
14434 call \do_sym
14435 @@ -1044,6 +1328,16 @@ ENTRY(\sym)
14436 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
14437 call save_paranoid
14438 TRACE_IRQS_OFF
14439 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14440 + testb $3, CS(%rsp)
14441 + jnz 1f
14442 + pax_enter_kernel
14443 + jmp 2f
14444 +1: pax_enter_kernel_user
14445 +2:
14446 +#else
14447 + pax_enter_kernel
14448 +#endif
14449 movq %rsp,%rdi /* pt_regs pointer */
14450 xorl %esi,%esi /* no error code */
14451 call \do_sym
14452 @@ -1052,7 +1346,7 @@ ENTRY(\sym)
14453 END(\sym)
14454 .endm
14455
14456 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
14457 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
14458 .macro paranoidzeroentry_ist sym do_sym ist
14459 ENTRY(\sym)
14460 INTR_FRAME
14461 @@ -1062,8 +1356,24 @@ ENTRY(\sym)
14462 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
14463 call save_paranoid
14464 TRACE_IRQS_OFF
14465 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14466 + testb $3, CS(%rsp)
14467 + jnz 1f
14468 + pax_enter_kernel
14469 + jmp 2f
14470 +1: pax_enter_kernel_user
14471 +2:
14472 +#else
14473 + pax_enter_kernel
14474 +#endif
14475 movq %rsp,%rdi /* pt_regs pointer */
14476 xorl %esi,%esi /* no error code */
14477 +#ifdef CONFIG_SMP
14478 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
14479 + lea init_tss(%r12), %r12
14480 +#else
14481 + lea init_tss(%rip), %r12
14482 +#endif
14483 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
14484 call \do_sym
14485 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
14486 @@ -1080,6 +1390,16 @@ ENTRY(\sym)
14487 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
14488 call error_entry
14489 DEFAULT_FRAME 0
14490 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14491 + testb $3, CS(%rsp)
14492 + jnz 1f
14493 + pax_enter_kernel
14494 + jmp 2f
14495 +1: pax_enter_kernel_user
14496 +2:
14497 +#else
14498 + pax_enter_kernel
14499 +#endif
14500 movq %rsp,%rdi /* pt_regs pointer */
14501 movq ORIG_RAX(%rsp),%rsi /* get error code */
14502 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
14503 @@ -1099,6 +1419,16 @@ ENTRY(\sym)
14504 call save_paranoid
14505 DEFAULT_FRAME 0
14506 TRACE_IRQS_OFF
14507 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14508 + testb $3, CS(%rsp)
14509 + jnz 1f
14510 + pax_enter_kernel
14511 + jmp 2f
14512 +1: pax_enter_kernel_user
14513 +2:
14514 +#else
14515 + pax_enter_kernel
14516 +#endif
14517 movq %rsp,%rdi /* pt_regs pointer */
14518 movq ORIG_RAX(%rsp),%rsi /* get error code */
14519 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
14520 @@ -1361,14 +1691,27 @@ ENTRY(paranoid_exit)
14521 TRACE_IRQS_OFF
14522 testl %ebx,%ebx /* swapgs needed? */
14523 jnz paranoid_restore
14524 - testl $3,CS(%rsp)
14525 + testb $3,CS(%rsp)
14526 jnz paranoid_userspace
14527 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14528 + pax_exit_kernel
14529 + TRACE_IRQS_IRETQ 0
14530 + SWAPGS_UNSAFE_STACK
14531 + RESTORE_ALL 8
14532 + jmp irq_return
14533 +#endif
14534 paranoid_swapgs:
14535 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14536 + pax_exit_kernel_user
14537 +#else
14538 + pax_exit_kernel
14539 +#endif
14540 TRACE_IRQS_IRETQ 0
14541 SWAPGS_UNSAFE_STACK
14542 RESTORE_ALL 8
14543 jmp irq_return
14544 paranoid_restore:
14545 + pax_exit_kernel
14546 TRACE_IRQS_IRETQ 0
14547 RESTORE_ALL 8
14548 jmp irq_return
14549 @@ -1426,7 +1769,7 @@ ENTRY(error_entry)
14550 movq_cfi r14, R14+8
14551 movq_cfi r15, R15+8
14552 xorl %ebx,%ebx
14553 - testl $3,CS+8(%rsp)
14554 + testb $3,CS+8(%rsp)
14555 je error_kernelspace
14556 error_swapgs:
14557 SWAPGS
14558 @@ -1490,6 +1833,16 @@ ENTRY(nmi)
14559 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
14560 call save_paranoid
14561 DEFAULT_FRAME 0
14562 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14563 + testb $3, CS(%rsp)
14564 + jnz 1f
14565 + pax_enter_kernel
14566 + jmp 2f
14567 +1: pax_enter_kernel_user
14568 +2:
14569 +#else
14570 + pax_enter_kernel
14571 +#endif
14572 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
14573 movq %rsp,%rdi
14574 movq $-1,%rsi
14575 @@ -1500,11 +1853,25 @@ ENTRY(nmi)
14576 DISABLE_INTERRUPTS(CLBR_NONE)
14577 testl %ebx,%ebx /* swapgs needed? */
14578 jnz nmi_restore
14579 - testl $3,CS(%rsp)
14580 + testb $3,CS(%rsp)
14581 jnz nmi_userspace
14582 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14583 + pax_exit_kernel
14584 + SWAPGS_UNSAFE_STACK
14585 + RESTORE_ALL 8
14586 + jmp irq_return
14587 +#endif
14588 nmi_swapgs:
14589 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14590 + pax_exit_kernel_user
14591 +#else
14592 + pax_exit_kernel
14593 +#endif
14594 SWAPGS_UNSAFE_STACK
14595 + RESTORE_ALL 8
14596 + jmp irq_return
14597 nmi_restore:
14598 + pax_exit_kernel
14599 RESTORE_ALL 8
14600 jmp irq_return
14601 nmi_userspace:
14602 diff -urNp linux-2.6.39/arch/x86/kernel/ftrace.c linux-2.6.39/arch/x86/kernel/ftrace.c
14603 --- linux-2.6.39/arch/x86/kernel/ftrace.c 2011-05-19 00:06:34.000000000 -0400
14604 +++ linux-2.6.39/arch/x86/kernel/ftrace.c 2011-05-22 19:36:30.000000000 -0400
14605 @@ -126,7 +126,7 @@ static void *mod_code_ip; /* holds the
14606 static void *mod_code_newcode; /* holds the text to write to the IP */
14607
14608 static unsigned nmi_wait_count;
14609 -static atomic_t nmi_update_count = ATOMIC_INIT(0);
14610 +static atomic_unchecked_t nmi_update_count = ATOMIC_INIT(0);
14611
14612 int ftrace_arch_read_dyn_info(char *buf, int size)
14613 {
14614 @@ -134,7 +134,7 @@ int ftrace_arch_read_dyn_info(char *buf,
14615
14616 r = snprintf(buf, size, "%u %u",
14617 nmi_wait_count,
14618 - atomic_read(&nmi_update_count));
14619 + atomic_read_unchecked(&nmi_update_count));
14620 return r;
14621 }
14622
14623 @@ -177,8 +177,10 @@ void ftrace_nmi_enter(void)
14624
14625 if (atomic_inc_return(&nmi_running) & MOD_CODE_WRITE_FLAG) {
14626 smp_rmb();
14627 + pax_open_kernel();
14628 ftrace_mod_code();
14629 - atomic_inc(&nmi_update_count);
14630 + pax_close_kernel();
14631 + atomic_inc_unchecked(&nmi_update_count);
14632 }
14633 /* Must have previous changes seen before executions */
14634 smp_mb();
14635 @@ -271,6 +273,8 @@ ftrace_modify_code(unsigned long ip, uns
14636 {
14637 unsigned char replaced[MCOUNT_INSN_SIZE];
14638
14639 + ip = ktla_ktva(ip);
14640 +
14641 /*
14642 * Note: Due to modules and __init, code can
14643 * disappear and change, we need to protect against faulting
14644 @@ -327,7 +331,7 @@ int ftrace_update_ftrace_func(ftrace_fun
14645 unsigned char old[MCOUNT_INSN_SIZE], *new;
14646 int ret;
14647
14648 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
14649 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
14650 new = ftrace_call_replace(ip, (unsigned long)func);
14651 ret = ftrace_modify_code(ip, old, new);
14652
14653 @@ -353,6 +357,8 @@ static int ftrace_mod_jmp(unsigned long
14654 {
14655 unsigned char code[MCOUNT_INSN_SIZE];
14656
14657 + ip = ktla_ktva(ip);
14658 +
14659 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
14660 return -EFAULT;
14661
14662 diff -urNp linux-2.6.39/arch/x86/kernel/head32.c linux-2.6.39/arch/x86/kernel/head32.c
14663 --- linux-2.6.39/arch/x86/kernel/head32.c 2011-05-19 00:06:34.000000000 -0400
14664 +++ linux-2.6.39/arch/x86/kernel/head32.c 2011-05-22 19:36:30.000000000 -0400
14665 @@ -19,6 +19,7 @@
14666 #include <asm/io_apic.h>
14667 #include <asm/bios_ebda.h>
14668 #include <asm/tlbflush.h>
14669 +#include <asm/boot.h>
14670
14671 static void __init i386_default_early_setup(void)
14672 {
14673 @@ -34,7 +35,7 @@ void __init i386_start_kernel(void)
14674 {
14675 memblock_init();
14676
14677 - memblock_x86_reserve_range(__pa_symbol(&_text), __pa_symbol(&__bss_stop), "TEXT DATA BSS");
14678 + memblock_x86_reserve_range(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop), "TEXT DATA BSS");
14679
14680 #ifdef CONFIG_BLK_DEV_INITRD
14681 /* Reserve INITRD */
14682 diff -urNp linux-2.6.39/arch/x86/kernel/head_32.S linux-2.6.39/arch/x86/kernel/head_32.S
14683 --- linux-2.6.39/arch/x86/kernel/head_32.S 2011-05-19 00:06:34.000000000 -0400
14684 +++ linux-2.6.39/arch/x86/kernel/head_32.S 2011-05-22 19:36:30.000000000 -0400
14685 @@ -25,6 +25,12 @@
14686 /* Physical address */
14687 #define pa(X) ((X) - __PAGE_OFFSET)
14688
14689 +#ifdef CONFIG_PAX_KERNEXEC
14690 +#define ta(X) (X)
14691 +#else
14692 +#define ta(X) ((X) - __PAGE_OFFSET)
14693 +#endif
14694 +
14695 /*
14696 * References to members of the new_cpu_data structure.
14697 */
14698 @@ -54,11 +60,7 @@
14699 * and small than max_low_pfn, otherwise will waste some page table entries
14700 */
14701
14702 -#if PTRS_PER_PMD > 1
14703 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
14704 -#else
14705 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
14706 -#endif
14707 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
14708
14709 /* Number of possible pages in the lowmem region */
14710 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
14711 @@ -77,6 +79,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_P
14712 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
14713
14714 /*
14715 + * Real beginning of normal "text" segment
14716 + */
14717 +ENTRY(stext)
14718 +ENTRY(_stext)
14719 +
14720 +/*
14721 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
14722 * %esi points to the real-mode code as a 32-bit pointer.
14723 * CS and DS must be 4 GB flat segments, but we don't depend on
14724 @@ -84,6 +92,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
14725 * can.
14726 */
14727 __HEAD
14728 +
14729 +#ifdef CONFIG_PAX_KERNEXEC
14730 + jmp startup_32
14731 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
14732 +.fill PAGE_SIZE-5,1,0xcc
14733 +#endif
14734 +
14735 ENTRY(startup_32)
14736 movl pa(stack_start),%ecx
14737
14738 @@ -105,6 +120,57 @@ ENTRY(startup_32)
14739 2:
14740 leal -__PAGE_OFFSET(%ecx),%esp
14741
14742 +#ifdef CONFIG_SMP
14743 + movl $pa(cpu_gdt_table),%edi
14744 + movl $__per_cpu_load,%eax
14745 + movw %ax,__KERNEL_PERCPU + 2(%edi)
14746 + rorl $16,%eax
14747 + movb %al,__KERNEL_PERCPU + 4(%edi)
14748 + movb %ah,__KERNEL_PERCPU + 7(%edi)
14749 + movl $__per_cpu_end - 1,%eax
14750 + subl $__per_cpu_start,%eax
14751 + movw %ax,__KERNEL_PERCPU + 0(%edi)
14752 +#endif
14753 +
14754 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14755 + movl $NR_CPUS,%ecx
14756 + movl $pa(cpu_gdt_table),%edi
14757 +1:
14758 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
14759 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
14760 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
14761 + addl $PAGE_SIZE_asm,%edi
14762 + loop 1b
14763 +#endif
14764 +
14765 +#ifdef CONFIG_PAX_KERNEXEC
14766 + movl $pa(boot_gdt),%edi
14767 + movl $__LOAD_PHYSICAL_ADDR,%eax
14768 + movw %ax,__BOOT_CS + 2(%edi)
14769 + rorl $16,%eax
14770 + movb %al,__BOOT_CS + 4(%edi)
14771 + movb %ah,__BOOT_CS + 7(%edi)
14772 + rorl $16,%eax
14773 +
14774 + ljmp $(__BOOT_CS),$1f
14775 +1:
14776 +
14777 + movl $NR_CPUS,%ecx
14778 + movl $pa(cpu_gdt_table),%edi
14779 + addl $__PAGE_OFFSET,%eax
14780 +1:
14781 + movw %ax,__KERNEL_CS + 2(%edi)
14782 + movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
14783 + rorl $16,%eax
14784 + movb %al,__KERNEL_CS + 4(%edi)
14785 + movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
14786 + movb %ah,__KERNEL_CS + 7(%edi)
14787 + movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
14788 + rorl $16,%eax
14789 + addl $PAGE_SIZE_asm,%edi
14790 + loop 1b
14791 +#endif
14792 +
14793 /*
14794 * Clear BSS first so that there are no surprises...
14795 */
14796 @@ -195,8 +261,11 @@ ENTRY(startup_32)
14797 movl %eax, pa(max_pfn_mapped)
14798
14799 /* Do early initialization of the fixmap area */
14800 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
14801 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
14802 +#ifdef CONFIG_COMPAT_VDSO
14803 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
14804 +#else
14805 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
14806 +#endif
14807 #else /* Not PAE */
14808
14809 page_pde_offset = (__PAGE_OFFSET >> 20);
14810 @@ -226,8 +295,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
14811 movl %eax, pa(max_pfn_mapped)
14812
14813 /* Do early initialization of the fixmap area */
14814 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
14815 - movl %eax,pa(initial_page_table+0xffc)
14816 +#ifdef CONFIG_COMPAT_VDSO
14817 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
14818 +#else
14819 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
14820 +#endif
14821 #endif
14822
14823 #ifdef CONFIG_PARAVIRT
14824 @@ -241,9 +313,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
14825 cmpl $num_subarch_entries, %eax
14826 jae bad_subarch
14827
14828 - movl pa(subarch_entries)(,%eax,4), %eax
14829 - subl $__PAGE_OFFSET, %eax
14830 - jmp *%eax
14831 + jmp *pa(subarch_entries)(,%eax,4)
14832
14833 bad_subarch:
14834 WEAK(lguest_entry)
14835 @@ -255,10 +325,10 @@ WEAK(xen_entry)
14836 __INITDATA
14837
14838 subarch_entries:
14839 - .long default_entry /* normal x86/PC */
14840 - .long lguest_entry /* lguest hypervisor */
14841 - .long xen_entry /* Xen hypervisor */
14842 - .long default_entry /* Moorestown MID */
14843 + .long ta(default_entry) /* normal x86/PC */
14844 + .long ta(lguest_entry) /* lguest hypervisor */
14845 + .long ta(xen_entry) /* Xen hypervisor */
14846 + .long ta(default_entry) /* Moorestown MID */
14847 num_subarch_entries = (. - subarch_entries) / 4
14848 .previous
14849 #else
14850 @@ -312,6 +382,7 @@ default_entry:
14851 orl %edx,%eax
14852 movl %eax,%cr4
14853
14854 +#ifdef CONFIG_X86_PAE
14855 testb $X86_CR4_PAE, %al # check if PAE is enabled
14856 jz 6f
14857
14858 @@ -340,6 +411,9 @@ default_entry:
14859 /* Make changes effective */
14860 wrmsr
14861
14862 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
14863 +#endif
14864 +
14865 6:
14866
14867 /*
14868 @@ -443,7 +517,7 @@ is386: movl $2,%ecx # set MP
14869 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
14870 movl %eax,%ss # after changing gdt.
14871
14872 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
14873 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
14874 movl %eax,%ds
14875 movl %eax,%es
14876
14877 @@ -457,15 +531,22 @@ is386: movl $2,%ecx # set MP
14878 */
14879 cmpb $0,ready
14880 jne 1f
14881 - movl $gdt_page,%eax
14882 + movl $cpu_gdt_table,%eax
14883 movl $stack_canary,%ecx
14884 +#ifdef CONFIG_SMP
14885 + addl $__per_cpu_load,%ecx
14886 +#endif
14887 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
14888 shrl $16, %ecx
14889 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
14890 movb %ch, 8 * GDT_ENTRY_STACK_CANARY + 7(%eax)
14891 1:
14892 -#endif
14893 movl $(__KERNEL_STACK_CANARY),%eax
14894 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
14895 + movl $(__USER_DS),%eax
14896 +#else
14897 + xorl %eax,%eax
14898 +#endif
14899 movl %eax,%gs
14900
14901 xorl %eax,%eax # Clear LDT
14902 @@ -558,22 +639,22 @@ early_page_fault:
14903 jmp early_fault
14904
14905 early_fault:
14906 - cld
14907 #ifdef CONFIG_PRINTK
14908 + cmpl $1,%ss:early_recursion_flag
14909 + je hlt_loop
14910 + incl %ss:early_recursion_flag
14911 + cld
14912 pusha
14913 movl $(__KERNEL_DS),%eax
14914 movl %eax,%ds
14915 movl %eax,%es
14916 - cmpl $2,early_recursion_flag
14917 - je hlt_loop
14918 - incl early_recursion_flag
14919 movl %cr2,%eax
14920 pushl %eax
14921 pushl %edx /* trapno */
14922 pushl $fault_msg
14923 call printk
14924 +; call dump_stack
14925 #endif
14926 - call dump_stack
14927 hlt_loop:
14928 hlt
14929 jmp hlt_loop
14930 @@ -581,8 +662,11 @@ hlt_loop:
14931 /* This is the default interrupt "handler" :-) */
14932 ALIGN
14933 ignore_int:
14934 - cld
14935 #ifdef CONFIG_PRINTK
14936 + cmpl $2,%ss:early_recursion_flag
14937 + je hlt_loop
14938 + incl %ss:early_recursion_flag
14939 + cld
14940 pushl %eax
14941 pushl %ecx
14942 pushl %edx
14943 @@ -591,9 +675,6 @@ ignore_int:
14944 movl $(__KERNEL_DS),%eax
14945 movl %eax,%ds
14946 movl %eax,%es
14947 - cmpl $2,early_recursion_flag
14948 - je hlt_loop
14949 - incl early_recursion_flag
14950 pushl 16(%esp)
14951 pushl 24(%esp)
14952 pushl 32(%esp)
14953 @@ -622,29 +703,43 @@ ENTRY(initial_code)
14954 /*
14955 * BSS section
14956 */
14957 -__PAGE_ALIGNED_BSS
14958 - .align PAGE_SIZE
14959 #ifdef CONFIG_X86_PAE
14960 +.section .initial_pg_pmd,"a",@progbits
14961 initial_pg_pmd:
14962 .fill 1024*KPMDS,4,0
14963 #else
14964 +.section .initial_page_table,"a",@progbits
14965 ENTRY(initial_page_table)
14966 .fill 1024,4,0
14967 #endif
14968 +.section .initial_pg_fixmap,"a",@progbits
14969 initial_pg_fixmap:
14970 .fill 1024,4,0
14971 +.section .empty_zero_page,"a",@progbits
14972 ENTRY(empty_zero_page)
14973 .fill 4096,1,0
14974 +.section .swapper_pg_dir,"a",@progbits
14975 ENTRY(swapper_pg_dir)
14976 +#ifdef CONFIG_X86_PAE
14977 + .fill 4,8,0
14978 +#else
14979 .fill 1024,4,0
14980 +#endif
14981 +
14982 +/*
14983 + * The IDT has to be page-aligned to simplify the Pentium
14984 + * F0 0F bug workaround.. We have a special link segment
14985 + * for this.
14986 + */
14987 +.section .idt,"a",@progbits
14988 +ENTRY(idt_table)
14989 + .fill 256,8,0
14990
14991 /*
14992 * This starts the data section.
14993 */
14994 #ifdef CONFIG_X86_PAE
14995 -__PAGE_ALIGNED_DATA
14996 - /* Page-aligned for the benefit of paravirt? */
14997 - .align PAGE_SIZE
14998 +.section .initial_page_table,"a",@progbits
14999 ENTRY(initial_page_table)
15000 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
15001 # if KPMDS == 3
15002 @@ -663,18 +758,27 @@ ENTRY(initial_page_table)
15003 # error "Kernel PMDs should be 1, 2 or 3"
15004 # endif
15005 .align PAGE_SIZE /* needs to be page-sized too */
15006 +
15007 +#ifdef CONFIG_PAX_PER_CPU_PGD
15008 +ENTRY(cpu_pgd)
15009 + .rept NR_CPUS
15010 + .fill 4,8,0
15011 + .endr
15012 +#endif
15013 +
15014 #endif
15015
15016 .data
15017 .balign 4
15018 ENTRY(stack_start)
15019 - .long init_thread_union+THREAD_SIZE
15020 + .long init_thread_union+THREAD_SIZE-8
15021 +
15022 +ready: .byte 0
15023
15024 +.section .rodata,"a",@progbits
15025 early_recursion_flag:
15026 .long 0
15027
15028 -ready: .byte 0
15029 -
15030 int_msg:
15031 .asciz "Unknown interrupt or fault at: %p %p %p\n"
15032
15033 @@ -707,7 +811,7 @@ fault_msg:
15034 .word 0 # 32 bit align gdt_desc.address
15035 boot_gdt_descr:
15036 .word __BOOT_DS+7
15037 - .long boot_gdt - __PAGE_OFFSET
15038 + .long pa(boot_gdt)
15039
15040 .word 0 # 32-bit align idt_desc.address
15041 idt_descr:
15042 @@ -718,7 +822,7 @@ idt_descr:
15043 .word 0 # 32 bit align gdt_desc.address
15044 ENTRY(early_gdt_descr)
15045 .word GDT_ENTRIES*8-1
15046 - .long gdt_page /* Overwritten for secondary CPUs */
15047 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
15048
15049 /*
15050 * The boot_gdt must mirror the equivalent in setup.S and is
15051 @@ -727,5 +831,65 @@ ENTRY(early_gdt_descr)
15052 .align L1_CACHE_BYTES
15053 ENTRY(boot_gdt)
15054 .fill GDT_ENTRY_BOOT_CS,8,0
15055 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
15056 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
15057 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
15058 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
15059 +
15060 + .align PAGE_SIZE_asm
15061 +ENTRY(cpu_gdt_table)
15062 + .rept NR_CPUS
15063 + .quad 0x0000000000000000 /* NULL descriptor */
15064 + .quad 0x0000000000000000 /* 0x0b reserved */
15065 + .quad 0x0000000000000000 /* 0x13 reserved */
15066 + .quad 0x0000000000000000 /* 0x1b reserved */
15067 +
15068 +#ifdef CONFIG_PAX_KERNEXEC
15069 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
15070 +#else
15071 + .quad 0x0000000000000000 /* 0x20 unused */
15072 +#endif
15073 +
15074 + .quad 0x0000000000000000 /* 0x28 unused */
15075 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
15076 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
15077 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
15078 + .quad 0x0000000000000000 /* 0x4b reserved */
15079 + .quad 0x0000000000000000 /* 0x53 reserved */
15080 + .quad 0x0000000000000000 /* 0x5b reserved */
15081 +
15082 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
15083 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
15084 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
15085 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
15086 +
15087 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
15088 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
15089 +
15090 + /*
15091 + * Segments used for calling PnP BIOS have byte granularity.
15092 + * The code segments and data segments have fixed 64k limits,
15093 + * the transfer segment sizes are set at run time.
15094 + */
15095 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
15096 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
15097 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
15098 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
15099 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
15100 +
15101 + /*
15102 + * The APM segments have byte granularity and their bases
15103 + * are set at run time. All have 64k limits.
15104 + */
15105 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
15106 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
15107 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
15108 +
15109 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
15110 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
15111 + .quad 0x0040910000000018 /* 0xe0 - STACK_CANARY */
15112 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
15113 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
15114 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
15115 +
15116 + /* Be sure this is zeroed to avoid false validations in Xen */
15117 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
15118 + .endr
15119 diff -urNp linux-2.6.39/arch/x86/kernel/head_64.S linux-2.6.39/arch/x86/kernel/head_64.S
15120 --- linux-2.6.39/arch/x86/kernel/head_64.S 2011-05-19 00:06:34.000000000 -0400
15121 +++ linux-2.6.39/arch/x86/kernel/head_64.S 2011-05-22 19:36:30.000000000 -0400
15122 @@ -19,6 +19,7 @@
15123 #include <asm/cache.h>
15124 #include <asm/processor-flags.h>
15125 #include <asm/percpu.h>
15126 +#include <asm/cpufeature.h>
15127
15128 #ifdef CONFIG_PARAVIRT
15129 #include <asm/asm-offsets.h>
15130 @@ -38,6 +39,10 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET
15131 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
15132 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
15133 L3_START_KERNEL = pud_index(__START_KERNEL_map)
15134 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
15135 +L3_VMALLOC_START = pud_index(VMALLOC_START)
15136 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
15137 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
15138
15139 .text
15140 __HEAD
15141 @@ -85,35 +90,22 @@ startup_64:
15142 */
15143 addq %rbp, init_level4_pgt + 0(%rip)
15144 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
15145 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
15146 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
15147 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
15148
15149 addq %rbp, level3_ident_pgt + 0(%rip)
15150 +#ifndef CONFIG_XEN
15151 + addq %rbp, level3_ident_pgt + 8(%rip)
15152 +#endif
15153
15154 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
15155 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
15156 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
15157
15158 - addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
15159 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
15160 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
15161
15162 - /* Add an Identity mapping if I am above 1G */
15163 - leaq _text(%rip), %rdi
15164 - andq $PMD_PAGE_MASK, %rdi
15165 -
15166 - movq %rdi, %rax
15167 - shrq $PUD_SHIFT, %rax
15168 - andq $(PTRS_PER_PUD - 1), %rax
15169 - jz ident_complete
15170 -
15171 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
15172 - leaq level3_ident_pgt(%rip), %rbx
15173 - movq %rdx, 0(%rbx, %rax, 8)
15174 -
15175 - movq %rdi, %rax
15176 - shrq $PMD_SHIFT, %rax
15177 - andq $(PTRS_PER_PMD - 1), %rax
15178 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
15179 - leaq level2_spare_pgt(%rip), %rbx
15180 - movq %rdx, 0(%rbx, %rax, 8)
15181 -ident_complete:
15182 + addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
15183 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
15184
15185 /*
15186 * Fixup the kernel text+data virtual addresses. Note that
15187 @@ -160,8 +152,8 @@ ENTRY(secondary_startup_64)
15188 * after the boot processor executes this code.
15189 */
15190
15191 - /* Enable PAE mode and PGE */
15192 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
15193 + /* Enable PAE mode and PSE/PGE */
15194 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
15195 movq %rax, %cr4
15196
15197 /* Setup early boot stage 4 level pagetables. */
15198 @@ -183,9 +175,14 @@ ENTRY(secondary_startup_64)
15199 movl $MSR_EFER, %ecx
15200 rdmsr
15201 btsl $_EFER_SCE, %eax /* Enable System Call */
15202 - btl $20,%edi /* No Execute supported? */
15203 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
15204 jnc 1f
15205 btsl $_EFER_NX, %eax
15206 + leaq init_level4_pgt(%rip), %rdi
15207 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
15208 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
15209 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
15210 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
15211 1: wrmsr /* Make changes effective */
15212
15213 /* Setup cr0 */
15214 @@ -269,7 +266,7 @@ ENTRY(secondary_startup_64)
15215 bad_address:
15216 jmp bad_address
15217
15218 - .section ".init.text","ax"
15219 + __INIT
15220 #ifdef CONFIG_EARLY_PRINTK
15221 .globl early_idt_handlers
15222 early_idt_handlers:
15223 @@ -314,18 +311,23 @@ ENTRY(early_idt_handler)
15224 #endif /* EARLY_PRINTK */
15225 1: hlt
15226 jmp 1b
15227 + .previous
15228
15229 #ifdef CONFIG_EARLY_PRINTK
15230 + __INITDATA
15231 early_recursion_flag:
15232 .long 0
15233 + .previous
15234
15235 + .section .rodata,"a",@progbits
15236 early_idt_msg:
15237 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
15238 early_idt_ripmsg:
15239 .asciz "RIP %s\n"
15240 -#endif /* CONFIG_EARLY_PRINTK */
15241 .previous
15242 +#endif /* CONFIG_EARLY_PRINTK */
15243
15244 + .section .rodata,"a",@progbits
15245 #define NEXT_PAGE(name) \
15246 .balign PAGE_SIZE; \
15247 ENTRY(name)
15248 @@ -338,7 +340,6 @@ ENTRY(name)
15249 i = i + 1 ; \
15250 .endr
15251
15252 - .data
15253 /*
15254 * This default setting generates an ident mapping at address 0x100000
15255 * and a mapping for the kernel that precisely maps virtual address
15256 @@ -349,13 +350,36 @@ NEXT_PAGE(init_level4_pgt)
15257 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
15258 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
15259 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
15260 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
15261 + .quad level3_vmalloc_pgt - __START_KERNEL_map + _KERNPG_TABLE
15262 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
15263 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
15264 .org init_level4_pgt + L4_START_KERNEL*8, 0
15265 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
15266 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
15267
15268 +#ifdef CONFIG_PAX_PER_CPU_PGD
15269 +NEXT_PAGE(cpu_pgd)
15270 + .rept NR_CPUS
15271 + .fill 512,8,0
15272 + .endr
15273 +#endif
15274 +
15275 NEXT_PAGE(level3_ident_pgt)
15276 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
15277 +#ifdef CONFIG_XEN
15278 .fill 511,8,0
15279 +#else
15280 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
15281 + .fill 510,8,0
15282 +#endif
15283 +
15284 +NEXT_PAGE(level3_vmalloc_pgt)
15285 + .fill 512,8,0
15286 +
15287 +NEXT_PAGE(level3_vmemmap_pgt)
15288 + .fill L3_VMEMMAP_START,8,0
15289 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
15290
15291 NEXT_PAGE(level3_kernel_pgt)
15292 .fill L3_START_KERNEL,8,0
15293 @@ -363,20 +387,23 @@ NEXT_PAGE(level3_kernel_pgt)
15294 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
15295 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
15296
15297 +NEXT_PAGE(level2_vmemmap_pgt)
15298 + .fill 512,8,0
15299 +
15300 NEXT_PAGE(level2_fixmap_pgt)
15301 - .fill 506,8,0
15302 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
15303 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
15304 - .fill 5,8,0
15305 + .fill 507,8,0
15306 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
15307 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
15308 + .fill 4,8,0
15309
15310 -NEXT_PAGE(level1_fixmap_pgt)
15311 +NEXT_PAGE(level1_vsyscall_pgt)
15312 .fill 512,8,0
15313
15314 -NEXT_PAGE(level2_ident_pgt)
15315 - /* Since I easily can, map the first 1G.
15316 + /* Since I easily can, map the first 2G.
15317 * Don't set NX because code runs from these pages.
15318 */
15319 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
15320 +NEXT_PAGE(level2_ident_pgt)
15321 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
15322
15323 NEXT_PAGE(level2_kernel_pgt)
15324 /*
15325 @@ -389,33 +416,55 @@ NEXT_PAGE(level2_kernel_pgt)
15326 * If you want to increase this then increase MODULES_VADDR
15327 * too.)
15328 */
15329 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
15330 - KERNEL_IMAGE_SIZE/PMD_SIZE)
15331 -
15332 -NEXT_PAGE(level2_spare_pgt)
15333 - .fill 512, 8, 0
15334 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
15335
15336 #undef PMDS
15337 #undef NEXT_PAGE
15338
15339 - .data
15340 + .align PAGE_SIZE
15341 +ENTRY(cpu_gdt_table)
15342 + .rept NR_CPUS
15343 + .quad 0x0000000000000000 /* NULL descriptor */
15344 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
15345 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
15346 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
15347 + .quad 0x00cffb000000ffff /* __USER32_CS */
15348 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
15349 + .quad 0x00affb000000ffff /* __USER_CS */
15350 +
15351 +#ifdef CONFIG_PAX_KERNEXEC
15352 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
15353 +#else
15354 + .quad 0x0 /* unused */
15355 +#endif
15356 +
15357 + .quad 0,0 /* TSS */
15358 + .quad 0,0 /* LDT */
15359 + .quad 0,0,0 /* three TLS descriptors */
15360 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
15361 + /* asm/segment.h:GDT_ENTRIES must match this */
15362 +
15363 + /* zero the remaining page */
15364 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
15365 + .endr
15366 +
15367 .align 16
15368 .globl early_gdt_descr
15369 early_gdt_descr:
15370 .word GDT_ENTRIES*8-1
15371 early_gdt_descr_base:
15372 - .quad INIT_PER_CPU_VAR(gdt_page)
15373 + .quad cpu_gdt_table
15374
15375 ENTRY(phys_base)
15376 /* This must match the first entry in level2_kernel_pgt */
15377 .quad 0x0000000000000000
15378
15379 #include "../../x86/xen/xen-head.S"
15380 -
15381 - .section .bss, "aw", @nobits
15382 +
15383 + .section .rodata,"a",@progbits
15384 .align L1_CACHE_BYTES
15385 ENTRY(idt_table)
15386 - .skip IDT_ENTRIES * 16
15387 + .fill 512,8,0
15388
15389 __PAGE_ALIGNED_BSS
15390 .align PAGE_SIZE
15391 diff -urNp linux-2.6.39/arch/x86/kernel/i386_ksyms_32.c linux-2.6.39/arch/x86/kernel/i386_ksyms_32.c
15392 --- linux-2.6.39/arch/x86/kernel/i386_ksyms_32.c 2011-05-19 00:06:34.000000000 -0400
15393 +++ linux-2.6.39/arch/x86/kernel/i386_ksyms_32.c 2011-05-22 19:36:30.000000000 -0400
15394 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
15395 EXPORT_SYMBOL(cmpxchg8b_emu);
15396 #endif
15397
15398 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
15399 +
15400 /* Networking helper routines. */
15401 EXPORT_SYMBOL(csum_partial_copy_generic);
15402 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
15403 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
15404
15405 EXPORT_SYMBOL(__get_user_1);
15406 EXPORT_SYMBOL(__get_user_2);
15407 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
15408
15409 EXPORT_SYMBOL(csum_partial);
15410 EXPORT_SYMBOL(empty_zero_page);
15411 +
15412 +#ifdef CONFIG_PAX_KERNEXEC
15413 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
15414 +#endif
15415 diff -urNp linux-2.6.39/arch/x86/kernel/i8259.c linux-2.6.39/arch/x86/kernel/i8259.c
15416 --- linux-2.6.39/arch/x86/kernel/i8259.c 2011-05-19 00:06:34.000000000 -0400
15417 +++ linux-2.6.39/arch/x86/kernel/i8259.c 2011-05-22 19:36:30.000000000 -0400
15418 @@ -210,7 +210,7 @@ spurious_8259A_irq:
15419 "spurious 8259A interrupt: IRQ%d.\n", irq);
15420 spurious_irq_mask |= irqmask;
15421 }
15422 - atomic_inc(&irq_err_count);
15423 + atomic_inc_unchecked(&irq_err_count);
15424 /*
15425 * Theoretically we do not have to handle this IRQ,
15426 * but in Linux this does not cause problems and is
15427 diff -urNp linux-2.6.39/arch/x86/kernel/init_task.c linux-2.6.39/arch/x86/kernel/init_task.c
15428 --- linux-2.6.39/arch/x86/kernel/init_task.c 2011-05-19 00:06:34.000000000 -0400
15429 +++ linux-2.6.39/arch/x86/kernel/init_task.c 2011-05-22 19:36:30.000000000 -0400
15430 @@ -20,8 +20,7 @@ static struct sighand_struct init_sighan
15431 * way process stacks are handled. This is done by having a special
15432 * "init_task" linker map entry..
15433 */
15434 -union thread_union init_thread_union __init_task_data =
15435 - { INIT_THREAD_INFO(init_task) };
15436 +union thread_union init_thread_union __init_task_data;
15437
15438 /*
15439 * Initial task structure.
15440 @@ -38,5 +37,5 @@ EXPORT_SYMBOL(init_task);
15441 * section. Since TSS's are completely CPU-local, we want them
15442 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
15443 */
15444 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
15445 -
15446 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
15447 +EXPORT_SYMBOL(init_tss);
15448 diff -urNp linux-2.6.39/arch/x86/kernel/ioport.c linux-2.6.39/arch/x86/kernel/ioport.c
15449 --- linux-2.6.39/arch/x86/kernel/ioport.c 2011-05-19 00:06:34.000000000 -0400
15450 +++ linux-2.6.39/arch/x86/kernel/ioport.c 2011-05-22 19:41:32.000000000 -0400
15451 @@ -6,6 +6,7 @@
15452 #include <linux/sched.h>
15453 #include <linux/kernel.h>
15454 #include <linux/capability.h>
15455 +#include <linux/security.h>
15456 #include <linux/errno.h>
15457 #include <linux/types.h>
15458 #include <linux/ioport.h>
15459 @@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long
15460
15461 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
15462 return -EINVAL;
15463 +#ifdef CONFIG_GRKERNSEC_IO
15464 + if (turn_on && grsec_disable_privio) {
15465 + gr_handle_ioperm();
15466 + return -EPERM;
15467 + }
15468 +#endif
15469 if (turn_on && !capable(CAP_SYS_RAWIO))
15470 return -EPERM;
15471
15472 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long
15473 * because the ->io_bitmap_max value must match the bitmap
15474 * contents:
15475 */
15476 - tss = &per_cpu(init_tss, get_cpu());
15477 + tss = init_tss + get_cpu();
15478
15479 if (turn_on)
15480 bitmap_clear(t->io_bitmap_ptr, from, num);
15481 @@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct
15482 return -EINVAL;
15483 /* Trying to gain more privileges? */
15484 if (level > old) {
15485 +#ifdef CONFIG_GRKERNSEC_IO
15486 + if (grsec_disable_privio) {
15487 + gr_handle_iopl();
15488 + return -EPERM;
15489 + }
15490 +#endif
15491 if (!capable(CAP_SYS_RAWIO))
15492 return -EPERM;
15493 }
15494 diff -urNp linux-2.6.39/arch/x86/kernel/irq_32.c linux-2.6.39/arch/x86/kernel/irq_32.c
15495 --- linux-2.6.39/arch/x86/kernel/irq_32.c 2011-05-19 00:06:34.000000000 -0400
15496 +++ linux-2.6.39/arch/x86/kernel/irq_32.c 2011-05-22 19:36:30.000000000 -0400
15497 @@ -36,7 +36,7 @@ static int check_stack_overflow(void)
15498 __asm__ __volatile__("andl %%esp,%0" :
15499 "=r" (sp) : "0" (THREAD_SIZE - 1));
15500
15501 - return sp < (sizeof(struct thread_info) + STACK_WARN);
15502 + return sp < STACK_WARN;
15503 }
15504
15505 static void print_stack_overflow(void)
15506 @@ -54,8 +54,8 @@ static inline void print_stack_overflow(
15507 * per-CPU IRQ handling contexts (thread information and stack)
15508 */
15509 union irq_ctx {
15510 - struct thread_info tinfo;
15511 - u32 stack[THREAD_SIZE/sizeof(u32)];
15512 + unsigned long previous_esp;
15513 + u32 stack[THREAD_SIZE/sizeof(u32)];
15514 } __attribute__((aligned(THREAD_SIZE)));
15515
15516 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
15517 @@ -75,10 +75,9 @@ static void call_on_stack(void *func, vo
15518 static inline int
15519 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
15520 {
15521 - union irq_ctx *curctx, *irqctx;
15522 + union irq_ctx *irqctx;
15523 u32 *isp, arg1, arg2;
15524
15525 - curctx = (union irq_ctx *) current_thread_info();
15526 irqctx = __this_cpu_read(hardirq_ctx);
15527
15528 /*
15529 @@ -87,21 +86,17 @@ execute_on_irq_stack(int overflow, struc
15530 * handler) we can't do that and just have to keep using the
15531 * current stack (which is the irq stack already after all)
15532 */
15533 - if (unlikely(curctx == irqctx))
15534 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
15535 return 0;
15536
15537 /* build the stack frame on the IRQ stack */
15538 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
15539 - irqctx->tinfo.task = curctx->tinfo.task;
15540 - irqctx->tinfo.previous_esp = current_stack_pointer;
15541 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
15542 + irqctx->previous_esp = current_stack_pointer;
15543 + add_preempt_count(HARDIRQ_OFFSET);
15544
15545 - /*
15546 - * Copy the softirq bits in preempt_count so that the
15547 - * softirq checks work in the hardirq context.
15548 - */
15549 - irqctx->tinfo.preempt_count =
15550 - (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
15551 - (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
15552 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15553 + __set_fs(MAKE_MM_SEG(0));
15554 +#endif
15555
15556 if (unlikely(overflow))
15557 call_on_stack(print_stack_overflow, isp);
15558 @@ -113,6 +108,12 @@ execute_on_irq_stack(int overflow, struc
15559 : "0" (irq), "1" (desc), "2" (isp),
15560 "D" (desc->handle_irq)
15561 : "memory", "cc", "ecx");
15562 +
15563 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15564 + __set_fs(current_thread_info()->addr_limit);
15565 +#endif
15566 +
15567 + sub_preempt_count(HARDIRQ_OFFSET);
15568 return 1;
15569 }
15570
15571 @@ -121,29 +122,11 @@ execute_on_irq_stack(int overflow, struc
15572 */
15573 void __cpuinit irq_ctx_init(int cpu)
15574 {
15575 - union irq_ctx *irqctx;
15576 -
15577 if (per_cpu(hardirq_ctx, cpu))
15578 return;
15579
15580 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
15581 - THREAD_FLAGS,
15582 - THREAD_ORDER));
15583 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
15584 - irqctx->tinfo.cpu = cpu;
15585 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
15586 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
15587 -
15588 - per_cpu(hardirq_ctx, cpu) = irqctx;
15589 -
15590 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
15591 - THREAD_FLAGS,
15592 - THREAD_ORDER));
15593 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
15594 - irqctx->tinfo.cpu = cpu;
15595 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
15596 -
15597 - per_cpu(softirq_ctx, cpu) = irqctx;
15598 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
15599 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
15600
15601 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
15602 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
15603 @@ -152,7 +135,6 @@ void __cpuinit irq_ctx_init(int cpu)
15604 asmlinkage void do_softirq(void)
15605 {
15606 unsigned long flags;
15607 - struct thread_info *curctx;
15608 union irq_ctx *irqctx;
15609 u32 *isp;
15610
15611 @@ -162,15 +144,22 @@ asmlinkage void do_softirq(void)
15612 local_irq_save(flags);
15613
15614 if (local_softirq_pending()) {
15615 - curctx = current_thread_info();
15616 irqctx = __this_cpu_read(softirq_ctx);
15617 - irqctx->tinfo.task = curctx->task;
15618 - irqctx->tinfo.previous_esp = current_stack_pointer;
15619 + irqctx->previous_esp = current_stack_pointer;
15620
15621 /* build the stack frame on the softirq stack */
15622 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
15623 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
15624 +
15625 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15626 + __set_fs(MAKE_MM_SEG(0));
15627 +#endif
15628
15629 call_on_stack(__do_softirq, isp);
15630 +
15631 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15632 + __set_fs(current_thread_info()->addr_limit);
15633 +#endif
15634 +
15635 /*
15636 * Shouldn't happen, we returned above if in_interrupt():
15637 */
15638 diff -urNp linux-2.6.39/arch/x86/kernel/irq.c linux-2.6.39/arch/x86/kernel/irq.c
15639 --- linux-2.6.39/arch/x86/kernel/irq.c 2011-05-19 00:06:34.000000000 -0400
15640 +++ linux-2.6.39/arch/x86/kernel/irq.c 2011-05-22 19:36:30.000000000 -0400
15641 @@ -17,7 +17,7 @@
15642 #include <asm/mce.h>
15643 #include <asm/hw_irq.h>
15644
15645 -atomic_t irq_err_count;
15646 +atomic_unchecked_t irq_err_count;
15647
15648 /* Function pointer for generic interrupt vector handling */
15649 void (*x86_platform_ipi_callback)(void) = NULL;
15650 @@ -116,9 +116,9 @@ int arch_show_interrupts(struct seq_file
15651 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
15652 seq_printf(p, " Machine check polls\n");
15653 #endif
15654 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
15655 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
15656 #if defined(CONFIG_X86_IO_APIC)
15657 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
15658 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
15659 #endif
15660 return 0;
15661 }
15662 @@ -158,10 +158,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
15663
15664 u64 arch_irq_stat(void)
15665 {
15666 - u64 sum = atomic_read(&irq_err_count);
15667 + u64 sum = atomic_read_unchecked(&irq_err_count);
15668
15669 #ifdef CONFIG_X86_IO_APIC
15670 - sum += atomic_read(&irq_mis_count);
15671 + sum += atomic_read_unchecked(&irq_mis_count);
15672 #endif
15673 return sum;
15674 }
15675 diff -urNp linux-2.6.39/arch/x86/kernel/kgdb.c linux-2.6.39/arch/x86/kernel/kgdb.c
15676 --- linux-2.6.39/arch/x86/kernel/kgdb.c 2011-05-19 00:06:34.000000000 -0400
15677 +++ linux-2.6.39/arch/x86/kernel/kgdb.c 2011-05-22 19:36:30.000000000 -0400
15678 @@ -124,11 +124,11 @@ char *dbg_get_reg(int regno, void *mem,
15679 #ifdef CONFIG_X86_32
15680 switch (regno) {
15681 case GDB_SS:
15682 - if (!user_mode_vm(regs))
15683 + if (!user_mode(regs))
15684 *(unsigned long *)mem = __KERNEL_DS;
15685 break;
15686 case GDB_SP:
15687 - if (!user_mode_vm(regs))
15688 + if (!user_mode(regs))
15689 *(unsigned long *)mem = kernel_stack_pointer(regs);
15690 break;
15691 case GDB_GS:
15692 @@ -473,12 +473,12 @@ int kgdb_arch_handle_exception(int e_vec
15693 case 'k':
15694 /* clear the trace bit */
15695 linux_regs->flags &= ~X86_EFLAGS_TF;
15696 - atomic_set(&kgdb_cpu_doing_single_step, -1);
15697 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
15698
15699 /* set the trace bit if we're stepping */
15700 if (remcomInBuffer[0] == 's') {
15701 linux_regs->flags |= X86_EFLAGS_TF;
15702 - atomic_set(&kgdb_cpu_doing_single_step,
15703 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
15704 raw_smp_processor_id());
15705 }
15706
15707 @@ -534,7 +534,7 @@ static int __kgdb_notify(struct die_args
15708 return NOTIFY_DONE;
15709
15710 case DIE_DEBUG:
15711 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
15712 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
15713 if (user_mode(regs))
15714 return single_step_cont(regs, args);
15715 break;
15716 @@ -710,7 +710,7 @@ void kgdb_arch_set_pc(struct pt_regs *re
15717 regs->ip = ip;
15718 }
15719
15720 -struct kgdb_arch arch_kgdb_ops = {
15721 +const struct kgdb_arch arch_kgdb_ops = {
15722 /* Breakpoint instruction: */
15723 .gdb_bpt_instr = { 0xcc },
15724 .flags = KGDB_HW_BREAKPOINT,
15725 diff -urNp linux-2.6.39/arch/x86/kernel/kprobes.c linux-2.6.39/arch/x86/kernel/kprobes.c
15726 --- linux-2.6.39/arch/x86/kernel/kprobes.c 2011-05-19 00:06:34.000000000 -0400
15727 +++ linux-2.6.39/arch/x86/kernel/kprobes.c 2011-05-22 19:36:30.000000000 -0400
15728 @@ -115,8 +115,11 @@ static void __kprobes __synthesize_relat
15729 } __attribute__((packed)) *insn;
15730
15731 insn = (struct __arch_relative_insn *)from;
15732 +
15733 + pax_open_kernel();
15734 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
15735 insn->op = op;
15736 + pax_close_kernel();
15737 }
15738
15739 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
15740 @@ -153,7 +156,7 @@ static int __kprobes can_boost(kprobe_op
15741 kprobe_opcode_t opcode;
15742 kprobe_opcode_t *orig_opcodes = opcodes;
15743
15744 - if (search_exception_tables((unsigned long)opcodes))
15745 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
15746 return 0; /* Page fault may occur on this address. */
15747
15748 retry:
15749 @@ -314,7 +317,9 @@ static int __kprobes __copy_instruction(
15750 }
15751 }
15752 insn_get_length(&insn);
15753 + pax_open_kernel();
15754 memcpy(dest, insn.kaddr, insn.length);
15755 + pax_close_kernel();
15756
15757 #ifdef CONFIG_X86_64
15758 if (insn_rip_relative(&insn)) {
15759 @@ -338,7 +343,9 @@ static int __kprobes __copy_instruction(
15760 (u8 *) dest;
15761 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
15762 disp = (u8 *) dest + insn_offset_displacement(&insn);
15763 + pax_open_kernel();
15764 *(s32 *) disp = (s32) newdisp;
15765 + pax_close_kernel();
15766 }
15767 #endif
15768 return insn.length;
15769 @@ -352,12 +359,12 @@ static void __kprobes arch_copy_kprobe(s
15770 */
15771 __copy_instruction(p->ainsn.insn, p->addr, 0);
15772
15773 - if (can_boost(p->addr))
15774 + if (can_boost(ktla_ktva(p->addr)))
15775 p->ainsn.boostable = 0;
15776 else
15777 p->ainsn.boostable = -1;
15778
15779 - p->opcode = *p->addr;
15780 + p->opcode = *(ktla_ktva(p->addr));
15781 }
15782
15783 int __kprobes arch_prepare_kprobe(struct kprobe *p)
15784 @@ -474,7 +481,7 @@ static void __kprobes setup_singlestep(s
15785 * nor set current_kprobe, because it doesn't use single
15786 * stepping.
15787 */
15788 - regs->ip = (unsigned long)p->ainsn.insn;
15789 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
15790 preempt_enable_no_resched();
15791 return;
15792 }
15793 @@ -493,7 +500,7 @@ static void __kprobes setup_singlestep(s
15794 if (p->opcode == BREAKPOINT_INSTRUCTION)
15795 regs->ip = (unsigned long)p->addr;
15796 else
15797 - regs->ip = (unsigned long)p->ainsn.insn;
15798 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
15799 }
15800
15801 /*
15802 @@ -572,7 +579,7 @@ static int __kprobes kprobe_handler(stru
15803 setup_singlestep(p, regs, kcb, 0);
15804 return 1;
15805 }
15806 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
15807 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
15808 /*
15809 * The breakpoint instruction was removed right
15810 * after we hit it. Another cpu has removed
15811 @@ -817,7 +824,7 @@ static void __kprobes resume_execution(s
15812 struct pt_regs *regs, struct kprobe_ctlblk *kcb)
15813 {
15814 unsigned long *tos = stack_addr(regs);
15815 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
15816 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
15817 unsigned long orig_ip = (unsigned long)p->addr;
15818 kprobe_opcode_t *insn = p->ainsn.insn;
15819
15820 @@ -999,7 +1006,7 @@ int __kprobes kprobe_exceptions_notify(s
15821 struct die_args *args = data;
15822 int ret = NOTIFY_DONE;
15823
15824 - if (args->regs && user_mode_vm(args->regs))
15825 + if (args->regs && user_mode(args->regs))
15826 return ret;
15827
15828 switch (val) {
15829 @@ -1381,7 +1388,7 @@ int __kprobes arch_prepare_optimized_kpr
15830 * Verify if the address gap is in 2GB range, because this uses
15831 * a relative jump.
15832 */
15833 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
15834 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
15835 if (abs(rel) > 0x7fffffff)
15836 return -ERANGE;
15837
15838 @@ -1402,11 +1409,11 @@ int __kprobes arch_prepare_optimized_kpr
15839 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
15840
15841 /* Set probe function call */
15842 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
15843 + synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
15844
15845 /* Set returning jmp instruction at the tail of out-of-line buffer */
15846 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
15847 - (u8 *)op->kp.addr + op->optinsn.size);
15848 + (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
15849
15850 flush_icache_range((unsigned long) buf,
15851 (unsigned long) buf + TMPL_END_IDX +
15852 @@ -1428,7 +1435,7 @@ static void __kprobes setup_optimize_kpr
15853 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
15854
15855 /* Backup instructions which will be replaced by jump address */
15856 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
15857 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
15858 RELATIVE_ADDR_SIZE);
15859
15860 insn_buf[0] = RELATIVEJUMP_OPCODE;
15861 diff -urNp linux-2.6.39/arch/x86/kernel/ldt.c linux-2.6.39/arch/x86/kernel/ldt.c
15862 --- linux-2.6.39/arch/x86/kernel/ldt.c 2011-05-19 00:06:34.000000000 -0400
15863 +++ linux-2.6.39/arch/x86/kernel/ldt.c 2011-05-22 19:36:30.000000000 -0400
15864 @@ -67,13 +67,13 @@ static int alloc_ldt(mm_context_t *pc, i
15865 if (reload) {
15866 #ifdef CONFIG_SMP
15867 preempt_disable();
15868 - load_LDT(pc);
15869 + load_LDT_nolock(pc);
15870 if (!cpumask_equal(mm_cpumask(current->mm),
15871 cpumask_of(smp_processor_id())))
15872 smp_call_function(flush_ldt, current->mm, 1);
15873 preempt_enable();
15874 #else
15875 - load_LDT(pc);
15876 + load_LDT_nolock(pc);
15877 #endif
15878 }
15879 if (oldsize) {
15880 @@ -95,7 +95,7 @@ static inline int copy_ldt(mm_context_t
15881 return err;
15882
15883 for (i = 0; i < old->size; i++)
15884 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
15885 + write_ldt_entry(new->ldt, i, old->ldt + i);
15886 return 0;
15887 }
15888
15889 @@ -116,6 +116,24 @@ int init_new_context(struct task_struct
15890 retval = copy_ldt(&mm->context, &old_mm->context);
15891 mutex_unlock(&old_mm->context.lock);
15892 }
15893 +
15894 + if (tsk == current) {
15895 + mm->context.vdso = 0;
15896 +
15897 +#ifdef CONFIG_X86_32
15898 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
15899 + mm->context.user_cs_base = 0UL;
15900 + mm->context.user_cs_limit = ~0UL;
15901 +
15902 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
15903 + cpus_clear(mm->context.cpu_user_cs_mask);
15904 +#endif
15905 +
15906 +#endif
15907 +#endif
15908 +
15909 + }
15910 +
15911 return retval;
15912 }
15913
15914 @@ -230,6 +248,13 @@ static int write_ldt(void __user *ptr, u
15915 }
15916 }
15917
15918 +#ifdef CONFIG_PAX_SEGMEXEC
15919 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
15920 + error = -EINVAL;
15921 + goto out_unlock;
15922 + }
15923 +#endif
15924 +
15925 fill_ldt(&ldt, &ldt_info);
15926 if (oldmode)
15927 ldt.avl = 0;
15928 diff -urNp linux-2.6.39/arch/x86/kernel/machine_kexec_32.c linux-2.6.39/arch/x86/kernel/machine_kexec_32.c
15929 --- linux-2.6.39/arch/x86/kernel/machine_kexec_32.c 2011-05-19 00:06:34.000000000 -0400
15930 +++ linux-2.6.39/arch/x86/kernel/machine_kexec_32.c 2011-05-22 19:36:30.000000000 -0400
15931 @@ -27,7 +27,7 @@
15932 #include <asm/cacheflush.h>
15933 #include <asm/debugreg.h>
15934
15935 -static void set_idt(void *newidt, __u16 limit)
15936 +static void set_idt(struct desc_struct *newidt, __u16 limit)
15937 {
15938 struct desc_ptr curidt;
15939
15940 @@ -39,7 +39,7 @@ static void set_idt(void *newidt, __u16
15941 }
15942
15943
15944 -static void set_gdt(void *newgdt, __u16 limit)
15945 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
15946 {
15947 struct desc_ptr curgdt;
15948
15949 @@ -217,7 +217,7 @@ void machine_kexec(struct kimage *image)
15950 }
15951
15952 control_page = page_address(image->control_code_page);
15953 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
15954 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
15955
15956 relocate_kernel_ptr = control_page;
15957 page_list[PA_CONTROL_PAGE] = __pa(control_page);
15958 diff -urNp linux-2.6.39/arch/x86/kernel/microcode_amd.c linux-2.6.39/arch/x86/kernel/microcode_amd.c
15959 --- linux-2.6.39/arch/x86/kernel/microcode_amd.c 2011-05-19 00:06:34.000000000 -0400
15960 +++ linux-2.6.39/arch/x86/kernel/microcode_amd.c 2011-05-22 19:36:30.000000000 -0400
15961 @@ -339,7 +339,7 @@ static void microcode_fini_cpu_amd(int c
15962 uci->mc = NULL;
15963 }
15964
15965 -static struct microcode_ops microcode_amd_ops = {
15966 +static const struct microcode_ops microcode_amd_ops = {
15967 .request_microcode_user = request_microcode_user,
15968 .request_microcode_fw = request_microcode_amd,
15969 .collect_cpu_info = collect_cpu_info_amd,
15970 @@ -347,7 +347,7 @@ static struct microcode_ops microcode_am
15971 .microcode_fini_cpu = microcode_fini_cpu_amd,
15972 };
15973
15974 -struct microcode_ops * __init init_amd_microcode(void)
15975 +const struct microcode_ops * __init init_amd_microcode(void)
15976 {
15977 return &microcode_amd_ops;
15978 }
15979 diff -urNp linux-2.6.39/arch/x86/kernel/microcode_core.c linux-2.6.39/arch/x86/kernel/microcode_core.c
15980 --- linux-2.6.39/arch/x86/kernel/microcode_core.c 2011-05-19 00:06:34.000000000 -0400
15981 +++ linux-2.6.39/arch/x86/kernel/microcode_core.c 2011-05-22 19:36:30.000000000 -0400
15982 @@ -93,7 +93,7 @@ MODULE_LICENSE("GPL");
15983
15984 #define MICROCODE_VERSION "2.00"
15985
15986 -static struct microcode_ops *microcode_ops;
15987 +static const struct microcode_ops *microcode_ops;
15988
15989 /*
15990 * Synchronization.
15991 diff -urNp linux-2.6.39/arch/x86/kernel/microcode_intel.c linux-2.6.39/arch/x86/kernel/microcode_intel.c
15992 --- linux-2.6.39/arch/x86/kernel/microcode_intel.c 2011-05-19 00:06:34.000000000 -0400
15993 +++ linux-2.6.39/arch/x86/kernel/microcode_intel.c 2011-05-22 19:36:30.000000000 -0400
15994 @@ -440,13 +440,13 @@ static enum ucode_state request_microcod
15995
15996 static int get_ucode_user(void *to, const void *from, size_t n)
15997 {
15998 - return copy_from_user(to, from, n);
15999 + return copy_from_user(to, (__force const void __user *)from, n);
16000 }
16001
16002 static enum ucode_state
16003 request_microcode_user(int cpu, const void __user *buf, size_t size)
16004 {
16005 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
16006 + return generic_load_microcode(cpu, (__force void *)buf, size, &get_ucode_user);
16007 }
16008
16009 static void microcode_fini_cpu(int cpu)
16010 @@ -457,7 +457,7 @@ static void microcode_fini_cpu(int cpu)
16011 uci->mc = NULL;
16012 }
16013
16014 -static struct microcode_ops microcode_intel_ops = {
16015 +static const struct microcode_ops microcode_intel_ops = {
16016 .request_microcode_user = request_microcode_user,
16017 .request_microcode_fw = request_microcode_fw,
16018 .collect_cpu_info = collect_cpu_info,
16019 @@ -465,7 +465,7 @@ static struct microcode_ops microcode_in
16020 .microcode_fini_cpu = microcode_fini_cpu,
16021 };
16022
16023 -struct microcode_ops * __init init_intel_microcode(void)
16024 +const struct microcode_ops * __init init_intel_microcode(void)
16025 {
16026 return &microcode_intel_ops;
16027 }
16028 diff -urNp linux-2.6.39/arch/x86/kernel/module.c linux-2.6.39/arch/x86/kernel/module.c
16029 --- linux-2.6.39/arch/x86/kernel/module.c 2011-05-19 00:06:34.000000000 -0400
16030 +++ linux-2.6.39/arch/x86/kernel/module.c 2011-05-22 19:36:30.000000000 -0400
16031 @@ -35,21 +35,66 @@
16032 #define DEBUGP(fmt...)
16033 #endif
16034
16035 -void *module_alloc(unsigned long size)
16036 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
16037 {
16038 if (PAGE_ALIGN(size) > MODULES_LEN)
16039 return NULL;
16040 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
16041 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
16042 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
16043 -1, __builtin_return_address(0));
16044 }
16045
16046 +void *module_alloc(unsigned long size)
16047 +{
16048 +
16049 +#ifdef CONFIG_PAX_KERNEXEC
16050 + return __module_alloc(size, PAGE_KERNEL);
16051 +#else
16052 + return __module_alloc(size, PAGE_KERNEL_EXEC);
16053 +#endif
16054 +
16055 +}
16056 +
16057 /* Free memory returned from module_alloc */
16058 void module_free(struct module *mod, void *module_region)
16059 {
16060 vfree(module_region);
16061 }
16062
16063 +#ifdef CONFIG_PAX_KERNEXEC
16064 +#ifdef CONFIG_X86_32
16065 +void *module_alloc_exec(unsigned long size)
16066 +{
16067 + struct vm_struct *area;
16068 +
16069 + if (size == 0)
16070 + return NULL;
16071 +
16072 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
16073 + return area ? area->addr : NULL;
16074 +}
16075 +EXPORT_SYMBOL(module_alloc_exec);
16076 +
16077 +void module_free_exec(struct module *mod, void *module_region)
16078 +{
16079 + vunmap(module_region);
16080 +}
16081 +EXPORT_SYMBOL(module_free_exec);
16082 +#else
16083 +void module_free_exec(struct module *mod, void *module_region)
16084 +{
16085 + module_free(mod, module_region);
16086 +}
16087 +EXPORT_SYMBOL(module_free_exec);
16088 +
16089 +void *module_alloc_exec(unsigned long size)
16090 +{
16091 + return __module_alloc(size, PAGE_KERNEL_RX);
16092 +}
16093 +EXPORT_SYMBOL(module_alloc_exec);
16094 +#endif
16095 +#endif
16096 +
16097 /* We don't need anything special. */
16098 int module_frob_arch_sections(Elf_Ehdr *hdr,
16099 Elf_Shdr *sechdrs,
16100 @@ -69,14 +114,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
16101 unsigned int i;
16102 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
16103 Elf32_Sym *sym;
16104 - uint32_t *location;
16105 + uint32_t *plocation, location;
16106
16107 DEBUGP("Applying relocate section %u to %u\n", relsec,
16108 sechdrs[relsec].sh_info);
16109 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
16110 /* This is where to make the change */
16111 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
16112 - + rel[i].r_offset;
16113 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
16114 + location = (uint32_t)plocation;
16115 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
16116 + plocation = ktla_ktva((void *)plocation);
16117 /* This is the symbol it is referring to. Note that all
16118 undefined symbols have been resolved. */
16119 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
16120 @@ -85,11 +132,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
16121 switch (ELF32_R_TYPE(rel[i].r_info)) {
16122 case R_386_32:
16123 /* We add the value into the location given */
16124 - *location += sym->st_value;
16125 + pax_open_kernel();
16126 + *plocation += sym->st_value;
16127 + pax_close_kernel();
16128 break;
16129 case R_386_PC32:
16130 /* Add the value, subtract its postition */
16131 - *location += sym->st_value - (uint32_t)location;
16132 + pax_open_kernel();
16133 + *plocation += sym->st_value - location;
16134 + pax_close_kernel();
16135 break;
16136 default:
16137 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
16138 @@ -145,21 +196,30 @@ int apply_relocate_add(Elf64_Shdr *sechd
16139 case R_X86_64_NONE:
16140 break;
16141 case R_X86_64_64:
16142 + pax_open_kernel();
16143 *(u64 *)loc = val;
16144 + pax_close_kernel();
16145 break;
16146 case R_X86_64_32:
16147 + pax_open_kernel();
16148 *(u32 *)loc = val;
16149 + pax_close_kernel();
16150 if (val != *(u32 *)loc)
16151 goto overflow;
16152 break;
16153 case R_X86_64_32S:
16154 + pax_open_kernel();
16155 *(s32 *)loc = val;
16156 + pax_close_kernel();
16157 if ((s64)val != *(s32 *)loc)
16158 goto overflow;
16159 break;
16160 case R_X86_64_PC32:
16161 val -= (u64)loc;
16162 + pax_open_kernel();
16163 *(u32 *)loc = val;
16164 + pax_close_kernel();
16165 +
16166 #if 0
16167 if ((s64)val != *(s32 *)loc)
16168 goto overflow;
16169 diff -urNp linux-2.6.39/arch/x86/kernel/paravirt.c linux-2.6.39/arch/x86/kernel/paravirt.c
16170 --- linux-2.6.39/arch/x86/kernel/paravirt.c 2011-05-19 00:06:34.000000000 -0400
16171 +++ linux-2.6.39/arch/x86/kernel/paravirt.c 2011-05-22 19:36:30.000000000 -0400
16172 @@ -122,7 +122,7 @@ unsigned paravirt_patch_jmp(void *insnbu
16173 * corresponding structure. */
16174 static void *get_call_destination(u8 type)
16175 {
16176 - struct paravirt_patch_template tmpl = {
16177 + const struct paravirt_patch_template tmpl = {
16178 .pv_init_ops = pv_init_ops,
16179 .pv_time_ops = pv_time_ops,
16180 .pv_cpu_ops = pv_cpu_ops,
16181 @@ -133,6 +133,9 @@ static void *get_call_destination(u8 typ
16182 .pv_lock_ops = pv_lock_ops,
16183 #endif
16184 };
16185 +
16186 + pax_track_stack();
16187 +
16188 return *((void **)&tmpl + type);
16189 }
16190
16191 @@ -145,14 +148,14 @@ unsigned paravirt_patch_default(u8 type,
16192 if (opfunc == NULL)
16193 /* If there's no function, patch it with a ud2a (BUG) */
16194 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
16195 - else if (opfunc == _paravirt_nop)
16196 + else if (opfunc == (void *)_paravirt_nop)
16197 /* If the operation is a nop, then nop the callsite */
16198 ret = paravirt_patch_nop();
16199
16200 /* identity functions just return their single argument */
16201 - else if (opfunc == _paravirt_ident_32)
16202 + else if (opfunc == (void *)_paravirt_ident_32)
16203 ret = paravirt_patch_ident_32(insnbuf, len);
16204 - else if (opfunc == _paravirt_ident_64)
16205 + else if (opfunc == (void *)_paravirt_ident_64)
16206 ret = paravirt_patch_ident_64(insnbuf, len);
16207
16208 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
16209 @@ -178,7 +181,7 @@ unsigned paravirt_patch_insns(void *insn
16210 if (insn_len > len || start == NULL)
16211 insn_len = len;
16212 else
16213 - memcpy(insnbuf, start, insn_len);
16214 + memcpy(insnbuf, ktla_ktva(start), insn_len);
16215
16216 return insn_len;
16217 }
16218 @@ -294,22 +297,22 @@ void arch_flush_lazy_mmu_mode(void)
16219 preempt_enable();
16220 }
16221
16222 -struct pv_info pv_info = {
16223 +struct pv_info pv_info __read_only = {
16224 .name = "bare hardware",
16225 .paravirt_enabled = 0,
16226 .kernel_rpl = 0,
16227 .shared_kernel_pmd = 1, /* Only used when CONFIG_X86_PAE is set */
16228 };
16229
16230 -struct pv_init_ops pv_init_ops = {
16231 +struct pv_init_ops pv_init_ops __read_only = {
16232 .patch = native_patch,
16233 };
16234
16235 -struct pv_time_ops pv_time_ops = {
16236 +struct pv_time_ops pv_time_ops __read_only = {
16237 .sched_clock = native_sched_clock,
16238 };
16239
16240 -struct pv_irq_ops pv_irq_ops = {
16241 +struct pv_irq_ops pv_irq_ops __read_only = {
16242 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
16243 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
16244 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
16245 @@ -321,7 +324,7 @@ struct pv_irq_ops pv_irq_ops = {
16246 #endif
16247 };
16248
16249 -struct pv_cpu_ops pv_cpu_ops = {
16250 +struct pv_cpu_ops pv_cpu_ops __read_only = {
16251 .cpuid = native_cpuid,
16252 .get_debugreg = native_get_debugreg,
16253 .set_debugreg = native_set_debugreg,
16254 @@ -382,7 +385,7 @@ struct pv_cpu_ops pv_cpu_ops = {
16255 .end_context_switch = paravirt_nop,
16256 };
16257
16258 -struct pv_apic_ops pv_apic_ops = {
16259 +struct pv_apic_ops pv_apic_ops __read_only = {
16260 #ifdef CONFIG_X86_LOCAL_APIC
16261 .startup_ipi_hook = paravirt_nop,
16262 #endif
16263 @@ -396,7 +399,7 @@ struct pv_apic_ops pv_apic_ops = {
16264 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
16265 #endif
16266
16267 -struct pv_mmu_ops pv_mmu_ops = {
16268 +struct pv_mmu_ops pv_mmu_ops __read_only = {
16269
16270 .read_cr2 = native_read_cr2,
16271 .write_cr2 = native_write_cr2,
16272 @@ -465,6 +468,12 @@ struct pv_mmu_ops pv_mmu_ops = {
16273 },
16274
16275 .set_fixmap = native_set_fixmap,
16276 +
16277 +#ifdef CONFIG_PAX_KERNEXEC
16278 + .pax_open_kernel = native_pax_open_kernel,
16279 + .pax_close_kernel = native_pax_close_kernel,
16280 +#endif
16281 +
16282 };
16283
16284 EXPORT_SYMBOL_GPL(pv_time_ops);
16285 diff -urNp linux-2.6.39/arch/x86/kernel/paravirt-spinlocks.c linux-2.6.39/arch/x86/kernel/paravirt-spinlocks.c
16286 --- linux-2.6.39/arch/x86/kernel/paravirt-spinlocks.c 2011-05-19 00:06:34.000000000 -0400
16287 +++ linux-2.6.39/arch/x86/kernel/paravirt-spinlocks.c 2011-05-22 19:36:30.000000000 -0400
16288 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t
16289 arch_spin_lock(lock);
16290 }
16291
16292 -struct pv_lock_ops pv_lock_ops = {
16293 +struct pv_lock_ops pv_lock_ops __read_only = {
16294 #ifdef CONFIG_SMP
16295 .spin_is_locked = __ticket_spin_is_locked,
16296 .spin_is_contended = __ticket_spin_is_contended,
16297 diff -urNp linux-2.6.39/arch/x86/kernel/pci-calgary_64.c linux-2.6.39/arch/x86/kernel/pci-calgary_64.c
16298 --- linux-2.6.39/arch/x86/kernel/pci-calgary_64.c 2011-05-19 00:06:34.000000000 -0400
16299 +++ linux-2.6.39/arch/x86/kernel/pci-calgary_64.c 2011-05-22 19:36:30.000000000 -0400
16300 @@ -179,13 +179,13 @@ static void calioc2_dump_error_regs(stru
16301 static void calgary_init_bitmap_from_tce_table(struct iommu_table *tbl);
16302 static void get_tce_space_from_tar(void);
16303
16304 -static struct cal_chipset_ops calgary_chip_ops = {
16305 +static const struct cal_chipset_ops calgary_chip_ops = {
16306 .handle_quirks = calgary_handle_quirks,
16307 .tce_cache_blast = calgary_tce_cache_blast,
16308 .dump_error_regs = calgary_dump_error_regs
16309 };
16310
16311 -static struct cal_chipset_ops calioc2_chip_ops = {
16312 +static const struct cal_chipset_ops calioc2_chip_ops = {
16313 .handle_quirks = calioc2_handle_quirks,
16314 .tce_cache_blast = calioc2_tce_cache_blast,
16315 .dump_error_regs = calioc2_dump_error_regs
16316 @@ -476,7 +476,7 @@ static void calgary_free_coherent(struct
16317 free_pages((unsigned long)vaddr, get_order(size));
16318 }
16319
16320 -static struct dma_map_ops calgary_dma_ops = {
16321 +static const struct dma_map_ops calgary_dma_ops = {
16322 .alloc_coherent = calgary_alloc_coherent,
16323 .free_coherent = calgary_free_coherent,
16324 .map_sg = calgary_map_sg,
16325 diff -urNp linux-2.6.39/arch/x86/kernel/pci-dma.c linux-2.6.39/arch/x86/kernel/pci-dma.c
16326 --- linux-2.6.39/arch/x86/kernel/pci-dma.c 2011-05-19 00:06:34.000000000 -0400
16327 +++ linux-2.6.39/arch/x86/kernel/pci-dma.c 2011-05-22 19:36:30.000000000 -0400
16328 @@ -16,7 +16,7 @@
16329
16330 static int forbid_dac __read_mostly;
16331
16332 -struct dma_map_ops *dma_ops = &nommu_dma_ops;
16333 +const struct dma_map_ops *dma_ops = &nommu_dma_ops;
16334 EXPORT_SYMBOL(dma_ops);
16335
16336 static int iommu_sac_force __read_mostly;
16337 @@ -250,7 +250,7 @@ early_param("iommu", iommu_setup);
16338
16339 int dma_supported(struct device *dev, u64 mask)
16340 {
16341 - struct dma_map_ops *ops = get_dma_ops(dev);
16342 + const struct dma_map_ops *ops = get_dma_ops(dev);
16343
16344 #ifdef CONFIG_PCI
16345 if (mask > 0xffffffff && forbid_dac > 0) {
16346 diff -urNp linux-2.6.39/arch/x86/kernel/pci-gart_64.c linux-2.6.39/arch/x86/kernel/pci-gart_64.c
16347 --- linux-2.6.39/arch/x86/kernel/pci-gart_64.c 2011-05-19 00:06:34.000000000 -0400
16348 +++ linux-2.6.39/arch/x86/kernel/pci-gart_64.c 2011-05-22 19:36:30.000000000 -0400
16349 @@ -695,7 +695,7 @@ static __init int init_amd_gatt(struct a
16350 return -1;
16351 }
16352
16353 -static struct dma_map_ops gart_dma_ops = {
16354 +static const struct dma_map_ops gart_dma_ops = {
16355 .map_sg = gart_map_sg,
16356 .unmap_sg = gart_unmap_sg,
16357 .map_page = gart_map_page,
16358 diff -urNp linux-2.6.39/arch/x86/kernel/pci-iommu_table.c linux-2.6.39/arch/x86/kernel/pci-iommu_table.c
16359 --- linux-2.6.39/arch/x86/kernel/pci-iommu_table.c 2011-05-19 00:06:34.000000000 -0400
16360 +++ linux-2.6.39/arch/x86/kernel/pci-iommu_table.c 2011-05-22 19:36:30.000000000 -0400
16361 @@ -2,7 +2,7 @@
16362 #include <asm/iommu_table.h>
16363 #include <linux/string.h>
16364 #include <linux/kallsyms.h>
16365 -
16366 +#include <linux/sched.h>
16367
16368 #define DEBUG 1
16369
16370 @@ -53,6 +53,8 @@ void __init check_iommu_entries(struct i
16371 char sym_p[KSYM_SYMBOL_LEN];
16372 char sym_q[KSYM_SYMBOL_LEN];
16373
16374 + pax_track_stack();
16375 +
16376 /* Simple cyclic dependency checker. */
16377 for (p = start; p < finish; p++) {
16378 q = find_dependents_of(start, finish, p);
16379 diff -urNp linux-2.6.39/arch/x86/kernel/pci-nommu.c linux-2.6.39/arch/x86/kernel/pci-nommu.c
16380 --- linux-2.6.39/arch/x86/kernel/pci-nommu.c 2011-05-19 00:06:34.000000000 -0400
16381 +++ linux-2.6.39/arch/x86/kernel/pci-nommu.c 2011-05-22 19:36:30.000000000 -0400
16382 @@ -95,7 +95,7 @@ static void nommu_sync_sg_for_device(str
16383 flush_write_buffers();
16384 }
16385
16386 -struct dma_map_ops nommu_dma_ops = {
16387 +const struct dma_map_ops nommu_dma_ops = {
16388 .alloc_coherent = dma_generic_alloc_coherent,
16389 .free_coherent = nommu_free_coherent,
16390 .map_sg = nommu_map_sg,
16391 diff -urNp linux-2.6.39/arch/x86/kernel/pci-swiotlb.c linux-2.6.39/arch/x86/kernel/pci-swiotlb.c
16392 --- linux-2.6.39/arch/x86/kernel/pci-swiotlb.c 2011-05-19 00:06:34.000000000 -0400
16393 +++ linux-2.6.39/arch/x86/kernel/pci-swiotlb.c 2011-05-22 19:36:30.000000000 -0400
16394 @@ -26,7 +26,7 @@ static void *x86_swiotlb_alloc_coherent(
16395 return swiotlb_alloc_coherent(hwdev, size, dma_handle, flags);
16396 }
16397
16398 -static struct dma_map_ops swiotlb_dma_ops = {
16399 +static const struct dma_map_ops swiotlb_dma_ops = {
16400 .mapping_error = swiotlb_dma_mapping_error,
16401 .alloc_coherent = x86_swiotlb_alloc_coherent,
16402 .free_coherent = swiotlb_free_coherent,
16403 diff -urNp linux-2.6.39/arch/x86/kernel/process_32.c linux-2.6.39/arch/x86/kernel/process_32.c
16404 --- linux-2.6.39/arch/x86/kernel/process_32.c 2011-05-19 00:06:34.000000000 -0400
16405 +++ linux-2.6.39/arch/x86/kernel/process_32.c 2011-05-22 19:36:30.000000000 -0400
16406 @@ -65,6 +65,7 @@ asmlinkage void ret_from_fork(void) __as
16407 unsigned long thread_saved_pc(struct task_struct *tsk)
16408 {
16409 return ((unsigned long *)tsk->thread.sp)[3];
16410 +//XXX return tsk->thread.eip;
16411 }
16412
16413 #ifndef CONFIG_SMP
16414 @@ -126,15 +127,14 @@ void __show_regs(struct pt_regs *regs, i
16415 unsigned long sp;
16416 unsigned short ss, gs;
16417
16418 - if (user_mode_vm(regs)) {
16419 + if (user_mode(regs)) {
16420 sp = regs->sp;
16421 ss = regs->ss & 0xffff;
16422 - gs = get_user_gs(regs);
16423 } else {
16424 sp = kernel_stack_pointer(regs);
16425 savesegment(ss, ss);
16426 - savesegment(gs, gs);
16427 }
16428 + gs = get_user_gs(regs);
16429
16430 show_regs_common();
16431
16432 @@ -196,13 +196,14 @@ int copy_thread(unsigned long clone_flag
16433 struct task_struct *tsk;
16434 int err;
16435
16436 - childregs = task_pt_regs(p);
16437 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
16438 *childregs = *regs;
16439 childregs->ax = 0;
16440 childregs->sp = sp;
16441
16442 p->thread.sp = (unsigned long) childregs;
16443 p->thread.sp0 = (unsigned long) (childregs+1);
16444 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
16445
16446 p->thread.ip = (unsigned long) ret_from_fork;
16447
16448 @@ -293,7 +294,7 @@ __switch_to(struct task_struct *prev_p,
16449 struct thread_struct *prev = &prev_p->thread,
16450 *next = &next_p->thread;
16451 int cpu = smp_processor_id();
16452 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
16453 + struct tss_struct *tss = init_tss + cpu;
16454 bool preload_fpu;
16455
16456 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
16457 @@ -328,6 +329,10 @@ __switch_to(struct task_struct *prev_p,
16458 */
16459 lazy_save_gs(prev->gs);
16460
16461 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16462 + __set_fs(task_thread_info(next_p)->addr_limit);
16463 +#endif
16464 +
16465 /*
16466 * Load the per-thread Thread-Local Storage descriptor.
16467 */
16468 @@ -363,6 +368,9 @@ __switch_to(struct task_struct *prev_p,
16469 */
16470 arch_end_context_switch(next_p);
16471
16472 + percpu_write(current_task, next_p);
16473 + percpu_write(current_tinfo, &next_p->tinfo);
16474 +
16475 if (preload_fpu)
16476 __math_state_restore();
16477
16478 @@ -372,8 +380,6 @@ __switch_to(struct task_struct *prev_p,
16479 if (prev->gs | next->gs)
16480 lazy_load_gs(next->gs);
16481
16482 - percpu_write(current_task, next_p);
16483 -
16484 return prev_p;
16485 }
16486
16487 @@ -403,4 +409,3 @@ unsigned long get_wchan(struct task_stru
16488 } while (count++ < 16);
16489 return 0;
16490 }
16491 -
16492 diff -urNp linux-2.6.39/arch/x86/kernel/process_64.c linux-2.6.39/arch/x86/kernel/process_64.c
16493 --- linux-2.6.39/arch/x86/kernel/process_64.c 2011-05-19 00:06:34.000000000 -0400
16494 +++ linux-2.6.39/arch/x86/kernel/process_64.c 2011-05-22 19:36:30.000000000 -0400
16495 @@ -87,7 +87,7 @@ static void __exit_idle(void)
16496 void exit_idle(void)
16497 {
16498 /* idle loop has pid 0 */
16499 - if (current->pid)
16500 + if (task_pid_nr(current))
16501 return;
16502 __exit_idle();
16503 }
16504 @@ -260,8 +260,7 @@ int copy_thread(unsigned long clone_flag
16505 struct pt_regs *childregs;
16506 struct task_struct *me = current;
16507
16508 - childregs = ((struct pt_regs *)
16509 - (THREAD_SIZE + task_stack_page(p))) - 1;
16510 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
16511 *childregs = *regs;
16512
16513 childregs->ax = 0;
16514 @@ -273,6 +272,7 @@ int copy_thread(unsigned long clone_flag
16515 p->thread.sp = (unsigned long) childregs;
16516 p->thread.sp0 = (unsigned long) (childregs+1);
16517 p->thread.usersp = me->thread.usersp;
16518 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
16519
16520 set_tsk_thread_flag(p, TIF_FORK);
16521
16522 @@ -376,7 +376,7 @@ __switch_to(struct task_struct *prev_p,
16523 struct thread_struct *prev = &prev_p->thread;
16524 struct thread_struct *next = &next_p->thread;
16525 int cpu = smp_processor_id();
16526 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
16527 + struct tss_struct *tss = init_tss + cpu;
16528 unsigned fsindex, gsindex;
16529 bool preload_fpu;
16530
16531 @@ -472,10 +472,9 @@ __switch_to(struct task_struct *prev_p,
16532 prev->usersp = percpu_read(old_rsp);
16533 percpu_write(old_rsp, next->usersp);
16534 percpu_write(current_task, next_p);
16535 + percpu_write(current_tinfo, &next_p->tinfo);
16536
16537 - percpu_write(kernel_stack,
16538 - (unsigned long)task_stack_page(next_p) +
16539 - THREAD_SIZE - KERNEL_STACK_OFFSET);
16540 + percpu_write(kernel_stack, next->sp0);
16541
16542 /*
16543 * Now maybe reload the debug registers and handle I/O bitmaps
16544 @@ -537,12 +536,11 @@ unsigned long get_wchan(struct task_stru
16545 if (!p || p == current || p->state == TASK_RUNNING)
16546 return 0;
16547 stack = (unsigned long)task_stack_page(p);
16548 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
16549 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
16550 return 0;
16551 fp = *(u64 *)(p->thread.sp);
16552 do {
16553 - if (fp < (unsigned long)stack ||
16554 - fp >= (unsigned long)stack+THREAD_SIZE)
16555 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
16556 return 0;
16557 ip = *(u64 *)(fp+8);
16558 if (!in_sched_functions(ip))
16559 diff -urNp linux-2.6.39/arch/x86/kernel/process.c linux-2.6.39/arch/x86/kernel/process.c
16560 --- linux-2.6.39/arch/x86/kernel/process.c 2011-05-19 00:06:34.000000000 -0400
16561 +++ linux-2.6.39/arch/x86/kernel/process.c 2011-05-22 19:36:30.000000000 -0400
16562 @@ -48,16 +48,33 @@ void free_thread_xstate(struct task_stru
16563
16564 void free_thread_info(struct thread_info *ti)
16565 {
16566 - free_thread_xstate(ti->task);
16567 free_pages((unsigned long)ti, get_order(THREAD_SIZE));
16568 }
16569
16570 +static struct kmem_cache *task_struct_cachep;
16571 +
16572 void arch_task_cache_init(void)
16573 {
16574 - task_xstate_cachep =
16575 - kmem_cache_create("task_xstate", xstate_size,
16576 + /* create a slab on which task_structs can be allocated */
16577 + task_struct_cachep =
16578 + kmem_cache_create("task_struct", sizeof(struct task_struct),
16579 + ARCH_MIN_TASKALIGN, SLAB_PANIC | SLAB_NOTRACK, NULL);
16580 +
16581 + task_xstate_cachep =
16582 + kmem_cache_create("task_xstate", xstate_size,
16583 __alignof__(union thread_xstate),
16584 - SLAB_PANIC | SLAB_NOTRACK, NULL);
16585 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
16586 +}
16587 +
16588 +struct task_struct *alloc_task_struct_node(int node)
16589 +{
16590 + return kmem_cache_alloc_node(task_struct_cachep, GFP_KERNEL, node);
16591 +}
16592 +
16593 +void free_task_struct(struct task_struct *task)
16594 +{
16595 + free_thread_xstate(task);
16596 + kmem_cache_free(task_struct_cachep, task);
16597 }
16598
16599 /*
16600 @@ -70,7 +87,7 @@ void exit_thread(void)
16601 unsigned long *bp = t->io_bitmap_ptr;
16602
16603 if (bp) {
16604 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
16605 + struct tss_struct *tss = init_tss + get_cpu();
16606
16607 t->io_bitmap_ptr = NULL;
16608 clear_thread_flag(TIF_IO_BITMAP);
16609 @@ -106,7 +123,7 @@ void show_regs_common(void)
16610
16611 printk(KERN_CONT "\n");
16612 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s",
16613 - current->pid, current->comm, print_tainted(),
16614 + task_pid_nr(current), current->comm, print_tainted(),
16615 init_utsname()->release,
16616 (int)strcspn(init_utsname()->version, " "),
16617 init_utsname()->version);
16618 @@ -120,6 +137,9 @@ void flush_thread(void)
16619 {
16620 struct task_struct *tsk = current;
16621
16622 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
16623 + loadsegment(gs, 0);
16624 +#endif
16625 flush_ptrace_hw_breakpoint(tsk);
16626 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
16627 /*
16628 @@ -282,10 +302,10 @@ int kernel_thread(int (*fn)(void *), voi
16629 regs.di = (unsigned long) arg;
16630
16631 #ifdef CONFIG_X86_32
16632 - regs.ds = __USER_DS;
16633 - regs.es = __USER_DS;
16634 + regs.ds = __KERNEL_DS;
16635 + regs.es = __KERNEL_DS;
16636 regs.fs = __KERNEL_PERCPU;
16637 - regs.gs = __KERNEL_STACK_CANARY;
16638 + savesegment(gs, regs.gs);
16639 #else
16640 regs.ss = __KERNEL_DS;
16641 #endif
16642 @@ -401,7 +421,7 @@ void default_idle(void)
16643 EXPORT_SYMBOL(default_idle);
16644 #endif
16645
16646 -void stop_this_cpu(void *dummy)
16647 +__noreturn void stop_this_cpu(void *dummy)
16648 {
16649 local_irq_disable();
16650 /*
16651 @@ -665,16 +685,34 @@ static int __init idle_setup(char *str)
16652 }
16653 early_param("idle", idle_setup);
16654
16655 -unsigned long arch_align_stack(unsigned long sp)
16656 +#ifdef CONFIG_PAX_RANDKSTACK
16657 +asmlinkage void pax_randomize_kstack(void)
16658 {
16659 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
16660 - sp -= get_random_int() % 8192;
16661 - return sp & ~0xf;
16662 -}
16663 + struct thread_struct *thread = &current->thread;
16664 + unsigned long time;
16665
16666 -unsigned long arch_randomize_brk(struct mm_struct *mm)
16667 -{
16668 - unsigned long range_end = mm->brk + 0x02000000;
16669 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
16670 -}
16671 + if (!randomize_va_space)
16672 + return;
16673 +
16674 + rdtscl(time);
16675 +
16676 + /* P4 seems to return a 0 LSB, ignore it */
16677 +#ifdef CONFIG_MPENTIUM4
16678 + time &= 0x3EUL;
16679 + time <<= 2;
16680 +#elif defined(CONFIG_X86_64)
16681 + time &= 0xFUL;
16682 + time <<= 4;
16683 +#else
16684 + time &= 0x1FUL;
16685 + time <<= 3;
16686 +#endif
16687 +
16688 + thread->sp0 ^= time;
16689 + load_sp0(init_tss + smp_processor_id(), thread);
16690
16691 +#ifdef CONFIG_X86_64
16692 + percpu_write(kernel_stack, thread->sp0);
16693 +#endif
16694 +}
16695 +#endif
16696 diff -urNp linux-2.6.39/arch/x86/kernel/ptrace.c linux-2.6.39/arch/x86/kernel/ptrace.c
16697 --- linux-2.6.39/arch/x86/kernel/ptrace.c 2011-05-19 00:06:34.000000000 -0400
16698 +++ linux-2.6.39/arch/x86/kernel/ptrace.c 2011-05-22 19:36:30.000000000 -0400
16699 @@ -821,7 +821,7 @@ long arch_ptrace(struct task_struct *chi
16700 unsigned long addr, unsigned long data)
16701 {
16702 int ret;
16703 - unsigned long __user *datap = (unsigned long __user *)data;
16704 + unsigned long __user *datap = (__force unsigned long __user *)data;
16705
16706 switch (request) {
16707 /* read the word at location addr in the USER area. */
16708 @@ -906,14 +906,14 @@ long arch_ptrace(struct task_struct *chi
16709 if ((int) addr < 0)
16710 return -EIO;
16711 ret = do_get_thread_area(child, addr,
16712 - (struct user_desc __user *)data);
16713 + (__force struct user_desc __user *) data);
16714 break;
16715
16716 case PTRACE_SET_THREAD_AREA:
16717 if ((int) addr < 0)
16718 return -EIO;
16719 ret = do_set_thread_area(child, addr,
16720 - (struct user_desc __user *)data, 0);
16721 + (__force struct user_desc __user *) data, 0);
16722 break;
16723 #endif
16724
16725 @@ -1330,7 +1330,7 @@ static void fill_sigtrap_info(struct tas
16726 memset(info, 0, sizeof(*info));
16727 info->si_signo = SIGTRAP;
16728 info->si_code = si_code;
16729 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
16730 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
16731 }
16732
16733 void user_single_step_siginfo(struct task_struct *tsk,
16734 @@ -1363,7 +1363,7 @@ void send_sigtrap(struct task_struct *ts
16735 * We must return the syscall number to actually look up in the table.
16736 * This can be -1L to skip running any syscall at all.
16737 */
16738 -asmregparm long syscall_trace_enter(struct pt_regs *regs)
16739 +long syscall_trace_enter(struct pt_regs *regs)
16740 {
16741 long ret = 0;
16742
16743 @@ -1408,7 +1408,7 @@ asmregparm long syscall_trace_enter(stru
16744 return ret ?: regs->orig_ax;
16745 }
16746
16747 -asmregparm void syscall_trace_leave(struct pt_regs *regs)
16748 +void syscall_trace_leave(struct pt_regs *regs)
16749 {
16750 bool step;
16751
16752 diff -urNp linux-2.6.39/arch/x86/kernel/pvclock.c linux-2.6.39/arch/x86/kernel/pvclock.c
16753 --- linux-2.6.39/arch/x86/kernel/pvclock.c 2011-05-19 00:06:34.000000000 -0400
16754 +++ linux-2.6.39/arch/x86/kernel/pvclock.c 2011-05-22 19:36:30.000000000 -0400
16755 @@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvc
16756 return pv_tsc_khz;
16757 }
16758
16759 -static atomic64_t last_value = ATOMIC64_INIT(0);
16760 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
16761
16762 void pvclock_resume(void)
16763 {
16764 - atomic64_set(&last_value, 0);
16765 + atomic64_set_unchecked(&last_value, 0);
16766 }
16767
16768 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
16769 @@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct
16770 * updating at the same time, and one of them could be slightly behind,
16771 * making the assumption that last_value always go forward fail to hold.
16772 */
16773 - last = atomic64_read(&last_value);
16774 + last = atomic64_read_unchecked(&last_value);
16775 do {
16776 if (ret < last)
16777 return last;
16778 - last = atomic64_cmpxchg(&last_value, last, ret);
16779 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
16780 } while (unlikely(last != ret));
16781
16782 return ret;
16783 diff -urNp linux-2.6.39/arch/x86/kernel/reboot.c linux-2.6.39/arch/x86/kernel/reboot.c
16784 --- linux-2.6.39/arch/x86/kernel/reboot.c 2011-05-19 00:06:34.000000000 -0400
16785 +++ linux-2.6.39/arch/x86/kernel/reboot.c 2011-05-23 17:07:00.000000000 -0400
16786 @@ -35,7 +35,7 @@ void (*pm_power_off)(void);
16787 EXPORT_SYMBOL(pm_power_off);
16788
16789 static const struct desc_ptr no_idt = {};
16790 -static int reboot_mode;
16791 +static unsigned short reboot_mode;
16792 enum reboot_type reboot_type = BOOT_KBD;
16793 int reboot_force;
16794
16795 @@ -307,13 +307,17 @@ core_initcall(reboot_init);
16796 extern const unsigned char machine_real_restart_asm[];
16797 extern const u64 machine_real_restart_gdt[3];
16798
16799 -void machine_real_restart(unsigned int type)
16800 +__noreturn void machine_real_restart(unsigned int type)
16801 {
16802 void *restart_va;
16803 unsigned long restart_pa;
16804 - void (*restart_lowmem)(unsigned int);
16805 + void (* __noreturn restart_lowmem)(unsigned int);
16806 u64 *lowmem_gdt;
16807
16808 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
16809 + struct desc_struct *gdt;
16810 +#endif
16811 +
16812 local_irq_disable();
16813
16814 /* Write zero to CMOS register number 0x0f, which the BIOS POST
16815 @@ -339,14 +343,14 @@ void machine_real_restart(unsigned int t
16816 boot)". This seems like a fairly standard thing that gets set by
16817 REBOOT.COM programs, and the previous reset routine did this
16818 too. */
16819 - *((unsigned short *)0x472) = reboot_mode;
16820 + *(unsigned short *)(__va(0x472)) = reboot_mode;
16821
16822 /* Patch the GDT in the low memory trampoline */
16823 lowmem_gdt = TRAMPOLINE_SYM(machine_real_restart_gdt);
16824
16825 restart_va = TRAMPOLINE_SYM(machine_real_restart_asm);
16826 restart_pa = virt_to_phys(restart_va);
16827 - restart_lowmem = (void (*)(unsigned int))restart_pa;
16828 + restart_lowmem = (void *)restart_pa;
16829
16830 /* GDT[0]: GDT self-pointer */
16831 lowmem_gdt[0] =
16832 @@ -357,7 +361,33 @@ void machine_real_restart(unsigned int t
16833 GDT_ENTRY(0x009b, restart_pa, 0xffff);
16834
16835 /* Jump to the identity-mapped low memory code */
16836 +
16837 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
16838 + gdt = get_cpu_gdt_table(smp_processor_id());
16839 + pax_open_kernel();
16840 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16841 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
16842 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
16843 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
16844 +#endif
16845 +#ifdef CONFIG_PAX_KERNEXEC
16846 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
16847 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
16848 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
16849 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
16850 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
16851 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
16852 +#endif
16853 + pax_close_kernel();
16854 +#endif
16855 +
16856 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16857 + asm volatile("push %0; push %1; lret\n" : : "i" (__KERNEL_CS), "rm" (restart_lowmem), "a" (type));
16858 + unreachable();
16859 +#else
16860 restart_lowmem(type);
16861 +#endif
16862 +
16863 }
16864 #ifdef CONFIG_APM_MODULE
16865 EXPORT_SYMBOL(machine_real_restart);
16866 @@ -478,7 +508,7 @@ void __attribute__((weak)) mach_reboot_f
16867 {
16868 }
16869
16870 -static void native_machine_emergency_restart(void)
16871 +__noreturn static void native_machine_emergency_restart(void)
16872 {
16873 int i;
16874
16875 @@ -593,13 +623,13 @@ void native_machine_shutdown(void)
16876 #endif
16877 }
16878
16879 -static void __machine_emergency_restart(int emergency)
16880 +static __noreturn void __machine_emergency_restart(int emergency)
16881 {
16882 reboot_emergency = emergency;
16883 machine_ops.emergency_restart();
16884 }
16885
16886 -static void native_machine_restart(char *__unused)
16887 +static __noreturn void native_machine_restart(char *__unused)
16888 {
16889 printk("machine restart\n");
16890
16891 @@ -608,7 +638,7 @@ static void native_machine_restart(char
16892 __machine_emergency_restart(0);
16893 }
16894
16895 -static void native_machine_halt(void)
16896 +static __noreturn void native_machine_halt(void)
16897 {
16898 /* stop other cpus and apics */
16899 machine_shutdown();
16900 @@ -619,7 +649,7 @@ static void native_machine_halt(void)
16901 stop_this_cpu(NULL);
16902 }
16903
16904 -static void native_machine_power_off(void)
16905 +__noreturn static void native_machine_power_off(void)
16906 {
16907 if (pm_power_off) {
16908 if (!reboot_force)
16909 @@ -628,6 +658,7 @@ static void native_machine_power_off(voi
16910 }
16911 /* a fallback in case there is no PM info available */
16912 tboot_shutdown(TB_SHUTDOWN_HALT);
16913 + unreachable();
16914 }
16915
16916 struct machine_ops machine_ops = {
16917 diff -urNp linux-2.6.39/arch/x86/kernel/setup.c linux-2.6.39/arch/x86/kernel/setup.c
16918 --- linux-2.6.39/arch/x86/kernel/setup.c 2011-05-19 00:06:34.000000000 -0400
16919 +++ linux-2.6.39/arch/x86/kernel/setup.c 2011-05-22 19:36:30.000000000 -0400
16920 @@ -650,7 +650,7 @@ static void __init trim_bios_range(void)
16921 * area (640->1Mb) as ram even though it is not.
16922 * take them out.
16923 */
16924 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
16925 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
16926 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
16927 }
16928
16929 @@ -775,14 +775,14 @@ void __init setup_arch(char **cmdline_p)
16930
16931 if (!boot_params.hdr.root_flags)
16932 root_mountflags &= ~MS_RDONLY;
16933 - init_mm.start_code = (unsigned long) _text;
16934 - init_mm.end_code = (unsigned long) _etext;
16935 + init_mm.start_code = ktla_ktva((unsigned long) _text);
16936 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
16937 init_mm.end_data = (unsigned long) _edata;
16938 init_mm.brk = _brk_end;
16939
16940 - code_resource.start = virt_to_phys(_text);
16941 - code_resource.end = virt_to_phys(_etext)-1;
16942 - data_resource.start = virt_to_phys(_etext);
16943 + code_resource.start = virt_to_phys(ktla_ktva(_text));
16944 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
16945 + data_resource.start = virt_to_phys(_sdata);
16946 data_resource.end = virt_to_phys(_edata)-1;
16947 bss_resource.start = virt_to_phys(&__bss_start);
16948 bss_resource.end = virt_to_phys(&__bss_stop)-1;
16949 diff -urNp linux-2.6.39/arch/x86/kernel/setup_percpu.c linux-2.6.39/arch/x86/kernel/setup_percpu.c
16950 --- linux-2.6.39/arch/x86/kernel/setup_percpu.c 2011-05-19 00:06:34.000000000 -0400
16951 +++ linux-2.6.39/arch/x86/kernel/setup_percpu.c 2011-05-22 19:36:30.000000000 -0400
16952 @@ -21,19 +21,17 @@
16953 #include <asm/cpu.h>
16954 #include <asm/stackprotector.h>
16955
16956 -DEFINE_PER_CPU(int, cpu_number);
16957 +#ifdef CONFIG_SMP
16958 +DEFINE_PER_CPU(unsigned int, cpu_number);
16959 EXPORT_PER_CPU_SYMBOL(cpu_number);
16960 +#endif
16961
16962 -#ifdef CONFIG_X86_64
16963 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
16964 -#else
16965 -#define BOOT_PERCPU_OFFSET 0
16966 -#endif
16967
16968 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
16969 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
16970
16971 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
16972 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
16973 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
16974 };
16975 EXPORT_SYMBOL(__per_cpu_offset);
16976 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(
16977 {
16978 #ifdef CONFIG_X86_32
16979 struct desc_struct gdt;
16980 + unsigned long base = per_cpu_offset(cpu);
16981
16982 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
16983 - 0x2 | DESCTYPE_S, 0x8);
16984 - gdt.s = 1;
16985 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
16986 + 0x83 | DESCTYPE_S, 0xC);
16987 write_gdt_entry(get_cpu_gdt_table(cpu),
16988 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
16989 #endif
16990 @@ -207,6 +205,11 @@ void __init setup_per_cpu_areas(void)
16991 /* alrighty, percpu areas up and running */
16992 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
16993 for_each_possible_cpu(cpu) {
16994 +#ifdef CONFIG_CC_STACKPROTECTOR
16995 +#ifdef CONFIG_x86_32
16996 + unsigned long canary = per_cpu(stack_canary, cpu);
16997 +#endif
16998 +#endif
16999 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
17000 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
17001 per_cpu(cpu_number, cpu) = cpu;
17002 @@ -247,6 +250,12 @@ void __init setup_per_cpu_areas(void)
17003 */
17004 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
17005 #endif
17006 +#ifdef CONFIG_CC_STACKPROTECTOR
17007 +#ifdef CONFIG_x86_32
17008 + if (cpu == boot_cpu_id)
17009 + per_cpu(stack_canary, cpu) = canary;
17010 +#endif
17011 +#endif
17012 /*
17013 * Up to this point, the boot CPU has been using .init.data
17014 * area. Reload any changed state for the boot CPU.
17015 diff -urNp linux-2.6.39/arch/x86/kernel/signal.c linux-2.6.39/arch/x86/kernel/signal.c
17016 --- linux-2.6.39/arch/x86/kernel/signal.c 2011-05-19 00:06:34.000000000 -0400
17017 +++ linux-2.6.39/arch/x86/kernel/signal.c 2011-05-23 17:07:00.000000000 -0400
17018 @@ -198,7 +198,7 @@ static unsigned long align_sigframe(unsi
17019 * Align the stack pointer according to the i386 ABI,
17020 * i.e. so that on function entry ((sp + 4) & 15) == 0.
17021 */
17022 - sp = ((sp + 4) & -16ul) - 4;
17023 + sp = ((sp - 12) & -16ul) - 4;
17024 #else /* !CONFIG_X86_32 */
17025 sp = round_down(sp, 16) - 8;
17026 #endif
17027 @@ -249,11 +249,11 @@ get_sigframe(struct k_sigaction *ka, str
17028 * Return an always-bogus address instead so we will die with SIGSEGV.
17029 */
17030 if (onsigstack && !likely(on_sig_stack(sp)))
17031 - return (void __user *)-1L;
17032 + return (__force void __user *)-1L;
17033
17034 /* save i387 state */
17035 if (used_math() && save_i387_xstate(*fpstate) < 0)
17036 - return (void __user *)-1L;
17037 + return (__force void __user *)-1L;
17038
17039 return (void __user *)sp;
17040 }
17041 @@ -308,9 +308,9 @@ __setup_frame(int sig, struct k_sigactio
17042 }
17043
17044 if (current->mm->context.vdso)
17045 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
17046 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
17047 else
17048 - restorer = &frame->retcode;
17049 + restorer = (void __user *)&frame->retcode;
17050 if (ka->sa.sa_flags & SA_RESTORER)
17051 restorer = ka->sa.sa_restorer;
17052
17053 @@ -324,7 +324,7 @@ __setup_frame(int sig, struct k_sigactio
17054 * reasons and because gdb uses it as a signature to notice
17055 * signal handler stack frames.
17056 */
17057 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
17058 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
17059
17060 if (err)
17061 return -EFAULT;
17062 @@ -378,7 +378,10 @@ static int __setup_rt_frame(int sig, str
17063 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
17064
17065 /* Set up to return from userspace. */
17066 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
17067 + if (current->mm->context.vdso)
17068 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
17069 + else
17070 + restorer = (void __user *)&frame->retcode;
17071 if (ka->sa.sa_flags & SA_RESTORER)
17072 restorer = ka->sa.sa_restorer;
17073 put_user_ex(restorer, &frame->pretcode);
17074 @@ -390,7 +393,7 @@ static int __setup_rt_frame(int sig, str
17075 * reasons and because gdb uses it as a signature to notice
17076 * signal handler stack frames.
17077 */
17078 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
17079 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
17080 } put_user_catch(err);
17081
17082 if (err)
17083 @@ -773,6 +776,8 @@ static void do_signal(struct pt_regs *re
17084 int signr;
17085 sigset_t *oldset;
17086
17087 + pax_track_stack();
17088 +
17089 /*
17090 * We want the common case to go fast, which is why we may in certain
17091 * cases get here from kernel mode. Just return without doing anything
17092 @@ -780,7 +785,7 @@ static void do_signal(struct pt_regs *re
17093 * X86_32: vm86 regs switched out by assembly code before reaching
17094 * here, so testing against kernel CS suffices.
17095 */
17096 - if (!user_mode(regs))
17097 + if (!user_mode_novm(regs))
17098 return;
17099
17100 if (current_thread_info()->status & TS_RESTORE_SIGMASK)
17101 diff -urNp linux-2.6.39/arch/x86/kernel/smpboot.c linux-2.6.39/arch/x86/kernel/smpboot.c
17102 --- linux-2.6.39/arch/x86/kernel/smpboot.c 2011-05-19 00:06:34.000000000 -0400
17103 +++ linux-2.6.39/arch/x86/kernel/smpboot.c 2011-05-22 19:36:30.000000000 -0400
17104 @@ -696,17 +696,20 @@ static int __cpuinit do_boot_cpu(int api
17105 set_idle_for_cpu(cpu, c_idle.idle);
17106 do_rest:
17107 per_cpu(current_task, cpu) = c_idle.idle;
17108 + per_cpu(current_tinfo, cpu) = &c_idle.idle->tinfo;
17109 #ifdef CONFIG_X86_32
17110 /* Stack for startup_32 can be just as for start_secondary onwards */
17111 irq_ctx_init(cpu);
17112 #else
17113 clear_tsk_thread_flag(c_idle.idle, TIF_FORK);
17114 initial_gs = per_cpu_offset(cpu);
17115 - per_cpu(kernel_stack, cpu) =
17116 - (unsigned long)task_stack_page(c_idle.idle) -
17117 - KERNEL_STACK_OFFSET + THREAD_SIZE;
17118 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(c_idle.idle) - 16 + THREAD_SIZE;
17119 #endif
17120 +
17121 + pax_open_kernel();
17122 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
17123 + pax_close_kernel();
17124 +
17125 initial_code = (unsigned long)start_secondary;
17126 stack_start = c_idle.idle->thread.sp;
17127
17128 @@ -848,6 +851,12 @@ int __cpuinit native_cpu_up(unsigned int
17129
17130 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
17131
17132 +#ifdef CONFIG_PAX_PER_CPU_PGD
17133 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
17134 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
17135 + KERNEL_PGD_PTRS);
17136 +#endif
17137 +
17138 err = do_boot_cpu(apicid, cpu);
17139 if (err) {
17140 pr_debug("do_boot_cpu failed %d\n", err);
17141 diff -urNp linux-2.6.39/arch/x86/kernel/step.c linux-2.6.39/arch/x86/kernel/step.c
17142 --- linux-2.6.39/arch/x86/kernel/step.c 2011-05-19 00:06:34.000000000 -0400
17143 +++ linux-2.6.39/arch/x86/kernel/step.c 2011-05-22 19:36:30.000000000 -0400
17144 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struc
17145 struct desc_struct *desc;
17146 unsigned long base;
17147
17148 - seg &= ~7UL;
17149 + seg >>= 3;
17150
17151 mutex_lock(&child->mm->context.lock);
17152 - if (unlikely((seg >> 3) >= child->mm->context.size))
17153 + if (unlikely(seg >= child->mm->context.size))
17154 addr = -1L; /* bogus selector, access would fault */
17155 else {
17156 desc = child->mm->context.ldt + seg;
17157 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struc
17158 addr += base;
17159 }
17160 mutex_unlock(&child->mm->context.lock);
17161 - }
17162 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
17163 + addr = ktla_ktva(addr);
17164
17165 return addr;
17166 }
17167 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct t
17168 unsigned char opcode[15];
17169 unsigned long addr = convert_ip_to_linear(child, regs);
17170
17171 + if (addr == -EINVAL)
17172 + return 0;
17173 +
17174 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
17175 for (i = 0; i < copied; i++) {
17176 switch (opcode[i]) {
17177 @@ -74,7 +78,7 @@ static int is_setting_trap_flag(struct t
17178
17179 #ifdef CONFIG_X86_64
17180 case 0x40 ... 0x4f:
17181 - if (regs->cs != __USER_CS)
17182 + if ((regs->cs & 0xffff) != __USER_CS)
17183 /* 32-bit mode: register increment */
17184 return 0;
17185 /* 64-bit mode: REX prefix */
17186 diff -urNp linux-2.6.39/arch/x86/kernel/syscall_table_32.S linux-2.6.39/arch/x86/kernel/syscall_table_32.S
17187 --- linux-2.6.39/arch/x86/kernel/syscall_table_32.S 2011-05-19 00:06:34.000000000 -0400
17188 +++ linux-2.6.39/arch/x86/kernel/syscall_table_32.S 2011-05-22 19:36:30.000000000 -0400
17189 @@ -1,3 +1,4 @@
17190 +.section .rodata,"a",@progbits
17191 ENTRY(sys_call_table)
17192 .long sys_restart_syscall /* 0 - old "setup()" system call, used for restarting */
17193 .long sys_exit
17194 diff -urNp linux-2.6.39/arch/x86/kernel/sys_i386_32.c linux-2.6.39/arch/x86/kernel/sys_i386_32.c
17195 --- linux-2.6.39/arch/x86/kernel/sys_i386_32.c 2011-05-19 00:06:34.000000000 -0400
17196 +++ linux-2.6.39/arch/x86/kernel/sys_i386_32.c 2011-05-22 19:36:30.000000000 -0400
17197 @@ -24,17 +24,224 @@
17198
17199 #include <asm/syscalls.h>
17200
17201 -/*
17202 - * Do a system call from kernel instead of calling sys_execve so we
17203 - * end up with proper pt_regs.
17204 - */
17205 -int kernel_execve(const char *filename,
17206 - const char *const argv[],
17207 - const char *const envp[])
17208 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
17209 {
17210 - long __res;
17211 - asm volatile ("int $0x80"
17212 - : "=a" (__res)
17213 - : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
17214 - return __res;
17215 + unsigned long pax_task_size = TASK_SIZE;
17216 +
17217 +#ifdef CONFIG_PAX_SEGMEXEC
17218 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
17219 + pax_task_size = SEGMEXEC_TASK_SIZE;
17220 +#endif
17221 +
17222 + if (len > pax_task_size || addr > pax_task_size - len)
17223 + return -EINVAL;
17224 +
17225 + return 0;
17226 +}
17227 +
17228 +unsigned long
17229 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
17230 + unsigned long len, unsigned long pgoff, unsigned long flags)
17231 +{
17232 + struct mm_struct *mm = current->mm;
17233 + struct vm_area_struct *vma;
17234 + unsigned long start_addr, pax_task_size = TASK_SIZE;
17235 +
17236 +#ifdef CONFIG_PAX_SEGMEXEC
17237 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
17238 + pax_task_size = SEGMEXEC_TASK_SIZE;
17239 +#endif
17240 +
17241 + pax_task_size -= PAGE_SIZE;
17242 +
17243 + if (len > pax_task_size)
17244 + return -ENOMEM;
17245 +
17246 + if (flags & MAP_FIXED)
17247 + return addr;
17248 +
17249 +#ifdef CONFIG_PAX_RANDMMAP
17250 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
17251 +#endif
17252 +
17253 + if (addr) {
17254 + addr = PAGE_ALIGN(addr);
17255 + if (pax_task_size - len >= addr) {
17256 + vma = find_vma(mm, addr);
17257 + if (check_heap_stack_gap(vma, addr, len))
17258 + return addr;
17259 + }
17260 + }
17261 + if (len > mm->cached_hole_size) {
17262 + start_addr = addr = mm->free_area_cache;
17263 + } else {
17264 + start_addr = addr = mm->mmap_base;
17265 + mm->cached_hole_size = 0;
17266 + }
17267 +
17268 +#ifdef CONFIG_PAX_PAGEEXEC
17269 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
17270 + start_addr = 0x00110000UL;
17271 +
17272 +#ifdef CONFIG_PAX_RANDMMAP
17273 + if (mm->pax_flags & MF_PAX_RANDMMAP)
17274 + start_addr += mm->delta_mmap & 0x03FFF000UL;
17275 +#endif
17276 +
17277 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
17278 + start_addr = addr = mm->mmap_base;
17279 + else
17280 + addr = start_addr;
17281 + }
17282 +#endif
17283 +
17284 +full_search:
17285 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
17286 + /* At this point: (!vma || addr < vma->vm_end). */
17287 + if (pax_task_size - len < addr) {
17288 + /*
17289 + * Start a new search - just in case we missed
17290 + * some holes.
17291 + */
17292 + if (start_addr != mm->mmap_base) {
17293 + start_addr = addr = mm->mmap_base;
17294 + mm->cached_hole_size = 0;
17295 + goto full_search;
17296 + }
17297 + return -ENOMEM;
17298 + }
17299 + if (check_heap_stack_gap(vma, addr, len))
17300 + break;
17301 + if (addr + mm->cached_hole_size < vma->vm_start)
17302 + mm->cached_hole_size = vma->vm_start - addr;
17303 + addr = vma->vm_end;
17304 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
17305 + start_addr = addr = mm->mmap_base;
17306 + mm->cached_hole_size = 0;
17307 + goto full_search;
17308 + }
17309 + }
17310 +
17311 + /*
17312 + * Remember the place where we stopped the search:
17313 + */
17314 + mm->free_area_cache = addr + len;
17315 + return addr;
17316 +}
17317 +
17318 +unsigned long
17319 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
17320 + const unsigned long len, const unsigned long pgoff,
17321 + const unsigned long flags)
17322 +{
17323 + struct vm_area_struct *vma;
17324 + struct mm_struct *mm = current->mm;
17325 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
17326 +
17327 +#ifdef CONFIG_PAX_SEGMEXEC
17328 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
17329 + pax_task_size = SEGMEXEC_TASK_SIZE;
17330 +#endif
17331 +
17332 + pax_task_size -= PAGE_SIZE;
17333 +
17334 + /* requested length too big for entire address space */
17335 + if (len > pax_task_size)
17336 + return -ENOMEM;
17337 +
17338 + if (flags & MAP_FIXED)
17339 + return addr;
17340 +
17341 +#ifdef CONFIG_PAX_PAGEEXEC
17342 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
17343 + goto bottomup;
17344 +#endif
17345 +
17346 +#ifdef CONFIG_PAX_RANDMMAP
17347 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
17348 +#endif
17349 +
17350 + /* requesting a specific address */
17351 + if (addr) {
17352 + addr = PAGE_ALIGN(addr);
17353 + if (pax_task_size - len >= addr) {
17354 + vma = find_vma(mm, addr);
17355 + if (check_heap_stack_gap(vma, addr, len))
17356 + return addr;
17357 + }
17358 + }
17359 +
17360 + /* check if free_area_cache is useful for us */
17361 + if (len <= mm->cached_hole_size) {
17362 + mm->cached_hole_size = 0;
17363 + mm->free_area_cache = mm->mmap_base;
17364 + }
17365 +
17366 + /* either no address requested or can't fit in requested address hole */
17367 + addr = mm->free_area_cache;
17368 +
17369 + /* make sure it can fit in the remaining address space */
17370 + if (addr > len) {
17371 + vma = find_vma(mm, addr-len);
17372 + if (check_heap_stack_gap(vma, addr - len, len))
17373 + /* remember the address as a hint for next time */
17374 + return (mm->free_area_cache = addr-len);
17375 + }
17376 +
17377 + if (mm->mmap_base < len)
17378 + goto bottomup;
17379 +
17380 + addr = mm->mmap_base-len;
17381 +
17382 + do {
17383 + /*
17384 + * Lookup failure means no vma is above this address,
17385 + * else if new region fits below vma->vm_start,
17386 + * return with success:
17387 + */
17388 + vma = find_vma(mm, addr);
17389 + if (check_heap_stack_gap(vma, addr, len))
17390 + /* remember the address as a hint for next time */
17391 + return (mm->free_area_cache = addr);
17392 +
17393 + /* remember the largest hole we saw so far */
17394 + if (addr + mm->cached_hole_size < vma->vm_start)
17395 + mm->cached_hole_size = vma->vm_start - addr;
17396 +
17397 + /* try just below the current vma->vm_start */
17398 + addr = skip_heap_stack_gap(vma, len);
17399 + } while (!IS_ERR_VALUE(addr));
17400 +
17401 +bottomup:
17402 + /*
17403 + * A failed mmap() very likely causes application failure,
17404 + * so fall back to the bottom-up function here. This scenario
17405 + * can happen with large stack limits and large mmap()
17406 + * allocations.
17407 + */
17408 +
17409 +#ifdef CONFIG_PAX_SEGMEXEC
17410 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
17411 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
17412 + else
17413 +#endif
17414 +
17415 + mm->mmap_base = TASK_UNMAPPED_BASE;
17416 +
17417 +#ifdef CONFIG_PAX_RANDMMAP
17418 + if (mm->pax_flags & MF_PAX_RANDMMAP)
17419 + mm->mmap_base += mm->delta_mmap;
17420 +#endif
17421 +
17422 + mm->free_area_cache = mm->mmap_base;
17423 + mm->cached_hole_size = ~0UL;
17424 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
17425 + /*
17426 + * Restore the topdown base:
17427 + */
17428 + mm->mmap_base = base;
17429 + mm->free_area_cache = base;
17430 + mm->cached_hole_size = ~0UL;
17431 +
17432 + return addr;
17433 }
17434 diff -urNp linux-2.6.39/arch/x86/kernel/sys_x86_64.c linux-2.6.39/arch/x86/kernel/sys_x86_64.c
17435 --- linux-2.6.39/arch/x86/kernel/sys_x86_64.c 2011-05-19 00:06:34.000000000 -0400
17436 +++ linux-2.6.39/arch/x86/kernel/sys_x86_64.c 2011-05-22 19:36:30.000000000 -0400
17437 @@ -32,8 +32,8 @@ out:
17438 return error;
17439 }
17440
17441 -static void find_start_end(unsigned long flags, unsigned long *begin,
17442 - unsigned long *end)
17443 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
17444 + unsigned long *begin, unsigned long *end)
17445 {
17446 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT)) {
17447 unsigned long new_begin;
17448 @@ -52,7 +52,7 @@ static void find_start_end(unsigned long
17449 *begin = new_begin;
17450 }
17451 } else {
17452 - *begin = TASK_UNMAPPED_BASE;
17453 + *begin = mm->mmap_base;
17454 *end = TASK_SIZE;
17455 }
17456 }
17457 @@ -69,16 +69,19 @@ arch_get_unmapped_area(struct file *filp
17458 if (flags & MAP_FIXED)
17459 return addr;
17460
17461 - find_start_end(flags, &begin, &end);
17462 + find_start_end(mm, flags, &begin, &end);
17463
17464 if (len > end)
17465 return -ENOMEM;
17466
17467 +#ifdef CONFIG_PAX_RANDMMAP
17468 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
17469 +#endif
17470 +
17471 if (addr) {
17472 addr = PAGE_ALIGN(addr);
17473 vma = find_vma(mm, addr);
17474 - if (end - len >= addr &&
17475 - (!vma || addr + len <= vma->vm_start))
17476 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
17477 return addr;
17478 }
17479 if (((flags & MAP_32BIT) || test_thread_flag(TIF_IA32))
17480 @@ -106,7 +109,7 @@ full_search:
17481 }
17482 return -ENOMEM;
17483 }
17484 - if (!vma || addr + len <= vma->vm_start) {
17485 + if (check_heap_stack_gap(vma, addr, len)) {
17486 /*
17487 * Remember the place where we stopped the search:
17488 */
17489 @@ -128,7 +131,7 @@ arch_get_unmapped_area_topdown(struct fi
17490 {
17491 struct vm_area_struct *vma;
17492 struct mm_struct *mm = current->mm;
17493 - unsigned long addr = addr0;
17494 + unsigned long base = mm->mmap_base, addr = addr0;
17495
17496 /* requested length too big for entire address space */
17497 if (len > TASK_SIZE)
17498 @@ -141,13 +144,18 @@ arch_get_unmapped_area_topdown(struct fi
17499 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT))
17500 goto bottomup;
17501
17502 +#ifdef CONFIG_PAX_RANDMMAP
17503 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
17504 +#endif
17505 +
17506 /* requesting a specific address */
17507 if (addr) {
17508 addr = PAGE_ALIGN(addr);
17509 - vma = find_vma(mm, addr);
17510 - if (TASK_SIZE - len >= addr &&
17511 - (!vma || addr + len <= vma->vm_start))
17512 - return addr;
17513 + if (TASK_SIZE - len >= addr) {
17514 + vma = find_vma(mm, addr);
17515 + if (check_heap_stack_gap(vma, addr, len))
17516 + return addr;
17517 + }
17518 }
17519
17520 /* check if free_area_cache is useful for us */
17521 @@ -162,7 +170,7 @@ arch_get_unmapped_area_topdown(struct fi
17522 /* make sure it can fit in the remaining address space */
17523 if (addr > len) {
17524 vma = find_vma(mm, addr-len);
17525 - if (!vma || addr <= vma->vm_start)
17526 + if (check_heap_stack_gap(vma, addr - len, len))
17527 /* remember the address as a hint for next time */
17528 return mm->free_area_cache = addr-len;
17529 }
17530 @@ -179,7 +187,7 @@ arch_get_unmapped_area_topdown(struct fi
17531 * return with success:
17532 */
17533 vma = find_vma(mm, addr);
17534 - if (!vma || addr+len <= vma->vm_start)
17535 + if (check_heap_stack_gap(vma, addr, len))
17536 /* remember the address as a hint for next time */
17537 return mm->free_area_cache = addr;
17538
17539 @@ -188,8 +196,8 @@ arch_get_unmapped_area_topdown(struct fi
17540 mm->cached_hole_size = vma->vm_start - addr;
17541
17542 /* try just below the current vma->vm_start */
17543 - addr = vma->vm_start-len;
17544 - } while (len < vma->vm_start);
17545 + addr = skip_heap_stack_gap(vma, len);
17546 + } while (!IS_ERR_VALUE(addr));
17547
17548 bottomup:
17549 /*
17550 @@ -198,13 +206,21 @@ bottomup:
17551 * can happen with large stack limits and large mmap()
17552 * allocations.
17553 */
17554 + mm->mmap_base = TASK_UNMAPPED_BASE;
17555 +
17556 +#ifdef CONFIG_PAX_RANDMMAP
17557 + if (mm->pax_flags & MF_PAX_RANDMMAP)
17558 + mm->mmap_base += mm->delta_mmap;
17559 +#endif
17560 +
17561 + mm->free_area_cache = mm->mmap_base;
17562 mm->cached_hole_size = ~0UL;
17563 - mm->free_area_cache = TASK_UNMAPPED_BASE;
17564 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
17565 /*
17566 * Restore the topdown base:
17567 */
17568 - mm->free_area_cache = mm->mmap_base;
17569 + mm->mmap_base = base;
17570 + mm->free_area_cache = base;
17571 mm->cached_hole_size = ~0UL;
17572
17573 return addr;
17574 diff -urNp linux-2.6.39/arch/x86/kernel/tboot.c linux-2.6.39/arch/x86/kernel/tboot.c
17575 --- linux-2.6.39/arch/x86/kernel/tboot.c 2011-05-19 00:06:34.000000000 -0400
17576 +++ linux-2.6.39/arch/x86/kernel/tboot.c 2011-05-22 19:36:30.000000000 -0400
17577 @@ -218,7 +218,7 @@ static int tboot_setup_sleep(void)
17578
17579 void tboot_shutdown(u32 shutdown_type)
17580 {
17581 - void (*shutdown)(void);
17582 + void (* __noreturn shutdown)(void);
17583
17584 if (!tboot_enabled())
17585 return;
17586 @@ -240,7 +240,7 @@ void tboot_shutdown(u32 shutdown_type)
17587
17588 switch_to_tboot_pt();
17589
17590 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
17591 + shutdown = (void *)tboot->shutdown_entry;
17592 shutdown();
17593
17594 /* should not reach here */
17595 @@ -297,7 +297,7 @@ void tboot_sleep(u8 sleep_state, u32 pm1
17596 tboot_shutdown(acpi_shutdown_map[sleep_state]);
17597 }
17598
17599 -static atomic_t ap_wfs_count;
17600 +static atomic_unchecked_t ap_wfs_count;
17601
17602 static int tboot_wait_for_aps(int num_aps)
17603 {
17604 @@ -321,9 +321,9 @@ static int __cpuinit tboot_cpu_callback(
17605 {
17606 switch (action) {
17607 case CPU_DYING:
17608 - atomic_inc(&ap_wfs_count);
17609 + atomic_inc_unchecked(&ap_wfs_count);
17610 if (num_online_cpus() == 1)
17611 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
17612 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
17613 return NOTIFY_BAD;
17614 break;
17615 }
17616 @@ -342,7 +342,7 @@ static __init int tboot_late_init(void)
17617
17618 tboot_create_trampoline();
17619
17620 - atomic_set(&ap_wfs_count, 0);
17621 + atomic_set_unchecked(&ap_wfs_count, 0);
17622 register_hotcpu_notifier(&tboot_cpu_notifier);
17623 return 0;
17624 }
17625 diff -urNp linux-2.6.39/arch/x86/kernel/time.c linux-2.6.39/arch/x86/kernel/time.c
17626 --- linux-2.6.39/arch/x86/kernel/time.c 2011-05-19 00:06:34.000000000 -0400
17627 +++ linux-2.6.39/arch/x86/kernel/time.c 2011-05-22 19:36:30.000000000 -0400
17628 @@ -22,17 +22,13 @@
17629 #include <asm/hpet.h>
17630 #include <asm/time.h>
17631
17632 -#ifdef CONFIG_X86_64
17633 -volatile unsigned long __jiffies __section_jiffies = INITIAL_JIFFIES;
17634 -#endif
17635 -
17636 unsigned long profile_pc(struct pt_regs *regs)
17637 {
17638 unsigned long pc = instruction_pointer(regs);
17639
17640 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
17641 + if (!user_mode(regs) && in_lock_functions(pc)) {
17642 #ifdef CONFIG_FRAME_POINTER
17643 - return *(unsigned long *)(regs->bp + sizeof(long));
17644 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
17645 #else
17646 unsigned long *sp =
17647 (unsigned long *)kernel_stack_pointer(regs);
17648 @@ -41,11 +37,17 @@ unsigned long profile_pc(struct pt_regs
17649 * or above a saved flags. Eflags has bits 22-31 zero,
17650 * kernel addresses don't.
17651 */
17652 +
17653 +#ifdef CONFIG_PAX_KERNEXEC
17654 + return ktla_ktva(sp[0]);
17655 +#else
17656 if (sp[0] >> 22)
17657 return sp[0];
17658 if (sp[1] >> 22)
17659 return sp[1];
17660 #endif
17661 +
17662 +#endif
17663 }
17664 return pc;
17665 }
17666 diff -urNp linux-2.6.39/arch/x86/kernel/tls.c linux-2.6.39/arch/x86/kernel/tls.c
17667 --- linux-2.6.39/arch/x86/kernel/tls.c 2011-05-19 00:06:34.000000000 -0400
17668 +++ linux-2.6.39/arch/x86/kernel/tls.c 2011-05-22 19:36:30.000000000 -0400
17669 @@ -85,6 +85,11 @@ int do_set_thread_area(struct task_struc
17670 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
17671 return -EINVAL;
17672
17673 +#ifdef CONFIG_PAX_SEGMEXEC
17674 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
17675 + return -EINVAL;
17676 +#endif
17677 +
17678 set_tls_desc(p, idx, &info, 1);
17679
17680 return 0;
17681 diff -urNp linux-2.6.39/arch/x86/kernel/trampoline_32.S linux-2.6.39/arch/x86/kernel/trampoline_32.S
17682 --- linux-2.6.39/arch/x86/kernel/trampoline_32.S 2011-05-19 00:06:34.000000000 -0400
17683 +++ linux-2.6.39/arch/x86/kernel/trampoline_32.S 2011-05-22 19:36:30.000000000 -0400
17684 @@ -32,6 +32,12 @@
17685 #include <asm/segment.h>
17686 #include <asm/page_types.h>
17687
17688 +#ifdef CONFIG_PAX_KERNEXEC
17689 +#define ta(X) (X)
17690 +#else
17691 +#define ta(X) ((X) - __PAGE_OFFSET)
17692 +#endif
17693 +
17694 #ifdef CONFIG_SMP
17695
17696 .section ".x86_trampoline","a"
17697 @@ -62,7 +68,7 @@ r_base = .
17698 inc %ax # protected mode (PE) bit
17699 lmsw %ax # into protected mode
17700 # flush prefetch and jump to startup_32_smp in arch/i386/kernel/head.S
17701 - ljmpl $__BOOT_CS, $(startup_32_smp-__PAGE_OFFSET)
17702 + ljmpl $__BOOT_CS, $ta(startup_32_smp)
17703
17704 # These need to be in the same 64K segment as the above;
17705 # hence we don't use the boot_gdt_descr defined in head.S
17706 diff -urNp linux-2.6.39/arch/x86/kernel/trampoline_64.S linux-2.6.39/arch/x86/kernel/trampoline_64.S
17707 --- linux-2.6.39/arch/x86/kernel/trampoline_64.S 2011-05-19 00:06:34.000000000 -0400
17708 +++ linux-2.6.39/arch/x86/kernel/trampoline_64.S 2011-05-22 19:36:30.000000000 -0400
17709 @@ -90,7 +90,7 @@ startup_32:
17710 movl $__KERNEL_DS, %eax # Initialize the %ds segment register
17711 movl %eax, %ds
17712
17713 - movl $X86_CR4_PAE, %eax
17714 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17715 movl %eax, %cr4 # Enable PAE mode
17716
17717 # Setup trampoline 4 level pagetables
17718 @@ -138,7 +138,7 @@ tidt:
17719 # so the kernel can live anywhere
17720 .balign 4
17721 tgdt:
17722 - .short tgdt_end - tgdt # gdt limit
17723 + .short tgdt_end - tgdt - 1 # gdt limit
17724 .long tgdt - r_base
17725 .short 0
17726 .quad 0x00cf9b000000ffff # __KERNEL32_CS
17727 diff -urNp linux-2.6.39/arch/x86/kernel/traps.c linux-2.6.39/arch/x86/kernel/traps.c
17728 --- linux-2.6.39/arch/x86/kernel/traps.c 2011-05-19 00:06:34.000000000 -0400
17729 +++ linux-2.6.39/arch/x86/kernel/traps.c 2011-05-22 19:36:30.000000000 -0400
17730 @@ -70,12 +70,6 @@ asmlinkage int system_call(void);
17731
17732 /* Do we ignore FPU interrupts ? */
17733 char ignore_fpu_irq;
17734 -
17735 -/*
17736 - * The IDT has to be page-aligned to simplify the Pentium
17737 - * F0 0F bug workaround.
17738 - */
17739 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
17740 #endif
17741
17742 DECLARE_BITMAP(used_vectors, NR_VECTORS);
17743 @@ -117,13 +111,13 @@ static inline void preempt_conditional_c
17744 }
17745
17746 static void __kprobes
17747 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
17748 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
17749 long error_code, siginfo_t *info)
17750 {
17751 struct task_struct *tsk = current;
17752
17753 #ifdef CONFIG_X86_32
17754 - if (regs->flags & X86_VM_MASK) {
17755 + if (v8086_mode(regs)) {
17756 /*
17757 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
17758 * On nmi (interrupt 2), do_trap should not be called.
17759 @@ -134,7 +128,7 @@ do_trap(int trapnr, int signr, char *str
17760 }
17761 #endif
17762
17763 - if (!user_mode(regs))
17764 + if (!user_mode_novm(regs))
17765 goto kernel_trap;
17766
17767 #ifdef CONFIG_X86_32
17768 @@ -157,7 +151,7 @@ trap_signal:
17769 printk_ratelimit()) {
17770 printk(KERN_INFO
17771 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
17772 - tsk->comm, tsk->pid, str,
17773 + tsk->comm, task_pid_nr(tsk), str,
17774 regs->ip, regs->sp, error_code);
17775 print_vma_addr(" in ", regs->ip);
17776 printk("\n");
17777 @@ -174,8 +168,20 @@ kernel_trap:
17778 if (!fixup_exception(regs)) {
17779 tsk->thread.error_code = error_code;
17780 tsk->thread.trap_no = trapnr;
17781 +
17782 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
17783 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
17784 + str = "PAX: suspicious stack segment fault";
17785 +#endif
17786 +
17787 die(str, regs, error_code);
17788 }
17789 +
17790 +#ifdef CONFIG_PAX_REFCOUNT
17791 + if (trapnr == 4)
17792 + pax_report_refcount_overflow(regs);
17793 +#endif
17794 +
17795 return;
17796
17797 #ifdef CONFIG_X86_32
17798 @@ -264,14 +270,30 @@ do_general_protection(struct pt_regs *re
17799 conditional_sti(regs);
17800
17801 #ifdef CONFIG_X86_32
17802 - if (regs->flags & X86_VM_MASK)
17803 + if (v8086_mode(regs))
17804 goto gp_in_vm86;
17805 #endif
17806
17807 tsk = current;
17808 - if (!user_mode(regs))
17809 + if (!user_mode_novm(regs))
17810 goto gp_in_kernel;
17811
17812 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17813 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
17814 + struct mm_struct *mm = tsk->mm;
17815 + unsigned long limit;
17816 +
17817 + down_write(&mm->mmap_sem);
17818 + limit = mm->context.user_cs_limit;
17819 + if (limit < TASK_SIZE) {
17820 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
17821 + up_write(&mm->mmap_sem);
17822 + return;
17823 + }
17824 + up_write(&mm->mmap_sem);
17825 + }
17826 +#endif
17827 +
17828 tsk->thread.error_code = error_code;
17829 tsk->thread.trap_no = 13;
17830
17831 @@ -304,6 +326,13 @@ gp_in_kernel:
17832 if (notify_die(DIE_GPF, "general protection fault", regs,
17833 error_code, 13, SIGSEGV) == NOTIFY_STOP)
17834 return;
17835 +
17836 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
17837 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
17838 + die("PAX: suspicious general protection fault", regs, error_code);
17839 + else
17840 +#endif
17841 +
17842 die("general protection fault", regs, error_code);
17843 }
17844
17845 @@ -569,7 +598,7 @@ dotraplinkage void __kprobes do_debug(st
17846 /* It's safe to allow irq's after DR6 has been saved */
17847 preempt_conditional_sti(regs);
17848
17849 - if (regs->flags & X86_VM_MASK) {
17850 + if (v8086_mode(regs)) {
17851 handle_vm86_trap((struct kernel_vm86_regs *) regs,
17852 error_code, 1);
17853 preempt_conditional_cli(regs);
17854 @@ -583,7 +612,7 @@ dotraplinkage void __kprobes do_debug(st
17855 * We already checked v86 mode above, so we can check for kernel mode
17856 * by just checking the CPL of CS.
17857 */
17858 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
17859 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
17860 tsk->thread.debugreg6 &= ~DR_STEP;
17861 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
17862 regs->flags &= ~X86_EFLAGS_TF;
17863 @@ -612,7 +641,7 @@ void math_error(struct pt_regs *regs, in
17864 return;
17865 conditional_sti(regs);
17866
17867 - if (!user_mode_vm(regs))
17868 + if (!user_mode(regs))
17869 {
17870 if (!fixup_exception(regs)) {
17871 task->thread.error_code = error_code;
17872 @@ -723,7 +752,7 @@ asmlinkage void __attribute__((weak)) sm
17873 void __math_state_restore(void)
17874 {
17875 struct thread_info *thread = current_thread_info();
17876 - struct task_struct *tsk = thread->task;
17877 + struct task_struct *tsk = current;
17878
17879 /*
17880 * Paranoid restore. send a SIGSEGV if we fail to restore the state.
17881 @@ -750,8 +779,7 @@ void __math_state_restore(void)
17882 */
17883 asmlinkage void math_state_restore(void)
17884 {
17885 - struct thread_info *thread = current_thread_info();
17886 - struct task_struct *tsk = thread->task;
17887 + struct task_struct *tsk = current;
17888
17889 if (!tsk_used_math(tsk)) {
17890 local_irq_enable();
17891 diff -urNp linux-2.6.39/arch/x86/kernel/vm86_32.c linux-2.6.39/arch/x86/kernel/vm86_32.c
17892 --- linux-2.6.39/arch/x86/kernel/vm86_32.c 2011-05-19 00:06:34.000000000 -0400
17893 +++ linux-2.6.39/arch/x86/kernel/vm86_32.c 2011-05-22 19:41:32.000000000 -0400
17894 @@ -41,6 +41,7 @@
17895 #include <linux/ptrace.h>
17896 #include <linux/audit.h>
17897 #include <linux/stddef.h>
17898 +#include <linux/grsecurity.h>
17899
17900 #include <asm/uaccess.h>
17901 #include <asm/io.h>
17902 @@ -148,7 +149,7 @@ struct pt_regs *save_v86_state(struct ke
17903 do_exit(SIGSEGV);
17904 }
17905
17906 - tss = &per_cpu(init_tss, get_cpu());
17907 + tss = init_tss + get_cpu();
17908 current->thread.sp0 = current->thread.saved_sp0;
17909 current->thread.sysenter_cs = __KERNEL_CS;
17910 load_sp0(tss, &current->thread);
17911 @@ -208,6 +209,13 @@ int sys_vm86old(struct vm86_struct __use
17912 struct task_struct *tsk;
17913 int tmp, ret = -EPERM;
17914
17915 +#ifdef CONFIG_GRKERNSEC_VM86
17916 + if (!capable(CAP_SYS_RAWIO)) {
17917 + gr_handle_vm86();
17918 + goto out;
17919 + }
17920 +#endif
17921 +
17922 tsk = current;
17923 if (tsk->thread.saved_sp0)
17924 goto out;
17925 @@ -238,6 +246,14 @@ int sys_vm86(unsigned long cmd, unsigned
17926 int tmp, ret;
17927 struct vm86plus_struct __user *v86;
17928
17929 +#ifdef CONFIG_GRKERNSEC_VM86
17930 + if (!capable(CAP_SYS_RAWIO)) {
17931 + gr_handle_vm86();
17932 + ret = -EPERM;
17933 + goto out;
17934 + }
17935 +#endif
17936 +
17937 tsk = current;
17938 switch (cmd) {
17939 case VM86_REQUEST_IRQ:
17940 @@ -324,7 +340,7 @@ static void do_sys_vm86(struct kernel_vm
17941 tsk->thread.saved_fs = info->regs32->fs;
17942 tsk->thread.saved_gs = get_user_gs(info->regs32);
17943
17944 - tss = &per_cpu(init_tss, get_cpu());
17945 + tss = init_tss + get_cpu();
17946 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
17947 if (cpu_has_sep)
17948 tsk->thread.sysenter_cs = 0;
17949 @@ -529,7 +545,7 @@ static void do_int(struct kernel_vm86_re
17950 goto cannot_handle;
17951 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
17952 goto cannot_handle;
17953 - intr_ptr = (unsigned long __user *) (i << 2);
17954 + intr_ptr = (__force unsigned long __user *) (i << 2);
17955 if (get_user(segoffs, intr_ptr))
17956 goto cannot_handle;
17957 if ((segoffs >> 16) == BIOSSEG)
17958 diff -urNp linux-2.6.39/arch/x86/kernel/vmlinux.lds.S linux-2.6.39/arch/x86/kernel/vmlinux.lds.S
17959 --- linux-2.6.39/arch/x86/kernel/vmlinux.lds.S 2011-05-19 00:06:34.000000000 -0400
17960 +++ linux-2.6.39/arch/x86/kernel/vmlinux.lds.S 2011-05-22 19:36:30.000000000 -0400
17961 @@ -26,6 +26,13 @@
17962 #include <asm/page_types.h>
17963 #include <asm/cache.h>
17964 #include <asm/boot.h>
17965 +#include <asm/segment.h>
17966 +
17967 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
17968 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
17969 +#else
17970 +#define __KERNEL_TEXT_OFFSET 0
17971 +#endif
17972
17973 #undef i386 /* in case the preprocessor is a 32bit one */
17974
17975 @@ -34,11 +41,9 @@ OUTPUT_FORMAT(CONFIG_OUTPUT_FORMAT, CONF
17976 #ifdef CONFIG_X86_32
17977 OUTPUT_ARCH(i386)
17978 ENTRY(phys_startup_32)
17979 -jiffies = jiffies_64;
17980 #else
17981 OUTPUT_ARCH(i386:x86-64)
17982 ENTRY(phys_startup_64)
17983 -jiffies_64 = jiffies;
17984 #endif
17985
17986 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
17987 @@ -69,31 +74,46 @@ jiffies_64 = jiffies;
17988
17989 PHDRS {
17990 text PT_LOAD FLAGS(5); /* R_E */
17991 +#ifdef CONFIG_X86_32
17992 + module PT_LOAD FLAGS(5); /* R_E */
17993 +#endif
17994 +#ifdef CONFIG_XEN
17995 + rodata PT_LOAD FLAGS(5); /* R_E */
17996 +#else
17997 + rodata PT_LOAD FLAGS(4); /* R__ */
17998 +#endif
17999 data PT_LOAD FLAGS(6); /* RW_ */
18000 #ifdef CONFIG_X86_64
18001 user PT_LOAD FLAGS(5); /* R_E */
18002 +#endif
18003 + init.begin PT_LOAD FLAGS(6); /* RW_ */
18004 #ifdef CONFIG_SMP
18005 percpu PT_LOAD FLAGS(6); /* RW_ */
18006 #endif
18007 + text.init PT_LOAD FLAGS(5); /* R_E */
18008 + text.exit PT_LOAD FLAGS(5); /* R_E */
18009 init PT_LOAD FLAGS(7); /* RWE */
18010 -#endif
18011 note PT_NOTE FLAGS(0); /* ___ */
18012 }
18013
18014 SECTIONS
18015 {
18016 #ifdef CONFIG_X86_32
18017 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
18018 - phys_startup_32 = startup_32 - LOAD_OFFSET;
18019 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
18020 #else
18021 - . = __START_KERNEL;
18022 - phys_startup_64 = startup_64 - LOAD_OFFSET;
18023 + . = __START_KERNEL;
18024 #endif
18025
18026 /* Text and read-only data */
18027 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
18028 - _text = .;
18029 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
18030 /* bootstrapping code */
18031 +#ifdef CONFIG_X86_32
18032 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
18033 +#else
18034 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
18035 +#endif
18036 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
18037 + _text = .;
18038 HEAD_TEXT
18039 #ifdef CONFIG_X86_32
18040 . = ALIGN(PAGE_SIZE);
18041 @@ -109,13 +129,47 @@ SECTIONS
18042 IRQENTRY_TEXT
18043 *(.fixup)
18044 *(.gnu.warning)
18045 - /* End of text section */
18046 - _etext = .;
18047 } :text = 0x9090
18048
18049 - NOTES :text :note
18050 + . += __KERNEL_TEXT_OFFSET;
18051 +
18052 +#ifdef CONFIG_X86_32
18053 + . = ALIGN(PAGE_SIZE);
18054 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
18055 +
18056 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
18057 + MODULES_EXEC_VADDR = .;
18058 + BYTE(0)
18059 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
18060 + . = ALIGN(HPAGE_SIZE);
18061 + MODULES_EXEC_END = . - 1;
18062 +#endif
18063 +
18064 + } :module
18065 +#endif
18066 +
18067 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
18068 + /* End of text section */
18069 + _etext = . - __KERNEL_TEXT_OFFSET;
18070 + }
18071
18072 - EXCEPTION_TABLE(16) :text = 0x9090
18073 +#ifdef CONFIG_X86_32
18074 + . = ALIGN(PAGE_SIZE);
18075 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
18076 + *(.idt)
18077 + . = ALIGN(PAGE_SIZE);
18078 + *(.empty_zero_page)
18079 + *(.initial_pg_fixmap)
18080 + *(.initial_pg_pmd)
18081 + *(.initial_page_table)
18082 + *(.swapper_pg_dir)
18083 + } :rodata
18084 +#endif
18085 +
18086 + . = ALIGN(PAGE_SIZE);
18087 + NOTES :rodata :note
18088 +
18089 + EXCEPTION_TABLE(16) :rodata
18090
18091 #if defined(CONFIG_DEBUG_RODATA)
18092 /* .text should occupy whole number of pages */
18093 @@ -127,16 +181,20 @@ SECTIONS
18094
18095 /* Data */
18096 .data : AT(ADDR(.data) - LOAD_OFFSET) {
18097 +
18098 +#ifdef CONFIG_PAX_KERNEXEC
18099 + . = ALIGN(HPAGE_SIZE);
18100 +#else
18101 + . = ALIGN(PAGE_SIZE);
18102 +#endif
18103 +
18104 /* Start of data section */
18105 _sdata = .;
18106
18107 /* init_task */
18108 INIT_TASK_DATA(THREAD_SIZE)
18109
18110 -#ifdef CONFIG_X86_32
18111 - /* 32 bit has nosave before _edata */
18112 NOSAVE_DATA
18113 -#endif
18114
18115 PAGE_ALIGNED_DATA(PAGE_SIZE)
18116
18117 @@ -145,6 +203,8 @@ SECTIONS
18118 DATA_DATA
18119 CONSTRUCTORS
18120
18121 + jiffies = jiffies_64;
18122 +
18123 /* rarely changed data like cpu maps */
18124 READ_MOSTLY_DATA(INTERNODE_CACHE_BYTES)
18125
18126 @@ -199,12 +259,6 @@ SECTIONS
18127 }
18128 vgetcpu_mode = VVIRT(.vgetcpu_mode);
18129
18130 - . = ALIGN(L1_CACHE_BYTES);
18131 - .jiffies : AT(VLOAD(.jiffies)) {
18132 - *(.jiffies)
18133 - }
18134 - jiffies = VVIRT(.jiffies);
18135 -
18136 .vsyscall_3 ADDR(.vsyscall_0) + 3072: AT(VLOAD(.vsyscall_3)) {
18137 *(.vsyscall_3)
18138 }
18139 @@ -220,12 +274,19 @@ SECTIONS
18140 #endif /* CONFIG_X86_64 */
18141
18142 /* Init code and data - will be freed after init */
18143 - . = ALIGN(PAGE_SIZE);
18144 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
18145 + BYTE(0)
18146 +
18147 +#ifdef CONFIG_PAX_KERNEXEC
18148 + . = ALIGN(HPAGE_SIZE);
18149 +#else
18150 + . = ALIGN(PAGE_SIZE);
18151 +#endif
18152 +
18153 __init_begin = .; /* paired with __init_end */
18154 - }
18155 + } :init.begin
18156
18157 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
18158 +#ifdef CONFIG_SMP
18159 /*
18160 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
18161 * output PHDR, so the next output section - .init.text - should
18162 @@ -234,12 +295,27 @@ SECTIONS
18163 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
18164 #endif
18165
18166 - INIT_TEXT_SECTION(PAGE_SIZE)
18167 -#ifdef CONFIG_X86_64
18168 - :init
18169 -#endif
18170 + . = ALIGN(PAGE_SIZE);
18171 + init_begin = .;
18172 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
18173 + VMLINUX_SYMBOL(_sinittext) = .;
18174 + INIT_TEXT
18175 + VMLINUX_SYMBOL(_einittext) = .;
18176 + . = ALIGN(PAGE_SIZE);
18177 + } :text.init
18178
18179 - INIT_DATA_SECTION(16)
18180 + /*
18181 + * .exit.text is discard at runtime, not link time, to deal with
18182 + * references from .altinstructions and .eh_frame
18183 + */
18184 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
18185 + EXIT_TEXT
18186 + . = ALIGN(16);
18187 + } :text.exit
18188 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
18189 +
18190 + . = ALIGN(PAGE_SIZE);
18191 + INIT_DATA_SECTION(16) :init
18192
18193 /*
18194 * Code and data for a variety of lowlevel trampolines, to be
18195 @@ -306,19 +382,12 @@ SECTIONS
18196 }
18197
18198 . = ALIGN(8);
18199 - /*
18200 - * .exit.text is discard at runtime, not link time, to deal with
18201 - * references from .altinstructions and .eh_frame
18202 - */
18203 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
18204 - EXIT_TEXT
18205 - }
18206
18207 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
18208 EXIT_DATA
18209 }
18210
18211 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
18212 +#ifndef CONFIG_SMP
18213 PERCPU(INTERNODE_CACHE_BYTES, PAGE_SIZE)
18214 #endif
18215
18216 @@ -337,16 +406,10 @@ SECTIONS
18217 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
18218 __smp_locks = .;
18219 *(.smp_locks)
18220 - . = ALIGN(PAGE_SIZE);
18221 __smp_locks_end = .;
18222 + . = ALIGN(PAGE_SIZE);
18223 }
18224
18225 -#ifdef CONFIG_X86_64
18226 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
18227 - NOSAVE_DATA
18228 - }
18229 -#endif
18230 -
18231 /* BSS */
18232 . = ALIGN(PAGE_SIZE);
18233 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
18234 @@ -362,6 +425,7 @@ SECTIONS
18235 __brk_base = .;
18236 . += 64 * 1024; /* 64k alignment slop space */
18237 *(.brk_reservation) /* areas brk users have reserved */
18238 + . = ALIGN(HPAGE_SIZE);
18239 __brk_limit = .;
18240 }
18241
18242 @@ -388,13 +452,12 @@ SECTIONS
18243 * for the boot processor.
18244 */
18245 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
18246 -INIT_PER_CPU(gdt_page);
18247 INIT_PER_CPU(irq_stack_union);
18248
18249 /*
18250 * Build-time check on the image size:
18251 */
18252 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
18253 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
18254 "kernel image bigger than KERNEL_IMAGE_SIZE");
18255
18256 #ifdef CONFIG_SMP
18257 diff -urNp linux-2.6.39/arch/x86/kernel/vsyscall_64.c linux-2.6.39/arch/x86/kernel/vsyscall_64.c
18258 --- linux-2.6.39/arch/x86/kernel/vsyscall_64.c 2011-05-19 00:06:34.000000000 -0400
18259 +++ linux-2.6.39/arch/x86/kernel/vsyscall_64.c 2011-05-22 19:36:30.000000000 -0400
18260 @@ -80,6 +80,7 @@ void update_vsyscall(struct timespec *wa
18261
18262 write_seqlock_irqsave(&vsyscall_gtod_data.lock, flags);
18263 /* copy vsyscall data */
18264 + strlcpy(vsyscall_gtod_data.clock.name, clock->name, sizeof vsyscall_gtod_data.clock.name);
18265 vsyscall_gtod_data.clock.vread = clock->vread;
18266 vsyscall_gtod_data.clock.cycle_last = clock->cycle_last;
18267 vsyscall_gtod_data.clock.mask = clock->mask;
18268 @@ -208,7 +209,7 @@ vgetcpu(unsigned *cpu, unsigned *node, s
18269 We do this here because otherwise user space would do it on
18270 its own in a likely inferior way (no access to jiffies).
18271 If you don't like it pass NULL. */
18272 - if (tcache && tcache->blob[0] == (j = __jiffies)) {
18273 + if (tcache && tcache->blob[0] == (j = jiffies)) {
18274 p = tcache->blob[1];
18275 } else if (__vgetcpu_mode == VGETCPU_RDTSCP) {
18276 /* Load per CPU data from RDTSCP */
18277 diff -urNp linux-2.6.39/arch/x86/kernel/x8664_ksyms_64.c linux-2.6.39/arch/x86/kernel/x8664_ksyms_64.c
18278 --- linux-2.6.39/arch/x86/kernel/x8664_ksyms_64.c 2011-05-19 00:06:34.000000000 -0400
18279 +++ linux-2.6.39/arch/x86/kernel/x8664_ksyms_64.c 2011-05-22 19:36:30.000000000 -0400
18280 @@ -29,8 +29,6 @@ EXPORT_SYMBOL(__put_user_8);
18281 EXPORT_SYMBOL(copy_user_generic_string);
18282 EXPORT_SYMBOL(copy_user_generic_unrolled);
18283 EXPORT_SYMBOL(__copy_user_nocache);
18284 -EXPORT_SYMBOL(_copy_from_user);
18285 -EXPORT_SYMBOL(_copy_to_user);
18286
18287 EXPORT_SYMBOL(copy_page);
18288 EXPORT_SYMBOL(clear_page);
18289 diff -urNp linux-2.6.39/arch/x86/kernel/xsave.c linux-2.6.39/arch/x86/kernel/xsave.c
18290 --- linux-2.6.39/arch/x86/kernel/xsave.c 2011-05-19 00:06:34.000000000 -0400
18291 +++ linux-2.6.39/arch/x86/kernel/xsave.c 2011-05-22 19:36:30.000000000 -0400
18292 @@ -130,7 +130,7 @@ int check_for_xstate(struct i387_fxsave_
18293 fx_sw_user->xstate_size > fx_sw_user->extended_size)
18294 return -EINVAL;
18295
18296 - err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
18297 + err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
18298 fx_sw_user->extended_size -
18299 FP_XSTATE_MAGIC2_SIZE));
18300 if (err)
18301 @@ -267,7 +267,7 @@ fx_only:
18302 * the other extended state.
18303 */
18304 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
18305 - return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
18306 + return fxrstor_checking((struct i387_fxsave_struct __user *)buf);
18307 }
18308
18309 /*
18310 @@ -299,7 +299,7 @@ int restore_i387_xstate(void __user *buf
18311 if (use_xsave())
18312 err = restore_user_xstate(buf);
18313 else
18314 - err = fxrstor_checking((__force struct i387_fxsave_struct *)
18315 + err = fxrstor_checking((struct i387_fxsave_struct __user *)
18316 buf);
18317 if (unlikely(err)) {
18318 /*
18319 diff -urNp linux-2.6.39/arch/x86/kvm/emulate.c linux-2.6.39/arch/x86/kvm/emulate.c
18320 --- linux-2.6.39/arch/x86/kvm/emulate.c 2011-05-19 00:06:34.000000000 -0400
18321 +++ linux-2.6.39/arch/x86/kvm/emulate.c 2011-05-22 19:36:30.000000000 -0400
18322 @@ -89,7 +89,7 @@
18323 #define Src2ImmByte (2<<29)
18324 #define Src2One (3<<29)
18325 #define Src2Imm (4<<29)
18326 -#define Src2Mask (7<<29)
18327 +#define Src2Mask (7U<<29)
18328
18329 #define X2(x...) x, x
18330 #define X3(x...) X2(x), x
18331 @@ -190,6 +190,7 @@ struct group_dual {
18332
18333 #define ____emulate_2op(_op, _src, _dst, _eflags, _x, _y, _suffix, _dsttype) \
18334 do { \
18335 + unsigned long _tmp; \
18336 __asm__ __volatile__ ( \
18337 _PRE_EFLAGS("0", "4", "2") \
18338 _op _suffix " %"_x"3,%1; " \
18339 @@ -203,8 +204,6 @@ struct group_dual {
18340 /* Raw emulation: instruction has two explicit operands. */
18341 #define __emulate_2op_nobyte(_op,_src,_dst,_eflags,_wx,_wy,_lx,_ly,_qx,_qy) \
18342 do { \
18343 - unsigned long _tmp; \
18344 - \
18345 switch ((_dst).bytes) { \
18346 case 2: \
18347 ____emulate_2op(_op,_src,_dst,_eflags,_wx,_wy,"w",u16);\
18348 @@ -220,7 +219,6 @@ struct group_dual {
18349
18350 #define __emulate_2op(_op,_src,_dst,_eflags,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
18351 do { \
18352 - unsigned long _tmp; \
18353 switch ((_dst).bytes) { \
18354 case 1: \
18355 ____emulate_2op(_op,_src,_dst,_eflags,_bx,_by,"b",u8); \
18356 diff -urNp linux-2.6.39/arch/x86/kvm/lapic.c linux-2.6.39/arch/x86/kvm/lapic.c
18357 --- linux-2.6.39/arch/x86/kvm/lapic.c 2011-05-19 00:06:34.000000000 -0400
18358 +++ linux-2.6.39/arch/x86/kvm/lapic.c 2011-05-22 19:36:30.000000000 -0400
18359 @@ -53,7 +53,7 @@
18360 #define APIC_BUS_CYCLE_NS 1
18361
18362 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
18363 -#define apic_debug(fmt, arg...)
18364 +#define apic_debug(fmt, arg...) do {} while (0)
18365
18366 #define APIC_LVT_NUM 6
18367 /* 14 is the version for Xeon and Pentium 8.4.8*/
18368 diff -urNp linux-2.6.39/arch/x86/kvm/mmu.c linux-2.6.39/arch/x86/kvm/mmu.c
18369 --- linux-2.6.39/arch/x86/kvm/mmu.c 2011-05-19 00:06:34.000000000 -0400
18370 +++ linux-2.6.39/arch/x86/kvm/mmu.c 2011-05-22 19:36:30.000000000 -0400
18371 @@ -3240,7 +3240,7 @@ void kvm_mmu_pte_write(struct kvm_vcpu *
18372
18373 pgprintk("%s: gpa %llx bytes %d\n", __func__, gpa, bytes);
18374
18375 - invlpg_counter = atomic_read(&vcpu->kvm->arch.invlpg_counter);
18376 + invlpg_counter = atomic_read_unchecked(&vcpu->kvm->arch.invlpg_counter);
18377
18378 /*
18379 * Assume that the pte write on a page table of the same type
18380 @@ -3275,7 +3275,7 @@ void kvm_mmu_pte_write(struct kvm_vcpu *
18381 smp_rmb();
18382
18383 spin_lock(&vcpu->kvm->mmu_lock);
18384 - if (atomic_read(&vcpu->kvm->arch.invlpg_counter) != invlpg_counter)
18385 + if (atomic_read_unchecked(&vcpu->kvm->arch.invlpg_counter) != invlpg_counter)
18386 gentry = 0;
18387 kvm_mmu_free_some_pages(vcpu);
18388 ++vcpu->kvm->stat.mmu_pte_write;
18389 diff -urNp linux-2.6.39/arch/x86/kvm/paging_tmpl.h linux-2.6.39/arch/x86/kvm/paging_tmpl.h
18390 --- linux-2.6.39/arch/x86/kvm/paging_tmpl.h 2011-05-19 00:06:34.000000000 -0400
18391 +++ linux-2.6.39/arch/x86/kvm/paging_tmpl.h 2011-05-22 19:36:30.000000000 -0400
18392 @@ -552,6 +552,8 @@ static int FNAME(page_fault)(struct kvm_
18393 unsigned long mmu_seq;
18394 bool map_writable;
18395
18396 + pax_track_stack();
18397 +
18398 pgprintk("%s: addr %lx err %x\n", __func__, addr, error_code);
18399
18400 r = mmu_topup_memory_caches(vcpu);
18401 @@ -672,7 +674,7 @@ static void FNAME(invlpg)(struct kvm_vcp
18402 if (need_flush)
18403 kvm_flush_remote_tlbs(vcpu->kvm);
18404
18405 - atomic_inc(&vcpu->kvm->arch.invlpg_counter);
18406 + atomic_inc_unchecked(&vcpu->kvm->arch.invlpg_counter);
18407
18408 spin_unlock(&vcpu->kvm->mmu_lock);
18409
18410 diff -urNp linux-2.6.39/arch/x86/kvm/svm.c linux-2.6.39/arch/x86/kvm/svm.c
18411 --- linux-2.6.39/arch/x86/kvm/svm.c 2011-05-19 00:06:34.000000000 -0400
18412 +++ linux-2.6.39/arch/x86/kvm/svm.c 2011-05-22 19:36:30.000000000 -0400
18413 @@ -3278,7 +3278,11 @@ static void reload_tss(struct kvm_vcpu *
18414 int cpu = raw_smp_processor_id();
18415
18416 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
18417 +
18418 + pax_open_kernel();
18419 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
18420 + pax_close_kernel();
18421 +
18422 load_TR_desc();
18423 }
18424
18425 @@ -3656,6 +3660,10 @@ static void svm_vcpu_run(struct kvm_vcpu
18426 #endif
18427 #endif
18428
18429 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
18430 + __set_fs(current_thread_info()->addr_limit);
18431 +#endif
18432 +
18433 reload_tss(vcpu);
18434
18435 local_irq_disable();
18436 @@ -3871,7 +3879,7 @@ static void svm_fpu_deactivate(struct kv
18437 update_cr0_intercept(svm);
18438 }
18439
18440 -static struct kvm_x86_ops svm_x86_ops = {
18441 +static const struct kvm_x86_ops svm_x86_ops = {
18442 .cpu_has_kvm_support = has_svm,
18443 .disabled_by_bios = is_disabled,
18444 .hardware_setup = svm_hardware_setup,
18445 diff -urNp linux-2.6.39/arch/x86/kvm/vmx.c linux-2.6.39/arch/x86/kvm/vmx.c
18446 --- linux-2.6.39/arch/x86/kvm/vmx.c 2011-05-19 00:06:34.000000000 -0400
18447 +++ linux-2.6.39/arch/x86/kvm/vmx.c 2011-05-22 19:36:30.000000000 -0400
18448 @@ -725,7 +725,11 @@ static void reload_tss(void)
18449 struct desc_struct *descs;
18450
18451 descs = (void *)gdt->address;
18452 +
18453 + pax_open_kernel();
18454 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
18455 + pax_close_kernel();
18456 +
18457 load_TR_desc();
18458 }
18459
18460 @@ -1648,8 +1652,11 @@ static __init int hardware_setup(void)
18461 if (!cpu_has_vmx_flexpriority())
18462 flexpriority_enabled = 0;
18463
18464 - if (!cpu_has_vmx_tpr_shadow())
18465 - kvm_x86_ops->update_cr8_intercept = NULL;
18466 + if (!cpu_has_vmx_tpr_shadow()) {
18467 + pax_open_kernel();
18468 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
18469 + pax_close_kernel();
18470 + }
18471
18472 if (enable_ept && !cpu_has_vmx_ept_2m_page())
18473 kvm_disable_largepages();
18474 @@ -2693,7 +2700,7 @@ static int vmx_vcpu_setup(struct vcpu_vm
18475 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
18476
18477 asm("mov $.Lkvm_vmx_return, %0" : "=r"(kvm_vmx_return));
18478 - vmcs_writel(HOST_RIP, kvm_vmx_return); /* 22.2.5 */
18479 + vmcs_writel(HOST_RIP, ktla_ktva(kvm_vmx_return)); /* 22.2.5 */
18480 vmcs_write32(VM_EXIT_MSR_STORE_COUNT, 0);
18481 vmcs_write32(VM_EXIT_MSR_LOAD_COUNT, 0);
18482 vmcs_write64(VM_EXIT_MSR_LOAD_ADDR, __pa(vmx->msr_autoload.host));
18483 @@ -4068,6 +4075,12 @@ static void __noclone vmx_vcpu_run(struc
18484 "jmp .Lkvm_vmx_return \n\t"
18485 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
18486 ".Lkvm_vmx_return: "
18487 +
18488 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18489 + "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
18490 + ".Lkvm_vmx_return2: "
18491 +#endif
18492 +
18493 /* Save guest registers, load host registers, keep flags */
18494 "mov %0, %c[wordsize](%%"R"sp) \n\t"
18495 "pop %0 \n\t"
18496 @@ -4116,6 +4129,11 @@ static void __noclone vmx_vcpu_run(struc
18497 #endif
18498 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
18499 [wordsize]"i"(sizeof(ulong))
18500 +
18501 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18502 + ,[cs]"i"(__KERNEL_CS)
18503 +#endif
18504 +
18505 : "cc", "memory"
18506 , R"ax", R"bx", R"di", R"si"
18507 #ifdef CONFIG_X86_64
18508 @@ -4130,7 +4148,16 @@ static void __noclone vmx_vcpu_run(struc
18509
18510 vmx->idt_vectoring_info = vmcs_read32(IDT_VECTORING_INFO_FIELD);
18511
18512 - asm("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
18513 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r"(__KERNEL_DS));
18514 +
18515 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18516 + loadsegment(fs, __KERNEL_PERCPU);
18517 +#endif
18518 +
18519 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
18520 + __set_fs(current_thread_info()->addr_limit);
18521 +#endif
18522 +
18523 vmx->launched = 1;
18524
18525 vmx->exit_reason = vmcs_read32(VM_EXIT_REASON);
18526 @@ -4368,7 +4395,7 @@ static void vmx_set_supported_cpuid(u32
18527 {
18528 }
18529
18530 -static struct kvm_x86_ops vmx_x86_ops = {
18531 +static const struct kvm_x86_ops vmx_x86_ops = {
18532 .cpu_has_kvm_support = cpu_has_kvm_support,
18533 .disabled_by_bios = vmx_disabled_by_bios,
18534 .hardware_setup = hardware_setup,
18535 diff -urNp linux-2.6.39/arch/x86/kvm/x86.c linux-2.6.39/arch/x86/kvm/x86.c
18536 --- linux-2.6.39/arch/x86/kvm/x86.c 2011-05-19 00:06:34.000000000 -0400
18537 +++ linux-2.6.39/arch/x86/kvm/x86.c 2011-05-22 19:36:30.000000000 -0400
18538 @@ -94,7 +94,7 @@ static void update_cr8_intercept(struct
18539 static int kvm_dev_ioctl_get_supported_cpuid(struct kvm_cpuid2 *cpuid,
18540 struct kvm_cpuid_entry2 __user *entries);
18541
18542 -struct kvm_x86_ops *kvm_x86_ops;
18543 +const struct kvm_x86_ops *kvm_x86_ops;
18544 EXPORT_SYMBOL_GPL(kvm_x86_ops);
18545
18546 int ignore_msrs = 0;
18547 @@ -2050,6 +2050,8 @@ long kvm_arch_dev_ioctl(struct file *fil
18548 if (n < msr_list.nmsrs)
18549 goto out;
18550 r = -EFAULT;
18551 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
18552 + goto out;
18553 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
18554 num_msrs_to_save * sizeof(u32)))
18555 goto out;
18556 @@ -2217,15 +2219,20 @@ static int kvm_vcpu_ioctl_set_cpuid2(str
18557 struct kvm_cpuid2 *cpuid,
18558 struct kvm_cpuid_entry2 __user *entries)
18559 {
18560 - int r;
18561 + int r, i;
18562
18563 r = -E2BIG;
18564 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
18565 goto out;
18566 r = -EFAULT;
18567 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
18568 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
18569 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
18570 goto out;
18571 + for (i = 0; i < cpuid->nent; ++i) {
18572 + struct kvm_cpuid_entry2 cpuid_entry;
18573 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
18574 + goto out;
18575 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
18576 + }
18577 vcpu->arch.cpuid_nent = cpuid->nent;
18578 kvm_apic_set_version(vcpu);
18579 kvm_x86_ops->cpuid_update(vcpu);
18580 @@ -2240,15 +2247,19 @@ static int kvm_vcpu_ioctl_get_cpuid2(str
18581 struct kvm_cpuid2 *cpuid,
18582 struct kvm_cpuid_entry2 __user *entries)
18583 {
18584 - int r;
18585 + int r, i;
18586
18587 r = -E2BIG;
18588 if (cpuid->nent < vcpu->arch.cpuid_nent)
18589 goto out;
18590 r = -EFAULT;
18591 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
18592 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
18593 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
18594 goto out;
18595 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
18596 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
18597 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
18598 + goto out;
18599 + }
18600 return 0;
18601
18602 out:
18603 @@ -2526,7 +2537,7 @@ static int kvm_vcpu_ioctl_set_lapic(stru
18604 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
18605 struct kvm_interrupt *irq)
18606 {
18607 - if (irq->irq < 0 || irq->irq >= 256)
18608 + if (irq->irq >= 256)
18609 return -EINVAL;
18610 if (irqchip_in_kernel(vcpu->kvm))
18611 return -ENXIO;
18612 @@ -4672,7 +4683,7 @@ static unsigned long kvm_get_guest_ip(vo
18613 return ip;
18614 }
18615
18616 -static struct perf_guest_info_callbacks kvm_guest_cbs = {
18617 +static const struct perf_guest_info_callbacks kvm_guest_cbs = {
18618 .is_in_guest = kvm_is_in_guest,
18619 .is_user_mode = kvm_is_user_mode,
18620 .get_guest_ip = kvm_get_guest_ip,
18621 @@ -4690,10 +4701,10 @@ void kvm_after_handle_nmi(struct kvm_vcp
18622 }
18623 EXPORT_SYMBOL_GPL(kvm_after_handle_nmi);
18624
18625 -int kvm_arch_init(void *opaque)
18626 +int kvm_arch_init(const void *opaque)
18627 {
18628 int r;
18629 - struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
18630 + const struct kvm_x86_ops *ops = (const struct kvm_x86_ops *)opaque;
18631
18632 if (kvm_x86_ops) {
18633 printk(KERN_ERR "kvm: already loaded the other module\n");
18634 diff -urNp linux-2.6.39/arch/x86/lib/atomic64_32.c linux-2.6.39/arch/x86/lib/atomic64_32.c
18635 --- linux-2.6.39/arch/x86/lib/atomic64_32.c 2011-05-19 00:06:34.000000000 -0400
18636 +++ linux-2.6.39/arch/x86/lib/atomic64_32.c 2011-05-22 19:36:30.000000000 -0400
18637 @@ -8,18 +8,30 @@
18638
18639 long long atomic64_read_cx8(long long, const atomic64_t *v);
18640 EXPORT_SYMBOL(atomic64_read_cx8);
18641 +long long atomic64_read_unchecked_cx8(long long, const atomic64_unchecked_t *v);
18642 +EXPORT_SYMBOL(atomic64_read_unchecked_cx8);
18643 long long atomic64_set_cx8(long long, const atomic64_t *v);
18644 EXPORT_SYMBOL(atomic64_set_cx8);
18645 +long long atomic64_set_unchecked_cx8(long long, const atomic64_unchecked_t *v);
18646 +EXPORT_SYMBOL(atomic64_set_unchecked_cx8);
18647 long long atomic64_xchg_cx8(long long, unsigned high);
18648 EXPORT_SYMBOL(atomic64_xchg_cx8);
18649 long long atomic64_add_return_cx8(long long a, atomic64_t *v);
18650 EXPORT_SYMBOL(atomic64_add_return_cx8);
18651 +long long atomic64_add_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
18652 +EXPORT_SYMBOL(atomic64_add_return_unchecked_cx8);
18653 long long atomic64_sub_return_cx8(long long a, atomic64_t *v);
18654 EXPORT_SYMBOL(atomic64_sub_return_cx8);
18655 +long long atomic64_sub_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
18656 +EXPORT_SYMBOL(atomic64_sub_return_unchecked_cx8);
18657 long long atomic64_inc_return_cx8(long long a, atomic64_t *v);
18658 EXPORT_SYMBOL(atomic64_inc_return_cx8);
18659 +long long atomic64_inc_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
18660 +EXPORT_SYMBOL(atomic64_inc_return_unchecked_cx8);
18661 long long atomic64_dec_return_cx8(long long a, atomic64_t *v);
18662 EXPORT_SYMBOL(atomic64_dec_return_cx8);
18663 +long long atomic64_dec_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
18664 +EXPORT_SYMBOL(atomic64_dec_return_unchecked_cx8);
18665 long long atomic64_dec_if_positive_cx8(atomic64_t *v);
18666 EXPORT_SYMBOL(atomic64_dec_if_positive_cx8);
18667 int atomic64_inc_not_zero_cx8(atomic64_t *v);
18668 @@ -30,26 +42,46 @@ EXPORT_SYMBOL(atomic64_add_unless_cx8);
18669 #ifndef CONFIG_X86_CMPXCHG64
18670 long long atomic64_read_386(long long, const atomic64_t *v);
18671 EXPORT_SYMBOL(atomic64_read_386);
18672 +long long atomic64_read_unchecked_386(long long, const atomic64_unchecked_t *v);
18673 +EXPORT_SYMBOL(atomic64_read_unchecked_386);
18674 long long atomic64_set_386(long long, const atomic64_t *v);
18675 EXPORT_SYMBOL(atomic64_set_386);
18676 +long long atomic64_set_unchecked_386(long long, const atomic64_unchecked_t *v);
18677 +EXPORT_SYMBOL(atomic64_set_unchecked_386);
18678 long long atomic64_xchg_386(long long, unsigned high);
18679 EXPORT_SYMBOL(atomic64_xchg_386);
18680 long long atomic64_add_return_386(long long a, atomic64_t *v);
18681 EXPORT_SYMBOL(atomic64_add_return_386);
18682 +long long atomic64_add_return_unchecked_386(long long a, atomic64_unchecked_t *v);
18683 +EXPORT_SYMBOL(atomic64_add_return_unchecked_386);
18684 long long atomic64_sub_return_386(long long a, atomic64_t *v);
18685 EXPORT_SYMBOL(atomic64_sub_return_386);
18686 +long long atomic64_sub_return_unchecked_386(long long a, atomic64_unchecked_t *v);
18687 +EXPORT_SYMBOL(atomic64_sub_return_unchecked_386);
18688 long long atomic64_inc_return_386(long long a, atomic64_t *v);
18689 EXPORT_SYMBOL(atomic64_inc_return_386);
18690 +long long atomic64_inc_return_unchecked_386(long long a, atomic64_unchecked_t *v);
18691 +EXPORT_SYMBOL(atomic64_inc_return_unchecked_386);
18692 long long atomic64_dec_return_386(long long a, atomic64_t *v);
18693 EXPORT_SYMBOL(atomic64_dec_return_386);
18694 +long long atomic64_dec_return_unchecked_386(long long a, atomic64_unchecked_t *v);
18695 +EXPORT_SYMBOL(atomic64_dec_return_unchecked_386);
18696 long long atomic64_add_386(long long a, atomic64_t *v);
18697 EXPORT_SYMBOL(atomic64_add_386);
18698 +long long atomic64_add_unchecked_386(long long a, atomic64_unchecked_t *v);
18699 +EXPORT_SYMBOL(atomic64_add_unchecked_386);
18700 long long atomic64_sub_386(long long a, atomic64_t *v);
18701 EXPORT_SYMBOL(atomic64_sub_386);
18702 +long long atomic64_sub_unchecked_386(long long a, atomic64_unchecked_t *v);
18703 +EXPORT_SYMBOL(atomic64_sub_unchecked_386);
18704 long long atomic64_inc_386(long long a, atomic64_t *v);
18705 EXPORT_SYMBOL(atomic64_inc_386);
18706 +long long atomic64_inc_unchecked_386(long long a, atomic64_unchecked_t *v);
18707 +EXPORT_SYMBOL(atomic64_inc_unchecked_386);
18708 long long atomic64_dec_386(long long a, atomic64_t *v);
18709 EXPORT_SYMBOL(atomic64_dec_386);
18710 +long long atomic64_dec_unchecked_386(long long a, atomic64_unchecked_t *v);
18711 +EXPORT_SYMBOL(atomic64_dec_unchecked_386);
18712 long long atomic64_dec_if_positive_386(atomic64_t *v);
18713 EXPORT_SYMBOL(atomic64_dec_if_positive_386);
18714 int atomic64_inc_not_zero_386(atomic64_t *v);
18715 diff -urNp linux-2.6.39/arch/x86/lib/atomic64_386_32.S linux-2.6.39/arch/x86/lib/atomic64_386_32.S
18716 --- linux-2.6.39/arch/x86/lib/atomic64_386_32.S 2011-05-19 00:06:34.000000000 -0400
18717 +++ linux-2.6.39/arch/x86/lib/atomic64_386_32.S 2011-05-22 19:36:30.000000000 -0400
18718 @@ -48,6 +48,10 @@ BEGIN(read)
18719 movl (v), %eax
18720 movl 4(v), %edx
18721 RET_ENDP
18722 +BEGIN(read_unchecked)
18723 + movl (v), %eax
18724 + movl 4(v), %edx
18725 +RET_ENDP
18726 #undef v
18727
18728 #define v %esi
18729 @@ -55,6 +59,10 @@ BEGIN(set)
18730 movl %ebx, (v)
18731 movl %ecx, 4(v)
18732 RET_ENDP
18733 +BEGIN(set_unchecked)
18734 + movl %ebx, (v)
18735 + movl %ecx, 4(v)
18736 +RET_ENDP
18737 #undef v
18738
18739 #define v %esi
18740 @@ -70,6 +78,20 @@ RET_ENDP
18741 BEGIN(add)
18742 addl %eax, (v)
18743 adcl %edx, 4(v)
18744 +
18745 +#ifdef CONFIG_PAX_REFCOUNT
18746 + jno 0f
18747 + subl %eax, (v)
18748 + sbbl %edx, 4(v)
18749 + int $4
18750 +0:
18751 + _ASM_EXTABLE(0b, 0b)
18752 +#endif
18753 +
18754 +RET_ENDP
18755 +BEGIN(add_unchecked)
18756 + addl %eax, (v)
18757 + adcl %edx, 4(v)
18758 RET_ENDP
18759 #undef v
18760
18761 @@ -77,6 +99,24 @@ RET_ENDP
18762 BEGIN(add_return)
18763 addl (v), %eax
18764 adcl 4(v), %edx
18765 +
18766 +#ifdef CONFIG_PAX_REFCOUNT
18767 + into
18768 +1234:
18769 + _ASM_EXTABLE(1234b, 2f)
18770 +#endif
18771 +
18772 + movl %eax, (v)
18773 + movl %edx, 4(v)
18774 +
18775 +#ifdef CONFIG_PAX_REFCOUNT
18776 +2:
18777 +#endif
18778 +
18779 +RET_ENDP
18780 +BEGIN(add_return_unchecked)
18781 + addl (v), %eax
18782 + adcl 4(v), %edx
18783 movl %eax, (v)
18784 movl %edx, 4(v)
18785 RET_ENDP
18786 @@ -86,6 +126,20 @@ RET_ENDP
18787 BEGIN(sub)
18788 subl %eax, (v)
18789 sbbl %edx, 4(v)
18790 +
18791 +#ifdef CONFIG_PAX_REFCOUNT
18792 + jno 0f
18793 + addl %eax, (v)
18794 + adcl %edx, 4(v)
18795 + int $4
18796 +0:
18797 + _ASM_EXTABLE(0b, 0b)
18798 +#endif
18799 +
18800 +RET_ENDP
18801 +BEGIN(sub_unchecked)
18802 + subl %eax, (v)
18803 + sbbl %edx, 4(v)
18804 RET_ENDP
18805 #undef v
18806
18807 @@ -96,6 +150,27 @@ BEGIN(sub_return)
18808 sbbl $0, %edx
18809 addl (v), %eax
18810 adcl 4(v), %edx
18811 +
18812 +#ifdef CONFIG_PAX_REFCOUNT
18813 + into
18814 +1234:
18815 + _ASM_EXTABLE(1234b, 2f)
18816 +#endif
18817 +
18818 + movl %eax, (v)
18819 + movl %edx, 4(v)
18820 +
18821 +#ifdef CONFIG_PAX_REFCOUNT
18822 +2:
18823 +#endif
18824 +
18825 +RET_ENDP
18826 +BEGIN(sub_return_unchecked)
18827 + negl %edx
18828 + negl %eax
18829 + sbbl $0, %edx
18830 + addl (v), %eax
18831 + adcl 4(v), %edx
18832 movl %eax, (v)
18833 movl %edx, 4(v)
18834 RET_ENDP
18835 @@ -105,6 +180,20 @@ RET_ENDP
18836 BEGIN(inc)
18837 addl $1, (v)
18838 adcl $0, 4(v)
18839 +
18840 +#ifdef CONFIG_PAX_REFCOUNT
18841 + jno 0f
18842 + subl $1, (v)
18843 + sbbl $0, 4(v)
18844 + int $4
18845 +0:
18846 + _ASM_EXTABLE(0b, 0b)
18847 +#endif
18848 +
18849 +RET_ENDP
18850 +BEGIN(inc_unchecked)
18851 + addl $1, (v)
18852 + adcl $0, 4(v)
18853 RET_ENDP
18854 #undef v
18855
18856 @@ -114,6 +203,26 @@ BEGIN(inc_return)
18857 movl 4(v), %edx
18858 addl $1, %eax
18859 adcl $0, %edx
18860 +
18861 +#ifdef CONFIG_PAX_REFCOUNT
18862 + into
18863 +1234:
18864 + _ASM_EXTABLE(1234b, 2f)
18865 +#endif
18866 +
18867 + movl %eax, (v)
18868 + movl %edx, 4(v)
18869 +
18870 +#ifdef CONFIG_PAX_REFCOUNT
18871 +2:
18872 +#endif
18873 +
18874 +RET_ENDP
18875 +BEGIN(inc_return_unchecked)
18876 + movl (v), %eax
18877 + movl 4(v), %edx
18878 + addl $1, %eax
18879 + adcl $0, %edx
18880 movl %eax, (v)
18881 movl %edx, 4(v)
18882 RET_ENDP
18883 @@ -123,6 +232,20 @@ RET_ENDP
18884 BEGIN(dec)
18885 subl $1, (v)
18886 sbbl $0, 4(v)
18887 +
18888 +#ifdef CONFIG_PAX_REFCOUNT
18889 + jno 0f
18890 + addl $1, (v)
18891 + adcl $0, 4(v)
18892 + int $4
18893 +0:
18894 + _ASM_EXTABLE(0b, 0b)
18895 +#endif
18896 +
18897 +RET_ENDP
18898 +BEGIN(dec_unchecked)
18899 + subl $1, (v)
18900 + sbbl $0, 4(v)
18901 RET_ENDP
18902 #undef v
18903
18904 @@ -132,6 +255,26 @@ BEGIN(dec_return)
18905 movl 4(v), %edx
18906 subl $1, %eax
18907 sbbl $0, %edx
18908 +
18909 +#ifdef CONFIG_PAX_REFCOUNT
18910 + into
18911 +1234:
18912 + _ASM_EXTABLE(1234b, 2f)
18913 +#endif
18914 +
18915 + movl %eax, (v)
18916 + movl %edx, 4(v)
18917 +
18918 +#ifdef CONFIG_PAX_REFCOUNT
18919 +2:
18920 +#endif
18921 +
18922 +RET_ENDP
18923 +BEGIN(dec_return_unchecked)
18924 + movl (v), %eax
18925 + movl 4(v), %edx
18926 + subl $1, %eax
18927 + sbbl $0, %edx
18928 movl %eax, (v)
18929 movl %edx, 4(v)
18930 RET_ENDP
18931 @@ -143,6 +286,13 @@ BEGIN(add_unless)
18932 adcl %edx, %edi
18933 addl (v), %eax
18934 adcl 4(v), %edx
18935 +
18936 +#ifdef CONFIG_PAX_REFCOUNT
18937 + into
18938 +1234:
18939 + _ASM_EXTABLE(1234b, 2f)
18940 +#endif
18941 +
18942 cmpl %eax, %esi
18943 je 3f
18944 1:
18945 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
18946 1:
18947 addl $1, %eax
18948 adcl $0, %edx
18949 +
18950 +#ifdef CONFIG_PAX_REFCOUNT
18951 + into
18952 +1234:
18953 + _ASM_EXTABLE(1234b, 2f)
18954 +#endif
18955 +
18956 movl %eax, (v)
18957 movl %edx, 4(v)
18958 movl $1, %eax
18959 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
18960 movl 4(v), %edx
18961 subl $1, %eax
18962 sbbl $0, %edx
18963 +
18964 +#ifdef CONFIG_PAX_REFCOUNT
18965 + into
18966 +1234:
18967 + _ASM_EXTABLE(1234b, 1f)
18968 +#endif
18969 +
18970 js 1f
18971 movl %eax, (v)
18972 movl %edx, 4(v)
18973 diff -urNp linux-2.6.39/arch/x86/lib/atomic64_cx8_32.S linux-2.6.39/arch/x86/lib/atomic64_cx8_32.S
18974 --- linux-2.6.39/arch/x86/lib/atomic64_cx8_32.S 2011-05-19 00:06:34.000000000 -0400
18975 +++ linux-2.6.39/arch/x86/lib/atomic64_cx8_32.S 2011-05-22 19:36:30.000000000 -0400
18976 @@ -39,6 +39,14 @@ ENTRY(atomic64_read_cx8)
18977 CFI_ENDPROC
18978 ENDPROC(atomic64_read_cx8)
18979
18980 +ENTRY(atomic64_read_unchecked_cx8)
18981 + CFI_STARTPROC
18982 +
18983 + read64 %ecx
18984 + ret
18985 + CFI_ENDPROC
18986 +ENDPROC(atomic64_read_unchecked_cx8)
18987 +
18988 ENTRY(atomic64_set_cx8)
18989 CFI_STARTPROC
18990
18991 @@ -52,6 +60,19 @@ ENTRY(atomic64_set_cx8)
18992 CFI_ENDPROC
18993 ENDPROC(atomic64_set_cx8)
18994
18995 +ENTRY(atomic64_set_unchecked_cx8)
18996 + CFI_STARTPROC
18997 +
18998 +1:
18999 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
19000 + * are atomic on 586 and newer */
19001 + cmpxchg8b (%esi)
19002 + jne 1b
19003 +
19004 + ret
19005 + CFI_ENDPROC
19006 +ENDPROC(atomic64_set_unchecked_cx8)
19007 +
19008 ENTRY(atomic64_xchg_cx8)
19009 CFI_STARTPROC
19010
19011 @@ -66,8 +87,8 @@ ENTRY(atomic64_xchg_cx8)
19012 CFI_ENDPROC
19013 ENDPROC(atomic64_xchg_cx8)
19014
19015 -.macro addsub_return func ins insc
19016 -ENTRY(atomic64_\func\()_return_cx8)
19017 +.macro addsub_return func ins insc unchecked=""
19018 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
19019 CFI_STARTPROC
19020 SAVE ebp
19021 SAVE ebx
19022 @@ -84,27 +105,43 @@ ENTRY(atomic64_\func\()_return_cx8)
19023 movl %edx, %ecx
19024 \ins\()l %esi, %ebx
19025 \insc\()l %edi, %ecx
19026 +
19027 +.ifb \unchecked
19028 +#ifdef CONFIG_PAX_REFCOUNT
19029 + into
19030 +2:
19031 + _ASM_EXTABLE(2b, 3f)
19032 +#endif
19033 +.endif
19034 +
19035 LOCK_PREFIX
19036 cmpxchg8b (%ebp)
19037 jne 1b
19038 -
19039 -10:
19040 movl %ebx, %eax
19041 movl %ecx, %edx
19042 +
19043 +.ifb \unchecked
19044 +#ifdef CONFIG_PAX_REFCOUNT
19045 +3:
19046 +#endif
19047 +.endif
19048 +
19049 RESTORE edi
19050 RESTORE esi
19051 RESTORE ebx
19052 RESTORE ebp
19053 ret
19054 CFI_ENDPROC
19055 -ENDPROC(atomic64_\func\()_return_cx8)
19056 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
19057 .endm
19058
19059 addsub_return add add adc
19060 addsub_return sub sub sbb
19061 +addsub_return add add adc _unchecked
19062 +addsub_return sub sub sbb _unchecked
19063
19064 -.macro incdec_return func ins insc
19065 -ENTRY(atomic64_\func\()_return_cx8)
19066 +.macro incdec_return func ins insc unchecked
19067 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
19068 CFI_STARTPROC
19069 SAVE ebx
19070
19071 @@ -114,21 +151,38 @@ ENTRY(atomic64_\func\()_return_cx8)
19072 movl %edx, %ecx
19073 \ins\()l $1, %ebx
19074 \insc\()l $0, %ecx
19075 +
19076 +.ifb \unchecked
19077 +#ifdef CONFIG_PAX_REFCOUNT
19078 + into
19079 +2:
19080 + _ASM_EXTABLE(2b, 3f)
19081 +#endif
19082 +.endif
19083 +
19084 LOCK_PREFIX
19085 cmpxchg8b (%esi)
19086 jne 1b
19087
19088 -10:
19089 movl %ebx, %eax
19090 movl %ecx, %edx
19091 +
19092 +.ifb \unchecked
19093 +#ifdef CONFIG_PAX_REFCOUNT
19094 +3:
19095 +#endif
19096 +.endif
19097 +
19098 RESTORE ebx
19099 ret
19100 CFI_ENDPROC
19101 -ENDPROC(atomic64_\func\()_return_cx8)
19102 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
19103 .endm
19104
19105 incdec_return inc add adc
19106 incdec_return dec sub sbb
19107 +incdec_return inc add adc _unchecked
19108 +incdec_return dec sub sbb _unchecked
19109
19110 ENTRY(atomic64_dec_if_positive_cx8)
19111 CFI_STARTPROC
19112 @@ -140,6 +194,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
19113 movl %edx, %ecx
19114 subl $1, %ebx
19115 sbb $0, %ecx
19116 +
19117 +#ifdef CONFIG_PAX_REFCOUNT
19118 + into
19119 +1234:
19120 + _ASM_EXTABLE(1234b, 2f)
19121 +#endif
19122 +
19123 js 2f
19124 LOCK_PREFIX
19125 cmpxchg8b (%esi)
19126 @@ -174,6 +235,13 @@ ENTRY(atomic64_add_unless_cx8)
19127 movl %edx, %ecx
19128 addl %esi, %ebx
19129 adcl %edi, %ecx
19130 +
19131 +#ifdef CONFIG_PAX_REFCOUNT
19132 + into
19133 +1234:
19134 + _ASM_EXTABLE(1234b, 3f)
19135 +#endif
19136 +
19137 LOCK_PREFIX
19138 cmpxchg8b (%ebp)
19139 jne 1b
19140 @@ -206,6 +274,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
19141 movl %edx, %ecx
19142 addl $1, %ebx
19143 adcl $0, %ecx
19144 +
19145 +#ifdef CONFIG_PAX_REFCOUNT
19146 + into
19147 +1234:
19148 + _ASM_EXTABLE(1234b, 3f)
19149 +#endif
19150 +
19151 LOCK_PREFIX
19152 cmpxchg8b (%esi)
19153 jne 1b
19154 diff -urNp linux-2.6.39/arch/x86/lib/checksum_32.S linux-2.6.39/arch/x86/lib/checksum_32.S
19155 --- linux-2.6.39/arch/x86/lib/checksum_32.S 2011-05-19 00:06:34.000000000 -0400
19156 +++ linux-2.6.39/arch/x86/lib/checksum_32.S 2011-05-22 19:36:30.000000000 -0400
19157 @@ -28,7 +28,8 @@
19158 #include <linux/linkage.h>
19159 #include <asm/dwarf2.h>
19160 #include <asm/errno.h>
19161 -
19162 +#include <asm/segment.h>
19163 +
19164 /*
19165 * computes a partial checksum, e.g. for TCP/UDP fragments
19166 */
19167 @@ -296,9 +297,24 @@ unsigned int csum_partial_copy_generic (
19168
19169 #define ARGBASE 16
19170 #define FP 12
19171 -
19172 -ENTRY(csum_partial_copy_generic)
19173 +
19174 +ENTRY(csum_partial_copy_generic_to_user)
19175 CFI_STARTPROC
19176 +
19177 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19178 + pushl_cfi %gs
19179 + popl_cfi %es
19180 + jmp csum_partial_copy_generic
19181 +#endif
19182 +
19183 +ENTRY(csum_partial_copy_generic_from_user)
19184 +
19185 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19186 + pushl_cfi %gs
19187 + popl_cfi %ds
19188 +#endif
19189 +
19190 +ENTRY(csum_partial_copy_generic)
19191 subl $4,%esp
19192 CFI_ADJUST_CFA_OFFSET 4
19193 pushl_cfi %edi
19194 @@ -320,7 +336,7 @@ ENTRY(csum_partial_copy_generic)
19195 jmp 4f
19196 SRC(1: movw (%esi), %bx )
19197 addl $2, %esi
19198 -DST( movw %bx, (%edi) )
19199 +DST( movw %bx, %es:(%edi) )
19200 addl $2, %edi
19201 addw %bx, %ax
19202 adcl $0, %eax
19203 @@ -332,30 +348,30 @@ DST( movw %bx, (%edi) )
19204 SRC(1: movl (%esi), %ebx )
19205 SRC( movl 4(%esi), %edx )
19206 adcl %ebx, %eax
19207 -DST( movl %ebx, (%edi) )
19208 +DST( movl %ebx, %es:(%edi) )
19209 adcl %edx, %eax
19210 -DST( movl %edx, 4(%edi) )
19211 +DST( movl %edx, %es:4(%edi) )
19212
19213 SRC( movl 8(%esi), %ebx )
19214 SRC( movl 12(%esi), %edx )
19215 adcl %ebx, %eax
19216 -DST( movl %ebx, 8(%edi) )
19217 +DST( movl %ebx, %es:8(%edi) )
19218 adcl %edx, %eax
19219 -DST( movl %edx, 12(%edi) )
19220 +DST( movl %edx, %es:12(%edi) )
19221
19222 SRC( movl 16(%esi), %ebx )
19223 SRC( movl 20(%esi), %edx )
19224 adcl %ebx, %eax
19225 -DST( movl %ebx, 16(%edi) )
19226 +DST( movl %ebx, %es:16(%edi) )
19227 adcl %edx, %eax
19228 -DST( movl %edx, 20(%edi) )
19229 +DST( movl %edx, %es:20(%edi) )
19230
19231 SRC( movl 24(%esi), %ebx )
19232 SRC( movl 28(%esi), %edx )
19233 adcl %ebx, %eax
19234 -DST( movl %ebx, 24(%edi) )
19235 +DST( movl %ebx, %es:24(%edi) )
19236 adcl %edx, %eax
19237 -DST( movl %edx, 28(%edi) )
19238 +DST( movl %edx, %es:28(%edi) )
19239
19240 lea 32(%esi), %esi
19241 lea 32(%edi), %edi
19242 @@ -369,7 +385,7 @@ DST( movl %edx, 28(%edi) )
19243 shrl $2, %edx # This clears CF
19244 SRC(3: movl (%esi), %ebx )
19245 adcl %ebx, %eax
19246 -DST( movl %ebx, (%edi) )
19247 +DST( movl %ebx, %es:(%edi) )
19248 lea 4(%esi), %esi
19249 lea 4(%edi), %edi
19250 dec %edx
19251 @@ -381,12 +397,12 @@ DST( movl %ebx, (%edi) )
19252 jb 5f
19253 SRC( movw (%esi), %cx )
19254 leal 2(%esi), %esi
19255 -DST( movw %cx, (%edi) )
19256 +DST( movw %cx, %es:(%edi) )
19257 leal 2(%edi), %edi
19258 je 6f
19259 shll $16,%ecx
19260 SRC(5: movb (%esi), %cl )
19261 -DST( movb %cl, (%edi) )
19262 +DST( movb %cl, %es:(%edi) )
19263 6: addl %ecx, %eax
19264 adcl $0, %eax
19265 7:
19266 @@ -397,7 +413,7 @@ DST( movb %cl, (%edi) )
19267
19268 6001:
19269 movl ARGBASE+20(%esp), %ebx # src_err_ptr
19270 - movl $-EFAULT, (%ebx)
19271 + movl $-EFAULT, %ss:(%ebx)
19272
19273 # zero the complete destination - computing the rest
19274 # is too much work
19275 @@ -410,11 +426,15 @@ DST( movb %cl, (%edi) )
19276
19277 6002:
19278 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
19279 - movl $-EFAULT,(%ebx)
19280 + movl $-EFAULT,%ss:(%ebx)
19281 jmp 5000b
19282
19283 .previous
19284
19285 + pushl_cfi %ss
19286 + popl_cfi %ds
19287 + pushl_cfi %ss
19288 + popl_cfi %es
19289 popl_cfi %ebx
19290 CFI_RESTORE ebx
19291 popl_cfi %esi
19292 @@ -424,26 +444,43 @@ DST( movb %cl, (%edi) )
19293 popl_cfi %ecx # equivalent to addl $4,%esp
19294 ret
19295 CFI_ENDPROC
19296 -ENDPROC(csum_partial_copy_generic)
19297 +ENDPROC(csum_partial_copy_generic_to_user)
19298
19299 #else
19300
19301 /* Version for PentiumII/PPro */
19302
19303 #define ROUND1(x) \
19304 + nop; nop; nop; \
19305 SRC(movl x(%esi), %ebx ) ; \
19306 addl %ebx, %eax ; \
19307 - DST(movl %ebx, x(%edi) ) ;
19308 + DST(movl %ebx, %es:x(%edi)) ;
19309
19310 #define ROUND(x) \
19311 + nop; nop; nop; \
19312 SRC(movl x(%esi), %ebx ) ; \
19313 adcl %ebx, %eax ; \
19314 - DST(movl %ebx, x(%edi) ) ;
19315 + DST(movl %ebx, %es:x(%edi)) ;
19316
19317 #define ARGBASE 12
19318 -
19319 -ENTRY(csum_partial_copy_generic)
19320 +
19321 +ENTRY(csum_partial_copy_generic_to_user)
19322 CFI_STARTPROC
19323 +
19324 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19325 + pushl_cfi %gs
19326 + popl_cfi %es
19327 + jmp csum_partial_copy_generic
19328 +#endif
19329 +
19330 +ENTRY(csum_partial_copy_generic_from_user)
19331 +
19332 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19333 + pushl_cfi %gs
19334 + popl_cfi %ds
19335 +#endif
19336 +
19337 +ENTRY(csum_partial_copy_generic)
19338 pushl_cfi %ebx
19339 CFI_REL_OFFSET ebx, 0
19340 pushl_cfi %edi
19341 @@ -464,7 +501,7 @@ ENTRY(csum_partial_copy_generic)
19342 subl %ebx, %edi
19343 lea -1(%esi),%edx
19344 andl $-32,%edx
19345 - lea 3f(%ebx,%ebx), %ebx
19346 + lea 3f(%ebx,%ebx,2), %ebx
19347 testl %esi, %esi
19348 jmp *%ebx
19349 1: addl $64,%esi
19350 @@ -485,19 +522,19 @@ ENTRY(csum_partial_copy_generic)
19351 jb 5f
19352 SRC( movw (%esi), %dx )
19353 leal 2(%esi), %esi
19354 -DST( movw %dx, (%edi) )
19355 +DST( movw %dx, %es:(%edi) )
19356 leal 2(%edi), %edi
19357 je 6f
19358 shll $16,%edx
19359 5:
19360 SRC( movb (%esi), %dl )
19361 -DST( movb %dl, (%edi) )
19362 +DST( movb %dl, %es:(%edi) )
19363 6: addl %edx, %eax
19364 adcl $0, %eax
19365 7:
19366 .section .fixup, "ax"
19367 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
19368 - movl $-EFAULT, (%ebx)
19369 + movl $-EFAULT, %ss:(%ebx)
19370 # zero the complete destination (computing the rest is too much work)
19371 movl ARGBASE+8(%esp),%edi # dst
19372 movl ARGBASE+12(%esp),%ecx # len
19373 @@ -505,10 +542,17 @@ DST( movb %dl, (%edi) )
19374 rep; stosb
19375 jmp 7b
19376 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
19377 - movl $-EFAULT, (%ebx)
19378 + movl $-EFAULT, %ss:(%ebx)
19379 jmp 7b
19380 .previous
19381
19382 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19383 + pushl_cfi %ss
19384 + popl_cfi %ds
19385 + pushl_cfi %ss
19386 + popl_cfi %es
19387 +#endif
19388 +
19389 popl_cfi %esi
19390 CFI_RESTORE esi
19391 popl_cfi %edi
19392 @@ -517,7 +561,7 @@ DST( movb %dl, (%edi) )
19393 CFI_RESTORE ebx
19394 ret
19395 CFI_ENDPROC
19396 -ENDPROC(csum_partial_copy_generic)
19397 +ENDPROC(csum_partial_copy_generic_to_user)
19398
19399 #undef ROUND
19400 #undef ROUND1
19401 diff -urNp linux-2.6.39/arch/x86/lib/clear_page_64.S linux-2.6.39/arch/x86/lib/clear_page_64.S
19402 --- linux-2.6.39/arch/x86/lib/clear_page_64.S 2011-05-19 00:06:34.000000000 -0400
19403 +++ linux-2.6.39/arch/x86/lib/clear_page_64.S 2011-05-22 19:36:30.000000000 -0400
19404 @@ -43,7 +43,7 @@ ENDPROC(clear_page)
19405
19406 #include <asm/cpufeature.h>
19407
19408 - .section .altinstr_replacement,"ax"
19409 + .section .altinstr_replacement,"a"
19410 1: .byte 0xeb /* jmp <disp8> */
19411 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
19412 2:
19413 diff -urNp linux-2.6.39/arch/x86/lib/copy_page_64.S linux-2.6.39/arch/x86/lib/copy_page_64.S
19414 --- linux-2.6.39/arch/x86/lib/copy_page_64.S 2011-05-19 00:06:34.000000000 -0400
19415 +++ linux-2.6.39/arch/x86/lib/copy_page_64.S 2011-05-22 19:36:30.000000000 -0400
19416 @@ -104,7 +104,7 @@ ENDPROC(copy_page)
19417
19418 #include <asm/cpufeature.h>
19419
19420 - .section .altinstr_replacement,"ax"
19421 + .section .altinstr_replacement,"a"
19422 1: .byte 0xeb /* jmp <disp8> */
19423 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
19424 2:
19425 diff -urNp linux-2.6.39/arch/x86/lib/copy_user_64.S linux-2.6.39/arch/x86/lib/copy_user_64.S
19426 --- linux-2.6.39/arch/x86/lib/copy_user_64.S 2011-05-19 00:06:34.000000000 -0400
19427 +++ linux-2.6.39/arch/x86/lib/copy_user_64.S 2011-05-22 19:36:30.000000000 -0400
19428 @@ -15,13 +15,14 @@
19429 #include <asm/asm-offsets.h>
19430 #include <asm/thread_info.h>
19431 #include <asm/cpufeature.h>
19432 +#include <asm/pgtable.h>
19433
19434 .macro ALTERNATIVE_JUMP feature,orig,alt
19435 0:
19436 .byte 0xe9 /* 32bit jump */
19437 .long \orig-1f /* by default jump to orig */
19438 1:
19439 - .section .altinstr_replacement,"ax"
19440 + .section .altinstr_replacement,"a"
19441 2: .byte 0xe9 /* near jump with 32bit immediate */
19442 .long \alt-1b /* offset */ /* or alternatively to alt */
19443 .previous
19444 @@ -64,37 +65,13 @@
19445 #endif
19446 .endm
19447
19448 -/* Standard copy_to_user with segment limit checking */
19449 -ENTRY(_copy_to_user)
19450 - CFI_STARTPROC
19451 - GET_THREAD_INFO(%rax)
19452 - movq %rdi,%rcx
19453 - addq %rdx,%rcx
19454 - jc bad_to_user
19455 - cmpq TI_addr_limit(%rax),%rcx
19456 - jae bad_to_user
19457 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,copy_user_generic_unrolled,copy_user_generic_string
19458 - CFI_ENDPROC
19459 -ENDPROC(_copy_to_user)
19460 -
19461 -/* Standard copy_from_user with segment limit checking */
19462 -ENTRY(_copy_from_user)
19463 - CFI_STARTPROC
19464 - GET_THREAD_INFO(%rax)
19465 - movq %rsi,%rcx
19466 - addq %rdx,%rcx
19467 - jc bad_from_user
19468 - cmpq TI_addr_limit(%rax),%rcx
19469 - jae bad_from_user
19470 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,copy_user_generic_unrolled,copy_user_generic_string
19471 - CFI_ENDPROC
19472 -ENDPROC(_copy_from_user)
19473 -
19474 .section .fixup,"ax"
19475 /* must zero dest */
19476 ENTRY(bad_from_user)
19477 bad_from_user:
19478 CFI_STARTPROC
19479 + testl %edx,%edx
19480 + js bad_to_user
19481 movl %edx,%ecx
19482 xorl %eax,%eax
19483 rep
19484 diff -urNp linux-2.6.39/arch/x86/lib/copy_user_nocache_64.S linux-2.6.39/arch/x86/lib/copy_user_nocache_64.S
19485 --- linux-2.6.39/arch/x86/lib/copy_user_nocache_64.S 2011-05-19 00:06:34.000000000 -0400
19486 +++ linux-2.6.39/arch/x86/lib/copy_user_nocache_64.S 2011-05-22 19:36:30.000000000 -0400
19487 @@ -14,6 +14,7 @@
19488 #include <asm/current.h>
19489 #include <asm/asm-offsets.h>
19490 #include <asm/thread_info.h>
19491 +#include <asm/pgtable.h>
19492
19493 .macro ALIGN_DESTINATION
19494 #ifdef FIX_ALIGNMENT
19495 @@ -50,6 +51,15 @@
19496 */
19497 ENTRY(__copy_user_nocache)
19498 CFI_STARTPROC
19499 +
19500 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19501 + mov $PAX_USER_SHADOW_BASE,%rcx
19502 + cmp %rcx,%rsi
19503 + jae 1f
19504 + add %rcx,%rsi
19505 +1:
19506 +#endif
19507 +
19508 cmpl $8,%edx
19509 jb 20f /* less then 8 bytes, go to byte copy loop */
19510 ALIGN_DESTINATION
19511 diff -urNp linux-2.6.39/arch/x86/lib/csum-wrappers_64.c linux-2.6.39/arch/x86/lib/csum-wrappers_64.c
19512 --- linux-2.6.39/arch/x86/lib/csum-wrappers_64.c 2011-05-19 00:06:34.000000000 -0400
19513 +++ linux-2.6.39/arch/x86/lib/csum-wrappers_64.c 2011-05-22 19:36:30.000000000 -0400
19514 @@ -52,6 +52,12 @@ csum_partial_copy_from_user(const void _
19515 len -= 2;
19516 }
19517 }
19518 +
19519 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19520 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
19521 + src += PAX_USER_SHADOW_BASE;
19522 +#endif
19523 +
19524 isum = csum_partial_copy_generic((__force const void *)src,
19525 dst, len, isum, errp, NULL);
19526 if (unlikely(*errp))
19527 @@ -105,6 +111,12 @@ csum_partial_copy_to_user(const void *sr
19528 }
19529
19530 *errp = 0;
19531 +
19532 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19533 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
19534 + dst += PAX_USER_SHADOW_BASE;
19535 +#endif
19536 +
19537 return csum_partial_copy_generic(src, (void __force *)dst,
19538 len, isum, NULL, errp);
19539 }
19540 diff -urNp linux-2.6.39/arch/x86/lib/getuser.S linux-2.6.39/arch/x86/lib/getuser.S
19541 --- linux-2.6.39/arch/x86/lib/getuser.S 2011-05-19 00:06:34.000000000 -0400
19542 +++ linux-2.6.39/arch/x86/lib/getuser.S 2011-05-22 19:36:30.000000000 -0400
19543 @@ -33,14 +33,35 @@
19544 #include <asm/asm-offsets.h>
19545 #include <asm/thread_info.h>
19546 #include <asm/asm.h>
19547 +#include <asm/segment.h>
19548 +#include <asm/pgtable.h>
19549 +
19550 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19551 +#define __copyuser_seg gs;
19552 +#else
19553 +#define __copyuser_seg
19554 +#endif
19555
19556 .text
19557 ENTRY(__get_user_1)
19558 CFI_STARTPROC
19559 +
19560 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
19561 GET_THREAD_INFO(%_ASM_DX)
19562 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
19563 jae bad_get_user
19564 -1: movzb (%_ASM_AX),%edx
19565 +
19566 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19567 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
19568 + cmp %_ASM_DX,%_ASM_AX
19569 + jae 1234f
19570 + add %_ASM_DX,%_ASM_AX
19571 +1234:
19572 +#endif
19573 +
19574 +#endif
19575 +
19576 +1: __copyuser_seg movzb (%_ASM_AX),%edx
19577 xor %eax,%eax
19578 ret
19579 CFI_ENDPROC
19580 @@ -49,11 +70,24 @@ ENDPROC(__get_user_1)
19581 ENTRY(__get_user_2)
19582 CFI_STARTPROC
19583 add $1,%_ASM_AX
19584 +
19585 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
19586 jc bad_get_user
19587 GET_THREAD_INFO(%_ASM_DX)
19588 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
19589 jae bad_get_user
19590 -2: movzwl -1(%_ASM_AX),%edx
19591 +
19592 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19593 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
19594 + cmp %_ASM_DX,%_ASM_AX
19595 + jae 1234f
19596 + add %_ASM_DX,%_ASM_AX
19597 +1234:
19598 +#endif
19599 +
19600 +#endif
19601 +
19602 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
19603 xor %eax,%eax
19604 ret
19605 CFI_ENDPROC
19606 @@ -62,11 +96,24 @@ ENDPROC(__get_user_2)
19607 ENTRY(__get_user_4)
19608 CFI_STARTPROC
19609 add $3,%_ASM_AX
19610 +
19611 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
19612 jc bad_get_user
19613 GET_THREAD_INFO(%_ASM_DX)
19614 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
19615 jae bad_get_user
19616 -3: mov -3(%_ASM_AX),%edx
19617 +
19618 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19619 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
19620 + cmp %_ASM_DX,%_ASM_AX
19621 + jae 1234f
19622 + add %_ASM_DX,%_ASM_AX
19623 +1234:
19624 +#endif
19625 +
19626 +#endif
19627 +
19628 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
19629 xor %eax,%eax
19630 ret
19631 CFI_ENDPROC
19632 @@ -80,6 +127,15 @@ ENTRY(__get_user_8)
19633 GET_THREAD_INFO(%_ASM_DX)
19634 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
19635 jae bad_get_user
19636 +
19637 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19638 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
19639 + cmp %_ASM_DX,%_ASM_AX
19640 + jae 1234f
19641 + add %_ASM_DX,%_ASM_AX
19642 +1234:
19643 +#endif
19644 +
19645 4: movq -7(%_ASM_AX),%_ASM_DX
19646 xor %eax,%eax
19647 ret
19648 diff -urNp linux-2.6.39/arch/x86/lib/insn.c linux-2.6.39/arch/x86/lib/insn.c
19649 --- linux-2.6.39/arch/x86/lib/insn.c 2011-05-19 00:06:34.000000000 -0400
19650 +++ linux-2.6.39/arch/x86/lib/insn.c 2011-05-22 19:36:30.000000000 -0400
19651 @@ -21,6 +21,11 @@
19652 #include <linux/string.h>
19653 #include <asm/inat.h>
19654 #include <asm/insn.h>
19655 +#ifdef __KERNEL__
19656 +#include <asm/pgtable_types.h>
19657 +#else
19658 +#define ktla_ktva(addr) addr
19659 +#endif
19660
19661 #define get_next(t, insn) \
19662 ({t r; r = *(t*)insn->next_byte; insn->next_byte += sizeof(t); r; })
19663 @@ -40,8 +45,8 @@
19664 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
19665 {
19666 memset(insn, 0, sizeof(*insn));
19667 - insn->kaddr = kaddr;
19668 - insn->next_byte = kaddr;
19669 + insn->kaddr = ktla_ktva(kaddr);
19670 + insn->next_byte = ktla_ktva(kaddr);
19671 insn->x86_64 = x86_64 ? 1 : 0;
19672 insn->opnd_bytes = 4;
19673 if (x86_64)
19674 diff -urNp linux-2.6.39/arch/x86/lib/mmx_32.c linux-2.6.39/arch/x86/lib/mmx_32.c
19675 --- linux-2.6.39/arch/x86/lib/mmx_32.c 2011-05-19 00:06:34.000000000 -0400
19676 +++ linux-2.6.39/arch/x86/lib/mmx_32.c 2011-05-22 19:36:30.000000000 -0400
19677 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *
19678 {
19679 void *p;
19680 int i;
19681 + unsigned long cr0;
19682
19683 if (unlikely(in_interrupt()))
19684 return __memcpy(to, from, len);
19685 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *
19686 kernel_fpu_begin();
19687
19688 __asm__ __volatile__ (
19689 - "1: prefetch (%0)\n" /* This set is 28 bytes */
19690 - " prefetch 64(%0)\n"
19691 - " prefetch 128(%0)\n"
19692 - " prefetch 192(%0)\n"
19693 - " prefetch 256(%0)\n"
19694 + "1: prefetch (%1)\n" /* This set is 28 bytes */
19695 + " prefetch 64(%1)\n"
19696 + " prefetch 128(%1)\n"
19697 + " prefetch 192(%1)\n"
19698 + " prefetch 256(%1)\n"
19699 "2: \n"
19700 ".section .fixup, \"ax\"\n"
19701 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
19702 + "3: \n"
19703 +
19704 +#ifdef CONFIG_PAX_KERNEXEC
19705 + " movl %%cr0, %0\n"
19706 + " movl %0, %%eax\n"
19707 + " andl $0xFFFEFFFF, %%eax\n"
19708 + " movl %%eax, %%cr0\n"
19709 +#endif
19710 +
19711 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
19712 +
19713 +#ifdef CONFIG_PAX_KERNEXEC
19714 + " movl %0, %%cr0\n"
19715 +#endif
19716 +
19717 " jmp 2b\n"
19718 ".previous\n"
19719 _ASM_EXTABLE(1b, 3b)
19720 - : : "r" (from));
19721 + : "=&r" (cr0) : "r" (from) : "ax");
19722
19723 for ( ; i > 5; i--) {
19724 __asm__ __volatile__ (
19725 - "1: prefetch 320(%0)\n"
19726 - "2: movq (%0), %%mm0\n"
19727 - " movq 8(%0), %%mm1\n"
19728 - " movq 16(%0), %%mm2\n"
19729 - " movq 24(%0), %%mm3\n"
19730 - " movq %%mm0, (%1)\n"
19731 - " movq %%mm1, 8(%1)\n"
19732 - " movq %%mm2, 16(%1)\n"
19733 - " movq %%mm3, 24(%1)\n"
19734 - " movq 32(%0), %%mm0\n"
19735 - " movq 40(%0), %%mm1\n"
19736 - " movq 48(%0), %%mm2\n"
19737 - " movq 56(%0), %%mm3\n"
19738 - " movq %%mm0, 32(%1)\n"
19739 - " movq %%mm1, 40(%1)\n"
19740 - " movq %%mm2, 48(%1)\n"
19741 - " movq %%mm3, 56(%1)\n"
19742 + "1: prefetch 320(%1)\n"
19743 + "2: movq (%1), %%mm0\n"
19744 + " movq 8(%1), %%mm1\n"
19745 + " movq 16(%1), %%mm2\n"
19746 + " movq 24(%1), %%mm3\n"
19747 + " movq %%mm0, (%2)\n"
19748 + " movq %%mm1, 8(%2)\n"
19749 + " movq %%mm2, 16(%2)\n"
19750 + " movq %%mm3, 24(%2)\n"
19751 + " movq 32(%1), %%mm0\n"
19752 + " movq 40(%1), %%mm1\n"
19753 + " movq 48(%1), %%mm2\n"
19754 + " movq 56(%1), %%mm3\n"
19755 + " movq %%mm0, 32(%2)\n"
19756 + " movq %%mm1, 40(%2)\n"
19757 + " movq %%mm2, 48(%2)\n"
19758 + " movq %%mm3, 56(%2)\n"
19759 ".section .fixup, \"ax\"\n"
19760 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
19761 + "3:\n"
19762 +
19763 +#ifdef CONFIG_PAX_KERNEXEC
19764 + " movl %%cr0, %0\n"
19765 + " movl %0, %%eax\n"
19766 + " andl $0xFFFEFFFF, %%eax\n"
19767 + " movl %%eax, %%cr0\n"
19768 +#endif
19769 +
19770 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
19771 +
19772 +#ifdef CONFIG_PAX_KERNEXEC
19773 + " movl %0, %%cr0\n"
19774 +#endif
19775 +
19776 " jmp 2b\n"
19777 ".previous\n"
19778 _ASM_EXTABLE(1b, 3b)
19779 - : : "r" (from), "r" (to) : "memory");
19780 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
19781
19782 from += 64;
19783 to += 64;
19784 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
19785 static void fast_copy_page(void *to, void *from)
19786 {
19787 int i;
19788 + unsigned long cr0;
19789
19790 kernel_fpu_begin();
19791
19792 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, voi
19793 * but that is for later. -AV
19794 */
19795 __asm__ __volatile__(
19796 - "1: prefetch (%0)\n"
19797 - " prefetch 64(%0)\n"
19798 - " prefetch 128(%0)\n"
19799 - " prefetch 192(%0)\n"
19800 - " prefetch 256(%0)\n"
19801 + "1: prefetch (%1)\n"
19802 + " prefetch 64(%1)\n"
19803 + " prefetch 128(%1)\n"
19804 + " prefetch 192(%1)\n"
19805 + " prefetch 256(%1)\n"
19806 "2: \n"
19807 ".section .fixup, \"ax\"\n"
19808 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
19809 + "3: \n"
19810 +
19811 +#ifdef CONFIG_PAX_KERNEXEC
19812 + " movl %%cr0, %0\n"
19813 + " movl %0, %%eax\n"
19814 + " andl $0xFFFEFFFF, %%eax\n"
19815 + " movl %%eax, %%cr0\n"
19816 +#endif
19817 +
19818 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
19819 +
19820 +#ifdef CONFIG_PAX_KERNEXEC
19821 + " movl %0, %%cr0\n"
19822 +#endif
19823 +
19824 " jmp 2b\n"
19825 ".previous\n"
19826 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
19827 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
19828
19829 for (i = 0; i < (4096-320)/64; i++) {
19830 __asm__ __volatile__ (
19831 - "1: prefetch 320(%0)\n"
19832 - "2: movq (%0), %%mm0\n"
19833 - " movntq %%mm0, (%1)\n"
19834 - " movq 8(%0), %%mm1\n"
19835 - " movntq %%mm1, 8(%1)\n"
19836 - " movq 16(%0), %%mm2\n"
19837 - " movntq %%mm2, 16(%1)\n"
19838 - " movq 24(%0), %%mm3\n"
19839 - " movntq %%mm3, 24(%1)\n"
19840 - " movq 32(%0), %%mm4\n"
19841 - " movntq %%mm4, 32(%1)\n"
19842 - " movq 40(%0), %%mm5\n"
19843 - " movntq %%mm5, 40(%1)\n"
19844 - " movq 48(%0), %%mm6\n"
19845 - " movntq %%mm6, 48(%1)\n"
19846 - " movq 56(%0), %%mm7\n"
19847 - " movntq %%mm7, 56(%1)\n"
19848 + "1: prefetch 320(%1)\n"
19849 + "2: movq (%1), %%mm0\n"
19850 + " movntq %%mm0, (%2)\n"
19851 + " movq 8(%1), %%mm1\n"
19852 + " movntq %%mm1, 8(%2)\n"
19853 + " movq 16(%1), %%mm2\n"
19854 + " movntq %%mm2, 16(%2)\n"
19855 + " movq 24(%1), %%mm3\n"
19856 + " movntq %%mm3, 24(%2)\n"
19857 + " movq 32(%1), %%mm4\n"
19858 + " movntq %%mm4, 32(%2)\n"
19859 + " movq 40(%1), %%mm5\n"
19860 + " movntq %%mm5, 40(%2)\n"
19861 + " movq 48(%1), %%mm6\n"
19862 + " movntq %%mm6, 48(%2)\n"
19863 + " movq 56(%1), %%mm7\n"
19864 + " movntq %%mm7, 56(%2)\n"
19865 ".section .fixup, \"ax\"\n"
19866 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
19867 + "3:\n"
19868 +
19869 +#ifdef CONFIG_PAX_KERNEXEC
19870 + " movl %%cr0, %0\n"
19871 + " movl %0, %%eax\n"
19872 + " andl $0xFFFEFFFF, %%eax\n"
19873 + " movl %%eax, %%cr0\n"
19874 +#endif
19875 +
19876 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
19877 +
19878 +#ifdef CONFIG_PAX_KERNEXEC
19879 + " movl %0, %%cr0\n"
19880 +#endif
19881 +
19882 " jmp 2b\n"
19883 ".previous\n"
19884 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
19885 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
19886
19887 from += 64;
19888 to += 64;
19889 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
19890 static void fast_copy_page(void *to, void *from)
19891 {
19892 int i;
19893 + unsigned long cr0;
19894
19895 kernel_fpu_begin();
19896
19897 __asm__ __volatile__ (
19898 - "1: prefetch (%0)\n"
19899 - " prefetch 64(%0)\n"
19900 - " prefetch 128(%0)\n"
19901 - " prefetch 192(%0)\n"
19902 - " prefetch 256(%0)\n"
19903 + "1: prefetch (%1)\n"
19904 + " prefetch 64(%1)\n"
19905 + " prefetch 128(%1)\n"
19906 + " prefetch 192(%1)\n"
19907 + " prefetch 256(%1)\n"
19908 "2: \n"
19909 ".section .fixup, \"ax\"\n"
19910 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
19911 + "3: \n"
19912 +
19913 +#ifdef CONFIG_PAX_KERNEXEC
19914 + " movl %%cr0, %0\n"
19915 + " movl %0, %%eax\n"
19916 + " andl $0xFFFEFFFF, %%eax\n"
19917 + " movl %%eax, %%cr0\n"
19918 +#endif
19919 +
19920 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
19921 +
19922 +#ifdef CONFIG_PAX_KERNEXEC
19923 + " movl %0, %%cr0\n"
19924 +#endif
19925 +
19926 " jmp 2b\n"
19927 ".previous\n"
19928 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
19929 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
19930
19931 for (i = 0; i < 4096/64; i++) {
19932 __asm__ __volatile__ (
19933 - "1: prefetch 320(%0)\n"
19934 - "2: movq (%0), %%mm0\n"
19935 - " movq 8(%0), %%mm1\n"
19936 - " movq 16(%0), %%mm2\n"
19937 - " movq 24(%0), %%mm3\n"
19938 - " movq %%mm0, (%1)\n"
19939 - " movq %%mm1, 8(%1)\n"
19940 - " movq %%mm2, 16(%1)\n"
19941 - " movq %%mm3, 24(%1)\n"
19942 - " movq 32(%0), %%mm0\n"
19943 - " movq 40(%0), %%mm1\n"
19944 - " movq 48(%0), %%mm2\n"
19945 - " movq 56(%0), %%mm3\n"
19946 - " movq %%mm0, 32(%1)\n"
19947 - " movq %%mm1, 40(%1)\n"
19948 - " movq %%mm2, 48(%1)\n"
19949 - " movq %%mm3, 56(%1)\n"
19950 + "1: prefetch 320(%1)\n"
19951 + "2: movq (%1), %%mm0\n"
19952 + " movq 8(%1), %%mm1\n"
19953 + " movq 16(%1), %%mm2\n"
19954 + " movq 24(%1), %%mm3\n"
19955 + " movq %%mm0, (%2)\n"
19956 + " movq %%mm1, 8(%2)\n"
19957 + " movq %%mm2, 16(%2)\n"
19958 + " movq %%mm3, 24(%2)\n"
19959 + " movq 32(%1), %%mm0\n"
19960 + " movq 40(%1), %%mm1\n"
19961 + " movq 48(%1), %%mm2\n"
19962 + " movq 56(%1), %%mm3\n"
19963 + " movq %%mm0, 32(%2)\n"
19964 + " movq %%mm1, 40(%2)\n"
19965 + " movq %%mm2, 48(%2)\n"
19966 + " movq %%mm3, 56(%2)\n"
19967 ".section .fixup, \"ax\"\n"
19968 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
19969 + "3:\n"
19970 +
19971 +#ifdef CONFIG_PAX_KERNEXEC
19972 + " movl %%cr0, %0\n"
19973 + " movl %0, %%eax\n"
19974 + " andl $0xFFFEFFFF, %%eax\n"
19975 + " movl %%eax, %%cr0\n"
19976 +#endif
19977 +
19978 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
19979 +
19980 +#ifdef CONFIG_PAX_KERNEXEC
19981 + " movl %0, %%cr0\n"
19982 +#endif
19983 +
19984 " jmp 2b\n"
19985 ".previous\n"
19986 _ASM_EXTABLE(1b, 3b)
19987 - : : "r" (from), "r" (to) : "memory");
19988 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
19989
19990 from += 64;
19991 to += 64;
19992 diff -urNp linux-2.6.39/arch/x86/lib/putuser.S linux-2.6.39/arch/x86/lib/putuser.S
19993 --- linux-2.6.39/arch/x86/lib/putuser.S 2011-05-19 00:06:34.000000000 -0400
19994 +++ linux-2.6.39/arch/x86/lib/putuser.S 2011-05-22 19:36:30.000000000 -0400
19995 @@ -15,7 +15,8 @@
19996 #include <asm/thread_info.h>
19997 #include <asm/errno.h>
19998 #include <asm/asm.h>
19999 -
20000 +#include <asm/segment.h>
20001 +#include <asm/pgtable.h>
20002
20003 /*
20004 * __put_user_X
20005 @@ -29,52 +30,119 @@
20006 * as they get called from within inline assembly.
20007 */
20008
20009 -#define ENTER CFI_STARTPROC ; \
20010 - GET_THREAD_INFO(%_ASM_BX)
20011 +#define ENTER CFI_STARTPROC
20012 #define EXIT ret ; \
20013 CFI_ENDPROC
20014
20015 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20016 +#define _DEST %_ASM_CX,%_ASM_BX
20017 +#else
20018 +#define _DEST %_ASM_CX
20019 +#endif
20020 +
20021 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20022 +#define __copyuser_seg gs;
20023 +#else
20024 +#define __copyuser_seg
20025 +#endif
20026 +
20027 .text
20028 ENTRY(__put_user_1)
20029 ENTER
20030 +
20031 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
20032 + GET_THREAD_INFO(%_ASM_BX)
20033 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
20034 jae bad_put_user
20035 -1: movb %al,(%_ASM_CX)
20036 +
20037 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20038 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
20039 + cmp %_ASM_BX,%_ASM_CX
20040 + jb 1234f
20041 + xor %ebx,%ebx
20042 +1234:
20043 +#endif
20044 +
20045 +#endif
20046 +
20047 +1: __copyuser_seg movb %al,(_DEST)
20048 xor %eax,%eax
20049 EXIT
20050 ENDPROC(__put_user_1)
20051
20052 ENTRY(__put_user_2)
20053 ENTER
20054 +
20055 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
20056 + GET_THREAD_INFO(%_ASM_BX)
20057 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
20058 sub $1,%_ASM_BX
20059 cmp %_ASM_BX,%_ASM_CX
20060 jae bad_put_user
20061 -2: movw %ax,(%_ASM_CX)
20062 +
20063 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20064 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
20065 + cmp %_ASM_BX,%_ASM_CX
20066 + jb 1234f
20067 + xor %ebx,%ebx
20068 +1234:
20069 +#endif
20070 +
20071 +#endif
20072 +
20073 +2: __copyuser_seg movw %ax,(_DEST)
20074 xor %eax,%eax
20075 EXIT
20076 ENDPROC(__put_user_2)
20077
20078 ENTRY(__put_user_4)
20079 ENTER
20080 +
20081 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
20082 + GET_THREAD_INFO(%_ASM_BX)
20083 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
20084 sub $3,%_ASM_BX
20085 cmp %_ASM_BX,%_ASM_CX
20086 jae bad_put_user
20087 -3: movl %eax,(%_ASM_CX)
20088 +
20089 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20090 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
20091 + cmp %_ASM_BX,%_ASM_CX
20092 + jb 1234f
20093 + xor %ebx,%ebx
20094 +1234:
20095 +#endif
20096 +
20097 +#endif
20098 +
20099 +3: __copyuser_seg movl %eax,(_DEST)
20100 xor %eax,%eax
20101 EXIT
20102 ENDPROC(__put_user_4)
20103
20104 ENTRY(__put_user_8)
20105 ENTER
20106 +
20107 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
20108 + GET_THREAD_INFO(%_ASM_BX)
20109 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
20110 sub $7,%_ASM_BX
20111 cmp %_ASM_BX,%_ASM_CX
20112 jae bad_put_user
20113 -4: mov %_ASM_AX,(%_ASM_CX)
20114 +
20115 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20116 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
20117 + cmp %_ASM_BX,%_ASM_CX
20118 + jb 1234f
20119 + xor %ebx,%ebx
20120 +1234:
20121 +#endif
20122 +
20123 +#endif
20124 +
20125 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
20126 #ifdef CONFIG_X86_32
20127 -5: movl %edx,4(%_ASM_CX)
20128 +5: __copyuser_seg movl %edx,4(_DEST)
20129 #endif
20130 xor %eax,%eax
20131 EXIT
20132 diff -urNp linux-2.6.39/arch/x86/lib/usercopy_32.c linux-2.6.39/arch/x86/lib/usercopy_32.c
20133 --- linux-2.6.39/arch/x86/lib/usercopy_32.c 2011-05-19 00:06:34.000000000 -0400
20134 +++ linux-2.6.39/arch/x86/lib/usercopy_32.c 2011-05-22 19:36:30.000000000 -0400
20135 @@ -43,7 +43,7 @@ do { \
20136 __asm__ __volatile__( \
20137 " testl %1,%1\n" \
20138 " jz 2f\n" \
20139 - "0: lodsb\n" \
20140 + "0: "__copyuser_seg"lodsb\n" \
20141 " stosb\n" \
20142 " testb %%al,%%al\n" \
20143 " jz 1f\n" \
20144 @@ -128,10 +128,12 @@ do { \
20145 int __d0; \
20146 might_fault(); \
20147 __asm__ __volatile__( \
20148 + __COPYUSER_SET_ES \
20149 "0: rep; stosl\n" \
20150 " movl %2,%0\n" \
20151 "1: rep; stosb\n" \
20152 "2:\n" \
20153 + __COPYUSER_RESTORE_ES \
20154 ".section .fixup,\"ax\"\n" \
20155 "3: lea 0(%2,%0,4),%0\n" \
20156 " jmp 2b\n" \
20157 @@ -200,6 +202,7 @@ long strnlen_user(const char __user *s,
20158 might_fault();
20159
20160 __asm__ __volatile__(
20161 + __COPYUSER_SET_ES
20162 " testl %0, %0\n"
20163 " jz 3f\n"
20164 " andl %0,%%ecx\n"
20165 @@ -208,6 +211,7 @@ long strnlen_user(const char __user *s,
20166 " subl %%ecx,%0\n"
20167 " addl %0,%%eax\n"
20168 "1:\n"
20169 + __COPYUSER_RESTORE_ES
20170 ".section .fixup,\"ax\"\n"
20171 "2: xorl %%eax,%%eax\n"
20172 " jmp 1b\n"
20173 @@ -227,7 +231,7 @@ EXPORT_SYMBOL(strnlen_user);
20174
20175 #ifdef CONFIG_X86_INTEL_USERCOPY
20176 static unsigned long
20177 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
20178 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
20179 {
20180 int d0, d1;
20181 __asm__ __volatile__(
20182 @@ -239,36 +243,36 @@ __copy_user_intel(void __user *to, const
20183 " .align 2,0x90\n"
20184 "3: movl 0(%4), %%eax\n"
20185 "4: movl 4(%4), %%edx\n"
20186 - "5: movl %%eax, 0(%3)\n"
20187 - "6: movl %%edx, 4(%3)\n"
20188 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
20189 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
20190 "7: movl 8(%4), %%eax\n"
20191 "8: movl 12(%4),%%edx\n"
20192 - "9: movl %%eax, 8(%3)\n"
20193 - "10: movl %%edx, 12(%3)\n"
20194 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
20195 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
20196 "11: movl 16(%4), %%eax\n"
20197 "12: movl 20(%4), %%edx\n"
20198 - "13: movl %%eax, 16(%3)\n"
20199 - "14: movl %%edx, 20(%3)\n"
20200 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
20201 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
20202 "15: movl 24(%4), %%eax\n"
20203 "16: movl 28(%4), %%edx\n"
20204 - "17: movl %%eax, 24(%3)\n"
20205 - "18: movl %%edx, 28(%3)\n"
20206 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
20207 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
20208 "19: movl 32(%4), %%eax\n"
20209 "20: movl 36(%4), %%edx\n"
20210 - "21: movl %%eax, 32(%3)\n"
20211 - "22: movl %%edx, 36(%3)\n"
20212 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
20213 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
20214 "23: movl 40(%4), %%eax\n"
20215 "24: movl 44(%4), %%edx\n"
20216 - "25: movl %%eax, 40(%3)\n"
20217 - "26: movl %%edx, 44(%3)\n"
20218 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
20219 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
20220 "27: movl 48(%4), %%eax\n"
20221 "28: movl 52(%4), %%edx\n"
20222 - "29: movl %%eax, 48(%3)\n"
20223 - "30: movl %%edx, 52(%3)\n"
20224 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
20225 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
20226 "31: movl 56(%4), %%eax\n"
20227 "32: movl 60(%4), %%edx\n"
20228 - "33: movl %%eax, 56(%3)\n"
20229 - "34: movl %%edx, 60(%3)\n"
20230 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
20231 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
20232 " addl $-64, %0\n"
20233 " addl $64, %4\n"
20234 " addl $64, %3\n"
20235 @@ -278,10 +282,119 @@ __copy_user_intel(void __user *to, const
20236 " shrl $2, %0\n"
20237 " andl $3, %%eax\n"
20238 " cld\n"
20239 + __COPYUSER_SET_ES
20240 "99: rep; movsl\n"
20241 "36: movl %%eax, %0\n"
20242 "37: rep; movsb\n"
20243 "100:\n"
20244 + __COPYUSER_RESTORE_ES
20245 + ".section .fixup,\"ax\"\n"
20246 + "101: lea 0(%%eax,%0,4),%0\n"
20247 + " jmp 100b\n"
20248 + ".previous\n"
20249 + ".section __ex_table,\"a\"\n"
20250 + " .align 4\n"
20251 + " .long 1b,100b\n"
20252 + " .long 2b,100b\n"
20253 + " .long 3b,100b\n"
20254 + " .long 4b,100b\n"
20255 + " .long 5b,100b\n"
20256 + " .long 6b,100b\n"
20257 + " .long 7b,100b\n"
20258 + " .long 8b,100b\n"
20259 + " .long 9b,100b\n"
20260 + " .long 10b,100b\n"
20261 + " .long 11b,100b\n"
20262 + " .long 12b,100b\n"
20263 + " .long 13b,100b\n"
20264 + " .long 14b,100b\n"
20265 + " .long 15b,100b\n"
20266 + " .long 16b,100b\n"
20267 + " .long 17b,100b\n"
20268 + " .long 18b,100b\n"
20269 + " .long 19b,100b\n"
20270 + " .long 20b,100b\n"
20271 + " .long 21b,100b\n"
20272 + " .long 22b,100b\n"
20273 + " .long 23b,100b\n"
20274 + " .long 24b,100b\n"
20275 + " .long 25b,100b\n"
20276 + " .long 26b,100b\n"
20277 + " .long 27b,100b\n"
20278 + " .long 28b,100b\n"
20279 + " .long 29b,100b\n"
20280 + " .long 30b,100b\n"
20281 + " .long 31b,100b\n"
20282 + " .long 32b,100b\n"
20283 + " .long 33b,100b\n"
20284 + " .long 34b,100b\n"
20285 + " .long 35b,100b\n"
20286 + " .long 36b,100b\n"
20287 + " .long 37b,100b\n"
20288 + " .long 99b,101b\n"
20289 + ".previous"
20290 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
20291 + : "1"(to), "2"(from), "0"(size)
20292 + : "eax", "edx", "memory");
20293 + return size;
20294 +}
20295 +
20296 +static unsigned long
20297 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
20298 +{
20299 + int d0, d1;
20300 + __asm__ __volatile__(
20301 + " .align 2,0x90\n"
20302 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
20303 + " cmpl $67, %0\n"
20304 + " jbe 3f\n"
20305 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
20306 + " .align 2,0x90\n"
20307 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
20308 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
20309 + "5: movl %%eax, 0(%3)\n"
20310 + "6: movl %%edx, 4(%3)\n"
20311 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
20312 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
20313 + "9: movl %%eax, 8(%3)\n"
20314 + "10: movl %%edx, 12(%3)\n"
20315 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
20316 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
20317 + "13: movl %%eax, 16(%3)\n"
20318 + "14: movl %%edx, 20(%3)\n"
20319 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
20320 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
20321 + "17: movl %%eax, 24(%3)\n"
20322 + "18: movl %%edx, 28(%3)\n"
20323 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
20324 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
20325 + "21: movl %%eax, 32(%3)\n"
20326 + "22: movl %%edx, 36(%3)\n"
20327 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
20328 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
20329 + "25: movl %%eax, 40(%3)\n"
20330 + "26: movl %%edx, 44(%3)\n"
20331 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
20332 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
20333 + "29: movl %%eax, 48(%3)\n"
20334 + "30: movl %%edx, 52(%3)\n"
20335 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
20336 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
20337 + "33: movl %%eax, 56(%3)\n"
20338 + "34: movl %%edx, 60(%3)\n"
20339 + " addl $-64, %0\n"
20340 + " addl $64, %4\n"
20341 + " addl $64, %3\n"
20342 + " cmpl $63, %0\n"
20343 + " ja 1b\n"
20344 + "35: movl %0, %%eax\n"
20345 + " shrl $2, %0\n"
20346 + " andl $3, %%eax\n"
20347 + " cld\n"
20348 + "99: rep; "__copyuser_seg" movsl\n"
20349 + "36: movl %%eax, %0\n"
20350 + "37: rep; "__copyuser_seg" movsb\n"
20351 + "100:\n"
20352 ".section .fixup,\"ax\"\n"
20353 "101: lea 0(%%eax,%0,4),%0\n"
20354 " jmp 100b\n"
20355 @@ -339,41 +452,41 @@ __copy_user_zeroing_intel(void *to, cons
20356 int d0, d1;
20357 __asm__ __volatile__(
20358 " .align 2,0x90\n"
20359 - "0: movl 32(%4), %%eax\n"
20360 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
20361 " cmpl $67, %0\n"
20362 " jbe 2f\n"
20363 - "1: movl 64(%4), %%eax\n"
20364 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
20365 " .align 2,0x90\n"
20366 - "2: movl 0(%4), %%eax\n"
20367 - "21: movl 4(%4), %%edx\n"
20368 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
20369 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
20370 " movl %%eax, 0(%3)\n"
20371 " movl %%edx, 4(%3)\n"
20372 - "3: movl 8(%4), %%eax\n"
20373 - "31: movl 12(%4),%%edx\n"
20374 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
20375 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
20376 " movl %%eax, 8(%3)\n"
20377 " movl %%edx, 12(%3)\n"
20378 - "4: movl 16(%4), %%eax\n"
20379 - "41: movl 20(%4), %%edx\n"
20380 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
20381 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
20382 " movl %%eax, 16(%3)\n"
20383 " movl %%edx, 20(%3)\n"
20384 - "10: movl 24(%4), %%eax\n"
20385 - "51: movl 28(%4), %%edx\n"
20386 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
20387 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
20388 " movl %%eax, 24(%3)\n"
20389 " movl %%edx, 28(%3)\n"
20390 - "11: movl 32(%4), %%eax\n"
20391 - "61: movl 36(%4), %%edx\n"
20392 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
20393 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
20394 " movl %%eax, 32(%3)\n"
20395 " movl %%edx, 36(%3)\n"
20396 - "12: movl 40(%4), %%eax\n"
20397 - "71: movl 44(%4), %%edx\n"
20398 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
20399 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
20400 " movl %%eax, 40(%3)\n"
20401 " movl %%edx, 44(%3)\n"
20402 - "13: movl 48(%4), %%eax\n"
20403 - "81: movl 52(%4), %%edx\n"
20404 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
20405 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
20406 " movl %%eax, 48(%3)\n"
20407 " movl %%edx, 52(%3)\n"
20408 - "14: movl 56(%4), %%eax\n"
20409 - "91: movl 60(%4), %%edx\n"
20410 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
20411 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
20412 " movl %%eax, 56(%3)\n"
20413 " movl %%edx, 60(%3)\n"
20414 " addl $-64, %0\n"
20415 @@ -385,9 +498,9 @@ __copy_user_zeroing_intel(void *to, cons
20416 " shrl $2, %0\n"
20417 " andl $3, %%eax\n"
20418 " cld\n"
20419 - "6: rep; movsl\n"
20420 + "6: rep; "__copyuser_seg" movsl\n"
20421 " movl %%eax,%0\n"
20422 - "7: rep; movsb\n"
20423 + "7: rep; "__copyuser_seg" movsb\n"
20424 "8:\n"
20425 ".section .fixup,\"ax\"\n"
20426 "9: lea 0(%%eax,%0,4),%0\n"
20427 @@ -440,41 +553,41 @@ static unsigned long __copy_user_zeroing
20428
20429 __asm__ __volatile__(
20430 " .align 2,0x90\n"
20431 - "0: movl 32(%4), %%eax\n"
20432 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
20433 " cmpl $67, %0\n"
20434 " jbe 2f\n"
20435 - "1: movl 64(%4), %%eax\n"
20436 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
20437 " .align 2,0x90\n"
20438 - "2: movl 0(%4), %%eax\n"
20439 - "21: movl 4(%4), %%edx\n"
20440 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
20441 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
20442 " movnti %%eax, 0(%3)\n"
20443 " movnti %%edx, 4(%3)\n"
20444 - "3: movl 8(%4), %%eax\n"
20445 - "31: movl 12(%4),%%edx\n"
20446 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
20447 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
20448 " movnti %%eax, 8(%3)\n"
20449 " movnti %%edx, 12(%3)\n"
20450 - "4: movl 16(%4), %%eax\n"
20451 - "41: movl 20(%4), %%edx\n"
20452 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
20453 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
20454 " movnti %%eax, 16(%3)\n"
20455 " movnti %%edx, 20(%3)\n"
20456 - "10: movl 24(%4), %%eax\n"
20457 - "51: movl 28(%4), %%edx\n"
20458 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
20459 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
20460 " movnti %%eax, 24(%3)\n"
20461 " movnti %%edx, 28(%3)\n"
20462 - "11: movl 32(%4), %%eax\n"
20463 - "61: movl 36(%4), %%edx\n"
20464 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
20465 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
20466 " movnti %%eax, 32(%3)\n"
20467 " movnti %%edx, 36(%3)\n"
20468 - "12: movl 40(%4), %%eax\n"
20469 - "71: movl 44(%4), %%edx\n"
20470 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
20471 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
20472 " movnti %%eax, 40(%3)\n"
20473 " movnti %%edx, 44(%3)\n"
20474 - "13: movl 48(%4), %%eax\n"
20475 - "81: movl 52(%4), %%edx\n"
20476 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
20477 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
20478 " movnti %%eax, 48(%3)\n"
20479 " movnti %%edx, 52(%3)\n"
20480 - "14: movl 56(%4), %%eax\n"
20481 - "91: movl 60(%4), %%edx\n"
20482 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
20483 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
20484 " movnti %%eax, 56(%3)\n"
20485 " movnti %%edx, 60(%3)\n"
20486 " addl $-64, %0\n"
20487 @@ -487,9 +600,9 @@ static unsigned long __copy_user_zeroing
20488 " shrl $2, %0\n"
20489 " andl $3, %%eax\n"
20490 " cld\n"
20491 - "6: rep; movsl\n"
20492 + "6: rep; "__copyuser_seg" movsl\n"
20493 " movl %%eax,%0\n"
20494 - "7: rep; movsb\n"
20495 + "7: rep; "__copyuser_seg" movsb\n"
20496 "8:\n"
20497 ".section .fixup,\"ax\"\n"
20498 "9: lea 0(%%eax,%0,4),%0\n"
20499 @@ -537,41 +650,41 @@ static unsigned long __copy_user_intel_n
20500
20501 __asm__ __volatile__(
20502 " .align 2,0x90\n"
20503 - "0: movl 32(%4), %%eax\n"
20504 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
20505 " cmpl $67, %0\n"
20506 " jbe 2f\n"
20507 - "1: movl 64(%4), %%eax\n"
20508 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
20509 " .align 2,0x90\n"
20510 - "2: movl 0(%4), %%eax\n"
20511 - "21: movl 4(%4), %%edx\n"
20512 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
20513 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
20514 " movnti %%eax, 0(%3)\n"
20515 " movnti %%edx, 4(%3)\n"
20516 - "3: movl 8(%4), %%eax\n"
20517 - "31: movl 12(%4),%%edx\n"
20518 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
20519 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
20520 " movnti %%eax, 8(%3)\n"
20521 " movnti %%edx, 12(%3)\n"
20522 - "4: movl 16(%4), %%eax\n"
20523 - "41: movl 20(%4), %%edx\n"
20524 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
20525 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
20526 " movnti %%eax, 16(%3)\n"
20527 " movnti %%edx, 20(%3)\n"
20528 - "10: movl 24(%4), %%eax\n"
20529 - "51: movl 28(%4), %%edx\n"
20530 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
20531 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
20532 " movnti %%eax, 24(%3)\n"
20533 " movnti %%edx, 28(%3)\n"
20534 - "11: movl 32(%4), %%eax\n"
20535 - "61: movl 36(%4), %%edx\n"
20536 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
20537 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
20538 " movnti %%eax, 32(%3)\n"
20539 " movnti %%edx, 36(%3)\n"
20540 - "12: movl 40(%4), %%eax\n"
20541 - "71: movl 44(%4), %%edx\n"
20542 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
20543 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
20544 " movnti %%eax, 40(%3)\n"
20545 " movnti %%edx, 44(%3)\n"
20546 - "13: movl 48(%4), %%eax\n"
20547 - "81: movl 52(%4), %%edx\n"
20548 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
20549 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
20550 " movnti %%eax, 48(%3)\n"
20551 " movnti %%edx, 52(%3)\n"
20552 - "14: movl 56(%4), %%eax\n"
20553 - "91: movl 60(%4), %%edx\n"
20554 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
20555 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
20556 " movnti %%eax, 56(%3)\n"
20557 " movnti %%edx, 60(%3)\n"
20558 " addl $-64, %0\n"
20559 @@ -584,9 +697,9 @@ static unsigned long __copy_user_intel_n
20560 " shrl $2, %0\n"
20561 " andl $3, %%eax\n"
20562 " cld\n"
20563 - "6: rep; movsl\n"
20564 + "6: rep; "__copyuser_seg" movsl\n"
20565 " movl %%eax,%0\n"
20566 - "7: rep; movsb\n"
20567 + "7: rep; "__copyuser_seg" movsb\n"
20568 "8:\n"
20569 ".section .fixup,\"ax\"\n"
20570 "9: lea 0(%%eax,%0,4),%0\n"
20571 @@ -629,32 +742,36 @@ static unsigned long __copy_user_intel_n
20572 */
20573 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
20574 unsigned long size);
20575 -unsigned long __copy_user_intel(void __user *to, const void *from,
20576 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
20577 + unsigned long size);
20578 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
20579 unsigned long size);
20580 unsigned long __copy_user_zeroing_intel_nocache(void *to,
20581 const void __user *from, unsigned long size);
20582 #endif /* CONFIG_X86_INTEL_USERCOPY */
20583
20584 /* Generic arbitrary sized copy. */
20585 -#define __copy_user(to, from, size) \
20586 +#define __copy_user(to, from, size, prefix, set, restore) \
20587 do { \
20588 int __d0, __d1, __d2; \
20589 __asm__ __volatile__( \
20590 + set \
20591 " cmp $7,%0\n" \
20592 " jbe 1f\n" \
20593 " movl %1,%0\n" \
20594 " negl %0\n" \
20595 " andl $7,%0\n" \
20596 " subl %0,%3\n" \
20597 - "4: rep; movsb\n" \
20598 + "4: rep; "prefix"movsb\n" \
20599 " movl %3,%0\n" \
20600 " shrl $2,%0\n" \
20601 " andl $3,%3\n" \
20602 " .align 2,0x90\n" \
20603 - "0: rep; movsl\n" \
20604 + "0: rep; "prefix"movsl\n" \
20605 " movl %3,%0\n" \
20606 - "1: rep; movsb\n" \
20607 + "1: rep; "prefix"movsb\n" \
20608 "2:\n" \
20609 + restore \
20610 ".section .fixup,\"ax\"\n" \
20611 "5: addl %3,%0\n" \
20612 " jmp 2b\n" \
20613 @@ -682,14 +799,14 @@ do { \
20614 " negl %0\n" \
20615 " andl $7,%0\n" \
20616 " subl %0,%3\n" \
20617 - "4: rep; movsb\n" \
20618 + "4: rep; "__copyuser_seg"movsb\n" \
20619 " movl %3,%0\n" \
20620 " shrl $2,%0\n" \
20621 " andl $3,%3\n" \
20622 " .align 2,0x90\n" \
20623 - "0: rep; movsl\n" \
20624 + "0: rep; "__copyuser_seg"movsl\n" \
20625 " movl %3,%0\n" \
20626 - "1: rep; movsb\n" \
20627 + "1: rep; "__copyuser_seg"movsb\n" \
20628 "2:\n" \
20629 ".section .fixup,\"ax\"\n" \
20630 "5: addl %3,%0\n" \
20631 @@ -775,9 +892,9 @@ survive:
20632 }
20633 #endif
20634 if (movsl_is_ok(to, from, n))
20635 - __copy_user(to, from, n);
20636 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
20637 else
20638 - n = __copy_user_intel(to, from, n);
20639 + n = __generic_copy_to_user_intel(to, from, n);
20640 return n;
20641 }
20642 EXPORT_SYMBOL(__copy_to_user_ll);
20643 @@ -797,10 +914,9 @@ unsigned long __copy_from_user_ll_nozero
20644 unsigned long n)
20645 {
20646 if (movsl_is_ok(to, from, n))
20647 - __copy_user(to, from, n);
20648 + __copy_user(to, from, n, __copyuser_seg, "", "");
20649 else
20650 - n = __copy_user_intel((void __user *)to,
20651 - (const void *)from, n);
20652 + n = __generic_copy_from_user_intel(to, from, n);
20653 return n;
20654 }
20655 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
20656 @@ -827,65 +943,50 @@ unsigned long __copy_from_user_ll_nocach
20657 if (n > 64 && cpu_has_xmm2)
20658 n = __copy_user_intel_nocache(to, from, n);
20659 else
20660 - __copy_user(to, from, n);
20661 + __copy_user(to, from, n, __copyuser_seg, "", "");
20662 #else
20663 - __copy_user(to, from, n);
20664 + __copy_user(to, from, n, __copyuser_seg, "", "");
20665 #endif
20666 return n;
20667 }
20668 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
20669
20670 -/**
20671 - * copy_to_user: - Copy a block of data into user space.
20672 - * @to: Destination address, in user space.
20673 - * @from: Source address, in kernel space.
20674 - * @n: Number of bytes to copy.
20675 - *
20676 - * Context: User context only. This function may sleep.
20677 - *
20678 - * Copy data from kernel space to user space.
20679 - *
20680 - * Returns number of bytes that could not be copied.
20681 - * On success, this will be zero.
20682 - */
20683 -unsigned long
20684 -copy_to_user(void __user *to, const void *from, unsigned long n)
20685 +void copy_from_user_overflow(void)
20686 {
20687 - if (access_ok(VERIFY_WRITE, to, n))
20688 - n = __copy_to_user(to, from, n);
20689 - return n;
20690 + WARN(1, "Buffer overflow detected!\n");
20691 }
20692 -EXPORT_SYMBOL(copy_to_user);
20693 +EXPORT_SYMBOL(copy_from_user_overflow);
20694
20695 -/**
20696 - * copy_from_user: - Copy a block of data from user space.
20697 - * @to: Destination address, in kernel space.
20698 - * @from: Source address, in user space.
20699 - * @n: Number of bytes to copy.
20700 - *
20701 - * Context: User context only. This function may sleep.
20702 - *
20703 - * Copy data from user space to kernel space.
20704 - *
20705 - * Returns number of bytes that could not be copied.
20706 - * On success, this will be zero.
20707 - *
20708 - * If some data could not be copied, this function will pad the copied
20709 - * data to the requested size using zero bytes.
20710 - */
20711 -unsigned long
20712 -_copy_from_user(void *to, const void __user *from, unsigned long n)
20713 +void copy_to_user_overflow(void)
20714 {
20715 - if (access_ok(VERIFY_READ, from, n))
20716 - n = __copy_from_user(to, from, n);
20717 - else
20718 - memset(to, 0, n);
20719 - return n;
20720 + WARN(1, "Buffer overflow detected!\n");
20721 }
20722 -EXPORT_SYMBOL(_copy_from_user);
20723 +EXPORT_SYMBOL(copy_to_user_overflow);
20724
20725 -void copy_from_user_overflow(void)
20726 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20727 +void __set_fs(mm_segment_t x)
20728 {
20729 - WARN(1, "Buffer overflow detected!\n");
20730 + switch (x.seg) {
20731 + case 0:
20732 + loadsegment(gs, 0);
20733 + break;
20734 + case TASK_SIZE_MAX:
20735 + loadsegment(gs, __USER_DS);
20736 + break;
20737 + case -1UL:
20738 + loadsegment(gs, __KERNEL_DS);
20739 + break;
20740 + default:
20741 + BUG();
20742 + }
20743 + return;
20744 }
20745 -EXPORT_SYMBOL(copy_from_user_overflow);
20746 +EXPORT_SYMBOL(__set_fs);
20747 +
20748 +void set_fs(mm_segment_t x)
20749 +{
20750 + current_thread_info()->addr_limit = x;
20751 + __set_fs(x);
20752 +}
20753 +EXPORT_SYMBOL(set_fs);
20754 +#endif
20755 diff -urNp linux-2.6.39/arch/x86/lib/usercopy_64.c linux-2.6.39/arch/x86/lib/usercopy_64.c
20756 --- linux-2.6.39/arch/x86/lib/usercopy_64.c 2011-05-19 00:06:34.000000000 -0400
20757 +++ linux-2.6.39/arch/x86/lib/usercopy_64.c 2011-05-22 19:36:30.000000000 -0400
20758 @@ -42,6 +42,12 @@ long
20759 __strncpy_from_user(char *dst, const char __user *src, long count)
20760 {
20761 long res;
20762 +
20763 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20764 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
20765 + src += PAX_USER_SHADOW_BASE;
20766 +#endif
20767 +
20768 __do_strncpy_from_user(dst, src, count, res);
20769 return res;
20770 }
20771 @@ -65,6 +71,12 @@ unsigned long __clear_user(void __user *
20772 {
20773 long __d0;
20774 might_fault();
20775 +
20776 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20777 + if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
20778 + addr += PAX_USER_SHADOW_BASE;
20779 +#endif
20780 +
20781 /* no memory constraint because it doesn't change any memory gcc knows
20782 about */
20783 asm volatile(
20784 @@ -151,10 +163,18 @@ EXPORT_SYMBOL(strlen_user);
20785
20786 unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
20787 {
20788 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
20789 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
20790 +
20791 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20792 + if ((unsigned long)to < PAX_USER_SHADOW_BASE)
20793 + to += PAX_USER_SHADOW_BASE;
20794 + if ((unsigned long)from < PAX_USER_SHADOW_BASE)
20795 + from += PAX_USER_SHADOW_BASE;
20796 +#endif
20797 +
20798 return copy_user_generic((__force void *)to, (__force void *)from, len);
20799 - }
20800 - return len;
20801 + }
20802 + return len;
20803 }
20804 EXPORT_SYMBOL(copy_in_user);
20805
20806 diff -urNp linux-2.6.39/arch/x86/Makefile linux-2.6.39/arch/x86/Makefile
20807 --- linux-2.6.39/arch/x86/Makefile 2011-05-19 00:06:34.000000000 -0400
20808 +++ linux-2.6.39/arch/x86/Makefile 2011-05-22 19:36:30.000000000 -0400
20809 @@ -195,3 +195,12 @@ define archhelp
20810 echo ' FDARGS="..." arguments for the booted kernel'
20811 echo ' FDINITRD=file initrd for the booted kernel'
20812 endef
20813 +
20814 +define OLD_LD
20815 +
20816 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
20817 +*** Please upgrade your binutils to 2.18 or newer
20818 +endef
20819 +
20820 +archprepare:
20821 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
20822 diff -urNp linux-2.6.39/arch/x86/mm/extable.c linux-2.6.39/arch/x86/mm/extable.c
20823 --- linux-2.6.39/arch/x86/mm/extable.c 2011-05-19 00:06:34.000000000 -0400
20824 +++ linux-2.6.39/arch/x86/mm/extable.c 2011-05-22 19:36:30.000000000 -0400
20825 @@ -1,14 +1,71 @@
20826 #include <linux/module.h>
20827 #include <linux/spinlock.h>
20828 +#include <linux/sort.h>
20829 #include <asm/uaccess.h>
20830 +#include <asm/pgtable.h>
20831
20832 +/*
20833 + * The exception table needs to be sorted so that the binary
20834 + * search that we use to find entries in it works properly.
20835 + * This is used both for the kernel exception table and for
20836 + * the exception tables of modules that get loaded.
20837 + */
20838 +static int cmp_ex(const void *a, const void *b)
20839 +{
20840 + const struct exception_table_entry *x = a, *y = b;
20841 +
20842 + /* avoid overflow */
20843 + if (x->insn > y->insn)
20844 + return 1;
20845 + if (x->insn < y->insn)
20846 + return -1;
20847 + return 0;
20848 +}
20849 +
20850 +static void swap_ex(void *a, void *b, int size)
20851 +{
20852 + struct exception_table_entry t, *x = a, *y = b;
20853 +
20854 + t = *x;
20855 +
20856 + pax_open_kernel();
20857 + *x = *y;
20858 + *y = t;
20859 + pax_close_kernel();
20860 +}
20861 +
20862 +void sort_extable(struct exception_table_entry *start,
20863 + struct exception_table_entry *finish)
20864 +{
20865 + sort(start, finish - start, sizeof(struct exception_table_entry),
20866 + cmp_ex, swap_ex);
20867 +}
20868 +
20869 +#ifdef CONFIG_MODULES
20870 +/*
20871 + * If the exception table is sorted, any referring to the module init
20872 + * will be at the beginning or the end.
20873 + */
20874 +void trim_init_extable(struct module *m)
20875 +{
20876 + /*trim the beginning*/
20877 + while (m->num_exentries && within_module_init(m->extable[0].insn, m)) {
20878 + m->extable++;
20879 + m->num_exentries--;
20880 + }
20881 + /*trim the end*/
20882 + while (m->num_exentries &&
20883 + within_module_init(m->extable[m->num_exentries-1].insn, m))
20884 + m->num_exentries--;
20885 +}
20886 +#endif /* CONFIG_MODULES */
20887
20888 int fixup_exception(struct pt_regs *regs)
20889 {
20890 const struct exception_table_entry *fixup;
20891
20892 #ifdef CONFIG_PNPBIOS
20893 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
20894 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
20895 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
20896 extern u32 pnp_bios_is_utter_crap;
20897 pnp_bios_is_utter_crap = 1;
20898 diff -urNp linux-2.6.39/arch/x86/mm/fault.c linux-2.6.39/arch/x86/mm/fault.c
20899 --- linux-2.6.39/arch/x86/mm/fault.c 2011-05-19 00:06:34.000000000 -0400
20900 +++ linux-2.6.39/arch/x86/mm/fault.c 2011-05-22 20:33:41.000000000 -0400
20901 @@ -12,10 +12,18 @@
20902 #include <linux/mmiotrace.h> /* kmmio_handler, ... */
20903 #include <linux/perf_event.h> /* perf_sw_event */
20904 #include <linux/hugetlb.h> /* hstate_index_to_shift */
20905 +#include <linux/unistd.h>
20906 +#include <linux/compiler.h>
20907
20908 #include <asm/traps.h> /* dotraplinkage, ... */
20909 #include <asm/pgalloc.h> /* pgd_*(), ... */
20910 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
20911 +#include <asm/vsyscall.h>
20912 +#include <asm/tlbflush.h>
20913 +
20914 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20915 +#include <asm/stacktrace.h>
20916 +#endif
20917
20918 /*
20919 * Page fault error code bits:
20920 @@ -53,7 +61,7 @@ static inline int __kprobes notify_page_
20921 int ret = 0;
20922
20923 /* kprobe_running() needs smp_processor_id() */
20924 - if (kprobes_built_in() && !user_mode_vm(regs)) {
20925 + if (kprobes_built_in() && !user_mode(regs)) {
20926 preempt_disable();
20927 if (kprobe_running() && kprobe_fault_handler(regs, 14))
20928 ret = 1;
20929 @@ -114,7 +122,10 @@ check_prefetch_opcode(struct pt_regs *re
20930 return !instr_lo || (instr_lo>>1) == 1;
20931 case 0x00:
20932 /* Prefetch instruction is 0x0F0D or 0x0F18 */
20933 - if (probe_kernel_address(instr, opcode))
20934 + if (user_mode(regs)) {
20935 + if (__copy_from_user_inatomic(&opcode, (__force unsigned char __user *)(instr), 1))
20936 + return 0;
20937 + } else if (probe_kernel_address(instr, opcode))
20938 return 0;
20939
20940 *prefetch = (instr_lo == 0xF) &&
20941 @@ -148,7 +159,10 @@ is_prefetch(struct pt_regs *regs, unsign
20942 while (instr < max_instr) {
20943 unsigned char opcode;
20944
20945 - if (probe_kernel_address(instr, opcode))
20946 + if (user_mode(regs)) {
20947 + if (__copy_from_user_inatomic(&opcode, (__force unsigned char __user *)(instr), 1))
20948 + break;
20949 + } else if (probe_kernel_address(instr, opcode))
20950 break;
20951
20952 instr++;
20953 @@ -179,6 +193,30 @@ force_sig_info_fault(int si_signo, int s
20954 force_sig_info(si_signo, &info, tsk);
20955 }
20956
20957 +#ifdef CONFIG_PAX_EMUTRAMP
20958 +static int pax_handle_fetch_fault(struct pt_regs *regs);
20959 +#endif
20960 +
20961 +#ifdef CONFIG_PAX_PAGEEXEC
20962 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
20963 +{
20964 + pgd_t *pgd;
20965 + pud_t *pud;
20966 + pmd_t *pmd;
20967 +
20968 + pgd = pgd_offset(mm, address);
20969 + if (!pgd_present(*pgd))
20970 + return NULL;
20971 + pud = pud_offset(pgd, address);
20972 + if (!pud_present(*pud))
20973 + return NULL;
20974 + pmd = pmd_offset(pud, address);
20975 + if (!pmd_present(*pmd))
20976 + return NULL;
20977 + return pmd;
20978 +}
20979 +#endif
20980 +
20981 DEFINE_SPINLOCK(pgd_lock);
20982 LIST_HEAD(pgd_list);
20983
20984 @@ -229,10 +267,22 @@ void vmalloc_sync_all(void)
20985 for (address = VMALLOC_START & PMD_MASK;
20986 address >= TASK_SIZE && address < FIXADDR_TOP;
20987 address += PMD_SIZE) {
20988 +
20989 +#ifdef CONFIG_PAX_PER_CPU_PGD
20990 + unsigned long cpu;
20991 +#else
20992 struct page *page;
20993 +#endif
20994
20995 spin_lock(&pgd_lock);
20996 +
20997 +#ifdef CONFIG_PAX_PER_CPU_PGD
20998 + for (cpu = 0; cpu < NR_CPUS; ++cpu) {
20999 + pgd_t *pgd = get_cpu_pgd(cpu);
21000 + pmd_t *ret;
21001 +#else
21002 list_for_each_entry(page, &pgd_list, lru) {
21003 + pgd_t *pgd = page_address(page);
21004 spinlock_t *pgt_lock;
21005 pmd_t *ret;
21006
21007 @@ -240,8 +290,13 @@ void vmalloc_sync_all(void)
21008 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
21009
21010 spin_lock(pgt_lock);
21011 - ret = vmalloc_sync_one(page_address(page), address);
21012 +#endif
21013 +
21014 + ret = vmalloc_sync_one(pgd, address);
21015 +
21016 +#ifndef CONFIG_PAX_PER_CPU_PGD
21017 spin_unlock(pgt_lock);
21018 +#endif
21019
21020 if (!ret)
21021 break;
21022 @@ -275,6 +330,11 @@ static noinline __kprobes int vmalloc_fa
21023 * an interrupt in the middle of a task switch..
21024 */
21025 pgd_paddr = read_cr3();
21026 +
21027 +#ifdef CONFIG_PAX_PER_CPU_PGD
21028 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
21029 +#endif
21030 +
21031 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
21032 if (!pmd_k)
21033 return -1;
21034 @@ -370,7 +430,14 @@ static noinline __kprobes int vmalloc_fa
21035 * happen within a race in page table update. In the later
21036 * case just flush:
21037 */
21038 +
21039 +#ifdef CONFIG_PAX_PER_CPU_PGD
21040 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
21041 + pgd = pgd_offset_cpu(smp_processor_id(), address);
21042 +#else
21043 pgd = pgd_offset(current->active_mm, address);
21044 +#endif
21045 +
21046 pgd_ref = pgd_offset_k(address);
21047 if (pgd_none(*pgd_ref))
21048 return -1;
21049 @@ -532,7 +599,7 @@ static int is_errata93(struct pt_regs *r
21050 static int is_errata100(struct pt_regs *regs, unsigned long address)
21051 {
21052 #ifdef CONFIG_X86_64
21053 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
21054 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
21055 return 1;
21056 #endif
21057 return 0;
21058 @@ -559,7 +626,7 @@ static int is_f00f_bug(struct pt_regs *r
21059 }
21060
21061 static const char nx_warning[] = KERN_CRIT
21062 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
21063 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
21064
21065 static void
21066 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
21067 @@ -568,15 +635,26 @@ show_fault_oops(struct pt_regs *regs, un
21068 if (!oops_may_print())
21069 return;
21070
21071 - if (error_code & PF_INSTR) {
21072 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
21073 unsigned int level;
21074
21075 pte_t *pte = lookup_address(address, &level);
21076
21077 if (pte && pte_present(*pte) && !pte_exec(*pte))
21078 - printk(nx_warning, current_uid());
21079 + printk(nx_warning, current_uid(), current->comm, task_pid_nr(current));
21080 }
21081
21082 +#ifdef CONFIG_PAX_KERNEXEC
21083 + if (init_mm.start_code <= address && address < init_mm.end_code) {
21084 + if (current->signal->curr_ip)
21085 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
21086 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
21087 + else
21088 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
21089 + current->comm, task_pid_nr(current), current_uid(), current_euid());
21090 + }
21091 +#endif
21092 +
21093 printk(KERN_ALERT "BUG: unable to handle kernel ");
21094 if (address < PAGE_SIZE)
21095 printk(KERN_CONT "NULL pointer dereference");
21096 @@ -701,6 +779,68 @@ __bad_area_nosemaphore(struct pt_regs *r
21097 unsigned long address, int si_code)
21098 {
21099 struct task_struct *tsk = current;
21100 + struct mm_struct *mm = tsk->mm;
21101 +
21102 +#ifdef CONFIG_X86_64
21103 + if (mm && (error_code & PF_INSTR) && mm->context.vdso) {
21104 + if (regs->ip == (unsigned long)vgettimeofday) {
21105 + regs->ip = (unsigned long)VDSO64_SYMBOL(mm->context.vdso, fallback_gettimeofday);
21106 + return;
21107 + } else if (regs->ip == (unsigned long)vtime) {
21108 + regs->ip = (unsigned long)VDSO64_SYMBOL(mm->context.vdso, fallback_time);
21109 + return;
21110 + } else if (regs->ip == (unsigned long)vgetcpu) {
21111 + regs->ip = (unsigned long)VDSO64_SYMBOL(mm->context.vdso, getcpu);
21112 + return;
21113 + }
21114 + }
21115 +#endif
21116 +
21117 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
21118 + if (mm && (error_code & PF_USER)) {
21119 + unsigned long ip = regs->ip;
21120 +
21121 + if (v8086_mode(regs))
21122 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
21123 +
21124 + /*
21125 + * It's possible to have interrupts off here:
21126 + */
21127 + local_irq_enable();
21128 +
21129 +#ifdef CONFIG_PAX_PAGEEXEC
21130 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) &&
21131 + (((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) || (!(error_code & (PF_PROT | PF_WRITE)) && ip == address))) {
21132 +
21133 +#ifdef CONFIG_PAX_EMUTRAMP
21134 + switch (pax_handle_fetch_fault(regs)) {
21135 + case 2:
21136 + return;
21137 + }
21138 +#endif
21139 +
21140 + pax_report_fault(regs, (void *)ip, (void *)regs->sp);
21141 + do_group_exit(SIGKILL);
21142 + }
21143 +#endif
21144 +
21145 +#ifdef CONFIG_PAX_SEGMEXEC
21146 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && !(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address)) {
21147 +
21148 +#ifdef CONFIG_PAX_EMUTRAMP
21149 + switch (pax_handle_fetch_fault(regs)) {
21150 + case 2:
21151 + return;
21152 + }
21153 +#endif
21154 +
21155 + pax_report_fault(regs, (void *)ip, (void *)regs->sp);
21156 + do_group_exit(SIGKILL);
21157 + }
21158 +#endif
21159 +
21160 + }
21161 +#endif
21162
21163 /* User mode accesses just cause a SIGSEGV */
21164 if (error_code & PF_USER) {
21165 @@ -855,6 +995,99 @@ static int spurious_fault_check(unsigned
21166 return 1;
21167 }
21168
21169 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
21170 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
21171 +{
21172 + pte_t *pte;
21173 + pmd_t *pmd;
21174 + spinlock_t *ptl;
21175 + unsigned char pte_mask;
21176 +
21177 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
21178 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
21179 + return 0;
21180 +
21181 + /* PaX: it's our fault, let's handle it if we can */
21182 +
21183 + /* PaX: take a look at read faults before acquiring any locks */
21184 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
21185 + /* instruction fetch attempt from a protected page in user mode */
21186 + up_read(&mm->mmap_sem);
21187 +
21188 +#ifdef CONFIG_PAX_EMUTRAMP
21189 + switch (pax_handle_fetch_fault(regs)) {
21190 + case 2:
21191 + return 1;
21192 + }
21193 +#endif
21194 +
21195 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
21196 + do_group_exit(SIGKILL);
21197 + }
21198 +
21199 + pmd = pax_get_pmd(mm, address);
21200 + if (unlikely(!pmd))
21201 + return 0;
21202 +
21203 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
21204 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
21205 + pte_unmap_unlock(pte, ptl);
21206 + return 0;
21207 + }
21208 +
21209 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
21210 + /* write attempt to a protected page in user mode */
21211 + pte_unmap_unlock(pte, ptl);
21212 + return 0;
21213 + }
21214 +
21215 +#ifdef CONFIG_SMP
21216 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
21217 +#else
21218 + if (likely(address > get_limit(regs->cs)))
21219 +#endif
21220 + {
21221 + set_pte(pte, pte_mkread(*pte));
21222 + __flush_tlb_one(address);
21223 + pte_unmap_unlock(pte, ptl);
21224 + up_read(&mm->mmap_sem);
21225 + return 1;
21226 + }
21227 +
21228 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
21229 +
21230 + /*
21231 + * PaX: fill DTLB with user rights and retry
21232 + */
21233 + __asm__ __volatile__ (
21234 + "orb %2,(%1)\n"
21235 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
21236 +/*
21237 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
21238 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
21239 + * page fault when examined during a TLB load attempt. this is true not only
21240 + * for PTEs holding a non-present entry but also present entries that will
21241 + * raise a page fault (such as those set up by PaX, or the copy-on-write
21242 + * mechanism). in effect it means that we do *not* need to flush the TLBs
21243 + * for our target pages since their PTEs are simply not in the TLBs at all.
21244 +
21245 + * the best thing in omitting it is that we gain around 15-20% speed in the
21246 + * fast path of the page fault handler and can get rid of tracing since we
21247 + * can no longer flush unintended entries.
21248 + */
21249 + "invlpg (%0)\n"
21250 +#endif
21251 + __copyuser_seg"testb $0,(%0)\n"
21252 + "xorb %3,(%1)\n"
21253 + :
21254 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
21255 + : "memory", "cc");
21256 + pte_unmap_unlock(pte, ptl);
21257 + up_read(&mm->mmap_sem);
21258 + return 1;
21259 +}
21260 +#endif
21261 +
21262 /*
21263 * Handle a spurious fault caused by a stale TLB entry.
21264 *
21265 @@ -927,6 +1160,9 @@ int show_unhandled_signals = 1;
21266 static inline int
21267 access_error(unsigned long error_code, struct vm_area_struct *vma)
21268 {
21269 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
21270 + return 1;
21271 +
21272 if (error_code & PF_WRITE) {
21273 /* write, present and write, not present: */
21274 if (unlikely(!(vma->vm_flags & VM_WRITE)))
21275 @@ -960,19 +1196,33 @@ do_page_fault(struct pt_regs *regs, unsi
21276 {
21277 struct vm_area_struct *vma;
21278 struct task_struct *tsk;
21279 - unsigned long address;
21280 struct mm_struct *mm;
21281 int fault;
21282 int write = error_code & PF_WRITE;
21283 unsigned int flags = FAULT_FLAG_ALLOW_RETRY |
21284 (write ? FAULT_FLAG_WRITE : 0);
21285
21286 + /* Get the faulting address: */
21287 + unsigned long address = read_cr2();
21288 +
21289 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21290 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
21291 + if (!search_exception_tables(regs->ip)) {
21292 + bad_area_nosemaphore(regs, error_code, address);
21293 + return;
21294 + }
21295 + if (address < PAX_USER_SHADOW_BASE) {
21296 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
21297 + printk(KERN_ERR "PAX: faulting IP: %pA\n", (void *)regs->ip);
21298 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
21299 + } else
21300 + address -= PAX_USER_SHADOW_BASE;
21301 + }
21302 +#endif
21303 +
21304 tsk = current;
21305 mm = tsk->mm;
21306
21307 - /* Get the faulting address: */
21308 - address = read_cr2();
21309 -
21310 /*
21311 * Detect and handle instructions that would cause a page fault for
21312 * both a tracked kernel page and a userspace page.
21313 @@ -1032,7 +1282,7 @@ do_page_fault(struct pt_regs *regs, unsi
21314 * User-mode registers count as a user access even for any
21315 * potential system fault or CPU buglet:
21316 */
21317 - if (user_mode_vm(regs)) {
21318 + if (user_mode(regs)) {
21319 local_irq_enable();
21320 error_code |= PF_USER;
21321 } else {
21322 @@ -1087,6 +1337,11 @@ retry:
21323 might_sleep();
21324 }
21325
21326 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
21327 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
21328 + return;
21329 +#endif
21330 +
21331 vma = find_vma(mm, address);
21332 if (unlikely(!vma)) {
21333 bad_area(regs, error_code, address);
21334 @@ -1098,18 +1353,24 @@ retry:
21335 bad_area(regs, error_code, address);
21336 return;
21337 }
21338 - if (error_code & PF_USER) {
21339 - /*
21340 - * Accessing the stack below %sp is always a bug.
21341 - * The large cushion allows instructions like enter
21342 - * and pusha to work. ("enter $65535, $31" pushes
21343 - * 32 pointers and then decrements %sp by 65535.)
21344 - */
21345 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
21346 - bad_area(regs, error_code, address);
21347 - return;
21348 - }
21349 + /*
21350 + * Accessing the stack below %sp is always a bug.
21351 + * The large cushion allows instructions like enter
21352 + * and pusha to work. ("enter $65535, $31" pushes
21353 + * 32 pointers and then decrements %sp by 65535.)
21354 + */
21355 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
21356 + bad_area(regs, error_code, address);
21357 + return;
21358 }
21359 +
21360 +#ifdef CONFIG_PAX_SEGMEXEC
21361 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
21362 + bad_area(regs, error_code, address);
21363 + return;
21364 + }
21365 +#endif
21366 +
21367 if (unlikely(expand_stack(vma, address))) {
21368 bad_area(regs, error_code, address);
21369 return;
21370 @@ -1164,3 +1425,199 @@ good_area:
21371
21372 up_read(&mm->mmap_sem);
21373 }
21374 +
21375 +#ifdef CONFIG_PAX_EMUTRAMP
21376 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
21377 +{
21378 + int err;
21379 +
21380 + do { /* PaX: gcc trampoline emulation #1 */
21381 + unsigned char mov1, mov2;
21382 + unsigned short jmp;
21383 + unsigned int addr1, addr2;
21384 +
21385 +#ifdef CONFIG_X86_64
21386 + if ((regs->ip + 11) >> 32)
21387 + break;
21388 +#endif
21389 +
21390 + err = get_user(mov1, (unsigned char __user *)regs->ip);
21391 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
21392 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
21393 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
21394 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
21395 +
21396 + if (err)
21397 + break;
21398 +
21399 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
21400 + regs->cx = addr1;
21401 + regs->ax = addr2;
21402 + regs->ip = addr2;
21403 + return 2;
21404 + }
21405 + } while (0);
21406 +
21407 + do { /* PaX: gcc trampoline emulation #2 */
21408 + unsigned char mov, jmp;
21409 + unsigned int addr1, addr2;
21410 +
21411 +#ifdef CONFIG_X86_64
21412 + if ((regs->ip + 9) >> 32)
21413 + break;
21414 +#endif
21415 +
21416 + err = get_user(mov, (unsigned char __user *)regs->ip);
21417 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
21418 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
21419 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
21420 +
21421 + if (err)
21422 + break;
21423 +
21424 + if (mov == 0xB9 && jmp == 0xE9) {
21425 + regs->cx = addr1;
21426 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
21427 + return 2;
21428 + }
21429 + } while (0);
21430 +
21431 + return 1; /* PaX in action */
21432 +}
21433 +
21434 +#ifdef CONFIG_X86_64
21435 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
21436 +{
21437 + int err;
21438 +
21439 + do { /* PaX: gcc trampoline emulation #1 */
21440 + unsigned short mov1, mov2, jmp1;
21441 + unsigned char jmp2;
21442 + unsigned int addr1;
21443 + unsigned long addr2;
21444 +
21445 + err = get_user(mov1, (unsigned short __user *)regs->ip);
21446 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
21447 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
21448 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
21449 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
21450 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
21451 +
21452 + if (err)
21453 + break;
21454 +
21455 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
21456 + regs->r11 = addr1;
21457 + regs->r10 = addr2;
21458 + regs->ip = addr1;
21459 + return 2;
21460 + }
21461 + } while (0);
21462 +
21463 + do { /* PaX: gcc trampoline emulation #2 */
21464 + unsigned short mov1, mov2, jmp1;
21465 + unsigned char jmp2;
21466 + unsigned long addr1, addr2;
21467 +
21468 + err = get_user(mov1, (unsigned short __user *)regs->ip);
21469 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
21470 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
21471 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
21472 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
21473 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
21474 +
21475 + if (err)
21476 + break;
21477 +
21478 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
21479 + regs->r11 = addr1;
21480 + regs->r10 = addr2;
21481 + regs->ip = addr1;
21482 + return 2;
21483 + }
21484 + } while (0);
21485 +
21486 + return 1; /* PaX in action */
21487 +}
21488 +#endif
21489 +
21490 +/*
21491 + * PaX: decide what to do with offenders (regs->ip = fault address)
21492 + *
21493 + * returns 1 when task should be killed
21494 + * 2 when gcc trampoline was detected
21495 + */
21496 +static int pax_handle_fetch_fault(struct pt_regs *regs)
21497 +{
21498 + if (v8086_mode(regs))
21499 + return 1;
21500 +
21501 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
21502 + return 1;
21503 +
21504 +#ifdef CONFIG_X86_32
21505 + return pax_handle_fetch_fault_32(regs);
21506 +#else
21507 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
21508 + return pax_handle_fetch_fault_32(regs);
21509 + else
21510 + return pax_handle_fetch_fault_64(regs);
21511 +#endif
21512 +}
21513 +#endif
21514 +
21515 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
21516 +void pax_report_insns(void *pc, void *sp)
21517 +{
21518 + long i;
21519 +
21520 + printk(KERN_ERR "PAX: bytes at PC: ");
21521 + for (i = 0; i < 20; i++) {
21522 + unsigned char c;
21523 + if (get_user(c, (__force unsigned char __user *)pc+i))
21524 + printk(KERN_CONT "?? ");
21525 + else
21526 + printk(KERN_CONT "%02x ", c);
21527 + }
21528 + printk("\n");
21529 +
21530 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
21531 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
21532 + unsigned long c;
21533 + if (get_user(c, (__force unsigned long __user *)sp+i))
21534 +#ifdef CONFIG_X86_32
21535 + printk(KERN_CONT "???????? ");
21536 +#else
21537 + printk(KERN_CONT "???????????????? ");
21538 +#endif
21539 + else
21540 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
21541 + }
21542 + printk("\n");
21543 +}
21544 +#endif
21545 +
21546 +/**
21547 + * probe_kernel_write(): safely attempt to write to a location
21548 + * @dst: address to write to
21549 + * @src: pointer to the data that shall be written
21550 + * @size: size of the data chunk
21551 + *
21552 + * Safely write to address @dst from the buffer at @src. If a kernel fault
21553 + * happens, handle that and return -EFAULT.
21554 + */
21555 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
21556 +{
21557 + long ret;
21558 + mm_segment_t old_fs = get_fs();
21559 +
21560 + set_fs(KERNEL_DS);
21561 + pagefault_disable();
21562 + pax_open_kernel();
21563 + ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
21564 + pax_close_kernel();
21565 + pagefault_enable();
21566 + set_fs(old_fs);
21567 +
21568 + return ret ? -EFAULT : 0;
21569 +}
21570 diff -urNp linux-2.6.39/arch/x86/mm/gup.c linux-2.6.39/arch/x86/mm/gup.c
21571 --- linux-2.6.39/arch/x86/mm/gup.c 2011-05-19 00:06:34.000000000 -0400
21572 +++ linux-2.6.39/arch/x86/mm/gup.c 2011-05-22 19:36:30.000000000 -0400
21573 @@ -263,7 +263,7 @@ int __get_user_pages_fast(unsigned long
21574 addr = start;
21575 len = (unsigned long) nr_pages << PAGE_SHIFT;
21576 end = start + len;
21577 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
21578 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
21579 (void __user *)start, len)))
21580 return 0;
21581
21582 diff -urNp linux-2.6.39/arch/x86/mm/highmem_32.c linux-2.6.39/arch/x86/mm/highmem_32.c
21583 --- linux-2.6.39/arch/x86/mm/highmem_32.c 2011-05-19 00:06:34.000000000 -0400
21584 +++ linux-2.6.39/arch/x86/mm/highmem_32.c 2011-05-22 19:36:30.000000000 -0400
21585 @@ -44,7 +44,10 @@ void *kmap_atomic_prot(struct page *page
21586 idx = type + KM_TYPE_NR*smp_processor_id();
21587 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
21588 BUG_ON(!pte_none(*(kmap_pte-idx)));
21589 +
21590 + pax_open_kernel();
21591 set_pte(kmap_pte-idx, mk_pte(page, prot));
21592 + pax_close_kernel();
21593
21594 return (void *)vaddr;
21595 }
21596 diff -urNp linux-2.6.39/arch/x86/mm/hugetlbpage.c linux-2.6.39/arch/x86/mm/hugetlbpage.c
21597 --- linux-2.6.39/arch/x86/mm/hugetlbpage.c 2011-05-19 00:06:34.000000000 -0400
21598 +++ linux-2.6.39/arch/x86/mm/hugetlbpage.c 2011-05-22 19:36:30.000000000 -0400
21599 @@ -266,13 +266,20 @@ static unsigned long hugetlb_get_unmappe
21600 struct hstate *h = hstate_file(file);
21601 struct mm_struct *mm = current->mm;
21602 struct vm_area_struct *vma;
21603 - unsigned long start_addr;
21604 + unsigned long start_addr, pax_task_size = TASK_SIZE;
21605 +
21606 +#ifdef CONFIG_PAX_SEGMEXEC
21607 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
21608 + pax_task_size = SEGMEXEC_TASK_SIZE;
21609 +#endif
21610 +
21611 + pax_task_size -= PAGE_SIZE;
21612
21613 if (len > mm->cached_hole_size) {
21614 - start_addr = mm->free_area_cache;
21615 + start_addr = mm->free_area_cache;
21616 } else {
21617 - start_addr = TASK_UNMAPPED_BASE;
21618 - mm->cached_hole_size = 0;
21619 + start_addr = mm->mmap_base;
21620 + mm->cached_hole_size = 0;
21621 }
21622
21623 full_search:
21624 @@ -280,26 +287,27 @@ full_search:
21625
21626 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
21627 /* At this point: (!vma || addr < vma->vm_end). */
21628 - if (TASK_SIZE - len < addr) {
21629 + if (pax_task_size - len < addr) {
21630 /*
21631 * Start a new search - just in case we missed
21632 * some holes.
21633 */
21634 - if (start_addr != TASK_UNMAPPED_BASE) {
21635 - start_addr = TASK_UNMAPPED_BASE;
21636 + if (start_addr != mm->mmap_base) {
21637 + start_addr = mm->mmap_base;
21638 mm->cached_hole_size = 0;
21639 goto full_search;
21640 }
21641 return -ENOMEM;
21642 }
21643 - if (!vma || addr + len <= vma->vm_start) {
21644 - mm->free_area_cache = addr + len;
21645 - return addr;
21646 - }
21647 + if (check_heap_stack_gap(vma, addr, len))
21648 + break;
21649 if (addr + mm->cached_hole_size < vma->vm_start)
21650 mm->cached_hole_size = vma->vm_start - addr;
21651 addr = ALIGN(vma->vm_end, huge_page_size(h));
21652 }
21653 +
21654 + mm->free_area_cache = addr + len;
21655 + return addr;
21656 }
21657
21658 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
21659 @@ -308,10 +316,9 @@ static unsigned long hugetlb_get_unmappe
21660 {
21661 struct hstate *h = hstate_file(file);
21662 struct mm_struct *mm = current->mm;
21663 - struct vm_area_struct *vma, *prev_vma;
21664 - unsigned long base = mm->mmap_base, addr = addr0;
21665 + struct vm_area_struct *vma;
21666 + unsigned long base = mm->mmap_base, addr;
21667 unsigned long largest_hole = mm->cached_hole_size;
21668 - int first_time = 1;
21669
21670 /* don't allow allocations above current base */
21671 if (mm->free_area_cache > base)
21672 @@ -321,64 +328,63 @@ static unsigned long hugetlb_get_unmappe
21673 largest_hole = 0;
21674 mm->free_area_cache = base;
21675 }
21676 -try_again:
21677 +
21678 /* make sure it can fit in the remaining address space */
21679 if (mm->free_area_cache < len)
21680 goto fail;
21681
21682 /* either no address requested or can't fit in requested address hole */
21683 - addr = (mm->free_area_cache - len) & huge_page_mask(h);
21684 + addr = (mm->free_area_cache - len);
21685 do {
21686 + addr &= huge_page_mask(h);
21687 + vma = find_vma(mm, addr);
21688 /*
21689 * Lookup failure means no vma is above this address,
21690 * i.e. return with success:
21691 - */
21692 - if (!(vma = find_vma_prev(mm, addr, &prev_vma)))
21693 - return addr;
21694 -
21695 - /*
21696 * new region fits between prev_vma->vm_end and
21697 * vma->vm_start, use it:
21698 */
21699 - if (addr + len <= vma->vm_start &&
21700 - (!prev_vma || (addr >= prev_vma->vm_end))) {
21701 + if (check_heap_stack_gap(vma, addr, len)) {
21702 /* remember the address as a hint for next time */
21703 - mm->cached_hole_size = largest_hole;
21704 - return (mm->free_area_cache = addr);
21705 - } else {
21706 - /* pull free_area_cache down to the first hole */
21707 - if (mm->free_area_cache == vma->vm_end) {
21708 - mm->free_area_cache = vma->vm_start;
21709 - mm->cached_hole_size = largest_hole;
21710 - }
21711 + mm->cached_hole_size = largest_hole;
21712 + return (mm->free_area_cache = addr);
21713 + }
21714 + /* pull free_area_cache down to the first hole */
21715 + if (mm->free_area_cache == vma->vm_end) {
21716 + mm->free_area_cache = vma->vm_start;
21717 + mm->cached_hole_size = largest_hole;
21718 }
21719
21720 /* remember the largest hole we saw so far */
21721 if (addr + largest_hole < vma->vm_start)
21722 - largest_hole = vma->vm_start - addr;
21723 + largest_hole = vma->vm_start - addr;
21724
21725 /* try just below the current vma->vm_start */
21726 - addr = (vma->vm_start - len) & huge_page_mask(h);
21727 - } while (len <= vma->vm_start);
21728 + addr = skip_heap_stack_gap(vma, len);
21729 + } while (!IS_ERR_VALUE(addr));
21730
21731 fail:
21732 /*
21733 - * if hint left us with no space for the requested
21734 - * mapping then try again:
21735 - */
21736 - if (first_time) {
21737 - mm->free_area_cache = base;
21738 - largest_hole = 0;
21739 - first_time = 0;
21740 - goto try_again;
21741 - }
21742 - /*
21743 * A failed mmap() very likely causes application failure,
21744 * so fall back to the bottom-up function here. This scenario
21745 * can happen with large stack limits and large mmap()
21746 * allocations.
21747 */
21748 - mm->free_area_cache = TASK_UNMAPPED_BASE;
21749 +
21750 +#ifdef CONFIG_PAX_SEGMEXEC
21751 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
21752 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
21753 + else
21754 +#endif
21755 +
21756 + mm->mmap_base = TASK_UNMAPPED_BASE;
21757 +
21758 +#ifdef CONFIG_PAX_RANDMMAP
21759 + if (mm->pax_flags & MF_PAX_RANDMMAP)
21760 + mm->mmap_base += mm->delta_mmap;
21761 +#endif
21762 +
21763 + mm->free_area_cache = mm->mmap_base;
21764 mm->cached_hole_size = ~0UL;
21765 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
21766 len, pgoff, flags);
21767 @@ -386,6 +392,7 @@ fail:
21768 /*
21769 * Restore the topdown base:
21770 */
21771 + mm->mmap_base = base;
21772 mm->free_area_cache = base;
21773 mm->cached_hole_size = ~0UL;
21774
21775 @@ -399,10 +406,19 @@ hugetlb_get_unmapped_area(struct file *f
21776 struct hstate *h = hstate_file(file);
21777 struct mm_struct *mm = current->mm;
21778 struct vm_area_struct *vma;
21779 + unsigned long pax_task_size = TASK_SIZE;
21780
21781 if (len & ~huge_page_mask(h))
21782 return -EINVAL;
21783 - if (len > TASK_SIZE)
21784 +
21785 +#ifdef CONFIG_PAX_SEGMEXEC
21786 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
21787 + pax_task_size = SEGMEXEC_TASK_SIZE;
21788 +#endif
21789 +
21790 + pax_task_size -= PAGE_SIZE;
21791 +
21792 + if (len > pax_task_size)
21793 return -ENOMEM;
21794
21795 if (flags & MAP_FIXED) {
21796 @@ -414,8 +430,7 @@ hugetlb_get_unmapped_area(struct file *f
21797 if (addr) {
21798 addr = ALIGN(addr, huge_page_size(h));
21799 vma = find_vma(mm, addr);
21800 - if (TASK_SIZE - len >= addr &&
21801 - (!vma || addr + len <= vma->vm_start))
21802 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
21803 return addr;
21804 }
21805 if (mm->get_unmapped_area == arch_get_unmapped_area)
21806 diff -urNp linux-2.6.39/arch/x86/mm/init_32.c linux-2.6.39/arch/x86/mm/init_32.c
21807 --- linux-2.6.39/arch/x86/mm/init_32.c 2011-05-19 00:06:34.000000000 -0400
21808 +++ linux-2.6.39/arch/x86/mm/init_32.c 2011-05-22 19:36:30.000000000 -0400
21809 @@ -74,36 +74,6 @@ static __init void *alloc_low_page(void)
21810 }
21811
21812 /*
21813 - * Creates a middle page table and puts a pointer to it in the
21814 - * given global directory entry. This only returns the gd entry
21815 - * in non-PAE compilation mode, since the middle layer is folded.
21816 - */
21817 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
21818 -{
21819 - pud_t *pud;
21820 - pmd_t *pmd_table;
21821 -
21822 -#ifdef CONFIG_X86_PAE
21823 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
21824 - if (after_bootmem)
21825 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
21826 - else
21827 - pmd_table = (pmd_t *)alloc_low_page();
21828 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
21829 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
21830 - pud = pud_offset(pgd, 0);
21831 - BUG_ON(pmd_table != pmd_offset(pud, 0));
21832 -
21833 - return pmd_table;
21834 - }
21835 -#endif
21836 - pud = pud_offset(pgd, 0);
21837 - pmd_table = pmd_offset(pud, 0);
21838 -
21839 - return pmd_table;
21840 -}
21841 -
21842 -/*
21843 * Create a page table and place a pointer to it in a middle page
21844 * directory entry:
21845 */
21846 @@ -123,13 +93,28 @@ static pte_t * __init one_page_table_ini
21847 page_table = (pte_t *)alloc_low_page();
21848
21849 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
21850 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
21851 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
21852 +#else
21853 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
21854 +#endif
21855 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
21856 }
21857
21858 return pte_offset_kernel(pmd, 0);
21859 }
21860
21861 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
21862 +{
21863 + pud_t *pud;
21864 + pmd_t *pmd_table;
21865 +
21866 + pud = pud_offset(pgd, 0);
21867 + pmd_table = pmd_offset(pud, 0);
21868 +
21869 + return pmd_table;
21870 +}
21871 +
21872 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
21873 {
21874 int pgd_idx = pgd_index(vaddr);
21875 @@ -203,6 +188,7 @@ page_table_range_init(unsigned long star
21876 int pgd_idx, pmd_idx;
21877 unsigned long vaddr;
21878 pgd_t *pgd;
21879 + pud_t *pud;
21880 pmd_t *pmd;
21881 pte_t *pte = NULL;
21882
21883 @@ -212,8 +198,13 @@ page_table_range_init(unsigned long star
21884 pgd = pgd_base + pgd_idx;
21885
21886 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
21887 - pmd = one_md_table_init(pgd);
21888 - pmd = pmd + pmd_index(vaddr);
21889 + pud = pud_offset(pgd, vaddr);
21890 + pmd = pmd_offset(pud, vaddr);
21891 +
21892 +#ifdef CONFIG_X86_PAE
21893 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
21894 +#endif
21895 +
21896 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
21897 pmd++, pmd_idx++) {
21898 pte = page_table_kmap_check(one_page_table_init(pmd),
21899 @@ -225,11 +216,20 @@ page_table_range_init(unsigned long star
21900 }
21901 }
21902
21903 -static inline int is_kernel_text(unsigned long addr)
21904 +static inline int is_kernel_text(unsigned long start, unsigned long end)
21905 {
21906 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
21907 - return 1;
21908 - return 0;
21909 + if ((start > ktla_ktva((unsigned long)_etext) ||
21910 + end <= ktla_ktva((unsigned long)_stext)) &&
21911 + (start > ktla_ktva((unsigned long)_einittext) ||
21912 + end <= ktla_ktva((unsigned long)_sinittext)) &&
21913 +
21914 +#ifdef CONFIG_ACPI_SLEEP
21915 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
21916 +#endif
21917 +
21918 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
21919 + return 0;
21920 + return 1;
21921 }
21922
21923 /*
21924 @@ -246,9 +246,10 @@ kernel_physical_mapping_init(unsigned lo
21925 unsigned long last_map_addr = end;
21926 unsigned long start_pfn, end_pfn;
21927 pgd_t *pgd_base = swapper_pg_dir;
21928 - int pgd_idx, pmd_idx, pte_ofs;
21929 + unsigned int pgd_idx, pmd_idx, pte_ofs;
21930 unsigned long pfn;
21931 pgd_t *pgd;
21932 + pud_t *pud;
21933 pmd_t *pmd;
21934 pte_t *pte;
21935 unsigned pages_2m, pages_4k;
21936 @@ -281,8 +282,13 @@ repeat:
21937 pfn = start_pfn;
21938 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
21939 pgd = pgd_base + pgd_idx;
21940 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
21941 - pmd = one_md_table_init(pgd);
21942 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
21943 + pud = pud_offset(pgd, 0);
21944 + pmd = pmd_offset(pud, 0);
21945 +
21946 +#ifdef CONFIG_X86_PAE
21947 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
21948 +#endif
21949
21950 if (pfn >= end_pfn)
21951 continue;
21952 @@ -294,14 +300,13 @@ repeat:
21953 #endif
21954 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
21955 pmd++, pmd_idx++) {
21956 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
21957 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
21958
21959 /*
21960 * Map with big pages if possible, otherwise
21961 * create normal page tables:
21962 */
21963 if (use_pse) {
21964 - unsigned int addr2;
21965 pgprot_t prot = PAGE_KERNEL_LARGE;
21966 /*
21967 * first pass will use the same initial
21968 @@ -311,11 +316,7 @@ repeat:
21969 __pgprot(PTE_IDENT_ATTR |
21970 _PAGE_PSE);
21971
21972 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
21973 - PAGE_OFFSET + PAGE_SIZE-1;
21974 -
21975 - if (is_kernel_text(addr) ||
21976 - is_kernel_text(addr2))
21977 + if (is_kernel_text(address, address + PMD_SIZE))
21978 prot = PAGE_KERNEL_LARGE_EXEC;
21979
21980 pages_2m++;
21981 @@ -332,7 +333,7 @@ repeat:
21982 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
21983 pte += pte_ofs;
21984 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
21985 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
21986 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
21987 pgprot_t prot = PAGE_KERNEL;
21988 /*
21989 * first pass will use the same initial
21990 @@ -340,7 +341,7 @@ repeat:
21991 */
21992 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
21993
21994 - if (is_kernel_text(addr))
21995 + if (is_kernel_text(address, address + PAGE_SIZE))
21996 prot = PAGE_KERNEL_EXEC;
21997
21998 pages_4k++;
21999 @@ -472,7 +473,7 @@ void __init native_pagetable_setup_start
22000
22001 pud = pud_offset(pgd, va);
22002 pmd = pmd_offset(pud, va);
22003 - if (!pmd_present(*pmd))
22004 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
22005 break;
22006
22007 pte = pte_offset_kernel(pmd, va);
22008 @@ -524,12 +525,10 @@ void __init early_ioremap_page_table_ran
22009
22010 static void __init pagetable_init(void)
22011 {
22012 - pgd_t *pgd_base = swapper_pg_dir;
22013 -
22014 - permanent_kmaps_init(pgd_base);
22015 + permanent_kmaps_init(swapper_pg_dir);
22016 }
22017
22018 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
22019 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
22020 EXPORT_SYMBOL_GPL(__supported_pte_mask);
22021
22022 /* user-defined highmem size */
22023 @@ -754,6 +753,12 @@ void __init mem_init(void)
22024
22025 pci_iommu_alloc();
22026
22027 +#ifdef CONFIG_PAX_PER_CPU_PGD
22028 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
22029 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
22030 + KERNEL_PGD_PTRS);
22031 +#endif
22032 +
22033 #ifdef CONFIG_FLATMEM
22034 BUG_ON(!mem_map);
22035 #endif
22036 @@ -771,7 +776,7 @@ void __init mem_init(void)
22037 set_highmem_pages_init();
22038
22039 codesize = (unsigned long) &_etext - (unsigned long) &_text;
22040 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
22041 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
22042 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
22043
22044 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
22045 @@ -812,10 +817,10 @@ void __init mem_init(void)
22046 ((unsigned long)&__init_end -
22047 (unsigned long)&__init_begin) >> 10,
22048
22049 - (unsigned long)&_etext, (unsigned long)&_edata,
22050 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
22051 + (unsigned long)&_sdata, (unsigned long)&_edata,
22052 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
22053
22054 - (unsigned long)&_text, (unsigned long)&_etext,
22055 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
22056 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
22057
22058 /*
22059 @@ -893,6 +898,7 @@ void set_kernel_text_rw(void)
22060 if (!kernel_set_to_readonly)
22061 return;
22062
22063 + start = ktla_ktva(start);
22064 pr_debug("Set kernel text: %lx - %lx for read write\n",
22065 start, start+size);
22066
22067 @@ -907,6 +913,7 @@ void set_kernel_text_ro(void)
22068 if (!kernel_set_to_readonly)
22069 return;
22070
22071 + start = ktla_ktva(start);
22072 pr_debug("Set kernel text: %lx - %lx for read only\n",
22073 start, start+size);
22074
22075 @@ -935,6 +942,7 @@ void mark_rodata_ro(void)
22076 unsigned long start = PFN_ALIGN(_text);
22077 unsigned long size = PFN_ALIGN(_etext) - start;
22078
22079 + start = ktla_ktva(start);
22080 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
22081 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
22082 size >> 10);
22083 diff -urNp linux-2.6.39/arch/x86/mm/init_64.c linux-2.6.39/arch/x86/mm/init_64.c
22084 --- linux-2.6.39/arch/x86/mm/init_64.c 2011-05-19 00:06:34.000000000 -0400
22085 +++ linux-2.6.39/arch/x86/mm/init_64.c 2011-05-22 19:36:30.000000000 -0400
22086 @@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpa
22087 * around without checking the pgd every time.
22088 */
22089
22090 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
22091 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
22092 EXPORT_SYMBOL_GPL(__supported_pte_mask);
22093
22094 int force_personality32;
22095 @@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long star
22096
22097 for (address = start; address <= end; address += PGDIR_SIZE) {
22098 const pgd_t *pgd_ref = pgd_offset_k(address);
22099 +
22100 +#ifdef CONFIG_PAX_PER_CPU_PGD
22101 + unsigned long cpu;
22102 +#else
22103 struct page *page;
22104 +#endif
22105
22106 if (pgd_none(*pgd_ref))
22107 continue;
22108
22109 spin_lock(&pgd_lock);
22110 +
22111 +#ifdef CONFIG_PAX_PER_CPU_PGD
22112 + for (cpu = 0; cpu < NR_CPUS; ++cpu) {
22113 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
22114 +#else
22115 list_for_each_entry(page, &pgd_list, lru) {
22116 pgd_t *pgd;
22117 spinlock_t *pgt_lock;
22118 @@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long star
22119 /* the pgt_lock only for Xen */
22120 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
22121 spin_lock(pgt_lock);
22122 +#endif
22123
22124 if (pgd_none(*pgd))
22125 set_pgd(pgd, *pgd_ref);
22126 @@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long star
22127 BUG_ON(pgd_page_vaddr(*pgd)
22128 != pgd_page_vaddr(*pgd_ref));
22129
22130 +#ifndef CONFIG_PAX_PER_CPU_PGD
22131 spin_unlock(pgt_lock);
22132 +#endif
22133 +
22134 }
22135 spin_unlock(&pgd_lock);
22136 }
22137 @@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page,
22138 pmd = fill_pmd(pud, vaddr);
22139 pte = fill_pte(pmd, vaddr);
22140
22141 + pax_open_kernel();
22142 set_pte(pte, new_pte);
22143 + pax_close_kernel();
22144
22145 /*
22146 * It's enough to flush this one mapping.
22147 @@ -261,14 +277,12 @@ static void __init __init_extra_mapping(
22148 pgd = pgd_offset_k((unsigned long)__va(phys));
22149 if (pgd_none(*pgd)) {
22150 pud = (pud_t *) spp_getpage();
22151 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
22152 - _PAGE_USER));
22153 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
22154 }
22155 pud = pud_offset(pgd, (unsigned long)__va(phys));
22156 if (pud_none(*pud)) {
22157 pmd = (pmd_t *) spp_getpage();
22158 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
22159 - _PAGE_USER));
22160 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
22161 }
22162 pmd = pmd_offset(pud, phys);
22163 BUG_ON(!pmd_none(*pmd));
22164 @@ -698,6 +712,12 @@ void __init mem_init(void)
22165
22166 pci_iommu_alloc();
22167
22168 +#ifdef CONFIG_PAX_PER_CPU_PGD
22169 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
22170 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
22171 + KERNEL_PGD_PTRS);
22172 +#endif
22173 +
22174 /* clear_bss() already clear the empty_zero_page */
22175
22176 reservedpages = 0;
22177 @@ -858,8 +878,8 @@ int kern_addr_valid(unsigned long addr)
22178 static struct vm_area_struct gate_vma = {
22179 .vm_start = VSYSCALL_START,
22180 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
22181 - .vm_page_prot = PAGE_READONLY_EXEC,
22182 - .vm_flags = VM_READ | VM_EXEC
22183 + .vm_page_prot = PAGE_READONLY,
22184 + .vm_flags = VM_READ
22185 };
22186
22187 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
22188 @@ -893,7 +913,7 @@ int in_gate_area_no_mm(unsigned long add
22189
22190 const char *arch_vma_name(struct vm_area_struct *vma)
22191 {
22192 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
22193 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
22194 return "[vdso]";
22195 if (vma == &gate_vma)
22196 return "[vsyscall]";
22197 diff -urNp linux-2.6.39/arch/x86/mm/init.c linux-2.6.39/arch/x86/mm/init.c
22198 --- linux-2.6.39/arch/x86/mm/init.c 2011-05-19 00:06:34.000000000 -0400
22199 +++ linux-2.6.39/arch/x86/mm/init.c 2011-05-23 19:01:08.000000000 -0400
22200 @@ -33,7 +33,7 @@ int direct_gbpages
22201 static void __init find_early_table_space(unsigned long end, int use_pse,
22202 int use_gbpages)
22203 {
22204 - unsigned long puds, pmds, ptes, tables, start = 0, good_end = end;
22205 + unsigned long puds, pmds, ptes, tables, start = 0x100000, good_end = end;
22206 phys_addr_t base;
22207
22208 puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
22209 @@ -315,12 +315,25 @@ unsigned long __init_refok init_memory_m
22210 */
22211 int devmem_is_allowed(unsigned long pagenr)
22212 {
22213 - if (pagenr <= 256)
22214 +#ifndef CONFIG_GRKERNSEC_KMEM
22215 + if (!pagenr)
22216 + return 1;
22217 +#ifdef CONFIG_VM86
22218 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
22219 + return 1;
22220 +#endif
22221 +#else
22222 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
22223 + return 0;
22224 +#endif
22225 +
22226 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
22227 return 1;
22228 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
22229 return 0;
22230 if (!page_is_ram(pagenr))
22231 return 1;
22232 +
22233 return 0;
22234 }
22235
22236 @@ -375,6 +388,86 @@ void free_init_pages(char *what, unsigne
22237
22238 void free_initmem(void)
22239 {
22240 +
22241 +#ifdef CONFIG_PAX_KERNEXEC
22242 +#ifdef CONFIG_X86_32
22243 + /* PaX: limit KERNEL_CS to actual size */
22244 + unsigned long addr, limit;
22245 + struct desc_struct d;
22246 + int cpu;
22247 +
22248 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
22249 + limit = (limit - 1UL) >> PAGE_SHIFT;
22250 +
22251 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
22252 + for (cpu = 0; cpu < NR_CPUS; cpu++) {
22253 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
22254 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
22255 + }
22256 +
22257 + /* PaX: make KERNEL_CS read-only */
22258 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
22259 + if (!paravirt_enabled())
22260 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
22261 +/*
22262 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
22263 + pgd = pgd_offset_k(addr);
22264 + pud = pud_offset(pgd, addr);
22265 + pmd = pmd_offset(pud, addr);
22266 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
22267 + }
22268 +*/
22269 +#ifdef CONFIG_X86_PAE
22270 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
22271 +/*
22272 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
22273 + pgd = pgd_offset_k(addr);
22274 + pud = pud_offset(pgd, addr);
22275 + pmd = pmd_offset(pud, addr);
22276 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
22277 + }
22278 +*/
22279 +#endif
22280 +
22281 +#ifdef CONFIG_MODULES
22282 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
22283 +#endif
22284 +
22285 +#else
22286 + pgd_t *pgd;
22287 + pud_t *pud;
22288 + pmd_t *pmd;
22289 + unsigned long addr, end;
22290 +
22291 + /* PaX: make kernel code/rodata read-only, rest non-executable */
22292 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
22293 + pgd = pgd_offset_k(addr);
22294 + pud = pud_offset(pgd, addr);
22295 + pmd = pmd_offset(pud, addr);
22296 + if (!pmd_present(*pmd))
22297 + continue;
22298 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
22299 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
22300 + else
22301 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
22302 + }
22303 +
22304 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
22305 + end = addr + KERNEL_IMAGE_SIZE;
22306 + for (; addr < end; addr += PMD_SIZE) {
22307 + pgd = pgd_offset_k(addr);
22308 + pud = pud_offset(pgd, addr);
22309 + pmd = pmd_offset(pud, addr);
22310 + if (!pmd_present(*pmd))
22311 + continue;
22312 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
22313 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
22314 + }
22315 +#endif
22316 +
22317 + flush_tlb_all();
22318 +#endif
22319 +
22320 free_init_pages("unused kernel memory",
22321 (unsigned long)(&__init_begin),
22322 (unsigned long)(&__init_end));
22323 diff -urNp linux-2.6.39/arch/x86/mm/iomap_32.c linux-2.6.39/arch/x86/mm/iomap_32.c
22324 --- linux-2.6.39/arch/x86/mm/iomap_32.c 2011-05-19 00:06:34.000000000 -0400
22325 +++ linux-2.6.39/arch/x86/mm/iomap_32.c 2011-05-22 19:36:30.000000000 -0400
22326 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long
22327 type = kmap_atomic_idx_push();
22328 idx = type + KM_TYPE_NR * smp_processor_id();
22329 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
22330 +
22331 + pax_open_kernel();
22332 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
22333 + pax_close_kernel();
22334 +
22335 arch_flush_lazy_mmu_mode();
22336
22337 return (void *)vaddr;
22338 diff -urNp linux-2.6.39/arch/x86/mm/ioremap.c linux-2.6.39/arch/x86/mm/ioremap.c
22339 --- linux-2.6.39/arch/x86/mm/ioremap.c 2011-05-19 00:06:34.000000000 -0400
22340 +++ linux-2.6.39/arch/x86/mm/ioremap.c 2011-05-22 19:36:30.000000000 -0400
22341 @@ -104,7 +104,7 @@ static void __iomem *__ioremap_caller(re
22342 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
22343 int is_ram = page_is_ram(pfn);
22344
22345 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
22346 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
22347 return NULL;
22348 WARN_ON_ONCE(is_ram);
22349 }
22350 @@ -344,7 +344,7 @@ static int __init early_ioremap_debug_se
22351 early_param("early_ioremap_debug", early_ioremap_debug_setup);
22352
22353 static __initdata int after_paging_init;
22354 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
22355 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
22356
22357 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
22358 {
22359 @@ -381,8 +381,7 @@ void __init early_ioremap_init(void)
22360 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
22361
22362 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
22363 - memset(bm_pte, 0, sizeof(bm_pte));
22364 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
22365 + pmd_populate_user(&init_mm, pmd, bm_pte);
22366
22367 /*
22368 * The boot-ioremap range spans multiple pmds, for which
22369 diff -urNp linux-2.6.39/arch/x86/mm/kmemcheck/kmemcheck.c linux-2.6.39/arch/x86/mm/kmemcheck/kmemcheck.c
22370 --- linux-2.6.39/arch/x86/mm/kmemcheck/kmemcheck.c 2011-05-19 00:06:34.000000000 -0400
22371 +++ linux-2.6.39/arch/x86/mm/kmemcheck/kmemcheck.c 2011-05-22 19:36:30.000000000 -0400
22372 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *reg
22373 * memory (e.g. tracked pages)? For now, we need this to avoid
22374 * invoking kmemcheck for PnP BIOS calls.
22375 */
22376 - if (regs->flags & X86_VM_MASK)
22377 + if (v8086_mode(regs))
22378 return false;
22379 - if (regs->cs != __KERNEL_CS)
22380 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
22381 return false;
22382
22383 pte = kmemcheck_pte_lookup(address);
22384 diff -urNp linux-2.6.39/arch/x86/mm/mmap.c linux-2.6.39/arch/x86/mm/mmap.c
22385 --- linux-2.6.39/arch/x86/mm/mmap.c 2011-05-19 00:06:34.000000000 -0400
22386 +++ linux-2.6.39/arch/x86/mm/mmap.c 2011-05-22 19:36:30.000000000 -0400
22387 @@ -49,7 +49,7 @@ static unsigned int stack_maxrandom_size
22388 * Leave an at least ~128 MB hole with possible stack randomization.
22389 */
22390 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
22391 -#define MAX_GAP (TASK_SIZE/6*5)
22392 +#define MAX_GAP (pax_task_size/6*5)
22393
22394 /*
22395 * True on X86_32 or when emulating IA32 on X86_64
22396 @@ -94,27 +94,40 @@ static unsigned long mmap_rnd(void)
22397 return rnd << PAGE_SHIFT;
22398 }
22399
22400 -static unsigned long mmap_base(void)
22401 +static unsigned long mmap_base(struct mm_struct *mm)
22402 {
22403 unsigned long gap = rlimit(RLIMIT_STACK);
22404 + unsigned long pax_task_size = TASK_SIZE;
22405 +
22406 +#ifdef CONFIG_PAX_SEGMEXEC
22407 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
22408 + pax_task_size = SEGMEXEC_TASK_SIZE;
22409 +#endif
22410
22411 if (gap < MIN_GAP)
22412 gap = MIN_GAP;
22413 else if (gap > MAX_GAP)
22414 gap = MAX_GAP;
22415
22416 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
22417 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
22418 }
22419
22420 /*
22421 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
22422 * does, but not when emulating X86_32
22423 */
22424 -static unsigned long mmap_legacy_base(void)
22425 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
22426 {
22427 - if (mmap_is_ia32())
22428 + if (mmap_is_ia32()) {
22429 +
22430 +#ifdef CONFIG_PAX_SEGMEXEC
22431 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
22432 + return SEGMEXEC_TASK_UNMAPPED_BASE;
22433 + else
22434 +#endif
22435 +
22436 return TASK_UNMAPPED_BASE;
22437 - else
22438 + } else
22439 return TASK_UNMAPPED_BASE + mmap_rnd();
22440 }
22441
22442 @@ -125,11 +138,23 @@ static unsigned long mmap_legacy_base(vo
22443 void arch_pick_mmap_layout(struct mm_struct *mm)
22444 {
22445 if (mmap_is_legacy()) {
22446 - mm->mmap_base = mmap_legacy_base();
22447 + mm->mmap_base = mmap_legacy_base(mm);
22448 +
22449 +#ifdef CONFIG_PAX_RANDMMAP
22450 + if (mm->pax_flags & MF_PAX_RANDMMAP)
22451 + mm->mmap_base += mm->delta_mmap;
22452 +#endif
22453 +
22454 mm->get_unmapped_area = arch_get_unmapped_area;
22455 mm->unmap_area = arch_unmap_area;
22456 } else {
22457 - mm->mmap_base = mmap_base();
22458 + mm->mmap_base = mmap_base(mm);
22459 +
22460 +#ifdef CONFIG_PAX_RANDMMAP
22461 + if (mm->pax_flags & MF_PAX_RANDMMAP)
22462 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
22463 +#endif
22464 +
22465 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
22466 mm->unmap_area = arch_unmap_area_topdown;
22467 }
22468 diff -urNp linux-2.6.39/arch/x86/mm/mmio-mod.c linux-2.6.39/arch/x86/mm/mmio-mod.c
22469 --- linux-2.6.39/arch/x86/mm/mmio-mod.c 2011-05-19 00:06:34.000000000 -0400
22470 +++ linux-2.6.39/arch/x86/mm/mmio-mod.c 2011-05-22 19:36:30.000000000 -0400
22471 @@ -235,7 +235,7 @@ static void post(struct kmmio_probe *p,
22472 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
22473 void __iomem *addr)
22474 {
22475 - static atomic_t next_id;
22476 + static atomic_unchecked_t next_id;
22477 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
22478 /* These are page-unaligned. */
22479 struct mmiotrace_map map = {
22480 @@ -259,7 +259,7 @@ static void ioremap_trace_core(resource_
22481 .private = trace
22482 },
22483 .phys = offset,
22484 - .id = atomic_inc_return(&next_id)
22485 + .id = atomic_inc_return_unchecked(&next_id)
22486 };
22487 map.map_id = trace->id;
22488
22489 diff -urNp linux-2.6.39/arch/x86/mm/numa_32.c linux-2.6.39/arch/x86/mm/numa_32.c
22490 --- linux-2.6.39/arch/x86/mm/numa_32.c 2011-05-19 00:06:34.000000000 -0400
22491 +++ linux-2.6.39/arch/x86/mm/numa_32.c 2011-05-22 19:36:30.000000000 -0400
22492 @@ -99,7 +99,6 @@ unsigned long node_memmap_size_bytes(int
22493 }
22494 #endif
22495
22496 -extern unsigned long find_max_low_pfn(void);
22497 extern unsigned long highend_pfn, highstart_pfn;
22498
22499 #define LARGE_PAGE_BYTES (PTRS_PER_PTE * PAGE_SIZE)
22500 diff -urNp linux-2.6.39/arch/x86/mm/pageattr.c linux-2.6.39/arch/x86/mm/pageattr.c
22501 --- linux-2.6.39/arch/x86/mm/pageattr.c 2011-05-19 00:06:34.000000000 -0400
22502 +++ linux-2.6.39/arch/x86/mm/pageattr.c 2011-05-22 19:36:30.000000000 -0400
22503 @@ -261,7 +261,7 @@ static inline pgprot_t static_protection
22504 */
22505 #ifdef CONFIG_PCI_BIOS
22506 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
22507 - pgprot_val(forbidden) |= _PAGE_NX;
22508 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
22509 #endif
22510
22511 /*
22512 @@ -269,9 +269,10 @@ static inline pgprot_t static_protection
22513 * Does not cover __inittext since that is gone later on. On
22514 * 64bit we do not enforce !NX on the low mapping
22515 */
22516 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
22517 - pgprot_val(forbidden) |= _PAGE_NX;
22518 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
22519 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
22520
22521 +#ifdef CONFIG_DEBUG_RODATA
22522 /*
22523 * The .rodata section needs to be read-only. Using the pfn
22524 * catches all aliases.
22525 @@ -279,6 +280,7 @@ static inline pgprot_t static_protection
22526 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
22527 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
22528 pgprot_val(forbidden) |= _PAGE_RW;
22529 +#endif
22530
22531 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
22532 /*
22533 @@ -317,6 +319,13 @@ static inline pgprot_t static_protection
22534 }
22535 #endif
22536
22537 +#ifdef CONFIG_PAX_KERNEXEC
22538 + if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
22539 + pgprot_val(forbidden) |= _PAGE_RW;
22540 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
22541 + }
22542 +#endif
22543 +
22544 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
22545
22546 return prot;
22547 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
22548 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
22549 {
22550 /* change init_mm */
22551 + pax_open_kernel();
22552 set_pte_atomic(kpte, pte);
22553 +
22554 #ifdef CONFIG_X86_32
22555 if (!SHARED_KERNEL_PMD) {
22556 +
22557 +#ifdef CONFIG_PAX_PER_CPU_PGD
22558 + unsigned long cpu;
22559 +#else
22560 struct page *page;
22561 +#endif
22562
22563 +#ifdef CONFIG_PAX_PER_CPU_PGD
22564 + for (cpu = 0; cpu < NR_CPUS; ++cpu) {
22565 + pgd_t *pgd = get_cpu_pgd(cpu);
22566 +#else
22567 list_for_each_entry(page, &pgd_list, lru) {
22568 - pgd_t *pgd;
22569 + pgd_t *pgd = (pgd_t *)page_address(page);
22570 +#endif
22571 +
22572 pud_t *pud;
22573 pmd_t *pmd;
22574
22575 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
22576 + pgd += pgd_index(address);
22577 pud = pud_offset(pgd, address);
22578 pmd = pmd_offset(pud, address);
22579 set_pte_atomic((pte_t *)pmd, pte);
22580 }
22581 }
22582 #endif
22583 + pax_close_kernel();
22584 }
22585
22586 static int
22587 diff -urNp linux-2.6.39/arch/x86/mm/pageattr-test.c linux-2.6.39/arch/x86/mm/pageattr-test.c
22588 --- linux-2.6.39/arch/x86/mm/pageattr-test.c 2011-05-19 00:06:34.000000000 -0400
22589 +++ linux-2.6.39/arch/x86/mm/pageattr-test.c 2011-05-22 19:36:30.000000000 -0400
22590 @@ -36,7 +36,7 @@ enum {
22591
22592 static int pte_testbit(pte_t pte)
22593 {
22594 - return pte_flags(pte) & _PAGE_UNUSED1;
22595 + return pte_flags(pte) & _PAGE_CPA_TEST;
22596 }
22597
22598 struct split_state {
22599 diff -urNp linux-2.6.39/arch/x86/mm/pat.c linux-2.6.39/arch/x86/mm/pat.c
22600 --- linux-2.6.39/arch/x86/mm/pat.c 2011-05-19 00:06:34.000000000 -0400
22601 +++ linux-2.6.39/arch/x86/mm/pat.c 2011-05-22 19:36:30.000000000 -0400
22602 @@ -361,7 +361,7 @@ int free_memtype(u64 start, u64 end)
22603
22604 if (!entry) {
22605 printk(KERN_INFO "%s:%d freeing invalid memtype %Lx-%Lx\n",
22606 - current->comm, current->pid, start, end);
22607 + current->comm, task_pid_nr(current), start, end);
22608 return -EINVAL;
22609 }
22610
22611 @@ -492,8 +492,8 @@ static inline int range_is_allowed(unsig
22612 while (cursor < to) {
22613 if (!devmem_is_allowed(pfn)) {
22614 printk(KERN_INFO
22615 - "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
22616 - current->comm, from, to);
22617 + "Program %s tried to access /dev/mem between %Lx->%Lx (%Lx).\n",
22618 + current->comm, from, to, cursor);
22619 return 0;
22620 }
22621 cursor += PAGE_SIZE;
22622 @@ -557,7 +557,7 @@ int kernel_map_sync_memtype(u64 base, un
22623 printk(KERN_INFO
22624 "%s:%d ioremap_change_attr failed %s "
22625 "for %Lx-%Lx\n",
22626 - current->comm, current->pid,
22627 + current->comm, task_pid_nr(current),
22628 cattr_name(flags),
22629 base, (unsigned long long)(base + size));
22630 return -EINVAL;
22631 @@ -593,7 +593,7 @@ static int reserve_pfn_range(u64 paddr,
22632 if (want_flags != flags) {
22633 printk(KERN_WARNING
22634 "%s:%d map pfn RAM range req %s for %Lx-%Lx, got %s\n",
22635 - current->comm, current->pid,
22636 + current->comm, task_pid_nr(current),
22637 cattr_name(want_flags),
22638 (unsigned long long)paddr,
22639 (unsigned long long)(paddr + size),
22640 @@ -615,7 +615,7 @@ static int reserve_pfn_range(u64 paddr,
22641 free_memtype(paddr, paddr + size);
22642 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
22643 " for %Lx-%Lx, got %s\n",
22644 - current->comm, current->pid,
22645 + current->comm, task_pid_nr(current),
22646 cattr_name(want_flags),
22647 (unsigned long long)paddr,
22648 (unsigned long long)(paddr + size),
22649 diff -urNp linux-2.6.39/arch/x86/mm/pgtable_32.c linux-2.6.39/arch/x86/mm/pgtable_32.c
22650 --- linux-2.6.39/arch/x86/mm/pgtable_32.c 2011-05-19 00:06:34.000000000 -0400
22651 +++ linux-2.6.39/arch/x86/mm/pgtable_32.c 2011-05-22 19:36:30.000000000 -0400
22652 @@ -48,10 +48,13 @@ void set_pte_vaddr(unsigned long vaddr,
22653 return;
22654 }
22655 pte = pte_offset_kernel(pmd, vaddr);
22656 +
22657 + pax_open_kernel();
22658 if (pte_val(pteval))
22659 set_pte_at(&init_mm, vaddr, pte, pteval);
22660 else
22661 pte_clear(&init_mm, vaddr, pte);
22662 + pax_close_kernel();
22663
22664 /*
22665 * It's enough to flush this one mapping.
22666 diff -urNp linux-2.6.39/arch/x86/mm/pgtable.c linux-2.6.39/arch/x86/mm/pgtable.c
22667 --- linux-2.6.39/arch/x86/mm/pgtable.c 2011-05-19 00:06:34.000000000 -0400
22668 +++ linux-2.6.39/arch/x86/mm/pgtable.c 2011-05-22 19:36:30.000000000 -0400
22669 @@ -84,10 +84,52 @@ static inline void pgd_list_del(pgd_t *p
22670 list_del(&page->lru);
22671 }
22672
22673 -#define UNSHARED_PTRS_PER_PGD \
22674 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
22675 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22676 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
22677
22678 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count)
22679 +{
22680 + while (count--)
22681 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
22682 +}
22683 +#endif
22684 +
22685 +#ifdef CONFIG_PAX_PER_CPU_PGD
22686 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count)
22687 +{
22688 + while (count--)
22689 +
22690 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22691 + *dst++ = __pgd(pgd_val(*src++) & clone_pgd_mask);
22692 +#else
22693 + *dst++ = *src++;
22694 +#endif
22695
22696 +}
22697 +#endif
22698 +
22699 +#ifdef CONFIG_X86_64
22700 +#define pxd_t pud_t
22701 +#define pyd_t pgd_t
22702 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
22703 +#define pxd_free(mm, pud) pud_free((mm), (pud))
22704 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
22705 +#define pyd_offset(mm ,address) pgd_offset((mm), (address))
22706 +#define PYD_SIZE PGDIR_SIZE
22707 +#else
22708 +#define pxd_t pmd_t
22709 +#define pyd_t pud_t
22710 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
22711 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
22712 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
22713 +#define pyd_offset(mm ,address) pud_offset((mm), (address))
22714 +#define PYD_SIZE PUD_SIZE
22715 +#endif
22716 +
22717 +#ifdef CONFIG_PAX_PER_CPU_PGD
22718 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
22719 +static inline void pgd_dtor(pgd_t *pgd) {}
22720 +#else
22721 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
22722 {
22723 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
22724 @@ -128,6 +170,7 @@ static void pgd_dtor(pgd_t *pgd)
22725 pgd_list_del(pgd);
22726 spin_unlock(&pgd_lock);
22727 }
22728 +#endif
22729
22730 /*
22731 * List of all pgd's needed for non-PAE so it can invalidate entries
22732 @@ -140,7 +183,7 @@ static void pgd_dtor(pgd_t *pgd)
22733 * -- wli
22734 */
22735
22736 -#ifdef CONFIG_X86_PAE
22737 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
22738 /*
22739 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
22740 * updating the top-level pagetable entries to guarantee the
22741 @@ -152,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
22742 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
22743 * and initialize the kernel pmds here.
22744 */
22745 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
22746 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
22747
22748 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
22749 {
22750 @@ -170,36 +213,38 @@ void pud_populate(struct mm_struct *mm,
22751 */
22752 flush_tlb_mm(mm);
22753 }
22754 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
22755 +#define PREALLOCATED_PXDS USER_PGD_PTRS
22756 #else /* !CONFIG_X86_PAE */
22757
22758 /* No need to prepopulate any pagetable entries in non-PAE modes. */
22759 -#define PREALLOCATED_PMDS 0
22760 +#define PREALLOCATED_PXDS 0
22761
22762 #endif /* CONFIG_X86_PAE */
22763
22764 -static void free_pmds(pmd_t *pmds[])
22765 +static void free_pxds(pxd_t *pxds[])
22766 {
22767 int i;
22768
22769 - for(i = 0; i < PREALLOCATED_PMDS; i++)
22770 - if (pmds[i])
22771 - free_page((unsigned long)pmds[i]);
22772 + for(i = 0; i < PREALLOCATED_PXDS; i++)
22773 + if (pxds[i])
22774 + free_page((unsigned long)pxds[i]);
22775 }
22776
22777 -static int preallocate_pmds(pmd_t *pmds[])
22778 +static int preallocate_pxds(pxd_t *pxds[])
22779 {
22780 int i;
22781 bool failed = false;
22782
22783 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
22784 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
22785 - if (pmd == NULL)
22786 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
22787 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
22788 + if (pxd == NULL)
22789 failed = true;
22790 - pmds[i] = pmd;
22791 + pxds[i] = pxd;
22792 }
22793
22794 if (failed) {
22795 - free_pmds(pmds);
22796 + free_pxds(pxds);
22797 return -ENOMEM;
22798 }
22799
22800 @@ -212,51 +257,55 @@ static int preallocate_pmds(pmd_t *pmds[
22801 * preallocate which never got a corresponding vma will need to be
22802 * freed manually.
22803 */
22804 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
22805 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
22806 {
22807 int i;
22808
22809 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
22810 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
22811 pgd_t pgd = pgdp[i];
22812
22813 if (pgd_val(pgd) != 0) {
22814 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
22815 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
22816
22817 - pgdp[i] = native_make_pgd(0);
22818 + set_pgd(pgdp + i, native_make_pgd(0));
22819
22820 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
22821 - pmd_free(mm, pmd);
22822 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
22823 + pxd_free(mm, pxd);
22824 }
22825 }
22826 }
22827
22828 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
22829 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
22830 {
22831 - pud_t *pud;
22832 + pyd_t *pyd;
22833 unsigned long addr;
22834 int i;
22835
22836 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
22837 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
22838 return;
22839
22840 - pud = pud_offset(pgd, 0);
22841 +#ifdef CONFIG_X86_64
22842 + pyd = pyd_offset(mm, 0L);
22843 +#else
22844 + pyd = pyd_offset(pgd, 0L);
22845 +#endif
22846
22847 - for (addr = i = 0; i < PREALLOCATED_PMDS;
22848 - i++, pud++, addr += PUD_SIZE) {
22849 - pmd_t *pmd = pmds[i];
22850 + for (addr = i = 0; i < PREALLOCATED_PXDS;
22851 + i++, pyd++, addr += PYD_SIZE) {
22852 + pxd_t *pxd = pxds[i];
22853
22854 if (i >= KERNEL_PGD_BOUNDARY)
22855 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
22856 - sizeof(pmd_t) * PTRS_PER_PMD);
22857 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
22858 + sizeof(pxd_t) * PTRS_PER_PMD);
22859
22860 - pud_populate(mm, pud, pmd);
22861 + pyd_populate(mm, pyd, pxd);
22862 }
22863 }
22864
22865 pgd_t *pgd_alloc(struct mm_struct *mm)
22866 {
22867 pgd_t *pgd;
22868 - pmd_t *pmds[PREALLOCATED_PMDS];
22869 + pxd_t *pxds[PREALLOCATED_PXDS];
22870
22871 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
22872
22873 @@ -265,11 +314,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
22874
22875 mm->pgd = pgd;
22876
22877 - if (preallocate_pmds(pmds) != 0)
22878 + if (preallocate_pxds(pxds) != 0)
22879 goto out_free_pgd;
22880
22881 if (paravirt_pgd_alloc(mm) != 0)
22882 - goto out_free_pmds;
22883 + goto out_free_pxds;
22884
22885 /*
22886 * Make sure that pre-populating the pmds is atomic with
22887 @@ -279,14 +328,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
22888 spin_lock(&pgd_lock);
22889
22890 pgd_ctor(mm, pgd);
22891 - pgd_prepopulate_pmd(mm, pgd, pmds);
22892 + pgd_prepopulate_pxd(mm, pgd, pxds);
22893
22894 spin_unlock(&pgd_lock);
22895
22896 return pgd;
22897
22898 -out_free_pmds:
22899 - free_pmds(pmds);
22900 +out_free_pxds:
22901 + free_pxds(pxds);
22902 out_free_pgd:
22903 free_page((unsigned long)pgd);
22904 out:
22905 @@ -295,7 +344,7 @@ out:
22906
22907 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
22908 {
22909 - pgd_mop_up_pmds(mm, pgd);
22910 + pgd_mop_up_pxds(mm, pgd);
22911 pgd_dtor(pgd);
22912 paravirt_pgd_free(mm, pgd);
22913 free_page((unsigned long)pgd);
22914 diff -urNp linux-2.6.39/arch/x86/mm/setup_nx.c linux-2.6.39/arch/x86/mm/setup_nx.c
22915 --- linux-2.6.39/arch/x86/mm/setup_nx.c 2011-05-19 00:06:34.000000000 -0400
22916 +++ linux-2.6.39/arch/x86/mm/setup_nx.c 2011-05-22 19:36:30.000000000 -0400
22917 @@ -5,8 +5,10 @@
22918 #include <asm/pgtable.h>
22919 #include <asm/proto.h>
22920
22921 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
22922 static int disable_nx __cpuinitdata;
22923
22924 +#ifndef CONFIG_PAX_PAGEEXEC
22925 /*
22926 * noexec = on|off
22927 *
22928 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str
22929 return 0;
22930 }
22931 early_param("noexec", noexec_setup);
22932 +#endif
22933 +
22934 +#endif
22935
22936 void __cpuinit x86_configure_nx(void)
22937 {
22938 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
22939 if (cpu_has_nx && !disable_nx)
22940 __supported_pte_mask |= _PAGE_NX;
22941 else
22942 +#endif
22943 __supported_pte_mask &= ~_PAGE_NX;
22944 }
22945
22946 diff -urNp linux-2.6.39/arch/x86/mm/tlb.c linux-2.6.39/arch/x86/mm/tlb.c
22947 --- linux-2.6.39/arch/x86/mm/tlb.c 2011-05-19 00:06:34.000000000 -0400
22948 +++ linux-2.6.39/arch/x86/mm/tlb.c 2011-05-22 19:36:30.000000000 -0400
22949 @@ -65,7 +65,11 @@ void leave_mm(int cpu)
22950 BUG();
22951 cpumask_clear_cpu(cpu,
22952 mm_cpumask(percpu_read(cpu_tlbstate.active_mm)));
22953 +
22954 +#ifndef CONFIG_PAX_PER_CPU_PGD
22955 load_cr3(swapper_pg_dir);
22956 +#endif
22957 +
22958 }
22959 EXPORT_SYMBOL_GPL(leave_mm);
22960
22961 diff -urNp linux-2.6.39/arch/x86/oprofile/backtrace.c linux-2.6.39/arch/x86/oprofile/backtrace.c
22962 --- linux-2.6.39/arch/x86/oprofile/backtrace.c 2011-05-19 00:06:34.000000000 -0400
22963 +++ linux-2.6.39/arch/x86/oprofile/backtrace.c 2011-05-22 19:36:30.000000000 -0400
22964 @@ -57,7 +57,7 @@ dump_user_backtrace_32(struct stack_fram
22965 struct stack_frame_ia32 *fp;
22966
22967 /* Also check accessibility of one struct frame_head beyond */
22968 - if (!access_ok(VERIFY_READ, head, sizeof(bufhead)))
22969 + if (!__access_ok(VERIFY_READ, head, sizeof(bufhead)))
22970 return NULL;
22971 if (__copy_from_user_inatomic(bufhead, head, sizeof(bufhead)))
22972 return NULL;
22973 @@ -123,7 +123,7 @@ x86_backtrace(struct pt_regs * const reg
22974 {
22975 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
22976
22977 - if (!user_mode_vm(regs)) {
22978 + if (!user_mode(regs)) {
22979 unsigned long stack = kernel_stack_pointer(regs);
22980 if (depth)
22981 dump_trace(NULL, regs, (unsigned long *)stack, 0,
22982 diff -urNp linux-2.6.39/arch/x86/pci/ce4100.c linux-2.6.39/arch/x86/pci/ce4100.c
22983 --- linux-2.6.39/arch/x86/pci/ce4100.c 2011-05-19 00:06:34.000000000 -0400
22984 +++ linux-2.6.39/arch/x86/pci/ce4100.c 2011-05-22 19:36:30.000000000 -0400
22985 @@ -302,7 +302,7 @@ static int ce4100_conf_write(unsigned in
22986 return pci_direct_conf1.write(seg, bus, devfn, reg, len, value);
22987 }
22988
22989 -struct pci_raw_ops ce4100_pci_conf = {
22990 +const struct pci_raw_ops ce4100_pci_conf = {
22991 .read = ce4100_conf_read,
22992 .write = ce4100_conf_write,
22993 };
22994 diff -urNp linux-2.6.39/arch/x86/pci/common.c linux-2.6.39/arch/x86/pci/common.c
22995 --- linux-2.6.39/arch/x86/pci/common.c 2011-05-19 00:06:34.000000000 -0400
22996 +++ linux-2.6.39/arch/x86/pci/common.c 2011-05-22 19:36:30.000000000 -0400
22997 @@ -33,8 +33,8 @@ int noioapicreroute = 1;
22998 int pcibios_last_bus = -1;
22999 unsigned long pirq_table_addr;
23000 struct pci_bus *pci_root_bus;
23001 -struct pci_raw_ops *raw_pci_ops;
23002 -struct pci_raw_ops *raw_pci_ext_ops;
23003 +const struct pci_raw_ops *raw_pci_ops;
23004 +const struct pci_raw_ops *raw_pci_ext_ops;
23005
23006 int raw_pci_read(unsigned int domain, unsigned int bus, unsigned int devfn,
23007 int reg, int len, u32 *val)
23008 diff -urNp linux-2.6.39/arch/x86/pci/direct.c linux-2.6.39/arch/x86/pci/direct.c
23009 --- linux-2.6.39/arch/x86/pci/direct.c 2011-05-19 00:06:34.000000000 -0400
23010 +++ linux-2.6.39/arch/x86/pci/direct.c 2011-05-22 19:36:30.000000000 -0400
23011 @@ -79,7 +79,7 @@ static int pci_conf1_write(unsigned int
23012
23013 #undef PCI_CONF1_ADDRESS
23014
23015 -struct pci_raw_ops pci_direct_conf1 = {
23016 +const struct pci_raw_ops pci_direct_conf1 = {
23017 .read = pci_conf1_read,
23018 .write = pci_conf1_write,
23019 };
23020 @@ -173,7 +173,7 @@ static int pci_conf2_write(unsigned int
23021
23022 #undef PCI_CONF2_ADDRESS
23023
23024 -struct pci_raw_ops pci_direct_conf2 = {
23025 +const struct pci_raw_ops pci_direct_conf2 = {
23026 .read = pci_conf2_read,
23027 .write = pci_conf2_write,
23028 };
23029 @@ -189,7 +189,7 @@ struct pci_raw_ops pci_direct_conf2 = {
23030 * This should be close to trivial, but it isn't, because there are buggy
23031 * chipsets (yes, you guessed it, by Intel and Compaq) that have no class ID.
23032 */
23033 -static int __init pci_sanity_check(struct pci_raw_ops *o)
23034 +static int __init pci_sanity_check(const struct pci_raw_ops *o)
23035 {
23036 u32 x = 0;
23037 int year, devfn;
23038 diff -urNp linux-2.6.39/arch/x86/pci/fixup.c linux-2.6.39/arch/x86/pci/fixup.c
23039 --- linux-2.6.39/arch/x86/pci/fixup.c 2011-05-19 00:06:34.000000000 -0400
23040 +++ linux-2.6.39/arch/x86/pci/fixup.c 2011-05-22 19:36:30.000000000 -0400
23041 @@ -435,7 +435,7 @@ static const struct dmi_system_id __devi
23042 DMI_MATCH(DMI_PRODUCT_VERSION, "PSA40U"),
23043 },
23044 },
23045 - { }
23046 + {}
23047 };
23048
23049 static void __devinit pci_pre_fixup_toshiba_ohci1394(struct pci_dev *dev)
23050 diff -urNp linux-2.6.39/arch/x86/pci/mmconfig_32.c linux-2.6.39/arch/x86/pci/mmconfig_32.c
23051 --- linux-2.6.39/arch/x86/pci/mmconfig_32.c 2011-05-19 00:06:34.000000000 -0400
23052 +++ linux-2.6.39/arch/x86/pci/mmconfig_32.c 2011-05-22 19:36:30.000000000 -0400
23053 @@ -117,7 +117,7 @@ static int pci_mmcfg_write(unsigned int
23054 return 0;
23055 }
23056
23057 -static struct pci_raw_ops pci_mmcfg = {
23058 +static const struct pci_raw_ops pci_mmcfg = {
23059 .read = pci_mmcfg_read,
23060 .write = pci_mmcfg_write,
23061 };
23062 diff -urNp linux-2.6.39/arch/x86/pci/mmconfig_64.c linux-2.6.39/arch/x86/pci/mmconfig_64.c
23063 --- linux-2.6.39/arch/x86/pci/mmconfig_64.c 2011-05-19 00:06:34.000000000 -0400
23064 +++ linux-2.6.39/arch/x86/pci/mmconfig_64.c 2011-05-22 19:36:30.000000000 -0400
23065 @@ -81,7 +81,7 @@ static int pci_mmcfg_write(unsigned int
23066 return 0;
23067 }
23068
23069 -static struct pci_raw_ops pci_mmcfg = {
23070 +static const struct pci_raw_ops pci_mmcfg = {
23071 .read = pci_mmcfg_read,
23072 .write = pci_mmcfg_write,
23073 };
23074 diff -urNp linux-2.6.39/arch/x86/pci/mrst.c linux-2.6.39/arch/x86/pci/mrst.c
23075 --- linux-2.6.39/arch/x86/pci/mrst.c 2011-05-19 00:06:34.000000000 -0400
23076 +++ linux-2.6.39/arch/x86/pci/mrst.c 2011-05-22 19:36:30.000000000 -0400
23077 @@ -218,7 +218,7 @@ static int mrst_pci_irq_enable(struct pc
23078 return 0;
23079 }
23080
23081 -struct pci_ops pci_mrst_ops = {
23082 +const struct pci_ops pci_mrst_ops = {
23083 .read = pci_read,
23084 .write = pci_write,
23085 };
23086 diff -urNp linux-2.6.39/arch/x86/pci/numaq_32.c linux-2.6.39/arch/x86/pci/numaq_32.c
23087 --- linux-2.6.39/arch/x86/pci/numaq_32.c 2011-05-19 00:06:34.000000000 -0400
23088 +++ linux-2.6.39/arch/x86/pci/numaq_32.c 2011-05-22 19:36:30.000000000 -0400
23089 @@ -108,7 +108,7 @@ static int pci_conf1_mq_write(unsigned i
23090
23091 #undef PCI_CONF1_MQ_ADDRESS
23092
23093 -static struct pci_raw_ops pci_direct_conf1_mq = {
23094 +static const struct pci_raw_ops pci_direct_conf1_mq = {
23095 .read = pci_conf1_mq_read,
23096 .write = pci_conf1_mq_write
23097 };
23098 diff -urNp linux-2.6.39/arch/x86/pci/olpc.c linux-2.6.39/arch/x86/pci/olpc.c
23099 --- linux-2.6.39/arch/x86/pci/olpc.c 2011-05-19 00:06:34.000000000 -0400
23100 +++ linux-2.6.39/arch/x86/pci/olpc.c 2011-05-22 19:36:30.000000000 -0400
23101 @@ -297,7 +297,7 @@ static int pci_olpc_write(unsigned int s
23102 return 0;
23103 }
23104
23105 -static struct pci_raw_ops pci_olpc_conf = {
23106 +static const struct pci_raw_ops pci_olpc_conf = {
23107 .read = pci_olpc_read,
23108 .write = pci_olpc_write,
23109 };
23110 diff -urNp linux-2.6.39/arch/x86/pci/pcbios.c linux-2.6.39/arch/x86/pci/pcbios.c
23111 --- linux-2.6.39/arch/x86/pci/pcbios.c 2011-05-19 00:06:34.000000000 -0400
23112 +++ linux-2.6.39/arch/x86/pci/pcbios.c 2011-05-22 19:36:30.000000000 -0400
23113 @@ -79,50 +79,93 @@ union bios32 {
23114 static struct {
23115 unsigned long address;
23116 unsigned short segment;
23117 -} bios32_indirect = { 0, __KERNEL_CS };
23118 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
23119
23120 /*
23121 * Returns the entry point for the given service, NULL on error
23122 */
23123
23124 -static unsigned long bios32_service(unsigned long service)
23125 +static unsigned long __devinit bios32_service(unsigned long service)
23126 {
23127 unsigned char return_code; /* %al */
23128 unsigned long address; /* %ebx */
23129 unsigned long length; /* %ecx */
23130 unsigned long entry; /* %edx */
23131 unsigned long flags;
23132 + struct desc_struct d, *gdt;
23133
23134 local_irq_save(flags);
23135 - __asm__("lcall *(%%edi); cld"
23136 +
23137 + gdt = get_cpu_gdt_table(smp_processor_id());
23138 +
23139 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
23140 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
23141 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
23142 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
23143 +
23144 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
23145 : "=a" (return_code),
23146 "=b" (address),
23147 "=c" (length),
23148 "=d" (entry)
23149 : "0" (service),
23150 "1" (0),
23151 - "D" (&bios32_indirect));
23152 + "D" (&bios32_indirect),
23153 + "r"(__PCIBIOS_DS)
23154 + : "memory");
23155 +
23156 + pax_open_kernel();
23157 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
23158 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
23159 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
23160 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
23161 + pax_close_kernel();
23162 +
23163 local_irq_restore(flags);
23164
23165 switch (return_code) {
23166 - case 0:
23167 - return address + entry;
23168 - case 0x80: /* Not present */
23169 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
23170 - return 0;
23171 - default: /* Shouldn't happen */
23172 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
23173 - service, return_code);
23174 + case 0: {
23175 + int cpu;
23176 + unsigned char flags;
23177 +
23178 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
23179 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
23180 + printk(KERN_WARNING "bios32_service: not valid\n");
23181 return 0;
23182 + }
23183 + address = address + PAGE_OFFSET;
23184 + length += 16UL; /* some BIOSs underreport this... */
23185 + flags = 4;
23186 + if (length >= 64*1024*1024) {
23187 + length >>= PAGE_SHIFT;
23188 + flags |= 8;
23189 + }
23190 +
23191 + for (cpu = 0; cpu < NR_CPUS; cpu++) {
23192 + gdt = get_cpu_gdt_table(cpu);
23193 + pack_descriptor(&d, address, length, 0x9b, flags);
23194 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
23195 + pack_descriptor(&d, address, length, 0x93, flags);
23196 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
23197 + }
23198 + return entry;
23199 + }
23200 + case 0x80: /* Not present */
23201 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
23202 + return 0;
23203 + default: /* Shouldn't happen */
23204 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
23205 + service, return_code);
23206 + return 0;
23207 }
23208 }
23209
23210 static struct {
23211 unsigned long address;
23212 unsigned short segment;
23213 -} pci_indirect = { 0, __KERNEL_CS };
23214 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
23215
23216 -static int pci_bios_present;
23217 +static int pci_bios_present __read_only;
23218
23219 static int __devinit check_pcibios(void)
23220 {
23221 @@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
23222 unsigned long flags, pcibios_entry;
23223
23224 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
23225 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
23226 + pci_indirect.address = pcibios_entry;
23227
23228 local_irq_save(flags);
23229 - __asm__(
23230 - "lcall *(%%edi); cld\n\t"
23231 + __asm__("movw %w6, %%ds\n\t"
23232 + "lcall *%%ss:(%%edi); cld\n\t"
23233 + "push %%ss\n\t"
23234 + "pop %%ds\n\t"
23235 "jc 1f\n\t"
23236 "xor %%ah, %%ah\n"
23237 "1:"
23238 @@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
23239 "=b" (ebx),
23240 "=c" (ecx)
23241 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
23242 - "D" (&pci_indirect)
23243 + "D" (&pci_indirect),
23244 + "r" (__PCIBIOS_DS)
23245 : "memory");
23246 local_irq_restore(flags);
23247
23248 @@ -188,7 +234,10 @@ static int pci_bios_read(unsigned int se
23249
23250 switch (len) {
23251 case 1:
23252 - __asm__("lcall *(%%esi); cld\n\t"
23253 + __asm__("movw %w6, %%ds\n\t"
23254 + "lcall *%%ss:(%%esi); cld\n\t"
23255 + "push %%ss\n\t"
23256 + "pop %%ds\n\t"
23257 "jc 1f\n\t"
23258 "xor %%ah, %%ah\n"
23259 "1:"
23260 @@ -197,7 +246,8 @@ static int pci_bios_read(unsigned int se
23261 : "1" (PCIBIOS_READ_CONFIG_BYTE),
23262 "b" (bx),
23263 "D" ((long)reg),
23264 - "S" (&pci_indirect));
23265 + "S" (&pci_indirect),
23266 + "r" (__PCIBIOS_DS));
23267 /*
23268 * Zero-extend the result beyond 8 bits, do not trust the
23269 * BIOS having done it:
23270 @@ -205,7 +255,10 @@ static int pci_bios_read(unsigned int se
23271 *value &= 0xff;
23272 break;
23273 case 2:
23274 - __asm__("lcall *(%%esi); cld\n\t"
23275 + __asm__("movw %w6, %%ds\n\t"
23276 + "lcall *%%ss:(%%esi); cld\n\t"
23277 + "push %%ss\n\t"
23278 + "pop %%ds\n\t"
23279 "jc 1f\n\t"
23280 "xor %%ah, %%ah\n"
23281 "1:"
23282 @@ -214,7 +267,8 @@ static int pci_bios_read(unsigned int se
23283 : "1" (PCIBIOS_READ_CONFIG_WORD),
23284 "b" (bx),
23285 "D" ((long)reg),
23286 - "S" (&pci_indirect));
23287 + "S" (&pci_indirect),
23288 + "r" (__PCIBIOS_DS));
23289 /*
23290 * Zero-extend the result beyond 16 bits, do not trust the
23291 * BIOS having done it:
23292 @@ -222,7 +276,10 @@ static int pci_bios_read(unsigned int se
23293 *value &= 0xffff;
23294 break;
23295 case 4:
23296 - __asm__("lcall *(%%esi); cld\n\t"
23297 + __asm__("movw %w6, %%ds\n\t"
23298 + "lcall *%%ss:(%%esi); cld\n\t"
23299 + "push %%ss\n\t"
23300 + "pop %%ds\n\t"
23301 "jc 1f\n\t"
23302 "xor %%ah, %%ah\n"
23303 "1:"
23304 @@ -231,7 +288,8 @@ static int pci_bios_read(unsigned int se
23305 : "1" (PCIBIOS_READ_CONFIG_DWORD),
23306 "b" (bx),
23307 "D" ((long)reg),
23308 - "S" (&pci_indirect));
23309 + "S" (&pci_indirect),
23310 + "r" (__PCIBIOS_DS));
23311 break;
23312 }
23313
23314 @@ -254,7 +312,10 @@ static int pci_bios_write(unsigned int s
23315
23316 switch (len) {
23317 case 1:
23318 - __asm__("lcall *(%%esi); cld\n\t"
23319 + __asm__("movw %w6, %%ds\n\t"
23320 + "lcall *%%ss:(%%esi); cld\n\t"
23321 + "push %%ss\n\t"
23322 + "pop %%ds\n\t"
23323 "jc 1f\n\t"
23324 "xor %%ah, %%ah\n"
23325 "1:"
23326 @@ -263,10 +324,14 @@ static int pci_bios_write(unsigned int s
23327 "c" (value),
23328 "b" (bx),
23329 "D" ((long)reg),
23330 - "S" (&pci_indirect));
23331 + "S" (&pci_indirect),
23332 + "r" (__PCIBIOS_DS));
23333 break;
23334 case 2:
23335 - __asm__("lcall *(%%esi); cld\n\t"
23336 + __asm__("movw %w6, %%ds\n\t"
23337 + "lcall *%%ss:(%%esi); cld\n\t"
23338 + "push %%ss\n\t"
23339 + "pop %%ds\n\t"
23340 "jc 1f\n\t"
23341 "xor %%ah, %%ah\n"
23342 "1:"
23343 @@ -275,10 +340,14 @@ static int pci_bios_write(unsigned int s
23344 "c" (value),
23345 "b" (bx),
23346 "D" ((long)reg),
23347 - "S" (&pci_indirect));
23348 + "S" (&pci_indirect),
23349 + "r" (__PCIBIOS_DS));
23350 break;
23351 case 4:
23352 - __asm__("lcall *(%%esi); cld\n\t"
23353 + __asm__("movw %w6, %%ds\n\t"
23354 + "lcall *%%ss:(%%esi); cld\n\t"
23355 + "push %%ss\n\t"
23356 + "pop %%ds\n\t"
23357 "jc 1f\n\t"
23358 "xor %%ah, %%ah\n"
23359 "1:"
23360 @@ -287,7 +356,8 @@ static int pci_bios_write(unsigned int s
23361 "c" (value),
23362 "b" (bx),
23363 "D" ((long)reg),
23364 - "S" (&pci_indirect));
23365 + "S" (&pci_indirect),
23366 + "r" (__PCIBIOS_DS));
23367 break;
23368 }
23369
23370 @@ -301,7 +371,7 @@ static int pci_bios_write(unsigned int s
23371 * Function table for BIOS32 access
23372 */
23373
23374 -static struct pci_raw_ops pci_bios_access = {
23375 +static const struct pci_raw_ops pci_bios_access = {
23376 .read = pci_bios_read,
23377 .write = pci_bios_write
23378 };
23379 @@ -310,7 +380,7 @@ static struct pci_raw_ops pci_bios_acces
23380 * Try to find PCI BIOS.
23381 */
23382
23383 -static struct pci_raw_ops * __devinit pci_find_bios(void)
23384 +static const struct pci_raw_ops * __devinit pci_find_bios(void)
23385 {
23386 union bios32 *check;
23387 unsigned char sum;
23388 @@ -392,10 +462,13 @@ struct irq_routing_table * pcibios_get_i
23389
23390 DBG("PCI: Fetching IRQ routing table... ");
23391 __asm__("push %%es\n\t"
23392 + "movw %w8, %%ds\n\t"
23393 "push %%ds\n\t"
23394 "pop %%es\n\t"
23395 - "lcall *(%%esi); cld\n\t"
23396 + "lcall *%%ss:(%%esi); cld\n\t"
23397 "pop %%es\n\t"
23398 + "push %%ss\n\t"
23399 + "pop %%ds\n"
23400 "jc 1f\n\t"
23401 "xor %%ah, %%ah\n"
23402 "1:"
23403 @@ -406,7 +479,8 @@ struct irq_routing_table * pcibios_get_i
23404 "1" (0),
23405 "D" ((long) &opt),
23406 "S" (&pci_indirect),
23407 - "m" (opt)
23408 + "m" (opt),
23409 + "r" (__PCIBIOS_DS)
23410 : "memory");
23411 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
23412 if (ret & 0xff00)
23413 @@ -430,7 +504,10 @@ int pcibios_set_irq_routing(struct pci_d
23414 {
23415 int ret;
23416
23417 - __asm__("lcall *(%%esi); cld\n\t"
23418 + __asm__("movw %w5, %%ds\n\t"
23419 + "lcall *%%ss:(%%esi); cld\n\t"
23420 + "push %%ss\n\t"
23421 + "pop %%ds\n"
23422 "jc 1f\n\t"
23423 "xor %%ah, %%ah\n"
23424 "1:"
23425 @@ -438,7 +515,8 @@ int pcibios_set_irq_routing(struct pci_d
23426 : "0" (PCIBIOS_SET_PCI_HW_INT),
23427 "b" ((dev->bus->number << 8) | dev->devfn),
23428 "c" ((irq << 8) | (pin + 10)),
23429 - "S" (&pci_indirect));
23430 + "S" (&pci_indirect),
23431 + "r" (__PCIBIOS_DS));
23432 return !(ret & 0xff00);
23433 }
23434 EXPORT_SYMBOL(pcibios_set_irq_routing);
23435 diff -urNp linux-2.6.39/arch/x86/pci/xen.c linux-2.6.39/arch/x86/pci/xen.c
23436 --- linux-2.6.39/arch/x86/pci/xen.c 2011-05-19 00:06:34.000000000 -0400
23437 +++ linux-2.6.39/arch/x86/pci/xen.c 2011-05-22 19:36:30.000000000 -0400
23438 @@ -62,7 +62,7 @@ static int acpi_register_gsi_xen_hvm(str
23439 #include <linux/msi.h>
23440 #include <asm/msidef.h>
23441
23442 -struct xen_pci_frontend_ops *xen_pci_frontend;
23443 +const struct xen_pci_frontend_ops *xen_pci_frontend;
23444 EXPORT_SYMBOL_GPL(xen_pci_frontend);
23445
23446 #define XEN_PIRQ_MSI_DATA (MSI_DATA_TRIGGER_EDGE | \
23447 diff -urNp linux-2.6.39/arch/x86/platform/efi/efi_32.c linux-2.6.39/arch/x86/platform/efi/efi_32.c
23448 --- linux-2.6.39/arch/x86/platform/efi/efi_32.c 2011-05-19 00:06:34.000000000 -0400
23449 +++ linux-2.6.39/arch/x86/platform/efi/efi_32.c 2011-05-22 19:36:30.000000000 -0400
23450 @@ -38,70 +38,37 @@
23451 */
23452
23453 static unsigned long efi_rt_eflags;
23454 -static pgd_t efi_bak_pg_dir_pointer[2];
23455 +static pgd_t __initdata efi_bak_pg_dir_pointer[KERNEL_PGD_PTRS];
23456
23457 -void efi_call_phys_prelog(void)
23458 +void __init efi_call_phys_prelog(void)
23459 {
23460 - unsigned long cr4;
23461 - unsigned long temp;
23462 struct desc_ptr gdt_descr;
23463
23464 local_irq_save(efi_rt_eflags);
23465
23466 - /*
23467 - * If I don't have PAE, I should just duplicate two entries in page
23468 - * directory. If I have PAE, I just need to duplicate one entry in
23469 - * page directory.
23470 - */
23471 - cr4 = read_cr4_safe();
23472 -
23473 - if (cr4 & X86_CR4_PAE) {
23474 - efi_bak_pg_dir_pointer[0].pgd =
23475 - swapper_pg_dir[pgd_index(0)].pgd;
23476 - swapper_pg_dir[0].pgd =
23477 - swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;
23478 - } else {
23479 - efi_bak_pg_dir_pointer[0].pgd =
23480 - swapper_pg_dir[pgd_index(0)].pgd;
23481 - efi_bak_pg_dir_pointer[1].pgd =
23482 - swapper_pg_dir[pgd_index(0x400000)].pgd;
23483 - swapper_pg_dir[pgd_index(0)].pgd =
23484 - swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;
23485 - temp = PAGE_OFFSET + 0x400000;
23486 - swapper_pg_dir[pgd_index(0x400000)].pgd =
23487 - swapper_pg_dir[pgd_index(temp)].pgd;
23488 - }
23489 + clone_pgd_range(efi_bak_pg_dir_pointer, swapper_pg_dir, KERNEL_PGD_PTRS);
23490 + clone_pgd_range(swapper_pg_dir, swapper_pg_dir + KERNEL_PGD_BOUNDARY,
23491 + min_t(unsigned long, KERNEL_PGD_PTRS, KERNEL_PGD_BOUNDARY));
23492
23493 /*
23494 * After the lock is released, the original page table is restored.
23495 */
23496 __flush_tlb_all();
23497
23498 - gdt_descr.address = __pa(get_cpu_gdt_table(0));
23499 + gdt_descr.address = (struct desc_struct *)__pa(get_cpu_gdt_table(0));
23500 gdt_descr.size = GDT_SIZE - 1;
23501 load_gdt(&gdt_descr);
23502 }
23503
23504 -void efi_call_phys_epilog(void)
23505 +void __init efi_call_phys_epilog(void)
23506 {
23507 - unsigned long cr4;
23508 struct desc_ptr gdt_descr;
23509
23510 - gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
23511 + gdt_descr.address = get_cpu_gdt_table(0);
23512 gdt_descr.size = GDT_SIZE - 1;
23513 load_gdt(&gdt_descr);
23514
23515 - cr4 = read_cr4_safe();
23516 -
23517 - if (cr4 & X86_CR4_PAE) {
23518 - swapper_pg_dir[pgd_index(0)].pgd =
23519 - efi_bak_pg_dir_pointer[0].pgd;
23520 - } else {
23521 - swapper_pg_dir[pgd_index(0)].pgd =
23522 - efi_bak_pg_dir_pointer[0].pgd;
23523 - swapper_pg_dir[pgd_index(0x400000)].pgd =
23524 - efi_bak_pg_dir_pointer[1].pgd;
23525 - }
23526 + clone_pgd_range(swapper_pg_dir, efi_bak_pg_dir_pointer, KERNEL_PGD_PTRS);
23527
23528 /*
23529 * After the lock is released, the original page table is restored.
23530 diff -urNp linux-2.6.39/arch/x86/platform/efi/efi_stub_32.S linux-2.6.39/arch/x86/platform/efi/efi_stub_32.S
23531 --- linux-2.6.39/arch/x86/platform/efi/efi_stub_32.S 2011-05-19 00:06:34.000000000 -0400
23532 +++ linux-2.6.39/arch/x86/platform/efi/efi_stub_32.S 2011-05-22 19:36:30.000000000 -0400
23533 @@ -6,6 +6,7 @@
23534 */
23535
23536 #include <linux/linkage.h>
23537 +#include <linux/init.h>
23538 #include <asm/page_types.h>
23539
23540 /*
23541 @@ -20,7 +21,7 @@
23542 * service functions will comply with gcc calling convention, too.
23543 */
23544
23545 -.text
23546 +__INIT
23547 ENTRY(efi_call_phys)
23548 /*
23549 * 0. The function can only be called in Linux kernel. So CS has been
23550 @@ -36,9 +37,7 @@ ENTRY(efi_call_phys)
23551 * The mapping of lower virtual memory has been created in prelog and
23552 * epilog.
23553 */
23554 - movl $1f, %edx
23555 - subl $__PAGE_OFFSET, %edx
23556 - jmp *%edx
23557 + jmp 1f-__PAGE_OFFSET
23558 1:
23559
23560 /*
23561 @@ -47,14 +46,8 @@ ENTRY(efi_call_phys)
23562 * parameter 2, ..., param n. To make things easy, we save the return
23563 * address of efi_call_phys in a global variable.
23564 */
23565 - popl %edx
23566 - movl %edx, saved_return_addr
23567 - /* get the function pointer into ECX*/
23568 - popl %ecx
23569 - movl %ecx, efi_rt_function_ptr
23570 - movl $2f, %edx
23571 - subl $__PAGE_OFFSET, %edx
23572 - pushl %edx
23573 + popl (saved_return_addr)
23574 + popl (efi_rt_function_ptr)
23575
23576 /*
23577 * 3. Clear PG bit in %CR0.
23578 @@ -73,9 +66,8 @@ ENTRY(efi_call_phys)
23579 /*
23580 * 5. Call the physical function.
23581 */
23582 - jmp *%ecx
23583 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
23584
23585 -2:
23586 /*
23587 * 6. After EFI runtime service returns, control will return to
23588 * following instruction. We'd better readjust stack pointer first.
23589 @@ -88,35 +80,28 @@ ENTRY(efi_call_phys)
23590 movl %cr0, %edx
23591 orl $0x80000000, %edx
23592 movl %edx, %cr0
23593 - jmp 1f
23594 -1:
23595 +
23596 /*
23597 * 8. Now restore the virtual mode from flat mode by
23598 * adding EIP with PAGE_OFFSET.
23599 */
23600 - movl $1f, %edx
23601 - jmp *%edx
23602 + jmp 1f+__PAGE_OFFSET
23603 1:
23604
23605 /*
23606 * 9. Balance the stack. And because EAX contain the return value,
23607 * we'd better not clobber it.
23608 */
23609 - leal efi_rt_function_ptr, %edx
23610 - movl (%edx), %ecx
23611 - pushl %ecx
23612 + pushl (efi_rt_function_ptr)
23613
23614 /*
23615 - * 10. Push the saved return address onto the stack and return.
23616 + * 10. Return to the saved return address.
23617 */
23618 - leal saved_return_addr, %edx
23619 - movl (%edx), %ecx
23620 - pushl %ecx
23621 - ret
23622 + jmpl *(saved_return_addr)
23623 ENDPROC(efi_call_phys)
23624 .previous
23625
23626 -.data
23627 +__INITDATA
23628 saved_return_addr:
23629 .long 0
23630 efi_rt_function_ptr:
23631 diff -urNp linux-2.6.39/arch/x86/platform/olpc/olpc_dt.c linux-2.6.39/arch/x86/platform/olpc/olpc_dt.c
23632 --- linux-2.6.39/arch/x86/platform/olpc/olpc_dt.c 2011-05-19 00:06:34.000000000 -0400
23633 +++ linux-2.6.39/arch/x86/platform/olpc/olpc_dt.c 2011-05-22 19:36:30.000000000 -0400
23634 @@ -154,7 +154,7 @@ void * __init prom_early_alloc(unsigned
23635 return res;
23636 }
23637
23638 -static struct of_pdt_ops prom_olpc_ops __initdata = {
23639 +static const struct of_pdt_ops prom_olpc_ops = {
23640 .nextprop = olpc_dt_nextprop,
23641 .getproplen = olpc_dt_getproplen,
23642 .getproperty = olpc_dt_getproperty,
23643 diff -urNp linux-2.6.39/arch/x86/platform/uv/tlb_uv.c linux-2.6.39/arch/x86/platform/uv/tlb_uv.c
23644 --- linux-2.6.39/arch/x86/platform/uv/tlb_uv.c 2011-05-19 00:06:34.000000000 -0400
23645 +++ linux-2.6.39/arch/x86/platform/uv/tlb_uv.c 2011-05-22 19:36:30.000000000 -0400
23646 @@ -342,6 +342,8 @@ static void uv_reset_with_ipi(struct bau
23647 cpumask_t mask;
23648 struct reset_args reset_args;
23649
23650 + pax_track_stack();
23651 +
23652 reset_args.sender = sender;
23653
23654 cpus_clear(mask);
23655 diff -urNp linux-2.6.39/arch/x86/power/cpu.c linux-2.6.39/arch/x86/power/cpu.c
23656 --- linux-2.6.39/arch/x86/power/cpu.c 2011-05-19 00:06:34.000000000 -0400
23657 +++ linux-2.6.39/arch/x86/power/cpu.c 2011-05-22 19:36:30.000000000 -0400
23658 @@ -130,7 +130,7 @@ static void do_fpu_end(void)
23659 static void fix_processor_context(void)
23660 {
23661 int cpu = smp_processor_id();
23662 - struct tss_struct *t = &per_cpu(init_tss, cpu);
23663 + struct tss_struct *t = init_tss + cpu;
23664
23665 set_tss_desc(cpu, t); /*
23666 * This just modifies memory; should not be
23667 @@ -140,7 +140,9 @@ static void fix_processor_context(void)
23668 */
23669
23670 #ifdef CONFIG_X86_64
23671 + pax_open_kernel();
23672 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
23673 + pax_close_kernel();
23674
23675 syscall_init(); /* This sets MSR_*STAR and related */
23676 #endif
23677 diff -urNp linux-2.6.39/arch/x86/vdso/Makefile linux-2.6.39/arch/x86/vdso/Makefile
23678 --- linux-2.6.39/arch/x86/vdso/Makefile 2011-05-19 00:06:34.000000000 -0400
23679 +++ linux-2.6.39/arch/x86/vdso/Makefile 2011-05-22 19:36:30.000000000 -0400
23680 @@ -123,7 +123,7 @@ quiet_cmd_vdso = VDSO $@
23681 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
23682 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
23683
23684 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
23685 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
23686 GCOV_PROFILE := n
23687
23688 #
23689 diff -urNp linux-2.6.39/arch/x86/vdso/vclock_gettime.c linux-2.6.39/arch/x86/vdso/vclock_gettime.c
23690 --- linux-2.6.39/arch/x86/vdso/vclock_gettime.c 2011-05-19 00:06:34.000000000 -0400
23691 +++ linux-2.6.39/arch/x86/vdso/vclock_gettime.c 2011-05-22 19:36:30.000000000 -0400
23692 @@ -22,24 +22,48 @@
23693 #include <asm/hpet.h>
23694 #include <asm/unistd.h>
23695 #include <asm/io.h>
23696 +#include <asm/fixmap.h>
23697 #include "vextern.h"
23698
23699 #define gtod vdso_vsyscall_gtod_data
23700
23701 +notrace noinline long __vdso_fallback_time(long *t)
23702 +{
23703 + long secs;
23704 + asm volatile("syscall"
23705 + : "=a" (secs)
23706 + : "0" (__NR_time),"D" (t) : "r11", "cx", "memory");
23707 + return secs;
23708 +}
23709 +
23710 notrace static long vdso_fallback_gettime(long clock, struct timespec *ts)
23711 {
23712 long ret;
23713 asm("syscall" : "=a" (ret) :
23714 - "0" (__NR_clock_gettime),"D" (clock), "S" (ts) : "memory");
23715 + "0" (__NR_clock_gettime),"D" (clock), "S" (ts) : "r11", "cx", "memory");
23716 return ret;
23717 }
23718
23719 +notrace static inline cycle_t __vdso_vread_hpet(void)
23720 +{
23721 + return readl((const void __iomem *)fix_to_virt(VSYSCALL_HPET) + 0xf0);
23722 +}
23723 +
23724 +notrace static inline cycle_t __vdso_vread_tsc(void)
23725 +{
23726 + cycle_t ret = (cycle_t)vget_cycles();
23727 +
23728 + return ret >= gtod->clock.cycle_last ? ret : gtod->clock.cycle_last;
23729 +}
23730 +
23731 notrace static inline long vgetns(void)
23732 {
23733 long v;
23734 - cycles_t (*vread)(void);
23735 - vread = gtod->clock.vread;
23736 - v = (vread() - gtod->clock.cycle_last) & gtod->clock.mask;
23737 + if (gtod->clock.name[0] == 't' && gtod->clock.name[1] == 's' && gtod->clock.name[2] == 'c' && !gtod->clock.name[3])
23738 + v = __vdso_vread_tsc();
23739 + else
23740 + v = __vdso_vread_hpet();
23741 + v = (v - gtod->clock.cycle_last) & gtod->clock.mask;
23742 return (v * gtod->clock.mult) >> gtod->clock.shift;
23743 }
23744
23745 @@ -113,7 +137,9 @@ notrace static noinline int do_monotonic
23746
23747 notrace int __vdso_clock_gettime(clockid_t clock, struct timespec *ts)
23748 {
23749 - if (likely(gtod->sysctl_enabled))
23750 + if (likely(gtod->sysctl_enabled &&
23751 + ((gtod->clock.name[0] == 'h' && gtod->clock.name[1] == 'p' && gtod->clock.name[2] == 'e' && gtod->clock.name[3] == 't' && !gtod->clock.name[4]) ||
23752 + (gtod->clock.name[0] == 't' && gtod->clock.name[1] == 's' && gtod->clock.name[2] == 'c' && !gtod->clock.name[3]))))
23753 switch (clock) {
23754 case CLOCK_REALTIME:
23755 if (likely(gtod->clock.vread))
23756 @@ -133,10 +159,20 @@ notrace int __vdso_clock_gettime(clockid
23757 int clock_gettime(clockid_t, struct timespec *)
23758 __attribute__((weak, alias("__vdso_clock_gettime")));
23759
23760 -notrace int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz)
23761 +notrace noinline int __vdso_fallback_gettimeofday(struct timeval *tv, struct timezone *tz)
23762 {
23763 long ret;
23764 - if (likely(gtod->sysctl_enabled && gtod->clock.vread)) {
23765 + asm("syscall" : "=a" (ret) :
23766 + "0" (__NR_gettimeofday), "D" (tv), "S" (tz) : "r11", "cx", "memory");
23767 + return ret;
23768 +}
23769 +
23770 +notrace int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz)
23771 +{
23772 + if (likely(gtod->sysctl_enabled &&
23773 + ((gtod->clock.name[0] == 'h' && gtod->clock.name[1] == 'p' && gtod->clock.name[2] == 'e' && gtod->clock.name[3] == 't' && !gtod->clock.name[4]) ||
23774 + (gtod->clock.name[0] == 't' && gtod->clock.name[1] == 's' && gtod->clock.name[2] == 'c' && !gtod->clock.name[3]))))
23775 + {
23776 if (likely(tv != NULL)) {
23777 BUILD_BUG_ON(offsetof(struct timeval, tv_usec) !=
23778 offsetof(struct timespec, tv_nsec) ||
23779 @@ -151,9 +187,7 @@ notrace int __vdso_gettimeofday(struct t
23780 }
23781 return 0;
23782 }
23783 - asm("syscall" : "=a" (ret) :
23784 - "0" (__NR_gettimeofday), "D" (tv), "S" (tz) : "memory");
23785 - return ret;
23786 + return __vdso_fallback_gettimeofday(tv, tz);
23787 }
23788 int gettimeofday(struct timeval *, struct timezone *)
23789 __attribute__((weak, alias("__vdso_gettimeofday")));
23790 diff -urNp linux-2.6.39/arch/x86/vdso/vdso32-setup.c linux-2.6.39/arch/x86/vdso/vdso32-setup.c
23791 --- linux-2.6.39/arch/x86/vdso/vdso32-setup.c 2011-05-19 00:06:34.000000000 -0400
23792 +++ linux-2.6.39/arch/x86/vdso/vdso32-setup.c 2011-05-22 19:36:30.000000000 -0400
23793 @@ -25,6 +25,7 @@
23794 #include <asm/tlbflush.h>
23795 #include <asm/vdso.h>
23796 #include <asm/proto.h>
23797 +#include <asm/mman.h>
23798
23799 enum {
23800 VDSO_DISABLED = 0,
23801 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int m
23802 void enable_sep_cpu(void)
23803 {
23804 int cpu = get_cpu();
23805 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
23806 + struct tss_struct *tss = init_tss + cpu;
23807
23808 if (!boot_cpu_has(X86_FEATURE_SEP)) {
23809 put_cpu();
23810 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
23811 gate_vma.vm_start = FIXADDR_USER_START;
23812 gate_vma.vm_end = FIXADDR_USER_END;
23813 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
23814 - gate_vma.vm_page_prot = __P101;
23815 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
23816 /*
23817 * Make sure the vDSO gets into every core dump.
23818 * Dumping its contents makes post-mortem fully interpretable later
23819 @@ -331,14 +332,14 @@ int arch_setup_additional_pages(struct l
23820 if (compat)
23821 addr = VDSO_HIGH_BASE;
23822 else {
23823 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
23824 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
23825 if (IS_ERR_VALUE(addr)) {
23826 ret = addr;
23827 goto up_fail;
23828 }
23829 }
23830
23831 - current->mm->context.vdso = (void *)addr;
23832 + current->mm->context.vdso = addr;
23833
23834 if (compat_uses_vma || !compat) {
23835 /*
23836 @@ -361,11 +362,11 @@ int arch_setup_additional_pages(struct l
23837 }
23838
23839 current_thread_info()->sysenter_return =
23840 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
23841 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
23842
23843 up_fail:
23844 if (ret)
23845 - current->mm->context.vdso = NULL;
23846 + current->mm->context.vdso = 0;
23847
23848 up_write(&mm->mmap_sem);
23849
23850 @@ -412,8 +413,14 @@ __initcall(ia32_binfmt_init);
23851
23852 const char *arch_vma_name(struct vm_area_struct *vma)
23853 {
23854 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
23855 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
23856 return "[vdso]";
23857 +
23858 +#ifdef CONFIG_PAX_SEGMEXEC
23859 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
23860 + return "[vdso]";
23861 +#endif
23862 +
23863 return NULL;
23864 }
23865
23866 @@ -423,7 +430,7 @@ struct vm_area_struct *get_gate_vma(stru
23867 * Check to see if the corresponding task was created in compat vdso
23868 * mode.
23869 */
23870 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
23871 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
23872 return &gate_vma;
23873 return NULL;
23874 }
23875 diff -urNp linux-2.6.39/arch/x86/vdso/vdso.lds.S linux-2.6.39/arch/x86/vdso/vdso.lds.S
23876 --- linux-2.6.39/arch/x86/vdso/vdso.lds.S 2011-05-19 00:06:34.000000000 -0400
23877 +++ linux-2.6.39/arch/x86/vdso/vdso.lds.S 2011-05-22 19:36:30.000000000 -0400
23878 @@ -35,3 +35,9 @@ VDSO64_PRELINK = VDSO_PRELINK;
23879 #define VEXTERN(x) VDSO64_ ## x = vdso_ ## x;
23880 #include "vextern.h"
23881 #undef VEXTERN
23882 +
23883 +#define VEXTERN(x) VDSO64_ ## x = __vdso_ ## x;
23884 +VEXTERN(fallback_gettimeofday)
23885 +VEXTERN(fallback_time)
23886 +VEXTERN(getcpu)
23887 +#undef VEXTERN
23888 diff -urNp linux-2.6.39/arch/x86/vdso/vextern.h linux-2.6.39/arch/x86/vdso/vextern.h
23889 --- linux-2.6.39/arch/x86/vdso/vextern.h 2011-05-19 00:06:34.000000000 -0400
23890 +++ linux-2.6.39/arch/x86/vdso/vextern.h 2011-05-22 19:36:30.000000000 -0400
23891 @@ -11,6 +11,5 @@
23892 put into vextern.h and be referenced as a pointer with vdso prefix.
23893 The main kernel later fills in the values. */
23894
23895 -VEXTERN(jiffies)
23896 VEXTERN(vgetcpu_mode)
23897 VEXTERN(vsyscall_gtod_data)
23898 diff -urNp linux-2.6.39/arch/x86/vdso/vma.c linux-2.6.39/arch/x86/vdso/vma.c
23899 --- linux-2.6.39/arch/x86/vdso/vma.c 2011-05-19 00:06:34.000000000 -0400
23900 +++ linux-2.6.39/arch/x86/vdso/vma.c 2011-05-22 19:36:30.000000000 -0400
23901 @@ -58,7 +58,7 @@ static int __init init_vdso_vars(void)
23902 if (!vbase)
23903 goto oom;
23904
23905 - if (memcmp(vbase, "\177ELF", 4)) {
23906 + if (memcmp(vbase, ELFMAG, SELFMAG)) {
23907 printk("VDSO: I'm broken; not ELF\n");
23908 vdso_enabled = 0;
23909 }
23910 @@ -118,7 +118,7 @@ int arch_setup_additional_pages(struct l
23911 goto up_fail;
23912 }
23913
23914 - current->mm->context.vdso = (void *)addr;
23915 + current->mm->context.vdso = addr;
23916
23917 ret = install_special_mapping(mm, addr, vdso_size,
23918 VM_READ|VM_EXEC|
23919 @@ -126,7 +126,7 @@ int arch_setup_additional_pages(struct l
23920 VM_ALWAYSDUMP,
23921 vdso_pages);
23922 if (ret) {
23923 - current->mm->context.vdso = NULL;
23924 + current->mm->context.vdso = 0;
23925 goto up_fail;
23926 }
23927
23928 @@ -134,10 +134,3 @@ up_fail:
23929 up_write(&mm->mmap_sem);
23930 return ret;
23931 }
23932 -
23933 -static __init int vdso_setup(char *s)
23934 -{
23935 - vdso_enabled = simple_strtoul(s, NULL, 0);
23936 - return 0;
23937 -}
23938 -__setup("vdso=", vdso_setup);
23939 diff -urNp linux-2.6.39/arch/x86/xen/enlighten.c linux-2.6.39/arch/x86/xen/enlighten.c
23940 --- linux-2.6.39/arch/x86/xen/enlighten.c 2011-05-19 00:06:34.000000000 -0400
23941 +++ linux-2.6.39/arch/x86/xen/enlighten.c 2011-05-22 19:36:30.000000000 -0400
23942 @@ -85,8 +85,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
23943
23944 struct shared_info xen_dummy_shared_info;
23945
23946 -void *xen_initial_gdt;
23947 -
23948 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
23949 __read_mostly int xen_have_vector_callback;
23950 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
23951 @@ -1010,7 +1008,7 @@ static const struct pv_apic_ops xen_apic
23952 #endif
23953 };
23954
23955 -static void xen_reboot(int reason)
23956 +static __noreturn void xen_reboot(int reason)
23957 {
23958 struct sched_shutdown r = { .reason = reason };
23959
23960 @@ -1018,17 +1016,17 @@ static void xen_reboot(int reason)
23961 BUG();
23962 }
23963
23964 -static void xen_restart(char *msg)
23965 +static __noreturn void xen_restart(char *msg)
23966 {
23967 xen_reboot(SHUTDOWN_reboot);
23968 }
23969
23970 -static void xen_emergency_restart(void)
23971 +static __noreturn void xen_emergency_restart(void)
23972 {
23973 xen_reboot(SHUTDOWN_reboot);
23974 }
23975
23976 -static void xen_machine_halt(void)
23977 +static __noreturn void xen_machine_halt(void)
23978 {
23979 xen_reboot(SHUTDOWN_poweroff);
23980 }
23981 @@ -1127,7 +1125,17 @@ asmlinkage void __init xen_start_kernel(
23982 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
23983
23984 /* Work out if we support NX */
23985 - x86_configure_nx();
23986 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
23987 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
23988 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
23989 + unsigned l, h;
23990 +
23991 + __supported_pte_mask |= _PAGE_NX;
23992 + rdmsr(MSR_EFER, l, h);
23993 + l |= EFER_NX;
23994 + wrmsr(MSR_EFER, l, h);
23995 + }
23996 +#endif
23997
23998 xen_setup_features();
23999
24000 @@ -1158,13 +1166,6 @@ asmlinkage void __init xen_start_kernel(
24001
24002 machine_ops = xen_machine_ops;
24003
24004 - /*
24005 - * The only reliable way to retain the initial address of the
24006 - * percpu gdt_page is to remember it here, so we can go and
24007 - * mark it RW later, when the initial percpu area is freed.
24008 - */
24009 - xen_initial_gdt = &per_cpu(gdt_page, 0);
24010 -
24011 xen_smp_init();
24012
24013 #ifdef CONFIG_ACPI_NUMA
24014 diff -urNp linux-2.6.39/arch/x86/xen/mmu.c linux-2.6.39/arch/x86/xen/mmu.c
24015 --- linux-2.6.39/arch/x86/xen/mmu.c 2011-05-19 00:06:34.000000000 -0400
24016 +++ linux-2.6.39/arch/x86/xen/mmu.c 2011-05-22 19:36:30.000000000 -0400
24017 @@ -1791,6 +1791,8 @@ __init pgd_t *xen_setup_kernel_pagetable
24018 convert_pfn_mfn(init_level4_pgt);
24019 convert_pfn_mfn(level3_ident_pgt);
24020 convert_pfn_mfn(level3_kernel_pgt);
24021 + convert_pfn_mfn(level3_vmalloc_pgt);
24022 + convert_pfn_mfn(level3_vmemmap_pgt);
24023
24024 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
24025 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
24026 @@ -1809,7 +1811,10 @@ __init pgd_t *xen_setup_kernel_pagetable
24027 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
24028 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
24029 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
24030 + set_page_prot(level3_vmalloc_pgt, PAGE_KERNEL_RO);
24031 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
24032 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
24033 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
24034 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
24035 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
24036
24037 diff -urNp linux-2.6.39/arch/x86/xen/pci-swiotlb-xen.c linux-2.6.39/arch/x86/xen/pci-swiotlb-xen.c
24038 --- linux-2.6.39/arch/x86/xen/pci-swiotlb-xen.c 2011-05-19 00:06:34.000000000 -0400
24039 +++ linux-2.6.39/arch/x86/xen/pci-swiotlb-xen.c 2011-05-22 19:36:30.000000000 -0400
24040 @@ -10,7 +10,7 @@
24041
24042 int xen_swiotlb __read_mostly;
24043
24044 -static struct dma_map_ops xen_swiotlb_dma_ops = {
24045 +static const struct dma_map_ops xen_swiotlb_dma_ops = {
24046 .mapping_error = xen_swiotlb_dma_mapping_error,
24047 .alloc_coherent = xen_swiotlb_alloc_coherent,
24048 .free_coherent = xen_swiotlb_free_coherent,
24049 diff -urNp linux-2.6.39/arch/x86/xen/smp.c linux-2.6.39/arch/x86/xen/smp.c
24050 --- linux-2.6.39/arch/x86/xen/smp.c 2011-05-19 00:06:34.000000000 -0400
24051 +++ linux-2.6.39/arch/x86/xen/smp.c 2011-05-22 19:36:30.000000000 -0400
24052 @@ -194,11 +194,6 @@ static void __init xen_smp_prepare_boot_
24053 {
24054 BUG_ON(smp_processor_id() != 0);
24055 native_smp_prepare_boot_cpu();
24056 -
24057 - /* We've switched to the "real" per-cpu gdt, so make sure the
24058 - old memory can be recycled */
24059 - make_lowmem_page_readwrite(xen_initial_gdt);
24060 -
24061 xen_filter_cpu_maps();
24062 xen_setup_vcpu_info_placement();
24063 }
24064 @@ -259,12 +254,12 @@ cpu_initialize_context(unsigned int cpu,
24065 gdt = get_cpu_gdt_table(cpu);
24066
24067 ctxt->flags = VGCF_IN_KERNEL;
24068 - ctxt->user_regs.ds = __USER_DS;
24069 - ctxt->user_regs.es = __USER_DS;
24070 + ctxt->user_regs.ds = __KERNEL_DS;
24071 + ctxt->user_regs.es = __KERNEL_DS;
24072 ctxt->user_regs.ss = __KERNEL_DS;
24073 #ifdef CONFIG_X86_32
24074 ctxt->user_regs.fs = __KERNEL_PERCPU;
24075 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
24076 + savesegment(gs, ctxt->user_regs.gs);
24077 #else
24078 ctxt->gs_base_kernel = per_cpu_offset(cpu);
24079 #endif
24080 @@ -315,13 +310,12 @@ static int __cpuinit xen_cpu_up(unsigned
24081 int rc;
24082
24083 per_cpu(current_task, cpu) = idle;
24084 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
24085 #ifdef CONFIG_X86_32
24086 irq_ctx_init(cpu);
24087 #else
24088 clear_tsk_thread_flag(idle, TIF_FORK);
24089 - per_cpu(kernel_stack, cpu) =
24090 - (unsigned long)task_stack_page(idle) -
24091 - KERNEL_STACK_OFFSET + THREAD_SIZE;
24092 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
24093 #endif
24094 xen_setup_runstate_info(cpu);
24095 xen_setup_timer(cpu);
24096 diff -urNp linux-2.6.39/arch/x86/xen/xen-asm_32.S linux-2.6.39/arch/x86/xen/xen-asm_32.S
24097 --- linux-2.6.39/arch/x86/xen/xen-asm_32.S 2011-05-19 00:06:34.000000000 -0400
24098 +++ linux-2.6.39/arch/x86/xen/xen-asm_32.S 2011-05-22 19:36:30.000000000 -0400
24099 @@ -83,14 +83,14 @@ ENTRY(xen_iret)
24100 ESP_OFFSET=4 # bytes pushed onto stack
24101
24102 /*
24103 - * Store vcpu_info pointer for easy access. Do it this way to
24104 - * avoid having to reload %fs
24105 + * Store vcpu_info pointer for easy access.
24106 */
24107 #ifdef CONFIG_SMP
24108 - GET_THREAD_INFO(%eax)
24109 - movl TI_cpu(%eax), %eax
24110 - movl __per_cpu_offset(,%eax,4), %eax
24111 - mov xen_vcpu(%eax), %eax
24112 + push %fs
24113 + mov $(__KERNEL_PERCPU), %eax
24114 + mov %eax, %fs
24115 + mov PER_CPU_VAR(xen_vcpu), %eax
24116 + pop %fs
24117 #else
24118 movl xen_vcpu, %eax
24119 #endif
24120 diff -urNp linux-2.6.39/arch/x86/xen/xen-head.S linux-2.6.39/arch/x86/xen/xen-head.S
24121 --- linux-2.6.39/arch/x86/xen/xen-head.S 2011-05-19 00:06:34.000000000 -0400
24122 +++ linux-2.6.39/arch/x86/xen/xen-head.S 2011-05-22 19:36:30.000000000 -0400
24123 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
24124 #ifdef CONFIG_X86_32
24125 mov %esi,xen_start_info
24126 mov $init_thread_union+THREAD_SIZE,%esp
24127 +#ifdef CONFIG_SMP
24128 + movl $cpu_gdt_table,%edi
24129 + movl $__per_cpu_load,%eax
24130 + movw %ax,__KERNEL_PERCPU + 2(%edi)
24131 + rorl $16,%eax
24132 + movb %al,__KERNEL_PERCPU + 4(%edi)
24133 + movb %ah,__KERNEL_PERCPU + 7(%edi)
24134 + movl $__per_cpu_end - 1,%eax
24135 + subl $__per_cpu_start,%eax
24136 + movw %ax,__KERNEL_PERCPU + 0(%edi)
24137 +#endif
24138 #else
24139 mov %rsi,xen_start_info
24140 mov $init_thread_union+THREAD_SIZE,%rsp
24141 diff -urNp linux-2.6.39/arch/x86/xen/xen-ops.h linux-2.6.39/arch/x86/xen/xen-ops.h
24142 --- linux-2.6.39/arch/x86/xen/xen-ops.h 2011-05-19 00:06:34.000000000 -0400
24143 +++ linux-2.6.39/arch/x86/xen/xen-ops.h 2011-05-22 19:36:30.000000000 -0400
24144 @@ -10,8 +10,6 @@
24145 extern const char xen_hypervisor_callback[];
24146 extern const char xen_failsafe_callback[];
24147
24148 -extern void *xen_initial_gdt;
24149 -
24150 struct trap_info;
24151 void xen_copy_trap_info(struct trap_info *traps);
24152
24153 diff -urNp linux-2.6.39/block/blk-iopoll.c linux-2.6.39/block/blk-iopoll.c
24154 --- linux-2.6.39/block/blk-iopoll.c 2011-05-19 00:06:34.000000000 -0400
24155 +++ linux-2.6.39/block/blk-iopoll.c 2011-05-22 19:36:30.000000000 -0400
24156 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopo
24157 }
24158 EXPORT_SYMBOL(blk_iopoll_complete);
24159
24160 -static void blk_iopoll_softirq(struct softirq_action *h)
24161 +static void blk_iopoll_softirq(void)
24162 {
24163 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
24164 int rearm = 0, budget = blk_iopoll_budget;
24165 diff -urNp linux-2.6.39/block/blk-map.c linux-2.6.39/block/blk-map.c
24166 --- linux-2.6.39/block/blk-map.c 2011-05-19 00:06:34.000000000 -0400
24167 +++ linux-2.6.39/block/blk-map.c 2011-05-22 19:36:30.000000000 -0400
24168 @@ -301,7 +301,7 @@ int blk_rq_map_kern(struct request_queue
24169 if (!len || !kbuf)
24170 return -EINVAL;
24171
24172 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
24173 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
24174 if (do_copy)
24175 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
24176 else
24177 diff -urNp linux-2.6.39/block/blk-softirq.c linux-2.6.39/block/blk-softirq.c
24178 --- linux-2.6.39/block/blk-softirq.c 2011-05-19 00:06:34.000000000 -0400
24179 +++ linux-2.6.39/block/blk-softirq.c 2011-05-22 19:36:30.000000000 -0400
24180 @@ -17,7 +17,7 @@ static DEFINE_PER_CPU(struct list_head,
24181 * Softirq action handler - move entries to local list and loop over them
24182 * while passing them to the queue registered handler.
24183 */
24184 -static void blk_done_softirq(struct softirq_action *h)
24185 +static void blk_done_softirq(void)
24186 {
24187 struct list_head *cpu_list, local_list;
24188
24189 diff -urNp linux-2.6.39/block/bsg.c linux-2.6.39/block/bsg.c
24190 --- linux-2.6.39/block/bsg.c 2011-05-19 00:06:34.000000000 -0400
24191 +++ linux-2.6.39/block/bsg.c 2011-05-22 19:36:30.000000000 -0400
24192 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct r
24193 struct sg_io_v4 *hdr, struct bsg_device *bd,
24194 fmode_t has_write_perm)
24195 {
24196 + unsigned char tmpcmd[sizeof(rq->__cmd)];
24197 + unsigned char *cmdptr;
24198 +
24199 if (hdr->request_len > BLK_MAX_CDB) {
24200 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
24201 if (!rq->cmd)
24202 return -ENOMEM;
24203 - }
24204 + cmdptr = rq->cmd;
24205 + } else
24206 + cmdptr = tmpcmd;
24207
24208 - if (copy_from_user(rq->cmd, (void *)(unsigned long)hdr->request,
24209 + if (copy_from_user(cmdptr, (void *)(unsigned long)hdr->request,
24210 hdr->request_len))
24211 return -EFAULT;
24212
24213 + if (cmdptr != rq->cmd)
24214 + memcpy(rq->cmd, cmdptr, hdr->request_len);
24215 +
24216 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
24217 if (blk_verify_command(rq->cmd, has_write_perm))
24218 return -EPERM;
24219 diff -urNp linux-2.6.39/block/scsi_ioctl.c linux-2.6.39/block/scsi_ioctl.c
24220 --- linux-2.6.39/block/scsi_ioctl.c 2011-05-19 00:06:34.000000000 -0400
24221 +++ linux-2.6.39/block/scsi_ioctl.c 2011-05-22 19:36:30.000000000 -0400
24222 @@ -222,8 +222,20 @@ EXPORT_SYMBOL(blk_verify_command);
24223 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
24224 struct sg_io_hdr *hdr, fmode_t mode)
24225 {
24226 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
24227 + unsigned char tmpcmd[sizeof(rq->__cmd)];
24228 + unsigned char *cmdptr;
24229 +
24230 + if (rq->cmd != rq->__cmd)
24231 + cmdptr = rq->cmd;
24232 + else
24233 + cmdptr = tmpcmd;
24234 +
24235 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
24236 return -EFAULT;
24237 +
24238 + if (cmdptr != rq->cmd)
24239 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
24240 +
24241 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
24242 return -EPERM;
24243
24244 @@ -432,6 +444,8 @@ int sg_scsi_ioctl(struct request_queue *
24245 int err;
24246 unsigned int in_len, out_len, bytes, opcode, cmdlen;
24247 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
24248 + unsigned char tmpcmd[sizeof(rq->__cmd)];
24249 + unsigned char *cmdptr;
24250
24251 if (!sic)
24252 return -EINVAL;
24253 @@ -465,9 +479,18 @@ int sg_scsi_ioctl(struct request_queue *
24254 */
24255 err = -EFAULT;
24256 rq->cmd_len = cmdlen;
24257 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
24258 +
24259 + if (rq->cmd != rq->__cmd)
24260 + cmdptr = rq->cmd;
24261 + else
24262 + cmdptr = tmpcmd;
24263 +
24264 + if (copy_from_user(cmdptr, sic->data, cmdlen))
24265 goto error;
24266
24267 + if (rq->cmd != cmdptr)
24268 + memcpy(rq->cmd, cmdptr, cmdlen);
24269 +
24270 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
24271 goto error;
24272
24273 diff -urNp linux-2.6.39/crypto/serpent.c linux-2.6.39/crypto/serpent.c
24274 --- linux-2.6.39/crypto/serpent.c 2011-05-19 00:06:34.000000000 -0400
24275 +++ linux-2.6.39/crypto/serpent.c 2011-05-22 19:36:30.000000000 -0400
24276 @@ -224,6 +224,8 @@ static int serpent_setkey(struct crypto_
24277 u32 r0,r1,r2,r3,r4;
24278 int i;
24279
24280 + pax_track_stack();
24281 +
24282 /* Copy key, add padding */
24283
24284 for (i = 0; i < keylen; ++i)
24285 diff -urNp linux-2.6.39/Documentation/dontdiff linux-2.6.39/Documentation/dontdiff
24286 --- linux-2.6.39/Documentation/dontdiff 2011-05-19 00:06:34.000000000 -0400
24287 +++ linux-2.6.39/Documentation/dontdiff 2011-05-22 19:36:30.000000000 -0400
24288 @@ -1,13 +1,16 @@
24289 *.a
24290 *.aux
24291 *.bin
24292 +*.cis
24293 *.cpio
24294 *.csp
24295 +*.dbg
24296 *.dsp
24297 *.dvi
24298 *.elf
24299 *.eps
24300 *.fw
24301 +*.gcno
24302 *.gen.S
24303 *.gif
24304 *.grep
24305 @@ -38,8 +41,10 @@
24306 *.tab.h
24307 *.tex
24308 *.ver
24309 +*.vim
24310 *.xml
24311 *_MODULES
24312 +*_reg_safe.h
24313 *_vga16.c
24314 *~
24315 *.9
24316 @@ -49,11 +54,16 @@
24317 53c700_d.h
24318 CVS
24319 ChangeSet
24320 +GPATH
24321 +GRTAGS
24322 +GSYMS
24323 +GTAGS
24324 Image
24325 Kerntypes
24326 Module.markers
24327 Module.symvers
24328 PENDING
24329 +PERF*
24330 SCCS
24331 System.map*
24332 TAGS
24333 @@ -80,8 +90,11 @@ btfixupprep
24334 build
24335 bvmlinux
24336 bzImage*
24337 +capability_names.h
24338 capflags.c
24339 classlist.h*
24340 +clut_vga16.c
24341 +common-cmds.h
24342 comp*.log
24343 compile.h*
24344 conf
24345 @@ -106,16 +119,19 @@ fore200e_mkfirm
24346 fore200e_pca_fw.c*
24347 gconf
24348 gen-devlist
24349 +gen-kdb_cmds.c
24350 gen_crc32table
24351 gen_init_cpio
24352 generated
24353 genheaders
24354 genksyms
24355 *_gray256.c
24356 +hash
24357 ihex2fw
24358 ikconfig.h*
24359 inat-tables.c
24360 initramfs_data.cpio
24361 +initramfs_data.cpio.bz2
24362 initramfs_data.cpio.gz
24363 initramfs_list
24364 int16.c
24365 @@ -125,7 +141,6 @@ int32.c
24366 int4.c
24367 int8.c
24368 kallsyms
24369 -kconfig
24370 keywords.c
24371 ksym.c*
24372 ksym.h*
24373 @@ -149,7 +164,9 @@ mkboot
24374 mkbugboot
24375 mkcpustr
24376 mkdep
24377 +mkpiggy
24378 mkprep
24379 +mkregtable
24380 mktables
24381 mktree
24382 modpost
24383 @@ -165,6 +182,7 @@ parse.h
24384 patches*
24385 pca200e.bin
24386 pca200e_ecd.bin2
24387 +perf-archive
24388 piggy.gz
24389 piggyback
24390 piggy.S
24391 @@ -180,7 +198,9 @@ r600_reg_safe.h
24392 raid6altivec*.c
24393 raid6int*.c
24394 raid6tables.c
24395 +regdb.c
24396 relocs
24397 +rlim_names.h
24398 rn50_reg_safe.h
24399 rs600_reg_safe.h
24400 rv515_reg_safe.h
24401 @@ -189,6 +209,7 @@ setup
24402 setup.bin
24403 setup.elf
24404 sImage
24405 +slabinfo
24406 sm_tbl*
24407 split-include
24408 syscalltab.h
24409 @@ -213,13 +234,17 @@ version.h*
24410 vmlinux
24411 vmlinux-*
24412 vmlinux.aout
24413 +vmlinux.bin.all
24414 +vmlinux.bin.bz2
24415 vmlinux.lds
24416 +vmlinux.relocs
24417 voffset.h
24418 vsyscall.lds
24419 vsyscall_32.lds
24420 wanxlfw.inc
24421 uImage
24422 unifdef
24423 +utsrelease.h
24424 wakeup.bin
24425 wakeup.elf
24426 wakeup.lds
24427 diff -urNp linux-2.6.39/Documentation/filesystems/configfs/configfs_example_macros.c linux-2.6.39/Documentation/filesystems/configfs/configfs_example_macros.c
24428 --- linux-2.6.39/Documentation/filesystems/configfs/configfs_example_macros.c 2011-05-19 00:06:34.000000000 -0400
24429 +++ linux-2.6.39/Documentation/filesystems/configfs/configfs_example_macros.c 2011-05-22 19:36:30.000000000 -0400
24430 @@ -368,7 +368,7 @@ static struct configfs_item_operations g
24431 * Note that, since no extra work is required on ->drop_item(),
24432 * no ->drop_item() is provided.
24433 */
24434 -static struct configfs_group_operations group_children_group_ops = {
24435 +static const struct configfs_group_operations group_children_group_ops = {
24436 .make_group = group_children_make_group,
24437 };
24438
24439 diff -urNp linux-2.6.39/Documentation/filesystems/sysfs.txt linux-2.6.39/Documentation/filesystems/sysfs.txt
24440 --- linux-2.6.39/Documentation/filesystems/sysfs.txt 2011-05-19 00:06:34.000000000 -0400
24441 +++ linux-2.6.39/Documentation/filesystems/sysfs.txt 2011-05-22 19:36:30.000000000 -0400
24442 @@ -125,8 +125,8 @@ set of sysfs operations for forwarding r
24443 show and store methods of the attribute owners.
24444
24445 struct sysfs_ops {
24446 - ssize_t (*show)(struct kobject *, struct attribute *, char *);
24447 - ssize_t (*store)(struct kobject *, struct attribute *, const char *, size_t);
24448 + ssize_t (* const show)(struct kobject *, struct attribute *, char *);
24449 + ssize_t (* const store)(struct kobject *, struct attribute *, const char *, size_t);
24450 };
24451
24452 [ Subsystems should have already defined a struct kobj_type as a
24453 diff -urNp linux-2.6.39/Documentation/kernel-parameters.txt linux-2.6.39/Documentation/kernel-parameters.txt
24454 --- linux-2.6.39/Documentation/kernel-parameters.txt 2011-05-19 00:06:34.000000000 -0400
24455 +++ linux-2.6.39/Documentation/kernel-parameters.txt 2011-05-22 19:36:30.000000000 -0400
24456 @@ -1879,6 +1879,13 @@ bytes respectively. Such letter suffixes
24457 the specified number of seconds. This is to be used if
24458 your oopses keep scrolling off the screen.
24459
24460 + pax_nouderef [X86] disables UDEREF. Most likely needed under certain
24461 + virtualization environments that don't cope well with the
24462 + expand down segment used by UDEREF on X86-32 or the frequent
24463 + page table updates on X86-64.
24464 +
24465 + pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
24466 +
24467 pcbit= [HW,ISDN]
24468
24469 pcd. [PARIDE]
24470 diff -urNp linux-2.6.39/drivers/acpi/acpi_ipmi.c linux-2.6.39/drivers/acpi/acpi_ipmi.c
24471 --- linux-2.6.39/drivers/acpi/acpi_ipmi.c 2011-05-19 00:06:34.000000000 -0400
24472 +++ linux-2.6.39/drivers/acpi/acpi_ipmi.c 2011-05-22 19:36:30.000000000 -0400
24473 @@ -70,7 +70,7 @@ struct acpi_ipmi_device {
24474 struct ipmi_driver_data {
24475 struct list_head ipmi_devices;
24476 struct ipmi_smi_watcher bmc_events;
24477 - struct ipmi_user_hndl ipmi_hndlrs;
24478 + const struct ipmi_user_hndl ipmi_hndlrs;
24479 struct mutex ipmi_lock;
24480 };
24481
24482 diff -urNp linux-2.6.39/drivers/acpi/apei/cper.c linux-2.6.39/drivers/acpi/apei/cper.c
24483 --- linux-2.6.39/drivers/acpi/apei/cper.c 2011-05-19 00:06:34.000000000 -0400
24484 +++ linux-2.6.39/drivers/acpi/apei/cper.c 2011-05-22 19:36:30.000000000 -0400
24485 @@ -38,12 +38,12 @@
24486 */
24487 u64 cper_next_record_id(void)
24488 {
24489 - static atomic64_t seq;
24490 + static atomic64_unchecked_t seq;
24491
24492 - if (!atomic64_read(&seq))
24493 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
24494 + if (!atomic64_read_unchecked(&seq))
24495 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
24496
24497 - return atomic64_inc_return(&seq);
24498 + return atomic64_inc_return_unchecked(&seq);
24499 }
24500 EXPORT_SYMBOL_GPL(cper_next_record_id);
24501
24502 diff -urNp linux-2.6.39/drivers/acpi/battery.c linux-2.6.39/drivers/acpi/battery.c
24503 --- linux-2.6.39/drivers/acpi/battery.c 2011-05-19 00:06:34.000000000 -0400
24504 +++ linux-2.6.39/drivers/acpi/battery.c 2011-05-22 19:36:30.000000000 -0400
24505 @@ -864,7 +864,7 @@ DECLARE_FILE_FUNCTIONS(alarm);
24506 }
24507
24508 static struct battery_file {
24509 - struct file_operations ops;
24510 + const struct file_operations ops;
24511 mode_t mode;
24512 const char *name;
24513 } acpi_battery_file[] = {
24514 diff -urNp linux-2.6.39/drivers/acpi/dock.c linux-2.6.39/drivers/acpi/dock.c
24515 --- linux-2.6.39/drivers/acpi/dock.c 2011-05-19 00:06:34.000000000 -0400
24516 +++ linux-2.6.39/drivers/acpi/dock.c 2011-05-22 19:36:30.000000000 -0400
24517 @@ -77,7 +77,7 @@ struct dock_dependent_device {
24518 struct list_head list;
24519 struct list_head hotplug_list;
24520 acpi_handle handle;
24521 - struct acpi_dock_ops *ops;
24522 + const struct acpi_dock_ops *ops;
24523 void *context;
24524 };
24525
24526 @@ -589,7 +589,7 @@ EXPORT_SYMBOL_GPL(unregister_dock_notifi
24527 * the dock driver after _DCK is executed.
24528 */
24529 int
24530 -register_hotplug_dock_device(acpi_handle handle, struct acpi_dock_ops *ops,
24531 +register_hotplug_dock_device(acpi_handle handle, const struct acpi_dock_ops *ops,
24532 void *context)
24533 {
24534 struct dock_dependent_device *dd;
24535 diff -urNp linux-2.6.39/drivers/acpi/ec_sys.c linux-2.6.39/drivers/acpi/ec_sys.c
24536 --- linux-2.6.39/drivers/acpi/ec_sys.c 2011-05-19 00:06:34.000000000 -0400
24537 +++ linux-2.6.39/drivers/acpi/ec_sys.c 2011-05-22 19:36:30.000000000 -0400
24538 @@ -92,7 +92,7 @@ static ssize_t acpi_ec_write_io(struct f
24539 return count;
24540 }
24541
24542 -static struct file_operations acpi_ec_io_ops = {
24543 +static const struct file_operations acpi_ec_io_ops = {
24544 .owner = THIS_MODULE,
24545 .open = acpi_ec_open_io,
24546 .read = acpi_ec_read_io,
24547 diff -urNp linux-2.6.39/drivers/acpi/fan.c linux-2.6.39/drivers/acpi/fan.c
24548 --- linux-2.6.39/drivers/acpi/fan.c 2011-05-19 00:06:34.000000000 -0400
24549 +++ linux-2.6.39/drivers/acpi/fan.c 2011-05-22 19:36:30.000000000 -0400
24550 @@ -110,7 +110,7 @@ fan_set_cur_state(struct thermal_cooling
24551 return result;
24552 }
24553
24554 -static struct thermal_cooling_device_ops fan_cooling_ops = {
24555 +static const struct thermal_cooling_device_ops fan_cooling_ops = {
24556 .get_max_state = fan_get_max_state,
24557 .get_cur_state = fan_get_cur_state,
24558 .set_cur_state = fan_set_cur_state,
24559 diff -urNp linux-2.6.39/drivers/acpi/power_meter.c linux-2.6.39/drivers/acpi/power_meter.c
24560 --- linux-2.6.39/drivers/acpi/power_meter.c 2011-05-19 00:06:34.000000000 -0400
24561 +++ linux-2.6.39/drivers/acpi/power_meter.c 2011-05-22 19:36:30.000000000 -0400
24562 @@ -316,8 +316,6 @@ static ssize_t set_trip(struct device *d
24563 return res;
24564
24565 temp /= 1000;
24566 - if (temp < 0)
24567 - return -EINVAL;
24568
24569 mutex_lock(&resource->lock);
24570 resource->trip[attr->index - 7] = temp;
24571 diff -urNp linux-2.6.39/drivers/acpi/proc.c linux-2.6.39/drivers/acpi/proc.c
24572 --- linux-2.6.39/drivers/acpi/proc.c 2011-05-19 00:06:34.000000000 -0400
24573 +++ linux-2.6.39/drivers/acpi/proc.c 2011-05-22 19:36:30.000000000 -0400
24574 @@ -342,19 +342,13 @@ acpi_system_write_wakeup_device(struct f
24575 size_t count, loff_t * ppos)
24576 {
24577 struct list_head *node, *next;
24578 - char strbuf[5];
24579 - char str[5] = "";
24580 - unsigned int len = count;
24581 -
24582 - if (len > 4)
24583 - len = 4;
24584 - if (len < 0)
24585 - return -EFAULT;
24586 + char strbuf[5] = {0};
24587
24588 - if (copy_from_user(strbuf, buffer, len))
24589 + if (count > 4)
24590 + count = 4;
24591 + if (copy_from_user(strbuf, buffer, count))
24592 return -EFAULT;
24593 - strbuf[len] = '\0';
24594 - sscanf(strbuf, "%s", str);
24595 + strbuf[count] = '\0';
24596
24597 mutex_lock(&acpi_device_lock);
24598 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
24599 @@ -363,7 +357,7 @@ acpi_system_write_wakeup_device(struct f
24600 if (!dev->wakeup.flags.valid)
24601 continue;
24602
24603 - if (!strncmp(dev->pnp.bus_id, str, 4)) {
24604 + if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
24605 if (device_can_wakeup(&dev->dev)) {
24606 bool enable = !device_may_wakeup(&dev->dev);
24607 device_set_wakeup_enable(&dev->dev, enable);
24608 diff -urNp linux-2.6.39/drivers/acpi/processor_driver.c linux-2.6.39/drivers/acpi/processor_driver.c
24609 --- linux-2.6.39/drivers/acpi/processor_driver.c 2011-05-19 00:06:34.000000000 -0400
24610 +++ linux-2.6.39/drivers/acpi/processor_driver.c 2011-05-22 19:36:30.000000000 -0400
24611 @@ -473,7 +473,7 @@ static int __cpuinit acpi_processor_add(
24612 return 0;
24613 #endif
24614
24615 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
24616 + BUG_ON(pr->id >= nr_cpu_ids);
24617
24618 /*
24619 * Buggy BIOS check
24620 diff -urNp linux-2.6.39/drivers/acpi/processor_idle.c linux-2.6.39/drivers/acpi/processor_idle.c
24621 --- linux-2.6.39/drivers/acpi/processor_idle.c 2011-05-19 00:06:34.000000000 -0400
24622 +++ linux-2.6.39/drivers/acpi/processor_idle.c 2011-05-22 19:36:30.000000000 -0400
24623 @@ -121,7 +121,7 @@ static struct dmi_system_id __cpuinitdat
24624 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
24625 DMI_MATCH(DMI_PRODUCT_NAME,"L8400B series Notebook PC")},
24626 (void *)1},
24627 - {},
24628 + {}
24629 };
24630
24631
24632 diff -urNp linux-2.6.39/drivers/acpi/processor_thermal.c linux-2.6.39/drivers/acpi/processor_thermal.c
24633 --- linux-2.6.39/drivers/acpi/processor_thermal.c 2011-05-19 00:06:34.000000000 -0400
24634 +++ linux-2.6.39/drivers/acpi/processor_thermal.c 2011-05-22 19:36:30.000000000 -0400
24635 @@ -244,7 +244,7 @@ processor_set_cur_state(struct thermal_c
24636 return result;
24637 }
24638
24639 -struct thermal_cooling_device_ops processor_cooling_ops = {
24640 +const struct thermal_cooling_device_ops processor_cooling_ops = {
24641 .get_max_state = processor_get_max_state,
24642 .get_cur_state = processor_get_cur_state,
24643 .set_cur_state = processor_set_cur_state,
24644 diff -urNp linux-2.6.39/drivers/acpi/sysfs.c linux-2.6.39/drivers/acpi/sysfs.c
24645 --- linux-2.6.39/drivers/acpi/sysfs.c 2011-05-19 00:06:34.000000000 -0400
24646 +++ linux-2.6.39/drivers/acpi/sysfs.c 2011-05-22 19:36:30.000000000 -0400
24647 @@ -149,12 +149,12 @@ static int param_get_debug_level(char *b
24648 return result;
24649 }
24650
24651 -static struct kernel_param_ops param_ops_debug_layer = {
24652 +static const struct kernel_param_ops param_ops_debug_layer = {
24653 .set = param_set_uint,
24654 .get = param_get_debug_layer,
24655 };
24656
24657 -static struct kernel_param_ops param_ops_debug_level = {
24658 +static const struct kernel_param_ops param_ops_debug_level = {
24659 .set = param_set_uint,
24660 .get = param_get_debug_level,
24661 };
24662 diff -urNp linux-2.6.39/drivers/acpi/thermal.c linux-2.6.39/drivers/acpi/thermal.c
24663 --- linux-2.6.39/drivers/acpi/thermal.c 2011-05-19 00:06:34.000000000 -0400
24664 +++ linux-2.6.39/drivers/acpi/thermal.c 2011-05-22 19:36:30.000000000 -0400
24665 @@ -812,7 +812,7 @@ acpi_thermal_unbind_cooling_device(struc
24666 thermal_zone_unbind_cooling_device);
24667 }
24668
24669 -static struct thermal_zone_device_ops acpi_thermal_zone_ops = {
24670 +static const struct thermal_zone_device_ops acpi_thermal_zone_ops = {
24671 .bind = acpi_thermal_bind_cooling_device,
24672 .unbind = acpi_thermal_unbind_cooling_device,
24673 .get_temp = thermal_get_temp,
24674 diff -urNp linux-2.6.39/drivers/acpi/video.c linux-2.6.39/drivers/acpi/video.c
24675 --- linux-2.6.39/drivers/acpi/video.c 2011-05-19 00:06:34.000000000 -0400
24676 +++ linux-2.6.39/drivers/acpi/video.c 2011-05-22 19:36:30.000000000 -0400
24677 @@ -308,7 +308,7 @@ video_set_cur_state(struct thermal_cooli
24678 return acpi_video_device_lcd_set_level(video, level);
24679 }
24680
24681 -static struct thermal_cooling_device_ops video_cooling_ops = {
24682 +static const struct thermal_cooling_device_ops video_cooling_ops = {
24683 .get_max_state = video_get_max_state,
24684 .get_cur_state = video_get_cur_state,
24685 .set_cur_state = video_set_cur_state,
24686 diff -urNp linux-2.6.39/drivers/ata/acard-ahci.c linux-2.6.39/drivers/ata/acard-ahci.c
24687 --- linux-2.6.39/drivers/ata/acard-ahci.c 2011-05-19 00:06:34.000000000 -0400
24688 +++ linux-2.6.39/drivers/ata/acard-ahci.c 2011-05-22 19:36:30.000000000 -0400
24689 @@ -87,7 +87,7 @@ static struct scsi_host_template acard_a
24690 AHCI_SHT("acard-ahci"),
24691 };
24692
24693 -static struct ata_port_operations acard_ops = {
24694 +static const struct ata_port_operations acard_ops = {
24695 .inherits = &ahci_ops,
24696 .qc_prep = acard_ahci_qc_prep,
24697 .qc_fill_rtf = acard_ahci_qc_fill_rtf,
24698 diff -urNp linux-2.6.39/drivers/ata/ahci.c linux-2.6.39/drivers/ata/ahci.c
24699 --- linux-2.6.39/drivers/ata/ahci.c 2011-05-19 00:06:34.000000000 -0400
24700 +++ linux-2.6.39/drivers/ata/ahci.c 2011-05-22 19:36:30.000000000 -0400
24701 @@ -94,17 +94,17 @@ static struct scsi_host_template ahci_sh
24702 AHCI_SHT("ahci"),
24703 };
24704
24705 -static struct ata_port_operations ahci_vt8251_ops = {
24706 +static const struct ata_port_operations ahci_vt8251_ops = {
24707 .inherits = &ahci_ops,
24708 .hardreset = ahci_vt8251_hardreset,
24709 };
24710
24711 -static struct ata_port_operations ahci_p5wdh_ops = {
24712 +static const struct ata_port_operations ahci_p5wdh_ops = {
24713 .inherits = &ahci_ops,
24714 .hardreset = ahci_p5wdh_hardreset,
24715 };
24716
24717 -static struct ata_port_operations ahci_sb600_ops = {
24718 +static const struct ata_port_operations ahci_sb600_ops = {
24719 .inherits = &ahci_ops,
24720 .softreset = ahci_sb600_softreset,
24721 .pmp_softreset = ahci_sb600_softreset,
24722 diff -urNp linux-2.6.39/drivers/ata/ahci.h linux-2.6.39/drivers/ata/ahci.h
24723 --- linux-2.6.39/drivers/ata/ahci.h 2011-05-19 00:06:34.000000000 -0400
24724 +++ linux-2.6.39/drivers/ata/ahci.h 2011-05-22 19:36:30.000000000 -0400
24725 @@ -311,7 +311,7 @@ extern struct device_attribute *ahci_sde
24726 .shost_attrs = ahci_shost_attrs, \
24727 .sdev_attrs = ahci_sdev_attrs
24728
24729 -extern struct ata_port_operations ahci_ops;
24730 +extern const struct ata_port_operations ahci_ops;
24731
24732 void ahci_fill_cmd_slot(struct ahci_port_priv *pp, unsigned int tag,
24733 u32 opts);
24734 diff -urNp linux-2.6.39/drivers/ata/ata_generic.c linux-2.6.39/drivers/ata/ata_generic.c
24735 --- linux-2.6.39/drivers/ata/ata_generic.c 2011-05-19 00:06:34.000000000 -0400
24736 +++ linux-2.6.39/drivers/ata/ata_generic.c 2011-05-22 19:36:30.000000000 -0400
24737 @@ -101,7 +101,7 @@ static struct scsi_host_template generic
24738 ATA_BMDMA_SHT(DRV_NAME),
24739 };
24740
24741 -static struct ata_port_operations generic_port_ops = {
24742 +static const struct ata_port_operations generic_port_ops = {
24743 .inherits = &ata_bmdma_port_ops,
24744 .cable_detect = ata_cable_unknown,
24745 .set_mode = generic_set_mode,
24746 diff -urNp linux-2.6.39/drivers/ata/ata_piix.c linux-2.6.39/drivers/ata/ata_piix.c
24747 --- linux-2.6.39/drivers/ata/ata_piix.c 2011-05-19 00:06:34.000000000 -0400
24748 +++ linux-2.6.39/drivers/ata/ata_piix.c 2011-05-22 19:36:30.000000000 -0400
24749 @@ -335,12 +335,12 @@ static struct scsi_host_template piix_sh
24750 ATA_BMDMA_SHT(DRV_NAME),
24751 };
24752
24753 -static struct ata_port_operations piix_sata_ops = {
24754 +static const struct ata_port_operations piix_sata_ops = {
24755 .inherits = &ata_bmdma32_port_ops,
24756 .sff_irq_check = piix_irq_check,
24757 };
24758
24759 -static struct ata_port_operations piix_pata_ops = {
24760 +static const struct ata_port_operations piix_pata_ops = {
24761 .inherits = &piix_sata_ops,
24762 .cable_detect = ata_cable_40wire,
24763 .set_piomode = piix_set_piomode,
24764 @@ -348,12 +348,12 @@ static struct ata_port_operations piix_p
24765 .prereset = piix_pata_prereset,
24766 };
24767
24768 -static struct ata_port_operations piix_vmw_ops = {
24769 +static const struct ata_port_operations piix_vmw_ops = {
24770 .inherits = &piix_pata_ops,
24771 .bmdma_status = piix_vmw_bmdma_status,
24772 };
24773
24774 -static struct ata_port_operations ich_pata_ops = {
24775 +static const struct ata_port_operations ich_pata_ops = {
24776 .inherits = &piix_pata_ops,
24777 .cable_detect = ich_pata_cable_detect,
24778 .set_dmamode = ich_set_dmamode,
24779 @@ -369,7 +369,7 @@ static struct scsi_host_template piix_si
24780 .shost_attrs = piix_sidpr_shost_attrs,
24781 };
24782
24783 -static struct ata_port_operations piix_sidpr_sata_ops = {
24784 +static const struct ata_port_operations piix_sidpr_sata_ops = {
24785 .inherits = &piix_sata_ops,
24786 .hardreset = sata_std_hardreset,
24787 .scr_read = piix_sidpr_scr_read,
24788 diff -urNp linux-2.6.39/drivers/ata/libahci.c linux-2.6.39/drivers/ata/libahci.c
24789 --- linux-2.6.39/drivers/ata/libahci.c 2011-05-19 00:06:34.000000000 -0400
24790 +++ linux-2.6.39/drivers/ata/libahci.c 2011-05-22 19:36:30.000000000 -0400
24791 @@ -141,7 +141,7 @@ struct device_attribute *ahci_sdev_attrs
24792 };
24793 EXPORT_SYMBOL_GPL(ahci_sdev_attrs);
24794
24795 -struct ata_port_operations ahci_ops = {
24796 +const struct ata_port_operations ahci_ops = {
24797 .inherits = &sata_pmp_port_ops,
24798
24799 .qc_defer = ahci_pmp_qc_defer,
24800 diff -urNp linux-2.6.39/drivers/ata/libata-acpi.c linux-2.6.39/drivers/ata/libata-acpi.c
24801 --- linux-2.6.39/drivers/ata/libata-acpi.c 2011-05-19 00:06:34.000000000 -0400
24802 +++ linux-2.6.39/drivers/ata/libata-acpi.c 2011-05-22 19:36:30.000000000 -0400
24803 @@ -218,12 +218,12 @@ static void ata_acpi_dev_uevent(acpi_han
24804 ata_acpi_uevent(dev->link->ap, dev, event);
24805 }
24806
24807 -static struct acpi_dock_ops ata_acpi_dev_dock_ops = {
24808 +static const struct acpi_dock_ops ata_acpi_dev_dock_ops = {
24809 .handler = ata_acpi_dev_notify_dock,
24810 .uevent = ata_acpi_dev_uevent,
24811 };
24812
24813 -static struct acpi_dock_ops ata_acpi_ap_dock_ops = {
24814 +static const struct acpi_dock_ops ata_acpi_ap_dock_ops = {
24815 .handler = ata_acpi_ap_notify_dock,
24816 .uevent = ata_acpi_ap_uevent,
24817 };
24818 diff -urNp linux-2.6.39/drivers/ata/libata-core.c linux-2.6.39/drivers/ata/libata-core.c
24819 --- linux-2.6.39/drivers/ata/libata-core.c 2011-05-19 00:06:34.000000000 -0400
24820 +++ linux-2.6.39/drivers/ata/libata-core.c 2011-05-22 19:36:30.000000000 -0400
24821 @@ -4747,7 +4747,7 @@ void ata_qc_free(struct ata_queued_cmd *
24822 struct ata_port *ap;
24823 unsigned int tag;
24824
24825 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
24826 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
24827 ap = qc->ap;
24828
24829 qc->flags = 0;
24830 @@ -4763,7 +4763,7 @@ void __ata_qc_complete(struct ata_queued
24831 struct ata_port *ap;
24832 struct ata_link *link;
24833
24834 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
24835 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
24836 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
24837 ap = qc->ap;
24838 link = qc->dev->link;
24839 @@ -5756,7 +5756,7 @@ static void ata_host_stop(struct device
24840 * LOCKING:
24841 * None.
24842 */
24843 -static void ata_finalize_port_ops(struct ata_port_operations *ops)
24844 +static void ata_finalize_port_ops(const struct ata_port_operations *ops)
24845 {
24846 static DEFINE_SPINLOCK(lock);
24847 const struct ata_port_operations *cur;
24848 @@ -5768,6 +5768,7 @@ static void ata_finalize_port_ops(struct
24849 return;
24850
24851 spin_lock(&lock);
24852 + pax_open_kernel();
24853
24854 for (cur = ops->inherits; cur; cur = cur->inherits) {
24855 void **inherit = (void **)cur;
24856 @@ -5781,8 +5782,9 @@ static void ata_finalize_port_ops(struct
24857 if (IS_ERR(*pp))
24858 *pp = NULL;
24859
24860 - ops->inherits = NULL;
24861 + ((struct ata_port_operations *)ops)->inherits = NULL;
24862
24863 + pax_close_kernel();
24864 spin_unlock(&lock);
24865 }
24866
24867 @@ -5879,7 +5881,7 @@ int ata_host_start(struct ata_host *host
24868 */
24869 /* KILLME - the only user left is ipr */
24870 void ata_host_init(struct ata_host *host, struct device *dev,
24871 - unsigned long flags, struct ata_port_operations *ops)
24872 + unsigned long flags, const struct ata_port_operations *ops)
24873 {
24874 spin_lock_init(&host->lock);
24875 mutex_init(&host->eh_mutex);
24876 @@ -6583,7 +6585,7 @@ static void ata_dummy_error_handler(stru
24877 /* truly dummy */
24878 }
24879
24880 -struct ata_port_operations ata_dummy_port_ops = {
24881 +const struct ata_port_operations ata_dummy_port_ops = {
24882 .qc_prep = ata_noop_qc_prep,
24883 .qc_issue = ata_dummy_qc_issue,
24884 .error_handler = ata_dummy_error_handler,
24885 diff -urNp linux-2.6.39/drivers/ata/libata-eh.c linux-2.6.39/drivers/ata/libata-eh.c
24886 --- linux-2.6.39/drivers/ata/libata-eh.c 2011-05-19 00:06:34.000000000 -0400
24887 +++ linux-2.6.39/drivers/ata/libata-eh.c 2011-05-22 19:36:30.000000000 -0400
24888 @@ -2518,6 +2518,8 @@ void ata_eh_report(struct ata_port *ap)
24889 {
24890 struct ata_link *link;
24891
24892 + pax_track_stack();
24893 +
24894 ata_for_each_link(link, ap, HOST_FIRST)
24895 ata_eh_link_report(link);
24896 }
24897 @@ -3922,7 +3924,7 @@ void ata_do_eh(struct ata_port *ap, ata_
24898 */
24899 void ata_std_error_handler(struct ata_port *ap)
24900 {
24901 - struct ata_port_operations *ops = ap->ops;
24902 + const struct ata_port_operations *ops = ap->ops;
24903 ata_reset_fn_t hardreset = ops->hardreset;
24904
24905 /* ignore built-in hardreset if SCR access is not available */
24906 diff -urNp linux-2.6.39/drivers/ata/libata-pmp.c linux-2.6.39/drivers/ata/libata-pmp.c
24907 --- linux-2.6.39/drivers/ata/libata-pmp.c 2011-05-19 00:06:34.000000000 -0400
24908 +++ linux-2.6.39/drivers/ata/libata-pmp.c 2011-05-22 19:36:30.000000000 -0400
24909 @@ -912,7 +912,7 @@ static int sata_pmp_handle_link_fail(str
24910 */
24911 static int sata_pmp_eh_recover(struct ata_port *ap)
24912 {
24913 - struct ata_port_operations *ops = ap->ops;
24914 + const struct ata_port_operations *ops = ap->ops;
24915 int pmp_tries, link_tries[SATA_PMP_MAX_PORTS];
24916 struct ata_link *pmp_link = &ap->link;
24917 struct ata_device *pmp_dev = pmp_link->device;
24918 diff -urNp linux-2.6.39/drivers/ata/pata_acpi.c linux-2.6.39/drivers/ata/pata_acpi.c
24919 --- linux-2.6.39/drivers/ata/pata_acpi.c 2011-05-19 00:06:34.000000000 -0400
24920 +++ linux-2.6.39/drivers/ata/pata_acpi.c 2011-05-22 19:36:30.000000000 -0400
24921 @@ -216,7 +216,7 @@ static struct scsi_host_template pacpi_s
24922 ATA_BMDMA_SHT(DRV_NAME),
24923 };
24924
24925 -static struct ata_port_operations pacpi_ops = {
24926 +static const struct ata_port_operations pacpi_ops = {
24927 .inherits = &ata_bmdma_port_ops,
24928 .qc_issue = pacpi_qc_issue,
24929 .cable_detect = pacpi_cable_detect,
24930 diff -urNp linux-2.6.39/drivers/ata/pata_ali.c linux-2.6.39/drivers/ata/pata_ali.c
24931 --- linux-2.6.39/drivers/ata/pata_ali.c 2011-05-19 00:06:34.000000000 -0400
24932 +++ linux-2.6.39/drivers/ata/pata_ali.c 2011-05-22 19:36:30.000000000 -0400
24933 @@ -363,7 +363,7 @@ static struct scsi_host_template ali_sht
24934 * Port operations for PIO only ALi
24935 */
24936
24937 -static struct ata_port_operations ali_early_port_ops = {
24938 +static const struct ata_port_operations ali_early_port_ops = {
24939 .inherits = &ata_sff_port_ops,
24940 .cable_detect = ata_cable_40wire,
24941 .set_piomode = ali_set_piomode,
24942 @@ -380,7 +380,7 @@ static const struct ata_port_operations
24943 * Port operations for DMA capable ALi without cable
24944 * detect
24945 */
24946 -static struct ata_port_operations ali_20_port_ops = {
24947 +static const struct ata_port_operations ali_20_port_ops = {
24948 .inherits = &ali_dma_base_ops,
24949 .cable_detect = ata_cable_40wire,
24950 .mode_filter = ali_20_filter,
24951 @@ -391,7 +391,7 @@ static struct ata_port_operations ali_20
24952 /*
24953 * Port operations for DMA capable ALi with cable detect
24954 */
24955 -static struct ata_port_operations ali_c2_port_ops = {
24956 +static const struct ata_port_operations ali_c2_port_ops = {
24957 .inherits = &ali_dma_base_ops,
24958 .check_atapi_dma = ali_check_atapi_dma,
24959 .cable_detect = ali_c2_cable_detect,
24960 @@ -402,7 +402,7 @@ static struct ata_port_operations ali_c2
24961 /*
24962 * Port operations for DMA capable ALi with cable detect
24963 */
24964 -static struct ata_port_operations ali_c4_port_ops = {
24965 +static const struct ata_port_operations ali_c4_port_ops = {
24966 .inherits = &ali_dma_base_ops,
24967 .check_atapi_dma = ali_check_atapi_dma,
24968 .cable_detect = ali_c2_cable_detect,
24969 @@ -412,7 +412,7 @@ static struct ata_port_operations ali_c4
24970 /*
24971 * Port operations for DMA capable ALi with cable detect and LBA48
24972 */
24973 -static struct ata_port_operations ali_c5_port_ops = {
24974 +static const struct ata_port_operations ali_c5_port_ops = {
24975 .inherits = &ali_dma_base_ops,
24976 .check_atapi_dma = ali_check_atapi_dma,
24977 .dev_config = ali_warn_atapi_dma,
24978 diff -urNp linux-2.6.39/drivers/ata/pata_amd.c linux-2.6.39/drivers/ata/pata_amd.c
24979 --- linux-2.6.39/drivers/ata/pata_amd.c 2011-05-19 00:06:34.000000000 -0400
24980 +++ linux-2.6.39/drivers/ata/pata_amd.c 2011-05-22 19:36:31.000000000 -0400
24981 @@ -397,28 +397,28 @@ static const struct ata_port_operations
24982 .prereset = amd_pre_reset,
24983 };
24984
24985 -static struct ata_port_operations amd33_port_ops = {
24986 +static const struct ata_port_operations amd33_port_ops = {
24987 .inherits = &amd_base_port_ops,
24988 .cable_detect = ata_cable_40wire,
24989 .set_piomode = amd33_set_piomode,
24990 .set_dmamode = amd33_set_dmamode,
24991 };
24992
24993 -static struct ata_port_operations amd66_port_ops = {
24994 +static const struct ata_port_operations amd66_port_ops = {
24995 .inherits = &amd_base_port_ops,
24996 .cable_detect = ata_cable_unknown,
24997 .set_piomode = amd66_set_piomode,
24998 .set_dmamode = amd66_set_dmamode,
24999 };
25000
25001 -static struct ata_port_operations amd100_port_ops = {
25002 +static const struct ata_port_operations amd100_port_ops = {
25003 .inherits = &amd_base_port_ops,
25004 .cable_detect = ata_cable_unknown,
25005 .set_piomode = amd100_set_piomode,
25006 .set_dmamode = amd100_set_dmamode,
25007 };
25008
25009 -static struct ata_port_operations amd133_port_ops = {
25010 +static const struct ata_port_operations amd133_port_ops = {
25011 .inherits = &amd_base_port_ops,
25012 .cable_detect = amd_cable_detect,
25013 .set_piomode = amd133_set_piomode,
25014 @@ -433,13 +433,13 @@ static const struct ata_port_operations
25015 .host_stop = nv_host_stop,
25016 };
25017
25018 -static struct ata_port_operations nv100_port_ops = {
25019 +static const struct ata_port_operations nv100_port_ops = {
25020 .inherits = &nv_base_port_ops,
25021 .set_piomode = nv100_set_piomode,
25022 .set_dmamode = nv100_set_dmamode,
25023 };
25024
25025 -static struct ata_port_operations nv133_port_ops = {
25026 +static const struct ata_port_operations nv133_port_ops = {
25027 .inherits = &nv_base_port_ops,
25028 .set_piomode = nv133_set_piomode,
25029 .set_dmamode = nv133_set_dmamode,
25030 diff -urNp linux-2.6.39/drivers/ata/pata_arasan_cf.c linux-2.6.39/drivers/ata/pata_arasan_cf.c
25031 --- linux-2.6.39/drivers/ata/pata_arasan_cf.c 2011-05-19 00:06:34.000000000 -0400
25032 +++ linux-2.6.39/drivers/ata/pata_arasan_cf.c 2011-05-22 19:36:31.000000000 -0400
25033 @@ -862,7 +862,9 @@ static int __devinit arasan_cf_probe(str
25034 /* Handle platform specific quirks */
25035 if (pdata->quirk) {
25036 if (pdata->quirk & CF_BROKEN_PIO) {
25037 - ap->ops->set_piomode = NULL;
25038 + pax_open_kernel();
25039 + *(void**)&ap->ops->set_piomode = NULL;
25040 + pax_close_kernel();
25041 ap->pio_mask = 0;
25042 }
25043 if (pdata->quirk & CF_BROKEN_MWDMA)
25044 diff -urNp linux-2.6.39/drivers/ata/pata_artop.c linux-2.6.39/drivers/ata/pata_artop.c
25045 --- linux-2.6.39/drivers/ata/pata_artop.c 2011-05-19 00:06:34.000000000 -0400
25046 +++ linux-2.6.39/drivers/ata/pata_artop.c 2011-05-22 19:36:31.000000000 -0400
25047 @@ -312,7 +312,7 @@ static struct scsi_host_template artop_s
25048 ATA_BMDMA_SHT(DRV_NAME),
25049 };
25050
25051 -static struct ata_port_operations artop6210_ops = {
25052 +static const struct ata_port_operations artop6210_ops = {
25053 .inherits = &ata_bmdma_port_ops,
25054 .cable_detect = ata_cable_40wire,
25055 .set_piomode = artop6210_set_piomode,
25056 @@ -321,7 +321,7 @@ static struct ata_port_operations artop6
25057 .qc_defer = artop6210_qc_defer,
25058 };
25059
25060 -static struct ata_port_operations artop6260_ops = {
25061 +static const struct ata_port_operations artop6260_ops = {
25062 .inherits = &ata_bmdma_port_ops,
25063 .cable_detect = artop6260_cable_detect,
25064 .set_piomode = artop6260_set_piomode,
25065 diff -urNp linux-2.6.39/drivers/ata/pata_at32.c linux-2.6.39/drivers/ata/pata_at32.c
25066 --- linux-2.6.39/drivers/ata/pata_at32.c 2011-05-19 00:06:34.000000000 -0400
25067 +++ linux-2.6.39/drivers/ata/pata_at32.c 2011-05-22 19:36:31.000000000 -0400
25068 @@ -173,7 +173,7 @@ static struct scsi_host_template at32_sh
25069 ATA_PIO_SHT(DRV_NAME),
25070 };
25071
25072 -static struct ata_port_operations at32_port_ops = {
25073 +static const struct ata_port_operations at32_port_ops = {
25074 .inherits = &ata_sff_port_ops,
25075 .cable_detect = ata_cable_40wire,
25076 .set_piomode = pata_at32_set_piomode,
25077 diff -urNp linux-2.6.39/drivers/ata/pata_at91.c linux-2.6.39/drivers/ata/pata_at91.c
25078 --- linux-2.6.39/drivers/ata/pata_at91.c 2011-05-19 00:06:34.000000000 -0400
25079 +++ linux-2.6.39/drivers/ata/pata_at91.c 2011-05-22 19:36:31.000000000 -0400
25080 @@ -212,7 +212,7 @@ static struct scsi_host_template pata_at
25081 ATA_PIO_SHT(DRV_NAME),
25082 };
25083
25084 -static struct ata_port_operations pata_at91_port_ops = {
25085 +static const struct ata_port_operations pata_at91_port_ops = {
25086 .inherits = &ata_sff_port_ops,
25087
25088 .sff_data_xfer = pata_at91_data_xfer_noirq,
25089 diff -urNp linux-2.6.39/drivers/ata/pata_atiixp.c linux-2.6.39/drivers/ata/pata_atiixp.c
25090 --- linux-2.6.39/drivers/ata/pata_atiixp.c 2011-05-19 00:06:34.000000000 -0400
25091 +++ linux-2.6.39/drivers/ata/pata_atiixp.c 2011-05-22 19:36:31.000000000 -0400
25092 @@ -214,7 +214,7 @@ static struct scsi_host_template atiixp_
25093 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
25094 };
25095
25096 -static struct ata_port_operations atiixp_port_ops = {
25097 +static const struct ata_port_operations atiixp_port_ops = {
25098 .inherits = &ata_bmdma_port_ops,
25099
25100 .qc_prep = ata_bmdma_dumb_qc_prep,
25101 diff -urNp linux-2.6.39/drivers/ata/pata_atp867x.c linux-2.6.39/drivers/ata/pata_atp867x.c
25102 --- linux-2.6.39/drivers/ata/pata_atp867x.c 2011-05-19 00:06:34.000000000 -0400
25103 +++ linux-2.6.39/drivers/ata/pata_atp867x.c 2011-05-22 19:36:31.000000000 -0400
25104 @@ -275,7 +275,7 @@ static struct scsi_host_template atp867x
25105 ATA_BMDMA_SHT(DRV_NAME),
25106 };
25107
25108 -static struct ata_port_operations atp867x_ops = {
25109 +static const struct ata_port_operations atp867x_ops = {
25110 .inherits = &ata_bmdma_port_ops,
25111 .cable_detect = atp867x_cable_detect,
25112 .set_piomode = atp867x_set_piomode,
25113 diff -urNp linux-2.6.39/drivers/ata/pata_bf54x.c linux-2.6.39/drivers/ata/pata_bf54x.c
25114 --- linux-2.6.39/drivers/ata/pata_bf54x.c 2011-05-19 00:06:34.000000000 -0400
25115 +++ linux-2.6.39/drivers/ata/pata_bf54x.c 2011-05-22 19:36:31.000000000 -0400
25116 @@ -1420,7 +1420,7 @@ static struct scsi_host_template bfin_sh
25117 .dma_boundary = ATA_DMA_BOUNDARY,
25118 };
25119
25120 -static struct ata_port_operations bfin_pata_ops = {
25121 +static const struct ata_port_operations bfin_pata_ops = {
25122 .inherits = &ata_bmdma_port_ops,
25123
25124 .set_piomode = bfin_set_piomode,
25125 diff -urNp linux-2.6.39/drivers/ata/pata_cmd640.c linux-2.6.39/drivers/ata/pata_cmd640.c
25126 --- linux-2.6.39/drivers/ata/pata_cmd640.c 2011-05-19 00:06:34.000000000 -0400
25127 +++ linux-2.6.39/drivers/ata/pata_cmd640.c 2011-05-22 19:36:31.000000000 -0400
25128 @@ -176,7 +176,7 @@ static struct scsi_host_template cmd640_
25129 ATA_PIO_SHT(DRV_NAME),
25130 };
25131
25132 -static struct ata_port_operations cmd640_port_ops = {
25133 +static const struct ata_port_operations cmd640_port_ops = {
25134 .inherits = &ata_sff_port_ops,
25135 /* In theory xfer_noirq is not needed once we kill the prefetcher */
25136 .sff_data_xfer = ata_sff_data_xfer_noirq,
25137 diff -urNp linux-2.6.39/drivers/ata/pata_cmd64x.c linux-2.6.39/drivers/ata/pata_cmd64x.c
25138 --- linux-2.6.39/drivers/ata/pata_cmd64x.c 2011-05-19 00:06:34.000000000 -0400
25139 +++ linux-2.6.39/drivers/ata/pata_cmd64x.c 2011-05-22 19:36:31.000000000 -0400
25140 @@ -268,18 +268,18 @@ static const struct ata_port_operations
25141 .set_dmamode = cmd64x_set_dmamode,
25142 };
25143
25144 -static struct ata_port_operations cmd64x_port_ops = {
25145 +static const struct ata_port_operations cmd64x_port_ops = {
25146 .inherits = &cmd64x_base_ops,
25147 .cable_detect = ata_cable_40wire,
25148 };
25149
25150 -static struct ata_port_operations cmd646r1_port_ops = {
25151 +static const struct ata_port_operations cmd646r1_port_ops = {
25152 .inherits = &cmd64x_base_ops,
25153 .bmdma_stop = cmd646r1_bmdma_stop,
25154 .cable_detect = ata_cable_40wire,
25155 };
25156
25157 -static struct ata_port_operations cmd648_port_ops = {
25158 +static const struct ata_port_operations cmd648_port_ops = {
25159 .inherits = &cmd64x_base_ops,
25160 .bmdma_stop = cmd648_bmdma_stop,
25161 .cable_detect = cmd648_cable_detect,
25162 diff -urNp linux-2.6.39/drivers/ata/pata_cs5520.c linux-2.6.39/drivers/ata/pata_cs5520.c
25163 --- linux-2.6.39/drivers/ata/pata_cs5520.c 2011-05-19 00:06:34.000000000 -0400
25164 +++ linux-2.6.39/drivers/ata/pata_cs5520.c 2011-05-22 19:36:31.000000000 -0400
25165 @@ -108,7 +108,7 @@ static struct scsi_host_template cs5520_
25166 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
25167 };
25168
25169 -static struct ata_port_operations cs5520_port_ops = {
25170 +static const struct ata_port_operations cs5520_port_ops = {
25171 .inherits = &ata_bmdma_port_ops,
25172 .qc_prep = ata_bmdma_dumb_qc_prep,
25173 .cable_detect = ata_cable_40wire,
25174 diff -urNp linux-2.6.39/drivers/ata/pata_cs5530.c linux-2.6.39/drivers/ata/pata_cs5530.c
25175 --- linux-2.6.39/drivers/ata/pata_cs5530.c 2011-05-19 00:06:34.000000000 -0400
25176 +++ linux-2.6.39/drivers/ata/pata_cs5530.c 2011-05-22 19:36:31.000000000 -0400
25177 @@ -164,7 +164,7 @@ static struct scsi_host_template cs5530_
25178 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
25179 };
25180
25181 -static struct ata_port_operations cs5530_port_ops = {
25182 +static const struct ata_port_operations cs5530_port_ops = {
25183 .inherits = &ata_bmdma_port_ops,
25184
25185 .qc_prep = ata_bmdma_dumb_qc_prep,
25186 diff -urNp linux-2.6.39/drivers/ata/pata_cs5535.c linux-2.6.39/drivers/ata/pata_cs5535.c
25187 --- linux-2.6.39/drivers/ata/pata_cs5535.c 2011-05-19 00:06:34.000000000 -0400
25188 +++ linux-2.6.39/drivers/ata/pata_cs5535.c 2011-05-22 19:36:31.000000000 -0400
25189 @@ -160,7 +160,7 @@ static struct scsi_host_template cs5535_
25190 ATA_BMDMA_SHT(DRV_NAME),
25191 };
25192
25193 -static struct ata_port_operations cs5535_port_ops = {
25194 +static const struct ata_port_operations cs5535_port_ops = {
25195 .inherits = &ata_bmdma_port_ops,
25196 .cable_detect = cs5535_cable_detect,
25197 .set_piomode = cs5535_set_piomode,
25198 diff -urNp linux-2.6.39/drivers/ata/pata_cs5536.c linux-2.6.39/drivers/ata/pata_cs5536.c
25199 --- linux-2.6.39/drivers/ata/pata_cs5536.c 2011-05-19 00:06:34.000000000 -0400
25200 +++ linux-2.6.39/drivers/ata/pata_cs5536.c 2011-05-22 19:36:31.000000000 -0400
25201 @@ -233,7 +233,7 @@ static struct scsi_host_template cs5536_
25202 ATA_BMDMA_SHT(DRV_NAME),
25203 };
25204
25205 -static struct ata_port_operations cs5536_port_ops = {
25206 +static const struct ata_port_operations cs5536_port_ops = {
25207 .inherits = &ata_bmdma32_port_ops,
25208 .cable_detect = cs5536_cable_detect,
25209 .set_piomode = cs5536_set_piomode,
25210 diff -urNp linux-2.6.39/drivers/ata/pata_cypress.c linux-2.6.39/drivers/ata/pata_cypress.c
25211 --- linux-2.6.39/drivers/ata/pata_cypress.c 2011-05-19 00:06:34.000000000 -0400
25212 +++ linux-2.6.39/drivers/ata/pata_cypress.c 2011-05-22 19:36:31.000000000 -0400
25213 @@ -115,7 +115,7 @@ static struct scsi_host_template cy82c69
25214 ATA_BMDMA_SHT(DRV_NAME),
25215 };
25216
25217 -static struct ata_port_operations cy82c693_port_ops = {
25218 +static const struct ata_port_operations cy82c693_port_ops = {
25219 .inherits = &ata_bmdma_port_ops,
25220 .cable_detect = ata_cable_40wire,
25221 .set_piomode = cy82c693_set_piomode,
25222 diff -urNp linux-2.6.39/drivers/ata/pata_efar.c linux-2.6.39/drivers/ata/pata_efar.c
25223 --- linux-2.6.39/drivers/ata/pata_efar.c 2011-05-19 00:06:34.000000000 -0400
25224 +++ linux-2.6.39/drivers/ata/pata_efar.c 2011-05-22 19:36:31.000000000 -0400
25225 @@ -238,7 +238,7 @@ static struct scsi_host_template efar_sh
25226 ATA_BMDMA_SHT(DRV_NAME),
25227 };
25228
25229 -static struct ata_port_operations efar_ops = {
25230 +static const struct ata_port_operations efar_ops = {
25231 .inherits = &ata_bmdma_port_ops,
25232 .cable_detect = efar_cable_detect,
25233 .set_piomode = efar_set_piomode,
25234 diff -urNp linux-2.6.39/drivers/ata/pata_hpt366.c linux-2.6.39/drivers/ata/pata_hpt366.c
25235 --- linux-2.6.39/drivers/ata/pata_hpt366.c 2011-05-19 00:06:34.000000000 -0400
25236 +++ linux-2.6.39/drivers/ata/pata_hpt366.c 2011-05-22 19:36:31.000000000 -0400
25237 @@ -276,7 +276,7 @@ static struct scsi_host_template hpt36x_
25238 * Configuration for HPT366/68
25239 */
25240
25241 -static struct ata_port_operations hpt366_port_ops = {
25242 +static const struct ata_port_operations hpt366_port_ops = {
25243 .inherits = &ata_bmdma_port_ops,
25244 .cable_detect = hpt36x_cable_detect,
25245 .mode_filter = hpt366_filter,
25246 diff -urNp linux-2.6.39/drivers/ata/pata_hpt37x.c linux-2.6.39/drivers/ata/pata_hpt37x.c
25247 --- linux-2.6.39/drivers/ata/pata_hpt37x.c 2011-05-19 00:06:34.000000000 -0400
25248 +++ linux-2.6.39/drivers/ata/pata_hpt37x.c 2011-05-22 19:36:31.000000000 -0400
25249 @@ -589,7 +589,7 @@ static struct scsi_host_template hpt37x_
25250 * Configuration for HPT370
25251 */
25252
25253 -static struct ata_port_operations hpt370_port_ops = {
25254 +static const struct ata_port_operations hpt370_port_ops = {
25255 .inherits = &ata_bmdma_port_ops,
25256
25257 .bmdma_stop = hpt370_bmdma_stop,
25258 @@ -605,7 +605,7 @@ static struct ata_port_operations hpt370
25259 * Configuration for HPT370A. Close to 370 but less filters
25260 */
25261
25262 -static struct ata_port_operations hpt370a_port_ops = {
25263 +static const struct ata_port_operations hpt370a_port_ops = {
25264 .inherits = &hpt370_port_ops,
25265 .mode_filter = hpt370a_filter,
25266 };
25267 @@ -615,7 +615,7 @@ static struct ata_port_operations hpt370
25268 * mode setting functionality.
25269 */
25270
25271 -static struct ata_port_operations hpt302_port_ops = {
25272 +static const struct ata_port_operations hpt302_port_ops = {
25273 .inherits = &ata_bmdma_port_ops,
25274
25275 .bmdma_stop = hpt37x_bmdma_stop,
25276 @@ -631,7 +631,7 @@ static struct ata_port_operations hpt302
25277 * but we have a mode filter.
25278 */
25279
25280 -static struct ata_port_operations hpt372_port_ops = {
25281 +static const struct ata_port_operations hpt372_port_ops = {
25282 .inherits = &hpt302_port_ops,
25283 .mode_filter = hpt372_filter,
25284 };
25285 @@ -641,7 +641,7 @@ static struct ata_port_operations hpt372
25286 * but we have a different cable detection procedure for function 1.
25287 */
25288
25289 -static struct ata_port_operations hpt374_fn1_port_ops = {
25290 +static const struct ata_port_operations hpt374_fn1_port_ops = {
25291 .inherits = &hpt372_port_ops,
25292 .cable_detect = hpt374_fn1_cable_detect,
25293 };
25294 diff -urNp linux-2.6.39/drivers/ata/pata_hpt3x2n.c linux-2.6.39/drivers/ata/pata_hpt3x2n.c
25295 --- linux-2.6.39/drivers/ata/pata_hpt3x2n.c 2011-05-19 00:06:34.000000000 -0400
25296 +++ linux-2.6.39/drivers/ata/pata_hpt3x2n.c 2011-05-22 19:36:31.000000000 -0400
25297 @@ -350,7 +350,7 @@ static struct scsi_host_template hpt3x2n
25298 * Configuration for HPT302N/371N.
25299 */
25300
25301 -static struct ata_port_operations hpt3xxn_port_ops = {
25302 +static const struct ata_port_operations hpt3xxn_port_ops = {
25303 .inherits = &ata_bmdma_port_ops,
25304
25305 .bmdma_stop = hpt3x2n_bmdma_stop,
25306 @@ -368,7 +368,7 @@ static struct ata_port_operations hpt3xx
25307 * Configuration for HPT372N. Same as 302N/371N but we have a mode filter.
25308 */
25309
25310 -static struct ata_port_operations hpt372n_port_ops = {
25311 +static const struct ata_port_operations hpt372n_port_ops = {
25312 .inherits = &hpt3xxn_port_ops,
25313 .mode_filter = &hpt372n_filter,
25314 };
25315 diff -urNp linux-2.6.39/drivers/ata/pata_hpt3x3.c linux-2.6.39/drivers/ata/pata_hpt3x3.c
25316 --- linux-2.6.39/drivers/ata/pata_hpt3x3.c 2011-05-19 00:06:34.000000000 -0400
25317 +++ linux-2.6.39/drivers/ata/pata_hpt3x3.c 2011-05-22 19:36:31.000000000 -0400
25318 @@ -141,7 +141,7 @@ static struct scsi_host_template hpt3x3_
25319 ATA_BMDMA_SHT(DRV_NAME),
25320 };
25321
25322 -static struct ata_port_operations hpt3x3_port_ops = {
25323 +static const struct ata_port_operations hpt3x3_port_ops = {
25324 .inherits = &ata_bmdma_port_ops,
25325 .cable_detect = ata_cable_40wire,
25326 .set_piomode = hpt3x3_set_piomode,
25327 diff -urNp linux-2.6.39/drivers/ata/pata_icside.c linux-2.6.39/drivers/ata/pata_icside.c
25328 --- linux-2.6.39/drivers/ata/pata_icside.c 2011-05-19 00:06:34.000000000 -0400
25329 +++ linux-2.6.39/drivers/ata/pata_icside.c 2011-05-22 19:36:31.000000000 -0400
25330 @@ -320,7 +320,7 @@ static void pata_icside_postreset(struct
25331 }
25332 }
25333
25334 -static struct ata_port_operations pata_icside_port_ops = {
25335 +static const struct ata_port_operations pata_icside_port_ops = {
25336 .inherits = &ata_bmdma_port_ops,
25337 /* no need to build any PRD tables for DMA */
25338 .qc_prep = ata_noop_qc_prep,
25339 diff -urNp linux-2.6.39/drivers/ata/pata_isapnp.c linux-2.6.39/drivers/ata/pata_isapnp.c
25340 --- linux-2.6.39/drivers/ata/pata_isapnp.c 2011-05-19 00:06:34.000000000 -0400
25341 +++ linux-2.6.39/drivers/ata/pata_isapnp.c 2011-05-22 19:36:31.000000000 -0400
25342 @@ -23,12 +23,12 @@ static struct scsi_host_template isapnp_
25343 ATA_PIO_SHT(DRV_NAME),
25344 };
25345
25346 -static struct ata_port_operations isapnp_port_ops = {
25347 +static const struct ata_port_operations isapnp_port_ops = {
25348 .inherits = &ata_sff_port_ops,
25349 .cable_detect = ata_cable_40wire,
25350 };
25351
25352 -static struct ata_port_operations isapnp_noalt_port_ops = {
25353 +static const struct ata_port_operations isapnp_noalt_port_ops = {
25354 .inherits = &ata_sff_port_ops,
25355 .cable_detect = ata_cable_40wire,
25356 /* No altstatus so we don't want to use the lost interrupt poll */
25357 diff -urNp linux-2.6.39/drivers/ata/pata_it8213.c linux-2.6.39/drivers/ata/pata_it8213.c
25358 --- linux-2.6.39/drivers/ata/pata_it8213.c 2011-05-19 00:06:34.000000000 -0400
25359 +++ linux-2.6.39/drivers/ata/pata_it8213.c 2011-05-22 19:36:31.000000000 -0400
25360 @@ -233,7 +233,7 @@ static struct scsi_host_template it8213_
25361 };
25362
25363
25364 -static struct ata_port_operations it8213_ops = {
25365 +static const struct ata_port_operations it8213_ops = {
25366 .inherits = &ata_bmdma_port_ops,
25367 .cable_detect = it8213_cable_detect,
25368 .set_piomode = it8213_set_piomode,
25369 diff -urNp linux-2.6.39/drivers/ata/pata_it821x.c linux-2.6.39/drivers/ata/pata_it821x.c
25370 --- linux-2.6.39/drivers/ata/pata_it821x.c 2011-05-19 00:06:34.000000000 -0400
25371 +++ linux-2.6.39/drivers/ata/pata_it821x.c 2011-05-22 19:36:31.000000000 -0400
25372 @@ -801,7 +801,7 @@ static struct scsi_host_template it821x_
25373 ATA_BMDMA_SHT(DRV_NAME),
25374 };
25375
25376 -static struct ata_port_operations it821x_smart_port_ops = {
25377 +static const struct ata_port_operations it821x_smart_port_ops = {
25378 .inherits = &ata_bmdma_port_ops,
25379
25380 .check_atapi_dma= it821x_check_atapi_dma,
25381 @@ -815,7 +815,7 @@ static struct ata_port_operations it821x
25382 .port_start = it821x_port_start,
25383 };
25384
25385 -static struct ata_port_operations it821x_passthru_port_ops = {
25386 +static const struct ata_port_operations it821x_passthru_port_ops = {
25387 .inherits = &ata_bmdma_port_ops,
25388
25389 .check_atapi_dma= it821x_check_atapi_dma,
25390 @@ -831,7 +831,7 @@ static struct ata_port_operations it821x
25391 .port_start = it821x_port_start,
25392 };
25393
25394 -static struct ata_port_operations it821x_rdc_port_ops = {
25395 +static const struct ata_port_operations it821x_rdc_port_ops = {
25396 .inherits = &ata_bmdma_port_ops,
25397
25398 .check_atapi_dma= it821x_check_atapi_dma,
25399 diff -urNp linux-2.6.39/drivers/ata/pata_ixp4xx_cf.c linux-2.6.39/drivers/ata/pata_ixp4xx_cf.c
25400 --- linux-2.6.39/drivers/ata/pata_ixp4xx_cf.c 2011-05-19 00:06:34.000000000 -0400
25401 +++ linux-2.6.39/drivers/ata/pata_ixp4xx_cf.c 2011-05-22 19:36:31.000000000 -0400
25402 @@ -89,7 +89,7 @@ static struct scsi_host_template ixp4xx_
25403 ATA_PIO_SHT(DRV_NAME),
25404 };
25405
25406 -static struct ata_port_operations ixp4xx_port_ops = {
25407 +static const struct ata_port_operations ixp4xx_port_ops = {
25408 .inherits = &ata_sff_port_ops,
25409 .sff_data_xfer = ixp4xx_mmio_data_xfer,
25410 .cable_detect = ata_cable_40wire,
25411 diff -urNp linux-2.6.39/drivers/ata/pata_jmicron.c linux-2.6.39/drivers/ata/pata_jmicron.c
25412 --- linux-2.6.39/drivers/ata/pata_jmicron.c 2011-05-19 00:06:34.000000000 -0400
25413 +++ linux-2.6.39/drivers/ata/pata_jmicron.c 2011-05-22 19:36:31.000000000 -0400
25414 @@ -111,7 +111,7 @@ static struct scsi_host_template jmicron
25415 ATA_BMDMA_SHT(DRV_NAME),
25416 };
25417
25418 -static struct ata_port_operations jmicron_ops = {
25419 +static const struct ata_port_operations jmicron_ops = {
25420 .inherits = &ata_bmdma_port_ops,
25421 .prereset = jmicron_pre_reset,
25422 };
25423 diff -urNp linux-2.6.39/drivers/ata/pata_legacy.c linux-2.6.39/drivers/ata/pata_legacy.c
25424 --- linux-2.6.39/drivers/ata/pata_legacy.c 2011-05-19 00:06:34.000000000 -0400
25425 +++ linux-2.6.39/drivers/ata/pata_legacy.c 2011-05-22 19:36:31.000000000 -0400
25426 @@ -116,7 +116,7 @@ struct legacy_probe {
25427
25428 struct legacy_controller {
25429 const char *name;
25430 - struct ata_port_operations *ops;
25431 + const struct ata_port_operations *ops;
25432 unsigned int pio_mask;
25433 unsigned int flags;
25434 unsigned int pflags;
25435 @@ -239,12 +239,12 @@ static const struct ata_port_operations
25436 * pio_mask as well.
25437 */
25438
25439 -static struct ata_port_operations simple_port_ops = {
25440 +static const struct ata_port_operations simple_port_ops = {
25441 .inherits = &legacy_base_port_ops,
25442 .sff_data_xfer = ata_sff_data_xfer_noirq,
25443 };
25444
25445 -static struct ata_port_operations legacy_port_ops = {
25446 +static const struct ata_port_operations legacy_port_ops = {
25447 .inherits = &legacy_base_port_ops,
25448 .sff_data_xfer = ata_sff_data_xfer_noirq,
25449 .set_mode = legacy_set_mode,
25450 @@ -340,7 +340,7 @@ static unsigned int pdc_data_xfer_vlb(st
25451 return buflen;
25452 }
25453
25454 -static struct ata_port_operations pdc20230_port_ops = {
25455 +static const struct ata_port_operations pdc20230_port_ops = {
25456 .inherits = &legacy_base_port_ops,
25457 .set_piomode = pdc20230_set_piomode,
25458 .sff_data_xfer = pdc_data_xfer_vlb,
25459 @@ -373,7 +373,7 @@ static void ht6560a_set_piomode(struct a
25460 ioread8(ap->ioaddr.status_addr);
25461 }
25462
25463 -static struct ata_port_operations ht6560a_port_ops = {
25464 +static const struct ata_port_operations ht6560a_port_ops = {
25465 .inherits = &legacy_base_port_ops,
25466 .set_piomode = ht6560a_set_piomode,
25467 };
25468 @@ -416,7 +416,7 @@ static void ht6560b_set_piomode(struct a
25469 ioread8(ap->ioaddr.status_addr);
25470 }
25471
25472 -static struct ata_port_operations ht6560b_port_ops = {
25473 +static const struct ata_port_operations ht6560b_port_ops = {
25474 .inherits = &legacy_base_port_ops,
25475 .set_piomode = ht6560b_set_piomode,
25476 };
25477 @@ -515,7 +515,7 @@ static void opti82c611a_set_piomode(stru
25478 }
25479
25480
25481 -static struct ata_port_operations opti82c611a_port_ops = {
25482 +static const struct ata_port_operations opti82c611a_port_ops = {
25483 .inherits = &legacy_base_port_ops,
25484 .set_piomode = opti82c611a_set_piomode,
25485 };
25486 @@ -625,7 +625,7 @@ static unsigned int opti82c46x_qc_issue(
25487 return ata_sff_qc_issue(qc);
25488 }
25489
25490 -static struct ata_port_operations opti82c46x_port_ops = {
25491 +static const struct ata_port_operations opti82c46x_port_ops = {
25492 .inherits = &legacy_base_port_ops,
25493 .set_piomode = opti82c46x_set_piomode,
25494 .qc_issue = opti82c46x_qc_issue,
25495 @@ -787,20 +787,20 @@ static int qdi_port(struct platform_devi
25496 return 0;
25497 }
25498
25499 -static struct ata_port_operations qdi6500_port_ops = {
25500 +static const struct ata_port_operations qdi6500_port_ops = {
25501 .inherits = &legacy_base_port_ops,
25502 .set_piomode = qdi6500_set_piomode,
25503 .qc_issue = qdi_qc_issue,
25504 .sff_data_xfer = vlb32_data_xfer,
25505 };
25506
25507 -static struct ata_port_operations qdi6580_port_ops = {
25508 +static const struct ata_port_operations qdi6580_port_ops = {
25509 .inherits = &legacy_base_port_ops,
25510 .set_piomode = qdi6580_set_piomode,
25511 .sff_data_xfer = vlb32_data_xfer,
25512 };
25513
25514 -static struct ata_port_operations qdi6580dp_port_ops = {
25515 +static const struct ata_port_operations qdi6580dp_port_ops = {
25516 .inherits = &legacy_base_port_ops,
25517 .set_piomode = qdi6580dp_set_piomode,
25518 .qc_issue = qdi_qc_issue,
25519 @@ -872,7 +872,7 @@ static int winbond_port(struct platform_
25520 return 0;
25521 }
25522
25523 -static struct ata_port_operations winbond_port_ops = {
25524 +static const struct ata_port_operations winbond_port_ops = {
25525 .inherits = &legacy_base_port_ops,
25526 .set_piomode = winbond_set_piomode,
25527 .sff_data_xfer = vlb32_data_xfer,
25528 @@ -995,7 +995,7 @@ static __init int legacy_init_one(struct
25529 int pio_modes = controller->pio_mask;
25530 unsigned long io = probe->port;
25531 u32 mask = (1 << probe->slot);
25532 - struct ata_port_operations *ops = controller->ops;
25533 + const struct ata_port_operations *ops = controller->ops;
25534 struct legacy_data *ld = &legacy_data[probe->slot];
25535 struct ata_host *host = NULL;
25536 struct ata_port *ap;
25537 diff -urNp linux-2.6.39/drivers/ata/pata_macio.c linux-2.6.39/drivers/ata/pata_macio.c
25538 --- linux-2.6.39/drivers/ata/pata_macio.c 2011-05-19 00:06:34.000000000 -0400
25539 +++ linux-2.6.39/drivers/ata/pata_macio.c 2011-05-22 19:36:31.000000000 -0400
25540 @@ -918,9 +918,8 @@ static struct scsi_host_template pata_ma
25541 .slave_configure = pata_macio_slave_config,
25542 };
25543
25544 -static struct ata_port_operations pata_macio_ops = {
25545 +static const struct ata_port_operations pata_macio_ops = {
25546 .inherits = &ata_bmdma_port_ops,
25547 -
25548 .freeze = pata_macio_freeze,
25549 .set_piomode = pata_macio_set_timings,
25550 .set_dmamode = pata_macio_set_timings,
25551 diff -urNp linux-2.6.39/drivers/ata/pata_marvell.c linux-2.6.39/drivers/ata/pata_marvell.c
25552 --- linux-2.6.39/drivers/ata/pata_marvell.c 2011-05-19 00:06:34.000000000 -0400
25553 +++ linux-2.6.39/drivers/ata/pata_marvell.c 2011-05-22 19:36:31.000000000 -0400
25554 @@ -100,7 +100,7 @@ static struct scsi_host_template marvell
25555 ATA_BMDMA_SHT(DRV_NAME),
25556 };
25557
25558 -static struct ata_port_operations marvell_ops = {
25559 +static const struct ata_port_operations marvell_ops = {
25560 .inherits = &ata_bmdma_port_ops,
25561 .cable_detect = marvell_cable_detect,
25562 .prereset = marvell_pre_reset,
25563 diff -urNp linux-2.6.39/drivers/ata/pata_mpc52xx.c linux-2.6.39/drivers/ata/pata_mpc52xx.c
25564 --- linux-2.6.39/drivers/ata/pata_mpc52xx.c 2011-05-19 00:06:34.000000000 -0400
25565 +++ linux-2.6.39/drivers/ata/pata_mpc52xx.c 2011-05-22 19:36:31.000000000 -0400
25566 @@ -609,7 +609,7 @@ static struct scsi_host_template mpc52xx
25567 ATA_PIO_SHT(DRV_NAME),
25568 };
25569
25570 -static struct ata_port_operations mpc52xx_ata_port_ops = {
25571 +static const struct ata_port_operations mpc52xx_ata_port_ops = {
25572 .inherits = &ata_bmdma_port_ops,
25573 .sff_dev_select = mpc52xx_ata_dev_select,
25574 .set_piomode = mpc52xx_ata_set_piomode,
25575 diff -urNp linux-2.6.39/drivers/ata/pata_mpiix.c linux-2.6.39/drivers/ata/pata_mpiix.c
25576 --- linux-2.6.39/drivers/ata/pata_mpiix.c 2011-05-19 00:06:34.000000000 -0400
25577 +++ linux-2.6.39/drivers/ata/pata_mpiix.c 2011-05-22 19:36:31.000000000 -0400
25578 @@ -140,7 +140,7 @@ static struct scsi_host_template mpiix_s
25579 ATA_PIO_SHT(DRV_NAME),
25580 };
25581
25582 -static struct ata_port_operations mpiix_port_ops = {
25583 +static const struct ata_port_operations mpiix_port_ops = {
25584 .inherits = &ata_sff_port_ops,
25585 .qc_issue = mpiix_qc_issue,
25586 .cable_detect = ata_cable_40wire,
25587 diff -urNp linux-2.6.39/drivers/ata/pata_netcell.c linux-2.6.39/drivers/ata/pata_netcell.c
25588 --- linux-2.6.39/drivers/ata/pata_netcell.c 2011-05-19 00:06:34.000000000 -0400
25589 +++ linux-2.6.39/drivers/ata/pata_netcell.c 2011-05-22 19:36:31.000000000 -0400
25590 @@ -34,7 +34,7 @@ static struct scsi_host_template netcell
25591 ATA_BMDMA_SHT(DRV_NAME),
25592 };
25593
25594 -static struct ata_port_operations netcell_ops = {
25595 +static const struct ata_port_operations netcell_ops = {
25596 .inherits = &ata_bmdma_port_ops,
25597 .cable_detect = ata_cable_80wire,
25598 .read_id = netcell_read_id,
25599 diff -urNp linux-2.6.39/drivers/ata/pata_ninja32.c linux-2.6.39/drivers/ata/pata_ninja32.c
25600 --- linux-2.6.39/drivers/ata/pata_ninja32.c 2011-05-19 00:06:34.000000000 -0400
25601 +++ linux-2.6.39/drivers/ata/pata_ninja32.c 2011-05-22 19:36:31.000000000 -0400
25602 @@ -81,7 +81,7 @@ static struct scsi_host_template ninja32
25603 ATA_BMDMA_SHT(DRV_NAME),
25604 };
25605
25606 -static struct ata_port_operations ninja32_port_ops = {
25607 +static const struct ata_port_operations ninja32_port_ops = {
25608 .inherits = &ata_bmdma_port_ops,
25609 .sff_dev_select = ninja32_dev_select,
25610 .cable_detect = ata_cable_40wire,
25611 diff -urNp linux-2.6.39/drivers/ata/pata_ns87410.c linux-2.6.39/drivers/ata/pata_ns87410.c
25612 --- linux-2.6.39/drivers/ata/pata_ns87410.c 2011-05-19 00:06:34.000000000 -0400
25613 +++ linux-2.6.39/drivers/ata/pata_ns87410.c 2011-05-22 19:36:31.000000000 -0400
25614 @@ -132,7 +132,7 @@ static struct scsi_host_template ns87410
25615 ATA_PIO_SHT(DRV_NAME),
25616 };
25617
25618 -static struct ata_port_operations ns87410_port_ops = {
25619 +static const struct ata_port_operations ns87410_port_ops = {
25620 .inherits = &ata_sff_port_ops,
25621 .qc_issue = ns87410_qc_issue,
25622 .cable_detect = ata_cable_40wire,
25623 diff -urNp linux-2.6.39/drivers/ata/pata_ns87415.c linux-2.6.39/drivers/ata/pata_ns87415.c
25624 --- linux-2.6.39/drivers/ata/pata_ns87415.c 2011-05-19 00:06:34.000000000 -0400
25625 +++ linux-2.6.39/drivers/ata/pata_ns87415.c 2011-05-22 19:36:31.000000000 -0400
25626 @@ -299,7 +299,7 @@ static u8 ns87560_bmdma_status(struct at
25627 }
25628 #endif /* 87560 SuperIO Support */
25629
25630 -static struct ata_port_operations ns87415_pata_ops = {
25631 +static const struct ata_port_operations ns87415_pata_ops = {
25632 .inherits = &ata_bmdma_port_ops,
25633
25634 .check_atapi_dma = ns87415_check_atapi_dma,
25635 @@ -313,7 +313,7 @@ static struct ata_port_operations ns8741
25636 };
25637
25638 #if defined(CONFIG_SUPERIO)
25639 -static struct ata_port_operations ns87560_pata_ops = {
25640 +static const struct ata_port_operations ns87560_pata_ops = {
25641 .inherits = &ns87415_pata_ops,
25642 .sff_tf_read = ns87560_tf_read,
25643 .sff_check_status = ns87560_check_status,
25644 diff -urNp linux-2.6.39/drivers/ata/pata_octeon_cf.c linux-2.6.39/drivers/ata/pata_octeon_cf.c
25645 --- linux-2.6.39/drivers/ata/pata_octeon_cf.c 2011-05-19 00:06:34.000000000 -0400
25646 +++ linux-2.6.39/drivers/ata/pata_octeon_cf.c 2011-05-22 19:36:31.000000000 -0400
25647 @@ -780,7 +780,7 @@ static unsigned int octeon_cf_qc_issue(s
25648 return 0;
25649 }
25650
25651 -static struct ata_port_operations octeon_cf_ops = {
25652 +static struct ata_port_operations octeon_cf_ops = { /* cannot be const */
25653 .inherits = &ata_sff_port_ops,
25654 .check_atapi_dma = octeon_cf_check_atapi_dma,
25655 .qc_prep = ata_noop_qc_prep,
25656 diff -urNp linux-2.6.39/drivers/ata/pata_oldpiix.c linux-2.6.39/drivers/ata/pata_oldpiix.c
25657 --- linux-2.6.39/drivers/ata/pata_oldpiix.c 2011-05-19 00:06:34.000000000 -0400
25658 +++ linux-2.6.39/drivers/ata/pata_oldpiix.c 2011-05-22 19:36:31.000000000 -0400
25659 @@ -208,7 +208,7 @@ static struct scsi_host_template oldpiix
25660 ATA_BMDMA_SHT(DRV_NAME),
25661 };
25662
25663 -static struct ata_port_operations oldpiix_pata_ops = {
25664 +static const struct ata_port_operations oldpiix_pata_ops = {
25665 .inherits = &ata_bmdma_port_ops,
25666 .qc_issue = oldpiix_qc_issue,
25667 .cable_detect = ata_cable_40wire,
25668 diff -urNp linux-2.6.39/drivers/ata/pata_opti.c linux-2.6.39/drivers/ata/pata_opti.c
25669 --- linux-2.6.39/drivers/ata/pata_opti.c 2011-05-19 00:06:34.000000000 -0400
25670 +++ linux-2.6.39/drivers/ata/pata_opti.c 2011-05-22 19:36:31.000000000 -0400
25671 @@ -152,7 +152,7 @@ static struct scsi_host_template opti_sh
25672 ATA_PIO_SHT(DRV_NAME),
25673 };
25674
25675 -static struct ata_port_operations opti_port_ops = {
25676 +static const struct ata_port_operations opti_port_ops = {
25677 .inherits = &ata_sff_port_ops,
25678 .cable_detect = ata_cable_40wire,
25679 .set_piomode = opti_set_piomode,
25680 diff -urNp linux-2.6.39/drivers/ata/pata_optidma.c linux-2.6.39/drivers/ata/pata_optidma.c
25681 --- linux-2.6.39/drivers/ata/pata_optidma.c 2011-05-19 00:06:34.000000000 -0400
25682 +++ linux-2.6.39/drivers/ata/pata_optidma.c 2011-05-22 19:36:31.000000000 -0400
25683 @@ -337,7 +337,7 @@ static struct scsi_host_template optidma
25684 ATA_BMDMA_SHT(DRV_NAME),
25685 };
25686
25687 -static struct ata_port_operations optidma_port_ops = {
25688 +static const struct ata_port_operations optidma_port_ops = {
25689 .inherits = &ata_bmdma_port_ops,
25690 .cable_detect = ata_cable_40wire,
25691 .set_piomode = optidma_set_pio_mode,
25692 @@ -346,7 +346,7 @@ static struct ata_port_operations optidm
25693 .prereset = optidma_pre_reset,
25694 };
25695
25696 -static struct ata_port_operations optiplus_port_ops = {
25697 +static const struct ata_port_operations optiplus_port_ops = {
25698 .inherits = &optidma_port_ops,
25699 .set_piomode = optiplus_set_pio_mode,
25700 .set_dmamode = optiplus_set_dma_mode,
25701 diff -urNp linux-2.6.39/drivers/ata/pata_palmld.c linux-2.6.39/drivers/ata/pata_palmld.c
25702 --- linux-2.6.39/drivers/ata/pata_palmld.c 2011-05-19 00:06:34.000000000 -0400
25703 +++ linux-2.6.39/drivers/ata/pata_palmld.c 2011-05-22 19:36:31.000000000 -0400
25704 @@ -42,7 +42,7 @@ static struct scsi_host_template palmld_
25705 ATA_PIO_SHT(DRV_NAME),
25706 };
25707
25708 -static struct ata_port_operations palmld_port_ops = {
25709 +static const struct ata_port_operations palmld_port_ops = {
25710 .inherits = &ata_sff_port_ops,
25711 .sff_data_xfer = ata_sff_data_xfer_noirq,
25712 .cable_detect = ata_cable_40wire,
25713 diff -urNp linux-2.6.39/drivers/ata/pata_pcmcia.c linux-2.6.39/drivers/ata/pata_pcmcia.c
25714 --- linux-2.6.39/drivers/ata/pata_pcmcia.c 2011-05-19 00:06:34.000000000 -0400
25715 +++ linux-2.6.39/drivers/ata/pata_pcmcia.c 2011-05-22 19:36:31.000000000 -0400
25716 @@ -151,14 +151,14 @@ static struct scsi_host_template pcmcia_
25717 ATA_PIO_SHT(DRV_NAME),
25718 };
25719
25720 -static struct ata_port_operations pcmcia_port_ops = {
25721 +static const struct ata_port_operations pcmcia_port_ops = {
25722 .inherits = &ata_sff_port_ops,
25723 .sff_data_xfer = ata_sff_data_xfer_noirq,
25724 .cable_detect = ata_cable_40wire,
25725 .set_mode = pcmcia_set_mode,
25726 };
25727
25728 -static struct ata_port_operations pcmcia_8bit_port_ops = {
25729 +static const struct ata_port_operations pcmcia_8bit_port_ops = {
25730 .inherits = &ata_sff_port_ops,
25731 .sff_data_xfer = ata_data_xfer_8bit,
25732 .cable_detect = ata_cable_40wire,
25733 @@ -205,7 +205,7 @@ static int pcmcia_init_one(struct pcmcia
25734 unsigned long io_base, ctl_base;
25735 void __iomem *io_addr, *ctl_addr;
25736 int n_ports = 1;
25737 - struct ata_port_operations *ops = &pcmcia_port_ops;
25738 + const struct ata_port_operations *ops = &pcmcia_port_ops;
25739
25740 /* Set up attributes in order to probe card and get resources */
25741 pdev->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO |
25742 diff -urNp linux-2.6.39/drivers/ata/pata_pdc2027x.c linux-2.6.39/drivers/ata/pata_pdc2027x.c
25743 --- linux-2.6.39/drivers/ata/pata_pdc2027x.c 2011-05-19 00:06:34.000000000 -0400
25744 +++ linux-2.6.39/drivers/ata/pata_pdc2027x.c 2011-05-22 19:36:31.000000000 -0400
25745 @@ -132,14 +132,14 @@ static struct scsi_host_template pdc2027
25746 ATA_BMDMA_SHT(DRV_NAME),
25747 };
25748
25749 -static struct ata_port_operations pdc2027x_pata100_ops = {
25750 +static const struct ata_port_operations pdc2027x_pata100_ops = {
25751 .inherits = &ata_bmdma_port_ops,
25752 .check_atapi_dma = pdc2027x_check_atapi_dma,
25753 .cable_detect = pdc2027x_cable_detect,
25754 .prereset = pdc2027x_prereset,
25755 };
25756
25757 -static struct ata_port_operations pdc2027x_pata133_ops = {
25758 +static const struct ata_port_operations pdc2027x_pata133_ops = {
25759 .inherits = &pdc2027x_pata100_ops,
25760 .mode_filter = pdc2027x_mode_filter,
25761 .set_piomode = pdc2027x_set_piomode,
25762 diff -urNp linux-2.6.39/drivers/ata/pata_pdc202xx_old.c linux-2.6.39/drivers/ata/pata_pdc202xx_old.c
25763 --- linux-2.6.39/drivers/ata/pata_pdc202xx_old.c 2011-05-19 00:06:34.000000000 -0400
25764 +++ linux-2.6.39/drivers/ata/pata_pdc202xx_old.c 2011-05-22 19:36:31.000000000 -0400
25765 @@ -295,7 +295,7 @@ static struct scsi_host_template pdc202x
25766 ATA_BMDMA_SHT(DRV_NAME),
25767 };
25768
25769 -static struct ata_port_operations pdc2024x_port_ops = {
25770 +static const struct ata_port_operations pdc2024x_port_ops = {
25771 .inherits = &ata_bmdma_port_ops,
25772
25773 .cable_detect = ata_cable_40wire,
25774 @@ -306,7 +306,7 @@ static struct ata_port_operations pdc202
25775 .sff_irq_check = pdc202xx_irq_check,
25776 };
25777
25778 -static struct ata_port_operations pdc2026x_port_ops = {
25779 +static const struct ata_port_operations pdc2026x_port_ops = {
25780 .inherits = &pdc2024x_port_ops,
25781
25782 .check_atapi_dma = pdc2026x_check_atapi_dma,
25783 diff -urNp linux-2.6.39/drivers/ata/pata_piccolo.c linux-2.6.39/drivers/ata/pata_piccolo.c
25784 --- linux-2.6.39/drivers/ata/pata_piccolo.c 2011-05-19 00:06:34.000000000 -0400
25785 +++ linux-2.6.39/drivers/ata/pata_piccolo.c 2011-05-22 19:36:31.000000000 -0400
25786 @@ -67,7 +67,7 @@ static struct scsi_host_template tosh_sh
25787 ATA_BMDMA_SHT(DRV_NAME),
25788 };
25789
25790 -static struct ata_port_operations tosh_port_ops = {
25791 +static const struct ata_port_operations tosh_port_ops = {
25792 .inherits = &ata_bmdma_port_ops,
25793 .cable_detect = ata_cable_unknown,
25794 .set_piomode = tosh_set_piomode,
25795 diff -urNp linux-2.6.39/drivers/ata/pata_platform.c linux-2.6.39/drivers/ata/pata_platform.c
25796 --- linux-2.6.39/drivers/ata/pata_platform.c 2011-05-19 00:06:34.000000000 -0400
25797 +++ linux-2.6.39/drivers/ata/pata_platform.c 2011-05-22 19:36:31.000000000 -0400
25798 @@ -48,7 +48,7 @@ static struct scsi_host_template pata_pl
25799 ATA_PIO_SHT(DRV_NAME),
25800 };
25801
25802 -static struct ata_port_operations pata_platform_port_ops = {
25803 +static const struct ata_port_operations pata_platform_port_ops = {
25804 .inherits = &ata_sff_port_ops,
25805 .sff_data_xfer = ata_sff_data_xfer_noirq,
25806 .cable_detect = ata_cable_unknown,
25807 diff -urNp linux-2.6.39/drivers/ata/pata_pxa.c linux-2.6.39/drivers/ata/pata_pxa.c
25808 --- linux-2.6.39/drivers/ata/pata_pxa.c 2011-05-19 00:06:34.000000000 -0400
25809 +++ linux-2.6.39/drivers/ata/pata_pxa.c 2011-05-22 19:36:31.000000000 -0400
25810 @@ -198,7 +198,7 @@ static struct scsi_host_template pxa_ata
25811 ATA_BMDMA_SHT(DRV_NAME),
25812 };
25813
25814 -static struct ata_port_operations pxa_ata_port_ops = {
25815 +static const struct ata_port_operations pxa_ata_port_ops = {
25816 .inherits = &ata_bmdma_port_ops,
25817 .cable_detect = ata_cable_40wire,
25818
25819 diff -urNp linux-2.6.39/drivers/ata/pata_qdi.c linux-2.6.39/drivers/ata/pata_qdi.c
25820 --- linux-2.6.39/drivers/ata/pata_qdi.c 2011-05-19 00:06:34.000000000 -0400
25821 +++ linux-2.6.39/drivers/ata/pata_qdi.c 2011-05-22 19:36:31.000000000 -0400
25822 @@ -157,7 +157,7 @@ static struct scsi_host_template qdi_sht
25823 ATA_PIO_SHT(DRV_NAME),
25824 };
25825
25826 -static struct ata_port_operations qdi6500_port_ops = {
25827 +static const struct ata_port_operations qdi6500_port_ops = {
25828 .inherits = &ata_sff_port_ops,
25829 .qc_issue = qdi_qc_issue,
25830 .sff_data_xfer = qdi_data_xfer,
25831 @@ -165,7 +165,7 @@ static struct ata_port_operations qdi650
25832 .set_piomode = qdi6500_set_piomode,
25833 };
25834
25835 -static struct ata_port_operations qdi6580_port_ops = {
25836 +static const struct ata_port_operations qdi6580_port_ops = {
25837 .inherits = &qdi6500_port_ops,
25838 .set_piomode = qdi6580_set_piomode,
25839 };
25840 diff -urNp linux-2.6.39/drivers/ata/pata_radisys.c linux-2.6.39/drivers/ata/pata_radisys.c
25841 --- linux-2.6.39/drivers/ata/pata_radisys.c 2011-05-19 00:06:34.000000000 -0400
25842 +++ linux-2.6.39/drivers/ata/pata_radisys.c 2011-05-22 19:36:31.000000000 -0400
25843 @@ -187,7 +187,7 @@ static struct scsi_host_template radisys
25844 ATA_BMDMA_SHT(DRV_NAME),
25845 };
25846
25847 -static struct ata_port_operations radisys_pata_ops = {
25848 +static const struct ata_port_operations radisys_pata_ops = {
25849 .inherits = &ata_bmdma_port_ops,
25850 .qc_issue = radisys_qc_issue,
25851 .cable_detect = ata_cable_unknown,
25852 diff -urNp linux-2.6.39/drivers/ata/pata_rb532_cf.c linux-2.6.39/drivers/ata/pata_rb532_cf.c
25853 --- linux-2.6.39/drivers/ata/pata_rb532_cf.c 2011-05-19 00:06:34.000000000 -0400
25854 +++ linux-2.6.39/drivers/ata/pata_rb532_cf.c 2011-05-22 19:36:31.000000000 -0400
25855 @@ -69,7 +69,7 @@ static irqreturn_t rb532_pata_irq_handle
25856 return IRQ_HANDLED;
25857 }
25858
25859 -static struct ata_port_operations rb532_pata_port_ops = {
25860 +static const struct ata_port_operations rb532_pata_port_ops = {
25861 .inherits = &ata_sff_port_ops,
25862 .sff_data_xfer = ata_sff_data_xfer32,
25863 };
25864 diff -urNp linux-2.6.39/drivers/ata/pata_rdc.c linux-2.6.39/drivers/ata/pata_rdc.c
25865 --- linux-2.6.39/drivers/ata/pata_rdc.c 2011-05-19 00:06:34.000000000 -0400
25866 +++ linux-2.6.39/drivers/ata/pata_rdc.c 2011-05-22 19:36:31.000000000 -0400
25867 @@ -273,7 +273,7 @@ static void rdc_set_dmamode(struct ata_p
25868 pci_write_config_byte(dev, 0x48, udma_enable);
25869 }
25870
25871 -static struct ata_port_operations rdc_pata_ops = {
25872 +static const struct ata_port_operations rdc_pata_ops = {
25873 .inherits = &ata_bmdma32_port_ops,
25874 .cable_detect = rdc_pata_cable_detect,
25875 .set_piomode = rdc_set_piomode,
25876 diff -urNp linux-2.6.39/drivers/ata/pata_rz1000.c linux-2.6.39/drivers/ata/pata_rz1000.c
25877 --- linux-2.6.39/drivers/ata/pata_rz1000.c 2011-05-19 00:06:34.000000000 -0400
25878 +++ linux-2.6.39/drivers/ata/pata_rz1000.c 2011-05-22 19:36:31.000000000 -0400
25879 @@ -54,7 +54,7 @@ static struct scsi_host_template rz1000_
25880 ATA_PIO_SHT(DRV_NAME),
25881 };
25882
25883 -static struct ata_port_operations rz1000_port_ops = {
25884 +static const struct ata_port_operations rz1000_port_ops = {
25885 .inherits = &ata_sff_port_ops,
25886 .cable_detect = ata_cable_40wire,
25887 .set_mode = rz1000_set_mode,
25888 diff -urNp linux-2.6.39/drivers/ata/pata_samsung_cf.c linux-2.6.39/drivers/ata/pata_samsung_cf.c
25889 --- linux-2.6.39/drivers/ata/pata_samsung_cf.c 2011-05-19 00:06:34.000000000 -0400
25890 +++ linux-2.6.39/drivers/ata/pata_samsung_cf.c 2011-05-22 19:36:31.000000000 -0400
25891 @@ -399,7 +399,7 @@ static struct scsi_host_template pata_s3
25892 ATA_PIO_SHT(DRV_NAME),
25893 };
25894
25895 -static struct ata_port_operations pata_s3c_port_ops = {
25896 +static const struct ata_port_operations pata_s3c_port_ops = {
25897 .inherits = &ata_sff_port_ops,
25898 .sff_check_status = pata_s3c_check_status,
25899 .sff_check_altstatus = pata_s3c_check_altstatus,
25900 @@ -413,7 +413,7 @@ static struct ata_port_operations pata_s
25901 .set_piomode = pata_s3c_set_piomode,
25902 };
25903
25904 -static struct ata_port_operations pata_s5p_port_ops = {
25905 +static const struct ata_port_operations pata_s5p_port_ops = {
25906 .inherits = &ata_sff_port_ops,
25907 .set_piomode = pata_s3c_set_piomode,
25908 };
25909 diff -urNp linux-2.6.39/drivers/ata/pata_sc1200.c linux-2.6.39/drivers/ata/pata_sc1200.c
25910 --- linux-2.6.39/drivers/ata/pata_sc1200.c 2011-05-19 00:06:34.000000000 -0400
25911 +++ linux-2.6.39/drivers/ata/pata_sc1200.c 2011-05-22 19:36:31.000000000 -0400
25912 @@ -207,7 +207,7 @@ static struct scsi_host_template sc1200_
25913 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
25914 };
25915
25916 -static struct ata_port_operations sc1200_port_ops = {
25917 +static const struct ata_port_operations sc1200_port_ops = {
25918 .inherits = &ata_bmdma_port_ops,
25919 .qc_prep = ata_bmdma_dumb_qc_prep,
25920 .qc_issue = sc1200_qc_issue,
25921 diff -urNp linux-2.6.39/drivers/ata/pata_scc.c linux-2.6.39/drivers/ata/pata_scc.c
25922 --- linux-2.6.39/drivers/ata/pata_scc.c 2011-05-19 00:06:34.000000000 -0400
25923 +++ linux-2.6.39/drivers/ata/pata_scc.c 2011-05-22 19:36:31.000000000 -0400
25924 @@ -926,7 +926,7 @@ static struct scsi_host_template scc_sht
25925 ATA_BMDMA_SHT(DRV_NAME),
25926 };
25927
25928 -static struct ata_port_operations scc_pata_ops = {
25929 +static const struct ata_port_operations scc_pata_ops = {
25930 .inherits = &ata_bmdma_port_ops,
25931
25932 .set_piomode = scc_set_piomode,
25933 diff -urNp linux-2.6.39/drivers/ata/pata_sch.c linux-2.6.39/drivers/ata/pata_sch.c
25934 --- linux-2.6.39/drivers/ata/pata_sch.c 2011-05-19 00:06:34.000000000 -0400
25935 +++ linux-2.6.39/drivers/ata/pata_sch.c 2011-05-22 19:36:31.000000000 -0400
25936 @@ -75,7 +75,7 @@ static struct scsi_host_template sch_sht
25937 ATA_BMDMA_SHT(DRV_NAME),
25938 };
25939
25940 -static struct ata_port_operations sch_pata_ops = {
25941 +static const struct ata_port_operations sch_pata_ops = {
25942 .inherits = &ata_bmdma_port_ops,
25943 .cable_detect = ata_cable_unknown,
25944 .set_piomode = sch_set_piomode,
25945 diff -urNp linux-2.6.39/drivers/ata/pata_serverworks.c linux-2.6.39/drivers/ata/pata_serverworks.c
25946 --- linux-2.6.39/drivers/ata/pata_serverworks.c 2011-05-19 00:06:34.000000000 -0400
25947 +++ linux-2.6.39/drivers/ata/pata_serverworks.c 2011-05-22 19:36:31.000000000 -0400
25948 @@ -300,7 +300,7 @@ static struct scsi_host_template serverw
25949 ATA_BMDMA_SHT(DRV_NAME),
25950 };
25951
25952 -static struct ata_port_operations serverworks_osb4_port_ops = {
25953 +static const struct ata_port_operations serverworks_osb4_port_ops = {
25954 .inherits = &ata_bmdma_port_ops,
25955 .cable_detect = serverworks_cable_detect,
25956 .mode_filter = serverworks_osb4_filter,
25957 @@ -308,7 +308,7 @@ static struct ata_port_operations server
25958 .set_dmamode = serverworks_set_dmamode,
25959 };
25960
25961 -static struct ata_port_operations serverworks_csb_port_ops = {
25962 +static const struct ata_port_operations serverworks_csb_port_ops = {
25963 .inherits = &serverworks_osb4_port_ops,
25964 .mode_filter = serverworks_csb_filter,
25965 };
25966 diff -urNp linux-2.6.39/drivers/ata/pata_sil680.c linux-2.6.39/drivers/ata/pata_sil680.c
25967 --- linux-2.6.39/drivers/ata/pata_sil680.c 2011-05-19 00:06:34.000000000 -0400
25968 +++ linux-2.6.39/drivers/ata/pata_sil680.c 2011-05-22 19:36:31.000000000 -0400
25969 @@ -225,8 +225,7 @@ static struct scsi_host_template sil680_
25970 ATA_BMDMA_SHT(DRV_NAME),
25971 };
25972
25973 -
25974 -static struct ata_port_operations sil680_port_ops = {
25975 +static const struct ata_port_operations sil680_port_ops = {
25976 .inherits = &ata_bmdma32_port_ops,
25977 .sff_exec_command = sil680_sff_exec_command,
25978 .sff_irq_check = sil680_sff_irq_check,
25979 diff -urNp linux-2.6.39/drivers/ata/pata_sis.c linux-2.6.39/drivers/ata/pata_sis.c
25980 --- linux-2.6.39/drivers/ata/pata_sis.c 2011-05-19 00:06:34.000000000 -0400
25981 +++ linux-2.6.39/drivers/ata/pata_sis.c 2011-05-22 19:36:31.000000000 -0400
25982 @@ -503,47 +503,47 @@ static struct scsi_host_template sis_sht
25983 ATA_BMDMA_SHT(DRV_NAME),
25984 };
25985
25986 -static struct ata_port_operations sis_133_for_sata_ops = {
25987 +static const struct ata_port_operations sis_133_for_sata_ops = {
25988 .inherits = &ata_bmdma_port_ops,
25989 .set_piomode = sis_133_set_piomode,
25990 .set_dmamode = sis_133_set_dmamode,
25991 .cable_detect = sis_133_cable_detect,
25992 };
25993
25994 -static struct ata_port_operations sis_base_ops = {
25995 +static const struct ata_port_operations sis_base_ops = {
25996 .inherits = &ata_bmdma_port_ops,
25997 .prereset = sis_pre_reset,
25998 };
25999
26000 -static struct ata_port_operations sis_133_ops = {
26001 +static const struct ata_port_operations sis_133_ops = {
26002 .inherits = &sis_base_ops,
26003 .set_piomode = sis_133_set_piomode,
26004 .set_dmamode = sis_133_set_dmamode,
26005 .cable_detect = sis_133_cable_detect,
26006 };
26007
26008 -static struct ata_port_operations sis_133_early_ops = {
26009 +static const struct ata_port_operations sis_133_early_ops = {
26010 .inherits = &sis_base_ops,
26011 .set_piomode = sis_100_set_piomode,
26012 .set_dmamode = sis_133_early_set_dmamode,
26013 .cable_detect = sis_66_cable_detect,
26014 };
26015
26016 -static struct ata_port_operations sis_100_ops = {
26017 +static const struct ata_port_operations sis_100_ops = {
26018 .inherits = &sis_base_ops,
26019 .set_piomode = sis_100_set_piomode,
26020 .set_dmamode = sis_100_set_dmamode,
26021 .cable_detect = sis_66_cable_detect,
26022 };
26023
26024 -static struct ata_port_operations sis_66_ops = {
26025 +static const struct ata_port_operations sis_66_ops = {
26026 .inherits = &sis_base_ops,
26027 .set_piomode = sis_old_set_piomode,
26028 .set_dmamode = sis_66_set_dmamode,
26029 .cable_detect = sis_66_cable_detect,
26030 };
26031
26032 -static struct ata_port_operations sis_old_ops = {
26033 +static const struct ata_port_operations sis_old_ops = {
26034 .inherits = &sis_base_ops,
26035 .set_piomode = sis_old_set_piomode,
26036 .set_dmamode = sis_old_set_dmamode,
26037 diff -urNp linux-2.6.39/drivers/ata/pata_sl82c105.c linux-2.6.39/drivers/ata/pata_sl82c105.c
26038 --- linux-2.6.39/drivers/ata/pata_sl82c105.c 2011-05-19 00:06:34.000000000 -0400
26039 +++ linux-2.6.39/drivers/ata/pata_sl82c105.c 2011-05-22 19:36:31.000000000 -0400
26040 @@ -241,7 +241,7 @@ static struct scsi_host_template sl82c10
26041 ATA_BMDMA_SHT(DRV_NAME),
26042 };
26043
26044 -static struct ata_port_operations sl82c105_port_ops = {
26045 +static const struct ata_port_operations sl82c105_port_ops = {
26046 .inherits = &ata_bmdma_port_ops,
26047 .qc_defer = sl82c105_qc_defer,
26048 .bmdma_start = sl82c105_bmdma_start,
26049 diff -urNp linux-2.6.39/drivers/ata/pata_triflex.c linux-2.6.39/drivers/ata/pata_triflex.c
26050 --- linux-2.6.39/drivers/ata/pata_triflex.c 2011-05-19 00:06:34.000000000 -0400
26051 +++ linux-2.6.39/drivers/ata/pata_triflex.c 2011-05-22 19:36:31.000000000 -0400
26052 @@ -178,7 +178,7 @@ static struct scsi_host_template triflex
26053 ATA_BMDMA_SHT(DRV_NAME),
26054 };
26055
26056 -static struct ata_port_operations triflex_port_ops = {
26057 +static const struct ata_port_operations triflex_port_ops = {
26058 .inherits = &ata_bmdma_port_ops,
26059 .bmdma_start = triflex_bmdma_start,
26060 .bmdma_stop = triflex_bmdma_stop,
26061 diff -urNp linux-2.6.39/drivers/ata/pata_via.c linux-2.6.39/drivers/ata/pata_via.c
26062 --- linux-2.6.39/drivers/ata/pata_via.c 2011-05-19 00:06:34.000000000 -0400
26063 +++ linux-2.6.39/drivers/ata/pata_via.c 2011-05-22 19:36:31.000000000 -0400
26064 @@ -441,7 +441,7 @@ static struct scsi_host_template via_sht
26065 ATA_BMDMA_SHT(DRV_NAME),
26066 };
26067
26068 -static struct ata_port_operations via_port_ops = {
26069 +static const struct ata_port_operations via_port_ops = {
26070 .inherits = &ata_bmdma_port_ops,
26071 .cable_detect = via_cable_detect,
26072 .set_piomode = via_set_piomode,
26073 @@ -452,7 +452,7 @@ static struct ata_port_operations via_po
26074 .mode_filter = via_mode_filter,
26075 };
26076
26077 -static struct ata_port_operations via_port_ops_noirq = {
26078 +static const struct ata_port_operations via_port_ops_noirq = {
26079 .inherits = &via_port_ops,
26080 .sff_data_xfer = ata_sff_data_xfer_noirq,
26081 };
26082 diff -urNp linux-2.6.39/drivers/ata/pdc_adma.c linux-2.6.39/drivers/ata/pdc_adma.c
26083 --- linux-2.6.39/drivers/ata/pdc_adma.c 2011-05-19 00:06:34.000000000 -0400
26084 +++ linux-2.6.39/drivers/ata/pdc_adma.c 2011-05-22 19:36:31.000000000 -0400
26085 @@ -146,7 +146,7 @@ static struct scsi_host_template adma_at
26086 .dma_boundary = ADMA_DMA_BOUNDARY,
26087 };
26088
26089 -static struct ata_port_operations adma_ata_ops = {
26090 +static const struct ata_port_operations adma_ata_ops = {
26091 .inherits = &ata_sff_port_ops,
26092
26093 .lost_interrupt = ATA_OP_NULL,
26094 diff -urNp linux-2.6.39/drivers/ata/sata_dwc_460ex.c linux-2.6.39/drivers/ata/sata_dwc_460ex.c
26095 --- linux-2.6.39/drivers/ata/sata_dwc_460ex.c 2011-05-19 00:06:34.000000000 -0400
26096 +++ linux-2.6.39/drivers/ata/sata_dwc_460ex.c 2011-05-22 19:36:31.000000000 -0400
26097 @@ -1598,7 +1598,7 @@ static struct scsi_host_template sata_dw
26098 .dma_boundary = ATA_DMA_BOUNDARY,
26099 };
26100
26101 -static struct ata_port_operations sata_dwc_ops = {
26102 +static const struct ata_port_operations sata_dwc_ops = {
26103 .inherits = &ata_sff_port_ops,
26104
26105 .error_handler = sata_dwc_error_handler,
26106 diff -urNp linux-2.6.39/drivers/ata/sata_fsl.c linux-2.6.39/drivers/ata/sata_fsl.c
26107 --- linux-2.6.39/drivers/ata/sata_fsl.c 2011-05-19 00:06:34.000000000 -0400
26108 +++ linux-2.6.39/drivers/ata/sata_fsl.c 2011-05-22 19:36:31.000000000 -0400
26109 @@ -1268,7 +1268,7 @@ static struct scsi_host_template sata_fs
26110 .dma_boundary = ATA_DMA_BOUNDARY,
26111 };
26112
26113 -static struct ata_port_operations sata_fsl_ops = {
26114 +static const struct ata_port_operations sata_fsl_ops = {
26115 .inherits = &sata_pmp_port_ops,
26116
26117 .qc_defer = ata_std_qc_defer,
26118 diff -urNp linux-2.6.39/drivers/ata/sata_inic162x.c linux-2.6.39/drivers/ata/sata_inic162x.c
26119 --- linux-2.6.39/drivers/ata/sata_inic162x.c 2011-05-19 00:06:34.000000000 -0400
26120 +++ linux-2.6.39/drivers/ata/sata_inic162x.c 2011-05-22 19:36:31.000000000 -0400
26121 @@ -705,7 +705,7 @@ static int inic_port_start(struct ata_po
26122 return 0;
26123 }
26124
26125 -static struct ata_port_operations inic_port_ops = {
26126 +static const struct ata_port_operations inic_port_ops = {
26127 .inherits = &sata_port_ops,
26128
26129 .check_atapi_dma = inic_check_atapi_dma,
26130 diff -urNp linux-2.6.39/drivers/ata/sata_mv.c linux-2.6.39/drivers/ata/sata_mv.c
26131 --- linux-2.6.39/drivers/ata/sata_mv.c 2011-05-19 00:06:34.000000000 -0400
26132 +++ linux-2.6.39/drivers/ata/sata_mv.c 2011-05-22 19:36:31.000000000 -0400
26133 @@ -662,7 +662,7 @@ static struct scsi_host_template mv6_sht
26134 .dma_boundary = MV_DMA_BOUNDARY,
26135 };
26136
26137 -static struct ata_port_operations mv5_ops = {
26138 +static const struct ata_port_operations mv5_ops = {
26139 .inherits = &ata_sff_port_ops,
26140
26141 .lost_interrupt = ATA_OP_NULL,
26142 @@ -682,7 +682,7 @@ static struct ata_port_operations mv5_op
26143 .port_stop = mv_port_stop,
26144 };
26145
26146 -static struct ata_port_operations mv6_ops = {
26147 +static const struct ata_port_operations mv6_ops = {
26148 .inherits = &ata_bmdma_port_ops,
26149
26150 .lost_interrupt = ATA_OP_NULL,
26151 @@ -716,7 +716,7 @@ static struct ata_port_operations mv6_op
26152 .port_stop = mv_port_stop,
26153 };
26154
26155 -static struct ata_port_operations mv_iie_ops = {
26156 +static const struct ata_port_operations mv_iie_ops = {
26157 .inherits = &mv6_ops,
26158 .dev_config = ATA_OP_NULL,
26159 .qc_prep = mv_qc_prep_iie,
26160 diff -urNp linux-2.6.39/drivers/ata/sata_nv.c linux-2.6.39/drivers/ata/sata_nv.c
26161 --- linux-2.6.39/drivers/ata/sata_nv.c 2011-05-19 00:06:34.000000000 -0400
26162 +++ linux-2.6.39/drivers/ata/sata_nv.c 2011-05-22 19:36:31.000000000 -0400
26163 @@ -465,7 +465,7 @@ static struct scsi_host_template nv_swnc
26164 * cases. Define nv_hardreset() which only kicks in for post-boot
26165 * probing and use it for all variants.
26166 */
26167 -static struct ata_port_operations nv_generic_ops = {
26168 +static const struct ata_port_operations nv_generic_ops = {
26169 .inherits = &ata_bmdma_port_ops,
26170 .lost_interrupt = ATA_OP_NULL,
26171 .scr_read = nv_scr_read,
26172 @@ -473,20 +473,20 @@ static struct ata_port_operations nv_gen
26173 .hardreset = nv_hardreset,
26174 };
26175
26176 -static struct ata_port_operations nv_nf2_ops = {
26177 +static const struct ata_port_operations nv_nf2_ops = {
26178 .inherits = &nv_generic_ops,
26179 .freeze = nv_nf2_freeze,
26180 .thaw = nv_nf2_thaw,
26181 };
26182
26183 -static struct ata_port_operations nv_ck804_ops = {
26184 +static const struct ata_port_operations nv_ck804_ops = {
26185 .inherits = &nv_generic_ops,
26186 .freeze = nv_ck804_freeze,
26187 .thaw = nv_ck804_thaw,
26188 .host_stop = nv_ck804_host_stop,
26189 };
26190
26191 -static struct ata_port_operations nv_adma_ops = {
26192 +static const struct ata_port_operations nv_adma_ops = {
26193 .inherits = &nv_ck804_ops,
26194
26195 .check_atapi_dma = nv_adma_check_atapi_dma,
26196 @@ -510,7 +510,7 @@ static struct ata_port_operations nv_adm
26197 .host_stop = nv_adma_host_stop,
26198 };
26199
26200 -static struct ata_port_operations nv_swncq_ops = {
26201 +static const struct ata_port_operations nv_swncq_ops = {
26202 .inherits = &nv_generic_ops,
26203
26204 .qc_defer = ata_std_qc_defer,
26205 diff -urNp linux-2.6.39/drivers/ata/sata_promise.c linux-2.6.39/drivers/ata/sata_promise.c
26206 --- linux-2.6.39/drivers/ata/sata_promise.c 2011-05-19 00:06:34.000000000 -0400
26207 +++ linux-2.6.39/drivers/ata/sata_promise.c 2011-05-22 19:36:31.000000000 -0400
26208 @@ -194,7 +194,7 @@ static const struct ata_port_operations
26209 .error_handler = pdc_error_handler,
26210 };
26211
26212 -static struct ata_port_operations pdc_sata_ops = {
26213 +static const struct ata_port_operations pdc_sata_ops = {
26214 .inherits = &pdc_common_ops,
26215 .cable_detect = pdc_sata_cable_detect,
26216 .freeze = pdc_sata_freeze,
26217 @@ -207,14 +207,14 @@ static struct ata_port_operations pdc_sa
26218
26219 /* First-generation chips need a more restrictive ->check_atapi_dma op,
26220 and ->freeze/thaw that ignore the hotplug controls. */
26221 -static struct ata_port_operations pdc_old_sata_ops = {
26222 +static const struct ata_port_operations pdc_old_sata_ops = {
26223 .inherits = &pdc_sata_ops,
26224 .freeze = pdc_freeze,
26225 .thaw = pdc_thaw,
26226 .check_atapi_dma = pdc_old_sata_check_atapi_dma,
26227 };
26228
26229 -static struct ata_port_operations pdc_pata_ops = {
26230 +static const struct ata_port_operations pdc_pata_ops = {
26231 .inherits = &pdc_common_ops,
26232 .cable_detect = pdc_pata_cable_detect,
26233 .freeze = pdc_freeze,
26234 diff -urNp linux-2.6.39/drivers/ata/sata_qstor.c linux-2.6.39/drivers/ata/sata_qstor.c
26235 --- linux-2.6.39/drivers/ata/sata_qstor.c 2011-05-19 00:06:34.000000000 -0400
26236 +++ linux-2.6.39/drivers/ata/sata_qstor.c 2011-05-22 19:36:31.000000000 -0400
26237 @@ -131,7 +131,7 @@ static struct scsi_host_template qs_ata_
26238 .dma_boundary = QS_DMA_BOUNDARY,
26239 };
26240
26241 -static struct ata_port_operations qs_ata_ops = {
26242 +static const struct ata_port_operations qs_ata_ops = {
26243 .inherits = &ata_sff_port_ops,
26244
26245 .check_atapi_dma = qs_check_atapi_dma,
26246 diff -urNp linux-2.6.39/drivers/ata/sata_sil24.c linux-2.6.39/drivers/ata/sata_sil24.c
26247 --- linux-2.6.39/drivers/ata/sata_sil24.c 2011-05-19 00:06:34.000000000 -0400
26248 +++ linux-2.6.39/drivers/ata/sata_sil24.c 2011-05-22 19:36:31.000000000 -0400
26249 @@ -388,7 +388,7 @@ static struct scsi_host_template sil24_s
26250 .dma_boundary = ATA_DMA_BOUNDARY,
26251 };
26252
26253 -static struct ata_port_operations sil24_ops = {
26254 +static const struct ata_port_operations sil24_ops = {
26255 .inherits = &sata_pmp_port_ops,
26256
26257 .qc_defer = sil24_qc_defer,
26258 diff -urNp linux-2.6.39/drivers/ata/sata_sil.c linux-2.6.39/drivers/ata/sata_sil.c
26259 --- linux-2.6.39/drivers/ata/sata_sil.c 2011-05-19 00:06:34.000000000 -0400
26260 +++ linux-2.6.39/drivers/ata/sata_sil.c 2011-05-22 19:36:31.000000000 -0400
26261 @@ -181,7 +181,7 @@ static struct scsi_host_template sil_sht
26262 .sg_tablesize = ATA_MAX_PRD
26263 };
26264
26265 -static struct ata_port_operations sil_ops = {
26266 +static const struct ata_port_operations sil_ops = {
26267 .inherits = &ata_bmdma32_port_ops,
26268 .dev_config = sil_dev_config,
26269 .set_mode = sil_set_mode,
26270 diff -urNp linux-2.6.39/drivers/ata/sata_sis.c linux-2.6.39/drivers/ata/sata_sis.c
26271 --- linux-2.6.39/drivers/ata/sata_sis.c 2011-05-19 00:06:34.000000000 -0400
26272 +++ linux-2.6.39/drivers/ata/sata_sis.c 2011-05-22 19:36:31.000000000 -0400
26273 @@ -89,7 +89,7 @@ static struct scsi_host_template sis_sht
26274 ATA_BMDMA_SHT(DRV_NAME),
26275 };
26276
26277 -static struct ata_port_operations sis_ops = {
26278 +static const struct ata_port_operations sis_ops = {
26279 .inherits = &ata_bmdma_port_ops,
26280 .scr_read = sis_scr_read,
26281 .scr_write = sis_scr_write,
26282 diff -urNp linux-2.6.39/drivers/ata/sata_svw.c linux-2.6.39/drivers/ata/sata_svw.c
26283 --- linux-2.6.39/drivers/ata/sata_svw.c 2011-05-19 00:06:34.000000000 -0400
26284 +++ linux-2.6.39/drivers/ata/sata_svw.c 2011-05-22 19:36:31.000000000 -0400
26285 @@ -344,7 +344,7 @@ static struct scsi_host_template k2_sata
26286 };
26287
26288
26289 -static struct ata_port_operations k2_sata_ops = {
26290 +static const struct ata_port_operations k2_sata_ops = {
26291 .inherits = &ata_bmdma_port_ops,
26292 .sff_tf_load = k2_sata_tf_load,
26293 .sff_tf_read = k2_sata_tf_read,
26294 diff -urNp linux-2.6.39/drivers/ata/sata_sx4.c linux-2.6.39/drivers/ata/sata_sx4.c
26295 --- linux-2.6.39/drivers/ata/sata_sx4.c 2011-05-19 00:06:34.000000000 -0400
26296 +++ linux-2.6.39/drivers/ata/sata_sx4.c 2011-05-22 19:36:31.000000000 -0400
26297 @@ -249,7 +249,7 @@ static struct scsi_host_template pdc_sat
26298 };
26299
26300 /* TODO: inherit from base port_ops after converting to new EH */
26301 -static struct ata_port_operations pdc_20621_ops = {
26302 +static const struct ata_port_operations pdc_20621_ops = {
26303 .inherits = &ata_sff_port_ops,
26304
26305 .check_atapi_dma = pdc_check_atapi_dma,
26306 diff -urNp linux-2.6.39/drivers/ata/sata_uli.c linux-2.6.39/drivers/ata/sata_uli.c
26307 --- linux-2.6.39/drivers/ata/sata_uli.c 2011-05-19 00:06:34.000000000 -0400
26308 +++ linux-2.6.39/drivers/ata/sata_uli.c 2011-05-22 19:36:31.000000000 -0400
26309 @@ -80,7 +80,7 @@ static struct scsi_host_template uli_sht
26310 ATA_BMDMA_SHT(DRV_NAME),
26311 };
26312
26313 -static struct ata_port_operations uli_ops = {
26314 +static const struct ata_port_operations uli_ops = {
26315 .inherits = &ata_bmdma_port_ops,
26316 .scr_read = uli_scr_read,
26317 .scr_write = uli_scr_write,
26318 diff -urNp linux-2.6.39/drivers/ata/sata_via.c linux-2.6.39/drivers/ata/sata_via.c
26319 --- linux-2.6.39/drivers/ata/sata_via.c 2011-05-19 00:06:34.000000000 -0400
26320 +++ linux-2.6.39/drivers/ata/sata_via.c 2011-05-22 19:36:31.000000000 -0400
26321 @@ -115,32 +115,32 @@ static struct scsi_host_template svia_sh
26322 ATA_BMDMA_SHT(DRV_NAME),
26323 };
26324
26325 -static struct ata_port_operations svia_base_ops = {
26326 +static const struct ata_port_operations svia_base_ops = {
26327 .inherits = &ata_bmdma_port_ops,
26328 .sff_tf_load = svia_tf_load,
26329 };
26330
26331 -static struct ata_port_operations vt6420_sata_ops = {
26332 +static const struct ata_port_operations vt6420_sata_ops = {
26333 .inherits = &svia_base_ops,
26334 .freeze = svia_noop_freeze,
26335 .prereset = vt6420_prereset,
26336 .bmdma_start = vt6420_bmdma_start,
26337 };
26338
26339 -static struct ata_port_operations vt6421_pata_ops = {
26340 +static const struct ata_port_operations vt6421_pata_ops = {
26341 .inherits = &svia_base_ops,
26342 .cable_detect = vt6421_pata_cable_detect,
26343 .set_piomode = vt6421_set_pio_mode,
26344 .set_dmamode = vt6421_set_dma_mode,
26345 };
26346
26347 -static struct ata_port_operations vt6421_sata_ops = {
26348 +static const struct ata_port_operations vt6421_sata_ops = {
26349 .inherits = &svia_base_ops,
26350 .scr_read = svia_scr_read,
26351 .scr_write = svia_scr_write,
26352 };
26353
26354 -static struct ata_port_operations vt8251_ops = {
26355 +static const struct ata_port_operations vt8251_ops = {
26356 .inherits = &svia_base_ops,
26357 .hardreset = sata_std_hardreset,
26358 .scr_read = vt8251_scr_read,
26359 diff -urNp linux-2.6.39/drivers/ata/sata_vsc.c linux-2.6.39/drivers/ata/sata_vsc.c
26360 --- linux-2.6.39/drivers/ata/sata_vsc.c 2011-05-19 00:06:34.000000000 -0400
26361 +++ linux-2.6.39/drivers/ata/sata_vsc.c 2011-05-22 19:36:31.000000000 -0400
26362 @@ -300,7 +300,7 @@ static struct scsi_host_template vsc_sat
26363 };
26364
26365
26366 -static struct ata_port_operations vsc_sata_ops = {
26367 +static const struct ata_port_operations vsc_sata_ops = {
26368 .inherits = &ata_bmdma_port_ops,
26369 /* The IRQ handling is not quite standard SFF behaviour so we
26370 cannot use the default lost interrupt handler */
26371 diff -urNp linux-2.6.39/drivers/atm/adummy.c linux-2.6.39/drivers/atm/adummy.c
26372 --- linux-2.6.39/drivers/atm/adummy.c 2011-05-19 00:06:34.000000000 -0400
26373 +++ linux-2.6.39/drivers/atm/adummy.c 2011-05-22 19:36:31.000000000 -0400
26374 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct
26375 vcc->pop(vcc, skb);
26376 else
26377 dev_kfree_skb_any(skb);
26378 - atomic_inc(&vcc->stats->tx);
26379 + atomic_inc_unchecked(&vcc->stats->tx);
26380
26381 return 0;
26382 }
26383 diff -urNp linux-2.6.39/drivers/atm/ambassador.c linux-2.6.39/drivers/atm/ambassador.c
26384 --- linux-2.6.39/drivers/atm/ambassador.c 2011-05-19 00:06:34.000000000 -0400
26385 +++ linux-2.6.39/drivers/atm/ambassador.c 2011-05-22 19:36:31.000000000 -0400
26386 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev,
26387 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
26388
26389 // VC layer stats
26390 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
26391 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
26392
26393 // free the descriptor
26394 kfree (tx_descr);
26395 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev,
26396 dump_skb ("<<<", vc, skb);
26397
26398 // VC layer stats
26399 - atomic_inc(&atm_vcc->stats->rx);
26400 + atomic_inc_unchecked(&atm_vcc->stats->rx);
26401 __net_timestamp(skb);
26402 // end of our responsibility
26403 atm_vcc->push (atm_vcc, skb);
26404 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev,
26405 } else {
26406 PRINTK (KERN_INFO, "dropped over-size frame");
26407 // should we count this?
26408 - atomic_inc(&atm_vcc->stats->rx_drop);
26409 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
26410 }
26411
26412 } else {
26413 @@ -1342,7 +1342,7 @@ static int amb_send (struct atm_vcc * at
26414 }
26415
26416 if (check_area (skb->data, skb->len)) {
26417 - atomic_inc(&atm_vcc->stats->tx_err);
26418 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
26419 return -ENOMEM; // ?
26420 }
26421
26422 diff -urNp linux-2.6.39/drivers/atm/atmtcp.c linux-2.6.39/drivers/atm/atmtcp.c
26423 --- linux-2.6.39/drivers/atm/atmtcp.c 2011-05-19 00:06:34.000000000 -0400
26424 +++ linux-2.6.39/drivers/atm/atmtcp.c 2011-05-22 19:36:31.000000000 -0400
26425 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc
26426 if (vcc->pop) vcc->pop(vcc,skb);
26427 else dev_kfree_skb(skb);
26428 if (dev_data) return 0;
26429 - atomic_inc(&vcc->stats->tx_err);
26430 + atomic_inc_unchecked(&vcc->stats->tx_err);
26431 return -ENOLINK;
26432 }
26433 size = skb->len+sizeof(struct atmtcp_hdr);
26434 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc
26435 if (!new_skb) {
26436 if (vcc->pop) vcc->pop(vcc,skb);
26437 else dev_kfree_skb(skb);
26438 - atomic_inc(&vcc->stats->tx_err);
26439 + atomic_inc_unchecked(&vcc->stats->tx_err);
26440 return -ENOBUFS;
26441 }
26442 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
26443 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc
26444 if (vcc->pop) vcc->pop(vcc,skb);
26445 else dev_kfree_skb(skb);
26446 out_vcc->push(out_vcc,new_skb);
26447 - atomic_inc(&vcc->stats->tx);
26448 - atomic_inc(&out_vcc->stats->rx);
26449 + atomic_inc_unchecked(&vcc->stats->tx);
26450 + atomic_inc_unchecked(&out_vcc->stats->rx);
26451 return 0;
26452 }
26453
26454 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc
26455 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
26456 read_unlock(&vcc_sklist_lock);
26457 if (!out_vcc) {
26458 - atomic_inc(&vcc->stats->tx_err);
26459 + atomic_inc_unchecked(&vcc->stats->tx_err);
26460 goto done;
26461 }
26462 skb_pull(skb,sizeof(struct atmtcp_hdr));
26463 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc
26464 __net_timestamp(new_skb);
26465 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
26466 out_vcc->push(out_vcc,new_skb);
26467 - atomic_inc(&vcc->stats->tx);
26468 - atomic_inc(&out_vcc->stats->rx);
26469 + atomic_inc_unchecked(&vcc->stats->tx);
26470 + atomic_inc_unchecked(&out_vcc->stats->rx);
26471 done:
26472 if (vcc->pop) vcc->pop(vcc,skb);
26473 else dev_kfree_skb(skb);
26474 diff -urNp linux-2.6.39/drivers/atm/eni.c linux-2.6.39/drivers/atm/eni.c
26475 --- linux-2.6.39/drivers/atm/eni.c 2011-05-19 00:06:34.000000000 -0400
26476 +++ linux-2.6.39/drivers/atm/eni.c 2011-05-22 19:36:31.000000000 -0400
26477 @@ -526,7 +526,7 @@ static int rx_aal0(struct atm_vcc *vcc)
26478 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
26479 vcc->dev->number);
26480 length = 0;
26481 - atomic_inc(&vcc->stats->rx_err);
26482 + atomic_inc_unchecked(&vcc->stats->rx_err);
26483 }
26484 else {
26485 length = ATM_CELL_SIZE-1; /* no HEC */
26486 @@ -581,7 +581,7 @@ static int rx_aal5(struct atm_vcc *vcc)
26487 size);
26488 }
26489 eff = length = 0;
26490 - atomic_inc(&vcc->stats->rx_err);
26491 + atomic_inc_unchecked(&vcc->stats->rx_err);
26492 }
26493 else {
26494 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
26495 @@ -598,7 +598,7 @@ static int rx_aal5(struct atm_vcc *vcc)
26496 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
26497 vcc->dev->number,vcc->vci,length,size << 2,descr);
26498 length = eff = 0;
26499 - atomic_inc(&vcc->stats->rx_err);
26500 + atomic_inc_unchecked(&vcc->stats->rx_err);
26501 }
26502 }
26503 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
26504 @@ -771,7 +771,7 @@ rx_dequeued++;
26505 vcc->push(vcc,skb);
26506 pushed++;
26507 }
26508 - atomic_inc(&vcc->stats->rx);
26509 + atomic_inc_unchecked(&vcc->stats->rx);
26510 }
26511 wake_up(&eni_dev->rx_wait);
26512 }
26513 @@ -1228,7 +1228,7 @@ static void dequeue_tx(struct atm_dev *d
26514 PCI_DMA_TODEVICE);
26515 if (vcc->pop) vcc->pop(vcc,skb);
26516 else dev_kfree_skb_irq(skb);
26517 - atomic_inc(&vcc->stats->tx);
26518 + atomic_inc_unchecked(&vcc->stats->tx);
26519 wake_up(&eni_dev->tx_wait);
26520 dma_complete++;
26521 }
26522 diff -urNp linux-2.6.39/drivers/atm/firestream.c linux-2.6.39/drivers/atm/firestream.c
26523 --- linux-2.6.39/drivers/atm/firestream.c 2011-05-19 00:06:34.000000000 -0400
26524 +++ linux-2.6.39/drivers/atm/firestream.c 2011-05-22 19:36:31.000000000 -0400
26525 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct
26526 }
26527 }
26528
26529 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
26530 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
26531
26532 fs_dprintk (FS_DEBUG_TXMEM, "i");
26533 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
26534 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_
26535 #endif
26536 skb_put (skb, qe->p1 & 0xffff);
26537 ATM_SKB(skb)->vcc = atm_vcc;
26538 - atomic_inc(&atm_vcc->stats->rx);
26539 + atomic_inc_unchecked(&atm_vcc->stats->rx);
26540 __net_timestamp(skb);
26541 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
26542 atm_vcc->push (atm_vcc, skb);
26543 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_
26544 kfree (pe);
26545 }
26546 if (atm_vcc)
26547 - atomic_inc(&atm_vcc->stats->rx_drop);
26548 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
26549 break;
26550 case 0x1f: /* Reassembly abort: no buffers. */
26551 /* Silently increment error counter. */
26552 if (atm_vcc)
26553 - atomic_inc(&atm_vcc->stats->rx_drop);
26554 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
26555 break;
26556 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
26557 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
26558 diff -urNp linux-2.6.39/drivers/atm/fore200e.c linux-2.6.39/drivers/atm/fore200e.c
26559 --- linux-2.6.39/drivers/atm/fore200e.c 2011-05-19 00:06:34.000000000 -0400
26560 +++ linux-2.6.39/drivers/atm/fore200e.c 2011-05-22 19:36:31.000000000 -0400
26561 @@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200
26562 #endif
26563 /* check error condition */
26564 if (*entry->status & STATUS_ERROR)
26565 - atomic_inc(&vcc->stats->tx_err);
26566 + atomic_inc_unchecked(&vcc->stats->tx_err);
26567 else
26568 - atomic_inc(&vcc->stats->tx);
26569 + atomic_inc_unchecked(&vcc->stats->tx);
26570 }
26571 }
26572
26573 @@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore2
26574 if (skb == NULL) {
26575 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
26576
26577 - atomic_inc(&vcc->stats->rx_drop);
26578 + atomic_inc_unchecked(&vcc->stats->rx_drop);
26579 return -ENOMEM;
26580 }
26581
26582 @@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore2
26583
26584 dev_kfree_skb_any(skb);
26585
26586 - atomic_inc(&vcc->stats->rx_drop);
26587 + atomic_inc_unchecked(&vcc->stats->rx_drop);
26588 return -ENOMEM;
26589 }
26590
26591 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
26592
26593 vcc->push(vcc, skb);
26594 - atomic_inc(&vcc->stats->rx);
26595 + atomic_inc_unchecked(&vcc->stats->rx);
26596
26597 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
26598
26599 @@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200
26600 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
26601 fore200e->atm_dev->number,
26602 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
26603 - atomic_inc(&vcc->stats->rx_err);
26604 + atomic_inc_unchecked(&vcc->stats->rx_err);
26605 }
26606 }
26607
26608 @@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struc
26609 goto retry_here;
26610 }
26611
26612 - atomic_inc(&vcc->stats->tx_err);
26613 + atomic_inc_unchecked(&vcc->stats->tx_err);
26614
26615 fore200e->tx_sat++;
26616 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
26617 diff -urNp linux-2.6.39/drivers/atm/he.c linux-2.6.39/drivers/atm/he.c
26618 --- linux-2.6.39/drivers/atm/he.c 2011-05-19 00:06:34.000000000 -0400
26619 +++ linux-2.6.39/drivers/atm/he.c 2011-05-22 19:36:31.000000000 -0400
26620 @@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, i
26621
26622 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
26623 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
26624 - atomic_inc(&vcc->stats->rx_drop);
26625 + atomic_inc_unchecked(&vcc->stats->rx_drop);
26626 goto return_host_buffers;
26627 }
26628
26629 @@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, i
26630 RBRQ_LEN_ERR(he_dev->rbrq_head)
26631 ? "LEN_ERR" : "",
26632 vcc->vpi, vcc->vci);
26633 - atomic_inc(&vcc->stats->rx_err);
26634 + atomic_inc_unchecked(&vcc->stats->rx_err);
26635 goto return_host_buffers;
26636 }
26637
26638 @@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, i
26639 vcc->push(vcc, skb);
26640 spin_lock(&he_dev->global_lock);
26641
26642 - atomic_inc(&vcc->stats->rx);
26643 + atomic_inc_unchecked(&vcc->stats->rx);
26644
26645 return_host_buffers:
26646 ++pdus_assembled;
26647 @@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, str
26648 tpd->vcc->pop(tpd->vcc, tpd->skb);
26649 else
26650 dev_kfree_skb_any(tpd->skb);
26651 - atomic_inc(&tpd->vcc->stats->tx_err);
26652 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
26653 }
26654 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
26655 return;
26656 @@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
26657 vcc->pop(vcc, skb);
26658 else
26659 dev_kfree_skb_any(skb);
26660 - atomic_inc(&vcc->stats->tx_err);
26661 + atomic_inc_unchecked(&vcc->stats->tx_err);
26662 return -EINVAL;
26663 }
26664
26665 @@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
26666 vcc->pop(vcc, skb);
26667 else
26668 dev_kfree_skb_any(skb);
26669 - atomic_inc(&vcc->stats->tx_err);
26670 + atomic_inc_unchecked(&vcc->stats->tx_err);
26671 return -EINVAL;
26672 }
26673 #endif
26674 @@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
26675 vcc->pop(vcc, skb);
26676 else
26677 dev_kfree_skb_any(skb);
26678 - atomic_inc(&vcc->stats->tx_err);
26679 + atomic_inc_unchecked(&vcc->stats->tx_err);
26680 spin_unlock_irqrestore(&he_dev->global_lock, flags);
26681 return -ENOMEM;
26682 }
26683 @@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
26684 vcc->pop(vcc, skb);
26685 else
26686 dev_kfree_skb_any(skb);
26687 - atomic_inc(&vcc->stats->tx_err);
26688 + atomic_inc_unchecked(&vcc->stats->tx_err);
26689 spin_unlock_irqrestore(&he_dev->global_lock, flags);
26690 return -ENOMEM;
26691 }
26692 @@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
26693 __enqueue_tpd(he_dev, tpd, cid);
26694 spin_unlock_irqrestore(&he_dev->global_lock, flags);
26695
26696 - atomic_inc(&vcc->stats->tx);
26697 + atomic_inc_unchecked(&vcc->stats->tx);
26698
26699 return 0;
26700 }
26701 diff -urNp linux-2.6.39/drivers/atm/horizon.c linux-2.6.39/drivers/atm/horizon.c
26702 --- linux-2.6.39/drivers/atm/horizon.c 2011-05-19 00:06:34.000000000 -0400
26703 +++ linux-2.6.39/drivers/atm/horizon.c 2011-05-22 19:36:31.000000000 -0400
26704 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev,
26705 {
26706 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
26707 // VC layer stats
26708 - atomic_inc(&vcc->stats->rx);
26709 + atomic_inc_unchecked(&vcc->stats->rx);
26710 __net_timestamp(skb);
26711 // end of our responsibility
26712 vcc->push (vcc, skb);
26713 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const
26714 dev->tx_iovec = NULL;
26715
26716 // VC layer stats
26717 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
26718 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
26719
26720 // free the skb
26721 hrz_kfree_skb (skb);
26722 diff -urNp linux-2.6.39/drivers/atm/idt77252.c linux-2.6.39/drivers/atm/idt77252.c
26723 --- linux-2.6.39/drivers/atm/idt77252.c 2011-05-19 00:06:34.000000000 -0400
26724 +++ linux-2.6.39/drivers/atm/idt77252.c 2011-05-22 19:36:31.000000000 -0400
26725 @@ -811,7 +811,7 @@ drain_scq(struct idt77252_dev *card, str
26726 else
26727 dev_kfree_skb(skb);
26728
26729 - atomic_inc(&vcc->stats->tx);
26730 + atomic_inc_unchecked(&vcc->stats->tx);
26731 }
26732
26733 atomic_dec(&scq->used);
26734 @@ -1074,13 +1074,13 @@ dequeue_rx(struct idt77252_dev *card, st
26735 if ((sb = dev_alloc_skb(64)) == NULL) {
26736 printk("%s: Can't allocate buffers for aal0.\n",
26737 card->name);
26738 - atomic_add(i, &vcc->stats->rx_drop);
26739 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
26740 break;
26741 }
26742 if (!atm_charge(vcc, sb->truesize)) {
26743 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
26744 card->name);
26745 - atomic_add(i - 1, &vcc->stats->rx_drop);
26746 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
26747 dev_kfree_skb(sb);
26748 break;
26749 }
26750 @@ -1097,7 +1097,7 @@ dequeue_rx(struct idt77252_dev *card, st
26751 ATM_SKB(sb)->vcc = vcc;
26752 __net_timestamp(sb);
26753 vcc->push(vcc, sb);
26754 - atomic_inc(&vcc->stats->rx);
26755 + atomic_inc_unchecked(&vcc->stats->rx);
26756
26757 cell += ATM_CELL_PAYLOAD;
26758 }
26759 @@ -1134,13 +1134,13 @@ dequeue_rx(struct idt77252_dev *card, st
26760 "(CDC: %08x)\n",
26761 card->name, len, rpp->len, readl(SAR_REG_CDC));
26762 recycle_rx_pool_skb(card, rpp);
26763 - atomic_inc(&vcc->stats->rx_err);
26764 + atomic_inc_unchecked(&vcc->stats->rx_err);
26765 return;
26766 }
26767 if (stat & SAR_RSQE_CRC) {
26768 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
26769 recycle_rx_pool_skb(card, rpp);
26770 - atomic_inc(&vcc->stats->rx_err);
26771 + atomic_inc_unchecked(&vcc->stats->rx_err);
26772 return;
26773 }
26774 if (skb_queue_len(&rpp->queue) > 1) {
26775 @@ -1151,7 +1151,7 @@ dequeue_rx(struct idt77252_dev *card, st
26776 RXPRINTK("%s: Can't alloc RX skb.\n",
26777 card->name);
26778 recycle_rx_pool_skb(card, rpp);
26779 - atomic_inc(&vcc->stats->rx_err);
26780 + atomic_inc_unchecked(&vcc->stats->rx_err);
26781 return;
26782 }
26783 if (!atm_charge(vcc, skb->truesize)) {
26784 @@ -1170,7 +1170,7 @@ dequeue_rx(struct idt77252_dev *card, st
26785 __net_timestamp(skb);
26786
26787 vcc->push(vcc, skb);
26788 - atomic_inc(&vcc->stats->rx);
26789 + atomic_inc_unchecked(&vcc->stats->rx);
26790
26791 return;
26792 }
26793 @@ -1192,7 +1192,7 @@ dequeue_rx(struct idt77252_dev *card, st
26794 __net_timestamp(skb);
26795
26796 vcc->push(vcc, skb);
26797 - atomic_inc(&vcc->stats->rx);
26798 + atomic_inc_unchecked(&vcc->stats->rx);
26799
26800 if (skb->truesize > SAR_FB_SIZE_3)
26801 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
26802 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *car
26803 if (vcc->qos.aal != ATM_AAL0) {
26804 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
26805 card->name, vpi, vci);
26806 - atomic_inc(&vcc->stats->rx_drop);
26807 + atomic_inc_unchecked(&vcc->stats->rx_drop);
26808 goto drop;
26809 }
26810
26811 if ((sb = dev_alloc_skb(64)) == NULL) {
26812 printk("%s: Can't allocate buffers for AAL0.\n",
26813 card->name);
26814 - atomic_inc(&vcc->stats->rx_err);
26815 + atomic_inc_unchecked(&vcc->stats->rx_err);
26816 goto drop;
26817 }
26818
26819 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *car
26820 ATM_SKB(sb)->vcc = vcc;
26821 __net_timestamp(sb);
26822 vcc->push(vcc, sb);
26823 - atomic_inc(&vcc->stats->rx);
26824 + atomic_inc_unchecked(&vcc->stats->rx);
26825
26826 drop:
26827 skb_pull(queue, 64);
26828 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, s
26829
26830 if (vc == NULL) {
26831 printk("%s: NULL connection in send().\n", card->name);
26832 - atomic_inc(&vcc->stats->tx_err);
26833 + atomic_inc_unchecked(&vcc->stats->tx_err);
26834 dev_kfree_skb(skb);
26835 return -EINVAL;
26836 }
26837 if (!test_bit(VCF_TX, &vc->flags)) {
26838 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
26839 - atomic_inc(&vcc->stats->tx_err);
26840 + atomic_inc_unchecked(&vcc->stats->tx_err);
26841 dev_kfree_skb(skb);
26842 return -EINVAL;
26843 }
26844 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, s
26845 break;
26846 default:
26847 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
26848 - atomic_inc(&vcc->stats->tx_err);
26849 + atomic_inc_unchecked(&vcc->stats->tx_err);
26850 dev_kfree_skb(skb);
26851 return -EINVAL;
26852 }
26853
26854 if (skb_shinfo(skb)->nr_frags != 0) {
26855 printk("%s: No scatter-gather yet.\n", card->name);
26856 - atomic_inc(&vcc->stats->tx_err);
26857 + atomic_inc_unchecked(&vcc->stats->tx_err);
26858 dev_kfree_skb(skb);
26859 return -EINVAL;
26860 }
26861 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, s
26862
26863 err = queue_skb(card, vc, skb, oam);
26864 if (err) {
26865 - atomic_inc(&vcc->stats->tx_err);
26866 + atomic_inc_unchecked(&vcc->stats->tx_err);
26867 dev_kfree_skb(skb);
26868 return err;
26869 }
26870 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, v
26871 skb = dev_alloc_skb(64);
26872 if (!skb) {
26873 printk("%s: Out of memory in send_oam().\n", card->name);
26874 - atomic_inc(&vcc->stats->tx_err);
26875 + atomic_inc_unchecked(&vcc->stats->tx_err);
26876 return -ENOMEM;
26877 }
26878 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
26879 diff -urNp linux-2.6.39/drivers/atm/iphase.c linux-2.6.39/drivers/atm/iphase.c
26880 --- linux-2.6.39/drivers/atm/iphase.c 2011-05-19 00:06:34.000000000 -0400
26881 +++ linux-2.6.39/drivers/atm/iphase.c 2011-05-22 19:36:31.000000000 -0400
26882 @@ -1124,7 +1124,7 @@ static int rx_pkt(struct atm_dev *dev)
26883 status = (u_short) (buf_desc_ptr->desc_mode);
26884 if (status & (RX_CER | RX_PTE | RX_OFL))
26885 {
26886 - atomic_inc(&vcc->stats->rx_err);
26887 + atomic_inc_unchecked(&vcc->stats->rx_err);
26888 IF_ERR(printk("IA: bad packet, dropping it");)
26889 if (status & RX_CER) {
26890 IF_ERR(printk(" cause: packet CRC error\n");)
26891 @@ -1147,7 +1147,7 @@ static int rx_pkt(struct atm_dev *dev)
26892 len = dma_addr - buf_addr;
26893 if (len > iadev->rx_buf_sz) {
26894 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
26895 - atomic_inc(&vcc->stats->rx_err);
26896 + atomic_inc_unchecked(&vcc->stats->rx_err);
26897 goto out_free_desc;
26898 }
26899
26900 @@ -1297,7 +1297,7 @@ static void rx_dle_intr(struct atm_dev *
26901 ia_vcc = INPH_IA_VCC(vcc);
26902 if (ia_vcc == NULL)
26903 {
26904 - atomic_inc(&vcc->stats->rx_err);
26905 + atomic_inc_unchecked(&vcc->stats->rx_err);
26906 dev_kfree_skb_any(skb);
26907 atm_return(vcc, atm_guess_pdu2truesize(len));
26908 goto INCR_DLE;
26909 @@ -1309,7 +1309,7 @@ static void rx_dle_intr(struct atm_dev *
26910 if ((length > iadev->rx_buf_sz) || (length >
26911 (skb->len - sizeof(struct cpcs_trailer))))
26912 {
26913 - atomic_inc(&vcc->stats->rx_err);
26914 + atomic_inc_unchecked(&vcc->stats->rx_err);
26915 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
26916 length, skb->len);)
26917 dev_kfree_skb_any(skb);
26918 @@ -1325,7 +1325,7 @@ static void rx_dle_intr(struct atm_dev *
26919
26920 IF_RX(printk("rx_dle_intr: skb push");)
26921 vcc->push(vcc,skb);
26922 - atomic_inc(&vcc->stats->rx);
26923 + atomic_inc_unchecked(&vcc->stats->rx);
26924 iadev->rx_pkt_cnt++;
26925 }
26926 INCR_DLE:
26927 @@ -2807,15 +2807,15 @@ static int ia_ioctl(struct atm_dev *dev,
26928 {
26929 struct k_sonet_stats *stats;
26930 stats = &PRIV(_ia_dev[board])->sonet_stats;
26931 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
26932 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
26933 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
26934 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
26935 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
26936 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
26937 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
26938 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
26939 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
26940 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
26941 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
26942 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
26943 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
26944 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
26945 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
26946 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
26947 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
26948 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
26949 }
26950 ia_cmds.status = 0;
26951 break;
26952 @@ -2920,7 +2920,7 @@ static int ia_pkt_tx (struct atm_vcc *vc
26953 if ((desc == 0) || (desc > iadev->num_tx_desc))
26954 {
26955 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
26956 - atomic_inc(&vcc->stats->tx);
26957 + atomic_inc_unchecked(&vcc->stats->tx);
26958 if (vcc->pop)
26959 vcc->pop(vcc, skb);
26960 else
26961 @@ -3025,14 +3025,14 @@ static int ia_pkt_tx (struct atm_vcc *vc
26962 ATM_DESC(skb) = vcc->vci;
26963 skb_queue_tail(&iadev->tx_dma_q, skb);
26964
26965 - atomic_inc(&vcc->stats->tx);
26966 + atomic_inc_unchecked(&vcc->stats->tx);
26967 iadev->tx_pkt_cnt++;
26968 /* Increment transaction counter */
26969 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
26970
26971 #if 0
26972 /* add flow control logic */
26973 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
26974 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
26975 if (iavcc->vc_desc_cnt > 10) {
26976 vcc->tx_quota = vcc->tx_quota * 3 / 4;
26977 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
26978 diff -urNp linux-2.6.39/drivers/atm/lanai.c linux-2.6.39/drivers/atm/lanai.c
26979 --- linux-2.6.39/drivers/atm/lanai.c 2011-05-19 00:06:34.000000000 -0400
26980 +++ linux-2.6.39/drivers/atm/lanai.c 2011-05-22 19:36:31.000000000 -0400
26981 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct l
26982 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
26983 lanai_endtx(lanai, lvcc);
26984 lanai_free_skb(lvcc->tx.atmvcc, skb);
26985 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
26986 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
26987 }
26988
26989 /* Try to fill the buffer - don't call unless there is backlog */
26990 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc
26991 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
26992 __net_timestamp(skb);
26993 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
26994 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
26995 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
26996 out:
26997 lvcc->rx.buf.ptr = end;
26998 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
26999 @@ -1668,7 +1668,7 @@ static int handle_service(struct lanai_d
27000 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
27001 "vcc %d\n", lanai->number, (unsigned int) s, vci);
27002 lanai->stats.service_rxnotaal5++;
27003 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
27004 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
27005 return 0;
27006 }
27007 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
27008 @@ -1680,7 +1680,7 @@ static int handle_service(struct lanai_d
27009 int bytes;
27010 read_unlock(&vcc_sklist_lock);
27011 DPRINTK("got trashed rx pdu on vci %d\n", vci);
27012 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
27013 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
27014 lvcc->stats.x.aal5.service_trash++;
27015 bytes = (SERVICE_GET_END(s) * 16) -
27016 (((unsigned long) lvcc->rx.buf.ptr) -
27017 @@ -1692,7 +1692,7 @@ static int handle_service(struct lanai_d
27018 }
27019 if (s & SERVICE_STREAM) {
27020 read_unlock(&vcc_sklist_lock);
27021 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
27022 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
27023 lvcc->stats.x.aal5.service_stream++;
27024 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
27025 "PDU on VCI %d!\n", lanai->number, vci);
27026 @@ -1700,7 +1700,7 @@ static int handle_service(struct lanai_d
27027 return 0;
27028 }
27029 DPRINTK("got rx crc error on vci %d\n", vci);
27030 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
27031 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
27032 lvcc->stats.x.aal5.service_rxcrc++;
27033 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
27034 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
27035 diff -urNp linux-2.6.39/drivers/atm/nicstar.c linux-2.6.39/drivers/atm/nicstar.c
27036 --- linux-2.6.39/drivers/atm/nicstar.c 2011-05-19 00:06:34.000000000 -0400
27037 +++ linux-2.6.39/drivers/atm/nicstar.c 2011-05-22 19:36:31.000000000 -0400
27038 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc,
27039 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
27040 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
27041 card->index);
27042 - atomic_inc(&vcc->stats->tx_err);
27043 + atomic_inc_unchecked(&vcc->stats->tx_err);
27044 dev_kfree_skb_any(skb);
27045 return -EINVAL;
27046 }
27047 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc,
27048 if (!vc->tx) {
27049 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
27050 card->index);
27051 - atomic_inc(&vcc->stats->tx_err);
27052 + atomic_inc_unchecked(&vcc->stats->tx_err);
27053 dev_kfree_skb_any(skb);
27054 return -EINVAL;
27055 }
27056 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc,
27057 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
27058 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
27059 card->index);
27060 - atomic_inc(&vcc->stats->tx_err);
27061 + atomic_inc_unchecked(&vcc->stats->tx_err);
27062 dev_kfree_skb_any(skb);
27063 return -EINVAL;
27064 }
27065
27066 if (skb_shinfo(skb)->nr_frags != 0) {
27067 printk("nicstar%d: No scatter-gather yet.\n", card->index);
27068 - atomic_inc(&vcc->stats->tx_err);
27069 + atomic_inc_unchecked(&vcc->stats->tx_err);
27070 dev_kfree_skb_any(skb);
27071 return -EINVAL;
27072 }
27073 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc,
27074 }
27075
27076 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
27077 - atomic_inc(&vcc->stats->tx_err);
27078 + atomic_inc_unchecked(&vcc->stats->tx_err);
27079 dev_kfree_skb_any(skb);
27080 return -EIO;
27081 }
27082 - atomic_inc(&vcc->stats->tx);
27083 + atomic_inc_unchecked(&vcc->stats->tx);
27084
27085 return 0;
27086 }
27087 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns
27088 printk
27089 ("nicstar%d: Can't allocate buffers for aal0.\n",
27090 card->index);
27091 - atomic_add(i, &vcc->stats->rx_drop);
27092 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
27093 break;
27094 }
27095 if (!atm_charge(vcc, sb->truesize)) {
27096 RXPRINTK
27097 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
27098 card->index);
27099 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
27100 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
27101 dev_kfree_skb_any(sb);
27102 break;
27103 }
27104 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns
27105 ATM_SKB(sb)->vcc = vcc;
27106 __net_timestamp(sb);
27107 vcc->push(vcc, sb);
27108 - atomic_inc(&vcc->stats->rx);
27109 + atomic_inc_unchecked(&vcc->stats->rx);
27110 cell += ATM_CELL_PAYLOAD;
27111 }
27112
27113 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns
27114 if (iovb == NULL) {
27115 printk("nicstar%d: Out of iovec buffers.\n",
27116 card->index);
27117 - atomic_inc(&vcc->stats->rx_drop);
27118 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27119 recycle_rx_buf(card, skb);
27120 return;
27121 }
27122 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns
27123 small or large buffer itself. */
27124 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
27125 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
27126 - atomic_inc(&vcc->stats->rx_err);
27127 + atomic_inc_unchecked(&vcc->stats->rx_err);
27128 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
27129 NS_MAX_IOVECS);
27130 NS_PRV_IOVCNT(iovb) = 0;
27131 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns
27132 ("nicstar%d: Expected a small buffer, and this is not one.\n",
27133 card->index);
27134 which_list(card, skb);
27135 - atomic_inc(&vcc->stats->rx_err);
27136 + atomic_inc_unchecked(&vcc->stats->rx_err);
27137 recycle_rx_buf(card, skb);
27138 vc->rx_iov = NULL;
27139 recycle_iov_buf(card, iovb);
27140 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns
27141 ("nicstar%d: Expected a large buffer, and this is not one.\n",
27142 card->index);
27143 which_list(card, skb);
27144 - atomic_inc(&vcc->stats->rx_err);
27145 + atomic_inc_unchecked(&vcc->stats->rx_err);
27146 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
27147 NS_PRV_IOVCNT(iovb));
27148 vc->rx_iov = NULL;
27149 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns
27150 printk(" - PDU size mismatch.\n");
27151 else
27152 printk(".\n");
27153 - atomic_inc(&vcc->stats->rx_err);
27154 + atomic_inc_unchecked(&vcc->stats->rx_err);
27155 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
27156 NS_PRV_IOVCNT(iovb));
27157 vc->rx_iov = NULL;
27158 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns
27159 /* skb points to a small buffer */
27160 if (!atm_charge(vcc, skb->truesize)) {
27161 push_rxbufs(card, skb);
27162 - atomic_inc(&vcc->stats->rx_drop);
27163 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27164 } else {
27165 skb_put(skb, len);
27166 dequeue_sm_buf(card, skb);
27167 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns
27168 ATM_SKB(skb)->vcc = vcc;
27169 __net_timestamp(skb);
27170 vcc->push(vcc, skb);
27171 - atomic_inc(&vcc->stats->rx);
27172 + atomic_inc_unchecked(&vcc->stats->rx);
27173 }
27174 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
27175 struct sk_buff *sb;
27176 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns
27177 if (len <= NS_SMBUFSIZE) {
27178 if (!atm_charge(vcc, sb->truesize)) {
27179 push_rxbufs(card, sb);
27180 - atomic_inc(&vcc->stats->rx_drop);
27181 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27182 } else {
27183 skb_put(sb, len);
27184 dequeue_sm_buf(card, sb);
27185 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns
27186 ATM_SKB(sb)->vcc = vcc;
27187 __net_timestamp(sb);
27188 vcc->push(vcc, sb);
27189 - atomic_inc(&vcc->stats->rx);
27190 + atomic_inc_unchecked(&vcc->stats->rx);
27191 }
27192
27193 push_rxbufs(card, skb);
27194 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns
27195
27196 if (!atm_charge(vcc, skb->truesize)) {
27197 push_rxbufs(card, skb);
27198 - atomic_inc(&vcc->stats->rx_drop);
27199 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27200 } else {
27201 dequeue_lg_buf(card, skb);
27202 #ifdef NS_USE_DESTRUCTORS
27203 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns
27204 ATM_SKB(skb)->vcc = vcc;
27205 __net_timestamp(skb);
27206 vcc->push(vcc, skb);
27207 - atomic_inc(&vcc->stats->rx);
27208 + atomic_inc_unchecked(&vcc->stats->rx);
27209 }
27210
27211 push_rxbufs(card, sb);
27212 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns
27213 printk
27214 ("nicstar%d: Out of huge buffers.\n",
27215 card->index);
27216 - atomic_inc(&vcc->stats->rx_drop);
27217 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27218 recycle_iovec_rx_bufs(card,
27219 (struct iovec *)
27220 iovb->data,
27221 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns
27222 card->hbpool.count++;
27223 } else
27224 dev_kfree_skb_any(hb);
27225 - atomic_inc(&vcc->stats->rx_drop);
27226 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27227 } else {
27228 /* Copy the small buffer to the huge buffer */
27229 sb = (struct sk_buff *)iov->iov_base;
27230 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns
27231 #endif /* NS_USE_DESTRUCTORS */
27232 __net_timestamp(hb);
27233 vcc->push(vcc, hb);
27234 - atomic_inc(&vcc->stats->rx);
27235 + atomic_inc_unchecked(&vcc->stats->rx);
27236 }
27237 }
27238
27239 diff -urNp linux-2.6.39/drivers/atm/solos-pci.c linux-2.6.39/drivers/atm/solos-pci.c
27240 --- linux-2.6.39/drivers/atm/solos-pci.c 2011-05-19 00:06:34.000000000 -0400
27241 +++ linux-2.6.39/drivers/atm/solos-pci.c 2011-05-22 19:36:31.000000000 -0400
27242 @@ -715,7 +715,7 @@ void solos_bh(unsigned long card_arg)
27243 }
27244 atm_charge(vcc, skb->truesize);
27245 vcc->push(vcc, skb);
27246 - atomic_inc(&vcc->stats->rx);
27247 + atomic_inc_unchecked(&vcc->stats->rx);
27248 break;
27249
27250 case PKT_STATUS:
27251 @@ -900,6 +900,8 @@ static int print_buffer(struct sk_buff *
27252 char msg[500];
27253 char item[10];
27254
27255 + pax_track_stack();
27256 +
27257 len = buf->len;
27258 for (i = 0; i < len; i++){
27259 if(i % 8 == 0)
27260 @@ -1009,7 +1011,7 @@ static uint32_t fpga_tx(struct solos_car
27261 vcc = SKB_CB(oldskb)->vcc;
27262
27263 if (vcc) {
27264 - atomic_inc(&vcc->stats->tx);
27265 + atomic_inc_unchecked(&vcc->stats->tx);
27266 solos_pop(vcc, oldskb);
27267 } else
27268 dev_kfree_skb_irq(oldskb);
27269 diff -urNp linux-2.6.39/drivers/atm/suni.c linux-2.6.39/drivers/atm/suni.c
27270 --- linux-2.6.39/drivers/atm/suni.c 2011-05-19 00:06:34.000000000 -0400
27271 +++ linux-2.6.39/drivers/atm/suni.c 2011-05-22 19:36:31.000000000 -0400
27272 @@ -50,8 +50,8 @@ static DEFINE_SPINLOCK(sunis_lock);
27273
27274
27275 #define ADD_LIMITED(s,v) \
27276 - atomic_add((v),&stats->s); \
27277 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
27278 + atomic_add_unchecked((v),&stats->s); \
27279 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
27280
27281
27282 static void suni_hz(unsigned long from_timer)
27283 diff -urNp linux-2.6.39/drivers/atm/uPD98402.c linux-2.6.39/drivers/atm/uPD98402.c
27284 --- linux-2.6.39/drivers/atm/uPD98402.c 2011-05-19 00:06:34.000000000 -0400
27285 +++ linux-2.6.39/drivers/atm/uPD98402.c 2011-05-22 19:36:31.000000000 -0400
27286 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *d
27287 struct sonet_stats tmp;
27288 int error = 0;
27289
27290 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
27291 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
27292 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
27293 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
27294 if (zero && !error) {
27295 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev
27296
27297
27298 #define ADD_LIMITED(s,v) \
27299 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
27300 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
27301 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
27302 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
27303 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
27304 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
27305
27306
27307 static void stat_event(struct atm_dev *dev)
27308 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev
27309 if (reason & uPD98402_INT_PFM) stat_event(dev);
27310 if (reason & uPD98402_INT_PCO) {
27311 (void) GET(PCOCR); /* clear interrupt cause */
27312 - atomic_add(GET(HECCT),
27313 + atomic_add_unchecked(GET(HECCT),
27314 &PRIV(dev)->sonet_stats.uncorr_hcs);
27315 }
27316 if ((reason & uPD98402_INT_RFO) &&
27317 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev
27318 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
27319 uPD98402_INT_LOS),PIMR); /* enable them */
27320 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
27321 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
27322 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
27323 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
27324 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
27325 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
27326 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
27327 return 0;
27328 }
27329
27330 diff -urNp linux-2.6.39/drivers/atm/zatm.c linux-2.6.39/drivers/atm/zatm.c
27331 --- linux-2.6.39/drivers/atm/zatm.c 2011-05-19 00:06:34.000000000 -0400
27332 +++ linux-2.6.39/drivers/atm/zatm.c 2011-05-22 19:36:31.000000000 -0400
27333 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy
27334 }
27335 if (!size) {
27336 dev_kfree_skb_irq(skb);
27337 - if (vcc) atomic_inc(&vcc->stats->rx_err);
27338 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
27339 continue;
27340 }
27341 if (!atm_charge(vcc,skb->truesize)) {
27342 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy
27343 skb->len = size;
27344 ATM_SKB(skb)->vcc = vcc;
27345 vcc->push(vcc,skb);
27346 - atomic_inc(&vcc->stats->rx);
27347 + atomic_inc_unchecked(&vcc->stats->rx);
27348 }
27349 zout(pos & 0xffff,MTA(mbx));
27350 #if 0 /* probably a stupid idea */
27351 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD
27352 skb_queue_head(&zatm_vcc->backlog,skb);
27353 break;
27354 }
27355 - atomic_inc(&vcc->stats->tx);
27356 + atomic_inc_unchecked(&vcc->stats->tx);
27357 wake_up(&zatm_vcc->tx_wait);
27358 }
27359
27360 diff -urNp linux-2.6.39/drivers/base/iommu.c linux-2.6.39/drivers/base/iommu.c
27361 --- linux-2.6.39/drivers/base/iommu.c 2011-05-19 00:06:34.000000000 -0400
27362 +++ linux-2.6.39/drivers/base/iommu.c 2011-05-22 19:36:31.000000000 -0400
27363 @@ -23,9 +23,8 @@
27364 #include <linux/errno.h>
27365 #include <linux/iommu.h>
27366
27367 -static struct iommu_ops *iommu_ops;
27368 -
27369 -void register_iommu(struct iommu_ops *ops)
27370 +static const struct iommu_ops *iommu_ops;
27371 +void register_iommu(const struct iommu_ops *ops)
27372 {
27373 if (iommu_ops)
27374 BUG();
27375 diff -urNp linux-2.6.39/drivers/base/power/generic_ops.c linux-2.6.39/drivers/base/power/generic_ops.c
27376 --- linux-2.6.39/drivers/base/power/generic_ops.c 2011-05-19 00:06:34.000000000 -0400
27377 +++ linux-2.6.39/drivers/base/power/generic_ops.c 2011-05-22 19:36:31.000000000 -0400
27378 @@ -215,7 +215,7 @@ int pm_generic_restore(struct device *de
27379 EXPORT_SYMBOL_GPL(pm_generic_restore);
27380 #endif /* CONFIG_PM_SLEEP */
27381
27382 -struct dev_pm_ops generic_subsys_pm_ops = {
27383 +const struct dev_pm_ops generic_subsys_pm_ops = {
27384 #ifdef CONFIG_PM_SLEEP
27385 .suspend = pm_generic_suspend,
27386 .resume = pm_generic_resume,
27387 diff -urNp linux-2.6.39/drivers/base/power/wakeup.c linux-2.6.39/drivers/base/power/wakeup.c
27388 --- linux-2.6.39/drivers/base/power/wakeup.c 2011-05-19 00:06:34.000000000 -0400
27389 +++ linux-2.6.39/drivers/base/power/wakeup.c 2011-05-22 19:36:31.000000000 -0400
27390 @@ -29,14 +29,14 @@ bool events_check_enabled;
27391 * They need to be modified together atomically, so it's better to use one
27392 * atomic variable to hold them both.
27393 */
27394 -static atomic_t combined_event_count = ATOMIC_INIT(0);
27395 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
27396
27397 #define IN_PROGRESS_BITS (sizeof(int) * 4)
27398 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
27399
27400 static void split_counters(unsigned int *cnt, unsigned int *inpr)
27401 {
27402 - unsigned int comb = atomic_read(&combined_event_count);
27403 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
27404
27405 *cnt = (comb >> IN_PROGRESS_BITS);
27406 *inpr = comb & MAX_IN_PROGRESS;
27407 @@ -351,7 +351,7 @@ static void wakeup_source_activate(struc
27408 ws->last_time = ktime_get();
27409
27410 /* Increment the counter of events in progress. */
27411 - atomic_inc(&combined_event_count);
27412 + atomic_inc_unchecked(&combined_event_count);
27413 }
27414
27415 /**
27416 @@ -441,7 +441,7 @@ static void wakeup_source_deactivate(str
27417 * Increment the counter of registered wakeup events and decrement the
27418 * couter of wakeup events in progress simultaneously.
27419 */
27420 - atomic_add(MAX_IN_PROGRESS, &combined_event_count);
27421 + atomic_add_unchecked(MAX_IN_PROGRESS, &combined_event_count);
27422 }
27423
27424 /**
27425 diff -urNp linux-2.6.39/drivers/block/cciss.c linux-2.6.39/drivers/block/cciss.c
27426 --- linux-2.6.39/drivers/block/cciss.c 2011-05-19 00:06:34.000000000 -0400
27427 +++ linux-2.6.39/drivers/block/cciss.c 2011-05-22 19:41:32.000000000 -0400
27428 @@ -103,7 +103,7 @@ MODULE_DEVICE_TABLE(pci, cciss_pci_devic
27429 * product = Marketing Name for the board
27430 * access = Address of the struct of function pointers
27431 */
27432 -static struct board_type products[] = {
27433 +static const struct board_type products[] = {
27434 {0x40700E11, "Smart Array 5300", &SA5_access},
27435 {0x40800E11, "Smart Array 5i", &SA5B_access},
27436 {0x40820E11, "Smart Array 532", &SA5B_access},
27437 @@ -1151,6 +1151,8 @@ static int cciss_ioctl32_passthru(struct
27438 int err;
27439 u32 cp;
27440
27441 + memset(&arg64, 0, sizeof(arg64));
27442 +
27443 err = 0;
27444 err |=
27445 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
27446 diff -urNp linux-2.6.39/drivers/block/cciss.h linux-2.6.39/drivers/block/cciss.h
27447 --- linux-2.6.39/drivers/block/cciss.h 2011-05-19 00:06:34.000000000 -0400
27448 +++ linux-2.6.39/drivers/block/cciss.h 2011-05-22 19:36:31.000000000 -0400
27449 @@ -393,7 +393,7 @@ static bool SA5_performant_intr_pending(
27450 return register_value & SA5_OUTDB_STATUS_PERF_BIT;
27451 }
27452
27453 -static struct access_method SA5_access = {
27454 +static const struct access_method SA5_access = {
27455 SA5_submit_command,
27456 SA5_intr_mask,
27457 SA5_fifo_full,
27458 @@ -401,7 +401,7 @@ static struct access_method SA5_access =
27459 SA5_completed,
27460 };
27461
27462 -static struct access_method SA5B_access = {
27463 +static const struct access_method SA5B_access = {
27464 SA5_submit_command,
27465 SA5B_intr_mask,
27466 SA5_fifo_full,
27467 @@ -409,7 +409,7 @@ static struct access_method SA5B_access
27468 SA5_completed,
27469 };
27470
27471 -static struct access_method SA5_performant_access = {
27472 +static const struct access_method SA5_performant_access = {
27473 SA5_submit_command,
27474 SA5_performant_intr_mask,
27475 SA5_fifo_full,
27476 @@ -420,7 +420,7 @@ static struct access_method SA5_performa
27477 struct board_type {
27478 __u32 board_id;
27479 char *product_name;
27480 - struct access_method *access;
27481 + const struct access_method *access;
27482 int nr_cmds; /* Max cmds this kind of ctlr can handle. */
27483 };
27484
27485 diff -urNp linux-2.6.39/drivers/block/cpqarray.c linux-2.6.39/drivers/block/cpqarray.c
27486 --- linux-2.6.39/drivers/block/cpqarray.c 2011-05-19 00:06:34.000000000 -0400
27487 +++ linux-2.6.39/drivers/block/cpqarray.c 2011-05-22 19:36:31.000000000 -0400
27488 @@ -80,7 +80,7 @@ static int eisa[8];
27489 * product = Marketing Name for the board
27490 * access = Address of the struct of function pointers
27491 */
27492 -static struct board_type products[] = {
27493 +static const struct board_type products[] = {
27494 { 0x0040110E, "IDA", &smart1_access },
27495 { 0x0140110E, "IDA-2", &smart1_access },
27496 { 0x1040110E, "IAES", &smart1_access },
27497 @@ -911,6 +911,8 @@ static void do_ida_request(struct reques
27498 struct scatterlist tmp_sg[SG_MAX];
27499 int i, dir, seg;
27500
27501 + pax_track_stack();
27502 +
27503 queue_next:
27504 creq = blk_peek_request(q);
27505 if (!creq)
27506 diff -urNp linux-2.6.39/drivers/block/cpqarray.h linux-2.6.39/drivers/block/cpqarray.h
27507 --- linux-2.6.39/drivers/block/cpqarray.h 2011-05-19 00:06:34.000000000 -0400
27508 +++ linux-2.6.39/drivers/block/cpqarray.h 2011-05-22 19:36:31.000000000 -0400
27509 @@ -69,7 +69,7 @@ struct access_method {
27510 struct board_type {
27511 __u32 board_id;
27512 char *product_name;
27513 - struct access_method *access;
27514 + const struct access_method *access;
27515 };
27516
27517 struct ctlr_info {
27518 diff -urNp linux-2.6.39/drivers/block/DAC960.c linux-2.6.39/drivers/block/DAC960.c
27519 --- linux-2.6.39/drivers/block/DAC960.c 2011-05-19 00:06:34.000000000 -0400
27520 +++ linux-2.6.39/drivers/block/DAC960.c 2011-05-22 19:36:31.000000000 -0400
27521 @@ -1980,6 +1980,8 @@ static bool DAC960_V1_ReadDeviceConfigur
27522 unsigned long flags;
27523 int Channel, TargetID;
27524
27525 + pax_track_stack();
27526 +
27527 if (!init_dma_loaf(Controller->PCIDevice, &local_dma,
27528 DAC960_V1_MaxChannels*(sizeof(DAC960_V1_DCDB_T) +
27529 sizeof(DAC960_SCSI_Inquiry_T) +
27530 diff -urNp linux-2.6.39/drivers/block/drbd/drbd_int.h linux-2.6.39/drivers/block/drbd/drbd_int.h
27531 --- linux-2.6.39/drivers/block/drbd/drbd_int.h 2011-05-19 00:06:34.000000000 -0400
27532 +++ linux-2.6.39/drivers/block/drbd/drbd_int.h 2011-05-22 19:36:31.000000000 -0400
27533 @@ -736,7 +736,7 @@ struct drbd_request;
27534 struct drbd_epoch {
27535 struct list_head list;
27536 unsigned int barrier_nr;
27537 - atomic_t epoch_size; /* increased on every request added. */
27538 + atomic_unchecked_t epoch_size; /* increased on every request added. */
27539 atomic_t active; /* increased on every req. added, and dec on every finished. */
27540 unsigned long flags;
27541 };
27542 @@ -1108,7 +1108,7 @@ struct drbd_conf {
27543 void *int_dig_in;
27544 void *int_dig_vv;
27545 wait_queue_head_t seq_wait;
27546 - atomic_t packet_seq;
27547 + atomic_unchecked_t packet_seq;
27548 unsigned int peer_seq;
27549 spinlock_t peer_seq_lock;
27550 unsigned int minor;
27551 diff -urNp linux-2.6.39/drivers/block/drbd/drbd_main.c linux-2.6.39/drivers/block/drbd/drbd_main.c
27552 --- linux-2.6.39/drivers/block/drbd/drbd_main.c 2011-05-19 00:06:34.000000000 -0400
27553 +++ linux-2.6.39/drivers/block/drbd/drbd_main.c 2011-05-22 19:36:31.000000000 -0400
27554 @@ -2387,7 +2387,7 @@ static int _drbd_send_ack(struct drbd_co
27555 p.sector = sector;
27556 p.block_id = block_id;
27557 p.blksize = blksize;
27558 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
27559 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
27560
27561 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
27562 return false;
27563 @@ -2686,7 +2686,7 @@ int drbd_send_dblock(struct drbd_conf *m
27564 p.sector = cpu_to_be64(req->sector);
27565 p.block_id = (unsigned long)req;
27566 p.seq_num = cpu_to_be32(req->seq_num =
27567 - atomic_add_return(1, &mdev->packet_seq));
27568 + atomic_add_return_unchecked(1, &mdev->packet_seq));
27569
27570 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
27571
27572 @@ -2971,7 +2971,7 @@ void drbd_init_set_defaults(struct drbd_
27573 atomic_set(&mdev->unacked_cnt, 0);
27574 atomic_set(&mdev->local_cnt, 0);
27575 atomic_set(&mdev->net_cnt, 0);
27576 - atomic_set(&mdev->packet_seq, 0);
27577 + atomic_set_unchecked(&mdev->packet_seq, 0);
27578 atomic_set(&mdev->pp_in_use, 0);
27579 atomic_set(&mdev->pp_in_use_by_net, 0);
27580 atomic_set(&mdev->rs_sect_in, 0);
27581 @@ -3051,8 +3051,8 @@ void drbd_mdev_cleanup(struct drbd_conf
27582 mdev->receiver.t_state);
27583
27584 /* no need to lock it, I'm the only thread alive */
27585 - if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
27586 - dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
27587 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
27588 + dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
27589 mdev->al_writ_cnt =
27590 mdev->bm_writ_cnt =
27591 mdev->read_cnt =
27592 diff -urNp linux-2.6.39/drivers/block/drbd/drbd_nl.c linux-2.6.39/drivers/block/drbd/drbd_nl.c
27593 --- linux-2.6.39/drivers/block/drbd/drbd_nl.c 2011-05-19 00:06:34.000000000 -0400
27594 +++ linux-2.6.39/drivers/block/drbd/drbd_nl.c 2011-05-22 19:36:31.000000000 -0400
27595 @@ -2298,7 +2298,7 @@ static void drbd_connector_callback(stru
27596 module_put(THIS_MODULE);
27597 }
27598
27599 -static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
27600 +static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
27601
27602 static unsigned short *
27603 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
27604 @@ -2369,7 +2369,7 @@ void drbd_bcast_state(struct drbd_conf *
27605 cn_reply->id.idx = CN_IDX_DRBD;
27606 cn_reply->id.val = CN_VAL_DRBD;
27607
27608 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
27609 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
27610 cn_reply->ack = 0; /* not used here. */
27611 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
27612 (int)((char *)tl - (char *)reply->tag_list);
27613 @@ -2401,7 +2401,7 @@ void drbd_bcast_ev_helper(struct drbd_co
27614 cn_reply->id.idx = CN_IDX_DRBD;
27615 cn_reply->id.val = CN_VAL_DRBD;
27616
27617 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
27618 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
27619 cn_reply->ack = 0; /* not used here. */
27620 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
27621 (int)((char *)tl - (char *)reply->tag_list);
27622 @@ -2479,7 +2479,7 @@ void drbd_bcast_ee(struct drbd_conf *mde
27623 cn_reply->id.idx = CN_IDX_DRBD;
27624 cn_reply->id.val = CN_VAL_DRBD;
27625
27626 - cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
27627 + cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
27628 cn_reply->ack = 0; // not used here.
27629 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
27630 (int)((char*)tl - (char*)reply->tag_list);
27631 @@ -2518,7 +2518,7 @@ void drbd_bcast_sync_progress(struct drb
27632 cn_reply->id.idx = CN_IDX_DRBD;
27633 cn_reply->id.val = CN_VAL_DRBD;
27634
27635 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
27636 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
27637 cn_reply->ack = 0; /* not used here. */
27638 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
27639 (int)((char *)tl - (char *)reply->tag_list);
27640 diff -urNp linux-2.6.39/drivers/block/drbd/drbd_receiver.c linux-2.6.39/drivers/block/drbd/drbd_receiver.c
27641 --- linux-2.6.39/drivers/block/drbd/drbd_receiver.c 2011-05-19 00:06:34.000000000 -0400
27642 +++ linux-2.6.39/drivers/block/drbd/drbd_receiver.c 2011-05-22 19:36:31.000000000 -0400
27643 @@ -894,7 +894,7 @@ retry:
27644 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
27645 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
27646
27647 - atomic_set(&mdev->packet_seq, 0);
27648 + atomic_set_unchecked(&mdev->packet_seq, 0);
27649 mdev->peer_seq = 0;
27650
27651 drbd_thread_start(&mdev->asender);
27652 @@ -990,7 +990,7 @@ static enum finish_epoch drbd_may_finish
27653 do {
27654 next_epoch = NULL;
27655
27656 - epoch_size = atomic_read(&epoch->epoch_size);
27657 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
27658
27659 switch (ev & ~EV_CLEANUP) {
27660 case EV_PUT:
27661 @@ -1025,7 +1025,7 @@ static enum finish_epoch drbd_may_finish
27662 rv = FE_DESTROYED;
27663 } else {
27664 epoch->flags = 0;
27665 - atomic_set(&epoch->epoch_size, 0);
27666 + atomic_set_unchecked(&epoch->epoch_size, 0);
27667 /* atomic_set(&epoch->active, 0); is already zero */
27668 if (rv == FE_STILL_LIVE)
27669 rv = FE_RECYCLED;
27670 @@ -1196,14 +1196,14 @@ static int receive_Barrier(struct drbd_c
27671 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
27672 drbd_flush(mdev);
27673
27674 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
27675 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
27676 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
27677 if (epoch)
27678 break;
27679 }
27680
27681 epoch = mdev->current_epoch;
27682 - wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
27683 + wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
27684
27685 D_ASSERT(atomic_read(&epoch->active) == 0);
27686 D_ASSERT(epoch->flags == 0);
27687 @@ -1215,11 +1215,11 @@ static int receive_Barrier(struct drbd_c
27688 }
27689
27690 epoch->flags = 0;
27691 - atomic_set(&epoch->epoch_size, 0);
27692 + atomic_set_unchecked(&epoch->epoch_size, 0);
27693 atomic_set(&epoch->active, 0);
27694
27695 spin_lock(&mdev->epoch_lock);
27696 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
27697 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
27698 list_add(&epoch->list, &mdev->current_epoch->list);
27699 mdev->current_epoch = epoch;
27700 mdev->epochs++;
27701 @@ -1668,7 +1668,7 @@ static int receive_Data(struct drbd_conf
27702 spin_unlock(&mdev->peer_seq_lock);
27703
27704 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
27705 - atomic_inc(&mdev->current_epoch->epoch_size);
27706 + atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
27707 return drbd_drain_block(mdev, data_size);
27708 }
27709
27710 @@ -1694,7 +1694,7 @@ static int receive_Data(struct drbd_conf
27711
27712 spin_lock(&mdev->epoch_lock);
27713 e->epoch = mdev->current_epoch;
27714 - atomic_inc(&e->epoch->epoch_size);
27715 + atomic_inc_unchecked(&e->epoch->epoch_size);
27716 atomic_inc(&e->epoch->active);
27717 spin_unlock(&mdev->epoch_lock);
27718
27719 @@ -3905,7 +3905,7 @@ static void drbd_disconnect(struct drbd_
27720 D_ASSERT(list_empty(&mdev->done_ee));
27721
27722 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
27723 - atomic_set(&mdev->current_epoch->epoch_size, 0);
27724 + atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
27725 D_ASSERT(list_empty(&mdev->current_epoch->list));
27726 }
27727
27728 diff -urNp linux-2.6.39/drivers/block/nbd.c linux-2.6.39/drivers/block/nbd.c
27729 --- linux-2.6.39/drivers/block/nbd.c 2011-05-19 00:06:34.000000000 -0400
27730 +++ linux-2.6.39/drivers/block/nbd.c 2011-05-22 19:36:31.000000000 -0400
27731 @@ -157,6 +157,8 @@ static int sock_xmit(struct nbd_device *
27732 struct kvec iov;
27733 sigset_t blocked, oldset;
27734
27735 + pax_track_stack();
27736 +
27737 if (unlikely(!sock)) {
27738 printk(KERN_ERR "%s: Attempted %s on closed socket in sock_xmit\n",
27739 lo->disk->disk_name, (send ? "send" : "recv"));
27740 @@ -571,6 +573,8 @@ static void do_nbd_request(struct reques
27741 static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *lo,
27742 unsigned int cmd, unsigned long arg)
27743 {
27744 + pax_track_stack();
27745 +
27746 switch (cmd) {
27747 case NBD_DISCONNECT: {
27748 struct request sreq;
27749 diff -urNp linux-2.6.39/drivers/block/smart1,2.h linux-2.6.39/drivers/block/smart1,2.h
27750 --- linux-2.6.39/drivers/block/smart1,2.h 2011-05-19 00:06:34.000000000 -0400
27751 +++ linux-2.6.39/drivers/block/smart1,2.h 2011-05-22 19:36:31.000000000 -0400
27752 @@ -107,7 +107,7 @@ static unsigned long smart4_intr_pending
27753 return 0 ;
27754 }
27755
27756 -static struct access_method smart4_access = {
27757 +static const struct access_method smart4_access = {
27758 smart4_submit_command,
27759 smart4_intr_mask,
27760 smart4_fifo_full,
27761 @@ -143,7 +143,7 @@ static unsigned long smart2_intr_pending
27762 return readl(h->vaddr + INTR_PENDING);
27763 }
27764
27765 -static struct access_method smart2_access = {
27766 +static const struct access_method smart2_access = {
27767 smart2_submit_command,
27768 smart2_intr_mask,
27769 smart2_fifo_full,
27770 @@ -179,7 +179,7 @@ static unsigned long smart2e_intr_pendin
27771 return inl(h->io_mem_addr + INTR_PENDING);
27772 }
27773
27774 -static struct access_method smart2e_access = {
27775 +static const struct access_method smart2e_access = {
27776 smart2e_submit_command,
27777 smart2e_intr_mask,
27778 smart2e_fifo_full,
27779 @@ -269,7 +269,7 @@ static unsigned long smart1_intr_pending
27780 return chan;
27781 }
27782
27783 -static struct access_method smart1_access = {
27784 +static const struct access_method smart1_access = {
27785 smart1_submit_command,
27786 smart1_intr_mask,
27787 smart1_fifo_full,
27788 diff -urNp linux-2.6.39/drivers/block/xsysace.c linux-2.6.39/drivers/block/xsysace.c
27789 --- linux-2.6.39/drivers/block/xsysace.c 2011-05-19 00:06:34.000000000 -0400
27790 +++ linux-2.6.39/drivers/block/xsysace.c 2011-05-22 19:36:31.000000000 -0400
27791 @@ -262,7 +262,7 @@ static void ace_dataout_8(struct ace_dev
27792 ace->data_ptr = src;
27793 }
27794
27795 -static struct ace_reg_ops ace_reg_8_ops = {
27796 +static const struct ace_reg_ops ace_reg_8_ops = {
27797 .in = ace_in_8,
27798 .out = ace_out_8,
27799 .datain = ace_datain_8,
27800 @@ -327,14 +327,14 @@ static void ace_dataout_le16(struct ace_
27801 ace->data_ptr = src;
27802 }
27803
27804 -static struct ace_reg_ops ace_reg_be16_ops = {
27805 +static const struct ace_reg_ops ace_reg_be16_ops = {
27806 .in = ace_in_be16,
27807 .out = ace_out_be16,
27808 .datain = ace_datain_be16,
27809 .dataout = ace_dataout_be16,
27810 };
27811
27812 -static struct ace_reg_ops ace_reg_le16_ops = {
27813 +static const struct ace_reg_ops ace_reg_le16_ops = {
27814 .in = ace_in_le16,
27815 .out = ace_out_le16,
27816 .datain = ace_datain_le16,
27817 diff -urNp linux-2.6.39/drivers/char/agp/frontend.c linux-2.6.39/drivers/char/agp/frontend.c
27818 --- linux-2.6.39/drivers/char/agp/frontend.c 2011-05-19 00:06:34.000000000 -0400
27819 +++ linux-2.6.39/drivers/char/agp/frontend.c 2011-05-22 19:36:31.000000000 -0400
27820 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct ag
27821 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
27822 return -EFAULT;
27823
27824 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
27825 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
27826 return -EFAULT;
27827
27828 client = agp_find_client_by_pid(reserve.pid);
27829 diff -urNp linux-2.6.39/drivers/char/briq_panel.c linux-2.6.39/drivers/char/briq_panel.c
27830 --- linux-2.6.39/drivers/char/briq_panel.c 2011-05-19 00:06:34.000000000 -0400
27831 +++ linux-2.6.39/drivers/char/briq_panel.c 2011-05-22 19:41:32.000000000 -0400
27832 @@ -9,6 +9,7 @@
27833 #include <linux/types.h>
27834 #include <linux/errno.h>
27835 #include <linux/tty.h>
27836 +#include <linux/mutex.h>
27837 #include <linux/timer.h>
27838 #include <linux/kernel.h>
27839 #include <linux/wait.h>
27840 @@ -34,6 +35,7 @@ static int vfd_is_open;
27841 static unsigned char vfd[40];
27842 static int vfd_cursor;
27843 static unsigned char ledpb, led;
27844 +static DEFINE_MUTEX(vfd_mutex);
27845
27846 static void update_vfd(void)
27847 {
27848 @@ -140,12 +142,15 @@ static ssize_t briq_panel_write(struct f
27849 if (!vfd_is_open)
27850 return -EBUSY;
27851
27852 + mutex_lock(&vfd_mutex);
27853 for (;;) {
27854 char c;
27855 if (!indx)
27856 break;
27857 - if (get_user(c, buf))
27858 + if (get_user(c, buf)) {
27859 + mutex_unlock(&vfd_mutex);
27860 return -EFAULT;
27861 + }
27862 if (esc) {
27863 set_led(c);
27864 esc = 0;
27865 @@ -175,6 +180,7 @@ static ssize_t briq_panel_write(struct f
27866 buf++;
27867 }
27868 update_vfd();
27869 + mutex_unlock(&vfd_mutex);
27870
27871 return len;
27872 }
27873 diff -urNp linux-2.6.39/drivers/char/genrtc.c linux-2.6.39/drivers/char/genrtc.c
27874 --- linux-2.6.39/drivers/char/genrtc.c 2011-05-19 00:06:34.000000000 -0400
27875 +++ linux-2.6.39/drivers/char/genrtc.c 2011-05-22 19:41:32.000000000 -0400
27876 @@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *fi
27877 switch (cmd) {
27878
27879 case RTC_PLL_GET:
27880 + memset(&pll, 0, sizeof(pll));
27881 if (get_rtc_pll(&pll))
27882 return -EINVAL;
27883 else
27884 diff -urNp linux-2.6.39/drivers/char/hpet.c linux-2.6.39/drivers/char/hpet.c
27885 --- linux-2.6.39/drivers/char/hpet.c 2011-05-19 00:06:34.000000000 -0400
27886 +++ linux-2.6.39/drivers/char/hpet.c 2011-05-22 19:36:31.000000000 -0400
27887 @@ -553,7 +553,7 @@ static inline unsigned long hpet_time_di
27888 }
27889
27890 static int
27891 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
27892 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
27893 struct hpet_info *info)
27894 {
27895 struct hpet_timer __iomem *timer;
27896 diff -urNp linux-2.6.39/drivers/char/ipmi/ipmi_devintf.c linux-2.6.39/drivers/char/ipmi/ipmi_devintf.c
27897 --- linux-2.6.39/drivers/char/ipmi/ipmi_devintf.c 2011-05-19 00:06:34.000000000 -0400
27898 +++ linux-2.6.39/drivers/char/ipmi/ipmi_devintf.c 2011-05-22 19:36:31.000000000 -0400
27899 @@ -109,8 +109,7 @@ static int ipmi_fasync(int fd, struct fi
27900 return (result);
27901 }
27902
27903 -static struct ipmi_user_hndl ipmi_hndlrs =
27904 -{
27905 +static const struct ipmi_user_hndl ipmi_hndlrs = {
27906 .ipmi_recv_hndl = file_receive_handler,
27907 };
27908
27909 diff -urNp linux-2.6.39/drivers/char/ipmi/ipmi_msghandler.c linux-2.6.39/drivers/char/ipmi/ipmi_msghandler.c
27910 --- linux-2.6.39/drivers/char/ipmi/ipmi_msghandler.c 2011-05-19 00:06:34.000000000 -0400
27911 +++ linux-2.6.39/drivers/char/ipmi/ipmi_msghandler.c 2011-05-22 19:36:31.000000000 -0400
27912 @@ -82,7 +82,7 @@ struct ipmi_user {
27913 struct kref refcount;
27914
27915 /* The upper layer that handles receive messages. */
27916 - struct ipmi_user_hndl *handler;
27917 + const struct ipmi_user_hndl *handler;
27918 void *handler_data;
27919
27920 /* The interface this user is bound to. */
27921 @@ -414,7 +414,7 @@ struct ipmi_smi {
27922 struct proc_dir_entry *proc_dir;
27923 char proc_dir_name[10];
27924
27925 - atomic_t stats[IPMI_NUM_STATS];
27926 + atomic_unchecked_t stats[IPMI_NUM_STATS];
27927
27928 /*
27929 * run_to_completion duplicate of smb_info, smi_info
27930 @@ -447,9 +447,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
27931
27932
27933 #define ipmi_inc_stat(intf, stat) \
27934 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
27935 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
27936 #define ipmi_get_stat(intf, stat) \
27937 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
27938 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
27939
27940 static int is_lan_addr(struct ipmi_addr *addr)
27941 {
27942 @@ -875,7 +875,7 @@ static int intf_err_seq(ipmi_smi_t int
27943
27944
27945 int ipmi_create_user(unsigned int if_num,
27946 - struct ipmi_user_hndl *handler,
27947 + const struct ipmi_user_hndl *handler,
27948 void *handler_data,
27949 ipmi_user_t *user)
27950 {
27951 @@ -2844,7 +2844,7 @@ int ipmi_register_smi(struct ipmi_smi_ha
27952 INIT_LIST_HEAD(&intf->cmd_rcvrs);
27953 init_waitqueue_head(&intf->waitq);
27954 for (i = 0; i < IPMI_NUM_STATS; i++)
27955 - atomic_set(&intf->stats[i], 0);
27956 + atomic_set_unchecked(&intf->stats[i], 0);
27957
27958 intf->proc_dir = NULL;
27959
27960 @@ -4196,6 +4196,8 @@ static void send_panic_events(char *str)
27961 struct ipmi_smi_msg smi_msg;
27962 struct ipmi_recv_msg recv_msg;
27963
27964 + pax_track_stack();
27965 +
27966 si = (struct ipmi_system_interface_addr *) &addr;
27967 si->addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
27968 si->channel = IPMI_BMC_CHANNEL;
27969 diff -urNp linux-2.6.39/drivers/char/ipmi/ipmi_poweroff.c linux-2.6.39/drivers/char/ipmi/ipmi_poweroff.c
27970 --- linux-2.6.39/drivers/char/ipmi/ipmi_poweroff.c 2011-05-19 00:06:34.000000000 -0400
27971 +++ linux-2.6.39/drivers/char/ipmi/ipmi_poweroff.c 2011-05-22 19:36:31.000000000 -0400
27972 @@ -133,7 +133,7 @@ static void receive_handler(struct ipmi_
27973 complete(comp);
27974 }
27975
27976 -static struct ipmi_user_hndl ipmi_poweroff_handler = {
27977 +static const struct ipmi_user_hndl ipmi_poweroff_handler = {
27978 .ipmi_recv_hndl = receive_handler
27979 };
27980
27981 diff -urNp linux-2.6.39/drivers/char/ipmi/ipmi_si_intf.c linux-2.6.39/drivers/char/ipmi/ipmi_si_intf.c
27982 --- linux-2.6.39/drivers/char/ipmi/ipmi_si_intf.c 2011-05-19 00:06:34.000000000 -0400
27983 +++ linux-2.6.39/drivers/char/ipmi/ipmi_si_intf.c 2011-05-22 19:36:31.000000000 -0400
27984 @@ -276,7 +276,7 @@ struct smi_info {
27985 unsigned char slave_addr;
27986
27987 /* Counters and things for the proc filesystem. */
27988 - atomic_t stats[SI_NUM_STATS];
27989 + atomic_unchecked_t stats[SI_NUM_STATS];
27990
27991 struct task_struct *thread;
27992
27993 @@ -285,9 +285,9 @@ struct smi_info {
27994 };
27995
27996 #define smi_inc_stat(smi, stat) \
27997 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
27998 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
27999 #define smi_get_stat(smi, stat) \
28000 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
28001 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
28002
28003 #define SI_MAX_PARMS 4
28004
28005 @@ -3198,7 +3198,7 @@ static int try_smi_init(struct smi_info
28006 atomic_set(&new_smi->req_events, 0);
28007 new_smi->run_to_completion = 0;
28008 for (i = 0; i < SI_NUM_STATS; i++)
28009 - atomic_set(&new_smi->stats[i], 0);
28010 + atomic_set_unchecked(&new_smi->stats[i], 0);
28011
28012 new_smi->interrupt_disabled = 1;
28013 atomic_set(&new_smi->stop_operation, 0);
28014 diff -urNp linux-2.6.39/drivers/char/ipmi/ipmi_watchdog.c linux-2.6.39/drivers/char/ipmi/ipmi_watchdog.c
28015 --- linux-2.6.39/drivers/char/ipmi/ipmi_watchdog.c 2011-05-19 00:06:34.000000000 -0400
28016 +++ linux-2.6.39/drivers/char/ipmi/ipmi_watchdog.c 2011-05-22 19:36:31.000000000 -0400
28017 @@ -216,7 +216,7 @@ static int set_param_timeout(const char
28018 return rv;
28019 }
28020
28021 -static struct kernel_param_ops param_ops_timeout = {
28022 +static const struct kernel_param_ops param_ops_timeout = {
28023 .set = set_param_timeout,
28024 .get = param_get_int,
28025 };
28026 @@ -278,14 +278,14 @@ static int set_param_wdog_ifnum(const ch
28027 return 0;
28028 }
28029
28030 -static struct kernel_param_ops param_ops_wdog_ifnum = {
28031 +static const struct kernel_param_ops param_ops_wdog_ifnum = {
28032 .set = set_param_wdog_ifnum,
28033 .get = param_get_int,
28034 };
28035
28036 #define param_check_wdog_ifnum param_check_int
28037
28038 -static struct kernel_param_ops param_ops_str = {
28039 +static const struct kernel_param_ops param_ops_str = {
28040 .set = set_param_str,
28041 .get = get_param_str,
28042 };
28043 @@ -953,7 +953,7 @@ static void ipmi_wdog_pretimeout_handler
28044 pretimeout_since_last_heartbeat = 1;
28045 }
28046
28047 -static struct ipmi_user_hndl ipmi_hndlrs = {
28048 +static const struct ipmi_user_hndl ipmi_hndlrs = {
28049 .ipmi_recv_hndl = ipmi_wdog_msg_handler,
28050 .ipmi_watchdog_pretimeout = ipmi_wdog_pretimeout_handler
28051 };
28052 diff -urNp linux-2.6.39/drivers/char/Kconfig linux-2.6.39/drivers/char/Kconfig
28053 --- linux-2.6.39/drivers/char/Kconfig 2011-05-19 00:06:34.000000000 -0400
28054 +++ linux-2.6.39/drivers/char/Kconfig 2011-05-22 19:41:37.000000000 -0400
28055 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
28056
28057 config DEVKMEM
28058 bool "/dev/kmem virtual device support"
28059 - default y
28060 + default n
28061 + depends on !GRKERNSEC_KMEM
28062 help
28063 Say Y here if you want to support the /dev/kmem device. The
28064 /dev/kmem device is rarely used, but can be used for certain
28065 @@ -596,6 +597,7 @@ config DEVPORT
28066 bool
28067 depends on !M68K
28068 depends on ISA || PCI
28069 + depends on !GRKERNSEC_KMEM
28070 default y
28071
28072 source "drivers/s390/char/Kconfig"
28073 diff -urNp linux-2.6.39/drivers/char/mem.c linux-2.6.39/drivers/char/mem.c
28074 --- linux-2.6.39/drivers/char/mem.c 2011-05-19 00:06:34.000000000 -0400
28075 +++ linux-2.6.39/drivers/char/mem.c 2011-05-22 19:41:37.000000000 -0400
28076 @@ -18,6 +18,7 @@
28077 #include <linux/raw.h>
28078 #include <linux/tty.h>
28079 #include <linux/capability.h>
28080 +#include <linux/security.h>
28081 #include <linux/ptrace.h>
28082 #include <linux/device.h>
28083 #include <linux/highmem.h>
28084 @@ -34,6 +35,10 @@
28085 # include <linux/efi.h>
28086 #endif
28087
28088 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
28089 +extern struct file_operations grsec_fops;
28090 +#endif
28091 +
28092 static inline unsigned long size_inside_page(unsigned long start,
28093 unsigned long size)
28094 {
28095 @@ -65,9 +70,13 @@ static inline int range_is_allowed(unsig
28096
28097 while (cursor < to) {
28098 if (!devmem_is_allowed(pfn)) {
28099 +#ifdef CONFIG_GRKERNSEC_KMEM
28100 + gr_handle_mem_readwrite(from, to);
28101 +#else
28102 printk(KERN_INFO
28103 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
28104 current->comm, from, to);
28105 +#endif
28106 return 0;
28107 }
28108 cursor += PAGE_SIZE;
28109 @@ -75,6 +84,11 @@ static inline int range_is_allowed(unsig
28110 }
28111 return 1;
28112 }
28113 +#elif defined(CONFIG_GRKERNSEC_KMEM)
28114 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
28115 +{
28116 + return 0;
28117 +}
28118 #else
28119 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
28120 {
28121 @@ -117,6 +131,7 @@ static ssize_t read_mem(struct file *fil
28122
28123 while (count > 0) {
28124 unsigned long remaining;
28125 + char *temp;
28126
28127 sz = size_inside_page(p, count);
28128
28129 @@ -132,7 +147,23 @@ static ssize_t read_mem(struct file *fil
28130 if (!ptr)
28131 return -EFAULT;
28132
28133 - remaining = copy_to_user(buf, ptr, sz);
28134 +#ifdef CONFIG_PAX_USERCOPY
28135 + temp = kmalloc(sz, GFP_KERNEL);
28136 + if (!temp) {
28137 + unxlate_dev_mem_ptr(p, ptr);
28138 + return -ENOMEM;
28139 + }
28140 + memcpy(temp, ptr, sz);
28141 +#else
28142 + temp = ptr;
28143 +#endif
28144 +
28145 + remaining = copy_to_user(buf, temp, sz);
28146 +
28147 +#ifdef CONFIG_PAX_USERCOPY
28148 + kfree(temp);
28149 +#endif
28150 +
28151 unxlate_dev_mem_ptr(p, ptr);
28152 if (remaining)
28153 return -EFAULT;
28154 @@ -395,9 +426,8 @@ static ssize_t read_kmem(struct file *fi
28155 size_t count, loff_t *ppos)
28156 {
28157 unsigned long p = *ppos;
28158 - ssize_t low_count, read, sz;
28159 + ssize_t low_count, read, sz, err = 0;
28160 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
28161 - int err = 0;
28162
28163 read = 0;
28164 if (p < (unsigned long) high_memory) {
28165 @@ -419,6 +449,8 @@ static ssize_t read_kmem(struct file *fi
28166 }
28167 #endif
28168 while (low_count > 0) {
28169 + char *temp;
28170 +
28171 sz = size_inside_page(p, low_count);
28172
28173 /*
28174 @@ -428,7 +460,22 @@ static ssize_t read_kmem(struct file *fi
28175 */
28176 kbuf = xlate_dev_kmem_ptr((char *)p);
28177
28178 - if (copy_to_user(buf, kbuf, sz))
28179 +#ifdef CONFIG_PAX_USERCOPY
28180 + temp = kmalloc(sz, GFP_KERNEL);
28181 + if (!temp)
28182 + return -ENOMEM;
28183 + memcpy(temp, kbuf, sz);
28184 +#else
28185 + temp = kbuf;
28186 +#endif
28187 +
28188 + err = copy_to_user(buf, temp, sz);
28189 +
28190 +#ifdef CONFIG_PAX_USERCOPY
28191 + kfree(temp);
28192 +#endif
28193 +
28194 + if (err)
28195 return -EFAULT;
28196 buf += sz;
28197 p += sz;
28198 @@ -854,6 +901,9 @@ static const struct memdev {
28199 #ifdef CONFIG_CRASH_DUMP
28200 [12] = { "oldmem", 0, &oldmem_fops, NULL },
28201 #endif
28202 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
28203 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
28204 +#endif
28205 };
28206
28207 static int memory_open(struct inode *inode, struct file *filp)
28208 diff -urNp linux-2.6.39/drivers/char/mmtimer.c linux-2.6.39/drivers/char/mmtimer.c
28209 --- linux-2.6.39/drivers/char/mmtimer.c 2011-05-19 00:06:34.000000000 -0400
28210 +++ linux-2.6.39/drivers/char/mmtimer.c 2011-05-22 19:36:31.000000000 -0400
28211 @@ -53,7 +53,7 @@ MODULE_LICENSE("GPL");
28212
28213 #define RTC_BITS 55 /* 55 bits for this implementation */
28214
28215 -static struct k_clock sgi_clock;
28216 +static const struct k_clock sgi_clock;
28217
28218 extern unsigned long sn_rtc_cycles_per_second;
28219
28220 @@ -772,7 +772,7 @@ static int sgi_clock_getres(const clocki
28221 return 0;
28222 }
28223
28224 -static struct k_clock sgi_clock = {
28225 +static const struct k_clock sgi_clock = {
28226 .clock_set = sgi_clock_set,
28227 .clock_get = sgi_clock_get,
28228 .clock_getres = sgi_clock_getres,
28229 diff -urNp linux-2.6.39/drivers/char/nvram.c linux-2.6.39/drivers/char/nvram.c
28230 --- linux-2.6.39/drivers/char/nvram.c 2011-05-19 00:06:34.000000000 -0400
28231 +++ linux-2.6.39/drivers/char/nvram.c 2011-05-22 19:36:31.000000000 -0400
28232 @@ -246,7 +246,7 @@ static ssize_t nvram_read(struct file *f
28233
28234 spin_unlock_irq(&rtc_lock);
28235
28236 - if (copy_to_user(buf, contents, tmp - contents))
28237 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
28238 return -EFAULT;
28239
28240 *ppos = i;
28241 diff -urNp linux-2.6.39/drivers/char/random.c linux-2.6.39/drivers/char/random.c
28242 --- linux-2.6.39/drivers/char/random.c 2011-05-19 00:06:34.000000000 -0400
28243 +++ linux-2.6.39/drivers/char/random.c 2011-05-22 19:41:37.000000000 -0400
28244 @@ -261,8 +261,13 @@
28245 /*
28246 * Configuration information
28247 */
28248 +#ifdef CONFIG_GRKERNSEC_RANDNET
28249 +#define INPUT_POOL_WORDS 512
28250 +#define OUTPUT_POOL_WORDS 128
28251 +#else
28252 #define INPUT_POOL_WORDS 128
28253 #define OUTPUT_POOL_WORDS 32
28254 +#endif
28255 #define SEC_XFER_SIZE 512
28256 #define EXTRACT_SIZE 10
28257
28258 @@ -300,10 +305,17 @@ static struct poolinfo {
28259 int poolwords;
28260 int tap1, tap2, tap3, tap4, tap5;
28261 } poolinfo_table[] = {
28262 +#ifdef CONFIG_GRKERNSEC_RANDNET
28263 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
28264 + { 512, 411, 308, 208, 104, 1 },
28265 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
28266 + { 128, 103, 76, 51, 25, 1 },
28267 +#else
28268 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
28269 { 128, 103, 76, 51, 25, 1 },
28270 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
28271 { 32, 26, 20, 14, 7, 1 },
28272 +#endif
28273 #if 0
28274 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
28275 { 2048, 1638, 1231, 819, 411, 1 },
28276 @@ -909,7 +921,7 @@ static ssize_t extract_entropy_user(stru
28277
28278 extract_buf(r, tmp);
28279 i = min_t(int, nbytes, EXTRACT_SIZE);
28280 - if (copy_to_user(buf, tmp, i)) {
28281 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
28282 ret = -EFAULT;
28283 break;
28284 }
28285 @@ -1214,7 +1226,7 @@ EXPORT_SYMBOL(generate_random_uuid);
28286 #include <linux/sysctl.h>
28287
28288 static int min_read_thresh = 8, min_write_thresh;
28289 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
28290 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
28291 static int max_write_thresh = INPUT_POOL_WORDS * 32;
28292 static char sysctl_bootid[16];
28293
28294 diff -urNp linux-2.6.39/drivers/char/sonypi.c linux-2.6.39/drivers/char/sonypi.c
28295 --- linux-2.6.39/drivers/char/sonypi.c 2011-05-19 00:06:34.000000000 -0400
28296 +++ linux-2.6.39/drivers/char/sonypi.c 2011-05-22 19:36:31.000000000 -0400
28297 @@ -55,6 +55,7 @@
28298 #include <asm/uaccess.h>
28299 #include <asm/io.h>
28300 #include <asm/system.h>
28301 +#include <asm/local.h>
28302
28303 #include <linux/sonypi.h>
28304
28305 @@ -491,7 +492,7 @@ static struct sonypi_device {
28306 spinlock_t fifo_lock;
28307 wait_queue_head_t fifo_proc_list;
28308 struct fasync_struct *fifo_async;
28309 - int open_count;
28310 + local_t open_count;
28311 int model;
28312 struct input_dev *input_jog_dev;
28313 struct input_dev *input_key_dev;
28314 @@ -898,7 +899,7 @@ static int sonypi_misc_fasync(int fd, st
28315 static int sonypi_misc_release(struct inode *inode, struct file *file)
28316 {
28317 mutex_lock(&sonypi_device.lock);
28318 - sonypi_device.open_count--;
28319 + local_dec(&sonypi_device.open_count);
28320 mutex_unlock(&sonypi_device.lock);
28321 return 0;
28322 }
28323 @@ -907,9 +908,9 @@ static int sonypi_misc_open(struct inode
28324 {
28325 mutex_lock(&sonypi_device.lock);
28326 /* Flush input queue on first open */
28327 - if (!sonypi_device.open_count)
28328 + if (!local_read(&sonypi_device.open_count))
28329 kfifo_reset(&sonypi_device.fifo);
28330 - sonypi_device.open_count++;
28331 + local_inc(&sonypi_device.open_count);
28332 mutex_unlock(&sonypi_device.lock);
28333
28334 return 0;
28335 diff -urNp linux-2.6.39/drivers/char/tpm/tpm_bios.c linux-2.6.39/drivers/char/tpm/tpm_bios.c
28336 --- linux-2.6.39/drivers/char/tpm/tpm_bios.c 2011-05-19 00:06:34.000000000 -0400
28337 +++ linux-2.6.39/drivers/char/tpm/tpm_bios.c 2011-05-22 19:36:31.000000000 -0400
28338 @@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start
28339 event = addr;
28340
28341 if ((event->event_type == 0 && event->event_size == 0) ||
28342 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
28343 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
28344 return NULL;
28345
28346 return addr;
28347 @@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(
28348 return NULL;
28349
28350 if ((event->event_type == 0 && event->event_size == 0) ||
28351 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
28352 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
28353 return NULL;
28354
28355 (*pos)++;
28356 @@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_
28357 int i;
28358
28359 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
28360 - seq_putc(m, data[i]);
28361 + if (!seq_putc(m, data[i]))
28362 + return -EFAULT;
28363
28364 return 0;
28365 }
28366 @@ -410,6 +411,11 @@ static int read_log(struct tpm_bios_log
28367 log->bios_event_log_end = log->bios_event_log + len;
28368
28369 virt = acpi_os_map_memory(start, len);
28370 + if (!virt) {
28371 + kfree(log->bios_event_log);
28372 + log->bios_event_log = NULL;
28373 + return -EFAULT;
28374 + }
28375
28376 memcpy(log->bios_event_log, virt, len);
28377
28378 diff -urNp linux-2.6.39/drivers/char/tpm/tpm.c linux-2.6.39/drivers/char/tpm/tpm.c
28379 --- linux-2.6.39/drivers/char/tpm/tpm.c 2011-05-19 00:06:34.000000000 -0400
28380 +++ linux-2.6.39/drivers/char/tpm/tpm.c 2011-05-22 19:36:31.000000000 -0400
28381 @@ -411,7 +411,7 @@ static ssize_t tpm_transmit(struct tpm_c
28382 chip->vendor.req_complete_val)
28383 goto out_recv;
28384
28385 - if ((status == chip->vendor.req_canceled)) {
28386 + if (status == chip->vendor.req_canceled) {
28387 dev_err(chip->dev, "Operation Canceled\n");
28388 rc = -ECANCELED;
28389 goto out;
28390 @@ -844,6 +844,8 @@ ssize_t tpm_show_pubek(struct device *de
28391
28392 struct tpm_chip *chip = dev_get_drvdata(dev);
28393
28394 + pax_track_stack();
28395 +
28396 tpm_cmd.header.in = tpm_readpubek_header;
28397 err = transmit_cmd(chip, &tpm_cmd, READ_PUBEK_RESULT_SIZE,
28398 "attempting to read the PUBEK");
28399 diff -urNp linux-2.6.39/drivers/char/ttyprintk.c linux-2.6.39/drivers/char/ttyprintk.c
28400 --- linux-2.6.39/drivers/char/ttyprintk.c 2011-05-19 00:06:34.000000000 -0400
28401 +++ linux-2.6.39/drivers/char/ttyprintk.c 2011-05-22 19:36:31.000000000 -0400
28402 @@ -170,7 +170,7 @@ static const struct tty_operations ttypr
28403 .ioctl = tpk_ioctl,
28404 };
28405
28406 -struct tty_port_operations null_ops = { };
28407 +const struct tty_port_operations null_ops = { };
28408
28409 static struct tty_driver *ttyprintk_driver;
28410
28411 diff -urNp linux-2.6.39/drivers/char/xilinx_hwicap/xilinx_hwicap.c linux-2.6.39/drivers/char/xilinx_hwicap/xilinx_hwicap.c
28412 --- linux-2.6.39/drivers/char/xilinx_hwicap/xilinx_hwicap.c 2011-05-19 00:06:34.000000000 -0400
28413 +++ linux-2.6.39/drivers/char/xilinx_hwicap/xilinx_hwicap.c 2011-05-22 19:36:31.000000000 -0400
28414 @@ -678,14 +678,14 @@ static int __devinit hwicap_setup(struct
28415 return retval;
28416 }
28417
28418 -static struct hwicap_driver_config buffer_icap_config = {
28419 +static const struct hwicap_driver_config buffer_icap_config = {
28420 .get_configuration = buffer_icap_get_configuration,
28421 .set_configuration = buffer_icap_set_configuration,
28422 .get_status = buffer_icap_get_status,
28423 .reset = buffer_icap_reset,
28424 };
28425
28426 -static struct hwicap_driver_config fifo_icap_config = {
28427 +static const struct hwicap_driver_config fifo_icap_config = {
28428 .get_configuration = fifo_icap_get_configuration,
28429 .set_configuration = fifo_icap_set_configuration,
28430 .get_status = fifo_icap_get_status,
28431 diff -urNp linux-2.6.39/drivers/crypto/hifn_795x.c linux-2.6.39/drivers/crypto/hifn_795x.c
28432 --- linux-2.6.39/drivers/crypto/hifn_795x.c 2011-05-19 00:06:34.000000000 -0400
28433 +++ linux-2.6.39/drivers/crypto/hifn_795x.c 2011-05-22 19:36:31.000000000 -0400
28434 @@ -1655,6 +1655,8 @@ static int hifn_test(struct hifn_device
28435 0xCA, 0x34, 0x2B, 0x2E};
28436 struct scatterlist sg;
28437
28438 + pax_track_stack();
28439 +
28440 memset(src, 0, sizeof(src));
28441 memset(ctx.key, 0, sizeof(ctx.key));
28442
28443 diff -urNp linux-2.6.39/drivers/crypto/padlock-aes.c linux-2.6.39/drivers/crypto/padlock-aes.c
28444 --- linux-2.6.39/drivers/crypto/padlock-aes.c 2011-05-19 00:06:34.000000000 -0400
28445 +++ linux-2.6.39/drivers/crypto/padlock-aes.c 2011-05-22 19:36:31.000000000 -0400
28446 @@ -109,6 +109,8 @@ static int aes_set_key(struct crypto_tfm
28447 struct crypto_aes_ctx gen_aes;
28448 int cpu;
28449
28450 + pax_track_stack();
28451 +
28452 if (key_len % 8) {
28453 *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
28454 return -EINVAL;
28455 diff -urNp linux-2.6.39/drivers/dca/dca-core.c linux-2.6.39/drivers/dca/dca-core.c
28456 --- linux-2.6.39/drivers/dca/dca-core.c 2011-05-19 00:06:34.000000000 -0400
28457 +++ linux-2.6.39/drivers/dca/dca-core.c 2011-05-22 19:36:31.000000000 -0400
28458 @@ -325,7 +325,7 @@ EXPORT_SYMBOL_GPL(dca_get_tag);
28459 * @ops - pointer to struct of dca operation function pointers
28460 * @priv_size - size of extra mem to be added for provider's needs
28461 */
28462 -struct dca_provider *alloc_dca_provider(struct dca_ops *ops, int priv_size)
28463 +struct dca_provider *alloc_dca_provider(const struct dca_ops *ops, int priv_size)
28464 {
28465 struct dca_provider *dca;
28466 int alloc_size;
28467 diff -urNp linux-2.6.39/drivers/dma/ioat/dca.c linux-2.6.39/drivers/dma/ioat/dca.c
28468 --- linux-2.6.39/drivers/dma/ioat/dca.c 2011-05-19 00:06:34.000000000 -0400
28469 +++ linux-2.6.39/drivers/dma/ioat/dca.c 2011-05-22 19:36:31.000000000 -0400
28470 @@ -234,7 +234,7 @@ static int ioat_dca_dev_managed(struct d
28471 return 0;
28472 }
28473
28474 -static struct dca_ops ioat_dca_ops = {
28475 +static const struct dca_ops ioat_dca_ops = {
28476 .add_requester = ioat_dca_add_requester,
28477 .remove_requester = ioat_dca_remove_requester,
28478 .get_tag = ioat_dca_get_tag,
28479 @@ -384,7 +384,7 @@ static u8 ioat2_dca_get_tag(struct dca_p
28480 return tag;
28481 }
28482
28483 -static struct dca_ops ioat2_dca_ops = {
28484 +static const struct dca_ops ioat2_dca_ops = {
28485 .add_requester = ioat2_dca_add_requester,
28486 .remove_requester = ioat2_dca_remove_requester,
28487 .get_tag = ioat2_dca_get_tag,
28488 @@ -579,7 +579,7 @@ static u8 ioat3_dca_get_tag(struct dca_p
28489 return tag;
28490 }
28491
28492 -static struct dca_ops ioat3_dca_ops = {
28493 +static const struct dca_ops ioat3_dca_ops = {
28494 .add_requester = ioat3_dca_add_requester,
28495 .remove_requester = ioat3_dca_remove_requester,
28496 .get_tag = ioat3_dca_get_tag,
28497 diff -urNp linux-2.6.39/drivers/edac/amd64_edac.h linux-2.6.39/drivers/edac/amd64_edac.h
28498 --- linux-2.6.39/drivers/edac/amd64_edac.h 2011-05-19 00:06:34.000000000 -0400
28499 +++ linux-2.6.39/drivers/edac/amd64_edac.h 2011-05-22 19:36:31.000000000 -0400
28500 @@ -333,7 +333,7 @@ struct chip_select {
28501 };
28502
28503 struct amd64_pvt {
28504 - struct low_ops *ops;
28505 + const struct low_ops *ops;
28506
28507 /* pci_device handles which we utilize */
28508 struct pci_dev *F1, *F2, *F3;
28509 @@ -443,7 +443,7 @@ struct low_ops {
28510 struct amd64_family_type {
28511 const char *ctl_name;
28512 u16 f1_id, f3_id;
28513 - struct low_ops ops;
28514 + const struct low_ops ops;
28515 };
28516
28517 int __amd64_write_pci_cfg_dword(struct pci_dev *pdev, int offset,
28518 diff -urNp linux-2.6.39/drivers/edac/edac_mc_sysfs.c linux-2.6.39/drivers/edac/edac_mc_sysfs.c
28519 --- linux-2.6.39/drivers/edac/edac_mc_sysfs.c 2011-05-19 00:06:34.000000000 -0400
28520 +++ linux-2.6.39/drivers/edac/edac_mc_sysfs.c 2011-05-22 19:36:31.000000000 -0400
28521 @@ -760,7 +760,7 @@ static void edac_inst_grp_release(struct
28522 }
28523
28524 /* Intermediate show/store table */
28525 -static struct sysfs_ops inst_grp_ops = {
28526 +static const struct sysfs_ops inst_grp_ops = {
28527 .show = inst_grp_show,
28528 .store = inst_grp_store
28529 };
28530 diff -urNp linux-2.6.39/drivers/edac/edac_pci_sysfs.c linux-2.6.39/drivers/edac/edac_pci_sysfs.c
28531 --- linux-2.6.39/drivers/edac/edac_pci_sysfs.c 2011-05-19 00:06:34.000000000 -0400
28532 +++ linux-2.6.39/drivers/edac/edac_pci_sysfs.c 2011-05-22 19:36:31.000000000 -0400
28533 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log
28534 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
28535 static int edac_pci_poll_msec = 1000; /* one second workq period */
28536
28537 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
28538 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
28539 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
28540 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
28541
28542 static struct kobject *edac_pci_top_main_kobj;
28543 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
28544 @@ -582,7 +582,7 @@ static void edac_pci_dev_parity_test(str
28545 edac_printk(KERN_CRIT, EDAC_PCI,
28546 "Signaled System Error on %s\n",
28547 pci_name(dev));
28548 - atomic_inc(&pci_nonparity_count);
28549 + atomic_inc_unchecked(&pci_nonparity_count);
28550 }
28551
28552 if (status & (PCI_STATUS_PARITY)) {
28553 @@ -590,7 +590,7 @@ static void edac_pci_dev_parity_test(str
28554 "Master Data Parity Error on %s\n",
28555 pci_name(dev));
28556
28557 - atomic_inc(&pci_parity_count);
28558 + atomic_inc_unchecked(&pci_parity_count);
28559 }
28560
28561 if (status & (PCI_STATUS_DETECTED_PARITY)) {
28562 @@ -598,7 +598,7 @@ static void edac_pci_dev_parity_test(str
28563 "Detected Parity Error on %s\n",
28564 pci_name(dev));
28565
28566 - atomic_inc(&pci_parity_count);
28567 + atomic_inc_unchecked(&pci_parity_count);
28568 }
28569 }
28570
28571 @@ -619,7 +619,7 @@ static void edac_pci_dev_parity_test(str
28572 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
28573 "Signaled System Error on %s\n",
28574 pci_name(dev));
28575 - atomic_inc(&pci_nonparity_count);
28576 + atomic_inc_unchecked(&pci_nonparity_count);
28577 }
28578
28579 if (status & (PCI_STATUS_PARITY)) {
28580 @@ -627,7 +627,7 @@ static void edac_pci_dev_parity_test(str
28581 "Master Data Parity Error on "
28582 "%s\n", pci_name(dev));
28583
28584 - atomic_inc(&pci_parity_count);
28585 + atomic_inc_unchecked(&pci_parity_count);
28586 }
28587
28588 if (status & (PCI_STATUS_DETECTED_PARITY)) {
28589 @@ -635,7 +635,7 @@ static void edac_pci_dev_parity_test(str
28590 "Detected Parity Error on %s\n",
28591 pci_name(dev));
28592
28593 - atomic_inc(&pci_parity_count);
28594 + atomic_inc_unchecked(&pci_parity_count);
28595 }
28596 }
28597 }
28598 @@ -677,7 +677,7 @@ void edac_pci_do_parity_check(void)
28599 if (!check_pci_errors)
28600 return;
28601
28602 - before_count = atomic_read(&pci_parity_count);
28603 + before_count = atomic_read_unchecked(&pci_parity_count);
28604
28605 /* scan all PCI devices looking for a Parity Error on devices and
28606 * bridges.
28607 @@ -689,7 +689,7 @@ void edac_pci_do_parity_check(void)
28608 /* Only if operator has selected panic on PCI Error */
28609 if (edac_pci_get_panic_on_pe()) {
28610 /* If the count is different 'after' from 'before' */
28611 - if (before_count != atomic_read(&pci_parity_count))
28612 + if (before_count != atomic_read_unchecked(&pci_parity_count))
28613 panic("EDAC: PCI Parity Error");
28614 }
28615 }
28616 diff -urNp linux-2.6.39/drivers/firewire/core-cdev.c linux-2.6.39/drivers/firewire/core-cdev.c
28617 --- linux-2.6.39/drivers/firewire/core-cdev.c 2011-05-19 00:06:34.000000000 -0400
28618 +++ linux-2.6.39/drivers/firewire/core-cdev.c 2011-05-22 19:36:31.000000000 -0400
28619 @@ -1312,8 +1312,7 @@ static int init_iso_resource(struct clie
28620 int ret;
28621
28622 if ((request->channels == 0 && request->bandwidth == 0) ||
28623 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
28624 - request->bandwidth < 0)
28625 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
28626 return -EINVAL;
28627
28628 r = kmalloc(sizeof(*r), GFP_KERNEL);
28629 diff -urNp linux-2.6.39/drivers/firewire/core-transaction.c linux-2.6.39/drivers/firewire/core-transaction.c
28630 --- linux-2.6.39/drivers/firewire/core-transaction.c 2011-05-19 00:06:34.000000000 -0400
28631 +++ linux-2.6.39/drivers/firewire/core-transaction.c 2011-05-22 19:36:31.000000000 -0400
28632 @@ -36,6 +36,7 @@
28633 #include <linux/string.h>
28634 #include <linux/timer.h>
28635 #include <linux/types.h>
28636 +#include <linux/sched.h>
28637
28638 #include <asm/byteorder.h>
28639
28640 @@ -420,6 +421,8 @@ int fw_run_transaction(struct fw_card *c
28641 struct transaction_callback_data d;
28642 struct fw_transaction t;
28643
28644 + pax_track_stack();
28645 +
28646 init_timer_on_stack(&t.split_timeout_timer);
28647 init_completion(&d.done);
28648 d.payload = payload;
28649 diff -urNp linux-2.6.39/drivers/firmware/dmi_scan.c linux-2.6.39/drivers/firmware/dmi_scan.c
28650 --- linux-2.6.39/drivers/firmware/dmi_scan.c 2011-05-19 00:06:34.000000000 -0400
28651 +++ linux-2.6.39/drivers/firmware/dmi_scan.c 2011-05-22 19:36:31.000000000 -0400
28652 @@ -449,11 +449,6 @@ void __init dmi_scan_machine(void)
28653 }
28654 }
28655 else {
28656 - /*
28657 - * no iounmap() for that ioremap(); it would be a no-op, but
28658 - * it's so early in setup that sucker gets confused into doing
28659 - * what it shouldn't if we actually call it.
28660 - */
28661 p = dmi_ioremap(0xF0000, 0x10000);
28662 if (p == NULL)
28663 goto error;
28664 diff -urNp linux-2.6.39/drivers/gpio/vr41xx_giu.c linux-2.6.39/drivers/gpio/vr41xx_giu.c
28665 --- linux-2.6.39/drivers/gpio/vr41xx_giu.c 2011-05-19 00:06:34.000000000 -0400
28666 +++ linux-2.6.39/drivers/gpio/vr41xx_giu.c 2011-05-22 19:36:31.000000000 -0400
28667 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
28668 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
28669 maskl, pendl, maskh, pendh);
28670
28671 - atomic_inc(&irq_err_count);
28672 + atomic_inc_unchecked(&irq_err_count);
28673
28674 return -EINVAL;
28675 }
28676 diff -urNp linux-2.6.39/drivers/gpu/drm/drm_crtc_helper.c linux-2.6.39/drivers/gpu/drm/drm_crtc_helper.c
28677 --- linux-2.6.39/drivers/gpu/drm/drm_crtc_helper.c 2011-05-19 00:06:34.000000000 -0400
28678 +++ linux-2.6.39/drivers/gpu/drm/drm_crtc_helper.c 2011-05-22 19:36:31.000000000 -0400
28679 @@ -276,7 +276,7 @@ static bool drm_encoder_crtc_ok(struct d
28680 struct drm_crtc *tmp;
28681 int crtc_mask = 1;
28682
28683 - WARN(!crtc, "checking null crtc?\n");
28684 + BUG_ON(!crtc);
28685
28686 dev = crtc->dev;
28687
28688 @@ -343,6 +343,8 @@ bool drm_crtc_helper_set_mode(struct drm
28689 struct drm_encoder *encoder;
28690 bool ret = true;
28691
28692 + pax_track_stack();
28693 +
28694 crtc->enabled = drm_helper_crtc_in_use(crtc);
28695 if (!crtc->enabled)
28696 return true;
28697 diff -urNp linux-2.6.39/drivers/gpu/drm/drm_drv.c linux-2.6.39/drivers/gpu/drm/drm_drv.c
28698 --- linux-2.6.39/drivers/gpu/drm/drm_drv.c 2011-05-19 00:06:34.000000000 -0400
28699 +++ linux-2.6.39/drivers/gpu/drm/drm_drv.c 2011-05-22 19:36:31.000000000 -0400
28700 @@ -386,7 +386,7 @@ long drm_ioctl(struct file *filp,
28701
28702 dev = file_priv->minor->dev;
28703 atomic_inc(&dev->ioctl_count);
28704 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
28705 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
28706 ++file_priv->ioctl_count;
28707
28708 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
28709 diff -urNp linux-2.6.39/drivers/gpu/drm/drm_fops.c linux-2.6.39/drivers/gpu/drm/drm_fops.c
28710 --- linux-2.6.39/drivers/gpu/drm/drm_fops.c 2011-05-19 00:06:34.000000000 -0400
28711 +++ linux-2.6.39/drivers/gpu/drm/drm_fops.c 2011-05-22 19:36:31.000000000 -0400
28712 @@ -70,7 +70,7 @@ static int drm_setup(struct drm_device *
28713 }
28714
28715 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
28716 - atomic_set(&dev->counts[i], 0);
28717 + atomic_set_unchecked(&dev->counts[i], 0);
28718
28719 dev->sigdata.lock = NULL;
28720
28721 @@ -134,8 +134,8 @@ int drm_open(struct inode *inode, struct
28722
28723 retcode = drm_open_helper(inode, filp, dev);
28724 if (!retcode) {
28725 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
28726 - if (!dev->open_count++)
28727 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
28728 + if (local_inc_return(&dev->open_count) == 1)
28729 retcode = drm_setup(dev);
28730 }
28731 if (!retcode) {
28732 @@ -472,7 +472,7 @@ int drm_release(struct inode *inode, str
28733
28734 mutex_lock(&drm_global_mutex);
28735
28736 - DRM_DEBUG("open_count = %d\n", dev->open_count);
28737 + DRM_DEBUG("open_count = %d\n", local_read(&dev->open_count));
28738
28739 if (dev->driver->preclose)
28740 dev->driver->preclose(dev, file_priv);
28741 @@ -484,7 +484,7 @@ int drm_release(struct inode *inode, str
28742 DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
28743 task_pid_nr(current),
28744 (long)old_encode_dev(file_priv->minor->device),
28745 - dev->open_count);
28746 + local_read(&dev->open_count));
28747
28748 /* if the master has gone away we can't do anything with the lock */
28749 if (file_priv->minor->master)
28750 @@ -565,8 +565,8 @@ int drm_release(struct inode *inode, str
28751 * End inline drm_release
28752 */
28753
28754 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
28755 - if (!--dev->open_count) {
28756 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
28757 + if (local_dec_and_test(&dev->open_count)) {
28758 if (atomic_read(&dev->ioctl_count)) {
28759 DRM_ERROR("Device busy: %d\n",
28760 atomic_read(&dev->ioctl_count));
28761 diff -urNp linux-2.6.39/drivers/gpu/drm/drm_global.c linux-2.6.39/drivers/gpu/drm/drm_global.c
28762 --- linux-2.6.39/drivers/gpu/drm/drm_global.c 2011-05-19 00:06:34.000000000 -0400
28763 +++ linux-2.6.39/drivers/gpu/drm/drm_global.c 2011-05-22 19:36:31.000000000 -0400
28764 @@ -36,7 +36,7 @@
28765 struct drm_global_item {
28766 struct mutex mutex;
28767 void *object;
28768 - int refcount;
28769 + atomic_t refcount;
28770 };
28771
28772 static struct drm_global_item glob[DRM_GLOBAL_NUM];
28773 @@ -49,7 +49,7 @@ void drm_global_init(void)
28774 struct drm_global_item *item = &glob[i];
28775 mutex_init(&item->mutex);
28776 item->object = NULL;
28777 - item->refcount = 0;
28778 + atomic_set(&item->refcount, 0);
28779 }
28780 }
28781
28782 @@ -59,7 +59,7 @@ void drm_global_release(void)
28783 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
28784 struct drm_global_item *item = &glob[i];
28785 BUG_ON(item->object != NULL);
28786 - BUG_ON(item->refcount != 0);
28787 + BUG_ON(atomic_read(&item->refcount) != 0);
28788 }
28789 }
28790
28791 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_globa
28792 void *object;
28793
28794 mutex_lock(&item->mutex);
28795 - if (item->refcount == 0) {
28796 + if (atomic_read(&item->refcount) == 0) {
28797 item->object = kzalloc(ref->size, GFP_KERNEL);
28798 if (unlikely(item->object == NULL)) {
28799 ret = -ENOMEM;
28800 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_globa
28801 goto out_err;
28802
28803 }
28804 - ++item->refcount;
28805 + atomic_inc(&item->refcount);
28806 ref->object = item->object;
28807 object = item->object;
28808 mutex_unlock(&item->mutex);
28809 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_gl
28810 struct drm_global_item *item = &glob[ref->global_type];
28811
28812 mutex_lock(&item->mutex);
28813 - BUG_ON(item->refcount == 0);
28814 + BUG_ON(atomic_read(&item->refcount) == 0);
28815 BUG_ON(ref->object != item->object);
28816 - if (--item->refcount == 0) {
28817 + if (atomic_dec_and_test(&item->refcount)) {
28818 ref->release(ref);
28819 item->object = NULL;
28820 }
28821 diff -urNp linux-2.6.39/drivers/gpu/drm/drm_info.c linux-2.6.39/drivers/gpu/drm/drm_info.c
28822 --- linux-2.6.39/drivers/gpu/drm/drm_info.c 2011-05-19 00:06:34.000000000 -0400
28823 +++ linux-2.6.39/drivers/gpu/drm/drm_info.c 2011-05-22 19:41:37.000000000 -0400
28824 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void
28825 struct drm_local_map *map;
28826 struct drm_map_list *r_list;
28827
28828 - /* Hardcoded from _DRM_FRAME_BUFFER,
28829 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
28830 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
28831 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
28832 + static const char * const types[] = {
28833 + [_DRM_FRAME_BUFFER] = "FB",
28834 + [_DRM_REGISTERS] = "REG",
28835 + [_DRM_SHM] = "SHM",
28836 + [_DRM_AGP] = "AGP",
28837 + [_DRM_SCATTER_GATHER] = "SG",
28838 + [_DRM_CONSISTENT] = "PCI",
28839 + [_DRM_GEM] = "GEM" };
28840 const char *type;
28841 int i;
28842
28843 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void
28844 map = r_list->map;
28845 if (!map)
28846 continue;
28847 - if (map->type < 0 || map->type > 5)
28848 + if (map->type >= ARRAY_SIZE(types))
28849 type = "??";
28850 else
28851 type = types[map->type];
28852 @@ -290,7 +294,11 @@ int drm_vma_info(struct seq_file *m, voi
28853 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
28854 vma->vm_flags & VM_LOCKED ? 'l' : '-',
28855 vma->vm_flags & VM_IO ? 'i' : '-',
28856 +#ifdef CONFIG_GRKERNSEC_HIDESYM
28857 + 0);
28858 +#else
28859 vma->vm_pgoff);
28860 +#endif
28861
28862 #if defined(__i386__)
28863 pgprot = pgprot_val(vma->vm_page_prot);
28864 diff -urNp linux-2.6.39/drivers/gpu/drm/drm_ioctl.c linux-2.6.39/drivers/gpu/drm/drm_ioctl.c
28865 --- linux-2.6.39/drivers/gpu/drm/drm_ioctl.c 2011-05-19 00:06:34.000000000 -0400
28866 +++ linux-2.6.39/drivers/gpu/drm/drm_ioctl.c 2011-05-22 19:36:31.000000000 -0400
28867 @@ -256,7 +256,7 @@ int drm_getstats(struct drm_device *dev,
28868 stats->data[i].value =
28869 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
28870 else
28871 - stats->data[i].value = atomic_read(&dev->counts[i]);
28872 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
28873 stats->data[i].type = dev->types[i];
28874 }
28875
28876 diff -urNp linux-2.6.39/drivers/gpu/drm/drm_lock.c linux-2.6.39/drivers/gpu/drm/drm_lock.c
28877 --- linux-2.6.39/drivers/gpu/drm/drm_lock.c 2011-05-19 00:06:34.000000000 -0400
28878 +++ linux-2.6.39/drivers/gpu/drm/drm_lock.c 2011-05-22 19:36:31.000000000 -0400
28879 @@ -89,7 +89,7 @@ int drm_lock(struct drm_device *dev, voi
28880 if (drm_lock_take(&master->lock, lock->context)) {
28881 master->lock.file_priv = file_priv;
28882 master->lock.lock_time = jiffies;
28883 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
28884 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
28885 break; /* Got lock */
28886 }
28887
28888 @@ -160,7 +160,7 @@ int drm_unlock(struct drm_device *dev, v
28889 return -EINVAL;
28890 }
28891
28892 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
28893 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
28894
28895 if (drm_lock_free(&master->lock, lock->context)) {
28896 /* FIXME: Should really bail out here. */
28897 diff -urNp linux-2.6.39/drivers/gpu/drm/i810/i810_dma.c linux-2.6.39/drivers/gpu/drm/i810/i810_dma.c
28898 --- linux-2.6.39/drivers/gpu/drm/i810/i810_dma.c 2011-05-19 00:06:34.000000000 -0400
28899 +++ linux-2.6.39/drivers/gpu/drm/i810/i810_dma.c 2011-05-22 19:36:31.000000000 -0400
28900 @@ -950,8 +950,8 @@ static int i810_dma_vertex(struct drm_de
28901 dma->buflist[vertex->idx],
28902 vertex->discard, vertex->used);
28903
28904 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
28905 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
28906 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
28907 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
28908 sarea_priv->last_enqueue = dev_priv->counter - 1;
28909 sarea_priv->last_dispatch = (int)hw_status[5];
28910
28911 @@ -1111,8 +1111,8 @@ static int i810_dma_mc(struct drm_device
28912 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
28913 mc->last_render);
28914
28915 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
28916 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
28917 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
28918 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
28919 sarea_priv->last_enqueue = dev_priv->counter - 1;
28920 sarea_priv->last_dispatch = (int)hw_status[5];
28921
28922 diff -urNp linux-2.6.39/drivers/gpu/drm/i810/i810_drv.h linux-2.6.39/drivers/gpu/drm/i810/i810_drv.h
28923 --- linux-2.6.39/drivers/gpu/drm/i810/i810_drv.h 2011-05-19 00:06:34.000000000 -0400
28924 +++ linux-2.6.39/drivers/gpu/drm/i810/i810_drv.h 2011-05-22 19:36:31.000000000 -0400
28925 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
28926 int page_flipping;
28927
28928 wait_queue_head_t irq_queue;
28929 - atomic_t irq_received;
28930 - atomic_t irq_emitted;
28931 + atomic_unchecked_t irq_received;
28932 + atomic_unchecked_t irq_emitted;
28933
28934 int front_offset;
28935 } drm_i810_private_t;
28936 diff -urNp linux-2.6.39/drivers/gpu/drm/i915/dvo_ch7017.c linux-2.6.39/drivers/gpu/drm/i915/dvo_ch7017.c
28937 --- linux-2.6.39/drivers/gpu/drm/i915/dvo_ch7017.c 2011-05-19 00:06:34.000000000 -0400
28938 +++ linux-2.6.39/drivers/gpu/drm/i915/dvo_ch7017.c 2011-05-22 19:36:31.000000000 -0400
28939 @@ -390,7 +390,7 @@ static void ch7017_destroy(struct intel_
28940 }
28941 }
28942
28943 -struct intel_dvo_dev_ops ch7017_ops = {
28944 +const struct intel_dvo_dev_ops ch7017_ops = {
28945 .init = ch7017_init,
28946 .detect = ch7017_detect,
28947 .mode_valid = ch7017_mode_valid,
28948 diff -urNp linux-2.6.39/drivers/gpu/drm/i915/dvo_ch7xxx.c linux-2.6.39/drivers/gpu/drm/i915/dvo_ch7xxx.c
28949 --- linux-2.6.39/drivers/gpu/drm/i915/dvo_ch7xxx.c 2011-05-19 00:06:34.000000000 -0400
28950 +++ linux-2.6.39/drivers/gpu/drm/i915/dvo_ch7xxx.c 2011-05-22 19:36:31.000000000 -0400
28951 @@ -320,7 +320,7 @@ static void ch7xxx_destroy(struct intel_
28952 }
28953 }
28954
28955 -struct intel_dvo_dev_ops ch7xxx_ops = {
28956 +const struct intel_dvo_dev_ops ch7xxx_ops = {
28957 .init = ch7xxx_init,
28958 .detect = ch7xxx_detect,
28959 .mode_valid = ch7xxx_mode_valid,
28960 diff -urNp linux-2.6.39/drivers/gpu/drm/i915/dvo.h linux-2.6.39/drivers/gpu/drm/i915/dvo.h
28961 --- linux-2.6.39/drivers/gpu/drm/i915/dvo.h 2011-05-19 00:06:34.000000000 -0400
28962 +++ linux-2.6.39/drivers/gpu/drm/i915/dvo.h 2011-05-22 19:36:31.000000000 -0400
28963 @@ -122,23 +122,23 @@ struct intel_dvo_dev_ops {
28964 *
28965 * \return singly-linked list of modes or NULL if no modes found.
28966 */
28967 - struct drm_display_mode *(*get_modes)(struct intel_dvo_device *dvo);
28968 + struct drm_display_mode *(* const get_modes)(struct intel_dvo_device *dvo);
28969
28970 /**
28971 * Clean up driver-specific bits of the output
28972 */
28973 - void (*destroy) (struct intel_dvo_device *dvo);
28974 + void (* const destroy) (struct intel_dvo_device *dvo);
28975
28976 /**
28977 * Debugging hook to dump device registers to log file
28978 */
28979 - void (*dump_regs)(struct intel_dvo_device *dvo);
28980 + void (* const dump_regs)(struct intel_dvo_device *dvo);
28981 };
28982
28983 -extern struct intel_dvo_dev_ops sil164_ops;
28984 -extern struct intel_dvo_dev_ops ch7xxx_ops;
28985 -extern struct intel_dvo_dev_ops ivch_ops;
28986 -extern struct intel_dvo_dev_ops tfp410_ops;
28987 -extern struct intel_dvo_dev_ops ch7017_ops;
28988 +extern const struct intel_dvo_dev_ops sil164_ops;
28989 +extern const struct intel_dvo_dev_ops ch7xxx_ops;
28990 +extern const struct intel_dvo_dev_ops ivch_ops;
28991 +extern const struct intel_dvo_dev_ops tfp410_ops;
28992 +extern const struct intel_dvo_dev_ops ch7017_ops;
28993
28994 #endif /* _INTEL_DVO_H */
28995 diff -urNp linux-2.6.39/drivers/gpu/drm/i915/dvo_ivch.c linux-2.6.39/drivers/gpu/drm/i915/dvo_ivch.c
28996 --- linux-2.6.39/drivers/gpu/drm/i915/dvo_ivch.c 2011-05-19 00:06:34.000000000 -0400
28997 +++ linux-2.6.39/drivers/gpu/drm/i915/dvo_ivch.c 2011-05-22 19:36:31.000000000 -0400
28998 @@ -410,7 +410,7 @@ static void ivch_destroy(struct intel_dv
28999 }
29000 }
29001
29002 -struct intel_dvo_dev_ops ivch_ops= {
29003 +const struct intel_dvo_dev_ops ivch_ops= {
29004 .init = ivch_init,
29005 .dpms = ivch_dpms,
29006 .mode_valid = ivch_mode_valid,
29007 diff -urNp linux-2.6.39/drivers/gpu/drm/i915/dvo_sil164.c linux-2.6.39/drivers/gpu/drm/i915/dvo_sil164.c
29008 --- linux-2.6.39/drivers/gpu/drm/i915/dvo_sil164.c 2011-05-19 00:06:34.000000000 -0400
29009 +++ linux-2.6.39/drivers/gpu/drm/i915/dvo_sil164.c 2011-05-22 19:36:31.000000000 -0400
29010 @@ -252,7 +252,7 @@ static void sil164_destroy(struct intel_
29011 }
29012 }
29013
29014 -struct intel_dvo_dev_ops sil164_ops = {
29015 +const struct intel_dvo_dev_ops sil164_ops = {
29016 .init = sil164_init,
29017 .detect = sil164_detect,
29018 .mode_valid = sil164_mode_valid,
29019 diff -urNp linux-2.6.39/drivers/gpu/drm/i915/dvo_tfp410.c linux-2.6.39/drivers/gpu/drm/i915/dvo_tfp410.c
29020 --- linux-2.6.39/drivers/gpu/drm/i915/dvo_tfp410.c 2011-05-19 00:06:34.000000000 -0400
29021 +++ linux-2.6.39/drivers/gpu/drm/i915/dvo_tfp410.c 2011-05-22 19:36:31.000000000 -0400
29022 @@ -293,7 +293,7 @@ static void tfp410_destroy(struct intel_
29023 }
29024 }
29025
29026 -struct intel_dvo_dev_ops tfp410_ops = {
29027 +const struct intel_dvo_dev_ops tfp410_ops = {
29028 .init = tfp410_init,
29029 .detect = tfp410_detect,
29030 .mode_valid = tfp410_mode_valid,
29031 diff -urNp linux-2.6.39/drivers/gpu/drm/i915/i915_debugfs.c linux-2.6.39/drivers/gpu/drm/i915/i915_debugfs.c
29032 --- linux-2.6.39/drivers/gpu/drm/i915/i915_debugfs.c 2011-05-19 00:06:34.000000000 -0400
29033 +++ linux-2.6.39/drivers/gpu/drm/i915/i915_debugfs.c 2011-05-22 19:36:31.000000000 -0400
29034 @@ -496,7 +496,7 @@ static int i915_interrupt_info(struct se
29035 I915_READ(GTIMR));
29036 }
29037 seq_printf(m, "Interrupts received: %d\n",
29038 - atomic_read(&dev_priv->irq_received));
29039 + atomic_read_unchecked(&dev_priv->irq_received));
29040 for (i = 0; i < I915_NUM_RINGS; i++) {
29041 if (IS_GEN6(dev)) {
29042 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
29043 diff -urNp linux-2.6.39/drivers/gpu/drm/i915/i915_dma.c linux-2.6.39/drivers/gpu/drm/i915/i915_dma.c
29044 --- linux-2.6.39/drivers/gpu/drm/i915/i915_dma.c 2011-05-19 00:06:34.000000000 -0400
29045 +++ linux-2.6.39/drivers/gpu/drm/i915/i915_dma.c 2011-05-22 19:36:31.000000000 -0400
29046 @@ -1171,7 +1171,7 @@ static bool i915_switcheroo_can_switch(s
29047 bool can_switch;
29048
29049 spin_lock(&dev->count_lock);
29050 - can_switch = (dev->open_count == 0);
29051 + can_switch = (local_read(&dev->open_count) == 0);
29052 spin_unlock(&dev->count_lock);
29053 return can_switch;
29054 }
29055 diff -urNp linux-2.6.39/drivers/gpu/drm/i915/i915_drv.c linux-2.6.39/drivers/gpu/drm/i915/i915_drv.c
29056 --- linux-2.6.39/drivers/gpu/drm/i915/i915_drv.c 2011-05-19 00:06:34.000000000 -0400
29057 +++ linux-2.6.39/drivers/gpu/drm/i915/i915_drv.c 2011-05-22 19:36:31.000000000 -0400
29058 @@ -679,7 +679,7 @@ static const struct dev_pm_ops i915_pm_o
29059 .restore = i915_pm_resume,
29060 };
29061
29062 -static struct vm_operations_struct i915_gem_vm_ops = {
29063 +static const struct vm_operations_struct i915_gem_vm_ops = {
29064 .fault = i915_gem_fault,
29065 .open = drm_gem_vm_open,
29066 .close = drm_gem_vm_close,
29067 diff -urNp linux-2.6.39/drivers/gpu/drm/i915/i915_drv.h linux-2.6.39/drivers/gpu/drm/i915/i915_drv.h
29068 --- linux-2.6.39/drivers/gpu/drm/i915/i915_drv.h 2011-05-19 00:06:34.000000000 -0400
29069 +++ linux-2.6.39/drivers/gpu/drm/i915/i915_drv.h 2011-05-22 19:36:31.000000000 -0400
29070 @@ -287,7 +287,7 @@ typedef struct drm_i915_private {
29071 int current_page;
29072 int page_flipping;
29073
29074 - atomic_t irq_received;
29075 + atomic_unchecked_t irq_received;
29076
29077 /* protects the irq masks */
29078 spinlock_t irq_lock;
29079 @@ -848,7 +848,7 @@ struct drm_i915_gem_object {
29080 * will be page flipped away on the next vblank. When it
29081 * reaches 0, dev_priv->pending_flip_queue will be woken up.
29082 */
29083 - atomic_t pending_flip;
29084 + atomic_unchecked_t pending_flip;
29085 };
29086
29087 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
29088 @@ -1232,7 +1232,7 @@ extern int intel_setup_gmbus(struct drm_
29089 extern void intel_teardown_gmbus(struct drm_device *dev);
29090 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
29091 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
29092 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
29093 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
29094 {
29095 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
29096 }
29097 diff -urNp linux-2.6.39/drivers/gpu/drm/i915/i915_gem_execbuffer.c linux-2.6.39/drivers/gpu/drm/i915/i915_gem_execbuffer.c
29098 --- linux-2.6.39/drivers/gpu/drm/i915/i915_gem_execbuffer.c 2011-05-19 00:06:34.000000000 -0400
29099 +++ linux-2.6.39/drivers/gpu/drm/i915/i915_gem_execbuffer.c 2011-05-22 19:36:31.000000000 -0400
29100 @@ -192,7 +192,7 @@ i915_gem_object_set_to_gpu_domain(struct
29101 i915_gem_release_mmap(obj);
29102
29103 if (obj->base.pending_write_domain)
29104 - cd->flips |= atomic_read(&obj->pending_flip);
29105 + cd->flips |= atomic_read_unchecked(&obj->pending_flip);
29106
29107 /* The actual obj->write_domain will be updated with
29108 * pending_write_domain after we emit the accumulated flush for all
29109 diff -urNp linux-2.6.39/drivers/gpu/drm/i915/i915_irq.c linux-2.6.39/drivers/gpu/drm/i915/i915_irq.c
29110 --- linux-2.6.39/drivers/gpu/drm/i915/i915_irq.c 2011-05-19 00:06:34.000000000 -0400
29111 +++ linux-2.6.39/drivers/gpu/drm/i915/i915_irq.c 2011-05-22 19:36:31.000000000 -0400
29112 @@ -1101,7 +1101,7 @@ irqreturn_t i915_driver_irq_handler(DRM_
29113 int ret = IRQ_NONE, pipe;
29114 bool blc_event = false;
29115
29116 - atomic_inc(&dev_priv->irq_received);
29117 + atomic_inc_unchecked(&dev_priv->irq_received);
29118
29119 if (HAS_PCH_SPLIT(dev))
29120 return ironlake_irq_handler(dev);
29121 @@ -1655,7 +1655,7 @@ void i915_driver_irq_preinstall(struct d
29122 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
29123 int pipe;
29124
29125 - atomic_set(&dev_priv->irq_received, 0);
29126 + atomic_set_unchecked(&dev_priv->irq_received, 0);
29127
29128 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
29129 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
29130 diff -urNp linux-2.6.39/drivers/gpu/drm/i915/intel_display.c linux-2.6.39/drivers/gpu/drm/i915/intel_display.c
29131 --- linux-2.6.39/drivers/gpu/drm/i915/intel_display.c 2011-05-19 00:06:34.000000000 -0400
29132 +++ linux-2.6.39/drivers/gpu/drm/i915/intel_display.c 2011-05-22 19:36:31.000000000 -0400
29133 @@ -2244,7 +2244,7 @@ intel_pipe_set_base(struct drm_crtc *crt
29134
29135 wait_event(dev_priv->pending_flip_queue,
29136 atomic_read(&dev_priv->mm.wedged) ||
29137 - atomic_read(&obj->pending_flip) == 0);
29138 + atomic_read_unchecked(&obj->pending_flip) == 0);
29139
29140 /* Big Hammer, we also need to ensure that any pending
29141 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
29142 @@ -2712,7 +2712,7 @@ static void intel_crtc_wait_for_pending_
29143 obj = to_intel_framebuffer(crtc->fb)->obj;
29144 dev_priv = crtc->dev->dev_private;
29145 wait_event(dev_priv->pending_flip_queue,
29146 - atomic_read(&obj->pending_flip) == 0);
29147 + atomic_read_unchecked(&obj->pending_flip) == 0);
29148 }
29149
29150 static bool intel_crtc_driving_pch(struct drm_crtc *crtc)
29151 @@ -6016,7 +6016,7 @@ static void do_intel_finish_page_flip(st
29152
29153 atomic_clear_mask(1 << intel_crtc->plane,
29154 &obj->pending_flip.counter);
29155 - if (atomic_read(&obj->pending_flip) == 0)
29156 + if (atomic_read_unchecked(&obj->pending_flip) == 0)
29157 wake_up(&dev_priv->pending_flip_queue);
29158
29159 schedule_work(&work->work);
29160 @@ -6145,7 +6145,7 @@ static int intel_crtc_page_flip(struct d
29161 /* Block clients from rendering to the new back buffer until
29162 * the flip occurs and the object is no longer visible.
29163 */
29164 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
29165 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
29166
29167 switch (INTEL_INFO(dev)->gen) {
29168 case 2:
29169 diff -urNp linux-2.6.39/drivers/gpu/drm/mga/mga_drv.h linux-2.6.39/drivers/gpu/drm/mga/mga_drv.h
29170 --- linux-2.6.39/drivers/gpu/drm/mga/mga_drv.h 2011-05-19 00:06:34.000000000 -0400
29171 +++ linux-2.6.39/drivers/gpu/drm/mga/mga_drv.h 2011-05-22 19:36:31.000000000 -0400
29172 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
29173 u32 clear_cmd;
29174 u32 maccess;
29175
29176 - atomic_t vbl_received; /**< Number of vblanks received. */
29177 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
29178 wait_queue_head_t fence_queue;
29179 - atomic_t last_fence_retired;
29180 + atomic_unchecked_t last_fence_retired;
29181 u32 next_fence_to_post;
29182
29183 unsigned int fb_cpp;
29184 diff -urNp linux-2.6.39/drivers/gpu/drm/mga/mga_irq.c linux-2.6.39/drivers/gpu/drm/mga/mga_irq.c
29185 --- linux-2.6.39/drivers/gpu/drm/mga/mga_irq.c 2011-05-19 00:06:34.000000000 -0400
29186 +++ linux-2.6.39/drivers/gpu/drm/mga/mga_irq.c 2011-05-22 19:36:31.000000000 -0400
29187 @@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_de
29188 if (crtc != 0)
29189 return 0;
29190
29191 - return atomic_read(&dev_priv->vbl_received);
29192 + return atomic_read_unchecked(&dev_priv->vbl_received);
29193 }
29194
29195
29196 @@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_I
29197 /* VBLANK interrupt */
29198 if (status & MGA_VLINEPEN) {
29199 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
29200 - atomic_inc(&dev_priv->vbl_received);
29201 + atomic_inc_unchecked(&dev_priv->vbl_received);
29202 drm_handle_vblank(dev, 0);
29203 handled = 1;
29204 }
29205 @@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_I
29206 if ((prim_start & ~0x03) != (prim_end & ~0x03))
29207 MGA_WRITE(MGA_PRIMEND, prim_end);
29208
29209 - atomic_inc(&dev_priv->last_fence_retired);
29210 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
29211 DRM_WAKEUP(&dev_priv->fence_queue);
29212 handled = 1;
29213 }
29214 @@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_dev
29215 * using fences.
29216 */
29217 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
29218 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
29219 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
29220 - *sequence) <= (1 << 23)));
29221
29222 *sequence = cur_fence;
29223 diff -urNp linux-2.6.39/drivers/gpu/drm/nouveau/nouveau_acpi.c linux-2.6.39/drivers/gpu/drm/nouveau/nouveau_acpi.c
29224 --- linux-2.6.39/drivers/gpu/drm/nouveau/nouveau_acpi.c 2011-05-19 00:06:34.000000000 -0400
29225 +++ linux-2.6.39/drivers/gpu/drm/nouveau/nouveau_acpi.c 2011-05-22 19:36:31.000000000 -0400
29226 @@ -141,7 +141,7 @@ static int nouveau_dsm_get_client_id(str
29227 return VGA_SWITCHEROO_DIS;
29228 }
29229
29230 -static struct vga_switcheroo_handler nouveau_dsm_handler = {
29231 +static const struct vga_switcheroo_handler nouveau_dsm_handler = {
29232 .switchto = nouveau_dsm_switchto,
29233 .power_state = nouveau_dsm_power_state,
29234 .init = nouveau_dsm_init,
29235 diff -urNp linux-2.6.39/drivers/gpu/drm/nouveau/nouveau_drv.h linux-2.6.39/drivers/gpu/drm/nouveau/nouveau_drv.h
29236 --- linux-2.6.39/drivers/gpu/drm/nouveau/nouveau_drv.h 2011-05-19 00:06:34.000000000 -0400
29237 +++ linux-2.6.39/drivers/gpu/drm/nouveau/nouveau_drv.h 2011-05-23 17:07:00.000000000 -0400
29238 @@ -228,7 +228,7 @@ struct nouveau_channel {
29239 struct list_head pending;
29240 uint32_t sequence;
29241 uint32_t sequence_ack;
29242 - atomic_t last_sequence_irq;
29243 + atomic_unchecked_t last_sequence_irq;
29244 } fence;
29245
29246 /* DMA push buffer */
29247 @@ -520,8 +520,8 @@ struct nouveau_vram_engine {
29248
29249 struct nouveau_engine {
29250 struct nouveau_instmem_engine instmem;
29251 - struct nouveau_mc_engine mc;
29252 - struct nouveau_timer_engine timer;
29253 + struct nouveau_mc_engine mc;
29254 + struct nouveau_timer_engine timer;
29255 struct nouveau_fb_engine fb;
29256 struct nouveau_pgraph_engine graph;
29257 struct nouveau_fifo_engine fifo;
29258 @@ -529,7 +529,7 @@ struct nouveau_engine {
29259 struct nouveau_gpio_engine gpio;
29260 struct nouveau_pm_engine pm;
29261 struct nouveau_crypt_engine crypt;
29262 - struct nouveau_vram_engine vram;
29263 + struct nouveau_vram_engine vram;
29264 };
29265
29266 struct nouveau_pll_vals {
29267 @@ -662,7 +662,7 @@ struct drm_nouveau_private {
29268 struct drm_global_reference mem_global_ref;
29269 struct ttm_bo_global_ref bo_global_ref;
29270 struct ttm_bo_device bdev;
29271 - atomic_t validate_sequence;
29272 + atomic_unchecked_t validate_sequence;
29273 } ttm;
29274
29275 struct {
29276 diff -urNp linux-2.6.39/drivers/gpu/drm/nouveau/nouveau_fence.c linux-2.6.39/drivers/gpu/drm/nouveau/nouveau_fence.c
29277 --- linux-2.6.39/drivers/gpu/drm/nouveau/nouveau_fence.c 2011-05-19 00:06:34.000000000 -0400
29278 +++ linux-2.6.39/drivers/gpu/drm/nouveau/nouveau_fence.c 2011-05-22 19:36:31.000000000 -0400
29279 @@ -85,7 +85,7 @@ nouveau_fence_update(struct nouveau_chan
29280 if (USE_REFCNT(dev))
29281 sequence = nvchan_rd32(chan, 0x48);
29282 else
29283 - sequence = atomic_read(&chan->fence.last_sequence_irq);
29284 + sequence = atomic_read_unchecked(&chan->fence.last_sequence_irq);
29285
29286 if (chan->fence.sequence_ack == sequence)
29287 goto out;
29288 @@ -553,7 +553,7 @@ nouveau_fence_channel_init(struct nouvea
29289 out_initialised:
29290 INIT_LIST_HEAD(&chan->fence.pending);
29291 spin_lock_init(&chan->fence.lock);
29292 - atomic_set(&chan->fence.last_sequence_irq, 0);
29293 + atomic_set_unchecked(&chan->fence.last_sequence_irq, 0);
29294 return 0;
29295 }
29296
29297 diff -urNp linux-2.6.39/drivers/gpu/drm/nouveau/nouveau_gem.c linux-2.6.39/drivers/gpu/drm/nouveau/nouveau_gem.c
29298 --- linux-2.6.39/drivers/gpu/drm/nouveau/nouveau_gem.c 2011-05-19 00:06:34.000000000 -0400
29299 +++ linux-2.6.39/drivers/gpu/drm/nouveau/nouveau_gem.c 2011-05-22 19:36:31.000000000 -0400
29300 @@ -249,7 +249,7 @@ validate_init(struct nouveau_channel *ch
29301 int trycnt = 0;
29302 int ret, i;
29303
29304 - sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
29305 + sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
29306 retry:
29307 if (++trycnt > 100000) {
29308 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
29309 diff -urNp linux-2.6.39/drivers/gpu/drm/nouveau/nouveau_state.c linux-2.6.39/drivers/gpu/drm/nouveau/nouveau_state.c
29310 --- linux-2.6.39/drivers/gpu/drm/nouveau/nouveau_state.c 2011-05-19 00:06:34.000000000 -0400
29311 +++ linux-2.6.39/drivers/gpu/drm/nouveau/nouveau_state.c 2011-05-22 19:36:31.000000000 -0400
29312 @@ -583,7 +583,7 @@ static bool nouveau_switcheroo_can_switc
29313 bool can_switch;
29314
29315 spin_lock(&dev->count_lock);
29316 - can_switch = (dev->open_count == 0);
29317 + can_switch = (local_read(&dev->open_count) == 0);
29318 spin_unlock(&dev->count_lock);
29319 return can_switch;
29320 }
29321 diff -urNp linux-2.6.39/drivers/gpu/drm/nouveau/nv04_graph.c linux-2.6.39/drivers/gpu/drm/nouveau/nv04_graph.c
29322 --- linux-2.6.39/drivers/gpu/drm/nouveau/nv04_graph.c 2011-05-19 00:06:34.000000000 -0400
29323 +++ linux-2.6.39/drivers/gpu/drm/nouveau/nv04_graph.c 2011-05-22 19:36:31.000000000 -0400
29324 @@ -552,7 +552,7 @@ static int
29325 nv04_graph_mthd_set_ref(struct nouveau_channel *chan,
29326 u32 class, u32 mthd, u32 data)
29327 {
29328 - atomic_set(&chan->fence.last_sequence_irq, data);
29329 + atomic_set_unchecked(&chan->fence.last_sequence_irq, data);
29330 return 0;
29331 }
29332
29333 diff -urNp linux-2.6.39/drivers/gpu/drm/r128/r128_cce.c linux-2.6.39/drivers/gpu/drm/r128/r128_cce.c
29334 --- linux-2.6.39/drivers/gpu/drm/r128/r128_cce.c 2011-05-19 00:06:34.000000000 -0400
29335 +++ linux-2.6.39/drivers/gpu/drm/r128/r128_cce.c 2011-05-22 19:36:31.000000000 -0400
29336 @@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_d
29337
29338 /* GH: Simple idle check.
29339 */
29340 - atomic_set(&dev_priv->idle_count, 0);
29341 + atomic_set_unchecked(&dev_priv->idle_count, 0);
29342
29343 /* We don't support anything other than bus-mastering ring mode,
29344 * but the ring can be in either AGP or PCI space for the ring
29345 diff -urNp linux-2.6.39/drivers/gpu/drm/r128/r128_drv.h linux-2.6.39/drivers/gpu/drm/r128/r128_drv.h
29346 --- linux-2.6.39/drivers/gpu/drm/r128/r128_drv.h 2011-05-19 00:06:34.000000000 -0400
29347 +++ linux-2.6.39/drivers/gpu/drm/r128/r128_drv.h 2011-05-22 19:36:31.000000000 -0400
29348 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
29349 int is_pci;
29350 unsigned long cce_buffers_offset;
29351
29352 - atomic_t idle_count;
29353 + atomic_unchecked_t idle_count;
29354
29355 int page_flipping;
29356 int current_page;
29357 u32 crtc_offset;
29358 u32 crtc_offset_cntl;
29359
29360 - atomic_t vbl_received;
29361 + atomic_unchecked_t vbl_received;
29362
29363 u32 color_fmt;
29364 unsigned int front_offset;
29365 diff -urNp linux-2.6.39/drivers/gpu/drm/r128/r128_irq.c linux-2.6.39/drivers/gpu/drm/r128/r128_irq.c
29366 --- linux-2.6.39/drivers/gpu/drm/r128/r128_irq.c 2011-05-19 00:06:34.000000000 -0400
29367 +++ linux-2.6.39/drivers/gpu/drm/r128/r128_irq.c 2011-05-22 19:36:31.000000000 -0400
29368 @@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_d
29369 if (crtc != 0)
29370 return 0;
29371
29372 - return atomic_read(&dev_priv->vbl_received);
29373 + return atomic_read_unchecked(&dev_priv->vbl_received);
29374 }
29375
29376 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
29377 @@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_
29378 /* VBLANK interrupt */
29379 if (status & R128_CRTC_VBLANK_INT) {
29380 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
29381 - atomic_inc(&dev_priv->vbl_received);
29382 + atomic_inc_unchecked(&dev_priv->vbl_received);
29383 drm_handle_vblank(dev, 0);
29384 return IRQ_HANDLED;
29385 }
29386 diff -urNp linux-2.6.39/drivers/gpu/drm/r128/r128_state.c linux-2.6.39/drivers/gpu/drm/r128/r128_state.c
29387 --- linux-2.6.39/drivers/gpu/drm/r128/r128_state.c 2011-05-19 00:06:34.000000000 -0400
29388 +++ linux-2.6.39/drivers/gpu/drm/r128/r128_state.c 2011-05-22 19:36:31.000000000 -0400
29389 @@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_priv
29390
29391 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
29392 {
29393 - if (atomic_read(&dev_priv->idle_count) == 0)
29394 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
29395 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
29396 else
29397 - atomic_set(&dev_priv->idle_count, 0);
29398 + atomic_set_unchecked(&dev_priv->idle_count, 0);
29399 }
29400
29401 #endif
29402 diff -urNp linux-2.6.39/drivers/gpu/drm/radeon/atom.c linux-2.6.39/drivers/gpu/drm/radeon/atom.c
29403 --- linux-2.6.39/drivers/gpu/drm/radeon/atom.c 2011-05-19 00:06:34.000000000 -0400
29404 +++ linux-2.6.39/drivers/gpu/drm/radeon/atom.c 2011-05-22 19:36:31.000000000 -0400
29405 @@ -1245,6 +1245,8 @@ struct atom_context *atom_parse(struct c
29406 char name[512];
29407 int i;
29408
29409 + pax_track_stack();
29410 +
29411 ctx->card = card;
29412 ctx->bios = bios;
29413
29414 diff -urNp linux-2.6.39/drivers/gpu/drm/radeon/mkregtable.c linux-2.6.39/drivers/gpu/drm/radeon/mkregtable.c
29415 --- linux-2.6.39/drivers/gpu/drm/radeon/mkregtable.c 2011-05-19 00:06:34.000000000 -0400
29416 +++ linux-2.6.39/drivers/gpu/drm/radeon/mkregtable.c 2011-05-22 19:36:31.000000000 -0400
29417 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t,
29418 regex_t mask_rex;
29419 regmatch_t match[4];
29420 char buf[1024];
29421 - size_t end;
29422 + long end;
29423 int len;
29424 int done = 0;
29425 int r;
29426 unsigned o;
29427 struct offset *offset;
29428 char last_reg_s[10];
29429 - int last_reg;
29430 + unsigned long last_reg;
29431
29432 if (regcomp
29433 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
29434 diff -urNp linux-2.6.39/drivers/gpu/drm/radeon/radeon_atombios.c linux-2.6.39/drivers/gpu/drm/radeon/radeon_atombios.c
29435 --- linux-2.6.39/drivers/gpu/drm/radeon/radeon_atombios.c 2011-05-19 00:06:34.000000000 -0400
29436 +++ linux-2.6.39/drivers/gpu/drm/radeon/radeon_atombios.c 2011-05-22 19:36:31.000000000 -0400
29437 @@ -545,6 +545,8 @@ bool radeon_get_atom_connector_info_from
29438 struct radeon_gpio_rec gpio;
29439 struct radeon_hpd hpd;
29440
29441 + pax_track_stack();
29442 +
29443 if (!atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset))
29444 return false;
29445
29446 diff -urNp linux-2.6.39/drivers/gpu/drm/radeon/radeon_atpx_handler.c linux-2.6.39/drivers/gpu/drm/radeon/radeon_atpx_handler.c
29447 --- linux-2.6.39/drivers/gpu/drm/radeon/radeon_atpx_handler.c 2011-05-19 00:06:34.000000000 -0400
29448 +++ linux-2.6.39/drivers/gpu/drm/radeon/radeon_atpx_handler.c 2011-05-22 19:36:31.000000000 -0400
29449 @@ -234,7 +234,7 @@ static int radeon_atpx_get_client_id(str
29450 return VGA_SWITCHEROO_DIS;
29451 }
29452
29453 -static struct vga_switcheroo_handler radeon_atpx_handler = {
29454 +static const struct vga_switcheroo_handler radeon_atpx_handler = {
29455 .switchto = radeon_atpx_switchto,
29456 .power_state = radeon_atpx_power_state,
29457 .init = radeon_atpx_init,
29458 diff -urNp linux-2.6.39/drivers/gpu/drm/radeon/radeon_device.c linux-2.6.39/drivers/gpu/drm/radeon/radeon_device.c
29459 --- linux-2.6.39/drivers/gpu/drm/radeon/radeon_device.c 2011-05-19 00:06:34.000000000 -0400
29460 +++ linux-2.6.39/drivers/gpu/drm/radeon/radeon_device.c 2011-05-22 19:36:31.000000000 -0400
29461 @@ -674,7 +674,7 @@ static bool radeon_switcheroo_can_switch
29462 bool can_switch;
29463
29464 spin_lock(&dev->count_lock);
29465 - can_switch = (dev->open_count == 0);
29466 + can_switch = (local_read(&dev->open_count) == 0);
29467 spin_unlock(&dev->count_lock);
29468 return can_switch;
29469 }
29470 diff -urNp linux-2.6.39/drivers/gpu/drm/radeon/radeon_display.c linux-2.6.39/drivers/gpu/drm/radeon/radeon_display.c
29471 --- linux-2.6.39/drivers/gpu/drm/radeon/radeon_display.c 2011-05-19 00:06:34.000000000 -0400
29472 +++ linux-2.6.39/drivers/gpu/drm/radeon/radeon_display.c 2011-05-22 19:36:31.000000000 -0400
29473 @@ -934,6 +934,8 @@ void radeon_compute_pll_legacy(struct ra
29474 uint32_t post_div;
29475 u32 pll_out_min, pll_out_max;
29476
29477 + pax_track_stack();
29478 +
29479 DRM_DEBUG_KMS("PLL freq %llu %u %u\n", freq, pll->min_ref_div, pll->max_ref_div);
29480 freq = freq * 1000;
29481
29482 diff -urNp linux-2.6.39/drivers/gpu/drm/radeon/radeon_drv.h linux-2.6.39/drivers/gpu/drm/radeon/radeon_drv.h
29483 --- linux-2.6.39/drivers/gpu/drm/radeon/radeon_drv.h 2011-05-19 00:06:34.000000000 -0400
29484 +++ linux-2.6.39/drivers/gpu/drm/radeon/radeon_drv.h 2011-05-22 19:36:31.000000000 -0400
29485 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
29486
29487 /* SW interrupt */
29488 wait_queue_head_t swi_queue;
29489 - atomic_t swi_emitted;
29490 + atomic_unchecked_t swi_emitted;
29491 int vblank_crtc;
29492 uint32_t irq_enable_reg;
29493 uint32_t r500_disp_irq_reg;
29494 diff -urNp linux-2.6.39/drivers/gpu/drm/radeon/radeon_fence.c linux-2.6.39/drivers/gpu/drm/radeon/radeon_fence.c
29495 --- linux-2.6.39/drivers/gpu/drm/radeon/radeon_fence.c 2011-05-19 00:06:34.000000000 -0400
29496 +++ linux-2.6.39/drivers/gpu/drm/radeon/radeon_fence.c 2011-05-22 19:36:31.000000000 -0400
29497 @@ -49,7 +49,7 @@ int radeon_fence_emit(struct radeon_devi
29498 write_unlock_irqrestore(&rdev->fence_drv.lock, irq_flags);
29499 return 0;
29500 }
29501 - fence->seq = atomic_add_return(1, &rdev->fence_drv.seq);
29502 + fence->seq = atomic_add_return_unchecked(1, &rdev->fence_drv.seq);
29503 if (!rdev->cp.ready) {
29504 /* FIXME: cp is not running assume everythings is done right
29505 * away
29506 @@ -352,7 +352,7 @@ int radeon_fence_driver_init(struct rade
29507 return r;
29508 }
29509 WREG32(rdev->fence_drv.scratch_reg, 0);
29510 - atomic_set(&rdev->fence_drv.seq, 0);
29511 + atomic_set_unchecked(&rdev->fence_drv.seq, 0);
29512 INIT_LIST_HEAD(&rdev->fence_drv.created);
29513 INIT_LIST_HEAD(&rdev->fence_drv.emited);
29514 INIT_LIST_HEAD(&rdev->fence_drv.signaled);
29515 diff -urNp linux-2.6.39/drivers/gpu/drm/radeon/radeon.h linux-2.6.39/drivers/gpu/drm/radeon/radeon.h
29516 --- linux-2.6.39/drivers/gpu/drm/radeon/radeon.h 2011-05-19 00:06:34.000000000 -0400
29517 +++ linux-2.6.39/drivers/gpu/drm/radeon/radeon.h 2011-05-22 19:36:31.000000000 -0400
29518 @@ -189,7 +189,7 @@ extern int sumo_get_temp(struct radeon_d
29519 */
29520 struct radeon_fence_driver {
29521 uint32_t scratch_reg;
29522 - atomic_t seq;
29523 + atomic_unchecked_t seq;
29524 uint32_t last_seq;
29525 unsigned long last_jiffies;
29526 unsigned long last_timeout;
29527 diff -urNp linux-2.6.39/drivers/gpu/drm/radeon/radeon_ioc32.c linux-2.6.39/drivers/gpu/drm/radeon/radeon_ioc32.c
29528 --- linux-2.6.39/drivers/gpu/drm/radeon/radeon_ioc32.c 2011-05-19 00:06:34.000000000 -0400
29529 +++ linux-2.6.39/drivers/gpu/drm/radeon/radeon_ioc32.c 2011-05-22 19:36:31.000000000 -0400
29530 @@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(str
29531 request = compat_alloc_user_space(sizeof(*request));
29532 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
29533 || __put_user(req32.param, &request->param)
29534 - || __put_user((void __user *)(unsigned long)req32.value,
29535 + || __put_user((unsigned long)req32.value,
29536 &request->value))
29537 return -EFAULT;
29538
29539 diff -urNp linux-2.6.39/drivers/gpu/drm/radeon/radeon_irq.c linux-2.6.39/drivers/gpu/drm/radeon/radeon_irq.c
29540 --- linux-2.6.39/drivers/gpu/drm/radeon/radeon_irq.c 2011-05-19 00:06:34.000000000 -0400
29541 +++ linux-2.6.39/drivers/gpu/drm/radeon/radeon_irq.c 2011-05-22 19:36:31.000000000 -0400
29542 @@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_de
29543 unsigned int ret;
29544 RING_LOCALS;
29545
29546 - atomic_inc(&dev_priv->swi_emitted);
29547 - ret = atomic_read(&dev_priv->swi_emitted);
29548 + atomic_inc_unchecked(&dev_priv->swi_emitted);
29549 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
29550
29551 BEGIN_RING(4);
29552 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
29553 @@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct
29554 drm_radeon_private_t *dev_priv =
29555 (drm_radeon_private_t *) dev->dev_private;
29556
29557 - atomic_set(&dev_priv->swi_emitted, 0);
29558 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
29559 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
29560
29561 dev->max_vblank_count = 0x001fffff;
29562 diff -urNp linux-2.6.39/drivers/gpu/drm/radeon/radeon_state.c linux-2.6.39/drivers/gpu/drm/radeon/radeon_state.c
29563 --- linux-2.6.39/drivers/gpu/drm/radeon/radeon_state.c 2011-05-19 00:06:34.000000000 -0400
29564 +++ linux-2.6.39/drivers/gpu/drm/radeon/radeon_state.c 2011-05-22 19:36:31.000000000 -0400
29565 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_de
29566 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
29567 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
29568
29569 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
29570 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
29571 sarea_priv->nbox * sizeof(depth_boxes[0])))
29572 return -EFAULT;
29573
29574 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm
29575 {
29576 drm_radeon_private_t *dev_priv = dev->dev_private;
29577 drm_radeon_getparam_t *param = data;
29578 - int value;
29579 + int value = 0;
29580
29581 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
29582
29583 diff -urNp linux-2.6.39/drivers/gpu/drm/radeon/radeon_ttm.c linux-2.6.39/drivers/gpu/drm/radeon/radeon_ttm.c
29584 --- linux-2.6.39/drivers/gpu/drm/radeon/radeon_ttm.c 2011-05-19 00:06:34.000000000 -0400
29585 +++ linux-2.6.39/drivers/gpu/drm/radeon/radeon_ttm.c 2011-05-22 19:36:31.000000000 -0400
29586 @@ -603,8 +603,9 @@ void radeon_ttm_set_active_vram_size(str
29587 man->size = size >> PAGE_SHIFT;
29588 }
29589
29590 -static struct vm_operations_struct radeon_ttm_vm_ops;
29591 -static const struct vm_operations_struct *ttm_vm_ops = NULL;
29592 +extern int ttm_bo_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf);
29593 +extern void ttm_bo_vm_open(struct vm_area_struct *vma);
29594 +extern void ttm_bo_vm_close(struct vm_area_struct *vma);
29595
29596 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
29597 {
29598 @@ -612,17 +613,22 @@ static int radeon_ttm_fault(struct vm_ar
29599 struct radeon_device *rdev;
29600 int r;
29601
29602 - bo = (struct ttm_buffer_object *)vma->vm_private_data;
29603 - if (bo == NULL) {
29604 + bo = (struct ttm_buffer_object *)vma->vm_private_data;
29605 + if (!bo)
29606 return VM_FAULT_NOPAGE;
29607 - }
29608 rdev = radeon_get_rdev(bo->bdev);
29609 mutex_lock(&rdev->vram_mutex);
29610 - r = ttm_vm_ops->fault(vma, vmf);
29611 + r = ttm_bo_vm_fault(vma, vmf);
29612 mutex_unlock(&rdev->vram_mutex);
29613 return r;
29614 }
29615
29616 +static const struct vm_operations_struct radeon_ttm_vm_ops = {
29617 + .fault = radeon_ttm_fault,
29618 + .open = ttm_bo_vm_open,
29619 + .close = ttm_bo_vm_close
29620 +};
29621 +
29622 int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
29623 {
29624 struct drm_file *file_priv;
29625 @@ -635,18 +641,11 @@ int radeon_mmap(struct file *filp, struc
29626
29627 file_priv = filp->private_data;
29628 rdev = file_priv->minor->dev->dev_private;
29629 - if (rdev == NULL) {
29630 + if (!rdev)
29631 return -EINVAL;
29632 - }
29633 r = ttm_bo_mmap(filp, vma, &rdev->mman.bdev);
29634 - if (unlikely(r != 0)) {
29635 + if (r)
29636 return r;
29637 - }
29638 - if (unlikely(ttm_vm_ops == NULL)) {
29639 - ttm_vm_ops = vma->vm_ops;
29640 - radeon_ttm_vm_ops = *ttm_vm_ops;
29641 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
29642 - }
29643 vma->vm_ops = &radeon_ttm_vm_ops;
29644 return 0;
29645 }
29646 diff -urNp linux-2.6.39/drivers/gpu/drm/radeon/rs690.c linux-2.6.39/drivers/gpu/drm/radeon/rs690.c
29647 --- linux-2.6.39/drivers/gpu/drm/radeon/rs690.c 2011-05-19 00:06:34.000000000 -0400
29648 +++ linux-2.6.39/drivers/gpu/drm/radeon/rs690.c 2011-05-22 19:36:31.000000000 -0400
29649 @@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct
29650 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
29651 rdev->pm.sideport_bandwidth.full)
29652 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
29653 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
29654 + read_delay_latency.full = dfixed_const(800 * 1000);
29655 read_delay_latency.full = dfixed_div(read_delay_latency,
29656 rdev->pm.igp_sideport_mclk);
29657 + a.full = dfixed_const(370);
29658 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
29659 } else {
29660 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
29661 rdev->pm.k8_bandwidth.full)
29662 diff -urNp linux-2.6.39/drivers/gpu/drm/ttm/ttm_bo_vm.c linux-2.6.39/drivers/gpu/drm/ttm/ttm_bo_vm.c
29663 --- linux-2.6.39/drivers/gpu/drm/ttm/ttm_bo_vm.c 2011-05-19 00:06:34.000000000 -0400
29664 +++ linux-2.6.39/drivers/gpu/drm/ttm/ttm_bo_vm.c 2011-05-22 19:36:31.000000000 -0400
29665 @@ -69,11 +69,11 @@ static struct ttm_buffer_object *ttm_bo_
29666 return best_bo;
29667 }
29668
29669 -static int ttm_bo_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
29670 +int ttm_bo_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
29671 {
29672 struct ttm_buffer_object *bo = (struct ttm_buffer_object *)
29673 vma->vm_private_data;
29674 - struct ttm_bo_device *bdev = bo->bdev;
29675 + struct ttm_bo_device *bdev;
29676 unsigned long page_offset;
29677 unsigned long page_last;
29678 unsigned long pfn;
29679 @@ -83,8 +83,12 @@ static int ttm_bo_vm_fault(struct vm_are
29680 int i;
29681 unsigned long address = (unsigned long)vmf->virtual_address;
29682 int retval = VM_FAULT_NOPAGE;
29683 - struct ttm_mem_type_manager *man =
29684 - &bdev->man[bo->mem.mem_type];
29685 + struct ttm_mem_type_manager *man;
29686 +
29687 + if (!bo)
29688 + return VM_FAULT_NOPAGE;
29689 + bdev = bo->bdev;
29690 + man = &bdev->man[bo->mem.mem_type];
29691
29692 /*
29693 * Work around locking order reversal in fault / nopfn
29694 @@ -219,22 +223,25 @@ out_unlock:
29695 ttm_bo_unreserve(bo);
29696 return retval;
29697 }
29698 +EXPORT_SYMBOL(ttm_bo_vm_fault);
29699
29700 -static void ttm_bo_vm_open(struct vm_area_struct *vma)
29701 +void ttm_bo_vm_open(struct vm_area_struct *vma)
29702 {
29703 struct ttm_buffer_object *bo =
29704 (struct ttm_buffer_object *)vma->vm_private_data;
29705
29706 (void)ttm_bo_reference(bo);
29707 }
29708 +EXPORT_SYMBOL(ttm_bo_vm_open);
29709
29710 -static void ttm_bo_vm_close(struct vm_area_struct *vma)
29711 +void ttm_bo_vm_close(struct vm_area_struct *vma)
29712 {
29713 struct ttm_buffer_object *bo = (struct ttm_buffer_object *)vma->vm_private_data;
29714
29715 ttm_bo_unref(&bo);
29716 vma->vm_private_data = NULL;
29717 }
29718 +EXPORT_SYMBOL(ttm_bo_vm_close);
29719
29720 static const struct vm_operations_struct ttm_bo_vm_ops = {
29721 .fault = ttm_bo_vm_fault,
29722 diff -urNp linux-2.6.39/drivers/gpu/drm/ttm/ttm_page_alloc.c linux-2.6.39/drivers/gpu/drm/ttm/ttm_page_alloc.c
29723 --- linux-2.6.39/drivers/gpu/drm/ttm/ttm_page_alloc.c 2011-05-19 00:06:34.000000000 -0400
29724 +++ linux-2.6.39/drivers/gpu/drm/ttm/ttm_page_alloc.c 2011-05-22 19:36:31.000000000 -0400
29725 @@ -397,9 +397,9 @@ static int ttm_pool_get_num_unused_pages
29726 */
29727 static int ttm_pool_mm_shrink(struct shrinker *shrink, int shrink_pages, gfp_t gfp_mask)
29728 {
29729 - static atomic_t start_pool = ATOMIC_INIT(0);
29730 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
29731 unsigned i;
29732 - unsigned pool_offset = atomic_add_return(1, &start_pool);
29733 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
29734 struct ttm_page_pool *pool;
29735
29736 pool_offset = pool_offset % NUM_POOLS;
29737 diff -urNp linux-2.6.39/drivers/gpu/drm/via/via_drv.h linux-2.6.39/drivers/gpu/drm/via/via_drv.h
29738 --- linux-2.6.39/drivers/gpu/drm/via/via_drv.h 2011-05-19 00:06:34.000000000 -0400
29739 +++ linux-2.6.39/drivers/gpu/drm/via/via_drv.h 2011-05-22 19:36:31.000000000 -0400
29740 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
29741 typedef uint32_t maskarray_t[5];
29742
29743 typedef struct drm_via_irq {
29744 - atomic_t irq_received;
29745 + atomic_unchecked_t irq_received;
29746 uint32_t pending_mask;
29747 uint32_t enable_mask;
29748 wait_queue_head_t irq_queue;
29749 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
29750 struct timeval last_vblank;
29751 int last_vblank_valid;
29752 unsigned usec_per_vblank;
29753 - atomic_t vbl_received;
29754 + atomic_unchecked_t vbl_received;
29755 drm_via_state_t hc_state;
29756 char pci_buf[VIA_PCI_BUF_SIZE];
29757 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
29758 diff -urNp linux-2.6.39/drivers/gpu/drm/via/via_irq.c linux-2.6.39/drivers/gpu/drm/via/via_irq.c
29759 --- linux-2.6.39/drivers/gpu/drm/via/via_irq.c 2011-05-19 00:06:34.000000000 -0400
29760 +++ linux-2.6.39/drivers/gpu/drm/via/via_irq.c 2011-05-22 19:36:31.000000000 -0400
29761 @@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_de
29762 if (crtc != 0)
29763 return 0;
29764
29765 - return atomic_read(&dev_priv->vbl_received);
29766 + return atomic_read_unchecked(&dev_priv->vbl_received);
29767 }
29768
29769 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
29770 @@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_I
29771
29772 status = VIA_READ(VIA_REG_INTERRUPT);
29773 if (status & VIA_IRQ_VBLANK_PENDING) {
29774 - atomic_inc(&dev_priv->vbl_received);
29775 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
29776 + atomic_inc_unchecked(&dev_priv->vbl_received);
29777 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
29778 do_gettimeofday(&cur_vblank);
29779 if (dev_priv->last_vblank_valid) {
29780 dev_priv->usec_per_vblank =
29781 @@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_I
29782 dev_priv->last_vblank = cur_vblank;
29783 dev_priv->last_vblank_valid = 1;
29784 }
29785 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
29786 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
29787 DRM_DEBUG("US per vblank is: %u\n",
29788 dev_priv->usec_per_vblank);
29789 }
29790 @@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_I
29791
29792 for (i = 0; i < dev_priv->num_irqs; ++i) {
29793 if (status & cur_irq->pending_mask) {
29794 - atomic_inc(&cur_irq->irq_received);
29795 + atomic_inc_unchecked(&cur_irq->irq_received);
29796 DRM_WAKEUP(&cur_irq->irq_queue);
29797 handled = 1;
29798 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
29799 @@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *d
29800 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
29801 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
29802 masks[irq][4]));
29803 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
29804 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
29805 } else {
29806 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
29807 (((cur_irq_sequence =
29808 - atomic_read(&cur_irq->irq_received)) -
29809 + atomic_read_unchecked(&cur_irq->irq_received)) -
29810 *sequence) <= (1 << 23)));
29811 }
29812 *sequence = cur_irq_sequence;
29813 @@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct dr
29814 }
29815
29816 for (i = 0; i < dev_priv->num_irqs; ++i) {
29817 - atomic_set(&cur_irq->irq_received, 0);
29818 + atomic_set_unchecked(&cur_irq->irq_received, 0);
29819 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
29820 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
29821 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
29822 @@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev,
29823 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
29824 case VIA_IRQ_RELATIVE:
29825 irqwait->request.sequence +=
29826 - atomic_read(&cur_irq->irq_received);
29827 + atomic_read_unchecked(&cur_irq->irq_received);
29828 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
29829 case VIA_IRQ_ABSOLUTE:
29830 break;
29831 diff -urNp linux-2.6.39/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h linux-2.6.39/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
29832 --- linux-2.6.39/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h 2011-05-19 00:06:34.000000000 -0400
29833 +++ linux-2.6.39/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h 2011-05-22 19:36:31.000000000 -0400
29834 @@ -240,7 +240,7 @@ struct vmw_private {
29835 * Fencing and IRQs.
29836 */
29837
29838 - atomic_t fence_seq;
29839 + atomic_unchecked_t fence_seq;
29840 wait_queue_head_t fence_queue;
29841 wait_queue_head_t fifo_queue;
29842 atomic_t fence_queue_waiters;
29843 diff -urNp linux-2.6.39/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c linux-2.6.39/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c
29844 --- linux-2.6.39/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c 2011-05-19 00:06:34.000000000 -0400
29845 +++ linux-2.6.39/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c 2011-05-22 19:36:31.000000000 -0400
29846 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev
29847 while (!vmw_lag_lt(queue, us)) {
29848 spin_lock(&queue->lock);
29849 if (list_empty(&queue->head))
29850 - sequence = atomic_read(&dev_priv->fence_seq);
29851 + sequence = atomic_read_unchecked(&dev_priv->fence_seq);
29852 else {
29853 fence = list_first_entry(&queue->head,
29854 struct vmw_fence, head);
29855 diff -urNp linux-2.6.39/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c linux-2.6.39/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
29856 --- linux-2.6.39/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c 2011-05-19 00:06:34.000000000 -0400
29857 +++ linux-2.6.39/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c 2011-05-22 19:36:31.000000000 -0400
29858 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *de
29859 (unsigned int) min,
29860 (unsigned int) fifo->capabilities);
29861
29862 - atomic_set(&dev_priv->fence_seq, dev_priv->last_read_sequence);
29863 + atomic_set_unchecked(&dev_priv->fence_seq, dev_priv->last_read_sequence);
29864 iowrite32(dev_priv->last_read_sequence, fifo_mem + SVGA_FIFO_FENCE);
29865 vmw_fence_queue_init(&fifo->fence_queue);
29866 return vmw_fifo_send_fence(dev_priv, &dummy);
29867 @@ -476,7 +476,7 @@ int vmw_fifo_send_fence(struct vmw_priva
29868
29869 fm = vmw_fifo_reserve(dev_priv, bytes);
29870 if (unlikely(fm == NULL)) {
29871 - *sequence = atomic_read(&dev_priv->fence_seq);
29872 + *sequence = atomic_read_unchecked(&dev_priv->fence_seq);
29873 ret = -ENOMEM;
29874 (void)vmw_fallback_wait(dev_priv, false, true, *sequence,
29875 false, 3*HZ);
29876 @@ -484,7 +484,7 @@ int vmw_fifo_send_fence(struct vmw_priva
29877 }
29878
29879 do {
29880 - *sequence = atomic_add_return(1, &dev_priv->fence_seq);
29881 + *sequence = atomic_add_return_unchecked(1, &dev_priv->fence_seq);
29882 } while (*sequence == 0);
29883
29884 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
29885 @@ -534,7 +534,7 @@ static int vmw_fifo_vm_fault(struct vm_a
29886 return VM_FAULT_SIGBUS;
29887 }
29888
29889 -static struct vm_operations_struct vmw_fifo_vm_ops = {
29890 +static const struct vm_operations_struct vmw_fifo_vm_ops = {
29891 .fault = vmw_fifo_vm_fault,
29892 .open = NULL,
29893 .close = NULL
29894 diff -urNp linux-2.6.39/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c linux-2.6.39/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
29895 --- linux-2.6.39/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c 2011-05-19 00:06:34.000000000 -0400
29896 +++ linux-2.6.39/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c 2011-05-22 19:36:31.000000000 -0400
29897 @@ -100,7 +100,7 @@ bool vmw_fence_signaled(struct vmw_priva
29898 * emitted. Then the fence is stale and signaled.
29899 */
29900
29901 - ret = ((atomic_read(&dev_priv->fence_seq) - sequence)
29902 + ret = ((atomic_read_unchecked(&dev_priv->fence_seq) - sequence)
29903 > VMW_FENCE_WRAP);
29904
29905 return ret;
29906 @@ -131,7 +131,7 @@ int vmw_fallback_wait(struct vmw_private
29907
29908 if (fifo_idle)
29909 down_read(&fifo_state->rwsem);
29910 - signal_seq = atomic_read(&dev_priv->fence_seq);
29911 + signal_seq = atomic_read_unchecked(&dev_priv->fence_seq);
29912 ret = 0;
29913
29914 for (;;) {
29915 diff -urNp linux-2.6.39/drivers/gpu/vga/vga_switcheroo.c linux-2.6.39/drivers/gpu/vga/vga_switcheroo.c
29916 --- linux-2.6.39/drivers/gpu/vga/vga_switcheroo.c 2011-05-19 00:06:34.000000000 -0400
29917 +++ linux-2.6.39/drivers/gpu/vga/vga_switcheroo.c 2011-05-22 19:36:31.000000000 -0400
29918 @@ -53,7 +53,7 @@ struct vgasr_priv {
29919 int registered_clients;
29920 struct vga_switcheroo_client clients[VGA_SWITCHEROO_MAX_CLIENTS];
29921
29922 - struct vga_switcheroo_handler *handler;
29923 + const struct vga_switcheroo_handler *handler;
29924 };
29925
29926 static int vga_switcheroo_debugfs_init(struct vgasr_priv *priv);
29927 @@ -62,7 +62,7 @@ static void vga_switcheroo_debugfs_fini(
29928 /* only one switcheroo per system */
29929 static struct vgasr_priv vgasr_priv;
29930
29931 -int vga_switcheroo_register_handler(struct vga_switcheroo_handler *handler)
29932 +int vga_switcheroo_register_handler(const struct vga_switcheroo_handler *handler)
29933 {
29934 mutex_lock(&vgasr_mutex);
29935 if (vgasr_priv.handler) {
29936 diff -urNp linux-2.6.39/drivers/hid/hid-core.c linux-2.6.39/drivers/hid/hid-core.c
29937 --- linux-2.6.39/drivers/hid/hid-core.c 2011-05-19 00:06:34.000000000 -0400
29938 +++ linux-2.6.39/drivers/hid/hid-core.c 2011-05-22 19:36:31.000000000 -0400
29939 @@ -1888,7 +1888,7 @@ static bool hid_ignore(struct hid_device
29940
29941 int hid_add_device(struct hid_device *hdev)
29942 {
29943 - static atomic_t id = ATOMIC_INIT(0);
29944 + static atomic_unchecked_t id = ATOMIC_INIT(0);
29945 int ret;
29946
29947 if (WARN_ON(hdev->status & HID_STAT_ADDED))
29948 @@ -1903,7 +1903,7 @@ int hid_add_device(struct hid_device *hd
29949 /* XXX hack, any other cleaner solution after the driver core
29950 * is converted to allow more than 20 bytes as the device name? */
29951 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
29952 - hdev->vendor, hdev->product, atomic_inc_return(&id));
29953 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
29954
29955 hid_debug_register(hdev, dev_name(&hdev->dev));
29956 ret = device_add(&hdev->dev);
29957 diff -urNp linux-2.6.39/drivers/hid/hid-picolcd.c linux-2.6.39/drivers/hid/hid-picolcd.c
29958 --- linux-2.6.39/drivers/hid/hid-picolcd.c 2011-05-19 00:06:34.000000000 -0400
29959 +++ linux-2.6.39/drivers/hid/hid-picolcd.c 2011-05-22 19:36:31.000000000 -0400
29960 @@ -1037,7 +1037,7 @@ static int picolcd_check_lcd_fb(struct l
29961 return fb && fb == picolcd_fbinfo((struct picolcd_data *)lcd_get_data(ldev));
29962 }
29963
29964 -static struct lcd_ops picolcd_lcdops = {
29965 +static const struct lcd_ops picolcd_lcdops = {
29966 .get_contrast = picolcd_get_contrast,
29967 .set_contrast = picolcd_set_contrast,
29968 .check_fb = picolcd_check_lcd_fb,
29969 diff -urNp linux-2.6.39/drivers/hid/usbhid/hiddev.c linux-2.6.39/drivers/hid/usbhid/hiddev.c
29970 --- linux-2.6.39/drivers/hid/usbhid/hiddev.c 2011-05-19 00:06:34.000000000 -0400
29971 +++ linux-2.6.39/drivers/hid/usbhid/hiddev.c 2011-05-22 19:36:31.000000000 -0400
29972 @@ -613,7 +613,7 @@ static long hiddev_ioctl(struct file *fi
29973 break;
29974
29975 case HIDIOCAPPLICATION:
29976 - if (arg < 0 || arg >= hid->maxapplication)
29977 + if (arg >= hid->maxapplication)
29978 break;
29979
29980 for (i = 0; i < hid->maxcollection; i++)
29981 diff -urNp linux-2.6.39/drivers/hwmon/ibmaem.c linux-2.6.39/drivers/hwmon/ibmaem.c
29982 --- linux-2.6.39/drivers/hwmon/ibmaem.c 2011-05-19 00:06:34.000000000 -0400
29983 +++ linux-2.6.39/drivers/hwmon/ibmaem.c 2011-05-22 19:36:31.000000000 -0400
29984 @@ -238,7 +238,7 @@ struct aem_read_sensor_resp {
29985 struct aem_driver_data {
29986 struct list_head aem_devices;
29987 struct ipmi_smi_watcher bmc_events;
29988 - struct ipmi_user_hndl ipmi_hndlrs;
29989 + const struct ipmi_user_hndl ipmi_hndlrs;
29990 };
29991
29992 static void aem_register_bmc(int iface, struct device *dev);
29993 diff -urNp linux-2.6.39/drivers/hwmon/ibmpex.c linux-2.6.39/drivers/hwmon/ibmpex.c
29994 --- linux-2.6.39/drivers/hwmon/ibmpex.c 2011-05-19 00:06:34.000000000 -0400
29995 +++ linux-2.6.39/drivers/hwmon/ibmpex.c 2011-05-22 19:36:31.000000000 -0400
29996 @@ -110,7 +110,7 @@ struct ibmpex_bmc_data {
29997 struct ibmpex_driver_data {
29998 struct list_head bmc_data;
29999 struct ipmi_smi_watcher bmc_events;
30000 - struct ipmi_user_hndl ipmi_hndlrs;
30001 + const struct ipmi_user_hndl ipmi_hndlrs;
30002 };
30003
30004 static struct ibmpex_driver_data driver_data = {
30005 diff -urNp linux-2.6.39/drivers/hwmon/sht15.c linux-2.6.39/drivers/hwmon/sht15.c
30006 --- linux-2.6.39/drivers/hwmon/sht15.c 2011-05-19 00:06:34.000000000 -0400
30007 +++ linux-2.6.39/drivers/hwmon/sht15.c 2011-05-22 19:36:31.000000000 -0400
30008 @@ -113,7 +113,7 @@ struct sht15_data {
30009 int supply_uV;
30010 int supply_uV_valid;
30011 struct work_struct update_supply_work;
30012 - atomic_t interrupt_handled;
30013 + atomic_unchecked_t interrupt_handled;
30014 };
30015
30016 /**
30017 @@ -246,13 +246,13 @@ static inline int sht15_update_single_va
30018 return ret;
30019
30020 gpio_direction_input(data->pdata->gpio_data);
30021 - atomic_set(&data->interrupt_handled, 0);
30022 + atomic_set_unchecked(&data->interrupt_handled, 0);
30023
30024 enable_irq(gpio_to_irq(data->pdata->gpio_data));
30025 if (gpio_get_value(data->pdata->gpio_data) == 0) {
30026 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
30027 /* Only relevant if the interrupt hasn't occurred. */
30028 - if (!atomic_read(&data->interrupt_handled))
30029 + if (!atomic_read_unchecked(&data->interrupt_handled))
30030 schedule_work(&data->read_work);
30031 }
30032 ret = wait_event_timeout(data->wait_queue,
30033 @@ -399,7 +399,7 @@ static irqreturn_t sht15_interrupt_fired
30034 struct sht15_data *data = d;
30035 /* First disable the interrupt */
30036 disable_irq_nosync(irq);
30037 - atomic_inc(&data->interrupt_handled);
30038 + atomic_inc_unchecked(&data->interrupt_handled);
30039 /* Then schedule a reading work struct */
30040 if (data->flag != SHT15_READING_NOTHING)
30041 schedule_work(&data->read_work);
30042 @@ -450,11 +450,11 @@ static void sht15_bh_read_data(struct wo
30043 here as could have gone low in meantime so verify
30044 it hasn't!
30045 */
30046 - atomic_set(&data->interrupt_handled, 0);
30047 + atomic_set_unchecked(&data->interrupt_handled, 0);
30048 enable_irq(gpio_to_irq(data->pdata->gpio_data));
30049 /* If still not occurred or another handler has been scheduled */
30050 if (gpio_get_value(data->pdata->gpio_data)
30051 - || atomic_read(&data->interrupt_handled))
30052 + || atomic_read_unchecked(&data->interrupt_handled))
30053 return;
30054 }
30055 /* Read the data back from the device */
30056 diff -urNp linux-2.6.39/drivers/hwmon/w83791d.c linux-2.6.39/drivers/hwmon/w83791d.c
30057 --- linux-2.6.39/drivers/hwmon/w83791d.c 2011-05-19 00:06:34.000000000 -0400
30058 +++ linux-2.6.39/drivers/hwmon/w83791d.c 2011-05-22 19:36:31.000000000 -0400
30059 @@ -329,8 +329,8 @@ static int w83791d_detect(struct i2c_cli
30060 struct i2c_board_info *info);
30061 static int w83791d_remove(struct i2c_client *client);
30062
30063 -static int w83791d_read(struct i2c_client *client, u8 register);
30064 -static int w83791d_write(struct i2c_client *client, u8 register, u8 value);
30065 +static int w83791d_read(struct i2c_client *client, u8 reg);
30066 +static int w83791d_write(struct i2c_client *client, u8 reg, u8 value);
30067 static struct w83791d_data *w83791d_update_device(struct device *dev);
30068
30069 #ifdef DEBUG
30070 diff -urNp linux-2.6.39/drivers/i2c/busses/i2c-at91.c linux-2.6.39/drivers/i2c/busses/i2c-at91.c
30071 --- linux-2.6.39/drivers/i2c/busses/i2c-at91.c 2011-05-19 00:06:34.000000000 -0400
30072 +++ linux-2.6.39/drivers/i2c/busses/i2c-at91.c 2011-05-22 19:36:31.000000000 -0400
30073 @@ -181,7 +181,7 @@ static u32 at91_func(struct i2c_adapter
30074 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
30075 }
30076
30077 -static struct i2c_algorithm at91_algorithm = {
30078 +static const struct i2c_algorithm at91_algorithm = {
30079 .master_xfer = at91_xfer,
30080 .functionality = at91_func,
30081 };
30082 diff -urNp linux-2.6.39/drivers/i2c/busses/i2c-bfin-twi.c linux-2.6.39/drivers/i2c/busses/i2c-bfin-twi.c
30083 --- linux-2.6.39/drivers/i2c/busses/i2c-bfin-twi.c 2011-05-19 00:06:34.000000000 -0400
30084 +++ linux-2.6.39/drivers/i2c/busses/i2c-bfin-twi.c 2011-05-22 19:36:31.000000000 -0400
30085 @@ -599,7 +599,7 @@ static u32 bfin_twi_functionality(struct
30086 I2C_FUNC_I2C | I2C_FUNC_SMBUS_I2C_BLOCK;
30087 }
30088
30089 -static struct i2c_algorithm bfin_twi_algorithm = {
30090 +static const struct i2c_algorithm bfin_twi_algorithm = {
30091 .master_xfer = bfin_twi_master_xfer,
30092 .smbus_xfer = bfin_twi_smbus_xfer,
30093 .functionality = bfin_twi_functionality,
30094 diff -urNp linux-2.6.39/drivers/i2c/busses/i2c-davinci.c linux-2.6.39/drivers/i2c/busses/i2c-davinci.c
30095 --- linux-2.6.39/drivers/i2c/busses/i2c-davinci.c 2011-05-19 00:06:34.000000000 -0400
30096 +++ linux-2.6.39/drivers/i2c/busses/i2c-davinci.c 2011-05-22 19:36:31.000000000 -0400
30097 @@ -630,7 +630,7 @@ static inline void i2c_davinci_cpufreq_d
30098 }
30099 #endif
30100
30101 -static struct i2c_algorithm i2c_davinci_algo = {
30102 +static const struct i2c_algorithm i2c_davinci_algo = {
30103 .master_xfer = i2c_davinci_xfer,
30104 .functionality = i2c_davinci_func,
30105 };
30106 diff -urNp linux-2.6.39/drivers/i2c/busses/i2c-designware.c linux-2.6.39/drivers/i2c/busses/i2c-designware.c
30107 --- linux-2.6.39/drivers/i2c/busses/i2c-designware.c 2011-05-19 00:06:34.000000000 -0400
30108 +++ linux-2.6.39/drivers/i2c/busses/i2c-designware.c 2011-05-22 19:36:31.000000000 -0400
30109 @@ -689,7 +689,7 @@ tx_aborted:
30110 return IRQ_HANDLED;
30111 }
30112
30113 -static struct i2c_algorithm i2c_dw_algo = {
30114 +static const struct i2c_algorithm i2c_dw_algo = {
30115 .master_xfer = i2c_dw_xfer,
30116 .functionality = i2c_dw_func,
30117 };
30118 diff -urNp linux-2.6.39/drivers/i2c/busses/i2c-eg20t.c linux-2.6.39/drivers/i2c/busses/i2c-eg20t.c
30119 --- linux-2.6.39/drivers/i2c/busses/i2c-eg20t.c 2011-05-19 00:06:34.000000000 -0400
30120 +++ linux-2.6.39/drivers/i2c/busses/i2c-eg20t.c 2011-05-22 19:36:31.000000000 -0400
30121 @@ -708,7 +708,7 @@ static u32 pch_i2c_func(struct i2c_adapt
30122 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR;
30123 }
30124
30125 -static struct i2c_algorithm pch_algorithm = {
30126 +static const struct i2c_algorithm pch_algorithm = {
30127 .master_xfer = pch_i2c_xfer,
30128 .functionality = pch_i2c_func
30129 };
30130 diff -urNp linux-2.6.39/drivers/i2c/busses/i2c-imx.c linux-2.6.39/drivers/i2c/busses/i2c-imx.c
30131 --- linux-2.6.39/drivers/i2c/busses/i2c-imx.c 2011-05-19 00:06:34.000000000 -0400
30132 +++ linux-2.6.39/drivers/i2c/busses/i2c-imx.c 2011-05-22 19:36:31.000000000 -0400
30133 @@ -457,7 +457,7 @@ static u32 i2c_imx_func(struct i2c_adapt
30134 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
30135 }
30136
30137 -static struct i2c_algorithm i2c_imx_algo = {
30138 +static const struct i2c_algorithm i2c_imx_algo = {
30139 .master_xfer = i2c_imx_xfer,
30140 .functionality = i2c_imx_func,
30141 };
30142 diff -urNp linux-2.6.39/drivers/i2c/busses/i2c-intel-mid.c linux-2.6.39/drivers/i2c/busses/i2c-intel-mid.c
30143 --- linux-2.6.39/drivers/i2c/busses/i2c-intel-mid.c 2011-05-19 00:06:34.000000000 -0400
30144 +++ linux-2.6.39/drivers/i2c/busses/i2c-intel-mid.c 2011-05-22 19:36:31.000000000 -0400
30145 @@ -917,7 +917,7 @@ err:
30146 return IRQ_HANDLED;
30147 }
30148
30149 -static struct i2c_algorithm intel_mid_i2c_algorithm = {
30150 +static const struct i2c_algorithm intel_mid_i2c_algorithm = {
30151 .master_xfer = intel_mid_i2c_xfer,
30152 .functionality = intel_mid_i2c_func,
30153 };
30154 diff -urNp linux-2.6.39/drivers/i2c/busses/i2c-nforce2.c linux-2.6.39/drivers/i2c/busses/i2c-nforce2.c
30155 --- linux-2.6.39/drivers/i2c/busses/i2c-nforce2.c 2011-05-19 00:06:34.000000000 -0400
30156 +++ linux-2.6.39/drivers/i2c/busses/i2c-nforce2.c 2011-05-22 19:36:31.000000000 -0400
30157 @@ -303,7 +303,7 @@ static u32 nforce2_func(struct i2c_adapt
30158 I2C_FUNC_SMBUS_BLOCK_DATA : 0);
30159 }
30160
30161 -static struct i2c_algorithm smbus_algorithm = {
30162 +static const struct i2c_algorithm smbus_algorithm = {
30163 .smbus_xfer = nforce2_access,
30164 .functionality = nforce2_func,
30165 };
30166 diff -urNp linux-2.6.39/drivers/i2c/busses/i2c-pmcmsp.c linux-2.6.39/drivers/i2c/busses/i2c-pmcmsp.c
30167 --- linux-2.6.39/drivers/i2c/busses/i2c-pmcmsp.c 2011-05-19 00:06:34.000000000 -0400
30168 +++ linux-2.6.39/drivers/i2c/busses/i2c-pmcmsp.c 2011-05-22 19:36:31.000000000 -0400
30169 @@ -615,7 +615,7 @@ static u32 pmcmsptwi_i2c_func(struct i2c
30170
30171 /* -- Initialization -- */
30172
30173 -static struct i2c_algorithm pmcmsptwi_algo = {
30174 +static const struct i2c_algorithm pmcmsptwi_algo = {
30175 .master_xfer = pmcmsptwi_master_xfer,
30176 .functionality = pmcmsptwi_i2c_func,
30177 };
30178 diff -urNp linux-2.6.39/drivers/i2c/busses/i2c-pnx.c linux-2.6.39/drivers/i2c/busses/i2c-pnx.c
30179 --- linux-2.6.39/drivers/i2c/busses/i2c-pnx.c 2011-05-19 00:06:34.000000000 -0400
30180 +++ linux-2.6.39/drivers/i2c/busses/i2c-pnx.c 2011-05-22 19:36:31.000000000 -0400
30181 @@ -535,7 +535,7 @@ static u32 i2c_pnx_func(struct i2c_adapt
30182 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
30183 }
30184
30185 -static struct i2c_algorithm pnx_algorithm = {
30186 +static const struct i2c_algorithm pnx_algorithm = {
30187 .master_xfer = i2c_pnx_xfer,
30188 .functionality = i2c_pnx_func,
30189 };
30190 diff -urNp linux-2.6.39/drivers/i2c/busses/i2c-puv3.c linux-2.6.39/drivers/i2c/busses/i2c-puv3.c
30191 --- linux-2.6.39/drivers/i2c/busses/i2c-puv3.c 2011-05-19 00:06:34.000000000 -0400
30192 +++ linux-2.6.39/drivers/i2c/busses/i2c-puv3.c 2011-05-22 19:36:31.000000000 -0400
30193 @@ -176,7 +176,7 @@ static u32 puv3_i2c_func(struct i2c_adap
30194 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
30195 }
30196
30197 -static struct i2c_algorithm puv3_i2c_algorithm = {
30198 +static const struct i2c_algorithm puv3_i2c_algorithm = {
30199 .master_xfer = puv3_i2c_xfer,
30200 .functionality = puv3_i2c_func,
30201 };
30202 diff -urNp linux-2.6.39/drivers/i2c/busses/i2c-s6000.c linux-2.6.39/drivers/i2c/busses/i2c-s6000.c
30203 --- linux-2.6.39/drivers/i2c/busses/i2c-s6000.c 2011-05-19 00:06:34.000000000 -0400
30204 +++ linux-2.6.39/drivers/i2c/busses/i2c-s6000.c 2011-05-22 19:36:31.000000000 -0400
30205 @@ -243,7 +243,7 @@ static u32 s6i2c_functionality(struct i2
30206 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
30207 }
30208
30209 -static struct i2c_algorithm s6i2c_algorithm = {
30210 +static const struct i2c_algorithm s6i2c_algorithm = {
30211 .master_xfer = s6i2c_master_xfer,
30212 .functionality = s6i2c_functionality,
30213 };
30214 diff -urNp linux-2.6.39/drivers/i2c/busses/i2c-sh_mobile.c linux-2.6.39/drivers/i2c/busses/i2c-sh_mobile.c
30215 --- linux-2.6.39/drivers/i2c/busses/i2c-sh_mobile.c 2011-05-19 00:06:34.000000000 -0400
30216 +++ linux-2.6.39/drivers/i2c/busses/i2c-sh_mobile.c 2011-05-22 19:36:31.000000000 -0400
30217 @@ -529,7 +529,7 @@ static u32 sh_mobile_i2c_func(struct i2c
30218 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
30219 }
30220
30221 -static struct i2c_algorithm sh_mobile_i2c_algorithm = {
30222 +static const struct i2c_algorithm sh_mobile_i2c_algorithm = {
30223 .functionality = sh_mobile_i2c_func,
30224 .master_xfer = sh_mobile_i2c_xfer,
30225 };
30226 diff -urNp linux-2.6.39/drivers/ide/ide-cd.c linux-2.6.39/drivers/ide/ide-cd.c
30227 --- linux-2.6.39/drivers/ide/ide-cd.c 2011-05-19 00:06:34.000000000 -0400
30228 +++ linux-2.6.39/drivers/ide/ide-cd.c 2011-05-22 19:36:31.000000000 -0400
30229 @@ -769,7 +769,7 @@ static void cdrom_do_block_pc(ide_drive_
30230 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
30231 if ((unsigned long)buf & alignment
30232 || blk_rq_bytes(rq) & q->dma_pad_mask
30233 - || object_is_on_stack(buf))
30234 + || object_starts_on_stack(buf))
30235 drive->dma = 0;
30236 }
30237 }
30238 diff -urNp linux-2.6.39/drivers/ide/ide-floppy.c linux-2.6.39/drivers/ide/ide-floppy.c
30239 --- linux-2.6.39/drivers/ide/ide-floppy.c 2011-05-19 00:06:34.000000000 -0400
30240 +++ linux-2.6.39/drivers/ide/ide-floppy.c 2011-05-22 19:36:31.000000000 -0400
30241 @@ -379,6 +379,8 @@ static int ide_floppy_get_capacity(ide_d
30242 u8 pc_buf[256], header_len, desc_cnt;
30243 int i, rc = 1, blocks, length;
30244
30245 + pax_track_stack();
30246 +
30247 ide_debug_log(IDE_DBG_FUNC, "enter");
30248
30249 drive->bios_cyl = 0;
30250 diff -urNp linux-2.6.39/drivers/ide/it821x.c linux-2.6.39/drivers/ide/it821x.c
30251 --- linux-2.6.39/drivers/ide/it821x.c 2011-05-19 00:06:34.000000000 -0400
30252 +++ linux-2.6.39/drivers/ide/it821x.c 2011-05-22 19:36:31.000000000 -0400
30253 @@ -508,7 +508,7 @@ static void it821x_quirkproc(ide_drive_t
30254
30255 }
30256
30257 -static struct ide_dma_ops it821x_pass_through_dma_ops = {
30258 +static const struct ide_dma_ops it821x_pass_through_dma_ops = {
30259 .dma_host_set = ide_dma_host_set,
30260 .dma_setup = ide_dma_setup,
30261 .dma_start = it821x_dma_start,
30262 diff -urNp linux-2.6.39/drivers/ide/setup-pci.c linux-2.6.39/drivers/ide/setup-pci.c
30263 --- linux-2.6.39/drivers/ide/setup-pci.c 2011-05-19 00:06:34.000000000 -0400
30264 +++ linux-2.6.39/drivers/ide/setup-pci.c 2011-05-22 19:36:31.000000000 -0400
30265 @@ -542,6 +542,8 @@ int ide_pci_init_two(struct pci_dev *dev
30266 int ret, i, n_ports = dev2 ? 4 : 2;
30267 struct ide_hw hw[4], *hws[] = { NULL, NULL, NULL, NULL };
30268
30269 + pax_track_stack();
30270 +
30271 for (i = 0; i < n_ports / 2; i++) {
30272 ret = ide_setup_pci_controller(pdev[i], d, !i);
30273 if (ret < 0)
30274 diff -urNp linux-2.6.39/drivers/ide/trm290.c linux-2.6.39/drivers/ide/trm290.c
30275 --- linux-2.6.39/drivers/ide/trm290.c 2011-05-19 00:06:34.000000000 -0400
30276 +++ linux-2.6.39/drivers/ide/trm290.c 2011-05-22 19:36:31.000000000 -0400
30277 @@ -314,7 +314,7 @@ static const struct ide_tp_ops trm290_tp
30278 .output_data = ide_output_data,
30279 };
30280
30281 -static struct ide_dma_ops trm290_dma_ops = {
30282 +static const struct ide_dma_ops trm290_dma_ops = {
30283 .dma_host_set = trm290_dma_host_set,
30284 .dma_setup = trm290_dma_setup,
30285 .dma_start = trm290_dma_start,
30286 diff -urNp linux-2.6.39/drivers/infiniband/core/cm.c linux-2.6.39/drivers/infiniband/core/cm.c
30287 --- linux-2.6.39/drivers/infiniband/core/cm.c 2011-05-19 00:06:34.000000000 -0400
30288 +++ linux-2.6.39/drivers/infiniband/core/cm.c 2011-05-22 19:36:31.000000000 -0400
30289 @@ -113,7 +113,7 @@ static char const counter_group_names[CM
30290
30291 struct cm_counter_group {
30292 struct kobject obj;
30293 - atomic_long_t counter[CM_ATTR_COUNT];
30294 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
30295 };
30296
30297 struct cm_counter_attribute {
30298 @@ -1387,7 +1387,7 @@ static void cm_dup_req_handler(struct cm
30299 struct ib_mad_send_buf *msg = NULL;
30300 int ret;
30301
30302 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30303 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30304 counter[CM_REQ_COUNTER]);
30305
30306 /* Quick state check to discard duplicate REQs. */
30307 @@ -1765,7 +1765,7 @@ static void cm_dup_rep_handler(struct cm
30308 if (!cm_id_priv)
30309 return;
30310
30311 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30312 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30313 counter[CM_REP_COUNTER]);
30314 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
30315 if (ret)
30316 @@ -1932,7 +1932,7 @@ static int cm_rtu_handler(struct cm_work
30317 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
30318 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
30319 spin_unlock_irq(&cm_id_priv->lock);
30320 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30321 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30322 counter[CM_RTU_COUNTER]);
30323 goto out;
30324 }
30325 @@ -2115,7 +2115,7 @@ static int cm_dreq_handler(struct cm_wor
30326 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
30327 dreq_msg->local_comm_id);
30328 if (!cm_id_priv) {
30329 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30330 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30331 counter[CM_DREQ_COUNTER]);
30332 cm_issue_drep(work->port, work->mad_recv_wc);
30333 return -EINVAL;
30334 @@ -2140,7 +2140,7 @@ static int cm_dreq_handler(struct cm_wor
30335 case IB_CM_MRA_REP_RCVD:
30336 break;
30337 case IB_CM_TIMEWAIT:
30338 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30339 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30340 counter[CM_DREQ_COUNTER]);
30341 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
30342 goto unlock;
30343 @@ -2154,7 +2154,7 @@ static int cm_dreq_handler(struct cm_wor
30344 cm_free_msg(msg);
30345 goto deref;
30346 case IB_CM_DREQ_RCVD:
30347 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30348 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30349 counter[CM_DREQ_COUNTER]);
30350 goto unlock;
30351 default:
30352 @@ -2521,7 +2521,7 @@ static int cm_mra_handler(struct cm_work
30353 ib_modify_mad(cm_id_priv->av.port->mad_agent,
30354 cm_id_priv->msg, timeout)) {
30355 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
30356 - atomic_long_inc(&work->port->
30357 + atomic_long_inc_unchecked(&work->port->
30358 counter_group[CM_RECV_DUPLICATES].
30359 counter[CM_MRA_COUNTER]);
30360 goto out;
30361 @@ -2530,7 +2530,7 @@ static int cm_mra_handler(struct cm_work
30362 break;
30363 case IB_CM_MRA_REQ_RCVD:
30364 case IB_CM_MRA_REP_RCVD:
30365 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30366 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30367 counter[CM_MRA_COUNTER]);
30368 /* fall through */
30369 default:
30370 @@ -2692,7 +2692,7 @@ static int cm_lap_handler(struct cm_work
30371 case IB_CM_LAP_IDLE:
30372 break;
30373 case IB_CM_MRA_LAP_SENT:
30374 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30375 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30376 counter[CM_LAP_COUNTER]);
30377 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
30378 goto unlock;
30379 @@ -2708,7 +2708,7 @@ static int cm_lap_handler(struct cm_work
30380 cm_free_msg(msg);
30381 goto deref;
30382 case IB_CM_LAP_RCVD:
30383 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30384 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30385 counter[CM_LAP_COUNTER]);
30386 goto unlock;
30387 default:
30388 @@ -2992,7 +2992,7 @@ static int cm_sidr_req_handler(struct cm
30389 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
30390 if (cur_cm_id_priv) {
30391 spin_unlock_irq(&cm.lock);
30392 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30393 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30394 counter[CM_SIDR_REQ_COUNTER]);
30395 goto out; /* Duplicate message. */
30396 }
30397 @@ -3204,10 +3204,10 @@ static void cm_send_handler(struct ib_ma
30398 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
30399 msg->retries = 1;
30400
30401 - atomic_long_add(1 + msg->retries,
30402 + atomic_long_add_unchecked(1 + msg->retries,
30403 &port->counter_group[CM_XMIT].counter[attr_index]);
30404 if (msg->retries)
30405 - atomic_long_add(msg->retries,
30406 + atomic_long_add_unchecked(msg->retries,
30407 &port->counter_group[CM_XMIT_RETRIES].
30408 counter[attr_index]);
30409
30410 @@ -3417,7 +3417,7 @@ static void cm_recv_handler(struct ib_ma
30411 }
30412
30413 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
30414 - atomic_long_inc(&port->counter_group[CM_RECV].
30415 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
30416 counter[attr_id - CM_ATTR_ID_OFFSET]);
30417
30418 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
30419 @@ -3615,7 +3615,7 @@ static ssize_t cm_show_counter(struct ko
30420 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
30421
30422 return sprintf(buf, "%ld\n",
30423 - atomic_long_read(&group->counter[cm_attr->index]));
30424 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
30425 }
30426
30427 static const struct sysfs_ops cm_counter_ops = {
30428 diff -urNp linux-2.6.39/drivers/infiniband/core/fmr_pool.c linux-2.6.39/drivers/infiniband/core/fmr_pool.c
30429 --- linux-2.6.39/drivers/infiniband/core/fmr_pool.c 2011-05-19 00:06:34.000000000 -0400
30430 +++ linux-2.6.39/drivers/infiniband/core/fmr_pool.c 2011-05-22 19:36:31.000000000 -0400
30431 @@ -97,8 +97,8 @@ struct ib_fmr_pool {
30432
30433 struct task_struct *thread;
30434
30435 - atomic_t req_ser;
30436 - atomic_t flush_ser;
30437 + atomic_unchecked_t req_ser;
30438 + atomic_unchecked_t flush_ser;
30439
30440 wait_queue_head_t force_wait;
30441 };
30442 @@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *p
30443 struct ib_fmr_pool *pool = pool_ptr;
30444
30445 do {
30446 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
30447 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
30448 ib_fmr_batch_release(pool);
30449
30450 - atomic_inc(&pool->flush_ser);
30451 + atomic_inc_unchecked(&pool->flush_ser);
30452 wake_up_interruptible(&pool->force_wait);
30453
30454 if (pool->flush_function)
30455 @@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *p
30456 }
30457
30458 set_current_state(TASK_INTERRUPTIBLE);
30459 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
30460 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
30461 !kthread_should_stop())
30462 schedule();
30463 __set_current_state(TASK_RUNNING);
30464 @@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(s
30465 pool->dirty_watermark = params->dirty_watermark;
30466 pool->dirty_len = 0;
30467 spin_lock_init(&pool->pool_lock);
30468 - atomic_set(&pool->req_ser, 0);
30469 - atomic_set(&pool->flush_ser, 0);
30470 + atomic_set_unchecked(&pool->req_ser, 0);
30471 + atomic_set_unchecked(&pool->flush_ser, 0);
30472 init_waitqueue_head(&pool->force_wait);
30473
30474 pool->thread = kthread_run(ib_fmr_cleanup_thread,
30475 @@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool
30476 }
30477 spin_unlock_irq(&pool->pool_lock);
30478
30479 - serial = atomic_inc_return(&pool->req_ser);
30480 + serial = atomic_inc_return_unchecked(&pool->req_ser);
30481 wake_up_process(pool->thread);
30482
30483 if (wait_event_interruptible(pool->force_wait,
30484 - atomic_read(&pool->flush_ser) - serial >= 0))
30485 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
30486 return -EINTR;
30487
30488 return 0;
30489 @@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr
30490 } else {
30491 list_add_tail(&fmr->list, &pool->dirty_list);
30492 if (++pool->dirty_len >= pool->dirty_watermark) {
30493 - atomic_inc(&pool->req_ser);
30494 + atomic_inc_unchecked(&pool->req_ser);
30495 wake_up_process(pool->thread);
30496 }
30497 }
30498 diff -urNp linux-2.6.39/drivers/infiniband/hw/cxgb4/mem.c linux-2.6.39/drivers/infiniband/hw/cxgb4/mem.c
30499 --- linux-2.6.39/drivers/infiniband/hw/cxgb4/mem.c 2011-05-19 00:06:34.000000000 -0400
30500 +++ linux-2.6.39/drivers/infiniband/hw/cxgb4/mem.c 2011-05-22 19:36:31.000000000 -0400
30501 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_r
30502 int err;
30503 struct fw_ri_tpte tpt;
30504 u32 stag_idx;
30505 - static atomic_t key;
30506 + static atomic_unchecked_t key;
30507
30508 if (c4iw_fatal_error(rdev))
30509 return -EIO;
30510 @@ -135,7 +135,7 @@ static int write_tpt_entry(struct c4iw_r
30511 &rdev->resource.tpt_fifo_lock);
30512 if (!stag_idx)
30513 return -ENOMEM;
30514 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
30515 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
30516 }
30517 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
30518 __func__, stag_state, type, pdid, stag_idx);
30519 diff -urNp linux-2.6.39/drivers/infiniband/hw/ipath/ipath_dma.c linux-2.6.39/drivers/infiniband/hw/ipath/ipath_dma.c
30520 --- linux-2.6.39/drivers/infiniband/hw/ipath/ipath_dma.c 2011-05-19 00:06:34.000000000 -0400
30521 +++ linux-2.6.39/drivers/infiniband/hw/ipath/ipath_dma.c 2011-05-22 19:36:31.000000000 -0400
30522 @@ -175,7 +175,7 @@ static void ipath_dma_free_coherent(stru
30523 free_pages((unsigned long) cpu_addr, get_order(size));
30524 }
30525
30526 -struct ib_dma_mapping_ops ipath_dma_mapping_ops = {
30527 +const struct ib_dma_mapping_ops ipath_dma_mapping_ops = {
30528 ipath_mapping_error,
30529 ipath_dma_map_single,
30530 ipath_dma_unmap_single,
30531 diff -urNp linux-2.6.39/drivers/infiniband/hw/ipath/ipath_fs.c linux-2.6.39/drivers/infiniband/hw/ipath/ipath_fs.c
30532 --- linux-2.6.39/drivers/infiniband/hw/ipath/ipath_fs.c 2011-05-19 00:06:34.000000000 -0400
30533 +++ linux-2.6.39/drivers/infiniband/hw/ipath/ipath_fs.c 2011-05-22 19:36:31.000000000 -0400
30534 @@ -113,6 +113,8 @@ static ssize_t atomic_counters_read(stru
30535 struct infinipath_counters counters;
30536 struct ipath_devdata *dd;
30537
30538 + pax_track_stack();
30539 +
30540 dd = file->f_path.dentry->d_inode->i_private;
30541 dd->ipath_f_read_counters(dd, &counters);
30542
30543 diff -urNp linux-2.6.39/drivers/infiniband/hw/ipath/ipath_rc.c linux-2.6.39/drivers/infiniband/hw/ipath/ipath_rc.c
30544 --- linux-2.6.39/drivers/infiniband/hw/ipath/ipath_rc.c 2011-05-19 00:06:34.000000000 -0400
30545 +++ linux-2.6.39/drivers/infiniband/hw/ipath/ipath_rc.c 2011-05-22 19:36:31.000000000 -0400
30546 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *de
30547 struct ib_atomic_eth *ateth;
30548 struct ipath_ack_entry *e;
30549 u64 vaddr;
30550 - atomic64_t *maddr;
30551 + atomic64_unchecked_t *maddr;
30552 u64 sdata;
30553 u32 rkey;
30554 u8 next;
30555 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *de
30556 IB_ACCESS_REMOTE_ATOMIC)))
30557 goto nack_acc_unlck;
30558 /* Perform atomic OP and save result. */
30559 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
30560 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
30561 sdata = be64_to_cpu(ateth->swap_data);
30562 e = &qp->s_ack_queue[qp->r_head_ack_queue];
30563 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
30564 - (u64) atomic64_add_return(sdata, maddr) - sdata :
30565 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
30566 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
30567 be64_to_cpu(ateth->compare_data),
30568 sdata);
30569 diff -urNp linux-2.6.39/drivers/infiniband/hw/ipath/ipath_ruc.c linux-2.6.39/drivers/infiniband/hw/ipath/ipath_ruc.c
30570 --- linux-2.6.39/drivers/infiniband/hw/ipath/ipath_ruc.c 2011-05-19 00:06:34.000000000 -0400
30571 +++ linux-2.6.39/drivers/infiniband/hw/ipath/ipath_ruc.c 2011-05-22 19:36:31.000000000 -0400
30572 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ip
30573 unsigned long flags;
30574 struct ib_wc wc;
30575 u64 sdata;
30576 - atomic64_t *maddr;
30577 + atomic64_unchecked_t *maddr;
30578 enum ib_wc_status send_status;
30579
30580 /*
30581 @@ -382,11 +382,11 @@ again:
30582 IB_ACCESS_REMOTE_ATOMIC)))
30583 goto acc_err;
30584 /* Perform atomic OP and save result. */
30585 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
30586 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
30587 sdata = wqe->wr.wr.atomic.compare_add;
30588 *(u64 *) sqp->s_sge.sge.vaddr =
30589 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
30590 - (u64) atomic64_add_return(sdata, maddr) - sdata :
30591 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
30592 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
30593 sdata, wqe->wr.wr.atomic.swap);
30594 goto send_comp;
30595 diff -urNp linux-2.6.39/drivers/infiniband/hw/ipath/ipath_verbs.h linux-2.6.39/drivers/infiniband/hw/ipath/ipath_verbs.h
30596 --- linux-2.6.39/drivers/infiniband/hw/ipath/ipath_verbs.h 2011-05-19 00:06:34.000000000 -0400
30597 +++ linux-2.6.39/drivers/infiniband/hw/ipath/ipath_verbs.h 2011-05-22 19:36:31.000000000 -0400
30598 @@ -931,6 +931,6 @@ extern unsigned int ib_ipath_max_srq_wrs
30599
30600 extern const u32 ib_ipath_rnr_table[];
30601
30602 -extern struct ib_dma_mapping_ops ipath_dma_mapping_ops;
30603 +extern const struct ib_dma_mapping_ops ipath_dma_mapping_ops;
30604
30605 #endif /* IPATH_VERBS_H */
30606 diff -urNp linux-2.6.39/drivers/infiniband/hw/nes/nes.c linux-2.6.39/drivers/infiniband/hw/nes/nes.c
30607 --- linux-2.6.39/drivers/infiniband/hw/nes/nes.c 2011-05-19 00:06:34.000000000 -0400
30608 +++ linux-2.6.39/drivers/infiniband/hw/nes/nes.c 2011-05-22 19:36:31.000000000 -0400
30609 @@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limi
30610 LIST_HEAD(nes_adapter_list);
30611 static LIST_HEAD(nes_dev_list);
30612
30613 -atomic_t qps_destroyed;
30614 +atomic_unchecked_t qps_destroyed;
30615
30616 static unsigned int ee_flsh_adapter;
30617 static unsigned int sysfs_nonidx_addr;
30618 @@ -275,7 +275,7 @@ static void nes_cqp_rem_ref_callback(str
30619 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
30620 struct nes_adapter *nesadapter = nesdev->nesadapter;
30621
30622 - atomic_inc(&qps_destroyed);
30623 + atomic_inc_unchecked(&qps_destroyed);
30624
30625 /* Free the control structures */
30626
30627 diff -urNp linux-2.6.39/drivers/infiniband/hw/nes/nes_cm.c linux-2.6.39/drivers/infiniband/hw/nes/nes_cm.c
30628 --- linux-2.6.39/drivers/infiniband/hw/nes/nes_cm.c 2011-05-19 00:06:34.000000000 -0400
30629 +++ linux-2.6.39/drivers/infiniband/hw/nes/nes_cm.c 2011-05-22 19:36:31.000000000 -0400
30630 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
30631 u32 cm_packets_retrans;
30632 u32 cm_packets_created;
30633 u32 cm_packets_received;
30634 -atomic_t cm_listens_created;
30635 -atomic_t cm_listens_destroyed;
30636 +atomic_unchecked_t cm_listens_created;
30637 +atomic_unchecked_t cm_listens_destroyed;
30638 u32 cm_backlog_drops;
30639 -atomic_t cm_loopbacks;
30640 -atomic_t cm_nodes_created;
30641 -atomic_t cm_nodes_destroyed;
30642 -atomic_t cm_accel_dropped_pkts;
30643 -atomic_t cm_resets_recvd;
30644 +atomic_unchecked_t cm_loopbacks;
30645 +atomic_unchecked_t cm_nodes_created;
30646 +atomic_unchecked_t cm_nodes_destroyed;
30647 +atomic_unchecked_t cm_accel_dropped_pkts;
30648 +atomic_unchecked_t cm_resets_recvd;
30649
30650 static inline int mini_cm_accelerated(struct nes_cm_core *,
30651 struct nes_cm_node *);
30652 @@ -151,13 +151,13 @@ static struct nes_cm_ops nes_cm_api = {
30653
30654 static struct nes_cm_core *g_cm_core;
30655
30656 -atomic_t cm_connects;
30657 -atomic_t cm_accepts;
30658 -atomic_t cm_disconnects;
30659 -atomic_t cm_closes;
30660 -atomic_t cm_connecteds;
30661 -atomic_t cm_connect_reqs;
30662 -atomic_t cm_rejects;
30663 +atomic_unchecked_t cm_connects;
30664 +atomic_unchecked_t cm_accepts;
30665 +atomic_unchecked_t cm_disconnects;
30666 +atomic_unchecked_t cm_closes;
30667 +atomic_unchecked_t cm_connecteds;
30668 +atomic_unchecked_t cm_connect_reqs;
30669 +atomic_unchecked_t cm_rejects;
30670
30671
30672 /**
30673 @@ -1045,7 +1045,7 @@ static int mini_cm_dec_refcnt_listen(str
30674 kfree(listener);
30675 listener = NULL;
30676 ret = 0;
30677 - atomic_inc(&cm_listens_destroyed);
30678 + atomic_inc_unchecked(&cm_listens_destroyed);
30679 } else {
30680 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
30681 }
30682 @@ -1240,7 +1240,7 @@ static struct nes_cm_node *make_cm_node(
30683 cm_node->rem_mac);
30684
30685 add_hte_node(cm_core, cm_node);
30686 - atomic_inc(&cm_nodes_created);
30687 + atomic_inc_unchecked(&cm_nodes_created);
30688
30689 return cm_node;
30690 }
30691 @@ -1298,7 +1298,7 @@ static int rem_ref_cm_node(struct nes_cm
30692 }
30693
30694 atomic_dec(&cm_core->node_cnt);
30695 - atomic_inc(&cm_nodes_destroyed);
30696 + atomic_inc_unchecked(&cm_nodes_destroyed);
30697 nesqp = cm_node->nesqp;
30698 if (nesqp) {
30699 nesqp->cm_node = NULL;
30700 @@ -1365,7 +1365,7 @@ static int process_options(struct nes_cm
30701
30702 static void drop_packet(struct sk_buff *skb)
30703 {
30704 - atomic_inc(&cm_accel_dropped_pkts);
30705 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
30706 dev_kfree_skb_any(skb);
30707 }
30708
30709 @@ -1428,7 +1428,7 @@ static void handle_rst_pkt(struct nes_cm
30710 {
30711
30712 int reset = 0; /* whether to send reset in case of err.. */
30713 - atomic_inc(&cm_resets_recvd);
30714 + atomic_inc_unchecked(&cm_resets_recvd);
30715 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
30716 " refcnt=%d\n", cm_node, cm_node->state,
30717 atomic_read(&cm_node->ref_count));
30718 @@ -2057,7 +2057,7 @@ static struct nes_cm_node *mini_cm_conne
30719 rem_ref_cm_node(cm_node->cm_core, cm_node);
30720 return NULL;
30721 }
30722 - atomic_inc(&cm_loopbacks);
30723 + atomic_inc_unchecked(&cm_loopbacks);
30724 loopbackremotenode->loopbackpartner = cm_node;
30725 loopbackremotenode->tcp_cntxt.rcv_wscale =
30726 NES_CM_DEFAULT_RCV_WND_SCALE;
30727 @@ -2332,7 +2332,7 @@ static int mini_cm_recv_pkt(struct nes_c
30728 add_ref_cm_node(cm_node);
30729 } else if (cm_node->state == NES_CM_STATE_TSA) {
30730 rem_ref_cm_node(cm_core, cm_node);
30731 - atomic_inc(&cm_accel_dropped_pkts);
30732 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
30733 dev_kfree_skb_any(skb);
30734 break;
30735 }
30736 @@ -2638,7 +2638,7 @@ static int nes_cm_disconn_true(struct ne
30737
30738 if ((cm_id) && (cm_id->event_handler)) {
30739 if (issue_disconn) {
30740 - atomic_inc(&cm_disconnects);
30741 + atomic_inc_unchecked(&cm_disconnects);
30742 cm_event.event = IW_CM_EVENT_DISCONNECT;
30743 cm_event.status = disconn_status;
30744 cm_event.local_addr = cm_id->local_addr;
30745 @@ -2660,7 +2660,7 @@ static int nes_cm_disconn_true(struct ne
30746 }
30747
30748 if (issue_close) {
30749 - atomic_inc(&cm_closes);
30750 + atomic_inc_unchecked(&cm_closes);
30751 nes_disconnect(nesqp, 1);
30752
30753 cm_id->provider_data = nesqp;
30754 @@ -2791,7 +2791,7 @@ int nes_accept(struct iw_cm_id *cm_id, s
30755
30756 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
30757 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
30758 - atomic_inc(&cm_accepts);
30759 + atomic_inc_unchecked(&cm_accepts);
30760
30761 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
30762 netdev_refcnt_read(nesvnic->netdev));
30763 @@ -3001,7 +3001,7 @@ int nes_reject(struct iw_cm_id *cm_id, c
30764
30765 struct nes_cm_core *cm_core;
30766
30767 - atomic_inc(&cm_rejects);
30768 + atomic_inc_unchecked(&cm_rejects);
30769 cm_node = (struct nes_cm_node *) cm_id->provider_data;
30770 loopback = cm_node->loopbackpartner;
30771 cm_core = cm_node->cm_core;
30772 @@ -3067,7 +3067,7 @@ int nes_connect(struct iw_cm_id *cm_id,
30773 ntohl(cm_id->local_addr.sin_addr.s_addr),
30774 ntohs(cm_id->local_addr.sin_port));
30775
30776 - atomic_inc(&cm_connects);
30777 + atomic_inc_unchecked(&cm_connects);
30778 nesqp->active_conn = 1;
30779
30780 /* cache the cm_id in the qp */
30781 @@ -3173,7 +3173,7 @@ int nes_create_listen(struct iw_cm_id *c
30782 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
30783 return err;
30784 }
30785 - atomic_inc(&cm_listens_created);
30786 + atomic_inc_unchecked(&cm_listens_created);
30787 }
30788
30789 cm_id->add_ref(cm_id);
30790 @@ -3278,7 +3278,7 @@ static void cm_event_connected(struct ne
30791 if (nesqp->destroyed) {
30792 return;
30793 }
30794 - atomic_inc(&cm_connecteds);
30795 + atomic_inc_unchecked(&cm_connecteds);
30796 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
30797 " local port 0x%04X. jiffies = %lu.\n",
30798 nesqp->hwqp.qp_id,
30799 @@ -3493,7 +3493,7 @@ static void cm_event_reset(struct nes_cm
30800
30801 cm_id->add_ref(cm_id);
30802 ret = cm_id->event_handler(cm_id, &cm_event);
30803 - atomic_inc(&cm_closes);
30804 + atomic_inc_unchecked(&cm_closes);
30805 cm_event.event = IW_CM_EVENT_CLOSE;
30806 cm_event.status = IW_CM_EVENT_STATUS_OK;
30807 cm_event.provider_data = cm_id->provider_data;
30808 @@ -3529,7 +3529,7 @@ static void cm_event_mpa_req(struct nes_
30809 return;
30810 cm_id = cm_node->cm_id;
30811
30812 - atomic_inc(&cm_connect_reqs);
30813 + atomic_inc_unchecked(&cm_connect_reqs);
30814 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
30815 cm_node, cm_id, jiffies);
30816
30817 @@ -3567,7 +3567,7 @@ static void cm_event_mpa_reject(struct n
30818 return;
30819 cm_id = cm_node->cm_id;
30820
30821 - atomic_inc(&cm_connect_reqs);
30822 + atomic_inc_unchecked(&cm_connect_reqs);
30823 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
30824 cm_node, cm_id, jiffies);
30825
30826 diff -urNp linux-2.6.39/drivers/infiniband/hw/nes/nes.h linux-2.6.39/drivers/infiniband/hw/nes/nes.h
30827 --- linux-2.6.39/drivers/infiniband/hw/nes/nes.h 2011-05-19 00:06:34.000000000 -0400
30828 +++ linux-2.6.39/drivers/infiniband/hw/nes/nes.h 2011-05-22 19:36:31.000000000 -0400
30829 @@ -175,17 +175,17 @@ extern unsigned int nes_debug_level;
30830 extern unsigned int wqm_quanta;
30831 extern struct list_head nes_adapter_list;
30832
30833 -extern atomic_t cm_connects;
30834 -extern atomic_t cm_accepts;
30835 -extern atomic_t cm_disconnects;
30836 -extern atomic_t cm_closes;
30837 -extern atomic_t cm_connecteds;
30838 -extern atomic_t cm_connect_reqs;
30839 -extern atomic_t cm_rejects;
30840 -extern atomic_t mod_qp_timouts;
30841 -extern atomic_t qps_created;
30842 -extern atomic_t qps_destroyed;
30843 -extern atomic_t sw_qps_destroyed;
30844 +extern atomic_unchecked_t cm_connects;
30845 +extern atomic_unchecked_t cm_accepts;
30846 +extern atomic_unchecked_t cm_disconnects;
30847 +extern atomic_unchecked_t cm_closes;
30848 +extern atomic_unchecked_t cm_connecteds;
30849 +extern atomic_unchecked_t cm_connect_reqs;
30850 +extern atomic_unchecked_t cm_rejects;
30851 +extern atomic_unchecked_t mod_qp_timouts;
30852 +extern atomic_unchecked_t qps_created;
30853 +extern atomic_unchecked_t qps_destroyed;
30854 +extern atomic_unchecked_t sw_qps_destroyed;
30855 extern u32 mh_detected;
30856 extern u32 mh_pauses_sent;
30857 extern u32 cm_packets_sent;
30858 @@ -194,14 +194,14 @@ extern u32 cm_packets_created;
30859 extern u32 cm_packets_received;
30860 extern u32 cm_packets_dropped;
30861 extern u32 cm_packets_retrans;
30862 -extern atomic_t cm_listens_created;
30863 -extern atomic_t cm_listens_destroyed;
30864 +extern atomic_unchecked_t cm_listens_created;
30865 +extern atomic_unchecked_t cm_listens_destroyed;
30866 extern u32 cm_backlog_drops;
30867 -extern atomic_t cm_loopbacks;
30868 -extern atomic_t cm_nodes_created;
30869 -extern atomic_t cm_nodes_destroyed;
30870 -extern atomic_t cm_accel_dropped_pkts;
30871 -extern atomic_t cm_resets_recvd;
30872 +extern atomic_unchecked_t cm_loopbacks;
30873 +extern atomic_unchecked_t cm_nodes_created;
30874 +extern atomic_unchecked_t cm_nodes_destroyed;
30875 +extern atomic_unchecked_t cm_accel_dropped_pkts;
30876 +extern atomic_unchecked_t cm_resets_recvd;
30877
30878 extern u32 int_mod_timer_init;
30879 extern u32 int_mod_cq_depth_256;
30880 diff -urNp linux-2.6.39/drivers/infiniband/hw/nes/nes_nic.c linux-2.6.39/drivers/infiniband/hw/nes/nes_nic.c
30881 --- linux-2.6.39/drivers/infiniband/hw/nes/nes_nic.c 2011-05-19 00:06:34.000000000 -0400
30882 +++ linux-2.6.39/drivers/infiniband/hw/nes/nes_nic.c 2011-05-22 19:36:31.000000000 -0400
30883 @@ -1302,31 +1302,31 @@ static void nes_netdev_get_ethtool_stats
30884 target_stat_values[++index] = mh_detected;
30885 target_stat_values[++index] = mh_pauses_sent;
30886 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
30887 - target_stat_values[++index] = atomic_read(&cm_connects);
30888 - target_stat_values[++index] = atomic_read(&cm_accepts);
30889 - target_stat_values[++index] = atomic_read(&cm_disconnects);
30890 - target_stat_values[++index] = atomic_read(&cm_connecteds);
30891 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
30892 - target_stat_values[++index] = atomic_read(&cm_rejects);
30893 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
30894 - target_stat_values[++index] = atomic_read(&qps_created);
30895 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
30896 - target_stat_values[++index] = atomic_read(&qps_destroyed);
30897 - target_stat_values[++index] = atomic_read(&cm_closes);
30898 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
30899 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
30900 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
30901 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
30902 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
30903 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
30904 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
30905 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
30906 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
30907 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
30908 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
30909 target_stat_values[++index] = cm_packets_sent;
30910 target_stat_values[++index] = cm_packets_bounced;
30911 target_stat_values[++index] = cm_packets_created;
30912 target_stat_values[++index] = cm_packets_received;
30913 target_stat_values[++index] = cm_packets_dropped;
30914 target_stat_values[++index] = cm_packets_retrans;
30915 - target_stat_values[++index] = atomic_read(&cm_listens_created);
30916 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
30917 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
30918 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
30919 target_stat_values[++index] = cm_backlog_drops;
30920 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
30921 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
30922 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
30923 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
30924 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
30925 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
30926 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
30927 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
30928 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
30929 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
30930 target_stat_values[++index] = nesadapter->free_4kpbl;
30931 target_stat_values[++index] = nesadapter->free_256pbl;
30932 target_stat_values[++index] = int_mod_timer_init;
30933 diff -urNp linux-2.6.39/drivers/infiniband/hw/nes/nes_verbs.c linux-2.6.39/drivers/infiniband/hw/nes/nes_verbs.c
30934 --- linux-2.6.39/drivers/infiniband/hw/nes/nes_verbs.c 2011-05-19 00:06:34.000000000 -0400
30935 +++ linux-2.6.39/drivers/infiniband/hw/nes/nes_verbs.c 2011-05-22 19:36:31.000000000 -0400
30936 @@ -46,9 +46,9 @@
30937
30938 #include <rdma/ib_umem.h>
30939
30940 -atomic_t mod_qp_timouts;
30941 -atomic_t qps_created;
30942 -atomic_t sw_qps_destroyed;
30943 +atomic_unchecked_t mod_qp_timouts;
30944 +atomic_unchecked_t qps_created;
30945 +atomic_unchecked_t sw_qps_destroyed;
30946
30947 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
30948
30949 @@ -1141,7 +1141,7 @@ static struct ib_qp *nes_create_qp(struc
30950 if (init_attr->create_flags)
30951 return ERR_PTR(-EINVAL);
30952
30953 - atomic_inc(&qps_created);
30954 + atomic_inc_unchecked(&qps_created);
30955 switch (init_attr->qp_type) {
30956 case IB_QPT_RC:
30957 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
30958 @@ -1470,7 +1470,7 @@ static int nes_destroy_qp(struct ib_qp *
30959 struct iw_cm_event cm_event;
30960 int ret;
30961
30962 - atomic_inc(&sw_qps_destroyed);
30963 + atomic_inc_unchecked(&sw_qps_destroyed);
30964 nesqp->destroyed = 1;
30965
30966 /* Blow away the connection if it exists. */
30967 diff -urNp linux-2.6.39/drivers/infiniband/hw/qib/qib.h linux-2.6.39/drivers/infiniband/hw/qib/qib.h
30968 --- linux-2.6.39/drivers/infiniband/hw/qib/qib.h 2011-05-19 00:06:34.000000000 -0400
30969 +++ linux-2.6.39/drivers/infiniband/hw/qib/qib.h 2011-05-22 19:36:31.000000000 -0400
30970 @@ -51,6 +51,7 @@
30971 #include <linux/completion.h>
30972 #include <linux/kref.h>
30973 #include <linux/sched.h>
30974 +#include <linux/slab.h>
30975
30976 #include "qib_common.h"
30977 #include "qib_verbs.h"
30978 @@ -87,7 +88,7 @@ struct qlogic_ib_stats {
30979 };
30980
30981 extern struct qlogic_ib_stats qib_stats;
30982 -extern struct pci_error_handlers qib_pci_err_handler;
30983 +extern const struct pci_error_handlers qib_pci_err_handler;
30984 extern struct pci_driver qib_driver;
30985
30986 #define QIB_CHIP_SWVERSION QIB_CHIP_VERS_MAJ
30987 diff -urNp linux-2.6.39/drivers/infiniband/hw/qib/qib_mmap.c linux-2.6.39/drivers/infiniband/hw/qib/qib_mmap.c
30988 --- linux-2.6.39/drivers/infiniband/hw/qib/qib_mmap.c 2011-05-19 00:06:34.000000000 -0400
30989 +++ linux-2.6.39/drivers/infiniband/hw/qib/qib_mmap.c 2011-05-22 19:36:31.000000000 -0400
30990 @@ -75,7 +75,7 @@ static void qib_vma_close(struct vm_area
30991 kref_put(&ip->ref, qib_release_mmap_info);
30992 }
30993
30994 -static struct vm_operations_struct qib_vm_ops = {
30995 +static const struct vm_operations_struct qib_vm_ops = {
30996 .open = qib_vma_open,
30997 .close = qib_vma_close,
30998 };
30999 diff -urNp linux-2.6.39/drivers/infiniband/hw/qib/qib_pcie.c linux-2.6.39/drivers/infiniband/hw/qib/qib_pcie.c
31000 --- linux-2.6.39/drivers/infiniband/hw/qib/qib_pcie.c 2011-05-19 00:06:34.000000000 -0400
31001 +++ linux-2.6.39/drivers/infiniband/hw/qib/qib_pcie.c 2011-05-22 19:36:31.000000000 -0400
31002 @@ -735,7 +735,7 @@ qib_pci_resume(struct pci_dev *pdev)
31003 qib_init(dd, 1); /* same as re-init after reset */
31004 }
31005
31006 -struct pci_error_handlers qib_pci_err_handler = {
31007 +const struct pci_error_handlers qib_pci_err_handler = {
31008 .error_detected = qib_pci_error_detected,
31009 .mmio_enabled = qib_pci_mmio_enabled,
31010 .link_reset = qib_pci_link_reset,
31011 diff -urNp linux-2.6.39/drivers/input/gameport/gameport.c linux-2.6.39/drivers/input/gameport/gameport.c
31012 --- linux-2.6.39/drivers/input/gameport/gameport.c 2011-05-19 00:06:34.000000000 -0400
31013 +++ linux-2.6.39/drivers/input/gameport/gameport.c 2011-05-22 19:36:31.000000000 -0400
31014 @@ -488,14 +488,14 @@ EXPORT_SYMBOL(gameport_set_phys);
31015 */
31016 static void gameport_init_port(struct gameport *gameport)
31017 {
31018 - static atomic_t gameport_no = ATOMIC_INIT(0);
31019 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
31020
31021 __module_get(THIS_MODULE);
31022
31023 mutex_init(&gameport->drv_mutex);
31024 device_initialize(&gameport->dev);
31025 dev_set_name(&gameport->dev, "gameport%lu",
31026 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
31027 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
31028 gameport->dev.bus = &gameport_bus;
31029 gameport->dev.release = gameport_release_port;
31030 if (gameport->parent)
31031 diff -urNp linux-2.6.39/drivers/input/input.c linux-2.6.39/drivers/input/input.c
31032 --- linux-2.6.39/drivers/input/input.c 2011-05-19 00:06:34.000000000 -0400
31033 +++ linux-2.6.39/drivers/input/input.c 2011-05-22 19:36:31.000000000 -0400
31034 @@ -1815,7 +1815,7 @@ static void input_cleanse_bitmasks(struc
31035 */
31036 int input_register_device(struct input_dev *dev)
31037 {
31038 - static atomic_t input_no = ATOMIC_INIT(0);
31039 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
31040 struct input_handler *handler;
31041 const char *path;
31042 int error;
31043 @@ -1852,7 +1852,7 @@ int input_register_device(struct input_d
31044 dev->setkeycode = input_default_setkeycode;
31045
31046 dev_set_name(&dev->dev, "input%ld",
31047 - (unsigned long) atomic_inc_return(&input_no) - 1);
31048 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
31049
31050 error = device_add(&dev->dev);
31051 if (error)
31052 diff -urNp linux-2.6.39/drivers/input/joystick/sidewinder.c linux-2.6.39/drivers/input/joystick/sidewinder.c
31053 --- linux-2.6.39/drivers/input/joystick/sidewinder.c 2011-05-19 00:06:34.000000000 -0400
31054 +++ linux-2.6.39/drivers/input/joystick/sidewinder.c 2011-05-22 19:36:31.000000000 -0400
31055 @@ -30,6 +30,7 @@
31056 #include <linux/kernel.h>
31057 #include <linux/module.h>
31058 #include <linux/slab.h>
31059 +#include <linux/sched.h>
31060 #include <linux/init.h>
31061 #include <linux/input.h>
31062 #include <linux/gameport.h>
31063 @@ -428,6 +429,8 @@ static int sw_read(struct sw *sw)
31064 unsigned char buf[SW_LENGTH];
31065 int i;
31066
31067 + pax_track_stack();
31068 +
31069 i = sw_read_packet(sw->gameport, buf, sw->length, 0);
31070
31071 if (sw->type == SW_ID_3DP && sw->length == 66 && i != 66) { /* Broken packet, try to fix */
31072 diff -urNp linux-2.6.39/drivers/input/joystick/xpad.c linux-2.6.39/drivers/input/joystick/xpad.c
31073 --- linux-2.6.39/drivers/input/joystick/xpad.c 2011-05-19 00:06:34.000000000 -0400
31074 +++ linux-2.6.39/drivers/input/joystick/xpad.c 2011-05-22 19:36:31.000000000 -0400
31075 @@ -689,7 +689,7 @@ static void xpad_led_set(struct led_clas
31076
31077 static int xpad_led_probe(struct usb_xpad *xpad)
31078 {
31079 - static atomic_t led_seq = ATOMIC_INIT(0);
31080 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
31081 long led_no;
31082 struct xpad_led *led;
31083 struct led_classdev *led_cdev;
31084 @@ -702,7 +702,7 @@ static int xpad_led_probe(struct usb_xpa
31085 if (!led)
31086 return -ENOMEM;
31087
31088 - led_no = (long)atomic_inc_return(&led_seq) - 1;
31089 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
31090
31091 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
31092 led->xpad = xpad;
31093 diff -urNp linux-2.6.39/drivers/input/mousedev.c linux-2.6.39/drivers/input/mousedev.c
31094 --- linux-2.6.39/drivers/input/mousedev.c 2011-05-19 00:06:34.000000000 -0400
31095 +++ linux-2.6.39/drivers/input/mousedev.c 2011-05-22 19:36:31.000000000 -0400
31096 @@ -764,7 +764,7 @@ static ssize_t mousedev_read(struct file
31097
31098 spin_unlock_irq(&client->packet_lock);
31099
31100 - if (copy_to_user(buffer, data, count))
31101 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
31102 return -EFAULT;
31103
31104 return count;
31105 diff -urNp linux-2.6.39/drivers/input/serio/serio.c linux-2.6.39/drivers/input/serio/serio.c
31106 --- linux-2.6.39/drivers/input/serio/serio.c 2011-05-19 00:06:34.000000000 -0400
31107 +++ linux-2.6.39/drivers/input/serio/serio.c 2011-05-22 19:36:31.000000000 -0400
31108 @@ -497,7 +497,7 @@ static void serio_release_port(struct de
31109 */
31110 static void serio_init_port(struct serio *serio)
31111 {
31112 - static atomic_t serio_no = ATOMIC_INIT(0);
31113 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
31114
31115 __module_get(THIS_MODULE);
31116
31117 @@ -508,7 +508,7 @@ static void serio_init_port(struct serio
31118 mutex_init(&serio->drv_mutex);
31119 device_initialize(&serio->dev);
31120 dev_set_name(&serio->dev, "serio%ld",
31121 - (long)atomic_inc_return(&serio_no) - 1);
31122 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
31123 serio->dev.bus = &serio_bus;
31124 serio->dev.release = serio_release_port;
31125 serio->dev.groups = serio_device_attr_groups;
31126 diff -urNp linux-2.6.39/drivers/isdn/capi/capi.c linux-2.6.39/drivers/isdn/capi/capi.c
31127 --- linux-2.6.39/drivers/isdn/capi/capi.c 2011-05-19 00:06:34.000000000 -0400
31128 +++ linux-2.6.39/drivers/isdn/capi/capi.c 2011-05-22 19:36:31.000000000 -0400
31129 @@ -89,8 +89,8 @@ struct capiminor {
31130
31131 struct capi20_appl *ap;
31132 u32 ncci;
31133 - atomic_t datahandle;
31134 - atomic_t msgid;
31135 + atomic_unchecked_t datahandle;
31136 + atomic_unchecked_t msgid;
31137
31138 struct tty_port port;
31139 int ttyinstop;
31140 @@ -414,7 +414,7 @@ gen_data_b3_resp_for(struct capiminor *m
31141 capimsg_setu16(s, 2, mp->ap->applid);
31142 capimsg_setu8 (s, 4, CAPI_DATA_B3);
31143 capimsg_setu8 (s, 5, CAPI_RESP);
31144 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
31145 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
31146 capimsg_setu32(s, 8, mp->ncci);
31147 capimsg_setu16(s, 12, datahandle);
31148 }
31149 @@ -547,14 +547,14 @@ static void handle_minor_send(struct cap
31150 mp->outbytes -= len;
31151 spin_unlock_bh(&mp->outlock);
31152
31153 - datahandle = atomic_inc_return(&mp->datahandle);
31154 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
31155 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
31156 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
31157 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
31158 capimsg_setu16(skb->data, 2, mp->ap->applid);
31159 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
31160 capimsg_setu8 (skb->data, 5, CAPI_REQ);
31161 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
31162 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
31163 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
31164 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
31165 capimsg_setu16(skb->data, 16, len); /* Data length */
31166 diff -urNp linux-2.6.39/drivers/isdn/gigaset/common.c linux-2.6.39/drivers/isdn/gigaset/common.c
31167 --- linux-2.6.39/drivers/isdn/gigaset/common.c 2011-05-19 00:06:34.000000000 -0400
31168 +++ linux-2.6.39/drivers/isdn/gigaset/common.c 2011-05-22 19:36:31.000000000 -0400
31169 @@ -723,7 +723,7 @@ struct cardstate *gigaset_initcs(struct
31170 cs->commands_pending = 0;
31171 cs->cur_at_seq = 0;
31172 cs->gotfwver = -1;
31173 - cs->open_count = 0;
31174 + local_set(&cs->open_count, 0);
31175 cs->dev = NULL;
31176 cs->tty = NULL;
31177 cs->tty_dev = NULL;
31178 diff -urNp linux-2.6.39/drivers/isdn/gigaset/gigaset.h linux-2.6.39/drivers/isdn/gigaset/gigaset.h
31179 --- linux-2.6.39/drivers/isdn/gigaset/gigaset.h 2011-05-19 00:06:34.000000000 -0400
31180 +++ linux-2.6.39/drivers/isdn/gigaset/gigaset.h 2011-05-22 19:36:31.000000000 -0400
31181 @@ -35,6 +35,7 @@
31182 #include <linux/tty_driver.h>
31183 #include <linux/list.h>
31184 #include <asm/atomic.h>
31185 +#include <asm/local.h>
31186
31187 #define GIG_VERSION {0, 5, 0, 0}
31188 #define GIG_COMPAT {0, 4, 0, 0}
31189 @@ -433,7 +434,7 @@ struct cardstate {
31190 spinlock_t cmdlock;
31191 unsigned curlen, cmdbytes;
31192
31193 - unsigned open_count;
31194 + local_t open_count;
31195 struct tty_struct *tty;
31196 struct tasklet_struct if_wake_tasklet;
31197 unsigned control_state;
31198 diff -urNp linux-2.6.39/drivers/isdn/gigaset/interface.c linux-2.6.39/drivers/isdn/gigaset/interface.c
31199 --- linux-2.6.39/drivers/isdn/gigaset/interface.c 2011-05-19 00:06:34.000000000 -0400
31200 +++ linux-2.6.39/drivers/isdn/gigaset/interface.c 2011-05-22 19:36:31.000000000 -0400
31201 @@ -160,9 +160,7 @@ static int if_open(struct tty_struct *tt
31202 return -ERESTARTSYS;
31203 tty->driver_data = cs;
31204
31205 - ++cs->open_count;
31206 -
31207 - if (cs->open_count == 1) {
31208 + if (local_inc_return(&cs->open_count) == 1) {
31209 spin_lock_irqsave(&cs->lock, flags);
31210 cs->tty = tty;
31211 spin_unlock_irqrestore(&cs->lock, flags);
31212 @@ -190,10 +188,10 @@ static void if_close(struct tty_struct *
31213
31214 if (!cs->connected)
31215 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
31216 - else if (!cs->open_count)
31217 + else if (!local_read(&cs->open_count))
31218 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31219 else {
31220 - if (!--cs->open_count) {
31221 + if (!local_dec_return(&cs->open_count)) {
31222 spin_lock_irqsave(&cs->lock, flags);
31223 cs->tty = NULL;
31224 spin_unlock_irqrestore(&cs->lock, flags);
31225 @@ -228,7 +226,7 @@ static int if_ioctl(struct tty_struct *t
31226 if (!cs->connected) {
31227 gig_dbg(DEBUG_IF, "not connected");
31228 retval = -ENODEV;
31229 - } else if (!cs->open_count)
31230 + } else if (!local_read(&cs->open_count))
31231 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31232 else {
31233 retval = 0;
31234 @@ -358,7 +356,7 @@ static int if_write(struct tty_struct *t
31235 retval = -ENODEV;
31236 goto done;
31237 }
31238 - if (!cs->open_count) {
31239 + if (!local_read(&cs->open_count)) {
31240 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31241 retval = -ENODEV;
31242 goto done;
31243 @@ -411,7 +409,7 @@ static int if_write_room(struct tty_stru
31244 if (!cs->connected) {
31245 gig_dbg(DEBUG_IF, "not connected");
31246 retval = -ENODEV;
31247 - } else if (!cs->open_count)
31248 + } else if (!local_read(&cs->open_count))
31249 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31250 else if (cs->mstate != MS_LOCKED) {
31251 dev_warn(cs->dev, "can't write to unlocked device\n");
31252 @@ -441,7 +439,7 @@ static int if_chars_in_buffer(struct tty
31253
31254 if (!cs->connected)
31255 gig_dbg(DEBUG_IF, "not connected");
31256 - else if (!cs->open_count)
31257 + else if (!local_read(&cs->open_count))
31258 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31259 else if (cs->mstate != MS_LOCKED)
31260 dev_warn(cs->dev, "can't write to unlocked device\n");
31261 @@ -469,7 +467,7 @@ static void if_throttle(struct tty_struc
31262
31263 if (!cs->connected)
31264 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
31265 - else if (!cs->open_count)
31266 + else if (!local_read(&cs->open_count))
31267 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31268 else
31269 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
31270 @@ -493,7 +491,7 @@ static void if_unthrottle(struct tty_str
31271
31272 if (!cs->connected)
31273 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
31274 - else if (!cs->open_count)
31275 + else if (!local_read(&cs->open_count))
31276 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31277 else
31278 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
31279 @@ -524,7 +522,7 @@ static void if_set_termios(struct tty_st
31280 goto out;
31281 }
31282
31283 - if (!cs->open_count) {
31284 + if (!local_read(&cs->open_count)) {
31285 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31286 goto out;
31287 }
31288 diff -urNp linux-2.6.39/drivers/isdn/hardware/avm/b1.c linux-2.6.39/drivers/isdn/hardware/avm/b1.c
31289 --- linux-2.6.39/drivers/isdn/hardware/avm/b1.c 2011-05-19 00:06:34.000000000 -0400
31290 +++ linux-2.6.39/drivers/isdn/hardware/avm/b1.c 2011-05-22 19:36:31.000000000 -0400
31291 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capilo
31292 }
31293 if (left) {
31294 if (t4file->user) {
31295 - if (copy_from_user(buf, dp, left))
31296 + if (left > sizeof buf || copy_from_user(buf, dp, left))
31297 return -EFAULT;
31298 } else {
31299 memcpy(buf, dp, left);
31300 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capilo
31301 }
31302 if (left) {
31303 if (config->user) {
31304 - if (copy_from_user(buf, dp, left))
31305 + if (left > sizeof buf || copy_from_user(buf, dp, left))
31306 return -EFAULT;
31307 } else {
31308 memcpy(buf, dp, left);
31309 diff -urNp linux-2.6.39/drivers/isdn/hardware/eicon/capidtmf.c linux-2.6.39/drivers/isdn/hardware/eicon/capidtmf.c
31310 --- linux-2.6.39/drivers/isdn/hardware/eicon/capidtmf.c 2011-05-19 00:06:34.000000000 -0400
31311 +++ linux-2.6.39/drivers/isdn/hardware/eicon/capidtmf.c 2011-05-22 19:36:31.000000000 -0400
31312 @@ -498,6 +498,7 @@ void capidtmf_recv_block (t_capidtmf_sta
31313 byte goertzel_result_buffer[CAPIDTMF_RECV_TOTAL_FREQUENCY_COUNT];
31314 short windowed_sample_buffer[CAPIDTMF_RECV_WINDOWED_SAMPLES];
31315
31316 + pax_track_stack();
31317
31318 if (p_state->recv.state & CAPIDTMF_RECV_STATE_DTMF_ACTIVE)
31319 {
31320 diff -urNp linux-2.6.39/drivers/isdn/hardware/eicon/capifunc.c linux-2.6.39/drivers/isdn/hardware/eicon/capifunc.c
31321 --- linux-2.6.39/drivers/isdn/hardware/eicon/capifunc.c 2011-05-19 00:06:34.000000000 -0400
31322 +++ linux-2.6.39/drivers/isdn/hardware/eicon/capifunc.c 2011-05-22 19:36:31.000000000 -0400
31323 @@ -1055,6 +1055,8 @@ static int divacapi_connect_didd(void)
31324 IDI_SYNC_REQ req;
31325 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
31326
31327 + pax_track_stack();
31328 +
31329 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
31330
31331 for (x = 0; x < MAX_DESCRIPTORS; x++) {
31332 diff -urNp linux-2.6.39/drivers/isdn/hardware/eicon/diddfunc.c linux-2.6.39/drivers/isdn/hardware/eicon/diddfunc.c
31333 --- linux-2.6.39/drivers/isdn/hardware/eicon/diddfunc.c 2011-05-19 00:06:34.000000000 -0400
31334 +++ linux-2.6.39/drivers/isdn/hardware/eicon/diddfunc.c 2011-05-22 19:36:31.000000000 -0400
31335 @@ -54,6 +54,8 @@ static int DIVA_INIT_FUNCTION connect_di
31336 IDI_SYNC_REQ req;
31337 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
31338
31339 + pax_track_stack();
31340 +
31341 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
31342
31343 for (x = 0; x < MAX_DESCRIPTORS; x++) {
31344 diff -urNp linux-2.6.39/drivers/isdn/hardware/eicon/divasfunc.c linux-2.6.39/drivers/isdn/hardware/eicon/divasfunc.c
31345 --- linux-2.6.39/drivers/isdn/hardware/eicon/divasfunc.c 2011-05-19 00:06:34.000000000 -0400
31346 +++ linux-2.6.39/drivers/isdn/hardware/eicon/divasfunc.c 2011-05-22 19:36:31.000000000 -0400
31347 @@ -161,6 +161,8 @@ static int DIVA_INIT_FUNCTION connect_di
31348 IDI_SYNC_REQ req;
31349 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
31350
31351 + pax_track_stack();
31352 +
31353 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
31354
31355 for (x = 0; x < MAX_DESCRIPTORS; x++) {
31356 diff -urNp linux-2.6.39/drivers/isdn/hardware/eicon/idifunc.c linux-2.6.39/drivers/isdn/hardware/eicon/idifunc.c
31357 --- linux-2.6.39/drivers/isdn/hardware/eicon/idifunc.c 2011-05-19 00:06:34.000000000 -0400
31358 +++ linux-2.6.39/drivers/isdn/hardware/eicon/idifunc.c 2011-05-22 19:36:31.000000000 -0400
31359 @@ -188,6 +188,8 @@ static int DIVA_INIT_FUNCTION connect_di
31360 IDI_SYNC_REQ req;
31361 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
31362
31363 + pax_track_stack();
31364 +
31365 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
31366
31367 for (x = 0; x < MAX_DESCRIPTORS; x++) {
31368 diff -urNp linux-2.6.39/drivers/isdn/hardware/eicon/message.c linux-2.6.39/drivers/isdn/hardware/eicon/message.c
31369 --- linux-2.6.39/drivers/isdn/hardware/eicon/message.c 2011-05-19 00:06:34.000000000 -0400
31370 +++ linux-2.6.39/drivers/isdn/hardware/eicon/message.c 2011-05-22 19:36:31.000000000 -0400
31371 @@ -4889,6 +4889,8 @@ static void sig_ind(PLCI *plci)
31372 dword d;
31373 word w;
31374
31375 + pax_track_stack();
31376 +
31377 a = plci->adapter;
31378 Id = ((word)plci->Id<<8)|a->Id;
31379 PUT_WORD(&SS_Ind[4],0x0000);
31380 @@ -7484,6 +7486,8 @@ static word add_b1(PLCI *plci, API_PARSE
31381 word j, n, w;
31382 dword d;
31383
31384 + pax_track_stack();
31385 +
31386
31387 for(i=0;i<8;i++) bp_parms[i].length = 0;
31388 for(i=0;i<2;i++) global_config[i].length = 0;
31389 @@ -7958,6 +7962,8 @@ static word add_b23(PLCI *plci, API_PARS
31390 const byte llc3[] = {4,3,2,2,6,6,0};
31391 const byte header[] = {0,2,3,3,0,0,0};
31392
31393 + pax_track_stack();
31394 +
31395 for(i=0;i<8;i++) bp_parms[i].length = 0;
31396 for(i=0;i<6;i++) b2_config_parms[i].length = 0;
31397 for(i=0;i<5;i++) b3_config_parms[i].length = 0;
31398 @@ -14760,6 +14766,8 @@ static void group_optimization(DIVA_CAPI
31399 word appl_number_group_type[MAX_APPL];
31400 PLCI *auxplci;
31401
31402 + pax_track_stack();
31403 +
31404 set_group_ind_mask (plci); /* all APPLs within this inc. call are allowed to dial in */
31405
31406 if(!a->group_optimization_enabled)
31407 diff -urNp linux-2.6.39/drivers/isdn/hardware/eicon/mntfunc.c linux-2.6.39/drivers/isdn/hardware/eicon/mntfunc.c
31408 --- linux-2.6.39/drivers/isdn/hardware/eicon/mntfunc.c 2011-05-19 00:06:34.000000000 -0400
31409 +++ linux-2.6.39/drivers/isdn/hardware/eicon/mntfunc.c 2011-05-22 19:36:31.000000000 -0400
31410 @@ -79,6 +79,8 @@ static int DIVA_INIT_FUNCTION connect_di
31411 IDI_SYNC_REQ req;
31412 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
31413
31414 + pax_track_stack();
31415 +
31416 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
31417
31418 for (x = 0; x < MAX_DESCRIPTORS; x++) {
31419 diff -urNp linux-2.6.39/drivers/isdn/i4l/isdn_common.c linux-2.6.39/drivers/isdn/i4l/isdn_common.c
31420 --- linux-2.6.39/drivers/isdn/i4l/isdn_common.c 2011-05-19 00:06:34.000000000 -0400
31421 +++ linux-2.6.39/drivers/isdn/i4l/isdn_common.c 2011-05-22 19:36:31.000000000 -0400
31422 @@ -1292,6 +1292,8 @@ isdn_ioctl(struct file *file, uint cmd,
31423 } iocpar;
31424 void __user *argp = (void __user *)arg;
31425
31426 + pax_track_stack();
31427 +
31428 #define name iocpar.name
31429 #define bname iocpar.bname
31430 #define iocts iocpar.iocts
31431 diff -urNp linux-2.6.39/drivers/isdn/i4l/isdn_net.c linux-2.6.39/drivers/isdn/i4l/isdn_net.c
31432 --- linux-2.6.39/drivers/isdn/i4l/isdn_net.c 2011-05-19 00:06:34.000000000 -0400
31433 +++ linux-2.6.39/drivers/isdn/i4l/isdn_net.c 2011-05-22 19:36:31.000000000 -0400
31434 @@ -400,7 +400,7 @@ isdn_net_stat_callback(int idx, isdn_ctr
31435 isdn_net_local *lp = p->local;
31436 #ifdef CONFIG_ISDN_X25
31437 struct concap_proto *cprot = lp->netdev->cprot;
31438 - struct concap_proto_ops *pops = cprot ? cprot->pops : NULL;
31439 + const struct concap_proto_ops *pops = cprot ? cprot->pops : NULL;
31440 #endif
31441 switch (cmd) {
31442 case ISDN_STAT_BSENT:
31443 @@ -831,7 +831,7 @@ isdn_net_hangup(struct net_device *d)
31444 isdn_ctrl cmd;
31445 #ifdef CONFIG_ISDN_X25
31446 struct concap_proto *cprot = lp->netdev->cprot;
31447 - struct concap_proto_ops *pops = cprot ? cprot->pops : NULL;
31448 + const struct concap_proto_ops *pops = cprot ? cprot->pops : NULL;
31449 #endif
31450
31451 if (lp->flags & ISDN_NET_CONNECTED) {
31452 diff -urNp linux-2.6.39/drivers/isdn/i4l/isdn_x25iface.c linux-2.6.39/drivers/isdn/i4l/isdn_x25iface.c
31453 --- linux-2.6.39/drivers/isdn/i4l/isdn_x25iface.c 2011-05-19 00:06:34.000000000 -0400
31454 +++ linux-2.6.39/drivers/isdn/i4l/isdn_x25iface.c 2011-05-22 19:36:31.000000000 -0400
31455 @@ -52,7 +52,7 @@ static int isdn_x25iface_connect_ind( st
31456 static int isdn_x25iface_disconn_ind( struct concap_proto * );
31457
31458
31459 -static struct concap_proto_ops ix25_pops = {
31460 +static const struct concap_proto_ops ix25_pops = {
31461 &isdn_x25iface_proto_new,
31462 &isdn_x25iface_proto_del,
31463 &isdn_x25iface_proto_restart,
31464 diff -urNp linux-2.6.39/drivers/isdn/i4l/isdn_x25iface.h linux-2.6.39/drivers/isdn/i4l/isdn_x25iface.h
31465 --- linux-2.6.39/drivers/isdn/i4l/isdn_x25iface.h 2011-05-19 00:06:34.000000000 -0400
31466 +++ linux-2.6.39/drivers/isdn/i4l/isdn_x25iface.h 2011-05-22 19:36:31.000000000 -0400
31467 @@ -23,7 +23,7 @@
31468 #include <linux/isdn.h>
31469 #include <linux/concap.h>
31470
31471 -extern struct concap_proto_ops * isdn_x25iface_concap_proto_ops_pt;
31472 +extern const struct concap_proto_ops *isdn_x25iface_concap_proto_ops_pt;
31473 extern struct concap_proto * isdn_x25iface_proto_new(void);
31474
31475
31476 diff -urNp linux-2.6.39/drivers/isdn/icn/icn.c linux-2.6.39/drivers/isdn/icn/icn.c
31477 --- linux-2.6.39/drivers/isdn/icn/icn.c 2011-05-19 00:06:34.000000000 -0400
31478 +++ linux-2.6.39/drivers/isdn/icn/icn.c 2011-05-22 19:36:31.000000000 -0400
31479 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char * buf, int len
31480 if (count > len)
31481 count = len;
31482 if (user) {
31483 - if (copy_from_user(msg, buf, count))
31484 + if (count > sizeof msg || copy_from_user(msg, buf, count))
31485 return -EFAULT;
31486 } else
31487 memcpy(msg, buf, count);
31488 diff -urNp linux-2.6.39/drivers/lguest/core.c linux-2.6.39/drivers/lguest/core.c
31489 --- linux-2.6.39/drivers/lguest/core.c 2011-05-19 00:06:34.000000000 -0400
31490 +++ linux-2.6.39/drivers/lguest/core.c 2011-05-22 19:36:31.000000000 -0400
31491 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
31492 * it's worked so far. The end address needs +1 because __get_vm_area
31493 * allocates an extra guard page, so we need space for that.
31494 */
31495 +
31496 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31497 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
31498 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
31499 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
31500 +#else
31501 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
31502 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
31503 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
31504 +#endif
31505 +
31506 if (!switcher_vma) {
31507 err = -ENOMEM;
31508 printk("lguest: could not map switcher pages high\n");
31509 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
31510 * Now the Switcher is mapped at the right address, we can't fail!
31511 * Copy in the compiled-in Switcher code (from <arch>_switcher.S).
31512 */
31513 - memcpy(switcher_vma->addr, start_switcher_text,
31514 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
31515 end_switcher_text - start_switcher_text);
31516
31517 printk(KERN_INFO "lguest: mapped switcher at %p\n",
31518 diff -urNp linux-2.6.39/drivers/lguest/lguest_device.c linux-2.6.39/drivers/lguest/lguest_device.c
31519 --- linux-2.6.39/drivers/lguest/lguest_device.c 2011-05-19 00:06:34.000000000 -0400
31520 +++ linux-2.6.39/drivers/lguest/lguest_device.c 2011-05-22 19:36:31.000000000 -0400
31521 @@ -374,7 +374,7 @@ error:
31522 }
31523
31524 /* The ops structure which hooks everything together. */
31525 -static struct virtio_config_ops lguest_config_ops = {
31526 +static const struct virtio_config_ops lguest_config_ops = {
31527 .get_features = lg_get_features,
31528 .finalize_features = lg_finalize_features,
31529 .get = lg_get,
31530 diff -urNp linux-2.6.39/drivers/lguest/x86/core.c linux-2.6.39/drivers/lguest/x86/core.c
31531 --- linux-2.6.39/drivers/lguest/x86/core.c 2011-05-19 00:06:34.000000000 -0400
31532 +++ linux-2.6.39/drivers/lguest/x86/core.c 2011-05-22 19:36:31.000000000 -0400
31533 @@ -59,7 +59,7 @@ static struct {
31534 /* Offset from where switcher.S was compiled to where we've copied it */
31535 static unsigned long switcher_offset(void)
31536 {
31537 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
31538 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
31539 }
31540
31541 /* This cpu's struct lguest_pages. */
31542 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg
31543 * These copies are pretty cheap, so we do them unconditionally: */
31544 /* Save the current Host top-level page directory.
31545 */
31546 +
31547 +#ifdef CONFIG_PAX_PER_CPU_PGD
31548 + pages->state.host_cr3 = read_cr3();
31549 +#else
31550 pages->state.host_cr3 = __pa(current->mm->pgd);
31551 +#endif
31552 +
31553 /*
31554 * Set up the Guest's page tables to see this CPU's pages (and no
31555 * other CPU's pages).
31556 @@ -547,7 +553,7 @@ void __init lguest_arch_host_init(void)
31557 * compiled-in switcher code and the high-mapped copy we just made.
31558 */
31559 for (i = 0; i < IDT_ENTRIES; i++)
31560 - default_idt_entries[i] += switcher_offset();
31561 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
31562
31563 /*
31564 * Set up the Switcher's per-cpu areas.
31565 @@ -630,7 +636,7 @@ void __init lguest_arch_host_init(void)
31566 * it will be undisturbed when we switch. To change %cs and jump we
31567 * need this structure to feed to Intel's "lcall" instruction.
31568 */
31569 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
31570 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
31571 lguest_entry.segment = LGUEST_CS;
31572
31573 /*
31574 diff -urNp linux-2.6.39/drivers/lguest/x86/switcher_32.S linux-2.6.39/drivers/lguest/x86/switcher_32.S
31575 --- linux-2.6.39/drivers/lguest/x86/switcher_32.S 2011-05-19 00:06:34.000000000 -0400
31576 +++ linux-2.6.39/drivers/lguest/x86/switcher_32.S 2011-05-22 19:36:31.000000000 -0400
31577 @@ -87,6 +87,7 @@
31578 #include <asm/page.h>
31579 #include <asm/segment.h>
31580 #include <asm/lguest.h>
31581 +#include <asm/processor-flags.h>
31582
31583 // We mark the start of the code to copy
31584 // It's placed in .text tho it's never run here
31585 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
31586 // Changes type when we load it: damn Intel!
31587 // For after we switch over our page tables
31588 // That entry will be read-only: we'd crash.
31589 +
31590 +#ifdef CONFIG_PAX_KERNEXEC
31591 + mov %cr0, %edx
31592 + xor $X86_CR0_WP, %edx
31593 + mov %edx, %cr0
31594 +#endif
31595 +
31596 movl $(GDT_ENTRY_TSS*8), %edx
31597 ltr %dx
31598
31599 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
31600 // Let's clear it again for our return.
31601 // The GDT descriptor of the Host
31602 // Points to the table after two "size" bytes
31603 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
31604 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
31605 // Clear "used" from type field (byte 5, bit 2)
31606 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
31607 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
31608 +
31609 +#ifdef CONFIG_PAX_KERNEXEC
31610 + mov %cr0, %eax
31611 + xor $X86_CR0_WP, %eax
31612 + mov %eax, %cr0
31613 +#endif
31614
31615 // Once our page table's switched, the Guest is live!
31616 // The Host fades as we run this final step.
31617 @@ -295,13 +309,12 @@ deliver_to_host:
31618 // I consulted gcc, and it gave
31619 // These instructions, which I gladly credit:
31620 leal (%edx,%ebx,8), %eax
31621 - movzwl (%eax),%edx
31622 - movl 4(%eax), %eax
31623 - xorw %ax, %ax
31624 - orl %eax, %edx
31625 + movl 4(%eax), %edx
31626 + movw (%eax), %dx
31627 // Now the address of the handler's in %edx
31628 // We call it now: its "iret" drops us home.
31629 - jmp *%edx
31630 + ljmp $__KERNEL_CS, $1f
31631 +1: jmp *%edx
31632
31633 // Every interrupt can come to us here
31634 // But we must truly tell each apart.
31635 diff -urNp linux-2.6.39/drivers/md/dm.c linux-2.6.39/drivers/md/dm.c
31636 --- linux-2.6.39/drivers/md/dm.c 2011-05-19 00:06:34.000000000 -0400
31637 +++ linux-2.6.39/drivers/md/dm.c 2011-05-22 19:36:31.000000000 -0400
31638 @@ -162,9 +162,9 @@ struct mapped_device {
31639 /*
31640 * Event handling.
31641 */
31642 - atomic_t event_nr;
31643 + atomic_unchecked_t event_nr;
31644 wait_queue_head_t eventq;
31645 - atomic_t uevent_seq;
31646 + atomic_unchecked_t uevent_seq;
31647 struct list_head uevent_list;
31648 spinlock_t uevent_lock; /* Protect access to uevent_list */
31649
31650 @@ -1836,8 +1836,8 @@ static struct mapped_device *alloc_dev(i
31651 rwlock_init(&md->map_lock);
31652 atomic_set(&md->holders, 1);
31653 atomic_set(&md->open_count, 0);
31654 - atomic_set(&md->event_nr, 0);
31655 - atomic_set(&md->uevent_seq, 0);
31656 + atomic_set_unchecked(&md->event_nr, 0);
31657 + atomic_set_unchecked(&md->uevent_seq, 0);
31658 INIT_LIST_HEAD(&md->uevent_list);
31659 spin_lock_init(&md->uevent_lock);
31660
31661 @@ -1971,7 +1971,7 @@ static void event_callback(void *context
31662
31663 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
31664
31665 - atomic_inc(&md->event_nr);
31666 + atomic_inc_unchecked(&md->event_nr);
31667 wake_up(&md->eventq);
31668 }
31669
31670 @@ -2547,18 +2547,18 @@ int dm_kobject_uevent(struct mapped_devi
31671
31672 uint32_t dm_next_uevent_seq(struct mapped_device *md)
31673 {
31674 - return atomic_add_return(1, &md->uevent_seq);
31675 + return atomic_add_return_unchecked(1, &md->uevent_seq);
31676 }
31677
31678 uint32_t dm_get_event_nr(struct mapped_device *md)
31679 {
31680 - return atomic_read(&md->event_nr);
31681 + return atomic_read_unchecked(&md->event_nr);
31682 }
31683
31684 int dm_wait_event(struct mapped_device *md, int event_nr)
31685 {
31686 return wait_event_interruptible(md->eventq,
31687 - (event_nr != atomic_read(&md->event_nr)));
31688 + (event_nr != atomic_read_unchecked(&md->event_nr)));
31689 }
31690
31691 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
31692 diff -urNp linux-2.6.39/drivers/md/dm-crypt.c linux-2.6.39/drivers/md/dm-crypt.c
31693 --- linux-2.6.39/drivers/md/dm-crypt.c 2011-05-19 00:06:34.000000000 -0400
31694 +++ linux-2.6.39/drivers/md/dm-crypt.c 2011-05-22 19:36:31.000000000 -0400
31695 @@ -138,7 +138,7 @@ struct crypt_config {
31696 char *cipher;
31697 char *cipher_string;
31698
31699 - struct crypt_iv_operations *iv_gen_ops;
31700 + const struct crypt_iv_operations *iv_gen_ops;
31701 union {
31702 struct iv_essiv_private essiv;
31703 struct iv_benbi_private benbi;
31704 @@ -620,15 +620,15 @@ static int crypt_iv_lmk_post(struct cryp
31705 return r;
31706 }
31707
31708 -static struct crypt_iv_operations crypt_iv_plain_ops = {
31709 +static const struct crypt_iv_operations crypt_iv_plain_ops = {
31710 .generator = crypt_iv_plain_gen
31711 };
31712
31713 -static struct crypt_iv_operations crypt_iv_plain64_ops = {
31714 +static const struct crypt_iv_operations crypt_iv_plain64_ops = {
31715 .generator = crypt_iv_plain64_gen
31716 };
31717
31718 -static struct crypt_iv_operations crypt_iv_essiv_ops = {
31719 +static const struct crypt_iv_operations crypt_iv_essiv_ops = {
31720 .ctr = crypt_iv_essiv_ctr,
31721 .dtr = crypt_iv_essiv_dtr,
31722 .init = crypt_iv_essiv_init,
31723 @@ -636,17 +636,17 @@ static struct crypt_iv_operations crypt_
31724 .generator = crypt_iv_essiv_gen
31725 };
31726
31727 -static struct crypt_iv_operations crypt_iv_benbi_ops = {
31728 +static const struct crypt_iv_operations crypt_iv_benbi_ops = {
31729 .ctr = crypt_iv_benbi_ctr,
31730 .dtr = crypt_iv_benbi_dtr,
31731 .generator = crypt_iv_benbi_gen
31732 };
31733
31734 -static struct crypt_iv_operations crypt_iv_null_ops = {
31735 +static const struct crypt_iv_operations crypt_iv_null_ops = {
31736 .generator = crypt_iv_null_gen
31737 };
31738
31739 -static struct crypt_iv_operations crypt_iv_lmk_ops = {
31740 +static const struct crypt_iv_operations crypt_iv_lmk_ops = {
31741 .ctr = crypt_iv_lmk_ctr,
31742 .dtr = crypt_iv_lmk_dtr,
31743 .init = crypt_iv_lmk_init,
31744 diff -urNp linux-2.6.39/drivers/md/dm-ioctl.c linux-2.6.39/drivers/md/dm-ioctl.c
31745 --- linux-2.6.39/drivers/md/dm-ioctl.c 2011-05-19 00:06:34.000000000 -0400
31746 +++ linux-2.6.39/drivers/md/dm-ioctl.c 2011-05-22 19:36:31.000000000 -0400
31747 @@ -1551,7 +1551,7 @@ static int validate_params(uint cmd, str
31748 cmd == DM_LIST_VERSIONS_CMD)
31749 return 0;
31750
31751 - if ((cmd == DM_DEV_CREATE_CMD)) {
31752 + if (cmd == DM_DEV_CREATE_CMD) {
31753 if (!*param->name) {
31754 DMWARN("name not supplied when creating device");
31755 return -EINVAL;
31756 diff -urNp linux-2.6.39/drivers/md/dm-raid1.c linux-2.6.39/drivers/md/dm-raid1.c
31757 --- linux-2.6.39/drivers/md/dm-raid1.c 2011-05-19 00:06:34.000000000 -0400
31758 +++ linux-2.6.39/drivers/md/dm-raid1.c 2011-05-22 19:36:31.000000000 -0400
31759 @@ -42,7 +42,7 @@ enum dm_raid1_error {
31760
31761 struct mirror {
31762 struct mirror_set *ms;
31763 - atomic_t error_count;
31764 + atomic_unchecked_t error_count;
31765 unsigned long error_type;
31766 struct dm_dev *dev;
31767 sector_t offset;
31768 @@ -187,7 +187,7 @@ static struct mirror *get_valid_mirror(s
31769 struct mirror *m;
31770
31771 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
31772 - if (!atomic_read(&m->error_count))
31773 + if (!atomic_read_unchecked(&m->error_count))
31774 return m;
31775
31776 return NULL;
31777 @@ -219,7 +219,7 @@ static void fail_mirror(struct mirror *m
31778 * simple way to tell if a device has encountered
31779 * errors.
31780 */
31781 - atomic_inc(&m->error_count);
31782 + atomic_inc_unchecked(&m->error_count);
31783
31784 if (test_and_set_bit(error_type, &m->error_type))
31785 return;
31786 @@ -410,7 +410,7 @@ static struct mirror *choose_mirror(stru
31787 struct mirror *m = get_default_mirror(ms);
31788
31789 do {
31790 - if (likely(!atomic_read(&m->error_count)))
31791 + if (likely(!atomic_read_unchecked(&m->error_count)))
31792 return m;
31793
31794 if (m-- == ms->mirror)
31795 @@ -424,7 +424,7 @@ static int default_ok(struct mirror *m)
31796 {
31797 struct mirror *default_mirror = get_default_mirror(m->ms);
31798
31799 - return !atomic_read(&default_mirror->error_count);
31800 + return !atomic_read_unchecked(&default_mirror->error_count);
31801 }
31802
31803 static int mirror_available(struct mirror_set *ms, struct bio *bio)
31804 @@ -561,7 +561,7 @@ static void do_reads(struct mirror_set *
31805 */
31806 if (likely(region_in_sync(ms, region, 1)))
31807 m = choose_mirror(ms, bio->bi_sector);
31808 - else if (m && atomic_read(&m->error_count))
31809 + else if (m && atomic_read_unchecked(&m->error_count))
31810 m = NULL;
31811
31812 if (likely(m))
31813 @@ -939,7 +939,7 @@ static int get_mirror(struct mirror_set
31814 }
31815
31816 ms->mirror[mirror].ms = ms;
31817 - atomic_set(&(ms->mirror[mirror].error_count), 0);
31818 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
31819 ms->mirror[mirror].error_type = 0;
31820 ms->mirror[mirror].offset = offset;
31821
31822 @@ -1347,7 +1347,7 @@ static void mirror_resume(struct dm_targ
31823 */
31824 static char device_status_char(struct mirror *m)
31825 {
31826 - if (!atomic_read(&(m->error_count)))
31827 + if (!atomic_read_unchecked(&(m->error_count)))
31828 return 'A';
31829
31830 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
31831 diff -urNp linux-2.6.39/drivers/md/dm-stripe.c linux-2.6.39/drivers/md/dm-stripe.c
31832 --- linux-2.6.39/drivers/md/dm-stripe.c 2011-05-19 00:06:34.000000000 -0400
31833 +++ linux-2.6.39/drivers/md/dm-stripe.c 2011-05-22 19:36:31.000000000 -0400
31834 @@ -20,7 +20,7 @@ struct stripe {
31835 struct dm_dev *dev;
31836 sector_t physical_start;
31837
31838 - atomic_t error_count;
31839 + atomic_unchecked_t error_count;
31840 };
31841
31842 struct stripe_c {
31843 @@ -192,7 +192,7 @@ static int stripe_ctr(struct dm_target *
31844 kfree(sc);
31845 return r;
31846 }
31847 - atomic_set(&(sc->stripe[i].error_count), 0);
31848 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
31849 }
31850
31851 ti->private = sc;
31852 @@ -314,7 +314,7 @@ static int stripe_status(struct dm_targe
31853 DMEMIT("%d ", sc->stripes);
31854 for (i = 0; i < sc->stripes; i++) {
31855 DMEMIT("%s ", sc->stripe[i].dev->name);
31856 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
31857 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
31858 'D' : 'A';
31859 }
31860 buffer[i] = '\0';
31861 @@ -361,8 +361,8 @@ static int stripe_end_io(struct dm_targe
31862 */
31863 for (i = 0; i < sc->stripes; i++)
31864 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
31865 - atomic_inc(&(sc->stripe[i].error_count));
31866 - if (atomic_read(&(sc->stripe[i].error_count)) <
31867 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
31868 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
31869 DM_IO_ERROR_THRESHOLD)
31870 schedule_work(&sc->trigger_event);
31871 }
31872 diff -urNp linux-2.6.39/drivers/md/dm-table.c linux-2.6.39/drivers/md/dm-table.c
31873 --- linux-2.6.39/drivers/md/dm-table.c 2011-05-19 00:06:34.000000000 -0400
31874 +++ linux-2.6.39/drivers/md/dm-table.c 2011-05-22 19:36:31.000000000 -0400
31875 @@ -373,7 +373,7 @@ static int device_area_is_invalid(struct
31876 if (!dev_size)
31877 return 0;
31878
31879 - if ((start >= dev_size) || (start + len > dev_size)) {
31880 + if ((start >= dev_size) || (len > dev_size - start)) {
31881 DMWARN("%s: %s too small for target: "
31882 "start=%llu, len=%llu, dev_size=%llu",
31883 dm_device_name(ti->table->md), bdevname(bdev, b),
31884 diff -urNp linux-2.6.39/drivers/md/md.c linux-2.6.39/drivers/md/md.c
31885 --- linux-2.6.39/drivers/md/md.c 2011-05-19 00:06:34.000000000 -0400
31886 +++ linux-2.6.39/drivers/md/md.c 2011-05-22 19:36:31.000000000 -0400
31887 @@ -226,10 +226,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
31888 * start build, activate spare
31889 */
31890 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
31891 -static atomic_t md_event_count;
31892 +static atomic_unchecked_t md_event_count;
31893 void md_new_event(mddev_t *mddev)
31894 {
31895 - atomic_inc(&md_event_count);
31896 + atomic_inc_unchecked(&md_event_count);
31897 wake_up(&md_event_waiters);
31898 }
31899 EXPORT_SYMBOL_GPL(md_new_event);
31900 @@ -239,7 +239,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
31901 */
31902 static void md_new_event_inintr(mddev_t *mddev)
31903 {
31904 - atomic_inc(&md_event_count);
31905 + atomic_inc_unchecked(&md_event_count);
31906 wake_up(&md_event_waiters);
31907 }
31908
31909 @@ -1454,7 +1454,7 @@ static int super_1_load(mdk_rdev_t *rdev
31910
31911 rdev->preferred_minor = 0xffff;
31912 rdev->data_offset = le64_to_cpu(sb->data_offset);
31913 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
31914 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
31915
31916 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
31917 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
31918 @@ -1632,7 +1632,7 @@ static void super_1_sync(mddev_t *mddev,
31919 else
31920 sb->resync_offset = cpu_to_le64(0);
31921
31922 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
31923 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
31924
31925 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
31926 sb->size = cpu_to_le64(mddev->dev_sectors);
31927 @@ -2414,7 +2414,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_sho
31928 static ssize_t
31929 errors_show(mdk_rdev_t *rdev, char *page)
31930 {
31931 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
31932 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
31933 }
31934
31935 static ssize_t
31936 @@ -2423,7 +2423,7 @@ errors_store(mdk_rdev_t *rdev, const cha
31937 char *e;
31938 unsigned long n = simple_strtoul(buf, &e, 10);
31939 if (*buf && (*e == 0 || *e == '\n')) {
31940 - atomic_set(&rdev->corrected_errors, n);
31941 + atomic_set_unchecked(&rdev->corrected_errors, n);
31942 return len;
31943 }
31944 return -EINVAL;
31945 @@ -2779,8 +2779,8 @@ void md_rdev_init(mdk_rdev_t *rdev)
31946 rdev->last_read_error.tv_sec = 0;
31947 rdev->last_read_error.tv_nsec = 0;
31948 atomic_set(&rdev->nr_pending, 0);
31949 - atomic_set(&rdev->read_errors, 0);
31950 - atomic_set(&rdev->corrected_errors, 0);
31951 + atomic_set_unchecked(&rdev->read_errors, 0);
31952 + atomic_set_unchecked(&rdev->corrected_errors, 0);
31953
31954 INIT_LIST_HEAD(&rdev->same_set);
31955 init_waitqueue_head(&rdev->blocked_wait);
31956 @@ -6383,7 +6383,7 @@ static int md_seq_show(struct seq_file *
31957
31958 spin_unlock(&pers_lock);
31959 seq_printf(seq, "\n");
31960 - mi->event = atomic_read(&md_event_count);
31961 + mi->event = atomic_read_unchecked(&md_event_count);
31962 return 0;
31963 }
31964 if (v == (void*)2) {
31965 @@ -6472,7 +6472,7 @@ static int md_seq_show(struct seq_file *
31966 chunk_kb ? "KB" : "B");
31967 if (bitmap->file) {
31968 seq_printf(seq, ", file: ");
31969 - seq_path(seq, &bitmap->file->f_path, " \t\n");
31970 + seq_path(seq, &bitmap->file->f_path, " \t\n\\");
31971 }
31972
31973 seq_printf(seq, "\n");
31974 @@ -6506,7 +6506,7 @@ static int md_seq_open(struct inode *ino
31975 else {
31976 struct seq_file *p = file->private_data;
31977 p->private = mi;
31978 - mi->event = atomic_read(&md_event_count);
31979 + mi->event = atomic_read_unchecked(&md_event_count);
31980 }
31981 return error;
31982 }
31983 @@ -6522,7 +6522,7 @@ static unsigned int mdstat_poll(struct f
31984 /* always allow read */
31985 mask = POLLIN | POLLRDNORM;
31986
31987 - if (mi->event != atomic_read(&md_event_count))
31988 + if (mi->event != atomic_read_unchecked(&md_event_count))
31989 mask |= POLLERR | POLLPRI;
31990 return mask;
31991 }
31992 @@ -6566,7 +6566,7 @@ static int is_mddev_idle(mddev_t *mddev,
31993 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
31994 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
31995 (int)part_stat_read(&disk->part0, sectors[1]) -
31996 - atomic_read(&disk->sync_io);
31997 + atomic_read_unchecked(&disk->sync_io);
31998 /* sync IO will cause sync_io to increase before the disk_stats
31999 * as sync_io is counted when a request starts, and
32000 * disk_stats is counted when it completes.
32001 diff -urNp linux-2.6.39/drivers/md/md.h linux-2.6.39/drivers/md/md.h
32002 --- linux-2.6.39/drivers/md/md.h 2011-05-19 00:06:34.000000000 -0400
32003 +++ linux-2.6.39/drivers/md/md.h 2011-05-22 19:36:31.000000000 -0400
32004 @@ -97,13 +97,13 @@ struct mdk_rdev_s
32005 * only maintained for arrays that
32006 * support hot removal
32007 */
32008 - atomic_t read_errors; /* number of consecutive read errors that
32009 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
32010 * we have tried to ignore.
32011 */
32012 struct timespec last_read_error; /* monotonic time since our
32013 * last read error
32014 */
32015 - atomic_t corrected_errors; /* number of corrected read errors,
32016 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
32017 * for reporting to userspace and storing
32018 * in superblock.
32019 */
32020 @@ -342,7 +342,7 @@ static inline void rdev_dec_pending(mdk_
32021
32022 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
32023 {
32024 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
32025 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
32026 }
32027
32028 struct mdk_personality
32029 diff -urNp linux-2.6.39/drivers/md/raid10.c linux-2.6.39/drivers/md/raid10.c
32030 --- linux-2.6.39/drivers/md/raid10.c 2011-05-19 00:06:34.000000000 -0400
32031 +++ linux-2.6.39/drivers/md/raid10.c 2011-05-22 19:36:31.000000000 -0400
32032 @@ -1209,7 +1209,7 @@ static void end_sync_read(struct bio *bi
32033 if (test_bit(BIO_UPTODATE, &bio->bi_flags))
32034 set_bit(R10BIO_Uptodate, &r10_bio->state);
32035 else {
32036 - atomic_add(r10_bio->sectors,
32037 + atomic_add_unchecked(r10_bio->sectors,
32038 &conf->mirrors[d].rdev->corrected_errors);
32039 if (!test_bit(MD_RECOVERY_SYNC, &conf->mddev->recovery))
32040 md_error(r10_bio->mddev,
32041 @@ -1417,7 +1417,7 @@ static void check_decay_read_errors(mdde
32042 {
32043 struct timespec cur_time_mon;
32044 unsigned long hours_since_last;
32045 - unsigned int read_errors = atomic_read(&rdev->read_errors);
32046 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
32047
32048 ktime_get_ts(&cur_time_mon);
32049
32050 @@ -1439,9 +1439,9 @@ static void check_decay_read_errors(mdde
32051 * overflowing the shift of read_errors by hours_since_last.
32052 */
32053 if (hours_since_last >= 8 * sizeof(read_errors))
32054 - atomic_set(&rdev->read_errors, 0);
32055 + atomic_set_unchecked(&rdev->read_errors, 0);
32056 else
32057 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
32058 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
32059 }
32060
32061 /*
32062 @@ -1476,8 +1476,8 @@ static void fix_read_error(conf_t *conf,
32063 }
32064
32065 check_decay_read_errors(mddev, rdev);
32066 - atomic_inc(&rdev->read_errors);
32067 - cur_read_error_count = atomic_read(&rdev->read_errors);
32068 + atomic_inc_unchecked(&rdev->read_errors);
32069 + cur_read_error_count = atomic_read_unchecked(&rdev->read_errors);
32070 if (cur_read_error_count > max_read_errors) {
32071 rcu_read_unlock();
32072 printk(KERN_NOTICE
32073 @@ -1550,7 +1550,7 @@ static void fix_read_error(conf_t *conf,
32074 test_bit(In_sync, &rdev->flags)) {
32075 atomic_inc(&rdev->nr_pending);
32076 rcu_read_unlock();
32077 - atomic_add(s, &rdev->corrected_errors);
32078 + atomic_add_unchecked(s, &rdev->corrected_errors);
32079 if (sync_page_io(rdev,
32080 r10_bio->devs[sl].addr +
32081 sect,
32082 diff -urNp linux-2.6.39/drivers/md/raid1.c linux-2.6.39/drivers/md/raid1.c
32083 --- linux-2.6.39/drivers/md/raid1.c 2011-05-19 00:06:34.000000000 -0400
32084 +++ linux-2.6.39/drivers/md/raid1.c 2011-05-22 19:36:31.000000000 -0400
32085 @@ -1342,7 +1342,7 @@ static void sync_request_write(mddev_t *
32086 if (r1_bio->bios[d]->bi_end_io != end_sync_read)
32087 continue;
32088 rdev = conf->mirrors[d].rdev;
32089 - atomic_add(s, &rdev->corrected_errors);
32090 + atomic_add_unchecked(s, &rdev->corrected_errors);
32091 if (sync_page_io(rdev,
32092 sect,
32093 s<<9,
32094 @@ -1488,7 +1488,7 @@ static void fix_read_error(conf_t *conf,
32095 /* Well, this device is dead */
32096 md_error(mddev, rdev);
32097 else {
32098 - atomic_add(s, &rdev->corrected_errors);
32099 + atomic_add_unchecked(s, &rdev->corrected_errors);
32100 printk(KERN_INFO
32101 "md/raid1:%s: read error corrected "
32102 "(%d sectors at %llu on %s)\n",
32103 diff -urNp linux-2.6.39/drivers/md/raid5.c linux-2.6.39/drivers/md/raid5.c
32104 --- linux-2.6.39/drivers/md/raid5.c 2011-05-19 00:06:34.000000000 -0400
32105 +++ linux-2.6.39/drivers/md/raid5.c 2011-05-22 19:36:31.000000000 -0400
32106 @@ -550,7 +550,7 @@ static void ops_run_io(struct stripe_hea
32107 bi->bi_next = NULL;
32108 if (rw == WRITE &&
32109 test_bit(R5_ReWrite, &sh->dev[i].flags))
32110 - atomic_add(STRIPE_SECTORS,
32111 + atomic_add_unchecked(STRIPE_SECTORS,
32112 &rdev->corrected_errors);
32113 generic_make_request(bi);
32114 } else {
32115 @@ -1596,15 +1596,15 @@ static void raid5_end_read_request(struc
32116 clear_bit(R5_ReadError, &sh->dev[i].flags);
32117 clear_bit(R5_ReWrite, &sh->dev[i].flags);
32118 }
32119 - if (atomic_read(&conf->disks[i].rdev->read_errors))
32120 - atomic_set(&conf->disks[i].rdev->read_errors, 0);
32121 + if (atomic_read_unchecked(&conf->disks[i].rdev->read_errors))
32122 + atomic_set_unchecked(&conf->disks[i].rdev->read_errors, 0);
32123 } else {
32124 const char *bdn = bdevname(conf->disks[i].rdev->bdev, b);
32125 int retry = 0;
32126 rdev = conf->disks[i].rdev;
32127
32128 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
32129 - atomic_inc(&rdev->read_errors);
32130 + atomic_inc_unchecked(&rdev->read_errors);
32131 if (conf->mddev->degraded >= conf->max_degraded)
32132 printk_rl(KERN_WARNING
32133 "md/raid:%s: read error not correctable "
32134 @@ -1622,7 +1622,7 @@ static void raid5_end_read_request(struc
32135 (unsigned long long)(sh->sector
32136 + rdev->data_offset),
32137 bdn);
32138 - else if (atomic_read(&rdev->read_errors)
32139 + else if (atomic_read_unchecked(&rdev->read_errors)
32140 > conf->max_nr_stripes)
32141 printk(KERN_WARNING
32142 "md/raid:%s: Too many read errors, failing device %s.\n",
32143 @@ -1947,6 +1947,7 @@ static sector_t compute_blocknr(struct s
32144 sector_t r_sector;
32145 struct stripe_head sh2;
32146
32147 + pax_track_stack();
32148
32149 chunk_offset = sector_div(new_sector, sectors_per_chunk);
32150 stripe = new_sector;
32151 diff -urNp linux-2.6.39/drivers/media/common/saa7146_hlp.c linux-2.6.39/drivers/media/common/saa7146_hlp.c
32152 --- linux-2.6.39/drivers/media/common/saa7146_hlp.c 2011-05-19 00:06:34.000000000 -0400
32153 +++ linux-2.6.39/drivers/media/common/saa7146_hlp.c 2011-05-22 19:36:31.000000000 -0400
32154 @@ -353,6 +353,8 @@ static void calculate_clipping_registers
32155
32156 int x[32], y[32], w[32], h[32];
32157
32158 + pax_track_stack();
32159 +
32160 /* clear out memory */
32161 memset(&line_list[0], 0x00, sizeof(u32)*32);
32162 memset(&pixel_list[0], 0x00, sizeof(u32)*32);
32163 diff -urNp linux-2.6.39/drivers/media/common/saa7146_vbi.c linux-2.6.39/drivers/media/common/saa7146_vbi.c
32164 --- linux-2.6.39/drivers/media/common/saa7146_vbi.c 2011-05-19 00:06:34.000000000 -0400
32165 +++ linux-2.6.39/drivers/media/common/saa7146_vbi.c 2011-05-22 19:36:31.000000000 -0400
32166 @@ -501,7 +501,7 @@ static ssize_t vbi_read(struct file *fil
32167 return ret;
32168 }
32169
32170 -struct saa7146_use_ops saa7146_vbi_uops = {
32171 +const struct saa7146_use_ops saa7146_vbi_uops = {
32172 .init = vbi_init,
32173 .open = vbi_open,
32174 .release = vbi_close,
32175 diff -urNp linux-2.6.39/drivers/media/common/saa7146_video.c linux-2.6.39/drivers/media/common/saa7146_video.c
32176 --- linux-2.6.39/drivers/media/common/saa7146_video.c 2011-05-19 00:06:34.000000000 -0400
32177 +++ linux-2.6.39/drivers/media/common/saa7146_video.c 2011-05-22 19:36:31.000000000 -0400
32178 @@ -1420,7 +1420,7 @@ out:
32179 return ret;
32180 }
32181
32182 -struct saa7146_use_ops saa7146_video_uops = {
32183 +const struct saa7146_use_ops saa7146_video_uops = {
32184 .init = video_init,
32185 .open = video_open,
32186 .release = video_close,
32187 diff -urNp linux-2.6.39/drivers/media/dvb/dm1105/dm1105.c linux-2.6.39/drivers/media/dvb/dm1105/dm1105.c
32188 --- linux-2.6.39/drivers/media/dvb/dm1105/dm1105.c 2011-05-19 00:06:34.000000000 -0400
32189 +++ linux-2.6.39/drivers/media/dvb/dm1105/dm1105.c 2011-05-22 19:36:31.000000000 -0400
32190 @@ -418,7 +418,7 @@ static u32 functionality(struct i2c_adap
32191 return I2C_FUNC_I2C;
32192 }
32193
32194 -static struct i2c_algorithm dm1105_algo = {
32195 +static const struct i2c_algorithm dm1105_algo = {
32196 .master_xfer = dm1105_i2c_xfer,
32197 .functionality = functionality,
32198 };
32199 diff -urNp linux-2.6.39/drivers/media/dvb/dvb-core/dvb_ca_en50221.c linux-2.6.39/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
32200 --- linux-2.6.39/drivers/media/dvb/dvb-core/dvb_ca_en50221.c 2011-05-19 00:06:34.000000000 -0400
32201 +++ linux-2.6.39/drivers/media/dvb/dvb-core/dvb_ca_en50221.c 2011-05-22 19:36:31.000000000 -0400
32202 @@ -590,6 +590,8 @@ static int dvb_ca_en50221_read_data(stru
32203 u8 buf[HOST_LINK_BUF_SIZE];
32204 int i;
32205
32206 + pax_track_stack();
32207 +
32208 dprintk("%s\n", __func__);
32209
32210 /* check if we have space for a link buf in the rx_buffer */
32211 @@ -1285,6 +1287,8 @@ static ssize_t dvb_ca_en50221_io_write(s
32212 unsigned long timeout;
32213 int written;
32214
32215 + pax_track_stack();
32216 +
32217 dprintk("%s\n", __func__);
32218
32219 /* Incoming packet has a 2 byte header. hdr[0] = slot_id, hdr[1] = connection_id */
32220 diff -urNp linux-2.6.39/drivers/media/dvb/dvb-core/dvbdev.c linux-2.6.39/drivers/media/dvb/dvb-core/dvbdev.c
32221 --- linux-2.6.39/drivers/media/dvb/dvb-core/dvbdev.c 2011-05-19 00:06:34.000000000 -0400
32222 +++ linux-2.6.39/drivers/media/dvb/dvb-core/dvbdev.c 2011-05-22 19:36:31.000000000 -0400
32223 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapt
32224 const struct dvb_device *template, void *priv, int type)
32225 {
32226 struct dvb_device *dvbdev;
32227 - struct file_operations *dvbdevfops;
32228 + struct file_operations *dvbdevfops; /* cannot be const, see this function */
32229 struct device *clsdev;
32230 int minor;
32231 int id;
32232 diff -urNp linux-2.6.39/drivers/media/dvb/dvb-usb/dib0700_core.c linux-2.6.39/drivers/media/dvb/dvb-usb/dib0700_core.c
32233 --- linux-2.6.39/drivers/media/dvb/dvb-usb/dib0700_core.c 2011-05-19 00:06:34.000000000 -0400
32234 +++ linux-2.6.39/drivers/media/dvb/dvb-usb/dib0700_core.c 2011-05-22 19:36:31.000000000 -0400
32235 @@ -391,6 +391,8 @@ int dib0700_download_firmware(struct usb
32236
32237 u8 buf[260];
32238
32239 + pax_track_stack();
32240 +
32241 while ((ret = dvb_usb_get_hexline(fw, &hx, &pos)) > 0) {
32242 deb_fwdata("writing to address 0x%08x (buffer: 0x%02x %02x)\n",
32243 hx.addr, hx.len, hx.chk);
32244 diff -urNp linux-2.6.39/drivers/media/dvb/dvb-usb/lmedm04.c linux-2.6.39/drivers/media/dvb/dvb-usb/lmedm04.c
32245 --- linux-2.6.39/drivers/media/dvb/dvb-usb/lmedm04.c 2011-05-19 00:06:34.000000000 -0400
32246 +++ linux-2.6.39/drivers/media/dvb/dvb-usb/lmedm04.c 2011-05-22 19:36:31.000000000 -0400
32247 @@ -663,6 +663,7 @@ static int lme2510_download_firmware(str
32248 packet_size = 0x31;
32249 len_in = 1;
32250
32251 + pax_track_stack();
32252
32253 info("FRM Starting Firmware Download");
32254
32255 @@ -715,6 +716,8 @@ static void lme_coldreset(struct usb_dev
32256 int ret = 0, len_in;
32257 u8 data[512] = {0};
32258
32259 + pax_track_stack();
32260 +
32261 data[0] = 0x0a;
32262 len_in = 1;
32263 info("FRM Firmware Cold Reset");
32264 diff -urNp linux-2.6.39/drivers/media/dvb/frontends/dib7000p.c linux-2.6.39/drivers/media/dvb/frontends/dib7000p.c
32265 --- linux-2.6.39/drivers/media/dvb/frontends/dib7000p.c 2011-05-19 00:06:34.000000000 -0400
32266 +++ linux-2.6.39/drivers/media/dvb/frontends/dib7000p.c 2011-05-22 19:36:31.000000000 -0400
32267 @@ -1913,7 +1913,7 @@ static u32 dib7000p_i2c_func(struct i2c_
32268 return I2C_FUNC_I2C;
32269 }
32270
32271 -static struct i2c_algorithm dib7090_tuner_xfer_algo = {
32272 +static const struct i2c_algorithm dib7090_tuner_xfer_algo = {
32273 .master_xfer = dib7090_tuner_xfer,
32274 .functionality = dib7000p_i2c_func,
32275 };
32276 diff -urNp linux-2.6.39/drivers/media/dvb/frontends/dib9000.c linux-2.6.39/drivers/media/dvb/frontends/dib9000.c
32277 --- linux-2.6.39/drivers/media/dvb/frontends/dib9000.c 2011-05-19 00:06:34.000000000 -0400
32278 +++ linux-2.6.39/drivers/media/dvb/frontends/dib9000.c 2011-05-22 19:36:31.000000000 -0400
32279 @@ -1649,12 +1649,12 @@ static u32 dib9000_i2c_func(struct i2c_a
32280 return I2C_FUNC_I2C;
32281 }
32282
32283 -static struct i2c_algorithm dib9000_tuner_algo = {
32284 +static const struct i2c_algorithm dib9000_tuner_algo = {
32285 .master_xfer = dib9000_tuner_xfer,
32286 .functionality = dib9000_i2c_func,
32287 };
32288
32289 -static struct i2c_algorithm dib9000_component_bus_algo = {
32290 +static const struct i2c_algorithm dib9000_component_bus_algo = {
32291 .master_xfer = dib9000_fw_component_bus_xfer,
32292 .functionality = dib9000_i2c_func,
32293 };
32294 diff -urNp linux-2.6.39/drivers/media/dvb/frontends/dibx000_common.c linux-2.6.39/drivers/media/dvb/frontends/dibx000_common.c
32295 --- linux-2.6.39/drivers/media/dvb/frontends/dibx000_common.c 2011-05-19 00:06:34.000000000 -0400
32296 +++ linux-2.6.39/drivers/media/dvb/frontends/dibx000_common.c 2011-05-22 19:36:31.000000000 -0400
32297 @@ -212,12 +212,12 @@ static int dibx000_i2c_master_xfer_gpio3
32298 return num;
32299 }
32300
32301 -static struct i2c_algorithm dibx000_i2c_master_gpio12_xfer_algo = {
32302 +static const struct i2c_algorithm dibx000_i2c_master_gpio12_xfer_algo = {
32303 .master_xfer = dibx000_i2c_master_xfer_gpio12,
32304 .functionality = dibx000_i2c_func,
32305 };
32306
32307 -static struct i2c_algorithm dibx000_i2c_master_gpio34_xfer_algo = {
32308 +static const struct i2c_algorithm dibx000_i2c_master_gpio34_xfer_algo = {
32309 .master_xfer = dibx000_i2c_master_xfer_gpio34,
32310 .functionality = dibx000_i2c_func,
32311 };
32312 @@ -270,7 +270,7 @@ static int dibx000_i2c_gated_gpio67_xfer
32313 return i2c_transfer(mst->i2c_adap, m, 2 + num) == 2 + num ? num : -EIO;
32314 }
32315
32316 -static struct i2c_algorithm dibx000_i2c_gated_gpio67_algo = {
32317 +static const struct i2c_algorithm dibx000_i2c_gated_gpio67_algo = {
32318 .master_xfer = dibx000_i2c_gated_gpio67_xfer,
32319 .functionality = dibx000_i2c_func,
32320 };
32321 @@ -301,7 +301,7 @@ static int dibx000_i2c_gated_tuner_xfer(
32322 return i2c_transfer(mst->i2c_adap, m, 2 + num) == 2 + num ? num : -EIO;
32323 }
32324
32325 -static struct i2c_algorithm dibx000_i2c_gated_tuner_algo = {
32326 +static const struct i2c_algorithm dibx000_i2c_gated_tuner_algo = {
32327 .master_xfer = dibx000_i2c_gated_tuner_xfer,
32328 .functionality = dibx000_i2c_func,
32329 };
32330 @@ -354,7 +354,7 @@ void dibx000_reset_i2c_master(struct dib
32331 EXPORT_SYMBOL(dibx000_reset_i2c_master);
32332
32333 static int i2c_adapter_init(struct i2c_adapter *i2c_adap,
32334 - struct i2c_algorithm *algo, const char *name,
32335 + const struct i2c_algorithm *algo, const char *name,
32336 struct dibx000_i2c_master *mst)
32337 {
32338 strncpy(i2c_adap->name, name, sizeof(i2c_adap->name));
32339 diff -urNp linux-2.6.39/drivers/media/dvb/frontends/mb86a16.c linux-2.6.39/drivers/media/dvb/frontends/mb86a16.c
32340 --- linux-2.6.39/drivers/media/dvb/frontends/mb86a16.c 2011-05-19 00:06:34.000000000 -0400
32341 +++ linux-2.6.39/drivers/media/dvb/frontends/mb86a16.c 2011-05-22 19:36:31.000000000 -0400
32342 @@ -1060,6 +1060,8 @@ static int mb86a16_set_fe(struct mb86a16
32343 int ret = -1;
32344 int sync;
32345
32346 + pax_track_stack();
32347 +
32348 dprintk(verbose, MB86A16_INFO, 1, "freq=%d Mhz, symbrt=%d Ksps", state->frequency, state->srate);
32349
32350 fcp = 3000;
32351 diff -urNp linux-2.6.39/drivers/media/dvb/frontends/or51211.c linux-2.6.39/drivers/media/dvb/frontends/or51211.c
32352 --- linux-2.6.39/drivers/media/dvb/frontends/or51211.c 2011-05-19 00:06:34.000000000 -0400
32353 +++ linux-2.6.39/drivers/media/dvb/frontends/or51211.c 2011-05-22 19:36:31.000000000 -0400
32354 @@ -113,6 +113,8 @@ static int or51211_load_firmware (struct
32355 u8 tudata[585];
32356 int i;
32357
32358 + pax_track_stack();
32359 +
32360 dprintk("Firmware is %zd bytes\n",fw->size);
32361
32362 /* Get eprom data */
32363 diff -urNp linux-2.6.39/drivers/media/dvb/frontends/s5h1420.c linux-2.6.39/drivers/media/dvb/frontends/s5h1420.c
32364 --- linux-2.6.39/drivers/media/dvb/frontends/s5h1420.c 2011-05-19 00:06:34.000000000 -0400
32365 +++ linux-2.6.39/drivers/media/dvb/frontends/s5h1420.c 2011-05-22 19:36:31.000000000 -0400
32366 @@ -870,7 +870,7 @@ static int s5h1420_tuner_i2c_tuner_xfer(
32367 return i2c_transfer(state->i2c, m, 1+num) == 1 + num ? num : -EIO;
32368 }
32369
32370 -static struct i2c_algorithm s5h1420_tuner_i2c_algo = {
32371 +static const struct i2c_algorithm s5h1420_tuner_i2c_algo = {
32372 .master_xfer = s5h1420_tuner_i2c_tuner_xfer,
32373 .functionality = s5h1420_tuner_i2c_func,
32374 };
32375 diff -urNp linux-2.6.39/drivers/media/dvb/mantis/mantis_i2c.c linux-2.6.39/drivers/media/dvb/mantis/mantis_i2c.c
32376 --- linux-2.6.39/drivers/media/dvb/mantis/mantis_i2c.c 2011-05-19 00:06:34.000000000 -0400
32377 +++ linux-2.6.39/drivers/media/dvb/mantis/mantis_i2c.c 2011-05-22 19:36:31.000000000 -0400
32378 @@ -212,7 +212,7 @@ static u32 mantis_i2c_func(struct i2c_ad
32379 return I2C_FUNC_SMBUS_EMUL;
32380 }
32381
32382 -static struct i2c_algorithm mantis_algo = {
32383 +static const struct i2c_algorithm mantis_algo = {
32384 .master_xfer = mantis_i2c_xfer,
32385 .functionality = mantis_i2c_func,
32386 };
32387 diff -urNp linux-2.6.39/drivers/media/dvb/ttusb-dec/ttusb_dec.c linux-2.6.39/drivers/media/dvb/ttusb-dec/ttusb_dec.c
32388 --- linux-2.6.39/drivers/media/dvb/ttusb-dec/ttusb_dec.c 2011-05-19 00:06:34.000000000 -0400
32389 +++ linux-2.6.39/drivers/media/dvb/ttusb-dec/ttusb_dec.c 2011-05-22 19:36:31.000000000 -0400
32390 @@ -1614,7 +1614,7 @@ static int fe_send_command(struct dvb_fr
32391 return ttusb_dec_send_command(dec, command, param_length, params, result_length, cmd_result);
32392 }
32393
32394 -static struct ttusbdecfe_config fe_config = {
32395 +static const struct ttusbdecfe_config fe_config = {
32396 .send_command = fe_send_command
32397 };
32398
32399 diff -urNp linux-2.6.39/drivers/media/radio/radio-cadet.c linux-2.6.39/drivers/media/radio/radio-cadet.c
32400 --- linux-2.6.39/drivers/media/radio/radio-cadet.c 2011-05-19 00:06:34.000000000 -0400
32401 +++ linux-2.6.39/drivers/media/radio/radio-cadet.c 2011-05-22 19:36:31.000000000 -0400
32402 @@ -349,7 +349,7 @@ static ssize_t cadet_read(struct file *f
32403 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
32404 mutex_unlock(&dev->lock);
32405
32406 - if (copy_to_user(data, readbuf, i))
32407 + if (i > sizeof readbuf || copy_to_user(data, readbuf, i))
32408 return -EFAULT;
32409 return i;
32410 }
32411 diff -urNp linux-2.6.39/drivers/media/radio/radio-si4713.c linux-2.6.39/drivers/media/radio/radio-si4713.c
32412 --- linux-2.6.39/drivers/media/radio/radio-si4713.c 2011-05-19 00:06:34.000000000 -0400
32413 +++ linux-2.6.39/drivers/media/radio/radio-si4713.c 2011-05-22 19:36:31.000000000 -0400
32414 @@ -231,7 +231,7 @@ static long radio_si4713_default(struct
32415 ioctl, cmd, arg);
32416 }
32417
32418 -static struct v4l2_ioctl_ops radio_si4713_ioctl_ops = {
32419 +static const struct v4l2_ioctl_ops radio_si4713_ioctl_ops = {
32420 .vidioc_enumaudout = radio_si4713_enumaudout,
32421 .vidioc_g_audout = radio_si4713_g_audout,
32422 .vidioc_s_audout = radio_si4713_s_audout,
32423 diff -urNp linux-2.6.39/drivers/media/rc/ir-lirc-codec.c linux-2.6.39/drivers/media/rc/ir-lirc-codec.c
32424 --- linux-2.6.39/drivers/media/rc/ir-lirc-codec.c 2011-05-19 00:06:34.000000000 -0400
32425 +++ linux-2.6.39/drivers/media/rc/ir-lirc-codec.c 2011-05-22 19:36:31.000000000 -0400
32426 @@ -277,7 +277,7 @@ static void ir_lirc_close(void *data)
32427 return;
32428 }
32429
32430 -static struct file_operations lirc_fops = {
32431 +static const struct file_operations lirc_fops = {
32432 .owner = THIS_MODULE,
32433 .write = ir_lirc_transmit_ir,
32434 .unlocked_ioctl = ir_lirc_ioctl,
32435 diff -urNp linux-2.6.39/drivers/media/rc/lirc_dev.c linux-2.6.39/drivers/media/rc/lirc_dev.c
32436 --- linux-2.6.39/drivers/media/rc/lirc_dev.c 2011-05-19 00:06:34.000000000 -0400
32437 +++ linux-2.6.39/drivers/media/rc/lirc_dev.c 2011-05-22 19:36:31.000000000 -0400
32438 @@ -151,7 +151,7 @@ static int lirc_thread(void *irctl)
32439 }
32440
32441
32442 -static struct file_operations lirc_dev_fops = {
32443 +static const struct file_operations lirc_dev_fops = {
32444 .owner = THIS_MODULE,
32445 .read = lirc_dev_fop_read,
32446 .write = lirc_dev_fop_write,
32447 diff -urNp linux-2.6.39/drivers/media/rc/rc-main.c linux-2.6.39/drivers/media/rc/rc-main.c
32448 --- linux-2.6.39/drivers/media/rc/rc-main.c 2011-05-19 00:06:34.000000000 -0400
32449 +++ linux-2.6.39/drivers/media/rc/rc-main.c 2011-05-22 19:36:31.000000000 -0400
32450 @@ -996,7 +996,7 @@ EXPORT_SYMBOL_GPL(rc_free_device);
32451
32452 int rc_register_device(struct rc_dev *dev)
32453 {
32454 - static atomic_t devno = ATOMIC_INIT(0);
32455 + static atomic_unchecked_t devno = ATOMIC_INIT(0);
32456 struct rc_map *rc_map;
32457 const char *path;
32458 int rc;
32459 @@ -1019,7 +1019,7 @@ int rc_register_device(struct rc_dev *de
32460 if (dev->close)
32461 dev->input_dev->close = ir_close;
32462
32463 - dev->devno = (unsigned long)(atomic_inc_return(&devno) - 1);
32464 + dev->devno = (unsigned long)(atomic_inc_return_unchecked(&devno) - 1);
32465 dev_set_name(&dev->dev, "rc%ld", dev->devno);
32466 dev_set_drvdata(&dev->dev, dev);
32467 rc = device_add(&dev->dev);
32468 diff -urNp linux-2.6.39/drivers/media/video/au0828/au0828.h linux-2.6.39/drivers/media/video/au0828/au0828.h
32469 --- linux-2.6.39/drivers/media/video/au0828/au0828.h 2011-05-19 00:06:34.000000000 -0400
32470 +++ linux-2.6.39/drivers/media/video/au0828/au0828.h 2011-05-22 19:36:31.000000000 -0400
32471 @@ -191,7 +191,7 @@ struct au0828_dev {
32472
32473 /* I2C */
32474 struct i2c_adapter i2c_adap;
32475 - struct i2c_algorithm i2c_algo;
32476 + struct i2c_algorithm i2c_algo;
32477 struct i2c_client i2c_client;
32478 u32 i2c_rc;
32479
32480 diff -urNp linux-2.6.39/drivers/media/video/cafe_ccic.c linux-2.6.39/drivers/media/video/cafe_ccic.c
32481 --- linux-2.6.39/drivers/media/video/cafe_ccic.c 2011-05-19 00:06:34.000000000 -0400
32482 +++ linux-2.6.39/drivers/media/video/cafe_ccic.c 2011-05-22 19:36:31.000000000 -0400
32483 @@ -520,7 +520,7 @@ static u32 cafe_smbus_func(struct i2c_ad
32484 I2C_FUNC_SMBUS_WRITE_BYTE_DATA;
32485 }
32486
32487 -static struct i2c_algorithm cafe_smbus_algo = {
32488 +static const struct i2c_algorithm cafe_smbus_algo = {
32489 .smbus_xfer = cafe_smbus_xfer,
32490 .functionality = cafe_smbus_func
32491 };
32492 diff -urNp linux-2.6.39/drivers/media/video/cx18/cx18-alsa-pcm.c linux-2.6.39/drivers/media/video/cx18/cx18-alsa-pcm.c
32493 --- linux-2.6.39/drivers/media/video/cx18/cx18-alsa-pcm.c 2011-05-19 00:06:34.000000000 -0400
32494 +++ linux-2.6.39/drivers/media/video/cx18/cx18-alsa-pcm.c 2011-05-22 19:36:31.000000000 -0400
32495 @@ -314,7 +314,7 @@ static struct page *snd_pcm_get_vmalloc_
32496 return vmalloc_to_page(pageptr);
32497 }
32498
32499 -static struct snd_pcm_ops snd_cx18_pcm_capture_ops = {
32500 +static const struct snd_pcm_ops snd_cx18_pcm_capture_ops = {
32501 .open = snd_cx18_pcm_capture_open,
32502 .close = snd_cx18_pcm_capture_close,
32503 .ioctl = snd_cx18_pcm_ioctl,
32504 diff -urNp linux-2.6.39/drivers/media/video/cx18/cx18-driver.c linux-2.6.39/drivers/media/video/cx18/cx18-driver.c
32505 --- linux-2.6.39/drivers/media/video/cx18/cx18-driver.c 2011-05-19 00:06:34.000000000 -0400
32506 +++ linux-2.6.39/drivers/media/video/cx18/cx18-driver.c 2011-05-22 19:36:31.000000000 -0400
32507 @@ -61,7 +61,7 @@ static struct pci_device_id cx18_pci_tbl
32508
32509 MODULE_DEVICE_TABLE(pci, cx18_pci_tbl);
32510
32511 -static atomic_t cx18_instance = ATOMIC_INIT(0);
32512 +static atomic_unchecked_t cx18_instance = ATOMIC_INIT(0);
32513
32514 /* Parameter declarations */
32515 static int cardtype[CX18_MAX_CARDS];
32516 @@ -327,6 +327,8 @@ void cx18_read_eeprom(struct cx18 *cx, s
32517 struct i2c_client c;
32518 u8 eedata[256];
32519
32520 + pax_track_stack();
32521 +
32522 memset(&c, 0, sizeof(c));
32523 strlcpy(c.name, "cx18 tveeprom tmp", sizeof(c.name));
32524 c.adapter = &cx->i2c_adap[0];
32525 @@ -892,7 +894,7 @@ static int __devinit cx18_probe(struct p
32526 struct cx18 *cx;
32527
32528 /* FIXME - module parameter arrays constrain max instances */
32529 - i = atomic_inc_return(&cx18_instance) - 1;
32530 + i = atomic_inc_return_unchecked(&cx18_instance) - 1;
32531 if (i >= CX18_MAX_CARDS) {
32532 printk(KERN_ERR "cx18: cannot manage card %d, driver has a "
32533 "limit of 0 - %d\n", i, CX18_MAX_CARDS - 1);
32534 diff -urNp linux-2.6.39/drivers/media/video/cx231xx/cx231xx-audio.c linux-2.6.39/drivers/media/video/cx231xx/cx231xx-audio.c
32535 --- linux-2.6.39/drivers/media/video/cx231xx/cx231xx-audio.c 2011-05-19 00:06:34.000000000 -0400
32536 +++ linux-2.6.39/drivers/media/video/cx231xx/cx231xx-audio.c 2011-05-22 19:36:31.000000000 -0400
32537 @@ -613,7 +613,7 @@ static struct page *snd_pcm_get_vmalloc_
32538 return vmalloc_to_page(pageptr);
32539 }
32540
32541 -static struct snd_pcm_ops snd_cx231xx_pcm_capture = {
32542 +static const struct snd_pcm_ops snd_cx231xx_pcm_capture = {
32543 .open = snd_cx231xx_capture_open,
32544 .close = snd_cx231xx_pcm_close,
32545 .ioctl = snd_pcm_lib_ioctl,
32546 diff -urNp linux-2.6.39/drivers/media/video/cx231xx/cx231xx-i2c.c linux-2.6.39/drivers/media/video/cx231xx/cx231xx-i2c.c
32547 --- linux-2.6.39/drivers/media/video/cx231xx/cx231xx-i2c.c 2011-05-19 00:06:34.000000000 -0400
32548 +++ linux-2.6.39/drivers/media/video/cx231xx/cx231xx-i2c.c 2011-05-22 19:36:31.000000000 -0400
32549 @@ -435,7 +435,7 @@ static u32 functionality(struct i2c_adap
32550 return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_I2C;
32551 }
32552
32553 -static struct i2c_algorithm cx231xx_algo = {
32554 +static const struct i2c_algorithm cx231xx_algo = {
32555 .master_xfer = cx231xx_i2c_xfer,
32556 .functionality = functionality,
32557 };
32558 diff -urNp linux-2.6.39/drivers/media/video/cx23885/cx23885-input.c linux-2.6.39/drivers/media/video/cx23885/cx23885-input.c
32559 --- linux-2.6.39/drivers/media/video/cx23885/cx23885-input.c 2011-05-19 00:06:34.000000000 -0400
32560 +++ linux-2.6.39/drivers/media/video/cx23885/cx23885-input.c 2011-05-22 19:36:31.000000000 -0400
32561 @@ -53,6 +53,8 @@ static void cx23885_input_process_measur
32562 bool handle = false;
32563 struct ir_raw_event ir_core_event[64];
32564
32565 + pax_track_stack();
32566 +
32567 do {
32568 num = 0;
32569 v4l2_subdev_call(dev->sd_ir, ir, rx_read, (u8 *) ir_core_event,
32570 diff -urNp linux-2.6.39/drivers/media/video/cx88/cx88-alsa.c linux-2.6.39/drivers/media/video/cx88/cx88-alsa.c
32571 --- linux-2.6.39/drivers/media/video/cx88/cx88-alsa.c 2011-05-19 00:06:34.000000000 -0400
32572 +++ linux-2.6.39/drivers/media/video/cx88/cx88-alsa.c 2011-05-22 19:36:31.000000000 -0400
32573 @@ -519,7 +519,7 @@ static struct page *snd_cx88_page(struct
32574 /*
32575 * operators
32576 */
32577 -static struct snd_pcm_ops snd_cx88_pcm_ops = {
32578 +static const struct snd_pcm_ops snd_cx88_pcm_ops = {
32579 .open = snd_cx88_pcm_open,
32580 .close = snd_cx88_close,
32581 .ioctl = snd_pcm_lib_ioctl,
32582 diff -urNp linux-2.6.39/drivers/media/video/davinci/ccdc_hw_device.h linux-2.6.39/drivers/media/video/davinci/ccdc_hw_device.h
32583 --- linux-2.6.39/drivers/media/video/davinci/ccdc_hw_device.h 2011-05-19 00:06:34.000000000 -0400
32584 +++ linux-2.6.39/drivers/media/video/davinci/ccdc_hw_device.h 2011-05-22 19:36:31.000000000 -0400
32585 @@ -99,7 +99,7 @@ struct ccdc_hw_device {
32586 /* module owner */
32587 struct module *owner;
32588 /* hw ops */
32589 - struct ccdc_hw_ops hw_ops;
32590 + const struct ccdc_hw_ops hw_ops;
32591 };
32592
32593 /* Used by CCDC module to register & unregister with vpfe capture driver */
32594 diff -urNp linux-2.6.39/drivers/media/video/davinci/vpss.c linux-2.6.39/drivers/media/video/davinci/vpss.c
32595 --- linux-2.6.39/drivers/media/video/davinci/vpss.c 2011-05-19 00:06:34.000000000 -0400
32596 +++ linux-2.6.39/drivers/media/video/davinci/vpss.c 2011-05-22 19:36:31.000000000 -0400
32597 @@ -103,7 +103,7 @@ struct vpss_oper_config {
32598 __iomem void *vpss_regs_base1;
32599 enum vpss_platform_type platform;
32600 spinlock_t vpss_lock;
32601 - struct vpss_hw_ops hw_ops;
32602 + const struct vpss_hw_ops hw_ops;
32603 };
32604
32605 static struct vpss_oper_config oper_cfg;
32606 diff -urNp linux-2.6.39/drivers/media/video/em28xx/em28xx-audio.c linux-2.6.39/drivers/media/video/em28xx/em28xx-audio.c
32607 --- linux-2.6.39/drivers/media/video/em28xx/em28xx-audio.c 2011-05-19 00:06:34.000000000 -0400
32608 +++ linux-2.6.39/drivers/media/video/em28xx/em28xx-audio.c 2011-05-22 19:36:31.000000000 -0400
32609 @@ -432,7 +432,7 @@ static struct page *snd_pcm_get_vmalloc_
32610 return vmalloc_to_page(pageptr);
32611 }
32612
32613 -static struct snd_pcm_ops snd_em28xx_pcm_capture = {
32614 +static const struct snd_pcm_ops snd_em28xx_pcm_capture = {
32615 .open = snd_em28xx_capture_open,
32616 .close = snd_em28xx_pcm_close,
32617 .ioctl = snd_pcm_lib_ioctl,
32618 diff -urNp linux-2.6.39/drivers/media/video/em28xx/em28xx-i2c.c linux-2.6.39/drivers/media/video/em28xx/em28xx-i2c.c
32619 --- linux-2.6.39/drivers/media/video/em28xx/em28xx-i2c.c 2011-05-19 00:06:34.000000000 -0400
32620 +++ linux-2.6.39/drivers/media/video/em28xx/em28xx-i2c.c 2011-05-22 19:36:31.000000000 -0400
32621 @@ -451,7 +451,7 @@ static u32 functionality(struct i2c_adap
32622 return I2C_FUNC_SMBUS_EMUL;
32623 }
32624
32625 -static struct i2c_algorithm em28xx_algo = {
32626 +static const struct i2c_algorithm em28xx_algo = {
32627 .master_xfer = em28xx_i2c_xfer,
32628 .functionality = functionality,
32629 };
32630 diff -urNp linux-2.6.39/drivers/media/video/hdpvr/hdpvr-i2c.c linux-2.6.39/drivers/media/video/hdpvr/hdpvr-i2c.c
32631 --- linux-2.6.39/drivers/media/video/hdpvr/hdpvr-i2c.c 2011-05-19 00:06:34.000000000 -0400
32632 +++ linux-2.6.39/drivers/media/video/hdpvr/hdpvr-i2c.c 2011-05-22 19:36:31.000000000 -0400
32633 @@ -179,7 +179,7 @@ static u32 hdpvr_functionality(struct i2
32634 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
32635 }
32636
32637 -static struct i2c_algorithm hdpvr_algo = {
32638 +static const struct i2c_algorithm hdpvr_algo = {
32639 .master_xfer = hdpvr_transfer,
32640 .functionality = hdpvr_functionality,
32641 };
32642 diff -urNp linux-2.6.39/drivers/media/video/imx074.c linux-2.6.39/drivers/media/video/imx074.c
32643 --- linux-2.6.39/drivers/media/video/imx074.c 2011-05-19 00:06:34.000000000 -0400
32644 +++ linux-2.6.39/drivers/media/video/imx074.c 2011-05-22 19:36:31.000000000 -0400
32645 @@ -267,7 +267,7 @@ static int imx074_g_chip_ident(struct v4
32646 return 0;
32647 }
32648
32649 -static struct v4l2_subdev_video_ops imx074_subdev_video_ops = {
32650 +static const struct v4l2_subdev_video_ops imx074_subdev_video_ops = {
32651 .s_stream = imx074_s_stream,
32652 .s_mbus_fmt = imx074_s_fmt,
32653 .g_mbus_fmt = imx074_g_fmt,
32654 @@ -277,7 +277,7 @@ static struct v4l2_subdev_video_ops imx0
32655 .cropcap = imx074_cropcap,
32656 };
32657
32658 -static struct v4l2_subdev_core_ops imx074_subdev_core_ops = {
32659 +static const struct v4l2_subdev_core_ops imx074_subdev_core_ops = {
32660 .g_chip_ident = imx074_g_chip_ident,
32661 };
32662
32663 diff -urNp linux-2.6.39/drivers/media/video/ivtv/ivtv-driver.c linux-2.6.39/drivers/media/video/ivtv/ivtv-driver.c
32664 --- linux-2.6.39/drivers/media/video/ivtv/ivtv-driver.c 2011-05-19 00:06:34.000000000 -0400
32665 +++ linux-2.6.39/drivers/media/video/ivtv/ivtv-driver.c 2011-05-22 19:36:31.000000000 -0400
32666 @@ -80,7 +80,7 @@ static struct pci_device_id ivtv_pci_tbl
32667 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
32668
32669 /* ivtv instance counter */
32670 -static atomic_t ivtv_instance = ATOMIC_INIT(0);
32671 +static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
32672
32673 /* Parameter declarations */
32674 static int cardtype[IVTV_MAX_CARDS];
32675 diff -urNp linux-2.6.39/drivers/media/video/mt9m001.c linux-2.6.39/drivers/media/video/mt9m001.c
32676 --- linux-2.6.39/drivers/media/video/mt9m001.c 2011-05-19 00:06:34.000000000 -0400
32677 +++ linux-2.6.39/drivers/media/video/mt9m001.c 2011-05-22 19:36:31.000000000 -0400
32678 @@ -691,7 +691,7 @@ static int mt9m001_g_skip_top_lines(stru
32679 return 0;
32680 }
32681
32682 -static struct v4l2_subdev_core_ops mt9m001_subdev_core_ops = {
32683 +static const struct v4l2_subdev_core_ops mt9m001_subdev_core_ops = {
32684 .g_ctrl = mt9m001_g_ctrl,
32685 .s_ctrl = mt9m001_s_ctrl,
32686 .g_chip_ident = mt9m001_g_chip_ident,
32687 @@ -714,7 +714,7 @@ static int mt9m001_enum_fmt(struct v4l2_
32688 return 0;
32689 }
32690
32691 -static struct v4l2_subdev_video_ops mt9m001_subdev_video_ops = {
32692 +static const struct v4l2_subdev_video_ops mt9m001_subdev_video_ops = {
32693 .s_stream = mt9m001_s_stream,
32694 .s_mbus_fmt = mt9m001_s_fmt,
32695 .g_mbus_fmt = mt9m001_g_fmt,
32696 @@ -725,7 +725,7 @@ static struct v4l2_subdev_video_ops mt9m
32697 .enum_mbus_fmt = mt9m001_enum_fmt,
32698 };
32699
32700 -static struct v4l2_subdev_sensor_ops mt9m001_subdev_sensor_ops = {
32701 +static const struct v4l2_subdev_sensor_ops mt9m001_subdev_sensor_ops = {
32702 .g_skip_top_lines = mt9m001_g_skip_top_lines,
32703 };
32704
32705 diff -urNp linux-2.6.39/drivers/media/video/mt9t031.c linux-2.6.39/drivers/media/video/mt9t031.c
32706 --- linux-2.6.39/drivers/media/video/mt9t031.c 2011-05-19 00:06:34.000000000 -0400
32707 +++ linux-2.6.39/drivers/media/video/mt9t031.c 2011-05-22 19:36:31.000000000 -0400
32708 @@ -725,7 +725,7 @@ static int mt9t031_runtime_resume(struct
32709 return 0;
32710 }
32711
32712 -static struct dev_pm_ops mt9t031_dev_pm_ops = {
32713 +static const struct dev_pm_ops mt9t031_dev_pm_ops = {
32714 .runtime_suspend = mt9t031_runtime_suspend,
32715 .runtime_resume = mt9t031_runtime_resume,
32716 };
32717 @@ -788,7 +788,7 @@ static int mt9t031_g_skip_top_lines(stru
32718 return 0;
32719 }
32720
32721 -static struct v4l2_subdev_core_ops mt9t031_subdev_core_ops = {
32722 +static const struct v4l2_subdev_core_ops mt9t031_subdev_core_ops = {
32723 .g_ctrl = mt9t031_g_ctrl,
32724 .s_ctrl = mt9t031_s_ctrl,
32725 .g_chip_ident = mt9t031_g_chip_ident,
32726 @@ -808,7 +808,7 @@ static int mt9t031_enum_fmt(struct v4l2_
32727 return 0;
32728 }
32729
32730 -static struct v4l2_subdev_video_ops mt9t031_subdev_video_ops = {
32731 +static const struct v4l2_subdev_video_ops mt9t031_subdev_video_ops = {
32732 .s_stream = mt9t031_s_stream,
32733 .s_mbus_fmt = mt9t031_s_fmt,
32734 .g_mbus_fmt = mt9t031_g_fmt,
32735 @@ -819,7 +819,7 @@ static struct v4l2_subdev_video_ops mt9t
32736 .enum_mbus_fmt = mt9t031_enum_fmt,
32737 };
32738
32739 -static struct v4l2_subdev_sensor_ops mt9t031_subdev_sensor_ops = {
32740 +static const struct v4l2_subdev_sensor_ops mt9t031_subdev_sensor_ops = {
32741 .g_skip_top_lines = mt9t031_g_skip_top_lines,
32742 };
32743
32744 diff -urNp linux-2.6.39/drivers/media/video/mt9v022.c linux-2.6.39/drivers/media/video/mt9v022.c
32745 --- linux-2.6.39/drivers/media/video/mt9v022.c 2011-05-19 00:06:34.000000000 -0400
32746 +++ linux-2.6.39/drivers/media/video/mt9v022.c 2011-05-22 19:36:31.000000000 -0400
32747 @@ -825,7 +825,7 @@ static int mt9v022_g_skip_top_lines(stru
32748 return 0;
32749 }
32750
32751 -static struct v4l2_subdev_core_ops mt9v022_subdev_core_ops = {
32752 +static const struct v4l2_subdev_core_ops mt9v022_subdev_core_ops = {
32753 .g_ctrl = mt9v022_g_ctrl,
32754 .s_ctrl = mt9v022_s_ctrl,
32755 .g_chip_ident = mt9v022_g_chip_ident,
32756 @@ -848,7 +848,7 @@ static int mt9v022_enum_fmt(struct v4l2_
32757 return 0;
32758 }
32759
32760 -static struct v4l2_subdev_video_ops mt9v022_subdev_video_ops = {
32761 +static const struct v4l2_subdev_video_ops mt9v022_subdev_video_ops = {
32762 .s_stream = mt9v022_s_stream,
32763 .s_mbus_fmt = mt9v022_s_fmt,
32764 .g_mbus_fmt = mt9v022_g_fmt,
32765 @@ -859,7 +859,7 @@ static struct v4l2_subdev_video_ops mt9v
32766 .enum_mbus_fmt = mt9v022_enum_fmt,
32767 };
32768
32769 -static struct v4l2_subdev_sensor_ops mt9v022_subdev_sensor_ops = {
32770 +static const struct v4l2_subdev_sensor_ops mt9v022_subdev_sensor_ops = {
32771 .g_skip_top_lines = mt9v022_g_skip_top_lines,
32772 };
32773
32774 diff -urNp linux-2.6.39/drivers/media/video/mx2_camera.c linux-2.6.39/drivers/media/video/mx2_camera.c
32775 --- linux-2.6.39/drivers/media/video/mx2_camera.c 2011-05-19 00:06:34.000000000 -0400
32776 +++ linux-2.6.39/drivers/media/video/mx2_camera.c 2011-05-22 19:36:31.000000000 -0400
32777 @@ -668,7 +668,7 @@ static void mx2_videobuf_release(struct
32778 free_buffer(vq, buf);
32779 }
32780
32781 -static struct videobuf_queue_ops mx2_videobuf_ops = {
32782 +static const struct videobuf_queue_ops mx2_videobuf_ops = {
32783 .buf_setup = mx2_videobuf_setup,
32784 .buf_prepare = mx2_videobuf_prepare,
32785 .buf_queue = mx2_videobuf_queue,
32786 diff -urNp linux-2.6.39/drivers/media/video/omap24xxcam.c linux-2.6.39/drivers/media/video/omap24xxcam.c
32787 --- linux-2.6.39/drivers/media/video/omap24xxcam.c 2011-05-19 00:06:34.000000000 -0400
32788 +++ linux-2.6.39/drivers/media/video/omap24xxcam.c 2011-05-22 19:36:31.000000000 -0400
32789 @@ -403,7 +403,7 @@ static void omap24xxcam_vbq_complete(str
32790 spin_unlock_irqrestore(&cam->core_enable_disable_lock, flags);
32791
32792 do_gettimeofday(&vb->ts);
32793 - vb->field_count = atomic_add_return(2, &fh->field_count);
32794 + vb->field_count = atomic_add_return_unchecked(2, &fh->field_count);
32795 if (csr & csr_error) {
32796 vb->state = VIDEOBUF_ERROR;
32797 if (!atomic_read(&fh->cam->in_reset)) {
32798 diff -urNp linux-2.6.39/drivers/media/video/omap24xxcam.h linux-2.6.39/drivers/media/video/omap24xxcam.h
32799 --- linux-2.6.39/drivers/media/video/omap24xxcam.h 2011-05-19 00:06:34.000000000 -0400
32800 +++ linux-2.6.39/drivers/media/video/omap24xxcam.h 2011-05-22 19:36:31.000000000 -0400
32801 @@ -533,7 +533,7 @@ struct omap24xxcam_fh {
32802 spinlock_t vbq_lock; /* spinlock for the videobuf queue */
32803 struct videobuf_queue vbq;
32804 struct v4l2_pix_format pix; /* serialise pix by vbq->lock */
32805 - atomic_t field_count; /* field counter for videobuf_buffer */
32806 + atomic_unchecked_t field_count; /* field counter for videobuf_buffer */
32807 /* accessing cam here doesn't need serialisation: it's constant */
32808 struct omap24xxcam_device *cam;
32809 };
32810 diff -urNp linux-2.6.39/drivers/media/video/omap3isp/isp.h linux-2.6.39/drivers/media/video/omap3isp/isp.h
32811 --- linux-2.6.39/drivers/media/video/omap3isp/isp.h 2011-05-19 00:06:34.000000000 -0400
32812 +++ linux-2.6.39/drivers/media/video/omap3isp/isp.h 2011-05-22 19:36:31.000000000 -0400
32813 @@ -290,7 +290,7 @@ struct isp_device {
32814
32815 struct iommu *iommu;
32816
32817 - struct isp_platform_callback platform_cb;
32818 + const struct isp_platform_callback platform_cb;
32819 };
32820
32821 #define v4l2_dev_to_isp_device(dev) \
32822 diff -urNp linux-2.6.39/drivers/media/video/ov2640.c linux-2.6.39/drivers/media/video/ov2640.c
32823 --- linux-2.6.39/drivers/media/video/ov2640.c 2011-05-19 00:06:34.000000000 -0400
32824 +++ linux-2.6.39/drivers/media/video/ov2640.c 2011-05-22 19:36:31.000000000 -0400
32825 @@ -1080,7 +1080,7 @@ static struct soc_camera_ops ov2640_ops
32826 .num_controls = ARRAY_SIZE(ov2640_controls),
32827 };
32828
32829 -static struct v4l2_subdev_core_ops ov2640_subdev_core_ops = {
32830 +static const struct v4l2_subdev_core_ops ov2640_subdev_core_ops = {
32831 .g_ctrl = ov2640_g_ctrl,
32832 .s_ctrl = ov2640_s_ctrl,
32833 .g_chip_ident = ov2640_g_chip_ident,
32834 @@ -1090,7 +1090,7 @@ static struct v4l2_subdev_core_ops ov264
32835 #endif
32836 };
32837
32838 -static struct v4l2_subdev_video_ops ov2640_subdev_video_ops = {
32839 +static const struct v4l2_subdev_video_ops ov2640_subdev_video_ops = {
32840 .s_stream = ov2640_s_stream,
32841 .g_mbus_fmt = ov2640_g_fmt,
32842 .s_mbus_fmt = ov2640_s_fmt,
32843 diff -urNp linux-2.6.39/drivers/media/video/ov772x.c linux-2.6.39/drivers/media/video/ov772x.c
32844 --- linux-2.6.39/drivers/media/video/ov772x.c 2011-05-19 00:06:34.000000000 -0400
32845 +++ linux-2.6.39/drivers/media/video/ov772x.c 2011-05-22 19:36:31.000000000 -0400
32846 @@ -1079,7 +1079,7 @@ static struct soc_camera_ops ov772x_ops
32847 .num_controls = ARRAY_SIZE(ov772x_controls),
32848 };
32849
32850 -static struct v4l2_subdev_core_ops ov772x_subdev_core_ops = {
32851 +static const struct v4l2_subdev_core_ops ov772x_subdev_core_ops = {
32852 .g_ctrl = ov772x_g_ctrl,
32853 .s_ctrl = ov772x_s_ctrl,
32854 .g_chip_ident = ov772x_g_chip_ident,
32855 @@ -1099,7 +1099,7 @@ static int ov772x_enum_fmt(struct v4l2_s
32856 return 0;
32857 }
32858
32859 -static struct v4l2_subdev_video_ops ov772x_subdev_video_ops = {
32860 +static const struct v4l2_subdev_video_ops ov772x_subdev_video_ops = {
32861 .s_stream = ov772x_s_stream,
32862 .g_mbus_fmt = ov772x_g_fmt,
32863 .s_mbus_fmt = ov772x_s_fmt,
32864 diff -urNp linux-2.6.39/drivers/media/video/pvrusb2/pvrusb2-eeprom.c linux-2.6.39/drivers/media/video/pvrusb2/pvrusb2-eeprom.c
32865 --- linux-2.6.39/drivers/media/video/pvrusb2/pvrusb2-eeprom.c 2011-05-19 00:06:34.000000000 -0400
32866 +++ linux-2.6.39/drivers/media/video/pvrusb2/pvrusb2-eeprom.c 2011-05-22 19:36:31.000000000 -0400
32867 @@ -120,6 +120,8 @@ int pvr2_eeprom_analyze(struct pvr2_hdw
32868 u8 *eeprom;
32869 struct tveeprom tvdata;
32870
32871 + pax_track_stack();
32872 +
32873 memset(&tvdata,0,sizeof(tvdata));
32874
32875 eeprom = pvr2_eeprom_fetch(hdw);
32876 diff -urNp linux-2.6.39/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c linux-2.6.39/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c
32877 --- linux-2.6.39/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c 2011-05-19 00:06:34.000000000 -0400
32878 +++ linux-2.6.39/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c 2011-05-22 19:36:31.000000000 -0400
32879 @@ -527,7 +527,7 @@ static u32 pvr2_i2c_functionality(struct
32880 return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_I2C;
32881 }
32882
32883 -static struct i2c_algorithm pvr2_i2c_algo_template = {
32884 +static const struct i2c_algorithm pvr2_i2c_algo_template = {
32885 .master_xfer = pvr2_i2c_xfer,
32886 .functionality = pvr2_i2c_functionality,
32887 };
32888 diff -urNp linux-2.6.39/drivers/media/video/rj54n1cb0c.c linux-2.6.39/drivers/media/video/rj54n1cb0c.c
32889 --- linux-2.6.39/drivers/media/video/rj54n1cb0c.c 2011-05-19 00:06:34.000000000 -0400
32890 +++ linux-2.6.39/drivers/media/video/rj54n1cb0c.c 2011-05-22 19:36:31.000000000 -0400
32891 @@ -1327,7 +1327,7 @@ static int rj54n1_s_ctrl(struct v4l2_sub
32892 return 0;
32893 }
32894
32895 -static struct v4l2_subdev_core_ops rj54n1_subdev_core_ops = {
32896 +static const struct v4l2_subdev_core_ops rj54n1_subdev_core_ops = {
32897 .g_ctrl = rj54n1_g_ctrl,
32898 .s_ctrl = rj54n1_s_ctrl,
32899 .g_chip_ident = rj54n1_g_chip_ident,
32900 @@ -1337,7 +1337,7 @@ static struct v4l2_subdev_core_ops rj54n
32901 #endif
32902 };
32903
32904 -static struct v4l2_subdev_video_ops rj54n1_subdev_video_ops = {
32905 +static const struct v4l2_subdev_video_ops rj54n1_subdev_video_ops = {
32906 .s_stream = rj54n1_s_stream,
32907 .s_mbus_fmt = rj54n1_s_fmt,
32908 .g_mbus_fmt = rj54n1_g_fmt,
32909 diff -urNp linux-2.6.39/drivers/media/video/s5p-fimc/fimc-capture.c linux-2.6.39/drivers/media/video/s5p-fimc/fimc-capture.c
32910 --- linux-2.6.39/drivers/media/video/s5p-fimc/fimc-capture.c 2011-05-19 00:06:34.000000000 -0400
32911 +++ linux-2.6.39/drivers/media/video/s5p-fimc/fimc-capture.c 2011-05-22 19:36:31.000000000 -0400
32912 @@ -376,7 +376,7 @@ static void fimc_unlock(struct vb2_queue
32913 mutex_unlock(&ctx->fimc_dev->lock);
32914 }
32915
32916 -static struct vb2_ops fimc_capture_qops = {
32917 +static const struct vb2_ops fimc_capture_qops = {
32918 .queue_setup = queue_setup,
32919 .buf_prepare = buffer_prepare,
32920 .buf_queue = buffer_queue,
32921 diff -urNp linux-2.6.39/drivers/media/video/s5p-fimc/fimc-core.c linux-2.6.39/drivers/media/video/s5p-fimc/fimc-core.c
32922 --- linux-2.6.39/drivers/media/video/s5p-fimc/fimc-core.c 2011-05-19 00:06:34.000000000 -0400
32923 +++ linux-2.6.39/drivers/media/video/s5p-fimc/fimc-core.c 2011-05-22 19:36:31.000000000 -0400
32924 @@ -768,7 +768,7 @@ static void fimc_unlock(struct vb2_queue
32925 mutex_unlock(&ctx->fimc_dev->lock);
32926 }
32927
32928 -static struct vb2_ops fimc_qops = {
32929 +static const struct vb2_ops fimc_qops = {
32930 .queue_setup = fimc_queue_setup,
32931 .buf_prepare = fimc_buf_prepare,
32932 .buf_queue = fimc_buf_queue,
32933 diff -urNp linux-2.6.39/drivers/media/video/saa7134/saa6752hs.c linux-2.6.39/drivers/media/video/saa7134/saa6752hs.c
32934 --- linux-2.6.39/drivers/media/video/saa7134/saa6752hs.c 2011-05-19 00:06:34.000000000 -0400
32935 +++ linux-2.6.39/drivers/media/video/saa7134/saa6752hs.c 2011-05-22 19:36:31.000000000 -0400
32936 @@ -682,6 +682,8 @@ static int saa6752hs_init(struct v4l2_su
32937 unsigned char localPAT[256];
32938 unsigned char localPMT[256];
32939
32940 + pax_track_stack();
32941 +
32942 /* Set video format - must be done first as it resets other settings */
32943 set_reg8(client, 0x41, h->video_format);
32944
32945 diff -urNp linux-2.6.39/drivers/media/video/saa7134/saa7134-alsa.c linux-2.6.39/drivers/media/video/saa7134/saa7134-alsa.c
32946 --- linux-2.6.39/drivers/media/video/saa7134/saa7134-alsa.c 2011-05-19 00:06:34.000000000 -0400
32947 +++ linux-2.6.39/drivers/media/video/saa7134/saa7134-alsa.c 2011-05-22 19:36:31.000000000 -0400
32948 @@ -808,7 +808,7 @@ static struct page *snd_card_saa7134_pag
32949 * ALSA capture callbacks definition
32950 */
32951
32952 -static struct snd_pcm_ops snd_card_saa7134_capture_ops = {
32953 +static const struct snd_pcm_ops snd_card_saa7134_capture_ops = {
32954 .open = snd_card_saa7134_capture_open,
32955 .close = snd_card_saa7134_capture_close,
32956 .ioctl = snd_pcm_lib_ioctl,
32957 diff -urNp linux-2.6.39/drivers/media/video/saa7164/saa7164-cmd.c linux-2.6.39/drivers/media/video/saa7164/saa7164-cmd.c
32958 --- linux-2.6.39/drivers/media/video/saa7164/saa7164-cmd.c 2011-05-19 00:06:34.000000000 -0400
32959 +++ linux-2.6.39/drivers/media/video/saa7164/saa7164-cmd.c 2011-05-22 19:36:31.000000000 -0400
32960 @@ -88,6 +88,8 @@ int saa7164_irq_dequeue(struct saa7164_d
32961 u8 tmp[512];
32962 dprintk(DBGLVL_CMD, "%s()\n", __func__);
32963
32964 + pax_track_stack();
32965 +
32966 /* While any outstand message on the bus exists... */
32967 do {
32968
32969 @@ -141,6 +143,8 @@ int saa7164_cmd_dequeue(struct saa7164_d
32970 u8 tmp[512];
32971 dprintk(DBGLVL_CMD, "%s()\n", __func__);
32972
32973 + pax_track_stack();
32974 +
32975 while (loop) {
32976
32977 struct tmComResInfo tRsp = { 0, 0, 0, 0, 0, 0 };
32978 diff -urNp linux-2.6.39/drivers/media/video/sh_mobile_csi2.c linux-2.6.39/drivers/media/video/sh_mobile_csi2.c
32979 --- linux-2.6.39/drivers/media/video/sh_mobile_csi2.c 2011-05-19 00:06:34.000000000 -0400
32980 +++ linux-2.6.39/drivers/media/video/sh_mobile_csi2.c 2011-05-22 19:36:31.000000000 -0400
32981 @@ -127,12 +127,12 @@ static int sh_csi2_s_fmt(struct v4l2_sub
32982 return 0;
32983 }
32984
32985 -static struct v4l2_subdev_video_ops sh_csi2_subdev_video_ops = {
32986 +static const struct v4l2_subdev_video_ops sh_csi2_subdev_video_ops = {
32987 .s_mbus_fmt = sh_csi2_s_fmt,
32988 .try_mbus_fmt = sh_csi2_try_fmt,
32989 };
32990
32991 -static struct v4l2_subdev_core_ops sh_csi2_subdev_core_ops;
32992 +static const struct v4l2_subdev_core_ops sh_csi2_subdev_core_ops;
32993
32994 static struct v4l2_subdev_ops sh_csi2_subdev_ops = {
32995 .core = &sh_csi2_subdev_core_ops,
32996 diff -urNp linux-2.6.39/drivers/media/video/soc_camera_platform.c linux-2.6.39/drivers/media/video/soc_camera_platform.c
32997 --- linux-2.6.39/drivers/media/video/soc_camera_platform.c 2011-05-19 00:06:34.000000000 -0400
32998 +++ linux-2.6.39/drivers/media/video/soc_camera_platform.c 2011-05-22 19:36:31.000000000 -0400
32999 @@ -70,7 +70,7 @@ static int soc_camera_platform_fill_fmt(
33000 return 0;
33001 }
33002
33003 -static struct v4l2_subdev_core_ops platform_subdev_core_ops;
33004 +static const struct v4l2_subdev_core_ops platform_subdev_core_ops;
33005
33006 static int soc_camera_platform_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
33007 enum v4l2_mbus_pixelcode *code)
33008 @@ -115,7 +115,7 @@ static int soc_camera_platform_cropcap(s
33009 return 0;
33010 }
33011
33012 -static struct v4l2_subdev_video_ops platform_subdev_video_ops = {
33013 +static const struct v4l2_subdev_video_ops platform_subdev_video_ops = {
33014 .s_stream = soc_camera_platform_s_stream,
33015 .enum_mbus_fmt = soc_camera_platform_enum_fmt,
33016 .cropcap = soc_camera_platform_cropcap,
33017 diff -urNp linux-2.6.39/drivers/media/video/tlg2300/pd-alsa.c linux-2.6.39/drivers/media/video/tlg2300/pd-alsa.c
33018 --- linux-2.6.39/drivers/media/video/tlg2300/pd-alsa.c 2011-05-19 00:06:34.000000000 -0400
33019 +++ linux-2.6.39/drivers/media/video/tlg2300/pd-alsa.c 2011-05-22 19:36:31.000000000 -0400
33020 @@ -265,7 +265,7 @@ static struct page *snd_pcm_pd_get_page(
33021 return vmalloc_to_page(pageptr);
33022 }
33023
33024 -static struct snd_pcm_ops pcm_capture_ops = {
33025 +static const struct snd_pcm_ops pcm_capture_ops = {
33026 .open = snd_pd_capture_open,
33027 .close = snd_pd_pcm_close,
33028 .ioctl = snd_pcm_lib_ioctl,
33029 diff -urNp linux-2.6.39/drivers/media/video/tw9910.c linux-2.6.39/drivers/media/video/tw9910.c
33030 --- linux-2.6.39/drivers/media/video/tw9910.c 2011-05-19 00:06:34.000000000 -0400
33031 +++ linux-2.6.39/drivers/media/video/tw9910.c 2011-05-22 19:36:31.000000000 -0400
33032 @@ -894,7 +894,7 @@ static struct soc_camera_ops tw9910_ops
33033 .enum_input = tw9910_enum_input,
33034 };
33035
33036 -static struct v4l2_subdev_core_ops tw9910_subdev_core_ops = {
33037 +static const struct v4l2_subdev_core_ops tw9910_subdev_core_ops = {
33038 .g_chip_ident = tw9910_g_chip_ident,
33039 .s_std = tw9910_s_std,
33040 #ifdef CONFIG_VIDEO_ADV_DEBUG
33041 @@ -913,7 +913,7 @@ static int tw9910_enum_fmt(struct v4l2_s
33042 return 0;
33043 }
33044
33045 -static struct v4l2_subdev_video_ops tw9910_subdev_video_ops = {
33046 +static const struct v4l2_subdev_video_ops tw9910_subdev_video_ops = {
33047 .s_stream = tw9910_s_stream,
33048 .g_mbus_fmt = tw9910_g_fmt,
33049 .s_mbus_fmt = tw9910_s_fmt,
33050 diff -urNp linux-2.6.39/drivers/media/video/usbvision/usbvision-core.c linux-2.6.39/drivers/media/video/usbvision/usbvision-core.c
33051 --- linux-2.6.39/drivers/media/video/usbvision/usbvision-core.c 2011-05-19 00:06:34.000000000 -0400
33052 +++ linux-2.6.39/drivers/media/video/usbvision/usbvision-core.c 2011-05-22 19:36:31.000000000 -0400
33053 @@ -799,6 +799,8 @@ static enum parse_state usbvision_parse_
33054 unsigned char rv, gv, bv;
33055 static unsigned char *Y, *U, *V;
33056
33057 + pax_track_stack();
33058 +
33059 frame = usbvision->cur_frame;
33060 image_size = frame->frmwidth * frame->frmheight;
33061 if ((frame->v4l2_format.format == V4L2_PIX_FMT_YUV422P) ||
33062 diff -urNp linux-2.6.39/drivers/media/video/usbvision/usbvision-i2c.c linux-2.6.39/drivers/media/video/usbvision/usbvision-i2c.c
33063 --- linux-2.6.39/drivers/media/video/usbvision/usbvision-i2c.c 2011-05-19 00:06:34.000000000 -0400
33064 +++ linux-2.6.39/drivers/media/video/usbvision/usbvision-i2c.c 2011-05-22 19:36:31.000000000 -0400
33065 @@ -189,7 +189,7 @@ static u32 functionality(struct i2c_adap
33066
33067 /* -----exported algorithm data: ------------------------------------- */
33068
33069 -static struct i2c_algorithm usbvision_algo = {
33070 +static const struct i2c_algorithm usbvision_algo = {
33071 .master_xfer = usbvision_i2c_xfer,
33072 .smbus_xfer = NULL,
33073 .functionality = functionality,
33074 diff -urNp linux-2.6.39/drivers/media/video/v4l2-device.c linux-2.6.39/drivers/media/video/v4l2-device.c
33075 --- linux-2.6.39/drivers/media/video/v4l2-device.c 2011-05-19 00:06:34.000000000 -0400
33076 +++ linux-2.6.39/drivers/media/video/v4l2-device.c 2011-05-22 19:36:31.000000000 -0400
33077 @@ -71,9 +71,9 @@ int v4l2_device_put(struct v4l2_device *
33078 EXPORT_SYMBOL_GPL(v4l2_device_put);
33079
33080 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
33081 - atomic_t *instance)
33082 + atomic_unchecked_t *instance)
33083 {
33084 - int num = atomic_inc_return(instance) - 1;
33085 + int num = atomic_inc_return_unchecked(instance) - 1;
33086 int len = strlen(basename);
33087
33088 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
33089 diff -urNp linux-2.6.39/drivers/media/video/videobuf-dma-sg.c linux-2.6.39/drivers/media/video/videobuf-dma-sg.c
33090 --- linux-2.6.39/drivers/media/video/videobuf-dma-sg.c 2011-05-19 00:06:34.000000000 -0400
33091 +++ linux-2.6.39/drivers/media/video/videobuf-dma-sg.c 2011-05-22 19:36:31.000000000 -0400
33092 @@ -606,6 +606,8 @@ void *videobuf_sg_alloc(size_t size)
33093 {
33094 struct videobuf_queue q;
33095
33096 + pax_track_stack();
33097 +
33098 /* Required to make generic handler to call __videobuf_alloc */
33099 q.int_ops = &sg_ops;
33100
33101 diff -urNp linux-2.6.39/drivers/message/fusion/mptbase.c linux-2.6.39/drivers/message/fusion/mptbase.c
33102 --- linux-2.6.39/drivers/message/fusion/mptbase.c 2011-05-19 00:06:34.000000000 -0400
33103 +++ linux-2.6.39/drivers/message/fusion/mptbase.c 2011-05-22 19:41:37.000000000 -0400
33104 @@ -143,7 +143,7 @@ static int MptDriverClass[MPT_MAX_PRO
33105 static MPT_EVHANDLER MptEvHandlers[MPT_MAX_PROTOCOL_DRIVERS];
33106 /* Reset handler lookup table */
33107 static MPT_RESETHANDLER MptResetHandlers[MPT_MAX_PROTOCOL_DRIVERS];
33108 -static struct mpt_pci_driver *MptDeviceDriverHandlers[MPT_MAX_PROTOCOL_DRIVERS];
33109 +static const struct mpt_pci_driver *MptDeviceDriverHandlers[MPT_MAX_PROTOCOL_DRIVERS];
33110
33111 #ifdef CONFIG_PROC_FS
33112 static struct proc_dir_entry *mpt_proc_root_dir;
33113 @@ -772,7 +772,7 @@ mpt_reset_deregister(u8 cb_idx)
33114 * @cb_idx: MPT protocol driver index
33115 */
33116 int
33117 -mpt_device_driver_register(struct mpt_pci_driver * dd_cbfunc, u8 cb_idx)
33118 +mpt_device_driver_register(const struct mpt_pci_driver * dd_cbfunc, u8 cb_idx)
33119 {
33120 MPT_ADAPTER *ioc;
33121 const struct pci_device_id *id;
33122 @@ -801,7 +801,7 @@ mpt_device_driver_register(struct mpt_pc
33123 void
33124 mpt_device_driver_deregister(u8 cb_idx)
33125 {
33126 - struct mpt_pci_driver *dd_cbfunc;
33127 + const struct mpt_pci_driver *dd_cbfunc;
33128 MPT_ADAPTER *ioc;
33129
33130 if (!cb_idx || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
33131 @@ -6683,8 +6683,13 @@ static int mpt_iocinfo_proc_show(struct
33132 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
33133 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
33134
33135 +#ifdef CONFIG_GRKERNSEC_HIDESYM
33136 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
33137 +#else
33138 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
33139 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
33140 +#endif
33141 +
33142 /*
33143 * Rounding UP to nearest 4-kB boundary here...
33144 */
33145 diff -urNp linux-2.6.39/drivers/message/fusion/mptbase.h linux-2.6.39/drivers/message/fusion/mptbase.h
33146 --- linux-2.6.39/drivers/message/fusion/mptbase.h 2011-05-19 00:06:34.000000000 -0400
33147 +++ linux-2.6.39/drivers/message/fusion/mptbase.h 2011-05-22 19:36:31.000000000 -0400
33148 @@ -908,7 +908,7 @@ extern int mpt_event_register(u8 cb_idx
33149 extern void mpt_event_deregister(u8 cb_idx);
33150 extern int mpt_reset_register(u8 cb_idx, MPT_RESETHANDLER reset_func);
33151 extern void mpt_reset_deregister(u8 cb_idx);
33152 -extern int mpt_device_driver_register(struct mpt_pci_driver * dd_cbfunc, u8 cb_idx);
33153 +extern int mpt_device_driver_register(const struct mpt_pci_driver * dd_cbfunc, u8 cb_idx);
33154 extern void mpt_device_driver_deregister(u8 cb_idx);
33155 extern MPT_FRAME_HDR *mpt_get_msg_frame(u8 cb_idx, MPT_ADAPTER *ioc);
33156 extern void mpt_free_msg_frame(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf);
33157 diff -urNp linux-2.6.39/drivers/message/fusion/mptctl.c linux-2.6.39/drivers/message/fusion/mptctl.c
33158 --- linux-2.6.39/drivers/message/fusion/mptctl.c 2011-05-19 00:06:34.000000000 -0400
33159 +++ linux-2.6.39/drivers/message/fusion/mptctl.c 2011-05-22 19:36:31.000000000 -0400
33160 @@ -3000,7 +3000,7 @@ mptctl_remove(struct pci_dev *pdev)
33161 {
33162 }
33163
33164 -static struct mpt_pci_driver mptctl_driver = {
33165 +static const struct mpt_pci_driver mptctl_driver = {
33166 .probe = mptctl_probe,
33167 .remove = mptctl_remove,
33168 };
33169 diff -urNp linux-2.6.39/drivers/message/fusion/mptsas.c linux-2.6.39/drivers/message/fusion/mptsas.c
33170 --- linux-2.6.39/drivers/message/fusion/mptsas.c 2011-05-19 00:06:34.000000000 -0400
33171 +++ linux-2.6.39/drivers/message/fusion/mptsas.c 2011-05-22 19:36:31.000000000 -0400
33172 @@ -439,6 +439,23 @@ mptsas_is_end_device(struct mptsas_devin
33173 return 0;
33174 }
33175
33176 +static inline void
33177 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33178 +{
33179 + if (phy_info->port_details) {
33180 + phy_info->port_details->rphy = rphy;
33181 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33182 + ioc->name, rphy));
33183 + }
33184 +
33185 + if (rphy) {
33186 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33187 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33188 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33189 + ioc->name, rphy, rphy->dev.release));
33190 + }
33191 +}
33192 +
33193 /* no mutex */
33194 static void
33195 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
33196 @@ -477,23 +494,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *p
33197 return NULL;
33198 }
33199
33200 -static inline void
33201 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33202 -{
33203 - if (phy_info->port_details) {
33204 - phy_info->port_details->rphy = rphy;
33205 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33206 - ioc->name, rphy));
33207 - }
33208 -
33209 - if (rphy) {
33210 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33211 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33212 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33213 - ioc->name, rphy, rphy->dev.release));
33214 - }
33215 -}
33216 -
33217 static inline struct sas_port *
33218 mptsas_get_port(struct mptsas_phyinfo *phy_info)
33219 {
33220 diff -urNp linux-2.6.39/drivers/message/fusion/mptscsih.c linux-2.6.39/drivers/message/fusion/mptscsih.c
33221 --- linux-2.6.39/drivers/message/fusion/mptscsih.c 2011-05-19 00:06:34.000000000 -0400
33222 +++ linux-2.6.39/drivers/message/fusion/mptscsih.c 2011-05-22 19:36:31.000000000 -0400
33223 @@ -1268,15 +1268,16 @@ mptscsih_info(struct Scsi_Host *SChost)
33224
33225 h = shost_priv(SChost);
33226
33227 - if (h) {
33228 - if (h->info_kbuf == NULL)
33229 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
33230 - return h->info_kbuf;
33231 - h->info_kbuf[0] = '\0';
33232 + if (!h)
33233 + return NULL;
33234
33235 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
33236 - h->info_kbuf[size-1] = '\0';
33237 - }
33238 + if (h->info_kbuf == NULL)
33239 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
33240 + return h->info_kbuf;
33241 + h->info_kbuf[0] = '\0';
33242 +
33243 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
33244 + h->info_kbuf[size-1] = '\0';
33245
33246 return h->info_kbuf;
33247 }
33248 diff -urNp linux-2.6.39/drivers/message/i2o/i2o_config.c linux-2.6.39/drivers/message/i2o/i2o_config.c
33249 --- linux-2.6.39/drivers/message/i2o/i2o_config.c 2011-05-19 00:06:34.000000000 -0400
33250 +++ linux-2.6.39/drivers/message/i2o/i2o_config.c 2011-05-22 19:36:31.000000000 -0400
33251 @@ -781,6 +781,8 @@ static int i2o_cfg_passthru(unsigned lon
33252 struct i2o_message *msg;
33253 unsigned int iop;
33254
33255 + pax_track_stack();
33256 +
33257 if (get_user(iop, &cmd->iop) || get_user(user_msg, &cmd->msg))
33258 return -EFAULT;
33259
33260 diff -urNp linux-2.6.39/drivers/message/i2o/i2o_proc.c linux-2.6.39/drivers/message/i2o/i2o_proc.c
33261 --- linux-2.6.39/drivers/message/i2o/i2o_proc.c 2011-05-19 00:06:34.000000000 -0400
33262 +++ linux-2.6.39/drivers/message/i2o/i2o_proc.c 2011-05-22 19:36:31.000000000 -0400
33263 @@ -255,13 +255,6 @@ static char *scsi_devices[] = {
33264 "Array Controller Device"
33265 };
33266
33267 -static char *chtostr(u8 * chars, int n)
33268 -{
33269 - char tmp[256];
33270 - tmp[0] = 0;
33271 - return strncat(tmp, (char *)chars, n);
33272 -}
33273 -
33274 static int i2o_report_query_status(struct seq_file *seq, int block_status,
33275 char *group)
33276 {
33277 @@ -838,8 +831,7 @@ static int i2o_seq_show_ddm_table(struct
33278
33279 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
33280 seq_printf(seq, "%-#8x", ddm_table.module_id);
33281 - seq_printf(seq, "%-29s",
33282 - chtostr(ddm_table.module_name_version, 28));
33283 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
33284 seq_printf(seq, "%9d ", ddm_table.data_size);
33285 seq_printf(seq, "%8d", ddm_table.code_size);
33286
33287 @@ -940,8 +932,8 @@ static int i2o_seq_show_drivers_stored(s
33288
33289 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
33290 seq_printf(seq, "%-#8x", dst->module_id);
33291 - seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
33292 - seq_printf(seq, "%-9s", chtostr(dst->date, 8));
33293 + seq_printf(seq, "%-.28s", dst->module_name_version);
33294 + seq_printf(seq, "%-.8s", dst->date);
33295 seq_printf(seq, "%8d ", dst->module_size);
33296 seq_printf(seq, "%8d ", dst->mpb_size);
33297 seq_printf(seq, "0x%04x", dst->module_flags);
33298 @@ -1272,14 +1264,10 @@ static int i2o_seq_show_dev_identity(str
33299 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
33300 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
33301 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
33302 - seq_printf(seq, "Vendor info : %s\n",
33303 - chtostr((u8 *) (work32 + 2), 16));
33304 - seq_printf(seq, "Product info : %s\n",
33305 - chtostr((u8 *) (work32 + 6), 16));
33306 - seq_printf(seq, "Description : %s\n",
33307 - chtostr((u8 *) (work32 + 10), 16));
33308 - seq_printf(seq, "Product rev. : %s\n",
33309 - chtostr((u8 *) (work32 + 14), 8));
33310 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
33311 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
33312 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
33313 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
33314
33315 seq_printf(seq, "Serial number : ");
33316 print_serial_number(seq, (u8 *) (work32 + 16),
33317 @@ -1324,10 +1312,8 @@ static int i2o_seq_show_ddm_identity(str
33318 }
33319
33320 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
33321 - seq_printf(seq, "Module name : %s\n",
33322 - chtostr(result.module_name, 24));
33323 - seq_printf(seq, "Module revision : %s\n",
33324 - chtostr(result.module_rev, 8));
33325 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
33326 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
33327
33328 seq_printf(seq, "Serial number : ");
33329 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
33330 @@ -1358,14 +1344,10 @@ static int i2o_seq_show_uinfo(struct seq
33331 return 0;
33332 }
33333
33334 - seq_printf(seq, "Device name : %s\n",
33335 - chtostr(result.device_name, 64));
33336 - seq_printf(seq, "Service name : %s\n",
33337 - chtostr(result.service_name, 64));
33338 - seq_printf(seq, "Physical name : %s\n",
33339 - chtostr(result.physical_location, 64));
33340 - seq_printf(seq, "Instance number : %s\n",
33341 - chtostr(result.instance_number, 4));
33342 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
33343 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
33344 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
33345 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
33346
33347 return 0;
33348 }
33349 diff -urNp linux-2.6.39/drivers/message/i2o/iop.c linux-2.6.39/drivers/message/i2o/iop.c
33350 --- linux-2.6.39/drivers/message/i2o/iop.c 2011-05-19 00:06:34.000000000 -0400
33351 +++ linux-2.6.39/drivers/message/i2o/iop.c 2011-05-22 19:36:31.000000000 -0400
33352 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_contro
33353
33354 spin_lock_irqsave(&c->context_list_lock, flags);
33355
33356 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
33357 - atomic_inc(&c->context_list_counter);
33358 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
33359 + atomic_inc_unchecked(&c->context_list_counter);
33360
33361 - entry->context = atomic_read(&c->context_list_counter);
33362 + entry->context = atomic_read_unchecked(&c->context_list_counter);
33363
33364 list_add(&entry->list, &c->context_list);
33365
33366 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(voi
33367
33368 #if BITS_PER_LONG == 64
33369 spin_lock_init(&c->context_list_lock);
33370 - atomic_set(&c->context_list_counter, 0);
33371 + atomic_set_unchecked(&c->context_list_counter, 0);
33372 INIT_LIST_HEAD(&c->context_list);
33373 #endif
33374
33375 diff -urNp linux-2.6.39/drivers/mfd/ab3100-core.c linux-2.6.39/drivers/mfd/ab3100-core.c
33376 --- linux-2.6.39/drivers/mfd/ab3100-core.c 2011-05-19 00:06:34.000000000 -0400
33377 +++ linux-2.6.39/drivers/mfd/ab3100-core.c 2011-05-22 19:36:31.000000000 -0400
33378 @@ -385,7 +385,7 @@ static int ab3100_event_registers_startu
33379 return 0;
33380 }
33381
33382 -static struct abx500_ops ab3100_ops = {
33383 +static const struct abx500_ops ab3100_ops = {
33384 .get_chip_id = ab3100_get_chip_id,
33385 .set_register = set_register_interruptible,
33386 .get_register = get_register_interruptible,
33387 diff -urNp linux-2.6.39/drivers/mfd/ab3550-core.c linux-2.6.39/drivers/mfd/ab3550-core.c
33388 --- linux-2.6.39/drivers/mfd/ab3550-core.c 2011-05-19 00:06:34.000000000 -0400
33389 +++ linux-2.6.39/drivers/mfd/ab3550-core.c 2011-05-22 19:36:31.000000000 -0400
33390 @@ -676,7 +676,7 @@ static int ab3550_startup_irq_enabled(st
33391 return val;
33392 }
33393
33394 -static struct abx500_ops ab3550_ops = {
33395 +static const struct abx500_ops ab3550_ops = {
33396 .get_chip_id = ab3550_get_chip_id,
33397 .get_register = ab3550_get_register_interruptible,
33398 .set_register = ab3550_set_register_interruptible,
33399 diff -urNp linux-2.6.39/drivers/mfd/ab8500-core.c linux-2.6.39/drivers/mfd/ab8500-core.c
33400 --- linux-2.6.39/drivers/mfd/ab8500-core.c 2011-05-19 00:06:34.000000000 -0400
33401 +++ linux-2.6.39/drivers/mfd/ab8500-core.c 2011-05-22 19:36:31.000000000 -0400
33402 @@ -223,7 +223,7 @@ static int ab8500_mask_and_set_register(
33403
33404 }
33405
33406 -static struct abx500_ops ab8500_ops = {
33407 +static const struct abx500_ops ab8500_ops = {
33408 .get_chip_id = ab8500_get_chip_id,
33409 .get_register = ab8500_get_register,
33410 .set_register = ab8500_set_register,
33411 diff -urNp linux-2.6.39/drivers/mfd/abx500-core.c linux-2.6.39/drivers/mfd/abx500-core.c
33412 --- linux-2.6.39/drivers/mfd/abx500-core.c 2011-05-19 00:06:34.000000000 -0400
33413 +++ linux-2.6.39/drivers/mfd/abx500-core.c 2011-05-22 19:36:31.000000000 -0400
33414 @@ -18,7 +18,7 @@ struct abx500_device_entry {
33415 struct device *dev;
33416 };
33417
33418 -static void lookup_ops(struct device *dev, struct abx500_ops **ops)
33419 +static void lookup_ops(struct device *dev, const struct abx500_ops **ops)
33420 {
33421 struct abx500_device_entry *dev_entry;
33422
33423 @@ -31,7 +31,7 @@ static void lookup_ops(struct device *de
33424 }
33425 }
33426
33427 -int abx500_register_ops(struct device *dev, struct abx500_ops *ops)
33428 +int abx500_register_ops(struct device *dev, const struct abx500_ops *ops)
33429 {
33430 struct abx500_device_entry *dev_entry;
33431
33432 @@ -65,7 +65,7 @@ EXPORT_SYMBOL(abx500_remove_ops);
33433 int abx500_set_register_interruptible(struct device *dev, u8 bank, u8 reg,
33434 u8 value)
33435 {
33436 - struct abx500_ops *ops;
33437 + const struct abx500_ops *ops;
33438
33439 lookup_ops(dev->parent, &ops);
33440 if ((ops != NULL) && (ops->set_register != NULL))
33441 @@ -78,7 +78,7 @@ EXPORT_SYMBOL(abx500_set_register_interr
33442 int abx500_get_register_interruptible(struct device *dev, u8 bank, u8 reg,
33443 u8 *value)
33444 {
33445 - struct abx500_ops *ops;
33446 + const struct abx500_ops *ops;
33447
33448 lookup_ops(dev->parent, &ops);
33449 if ((ops != NULL) && (ops->get_register != NULL))
33450 @@ -91,7 +91,7 @@ EXPORT_SYMBOL(abx500_get_register_interr
33451 int abx500_get_register_page_interruptible(struct device *dev, u8 bank,
33452 u8 first_reg, u8 *regvals, u8 numregs)
33453 {
33454 - struct abx500_ops *ops;
33455 + const struct abx500_ops *ops;
33456
33457 lookup_ops(dev->parent, &ops);
33458 if ((ops != NULL) && (ops->get_register_page != NULL))
33459 @@ -105,7 +105,7 @@ EXPORT_SYMBOL(abx500_get_register_page_i
33460 int abx500_mask_and_set_register_interruptible(struct device *dev, u8 bank,
33461 u8 reg, u8 bitmask, u8 bitvalues)
33462 {
33463 - struct abx500_ops *ops;
33464 + const struct abx500_ops *ops;
33465
33466 lookup_ops(dev->parent, &ops);
33467 if ((ops != NULL) && (ops->mask_and_set_register != NULL))
33468 @@ -118,7 +118,7 @@ EXPORT_SYMBOL(abx500_mask_and_set_regist
33469
33470 int abx500_get_chip_id(struct device *dev)
33471 {
33472 - struct abx500_ops *ops;
33473 + const struct abx500_ops *ops;
33474
33475 lookup_ops(dev->parent, &ops);
33476 if ((ops != NULL) && (ops->get_chip_id != NULL))
33477 @@ -130,7 +130,7 @@ EXPORT_SYMBOL(abx500_get_chip_id);
33478
33479 int abx500_event_registers_startup_state_get(struct device *dev, u8 *event)
33480 {
33481 - struct abx500_ops *ops;
33482 + const struct abx500_ops *ops;
33483
33484 lookup_ops(dev->parent, &ops);
33485 if ((ops != NULL) && (ops->event_registers_startup_state_get != NULL))
33486 @@ -142,7 +142,7 @@ EXPORT_SYMBOL(abx500_event_registers_sta
33487
33488 int abx500_startup_irq_enabled(struct device *dev, unsigned int irq)
33489 {
33490 - struct abx500_ops *ops;
33491 + const struct abx500_ops *ops;
33492
33493 lookup_ops(dev->parent, &ops);
33494 if ((ops != NULL) && (ops->startup_irq_enabled != NULL))
33495 diff -urNp linux-2.6.39/drivers/mfd/janz-cmodio.c linux-2.6.39/drivers/mfd/janz-cmodio.c
33496 --- linux-2.6.39/drivers/mfd/janz-cmodio.c 2011-05-19 00:06:34.000000000 -0400
33497 +++ linux-2.6.39/drivers/mfd/janz-cmodio.c 2011-05-22 19:36:31.000000000 -0400
33498 @@ -13,6 +13,7 @@
33499
33500 #include <linux/kernel.h>
33501 #include <linux/module.h>
33502 +#include <linux/slab.h>
33503 #include <linux/init.h>
33504 #include <linux/pci.h>
33505 #include <linux/interrupt.h>
33506 diff -urNp linux-2.6.39/drivers/mfd/mcp-sa11x0.c linux-2.6.39/drivers/mfd/mcp-sa11x0.c
33507 --- linux-2.6.39/drivers/mfd/mcp-sa11x0.c 2011-05-19 00:06:34.000000000 -0400
33508 +++ linux-2.6.39/drivers/mfd/mcp-sa11x0.c 2011-05-22 19:36:31.000000000 -0400
33509 @@ -128,7 +128,7 @@ static void mcp_sa11x0_disable(struct mc
33510 /*
33511 * Our methods.
33512 */
33513 -static struct mcp_ops mcp_sa11x0 = {
33514 +static const struct mcp_ops mcp_sa11x0 = {
33515 .set_telecom_divisor = mcp_sa11x0_set_telecom_divisor,
33516 .set_audio_divisor = mcp_sa11x0_set_audio_divisor,
33517 .reg_write = mcp_sa11x0_write,
33518 diff -urNp linux-2.6.39/drivers/mfd/wm8350-i2c.c linux-2.6.39/drivers/mfd/wm8350-i2c.c
33519 --- linux-2.6.39/drivers/mfd/wm8350-i2c.c 2011-05-19 00:06:34.000000000 -0400
33520 +++ linux-2.6.39/drivers/mfd/wm8350-i2c.c 2011-05-22 19:36:31.000000000 -0400
33521 @@ -44,6 +44,8 @@ static int wm8350_i2c_write_device(struc
33522 u8 msg[(WM8350_MAX_REGISTER << 1) + 1];
33523 int ret;
33524
33525 + pax_track_stack();
33526 +
33527 if (bytes > ((WM8350_MAX_REGISTER << 1) + 1))
33528 return -EINVAL;
33529
33530 diff -urNp linux-2.6.39/drivers/misc/enclosure.c linux-2.6.39/drivers/misc/enclosure.c
33531 --- linux-2.6.39/drivers/misc/enclosure.c 2011-05-19 00:06:34.000000000 -0400
33532 +++ linux-2.6.39/drivers/misc/enclosure.c 2011-05-22 19:36:31.000000000 -0400
33533 @@ -161,7 +161,7 @@ enclosure_register(struct device *dev, c
33534 }
33535 EXPORT_SYMBOL_GPL(enclosure_register);
33536
33537 -static struct enclosure_component_callbacks enclosure_null_callbacks;
33538 +static const struct enclosure_component_callbacks enclosure_null_callbacks;
33539
33540 /**
33541 * enclosure_unregister - remove an enclosure
33542 diff -urNp linux-2.6.39/drivers/misc/kgdbts.c linux-2.6.39/drivers/misc/kgdbts.c
33543 --- linux-2.6.39/drivers/misc/kgdbts.c 2011-05-19 00:06:34.000000000 -0400
33544 +++ linux-2.6.39/drivers/misc/kgdbts.c 2011-05-22 19:36:31.000000000 -0400
33545 @@ -118,7 +118,7 @@
33546 } while (0)
33547 #define MAX_CONFIG_LEN 40
33548
33549 -static struct kgdb_io kgdbts_io_ops;
33550 +static const struct kgdb_io kgdbts_io_ops;
33551 static char get_buf[BUFMAX];
33552 static int get_buf_cnt;
33553 static char put_buf[BUFMAX];
33554 @@ -1103,7 +1103,7 @@ static void kgdbts_post_exp_handler(void
33555 module_put(THIS_MODULE);
33556 }
33557
33558 -static struct kgdb_io kgdbts_io_ops = {
33559 +static const struct kgdb_io kgdbts_io_ops = {
33560 .name = "kgdbts",
33561 .read_char = kgdbts_get_char,
33562 .write_char = kgdbts_put_char,
33563 diff -urNp linux-2.6.39/drivers/misc/lis3lv02d/lis3lv02d.c linux-2.6.39/drivers/misc/lis3lv02d/lis3lv02d.c
33564 --- linux-2.6.39/drivers/misc/lis3lv02d/lis3lv02d.c 2011-05-19 00:06:34.000000000 -0400
33565 +++ linux-2.6.39/drivers/misc/lis3lv02d/lis3lv02d.c 2011-05-22 19:36:31.000000000 -0400
33566 @@ -435,7 +435,7 @@ static irqreturn_t lis302dl_interrupt(in
33567 * the lid is closed. This leads to interrupts as soon as a little move
33568 * is done.
33569 */
33570 - atomic_inc(&lis3_dev.count);
33571 + atomic_inc_unchecked(&lis3_dev.count);
33572
33573 wake_up_interruptible(&lis3_dev.misc_wait);
33574 kill_fasync(&lis3_dev.async_queue, SIGIO, POLL_IN);
33575 @@ -518,7 +518,7 @@ static int lis3lv02d_misc_open(struct in
33576 if (lis3_dev.pm_dev)
33577 pm_runtime_get_sync(lis3_dev.pm_dev);
33578
33579 - atomic_set(&lis3_dev.count, 0);
33580 + atomic_set_unchecked(&lis3_dev.count, 0);
33581 return 0;
33582 }
33583
33584 @@ -545,7 +545,7 @@ static ssize_t lis3lv02d_misc_read(struc
33585 add_wait_queue(&lis3_dev.misc_wait, &wait);
33586 while (true) {
33587 set_current_state(TASK_INTERRUPTIBLE);
33588 - data = atomic_xchg(&lis3_dev.count, 0);
33589 + data = atomic_xchg_unchecked(&lis3_dev.count, 0);
33590 if (data)
33591 break;
33592
33593 @@ -583,7 +583,7 @@ out:
33594 static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
33595 {
33596 poll_wait(file, &lis3_dev.misc_wait, wait);
33597 - if (atomic_read(&lis3_dev.count))
33598 + if (atomic_read_unchecked(&lis3_dev.count))
33599 return POLLIN | POLLRDNORM;
33600 return 0;
33601 }
33602 diff -urNp linux-2.6.39/drivers/misc/lis3lv02d/lis3lv02d.h linux-2.6.39/drivers/misc/lis3lv02d/lis3lv02d.h
33603 --- linux-2.6.39/drivers/misc/lis3lv02d/lis3lv02d.h 2011-05-19 00:06:34.000000000 -0400
33604 +++ linux-2.6.39/drivers/misc/lis3lv02d/lis3lv02d.h 2011-05-22 19:36:31.000000000 -0400
33605 @@ -265,7 +265,7 @@ struct lis3lv02d {
33606 struct input_polled_dev *idev; /* input device */
33607 struct platform_device *pdev; /* platform device */
33608 struct regulator_bulk_data regulators[2];
33609 - atomic_t count; /* interrupt count after last read */
33610 + atomic_unchecked_t count; /* interrupt count after last read */
33611 union axis_conversion ac; /* hw -> logical axis */
33612 int mapped_btns[3];
33613
33614 diff -urNp linux-2.6.39/drivers/misc/sgi-gru/gruhandles.c linux-2.6.39/drivers/misc/sgi-gru/gruhandles.c
33615 --- linux-2.6.39/drivers/misc/sgi-gru/gruhandles.c 2011-05-19 00:06:34.000000000 -0400
33616 +++ linux-2.6.39/drivers/misc/sgi-gru/gruhandles.c 2011-05-22 19:36:31.000000000 -0400
33617 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op
33618 unsigned long nsec;
33619
33620 nsec = CLKS2NSEC(clks);
33621 - atomic_long_inc(&mcs_op_statistics[op].count);
33622 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
33623 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
33624 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
33625 if (mcs_op_statistics[op].max < nsec)
33626 mcs_op_statistics[op].max = nsec;
33627 }
33628 diff -urNp linux-2.6.39/drivers/misc/sgi-gru/gruprocfs.c linux-2.6.39/drivers/misc/sgi-gru/gruprocfs.c
33629 --- linux-2.6.39/drivers/misc/sgi-gru/gruprocfs.c 2011-05-19 00:06:34.000000000 -0400
33630 +++ linux-2.6.39/drivers/misc/sgi-gru/gruprocfs.c 2011-05-22 19:36:31.000000000 -0400
33631 @@ -32,9 +32,9 @@
33632
33633 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
33634
33635 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
33636 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
33637 {
33638 - unsigned long val = atomic_long_read(v);
33639 + unsigned long val = atomic_long_read_unchecked(v);
33640
33641 seq_printf(s, "%16lu %s\n", val, id);
33642 }
33643 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct se
33644
33645 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
33646 for (op = 0; op < mcsop_last; op++) {
33647 - count = atomic_long_read(&mcs_op_statistics[op].count);
33648 - total = atomic_long_read(&mcs_op_statistics[op].total);
33649 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
33650 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
33651 max = mcs_op_statistics[op].max;
33652 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
33653 count ? total / count : 0, max);
33654 diff -urNp linux-2.6.39/drivers/misc/sgi-gru/grutables.h linux-2.6.39/drivers/misc/sgi-gru/grutables.h
33655 --- linux-2.6.39/drivers/misc/sgi-gru/grutables.h 2011-05-19 00:06:34.000000000 -0400
33656 +++ linux-2.6.39/drivers/misc/sgi-gru/grutables.h 2011-05-22 19:36:31.000000000 -0400
33657 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
33658 * GRU statistics.
33659 */
33660 struct gru_stats_s {
33661 - atomic_long_t vdata_alloc;
33662 - atomic_long_t vdata_free;
33663 - atomic_long_t gts_alloc;
33664 - atomic_long_t gts_free;
33665 - atomic_long_t gms_alloc;
33666 - atomic_long_t gms_free;
33667 - atomic_long_t gts_double_allocate;
33668 - atomic_long_t assign_context;
33669 - atomic_long_t assign_context_failed;
33670 - atomic_long_t free_context;
33671 - atomic_long_t load_user_context;
33672 - atomic_long_t load_kernel_context;
33673 - atomic_long_t lock_kernel_context;
33674 - atomic_long_t unlock_kernel_context;
33675 - atomic_long_t steal_user_context;
33676 - atomic_long_t steal_kernel_context;
33677 - atomic_long_t steal_context_failed;
33678 - atomic_long_t nopfn;
33679 - atomic_long_t asid_new;
33680 - atomic_long_t asid_next;
33681 - atomic_long_t asid_wrap;
33682 - atomic_long_t asid_reuse;
33683 - atomic_long_t intr;
33684 - atomic_long_t intr_cbr;
33685 - atomic_long_t intr_tfh;
33686 - atomic_long_t intr_spurious;
33687 - atomic_long_t intr_mm_lock_failed;
33688 - atomic_long_t call_os;
33689 - atomic_long_t call_os_wait_queue;
33690 - atomic_long_t user_flush_tlb;
33691 - atomic_long_t user_unload_context;
33692 - atomic_long_t user_exception;
33693 - atomic_long_t set_context_option;
33694 - atomic_long_t check_context_retarget_intr;
33695 - atomic_long_t check_context_unload;
33696 - atomic_long_t tlb_dropin;
33697 - atomic_long_t tlb_preload_page;
33698 - atomic_long_t tlb_dropin_fail_no_asid;
33699 - atomic_long_t tlb_dropin_fail_upm;
33700 - atomic_long_t tlb_dropin_fail_invalid;
33701 - atomic_long_t tlb_dropin_fail_range_active;
33702 - atomic_long_t tlb_dropin_fail_idle;
33703 - atomic_long_t tlb_dropin_fail_fmm;
33704 - atomic_long_t tlb_dropin_fail_no_exception;
33705 - atomic_long_t tfh_stale_on_fault;
33706 - atomic_long_t mmu_invalidate_range;
33707 - atomic_long_t mmu_invalidate_page;
33708 - atomic_long_t flush_tlb;
33709 - atomic_long_t flush_tlb_gru;
33710 - atomic_long_t flush_tlb_gru_tgh;
33711 - atomic_long_t flush_tlb_gru_zero_asid;
33712 -
33713 - atomic_long_t copy_gpa;
33714 - atomic_long_t read_gpa;
33715 -
33716 - atomic_long_t mesq_receive;
33717 - atomic_long_t mesq_receive_none;
33718 - atomic_long_t mesq_send;
33719 - atomic_long_t mesq_send_failed;
33720 - atomic_long_t mesq_noop;
33721 - atomic_long_t mesq_send_unexpected_error;
33722 - atomic_long_t mesq_send_lb_overflow;
33723 - atomic_long_t mesq_send_qlimit_reached;
33724 - atomic_long_t mesq_send_amo_nacked;
33725 - atomic_long_t mesq_send_put_nacked;
33726 - atomic_long_t mesq_page_overflow;
33727 - atomic_long_t mesq_qf_locked;
33728 - atomic_long_t mesq_qf_noop_not_full;
33729 - atomic_long_t mesq_qf_switch_head_failed;
33730 - atomic_long_t mesq_qf_unexpected_error;
33731 - atomic_long_t mesq_noop_unexpected_error;
33732 - atomic_long_t mesq_noop_lb_overflow;
33733 - atomic_long_t mesq_noop_qlimit_reached;
33734 - atomic_long_t mesq_noop_amo_nacked;
33735 - atomic_long_t mesq_noop_put_nacked;
33736 - atomic_long_t mesq_noop_page_overflow;
33737 + atomic_long_unchecked_t vdata_alloc;
33738 + atomic_long_unchecked_t vdata_free;
33739 + atomic_long_unchecked_t gts_alloc;
33740 + atomic_long_unchecked_t gts_free;
33741 + atomic_long_unchecked_t gms_alloc;
33742 + atomic_long_unchecked_t gms_free;
33743 + atomic_long_unchecked_t gts_double_allocate;
33744 + atomic_long_unchecked_t assign_context;
33745 + atomic_long_unchecked_t assign_context_failed;
33746 + atomic_long_unchecked_t free_context;
33747 + atomic_long_unchecked_t load_user_context;
33748 + atomic_long_unchecked_t load_kernel_context;
33749 + atomic_long_unchecked_t lock_kernel_context;
33750 + atomic_long_unchecked_t unlock_kernel_context;
33751 + atomic_long_unchecked_t steal_user_context;
33752 + atomic_long_unchecked_t steal_kernel_context;
33753 + atomic_long_unchecked_t steal_context_failed;
33754 + atomic_long_unchecked_t nopfn;
33755 + atomic_long_unchecked_t asid_new;
33756 + atomic_long_unchecked_t asid_next;
33757 + atomic_long_unchecked_t asid_wrap;
33758 + atomic_long_unchecked_t asid_reuse;
33759 + atomic_long_unchecked_t intr;
33760 + atomic_long_unchecked_t intr_cbr;
33761 + atomic_long_unchecked_t intr_tfh;
33762 + atomic_long_unchecked_t intr_spurious;
33763 + atomic_long_unchecked_t intr_mm_lock_failed;
33764 + atomic_long_unchecked_t call_os;
33765 + atomic_long_unchecked_t call_os_wait_queue;
33766 + atomic_long_unchecked_t user_flush_tlb;
33767 + atomic_long_unchecked_t user_unload_context;
33768 + atomic_long_unchecked_t user_exception;
33769 + atomic_long_unchecked_t set_context_option;
33770 + atomic_long_unchecked_t check_context_retarget_intr;
33771 + atomic_long_unchecked_t check_context_unload;
33772 + atomic_long_unchecked_t tlb_dropin;
33773 + atomic_long_unchecked_t tlb_preload_page;
33774 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
33775 + atomic_long_unchecked_t tlb_dropin_fail_upm;
33776 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
33777 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
33778 + atomic_long_unchecked_t tlb_dropin_fail_idle;
33779 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
33780 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
33781 + atomic_long_unchecked_t tfh_stale_on_fault;
33782 + atomic_long_unchecked_t mmu_invalidate_range;
33783 + atomic_long_unchecked_t mmu_invalidate_page;
33784 + atomic_long_unchecked_t flush_tlb;
33785 + atomic_long_unchecked_t flush_tlb_gru;
33786 + atomic_long_unchecked_t flush_tlb_gru_tgh;
33787 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
33788 +
33789 + atomic_long_unchecked_t copy_gpa;
33790 + atomic_long_unchecked_t read_gpa;
33791 +
33792 + atomic_long_unchecked_t mesq_receive;
33793 + atomic_long_unchecked_t mesq_receive_none;
33794 + atomic_long_unchecked_t mesq_send;
33795 + atomic_long_unchecked_t mesq_send_failed;
33796 + atomic_long_unchecked_t mesq_noop;
33797 + atomic_long_unchecked_t mesq_send_unexpected_error;
33798 + atomic_long_unchecked_t mesq_send_lb_overflow;
33799 + atomic_long_unchecked_t mesq_send_qlimit_reached;
33800 + atomic_long_unchecked_t mesq_send_amo_nacked;
33801 + atomic_long_unchecked_t mesq_send_put_nacked;
33802 + atomic_long_unchecked_t mesq_page_overflow;
33803 + atomic_long_unchecked_t mesq_qf_locked;
33804 + atomic_long_unchecked_t mesq_qf_noop_not_full;
33805 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
33806 + atomic_long_unchecked_t mesq_qf_unexpected_error;
33807 + atomic_long_unchecked_t mesq_noop_unexpected_error;
33808 + atomic_long_unchecked_t mesq_noop_lb_overflow;
33809 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
33810 + atomic_long_unchecked_t mesq_noop_amo_nacked;
33811 + atomic_long_unchecked_t mesq_noop_put_nacked;
33812 + atomic_long_unchecked_t mesq_noop_page_overflow;
33813
33814 };
33815
33816 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start
33817 tghop_invalidate, mcsop_last};
33818
33819 struct mcs_op_statistic {
33820 - atomic_long_t count;
33821 - atomic_long_t total;
33822 + atomic_long_unchecked_t count;
33823 + atomic_long_unchecked_t total;
33824 unsigned long max;
33825 };
33826
33827 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_st
33828
33829 #define STAT(id) do { \
33830 if (gru_options & OPT_STATS) \
33831 - atomic_long_inc(&gru_stats.id); \
33832 + atomic_long_inc_unchecked(&gru_stats.id); \
33833 } while (0)
33834
33835 #ifdef CONFIG_SGI_GRU_DEBUG
33836 diff -urNp linux-2.6.39/drivers/misc/sgi-xp/xpc_sn2.c linux-2.6.39/drivers/misc/sgi-xp/xpc_sn2.c
33837 --- linux-2.6.39/drivers/misc/sgi-xp/xpc_sn2.c 2011-05-19 00:06:34.000000000 -0400
33838 +++ linux-2.6.39/drivers/misc/sgi-xp/xpc_sn2.c 2011-05-22 19:36:31.000000000 -0400
33839 @@ -2351,7 +2351,7 @@ xpc_received_payload_sn2(struct xpc_chan
33840 xpc_acknowledge_msgs_sn2(ch, get, msg->flags);
33841 }
33842
33843 -static struct xpc_arch_operations xpc_arch_ops_sn2 = {
33844 +static const struct xpc_arch_operations xpc_arch_ops_sn2 = {
33845 .setup_partitions = xpc_setup_partitions_sn2,
33846 .teardown_partitions = xpc_teardown_partitions_sn2,
33847 .process_activate_IRQ_rcvd = xpc_process_activate_IRQ_rcvd_sn2,
33848 diff -urNp linux-2.6.39/drivers/misc/sgi-xp/xpc_uv.c linux-2.6.39/drivers/misc/sgi-xp/xpc_uv.c
33849 --- linux-2.6.39/drivers/misc/sgi-xp/xpc_uv.c 2011-05-19 00:06:34.000000000 -0400
33850 +++ linux-2.6.39/drivers/misc/sgi-xp/xpc_uv.c 2011-05-22 19:36:31.000000000 -0400
33851 @@ -1674,7 +1674,7 @@ xpc_received_payload_uv(struct xpc_chann
33852 XPC_DEACTIVATE_PARTITION(&xpc_partitions[ch->partid], ret);
33853 }
33854
33855 -static struct xpc_arch_operations xpc_arch_ops_uv = {
33856 +static const struct xpc_arch_operations xpc_arch_ops_uv = {
33857 .setup_partitions = xpc_setup_partitions_uv,
33858 .teardown_partitions = xpc_teardown_partitions_uv,
33859 .process_activate_IRQ_rcvd = xpc_process_activate_IRQ_rcvd_uv,
33860 diff -urNp linux-2.6.39/drivers/misc/spear13xx_pcie_gadget.c linux-2.6.39/drivers/misc/spear13xx_pcie_gadget.c
33861 --- linux-2.6.39/drivers/misc/spear13xx_pcie_gadget.c 2011-05-19 00:06:34.000000000 -0400
33862 +++ linux-2.6.39/drivers/misc/spear13xx_pcie_gadget.c 2011-05-22 19:36:31.000000000 -0400
33863 @@ -644,7 +644,7 @@ static ssize_t pcie_gadget_target_attr_s
33864 return ret;
33865 }
33866
33867 -static struct configfs_item_operations pcie_gadget_target_item_ops = {
33868 +static const struct configfs_item_operations pcie_gadget_target_item_ops = {
33869 .show_attribute = pcie_gadget_target_attr_show,
33870 .store_attribute = pcie_gadget_target_attr_store,
33871 };
33872 diff -urNp linux-2.6.39/drivers/mmc/host/davinci_mmc.c linux-2.6.39/drivers/mmc/host/davinci_mmc.c
33873 --- linux-2.6.39/drivers/mmc/host/davinci_mmc.c 2011-05-19 00:06:34.000000000 -0400
33874 +++ linux-2.6.39/drivers/mmc/host/davinci_mmc.c 2011-05-22 19:36:31.000000000 -0400
33875 @@ -1133,7 +1133,7 @@ static void mmc_davinci_enable_sdio_irq(
33876 }
33877 }
33878
33879 -static struct mmc_host_ops mmc_davinci_ops = {
33880 +static const struct mmc_host_ops mmc_davinci_ops = {
33881 .request = mmc_davinci_request,
33882 .set_ios = mmc_davinci_set_ios,
33883 .get_cd = mmc_davinci_get_cd,
33884 diff -urNp linux-2.6.39/drivers/mmc/host/dw_mmc.c linux-2.6.39/drivers/mmc/host/dw_mmc.c
33885 --- linux-2.6.39/drivers/mmc/host/dw_mmc.c 2011-05-19 00:06:34.000000000 -0400
33886 +++ linux-2.6.39/drivers/mmc/host/dw_mmc.c 2011-05-22 19:36:31.000000000 -0400
33887 @@ -417,7 +417,7 @@ static int dw_mci_idmac_init(struct dw_m
33888 return 0;
33889 }
33890
33891 -static struct dw_mci_dma_ops dw_mci_idmac_ops = {
33892 +static const struct dw_mci_dma_ops dw_mci_idmac_ops = {
33893 .init = dw_mci_idmac_init,
33894 .start = dw_mci_idmac_start_dma,
33895 .stop = dw_mci_idmac_stop_dma,
33896 diff -urNp linux-2.6.39/drivers/mmc/host/s3cmci.c linux-2.6.39/drivers/mmc/host/s3cmci.c
33897 --- linux-2.6.39/drivers/mmc/host/s3cmci.c 2011-05-19 00:06:34.000000000 -0400
33898 +++ linux-2.6.39/drivers/mmc/host/s3cmci.c 2011-05-22 19:36:31.000000000 -0400
33899 @@ -1349,7 +1349,7 @@ static void s3cmci_enable_sdio_irq(struc
33900 s3cmci_check_sdio_irq(host);
33901 }
33902
33903 -static struct mmc_host_ops s3cmci_ops = {
33904 +static const struct mmc_host_ops s3cmci_ops = {
33905 .request = s3cmci_request,
33906 .set_ios = s3cmci_set_ios,
33907 .get_ro = s3cmci_get_ro,
33908 diff -urNp linux-2.6.39/drivers/mmc/host/sdhci-cns3xxx.c linux-2.6.39/drivers/mmc/host/sdhci-cns3xxx.c
33909 --- linux-2.6.39/drivers/mmc/host/sdhci-cns3xxx.c 2011-05-19 00:06:34.000000000 -0400
33910 +++ linux-2.6.39/drivers/mmc/host/sdhci-cns3xxx.c 2011-05-22 19:36:31.000000000 -0400
33911 @@ -81,7 +81,7 @@ out:
33912 host->clock = clock;
33913 }
33914
33915 -static struct sdhci_ops sdhci_cns3xxx_ops = {
33916 +static const struct sdhci_ops sdhci_cns3xxx_ops = {
33917 .get_max_clock = sdhci_cns3xxx_get_max_clk,
33918 .set_clock = sdhci_cns3xxx_set_clock,
33919 };
33920 diff -urNp linux-2.6.39/drivers/mmc/host/sdhci-dove.c linux-2.6.39/drivers/mmc/host/sdhci-dove.c
33921 --- linux-2.6.39/drivers/mmc/host/sdhci-dove.c 2011-05-19 00:06:34.000000000 -0400
33922 +++ linux-2.6.39/drivers/mmc/host/sdhci-dove.c 2011-05-22 19:36:31.000000000 -0400
33923 @@ -56,7 +56,7 @@ static u32 sdhci_dove_readl(struct sdhci
33924 return ret;
33925 }
33926
33927 -static struct sdhci_ops sdhci_dove_ops = {
33928 +static const struct sdhci_ops sdhci_dove_ops = {
33929 .read_w = sdhci_dove_readw,
33930 .read_l = sdhci_dove_readl,
33931 };
33932 diff -urNp linux-2.6.39/drivers/mmc/host/sdhci-esdhc-imx.c linux-2.6.39/drivers/mmc/host/sdhci-esdhc-imx.c
33933 --- linux-2.6.39/drivers/mmc/host/sdhci-esdhc-imx.c 2011-05-19 00:06:34.000000000 -0400
33934 +++ linux-2.6.39/drivers/mmc/host/sdhci-esdhc-imx.c 2011-05-22 19:36:31.000000000 -0400
33935 @@ -201,7 +201,7 @@ static unsigned int esdhc_pltfm_get_ro(s
33936 return -ENOSYS;
33937 }
33938
33939 -static struct sdhci_ops sdhci_esdhc_ops = {
33940 +static const struct sdhci_ops sdhci_esdhc_ops = {
33941 .read_l = esdhc_readl_le,
33942 .read_w = esdhc_readw_le,
33943 .write_l = esdhc_writel_le,
33944 diff -urNp linux-2.6.39/drivers/mmc/host/sdhci-of.h linux-2.6.39/drivers/mmc/host/sdhci-of.h
33945 --- linux-2.6.39/drivers/mmc/host/sdhci-of.h 2011-05-19 00:06:34.000000000 -0400
33946 +++ linux-2.6.39/drivers/mmc/host/sdhci-of.h 2011-05-22 19:36:31.000000000 -0400
33947 @@ -21,7 +21,7 @@
33948
33949 struct sdhci_of_data {
33950 unsigned int quirks;
33951 - struct sdhci_ops ops;
33952 + const struct sdhci_ops ops;
33953 };
33954
33955 struct sdhci_of_host {
33956 diff -urNp linux-2.6.39/drivers/mmc/host/sdhci-pci.c linux-2.6.39/drivers/mmc/host/sdhci-pci.c
33957 --- linux-2.6.39/drivers/mmc/host/sdhci-pci.c 2011-05-19 00:06:34.000000000 -0400
33958 +++ linux-2.6.39/drivers/mmc/host/sdhci-pci.c 2011-05-22 19:36:31.000000000 -0400
33959 @@ -786,7 +786,7 @@ static int sdhci_pci_enable_dma(struct s
33960 return 0;
33961 }
33962
33963 -static struct sdhci_ops sdhci_pci_ops = {
33964 +static const struct sdhci_ops sdhci_pci_ops = {
33965 .enable_dma = sdhci_pci_enable_dma,
33966 };
33967
33968 diff -urNp linux-2.6.39/drivers/mmc/host/sdhci-pltfm.c linux-2.6.39/drivers/mmc/host/sdhci-pltfm.c
33969 --- linux-2.6.39/drivers/mmc/host/sdhci-pltfm.c 2011-05-19 00:06:34.000000000 -0400
33970 +++ linux-2.6.39/drivers/mmc/host/sdhci-pltfm.c 2011-05-22 19:36:31.000000000 -0400
33971 @@ -41,7 +41,7 @@
33972 * *
33973 \*****************************************************************************/
33974
33975 -static struct sdhci_ops sdhci_pltfm_ops = {
33976 +static const struct sdhci_ops sdhci_pltfm_ops = {
33977 };
33978
33979 /*****************************************************************************\
33980 diff -urNp linux-2.6.39/drivers/mmc/host/sdhci-pxa.c linux-2.6.39/drivers/mmc/host/sdhci-pxa.c
33981 --- linux-2.6.39/drivers/mmc/host/sdhci-pxa.c 2011-05-19 00:06:34.000000000 -0400
33982 +++ linux-2.6.39/drivers/mmc/host/sdhci-pxa.c 2011-05-22 19:36:31.000000000 -0400
33983 @@ -69,7 +69,7 @@ static void set_clock(struct sdhci_host
33984 }
33985 }
33986
33987 -static struct sdhci_ops sdhci_pxa_ops = {
33988 +static const struct sdhci_ops sdhci_pxa_ops = {
33989 .set_clock = set_clock,
33990 };
33991
33992 diff -urNp linux-2.6.39/drivers/mmc/host/sdhci-s3c.c linux-2.6.39/drivers/mmc/host/sdhci-s3c.c
33993 --- linux-2.6.39/drivers/mmc/host/sdhci-s3c.c 2011-05-19 00:06:34.000000000 -0400
33994 +++ linux-2.6.39/drivers/mmc/host/sdhci-s3c.c 2011-05-22 19:36:31.000000000 -0400
33995 @@ -309,7 +309,7 @@ static int sdhci_s3c_platform_8bit_width
33996 return 0;
33997 }
33998
33999 -static struct sdhci_ops sdhci_s3c_ops = {
34000 +static const struct sdhci_ops sdhci_s3c_ops = {
34001 .get_max_clock = sdhci_s3c_get_max_clk,
34002 .set_clock = sdhci_s3c_set_clock,
34003 .get_min_clock = sdhci_s3c_get_min_clock,
34004 diff -urNp linux-2.6.39/drivers/mmc/host/sdhci-spear.c linux-2.6.39/drivers/mmc/host/sdhci-spear.c
34005 --- linux-2.6.39/drivers/mmc/host/sdhci-spear.c 2011-05-19 00:06:34.000000000 -0400
34006 +++ linux-2.6.39/drivers/mmc/host/sdhci-spear.c 2011-05-22 19:36:31.000000000 -0400
34007 @@ -32,7 +32,7 @@ struct spear_sdhci {
34008 };
34009
34010 /* sdhci ops */
34011 -static struct sdhci_ops sdhci_pltfm_ops = {
34012 +static const struct sdhci_ops sdhci_pltfm_ops = {
34013 /* Nothing to do for now. */
34014 };
34015
34016 diff -urNp linux-2.6.39/drivers/mmc/host/sdhci-tegra.c linux-2.6.39/drivers/mmc/host/sdhci-tegra.c
34017 --- linux-2.6.39/drivers/mmc/host/sdhci-tegra.c 2011-05-19 00:06:34.000000000 -0400
34018 +++ linux-2.6.39/drivers/mmc/host/sdhci-tegra.c 2011-05-22 19:36:31.000000000 -0400
34019 @@ -242,7 +242,7 @@ static void tegra_sdhci_pltfm_exit(struc
34020 clk_put(pltfm_host->clk);
34021 }
34022
34023 -static struct sdhci_ops tegra_sdhci_ops = {
34024 +static const struct sdhci_ops tegra_sdhci_ops = {
34025 .get_ro = tegra_sdhci_get_ro,
34026 .read_l = tegra_sdhci_readl,
34027 .read_w = tegra_sdhci_readw,
34028 diff -urNp linux-2.6.39/drivers/mmc/host/sdricoh_cs.c linux-2.6.39/drivers/mmc/host/sdricoh_cs.c
34029 --- linux-2.6.39/drivers/mmc/host/sdricoh_cs.c 2011-05-19 00:06:34.000000000 -0400
34030 +++ linux-2.6.39/drivers/mmc/host/sdricoh_cs.c 2011-05-22 19:36:31.000000000 -0400
34031 @@ -387,7 +387,7 @@ static int sdricoh_get_ro(struct mmc_hos
34032 return (status & STATUS_CARD_LOCKED);
34033 }
34034
34035 -static struct mmc_host_ops sdricoh_ops = {
34036 +static const struct mmc_host_ops sdricoh_ops = {
34037 .request = sdricoh_request,
34038 .set_ios = sdricoh_set_ios,
34039 .get_ro = sdricoh_get_ro,
34040 diff -urNp linux-2.6.39/drivers/mmc/host/sh_mmcif.c linux-2.6.39/drivers/mmc/host/sh_mmcif.c
34041 --- linux-2.6.39/drivers/mmc/host/sh_mmcif.c 2011-05-19 00:06:34.000000000 -0400
34042 +++ linux-2.6.39/drivers/mmc/host/sh_mmcif.c 2011-05-22 19:36:31.000000000 -0400
34043 @@ -872,7 +872,7 @@ static int sh_mmcif_get_cd(struct mmc_ho
34044 return p->get_cd(host->pd);
34045 }
34046
34047 -static struct mmc_host_ops sh_mmcif_ops = {
34048 +static const struct mmc_host_ops sh_mmcif_ops = {
34049 .request = sh_mmcif_request,
34050 .set_ios = sh_mmcif_set_ios,
34051 .get_cd = sh_mmcif_get_cd,
34052 diff -urNp linux-2.6.39/drivers/mtd/chips/cfi_cmdset_0001.c linux-2.6.39/drivers/mtd/chips/cfi_cmdset_0001.c
34053 --- linux-2.6.39/drivers/mtd/chips/cfi_cmdset_0001.c 2011-05-19 00:06:34.000000000 -0400
34054 +++ linux-2.6.39/drivers/mtd/chips/cfi_cmdset_0001.c 2011-05-22 19:36:31.000000000 -0400
34055 @@ -757,6 +757,8 @@ static int chip_ready (struct map_info *
34056 struct cfi_pri_intelext *cfip = cfi->cmdset_priv;
34057 unsigned long timeo = jiffies + HZ;
34058
34059 + pax_track_stack();
34060 +
34061 /* Prevent setting state FL_SYNCING for chip in suspended state. */
34062 if (mode == FL_SYNCING && chip->oldstate != FL_READY)
34063 goto sleep;
34064 @@ -1657,6 +1659,8 @@ static int __xipram do_write_buffer(stru
34065 unsigned long initial_adr;
34066 int initial_len = len;
34067
34068 + pax_track_stack();
34069 +
34070 wbufsize = cfi_interleave(cfi) << cfi->cfiq->MaxBufWriteSize;
34071 adr += chip->start;
34072 initial_adr = adr;
34073 @@ -1875,6 +1879,8 @@ static int __xipram do_erase_oneblock(st
34074 int retries = 3;
34075 int ret;
34076
34077 + pax_track_stack();
34078 +
34079 adr += chip->start;
34080
34081 retry:
34082 diff -urNp linux-2.6.39/drivers/mtd/chips/cfi_cmdset_0020.c linux-2.6.39/drivers/mtd/chips/cfi_cmdset_0020.c
34083 --- linux-2.6.39/drivers/mtd/chips/cfi_cmdset_0020.c 2011-05-19 00:06:34.000000000 -0400
34084 +++ linux-2.6.39/drivers/mtd/chips/cfi_cmdset_0020.c 2011-05-22 19:36:31.000000000 -0400
34085 @@ -255,6 +255,8 @@ static inline int do_read_onechip(struct
34086 unsigned long cmd_addr;
34087 struct cfi_private *cfi = map->fldrv_priv;
34088
34089 + pax_track_stack();
34090 +
34091 adr += chip->start;
34092
34093 /* Ensure cmd read/writes are aligned. */
34094 @@ -428,6 +430,8 @@ static inline int do_write_buffer(struct
34095 DECLARE_WAITQUEUE(wait, current);
34096 int wbufsize, z;
34097
34098 + pax_track_stack();
34099 +
34100 /* M58LW064A requires bus alignment for buffer wriets -- saw */
34101 if (adr & (map_bankwidth(map)-1))
34102 return -EINVAL;
34103 @@ -742,6 +746,8 @@ static inline int do_erase_oneblock(stru
34104 DECLARE_WAITQUEUE(wait, current);
34105 int ret = 0;
34106
34107 + pax_track_stack();
34108 +
34109 adr += chip->start;
34110
34111 /* Let's determine this according to the interleave only once */
34112 @@ -1047,6 +1053,8 @@ static inline int do_lock_oneblock(struc
34113 unsigned long timeo = jiffies + HZ;
34114 DECLARE_WAITQUEUE(wait, current);
34115
34116 + pax_track_stack();
34117 +
34118 adr += chip->start;
34119
34120 /* Let's determine this according to the interleave only once */
34121 @@ -1196,6 +1204,8 @@ static inline int do_unlock_oneblock(str
34122 unsigned long timeo = jiffies + HZ;
34123 DECLARE_WAITQUEUE(wait, current);
34124
34125 + pax_track_stack();
34126 +
34127 adr += chip->start;
34128
34129 /* Let's determine this according to the interleave only once */
34130 diff -urNp linux-2.6.39/drivers/mtd/devices/doc2000.c linux-2.6.39/drivers/mtd/devices/doc2000.c
34131 --- linux-2.6.39/drivers/mtd/devices/doc2000.c 2011-05-19 00:06:34.000000000 -0400
34132 +++ linux-2.6.39/drivers/mtd/devices/doc2000.c 2011-05-22 19:36:31.000000000 -0400
34133 @@ -776,7 +776,7 @@ static int doc_write(struct mtd_info *mt
34134
34135 /* The ECC will not be calculated correctly if less than 512 is written */
34136 /* DBB-
34137 - if (len != 0x200 && eccbuf)
34138 + if (len != 0x200)
34139 printk(KERN_WARNING
34140 "ECC needs a full sector write (adr: %lx size %lx)\n",
34141 (long) to, (long) len);
34142 diff -urNp linux-2.6.39/drivers/mtd/devices/doc2001.c linux-2.6.39/drivers/mtd/devices/doc2001.c
34143 --- linux-2.6.39/drivers/mtd/devices/doc2001.c 2011-05-19 00:06:34.000000000 -0400
34144 +++ linux-2.6.39/drivers/mtd/devices/doc2001.c 2011-05-22 19:36:31.000000000 -0400
34145 @@ -393,7 +393,7 @@ static int doc_read (struct mtd_info *mt
34146 struct Nand *mychip = &this->chips[from >> (this->chipshift)];
34147
34148 /* Don't allow read past end of device */
34149 - if (from >= this->totlen)
34150 + if (from >= this->totlen || !len)
34151 return -EINVAL;
34152
34153 /* Don't allow a single read to cross a 512-byte block boundary */
34154 diff -urNp linux-2.6.39/drivers/mtd/ftl.c linux-2.6.39/drivers/mtd/ftl.c
34155 --- linux-2.6.39/drivers/mtd/ftl.c 2011-05-19 00:06:34.000000000 -0400
34156 +++ linux-2.6.39/drivers/mtd/ftl.c 2011-05-22 19:36:31.000000000 -0400
34157 @@ -474,6 +474,8 @@ static int copy_erase_unit(partition_t *
34158 loff_t offset;
34159 uint16_t srcunitswap = cpu_to_le16(srcunit);
34160
34161 + pax_track_stack();
34162 +
34163 eun = &part->EUNInfo[srcunit];
34164 xfer = &part->XferInfo[xferunit];
34165 DEBUG(2, "ftl_cs: copying block 0x%x to 0x%x\n",
34166 diff -urNp linux-2.6.39/drivers/mtd/inftlcore.c linux-2.6.39/drivers/mtd/inftlcore.c
34167 --- linux-2.6.39/drivers/mtd/inftlcore.c 2011-05-19 00:06:34.000000000 -0400
34168 +++ linux-2.6.39/drivers/mtd/inftlcore.c 2011-05-22 19:36:31.000000000 -0400
34169 @@ -259,6 +259,8 @@ static u16 INFTL_foldchain(struct INFTLr
34170 struct inftl_oob oob;
34171 size_t retlen;
34172
34173 + pax_track_stack();
34174 +
34175 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: INFTL_foldchain(inftl=%p,thisVUC=%d,"
34176 "pending=%d)\n", inftl, thisVUC, pendingblock);
34177
34178 diff -urNp linux-2.6.39/drivers/mtd/inftlmount.c linux-2.6.39/drivers/mtd/inftlmount.c
34179 --- linux-2.6.39/drivers/mtd/inftlmount.c 2011-05-19 00:06:34.000000000 -0400
34180 +++ linux-2.6.39/drivers/mtd/inftlmount.c 2011-05-22 19:36:31.000000000 -0400
34181 @@ -53,6 +53,8 @@ static int find_boot_record(struct INFTL
34182 struct INFTLPartition *ip;
34183 size_t retlen;
34184
34185 + pax_track_stack();
34186 +
34187 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: find_boot_record(inftl=%p)\n", inftl);
34188
34189 /*
34190 diff -urNp linux-2.6.39/drivers/mtd/lpddr/qinfo_probe.c linux-2.6.39/drivers/mtd/lpddr/qinfo_probe.c
34191 --- linux-2.6.39/drivers/mtd/lpddr/qinfo_probe.c 2011-05-19 00:06:34.000000000 -0400
34192 +++ linux-2.6.39/drivers/mtd/lpddr/qinfo_probe.c 2011-05-22 19:36:31.000000000 -0400
34193 @@ -106,6 +106,8 @@ static int lpddr_pfow_present(struct map
34194 {
34195 map_word pfow_val[4];
34196
34197 + pax_track_stack();
34198 +
34199 /* Check identification string */
34200 pfow_val[0] = map_read(map, map->pfow_base + PFOW_QUERY_STRING_P);
34201 pfow_val[1] = map_read(map, map->pfow_base + PFOW_QUERY_STRING_F);
34202 diff -urNp linux-2.6.39/drivers/mtd/mtdchar.c linux-2.6.39/drivers/mtd/mtdchar.c
34203 --- linux-2.6.39/drivers/mtd/mtdchar.c 2011-05-19 00:06:34.000000000 -0400
34204 +++ linux-2.6.39/drivers/mtd/mtdchar.c 2011-05-22 19:36:31.000000000 -0400
34205 @@ -560,6 +560,8 @@ static int mtd_ioctl(struct file *file,
34206 u_long size;
34207 struct mtd_info_user info;
34208
34209 + pax_track_stack();
34210 +
34211 DEBUG(MTD_DEBUG_LEVEL0, "MTD_ioctl\n");
34212
34213 size = (cmd & IOCSIZE_MASK) >> IOCSIZE_SHIFT;
34214 diff -urNp linux-2.6.39/drivers/mtd/nand/denali.c linux-2.6.39/drivers/mtd/nand/denali.c
34215 --- linux-2.6.39/drivers/mtd/nand/denali.c 2011-05-19 00:06:34.000000000 -0400
34216 +++ linux-2.6.39/drivers/mtd/nand/denali.c 2011-05-22 19:36:31.000000000 -0400
34217 @@ -25,6 +25,7 @@
34218 #include <linux/pci.h>
34219 #include <linux/mtd/mtd.h>
34220 #include <linux/module.h>
34221 +#include <linux/slab.h>
34222
34223 #include "denali.h"
34224
34225 diff -urNp linux-2.6.39/drivers/mtd/nftlcore.c linux-2.6.39/drivers/mtd/nftlcore.c
34226 --- linux-2.6.39/drivers/mtd/nftlcore.c 2011-05-19 00:06:34.000000000 -0400
34227 +++ linux-2.6.39/drivers/mtd/nftlcore.c 2011-05-22 19:36:31.000000000 -0400
34228 @@ -264,6 +264,8 @@ static u16 NFTL_foldchain (struct NFTLre
34229 int inplace = 1;
34230 size_t retlen;
34231
34232 + pax_track_stack();
34233 +
34234 memset(BlockMap, 0xff, sizeof(BlockMap));
34235 memset(BlockFreeFound, 0, sizeof(BlockFreeFound));
34236
34237 diff -urNp linux-2.6.39/drivers/mtd/nftlmount.c linux-2.6.39/drivers/mtd/nftlmount.c
34238 --- linux-2.6.39/drivers/mtd/nftlmount.c 2011-05-19 00:06:34.000000000 -0400
34239 +++ linux-2.6.39/drivers/mtd/nftlmount.c 2011-05-22 19:36:31.000000000 -0400
34240 @@ -24,6 +24,7 @@
34241 #include <asm/errno.h>
34242 #include <linux/delay.h>
34243 #include <linux/slab.h>
34244 +#include <linux/sched.h>
34245 #include <linux/mtd/mtd.h>
34246 #include <linux/mtd/nand.h>
34247 #include <linux/mtd/nftl.h>
34248 @@ -45,6 +46,8 @@ static int find_boot_record(struct NFTLr
34249 struct mtd_info *mtd = nftl->mbd.mtd;
34250 unsigned int i;
34251
34252 + pax_track_stack();
34253 +
34254 /* Assume logical EraseSize == physical erasesize for starting the scan.
34255 We'll sort it out later if we find a MediaHeader which says otherwise */
34256 /* Actually, we won't. The new DiskOnChip driver has already scanned
34257 diff -urNp linux-2.6.39/drivers/mtd/ubi/build.c linux-2.6.39/drivers/mtd/ubi/build.c
34258 --- linux-2.6.39/drivers/mtd/ubi/build.c 2011-05-19 00:06:34.000000000 -0400
34259 +++ linux-2.6.39/drivers/mtd/ubi/build.c 2011-05-22 19:36:31.000000000 -0400
34260 @@ -1287,7 +1287,7 @@ module_exit(ubi_exit);
34261 static int __init bytes_str_to_int(const char *str)
34262 {
34263 char *endp;
34264 - unsigned long result;
34265 + unsigned long result, scale = 1;
34266
34267 result = simple_strtoul(str, &endp, 0);
34268 if (str == endp || result >= INT_MAX) {
34269 @@ -1298,11 +1298,11 @@ static int __init bytes_str_to_int(const
34270
34271 switch (*endp) {
34272 case 'G':
34273 - result *= 1024;
34274 + scale *= 1024;
34275 case 'M':
34276 - result *= 1024;
34277 + scale *= 1024;
34278 case 'K':
34279 - result *= 1024;
34280 + scale *= 1024;
34281 if (endp[1] == 'i' && endp[2] == 'B')
34282 endp += 2;
34283 case '\0':
34284 @@ -1313,7 +1313,13 @@ static int __init bytes_str_to_int(const
34285 return -EINVAL;
34286 }
34287
34288 - return result;
34289 + if ((intoverflow_t)result*scale >= INT_MAX) {
34290 + printk(KERN_ERR "UBI error: incorrect bytes count: \"%s\"\n",
34291 + str);
34292 + return -EINVAL;
34293 + }
34294 +
34295 + return result*scale;
34296 }
34297
34298 /**
34299 diff -urNp linux-2.6.39/drivers/net/bcm63xx_enet.c linux-2.6.39/drivers/net/bcm63xx_enet.c
34300 --- linux-2.6.39/drivers/net/bcm63xx_enet.c 2011-05-19 00:06:34.000000000 -0400
34301 +++ linux-2.6.39/drivers/net/bcm63xx_enet.c 2011-05-22 19:36:31.000000000 -0400
34302 @@ -1469,7 +1469,7 @@ static int bcm_enet_set_pauseparam(struc
34303 return 0;
34304 }
34305
34306 -static struct ethtool_ops bcm_enet_ethtool_ops = {
34307 +static const struct ethtool_ops bcm_enet_ethtool_ops = {
34308 .get_strings = bcm_enet_get_strings,
34309 .get_sset_count = bcm_enet_get_sset_count,
34310 .get_ethtool_stats = bcm_enet_get_ethtool_stats,
34311 diff -urNp linux-2.6.39/drivers/net/bna/bnad_ethtool.c linux-2.6.39/drivers/net/bna/bnad_ethtool.c
34312 --- linux-2.6.39/drivers/net/bna/bnad_ethtool.c 2011-05-19 00:06:34.000000000 -0400
34313 +++ linux-2.6.39/drivers/net/bna/bnad_ethtool.c 2011-05-22 19:36:31.000000000 -0400
34314 @@ -1242,7 +1242,7 @@ bnad_get_sset_count(struct net_device *n
34315 }
34316 }
34317
34318 -static struct ethtool_ops bnad_ethtool_ops = {
34319 +static const struct ethtool_ops bnad_ethtool_ops = {
34320 .get_settings = bnad_get_settings,
34321 .set_settings = bnad_set_settings,
34322 .get_drvinfo = bnad_get_drvinfo,
34323 diff -urNp linux-2.6.39/drivers/net/bnx2.c linux-2.6.39/drivers/net/bnx2.c
34324 --- linux-2.6.39/drivers/net/bnx2.c 2011-05-19 00:06:34.000000000 -0400
34325 +++ linux-2.6.39/drivers/net/bnx2.c 2011-05-22 19:36:31.000000000 -0400
34326 @@ -5828,6 +5828,8 @@ bnx2_test_nvram(struct bnx2 *bp)
34327 int rc = 0;
34328 u32 magic, csum;
34329
34330 + pax_track_stack();
34331 +
34332 if ((rc = bnx2_nvram_read(bp, 0, data, 4)) != 0)
34333 goto test_nvram_done;
34334
34335 diff -urNp linux-2.6.39/drivers/net/bnx2x/bnx2x_ethtool.c linux-2.6.39/drivers/net/bnx2x/bnx2x_ethtool.c
34336 --- linux-2.6.39/drivers/net/bnx2x/bnx2x_ethtool.c 2011-05-19 00:06:34.000000000 -0400
34337 +++ linux-2.6.39/drivers/net/bnx2x/bnx2x_ethtool.c 2011-05-22 19:36:31.000000000 -0400
34338 @@ -1788,6 +1788,8 @@ static int bnx2x_test_nvram(struct bnx2x
34339 int i, rc;
34340 u32 magic, crc;
34341
34342 + pax_track_stack();
34343 +
34344 if (BP_NOMCP(bp))
34345 return 0;
34346
34347 diff -urNp linux-2.6.39/drivers/net/chelsio/pm3393.c linux-2.6.39/drivers/net/chelsio/pm3393.c
34348 --- linux-2.6.39/drivers/net/chelsio/pm3393.c 2011-05-19 00:06:34.000000000 -0400
34349 +++ linux-2.6.39/drivers/net/chelsio/pm3393.c 2011-05-22 19:36:31.000000000 -0400
34350 @@ -571,7 +571,7 @@ static void pm3393_destroy(struct cmac *
34351 kfree(cmac);
34352 }
34353
34354 -static struct cmac_ops pm3393_ops = {
34355 +static const struct cmac_ops pm3393_ops = {
34356 .destroy = pm3393_destroy,
34357 .reset = pm3393_reset,
34358 .interrupt_enable = pm3393_interrupt_enable,
34359 diff -urNp linux-2.6.39/drivers/net/chelsio/vsc7326.c linux-2.6.39/drivers/net/chelsio/vsc7326.c
34360 --- linux-2.6.39/drivers/net/chelsio/vsc7326.c 2011-05-19 00:06:34.000000000 -0400
34361 +++ linux-2.6.39/drivers/net/chelsio/vsc7326.c 2011-05-22 19:36:31.000000000 -0400
34362 @@ -666,7 +666,7 @@ static void mac_destroy(struct cmac *mac
34363 kfree(mac);
34364 }
34365
34366 -static struct cmac_ops vsc7326_ops = {
34367 +static const struct cmac_ops vsc7326_ops = {
34368 .destroy = mac_destroy,
34369 .reset = mac_reset,
34370 .interrupt_handler = mac_intr_handler,
34371 diff -urNp linux-2.6.39/drivers/net/cxgb4/cxgb4_main.c linux-2.6.39/drivers/net/cxgb4/cxgb4_main.c
34372 --- linux-2.6.39/drivers/net/cxgb4/cxgb4_main.c 2011-05-19 00:06:34.000000000 -0400
34373 +++ linux-2.6.39/drivers/net/cxgb4/cxgb4_main.c 2011-05-22 19:36:31.000000000 -0400
34374 @@ -3428,6 +3428,8 @@ static int __devinit enable_msix(struct
34375 unsigned int nchan = adap->params.nports;
34376 struct msix_entry entries[MAX_INGQ + 1];
34377
34378 + pax_track_stack();
34379 +
34380 for (i = 0; i < ARRAY_SIZE(entries); ++i)
34381 entries[i].entry = i;
34382
34383 diff -urNp linux-2.6.39/drivers/net/cxgb4/t4_hw.c linux-2.6.39/drivers/net/cxgb4/t4_hw.c
34384 --- linux-2.6.39/drivers/net/cxgb4/t4_hw.c 2011-05-19 00:06:34.000000000 -0400
34385 +++ linux-2.6.39/drivers/net/cxgb4/t4_hw.c 2011-05-22 19:36:31.000000000 -0400
34386 @@ -362,6 +362,8 @@ static int get_vpd_params(struct adapter
34387 u8 vpd[VPD_LEN], csum;
34388 unsigned int vpdr_len, kw_offset, id_len;
34389
34390 + pax_track_stack();
34391 +
34392 ret = pci_read_vpd(adapter->pdev, VPD_BASE, sizeof(vpd), vpd);
34393 if (ret < 0)
34394 return ret;
34395 diff -urNp linux-2.6.39/drivers/net/cxgb4vf/cxgb4vf_main.c linux-2.6.39/drivers/net/cxgb4vf/cxgb4vf_main.c
34396 --- linux-2.6.39/drivers/net/cxgb4vf/cxgb4vf_main.c 2011-05-19 00:06:34.000000000 -0400
34397 +++ linux-2.6.39/drivers/net/cxgb4vf/cxgb4vf_main.c 2011-05-22 19:36:31.000000000 -0400
34398 @@ -1572,7 +1572,7 @@ static int cxgb4vf_set_tso(struct net_de
34399 return 0;
34400 }
34401
34402 -static struct ethtool_ops cxgb4vf_ethtool_ops = {
34403 +static const struct ethtool_ops cxgb4vf_ethtool_ops = {
34404 .get_settings = cxgb4vf_get_settings,
34405 .get_drvinfo = cxgb4vf_get_drvinfo,
34406 .get_msglevel = cxgb4vf_get_msglevel,
34407 diff -urNp linux-2.6.39/drivers/net/e1000e/82571.c linux-2.6.39/drivers/net/e1000e/82571.c
34408 --- linux-2.6.39/drivers/net/e1000e/82571.c 2011-05-19 00:06:34.000000000 -0400
34409 +++ linux-2.6.39/drivers/net/e1000e/82571.c 2011-05-22 19:36:31.000000000 -0400
34410 @@ -239,7 +239,7 @@ static s32 e1000_init_mac_params_82571(s
34411 {
34412 struct e1000_hw *hw = &adapter->hw;
34413 struct e1000_mac_info *mac = &hw->mac;
34414 - struct e1000_mac_operations *func = &mac->ops;
34415 + struct e1000_mac_operations *func = &mac->ops; /* cannot be const */
34416 u32 swsm = 0;
34417 u32 swsm2 = 0;
34418 bool force_clear_smbi = false;
34419 @@ -1930,7 +1930,7 @@ static void e1000_clear_hw_cntrs_82571(s
34420 er32(ICRXDMTC);
34421 }
34422
34423 -static struct e1000_mac_operations e82571_mac_ops = {
34424 +static const struct e1000_mac_operations e82571_mac_ops = {
34425 /* .check_mng_mode: mac type dependent */
34426 /* .check_for_link: media type dependent */
34427 .id_led_init = e1000e_id_led_init,
34428 @@ -1952,7 +1952,7 @@ static struct e1000_mac_operations e8257
34429 .read_mac_addr = e1000_read_mac_addr_82571,
34430 };
34431
34432 -static struct e1000_phy_operations e82_phy_ops_igp = {
34433 +static const struct e1000_phy_operations e82_phy_ops_igp = {
34434 .acquire = e1000_get_hw_semaphore_82571,
34435 .check_polarity = e1000_check_polarity_igp,
34436 .check_reset_block = e1000e_check_reset_block_generic,
34437 @@ -1970,7 +1970,7 @@ static struct e1000_phy_operations e82_p
34438 .cfg_on_link_up = NULL,
34439 };
34440
34441 -static struct e1000_phy_operations e82_phy_ops_m88 = {
34442 +static const struct e1000_phy_operations e82_phy_ops_m88 = {
34443 .acquire = e1000_get_hw_semaphore_82571,
34444 .check_polarity = e1000_check_polarity_m88,
34445 .check_reset_block = e1000e_check_reset_block_generic,
34446 @@ -1988,7 +1988,7 @@ static struct e1000_phy_operations e82_p
34447 .cfg_on_link_up = NULL,
34448 };
34449
34450 -static struct e1000_phy_operations e82_phy_ops_bm = {
34451 +static const struct e1000_phy_operations e82_phy_ops_bm = {
34452 .acquire = e1000_get_hw_semaphore_82571,
34453 .check_polarity = e1000_check_polarity_m88,
34454 .check_reset_block = e1000e_check_reset_block_generic,
34455 @@ -2006,7 +2006,7 @@ static struct e1000_phy_operations e82_p
34456 .cfg_on_link_up = NULL,
34457 };
34458
34459 -static struct e1000_nvm_operations e82571_nvm_ops = {
34460 +static const struct e1000_nvm_operations e82571_nvm_ops = {
34461 .acquire = e1000_acquire_nvm_82571,
34462 .read = e1000e_read_nvm_eerd,
34463 .release = e1000_release_nvm_82571,
34464 diff -urNp linux-2.6.39/drivers/net/e1000e/e1000.h linux-2.6.39/drivers/net/e1000e/e1000.h
34465 --- linux-2.6.39/drivers/net/e1000e/e1000.h 2011-05-19 00:06:34.000000000 -0400
34466 +++ linux-2.6.39/drivers/net/e1000e/e1000.h 2011-05-22 19:36:31.000000000 -0400
34467 @@ -409,9 +409,9 @@ struct e1000_info {
34468 u32 pba;
34469 u32 max_hw_frame_size;
34470 s32 (*get_variants)(struct e1000_adapter *);
34471 - struct e1000_mac_operations *mac_ops;
34472 - struct e1000_phy_operations *phy_ops;
34473 - struct e1000_nvm_operations *nvm_ops;
34474 + const struct e1000_mac_operations *mac_ops;
34475 + const struct e1000_phy_operations *phy_ops;
34476 + const struct e1000_nvm_operations *nvm_ops;
34477 };
34478
34479 /* hardware capability, feature, and workaround flags */
34480 diff -urNp linux-2.6.39/drivers/net/e1000e/es2lan.c linux-2.6.39/drivers/net/e1000e/es2lan.c
34481 --- linux-2.6.39/drivers/net/e1000e/es2lan.c 2011-05-19 00:06:34.000000000 -0400
34482 +++ linux-2.6.39/drivers/net/e1000e/es2lan.c 2011-05-22 19:36:31.000000000 -0400
34483 @@ -205,7 +205,7 @@ static s32 e1000_init_mac_params_80003es
34484 {
34485 struct e1000_hw *hw = &adapter->hw;
34486 struct e1000_mac_info *mac = &hw->mac;
34487 - struct e1000_mac_operations *func = &mac->ops;
34488 + struct e1000_mac_operations *func = &mac->ops; /* cannot be const */
34489
34490 /* Set media type */
34491 switch (adapter->pdev->device) {
34492 @@ -1431,7 +1431,7 @@ static void e1000_clear_hw_cntrs_80003es
34493 er32(ICRXDMTC);
34494 }
34495
34496 -static struct e1000_mac_operations es2_mac_ops = {
34497 +static const struct e1000_mac_operations es2_mac_ops = {
34498 .read_mac_addr = e1000_read_mac_addr_80003es2lan,
34499 .id_led_init = e1000e_id_led_init,
34500 .check_mng_mode = e1000e_check_mng_mode_generic,
34501 @@ -1453,7 +1453,7 @@ static struct e1000_mac_operations es2_m
34502 .setup_led = e1000e_setup_led_generic,
34503 };
34504
34505 -static struct e1000_phy_operations es2_phy_ops = {
34506 +static const struct e1000_phy_operations es2_phy_ops = {
34507 .acquire = e1000_acquire_phy_80003es2lan,
34508 .check_polarity = e1000_check_polarity_m88,
34509 .check_reset_block = e1000e_check_reset_block_generic,
34510 @@ -1471,7 +1471,7 @@ static struct e1000_phy_operations es2_p
34511 .cfg_on_link_up = e1000_cfg_on_link_up_80003es2lan,
34512 };
34513
34514 -static struct e1000_nvm_operations es2_nvm_ops = {
34515 +static const struct e1000_nvm_operations es2_nvm_ops = {
34516 .acquire = e1000_acquire_nvm_80003es2lan,
34517 .read = e1000e_read_nvm_eerd,
34518 .release = e1000_release_nvm_80003es2lan,
34519 diff -urNp linux-2.6.39/drivers/net/e1000e/hw.h linux-2.6.39/drivers/net/e1000e/hw.h
34520 --- linux-2.6.39/drivers/net/e1000e/hw.h 2011-05-19 00:06:34.000000000 -0400
34521 +++ linux-2.6.39/drivers/net/e1000e/hw.h 2011-05-22 19:36:31.000000000 -0400
34522 @@ -811,6 +811,7 @@ struct e1000_nvm_operations {
34523 };
34524
34525 struct e1000_mac_info {
34526 + /* cannot be const see e1000_init_mac_params_ich8lan */
34527 struct e1000_mac_operations ops;
34528 u8 addr[ETH_ALEN];
34529 u8 perm_addr[ETH_ALEN];
34530 @@ -852,6 +853,7 @@ struct e1000_mac_info {
34531 };
34532
34533 struct e1000_phy_info {
34534 + /* Cannot be const see e1000_init_phy_params_82571() */
34535 struct e1000_phy_operations ops;
34536
34537 enum e1000_phy_type type;
34538 @@ -886,6 +888,7 @@ struct e1000_phy_info {
34539 };
34540
34541 struct e1000_nvm_info {
34542 + /* cannot be const */
34543 struct e1000_nvm_operations ops;
34544
34545 enum e1000_nvm_type type;
34546 diff -urNp linux-2.6.39/drivers/net/e1000e/ich8lan.c linux-2.6.39/drivers/net/e1000e/ich8lan.c
34547 --- linux-2.6.39/drivers/net/e1000e/ich8lan.c 2011-05-19 00:06:34.000000000 -0400
34548 +++ linux-2.6.39/drivers/net/e1000e/ich8lan.c 2011-05-22 19:36:31.000000000 -0400
34549 @@ -3866,7 +3866,7 @@ static void e1000_clear_hw_cntrs_ich8lan
34550 }
34551 }
34552
34553 -static struct e1000_mac_operations ich8_mac_ops = {
34554 +static const struct e1000_mac_operations ich8_mac_ops = {
34555 .id_led_init = e1000e_id_led_init,
34556 /* check_mng_mode dependent on mac type */
34557 .check_for_link = e1000_check_for_copper_link_ich8lan,
34558 @@ -3885,7 +3885,7 @@ static struct e1000_mac_operations ich8_
34559 /* id_led_init dependent on mac type */
34560 };
34561
34562 -static struct e1000_phy_operations ich8_phy_ops = {
34563 +static const struct e1000_phy_operations ich8_phy_ops = {
34564 .acquire = e1000_acquire_swflag_ich8lan,
34565 .check_reset_block = e1000_check_reset_block_ich8lan,
34566 .commit = NULL,
34567 @@ -3899,7 +3899,7 @@ static struct e1000_phy_operations ich8_
34568 .write_reg = e1000e_write_phy_reg_igp,
34569 };
34570
34571 -static struct e1000_nvm_operations ich8_nvm_ops = {
34572 +static const struct e1000_nvm_operations ich8_nvm_ops = {
34573 .acquire = e1000_acquire_nvm_ich8lan,
34574 .read = e1000_read_nvm_ich8lan,
34575 .release = e1000_release_nvm_ich8lan,
34576 diff -urNp linux-2.6.39/drivers/net/greth.c linux-2.6.39/drivers/net/greth.c
34577 --- linux-2.6.39/drivers/net/greth.c 2011-05-19 00:06:34.000000000 -0400
34578 +++ linux-2.6.39/drivers/net/greth.c 2011-05-22 19:36:31.000000000 -0400
34579 @@ -1192,7 +1192,7 @@ static const struct ethtool_ops greth_et
34580 .get_link = ethtool_op_get_link,
34581 };
34582
34583 -static struct net_device_ops greth_netdev_ops = {
34584 +static const struct net_device_ops greth_netdev_ops = {
34585 .ndo_open = greth_open,
34586 .ndo_stop = greth_close,
34587 .ndo_start_xmit = greth_start_xmit,
34588 diff -urNp linux-2.6.39/drivers/net/hamradio/6pack.c linux-2.6.39/drivers/net/hamradio/6pack.c
34589 --- linux-2.6.39/drivers/net/hamradio/6pack.c 2011-05-19 00:06:34.000000000 -0400
34590 +++ linux-2.6.39/drivers/net/hamradio/6pack.c 2011-05-22 19:36:31.000000000 -0400
34591 @@ -463,6 +463,8 @@ static void sixpack_receive_buf(struct t
34592 unsigned char buf[512];
34593 int count1;
34594
34595 + pax_track_stack();
34596 +
34597 if (!count)
34598 return;
34599
34600 diff -urNp linux-2.6.39/drivers/net/ibm_newemac/phy.c linux-2.6.39/drivers/net/ibm_newemac/phy.c
34601 --- linux-2.6.39/drivers/net/ibm_newemac/phy.c 2011-05-19 00:06:34.000000000 -0400
34602 +++ linux-2.6.39/drivers/net/ibm_newemac/phy.c 2011-05-22 19:36:31.000000000 -0400
34603 @@ -273,7 +273,7 @@ static int genmii_read_link(struct mii_p
34604 }
34605
34606 /* Generic implementation for most 10/100/1000 PHYs */
34607 -static struct mii_phy_ops generic_phy_ops = {
34608 +static const struct mii_phy_ops generic_phy_ops = {
34609 .setup_aneg = genmii_setup_aneg,
34610 .setup_forced = genmii_setup_forced,
34611 .poll_link = genmii_poll_link,
34612 @@ -337,7 +337,7 @@ static int cis8201_init(struct mii_phy *
34613 return 0;
34614 }
34615
34616 -static struct mii_phy_ops cis8201_phy_ops = {
34617 +static const struct mii_phy_ops cis8201_phy_ops = {
34618 .init = cis8201_init,
34619 .setup_aneg = genmii_setup_aneg,
34620 .setup_forced = genmii_setup_forced,
34621 @@ -417,7 +417,7 @@ static int et1011c_init(struct mii_phy *
34622 return 0;
34623 }
34624
34625 -static struct mii_phy_ops et1011c_phy_ops = {
34626 +static const struct mii_phy_ops et1011c_phy_ops = {
34627 .init = et1011c_init,
34628 .setup_aneg = genmii_setup_aneg,
34629 .setup_forced = genmii_setup_forced,
34630 @@ -436,7 +436,7 @@ static struct mii_phy_def et1011c_phy_de
34631
34632
34633
34634 -static struct mii_phy_ops m88e1111_phy_ops = {
34635 +static const struct mii_phy_ops m88e1111_phy_ops = {
34636 .init = m88e1111_init,
34637 .setup_aneg = genmii_setup_aneg,
34638 .setup_forced = genmii_setup_forced,
34639 @@ -452,7 +452,7 @@ static struct mii_phy_def m88e1111_phy_d
34640 .ops = &m88e1111_phy_ops,
34641 };
34642
34643 -static struct mii_phy_ops m88e1112_phy_ops = {
34644 +static const struct mii_phy_ops m88e1112_phy_ops = {
34645 .init = m88e1112_init,
34646 .setup_aneg = genmii_setup_aneg,
34647 .setup_forced = genmii_setup_forced,
34648 diff -urNp linux-2.6.39/drivers/net/ibmveth.c linux-2.6.39/drivers/net/ibmveth.c
34649 --- linux-2.6.39/drivers/net/ibmveth.c 2011-05-19 00:06:34.000000000 -0400
34650 +++ linux-2.6.39/drivers/net/ibmveth.c 2011-05-22 19:36:31.000000000 -0400
34651 @@ -1625,7 +1625,7 @@ static struct vio_device_id ibmveth_devi
34652 };
34653 MODULE_DEVICE_TABLE(vio, ibmveth_device_table);
34654
34655 -static struct dev_pm_ops ibmveth_pm_ops = {
34656 +static const struct dev_pm_ops ibmveth_pm_ops = {
34657 .resume = ibmveth_resume
34658 };
34659
34660 diff -urNp linux-2.6.39/drivers/net/igb/e1000_82575.c linux-2.6.39/drivers/net/igb/e1000_82575.c
34661 --- linux-2.6.39/drivers/net/igb/e1000_82575.c 2011-05-19 00:06:34.000000000 -0400
34662 +++ linux-2.6.39/drivers/net/igb/e1000_82575.c 2011-05-22 19:36:31.000000000 -0400
34663 @@ -2029,7 +2029,7 @@ out:
34664 return ret_val;
34665 }
34666
34667 -static struct e1000_mac_operations e1000_mac_ops_82575 = {
34668 +static const struct e1000_mac_operations e1000_mac_ops_82575 = {
34669 .init_hw = igb_init_hw_82575,
34670 .check_for_link = igb_check_for_link_82575,
34671 .rar_set = igb_rar_set,
34672 @@ -2037,13 +2037,13 @@ static struct e1000_mac_operations e1000
34673 .get_speed_and_duplex = igb_get_speed_and_duplex_copper,
34674 };
34675
34676 -static struct e1000_phy_operations e1000_phy_ops_82575 = {
34677 +static const struct e1000_phy_operations e1000_phy_ops_82575 = {
34678 .acquire = igb_acquire_phy_82575,
34679 .get_cfg_done = igb_get_cfg_done_82575,
34680 .release = igb_release_phy_82575,
34681 };
34682
34683 -static struct e1000_nvm_operations e1000_nvm_ops_82575 = {
34684 +static const struct e1000_nvm_operations e1000_nvm_ops_82575 = {
34685 .acquire = igb_acquire_nvm_82575,
34686 .read = igb_read_nvm_eerd,
34687 .release = igb_release_nvm_82575,
34688 diff -urNp linux-2.6.39/drivers/net/igb/e1000_hw.h linux-2.6.39/drivers/net/igb/e1000_hw.h
34689 --- linux-2.6.39/drivers/net/igb/e1000_hw.h 2011-05-19 00:06:34.000000000 -0400
34690 +++ linux-2.6.39/drivers/net/igb/e1000_hw.h 2011-05-22 19:36:31.000000000 -0400
34691 @@ -342,14 +342,15 @@ struct e1000_nvm_operations {
34692
34693 struct e1000_info {
34694 s32 (*get_invariants)(struct e1000_hw *);
34695 - struct e1000_mac_operations *mac_ops;
34696 - struct e1000_phy_operations *phy_ops;
34697 - struct e1000_nvm_operations *nvm_ops;
34698 + const struct e1000_mac_operations *mac_ops;
34699 + const struct e1000_phy_operations *phy_ops;
34700 + const struct e1000_nvm_operations *nvm_ops;
34701 };
34702
34703 extern const struct e1000_info e1000_82575_info;
34704
34705 struct e1000_mac_info {
34706 + /* cannot be const see igb_get_invariants_82575() */
34707 struct e1000_mac_operations ops;
34708
34709 u8 addr[6];
34710 @@ -388,6 +389,7 @@ struct e1000_mac_info {
34711 };
34712
34713 struct e1000_phy_info {
34714 + /* cannot be const see igb_get_invariants_82575() */
34715 struct e1000_phy_operations ops;
34716
34717 enum e1000_phy_type type;
34718 @@ -423,6 +425,7 @@ struct e1000_phy_info {
34719 };
34720
34721 struct e1000_nvm_info {
34722 + /* cannot be const */
34723 struct e1000_nvm_operations ops;
34724 enum e1000_nvm_type type;
34725 enum e1000_nvm_override override;
34726 diff -urNp linux-2.6.39/drivers/net/igbvf/vf.h linux-2.6.39/drivers/net/igbvf/vf.h
34727 --- linux-2.6.39/drivers/net/igbvf/vf.h 2011-05-19 00:06:34.000000000 -0400
34728 +++ linux-2.6.39/drivers/net/igbvf/vf.h 2011-05-22 19:36:31.000000000 -0400
34729 @@ -191,6 +191,7 @@ struct e1000_mac_operations {
34730 };
34731
34732 struct e1000_mac_info {
34733 + /* cannot be const see e1000_init_mac_params_vf() */
34734 struct e1000_mac_operations ops;
34735 u8 addr[6];
34736 u8 perm_addr[6];
34737 diff -urNp linux-2.6.39/drivers/net/irda/sh_irda.c linux-2.6.39/drivers/net/irda/sh_irda.c
34738 --- linux-2.6.39/drivers/net/irda/sh_irda.c 2011-05-19 00:06:34.000000000 -0400
34739 +++ linux-2.6.39/drivers/net/irda/sh_irda.c 2011-05-22 19:36:31.000000000 -0400
34740 @@ -307,7 +307,7 @@ static int xir_fte(struct sh_irda_self *
34741 return 0;
34742 }
34743
34744 -static struct sh_irda_xir_func xir_func = {
34745 +static const struct sh_irda_xir_func xir_func = {
34746 .xir_fre = xir_fre,
34747 .xir_trov = xir_trov,
34748 .xir_9 = xir_9,
34749 @@ -321,7 +321,7 @@ static struct sh_irda_xir_func xir_func
34750 *
34751 * MIR/FIR are not supported now
34752 *=====================================*/
34753 -static struct sh_irda_xir_func mfir_func = {
34754 +static const struct sh_irda_xir_func mfir_func = {
34755 .xir_fre = xir_fre,
34756 .xir_trov = xir_trov,
34757 .xir_9 = xir_9,
34758 @@ -400,7 +400,7 @@ static int sir_fte(struct sh_irda_self *
34759 return 0;
34760 }
34761
34762 -static struct sh_irda_xir_func sir_func = {
34763 +static const struct sh_irda_xir_func sir_func = {
34764 .xir_fre = sir_fre,
34765 .xir_trov = sir_trov,
34766 .xir_9 = sir_tot,
34767 @@ -411,7 +411,7 @@ static struct sh_irda_xir_func sir_func
34768 static void sh_irda_set_mode(struct sh_irda_self *self, enum sh_irda_mode mode)
34769 {
34770 struct device *dev = &self->ndev->dev;
34771 - struct sh_irda_xir_func *func;
34772 + const struct sh_irda_xir_func *func;
34773 const char *name;
34774 u16 data;
34775
34776 diff -urNp linux-2.6.39/drivers/net/ixgb/ixgb_main.c linux-2.6.39/drivers/net/ixgb/ixgb_main.c
34777 --- linux-2.6.39/drivers/net/ixgb/ixgb_main.c 2011-05-19 00:06:34.000000000 -0400
34778 +++ linux-2.6.39/drivers/net/ixgb/ixgb_main.c 2011-05-22 19:36:31.000000000 -0400
34779 @@ -1069,6 +1069,8 @@ ixgb_set_multi(struct net_device *netdev
34780 u32 rctl;
34781 int i;
34782
34783 + pax_track_stack();
34784 +
34785 /* Check for Promiscuous and All Multicast modes */
34786
34787 rctl = IXGB_READ_REG(hw, RCTL);
34788 diff -urNp linux-2.6.39/drivers/net/ixgb/ixgb_param.c linux-2.6.39/drivers/net/ixgb/ixgb_param.c
34789 --- linux-2.6.39/drivers/net/ixgb/ixgb_param.c 2011-05-19 00:06:34.000000000 -0400
34790 +++ linux-2.6.39/drivers/net/ixgb/ixgb_param.c 2011-05-22 19:36:31.000000000 -0400
34791 @@ -261,6 +261,9 @@ void __devinit
34792 ixgb_check_options(struct ixgb_adapter *adapter)
34793 {
34794 int bd = adapter->bd_number;
34795 +
34796 + pax_track_stack();
34797 +
34798 if (bd >= IXGB_MAX_NIC) {
34799 pr_notice("Warning: no configuration for board #%i\n", bd);
34800 pr_notice("Using defaults for all values\n");
34801 diff -urNp linux-2.6.39/drivers/net/ixgbe/ixgbe_82599.c linux-2.6.39/drivers/net/ixgbe/ixgbe_82599.c
34802 --- linux-2.6.39/drivers/net/ixgbe/ixgbe_82599.c 2011-05-19 00:06:34.000000000 -0400
34803 +++ linux-2.6.39/drivers/net/ixgbe/ixgbe_82599.c 2011-05-22 19:36:31.000000000 -0400
34804 @@ -2099,7 +2099,7 @@ static struct ixgbe_phy_operations phy_o
34805 .check_overtemp = &ixgbe_tn_check_overtemp,
34806 };
34807
34808 -struct ixgbe_info ixgbe_82599_info = {
34809 +const struct ixgbe_info ixgbe_82599_info = {
34810 .mac = ixgbe_mac_82599EB,
34811 .get_invariants = &ixgbe_get_invariants_82599,
34812 .mac_ops = &mac_ops_82599,
34813 diff -urNp linux-2.6.39/drivers/net/ixgbe/ixgbe.h linux-2.6.39/drivers/net/ixgbe/ixgbe.h
34814 --- linux-2.6.39/drivers/net/ixgbe/ixgbe.h 2011-05-19 00:06:34.000000000 -0400
34815 +++ linux-2.6.39/drivers/net/ixgbe/ixgbe.h 2011-05-22 19:36:31.000000000 -0400
34816 @@ -493,8 +493,8 @@ enum ixgbe_boards {
34817 };
34818
34819 extern struct ixgbe_info ixgbe_82598_info;
34820 -extern struct ixgbe_info ixgbe_82599_info;
34821 -extern struct ixgbe_info ixgbe_X540_info;
34822 +extern const struct ixgbe_info ixgbe_82599_info;
34823 +extern const struct ixgbe_info ixgbe_X540_info;
34824 #ifdef CONFIG_IXGBE_DCB
34825 extern const struct dcbnl_rtnl_ops dcbnl_ops;
34826 extern int ixgbe_copy_dcb_cfg(struct ixgbe_dcb_config *src_dcb_cfg,
34827 diff -urNp linux-2.6.39/drivers/net/ixgbe/ixgbe_type.h linux-2.6.39/drivers/net/ixgbe/ixgbe_type.h
34828 --- linux-2.6.39/drivers/net/ixgbe/ixgbe_type.h 2011-05-19 00:06:34.000000000 -0400
34829 +++ linux-2.6.39/drivers/net/ixgbe/ixgbe_type.h 2011-05-22 19:36:31.000000000 -0400
34830 @@ -2572,7 +2572,7 @@ struct ixgbe_phy_operations {
34831 };
34832
34833 struct ixgbe_eeprom_info {
34834 - struct ixgbe_eeprom_operations ops;
34835 + struct ixgbe_eeprom_operations ops;
34836 enum ixgbe_eeprom_type type;
34837 u32 semaphore_delay;
34838 u16 word_size;
34839 @@ -2581,7 +2581,7 @@ struct ixgbe_eeprom_info {
34840
34841 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
34842 struct ixgbe_mac_info {
34843 - struct ixgbe_mac_operations ops;
34844 + struct ixgbe_mac_operations ops;
34845 enum ixgbe_mac_type type;
34846 u8 addr[IXGBE_ETH_LENGTH_OF_ADDRESS];
34847 u8 perm_addr[IXGBE_ETH_LENGTH_OF_ADDRESS];
34848 @@ -2608,7 +2608,7 @@ struct ixgbe_mac_info {
34849 };
34850
34851 struct ixgbe_phy_info {
34852 - struct ixgbe_phy_operations ops;
34853 + struct ixgbe_phy_operations ops;
34854 struct mdio_if_info mdio;
34855 enum ixgbe_phy_type type;
34856 u32 id;
34857 diff -urNp linux-2.6.39/drivers/net/ixgbe/ixgbe_x540.c linux-2.6.39/drivers/net/ixgbe/ixgbe_x540.c
34858 --- linux-2.6.39/drivers/net/ixgbe/ixgbe_x540.c 2011-05-19 00:06:34.000000000 -0400
34859 +++ linux-2.6.39/drivers/net/ixgbe/ixgbe_x540.c 2011-05-22 19:36:31.000000000 -0400
34860 @@ -727,7 +727,7 @@ static struct ixgbe_phy_operations phy_o
34861 .check_overtemp = &ixgbe_tn_check_overtemp,
34862 };
34863
34864 -struct ixgbe_info ixgbe_X540_info = {
34865 +const struct ixgbe_info ixgbe_X540_info = {
34866 .mac = ixgbe_mac_X540,
34867 .get_invariants = &ixgbe_get_invariants_X540,
34868 .mac_ops = &mac_ops_X540,
34869 diff -urNp linux-2.6.39/drivers/net/ixgbevf/ethtool.c linux-2.6.39/drivers/net/ixgbevf/ethtool.c
34870 --- linux-2.6.39/drivers/net/ixgbevf/ethtool.c 2011-05-19 00:06:34.000000000 -0400
34871 +++ linux-2.6.39/drivers/net/ixgbevf/ethtool.c 2011-05-22 19:36:31.000000000 -0400
34872 @@ -709,7 +709,7 @@ static int ixgbevf_nway_reset(struct net
34873 return 0;
34874 }
34875
34876 -static struct ethtool_ops ixgbevf_ethtool_ops = {
34877 +static const struct ethtool_ops ixgbevf_ethtool_ops = {
34878 .get_settings = ixgbevf_get_settings,
34879 .get_drvinfo = ixgbevf_get_drvinfo,
34880 .get_regs_len = ixgbevf_get_regs_len,
34881 diff -urNp linux-2.6.39/drivers/net/ixgbevf/ixgbevf.h linux-2.6.39/drivers/net/ixgbevf/ixgbevf.h
34882 --- linux-2.6.39/drivers/net/ixgbevf/ixgbevf.h 2011-05-19 00:06:34.000000000 -0400
34883 +++ linux-2.6.39/drivers/net/ixgbevf/ixgbevf.h 2011-05-22 19:36:31.000000000 -0400
34884 @@ -279,7 +279,7 @@ enum ixgbevf_boards {
34885
34886 extern struct ixgbevf_info ixgbevf_82599_vf_info;
34887 extern struct ixgbevf_info ixgbevf_X540_vf_info;
34888 -extern struct ixgbe_mac_operations ixgbevf_mbx_ops;
34889 +extern const struct ixgbe_mac_operations ixgbevf_mbx_ops;
34890
34891 /* needed by ethtool.c */
34892 extern char ixgbevf_driver_name[];
34893 diff -urNp linux-2.6.39/drivers/net/ixgbevf/vf.c linux-2.6.39/drivers/net/ixgbevf/vf.c
34894 --- linux-2.6.39/drivers/net/ixgbevf/vf.c 2011-05-19 00:06:34.000000000 -0400
34895 +++ linux-2.6.39/drivers/net/ixgbevf/vf.c 2011-05-22 19:36:31.000000000 -0400
34896 @@ -368,7 +368,7 @@ static s32 ixgbevf_check_mac_link_vf(str
34897 return 0;
34898 }
34899
34900 -static struct ixgbe_mac_operations ixgbevf_mac_ops = {
34901 +static const struct ixgbe_mac_operations ixgbevf_mac_ops = {
34902 .init_hw = ixgbevf_init_hw_vf,
34903 .reset_hw = ixgbevf_reset_hw_vf,
34904 .start_hw = ixgbevf_start_hw_vf,
34905 @@ -381,12 +381,12 @@ static struct ixgbe_mac_operations ixgbe
34906 .set_vfta = ixgbevf_set_vfta_vf,
34907 };
34908
34909 -struct ixgbevf_info ixgbevf_82599_vf_info = {
34910 +const struct ixgbevf_info ixgbevf_82599_vf_info = {
34911 .mac = ixgbe_mac_82599_vf,
34912 .mac_ops = &ixgbevf_mac_ops,
34913 };
34914
34915 -struct ixgbevf_info ixgbevf_X540_vf_info = {
34916 +const struct ixgbevf_info ixgbevf_X540_vf_info = {
34917 .mac = ixgbe_mac_X540_vf,
34918 .mac_ops = &ixgbevf_mac_ops,
34919 };
34920 diff -urNp linux-2.6.39/drivers/net/ixgbevf/vf.h linux-2.6.39/drivers/net/ixgbevf/vf.h
34921 --- linux-2.6.39/drivers/net/ixgbevf/vf.h 2011-05-19 00:06:34.000000000 -0400
34922 +++ linux-2.6.39/drivers/net/ixgbevf/vf.h 2011-05-22 19:36:31.000000000 -0400
34923 @@ -166,7 +166,7 @@ struct ixgbevf_hw_stats {
34924
34925 struct ixgbevf_info {
34926 enum ixgbe_mac_type mac;
34927 - struct ixgbe_mac_operations *mac_ops;
34928 + const struct ixgbe_mac_operations *mac_ops;
34929 };
34930
34931 #endif /* __IXGBE_VF_H__ */
34932 diff -urNp linux-2.6.39/drivers/net/ksz884x.c linux-2.6.39/drivers/net/ksz884x.c
34933 --- linux-2.6.39/drivers/net/ksz884x.c 2011-05-19 00:06:34.000000000 -0400
34934 +++ linux-2.6.39/drivers/net/ksz884x.c 2011-05-22 19:36:31.000000000 -0400
34935 @@ -6536,6 +6536,8 @@ static void netdev_get_ethtool_stats(str
34936 int rc;
34937 u64 counter[TOTAL_PORT_COUNTER_NUM];
34938
34939 + pax_track_stack();
34940 +
34941 mutex_lock(&hw_priv->lock);
34942 n = SWITCH_PORT_NUM;
34943 for (i = 0, p = port->first_port; i < port->mib_port_cnt; i++, p++) {
34944 @@ -6637,7 +6639,7 @@ static int netdev_set_rx_csum(struct net
34945 return 0;
34946 }
34947
34948 -static struct ethtool_ops netdev_ethtool_ops = {
34949 +static const struct ethtool_ops netdev_ethtool_ops = {
34950 .get_settings = netdev_get_settings,
34951 .set_settings = netdev_set_settings,
34952 .nway_reset = netdev_nway_reset,
34953 diff -urNp linux-2.6.39/drivers/net/mlx4/main.c linux-2.6.39/drivers/net/mlx4/main.c
34954 --- linux-2.6.39/drivers/net/mlx4/main.c 2011-05-19 00:06:34.000000000 -0400
34955 +++ linux-2.6.39/drivers/net/mlx4/main.c 2011-05-22 19:36:31.000000000 -0400
34956 @@ -40,6 +40,7 @@
34957 #include <linux/dma-mapping.h>
34958 #include <linux/slab.h>
34959 #include <linux/io-mapping.h>
34960 +#include <linux/sched.h>
34961
34962 #include <linux/mlx4/device.h>
34963 #include <linux/mlx4/doorbell.h>
34964 @@ -764,6 +765,8 @@ static int mlx4_init_hca(struct mlx4_dev
34965 u64 icm_size;
34966 int err;
34967
34968 + pax_track_stack();
34969 +
34970 err = mlx4_QUERY_FW(dev);
34971 if (err) {
34972 if (err == -EACCES)
34973 diff -urNp linux-2.6.39/drivers/net/netconsole.c linux-2.6.39/drivers/net/netconsole.c
34974 --- linux-2.6.39/drivers/net/netconsole.c 2011-05-19 00:06:34.000000000 -0400
34975 +++ linux-2.6.39/drivers/net/netconsole.c 2011-05-22 19:36:31.000000000 -0400
34976 @@ -634,7 +634,7 @@ static void drop_netconsole_target(struc
34977 config_item_put(&nt->item);
34978 }
34979
34980 -static struct configfs_group_operations netconsole_subsys_group_ops = {
34981 +static const struct configfs_group_operations netconsole_subsys_group_ops = {
34982 .make_item = make_netconsole_target,
34983 .drop_item = drop_netconsole_target,
34984 };
34985 diff -urNp linux-2.6.39/drivers/net/niu.c linux-2.6.39/drivers/net/niu.c
34986 --- linux-2.6.39/drivers/net/niu.c 2011-05-19 00:06:34.000000000 -0400
34987 +++ linux-2.6.39/drivers/net/niu.c 2011-05-22 19:36:31.000000000 -0400
34988 @@ -9067,6 +9067,8 @@ static void __devinit niu_try_msix(struc
34989 int i, num_irqs, err;
34990 u8 first_ldg;
34991
34992 + pax_track_stack();
34993 +
34994 first_ldg = (NIU_NUM_LDG / parent->num_ports) * np->port;
34995 for (i = 0; i < (NIU_NUM_LDG / parent->num_ports); i++)
34996 ldg_num_map[i] = first_ldg + i;
34997 diff -urNp linux-2.6.39/drivers/net/pcnet32.c linux-2.6.39/drivers/net/pcnet32.c
34998 --- linux-2.6.39/drivers/net/pcnet32.c 2011-05-19 00:06:34.000000000 -0400
34999 +++ linux-2.6.39/drivers/net/pcnet32.c 2011-05-22 19:36:31.000000000 -0400
35000 @@ -82,7 +82,7 @@ static int cards_found;
35001 /*
35002 * VLB I/O addresses
35003 */
35004 -static unsigned int pcnet32_portlist[] __initdata =
35005 +static unsigned int pcnet32_portlist[] __devinitdata =
35006 { 0x300, 0x320, 0x340, 0x360, 0 };
35007
35008 static int pcnet32_debug;
35009 @@ -379,7 +379,7 @@ static int pcnet32_wio_check(unsigned lo
35010 return inw(addr + PCNET32_WIO_RAP) == 88;
35011 }
35012
35013 -static struct pcnet32_access pcnet32_wio = {
35014 +static const struct pcnet32_access pcnet32_wio = {
35015 .read_csr = pcnet32_wio_read_csr,
35016 .write_csr = pcnet32_wio_write_csr,
35017 .read_bcr = pcnet32_wio_read_bcr,
35018 @@ -434,7 +434,7 @@ static int pcnet32_dwio_check(unsigned l
35019 return (inl(addr + PCNET32_DWIO_RAP) & 0xffff) == 88;
35020 }
35021
35022 -static struct pcnet32_access pcnet32_dwio = {
35023 +static const struct pcnet32_access pcnet32_dwio = {
35024 .read_csr = pcnet32_dwio_read_csr,
35025 .write_csr = pcnet32_dwio_write_csr,
35026 .read_bcr = pcnet32_dwio_read_bcr,
35027 @@ -1546,7 +1546,7 @@ pcnet32_probe1(unsigned long ioaddr, int
35028 int chip_version;
35029 char *chipname;
35030 struct net_device *dev;
35031 - struct pcnet32_access *a = NULL;
35032 + const struct pcnet32_access *a = NULL;
35033 u8 promaddr[6];
35034 int ret = -ENODEV;
35035
35036 diff -urNp linux-2.6.39/drivers/net/ppp_generic.c linux-2.6.39/drivers/net/ppp_generic.c
35037 --- linux-2.6.39/drivers/net/ppp_generic.c 2011-05-19 00:06:34.000000000 -0400
35038 +++ linux-2.6.39/drivers/net/ppp_generic.c 2011-05-22 19:36:31.000000000 -0400
35039 @@ -987,7 +987,6 @@ ppp_net_ioctl(struct net_device *dev, st
35040 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
35041 struct ppp_stats stats;
35042 struct ppp_comp_stats cstats;
35043 - char *vers;
35044
35045 switch (cmd) {
35046 case SIOCGPPPSTATS:
35047 @@ -1009,8 +1008,7 @@ ppp_net_ioctl(struct net_device *dev, st
35048 break;
35049
35050 case SIOCGPPPVER:
35051 - vers = PPP_VERSION;
35052 - if (copy_to_user(addr, vers, strlen(vers) + 1))
35053 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
35054 break;
35055 err = 0;
35056 break;
35057 diff -urNp linux-2.6.39/drivers/net/qlcnic/qlcnic.h linux-2.6.39/drivers/net/qlcnic/qlcnic.h
35058 --- linux-2.6.39/drivers/net/qlcnic/qlcnic.h 2011-05-19 00:06:34.000000000 -0400
35059 +++ linux-2.6.39/drivers/net/qlcnic/qlcnic.h 2011-05-22 19:36:31.000000000 -0400
35060 @@ -1037,7 +1037,7 @@ struct qlcnic_adapter {
35061 struct vlan_group *vlgrp;
35062 struct qlcnic_npar_info *npars;
35063 struct qlcnic_eswitch *eswitch;
35064 - struct qlcnic_nic_template *nic_ops;
35065 + const struct qlcnic_nic_template *nic_ops;
35066
35067 struct qlcnic_adapter_stats stats;
35068
35069 diff -urNp linux-2.6.39/drivers/net/qlcnic/qlcnic_main.c linux-2.6.39/drivers/net/qlcnic/qlcnic_main.c
35070 --- linux-2.6.39/drivers/net/qlcnic/qlcnic_main.c 2011-05-19 00:06:34.000000000 -0400
35071 +++ linux-2.6.39/drivers/net/qlcnic/qlcnic_main.c 2011-05-22 19:36:31.000000000 -0400
35072 @@ -340,13 +340,13 @@ static const struct net_device_ops qlcni
35073 #endif
35074 };
35075
35076 -static struct qlcnic_nic_template qlcnic_ops = {
35077 +static const struct qlcnic_nic_template qlcnic_ops = {
35078 .config_bridged_mode = qlcnic_config_bridged_mode,
35079 .config_led = qlcnic_config_led,
35080 .start_firmware = qlcnic_start_firmware
35081 };
35082
35083 -static struct qlcnic_nic_template qlcnic_vf_ops = {
35084 +static const struct qlcnic_nic_template qlcnic_vf_ops = {
35085 .config_bridged_mode = qlcnicvf_config_bridged_mode,
35086 .config_led = qlcnicvf_config_led,
35087 .start_firmware = qlcnicvf_start_firmware
35088 diff -urNp linux-2.6.39/drivers/net/qlge/qlge.h linux-2.6.39/drivers/net/qlge/qlge.h
35089 --- linux-2.6.39/drivers/net/qlge/qlge.h 2011-05-19 00:06:34.000000000 -0400
35090 +++ linux-2.6.39/drivers/net/qlge/qlge.h 2011-05-22 19:36:31.000000000 -0400
35091 @@ -2134,7 +2134,7 @@ struct ql_adapter {
35092 struct delayed_work mpi_idc_work;
35093 struct delayed_work mpi_core_to_log;
35094 struct completion ide_completion;
35095 - struct nic_operations *nic_ops;
35096 + const struct nic_operations *nic_ops;
35097 u16 device_id;
35098 struct timer_list timer;
35099 atomic_t lb_count;
35100 diff -urNp linux-2.6.39/drivers/net/qlge/qlge_main.c linux-2.6.39/drivers/net/qlge/qlge_main.c
35101 --- linux-2.6.39/drivers/net/qlge/qlge_main.c 2011-05-19 00:06:34.000000000 -0400
35102 +++ linux-2.6.39/drivers/net/qlge/qlge_main.c 2011-05-22 19:36:31.000000000 -0400
35103 @@ -4412,12 +4412,12 @@ error:
35104 rtnl_unlock();
35105 }
35106
35107 -static struct nic_operations qla8012_nic_ops = {
35108 +static const struct nic_operations qla8012_nic_ops = {
35109 .get_flash = ql_get_8012_flash_params,
35110 .port_initialize = ql_8012_port_initialize,
35111 };
35112
35113 -static struct nic_operations qla8000_nic_ops = {
35114 +static const struct nic_operations qla8000_nic_ops = {
35115 .get_flash = ql_get_8000_flash_params,
35116 .port_initialize = ql_8000_port_initialize,
35117 };
35118 diff -urNp linux-2.6.39/drivers/net/sfc/falcon.c linux-2.6.39/drivers/net/sfc/falcon.c
35119 --- linux-2.6.39/drivers/net/sfc/falcon.c 2011-05-19 00:06:34.000000000 -0400
35120 +++ linux-2.6.39/drivers/net/sfc/falcon.c 2011-05-22 19:36:31.000000000 -0400
35121 @@ -1703,7 +1703,7 @@ static int falcon_set_wol(struct efx_nic
35122 **************************************************************************
35123 */
35124
35125 -struct efx_nic_type falcon_a1_nic_type = {
35126 +const struct efx_nic_type falcon_a1_nic_type = {
35127 .probe = falcon_probe_nic,
35128 .remove = falcon_remove_nic,
35129 .init = falcon_init_nic,
35130 @@ -1744,7 +1744,7 @@ struct efx_nic_type falcon_a1_nic_type =
35131 .reset_world_flags = ETH_RESET_IRQ,
35132 };
35133
35134 -struct efx_nic_type falcon_b0_nic_type = {
35135 +const struct efx_nic_type falcon_b0_nic_type = {
35136 .probe = falcon_probe_nic,
35137 .remove = falcon_remove_nic,
35138 .init = falcon_init_nic,
35139 diff -urNp linux-2.6.39/drivers/net/sfc/mtd.c linux-2.6.39/drivers/net/sfc/mtd.c
35140 --- linux-2.6.39/drivers/net/sfc/mtd.c 2011-05-19 00:06:34.000000000 -0400
35141 +++ linux-2.6.39/drivers/net/sfc/mtd.c 2011-05-22 19:36:31.000000000 -0400
35142 @@ -382,7 +382,7 @@ static int falcon_mtd_sync(struct mtd_in
35143 return rc;
35144 }
35145
35146 -static struct efx_mtd_ops falcon_mtd_ops = {
35147 +static const struct efx_mtd_ops falcon_mtd_ops = {
35148 .read = falcon_mtd_read,
35149 .erase = falcon_mtd_erase,
35150 .write = falcon_mtd_write,
35151 @@ -560,7 +560,7 @@ static int siena_mtd_sync(struct mtd_inf
35152 return rc;
35153 }
35154
35155 -static struct efx_mtd_ops siena_mtd_ops = {
35156 +static const struct efx_mtd_ops siena_mtd_ops = {
35157 .read = siena_mtd_read,
35158 .erase = siena_mtd_erase,
35159 .write = siena_mtd_write,
35160 diff -urNp linux-2.6.39/drivers/net/sfc/nic.h linux-2.6.39/drivers/net/sfc/nic.h
35161 --- linux-2.6.39/drivers/net/sfc/nic.h 2011-05-19 00:06:34.000000000 -0400
35162 +++ linux-2.6.39/drivers/net/sfc/nic.h 2011-05-22 19:36:31.000000000 -0400
35163 @@ -152,9 +152,9 @@ struct siena_nic_data {
35164 int wol_filter_id;
35165 };
35166
35167 -extern struct efx_nic_type falcon_a1_nic_type;
35168 -extern struct efx_nic_type falcon_b0_nic_type;
35169 -extern struct efx_nic_type siena_a0_nic_type;
35170 +extern const struct efx_nic_type falcon_a1_nic_type;
35171 +extern const struct efx_nic_type falcon_b0_nic_type;
35172 +extern const struct efx_nic_type siena_a0_nic_type;
35173
35174 /**************************************************************************
35175 *
35176 diff -urNp linux-2.6.39/drivers/net/sfc/siena.c linux-2.6.39/drivers/net/sfc/siena.c
35177 --- linux-2.6.39/drivers/net/sfc/siena.c 2011-05-19 00:06:34.000000000 -0400
35178 +++ linux-2.6.39/drivers/net/sfc/siena.c 2011-05-22 19:36:31.000000000 -0400
35179 @@ -599,7 +599,7 @@ static void siena_init_wol(struct efx_ni
35180 **************************************************************************
35181 */
35182
35183 -struct efx_nic_type siena_a0_nic_type = {
35184 +const struct efx_nic_type siena_a0_nic_type = {
35185 .probe = siena_probe_nic,
35186 .remove = siena_remove_nic,
35187 .init = siena_init_nic,
35188 diff -urNp linux-2.6.39/drivers/net/sh_eth.c linux-2.6.39/drivers/net/sh_eth.c
35189 --- linux-2.6.39/drivers/net/sh_eth.c 2011-05-19 00:06:34.000000000 -0400
35190 +++ linux-2.6.39/drivers/net/sh_eth.c 2011-05-22 19:36:31.000000000 -0400
35191 @@ -1360,7 +1360,7 @@ static void sh_eth_get_strings(struct ne
35192 }
35193 }
35194
35195 -static struct ethtool_ops sh_eth_ethtool_ops = {
35196 +static const struct ethtool_ops sh_eth_ethtool_ops = {
35197 .get_settings = sh_eth_get_settings,
35198 .set_settings = sh_eth_set_settings,
35199 .nway_reset = sh_eth_nway_reset,
35200 diff -urNp linux-2.6.39/drivers/net/stmmac/stmmac_ethtool.c linux-2.6.39/drivers/net/stmmac/stmmac_ethtool.c
35201 --- linux-2.6.39/drivers/net/stmmac/stmmac_ethtool.c 2011-05-19 00:06:34.000000000 -0400
35202 +++ linux-2.6.39/drivers/net/stmmac/stmmac_ethtool.c 2011-05-22 19:36:31.000000000 -0400
35203 @@ -348,7 +348,7 @@ static int stmmac_set_wol(struct net_dev
35204 return 0;
35205 }
35206
35207 -static struct ethtool_ops stmmac_ethtool_ops = {
35208 +static const struct ethtool_ops stmmac_ethtool_ops = {
35209 .begin = stmmac_check_if_running,
35210 .get_drvinfo = stmmac_ethtool_getdrvinfo,
35211 .get_settings = stmmac_ethtool_getsettings,
35212 diff -urNp linux-2.6.39/drivers/net/sungem_phy.c linux-2.6.39/drivers/net/sungem_phy.c
35213 --- linux-2.6.39/drivers/net/sungem_phy.c 2011-05-19 00:06:34.000000000 -0400
35214 +++ linux-2.6.39/drivers/net/sungem_phy.c 2011-05-22 19:36:31.000000000 -0400
35215 @@ -886,7 +886,7 @@ static int marvell_read_link(struct mii_
35216 SUPPORTED_1000baseT_Half | SUPPORTED_1000baseT_Full)
35217
35218 /* Broadcom BCM 5201 */
35219 -static struct mii_phy_ops bcm5201_phy_ops = {
35220 +static const struct mii_phy_ops bcm5201_phy_ops = {
35221 .init = bcm5201_init,
35222 .suspend = bcm5201_suspend,
35223 .setup_aneg = genmii_setup_aneg,
35224 @@ -905,7 +905,7 @@ static struct mii_phy_def bcm5201_phy_de
35225 };
35226
35227 /* Broadcom BCM 5221 */
35228 -static struct mii_phy_ops bcm5221_phy_ops = {
35229 +static const struct mii_phy_ops bcm5221_phy_ops = {
35230 .suspend = bcm5221_suspend,
35231 .init = bcm5221_init,
35232 .setup_aneg = genmii_setup_aneg,
35233 @@ -924,7 +924,7 @@ static struct mii_phy_def bcm5221_phy_de
35234 };
35235
35236 /* Broadcom BCM 5241 */
35237 -static struct mii_phy_ops bcm5241_phy_ops = {
35238 +static const struct mii_phy_ops bcm5241_phy_ops = {
35239 .suspend = bcm5241_suspend,
35240 .init = bcm5241_init,
35241 .setup_aneg = genmii_setup_aneg,
35242 @@ -942,7 +942,7 @@ static struct mii_phy_def bcm5241_phy_de
35243 };
35244
35245 /* Broadcom BCM 5400 */
35246 -static struct mii_phy_ops bcm5400_phy_ops = {
35247 +static const struct mii_phy_ops bcm5400_phy_ops = {
35248 .init = bcm5400_init,
35249 .suspend = bcm5400_suspend,
35250 .setup_aneg = bcm54xx_setup_aneg,
35251 @@ -961,7 +961,7 @@ static struct mii_phy_def bcm5400_phy_de
35252 };
35253
35254 /* Broadcom BCM 5401 */
35255 -static struct mii_phy_ops bcm5401_phy_ops = {
35256 +static const struct mii_phy_ops bcm5401_phy_ops = {
35257 .init = bcm5401_init,
35258 .suspend = bcm5401_suspend,
35259 .setup_aneg = bcm54xx_setup_aneg,
35260 @@ -980,7 +980,7 @@ static struct mii_phy_def bcm5401_phy_de
35261 };
35262
35263 /* Broadcom BCM 5411 */
35264 -static struct mii_phy_ops bcm5411_phy_ops = {
35265 +static const struct mii_phy_ops bcm5411_phy_ops = {
35266 .init = bcm5411_init,
35267 .suspend = generic_suspend,
35268 .setup_aneg = bcm54xx_setup_aneg,
35269 @@ -999,7 +999,7 @@ static struct mii_phy_def bcm5411_phy_de
35270 };
35271
35272 /* Broadcom BCM 5421 */
35273 -static struct mii_phy_ops bcm5421_phy_ops = {
35274 +static const struct mii_phy_ops bcm5421_phy_ops = {
35275 .init = bcm5421_init,
35276 .suspend = generic_suspend,
35277 .setup_aneg = bcm54xx_setup_aneg,
35278 @@ -1019,7 +1019,7 @@ static struct mii_phy_def bcm5421_phy_de
35279 };
35280
35281 /* Broadcom BCM 5421 built-in K2 */
35282 -static struct mii_phy_ops bcm5421k2_phy_ops = {
35283 +static const struct mii_phy_ops bcm5421k2_phy_ops = {
35284 .init = bcm5421_init,
35285 .suspend = generic_suspend,
35286 .setup_aneg = bcm54xx_setup_aneg,
35287 @@ -1037,7 +1037,7 @@ static struct mii_phy_def bcm5421k2_phy_
35288 .ops = &bcm5421k2_phy_ops
35289 };
35290
35291 -static struct mii_phy_ops bcm5461_phy_ops = {
35292 +static const struct mii_phy_ops bcm5461_phy_ops = {
35293 .init = bcm5421_init,
35294 .suspend = generic_suspend,
35295 .setup_aneg = bcm54xx_setup_aneg,
35296 @@ -1057,7 +1057,7 @@ static struct mii_phy_def bcm5461_phy_de
35297 };
35298
35299 /* Broadcom BCM 5462 built-in Vesta */
35300 -static struct mii_phy_ops bcm5462V_phy_ops = {
35301 +static const struct mii_phy_ops bcm5462V_phy_ops = {
35302 .init = bcm5421_init,
35303 .suspend = generic_suspend,
35304 .setup_aneg = bcm54xx_setup_aneg,
35305 @@ -1076,7 +1076,7 @@ static struct mii_phy_def bcm5462V_phy_d
35306 };
35307
35308 /* Marvell 88E1101 amd 88E1111 */
35309 -static struct mii_phy_ops marvell88e1101_phy_ops = {
35310 +static const struct mii_phy_ops marvell88e1101_phy_ops = {
35311 .suspend = generic_suspend,
35312 .setup_aneg = marvell_setup_aneg,
35313 .setup_forced = marvell_setup_forced,
35314 @@ -1084,7 +1084,7 @@ static struct mii_phy_ops marvell88e1101
35315 .read_link = marvell_read_link
35316 };
35317
35318 -static struct mii_phy_ops marvell88e1111_phy_ops = {
35319 +static const struct mii_phy_ops marvell88e1111_phy_ops = {
35320 .init = marvell88e1111_init,
35321 .suspend = generic_suspend,
35322 .setup_aneg = marvell_setup_aneg,
35323 @@ -1122,7 +1122,7 @@ static struct mii_phy_def marvell88e1111
35324 };
35325
35326 /* Generic implementation for most 10/100 PHYs */
35327 -static struct mii_phy_ops generic_phy_ops = {
35328 +static const struct mii_phy_ops generic_phy_ops = {
35329 .setup_aneg = genmii_setup_aneg,
35330 .setup_forced = genmii_setup_forced,
35331 .poll_link = genmii_poll_link,
35332 diff -urNp linux-2.6.39/drivers/net/tg3.h linux-2.6.39/drivers/net/tg3.h
35333 --- linux-2.6.39/drivers/net/tg3.h 2011-05-19 00:06:34.000000000 -0400
35334 +++ linux-2.6.39/drivers/net/tg3.h 2011-05-22 19:36:31.000000000 -0400
35335 @@ -131,6 +131,7 @@
35336 #define CHIPREV_ID_5750_A0 0x4000
35337 #define CHIPREV_ID_5750_A1 0x4001
35338 #define CHIPREV_ID_5750_A3 0x4003
35339 +#define CHIPREV_ID_5750_C1 0x4201
35340 #define CHIPREV_ID_5750_C2 0x4202
35341 #define CHIPREV_ID_5752_A0_HW 0x5000
35342 #define CHIPREV_ID_5752_A0 0x6000
35343 diff -urNp linux-2.6.39/drivers/net/tile/tilepro.c linux-2.6.39/drivers/net/tile/tilepro.c
35344 --- linux-2.6.39/drivers/net/tile/tilepro.c 2011-05-19 00:06:34.000000000 -0400
35345 +++ linux-2.6.39/drivers/net/tile/tilepro.c 2011-05-22 19:36:31.000000000 -0400
35346 @@ -2263,7 +2263,7 @@ static int tile_net_get_mac(struct net_d
35347 }
35348
35349
35350 -static struct net_device_ops tile_net_ops = {
35351 +static const struct net_device_ops tile_net_ops = {
35352 .ndo_open = tile_net_open,
35353 .ndo_stop = tile_net_stop,
35354 .ndo_start_xmit = tile_net_tx,
35355 diff -urNp linux-2.6.39/drivers/net/tulip/de2104x.c linux-2.6.39/drivers/net/tulip/de2104x.c
35356 --- linux-2.6.39/drivers/net/tulip/de2104x.c 2011-05-19 00:06:34.000000000 -0400
35357 +++ linux-2.6.39/drivers/net/tulip/de2104x.c 2011-05-22 19:36:31.000000000 -0400
35358 @@ -1817,6 +1817,8 @@ static void __devinit de21041_get_srom_i
35359 struct de_srom_info_leaf *il;
35360 void *bufp;
35361
35362 + pax_track_stack();
35363 +
35364 /* download entire eeprom */
35365 for (i = 0; i < DE_EEPROM_WORDS; i++)
35366 ((__le16 *)ee_data)[i] =
35367 diff -urNp linux-2.6.39/drivers/net/tulip/de4x5.c linux-2.6.39/drivers/net/tulip/de4x5.c
35368 --- linux-2.6.39/drivers/net/tulip/de4x5.c 2011-05-19 00:06:34.000000000 -0400
35369 +++ linux-2.6.39/drivers/net/tulip/de4x5.c 2011-05-22 19:36:31.000000000 -0400
35370 @@ -5401,7 +5401,7 @@ de4x5_ioctl(struct net_device *dev, stru
35371 for (i=0; i<ETH_ALEN; i++) {
35372 tmp.addr[i] = dev->dev_addr[i];
35373 }
35374 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
35375 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
35376 break;
35377
35378 case DE4X5_SET_HWADDR: /* Set the hardware address */
35379 @@ -5441,7 +5441,7 @@ de4x5_ioctl(struct net_device *dev, stru
35380 spin_lock_irqsave(&lp->lock, flags);
35381 memcpy(&statbuf, &lp->pktStats, ioc->len);
35382 spin_unlock_irqrestore(&lp->lock, flags);
35383 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
35384 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
35385 return -EFAULT;
35386 break;
35387 }
35388 diff -urNp linux-2.6.39/drivers/net/usb/asix.c linux-2.6.39/drivers/net/usb/asix.c
35389 --- linux-2.6.39/drivers/net/usb/asix.c 2011-05-19 00:06:34.000000000 -0400
35390 +++ linux-2.6.39/drivers/net/usb/asix.c 2011-05-22 19:36:31.000000000 -0400
35391 @@ -1098,7 +1098,7 @@ out:
35392 return ret;
35393 }
35394
35395 -static struct ethtool_ops ax88178_ethtool_ops = {
35396 +static const struct ethtool_ops ax88178_ethtool_ops = {
35397 .get_drvinfo = asix_get_drvinfo,
35398 .get_link = asix_get_link,
35399 .get_msglevel = usbnet_get_msglevel,
35400 diff -urNp linux-2.6.39/drivers/net/usb/cdc_ncm.c linux-2.6.39/drivers/net/usb/cdc_ncm.c
35401 --- linux-2.6.39/drivers/net/usb/cdc_ncm.c 2011-05-19 00:06:34.000000000 -0400
35402 +++ linux-2.6.39/drivers/net/usb/cdc_ncm.c 2011-05-22 19:36:31.000000000 -0400
35403 @@ -141,7 +141,7 @@ struct cdc_ncm_ctx {
35404 static void cdc_ncm_tx_timeout(unsigned long arg);
35405 static const struct driver_info cdc_ncm_info;
35406 static struct usb_driver cdc_ncm_driver;
35407 -static struct ethtool_ops cdc_ncm_ethtool_ops;
35408 +static const struct ethtool_ops cdc_ncm_ethtool_ops;
35409
35410 static const struct usb_device_id cdc_devs[] = {
35411 { USB_INTERFACE_INFO(USB_CLASS_COMM,
35412 @@ -1257,7 +1257,7 @@ static struct usb_driver cdc_ncm_driver
35413 .supports_autosuspend = 1,
35414 };
35415
35416 -static struct ethtool_ops cdc_ncm_ethtool_ops = {
35417 +static const struct ethtool_ops cdc_ncm_ethtool_ops = {
35418 .get_drvinfo = cdc_ncm_get_drvinfo,
35419 .get_link = usbnet_get_link,
35420 .get_msglevel = usbnet_get_msglevel,
35421 diff -urNp linux-2.6.39/drivers/net/usb/hso.c linux-2.6.39/drivers/net/usb/hso.c
35422 --- linux-2.6.39/drivers/net/usb/hso.c 2011-05-19 00:06:34.000000000 -0400
35423 +++ linux-2.6.39/drivers/net/usb/hso.c 2011-05-22 19:36:31.000000000 -0400
35424 @@ -71,7 +71,7 @@
35425 #include <asm/byteorder.h>
35426 #include <linux/serial_core.h>
35427 #include <linux/serial.h>
35428 -
35429 +#include <asm/local.h>
35430
35431 #define MOD_AUTHOR "Option Wireless"
35432 #define MOD_DESCRIPTION "USB High Speed Option driver"
35433 @@ -257,7 +257,7 @@ struct hso_serial {
35434
35435 /* from usb_serial_port */
35436 struct tty_struct *tty;
35437 - int open_count;
35438 + local_t open_count;
35439 spinlock_t serial_lock;
35440
35441 int (*write_data) (struct hso_serial *serial);
35442 @@ -1190,7 +1190,7 @@ static void put_rxbuf_data_and_resubmit_
35443 struct urb *urb;
35444
35445 urb = serial->rx_urb[0];
35446 - if (serial->open_count > 0) {
35447 + if (local_read(&serial->open_count) > 0) {
35448 count = put_rxbuf_data(urb, serial);
35449 if (count == -1)
35450 return;
35451 @@ -1226,7 +1226,7 @@ static void hso_std_serial_read_bulk_cal
35452 DUMP1(urb->transfer_buffer, urb->actual_length);
35453
35454 /* Anyone listening? */
35455 - if (serial->open_count == 0)
35456 + if (local_read(&serial->open_count) == 0)
35457 return;
35458
35459 if (status == 0) {
35460 @@ -1311,8 +1311,7 @@ static int hso_serial_open(struct tty_st
35461 spin_unlock_irq(&serial->serial_lock);
35462
35463 /* check for port already opened, if not set the termios */
35464 - serial->open_count++;
35465 - if (serial->open_count == 1) {
35466 + if (local_inc_return(&serial->open_count) == 1) {
35467 serial->rx_state = RX_IDLE;
35468 /* Force default termio settings */
35469 _hso_serial_set_termios(tty, NULL);
35470 @@ -1324,7 +1323,7 @@ static int hso_serial_open(struct tty_st
35471 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35472 if (result) {
35473 hso_stop_serial_device(serial->parent);
35474 - serial->open_count--;
35475 + local_dec(&serial->open_count);
35476 kref_put(&serial->parent->ref, hso_serial_ref_free);
35477 }
35478 } else {
35479 @@ -1361,10 +1360,10 @@ static void hso_serial_close(struct tty_
35480
35481 /* reset the rts and dtr */
35482 /* do the actual close */
35483 - serial->open_count--;
35484 + local_dec(&serial->open_count);
35485
35486 - if (serial->open_count <= 0) {
35487 - serial->open_count = 0;
35488 + if (local_read(&serial->open_count) <= 0) {
35489 + local_set(&serial->open_count, 0);
35490 spin_lock_irq(&serial->serial_lock);
35491 if (serial->tty == tty) {
35492 serial->tty->driver_data = NULL;
35493 @@ -1446,7 +1445,7 @@ static void hso_serial_set_termios(struc
35494
35495 /* the actual setup */
35496 spin_lock_irqsave(&serial->serial_lock, flags);
35497 - if (serial->open_count)
35498 + if (local_read(&serial->open_count))
35499 _hso_serial_set_termios(tty, old);
35500 else
35501 tty->termios = old;
35502 @@ -1905,7 +1904,7 @@ static void intr_callback(struct urb *ur
35503 D1("Pending read interrupt on port %d\n", i);
35504 spin_lock(&serial->serial_lock);
35505 if (serial->rx_state == RX_IDLE &&
35506 - serial->open_count > 0) {
35507 + local_read(&serial->open_count) > 0) {
35508 /* Setup and send a ctrl req read on
35509 * port i */
35510 if (!serial->rx_urb_filled[0]) {
35511 @@ -3097,7 +3096,7 @@ static int hso_resume(struct usb_interfa
35512 /* Start all serial ports */
35513 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35514 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35515 - if (dev2ser(serial_table[i])->open_count) {
35516 + if (local_read(&dev2ser(serial_table[i])->open_count)) {
35517 result =
35518 hso_start_serial_device(serial_table[i], GFP_NOIO);
35519 hso_kick_transmit(dev2ser(serial_table[i]));
35520 diff -urNp linux-2.6.39/drivers/net/usb/ipheth.c linux-2.6.39/drivers/net/usb/ipheth.c
35521 --- linux-2.6.39/drivers/net/usb/ipheth.c 2011-05-19 00:06:34.000000000 -0400
35522 +++ linux-2.6.39/drivers/net/usb/ipheth.c 2011-05-22 19:36:31.000000000 -0400
35523 @@ -421,7 +421,7 @@ static u32 ipheth_ethtool_op_get_link(st
35524 return netif_carrier_ok(dev->net);
35525 }
35526
35527 -static struct ethtool_ops ops = {
35528 +static const struct ethtool_ops ops = {
35529 .get_link = ipheth_ethtool_op_get_link
35530 };
35531
35532 diff -urNp linux-2.6.39/drivers/net/usb/sierra_net.c linux-2.6.39/drivers/net/usb/sierra_net.c
35533 --- linux-2.6.39/drivers/net/usb/sierra_net.c 2011-05-19 00:06:34.000000000 -0400
35534 +++ linux-2.6.39/drivers/net/usb/sierra_net.c 2011-05-22 19:36:31.000000000 -0400
35535 @@ -618,7 +618,7 @@ static u32 sierra_net_get_link(struct ne
35536 return sierra_net_get_private(dev)->link_up && netif_running(net);
35537 }
35538
35539 -static struct ethtool_ops sierra_net_ethtool_ops = {
35540 +static const struct ethtool_ops sierra_net_ethtool_ops = {
35541 .get_drvinfo = sierra_net_get_drvinfo,
35542 .get_link = sierra_net_get_link,
35543 .get_msglevel = usbnet_get_msglevel,
35544 diff -urNp linux-2.6.39/drivers/net/vmxnet3/vmxnet3_ethtool.c linux-2.6.39/drivers/net/vmxnet3/vmxnet3_ethtool.c
35545 --- linux-2.6.39/drivers/net/vmxnet3/vmxnet3_ethtool.c 2011-05-19 00:06:34.000000000 -0400
35546 +++ linux-2.6.39/drivers/net/vmxnet3/vmxnet3_ethtool.c 2011-05-22 19:36:31.000000000 -0400
35547 @@ -631,8 +631,7 @@ vmxnet3_set_rss_indir(struct net_device
35548 * Return with error code if any of the queue indices
35549 * is out of range
35550 */
35551 - if (p->ring_index[i] < 0 ||
35552 - p->ring_index[i] >= adapter->num_rx_queues)
35553 + if (p->ring_index[i] >= adapter->num_rx_queues)
35554 return -EINVAL;
35555 }
35556
35557 diff -urNp linux-2.6.39/drivers/net/vxge/vxge-config.h linux-2.6.39/drivers/net/vxge/vxge-config.h
35558 --- linux-2.6.39/drivers/net/vxge/vxge-config.h 2011-05-19 00:06:34.000000000 -0400
35559 +++ linux-2.6.39/drivers/net/vxge/vxge-config.h 2011-05-22 19:36:31.000000000 -0400
35560 @@ -834,7 +834,7 @@ struct vxge_hw_device_hw_info {
35561 struct vxge_hw_device_attr {
35562 void __iomem *bar0;
35563 struct pci_dev *pdev;
35564 - struct vxge_hw_uld_cbs uld_callbacks;
35565 + struct vxge_hw_uld_cbs uld_callbacks;
35566 };
35567
35568 #define VXGE_HW_DEVICE_LINK_STATE_SET(hldev, ls) (hldev->link_state = ls)
35569 diff -urNp linux-2.6.39/drivers/net/vxge/vxge-main.c linux-2.6.39/drivers/net/vxge/vxge-main.c
35570 --- linux-2.6.39/drivers/net/vxge/vxge-main.c 2011-05-19 00:06:34.000000000 -0400
35571 +++ linux-2.6.39/drivers/net/vxge/vxge-main.c 2011-05-22 19:36:31.000000000 -0400
35572 @@ -97,6 +97,8 @@ static inline void VXGE_COMPLETE_VPATH_T
35573 struct sk_buff *completed[NR_SKB_COMPLETED];
35574 int more;
35575
35576 + pax_track_stack();
35577 +
35578 do {
35579 more = 0;
35580 skb_ptr = completed;
35581 @@ -1927,6 +1929,8 @@ static enum vxge_hw_status vxge_rth_conf
35582 u8 mtable[256] = {0}; /* CPU to vpath mapping */
35583 int index;
35584
35585 + pax_track_stack();
35586 +
35587 /*
35588 * Filling
35589 * - itable with bucket numbers
35590 diff -urNp linux-2.6.39/drivers/net/wan/cycx_x25.c linux-2.6.39/drivers/net/wan/cycx_x25.c
35591 --- linux-2.6.39/drivers/net/wan/cycx_x25.c 2011-05-19 00:06:34.000000000 -0400
35592 +++ linux-2.6.39/drivers/net/wan/cycx_x25.c 2011-05-22 19:36:31.000000000 -0400
35593 @@ -1018,6 +1018,8 @@ static void hex_dump(char *msg, unsigned
35594 unsigned char hex[1024],
35595 * phex = hex;
35596
35597 + pax_track_stack();
35598 +
35599 if (len >= (sizeof(hex) / 2))
35600 len = (sizeof(hex) / 2) - 1;
35601
35602 diff -urNp linux-2.6.39/drivers/net/wan/lapbether.c linux-2.6.39/drivers/net/wan/lapbether.c
35603 --- linux-2.6.39/drivers/net/wan/lapbether.c 2011-05-19 00:06:34.000000000 -0400
35604 +++ linux-2.6.39/drivers/net/wan/lapbether.c 2011-05-22 19:36:31.000000000 -0400
35605 @@ -259,7 +259,7 @@ static int lapbeth_set_mac_address(struc
35606 }
35607
35608
35609 -static struct lapb_register_struct lapbeth_callbacks = {
35610 +static const struct lapb_register_struct lapbeth_callbacks = {
35611 .connect_confirmation = lapbeth_connected,
35612 .connect_indication = lapbeth_connected,
35613 .disconnect_confirmation = lapbeth_disconnected,
35614 diff -urNp linux-2.6.39/drivers/net/wan/x25_asy.c linux-2.6.39/drivers/net/wan/x25_asy.c
35615 --- linux-2.6.39/drivers/net/wan/x25_asy.c 2011-05-19 00:06:34.000000000 -0400
35616 +++ linux-2.6.39/drivers/net/wan/x25_asy.c 2011-05-22 19:36:31.000000000 -0400
35617 @@ -434,7 +434,7 @@ static void x25_asy_disconnected(struct
35618 netif_rx(skb);
35619 }
35620
35621 -static struct lapb_register_struct x25_asy_callbacks = {
35622 +static const struct lapb_register_struct x25_asy_callbacks = {
35623 .connect_confirmation = x25_asy_connected,
35624 .connect_indication = x25_asy_connected,
35625 .disconnect_confirmation = x25_asy_disconnected,
35626 diff -urNp linux-2.6.39/drivers/net/wimax/i2400m/usb-fw.c linux-2.6.39/drivers/net/wimax/i2400m/usb-fw.c
35627 --- linux-2.6.39/drivers/net/wimax/i2400m/usb-fw.c 2011-05-19 00:06:34.000000000 -0400
35628 +++ linux-2.6.39/drivers/net/wimax/i2400m/usb-fw.c 2011-05-22 19:36:31.000000000 -0400
35629 @@ -287,6 +287,8 @@ ssize_t i2400mu_bus_bm_wait_for_ack(stru
35630 int do_autopm = 1;
35631 DECLARE_COMPLETION_ONSTACK(notif_completion);
35632
35633 + pax_track_stack();
35634 +
35635 d_fnstart(8, dev, "(i2400m %p ack %p size %zu)\n",
35636 i2400m, ack, ack_size);
35637 BUG_ON(_ack == i2400m->bm_ack_buf);
35638 diff -urNp linux-2.6.39/drivers/net/wireless/airo.c linux-2.6.39/drivers/net/wireless/airo.c
35639 --- linux-2.6.39/drivers/net/wireless/airo.c 2011-05-19 00:06:34.000000000 -0400
35640 +++ linux-2.6.39/drivers/net/wireless/airo.c 2011-05-22 19:36:31.000000000 -0400
35641 @@ -3001,6 +3001,8 @@ static void airo_process_scan_results (s
35642 BSSListElement * loop_net;
35643 BSSListElement * tmp_net;
35644
35645 + pax_track_stack();
35646 +
35647 /* Blow away current list of scan results */
35648 list_for_each_entry_safe (loop_net, tmp_net, &ai->network_list, list) {
35649 list_move_tail (&loop_net->list, &ai->network_free_list);
35650 @@ -3792,6 +3794,8 @@ static u16 setup_card(struct airo_info *
35651 WepKeyRid wkr;
35652 int rc;
35653
35654 + pax_track_stack();
35655 +
35656 memset( &mySsid, 0, sizeof( mySsid ) );
35657 kfree (ai->flash);
35658 ai->flash = NULL;
35659 @@ -4760,6 +4764,8 @@ static int proc_stats_rid_open( struct i
35660 __le32 *vals = stats.vals;
35661 int len;
35662
35663 + pax_track_stack();
35664 +
35665 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
35666 return -ENOMEM;
35667 data = file->private_data;
35668 @@ -5483,6 +5489,8 @@ static int proc_BSSList_open( struct ino
35669 /* If doLoseSync is not 1, we won't do a Lose Sync */
35670 int doLoseSync = -1;
35671
35672 + pax_track_stack();
35673 +
35674 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
35675 return -ENOMEM;
35676 data = file->private_data;
35677 @@ -7190,6 +7198,8 @@ static int airo_get_aplist(struct net_de
35678 int i;
35679 int loseSync = capable(CAP_NET_ADMIN) ? 1: -1;
35680
35681 + pax_track_stack();
35682 +
35683 qual = kmalloc(IW_MAX_AP * sizeof(*qual), GFP_KERNEL);
35684 if (!qual)
35685 return -ENOMEM;
35686 @@ -7750,6 +7760,8 @@ static void airo_read_wireless_stats(str
35687 CapabilityRid cap_rid;
35688 __le32 *vals = stats_rid.vals;
35689
35690 + pax_track_stack();
35691 +
35692 /* Get stats out of the card */
35693 clear_bit(JOB_WSTATS, &local->jobs);
35694 if (local->power.event) {
35695 diff -urNp linux-2.6.39/drivers/net/wireless/ath/ath5k/debug.c linux-2.6.39/drivers/net/wireless/ath/ath5k/debug.c
35696 --- linux-2.6.39/drivers/net/wireless/ath/ath5k/debug.c 2011-05-19 00:06:34.000000000 -0400
35697 +++ linux-2.6.39/drivers/net/wireless/ath/ath5k/debug.c 2011-05-22 19:36:31.000000000 -0400
35698 @@ -204,6 +204,8 @@ static ssize_t read_file_beacon(struct f
35699 unsigned int v;
35700 u64 tsf;
35701
35702 + pax_track_stack();
35703 +
35704 v = ath5k_hw_reg_read(sc->ah, AR5K_BEACON);
35705 len += snprintf(buf+len, sizeof(buf)-len,
35706 "%-24s0x%08x\tintval: %d\tTIM: 0x%x\n",
35707 @@ -323,6 +325,8 @@ static ssize_t read_file_debug(struct fi
35708 unsigned int len = 0;
35709 unsigned int i;
35710
35711 + pax_track_stack();
35712 +
35713 len += snprintf(buf+len, sizeof(buf)-len,
35714 "DEBUG LEVEL: 0x%08x\n\n", sc->debug.level);
35715
35716 @@ -384,6 +388,8 @@ static ssize_t read_file_antenna(struct
35717 unsigned int i;
35718 unsigned int v;
35719
35720 + pax_track_stack();
35721 +
35722 len += snprintf(buf+len, sizeof(buf)-len, "antenna mode\t%d\n",
35723 sc->ah->ah_ant_mode);
35724 len += snprintf(buf+len, sizeof(buf)-len, "default antenna\t%d\n",
35725 @@ -494,6 +500,8 @@ static ssize_t read_file_misc(struct fil
35726 unsigned int len = 0;
35727 u32 filt = ath5k_hw_get_rx_filter(sc->ah);
35728
35729 + pax_track_stack();
35730 +
35731 len += snprintf(buf+len, sizeof(buf)-len, "bssid-mask: %pM\n",
35732 sc->bssidmask);
35733 len += snprintf(buf+len, sizeof(buf)-len, "filter-flags: 0x%x ",
35734 @@ -550,6 +558,8 @@ static ssize_t read_file_frameerrors(str
35735 unsigned int len = 0;
35736 int i;
35737
35738 + pax_track_stack();
35739 +
35740 len += snprintf(buf+len, sizeof(buf)-len,
35741 "RX\n---------------------\n");
35742 len += snprintf(buf+len, sizeof(buf)-len, "CRC\t%u\t(%u%%)\n",
35743 @@ -667,6 +677,8 @@ static ssize_t read_file_ani(struct file
35744 char buf[700];
35745 unsigned int len = 0;
35746
35747 + pax_track_stack();
35748 +
35749 len += snprintf(buf+len, sizeof(buf)-len,
35750 "HW has PHY error counters:\t%s\n",
35751 sc->ah->ah_capabilities.cap_has_phyerr_counters ?
35752 @@ -827,6 +839,8 @@ static ssize_t read_file_queue(struct fi
35753 struct ath5k_buf *bf, *bf0;
35754 int i, n;
35755
35756 + pax_track_stack();
35757 +
35758 len += snprintf(buf+len, sizeof(buf)-len,
35759 "available txbuffers: %d\n", sc->txbuf_len);
35760
35761 diff -urNp linux-2.6.39/drivers/net/wireless/ath/ath9k/ar9003_calib.c linux-2.6.39/drivers/net/wireless/ath/ath9k/ar9003_calib.c
35762 --- linux-2.6.39/drivers/net/wireless/ath/ath9k/ar9003_calib.c 2011-05-19 00:06:34.000000000 -0400
35763 +++ linux-2.6.39/drivers/net/wireless/ath/ath9k/ar9003_calib.c 2011-05-22 19:36:31.000000000 -0400
35764 @@ -734,6 +734,8 @@ static void ar9003_hw_tx_iq_cal(struct a
35765 s32 i, j, ip, im, nmeasurement;
35766 u8 nchains = get_streams(common->tx_chainmask);
35767
35768 + pax_track_stack();
35769 +
35770 for (ip = 0; ip < MPASS; ip++) {
35771 REG_RMW_FIELD(ah, AR_PHY_TX_IQCAL_CONTROL_1,
35772 AR_PHY_TX_IQCAQL_CONTROL_1_IQCORR_I_Q_COFF_DELPT,
35773 @@ -856,6 +858,8 @@ static void ar9003_hw_tx_iq_cal_post_pro
35774 int i, ip, im, j;
35775 int nmeasurement;
35776
35777 + pax_track_stack();
35778 +
35779 for (i = 0; i < AR9300_MAX_CHAINS; i++) {
35780 if (ah->txchainmask & (1 << i))
35781 num_chains++;
35782 diff -urNp linux-2.6.39/drivers/net/wireless/ath/ath9k/ar9003_paprd.c linux-2.6.39/drivers/net/wireless/ath/ath9k/ar9003_paprd.c
35783 --- linux-2.6.39/drivers/net/wireless/ath/ath9k/ar9003_paprd.c 2011-05-19 00:06:34.000000000 -0400
35784 +++ linux-2.6.39/drivers/net/wireless/ath/ath9k/ar9003_paprd.c 2011-05-22 19:36:31.000000000 -0400
35785 @@ -356,6 +356,8 @@ static bool create_pa_curve(u32 *data_L,
35786 int theta_low_bin = 0;
35787 int i;
35788
35789 + pax_track_stack();
35790 +
35791 /* disregard any bin that contains <= 16 samples */
35792 thresh_accum_cnt = 16;
35793 scale_factor = 5;
35794 diff -urNp linux-2.6.39/drivers/net/wireless/ath/ath9k/debug.c linux-2.6.39/drivers/net/wireless/ath/ath9k/debug.c
35795 --- linux-2.6.39/drivers/net/wireless/ath/ath9k/debug.c 2011-05-19 00:06:34.000000000 -0400
35796 +++ linux-2.6.39/drivers/net/wireless/ath/ath9k/debug.c 2011-05-22 19:36:31.000000000 -0400
35797 @@ -335,6 +335,8 @@ static ssize_t read_file_interrupt(struc
35798 char buf[512];
35799 unsigned int len = 0;
35800
35801 + pax_track_stack();
35802 +
35803 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
35804 len += snprintf(buf + len, sizeof(buf) - len,
35805 "%8s: %10u\n", "RXLP", sc->debug.stats.istats.rxlp);
35806 @@ -422,6 +424,8 @@ static ssize_t read_file_wiphy(struct fi
35807 u8 addr[ETH_ALEN];
35808 u32 tmp;
35809
35810 + pax_track_stack();
35811 +
35812 len += snprintf(buf + len, sizeof(buf) - len,
35813 "%s (chan=%d center-freq: %d MHz channel-type: %d (%s))\n",
35814 wiphy_name(sc->hw->wiphy),
35815 diff -urNp linux-2.6.39/drivers/net/wireless/ath/ath9k/htc_drv_main.c linux-2.6.39/drivers/net/wireless/ath/ath9k/htc_drv_main.c
35816 --- linux-2.6.39/drivers/net/wireless/ath/ath9k/htc_drv_main.c 2011-05-19 00:06:34.000000000 -0400
35817 +++ linux-2.6.39/drivers/net/wireless/ath/ath9k/htc_drv_main.c 2011-05-22 19:36:31.000000000 -0400
35818 @@ -737,6 +737,8 @@ static ssize_t read_file_tgt_stats(struc
35819 unsigned int len = 0;
35820 int ret = 0;
35821
35822 + pax_track_stack();
35823 +
35824 memset(&cmd_rsp, 0, sizeof(cmd_rsp));
35825
35826 WMI_CMD(WMI_TGT_STATS_CMDID);
35827 @@ -782,6 +784,8 @@ static ssize_t read_file_xmit(struct fil
35828 char buf[512];
35829 unsigned int len = 0;
35830
35831 + pax_track_stack();
35832 +
35833 len += snprintf(buf + len, sizeof(buf) - len,
35834 "%20s : %10u\n", "Buffers queued",
35835 priv->debug.tx_stats.buf_queued);
35836 @@ -831,6 +835,8 @@ static ssize_t read_file_recv(struct fil
35837 char buf[512];
35838 unsigned int len = 0;
35839
35840 + pax_track_stack();
35841 +
35842 len += snprintf(buf + len, sizeof(buf) - len,
35843 "%20s : %10u\n", "SKBs allocated",
35844 priv->debug.rx_stats.skb_allocated);
35845 @@ -1816,7 +1822,7 @@ static void ath9k_htc_set_coverage_class
35846 mutex_unlock(&priv->mutex);
35847 }
35848
35849 -struct ieee80211_ops ath9k_htc_ops = {
35850 +const struct ieee80211_ops ath9k_htc_ops = {
35851 .tx = ath9k_htc_tx,
35852 .start = ath9k_htc_start,
35853 .stop = ath9k_htc_stop,
35854 diff -urNp linux-2.6.39/drivers/net/wireless/ath/ath9k/htc.h linux-2.6.39/drivers/net/wireless/ath/ath9k/htc.h
35855 --- linux-2.6.39/drivers/net/wireless/ath/ath9k/htc.h 2011-05-19 00:06:34.000000000 -0400
35856 +++ linux-2.6.39/drivers/net/wireless/ath/ath9k/htc.h 2011-05-22 19:36:31.000000000 -0400
35857 @@ -42,7 +42,7 @@
35858 #define TSF_TO_TU(_h, _l) \
35859 ((((u32)(_h)) << 22) | (((u32)(_l)) >> 10))
35860
35861 -extern struct ieee80211_ops ath9k_htc_ops;
35862 +extern const struct ieee80211_ops ath9k_htc_ops;
35863 extern int htc_modparam_nohwcrypt;
35864
35865 enum htc_phymode {
35866 diff -urNp linux-2.6.39/drivers/net/wireless/ath/ath9k/hw.h linux-2.6.39/drivers/net/wireless/ath/ath9k/hw.h
35867 --- linux-2.6.39/drivers/net/wireless/ath/ath9k/hw.h 2011-05-19 00:06:34.000000000 -0400
35868 +++ linux-2.6.39/drivers/net/wireless/ath/ath9k/hw.h 2011-05-22 19:36:31.000000000 -0400
35869 @@ -753,9 +753,7 @@ struct ath_hw {
35870 } enable_32kHz_clock;
35871
35872 /* Private to hardware code */
35873 - struct ath_hw_private_ops private_ops;
35874 - /* Accessed by the lower level driver */
35875 - struct ath_hw_ops ops;
35876 + struct ath_hw_private_ops private_ops;struct ath_hw_ops ops;
35877
35878 /* Used to program the radio on non single-chip devices */
35879 u32 *analogBank0Data;
35880 diff -urNp linux-2.6.39/drivers/net/wireless/b43/debugfs.c linux-2.6.39/drivers/net/wireless/b43/debugfs.c
35881 --- linux-2.6.39/drivers/net/wireless/b43/debugfs.c 2011-05-19 00:06:34.000000000 -0400
35882 +++ linux-2.6.39/drivers/net/wireless/b43/debugfs.c 2011-05-22 19:36:31.000000000 -0400
35883 @@ -43,7 +43,7 @@ static struct dentry *rootdir;
35884 struct b43_debugfs_fops {
35885 ssize_t (*read)(struct b43_wldev *dev, char *buf, size_t bufsize);
35886 int (*write)(struct b43_wldev *dev, const char *buf, size_t count);
35887 - struct file_operations fops;
35888 + const struct file_operations fops;
35889 /* Offset of struct b43_dfs_file in struct b43_dfsentry */
35890 size_t file_struct_offset;
35891 };
35892 diff -urNp linux-2.6.39/drivers/net/wireless/b43legacy/debugfs.c linux-2.6.39/drivers/net/wireless/b43legacy/debugfs.c
35893 --- linux-2.6.39/drivers/net/wireless/b43legacy/debugfs.c 2011-05-19 00:06:34.000000000 -0400
35894 +++ linux-2.6.39/drivers/net/wireless/b43legacy/debugfs.c 2011-05-22 19:36:31.000000000 -0400
35895 @@ -44,7 +44,7 @@ static struct dentry *rootdir;
35896 struct b43legacy_debugfs_fops {
35897 ssize_t (*read)(struct b43legacy_wldev *dev, char *buf, size_t bufsize);
35898 int (*write)(struct b43legacy_wldev *dev, const char *buf, size_t count);
35899 - struct file_operations fops;
35900 + const struct file_operations fops;
35901 /* Offset of struct b43legacy_dfs_file in struct b43legacy_dfsentry */
35902 size_t file_struct_offset;
35903 /* Take wl->irq_lock before calling read/write? */
35904 diff -urNp linux-2.6.39/drivers/net/wireless/ipw2x00/ipw2100.c linux-2.6.39/drivers/net/wireless/ipw2x00/ipw2100.c
35905 --- linux-2.6.39/drivers/net/wireless/ipw2x00/ipw2100.c 2011-05-19 00:06:34.000000000 -0400
35906 +++ linux-2.6.39/drivers/net/wireless/ipw2x00/ipw2100.c 2011-05-22 19:36:31.000000000 -0400
35907 @@ -2100,6 +2100,8 @@ static int ipw2100_set_essid(struct ipw2
35908 int err;
35909 DECLARE_SSID_BUF(ssid);
35910
35911 + pax_track_stack();
35912 +
35913 IPW_DEBUG_HC("SSID: '%s'\n", print_ssid(ssid, essid, ssid_len));
35914
35915 if (ssid_len)
35916 @@ -5449,6 +5451,8 @@ static int ipw2100_set_key(struct ipw210
35917 struct ipw2100_wep_key *wep_key = (void *)cmd.host_command_parameters;
35918 int err;
35919
35920 + pax_track_stack();
35921 +
35922 IPW_DEBUG_HC("WEP_KEY_INFO: index = %d, len = %d/%d\n",
35923 idx, keylen, len);
35924
35925 diff -urNp linux-2.6.39/drivers/net/wireless/ipw2x00/libipw_rx.c linux-2.6.39/drivers/net/wireless/ipw2x00/libipw_rx.c
35926 --- linux-2.6.39/drivers/net/wireless/ipw2x00/libipw_rx.c 2011-05-19 00:06:34.000000000 -0400
35927 +++ linux-2.6.39/drivers/net/wireless/ipw2x00/libipw_rx.c 2011-05-22 19:36:31.000000000 -0400
35928 @@ -1565,6 +1565,8 @@ static void libipw_process_probe_respons
35929 unsigned long flags;
35930 DECLARE_SSID_BUF(ssid);
35931
35932 + pax_track_stack();
35933 +
35934 LIBIPW_DEBUG_SCAN("'%s' (%pM"
35935 "): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
35936 print_ssid(ssid, info_element->data, info_element->len),
35937 diff -urNp linux-2.6.39/drivers/net/wireless/iwlegacy/iwl-3945.c linux-2.6.39/drivers/net/wireless/iwlegacy/iwl-3945.c
35938 --- linux-2.6.39/drivers/net/wireless/iwlegacy/iwl-3945.c 2011-05-19 00:06:34.000000000 -0400
35939 +++ linux-2.6.39/drivers/net/wireless/iwlegacy/iwl-3945.c 2011-05-22 19:36:31.000000000 -0400
35940 @@ -2630,7 +2630,7 @@ static int iwl3945_load_bsm(struct iwl_p
35941 return 0;
35942 }
35943
35944 -static struct iwl_hcmd_ops iwl3945_hcmd = {
35945 +static const struct iwl_hcmd_ops iwl3945_hcmd = {
35946 .rxon_assoc = iwl3945_send_rxon_assoc,
35947 .commit_rxon = iwl3945_commit_rxon,
35948 };
35949 @@ -2675,7 +2675,7 @@ static const struct iwl_legacy_ops iwl39
35950 .manage_ibss_station = iwl3945_manage_ibss_station,
35951 };
35952
35953 -static struct iwl_hcmd_utils_ops iwl3945_hcmd_utils = {
35954 +static const struct iwl_hcmd_utils_ops iwl3945_hcmd_utils = {
35955 .get_hcmd_size = iwl3945_get_hcmd_size,
35956 .build_addsta_hcmd = iwl3945_build_addsta_hcmd,
35957 .request_scan = iwl3945_request_scan,
35958 diff -urNp linux-2.6.39/drivers/net/wireless/iwlegacy/iwl-4965.c linux-2.6.39/drivers/net/wireless/iwlegacy/iwl-4965.c
35959 --- linux-2.6.39/drivers/net/wireless/iwlegacy/iwl-4965.c 2011-05-19 00:06:34.000000000 -0400
35960 +++ linux-2.6.39/drivers/net/wireless/iwlegacy/iwl-4965.c 2011-05-22 19:36:32.000000000 -0400
35961 @@ -1904,7 +1904,7 @@ static void iwl4965_rx_handler_setup(str
35962 priv->rx_handlers[BEACON_NOTIFICATION] = iwl4965_rx_beacon_notif;
35963 }
35964
35965 -static struct iwl_hcmd_ops iwl4965_hcmd = {
35966 +static const struct iwl_hcmd_ops iwl4965_hcmd = {
35967 .rxon_assoc = iwl4965_send_rxon_assoc,
35968 .commit_rxon = iwl4965_commit_rxon,
35969 .set_rxon_chain = iwl4965_set_rxon_chain,
35970 @@ -2056,7 +2056,7 @@ static void iwl4965_config_ap(struct iwl
35971 iwl4965_send_beacon_cmd(priv);
35972 }
35973
35974 -static struct iwl_hcmd_utils_ops iwl4965_hcmd_utils = {
35975 +static const struct iwl_hcmd_utils_ops iwl4965_hcmd_utils = {
35976 .get_hcmd_size = iwl4965_get_hcmd_size,
35977 .build_addsta_hcmd = iwl4965_build_addsta_hcmd,
35978 .request_scan = iwl4965_request_scan,
35979 @@ -2114,7 +2114,7 @@ static const struct iwl_legacy_ops iwl49
35980 .update_bcast_stations = iwl4965_update_bcast_stations,
35981 };
35982
35983 -struct ieee80211_ops iwl4965_hw_ops = {
35984 +const struct ieee80211_ops iwl4965_hw_ops = {
35985 .tx = iwl4965_mac_tx,
35986 .start = iwl4965_mac_start,
35987 .stop = iwl4965_mac_stop,
35988 diff -urNp linux-2.6.39/drivers/net/wireless/iwlegacy/iwl-4965.h linux-2.6.39/drivers/net/wireless/iwlegacy/iwl-4965.h
35989 --- linux-2.6.39/drivers/net/wireless/iwlegacy/iwl-4965.h 2011-05-19 00:06:34.000000000 -0400
35990 +++ linux-2.6.39/drivers/net/wireless/iwlegacy/iwl-4965.h 2011-05-22 19:36:32.000000000 -0400
35991 @@ -70,7 +70,7 @@ extern struct iwl_cfg iwl4965_cfg;
35992
35993 extern struct iwl_mod_params iwl4965_mod_params;
35994
35995 -extern struct ieee80211_ops iwl4965_hw_ops;
35996 +extern const struct ieee80211_ops iwl4965_hw_ops;
35997
35998 /* tx queue */
35999 void iwl4965_free_tfds_in_queue(struct iwl_priv *priv,
36000 diff -urNp linux-2.6.39/drivers/net/wireless/iwlegacy/iwl-core.h linux-2.6.39/drivers/net/wireless/iwlegacy/iwl-core.h
36001 --- linux-2.6.39/drivers/net/wireless/iwlegacy/iwl-core.h 2011-05-19 00:06:34.000000000 -0400
36002 +++ linux-2.6.39/drivers/net/wireless/iwlegacy/iwl-core.h 2011-05-22 19:36:32.000000000 -0400
36003 @@ -150,7 +150,7 @@ struct iwl_lib_ops {
36004 int (*set_channel_switch)(struct iwl_priv *priv,
36005 struct ieee80211_channel_switch *ch_switch);
36006 /* power management */
36007 - struct iwl_apm_ops apm_ops;
36008 + const struct iwl_apm_ops apm_ops;
36009
36010 /* power */
36011 int (*send_tx_power) (struct iwl_priv *priv);
36012 @@ -160,12 +160,12 @@ struct iwl_lib_ops {
36013 struct iwl_eeprom_ops eeprom_ops;
36014
36015 /* temperature */
36016 - struct iwl_temp_ops temp_ops;
36017 + const struct iwl_temp_ops temp_ops;
36018 /* check for plcp health */
36019 bool (*check_plcp_health)(struct iwl_priv *priv,
36020 struct iwl_rx_packet *pkt);
36021
36022 - struct iwl_debugfs_ops debugfs_ops;
36023 + const struct iwl_debugfs_ops debugfs_ops;
36024
36025 };
36026
36027 diff -urNp linux-2.6.39/drivers/net/wireless/iwlwifi/iwl-6000.c linux-2.6.39/drivers/net/wireless/iwlwifi/iwl-6000.c
36028 --- linux-2.6.39/drivers/net/wireless/iwlwifi/iwl-6000.c 2011-05-19 00:06:34.000000000 -0400
36029 +++ linux-2.6.39/drivers/net/wireless/iwlwifi/iwl-6000.c 2011-05-22 19:36:32.000000000 -0400
36030 @@ -422,11 +422,11 @@ static struct iwl_lib_ops iwl6030_lib =
36031 }
36032 };
36033
36034 -static struct iwl_nic_ops iwl6050_nic_ops = {
36035 +static const struct iwl_nic_ops iwl6050_nic_ops = {
36036 .additional_nic_config = &iwl6050_additional_nic_config,
36037 };
36038
36039 -static struct iwl_nic_ops iwl6150_nic_ops = {
36040 +static const struct iwl_nic_ops iwl6150_nic_ops = {
36041 .additional_nic_config = &iwl6150_additional_nic_config,
36042 };
36043
36044 diff -urNp linux-2.6.39/drivers/net/wireless/iwlwifi/iwl-agn.h linux-2.6.39/drivers/net/wireless/iwlwifi/iwl-agn.h
36045 --- linux-2.6.39/drivers/net/wireless/iwlwifi/iwl-agn.h 2011-05-19 00:06:34.000000000 -0400
36046 +++ linux-2.6.39/drivers/net/wireless/iwlwifi/iwl-agn.h 2011-05-22 19:36:32.000000000 -0400
36047 @@ -109,9 +109,9 @@ extern struct iwl_cfg iwl230_bg_cfg;
36048 extern struct iwl_cfg iwl230_bgn_cfg;
36049
36050 extern struct iwl_mod_params iwlagn_mod_params;
36051 -extern struct iwl_hcmd_ops iwlagn_hcmd;
36052 -extern struct iwl_hcmd_ops iwlagn_bt_hcmd;
36053 -extern struct iwl_hcmd_utils_ops iwlagn_hcmd_utils;
36054 +extern const struct iwl_hcmd_ops iwlagn_hcmd;
36055 +extern const struct iwl_hcmd_ops iwlagn_bt_hcmd;
36056 +extern const struct iwl_hcmd_utils_ops iwlagn_hcmd_utils;
36057
36058 extern struct ieee80211_ops iwlagn_hw_ops;
36059 extern struct ieee80211_ops iwl4965_hw_ops;
36060 diff -urNp linux-2.6.39/drivers/net/wireless/iwlwifi/iwl-agn-hcmd.c linux-2.6.39/drivers/net/wireless/iwlwifi/iwl-agn-hcmd.c
36061 --- linux-2.6.39/drivers/net/wireless/iwlwifi/iwl-agn-hcmd.c 2011-05-19 00:06:34.000000000 -0400
36062 +++ linux-2.6.39/drivers/net/wireless/iwlwifi/iwl-agn-hcmd.c 2011-05-22 19:36:32.000000000 -0400
36063 @@ -363,7 +363,7 @@ static int iwlagn_set_pan_params(struct
36064 return ret;
36065 }
36066
36067 -struct iwl_hcmd_ops iwlagn_hcmd = {
36068 +const struct iwl_hcmd_ops iwlagn_hcmd = {
36069 .rxon_assoc = iwlagn_send_rxon_assoc,
36070 .commit_rxon = iwlagn_commit_rxon,
36071 .set_rxon_chain = iwlagn_set_rxon_chain,
36072 @@ -372,7 +372,7 @@ struct iwl_hcmd_ops iwlagn_hcmd = {
36073 .set_pan_params = iwlagn_set_pan_params,
36074 };
36075
36076 -struct iwl_hcmd_ops iwlagn_bt_hcmd = {
36077 +const struct iwl_hcmd_ops iwlagn_bt_hcmd = {
36078 .rxon_assoc = iwlagn_send_rxon_assoc,
36079 .commit_rxon = iwlagn_commit_rxon,
36080 .set_rxon_chain = iwlagn_set_rxon_chain,
36081 @@ -381,7 +381,7 @@ struct iwl_hcmd_ops iwlagn_bt_hcmd = {
36082 .set_pan_params = iwlagn_set_pan_params,
36083 };
36084
36085 -struct iwl_hcmd_utils_ops iwlagn_hcmd_utils = {
36086 +const struct iwl_hcmd_utils_ops iwlagn_hcmd_utils = {
36087 .get_hcmd_size = iwlagn_get_hcmd_size,
36088 .build_addsta_hcmd = iwlagn_build_addsta_hcmd,
36089 .gain_computation = iwlagn_gain_computation,
36090 diff -urNp linux-2.6.39/drivers/net/wireless/iwlwifi/iwl-agn-rs.c linux-2.6.39/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
36091 --- linux-2.6.39/drivers/net/wireless/iwlwifi/iwl-agn-rs.c 2011-05-19 00:06:34.000000000 -0400
36092 +++ linux-2.6.39/drivers/net/wireless/iwlwifi/iwl-agn-rs.c 2011-05-22 19:36:32.000000000 -0400
36093 @@ -883,6 +883,8 @@ static void rs_tx_status(void *priv_r, s
36094 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
36095 struct iwl_rxon_context *ctx = sta_priv->common.ctx;
36096
36097 + pax_track_stack();
36098 +
36099 IWL_DEBUG_RATE_LIMIT(priv, "get frame ack response, update rate scale window\n");
36100
36101 /* Treat uninitialized rate scaling data same as non-existing. */
36102 @@ -2894,6 +2896,8 @@ static void rs_fill_link_cmd(struct iwl_
36103 container_of(lq_sta, struct iwl_station_priv, lq_sta);
36104 struct iwl_link_quality_cmd *lq_cmd = &lq_sta->lq;
36105
36106 + pax_track_stack();
36107 +
36108 /* Override starting rate (index 0) if needed for debug purposes */
36109 rs_dbgfs_set_mcs(lq_sta, &new_rate, index);
36110
36111 diff -urNp linux-2.6.39/drivers/net/wireless/iwlwifi/iwl-core.h linux-2.6.39/drivers/net/wireless/iwlwifi/iwl-core.h
36112 --- linux-2.6.39/drivers/net/wireless/iwlwifi/iwl-core.h 2011-05-19 00:06:34.000000000 -0400
36113 +++ linux-2.6.39/drivers/net/wireless/iwlwifi/iwl-core.h 2011-05-22 19:36:32.000000000 -0400
36114 @@ -198,28 +198,25 @@ struct iwl_lib_ops {
36115 int (*set_channel_switch)(struct iwl_priv *priv,
36116 struct ieee80211_channel_switch *ch_switch);
36117 /* power management */
36118 - struct iwl_apm_ops apm_ops;
36119 + const struct iwl_apm_ops apm_ops;
36120
36121 /* power */
36122 int (*send_tx_power) (struct iwl_priv *priv);
36123 void (*update_chain_flags)(struct iwl_priv *priv);
36124
36125 /* isr */
36126 - struct iwl_isr_ops isr_ops;
36127 + const struct iwl_isr_ops isr_ops;
36128
36129 /* eeprom operations (as defined in iwl-eeprom.h) */
36130 struct iwl_eeprom_ops eeprom_ops;
36131
36132 /* temperature */
36133 - struct iwl_temp_ops temp_ops;
36134 + const struct iwl_temp_ops temp_ops;
36135
36136 int (*txfifo_flush)(struct iwl_priv *priv, u16 flush_control);
36137 void (*dev_txfifo_flush)(struct iwl_priv *priv, u16 flush_control);
36138
36139 - struct iwl_debugfs_ops debugfs_ops;
36140 -
36141 - /* thermal throttling */
36142 - struct iwl_tt_ops tt_ops;
36143 + const struct iwl_debugfs_ops debugfs_ops;const struct iwl_tt_ops tt_ops;
36144 };
36145
36146 struct iwl_led_ops {
36147 diff -urNp linux-2.6.39/drivers/net/wireless/iwlwifi/iwl-debugfs.c linux-2.6.39/drivers/net/wireless/iwlwifi/iwl-debugfs.c
36148 --- linux-2.6.39/drivers/net/wireless/iwlwifi/iwl-debugfs.c 2011-05-19 00:06:34.000000000 -0400
36149 +++ linux-2.6.39/drivers/net/wireless/iwlwifi/iwl-debugfs.c 2011-05-22 19:36:32.000000000 -0400
36150 @@ -549,6 +549,8 @@ static ssize_t iwl_dbgfs_status_read(str
36151 int pos = 0;
36152 const size_t bufsz = sizeof(buf);
36153
36154 + pax_track_stack();
36155 +
36156 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_ACTIVE:\t %d\n",
36157 test_bit(STATUS_HCMD_ACTIVE, &priv->status));
36158 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INT_ENABLED:\t %d\n",
36159 @@ -681,6 +683,8 @@ static ssize_t iwl_dbgfs_qos_read(struct
36160 char buf[256 * NUM_IWL_RXON_CTX];
36161 const size_t bufsz = sizeof(buf);
36162
36163 + pax_track_stack();
36164 +
36165 for_each_context(priv, ctx) {
36166 pos += scnprintf(buf + pos, bufsz - pos, "context %d:\n",
36167 ctx->ctxid);
36168 diff -urNp linux-2.6.39/drivers/net/wireless/iwlwifi/iwl-debug.h linux-2.6.39/drivers/net/wireless/iwlwifi/iwl-debug.h
36169 --- linux-2.6.39/drivers/net/wireless/iwlwifi/iwl-debug.h 2011-05-19 00:06:34.000000000 -0400
36170 +++ linux-2.6.39/drivers/net/wireless/iwlwifi/iwl-debug.h 2011-05-22 19:36:32.000000000 -0400
36171 @@ -68,8 +68,8 @@ do {
36172 } while (0)
36173
36174 #else
36175 -#define IWL_DEBUG(__priv, level, fmt, args...)
36176 -#define IWL_DEBUG_LIMIT(__priv, level, fmt, args...)
36177 +#define IWL_DEBUG(__priv, level, fmt, args...) do {} while (0)
36178 +#define IWL_DEBUG_LIMIT(__priv, level, fmt, args...) do {} while (0)
36179 static inline void iwl_print_hex_dump(struct iwl_priv *priv, int level,
36180 const void *p, u32 len)
36181 {}
36182 diff -urNp linux-2.6.39/drivers/net/wireless/iwmc3200wifi/cfg80211.c linux-2.6.39/drivers/net/wireless/iwmc3200wifi/cfg80211.c
36183 --- linux-2.6.39/drivers/net/wireless/iwmc3200wifi/cfg80211.c 2011-05-19 00:06:34.000000000 -0400
36184 +++ linux-2.6.39/drivers/net/wireless/iwmc3200wifi/cfg80211.c 2011-05-22 19:36:32.000000000 -0400
36185 @@ -763,7 +763,7 @@ static int iwm_cfg80211_flush_pmksa(stru
36186 }
36187
36188
36189 -static struct cfg80211_ops iwm_cfg80211_ops = {
36190 +static const struct cfg80211_ops iwm_cfg80211_ops = {
36191 .change_virtual_intf = iwm_cfg80211_change_iface,
36192 .add_key = iwm_cfg80211_add_key,
36193 .get_key = iwm_cfg80211_get_key,
36194 diff -urNp linux-2.6.39/drivers/net/wireless/iwmc3200wifi/debugfs.c linux-2.6.39/drivers/net/wireless/iwmc3200wifi/debugfs.c
36195 --- linux-2.6.39/drivers/net/wireless/iwmc3200wifi/debugfs.c 2011-05-19 00:06:34.000000000 -0400
36196 +++ linux-2.6.39/drivers/net/wireless/iwmc3200wifi/debugfs.c 2011-05-22 19:36:32.000000000 -0400
36197 @@ -327,6 +327,8 @@ static ssize_t iwm_debugfs_fw_err_read(s
36198 int buf_len = 512;
36199 size_t len = 0;
36200
36201 + pax_track_stack();
36202 +
36203 if (*ppos != 0)
36204 return 0;
36205 if (count < sizeof(buf))
36206 diff -urNp linux-2.6.39/drivers/net/wireless/libertas/cfg.c linux-2.6.39/drivers/net/wireless/libertas/cfg.c
36207 --- linux-2.6.39/drivers/net/wireless/libertas/cfg.c 2011-05-19 00:06:34.000000000 -0400
36208 +++ linux-2.6.39/drivers/net/wireless/libertas/cfg.c 2011-05-22 19:36:32.000000000 -0400
36209 @@ -2003,7 +2003,7 @@ static int lbs_leave_ibss(struct wiphy *
36210 * Initialization
36211 */
36212
36213 -static struct cfg80211_ops lbs_cfg80211_ops = {
36214 +static const struct cfg80211_ops lbs_cfg80211_ops = {
36215 .set_channel = lbs_cfg_set_channel,
36216 .scan = lbs_cfg_scan,
36217 .connect = lbs_cfg_connect,
36218 diff -urNp linux-2.6.39/drivers/net/wireless/libertas/debugfs.c linux-2.6.39/drivers/net/wireless/libertas/debugfs.c
36219 --- linux-2.6.39/drivers/net/wireless/libertas/debugfs.c 2011-05-19 00:06:34.000000000 -0400
36220 +++ linux-2.6.39/drivers/net/wireless/libertas/debugfs.c 2011-05-22 19:36:32.000000000 -0400
36221 @@ -702,7 +702,7 @@ out_unlock:
36222 struct lbs_debugfs_files {
36223 const char *name;
36224 int perm;
36225 - struct file_operations fops;
36226 + const struct file_operations fops;
36227 };
36228
36229 static const struct lbs_debugfs_files debugfs_files[] = {
36230 diff -urNp linux-2.6.39/drivers/net/wireless/rndis_wlan.c linux-2.6.39/drivers/net/wireless/rndis_wlan.c
36231 --- linux-2.6.39/drivers/net/wireless/rndis_wlan.c 2011-05-19 00:06:34.000000000 -0400
36232 +++ linux-2.6.39/drivers/net/wireless/rndis_wlan.c 2011-05-22 19:36:32.000000000 -0400
36233 @@ -1277,7 +1277,7 @@ static int set_rts_threshold(struct usbn
36234
36235 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
36236
36237 - if (rts_threshold < 0 || rts_threshold > 2347)
36238 + if (rts_threshold > 2347)
36239 rts_threshold = 2347;
36240
36241 tmp = cpu_to_le32(rts_threshold);
36242 diff -urNp linux-2.6.39/drivers/net/wireless/rtlwifi/pci.c linux-2.6.39/drivers/net/wireless/rtlwifi/pci.c
36243 --- linux-2.6.39/drivers/net/wireless/rtlwifi/pci.c 2011-05-19 00:06:34.000000000 -0400
36244 +++ linux-2.6.39/drivers/net/wireless/rtlwifi/pci.c 2011-05-22 19:36:32.000000000 -0400
36245 @@ -1869,7 +1869,7 @@ int rtl_pci_resume(struct pci_dev *pdev)
36246 }
36247 EXPORT_SYMBOL(rtl_pci_resume);
36248
36249 -struct rtl_intf_ops rtl_pci_ops = {
36250 +const struct rtl_intf_ops rtl_pci_ops = {
36251 .adapter_start = rtl_pci_start,
36252 .adapter_stop = rtl_pci_stop,
36253 .adapter_tx = rtl_pci_tx,
36254 diff -urNp linux-2.6.39/drivers/net/wireless/rtlwifi/pci.h linux-2.6.39/drivers/net/wireless/rtlwifi/pci.h
36255 --- linux-2.6.39/drivers/net/wireless/rtlwifi/pci.h 2011-05-19 00:06:34.000000000 -0400
36256 +++ linux-2.6.39/drivers/net/wireless/rtlwifi/pci.h 2011-05-22 19:36:32.000000000 -0400
36257 @@ -234,7 +234,7 @@ struct rtl_pci_priv {
36258
36259 int rtl_pci_reset_trx_ring(struct ieee80211_hw *hw);
36260
36261 -extern struct rtl_intf_ops rtl_pci_ops;
36262 +extern const struct rtl_intf_ops rtl_pci_ops;
36263
36264 int __devinit rtl_pci_probe(struct pci_dev *pdev,
36265 const struct pci_device_id *id);
36266 diff -urNp linux-2.6.39/drivers/net/wireless/rtlwifi/rtl8192c/phy_common.c linux-2.6.39/drivers/net/wireless/rtlwifi/rtl8192c/phy_common.c
36267 --- linux-2.6.39/drivers/net/wireless/rtlwifi/rtl8192c/phy_common.c 2011-05-19 00:06:34.000000000 -0400
36268 +++ linux-2.6.39/drivers/net/wireless/rtlwifi/rtl8192c/phy_common.c 2011-05-22 19:36:32.000000000 -0400
36269 @@ -827,6 +827,8 @@ static bool _rtl92c_phy_sw_chnl_step_by_
36270 u8 rfpath;
36271 u8 num_total_rfpath = rtlphy->num_total_rfpath;
36272
36273 + pax_track_stack();
36274 +
36275 precommoncmdcnt = 0;
36276 _rtl92c_phy_set_sw_chnl_cmdarray(precommoncmd, precommoncmdcnt++,
36277 MAX_PRECMD_CNT,
36278 diff -urNp linux-2.6.39/drivers/net/wireless/rtlwifi/rtl8192ce/sw.c linux-2.6.39/drivers/net/wireless/rtlwifi/rtl8192ce/sw.c
36279 --- linux-2.6.39/drivers/net/wireless/rtlwifi/rtl8192ce/sw.c 2011-05-19 00:06:34.000000000 -0400
36280 +++ linux-2.6.39/drivers/net/wireless/rtlwifi/rtl8192ce/sw.c 2011-05-22 19:36:32.000000000 -0400
36281 @@ -96,7 +96,7 @@ void rtl92c_deinit_sw_vars(struct ieee80
36282 }
36283 }
36284
36285 -static struct rtl_hal_ops rtl8192ce_hal_ops = {
36286 +static const struct rtl_hal_ops rtl8192ce_hal_ops = {
36287 .init_sw_vars = rtl92c_init_sw_vars,
36288 .deinit_sw_vars = rtl92c_deinit_sw_vars,
36289 .read_eeprom_info = rtl92ce_read_eeprom_info,
36290 @@ -151,7 +151,7 @@ static struct rtl_mod_params rtl92ce_mod
36291 .sw_crypto = 0,
36292 };
36293
36294 -static struct rtl_hal_cfg rtl92ce_hal_cfg = {
36295 +static const struct rtl_hal_cfg rtl92ce_hal_cfg = {
36296 .name = "rtl92c_pci",
36297 .fw_name = "rtlwifi/rtl8192cfw.bin",
36298 .ops = &rtl8192ce_hal_ops,
36299 diff -urNp linux-2.6.39/drivers/net/wireless/rtlwifi/rtl8192cu/sw.c linux-2.6.39/drivers/net/wireless/rtlwifi/rtl8192cu/sw.c
36300 --- linux-2.6.39/drivers/net/wireless/rtlwifi/rtl8192cu/sw.c 2011-05-19 00:06:34.000000000 -0400
36301 +++ linux-2.6.39/drivers/net/wireless/rtlwifi/rtl8192cu/sw.c 2011-05-22 19:36:32.000000000 -0400
36302 @@ -77,7 +77,7 @@ static void rtl92cu_deinit_sw_vars(struc
36303 }
36304 }
36305
36306 -static struct rtl_hal_ops rtl8192cu_hal_ops = {
36307 +static const struct rtl_hal_ops rtl8192cu_hal_ops = {
36308 .init_sw_vars = rtl92cu_init_sw_vars,
36309 .deinit_sw_vars = rtl92cu_deinit_sw_vars,
36310 .read_chip_version = rtl92c_read_chip_version,
36311 @@ -147,7 +147,7 @@ static struct rtl_hal_usbint_cfg rtl92cu
36312 .usb_mq_to_hwq = rtl8192cu_mq_to_hwq,
36313 };
36314
36315 -static struct rtl_hal_cfg rtl92cu_hal_cfg = {
36316 +static const struct rtl_hal_cfg rtl92cu_hal_cfg = {
36317 .name = "rtl92c_usb",
36318 .fw_name = "rtlwifi/rtl8192cufw.bin",
36319 .ops = &rtl8192cu_hal_ops,
36320 diff -urNp linux-2.6.39/drivers/net/wireless/rtlwifi/usb.c linux-2.6.39/drivers/net/wireless/rtlwifi/usb.c
36321 --- linux-2.6.39/drivers/net/wireless/rtlwifi/usb.c 2011-05-19 00:06:34.000000000 -0400
36322 +++ linux-2.6.39/drivers/net/wireless/rtlwifi/usb.c 2011-05-22 19:36:32.000000000 -0400
36323 @@ -913,7 +913,7 @@ static bool rtl_usb_tx_chk_waitq_insert(
36324 return false;
36325 }
36326
36327 -static struct rtl_intf_ops rtl_usb_ops = {
36328 +static const struct rtl_intf_ops rtl_usb_ops = {
36329 .adapter_start = rtl_usb_start,
36330 .adapter_stop = rtl_usb_stop,
36331 .adapter_tx = rtl_usb_tx,
36332 diff -urNp linux-2.6.39/drivers/net/wireless/rtlwifi/wifi.h linux-2.6.39/drivers/net/wireless/rtlwifi/wifi.h
36333 --- linux-2.6.39/drivers/net/wireless/rtlwifi/wifi.h 2011-05-19 00:06:34.000000000 -0400
36334 +++ linux-2.6.39/drivers/net/wireless/rtlwifi/wifi.h 2011-05-22 19:36:32.000000000 -0400
36335 @@ -1447,7 +1447,7 @@ struct rtl_hal_cfg {
36336 u8 bar_id;
36337 char *name;
36338 char *fw_name;
36339 - struct rtl_hal_ops *ops;
36340 + const struct rtl_hal_ops *ops;
36341 struct rtl_mod_params *mod_params;
36342 struct rtl_hal_usbint_cfg *usb_interface_cfg;
36343
36344 @@ -1533,7 +1533,7 @@ struct rtl_priv {
36345 *intf_ops : for diff interrface usb/pcie
36346 */
36347 struct rtl_hal_cfg *cfg;
36348 - struct rtl_intf_ops *intf_ops;
36349 + const struct rtl_intf_ops *intf_ops;
36350
36351 /*this var will be set by set_bit,
36352 and was used to indicate status of
36353 diff -urNp linux-2.6.39/drivers/net/wireless/wl12xx/spi.c linux-2.6.39/drivers/net/wireless/wl12xx/spi.c
36354 --- linux-2.6.39/drivers/net/wireless/wl12xx/spi.c 2011-05-19 00:06:34.000000000 -0400
36355 +++ linux-2.6.39/drivers/net/wireless/wl12xx/spi.c 2011-05-22 19:36:32.000000000 -0400
36356 @@ -280,6 +280,8 @@ static void wl1271_spi_raw_write(struct
36357 u32 chunk_len;
36358 int i;
36359
36360 + pax_track_stack();
36361 +
36362 WARN_ON(len > WL1271_AGGR_BUFFER_SIZE);
36363
36364 spi_message_init(&m);
36365 diff -urNp linux-2.6.39/drivers/net/xen-netback/interface.c linux-2.6.39/drivers/net/xen-netback/interface.c
36366 --- linux-2.6.39/drivers/net/xen-netback/interface.c 2011-05-19 00:06:34.000000000 -0400
36367 +++ linux-2.6.39/drivers/net/xen-netback/interface.c 2011-05-22 19:36:32.000000000 -0400
36368 @@ -273,7 +273,7 @@ static void xenvif_get_strings(struct ne
36369 }
36370 }
36371
36372 -static struct ethtool_ops xenvif_ethtool_ops = {
36373 +static const struct ethtool_ops xenvif_ethtool_ops = {
36374 .get_tx_csum = ethtool_op_get_tx_csum,
36375 .set_tx_csum = xenvif_set_tx_csum,
36376 .get_sg = ethtool_op_get_sg,
36377 diff -urNp linux-2.6.39/drivers/net/xilinx_emaclite.c linux-2.6.39/drivers/net/xilinx_emaclite.c
36378 --- linux-2.6.39/drivers/net/xilinx_emaclite.c 2011-05-19 00:06:34.000000000 -0400
36379 +++ linux-2.6.39/drivers/net/xilinx_emaclite.c 2011-05-22 19:36:32.000000000 -0400
36380 @@ -1085,7 +1085,7 @@ static bool get_bool(struct platform_dev
36381 }
36382 }
36383
36384 -static struct net_device_ops xemaclite_netdev_ops;
36385 +static const struct net_device_ops xemaclite_netdev_ops;
36386
36387 /**
36388 * xemaclite_of_probe - Probe method for the Emaclite device.
36389 @@ -1264,7 +1264,7 @@ xemaclite_poll_controller(struct net_dev
36390 }
36391 #endif
36392
36393 -static struct net_device_ops xemaclite_netdev_ops = {
36394 +static const struct net_device_ops xemaclite_netdev_ops = {
36395 .ndo_open = xemaclite_open,
36396 .ndo_stop = xemaclite_close,
36397 .ndo_start_xmit = xemaclite_send,
36398 diff -urNp linux-2.6.39/drivers/nfc/pn544.c linux-2.6.39/drivers/nfc/pn544.c
36399 --- linux-2.6.39/drivers/nfc/pn544.c 2011-05-19 00:06:34.000000000 -0400
36400 +++ linux-2.6.39/drivers/nfc/pn544.c 2011-05-22 19:36:32.000000000 -0400
36401 @@ -89,7 +89,7 @@ static ssize_t pn544_test(struct device
36402
36403 static int pn544_enable(struct pn544_info *info, int mode)
36404 {
36405 - struct pn544_nfc_platform_data *pdata;
36406 + const struct pn544_nfc_platform_data *pdata;
36407 struct i2c_client *client = info->i2c_dev;
36408
36409 int r;
36410 @@ -118,7 +118,7 @@ static int pn544_enable(struct pn544_inf
36411
36412 static void pn544_disable(struct pn544_info *info)
36413 {
36414 - struct pn544_nfc_platform_data *pdata;
36415 + const struct pn544_nfc_platform_data *pdata;
36416 struct i2c_client *client = info->i2c_dev;
36417
36418 pdata = client->dev.platform_data;
36419 @@ -509,7 +509,7 @@ static long pn544_ioctl(struct file *fil
36420 struct pn544_info *info = container_of(file->private_data,
36421 struct pn544_info, miscdev);
36422 struct i2c_client *client = info->i2c_dev;
36423 - struct pn544_nfc_platform_data *pdata;
36424 + const struct pn544_nfc_platform_data *pdata;
36425 unsigned int val;
36426 int r = 0;
36427
36428 @@ -715,7 +715,7 @@ static int __devinit pn544_probe(struct
36429 const struct i2c_device_id *id)
36430 {
36431 struct pn544_info *info;
36432 - struct pn544_nfc_platform_data *pdata;
36433 + const struct pn544_nfc_platform_data *pdata;
36434 int r = 0;
36435
36436 dev_dbg(&client->dev, "%s\n", __func__);
36437 diff -urNp linux-2.6.39/drivers/of/pdt.c linux-2.6.39/drivers/of/pdt.c
36438 --- linux-2.6.39/drivers/of/pdt.c 2011-05-19 00:06:34.000000000 -0400
36439 +++ linux-2.6.39/drivers/of/pdt.c 2011-05-22 19:36:32.000000000 -0400
36440 @@ -24,7 +24,7 @@
36441 #include <linux/of_pdt.h>
36442 #include <asm/prom.h>
36443
36444 -static struct of_pdt_ops *of_pdt_prom_ops __initdata;
36445 +static const struct of_pdt_ops *of_pdt_prom_ops;
36446
36447 void __initdata (*of_pdt_build_more)(struct device_node *dp,
36448 struct device_node ***nextp);
36449 diff -urNp linux-2.6.39/drivers/oprofile/buffer_sync.c linux-2.6.39/drivers/oprofile/buffer_sync.c
36450 --- linux-2.6.39/drivers/oprofile/buffer_sync.c 2011-05-19 00:06:34.000000000 -0400
36451 +++ linux-2.6.39/drivers/oprofile/buffer_sync.c 2011-05-22 19:36:32.000000000 -0400
36452 @@ -342,7 +342,7 @@ static void add_data(struct op_entry *en
36453 if (cookie == NO_COOKIE)
36454 offset = pc;
36455 if (cookie == INVALID_COOKIE) {
36456 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36457 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36458 offset = pc;
36459 }
36460 if (cookie != last_cookie) {
36461 @@ -386,14 +386,14 @@ add_sample(struct mm_struct *mm, struct
36462 /* add userspace sample */
36463
36464 if (!mm) {
36465 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
36466 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
36467 return 0;
36468 }
36469
36470 cookie = lookup_dcookie(mm, s->eip, &offset);
36471
36472 if (cookie == INVALID_COOKIE) {
36473 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36474 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36475 return 0;
36476 }
36477
36478 @@ -562,7 +562,7 @@ void sync_buffer(int cpu)
36479 /* ignore backtraces if failed to add a sample */
36480 if (state == sb_bt_start) {
36481 state = sb_bt_ignore;
36482 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
36483 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
36484 }
36485 }
36486 release_mm(mm);
36487 diff -urNp linux-2.6.39/drivers/oprofile/event_buffer.c linux-2.6.39/drivers/oprofile/event_buffer.c
36488 --- linux-2.6.39/drivers/oprofile/event_buffer.c 2011-05-19 00:06:34.000000000 -0400
36489 +++ linux-2.6.39/drivers/oprofile/event_buffer.c 2011-05-22 19:36:32.000000000 -0400
36490 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value
36491 }
36492
36493 if (buffer_pos == buffer_size) {
36494 - atomic_inc(&oprofile_stats.event_lost_overflow);
36495 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
36496 return;
36497 }
36498
36499 diff -urNp linux-2.6.39/drivers/oprofile/oprof.c linux-2.6.39/drivers/oprofile/oprof.c
36500 --- linux-2.6.39/drivers/oprofile/oprof.c 2011-05-19 00:06:34.000000000 -0400
36501 +++ linux-2.6.39/drivers/oprofile/oprof.c 2011-05-22 19:36:32.000000000 -0400
36502 @@ -110,7 +110,7 @@ static void switch_worker(struct work_st
36503 if (oprofile_ops.switch_events())
36504 return;
36505
36506 - atomic_inc(&oprofile_stats.multiplex_counter);
36507 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
36508 start_switch_worker();
36509 }
36510
36511 diff -urNp linux-2.6.39/drivers/oprofile/oprofilefs.c linux-2.6.39/drivers/oprofile/oprofilefs.c
36512 --- linux-2.6.39/drivers/oprofile/oprofilefs.c 2011-05-19 00:06:34.000000000 -0400
36513 +++ linux-2.6.39/drivers/oprofile/oprofilefs.c 2011-05-22 19:36:32.000000000 -0400
36514 @@ -186,7 +186,7 @@ static const struct file_operations atom
36515
36516
36517 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
36518 - char const *name, atomic_t *val)
36519 + char const *name, atomic_unchecked_t *val)
36520 {
36521 return __oprofilefs_create_file(sb, root, name,
36522 &atomic_ro_fops, 0444, val);
36523 diff -urNp linux-2.6.39/drivers/oprofile/oprofile_stats.c linux-2.6.39/drivers/oprofile/oprofile_stats.c
36524 --- linux-2.6.39/drivers/oprofile/oprofile_stats.c 2011-05-19 00:06:34.000000000 -0400
36525 +++ linux-2.6.39/drivers/oprofile/oprofile_stats.c 2011-05-22 19:36:32.000000000 -0400
36526 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
36527 cpu_buf->sample_invalid_eip = 0;
36528 }
36529
36530 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
36531 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
36532 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
36533 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
36534 - atomic_set(&oprofile_stats.multiplex_counter, 0);
36535 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
36536 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
36537 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
36538 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
36539 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
36540 }
36541
36542
36543 diff -urNp linux-2.6.39/drivers/oprofile/oprofile_stats.h linux-2.6.39/drivers/oprofile/oprofile_stats.h
36544 --- linux-2.6.39/drivers/oprofile/oprofile_stats.h 2011-05-19 00:06:34.000000000 -0400
36545 +++ linux-2.6.39/drivers/oprofile/oprofile_stats.h 2011-05-22 19:36:32.000000000 -0400
36546 @@ -13,11 +13,11 @@
36547 #include <asm/atomic.h>
36548
36549 struct oprofile_stat_struct {
36550 - atomic_t sample_lost_no_mm;
36551 - atomic_t sample_lost_no_mapping;
36552 - atomic_t bt_lost_no_mapping;
36553 - atomic_t event_lost_overflow;
36554 - atomic_t multiplex_counter;
36555 + atomic_unchecked_t sample_lost_no_mm;
36556 + atomic_unchecked_t sample_lost_no_mapping;
36557 + atomic_unchecked_t bt_lost_no_mapping;
36558 + atomic_unchecked_t event_lost_overflow;
36559 + atomic_unchecked_t multiplex_counter;
36560 };
36561
36562 extern struct oprofile_stat_struct oprofile_stats;
36563 diff -urNp linux-2.6.39/drivers/parisc/dino.c linux-2.6.39/drivers/parisc/dino.c
36564 --- linux-2.6.39/drivers/parisc/dino.c 2011-05-19 00:06:34.000000000 -0400
36565 +++ linux-2.6.39/drivers/parisc/dino.c 2011-05-22 19:36:32.000000000 -0400
36566 @@ -238,7 +238,7 @@ static int dino_cfg_write(struct pci_bus
36567 return 0;
36568 }
36569
36570 -static struct pci_ops dino_cfg_ops = {
36571 +static const struct pci_ops dino_cfg_ops = {
36572 .read = dino_cfg_read,
36573 .write = dino_cfg_write,
36574 };
36575 diff -urNp linux-2.6.39/drivers/parisc/lba_pci.c linux-2.6.39/drivers/parisc/lba_pci.c
36576 --- linux-2.6.39/drivers/parisc/lba_pci.c 2011-05-19 00:06:34.000000000 -0400
36577 +++ linux-2.6.39/drivers/parisc/lba_pci.c 2011-05-22 19:36:32.000000000 -0400
36578 @@ -468,7 +468,7 @@ static int elroy_cfg_write(struct pci_bu
36579 }
36580
36581
36582 -static struct pci_ops elroy_cfg_ops = {
36583 +static const struct pci_ops elroy_cfg_ops = {
36584 .read = elroy_cfg_read,
36585 .write = elroy_cfg_write,
36586 };
36587 @@ -541,7 +541,7 @@ static int mercury_cfg_write(struct pci_
36588 return 0;
36589 }
36590
36591 -static struct pci_ops mercury_cfg_ops = {
36592 +static const struct pci_ops mercury_cfg_ops = {
36593 .read = mercury_cfg_read,
36594 .write = mercury_cfg_write,
36595 };
36596 @@ -1405,7 +1405,7 @@ lba_driver_probe(struct parisc_device *d
36597 {
36598 struct lba_device *lba_dev;
36599 struct pci_bus *lba_bus;
36600 - struct pci_ops *cfg_ops;
36601 + const struct pci_ops *cfg_ops;
36602 u32 func_class;
36603 void *tmp_obj;
36604 char *version;
36605 diff -urNp linux-2.6.39/drivers/parport/procfs.c linux-2.6.39/drivers/parport/procfs.c
36606 --- linux-2.6.39/drivers/parport/procfs.c 2011-05-19 00:06:34.000000000 -0400
36607 +++ linux-2.6.39/drivers/parport/procfs.c 2011-05-22 19:36:32.000000000 -0400
36608 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *t
36609
36610 *ppos += len;
36611
36612 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
36613 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
36614 }
36615
36616 #ifdef CONFIG_PARPORT_1284
36617 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table
36618
36619 *ppos += len;
36620
36621 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
36622 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
36623 }
36624 #endif /* IEEE1284.3 support. */
36625
36626 diff -urNp linux-2.6.39/drivers/pci/access.c linux-2.6.39/drivers/pci/access.c
36627 --- linux-2.6.39/drivers/pci/access.c 2011-05-19 00:06:34.000000000 -0400
36628 +++ linux-2.6.39/drivers/pci/access.c 2011-05-22 19:36:32.000000000 -0400
36629 @@ -74,9 +74,9 @@ EXPORT_SYMBOL(pci_bus_write_config_dword
36630 *
36631 * Return previous raw operations
36632 */
36633 -struct pci_ops *pci_bus_set_ops(struct pci_bus *bus, struct pci_ops *ops)
36634 +const struct pci_ops *pci_bus_set_ops(struct pci_bus *bus, const struct pci_ops *ops)
36635 {
36636 - struct pci_ops *old_ops;
36637 + const struct pci_ops *old_ops;
36638 unsigned long flags;
36639
36640 raw_spin_lock_irqsave(&pci_lock, flags);
36641 diff -urNp linux-2.6.39/drivers/pci/hotplug/acpiphp_glue.c linux-2.6.39/drivers/pci/hotplug/acpiphp_glue.c
36642 --- linux-2.6.39/drivers/pci/hotplug/acpiphp_glue.c 2011-05-19 00:06:34.000000000 -0400
36643 +++ linux-2.6.39/drivers/pci/hotplug/acpiphp_glue.c 2011-05-22 19:36:32.000000000 -0400
36644 @@ -110,7 +110,7 @@ static int post_dock_fixups(struct notif
36645 }
36646
36647
36648 -static struct acpi_dock_ops acpiphp_dock_ops = {
36649 +static const struct acpi_dock_ops acpiphp_dock_ops = {
36650 .handler = handle_hotplug_event_func,
36651 };
36652
36653 diff -urNp linux-2.6.39/drivers/pci/hotplug/cpqphp_nvram.c linux-2.6.39/drivers/pci/hotplug/cpqphp_nvram.c
36654 --- linux-2.6.39/drivers/pci/hotplug/cpqphp_nvram.c 2011-05-19 00:06:34.000000000 -0400
36655 +++ linux-2.6.39/drivers/pci/hotplug/cpqphp_nvram.c 2011-05-22 19:36:32.000000000 -0400
36656 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_
36657
36658 void compaq_nvram_init (void __iomem *rom_start)
36659 {
36660 +
36661 +#ifndef CONFIG_PAX_KERNEXEC
36662 if (rom_start) {
36663 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
36664 }
36665 +#endif
36666 +
36667 dbg("int15 entry = %p\n", compaq_int15_entry_point);
36668
36669 /* initialize our int15 lock */
36670 diff -urNp linux-2.6.39/drivers/pci/hotplug/shpchp.h linux-2.6.39/drivers/pci/hotplug/shpchp.h
36671 --- linux-2.6.39/drivers/pci/hotplug/shpchp.h 2011-05-19 00:06:34.000000000 -0400
36672 +++ linux-2.6.39/drivers/pci/hotplug/shpchp.h 2011-05-22 19:36:32.000000000 -0400
36673 @@ -86,7 +86,7 @@ struct slot {
36674 u8 presence_save;
36675 u8 pwr_save;
36676 struct controller *ctrl;
36677 - struct hpc_ops *hpc_ops;
36678 + const struct hpc_ops *hpc_ops;
36679 struct hotplug_slot *hotplug_slot;
36680 struct list_head slot_list;
36681 struct delayed_work work; /* work for button event */
36682 @@ -107,7 +107,7 @@ struct controller {
36683 int slot_num_inc; /* 1 or -1 */
36684 struct pci_dev *pci_dev;
36685 struct list_head slot_list;
36686 - struct hpc_ops *hpc_ops;
36687 + const struct hpc_ops *hpc_ops;
36688 wait_queue_head_t queue; /* sleep & wake process */
36689 u8 slot_device_offset;
36690 u32 pcix_misc2_reg; /* for amd pogo errata */
36691 diff -urNp linux-2.6.39/drivers/pci/hotplug/shpchp_hpc.c linux-2.6.39/drivers/pci/hotplug/shpchp_hpc.c
36692 --- linux-2.6.39/drivers/pci/hotplug/shpchp_hpc.c 2011-05-19 00:06:34.000000000 -0400
36693 +++ linux-2.6.39/drivers/pci/hotplug/shpchp_hpc.c 2011-05-22 19:36:32.000000000 -0400
36694 @@ -910,7 +910,7 @@ static int shpc_get_max_bus_speed(struct
36695 return retval;
36696 }
36697
36698 -static struct hpc_ops shpchp_hpc_ops = {
36699 +static const struct hpc_ops shpchp_hpc_ops = {
36700 .power_on_slot = hpc_power_on_slot,
36701 .slot_enable = hpc_slot_enable,
36702 .slot_disable = hpc_slot_disable,
36703 diff -urNp linux-2.6.39/drivers/pci/intel-iommu.c linux-2.6.39/drivers/pci/intel-iommu.c
36704 --- linux-2.6.39/drivers/pci/intel-iommu.c 2011-05-19 00:06:34.000000000 -0400
36705 +++ linux-2.6.39/drivers/pci/intel-iommu.c 2011-05-22 19:36:32.000000000 -0400
36706 @@ -391,7 +391,7 @@ static int intel_iommu_strict;
36707 static DEFINE_SPINLOCK(device_domain_lock);
36708 static LIST_HEAD(device_domain_list);
36709
36710 -static struct iommu_ops intel_iommu_ops;
36711 +static const struct iommu_ops intel_iommu_ops;
36712
36713 static int __init intel_iommu_setup(char *str)
36714 {
36715 @@ -2945,7 +2945,7 @@ static int intel_mapping_error(struct de
36716 return !dma_addr;
36717 }
36718
36719 -struct dma_map_ops intel_dma_ops = {
36720 +const struct dma_map_ops intel_dma_ops = {
36721 .alloc_coherent = intel_alloc_coherent,
36722 .free_coherent = intel_free_coherent,
36723 .map_sg = intel_map_sg,
36724 @@ -3739,7 +3739,7 @@ static int intel_iommu_domain_has_cap(st
36725 return 0;
36726 }
36727
36728 -static struct iommu_ops intel_iommu_ops = {
36729 +static const struct iommu_ops intel_iommu_ops = {
36730 .domain_init = intel_iommu_domain_init,
36731 .domain_destroy = intel_iommu_domain_destroy,
36732 .attach_dev = intel_iommu_attach_device,
36733 diff -urNp linux-2.6.39/drivers/pci/pci-acpi.c linux-2.6.39/drivers/pci/pci-acpi.c
36734 --- linux-2.6.39/drivers/pci/pci-acpi.c 2011-05-19 00:06:34.000000000 -0400
36735 +++ linux-2.6.39/drivers/pci/pci-acpi.c 2011-05-22 19:36:32.000000000 -0400
36736 @@ -332,7 +332,7 @@ static int acpi_pci_run_wake(struct pci_
36737 return 0;
36738 }
36739
36740 -static struct pci_platform_pm_ops acpi_pci_platform_pm = {
36741 +static const struct pci_platform_pm_ops acpi_pci_platform_pm = {
36742 .is_manageable = acpi_pci_power_manageable,
36743 .set_state = acpi_pci_set_power_state,
36744 .choose_state = acpi_pci_choose_state,
36745 diff -urNp linux-2.6.39/drivers/pci/pci.c linux-2.6.39/drivers/pci/pci.c
36746 --- linux-2.6.39/drivers/pci/pci.c 2011-05-19 00:06:34.000000000 -0400
36747 +++ linux-2.6.39/drivers/pci/pci.c 2011-05-22 19:36:32.000000000 -0400
36748 @@ -480,9 +480,9 @@ pci_restore_bars(struct pci_dev *dev)
36749 pci_update_resource(dev, i);
36750 }
36751
36752 -static struct pci_platform_pm_ops *pci_platform_pm;
36753 +static const struct pci_platform_pm_ops *pci_platform_pm;
36754
36755 -int pci_set_platform_pm(struct pci_platform_pm_ops *ops)
36756 +int pci_set_platform_pm(const struct pci_platform_pm_ops *ops)
36757 {
36758 if (!ops->is_manageable || !ops->set_state || !ops->choose_state
36759 || !ops->sleep_wake || !ops->can_wakeup)
36760 diff -urNp linux-2.6.39/drivers/pci/pcie/aer/aerdrv_core.c linux-2.6.39/drivers/pci/pcie/aer/aerdrv_core.c
36761 --- linux-2.6.39/drivers/pci/pcie/aer/aerdrv_core.c 2011-05-19 00:06:34.000000000 -0400
36762 +++ linux-2.6.39/drivers/pci/pcie/aer/aerdrv_core.c 2011-05-22 19:36:32.000000000 -0400
36763 @@ -239,7 +239,7 @@ static bool find_source_device(struct pc
36764 static int report_error_detected(struct pci_dev *dev, void *data)
36765 {
36766 pci_ers_result_t vote;
36767 - struct pci_error_handlers *err_handler;
36768 + const struct pci_error_handlers *err_handler;
36769 struct aer_broadcast_data *result_data;
36770 result_data = (struct aer_broadcast_data *) data;
36771
36772 @@ -273,7 +273,7 @@ static int report_error_detected(struct
36773 static int report_mmio_enabled(struct pci_dev *dev, void *data)
36774 {
36775 pci_ers_result_t vote;
36776 - struct pci_error_handlers *err_handler;
36777 + const struct pci_error_handlers *err_handler;
36778 struct aer_broadcast_data *result_data;
36779 result_data = (struct aer_broadcast_data *) data;
36780
36781 @@ -291,7 +291,7 @@ static int report_mmio_enabled(struct pc
36782 static int report_slot_reset(struct pci_dev *dev, void *data)
36783 {
36784 pci_ers_result_t vote;
36785 - struct pci_error_handlers *err_handler;
36786 + const struct pci_error_handlers *err_handler;
36787 struct aer_broadcast_data *result_data;
36788 result_data = (struct aer_broadcast_data *) data;
36789
36790 @@ -308,7 +308,7 @@ static int report_slot_reset(struct pci_
36791
36792 static int report_resume(struct pci_dev *dev, void *data)
36793 {
36794 - struct pci_error_handlers *err_handler;
36795 + const struct pci_error_handlers *err_handler;
36796
36797 dev->error_state = pci_channel_io_normal;
36798
36799 diff -urNp linux-2.6.39/drivers/pci/pcie/aer/aer_inject.c linux-2.6.39/drivers/pci/pcie/aer/aer_inject.c
36800 --- linux-2.6.39/drivers/pci/pcie/aer/aer_inject.c 2011-05-19 00:06:34.000000000 -0400
36801 +++ linux-2.6.39/drivers/pci/pcie/aer/aer_inject.c 2011-05-22 19:36:32.000000000 -0400
36802 @@ -64,7 +64,7 @@ struct aer_error {
36803 struct pci_bus_ops {
36804 struct list_head list;
36805 struct pci_bus *bus;
36806 - struct pci_ops *ops;
36807 + const struct pci_ops *ops;
36808 };
36809
36810 static LIST_HEAD(einjected);
36811 @@ -110,7 +110,7 @@ static struct aer_error *__find_aer_erro
36812 }
36813
36814 /* inject_lock must be held before calling */
36815 -static struct pci_ops *__find_pci_bus_ops(struct pci_bus *bus)
36816 +static const struct pci_ops *__find_pci_bus_ops(struct pci_bus *bus)
36817 {
36818 struct pci_bus_ops *bus_ops;
36819
36820 @@ -187,7 +187,7 @@ static int pci_read_aer(struct pci_bus *
36821 u32 *sim;
36822 struct aer_error *err;
36823 unsigned long flags;
36824 - struct pci_ops *ops;
36825 + const struct pci_ops *ops;
36826 int domain;
36827
36828 spin_lock_irqsave(&inject_lock, flags);
36829 @@ -219,7 +219,7 @@ int pci_write_aer(struct pci_bus *bus, u
36830 struct aer_error *err;
36831 unsigned long flags;
36832 int rw1cs;
36833 - struct pci_ops *ops;
36834 + const struct pci_ops *ops;
36835 int domain;
36836
36837 spin_lock_irqsave(&inject_lock, flags);
36838 @@ -254,7 +254,7 @@ static struct pci_ops pci_ops_aer = {
36839
36840 static void pci_bus_ops_init(struct pci_bus_ops *bus_ops,
36841 struct pci_bus *bus,
36842 - struct pci_ops *ops)
36843 + const struct pci_ops *ops)
36844 {
36845 INIT_LIST_HEAD(&bus_ops->list);
36846 bus_ops->bus = bus;
36847 @@ -263,7 +263,7 @@ static void pci_bus_ops_init(struct pci_
36848
36849 static int pci_bus_set_aer_ops(struct pci_bus *bus)
36850 {
36851 - struct pci_ops *ops;
36852 + const struct pci_ops *ops;
36853 struct pci_bus_ops *bus_ops;
36854 unsigned long flags;
36855
36856 diff -urNp linux-2.6.39/drivers/pci/pcie/aspm.c linux-2.6.39/drivers/pci/pcie/aspm.c
36857 --- linux-2.6.39/drivers/pci/pcie/aspm.c 2011-05-19 00:06:34.000000000 -0400
36858 +++ linux-2.6.39/drivers/pci/pcie/aspm.c 2011-05-22 19:36:32.000000000 -0400
36859 @@ -27,9 +27,9 @@
36860 #define MODULE_PARAM_PREFIX "pcie_aspm."
36861
36862 /* Note: those are not register definitions */
36863 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
36864 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
36865 -#define ASPM_STATE_L1 (4) /* L1 state */
36866 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
36867 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
36868 +#define ASPM_STATE_L1 (4U) /* L1 state */
36869 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
36870 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
36871
36872 diff -urNp linux-2.6.39/drivers/pci/pci.h linux-2.6.39/drivers/pci/pci.h
36873 --- linux-2.6.39/drivers/pci/pci.h 2011-05-19 00:06:34.000000000 -0400
36874 +++ linux-2.6.39/drivers/pci/pci.h 2011-05-22 19:36:32.000000000 -0400
36875 @@ -65,7 +65,7 @@ struct pci_platform_pm_ops {
36876 int (*run_wake)(struct pci_dev *dev, bool enable);
36877 };
36878
36879 -extern int pci_set_platform_pm(struct pci_platform_pm_ops *ops);
36880 +extern int pci_set_platform_pm(const struct pci_platform_pm_ops *ops);
36881 extern void pci_update_current_state(struct pci_dev *dev, pci_power_t state);
36882 extern void pci_disable_enabled_device(struct pci_dev *dev);
36883 extern int pci_finish_runtime_suspend(struct pci_dev *dev);
36884 diff -urNp linux-2.6.39/drivers/pci/probe.c linux-2.6.39/drivers/pci/probe.c
36885 --- linux-2.6.39/drivers/pci/probe.c 2011-05-19 00:06:34.000000000 -0400
36886 +++ linux-2.6.39/drivers/pci/probe.c 2011-05-22 19:36:32.000000000 -0400
36887 @@ -62,14 +62,14 @@ static ssize_t pci_bus_show_cpuaffinity(
36888 return ret;
36889 }
36890
36891 -static ssize_t inline pci_bus_show_cpumaskaffinity(struct device *dev,
36892 +static inline ssize_t pci_bus_show_cpumaskaffinity(struct device *dev,
36893 struct device_attribute *attr,
36894 char *buf)
36895 {
36896 return pci_bus_show_cpuaffinity(dev, 0, attr, buf);
36897 }
36898
36899 -static ssize_t inline pci_bus_show_cpulistaffinity(struct device *dev,
36900 +static inline ssize_t pci_bus_show_cpulistaffinity(struct device *dev,
36901 struct device_attribute *attr,
36902 char *buf)
36903 {
36904 @@ -165,7 +165,7 @@ int __pci_read_base(struct pci_dev *dev,
36905 u32 l, sz, mask;
36906 u16 orig_cmd;
36907
36908 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
36909 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
36910
36911 if (!dev->mmio_always_on) {
36912 pci_read_config_word(dev, PCI_COMMAND, &orig_cmd);
36913 @@ -1407,7 +1407,7 @@ unsigned int __devinit pci_scan_child_bu
36914 }
36915
36916 struct pci_bus * pci_create_bus(struct device *parent,
36917 - int bus, struct pci_ops *ops, void *sysdata)
36918 + int bus, const struct pci_ops *ops, void *sysdata)
36919 {
36920 int error;
36921 struct pci_bus *b, *b2;
36922 @@ -1483,7 +1483,7 @@ err_out:
36923 }
36924
36925 struct pci_bus * __devinit pci_scan_bus_parented(struct device *parent,
36926 - int bus, struct pci_ops *ops, void *sysdata)
36927 + int bus, const struct pci_ops *ops, void *sysdata)
36928 {
36929 struct pci_bus *b;
36930
36931 diff -urNp linux-2.6.39/drivers/pci/proc.c linux-2.6.39/drivers/pci/proc.c
36932 --- linux-2.6.39/drivers/pci/proc.c 2011-05-19 00:06:34.000000000 -0400
36933 +++ linux-2.6.39/drivers/pci/proc.c 2011-05-22 19:41:37.000000000 -0400
36934 @@ -476,7 +476,16 @@ static const struct file_operations proc
36935 static int __init pci_proc_init(void)
36936 {
36937 struct pci_dev *dev = NULL;
36938 +
36939 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
36940 +#ifdef CONFIG_GRKERNSEC_PROC_USER
36941 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
36942 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
36943 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
36944 +#endif
36945 +#else
36946 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
36947 +#endif
36948 proc_create("devices", 0, proc_bus_pci_dir,
36949 &proc_bus_pci_dev_operations);
36950 proc_initialized = 1;
36951 diff -urNp linux-2.6.39/drivers/pci/xen-pcifront.c linux-2.6.39/drivers/pci/xen-pcifront.c
36952 --- linux-2.6.39/drivers/pci/xen-pcifront.c 2011-05-19 00:06:34.000000000 -0400
36953 +++ linux-2.6.39/drivers/pci/xen-pcifront.c 2011-05-22 19:36:32.000000000 -0400
36954 @@ -187,6 +187,8 @@ static int pcifront_bus_read(struct pci_
36955 struct pcifront_sd *sd = bus->sysdata;
36956 struct pcifront_device *pdev = pcifront_get_pdev(sd);
36957
36958 + pax_track_stack();
36959 +
36960 if (verbose_request)
36961 dev_info(&pdev->xdev->dev,
36962 "read dev=%04x:%02x:%02x.%01x - offset %x size %d\n",
36963 @@ -226,6 +228,8 @@ static int pcifront_bus_write(struct pci
36964 struct pcifront_sd *sd = bus->sysdata;
36965 struct pcifront_device *pdev = pcifront_get_pdev(sd);
36966
36967 + pax_track_stack();
36968 +
36969 if (verbose_request)
36970 dev_info(&pdev->xdev->dev,
36971 "write dev=%04x:%02x:%02x.%01x - "
36972 @@ -236,7 +240,7 @@ static int pcifront_bus_write(struct pci
36973 return errno_to_pcibios_err(do_pci_op(pdev, &op));
36974 }
36975
36976 -struct pci_ops pcifront_bus_ops = {
36977 +const struct pci_ops pcifront_bus_ops = {
36978 .read = pcifront_bus_read,
36979 .write = pcifront_bus_write,
36980 };
36981 @@ -258,6 +262,8 @@ static int pci_frontend_enable_msix(stru
36982 struct pcifront_device *pdev = pcifront_get_pdev(sd);
36983 struct msi_desc *entry;
36984
36985 + pax_track_stack();
36986 +
36987 if (nvec > SH_INFO_MAX_VEC) {
36988 dev_err(&dev->dev, "too much vector for pci frontend: %x."
36989 " Increase SH_INFO_MAX_VEC.\n", nvec);
36990 @@ -309,6 +315,8 @@ static void pci_frontend_disable_msix(st
36991 struct pcifront_sd *sd = dev->bus->sysdata;
36992 struct pcifront_device *pdev = pcifront_get_pdev(sd);
36993
36994 + pax_track_stack();
36995 +
36996 err = do_pci_op(pdev, &op);
36997
36998 /* What should do for error ? */
36999 @@ -328,6 +336,8 @@ static int pci_frontend_enable_msi(struc
37000 struct pcifront_sd *sd = dev->bus->sysdata;
37001 struct pcifront_device *pdev = pcifront_get_pdev(sd);
37002
37003 + pax_track_stack();
37004 +
37005 err = do_pci_op(pdev, &op);
37006 if (likely(!err)) {
37007 vector[0] = op.value;
37008 @@ -368,7 +378,7 @@ static void pci_frontend_disable_msi(str
37009 printk(KERN_DEBUG "get fake response frombackend\n");
37010 }
37011
37012 -static struct xen_pci_frontend_ops pci_frontend_ops = {
37013 +static const struct xen_pci_frontend_ops pci_frontend_ops = {
37014 .enable_msi = pci_frontend_enable_msi,
37015 .disable_msi = pci_frontend_disable_msi,
37016 .enable_msix = pci_frontend_enable_msix,
37017 diff -urNp linux-2.6.39/drivers/pcmcia/at91_cf.c linux-2.6.39/drivers/pcmcia/at91_cf.c
37018 --- linux-2.6.39/drivers/pcmcia/at91_cf.c 2011-05-19 00:06:34.000000000 -0400
37019 +++ linux-2.6.39/drivers/pcmcia/at91_cf.c 2011-05-22 19:36:32.000000000 -0400
37020 @@ -203,7 +203,7 @@ at91_cf_set_mem_map(struct pcmcia_socket
37021 return 0;
37022 }
37023
37024 -static struct pccard_operations at91_cf_ops = {
37025 +static const struct pccard_operations at91_cf_ops = {
37026 .init = at91_cf_ss_init,
37027 .suspend = at91_cf_ss_suspend,
37028 .get_status = at91_cf_get_status,
37029 diff -urNp linux-2.6.39/drivers/pcmcia/bfin_cf_pcmcia.c linux-2.6.39/drivers/pcmcia/bfin_cf_pcmcia.c
37030 --- linux-2.6.39/drivers/pcmcia/bfin_cf_pcmcia.c 2011-05-19 00:06:34.000000000 -0400
37031 +++ linux-2.6.39/drivers/pcmcia/bfin_cf_pcmcia.c 2011-05-22 19:36:32.000000000 -0400
37032 @@ -184,7 +184,7 @@ bfin_cf_set_mem_map(struct pcmcia_socket
37033 return 0;
37034 }
37035
37036 -static struct pccard_operations bfin_cf_ops = {
37037 +static const struct pccard_operations bfin_cf_ops = {
37038 .init = bfin_cf_ss_init,
37039 .suspend = bfin_cf_ss_suspend,
37040 .get_status = bfin_cf_get_status,
37041 diff -urNp linux-2.6.39/drivers/pcmcia/db1xxx_ss.c linux-2.6.39/drivers/pcmcia/db1xxx_ss.c
37042 --- linux-2.6.39/drivers/pcmcia/db1xxx_ss.c 2011-05-19 00:06:34.000000000 -0400
37043 +++ linux-2.6.39/drivers/pcmcia/db1xxx_ss.c 2011-05-22 19:36:32.000000000 -0400
37044 @@ -384,7 +384,7 @@ static int au1x00_pcmcia_set_mem_map(str
37045 return 0;
37046 }
37047
37048 -static struct pccard_operations db1x_pcmcia_operations = {
37049 +static const struct pccard_operations db1x_pcmcia_operations = {
37050 .init = db1x_pcmcia_sock_init,
37051 .suspend = db1x_pcmcia_sock_suspend,
37052 .get_status = db1x_pcmcia_get_status,
37053 diff -urNp linux-2.6.39/drivers/pcmcia/electra_cf.c linux-2.6.39/drivers/pcmcia/electra_cf.c
37054 --- linux-2.6.39/drivers/pcmcia/electra_cf.c 2011-05-19 00:06:34.000000000 -0400
37055 +++ linux-2.6.39/drivers/pcmcia/electra_cf.c 2011-05-22 19:36:32.000000000 -0400
37056 @@ -173,7 +173,7 @@ static int electra_cf_set_mem_map(struct
37057 return 0;
37058 }
37059
37060 -static struct pccard_operations electra_cf_ops = {
37061 +static const struct pccard_operations electra_cf_ops = {
37062 .init = electra_cf_ss_init,
37063 .get_status = electra_cf_get_status,
37064 .set_socket = electra_cf_set_socket,
37065 diff -urNp linux-2.6.39/drivers/pcmcia/m32r_cfc.c linux-2.6.39/drivers/pcmcia/m32r_cfc.c
37066 --- linux-2.6.39/drivers/pcmcia/m32r_cfc.c 2011-05-19 00:06:34.000000000 -0400
37067 +++ linux-2.6.39/drivers/pcmcia/m32r_cfc.c 2011-05-22 19:36:32.000000000 -0400
37068 @@ -674,7 +674,7 @@ static int pcc_init(struct pcmcia_socket
37069 return 0;
37070 }
37071
37072 -static struct pccard_operations pcc_operations = {
37073 +static const struct pccard_operations pcc_operations = {
37074 .init = pcc_init,
37075 .get_status = pcc_get_status,
37076 .set_socket = pcc_set_socket,
37077 diff -urNp linux-2.6.39/drivers/pcmcia/m32r_pcc.c linux-2.6.39/drivers/pcmcia/m32r_pcc.c
37078 --- linux-2.6.39/drivers/pcmcia/m32r_pcc.c 2011-05-19 00:06:34.000000000 -0400
37079 +++ linux-2.6.39/drivers/pcmcia/m32r_pcc.c 2011-05-22 19:36:32.000000000 -0400
37080 @@ -652,7 +652,7 @@ static int pcc_init(struct pcmcia_socket
37081 return 0;
37082 }
37083
37084 -static struct pccard_operations pcc_operations = {
37085 +static const struct pccard_operations pcc_operations = {
37086 .init = pcc_init,
37087 .get_status = pcc_get_status,
37088 .set_socket = pcc_set_socket,
37089 diff -urNp linux-2.6.39/drivers/pcmcia/m8xx_pcmcia.c linux-2.6.39/drivers/pcmcia/m8xx_pcmcia.c
37090 --- linux-2.6.39/drivers/pcmcia/m8xx_pcmcia.c 2011-05-19 00:06:34.000000000 -0400
37091 +++ linux-2.6.39/drivers/pcmcia/m8xx_pcmcia.c 2011-05-22 19:36:32.000000000 -0400
37092 @@ -1139,7 +1139,7 @@ static int m8xx_sock_suspend(struct pcmc
37093 return m8xx_set_socket(sock, &dead_socket);
37094 }
37095
37096 -static struct pccard_operations m8xx_services = {
37097 +static const struct pccard_operations m8xx_services = {
37098 .init = m8xx_sock_init,
37099 .suspend = m8xx_sock_suspend,
37100 .get_status = m8xx_get_status,
37101 diff -urNp linux-2.6.39/drivers/pcmcia/omap_cf.c linux-2.6.39/drivers/pcmcia/omap_cf.c
37102 --- linux-2.6.39/drivers/pcmcia/omap_cf.c 2011-05-19 00:06:34.000000000 -0400
37103 +++ linux-2.6.39/drivers/pcmcia/omap_cf.c 2011-05-22 19:36:32.000000000 -0400
37104 @@ -185,7 +185,7 @@ omap_cf_set_mem_map(struct pcmcia_socket
37105 return 0;
37106 }
37107
37108 -static struct pccard_operations omap_cf_ops = {
37109 +static const struct pccard_operations omap_cf_ops = {
37110 .init = omap_cf_ss_init,
37111 .suspend = omap_cf_ss_suspend,
37112 .get_status = omap_cf_get_status,
37113 diff -urNp linux-2.6.39/drivers/pcmcia/rsrc_iodyn.c linux-2.6.39/drivers/pcmcia/rsrc_iodyn.c
37114 --- linux-2.6.39/drivers/pcmcia/rsrc_iodyn.c 2011-05-19 00:06:34.000000000 -0400
37115 +++ linux-2.6.39/drivers/pcmcia/rsrc_iodyn.c 2011-05-22 19:36:32.000000000 -0400
37116 @@ -161,7 +161,7 @@ static int iodyn_find_io(struct pcmcia_s
37117 }
37118
37119
37120 -struct pccard_resource_ops pccard_iodyn_ops = {
37121 +const struct pccard_resource_ops pccard_iodyn_ops = {
37122 .validate_mem = NULL,
37123 .find_io = iodyn_find_io,
37124 .find_mem = NULL,
37125 diff -urNp linux-2.6.39/drivers/pcmcia/rsrc_mgr.c linux-2.6.39/drivers/pcmcia/rsrc_mgr.c
37126 --- linux-2.6.39/drivers/pcmcia/rsrc_mgr.c 2011-05-19 00:06:34.000000000 -0400
37127 +++ linux-2.6.39/drivers/pcmcia/rsrc_mgr.c 2011-05-22 19:36:32.000000000 -0400
37128 @@ -57,7 +57,7 @@ static int static_find_io(struct pcmcia_
37129 }
37130
37131
37132 -struct pccard_resource_ops pccard_static_ops = {
37133 +const struct pccard_resource_ops pccard_static_ops = {
37134 .validate_mem = NULL,
37135 .find_io = static_find_io,
37136 .find_mem = NULL,
37137 diff -urNp linux-2.6.39/drivers/pcmcia/vrc4171_card.c linux-2.6.39/drivers/pcmcia/vrc4171_card.c
37138 --- linux-2.6.39/drivers/pcmcia/vrc4171_card.c 2011-05-19 00:06:34.000000000 -0400
37139 +++ linux-2.6.39/drivers/pcmcia/vrc4171_card.c 2011-05-22 19:36:32.000000000 -0400
37140 @@ -479,7 +479,7 @@ static int pccard_set_mem_map(struct pcm
37141 return 0;
37142 }
37143
37144 -static struct pccard_operations vrc4171_pccard_operations = {
37145 +static const struct pccard_operations vrc4171_pccard_operations = {
37146 .init = pccard_init,
37147 .get_status = pccard_get_status,
37148 .set_socket = pccard_set_socket,
37149 diff -urNp linux-2.6.39/drivers/pcmcia/vrc4173_cardu.c linux-2.6.39/drivers/pcmcia/vrc4173_cardu.c
37150 --- linux-2.6.39/drivers/pcmcia/vrc4173_cardu.c 2011-05-19 00:06:34.000000000 -0400
37151 +++ linux-2.6.39/drivers/pcmcia/vrc4173_cardu.c 2011-05-22 19:36:32.000000000 -0400
37152 @@ -384,7 +384,7 @@ static void cardu_proc_setup(unsigned in
37153 {
37154 }
37155
37156 -static struct pccard_operations cardu_operations = {
37157 +static const struct pccard_operations cardu_operations = {
37158 .init = cardu_init,
37159 .register_callback = cardu_register_callback,
37160 .inquire_socket = cardu_inquire_socket,
37161 diff -urNp linux-2.6.39/drivers/pcmcia/xxs1500_ss.c linux-2.6.39/drivers/pcmcia/xxs1500_ss.c
37162 --- linux-2.6.39/drivers/pcmcia/xxs1500_ss.c 2011-05-19 00:06:34.000000000 -0400
37163 +++ linux-2.6.39/drivers/pcmcia/xxs1500_ss.c 2011-05-22 19:36:32.000000000 -0400
37164 @@ -196,7 +196,7 @@ static int au1x00_pcmcia_set_mem_map(str
37165 return 0;
37166 }
37167
37168 -static struct pccard_operations xxs1500_pcmcia_operations = {
37169 +static const struct pccard_operations xxs1500_pcmcia_operations = {
37170 .init = xxs1500_pcmcia_sock_init,
37171 .suspend = xxs1500_pcmcia_sock_suspend,
37172 .get_status = xxs1500_pcmcia_get_status,
37173 diff -urNp linux-2.6.39/drivers/platform/x86/acerhdf.c linux-2.6.39/drivers/platform/x86/acerhdf.c
37174 --- linux-2.6.39/drivers/platform/x86/acerhdf.c 2011-05-19 00:06:34.000000000 -0400
37175 +++ linux-2.6.39/drivers/platform/x86/acerhdf.c 2011-05-22 19:36:32.000000000 -0400
37176 @@ -406,7 +406,7 @@ static int acerhdf_get_crit_temp(struct
37177 }
37178
37179 /* bind callback functions to thermalzone */
37180 -static struct thermal_zone_device_ops acerhdf_dev_ops = {
37181 +static const struct thermal_zone_device_ops acerhdf_dev_ops = {
37182 .bind = acerhdf_bind,
37183 .unbind = acerhdf_unbind,
37184 .get_temp = acerhdf_get_ec_temp,
37185 @@ -481,7 +481,7 @@ err_out:
37186 }
37187
37188 /* bind fan callbacks to fan device */
37189 -static struct thermal_cooling_device_ops acerhdf_cooling_ops = {
37190 +static const struct thermal_cooling_device_ops acerhdf_cooling_ops = {
37191 .get_max_state = acerhdf_get_max_state,
37192 .get_cur_state = acerhdf_get_cur_state,
37193 .set_cur_state = acerhdf_set_cur_state,
37194 diff -urNp linux-2.6.39/drivers/platform/x86/ideapad-laptop.c linux-2.6.39/drivers/platform/x86/ideapad-laptop.c
37195 --- linux-2.6.39/drivers/platform/x86/ideapad-laptop.c 2011-05-19 00:06:34.000000000 -0400
37196 +++ linux-2.6.39/drivers/platform/x86/ideapad-laptop.c 2011-05-22 19:36:32.000000000 -0400
37197 @@ -207,7 +207,7 @@ static int ideapad_rfk_set(void *data, b
37198 return write_ec_cmd(ideapad_handle, opcode, !blocked);
37199 }
37200
37201 -static struct rfkill_ops ideapad_rfk_ops = {
37202 +static const struct rfkill_ops ideapad_rfk_ops = {
37203 .set_block = ideapad_rfk_set,
37204 };
37205
37206 diff -urNp linux-2.6.39/drivers/platform/x86/intel_menlow.c linux-2.6.39/drivers/platform/x86/intel_menlow.c
37207 --- linux-2.6.39/drivers/platform/x86/intel_menlow.c 2011-05-19 00:06:34.000000000 -0400
37208 +++ linux-2.6.39/drivers/platform/x86/intel_menlow.c 2011-05-22 19:36:32.000000000 -0400
37209 @@ -143,7 +143,7 @@ static int memory_set_cur_bandwidth(stru
37210 return 0;
37211 }
37212
37213 -static struct thermal_cooling_device_ops memory_cooling_ops = {
37214 +static const struct thermal_cooling_device_ops memory_cooling_ops = {
37215 .get_max_state = memory_get_max_bandwidth,
37216 .get_cur_state = memory_get_cur_bandwidth,
37217 .set_cur_state = memory_set_cur_bandwidth,
37218 diff -urNp linux-2.6.39/drivers/platform/x86/intel_mid_thermal.c linux-2.6.39/drivers/platform/x86/intel_mid_thermal.c
37219 --- linux-2.6.39/drivers/platform/x86/intel_mid_thermal.c 2011-05-19 00:06:34.000000000 -0400
37220 +++ linux-2.6.39/drivers/platform/x86/intel_mid_thermal.c 2011-05-22 19:36:32.000000000 -0400
37221 @@ -458,7 +458,7 @@ static int read_curr_temp(struct thermal
37222 }
37223
37224 /* Can't be const */
37225 -static struct thermal_zone_device_ops tzd_ops = {
37226 +static const struct thermal_zone_device_ops tzd_ops = {
37227 .get_temp = read_curr_temp,
37228 };
37229
37230 diff -urNp linux-2.6.39/drivers/platform/x86/samsung-laptop.c linux-2.6.39/drivers/platform/x86/samsung-laptop.c
37231 --- linux-2.6.39/drivers/platform/x86/samsung-laptop.c 2011-05-19 00:06:34.000000000 -0400
37232 +++ linux-2.6.39/drivers/platform/x86/samsung-laptop.c 2011-05-22 19:36:32.000000000 -0400
37233 @@ -419,7 +419,7 @@ static int rfkill_set(void *data, bool b
37234 return 0;
37235 }
37236
37237 -static struct rfkill_ops rfkill_ops = {
37238 +static const struct rfkill_ops rfkill_ops = {
37239 .set_block = rfkill_set,
37240 };
37241
37242 diff -urNp linux-2.6.39/drivers/pnp/pnpbios/bioscalls.c linux-2.6.39/drivers/pnp/pnpbios/bioscalls.c
37243 --- linux-2.6.39/drivers/pnp/pnpbios/bioscalls.c 2011-05-19 00:06:34.000000000 -0400
37244 +++ linux-2.6.39/drivers/pnp/pnpbios/bioscalls.c 2011-05-22 19:36:32.000000000 -0400
37245 @@ -59,7 +59,7 @@ do { \
37246 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
37247 } while(0)
37248
37249 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
37250 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
37251 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
37252
37253 /*
37254 @@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func
37255
37256 cpu = get_cpu();
37257 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
37258 +
37259 + pax_open_kernel();
37260 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
37261 + pax_close_kernel();
37262
37263 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
37264 spin_lock_irqsave(&pnp_bios_lock, flags);
37265 @@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func
37266 :"memory");
37267 spin_unlock_irqrestore(&pnp_bios_lock, flags);
37268
37269 + pax_open_kernel();
37270 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
37271 + pax_close_kernel();
37272 +
37273 put_cpu();
37274
37275 /* If we get here and this is set then the PnP BIOS faulted on us. */
37276 @@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 n
37277 return status;
37278 }
37279
37280 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
37281 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
37282 {
37283 int i;
37284
37285 @@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_i
37286 pnp_bios_callpoint.offset = header->fields.pm16offset;
37287 pnp_bios_callpoint.segment = PNP_CS16;
37288
37289 + pax_open_kernel();
37290 +
37291 for_each_possible_cpu(i) {
37292 struct desc_struct *gdt = get_cpu_gdt_table(i);
37293 if (!gdt)
37294 @@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_i
37295 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
37296 (unsigned long)__va(header->fields.pm16dseg));
37297 }
37298 +
37299 + pax_close_kernel();
37300 }
37301 diff -urNp linux-2.6.39/drivers/pnp/resource.c linux-2.6.39/drivers/pnp/resource.c
37302 --- linux-2.6.39/drivers/pnp/resource.c 2011-05-19 00:06:34.000000000 -0400
37303 +++ linux-2.6.39/drivers/pnp/resource.c 2011-05-22 19:36:32.000000000 -0400
37304 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, s
37305 return 1;
37306
37307 /* check if the resource is valid */
37308 - if (*irq < 0 || *irq > 15)
37309 + if (*irq > 15)
37310 return 0;
37311
37312 /* check if the resource is reserved */
37313 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, s
37314 return 1;
37315
37316 /* check if the resource is valid */
37317 - if (*dma < 0 || *dma == 4 || *dma > 7)
37318 + if (*dma == 4 || *dma > 7)
37319 return 0;
37320
37321 /* check if the resource is reserved */
37322 diff -urNp linux-2.6.39/drivers/power/max8925_power.c linux-2.6.39/drivers/power/max8925_power.c
37323 --- linux-2.6.39/drivers/power/max8925_power.c 2011-05-19 00:06:34.000000000 -0400
37324 +++ linux-2.6.39/drivers/power/max8925_power.c 2011-05-22 19:36:32.000000000 -0400
37325 @@ -426,7 +426,7 @@ static __devinit int max8925_power_probe
37326 {
37327 struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent);
37328 struct max8925_platform_data *max8925_pdata;
37329 - struct max8925_power_pdata *pdata = NULL;
37330 + const struct max8925_power_pdata *pdata = NULL;
37331 struct max8925_power_info *info;
37332 int ret;
37333
37334 diff -urNp linux-2.6.39/drivers/regulator/core.c linux-2.6.39/drivers/regulator/core.c
37335 --- linux-2.6.39/drivers/regulator/core.c 2011-05-19 00:06:34.000000000 -0400
37336 +++ linux-2.6.39/drivers/regulator/core.c 2011-05-22 19:36:32.000000000 -0400
37337 @@ -2883,7 +2883,7 @@ core_initcall(regulator_init);
37338 static int __init regulator_init_complete(void)
37339 {
37340 struct regulator_dev *rdev;
37341 - struct regulator_ops *ops;
37342 + const struct regulator_ops *ops;
37343 struct regulation_constraints *c;
37344 int enabled, ret;
37345
37346 diff -urNp linux-2.6.39/drivers/rtc/rtc-at32ap700x.c linux-2.6.39/drivers/rtc/rtc-at32ap700x.c
37347 --- linux-2.6.39/drivers/rtc/rtc-at32ap700x.c 2011-05-19 00:06:34.000000000 -0400
37348 +++ linux-2.6.39/drivers/rtc/rtc-at32ap700x.c 2011-05-22 19:36:32.000000000 -0400
37349 @@ -187,7 +187,7 @@ static irqreturn_t at32_rtc_interrupt(in
37350 return ret;
37351 }
37352
37353 -static struct rtc_class_ops at32_rtc_ops = {
37354 +static const struct rtc_class_ops at32_rtc_ops = {
37355 .read_time = at32_rtc_readtime,
37356 .set_time = at32_rtc_settime,
37357 .read_alarm = at32_rtc_readalarm,
37358 diff -urNp linux-2.6.39/drivers/rtc/rtc-au1xxx.c linux-2.6.39/drivers/rtc/rtc-au1xxx.c
37359 --- linux-2.6.39/drivers/rtc/rtc-au1xxx.c 2011-05-19 00:06:34.000000000 -0400
37360 +++ linux-2.6.39/drivers/rtc/rtc-au1xxx.c 2011-05-22 19:36:32.000000000 -0400
37361 @@ -57,7 +57,7 @@ static int au1xtoy_rtc_set_time(struct d
37362 return 0;
37363 }
37364
37365 -static struct rtc_class_ops au1xtoy_rtc_ops = {
37366 +static const struct rtc_class_ops au1xtoy_rtc_ops = {
37367 .read_time = au1xtoy_rtc_read_time,
37368 .set_time = au1xtoy_rtc_set_time,
37369 };
37370 diff -urNp linux-2.6.39/drivers/rtc/rtc-bfin.c linux-2.6.39/drivers/rtc/rtc-bfin.c
37371 --- linux-2.6.39/drivers/rtc/rtc-bfin.c 2011-05-19 00:06:34.000000000 -0400
37372 +++ linux-2.6.39/drivers/rtc/rtc-bfin.c 2011-05-22 19:36:32.000000000 -0400
37373 @@ -333,7 +333,7 @@ static int bfin_rtc_proc(struct device *
37374 #undef yesno
37375 }
37376
37377 -static struct rtc_class_ops bfin_rtc_ops = {
37378 +static const struct rtc_class_ops bfin_rtc_ops = {
37379 .read_time = bfin_rtc_read_time,
37380 .set_time = bfin_rtc_set_time,
37381 .read_alarm = bfin_rtc_read_alarm,
37382 diff -urNp linux-2.6.39/drivers/rtc/rtc-coh901331.c linux-2.6.39/drivers/rtc/rtc-coh901331.c
37383 --- linux-2.6.39/drivers/rtc/rtc-coh901331.c 2011-05-19 00:06:34.000000000 -0400
37384 +++ linux-2.6.39/drivers/rtc/rtc-coh901331.c 2011-05-22 19:36:32.000000000 -0400
37385 @@ -142,7 +142,7 @@ static int coh901331_alarm_irq_enable(st
37386 return 0;
37387 }
37388
37389 -static struct rtc_class_ops coh901331_ops = {
37390 +static const struct rtc_class_ops coh901331_ops = {
37391 .read_time = coh901331_read_time,
37392 .set_mmss = coh901331_set_mmss,
37393 .read_alarm = coh901331_read_alarm,
37394 diff -urNp linux-2.6.39/drivers/rtc/rtc-davinci.c linux-2.6.39/drivers/rtc/rtc-davinci.c
37395 --- linux-2.6.39/drivers/rtc/rtc-davinci.c 2011-05-19 00:06:34.000000000 -0400
37396 +++ linux-2.6.39/drivers/rtc/rtc-davinci.c 2011-05-22 19:36:32.000000000 -0400
37397 @@ -469,7 +469,7 @@ static int davinci_rtc_set_alarm(struct
37398 return 0;
37399 }
37400
37401 -static struct rtc_class_ops davinci_rtc_ops = {
37402 +static const struct rtc_class_ops davinci_rtc_ops = {
37403 .ioctl = davinci_rtc_ioctl,
37404 .read_time = davinci_rtc_read_time,
37405 .set_time = davinci_rtc_set_time,
37406 diff -urNp linux-2.6.39/drivers/rtc/rtc-dev.c linux-2.6.39/drivers/rtc/rtc-dev.c
37407 --- linux-2.6.39/drivers/rtc/rtc-dev.c 2011-05-19 00:06:34.000000000 -0400
37408 +++ linux-2.6.39/drivers/rtc/rtc-dev.c 2011-05-22 19:41:37.000000000 -0400
37409 @@ -14,6 +14,7 @@
37410 #include <linux/module.h>
37411 #include <linux/rtc.h>
37412 #include <linux/sched.h>
37413 +#include <linux/grsecurity.h>
37414 #include "rtc-core.h"
37415
37416 static dev_t rtc_devt;
37417 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *f
37418 if (copy_from_user(&tm, uarg, sizeof(tm)))
37419 return -EFAULT;
37420
37421 + gr_log_timechange();
37422 +
37423 return rtc_set_time(rtc, &tm);
37424
37425 case RTC_PIE_ON:
37426 diff -urNp linux-2.6.39/drivers/rtc/rtc-dm355evm.c linux-2.6.39/drivers/rtc/rtc-dm355evm.c
37427 --- linux-2.6.39/drivers/rtc/rtc-dm355evm.c 2011-05-19 00:06:34.000000000 -0400
37428 +++ linux-2.6.39/drivers/rtc/rtc-dm355evm.c 2011-05-22 19:36:32.000000000 -0400
37429 @@ -115,7 +115,7 @@ static int dm355evm_rtc_set_time(struct
37430 return 0;
37431 }
37432
37433 -static struct rtc_class_ops dm355evm_rtc_ops = {
37434 +static const struct rtc_class_ops dm355evm_rtc_ops = {
37435 .read_time = dm355evm_rtc_read_time,
37436 .set_time = dm355evm_rtc_set_time,
37437 };
37438 diff -urNp linux-2.6.39/drivers/rtc/rtc-ds1302.c linux-2.6.39/drivers/rtc/rtc-ds1302.c
37439 --- linux-2.6.39/drivers/rtc/rtc-ds1302.c 2011-05-19 00:06:34.000000000 -0400
37440 +++ linux-2.6.39/drivers/rtc/rtc-ds1302.c 2011-05-22 19:36:32.000000000 -0400
37441 @@ -199,7 +199,7 @@ static int ds1302_rtc_ioctl(struct devic
37442 return -ENOIOCTLCMD;
37443 }
37444
37445 -static struct rtc_class_ops ds1302_rtc_ops = {
37446 +static const struct rtc_class_ops ds1302_rtc_ops = {
37447 .read_time = ds1302_rtc_read_time,
37448 .set_time = ds1302_rtc_set_time,
37449 .ioctl = ds1302_rtc_ioctl,
37450 diff -urNp linux-2.6.39/drivers/rtc/rtc-imxdi.c linux-2.6.39/drivers/rtc/rtc-imxdi.c
37451 --- linux-2.6.39/drivers/rtc/rtc-imxdi.c 2011-05-19 00:06:34.000000000 -0400
37452 +++ linux-2.6.39/drivers/rtc/rtc-imxdi.c 2011-05-22 19:36:32.000000000 -0400
37453 @@ -290,7 +290,7 @@ static int dryice_rtc_set_alarm(struct d
37454 return 0;
37455 }
37456
37457 -static struct rtc_class_ops dryice_rtc_ops = {
37458 +static const struct rtc_class_ops dryice_rtc_ops = {
37459 .read_time = dryice_rtc_read_time,
37460 .set_mmss = dryice_rtc_set_mmss,
37461 .alarm_irq_enable = dryice_rtc_alarm_irq_enable,
37462 diff -urNp linux-2.6.39/drivers/rtc/rtc-jz4740.c linux-2.6.39/drivers/rtc/rtc-jz4740.c
37463 --- linux-2.6.39/drivers/rtc/rtc-jz4740.c 2011-05-19 00:06:34.000000000 -0400
37464 +++ linux-2.6.39/drivers/rtc/rtc-jz4740.c 2011-05-22 19:36:32.000000000 -0400
37465 @@ -174,7 +174,7 @@ static int jz4740_rtc_alarm_irq_enable(s
37466 return jz4740_rtc_ctrl_set_bits(rtc, JZ_RTC_CTRL_AF_IRQ, enable);
37467 }
37468
37469 -static struct rtc_class_ops jz4740_rtc_ops = {
37470 +static const struct rtc_class_ops jz4740_rtc_ops = {
37471 .read_time = jz4740_rtc_read_time,
37472 .set_mmss = jz4740_rtc_set_mmss,
37473 .read_alarm = jz4740_rtc_read_alarm,
37474 diff -urNp linux-2.6.39/drivers/rtc/rtc-m41t80.c linux-2.6.39/drivers/rtc/rtc-m41t80.c
37475 --- linux-2.6.39/drivers/rtc/rtc-m41t80.c 2011-05-19 00:06:34.000000000 -0400
37476 +++ linux-2.6.39/drivers/rtc/rtc-m41t80.c 2011-05-22 19:36:32.000000000 -0400
37477 @@ -354,7 +354,7 @@ static int m41t80_rtc_read_alarm(struct
37478 return 0;
37479 }
37480
37481 -static struct rtc_class_ops m41t80_rtc_ops = {
37482 +static const struct rtc_class_ops m41t80_rtc_ops = {
37483 .read_time = m41t80_rtc_read_time,
37484 .set_time = m41t80_rtc_set_time,
37485 .read_alarm = m41t80_rtc_read_alarm,
37486 diff -urNp linux-2.6.39/drivers/rtc/rtc-mxc.c linux-2.6.39/drivers/rtc/rtc-mxc.c
37487 --- linux-2.6.39/drivers/rtc/rtc-mxc.c 2011-05-19 00:06:34.000000000 -0400
37488 +++ linux-2.6.39/drivers/rtc/rtc-mxc.c 2011-05-22 19:36:32.000000000 -0400
37489 @@ -355,7 +355,7 @@ static int mxc_rtc_set_alarm(struct devi
37490 }
37491
37492 /* RTC layer */
37493 -static struct rtc_class_ops mxc_rtc_ops = {
37494 +static const struct rtc_class_ops mxc_rtc_ops = {
37495 .release = mxc_rtc_release,
37496 .read_time = mxc_rtc_read_time,
37497 .set_mmss = mxc_rtc_set_mmss,
37498 diff -urNp linux-2.6.39/drivers/rtc/rtc-nuc900.c linux-2.6.39/drivers/rtc/rtc-nuc900.c
37499 --- linux-2.6.39/drivers/rtc/rtc-nuc900.c 2011-05-19 00:06:34.000000000 -0400
37500 +++ linux-2.6.39/drivers/rtc/rtc-nuc900.c 2011-05-22 19:36:32.000000000 -0400
37501 @@ -214,7 +214,7 @@ static int nuc900_rtc_set_alarm(struct d
37502 return 0;
37503 }
37504
37505 -static struct rtc_class_ops nuc900_rtc_ops = {
37506 +static const struct rtc_class_ops nuc900_rtc_ops = {
37507 .read_time = nuc900_rtc_read_time,
37508 .set_time = nuc900_rtc_set_time,
37509 .read_alarm = nuc900_rtc_read_alarm,
37510 diff -urNp linux-2.6.39/drivers/rtc/rtc-omap.c linux-2.6.39/drivers/rtc/rtc-omap.c
37511 --- linux-2.6.39/drivers/rtc/rtc-omap.c 2011-05-19 00:06:34.000000000 -0400
37512 +++ linux-2.6.39/drivers/rtc/rtc-omap.c 2011-05-22 19:36:32.000000000 -0400
37513 @@ -274,7 +274,7 @@ static int omap_rtc_set_alarm(struct dev
37514 return 0;
37515 }
37516
37517 -static struct rtc_class_ops omap_rtc_ops = {
37518 +static const struct rtc_class_ops omap_rtc_ops = {
37519 .read_time = omap_rtc_read_time,
37520 .set_time = omap_rtc_set_time,
37521 .read_alarm = omap_rtc_read_alarm,
37522 diff -urNp linux-2.6.39/drivers/rtc/rtc-pcf50633.c linux-2.6.39/drivers/rtc/rtc-pcf50633.c
37523 --- linux-2.6.39/drivers/rtc/rtc-pcf50633.c 2011-05-19 00:06:34.000000000 -0400
37524 +++ linux-2.6.39/drivers/rtc/rtc-pcf50633.c 2011-05-22 19:36:32.000000000 -0400
37525 @@ -238,7 +238,7 @@ static int pcf50633_rtc_set_alarm(struct
37526 return ret;
37527 }
37528
37529 -static struct rtc_class_ops pcf50633_rtc_ops = {
37530 +static const struct rtc_class_ops pcf50633_rtc_ops = {
37531 .read_time = pcf50633_rtc_read_time,
37532 .set_time = pcf50633_rtc_set_time,
37533 .read_alarm = pcf50633_rtc_read_alarm,
37534 diff -urNp linux-2.6.39/drivers/rtc/rtc-pl031.c linux-2.6.39/drivers/rtc/rtc-pl031.c
37535 --- linux-2.6.39/drivers/rtc/rtc-pl031.c 2011-05-19 00:06:34.000000000 -0400
37536 +++ linux-2.6.39/drivers/rtc/rtc-pl031.c 2011-05-22 19:36:32.000000000 -0400
37537 @@ -374,7 +374,7 @@ err_req:
37538 }
37539
37540 /* Operations for the original ARM version */
37541 -static struct rtc_class_ops arm_pl031_ops = {
37542 +static const struct rtc_class_ops arm_pl031_ops = {
37543 .read_time = pl031_read_time,
37544 .set_time = pl031_set_time,
37545 .read_alarm = pl031_read_alarm,
37546 @@ -383,7 +383,7 @@ static struct rtc_class_ops arm_pl031_op
37547 };
37548
37549 /* The First ST derivative */
37550 -static struct rtc_class_ops stv1_pl031_ops = {
37551 +static const struct rtc_class_ops stv1_pl031_ops = {
37552 .read_time = pl031_read_time,
37553 .set_time = pl031_set_time,
37554 .read_alarm = pl031_read_alarm,
37555 @@ -392,7 +392,7 @@ static struct rtc_class_ops stv1_pl031_o
37556 };
37557
37558 /* And the second ST derivative */
37559 -static struct rtc_class_ops stv2_pl031_ops = {
37560 +static const struct rtc_class_ops stv2_pl031_ops = {
37561 .read_time = pl031_stv2_read_time,
37562 .set_time = pl031_stv2_set_time,
37563 .read_alarm = pl031_stv2_read_alarm,
37564 diff -urNp linux-2.6.39/drivers/rtc/rtc-rx8025.c linux-2.6.39/drivers/rtc/rtc-rx8025.c
37565 --- linux-2.6.39/drivers/rtc/rtc-rx8025.c 2011-05-19 00:06:34.000000000 -0400
37566 +++ linux-2.6.39/drivers/rtc/rtc-rx8025.c 2011-05-22 19:36:32.000000000 -0400
37567 @@ -424,7 +424,7 @@ static int rx8025_alarm_irq_enable(struc
37568 return 0;
37569 }
37570
37571 -static struct rtc_class_ops rx8025_rtc_ops = {
37572 +static const struct rtc_class_ops rx8025_rtc_ops = {
37573 .read_time = rx8025_get_time,
37574 .set_time = rx8025_set_time,
37575 .read_alarm = rx8025_read_alarm,
37576 diff -urNp linux-2.6.39/drivers/rtc/rtc-sh.c linux-2.6.39/drivers/rtc/rtc-sh.c
37577 --- linux-2.6.39/drivers/rtc/rtc-sh.c 2011-05-19 00:06:34.000000000 -0400
37578 +++ linux-2.6.39/drivers/rtc/rtc-sh.c 2011-05-22 19:36:32.000000000 -0400
37579 @@ -576,7 +576,7 @@ static int sh_rtc_set_alarm(struct devic
37580 return 0;
37581 }
37582
37583 -static struct rtc_class_ops sh_rtc_ops = {
37584 +static const struct rtc_class_ops sh_rtc_ops = {
37585 .read_time = sh_rtc_read_time,
37586 .set_time = sh_rtc_set_time,
37587 .read_alarm = sh_rtc_read_alarm,
37588 diff -urNp linux-2.6.39/drivers/rtc/rtc-stmp3xxx.c linux-2.6.39/drivers/rtc/rtc-stmp3xxx.c
37589 --- linux-2.6.39/drivers/rtc/rtc-stmp3xxx.c 2011-05-19 00:06:34.000000000 -0400
37590 +++ linux-2.6.39/drivers/rtc/rtc-stmp3xxx.c 2011-05-22 19:36:32.000000000 -0400
37591 @@ -133,7 +133,7 @@ static int stmp3xxx_rtc_set_alarm(struct
37592 return 0;
37593 }
37594
37595 -static struct rtc_class_ops stmp3xxx_rtc_ops = {
37596 +static const struct rtc_class_ops stmp3xxx_rtc_ops = {
37597 .alarm_irq_enable =
37598 stmp3xxx_alarm_irq_enable,
37599 .read_time = stmp3xxx_rtc_gettime,
37600 diff -urNp linux-2.6.39/drivers/rtc/rtc-tegra.c linux-2.6.39/drivers/rtc/rtc-tegra.c
37601 --- linux-2.6.39/drivers/rtc/rtc-tegra.c 2011-05-19 00:06:34.000000000 -0400
37602 +++ linux-2.6.39/drivers/rtc/rtc-tegra.c 2011-05-22 19:36:32.000000000 -0400
37603 @@ -294,7 +294,7 @@ static irqreturn_t tegra_rtc_irq_handler
37604 return IRQ_HANDLED;
37605 }
37606
37607 -static struct rtc_class_ops tegra_rtc_ops = {
37608 +static const struct rtc_class_ops tegra_rtc_ops = {
37609 .read_time = tegra_rtc_read_time,
37610 .set_time = tegra_rtc_set_time,
37611 .read_alarm = tegra_rtc_read_alarm,
37612 diff -urNp linux-2.6.39/drivers/rtc/rtc-twl.c linux-2.6.39/drivers/rtc/rtc-twl.c
37613 --- linux-2.6.39/drivers/rtc/rtc-twl.c 2011-05-19 00:06:34.000000000 -0400
37614 +++ linux-2.6.39/drivers/rtc/rtc-twl.c 2011-05-22 19:36:32.000000000 -0400
37615 @@ -415,7 +415,7 @@ out:
37616 return ret;
37617 }
37618
37619 -static struct rtc_class_ops twl_rtc_ops = {
37620 +static const struct rtc_class_ops twl_rtc_ops = {
37621 .read_time = twl_rtc_read_time,
37622 .set_time = twl_rtc_set_time,
37623 .read_alarm = twl_rtc_read_alarm,
37624 diff -urNp linux-2.6.39/drivers/rtc/rtc-v3020.c linux-2.6.39/drivers/rtc/rtc-v3020.c
37625 --- linux-2.6.39/drivers/rtc/rtc-v3020.c 2011-05-19 00:06:34.000000000 -0400
37626 +++ linux-2.6.39/drivers/rtc/rtc-v3020.c 2011-05-22 19:36:32.000000000 -0400
37627 @@ -62,7 +62,7 @@ struct v3020 {
37628 /* GPIO access */
37629 struct v3020_gpio *gpio;
37630
37631 - struct v3020_chip_ops *ops;
37632 + const struct v3020_chip_ops *ops;
37633
37634 struct rtc_device *rtc;
37635 };
37636 @@ -100,7 +100,7 @@ static unsigned char v3020_mmio_read_bit
37637 return !!(readl(chip->ioaddress) & (1 << chip->leftshift));
37638 }
37639
37640 -static struct v3020_chip_ops v3020_mmio_ops = {
37641 +static const struct v3020_chip_ops v3020_mmio_ops = {
37642 .map_io = v3020_mmio_map,
37643 .unmap_io = v3020_mmio_unmap,
37644 .read_bit = v3020_mmio_read_bit,
37645 @@ -177,7 +177,7 @@ static unsigned char v3020_gpio_read_bit
37646 return bit;
37647 }
37648
37649 -static struct v3020_chip_ops v3020_gpio_ops = {
37650 +static const struct v3020_chip_ops v3020_gpio_ops = {
37651 .map_io = v3020_gpio_map,
37652 .unmap_io = v3020_gpio_unmap,
37653 .read_bit = v3020_gpio_read_bit,
37654 diff -urNp linux-2.6.39/drivers/s390/char/con3270.c linux-2.6.39/drivers/s390/char/con3270.c
37655 --- linux-2.6.39/drivers/s390/char/con3270.c 2011-05-19 00:06:34.000000000 -0400
37656 +++ linux-2.6.39/drivers/s390/char/con3270.c 2011-05-22 19:36:32.000000000 -0400
37657 @@ -28,7 +28,7 @@
37658 #define CON3270_OUTPUT_BUFFER_SIZE 1024
37659 #define CON3270_STRING_PAGES 4
37660
37661 -static struct raw3270_fn con3270_fn;
37662 +static const struct raw3270_fn con3270_fn;
37663
37664 /*
37665 * Main 3270 console view data structure.
37666 @@ -413,7 +413,7 @@ con3270_irq(struct con3270 *cp, struct r
37667 }
37668
37669 /* Console view to a 3270 device. */
37670 -static struct raw3270_fn con3270_fn = {
37671 +static const struct raw3270_fn con3270_fn = {
37672 .activate = con3270_activate,
37673 .deactivate = con3270_deactivate,
37674 .intv = (void *) con3270_irq
37675 diff -urNp linux-2.6.39/drivers/s390/char/fs3270.c linux-2.6.39/drivers/s390/char/fs3270.c
37676 --- linux-2.6.39/drivers/s390/char/fs3270.c 2011-05-19 00:06:34.000000000 -0400
37677 +++ linux-2.6.39/drivers/s390/char/fs3270.c 2011-05-22 19:36:32.000000000 -0400
37678 @@ -24,7 +24,7 @@
37679 #include "raw3270.h"
37680 #include "ctrlchar.h"
37681
37682 -static struct raw3270_fn fs3270_fn;
37683 +static const struct raw3270_fn fs3270_fn;
37684
37685 struct fs3270 {
37686 struct raw3270_view view;
37687 @@ -413,7 +413,7 @@ fs3270_release(struct raw3270_view *view
37688 }
37689
37690 /* View to a 3270 device. Can be console, tty or fullscreen. */
37691 -static struct raw3270_fn fs3270_fn = {
37692 +static const struct raw3270_fn fs3270_fn = {
37693 .activate = fs3270_activate,
37694 .deactivate = fs3270_deactivate,
37695 .intv = (void *) fs3270_irq,
37696 diff -urNp linux-2.6.39/drivers/s390/char/raw3270.c linux-2.6.39/drivers/s390/char/raw3270.c
37697 --- linux-2.6.39/drivers/s390/char/raw3270.c 2011-05-19 00:06:34.000000000 -0400
37698 +++ linux-2.6.39/drivers/s390/char/raw3270.c 2011-05-22 19:36:32.000000000 -0400
37699 @@ -488,7 +488,7 @@ raw3270_init_irq(struct raw3270_view *vi
37700 return RAW3270_IO_DONE;
37701 }
37702
37703 -static struct raw3270_fn raw3270_init_fn = {
37704 +static const struct raw3270_fn raw3270_init_fn = {
37705 .intv = raw3270_init_irq
37706 };
37707
37708 diff -urNp linux-2.6.39/drivers/s390/char/tty3270.c linux-2.6.39/drivers/s390/char/tty3270.c
37709 --- linux-2.6.39/drivers/s390/char/tty3270.c 2011-05-19 00:06:34.000000000 -0400
37710 +++ linux-2.6.39/drivers/s390/char/tty3270.c 2011-05-22 19:36:32.000000000 -0400
37711 @@ -37,7 +37,7 @@
37712 struct tty_driver *tty3270_driver;
37713 static int tty3270_max_index;
37714
37715 -static struct raw3270_fn tty3270_fn;
37716 +static const struct raw3270_fn tty3270_fn;
37717
37718 struct tty3270_cell {
37719 unsigned char character;
37720 @@ -834,7 +834,7 @@ tty3270_del_views(void)
37721 }
37722 }
37723
37724 -static struct raw3270_fn tty3270_fn = {
37725 +static const struct raw3270_fn tty3270_fn = {
37726 .activate = tty3270_activate,
37727 .deactivate = tty3270_deactivate,
37728 .intv = (void *) tty3270_irq,
37729 diff -urNp linux-2.6.39/drivers/s390/cio/qdio_debug.c linux-2.6.39/drivers/s390/cio/qdio_debug.c
37730 --- linux-2.6.39/drivers/s390/cio/qdio_debug.c 2011-05-19 00:06:34.000000000 -0400
37731 +++ linux-2.6.39/drivers/s390/cio/qdio_debug.c 2011-05-22 19:36:32.000000000 -0400
37732 @@ -225,7 +225,7 @@ static int qperf_seq_open(struct inode *
37733 filp->f_path.dentry->d_inode->i_private);
37734 }
37735
37736 -static struct file_operations debugfs_perf_fops = {
37737 +static const struct file_operations debugfs_perf_fops = {
37738 .owner = THIS_MODULE,
37739 .open = qperf_seq_open,
37740 .read = seq_read,
37741 diff -urNp linux-2.6.39/drivers/s390/crypto/zcrypt_cex2a.c linux-2.6.39/drivers/s390/crypto/zcrypt_cex2a.c
37742 --- linux-2.6.39/drivers/s390/crypto/zcrypt_cex2a.c 2011-05-19 00:06:34.000000000 -0400
37743 +++ linux-2.6.39/drivers/s390/crypto/zcrypt_cex2a.c 2011-05-22 19:36:32.000000000 -0400
37744 @@ -415,7 +415,7 @@ out_free:
37745 /**
37746 * The crypto operations for a CEX2A card.
37747 */
37748 -static struct zcrypt_ops zcrypt_cex2a_ops = {
37749 +static const struct zcrypt_ops zcrypt_cex2a_ops = {
37750 .rsa_modexpo = zcrypt_cex2a_modexpo,
37751 .rsa_modexpo_crt = zcrypt_cex2a_modexpo_crt,
37752 };
37753 diff -urNp linux-2.6.39/drivers/s390/crypto/zcrypt_pcica.c linux-2.6.39/drivers/s390/crypto/zcrypt_pcica.c
37754 --- linux-2.6.39/drivers/s390/crypto/zcrypt_pcica.c 2011-05-19 00:06:34.000000000 -0400
37755 +++ linux-2.6.39/drivers/s390/crypto/zcrypt_pcica.c 2011-05-22 19:36:32.000000000 -0400
37756 @@ -347,7 +347,7 @@ out_free:
37757 /**
37758 * The crypto operations for a PCICA card.
37759 */
37760 -static struct zcrypt_ops zcrypt_pcica_ops = {
37761 +static const struct zcrypt_ops zcrypt_pcica_ops = {
37762 .rsa_modexpo = zcrypt_pcica_modexpo,
37763 .rsa_modexpo_crt = zcrypt_pcica_modexpo_crt,
37764 };
37765 diff -urNp linux-2.6.39/drivers/s390/crypto/zcrypt_pcicc.c linux-2.6.39/drivers/s390/crypto/zcrypt_pcicc.c
37766 --- linux-2.6.39/drivers/s390/crypto/zcrypt_pcicc.c 2011-05-19 00:06:34.000000000 -0400
37767 +++ linux-2.6.39/drivers/s390/crypto/zcrypt_pcicc.c 2011-05-22 19:36:32.000000000 -0400
37768 @@ -553,7 +553,7 @@ out_free:
37769 /**
37770 * The crypto operations for a PCICC card.
37771 */
37772 -static struct zcrypt_ops zcrypt_pcicc_ops = {
37773 +static const struct zcrypt_ops zcrypt_pcicc_ops = {
37774 .rsa_modexpo = zcrypt_pcicc_modexpo,
37775 .rsa_modexpo_crt = zcrypt_pcicc_modexpo_crt,
37776 };
37777 diff -urNp linux-2.6.39/drivers/s390/crypto/zcrypt_pcixcc.c linux-2.6.39/drivers/s390/crypto/zcrypt_pcixcc.c
37778 --- linux-2.6.39/drivers/s390/crypto/zcrypt_pcixcc.c 2011-05-19 00:06:34.000000000 -0400
37779 +++ linux-2.6.39/drivers/s390/crypto/zcrypt_pcixcc.c 2011-05-22 19:36:32.000000000 -0400
37780 @@ -851,13 +851,13 @@ static long zcrypt_pcixcc_rng(struct zcr
37781 /**
37782 * The crypto operations for a PCIXCC/CEX2C card.
37783 */
37784 -static struct zcrypt_ops zcrypt_pcixcc_ops = {
37785 +static const struct zcrypt_ops zcrypt_pcixcc_ops = {
37786 .rsa_modexpo = zcrypt_pcixcc_modexpo,
37787 .rsa_modexpo_crt = zcrypt_pcixcc_modexpo_crt,
37788 .send_cprb = zcrypt_pcixcc_send_cprb,
37789 };
37790
37791 -static struct zcrypt_ops zcrypt_pcixcc_with_rng_ops = {
37792 +static const struct zcrypt_ops zcrypt_pcixcc_with_rng_ops = {
37793 .rsa_modexpo = zcrypt_pcixcc_modexpo,
37794 .rsa_modexpo_crt = zcrypt_pcixcc_modexpo_crt,
37795 .send_cprb = zcrypt_pcixcc_send_cprb,
37796 diff -urNp linux-2.6.39/drivers/s390/kvm/kvm_virtio.c linux-2.6.39/drivers/s390/kvm/kvm_virtio.c
37797 --- linux-2.6.39/drivers/s390/kvm/kvm_virtio.c 2011-05-19 00:06:34.000000000 -0400
37798 +++ linux-2.6.39/drivers/s390/kvm/kvm_virtio.c 2011-05-22 19:36:32.000000000 -0400
37799 @@ -266,7 +266,7 @@ error:
37800 /*
37801 * The config ops structure as defined by virtio config
37802 */
37803 -static struct virtio_config_ops kvm_vq_configspace_ops = {
37804 +static const struct virtio_config_ops kvm_vq_configspace_ops = {
37805 .get_features = kvm_get_features,
37806 .finalize_features = kvm_finalize_features,
37807 .get = kvm_get,
37808 diff -urNp linux-2.6.39/drivers/s390/net/qeth_core.h linux-2.6.39/drivers/s390/net/qeth_core.h
37809 --- linux-2.6.39/drivers/s390/net/qeth_core.h 2011-05-19 00:06:34.000000000 -0400
37810 +++ linux-2.6.39/drivers/s390/net/qeth_core.h 2011-05-22 19:36:32.000000000 -0400
37811 @@ -743,7 +743,7 @@ struct qeth_card {
37812 struct qeth_qdio_info qdio;
37813 struct qeth_perf_stats perf_stats;
37814 int read_or_write_problem;
37815 - struct qeth_osn_info osn_info;
37816 + const struct qeth_osn_info osn_info;
37817 struct qeth_discipline discipline;
37818 atomic_t force_alloc_skb;
37819 struct service_level qeth_service_level;
37820 diff -urNp linux-2.6.39/drivers/scsi/53c700.c linux-2.6.39/drivers/scsi/53c700.c
37821 --- linux-2.6.39/drivers/scsi/53c700.c 2011-05-19 00:06:34.000000000 -0400
37822 +++ linux-2.6.39/drivers/scsi/53c700.c 2011-05-22 19:36:32.000000000 -0400
37823 @@ -2153,7 +2153,7 @@ EXPORT_SYMBOL(NCR_700_detect);
37824 EXPORT_SYMBOL(NCR_700_release);
37825 EXPORT_SYMBOL(NCR_700_intr);
37826
37827 -static struct spi_function_template NCR_700_transport_functions = {
37828 +static struct spi_function_template NCR_700_transport_functions = {
37829 .set_period = NCR_700_set_period,
37830 .show_period = 1,
37831 .set_offset = NCR_700_set_offset,
37832 diff -urNp linux-2.6.39/drivers/scsi/aacraid/commctrl.c linux-2.6.39/drivers/scsi/aacraid/commctrl.c
37833 --- linux-2.6.39/drivers/scsi/aacraid/commctrl.c 2011-05-19 00:06:34.000000000 -0400
37834 +++ linux-2.6.39/drivers/scsi/aacraid/commctrl.c 2011-05-22 19:36:32.000000000 -0400
37835 @@ -482,6 +482,7 @@ static int aac_send_raw_srb(struct aac_d
37836 u32 actual_fibsize64, actual_fibsize = 0;
37837 int i;
37838
37839 + pax_track_stack();
37840
37841 if (dev->in_reset) {
37842 dprintk((KERN_DEBUG"aacraid: send raw srb -EBUSY\n"));
37843 diff -urNp linux-2.6.39/drivers/scsi/aic94xx/aic94xx_init.c linux-2.6.39/drivers/scsi/aic94xx/aic94xx_init.c
37844 --- linux-2.6.39/drivers/scsi/aic94xx/aic94xx_init.c 2011-05-19 00:06:34.000000000 -0400
37845 +++ linux-2.6.39/drivers/scsi/aic94xx/aic94xx_init.c 2011-05-22 19:41:37.000000000 -0400
37846 @@ -486,7 +486,7 @@ static ssize_t asd_show_update_bios(stru
37847 flash_error_table[i].reason);
37848 }
37849
37850 -static DEVICE_ATTR(update_bios, S_IRUGO|S_IWUGO,
37851 +static DEVICE_ATTR(update_bios, S_IRUGO|S_IWUSR,
37852 asd_show_update_bios, asd_store_update_bios);
37853
37854 static int asd_create_dev_attrs(struct asd_ha_struct *asd_ha)
37855 diff -urNp linux-2.6.39/drivers/scsi/bfa/bfa_core.c linux-2.6.39/drivers/scsi/bfa/bfa_core.c
37856 --- linux-2.6.39/drivers/scsi/bfa/bfa_core.c 2011-05-19 00:06:34.000000000 -0400
37857 +++ linux-2.6.39/drivers/scsi/bfa/bfa_core.c 2011-05-22 19:36:32.000000000 -0400
37858 @@ -24,7 +24,7 @@ BFA_TRC_FILE(HAL, CORE);
37859 /*
37860 * BFA module list terminated by NULL
37861 */
37862 -static struct bfa_module_s *hal_mods[] = {
37863 +static const struct bfa_module_s *hal_mods[] = {
37864 &hal_mod_sgpg,
37865 &hal_mod_fcport,
37866 &hal_mod_fcxp,
37867 diff -urNp linux-2.6.39/drivers/scsi/bfa/bfad.c linux-2.6.39/drivers/scsi/bfa/bfad.c
37868 --- linux-2.6.39/drivers/scsi/bfa/bfad.c 2011-05-19 00:06:34.000000000 -0400
37869 +++ linux-2.6.39/drivers/scsi/bfa/bfad.c 2011-05-22 19:36:32.000000000 -0400
37870 @@ -1027,6 +1027,8 @@ bfad_start_ops(struct bfad_s *bfad) {
37871 struct bfad_vport_s *vport, *vport_new;
37872 struct bfa_fcs_driver_info_s driver_info;
37873
37874 + pax_track_stack();
37875 +
37876 /* Fill the driver_info info to fcs*/
37877 memset(&driver_info, 0, sizeof(driver_info));
37878 strncpy(driver_info.version, BFAD_DRIVER_VERSION,
37879 diff -urNp linux-2.6.39/drivers/scsi/bfa/bfa_fcs.c linux-2.6.39/drivers/scsi/bfa/bfa_fcs.c
37880 --- linux-2.6.39/drivers/scsi/bfa/bfa_fcs.c 2011-05-19 00:06:34.000000000 -0400
37881 +++ linux-2.6.39/drivers/scsi/bfa/bfa_fcs.c 2011-05-22 19:36:32.000000000 -0400
37882 @@ -70,7 +70,7 @@ bfa_fcs_attach(struct bfa_fcs_s *fcs, st
37883 bfa_boolean_t min_cfg)
37884 {
37885 int i;
37886 - struct bfa_fcs_mod_s *mod;
37887 + const struct bfa_fcs_mod_s *mod;
37888
37889 fcs->bfa = bfa;
37890 fcs->bfad = bfad;
37891 @@ -93,7 +93,7 @@ void
37892 bfa_fcs_init(struct bfa_fcs_s *fcs)
37893 {
37894 int i, npbc_vports;
37895 - struct bfa_fcs_mod_s *mod;
37896 + const struct bfa_fcs_mod_s *mod;
37897 struct bfi_pbc_vport_s pbc_vports[BFI_PBC_MAX_VPORTS];
37898
37899 for (i = 0; i < sizeof(fcs_modules) / sizeof(fcs_modules[0]); i++) {
37900 @@ -140,7 +140,7 @@ bfa_fcs_driver_info_init(struct bfa_fcs_
37901 void
37902 bfa_fcs_exit(struct bfa_fcs_s *fcs)
37903 {
37904 - struct bfa_fcs_mod_s *mod;
37905 + const struct bfa_fcs_mod_s *mod;
37906 int nmods, i;
37907
37908 bfa_wc_init(&fcs->wc, bfa_fcs_exit_comp, fcs);
37909 diff -urNp linux-2.6.39/drivers/scsi/bfa/bfa_fcs_lport.c linux-2.6.39/drivers/scsi/bfa/bfa_fcs_lport.c
37910 --- linux-2.6.39/drivers/scsi/bfa/bfa_fcs_lport.c 2011-05-19 00:06:34.000000000 -0400
37911 +++ linux-2.6.39/drivers/scsi/bfa/bfa_fcs_lport.c 2011-05-22 19:36:32.000000000 -0400
37912 @@ -1559,6 +1559,8 @@ bfa_fcs_lport_fdmi_build_rhba_pyld(struc
37913 u16 len, count;
37914 u16 templen;
37915
37916 + pax_track_stack();
37917 +
37918 /*
37919 * get hba attributes
37920 */
37921 @@ -1836,6 +1838,8 @@ bfa_fcs_lport_fdmi_build_portattr_block(
37922 u8 count = 0;
37923 u16 templen;
37924
37925 + pax_track_stack();
37926 +
37927 /*
37928 * get port attributes
37929 */
37930 diff -urNp linux-2.6.39/drivers/scsi/bfa/bfa_fcs_rport.c linux-2.6.39/drivers/scsi/bfa/bfa_fcs_rport.c
37931 --- linux-2.6.39/drivers/scsi/bfa/bfa_fcs_rport.c 2011-05-19 00:06:34.000000000 -0400
37932 +++ linux-2.6.39/drivers/scsi/bfa/bfa_fcs_rport.c 2011-05-22 19:36:32.000000000 -0400
37933 @@ -1844,6 +1844,8 @@ bfa_fcs_rport_process_rpsc(struct bfa_fc
37934 struct fc_rpsc_speed_info_s speeds;
37935 struct bfa_port_attr_s pport_attr;
37936
37937 + pax_track_stack();
37938 +
37939 bfa_trc(port->fcs, rx_fchs->s_id);
37940 bfa_trc(port->fcs, rx_fchs->d_id);
37941
37942 diff -urNp linux-2.6.39/drivers/scsi/bfa/bfa_modules.h linux-2.6.39/drivers/scsi/bfa/bfa_modules.h
37943 --- linux-2.6.39/drivers/scsi/bfa/bfa_modules.h 2011-05-19 00:06:34.000000000 -0400
37944 +++ linux-2.6.39/drivers/scsi/bfa/bfa_modules.h 2011-05-22 19:36:32.000000000 -0400
37945 @@ -68,8 +68,8 @@ enum {
37946 static void bfa_ ## __mod ## _stop(struct bfa_s *bfa); \
37947 static void bfa_ ## __mod ## _iocdisable(struct bfa_s *bfa); \
37948 \
37949 - extern struct bfa_module_s hal_mod_ ## __mod; \
37950 - struct bfa_module_s hal_mod_ ## __mod = { \
37951 + extern const struct bfa_module_s hal_mod_ ## __mod; \
37952 + const struct bfa_module_s hal_mod_ ## __mod = { \
37953 bfa_ ## __mod ## _meminfo, \
37954 bfa_ ## __mod ## _attach, \
37955 bfa_ ## __mod ## _detach, \
37956 @@ -116,12 +116,12 @@ struct bfa_s {
37957 };
37958
37959 extern bfa_boolean_t bfa_auto_recover;
37960 -extern struct bfa_module_s hal_mod_sgpg;
37961 -extern struct bfa_module_s hal_mod_fcport;
37962 -extern struct bfa_module_s hal_mod_fcxp;
37963 -extern struct bfa_module_s hal_mod_lps;
37964 -extern struct bfa_module_s hal_mod_uf;
37965 -extern struct bfa_module_s hal_mod_rport;
37966 -extern struct bfa_module_s hal_mod_fcpim;
37967 +extern const struct bfa_module_s hal_mod_sgpg;
37968 +extern const struct bfa_module_s hal_mod_fcport;
37969 +extern const struct bfa_module_s hal_mod_fcxp;
37970 +extern const struct bfa_module_s hal_mod_lps;
37971 +extern const struct bfa_module_s hal_mod_uf;
37972 +extern const struct bfa_module_s hal_mod_rport;
37973 +extern const struct bfa_module_s hal_mod_fcpim;
37974
37975 #endif /* __BFA_MODULES_H__ */
37976 diff -urNp linux-2.6.39/drivers/scsi/BusLogic.c linux-2.6.39/drivers/scsi/BusLogic.c
37977 --- linux-2.6.39/drivers/scsi/BusLogic.c 2011-05-19 00:06:34.000000000 -0400
37978 +++ linux-2.6.39/drivers/scsi/BusLogic.c 2011-05-22 19:36:32.000000000 -0400
37979 @@ -962,6 +962,8 @@ static int __init BusLogic_InitializeFla
37980 static void __init BusLogic_InitializeProbeInfoList(struct BusLogic_HostAdapter
37981 *PrototypeHostAdapter)
37982 {
37983 + pax_track_stack();
37984 +
37985 /*
37986 If a PCI BIOS is present, interrogate it for MultiMaster and FlashPoint
37987 Host Adapters; otherwise, default to the standard ISA MultiMaster probe.
37988 diff -urNp linux-2.6.39/drivers/scsi/dpt_i2o.c linux-2.6.39/drivers/scsi/dpt_i2o.c
37989 --- linux-2.6.39/drivers/scsi/dpt_i2o.c 2011-05-19 00:06:34.000000000 -0400
37990 +++ linux-2.6.39/drivers/scsi/dpt_i2o.c 2011-05-22 19:36:32.000000000 -0400
37991 @@ -1811,6 +1811,8 @@ static int adpt_i2o_passthru(adpt_hba* p
37992 dma_addr_t addr;
37993 ulong flags = 0;
37994
37995 + pax_track_stack();
37996 +
37997 memset(&msg, 0, MAX_MESSAGE_SIZE*4);
37998 // get user msg size in u32s
37999 if(get_user(size, &user_msg[0])){
38000 @@ -2317,6 +2319,8 @@ static s32 adpt_scsi_to_i2o(adpt_hba* pH
38001 s32 rcode;
38002 dma_addr_t addr;
38003
38004 + pax_track_stack();
38005 +
38006 memset(msg, 0 , sizeof(msg));
38007 len = scsi_bufflen(cmd);
38008 direction = 0x00000000;
38009 diff -urNp linux-2.6.39/drivers/scsi/eata.c linux-2.6.39/drivers/scsi/eata.c
38010 --- linux-2.6.39/drivers/scsi/eata.c 2011-05-19 00:06:34.000000000 -0400
38011 +++ linux-2.6.39/drivers/scsi/eata.c 2011-05-22 19:36:32.000000000 -0400
38012 @@ -1087,6 +1087,8 @@ static int port_detect(unsigned long por
38013 struct hostdata *ha;
38014 char name[16];
38015
38016 + pax_track_stack();
38017 +
38018 sprintf(name, "%s%d", driver_name, j);
38019
38020 if (!request_region(port_base, REGION_SIZE, driver_name)) {
38021 diff -urNp linux-2.6.39/drivers/scsi/esp_scsi.c linux-2.6.39/drivers/scsi/esp_scsi.c
38022 --- linux-2.6.39/drivers/scsi/esp_scsi.c 2011-05-19 00:06:34.000000000 -0400
38023 +++ linux-2.6.39/drivers/scsi/esp_scsi.c 2011-05-22 19:36:32.000000000 -0400
38024 @@ -2680,7 +2680,7 @@ static void esp_set_width(struct scsi_ta
38025 tp->flags |= ESP_TGT_CHECK_NEGO;
38026 }
38027
38028 -static struct spi_function_template esp_transport_ops = {
38029 +static const struct spi_function_template esp_transport_ops = {
38030 .set_offset = esp_set_offset,
38031 .show_offset = 1,
38032 .set_period = esp_set_period,
38033 diff -urNp linux-2.6.39/drivers/scsi/fcoe/fcoe.c linux-2.6.39/drivers/scsi/fcoe/fcoe.c
38034 --- linux-2.6.39/drivers/scsi/fcoe/fcoe.c 2011-05-19 00:06:34.000000000 -0400
38035 +++ linux-2.6.39/drivers/scsi/fcoe/fcoe.c 2011-05-22 19:36:32.000000000 -0400
38036 @@ -138,7 +138,7 @@ static int fcoe_vport_disable(struct fc_
38037 static void fcoe_set_vport_symbolic_name(struct fc_vport *);
38038 static void fcoe_set_port_id(struct fc_lport *, u32, struct fc_frame *);
38039
38040 -static struct libfc_function_template fcoe_libfc_fcn_templ = {
38041 +static const struct libfc_function_template fcoe_libfc_fcn_templ = {
38042 .frame_send = fcoe_xmit,
38043 .ddp_setup = fcoe_ddp_setup,
38044 .ddp_done = fcoe_ddp_done,
38045 diff -urNp linux-2.6.39/drivers/scsi/fcoe/fcoe_ctlr.c linux-2.6.39/drivers/scsi/fcoe/fcoe_ctlr.c
38046 --- linux-2.6.39/drivers/scsi/fcoe/fcoe_ctlr.c 2011-05-19 00:06:34.000000000 -0400
38047 +++ linux-2.6.39/drivers/scsi/fcoe/fcoe_ctlr.c 2011-05-22 19:36:32.000000000 -0400
38048 @@ -1912,7 +1912,7 @@ static void fcoe_ctlr_vn_rport_callback(
38049 mutex_unlock(&fip->ctlr_mutex);
38050 }
38051
38052 -static struct fc_rport_operations fcoe_ctlr_vn_rport_ops = {
38053 +static const struct fc_rport_operations fcoe_ctlr_vn_rport_ops = {
38054 .event_callback = fcoe_ctlr_vn_rport_callback,
38055 };
38056
38057 @@ -2458,6 +2458,8 @@ static int fcoe_ctlr_vn_recv(struct fcoe
38058 } buf;
38059 int rc;
38060
38061 + pax_track_stack();
38062 +
38063 fiph = (struct fip_header *)skb->data;
38064 sub = fiph->fip_subcode;
38065
38066 diff -urNp linux-2.6.39/drivers/scsi/fnic/fnic_main.c linux-2.6.39/drivers/scsi/fnic/fnic_main.c
38067 --- linux-2.6.39/drivers/scsi/fnic/fnic_main.c 2011-05-19 00:06:34.000000000 -0400
38068 +++ linux-2.6.39/drivers/scsi/fnic/fnic_main.c 2011-05-22 19:36:32.000000000 -0400
38069 @@ -69,7 +69,7 @@ module_param(fnic_log_level, int, S_IRUG
38070 MODULE_PARM_DESC(fnic_log_level, "bit mask of fnic logging levels");
38071
38072
38073 -static struct libfc_function_template fnic_transport_template = {
38074 +static const struct libfc_function_template fnic_transport_template = {
38075 .frame_send = fnic_send,
38076 .lport_set_port_id = fnic_set_port_id,
38077 .fcp_abort_io = fnic_empty_scsi_cleanup,
38078 diff -urNp linux-2.6.39/drivers/scsi/gdth.c linux-2.6.39/drivers/scsi/gdth.c
38079 --- linux-2.6.39/drivers/scsi/gdth.c 2011-05-19 00:06:34.000000000 -0400
38080 +++ linux-2.6.39/drivers/scsi/gdth.c 2011-05-22 19:36:32.000000000 -0400
38081 @@ -4107,6 +4107,8 @@ static int ioc_lockdrv(void __user *arg)
38082 unsigned long flags;
38083 gdth_ha_str *ha;
38084
38085 + pax_track_stack();
38086 +
38087 if (copy_from_user(&ldrv, arg, sizeof(gdth_ioctl_lockdrv)))
38088 return -EFAULT;
38089 ha = gdth_find_ha(ldrv.ionode);
38090 @@ -4139,6 +4141,8 @@ static int ioc_resetdrv(void __user *arg
38091 gdth_ha_str *ha;
38092 int rval;
38093
38094 + pax_track_stack();
38095 +
38096 if (copy_from_user(&res, arg, sizeof(gdth_ioctl_reset)) ||
38097 res.number >= MAX_HDRIVES)
38098 return -EFAULT;
38099 @@ -4174,6 +4178,8 @@ static int ioc_general(void __user *arg,
38100 gdth_ha_str *ha;
38101 int rval;
38102
38103 + pax_track_stack();
38104 +
38105 if (copy_from_user(&gen, arg, sizeof(gdth_ioctl_general)))
38106 return -EFAULT;
38107 ha = gdth_find_ha(gen.ionode);
38108 @@ -4642,6 +4648,9 @@ static void gdth_flush(gdth_ha_str *ha)
38109 int i;
38110 gdth_cmd_str gdtcmd;
38111 char cmnd[MAX_COMMAND_SIZE];
38112 +
38113 + pax_track_stack();
38114 +
38115 memset(cmnd, 0xff, MAX_COMMAND_SIZE);
38116
38117 TRACE2(("gdth_flush() hanum %d\n", ha->hanum));
38118 diff -urNp linux-2.6.39/drivers/scsi/gdth_proc.c linux-2.6.39/drivers/scsi/gdth_proc.c
38119 --- linux-2.6.39/drivers/scsi/gdth_proc.c 2011-05-19 00:06:34.000000000 -0400
38120 +++ linux-2.6.39/drivers/scsi/gdth_proc.c 2011-05-22 19:36:32.000000000 -0400
38121 @@ -47,6 +47,9 @@ static int gdth_set_asc_info(struct Scsi
38122 u64 paddr;
38123
38124 char cmnd[MAX_COMMAND_SIZE];
38125 +
38126 + pax_track_stack();
38127 +
38128 memset(cmnd, 0xff, 12);
38129 memset(&gdtcmd, 0, sizeof(gdth_cmd_str));
38130
38131 @@ -175,6 +178,8 @@ static int gdth_get_info(char *buffer,ch
38132 gdth_hget_str *phg;
38133 char cmnd[MAX_COMMAND_SIZE];
38134
38135 + pax_track_stack();
38136 +
38137 gdtcmd = kmalloc(sizeof(*gdtcmd), GFP_KERNEL);
38138 estr = kmalloc(sizeof(*estr), GFP_KERNEL);
38139 if (!gdtcmd || !estr)
38140 diff -urNp linux-2.6.39/drivers/scsi/hosts.c linux-2.6.39/drivers/scsi/hosts.c
38141 --- linux-2.6.39/drivers/scsi/hosts.c 2011-05-19 00:06:34.000000000 -0400
38142 +++ linux-2.6.39/drivers/scsi/hosts.c 2011-05-22 19:36:32.000000000 -0400
38143 @@ -42,7 +42,7 @@
38144 #include "scsi_logging.h"
38145
38146
38147 -static atomic_t scsi_host_next_hn; /* host_no for next new host */
38148 +static atomic_unchecked_t scsi_host_next_hn; /* host_no for next new host */
38149
38150
38151 static void scsi_host_cls_release(struct device *dev)
38152 @@ -354,7 +354,7 @@ struct Scsi_Host *scsi_host_alloc(struct
38153 * subtract one because we increment first then return, but we need to
38154 * know what the next host number was before increment
38155 */
38156 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
38157 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
38158 shost->dma_channel = 0xff;
38159
38160 /* These three are default values which can be overridden */
38161 diff -urNp linux-2.6.39/drivers/scsi/hpsa.h linux-2.6.39/drivers/scsi/hpsa.h
38162 --- linux-2.6.39/drivers/scsi/hpsa.h 2011-05-19 00:06:34.000000000 -0400
38163 +++ linux-2.6.39/drivers/scsi/hpsa.h 2011-05-22 19:36:32.000000000 -0400
38164 @@ -347,7 +347,7 @@ static struct access_method SA5_access =
38165 SA5_completed,
38166 };
38167
38168 -static struct access_method SA5_performant_access = {
38169 +static const struct access_method SA5_performant_access = {
38170 SA5_submit_command,
38171 SA5_performant_intr_mask,
38172 SA5_fifo_full,
38173 diff -urNp linux-2.6.39/drivers/scsi/hptiop.c linux-2.6.39/drivers/scsi/hptiop.c
38174 --- linux-2.6.39/drivers/scsi/hptiop.c 2011-05-19 00:06:34.000000000 -0400
38175 +++ linux-2.6.39/drivers/scsi/hptiop.c 2011-05-22 19:36:32.000000000 -0400
38176 @@ -1226,7 +1226,7 @@ static void hptiop_remove(struct pci_dev
38177 scsi_host_put(host);
38178 }
38179
38180 -static struct hptiop_adapter_ops hptiop_itl_ops = {
38181 +static const struct hptiop_adapter_ops hptiop_itl_ops = {
38182 .iop_wait_ready = iop_wait_ready_itl,
38183 .internal_memalloc = NULL,
38184 .internal_memfree = NULL,
38185 @@ -1241,7 +1241,7 @@ static struct hptiop_adapter_ops hptiop_
38186 .post_req = hptiop_post_req_itl,
38187 };
38188
38189 -static struct hptiop_adapter_ops hptiop_mv_ops = {
38190 +static const struct hptiop_adapter_ops hptiop_mv_ops = {
38191 .iop_wait_ready = iop_wait_ready_mv,
38192 .internal_memalloc = hptiop_internal_memalloc_mv,
38193 .internal_memfree = hptiop_internal_memfree_mv,
38194 diff -urNp linux-2.6.39/drivers/scsi/ibmvscsi/ibmvfc.c linux-2.6.39/drivers/scsi/ibmvscsi/ibmvfc.c
38195 --- linux-2.6.39/drivers/scsi/ibmvscsi/ibmvfc.c 2011-05-19 00:06:34.000000000 -0400
38196 +++ linux-2.6.39/drivers/scsi/ibmvscsi/ibmvfc.c 2011-05-22 19:36:32.000000000 -0400
38197 @@ -4881,7 +4881,7 @@ static struct vio_device_id ibmvfc_devic
38198 };
38199 MODULE_DEVICE_TABLE(vio, ibmvfc_device_table);
38200
38201 -static struct dev_pm_ops ibmvfc_pm_ops = {
38202 +static const struct dev_pm_ops ibmvfc_pm_ops = {
38203 .resume = ibmvfc_resume
38204 };
38205
38206 diff -urNp linux-2.6.39/drivers/scsi/ibmvscsi/ibmvscsi.c linux-2.6.39/drivers/scsi/ibmvscsi/ibmvscsi.c
38207 --- linux-2.6.39/drivers/scsi/ibmvscsi/ibmvscsi.c 2011-05-19 00:06:34.000000000 -0400
38208 +++ linux-2.6.39/drivers/scsi/ibmvscsi/ibmvscsi.c 2011-05-22 19:36:32.000000000 -0400
38209 @@ -104,7 +104,7 @@ static struct scsi_transport_template *i
38210
38211 #define IBMVSCSI_VERSION "1.5.9"
38212
38213 -static struct ibmvscsi_ops *ibmvscsi_ops;
38214 +static const struct ibmvscsi_ops *ibmvscsi_ops;
38215
38216 MODULE_DESCRIPTION("IBM Virtual SCSI");
38217 MODULE_AUTHOR("Dave Boutcher");
38218 @@ -2059,7 +2059,7 @@ static struct vio_device_id ibmvscsi_dev
38219 };
38220 MODULE_DEVICE_TABLE(vio, ibmvscsi_device_table);
38221
38222 -static struct dev_pm_ops ibmvscsi_pm_ops = {
38223 +static const struct dev_pm_ops ibmvscsi_pm_ops = {
38224 .resume = ibmvscsi_resume
38225 };
38226
38227 @@ -2075,7 +2075,7 @@ static struct vio_driver ibmvscsi_driver
38228 }
38229 };
38230
38231 -static struct srp_function_template ibmvscsi_transport_functions = {
38232 +static const struct srp_function_template ibmvscsi_transport_functions = {
38233 };
38234
38235 int __init ibmvscsi_module_init(void)
38236 diff -urNp linux-2.6.39/drivers/scsi/ibmvscsi/ibmvscsi.h linux-2.6.39/drivers/scsi/ibmvscsi/ibmvscsi.h
38237 --- linux-2.6.39/drivers/scsi/ibmvscsi/ibmvscsi.h 2011-05-19 00:06:34.000000000 -0400
38238 +++ linux-2.6.39/drivers/scsi/ibmvscsi/ibmvscsi.h 2011-05-22 19:36:32.000000000 -0400
38239 @@ -127,7 +127,7 @@ struct ibmvscsi_ops {
38240 int (*resume) (struct ibmvscsi_host_data *hostdata);
38241 };
38242
38243 -extern struct ibmvscsi_ops iseriesvscsi_ops;
38244 -extern struct ibmvscsi_ops rpavscsi_ops;
38245 +extern const struct ibmvscsi_ops iseriesvscsi_ops;
38246 +extern const struct ibmvscsi_ops rpavscsi_ops;
38247
38248 #endif /* IBMVSCSI_H */
38249 diff -urNp linux-2.6.39/drivers/scsi/ibmvscsi/ibmvstgt.c linux-2.6.39/drivers/scsi/ibmvscsi/ibmvstgt.c
38250 --- linux-2.6.39/drivers/scsi/ibmvscsi/ibmvstgt.c 2011-05-19 00:06:34.000000000 -0400
38251 +++ linux-2.6.39/drivers/scsi/ibmvscsi/ibmvstgt.c 2011-05-22 19:36:32.000000000 -0400
38252 @@ -951,7 +951,7 @@ static int get_system_info(void)
38253 return 0;
38254 }
38255
38256 -static struct srp_function_template ibmvstgt_transport_functions = {
38257 +static const struct srp_function_template ibmvstgt_transport_functions = {
38258 .tsk_mgmt_response = ibmvstgt_tsk_mgmt_response,
38259 .it_nexus_response = ibmvstgt_it_nexus_response,
38260 };
38261 diff -urNp linux-2.6.39/drivers/scsi/ibmvscsi/iseries_vscsi.c linux-2.6.39/drivers/scsi/ibmvscsi/iseries_vscsi.c
38262 --- linux-2.6.39/drivers/scsi/ibmvscsi/iseries_vscsi.c 2011-05-19 00:06:34.000000000 -0400
38263 +++ linux-2.6.39/drivers/scsi/ibmvscsi/iseries_vscsi.c 2011-05-22 19:36:32.000000000 -0400
38264 @@ -163,7 +163,7 @@ static int iseriesvscsi_resume(struct ib
38265 return 0;
38266 }
38267
38268 -struct ibmvscsi_ops iseriesvscsi_ops = {
38269 +const struct ibmvscsi_ops iseriesvscsi_ops = {
38270 .init_crq_queue = iseriesvscsi_init_crq_queue,
38271 .release_crq_queue = iseriesvscsi_release_crq_queue,
38272 .reset_crq_queue = iseriesvscsi_reset_crq_queue,
38273 diff -urNp linux-2.6.39/drivers/scsi/ibmvscsi/rpa_vscsi.c linux-2.6.39/drivers/scsi/ibmvscsi/rpa_vscsi.c
38274 --- linux-2.6.39/drivers/scsi/ibmvscsi/rpa_vscsi.c 2011-05-19 00:06:34.000000000 -0400
38275 +++ linux-2.6.39/drivers/scsi/ibmvscsi/rpa_vscsi.c 2011-05-22 19:36:32.000000000 -0400
38276 @@ -358,7 +358,7 @@ static int rpavscsi_resume(struct ibmvsc
38277 return 0;
38278 }
38279
38280 -struct ibmvscsi_ops rpavscsi_ops = {
38281 +const struct ibmvscsi_ops rpavscsi_ops = {
38282 .init_crq_queue = rpavscsi_init_crq_queue,
38283 .release_crq_queue = rpavscsi_release_crq_queue,
38284 .reset_crq_queue = rpavscsi_reset_crq_queue,
38285 diff -urNp linux-2.6.39/drivers/scsi/ipr.c linux-2.6.39/drivers/scsi/ipr.c
38286 --- linux-2.6.39/drivers/scsi/ipr.c 2011-05-19 00:06:34.000000000 -0400
38287 +++ linux-2.6.39/drivers/scsi/ipr.c 2011-05-22 19:36:32.000000000 -0400
38288 @@ -6210,7 +6210,7 @@ static bool ipr_qc_fill_rtf(struct ata_q
38289 return true;
38290 }
38291
38292 -static struct ata_port_operations ipr_sata_ops = {
38293 +static const struct ata_port_operations ipr_sata_ops = {
38294 .phy_reset = ipr_ata_phy_reset,
38295 .hardreset = ipr_sata_reset,
38296 .post_internal_cmd = ipr_ata_post_internal,
38297 diff -urNp linux-2.6.39/drivers/scsi/libfc/fc_exch.c linux-2.6.39/drivers/scsi/libfc/fc_exch.c
38298 --- linux-2.6.39/drivers/scsi/libfc/fc_exch.c 2011-05-19 00:06:34.000000000 -0400
38299 +++ linux-2.6.39/drivers/scsi/libfc/fc_exch.c 2011-05-22 19:36:32.000000000 -0400
38300 @@ -105,12 +105,12 @@ struct fc_exch_mgr {
38301 * all together if not used XXX
38302 */
38303 struct {
38304 - atomic_t no_free_exch;
38305 - atomic_t no_free_exch_xid;
38306 - atomic_t xid_not_found;
38307 - atomic_t xid_busy;
38308 - atomic_t seq_not_found;
38309 - atomic_t non_bls_resp;
38310 + atomic_unchecked_t no_free_exch;
38311 + atomic_unchecked_t no_free_exch_xid;
38312 + atomic_unchecked_t xid_not_found;
38313 + atomic_unchecked_t xid_busy;
38314 + atomic_unchecked_t seq_not_found;
38315 + atomic_unchecked_t non_bls_resp;
38316 } stats;
38317 };
38318
38319 @@ -700,7 +700,7 @@ static struct fc_exch *fc_exch_em_alloc(
38320 /* allocate memory for exchange */
38321 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
38322 if (!ep) {
38323 - atomic_inc(&mp->stats.no_free_exch);
38324 + atomic_inc_unchecked(&mp->stats.no_free_exch);
38325 goto out;
38326 }
38327 memset(ep, 0, sizeof(*ep));
38328 @@ -761,7 +761,7 @@ out:
38329 return ep;
38330 err:
38331 spin_unlock_bh(&pool->lock);
38332 - atomic_inc(&mp->stats.no_free_exch_xid);
38333 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
38334 mempool_free(ep, mp->ep_pool);
38335 return NULL;
38336 }
38337 @@ -906,7 +906,7 @@ static enum fc_pf_rjt_reason fc_seq_look
38338 xid = ntohs(fh->fh_ox_id); /* we originated exch */
38339 ep = fc_exch_find(mp, xid);
38340 if (!ep) {
38341 - atomic_inc(&mp->stats.xid_not_found);
38342 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38343 reject = FC_RJT_OX_ID;
38344 goto out;
38345 }
38346 @@ -936,7 +936,7 @@ static enum fc_pf_rjt_reason fc_seq_look
38347 ep = fc_exch_find(mp, xid);
38348 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
38349 if (ep) {
38350 - atomic_inc(&mp->stats.xid_busy);
38351 + atomic_inc_unchecked(&mp->stats.xid_busy);
38352 reject = FC_RJT_RX_ID;
38353 goto rel;
38354 }
38355 @@ -947,7 +947,7 @@ static enum fc_pf_rjt_reason fc_seq_look
38356 }
38357 xid = ep->xid; /* get our XID */
38358 } else if (!ep) {
38359 - atomic_inc(&mp->stats.xid_not_found);
38360 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38361 reject = FC_RJT_RX_ID; /* XID not found */
38362 goto out;
38363 }
38364 @@ -964,7 +964,7 @@ static enum fc_pf_rjt_reason fc_seq_look
38365 } else {
38366 sp = &ep->seq;
38367 if (sp->id != fh->fh_seq_id) {
38368 - atomic_inc(&mp->stats.seq_not_found);
38369 + atomic_inc_unchecked(&mp->stats.seq_not_found);
38370 reject = FC_RJT_SEQ_ID; /* sequence/exch should exist */
38371 goto rel;
38372 }
38373 @@ -1392,22 +1392,22 @@ static void fc_exch_recv_seq_resp(struct
38374
38375 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
38376 if (!ep) {
38377 - atomic_inc(&mp->stats.xid_not_found);
38378 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38379 goto out;
38380 }
38381 if (ep->esb_stat & ESB_ST_COMPLETE) {
38382 - atomic_inc(&mp->stats.xid_not_found);
38383 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38384 goto rel;
38385 }
38386 if (ep->rxid == FC_XID_UNKNOWN)
38387 ep->rxid = ntohs(fh->fh_rx_id);
38388 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
38389 - atomic_inc(&mp->stats.xid_not_found);
38390 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38391 goto rel;
38392 }
38393 if (ep->did != ntoh24(fh->fh_s_id) &&
38394 ep->did != FC_FID_FLOGI) {
38395 - atomic_inc(&mp->stats.xid_not_found);
38396 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38397 goto rel;
38398 }
38399 sof = fr_sof(fp);
38400 @@ -1416,7 +1416,7 @@ static void fc_exch_recv_seq_resp(struct
38401 sp->ssb_stat |= SSB_ST_RESP;
38402 sp->id = fh->fh_seq_id;
38403 } else if (sp->id != fh->fh_seq_id) {
38404 - atomic_inc(&mp->stats.seq_not_found);
38405 + atomic_inc_unchecked(&mp->stats.seq_not_found);
38406 goto rel;
38407 }
38408
38409 @@ -1479,9 +1479,9 @@ static void fc_exch_recv_resp(struct fc_
38410 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
38411
38412 if (!sp)
38413 - atomic_inc(&mp->stats.xid_not_found);
38414 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38415 else
38416 - atomic_inc(&mp->stats.non_bls_resp);
38417 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
38418
38419 fc_frame_free(fp);
38420 }
38421 diff -urNp linux-2.6.39/drivers/scsi/libfc/fc_lport.c linux-2.6.39/drivers/scsi/libfc/fc_lport.c
38422 --- linux-2.6.39/drivers/scsi/libfc/fc_lport.c 2011-05-19 00:06:34.000000000 -0400
38423 +++ linux-2.6.39/drivers/scsi/libfc/fc_lport.c 2011-05-22 19:36:32.000000000 -0400
38424 @@ -1299,7 +1299,7 @@ static void fc_lport_enter_ns(struct fc_
38425 fc_lport_error(lport, fp);
38426 }
38427
38428 -static struct fc_rport_operations fc_lport_rport_ops = {
38429 +static const struct fc_rport_operations fc_lport_rport_ops = {
38430 .event_callback = fc_lport_rport_callback,
38431 };
38432
38433 diff -urNp linux-2.6.39/drivers/scsi/libfc/fc_rport.c linux-2.6.39/drivers/scsi/libfc/fc_rport.c
38434 --- linux-2.6.39/drivers/scsi/libfc/fc_rport.c 2011-05-19 00:06:34.000000000 -0400
38435 +++ linux-2.6.39/drivers/scsi/libfc/fc_rport.c 2011-05-22 19:36:32.000000000 -0400
38436 @@ -256,7 +256,7 @@ static void fc_rport_work(struct work_st
38437 struct fc_rport_libfc_priv *rpriv;
38438 enum fc_rport_event event;
38439 struct fc_lport *lport = rdata->local_port;
38440 - struct fc_rport_operations *rport_ops;
38441 + const struct fc_rport_operations *rport_ops;
38442 struct fc_rport_identifiers ids;
38443 struct fc_rport *rport;
38444 struct fc4_prov *prov;
38445 diff -urNp linux-2.6.39/drivers/scsi/libsas/sas_ata.c linux-2.6.39/drivers/scsi/libsas/sas_ata.c
38446 --- linux-2.6.39/drivers/scsi/libsas/sas_ata.c 2011-05-19 00:06:34.000000000 -0400
38447 +++ linux-2.6.39/drivers/scsi/libsas/sas_ata.c 2011-05-22 19:36:32.000000000 -0400
38448 @@ -307,14 +307,14 @@ static void sas_ata_post_internal(struct
38449 }
38450 }
38451
38452 -static struct ata_port_operations sas_sata_ops = {
38453 +static const struct ata_port_operations sas_sata_ops = {
38454 .prereset = ata_std_prereset,
38455 .softreset = NULL,
38456 .hardreset = sas_ata_hard_reset,
38457 .postreset = ata_std_postreset,
38458 .error_handler = ata_std_error_handler,
38459 .post_internal_cmd = sas_ata_post_internal,
38460 - .qc_defer = ata_std_qc_defer,
38461 + .qc_defer = ata_std_qc_defer,
38462 .qc_prep = ata_noop_qc_prep,
38463 .qc_issue = sas_ata_qc_issue,
38464 .qc_fill_rtf = sas_ata_qc_fill_rtf,
38465 diff -urNp linux-2.6.39/drivers/scsi/lpfc/lpfc_debugfs.c linux-2.6.39/drivers/scsi/lpfc/lpfc_debugfs.c
38466 --- linux-2.6.39/drivers/scsi/lpfc/lpfc_debugfs.c 2011-05-19 00:06:34.000000000 -0400
38467 +++ linux-2.6.39/drivers/scsi/lpfc/lpfc_debugfs.c 2011-05-22 19:36:32.000000000 -0400
38468 @@ -104,7 +104,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_
38469
38470 #include <linux/debugfs.h>
38471
38472 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
38473 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
38474 static unsigned long lpfc_debugfs_start_time = 0L;
38475
38476 /* iDiag */
38477 @@ -141,7 +141,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_v
38478 lpfc_debugfs_enable = 0;
38479
38480 len = 0;
38481 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
38482 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
38483 (lpfc_debugfs_max_disc_trc - 1);
38484 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
38485 dtp = vport->disc_trc + i;
38486 @@ -202,7 +202,7 @@ lpfc_debugfs_slow_ring_trc_data(struct l
38487 lpfc_debugfs_enable = 0;
38488
38489 len = 0;
38490 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
38491 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
38492 (lpfc_debugfs_max_slow_ring_trc - 1);
38493 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
38494 dtp = phba->slow_ring_trc + i;
38495 @@ -380,6 +380,8 @@ lpfc_debugfs_dumpHBASlim_data(struct lpf
38496 uint32_t *ptr;
38497 char buffer[1024];
38498
38499 + pax_track_stack();
38500 +
38501 off = 0;
38502 spin_lock_irq(&phba->hbalock);
38503
38504 @@ -617,14 +619,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport
38505 !vport || !vport->disc_trc)
38506 return;
38507
38508 - index = atomic_inc_return(&vport->disc_trc_cnt) &
38509 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
38510 (lpfc_debugfs_max_disc_trc - 1);
38511 dtp = vport->disc_trc + index;
38512 dtp->fmt = fmt;
38513 dtp->data1 = data1;
38514 dtp->data2 = data2;
38515 dtp->data3 = data3;
38516 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
38517 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
38518 dtp->jif = jiffies;
38519 #endif
38520 return;
38521 @@ -655,14 +657,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_h
38522 !phba || !phba->slow_ring_trc)
38523 return;
38524
38525 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
38526 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
38527 (lpfc_debugfs_max_slow_ring_trc - 1);
38528 dtp = phba->slow_ring_trc + index;
38529 dtp->fmt = fmt;
38530 dtp->data1 = data1;
38531 dtp->data2 = data2;
38532 dtp->data3 = data3;
38533 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
38534 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
38535 dtp->jif = jiffies;
38536 #endif
38537 return;
38538 @@ -2145,7 +2147,7 @@ lpfc_debugfs_initialize(struct lpfc_vpor
38539 "slow_ring buffer\n");
38540 goto debug_failed;
38541 }
38542 - atomic_set(&phba->slow_ring_trc_cnt, 0);
38543 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
38544 memset(phba->slow_ring_trc, 0,
38545 (sizeof(struct lpfc_debugfs_trc) *
38546 lpfc_debugfs_max_slow_ring_trc));
38547 @@ -2191,7 +2193,7 @@ lpfc_debugfs_initialize(struct lpfc_vpor
38548 "buffer\n");
38549 goto debug_failed;
38550 }
38551 - atomic_set(&vport->disc_trc_cnt, 0);
38552 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
38553
38554 snprintf(name, sizeof(name), "discovery_trace");
38555 vport->debug_disc_trc =
38556 diff -urNp linux-2.6.39/drivers/scsi/lpfc/lpfc.h linux-2.6.39/drivers/scsi/lpfc/lpfc.h
38557 --- linux-2.6.39/drivers/scsi/lpfc/lpfc.h 2011-05-19 00:06:34.000000000 -0400
38558 +++ linux-2.6.39/drivers/scsi/lpfc/lpfc.h 2011-05-22 19:36:32.000000000 -0400
38559 @@ -419,7 +419,7 @@ struct lpfc_vport {
38560 struct dentry *debug_nodelist;
38561 struct dentry *vport_debugfs_root;
38562 struct lpfc_debugfs_trc *disc_trc;
38563 - atomic_t disc_trc_cnt;
38564 + atomic_unchecked_t disc_trc_cnt;
38565 #endif
38566 uint8_t stat_data_enabled;
38567 uint8_t stat_data_blocked;
38568 @@ -785,8 +785,8 @@ struct lpfc_hba {
38569 struct timer_list fabric_block_timer;
38570 unsigned long bit_flags;
38571 #define FABRIC_COMANDS_BLOCKED 0
38572 - atomic_t num_rsrc_err;
38573 - atomic_t num_cmd_success;
38574 + atomic_unchecked_t num_rsrc_err;
38575 + atomic_unchecked_t num_cmd_success;
38576 unsigned long last_rsrc_error_time;
38577 unsigned long last_ramp_down_time;
38578 unsigned long last_ramp_up_time;
38579 @@ -800,7 +800,7 @@ struct lpfc_hba {
38580 struct dentry *debug_dumpDif; /* BlockGuard BPL*/
38581 struct dentry *debug_slow_ring_trc;
38582 struct lpfc_debugfs_trc *slow_ring_trc;
38583 - atomic_t slow_ring_trc_cnt;
38584 + atomic_unchecked_t slow_ring_trc_cnt;
38585 /* iDiag debugfs sub-directory */
38586 struct dentry *idiag_root;
38587 struct dentry *idiag_pci_cfg;
38588 diff -urNp linux-2.6.39/drivers/scsi/lpfc/lpfc_scsi.c linux-2.6.39/drivers/scsi/lpfc/lpfc_scsi.c
38589 --- linux-2.6.39/drivers/scsi/lpfc/lpfc_scsi.c 2011-05-19 00:06:34.000000000 -0400
38590 +++ linux-2.6.39/drivers/scsi/lpfc/lpfc_scsi.c 2011-05-22 19:36:32.000000000 -0400
38591 @@ -297,7 +297,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hb
38592 uint32_t evt_posted;
38593
38594 spin_lock_irqsave(&phba->hbalock, flags);
38595 - atomic_inc(&phba->num_rsrc_err);
38596 + atomic_inc_unchecked(&phba->num_rsrc_err);
38597 phba->last_rsrc_error_time = jiffies;
38598
38599 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
38600 @@ -338,7 +338,7 @@ lpfc_rampup_queue_depth(struct lpfc_vpor
38601 unsigned long flags;
38602 struct lpfc_hba *phba = vport->phba;
38603 uint32_t evt_posted;
38604 - atomic_inc(&phba->num_cmd_success);
38605 + atomic_inc_unchecked(&phba->num_cmd_success);
38606
38607 if (vport->cfg_lun_queue_depth <= queue_depth)
38608 return;
38609 @@ -382,8 +382,8 @@ lpfc_ramp_down_queue_handler(struct lpfc
38610 unsigned long num_rsrc_err, num_cmd_success;
38611 int i;
38612
38613 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
38614 - num_cmd_success = atomic_read(&phba->num_cmd_success);
38615 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
38616 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
38617
38618 vports = lpfc_create_vport_work_array(phba);
38619 if (vports != NULL)
38620 @@ -403,8 +403,8 @@ lpfc_ramp_down_queue_handler(struct lpfc
38621 }
38622 }
38623 lpfc_destroy_vport_work_array(phba, vports);
38624 - atomic_set(&phba->num_rsrc_err, 0);
38625 - atomic_set(&phba->num_cmd_success, 0);
38626 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
38627 + atomic_set_unchecked(&phba->num_cmd_success, 0);
38628 }
38629
38630 /**
38631 @@ -438,8 +438,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_h
38632 }
38633 }
38634 lpfc_destroy_vport_work_array(phba, vports);
38635 - atomic_set(&phba->num_rsrc_err, 0);
38636 - atomic_set(&phba->num_cmd_success, 0);
38637 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
38638 + atomic_set_unchecked(&phba->num_cmd_success, 0);
38639 }
38640
38641 /**
38642 diff -urNp linux-2.6.39/drivers/scsi/mac_esp.c linux-2.6.39/drivers/scsi/mac_esp.c
38643 --- linux-2.6.39/drivers/scsi/mac_esp.c 2011-05-19 00:06:34.000000000 -0400
38644 +++ linux-2.6.39/drivers/scsi/mac_esp.c 2011-05-22 19:36:32.000000000 -0400
38645 @@ -473,7 +473,7 @@ static irqreturn_t mac_scsi_esp_intr(int
38646 return IRQ_HANDLED;
38647 }
38648
38649 -static struct esp_driver_ops mac_esp_ops = {
38650 +static const struct esp_driver_ops mac_esp_ops = {
38651 .esp_write8 = mac_esp_write8,
38652 .esp_read8 = mac_esp_read8,
38653 .map_single = mac_esp_map_single,
38654 diff -urNp linux-2.6.39/drivers/scsi/megaraid/megaraid_mbox.c linux-2.6.39/drivers/scsi/megaraid/megaraid_mbox.c
38655 --- linux-2.6.39/drivers/scsi/megaraid/megaraid_mbox.c 2011-05-19 00:06:34.000000000 -0400
38656 +++ linux-2.6.39/drivers/scsi/megaraid/megaraid_mbox.c 2011-05-22 19:36:32.000000000 -0400
38657 @@ -3510,6 +3510,8 @@ megaraid_cmm_register(adapter_t *adapter
38658 int rval;
38659 int i;
38660
38661 + pax_track_stack();
38662 +
38663 // Allocate memory for the base list of scb for management module.
38664 adapter->uscb_list = kcalloc(MBOX_MAX_USER_CMDS, sizeof(scb_t), GFP_KERNEL);
38665
38666 diff -urNp linux-2.6.39/drivers/scsi/megaraid/megaraid_sas_base.c linux-2.6.39/drivers/scsi/megaraid/megaraid_sas_base.c
38667 --- linux-2.6.39/drivers/scsi/megaraid/megaraid_sas_base.c 2011-05-19 00:06:34.000000000 -0400
38668 +++ linux-2.6.39/drivers/scsi/megaraid/megaraid_sas_base.c 2011-05-22 19:36:32.000000000 -0400
38669 @@ -366,7 +366,7 @@ megasas_check_reset_xscale(struct megasa
38670 return 0;
38671 }
38672
38673 -static struct megasas_instance_template megasas_instance_template_xscale = {
38674 +static const struct megasas_instance_template megasas_instance_template_xscale = {
38675
38676 .fire_cmd = megasas_fire_cmd_xscale,
38677 .enable_intr = megasas_enable_intr_xscale,
38678 @@ -497,7 +497,7 @@ megasas_check_reset_ppc(struct megasas_i
38679 {
38680 return 0;
38681 }
38682 -static struct megasas_instance_template megasas_instance_template_ppc = {
38683 +static const struct megasas_instance_template megasas_instance_template_ppc = {
38684
38685 .fire_cmd = megasas_fire_cmd_ppc,
38686 .enable_intr = megasas_enable_intr_ppc,
38687 @@ -623,7 +623,7 @@ megasas_check_reset_skinny(struct megasa
38688 return 0;
38689 }
38690
38691 -static struct megasas_instance_template megasas_instance_template_skinny = {
38692 +static const struct megasas_instance_template megasas_instance_template_skinny = {
38693
38694 .fire_cmd = megasas_fire_cmd_skinny,
38695 .enable_intr = megasas_enable_intr_skinny,
38696 @@ -810,7 +810,7 @@ megasas_check_reset_gen2(struct megasas_
38697 return 0;
38698 }
38699
38700 -static struct megasas_instance_template megasas_instance_template_gen2 = {
38701 +static const struct megasas_instance_template megasas_instance_template_gen2 = {
38702
38703 .fire_cmd = megasas_fire_cmd_gen2,
38704 .enable_intr = megasas_enable_intr_gen2,
38705 @@ -834,7 +834,7 @@ static struct megasas_instance_template
38706 /*
38707 * Template added for TB (Fusion)
38708 */
38709 -extern struct megasas_instance_template megasas_instance_template_fusion;
38710 +extern const struct megasas_instance_template megasas_instance_template_fusion;
38711
38712 /**
38713 * megasas_issue_polled - Issues a polling command
38714 diff -urNp linux-2.6.39/drivers/scsi/megaraid/megaraid_sas_fusion.c linux-2.6.39/drivers/scsi/megaraid/megaraid_sas_fusion.c
38715 --- linux-2.6.39/drivers/scsi/megaraid/megaraid_sas_fusion.c 2011-05-19 00:06:34.000000000 -0400
38716 +++ linux-2.6.39/drivers/scsi/megaraid/megaraid_sas_fusion.c 2011-05-22 19:36:32.000000000 -0400
38717 @@ -2236,7 +2236,7 @@ void megasas_fusion_ocr_wq(struct work_s
38718 megasas_reset_fusion(instance->host);
38719 }
38720
38721 -struct megasas_instance_template megasas_instance_template_fusion = {
38722 +const struct megasas_instance_template megasas_instance_template_fusion = {
38723 .fire_cmd = megasas_fire_cmd_fusion,
38724 .enable_intr = megasas_enable_intr_fusion,
38725 .disable_intr = megasas_disable_intr_fusion,
38726 diff -urNp linux-2.6.39/drivers/scsi/megaraid/megaraid_sas.h linux-2.6.39/drivers/scsi/megaraid/megaraid_sas.h
38727 --- linux-2.6.39/drivers/scsi/megaraid/megaraid_sas.h 2011-05-19 00:06:34.000000000 -0400
38728 +++ linux-2.6.39/drivers/scsi/megaraid/megaraid_sas.h 2011-05-22 19:36:32.000000000 -0400
38729 @@ -1330,7 +1330,7 @@ struct megasas_instance {
38730 atomic_t fw_outstanding;
38731 atomic_t fw_reset_no_pci_access;
38732
38733 - struct megasas_instance_template *instancet;
38734 + const struct megasas_instance_template *instancet;
38735 struct tasklet_struct isr_tasklet;
38736 struct work_struct work_init;
38737
38738 diff -urNp linux-2.6.39/drivers/scsi/ncr53c8xx.c linux-2.6.39/drivers/scsi/ncr53c8xx.c
38739 --- linux-2.6.39/drivers/scsi/ncr53c8xx.c 2011-05-19 00:06:34.000000000 -0400
38740 +++ linux-2.6.39/drivers/scsi/ncr53c8xx.c 2011-05-22 19:36:32.000000000 -0400
38741 @@ -8606,7 +8606,7 @@ static void ncr53c8xx_get_signalling(str
38742 spi_signalling(shost) = type;
38743 }
38744
38745 -static struct spi_function_template ncr53c8xx_transport_functions = {
38746 +static struct spi_function_template ncr53c8xx_transport_functions = {
38747 .set_period = ncr53c8xx_set_period,
38748 .show_period = 1,
38749 .set_offset = ncr53c8xx_set_offset,
38750 diff -urNp linux-2.6.39/drivers/scsi/osd/osd_initiator.c linux-2.6.39/drivers/scsi/osd/osd_initiator.c
38751 --- linux-2.6.39/drivers/scsi/osd/osd_initiator.c 2011-05-19 00:06:34.000000000 -0400
38752 +++ linux-2.6.39/drivers/scsi/osd/osd_initiator.c 2011-05-22 19:36:32.000000000 -0400
38753 @@ -97,6 +97,8 @@ static int _osd_get_print_system_info(st
38754 int nelem = ARRAY_SIZE(get_attrs), a = 0;
38755 int ret;
38756
38757 + pax_track_stack();
38758 +
38759 or = osd_start_request(od, GFP_KERNEL);
38760 if (!or)
38761 return -ENOMEM;
38762 diff -urNp linux-2.6.39/drivers/scsi/pmcraid.c linux-2.6.39/drivers/scsi/pmcraid.c
38763 --- linux-2.6.39/drivers/scsi/pmcraid.c 2011-05-19 00:06:34.000000000 -0400
38764 +++ linux-2.6.39/drivers/scsi/pmcraid.c 2011-05-22 19:36:32.000000000 -0400
38765 @@ -201,8 +201,8 @@ static int pmcraid_slave_alloc(struct sc
38766 res->scsi_dev = scsi_dev;
38767 scsi_dev->hostdata = res;
38768 res->change_detected = 0;
38769 - atomic_set(&res->read_failures, 0);
38770 - atomic_set(&res->write_failures, 0);
38771 + atomic_set_unchecked(&res->read_failures, 0);
38772 + atomic_set_unchecked(&res->write_failures, 0);
38773 rc = 0;
38774 }
38775 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
38776 @@ -2677,9 +2677,9 @@ static int pmcraid_error_handler(struct
38777
38778 /* If this was a SCSI read/write command keep count of errors */
38779 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
38780 - atomic_inc(&res->read_failures);
38781 + atomic_inc_unchecked(&res->read_failures);
38782 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
38783 - atomic_inc(&res->write_failures);
38784 + atomic_inc_unchecked(&res->write_failures);
38785
38786 if (!RES_IS_GSCSI(res->cfg_entry) &&
38787 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
38788 @@ -3535,7 +3535,7 @@ static int pmcraid_queuecommand_lck(
38789 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
38790 * hrrq_id assigned here in queuecommand
38791 */
38792 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
38793 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
38794 pinstance->num_hrrq;
38795 cmd->cmd_done = pmcraid_io_done;
38796
38797 @@ -3860,7 +3860,7 @@ static long pmcraid_ioctl_passthrough(
38798 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
38799 * hrrq_id assigned here in queuecommand
38800 */
38801 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
38802 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
38803 pinstance->num_hrrq;
38804
38805 if (request_size) {
38806 @@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(stru
38807
38808 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
38809 /* add resources only after host is added into system */
38810 - if (!atomic_read(&pinstance->expose_resources))
38811 + if (!atomic_read_unchecked(&pinstance->expose_resources))
38812 return;
38813
38814 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
38815 @@ -5329,8 +5329,8 @@ static int __devinit pmcraid_init_instan
38816 init_waitqueue_head(&pinstance->reset_wait_q);
38817
38818 atomic_set(&pinstance->outstanding_cmds, 0);
38819 - atomic_set(&pinstance->last_message_id, 0);
38820 - atomic_set(&pinstance->expose_resources, 0);
38821 + atomic_set_unchecked(&pinstance->last_message_id, 0);
38822 + atomic_set_unchecked(&pinstance->expose_resources, 0);
38823
38824 INIT_LIST_HEAD(&pinstance->free_res_q);
38825 INIT_LIST_HEAD(&pinstance->used_res_q);
38826 @@ -6045,7 +6045,7 @@ static int __devinit pmcraid_probe(
38827 /* Schedule worker thread to handle CCN and take care of adding and
38828 * removing devices to OS
38829 */
38830 - atomic_set(&pinstance->expose_resources, 1);
38831 + atomic_set_unchecked(&pinstance->expose_resources, 1);
38832 schedule_work(&pinstance->worker_q);
38833 return rc;
38834
38835 diff -urNp linux-2.6.39/drivers/scsi/pmcraid.h linux-2.6.39/drivers/scsi/pmcraid.h
38836 --- linux-2.6.39/drivers/scsi/pmcraid.h 2011-05-19 00:06:34.000000000 -0400
38837 +++ linux-2.6.39/drivers/scsi/pmcraid.h 2011-05-22 19:36:32.000000000 -0400
38838 @@ -750,7 +750,7 @@ struct pmcraid_instance {
38839 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
38840
38841 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
38842 - atomic_t last_message_id;
38843 + atomic_unchecked_t last_message_id;
38844
38845 /* configuration table */
38846 struct pmcraid_config_table *cfg_table;
38847 @@ -779,7 +779,7 @@ struct pmcraid_instance {
38848 atomic_t outstanding_cmds;
38849
38850 /* should add/delete resources to mid-layer now ?*/
38851 - atomic_t expose_resources;
38852 + atomic_unchecked_t expose_resources;
38853
38854
38855
38856 @@ -815,8 +815,8 @@ struct pmcraid_resource_entry {
38857 struct pmcraid_config_table_entry_ext cfg_entry_ext;
38858 };
38859 struct scsi_device *scsi_dev; /* Link scsi_device structure */
38860 - atomic_t read_failures; /* count of failed READ commands */
38861 - atomic_t write_failures; /* count of failed WRITE commands */
38862 + atomic_unchecked_t read_failures; /* count of failed READ commands */
38863 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
38864
38865 /* To indicate add/delete/modify during CCN */
38866 u8 change_detected;
38867 diff -urNp linux-2.6.39/drivers/scsi/qla2xxx/qla_os.c linux-2.6.39/drivers/scsi/qla2xxx/qla_os.c
38868 --- linux-2.6.39/drivers/scsi/qla2xxx/qla_os.c 2011-05-19 00:06:34.000000000 -0400
38869 +++ linux-2.6.39/drivers/scsi/qla2xxx/qla_os.c 2011-05-22 19:36:32.000000000 -0400
38870 @@ -4097,7 +4097,7 @@ static struct pci_driver qla2xxx_pci_dri
38871 .err_handler = &qla2xxx_err_handler,
38872 };
38873
38874 -static struct file_operations apidev_fops = {
38875 +static const struct file_operations apidev_fops = {
38876 .owner = THIS_MODULE,
38877 .llseek = noop_llseek,
38878 };
38879 diff -urNp linux-2.6.39/drivers/scsi/qla4xxx/ql4_def.h linux-2.6.39/drivers/scsi/qla4xxx/ql4_def.h
38880 --- linux-2.6.39/drivers/scsi/qla4xxx/ql4_def.h 2011-05-19 00:06:34.000000000 -0400
38881 +++ linux-2.6.39/drivers/scsi/qla4xxx/ql4_def.h 2011-05-22 19:36:32.000000000 -0400
38882 @@ -256,7 +256,7 @@ struct ddb_entry {
38883 atomic_t retry_relogin_timer; /* Min Time between relogins
38884 * (4000 only) */
38885 atomic_t relogin_timer; /* Max Time to wait for relogin to complete */
38886 - atomic_t relogin_retry_count; /* Num of times relogin has been
38887 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
38888 * retried */
38889
38890 uint16_t port;
38891 diff -urNp linux-2.6.39/drivers/scsi/qla4xxx/ql4_init.c linux-2.6.39/drivers/scsi/qla4xxx/ql4_init.c
38892 --- linux-2.6.39/drivers/scsi/qla4xxx/ql4_init.c 2011-05-19 00:06:34.000000000 -0400
38893 +++ linux-2.6.39/drivers/scsi/qla4xxx/ql4_init.c 2011-05-22 19:36:32.000000000 -0400
38894 @@ -680,7 +680,7 @@ static struct ddb_entry * qla4xxx_alloc_
38895 ddb_entry->fw_ddb_index = fw_ddb_index;
38896 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
38897 atomic_set(&ddb_entry->relogin_timer, 0);
38898 - atomic_set(&ddb_entry->relogin_retry_count, 0);
38899 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
38900 atomic_set(&ddb_entry->state, DDB_STATE_ONLINE);
38901 list_add_tail(&ddb_entry->list, &ha->ddb_list);
38902 ha->fw_ddb_index_map[fw_ddb_index] = ddb_entry;
38903 @@ -1433,7 +1433,7 @@ int qla4xxx_process_ddb_changed(struct s
38904 if ((ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) &&
38905 (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE)) {
38906 atomic_set(&ddb_entry->state, DDB_STATE_ONLINE);
38907 - atomic_set(&ddb_entry->relogin_retry_count, 0);
38908 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
38909 atomic_set(&ddb_entry->relogin_timer, 0);
38910 clear_bit(DF_RELOGIN, &ddb_entry->flags);
38911 iscsi_unblock_session(ddb_entry->sess);
38912 diff -urNp linux-2.6.39/drivers/scsi/qla4xxx/ql4_os.c linux-2.6.39/drivers/scsi/qla4xxx/ql4_os.c
38913 --- linux-2.6.39/drivers/scsi/qla4xxx/ql4_os.c 2011-05-19 00:06:34.000000000 -0400
38914 +++ linux-2.6.39/drivers/scsi/qla4xxx/ql4_os.c 2011-05-22 19:36:32.000000000 -0400
38915 @@ -802,13 +802,13 @@ static void qla4xxx_timer(struct scsi_ql
38916 ddb_entry->fw_ddb_device_state ==
38917 DDB_DS_SESSION_FAILED) {
38918 /* Reset retry relogin timer */
38919 - atomic_inc(&ddb_entry->relogin_retry_count);
38920 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
38921 DEBUG2(printk("scsi%ld: ddb [%d] relogin"
38922 " timed out-retrying"
38923 " relogin (%d)\n",
38924 ha->host_no,
38925 ddb_entry->fw_ddb_index,
38926 - atomic_read(&ddb_entry->
38927 + atomic_read_unchecked(&ddb_entry->
38928 relogin_retry_count))
38929 );
38930 start_dpc++;
38931 diff -urNp linux-2.6.39/drivers/scsi/scsi.c linux-2.6.39/drivers/scsi/scsi.c
38932 --- linux-2.6.39/drivers/scsi/scsi.c 2011-05-19 00:06:34.000000000 -0400
38933 +++ linux-2.6.39/drivers/scsi/scsi.c 2011-05-22 19:36:32.000000000 -0400
38934 @@ -655,7 +655,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *
38935 unsigned long timeout;
38936 int rtn = 0;
38937
38938 - atomic_inc(&cmd->device->iorequest_cnt);
38939 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
38940
38941 /* check if the device is still usable */
38942 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
38943 diff -urNp linux-2.6.39/drivers/scsi/scsi_debug.c linux-2.6.39/drivers/scsi/scsi_debug.c
38944 --- linux-2.6.39/drivers/scsi/scsi_debug.c 2011-05-19 00:06:34.000000000 -0400
38945 +++ linux-2.6.39/drivers/scsi/scsi_debug.c 2011-05-22 19:36:32.000000000 -0400
38946 @@ -1493,6 +1493,8 @@ static int resp_mode_select(struct scsi_
38947 unsigned char arr[SDEBUG_MAX_MSELECT_SZ];
38948 unsigned char *cmd = (unsigned char *)scp->cmnd;
38949
38950 + pax_track_stack();
38951 +
38952 if ((errsts = check_readiness(scp, 1, devip)))
38953 return errsts;
38954 memset(arr, 0, sizeof(arr));
38955 @@ -1590,6 +1592,8 @@ static int resp_log_sense(struct scsi_cm
38956 unsigned char arr[SDEBUG_MAX_LSENSE_SZ];
38957 unsigned char *cmd = (unsigned char *)scp->cmnd;
38958
38959 + pax_track_stack();
38960 +
38961 if ((errsts = check_readiness(scp, 1, devip)))
38962 return errsts;
38963 memset(arr, 0, sizeof(arr));
38964 diff -urNp linux-2.6.39/drivers/scsi/scsi_lib.c linux-2.6.39/drivers/scsi/scsi_lib.c
38965 --- linux-2.6.39/drivers/scsi/scsi_lib.c 2011-05-19 00:06:34.000000000 -0400
38966 +++ linux-2.6.39/drivers/scsi/scsi_lib.c 2011-05-22 19:36:32.000000000 -0400
38967 @@ -1410,7 +1410,7 @@ static void scsi_kill_request(struct req
38968 shost = sdev->host;
38969 scsi_init_cmd_errh(cmd);
38970 cmd->result = DID_NO_CONNECT << 16;
38971 - atomic_inc(&cmd->device->iorequest_cnt);
38972 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
38973
38974 /*
38975 * SCSI request completion path will do scsi_device_unbusy(),
38976 @@ -1436,9 +1436,9 @@ static void scsi_softirq_done(struct req
38977
38978 INIT_LIST_HEAD(&cmd->eh_entry);
38979
38980 - atomic_inc(&cmd->device->iodone_cnt);
38981 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
38982 if (cmd->result)
38983 - atomic_inc(&cmd->device->ioerr_cnt);
38984 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
38985
38986 disposition = scsi_decide_disposition(cmd);
38987 if (disposition != SUCCESS &&
38988 diff -urNp linux-2.6.39/drivers/scsi/scsi_sysfs.c linux-2.6.39/drivers/scsi/scsi_sysfs.c
38989 --- linux-2.6.39/drivers/scsi/scsi_sysfs.c 2011-05-19 00:06:34.000000000 -0400
38990 +++ linux-2.6.39/drivers/scsi/scsi_sysfs.c 2011-05-22 19:36:32.000000000 -0400
38991 @@ -621,7 +621,7 @@ show_iostat_##field(struct device *dev,
38992 char *buf) \
38993 { \
38994 struct scsi_device *sdev = to_scsi_device(dev); \
38995 - unsigned long long count = atomic_read(&sdev->field); \
38996 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
38997 return snprintf(buf, 20, "0x%llx\n", count); \
38998 } \
38999 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
39000 diff -urNp linux-2.6.39/drivers/scsi/scsi_transport_fc.c linux-2.6.39/drivers/scsi/scsi_transport_fc.c
39001 --- linux-2.6.39/drivers/scsi/scsi_transport_fc.c 2011-05-19 00:06:34.000000000 -0400
39002 +++ linux-2.6.39/drivers/scsi/scsi_transport_fc.c 2011-05-22 19:36:32.000000000 -0400
39003 @@ -485,7 +485,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_
39004 * Netlink Infrastructure
39005 */
39006
39007 -static atomic_t fc_event_seq;
39008 +static atomic_unchecked_t fc_event_seq;
39009
39010 /**
39011 * fc_get_event_number - Obtain the next sequential FC event number
39012 @@ -498,7 +498,7 @@ static atomic_t fc_event_seq;
39013 u32
39014 fc_get_event_number(void)
39015 {
39016 - return atomic_add_return(1, &fc_event_seq);
39017 + return atomic_add_return_unchecked(1, &fc_event_seq);
39018 }
39019 EXPORT_SYMBOL(fc_get_event_number);
39020
39021 @@ -646,7 +646,7 @@ static __init int fc_transport_init(void
39022 {
39023 int error;
39024
39025 - atomic_set(&fc_event_seq, 0);
39026 + atomic_set_unchecked(&fc_event_seq, 0);
39027
39028 error = transport_class_register(&fc_host_class);
39029 if (error)
39030 @@ -836,7 +836,7 @@ static int fc_str_to_dev_loss(const char
39031 char *cp;
39032
39033 *val = simple_strtoul(buf, &cp, 0);
39034 - if ((*cp && (*cp != '\n')) || (*val < 0))
39035 + if (*cp && (*cp != '\n'))
39036 return -EINVAL;
39037 /*
39038 * Check for overflow; dev_loss_tmo is u32
39039 diff -urNp linux-2.6.39/drivers/scsi/scsi_transport_iscsi.c linux-2.6.39/drivers/scsi/scsi_transport_iscsi.c
39040 --- linux-2.6.39/drivers/scsi/scsi_transport_iscsi.c 2011-05-19 00:06:34.000000000 -0400
39041 +++ linux-2.6.39/drivers/scsi/scsi_transport_iscsi.c 2011-05-22 19:36:32.000000000 -0400
39042 @@ -83,7 +83,7 @@ struct iscsi_internal {
39043 struct device_attribute *session_attrs[ISCSI_SESSION_ATTRS + 1];
39044 };
39045
39046 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
39047 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
39048 static struct workqueue_struct *iscsi_eh_timer_workq;
39049
39050 /*
39051 @@ -761,7 +761,7 @@ int iscsi_add_session(struct iscsi_cls_s
39052 int err;
39053
39054 ihost = shost->shost_data;
39055 - session->sid = atomic_add_return(1, &iscsi_session_nr);
39056 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
39057
39058 if (id == ISCSI_MAX_TARGET) {
39059 for (id = 0; id < ISCSI_MAX_TARGET; id++) {
39060 @@ -2200,7 +2200,7 @@ static __init int iscsi_transport_init(v
39061 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
39062 ISCSI_TRANSPORT_VERSION);
39063
39064 - atomic_set(&iscsi_session_nr, 0);
39065 + atomic_set_unchecked(&iscsi_session_nr, 0);
39066
39067 err = class_register(&iscsi_transport_class);
39068 if (err)
39069 diff -urNp linux-2.6.39/drivers/scsi/scsi_transport_srp.c linux-2.6.39/drivers/scsi/scsi_transport_srp.c
39070 --- linux-2.6.39/drivers/scsi/scsi_transport_srp.c 2011-05-19 00:06:34.000000000 -0400
39071 +++ linux-2.6.39/drivers/scsi/scsi_transport_srp.c 2011-05-22 19:36:32.000000000 -0400
39072 @@ -33,7 +33,7 @@
39073 #include "scsi_transport_srp_internal.h"
39074
39075 struct srp_host_attrs {
39076 - atomic_t next_port_id;
39077 + atomic_unchecked_t next_port_id;
39078 };
39079 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
39080
39081 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transpo
39082 struct Scsi_Host *shost = dev_to_shost(dev);
39083 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
39084
39085 - atomic_set(&srp_host->next_port_id, 0);
39086 + atomic_set_unchecked(&srp_host->next_port_id, 0);
39087 return 0;
39088 }
39089
39090 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct S
39091 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
39092 rport->roles = ids->roles;
39093
39094 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
39095 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
39096 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
39097
39098 transport_setup_device(&rport->dev);
39099 diff -urNp linux-2.6.39/drivers/scsi/sg.c linux-2.6.39/drivers/scsi/sg.c
39100 --- linux-2.6.39/drivers/scsi/sg.c 2011-05-19 00:06:34.000000000 -0400
39101 +++ linux-2.6.39/drivers/scsi/sg.c 2011-05-22 19:36:32.000000000 -0400
39102 @@ -2310,7 +2310,7 @@ struct sg_proc_leaf {
39103 const struct file_operations * fops;
39104 };
39105
39106 -static struct sg_proc_leaf sg_proc_leaf_arr[] = {
39107 +static const struct sg_proc_leaf sg_proc_leaf_arr[] = {
39108 {"allow_dio", &adio_fops},
39109 {"debug", &debug_fops},
39110 {"def_reserved_size", &dressz_fops},
39111 @@ -2325,7 +2325,7 @@ sg_proc_init(void)
39112 {
39113 int k, mask;
39114 int num_leaves = ARRAY_SIZE(sg_proc_leaf_arr);
39115 - struct sg_proc_leaf * leaf;
39116 + const struct sg_proc_leaf * leaf;
39117
39118 sg_proc_sgp = proc_mkdir(sg_proc_sg_dirname, NULL);
39119 if (!sg_proc_sgp)
39120 diff -urNp linux-2.6.39/drivers/scsi/sym53c8xx_2/sym_glue.c linux-2.6.39/drivers/scsi/sym53c8xx_2/sym_glue.c
39121 --- linux-2.6.39/drivers/scsi/sym53c8xx_2/sym_glue.c 2011-05-19 00:06:34.000000000 -0400
39122 +++ linux-2.6.39/drivers/scsi/sym53c8xx_2/sym_glue.c 2011-05-22 19:36:32.000000000 -0400
39123 @@ -1756,6 +1756,8 @@ static int __devinit sym2_probe(struct p
39124 int do_iounmap = 0;
39125 int do_disable_device = 1;
39126
39127 + pax_track_stack();
39128 +
39129 memset(&sym_dev, 0, sizeof(sym_dev));
39130 memset(&nvram, 0, sizeof(nvram));
39131 sym_dev.pdev = pdev;
39132 diff -urNp linux-2.6.39/drivers/scsi/vmw_pvscsi.c linux-2.6.39/drivers/scsi/vmw_pvscsi.c
39133 --- linux-2.6.39/drivers/scsi/vmw_pvscsi.c 2011-05-19 00:06:34.000000000 -0400
39134 +++ linux-2.6.39/drivers/scsi/vmw_pvscsi.c 2011-05-22 19:36:32.000000000 -0400
39135 @@ -447,6 +447,8 @@ static void pvscsi_setup_all_rings(const
39136 dma_addr_t base;
39137 unsigned i;
39138
39139 + pax_track_stack();
39140 +
39141 cmd.ringsStatePPN = adapter->ringStatePA >> PAGE_SHIFT;
39142 cmd.reqRingNumPages = adapter->req_pages;
39143 cmd.cmpRingNumPages = adapter->cmp_pages;
39144 diff -urNp linux-2.6.39/drivers/sh/clk/cpg.c linux-2.6.39/drivers/sh/clk/cpg.c
39145 --- linux-2.6.39/drivers/sh/clk/cpg.c 2011-05-19 00:06:34.000000000 -0400
39146 +++ linux-2.6.39/drivers/sh/clk/cpg.c 2011-05-22 19:36:32.000000000 -0400
39147 @@ -26,7 +26,7 @@ static void sh_clk_mstp32_disable(struct
39148 clk->enable_reg);
39149 }
39150
39151 -static struct clk_ops sh_clk_mstp32_clk_ops = {
39152 +static const struct clk_ops sh_clk_mstp32_clk_ops = {
39153 .enable = sh_clk_mstp32_enable,
39154 .disable = sh_clk_mstp32_disable,
39155 .recalc = followparent_recalc,
39156 @@ -150,7 +150,7 @@ static void sh_clk_div6_disable(struct c
39157 __raw_writel(value, clk->enable_reg);
39158 }
39159
39160 -static struct clk_ops sh_clk_div6_clk_ops = {
39161 +static const struct clk_ops sh_clk_div6_clk_ops = {
39162 .recalc = sh_clk_div6_recalc,
39163 .round_rate = sh_clk_div_round_rate,
39164 .set_rate = sh_clk_div6_set_rate,
39165 @@ -158,7 +158,7 @@ static struct clk_ops sh_clk_div6_clk_op
39166 .disable = sh_clk_div6_disable,
39167 };
39168
39169 -static struct clk_ops sh_clk_div6_reparent_clk_ops = {
39170 +static const struct clk_ops sh_clk_div6_reparent_clk_ops = {
39171 .recalc = sh_clk_div6_recalc,
39172 .round_rate = sh_clk_div_round_rate,
39173 .set_rate = sh_clk_div6_set_rate,
39174 @@ -282,13 +282,13 @@ static void sh_clk_div4_disable(struct c
39175 __raw_writel(__raw_readl(clk->enable_reg) | (1 << 8), clk->enable_reg);
39176 }
39177
39178 -static struct clk_ops sh_clk_div4_clk_ops = {
39179 +static const struct clk_ops sh_clk_div4_clk_ops = {
39180 .recalc = sh_clk_div4_recalc,
39181 .set_rate = sh_clk_div4_set_rate,
39182 .round_rate = sh_clk_div_round_rate,
39183 };
39184
39185 -static struct clk_ops sh_clk_div4_enable_clk_ops = {
39186 +static const struct clk_ops sh_clk_div4_enable_clk_ops = {
39187 .recalc = sh_clk_div4_recalc,
39188 .set_rate = sh_clk_div4_set_rate,
39189 .round_rate = sh_clk_div_round_rate,
39190 @@ -296,7 +296,7 @@ static struct clk_ops sh_clk_div4_enable
39191 .disable = sh_clk_div4_disable,
39192 };
39193
39194 -static struct clk_ops sh_clk_div4_reparent_clk_ops = {
39195 +static const struct clk_ops sh_clk_div4_reparent_clk_ops = {
39196 .recalc = sh_clk_div4_recalc,
39197 .set_rate = sh_clk_div4_set_rate,
39198 .round_rate = sh_clk_div_round_rate,
39199 diff -urNp linux-2.6.39/drivers/spi/dw_spi.h linux-2.6.39/drivers/spi/dw_spi.h
39200 --- linux-2.6.39/drivers/spi/dw_spi.h 2011-05-19 00:06:34.000000000 -0400
39201 +++ linux-2.6.39/drivers/spi/dw_spi.h 2011-05-22 19:36:32.000000000 -0400
39202 @@ -151,7 +151,7 @@ struct dw_spi {
39203 int dma_chan_done;
39204 struct device *dma_dev;
39205 dma_addr_t dma_addr; /* phy address of the Data register */
39206 - struct dw_spi_dma_ops *dma_ops;
39207 + const struct dw_spi_dma_ops *dma_ops;
39208 void *dma_priv; /* platform relate info */
39209 struct pci_dev *dmac;
39210
39211 diff -urNp linux-2.6.39/drivers/spi/dw_spi_mid.c linux-2.6.39/drivers/spi/dw_spi_mid.c
39212 --- linux-2.6.39/drivers/spi/dw_spi_mid.c 2011-05-19 00:06:34.000000000 -0400
39213 +++ linux-2.6.39/drivers/spi/dw_spi_mid.c 2011-05-22 19:36:32.000000000 -0400
39214 @@ -180,7 +180,7 @@ static int mid_spi_dma_transfer(struct d
39215 return 0;
39216 }
39217
39218 -static struct dw_spi_dma_ops mid_dma_ops = {
39219 +static const struct dw_spi_dma_ops mid_dma_ops = {
39220 .dma_init = mid_spi_dma_init,
39221 .dma_exit = mid_spi_dma_exit,
39222 .dma_transfer = mid_spi_dma_transfer,
39223 diff -urNp linux-2.6.39/drivers/spi/spi.c linux-2.6.39/drivers/spi/spi.c
39224 --- linux-2.6.39/drivers/spi/spi.c 2011-05-19 00:06:34.000000000 -0400
39225 +++ linux-2.6.39/drivers/spi/spi.c 2011-05-22 19:36:32.000000000 -0400
39226 @@ -1023,7 +1023,7 @@ int spi_bus_unlock(struct spi_master *ma
39227 EXPORT_SYMBOL_GPL(spi_bus_unlock);
39228
39229 /* portable code must never pass more than 32 bytes */
39230 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
39231 +#define SPI_BUFSIZ max(32U,SMP_CACHE_BYTES)
39232
39233 static u8 *buf;
39234
39235 diff -urNp linux-2.6.39/drivers/ssb/driver_pcicore.c linux-2.6.39/drivers/ssb/driver_pcicore.c
39236 --- linux-2.6.39/drivers/ssb/driver_pcicore.c 2011-05-19 00:06:34.000000000 -0400
39237 +++ linux-2.6.39/drivers/ssb/driver_pcicore.c 2011-05-22 19:36:32.000000000 -0400
39238 @@ -223,7 +223,7 @@ static int ssb_pcicore_write_config(stru
39239 return err ? PCIBIOS_DEVICE_NOT_FOUND : PCIBIOS_SUCCESSFUL;
39240 }
39241
39242 -static struct pci_ops ssb_pcicore_pciops = {
39243 +static const struct pci_ops ssb_pcicore_pciops = {
39244 .read = ssb_pcicore_read_config,
39245 .write = ssb_pcicore_write_config,
39246 };
39247 diff -urNp linux-2.6.39/drivers/staging/ath6kl/os/linux/cfg80211.c linux-2.6.39/drivers/staging/ath6kl/os/linux/cfg80211.c
39248 --- linux-2.6.39/drivers/staging/ath6kl/os/linux/cfg80211.c 2011-05-19 00:06:34.000000000 -0400
39249 +++ linux-2.6.39/drivers/staging/ath6kl/os/linux/cfg80211.c 2011-05-22 19:36:32.000000000 -0400
39250 @@ -1391,8 +1391,7 @@ u32 cipher_suites[] = {
39251 WLAN_CIPHER_SUITE_CCMP,
39252 };
39253
39254 -static struct
39255 -cfg80211_ops ar6k_cfg80211_ops = {
39256 +static const struct cfg80211_ops ar6k_cfg80211_ops = {
39257 .change_virtual_intf = ar6k_cfg80211_change_iface,
39258 .add_virtual_intf = ar6k_cfg80211_add_virtual_intf,
39259 .del_virtual_intf = ar6k_cfg80211_del_virtual_intf,
39260 diff -urNp linux-2.6.39/drivers/staging/brcm80211/brcmfmac/dhd_linux.c linux-2.6.39/drivers/staging/brcm80211/brcmfmac/dhd_linux.c
39261 --- linux-2.6.39/drivers/staging/brcm80211/brcmfmac/dhd_linux.c 2011-05-19 00:06:34.000000000 -0400
39262 +++ linux-2.6.39/drivers/staging/brcm80211/brcmfmac/dhd_linux.c 2011-05-22 19:36:32.000000000 -0400
39263 @@ -857,14 +857,14 @@ static void dhd_op_if(dhd_if_t *ifp)
39264 free_netdev(ifp->net);
39265 }
39266 /* Allocate etherdev, including space for private structure */
39267 - ifp->net = alloc_etherdev(sizeof(dhd));
39268 + ifp->net = alloc_etherdev(sizeof(*dhd));
39269 if (!ifp->net) {
39270 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
39271 ret = -ENOMEM;
39272 }
39273 if (ret == 0) {
39274 strcpy(ifp->net->name, ifp->name);
39275 - memcpy(netdev_priv(ifp->net), &dhd, sizeof(dhd));
39276 + memcpy(netdev_priv(ifp->net), dhd, sizeof(*dhd));
39277 err = dhd_net_attach(&dhd->pub, ifp->idx);
39278 if (err != 0) {
39279 DHD_ERROR(("%s: dhd_net_attach failed, "
39280 @@ -1500,7 +1500,7 @@ static void dhd_ethtool_get_drvinfo(stru
39281 sprintf(info->bus_info, "%s", dev_name(&wl_cfg80211_get_sdio_func()->dev));
39282 }
39283
39284 -struct ethtool_ops dhd_ethtool_ops = {
39285 +const struct ethtool_ops dhd_ethtool_ops = {
39286 .get_drvinfo = dhd_ethtool_get_drvinfo
39287 };
39288
39289 @@ -1923,7 +1923,7 @@ dhd_pub_t *dhd_attach(struct dhd_bus *bu
39290 strcpy(nv_path, nvram_path);
39291
39292 /* Allocate etherdev, including space for private structure */
39293 - net = alloc_etherdev(sizeof(dhd));
39294 + net = alloc_etherdev(sizeof(*dhd));
39295 if (!net) {
39296 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
39297 goto fail;
39298 @@ -1939,7 +1939,7 @@ dhd_pub_t *dhd_attach(struct dhd_bus *bu
39299 /*
39300 * Save the dhd_info into the priv
39301 */
39302 - memcpy(netdev_priv(net), &dhd, sizeof(dhd));
39303 + memcpy(netdev_priv(net), dhd, sizeof(*dhd));
39304
39305 /* Set network interface name if it was provided as module parameter */
39306 if (iface_name[0]) {
39307 @@ -2056,7 +2056,7 @@ dhd_pub_t *dhd_attach(struct dhd_bus *bu
39308 /*
39309 * Save the dhd_info into the priv
39310 */
39311 - memcpy(netdev_priv(net), &dhd, sizeof(dhd));
39312 + memcpy(netdev_priv(net), dhd, sizeof(*dhd));
39313
39314 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
39315 g_bus = bus;
39316 @@ -2206,7 +2206,7 @@ dhd_iovar(dhd_pub_t *pub, int ifidx, cha
39317 return ret;
39318 }
39319
39320 -static struct net_device_ops dhd_ops_pri = {
39321 +static const struct net_device_ops dhd_ops_pri = {
39322 .ndo_open = dhd_open,
39323 .ndo_stop = dhd_stop,
39324 .ndo_get_stats = dhd_get_stats,
39325 diff -urNp linux-2.6.39/drivers/staging/brcm80211/brcmfmac/wl_cfg80211.c linux-2.6.39/drivers/staging/brcm80211/brcmfmac/wl_cfg80211.c
39326 --- linux-2.6.39/drivers/staging/brcm80211/brcmfmac/wl_cfg80211.c 2011-05-19 00:06:34.000000000 -0400
39327 +++ linux-2.6.39/drivers/staging/brcm80211/brcmfmac/wl_cfg80211.c 2011-05-22 19:36:32.000000000 -0400
39328 @@ -2109,7 +2109,7 @@ wl_cfg80211_flush_pmksa(struct wiphy *wi
39329
39330 }
39331
39332 -static struct cfg80211_ops wl_cfg80211_ops = {
39333 +static const struct cfg80211_ops wl_cfg80211_ops = {
39334 .change_virtual_intf = wl_cfg80211_change_iface,
39335 .scan = wl_cfg80211_scan,
39336 .set_wiphy_params = wl_cfg80211_set_wiphy_params,
39337 diff -urNp linux-2.6.39/drivers/staging/brcm80211/brcmfmac/wl_iw.c linux-2.6.39/drivers/staging/brcm80211/brcmfmac/wl_iw.c
39338 --- linux-2.6.39/drivers/staging/brcm80211/brcmfmac/wl_iw.c 2011-05-19 00:06:34.000000000 -0400
39339 +++ linux-2.6.39/drivers/staging/brcm80211/brcmfmac/wl_iw.c 2011-05-22 19:36:32.000000000 -0400
39340 @@ -495,7 +495,7 @@ wl_iw_get_range(struct net_device *dev,
39341 list = (wl_u32_list_t *) channels;
39342
39343 dwrq->length = sizeof(struct iw_range);
39344 - memset(range, 0, sizeof(range));
39345 + memset(range, 0, sizeof(*range));
39346
39347 range->min_nwid = range->max_nwid = 0;
39348
39349 diff -urNp linux-2.6.39/drivers/staging/comedi/comedi_fops.c linux-2.6.39/drivers/staging/comedi/comedi_fops.c
39350 --- linux-2.6.39/drivers/staging/comedi/comedi_fops.c 2011-05-19 00:06:34.000000000 -0400
39351 +++ linux-2.6.39/drivers/staging/comedi/comedi_fops.c 2011-05-22 19:36:32.000000000 -0400
39352 @@ -1445,7 +1445,7 @@ static void comedi_unmap(struct vm_area_
39353 mutex_unlock(&dev->mutex);
39354 }
39355
39356 -static struct vm_operations_struct comedi_vm_ops = {
39357 +static const struct vm_operations_struct comedi_vm_ops = {
39358 .close = comedi_unmap,
39359 };
39360
39361 diff -urNp linux-2.6.39/drivers/staging/cx25821/cx25821-alsa.c linux-2.6.39/drivers/staging/cx25821/cx25821-alsa.c
39362 --- linux-2.6.39/drivers/staging/cx25821/cx25821-alsa.c 2011-05-19 00:06:34.000000000 -0400
39363 +++ linux-2.6.39/drivers/staging/cx25821/cx25821-alsa.c 2011-05-22 19:36:32.000000000 -0400
39364 @@ -586,7 +586,7 @@ static struct page *snd_cx25821_page(str
39365 /*
39366 * operators
39367 */
39368 -static struct snd_pcm_ops snd_cx25821_pcm_ops = {
39369 +static const struct snd_pcm_ops snd_cx25821_pcm_ops = {
39370 .open = snd_cx25821_pcm_open,
39371 .close = snd_cx25821_close,
39372 .ioctl = snd_pcm_lib_ioctl,
39373 diff -urNp linux-2.6.39/drivers/staging/cx25821/cx25821-i2c.c linux-2.6.39/drivers/staging/cx25821/cx25821-i2c.c
39374 --- linux-2.6.39/drivers/staging/cx25821/cx25821-i2c.c 2011-05-19 00:06:34.000000000 -0400
39375 +++ linux-2.6.39/drivers/staging/cx25821/cx25821-i2c.c 2011-05-22 19:36:32.000000000 -0400
39376 @@ -282,7 +282,7 @@ static u32 cx25821_functionality(struct
39377 I2C_FUNC_SMBUS_READ_WORD_DATA | I2C_FUNC_SMBUS_WRITE_WORD_DATA;
39378 }
39379
39380 -static struct i2c_algorithm cx25821_i2c_algo_template = {
39381 +static const struct i2c_algorithm cx25821_i2c_algo_template = {
39382 .master_xfer = i2c_xfer,
39383 .functionality = cx25821_functionality,
39384 #ifdef NEED_ALGO_CONTROL
39385 diff -urNp linux-2.6.39/drivers/staging/et131x/et1310_tx.c linux-2.6.39/drivers/staging/et131x/et1310_tx.c
39386 --- linux-2.6.39/drivers/staging/et131x/et1310_tx.c 2011-05-19 00:06:34.000000000 -0400
39387 +++ linux-2.6.39/drivers/staging/et131x/et1310_tx.c 2011-05-22 19:36:32.000000000 -0400
39388 @@ -635,11 +635,11 @@ inline void et131x_free_send_packet(stru
39389 struct net_device_stats *stats = &etdev->net_stats;
39390
39391 if (tcb->flags & fMP_DEST_BROAD)
39392 - atomic_inc(&etdev->Stats.brdcstxmt);
39393 + atomic_inc_unchecked(&etdev->Stats.brdcstxmt);
39394 else if (tcb->flags & fMP_DEST_MULTI)
39395 - atomic_inc(&etdev->Stats.multixmt);
39396 + atomic_inc_unchecked(&etdev->Stats.multixmt);
39397 else
39398 - atomic_inc(&etdev->Stats.unixmt);
39399 + atomic_inc_unchecked(&etdev->Stats.unixmt);
39400
39401 if (tcb->skb) {
39402 stats->tx_bytes += tcb->skb->len;
39403 diff -urNp linux-2.6.39/drivers/staging/et131x/et131x_adapter.h linux-2.6.39/drivers/staging/et131x/et131x_adapter.h
39404 --- linux-2.6.39/drivers/staging/et131x/et131x_adapter.h 2011-05-19 00:06:34.000000000 -0400
39405 +++ linux-2.6.39/drivers/staging/et131x/et131x_adapter.h 2011-05-22 19:36:32.000000000 -0400
39406 @@ -110,11 +110,11 @@ typedef struct _ce_stats_t {
39407 * operations
39408 */
39409 u32 unircv; /* # multicast packets received */
39410 - atomic_t unixmt; /* # multicast packets for Tx */
39411 + atomic_unchecked_t unixmt; /* # multicast packets for Tx */
39412 u32 multircv; /* # multicast packets received */
39413 - atomic_t multixmt; /* # multicast packets for Tx */
39414 + atomic_unchecked_t multixmt; /* # multicast packets for Tx */
39415 u32 brdcstrcv; /* # broadcast packets received */
39416 - atomic_t brdcstxmt; /* # broadcast packets for Tx */
39417 + atomic_unchecked_t brdcstxmt; /* # broadcast packets for Tx */
39418 u32 norcvbuf; /* # Rx packets discarded */
39419 u32 noxmtbuf; /* # Tx packets discarded */
39420
39421 diff -urNp linux-2.6.39/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c linux-2.6.39/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c
39422 --- linux-2.6.39/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c 2011-05-19 00:06:34.000000000 -0400
39423 +++ linux-2.6.39/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c 2011-05-22 19:36:32.000000000 -0400
39424 @@ -55,7 +55,7 @@ int numofmsgbuf = 0;
39425 //
39426 // Table of entry-point routines for char device
39427 //
39428 -static struct file_operations ft1000fops =
39429 +static const struct file_operations ft1000fops =
39430 {
39431 .unlocked_ioctl = ft1000_ioctl,
39432 .poll = ft1000_poll_dev,
39433 diff -urNp linux-2.6.39/drivers/staging/generic_serial/rio/rio_linux.c linux-2.6.39/drivers/staging/generic_serial/rio/rio_linux.c
39434 --- linux-2.6.39/drivers/staging/generic_serial/rio/rio_linux.c 2011-05-19 00:06:34.000000000 -0400
39435 +++ linux-2.6.39/drivers/staging/generic_serial/rio/rio_linux.c 2011-05-22 19:36:32.000000000 -0400
39436 @@ -221,7 +221,7 @@ module_param(rio_poll, int, 0);
39437 module_param(rio_debug, int, 0644);
39438 module_param(rio_irqmask, long, 0);
39439
39440 -static struct real_driver rio_real_driver = {
39441 +static const struct real_driver rio_real_driver = {
39442 rio_disable_tx_interrupts,
39443 rio_enable_tx_interrupts,
39444 rio_disable_rx_interrupts,
39445 diff -urNp linux-2.6.39/drivers/staging/generic_serial/ser_a2232.c linux-2.6.39/drivers/staging/generic_serial/ser_a2232.c
39446 --- linux-2.6.39/drivers/staging/generic_serial/ser_a2232.c 2011-05-19 00:06:34.000000000 -0400
39447 +++ linux-2.6.39/drivers/staging/generic_serial/ser_a2232.c 2011-05-22 19:36:32.000000000 -0400
39448 @@ -144,7 +144,7 @@ static int a2232_open(struct tty_struct
39449 /*---------------------------------------------------------------------------
39450 * Interface from generic_serial.c back here
39451 *--------------------------------------------------------------------------*/
39452 -static struct real_driver a2232_real_driver = {
39453 +static const struct real_driver a2232_real_driver = {
39454 a2232_disable_tx_interrupts,
39455 a2232_enable_tx_interrupts,
39456 a2232_disable_rx_interrupts,
39457 diff -urNp linux-2.6.39/drivers/staging/generic_serial/sx.c linux-2.6.39/drivers/staging/generic_serial/sx.c
39458 --- linux-2.6.39/drivers/staging/generic_serial/sx.c 2011-05-19 00:06:34.000000000 -0400
39459 +++ linux-2.6.39/drivers/staging/generic_serial/sx.c 2011-05-22 19:36:32.000000000 -0400
39460 @@ -355,7 +355,7 @@ module_param(sx_irqmask, int, 0);
39461
39462 MODULE_LICENSE("GPL");
39463
39464 -static struct real_driver sx_real_driver = {
39465 +static const struct real_driver sx_real_driver = {
39466 sx_disable_tx_interrupts,
39467 sx_enable_tx_interrupts,
39468 sx_disable_rx_interrupts,
39469 diff -urNp linux-2.6.39/drivers/staging/generic_serial/vme_scc.c linux-2.6.39/drivers/staging/generic_serial/vme_scc.c
39470 --- linux-2.6.39/drivers/staging/generic_serial/vme_scc.c 2011-05-19 00:06:34.000000000 -0400
39471 +++ linux-2.6.39/drivers/staging/generic_serial/vme_scc.c 2011-05-22 19:36:32.000000000 -0400
39472 @@ -94,7 +94,7 @@ static struct scc_port scc_ports[2];
39473 * Interface from generic_serial.c back here
39474 *--------------------------------------------------------------------------*/
39475
39476 -static struct real_driver scc_real_driver = {
39477 +static const struct real_driver scc_real_driver = {
39478 scc_disable_tx_interrupts,
39479 scc_enable_tx_interrupts,
39480 scc_disable_rx_interrupts,
39481 diff -urNp linux-2.6.39/drivers/staging/gma500/psb_fb.c linux-2.6.39/drivers/staging/gma500/psb_fb.c
39482 --- linux-2.6.39/drivers/staging/gma500/psb_fb.c 2011-05-19 00:06:34.000000000 -0400
39483 +++ linux-2.6.39/drivers/staging/gma500/psb_fb.c 2011-05-22 19:36:32.000000000 -0400
39484 @@ -230,7 +230,7 @@ static void psbfb_vm_close(struct vm_are
39485 DRM_DEBUG("vm_close\n");
39486 }
39487
39488 -static struct vm_operations_struct psbfb_vm_ops = {
39489 +static const struct vm_operations_struct psbfb_vm_ops = {
39490 .fault = psbfb_vm_fault,
39491 .open = psbfb_vm_open,
39492 .close = psbfb_vm_close
39493 diff -urNp linux-2.6.39/drivers/staging/go7007/go7007-i2c.c linux-2.6.39/drivers/staging/go7007/go7007-i2c.c
39494 --- linux-2.6.39/drivers/staging/go7007/go7007-i2c.c 2011-05-19 00:06:34.000000000 -0400
39495 +++ linux-2.6.39/drivers/staging/go7007/go7007-i2c.c 2011-05-22 19:36:32.000000000 -0400
39496 @@ -198,7 +198,7 @@ static u32 go7007_functionality(struct i
39497 return I2C_FUNC_SMBUS_BYTE_DATA;
39498 }
39499
39500 -static struct i2c_algorithm go7007_algo = {
39501 +static const struct i2c_algorithm go7007_algo = {
39502 .smbus_xfer = go7007_smbus_xfer,
39503 .master_xfer = go7007_i2c_master_xfer,
39504 .functionality = go7007_functionality,
39505 diff -urNp linux-2.6.39/drivers/staging/go7007/go7007-usb.c linux-2.6.39/drivers/staging/go7007/go7007-usb.c
39506 --- linux-2.6.39/drivers/staging/go7007/go7007-usb.c 2011-05-19 00:06:34.000000000 -0400
39507 +++ linux-2.6.39/drivers/staging/go7007/go7007-usb.c 2011-05-22 19:36:32.000000000 -0400
39508 @@ -849,7 +849,7 @@ static int go7007_usb_send_firmware(stru
39509 &transferred, timeout);
39510 }
39511
39512 -static struct go7007_hpi_ops go7007_usb_ezusb_hpi_ops = {
39513 +static const struct go7007_hpi_ops go7007_usb_ezusb_hpi_ops = {
39514 .interface_reset = go7007_usb_interface_reset,
39515 .write_interrupt = go7007_usb_ezusb_write_interrupt,
39516 .read_interrupt = go7007_usb_read_interrupt,
39517 @@ -858,7 +858,7 @@ static struct go7007_hpi_ops go7007_usb_
39518 .send_firmware = go7007_usb_send_firmware,
39519 };
39520
39521 -static struct go7007_hpi_ops go7007_usb_onboard_hpi_ops = {
39522 +static const struct go7007_hpi_ops go7007_usb_onboard_hpi_ops = {
39523 .interface_reset = go7007_usb_interface_reset,
39524 .write_interrupt = go7007_usb_onboard_write_interrupt,
39525 .read_interrupt = go7007_usb_read_interrupt,
39526 @@ -950,7 +950,7 @@ static u32 go7007_usb_functionality(stru
39527 return (I2C_FUNC_SMBUS_EMUL) & ~I2C_FUNC_SMBUS_QUICK;
39528 }
39529
39530 -static struct i2c_algorithm go7007_usb_algo = {
39531 +static const struct i2c_algorithm go7007_usb_algo = {
39532 .master_xfer = go7007_usb_i2c_master_xfer,
39533 .functionality = go7007_usb_functionality,
39534 };
39535 diff -urNp linux-2.6.39/drivers/staging/go7007/go7007-v4l2.c linux-2.6.39/drivers/staging/go7007/go7007-v4l2.c
39536 --- linux-2.6.39/drivers/staging/go7007/go7007-v4l2.c 2011-05-19 00:06:34.000000000 -0400
39537 +++ linux-2.6.39/drivers/staging/go7007/go7007-v4l2.c 2011-05-22 19:36:32.000000000 -0400
39538 @@ -1672,7 +1672,7 @@ static int go7007_vm_fault(struct vm_are
39539 return 0;
39540 }
39541
39542 -static struct vm_operations_struct go7007_vm_ops = {
39543 +static const struct vm_operations_struct go7007_vm_ops = {
39544 .open = go7007_vm_open,
39545 .close = go7007_vm_close,
39546 .fault = go7007_vm_fault,
39547 diff -urNp linux-2.6.39/drivers/staging/go7007/saa7134-go7007.c linux-2.6.39/drivers/staging/go7007/saa7134-go7007.c
39548 --- linux-2.6.39/drivers/staging/go7007/saa7134-go7007.c 2011-05-19 00:06:34.000000000 -0400
39549 +++ linux-2.6.39/drivers/staging/go7007/saa7134-go7007.c 2011-05-22 19:36:32.000000000 -0400
39550 @@ -421,7 +421,7 @@ static int saa7134_go7007_send_command(s
39551
39552 }
39553
39554 -static struct go7007_hpi_ops saa7134_go7007_hpi_ops = {
39555 +static const struct go7007_hpi_ops saa7134_go7007_hpi_ops = {
39556 .interface_reset = saa7134_go7007_interface_reset,
39557 .write_interrupt = saa7134_go7007_write_interrupt,
39558 .read_interrupt = saa7134_go7007_read_interrupt,
39559 diff -urNp linux-2.6.39/drivers/staging/go7007/snd-go7007.c linux-2.6.39/drivers/staging/go7007/snd-go7007.c
39560 --- linux-2.6.39/drivers/staging/go7007/snd-go7007.c 2011-05-19 00:06:34.000000000 -0400
39561 +++ linux-2.6.39/drivers/staging/go7007/snd-go7007.c 2011-05-22 19:36:32.000000000 -0400
39562 @@ -204,7 +204,7 @@ static struct page *go7007_snd_pcm_page(
39563 return vmalloc_to_page(substream->runtime->dma_area + offset);
39564 }
39565
39566 -static struct snd_pcm_ops go7007_snd_capture_ops = {
39567 +static const struct snd_pcm_ops go7007_snd_capture_ops = {
39568 .open = go7007_snd_capture_open,
39569 .close = go7007_snd_capture_close,
39570 .ioctl = snd_pcm_lib_ioctl,
39571 @@ -227,7 +227,7 @@ static int go7007_snd_free(struct snd_de
39572 return 0;
39573 }
39574
39575 -static struct snd_device_ops go7007_snd_device_ops = {
39576 +static const struct snd_device_ops go7007_snd_device_ops = {
39577 .dev_free = go7007_snd_free,
39578 };
39579
39580 diff -urNp linux-2.6.39/drivers/staging/hv/channel.c linux-2.6.39/drivers/staging/hv/channel.c
39581 --- linux-2.6.39/drivers/staging/hv/channel.c 2011-05-19 00:06:34.000000000 -0400
39582 +++ linux-2.6.39/drivers/staging/hv/channel.c 2011-05-22 19:36:32.000000000 -0400
39583 @@ -509,8 +509,8 @@ int vmbus_establish_gpadl(struct vmbus_c
39584 unsigned long flags;
39585 int ret = 0;
39586
39587 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
39588 - atomic_inc(&vmbus_connection.next_gpadl_handle);
39589 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
39590 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
39591
39592 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
39593 if (ret)
39594 diff -urNp linux-2.6.39/drivers/staging/hv/hv.c linux-2.6.39/drivers/staging/hv/hv.c
39595 --- linux-2.6.39/drivers/staging/hv/hv.c 2011-05-19 00:06:34.000000000 -0400
39596 +++ linux-2.6.39/drivers/staging/hv/hv.c 2011-05-22 19:36:32.000000000 -0400
39597 @@ -163,7 +163,7 @@ static u64 do_hypercall(u64 control, voi
39598 u64 output_address = (output) ? virt_to_phys(output) : 0;
39599 u32 output_address_hi = output_address >> 32;
39600 u32 output_address_lo = output_address & 0xFFFFFFFF;
39601 - volatile void *hypercall_page = hv_context.hypercall_page;
39602 + volatile void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
39603
39604 DPRINT_DBG(VMBUS, "Hypercall <control %llx input %p output %p>",
39605 control, input, output);
39606 diff -urNp linux-2.6.39/drivers/staging/hv/rndis_filter.c linux-2.6.39/drivers/staging/hv/rndis_filter.c
39607 --- linux-2.6.39/drivers/staging/hv/rndis_filter.c 2011-05-19 00:06:34.000000000 -0400
39608 +++ linux-2.6.39/drivers/staging/hv/rndis_filter.c 2011-05-22 19:36:32.000000000 -0400
39609 @@ -49,7 +49,7 @@ struct rndis_device {
39610
39611 enum rndis_device_state state;
39612 u32 link_stat;
39613 - atomic_t new_req_id;
39614 + atomic_unchecked_t new_req_id;
39615
39616 spinlock_t request_lock;
39617 struct list_head req_list;
39618 @@ -144,7 +144,7 @@ static struct rndis_request *get_rndis_r
39619 * template
39620 */
39621 set = &rndis_msg->msg.set_req;
39622 - set->req_id = atomic_inc_return(&dev->new_req_id);
39623 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
39624
39625 /* Add to the request list */
39626 spin_lock_irqsave(&dev->request_lock, flags);
39627 @@ -709,7 +709,7 @@ static void rndis_filter_halt_device(str
39628
39629 /* Setup the rndis set */
39630 halt = &request->request_msg.msg.halt_req;
39631 - halt->req_id = atomic_inc_return(&dev->new_req_id);
39632 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
39633
39634 /* Ignore return since this msg is optional. */
39635 rndis_filter_send_request(dev, request);
39636 diff -urNp linux-2.6.39/drivers/staging/hv/vmbus_drv.c linux-2.6.39/drivers/staging/hv/vmbus_drv.c
39637 --- linux-2.6.39/drivers/staging/hv/vmbus_drv.c 2011-05-19 00:06:34.000000000 -0400
39638 +++ linux-2.6.39/drivers/staging/hv/vmbus_drv.c 2011-05-22 19:36:32.000000000 -0400
39639 @@ -661,14 +661,14 @@ int vmbus_child_device_register(struct h
39640 {
39641 int ret = 0;
39642
39643 - static atomic_t device_num = ATOMIC_INIT(0);
39644 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
39645
39646 DPRINT_DBG(VMBUS_DRV, "child device (%p) registering",
39647 child_device_obj);
39648
39649 /* Set the device name. Otherwise, device_register() will fail. */
39650 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
39651 - atomic_inc_return(&device_num));
39652 + atomic_inc_return_unchecked(&device_num));
39653
39654 /* The new device belongs to this bus */
39655 child_device_obj->device.bus = &vmbus_drv.bus; /* device->dev.bus; */
39656 diff -urNp linux-2.6.39/drivers/staging/hv/vmbus_private.h linux-2.6.39/drivers/staging/hv/vmbus_private.h
39657 --- linux-2.6.39/drivers/staging/hv/vmbus_private.h 2011-05-19 00:06:34.000000000 -0400
39658 +++ linux-2.6.39/drivers/staging/hv/vmbus_private.h 2011-05-22 19:36:32.000000000 -0400
39659 @@ -58,7 +58,7 @@ enum vmbus_connect_state {
39660 struct vmbus_connection {
39661 enum vmbus_connect_state conn_state;
39662
39663 - atomic_t next_gpadl_handle;
39664 + atomic_unchecked_t next_gpadl_handle;
39665
39666 /*
39667 * Represents channel interrupts. Each bit position represents a
39668 diff -urNp linux-2.6.39/drivers/staging/iio/ring_generic.h linux-2.6.39/drivers/staging/iio/ring_generic.h
39669 --- linux-2.6.39/drivers/staging/iio/ring_generic.h 2011-05-19 00:06:34.000000000 -0400
39670 +++ linux-2.6.39/drivers/staging/iio/ring_generic.h 2011-05-22 19:36:32.000000000 -0400
39671 @@ -134,7 +134,7 @@ struct iio_ring_buffer {
39672 struct iio_handler access_handler;
39673 struct iio_event_interface ev_int;
39674 struct iio_shared_ev_pointer shared_ev_pointer;
39675 - struct iio_ring_access_funcs access;
39676 + const struct iio_ring_access_funcs access;
39677 int (*preenable)(struct iio_dev *);
39678 int (*postenable)(struct iio_dev *);
39679 int (*predisable)(struct iio_dev *);
39680 diff -urNp linux-2.6.39/drivers/staging/intel_sst/intelmid_ctrl.c linux-2.6.39/drivers/staging/intel_sst/intelmid_ctrl.c
39681 --- linux-2.6.39/drivers/staging/intel_sst/intelmid_ctrl.c 2011-05-19 00:06:34.000000000 -0400
39682 +++ linux-2.6.39/drivers/staging/intel_sst/intelmid_ctrl.c 2011-05-22 19:36:32.000000000 -0400
39683 @@ -494,7 +494,7 @@ static int snd_intelmad_device_set(struc
39684 struct snd_intelmad *intelmaddata;
39685 struct snd_pmic_ops *scard_ops;
39686 int ret_val = 0, vendor, status;
39687 - struct intel_sst_pcm_control *pcm_control;
39688 + const struct intel_sst_pcm_control *pcm_control;
39689
39690 pr_debug("snd_intelmad_device_set called\n");
39691
39692 diff -urNp linux-2.6.39/drivers/staging/intel_sst/intel_sst_drv_interface.c linux-2.6.39/drivers/staging/intel_sst/intel_sst_drv_interface.c
39693 --- linux-2.6.39/drivers/staging/intel_sst/intel_sst_drv_interface.c 2011-05-19 00:06:34.000000000 -0400
39694 +++ linux-2.6.39/drivers/staging/intel_sst/intel_sst_drv_interface.c 2011-05-22 19:36:32.000000000 -0400
39695 @@ -470,7 +470,7 @@ int sst_device_control(int cmd, void *ar
39696 }
39697
39698
39699 -struct intel_sst_pcm_control pcm_ops = {
39700 +const struct intel_sst_pcm_control pcm_ops = {
39701 .open = sst_open_pcm_stream,
39702 .device_control = sst_device_control,
39703 .close = sst_close_pcm_stream,
39704 diff -urNp linux-2.6.39/drivers/staging/line6/capture.c linux-2.6.39/drivers/staging/line6/capture.c
39705 --- linux-2.6.39/drivers/staging/line6/capture.c 2011-05-19 00:06:34.000000000 -0400
39706 +++ linux-2.6.39/drivers/staging/line6/capture.c 2011-05-22 19:36:32.000000000 -0400
39707 @@ -378,7 +378,7 @@ snd_line6_capture_pointer(struct snd_pcm
39708 }
39709
39710 /* capture operators */
39711 -struct snd_pcm_ops snd_line6_capture_ops = {
39712 +const struct snd_pcm_ops snd_line6_capture_ops = {
39713 .open = snd_line6_capture_open,
39714 .close = snd_line6_capture_close,
39715 .ioctl = snd_pcm_lib_ioctl,
39716 diff -urNp linux-2.6.39/drivers/staging/line6/capture.h linux-2.6.39/drivers/staging/line6/capture.h
39717 --- linux-2.6.39/drivers/staging/line6/capture.h 2011-05-19 00:06:34.000000000 -0400
39718 +++ linux-2.6.39/drivers/staging/line6/capture.h 2011-05-22 19:36:32.000000000 -0400
39719 @@ -17,7 +17,7 @@
39720 #include "driver.h"
39721 #include "pcm.h"
39722
39723 -extern struct snd_pcm_ops snd_line6_capture_ops;
39724 +extern const struct snd_pcm_ops snd_line6_capture_ops;
39725
39726 extern void line6_capture_copy(struct snd_line6_pcm *line6pcm, char *fbuf,
39727 int fsize);
39728 diff -urNp linux-2.6.39/drivers/staging/line6/midi.c linux-2.6.39/drivers/staging/line6/midi.c
39729 --- linux-2.6.39/drivers/staging/line6/midi.c 2011-05-19 00:06:34.000000000 -0400
39730 +++ linux-2.6.39/drivers/staging/line6/midi.c 2011-05-22 19:36:32.000000000 -0400
39731 @@ -239,14 +239,14 @@ static void line6_midi_input_trigger(str
39732 line6->line6midi->substream_receive = 0;
39733 }
39734
39735 -static struct snd_rawmidi_ops line6_midi_output_ops = {
39736 +static const struct snd_rawmidi_ops line6_midi_output_ops = {
39737 .open = line6_midi_output_open,
39738 .close = line6_midi_output_close,
39739 .trigger = line6_midi_output_trigger,
39740 .drain = line6_midi_output_drain,
39741 };
39742
39743 -static struct snd_rawmidi_ops line6_midi_input_ops = {
39744 +static const struct snd_rawmidi_ops line6_midi_input_ops = {
39745 .open = line6_midi_input_open,
39746 .close = line6_midi_input_close,
39747 .trigger = line6_midi_input_trigger,
39748 @@ -373,7 +373,7 @@ static int snd_line6_midi_free(struct sn
39749 */
39750 int line6_init_midi(struct usb_line6 *line6)
39751 {
39752 - static struct snd_device_ops midi_ops = {
39753 + static const struct snd_device_ops midi_ops = {
39754 .dev_free = snd_line6_midi_free,
39755 };
39756
39757 diff -urNp linux-2.6.39/drivers/staging/line6/pcm.c linux-2.6.39/drivers/staging/line6/pcm.c
39758 --- linux-2.6.39/drivers/staging/line6/pcm.c 2011-05-19 00:06:34.000000000 -0400
39759 +++ linux-2.6.39/drivers/staging/line6/pcm.c 2011-05-22 19:36:32.000000000 -0400
39760 @@ -384,7 +384,7 @@ void line6_pcm_disconnect(struct snd_lin
39761 int line6_init_pcm(struct usb_line6 *line6,
39762 struct line6_pcm_properties *properties)
39763 {
39764 - static struct snd_device_ops pcm_ops = {
39765 + static const struct snd_device_ops pcm_ops = {
39766 .dev_free = snd_line6_pcm_free,
39767 };
39768
39769 diff -urNp linux-2.6.39/drivers/staging/line6/playback.c linux-2.6.39/drivers/staging/line6/playback.c
39770 --- linux-2.6.39/drivers/staging/line6/playback.c 2011-05-19 00:06:34.000000000 -0400
39771 +++ linux-2.6.39/drivers/staging/line6/playback.c 2011-05-22 19:36:32.000000000 -0400
39772 @@ -536,7 +536,7 @@ snd_line6_playback_pointer(struct snd_pc
39773 }
39774
39775 /* playback operators */
39776 -struct snd_pcm_ops snd_line6_playback_ops = {
39777 +const struct snd_pcm_ops snd_line6_playback_ops = {
39778 .open = snd_line6_playback_open,
39779 .close = snd_line6_playback_close,
39780 .ioctl = snd_pcm_lib_ioctl,
39781 diff -urNp linux-2.6.39/drivers/staging/line6/playback.h linux-2.6.39/drivers/staging/line6/playback.h
39782 --- linux-2.6.39/drivers/staging/line6/playback.h 2011-05-19 00:06:34.000000000 -0400
39783 +++ linux-2.6.39/drivers/staging/line6/playback.h 2011-05-22 19:36:32.000000000 -0400
39784 @@ -27,7 +27,7 @@
39785 */
39786 #define USE_CLEAR_BUFFER_WORKAROUND 1
39787
39788 -extern struct snd_pcm_ops snd_line6_playback_ops;
39789 +extern const struct snd_pcm_ops snd_line6_playback_ops;
39790
39791 extern int line6_create_audio_out_urbs(struct snd_line6_pcm *line6pcm);
39792 extern int line6_submit_audio_out_all_urbs(struct snd_line6_pcm *line6pcm);
39793 diff -urNp linux-2.6.39/drivers/staging/msm/staging-devices.c linux-2.6.39/drivers/staging/msm/staging-devices.c
39794 --- linux-2.6.39/drivers/staging/msm/staging-devices.c 2011-05-19 00:06:34.000000000 -0400
39795 +++ linux-2.6.39/drivers/staging/msm/staging-devices.c 2011-05-22 19:36:32.000000000 -0400
39796 @@ -211,7 +211,7 @@ static int msm_fb_lcdc_gpio_config(int o
39797 }
39798
39799
39800 -static struct lcdc_platform_data lcdc_pdata = {
39801 +static const struct lcdc_platform_data lcdc_pdata = {
39802 .lcdc_gpio_config = msm_fb_lcdc_gpio_config,
39803 };
39804
39805 diff -urNp linux-2.6.39/drivers/staging/octeon/ethernet.c linux-2.6.39/drivers/staging/octeon/ethernet.c
39806 --- linux-2.6.39/drivers/staging/octeon/ethernet.c 2011-05-19 00:06:34.000000000 -0400
39807 +++ linux-2.6.39/drivers/staging/octeon/ethernet.c 2011-05-22 19:36:32.000000000 -0400
39808 @@ -258,11 +258,11 @@ static struct net_device_stats *cvm_oct_
39809 * since the RX tasklet also increments it.
39810 */
39811 #ifdef CONFIG_64BIT
39812 - atomic64_add(rx_status.dropped_packets,
39813 - (atomic64_t *)&priv->stats.rx_dropped);
39814 + atomic64_add_unchecked(rx_status.dropped_packets,
39815 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
39816 #else
39817 - atomic_add(rx_status.dropped_packets,
39818 - (atomic_t *)&priv->stats.rx_dropped);
39819 + atomic_add_unchecked(rx_status.dropped_packets,
39820 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
39821 #endif
39822 }
39823
39824 diff -urNp linux-2.6.39/drivers/staging/octeon/ethernet-rx.c linux-2.6.39/drivers/staging/octeon/ethernet-rx.c
39825 --- linux-2.6.39/drivers/staging/octeon/ethernet-rx.c 2011-05-19 00:06:34.000000000 -0400
39826 +++ linux-2.6.39/drivers/staging/octeon/ethernet-rx.c 2011-05-22 19:36:32.000000000 -0400
39827 @@ -417,11 +417,11 @@ static int cvm_oct_napi_poll(struct napi
39828 /* Increment RX stats for virtual ports */
39829 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
39830 #ifdef CONFIG_64BIT
39831 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
39832 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
39833 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
39834 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
39835 #else
39836 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
39837 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
39838 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
39839 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
39840 #endif
39841 }
39842 netif_receive_skb(skb);
39843 @@ -433,9 +433,9 @@ static int cvm_oct_napi_poll(struct napi
39844 dev->name);
39845 */
39846 #ifdef CONFIG_64BIT
39847 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
39848 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
39849 #else
39850 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
39851 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
39852 #endif
39853 dev_kfree_skb_irq(skb);
39854 }
39855 diff -urNp linux-2.6.39/drivers/staging/olpc_dcon/olpc_dcon.c linux-2.6.39/drivers/staging/olpc_dcon/olpc_dcon.c
39856 --- linux-2.6.39/drivers/staging/olpc_dcon/olpc_dcon.c 2011-05-19 00:06:34.000000000 -0400
39857 +++ linux-2.6.39/drivers/staging/olpc_dcon/olpc_dcon.c 2011-05-22 19:36:32.000000000 -0400
39858 @@ -43,7 +43,7 @@ module_param(noinit, int, 0444);
39859 static int useaa = 1;
39860 module_param(useaa, int, 0444);
39861
39862 -static struct dcon_platform_data *pdata;
39863 +static const struct dcon_platform_data *pdata;
39864
39865 /* I2C structures */
39866
39867 diff -urNp linux-2.6.39/drivers/staging/olpc_dcon/olpc_dcon.h linux-2.6.39/drivers/staging/olpc_dcon/olpc_dcon.h
39868 --- linux-2.6.39/drivers/staging/olpc_dcon/olpc_dcon.h 2011-05-19 00:06:34.000000000 -0400
39869 +++ linux-2.6.39/drivers/staging/olpc_dcon/olpc_dcon.h 2011-05-22 19:36:32.000000000 -0400
39870 @@ -92,11 +92,11 @@ struct dcon_platform_data {
39871 extern irqreturn_t dcon_interrupt(int irq, void *id);
39872
39873 #ifdef CONFIG_FB_OLPC_DCON_1
39874 -extern struct dcon_platform_data dcon_pdata_xo_1;
39875 +extern const struct dcon_platform_data dcon_pdata_xo_1;
39876 #endif
39877
39878 #ifdef CONFIG_FB_OLPC_DCON_1_5
39879 -extern struct dcon_platform_data dcon_pdata_xo_1_5;
39880 +extern const struct dcon_platform_data dcon_pdata_xo_1_5;
39881 #endif
39882
39883 #endif
39884 diff -urNp linux-2.6.39/drivers/staging/olpc_dcon/olpc_dcon_xo_1_5.c linux-2.6.39/drivers/staging/olpc_dcon/olpc_dcon_xo_1_5.c
39885 --- linux-2.6.39/drivers/staging/olpc_dcon/olpc_dcon_xo_1_5.c 2011-05-19 00:06:34.000000000 -0400
39886 +++ linux-2.6.39/drivers/staging/olpc_dcon/olpc_dcon_xo_1_5.c 2011-05-22 19:36:32.000000000 -0400
39887 @@ -185,7 +185,7 @@ static u8 dcon_read_status_xo_1_5(void)
39888 return status;
39889 }
39890
39891 -struct dcon_platform_data dcon_pdata_xo_1_5 = {
39892 +const struct dcon_platform_data dcon_pdata_xo_1_5 = {
39893 .init = dcon_init_xo_1_5,
39894 .bus_stabilize_wiggle = dcon_wiggle_xo_1_5,
39895 .set_dconload = dcon_set_dconload_xo_1_5,
39896 diff -urNp linux-2.6.39/drivers/staging/olpc_dcon/olpc_dcon_xo_1.c linux-2.6.39/drivers/staging/olpc_dcon/olpc_dcon_xo_1.c
39897 --- linux-2.6.39/drivers/staging/olpc_dcon/olpc_dcon_xo_1.c 2011-05-19 00:06:34.000000000 -0400
39898 +++ linux-2.6.39/drivers/staging/olpc_dcon/olpc_dcon_xo_1.c 2011-05-22 19:36:32.000000000 -0400
39899 @@ -196,7 +196,7 @@ static u8 dcon_read_status_xo_1(void)
39900 return status;
39901 }
39902
39903 -struct dcon_platform_data dcon_pdata_xo_1 = {
39904 +const struct dcon_platform_data dcon_pdata_xo_1 = {
39905 .init = dcon_init_xo_1,
39906 .bus_stabilize_wiggle = dcon_wiggle_xo_1,
39907 .set_dconload = dcon_set_dconload_1,
39908 diff -urNp linux-2.6.39/drivers/staging/phison/phison.c linux-2.6.39/drivers/staging/phison/phison.c
39909 --- linux-2.6.39/drivers/staging/phison/phison.c 2011-05-19 00:06:34.000000000 -0400
39910 +++ linux-2.6.39/drivers/staging/phison/phison.c 2011-05-22 19:36:32.000000000 -0400
39911 @@ -43,7 +43,7 @@ static struct scsi_host_template phison_
39912 ATA_BMDMA_SHT(DRV_NAME),
39913 };
39914
39915 -static struct ata_port_operations phison_ops = {
39916 +static const struct ata_port_operations phison_ops = {
39917 .inherits = &ata_bmdma_port_ops,
39918 .prereset = phison_pre_reset,
39919 };
39920 diff -urNp linux-2.6.39/drivers/staging/pohmelfs/inode.c linux-2.6.39/drivers/staging/pohmelfs/inode.c
39921 --- linux-2.6.39/drivers/staging/pohmelfs/inode.c 2011-05-19 00:06:34.000000000 -0400
39922 +++ linux-2.6.39/drivers/staging/pohmelfs/inode.c 2011-05-22 19:36:32.000000000 -0400
39923 @@ -1855,7 +1855,7 @@ static int pohmelfs_fill_super(struct su
39924 mutex_init(&psb->mcache_lock);
39925 psb->mcache_root = RB_ROOT;
39926 psb->mcache_timeout = msecs_to_jiffies(5000);
39927 - atomic_long_set(&psb->mcache_gen, 0);
39928 + atomic_long_set_unchecked(&psb->mcache_gen, 0);
39929
39930 psb->trans_max_pages = 100;
39931
39932 @@ -1870,7 +1870,7 @@ static int pohmelfs_fill_super(struct su
39933 INIT_LIST_HEAD(&psb->crypto_ready_list);
39934 INIT_LIST_HEAD(&psb->crypto_active_list);
39935
39936 - atomic_set(&psb->trans_gen, 1);
39937 + atomic_set_unchecked(&psb->trans_gen, 1);
39938 atomic_long_set(&psb->total_inodes, 0);
39939
39940 mutex_init(&psb->state_lock);
39941 diff -urNp linux-2.6.39/drivers/staging/pohmelfs/mcache.c linux-2.6.39/drivers/staging/pohmelfs/mcache.c
39942 --- linux-2.6.39/drivers/staging/pohmelfs/mcache.c 2011-05-19 00:06:34.000000000 -0400
39943 +++ linux-2.6.39/drivers/staging/pohmelfs/mcache.c 2011-05-22 19:36:32.000000000 -0400
39944 @@ -121,7 +121,7 @@ struct pohmelfs_mcache *pohmelfs_mcache_
39945 m->data = data;
39946 m->start = start;
39947 m->size = size;
39948 - m->gen = atomic_long_inc_return(&psb->mcache_gen);
39949 + m->gen = atomic_long_inc_return_unchecked(&psb->mcache_gen);
39950
39951 mutex_lock(&psb->mcache_lock);
39952 err = pohmelfs_mcache_insert(psb, m);
39953 diff -urNp linux-2.6.39/drivers/staging/pohmelfs/netfs.h linux-2.6.39/drivers/staging/pohmelfs/netfs.h
39954 --- linux-2.6.39/drivers/staging/pohmelfs/netfs.h 2011-05-19 00:06:34.000000000 -0400
39955 +++ linux-2.6.39/drivers/staging/pohmelfs/netfs.h 2011-05-22 19:36:32.000000000 -0400
39956 @@ -571,14 +571,14 @@ struct pohmelfs_config;
39957 struct pohmelfs_sb {
39958 struct rb_root mcache_root;
39959 struct mutex mcache_lock;
39960 - atomic_long_t mcache_gen;
39961 + atomic_long_unchecked_t mcache_gen;
39962 unsigned long mcache_timeout;
39963
39964 unsigned int idx;
39965
39966 unsigned int trans_retries;
39967
39968 - atomic_t trans_gen;
39969 + atomic_unchecked_t trans_gen;
39970
39971 unsigned int crypto_attached_size;
39972 unsigned int crypto_align_size;
39973 diff -urNp linux-2.6.39/drivers/staging/pohmelfs/trans.c linux-2.6.39/drivers/staging/pohmelfs/trans.c
39974 --- linux-2.6.39/drivers/staging/pohmelfs/trans.c 2011-05-19 00:06:34.000000000 -0400
39975 +++ linux-2.6.39/drivers/staging/pohmelfs/trans.c 2011-05-22 19:36:32.000000000 -0400
39976 @@ -492,7 +492,7 @@ int netfs_trans_finish(struct netfs_tran
39977 int err;
39978 struct netfs_cmd *cmd = t->iovec.iov_base;
39979
39980 - t->gen = atomic_inc_return(&psb->trans_gen);
39981 + t->gen = atomic_inc_return_unchecked(&psb->trans_gen);
39982
39983 cmd->size = t->iovec.iov_len - sizeof(struct netfs_cmd) +
39984 t->attached_size + t->attached_pages * sizeof(struct netfs_cmd);
39985 diff -urNp linux-2.6.39/drivers/staging/rtl8192u/ieee80211/proc.c linux-2.6.39/drivers/staging/rtl8192u/ieee80211/proc.c
39986 --- linux-2.6.39/drivers/staging/rtl8192u/ieee80211/proc.c 2011-05-19 00:06:34.000000000 -0400
39987 +++ linux-2.6.39/drivers/staging/rtl8192u/ieee80211/proc.c 2011-05-22 19:36:32.000000000 -0400
39988 @@ -87,7 +87,7 @@ static int c_show(struct seq_file *m, vo
39989 return 0;
39990 }
39991
39992 -static struct seq_operations crypto_seq_ops = {
39993 +static const struct seq_operations crypto_seq_ops = {
39994 .start = c_start,
39995 .next = c_next,
39996 .stop = c_stop,
39997 @@ -99,7 +99,7 @@ static int crypto_info_open(struct inode
39998 return seq_open(file, &crypto_seq_ops);
39999 }
40000
40001 -static struct file_operations proc_crypto_ops = {
40002 +static const struct file_operations proc_crypto_ops = {
40003 .open = crypto_info_open,
40004 .read = seq_read,
40005 .llseek = seq_lseek,
40006 diff -urNp linux-2.6.39/drivers/staging/rtl8712/rtl871x_io.h linux-2.6.39/drivers/staging/rtl8712/rtl871x_io.h
40007 --- linux-2.6.39/drivers/staging/rtl8712/rtl871x_io.h 2011-05-19 00:06:34.000000000 -0400
40008 +++ linux-2.6.39/drivers/staging/rtl8712/rtl871x_io.h 2011-05-22 19:36:32.000000000 -0400
40009 @@ -107,7 +107,7 @@ struct intf_hdl {
40010 void (*intf_hdl_unload)(u8 *priv);
40011 void (*intf_hdl_open)(u8 *priv);
40012 void (*intf_hdl_close)(u8 *priv);
40013 - struct _io_ops io_ops;
40014 + const struct _io_ops io_ops;
40015 };
40016
40017 struct reg_protocol_rd {
40018 diff -urNp linux-2.6.39/drivers/staging/solo6x10/g723.c linux-2.6.39/drivers/staging/solo6x10/g723.c
40019 --- linux-2.6.39/drivers/staging/solo6x10/g723.c 2011-05-19 00:06:34.000000000 -0400
40020 +++ linux-2.6.39/drivers/staging/solo6x10/g723.c 2011-05-22 19:36:32.000000000 -0400
40021 @@ -237,7 +237,7 @@ static int snd_solo_pcm_copy(struct snd_
40022 return 0;
40023 }
40024
40025 -static struct snd_pcm_ops snd_solo_pcm_ops = {
40026 +static const struct snd_pcm_ops snd_solo_pcm_ops = {
40027 .open = snd_solo_pcm_open,
40028 .close = snd_solo_pcm_close,
40029 .ioctl = snd_pcm_lib_ioctl,
40030 @@ -334,7 +334,7 @@ static int solo_snd_pcm_init(struct solo
40031
40032 int solo_g723_init(struct solo_dev *solo_dev)
40033 {
40034 - static struct snd_device_ops ops = { NULL };
40035 + static const struct snd_device_ops ops = { NULL };
40036 struct snd_card *card;
40037 struct snd_kcontrol_new kctl;
40038 char name[32];
40039 diff -urNp linux-2.6.39/drivers/staging/spectra/ffsport.c linux-2.6.39/drivers/staging/spectra/ffsport.c
40040 --- linux-2.6.39/drivers/staging/spectra/ffsport.c 2011-05-19 00:06:34.000000000 -0400
40041 +++ linux-2.6.39/drivers/staging/spectra/ffsport.c 2011-05-22 19:36:32.000000000 -0400
40042 @@ -604,7 +604,7 @@ int GLOB_SBD_unlocked_ioctl(struct block
40043 return ret;
40044 }
40045
40046 -static struct block_device_operations GLOB_SBD_ops = {
40047 +static const struct block_device_operations GLOB_SBD_ops = {
40048 .owner = THIS_MODULE,
40049 .open = GLOB_SBD_open,
40050 .release = GLOB_SBD_release,
40051 diff -urNp linux-2.6.39/drivers/staging/tm6000/tm6000-alsa.c linux-2.6.39/drivers/staging/tm6000/tm6000-alsa.c
40052 --- linux-2.6.39/drivers/staging/tm6000/tm6000-alsa.c 2011-05-19 00:06:34.000000000 -0400
40053 +++ linux-2.6.39/drivers/staging/tm6000/tm6000-alsa.c 2011-05-22 19:36:32.000000000 -0400
40054 @@ -380,7 +380,7 @@ static snd_pcm_uframes_t snd_tm6000_poin
40055 /*
40056 * operators
40057 */
40058 -static struct snd_pcm_ops snd_tm6000_pcm_ops = {
40059 +static const struct snd_pcm_ops snd_tm6000_pcm_ops = {
40060 .open = snd_tm6000_pcm_open,
40061 .close = snd_tm6000_close,
40062 .ioctl = snd_pcm_lib_ioctl,
40063 diff -urNp linux-2.6.39/drivers/staging/tty/istallion.c linux-2.6.39/drivers/staging/tty/istallion.c
40064 --- linux-2.6.39/drivers/staging/tty/istallion.c 2011-05-19 00:06:34.000000000 -0400
40065 +++ linux-2.6.39/drivers/staging/tty/istallion.c 2011-05-22 20:49:07.000000000 -0400
40066 @@ -186,7 +186,6 @@ static struct ktermios stli_deftermios
40067 * re-used for each stats call.
40068 */
40069 static comstats_t stli_comstats;
40070 -static combrd_t stli_brdstats;
40071 static struct asystats stli_cdkstats;
40072
40073 /*****************************************************************************/
40074 @@ -4003,6 +4002,7 @@ out:
40075
40076 static int stli_getbrdstats(combrd_t __user *bp)
40077 {
40078 + combrd_t stli_brdstats;
40079 struct stlibrd *brdp;
40080 unsigned int i;
40081
40082 @@ -4226,6 +4226,8 @@ static int stli_getportstruct(struct stl
40083 struct stliport stli_dummyport;
40084 struct stliport *portp;
40085
40086 + pax_track_stack();
40087 +
40088 if (copy_from_user(&stli_dummyport, arg, sizeof(struct stliport)))
40089 return -EFAULT;
40090 portp = stli_getport(stli_dummyport.brdnr, stli_dummyport.panelnr,
40091 @@ -4248,6 +4250,8 @@ static int stli_getbrdstruct(struct stli
40092 struct stlibrd stli_dummybrd;
40093 struct stlibrd *brdp;
40094
40095 + pax_track_stack();
40096 +
40097 if (copy_from_user(&stli_dummybrd, arg, sizeof(struct stlibrd)))
40098 return -EFAULT;
40099 if (stli_dummybrd.brdnr >= STL_MAXBRDS)
40100 diff -urNp linux-2.6.39/drivers/staging/tty/stallion.c linux-2.6.39/drivers/staging/tty/stallion.c
40101 --- linux-2.6.39/drivers/staging/tty/stallion.c 2011-05-19 00:06:34.000000000 -0400
40102 +++ linux-2.6.39/drivers/staging/tty/stallion.c 2011-05-22 19:36:32.000000000 -0400
40103 @@ -2406,6 +2406,8 @@ static int stl_getportstruct(struct stlp
40104 struct stlport stl_dummyport;
40105 struct stlport *portp;
40106
40107 + pax_track_stack();
40108 +
40109 if (copy_from_user(&stl_dummyport, arg, sizeof(struct stlport)))
40110 return -EFAULT;
40111 portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr,
40112 diff -urNp linux-2.6.39/drivers/staging/usbip/vhci.h linux-2.6.39/drivers/staging/usbip/vhci.h
40113 --- linux-2.6.39/drivers/staging/usbip/vhci.h 2011-05-19 00:06:34.000000000 -0400
40114 +++ linux-2.6.39/drivers/staging/usbip/vhci.h 2011-05-22 19:36:32.000000000 -0400
40115 @@ -92,7 +92,7 @@ struct vhci_hcd {
40116 unsigned resuming:1;
40117 unsigned long re_timeout;
40118
40119 - atomic_t seqnum;
40120 + atomic_unchecked_t seqnum;
40121
40122 /*
40123 * NOTE:
40124 diff -urNp linux-2.6.39/drivers/staging/usbip/vhci_hcd.c linux-2.6.39/drivers/staging/usbip/vhci_hcd.c
40125 --- linux-2.6.39/drivers/staging/usbip/vhci_hcd.c 2011-05-19 00:06:34.000000000 -0400
40126 +++ linux-2.6.39/drivers/staging/usbip/vhci_hcd.c 2011-05-22 19:36:32.000000000 -0400
40127 @@ -536,7 +536,7 @@ static void vhci_tx_urb(struct urb *urb)
40128 return;
40129 }
40130
40131 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
40132 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
40133 if (priv->seqnum == 0xffff)
40134 usbip_uinfo("seqnum max\n");
40135
40136 @@ -795,7 +795,7 @@ static int vhci_urb_dequeue(struct usb_h
40137 return -ENOMEM;
40138 }
40139
40140 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
40141 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
40142 if (unlink->seqnum == 0xffff)
40143 usbip_uinfo("seqnum max\n");
40144
40145 @@ -992,7 +992,7 @@ static int vhci_start(struct usb_hcd *hc
40146 vdev->rhport = rhport;
40147 }
40148
40149 - atomic_set(&vhci->seqnum, 0);
40150 + atomic_set_unchecked(&vhci->seqnum, 0);
40151 spin_lock_init(&vhci->lock);
40152
40153
40154 diff -urNp linux-2.6.39/drivers/staging/usbip/vhci_rx.c linux-2.6.39/drivers/staging/usbip/vhci_rx.c
40155 --- linux-2.6.39/drivers/staging/usbip/vhci_rx.c 2011-05-19 00:06:34.000000000 -0400
40156 +++ linux-2.6.39/drivers/staging/usbip/vhci_rx.c 2011-05-22 19:36:32.000000000 -0400
40157 @@ -81,7 +81,7 @@ static void vhci_recv_ret_submit(struct
40158 usbip_uerr("cannot find a urb of seqnum %u\n",
40159 pdu->base.seqnum);
40160 usbip_uinfo("max seqnum %d\n",
40161 - atomic_read(&the_controller->seqnum));
40162 + atomic_read_unchecked(&the_controller->seqnum));
40163 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
40164 return;
40165 }
40166 diff -urNp linux-2.6.39/drivers/staging/vme/devices/vme_user.c linux-2.6.39/drivers/staging/vme/devices/vme_user.c
40167 --- linux-2.6.39/drivers/staging/vme/devices/vme_user.c 2011-05-19 00:06:34.000000000 -0400
40168 +++ linux-2.6.39/drivers/staging/vme/devices/vme_user.c 2011-05-22 19:36:32.000000000 -0400
40169 @@ -138,7 +138,7 @@ static long vme_user_unlocked_ioctl(stru
40170 static int __devinit vme_user_probe(struct device *, int, int);
40171 static int __devexit vme_user_remove(struct device *, int, int);
40172
40173 -static struct file_operations vme_user_fops = {
40174 +static const struct file_operations vme_user_fops = {
40175 .open = vme_user_open,
40176 .release = vme_user_release,
40177 .read = vme_user_read,
40178 diff -urNp linux-2.6.39/drivers/staging/westbridge/astoria/block/cyasblkdev_block.c linux-2.6.39/drivers/staging/westbridge/astoria/block/cyasblkdev_block.c
40179 --- linux-2.6.39/drivers/staging/westbridge/astoria/block/cyasblkdev_block.c 2011-05-19 00:06:34.000000000 -0400
40180 +++ linux-2.6.39/drivers/staging/westbridge/astoria/block/cyasblkdev_block.c 2011-05-22 19:36:32.000000000 -0400
40181 @@ -426,7 +426,7 @@ int cyasblkdev_revalidate_disk(struct ge
40182
40183
40184 /*standard block device driver interface */
40185 -static struct block_device_operations cyasblkdev_bdops = {
40186 +static const struct block_device_operations cyasblkdev_bdops = {
40187 .open = cyasblkdev_blk_open,
40188 .release = cyasblkdev_blk_release,
40189 .ioctl = cyasblkdev_blk_ioctl,
40190 diff -urNp linux-2.6.39/drivers/staging/wlags49_h2/wl_netdev.c linux-2.6.39/drivers/staging/wlags49_h2/wl_netdev.c
40191 --- linux-2.6.39/drivers/staging/wlags49_h2/wl_netdev.c 2011-05-19 00:06:34.000000000 -0400
40192 +++ linux-2.6.39/drivers/staging/wlags49_h2/wl_netdev.c 2011-05-22 19:36:32.000000000 -0400
40193 @@ -474,7 +474,7 @@ static void wl_get_drvinfo(struct net_de
40194 }
40195 } // wl_get_drvinfo
40196
40197 -static struct ethtool_ops wl_ethtool_ops = {
40198 +static const struct ethtool_ops wl_ethtool_ops = {
40199 .get_drvinfo = wl_get_drvinfo,
40200 .get_link = ethtool_op_get_link,
40201 };
40202 diff -urNp linux-2.6.39/drivers/staging/wlan-ng/hfa384x_usb.c linux-2.6.39/drivers/staging/wlan-ng/hfa384x_usb.c
40203 --- linux-2.6.39/drivers/staging/wlan-ng/hfa384x_usb.c 2011-05-19 00:06:34.000000000 -0400
40204 +++ linux-2.6.39/drivers/staging/wlan-ng/hfa384x_usb.c 2011-05-22 19:36:32.000000000 -0400
40205 @@ -671,7 +671,7 @@ struct usbctlx_cmd_completor {
40206 hfa384x_cmdresult_t *result;
40207 };
40208
40209 -static inline int usbctlx_cmd_completor_fn(struct usbctlx_completor *head)
40210 +static inline int usbctlx_cmd_completor_fn(const struct usbctlx_completor *head)
40211 {
40212 struct usbctlx_cmd_completor *complete;
40213
40214 @@ -705,7 +705,7 @@ struct usbctlx_rrid_completor {
40215 unsigned int riddatalen;
40216 };
40217
40218 -static int usbctlx_rrid_completor_fn(struct usbctlx_completor *head)
40219 +static int usbctlx_rrid_completor_fn(const struct usbctlx_completor *head)
40220 {
40221 struct usbctlx_rrid_completor *complete;
40222 hfa384x_rridresult_t rridresult;
40223 @@ -768,7 +768,7 @@ struct usbctlx_rmem_completor {
40224 };
40225 typedef struct usbctlx_rmem_completor usbctlx_rmem_completor_t;
40226
40227 -static int usbctlx_rmem_completor_fn(struct usbctlx_completor *head)
40228 +static int usbctlx_rmem_completor_fn(const struct usbctlx_completor *head)
40229 {
40230 usbctlx_rmem_completor_t *complete = (usbctlx_rmem_completor_t *) head;
40231
40232 diff -urNp linux-2.6.39/drivers/staging/zcache/tmem.c linux-2.6.39/drivers/staging/zcache/tmem.c
40233 --- linux-2.6.39/drivers/staging/zcache/tmem.c 2011-05-19 00:06:34.000000000 -0400
40234 +++ linux-2.6.39/drivers/staging/zcache/tmem.c 2011-05-22 19:36:32.000000000 -0400
40235 @@ -39,7 +39,7 @@
40236 * A tmem host implementation must use this function to register callbacks
40237 * for memory allocation.
40238 */
40239 -static struct tmem_hostops tmem_hostops;
40240 +static const struct tmem_hostops tmem_hostops;
40241
40242 static void tmem_objnode_tree_init(void);
40243
40244 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_h
40245 * A tmem host implementation must use this function to register
40246 * callbacks for a page-accessible memory (PAM) implementation
40247 */
40248 -static struct tmem_pamops tmem_pamops;
40249 +static const struct tmem_pamops tmem_pamops;
40250
40251 void tmem_register_pamops(struct tmem_pamops *m)
40252 {
40253 diff -urNp linux-2.6.39/drivers/staging/zcache/zcache.c linux-2.6.39/drivers/staging/zcache/zcache.c
40254 --- linux-2.6.39/drivers/staging/zcache/zcache.c 2011-05-19 00:06:34.000000000 -0400
40255 +++ linux-2.6.39/drivers/staging/zcache/zcache.c 2011-05-22 19:36:32.000000000 -0400
40256 @@ -882,7 +882,7 @@ static void zcache_obj_free(struct tmem_
40257 kmem_cache_free(zcache_obj_cache, obj);
40258 }
40259
40260 -static struct tmem_hostops zcache_hostops = {
40261 +static const struct tmem_hostops zcache_hostops = {
40262 .obj_alloc = zcache_obj_alloc,
40263 .obj_free = zcache_obj_free,
40264 .objnode_alloc = zcache_objnode_alloc,
40265 @@ -987,7 +987,7 @@ static void zcache_pampd_free(void *pamp
40266 }
40267 }
40268
40269 -static struct tmem_pamops zcache_pamops = {
40270 +static const struct tmem_pamops zcache_pamops = {
40271 .create = zcache_pampd_create,
40272 .get_data = zcache_pampd_get_data,
40273 .free = zcache_pampd_free,
40274 diff -urNp linux-2.6.39/drivers/target/target_core_alua.c linux-2.6.39/drivers/target/target_core_alua.c
40275 --- linux-2.6.39/drivers/target/target_core_alua.c 2011-05-19 00:06:34.000000000 -0400
40276 +++ linux-2.6.39/drivers/target/target_core_alua.c 2011-05-22 19:36:32.000000000 -0400
40277 @@ -675,6 +675,8 @@ static int core_alua_update_tpg_primary_
40278 char path[ALUA_METADATA_PATH_LEN];
40279 int len;
40280
40281 + pax_track_stack();
40282 +
40283 memset(path, 0, ALUA_METADATA_PATH_LEN);
40284
40285 len = snprintf(md_buf, tg_pt_gp->tg_pt_gp_md_buf_len,
40286 @@ -938,6 +940,8 @@ static int core_alua_update_tpg_secondar
40287 char path[ALUA_METADATA_PATH_LEN], wwn[ALUA_SECONDARY_METADATA_WWN_LEN];
40288 int len;
40289
40290 + pax_track_stack();
40291 +
40292 memset(path, 0, ALUA_METADATA_PATH_LEN);
40293 memset(wwn, 0, ALUA_SECONDARY_METADATA_WWN_LEN);
40294
40295 diff -urNp linux-2.6.39/drivers/target/target_core_cdb.c linux-2.6.39/drivers/target/target_core_cdb.c
40296 --- linux-2.6.39/drivers/target/target_core_cdb.c 2011-05-19 00:06:34.000000000 -0400
40297 +++ linux-2.6.39/drivers/target/target_core_cdb.c 2011-05-22 19:36:32.000000000 -0400
40298 @@ -838,6 +838,8 @@ target_emulate_modesense(struct se_cmd *
40299 int length = 0;
40300 unsigned char buf[SE_MODE_PAGE_BUF];
40301
40302 + pax_track_stack();
40303 +
40304 memset(buf, 0, SE_MODE_PAGE_BUF);
40305
40306 switch (cdb[2] & 0x3f) {
40307 diff -urNp linux-2.6.39/drivers/target/target_core_configfs.c linux-2.6.39/drivers/target/target_core_configfs.c
40308 --- linux-2.6.39/drivers/target/target_core_configfs.c 2011-05-19 00:06:34.000000000 -0400
40309 +++ linux-2.6.39/drivers/target/target_core_configfs.c 2011-05-22 19:36:32.000000000 -0400
40310 @@ -1280,6 +1280,8 @@ static ssize_t target_core_dev_pr_show_a
40311 ssize_t len = 0;
40312 int reg_count = 0, prf_isid;
40313
40314 + pax_track_stack();
40315 +
40316 if (!(su_dev->se_dev_ptr))
40317 return -ENODEV;
40318
40319 @@ -2682,7 +2684,7 @@ static void target_core_alua_drop_tg_pt_
40320 config_item_put(item);
40321 }
40322
40323 -static struct configfs_group_operations target_core_alua_tg_pt_gps_group_ops = {
40324 +static const struct configfs_group_operations target_core_alua_tg_pt_gps_group_ops = {
40325 .make_group = &target_core_alua_create_tg_pt_gp,
40326 .drop_item = &target_core_alua_drop_tg_pt_gp,
40327 };
40328 @@ -2726,7 +2728,7 @@ static void target_core_stat_rmdir(
40329 return;
40330 }
40331
40332 -static struct configfs_group_operations target_core_stat_group_ops = {
40333 +static const struct configfs_group_operations target_core_stat_group_ops = {
40334 .make_group = &target_core_stat_mkdir,
40335 .drop_item = &target_core_stat_rmdir,
40336 };
40337 @@ -2939,7 +2941,7 @@ static void target_core_drop_subdev(
40338 mutex_unlock(&hba->hba_access_mutex);
40339 }
40340
40341 -static struct configfs_group_operations target_core_hba_group_ops = {
40342 +static const struct configfs_group_operations target_core_hba_group_ops = {
40343 .make_group = target_core_make_subdev,
40344 .drop_item = target_core_drop_subdev,
40345 };
40346 @@ -3117,7 +3119,7 @@ static void target_core_call_delhbafromt
40347 config_item_put(item);
40348 }
40349
40350 -static struct configfs_group_operations target_core_group_ops = {
40351 +static const struct configfs_group_operations target_core_group_ops = {
40352 .make_group = target_core_call_addhbatotarget,
40353 .drop_item = target_core_call_delhbafromtarget,
40354 };
40355 diff -urNp linux-2.6.39/drivers/target/target_core_fabric_configfs.c linux-2.6.39/drivers/target/target_core_fabric_configfs.c
40356 --- linux-2.6.39/drivers/target/target_core_fabric_configfs.c 2011-05-19 00:06:34.000000000 -0400
40357 +++ linux-2.6.39/drivers/target/target_core_fabric_configfs.c 2011-05-22 19:36:32.000000000 -0400
40358 @@ -1174,7 +1174,7 @@ static void target_fabric_drop_wwn(
40359 config_item_put(item);
40360 }
40361
40362 -static struct configfs_group_operations target_fabric_wwn_group_ops = {
40363 +static const struct configfs_group_operations target_fabric_wwn_group_ops = {
40364 .make_group = target_fabric_make_wwn,
40365 .drop_item = target_fabric_drop_wwn,
40366 };
40367 diff -urNp linux-2.6.39/drivers/target/target_core_pr.c linux-2.6.39/drivers/target/target_core_pr.c
40368 --- linux-2.6.39/drivers/target/target_core_pr.c 2011-05-19 00:06:34.000000000 -0400
40369 +++ linux-2.6.39/drivers/target/target_core_pr.c 2011-05-22 19:36:32.000000000 -0400
40370 @@ -918,6 +918,8 @@ static int __core_scsi3_check_aptpl_regi
40371 unsigned char t_port[PR_APTPL_MAX_TPORT_LEN];
40372 u16 tpgt;
40373
40374 + pax_track_stack();
40375 +
40376 memset(i_port, 0, PR_APTPL_MAX_IPORT_LEN);
40377 memset(t_port, 0, PR_APTPL_MAX_TPORT_LEN);
40378 /*
40379 @@ -1861,6 +1863,8 @@ static int __core_scsi3_update_aptpl_buf
40380 ssize_t len = 0;
40381 int reg_count = 0;
40382
40383 + pax_track_stack();
40384 +
40385 memset(buf, 0, pr_aptpl_buf_len);
40386 /*
40387 * Called to clear metadata once APTPL has been deactivated.
40388 @@ -1983,6 +1987,8 @@ static int __core_scsi3_write_aptpl_to_f
40389 char path[512];
40390 int ret;
40391
40392 + pax_track_stack();
40393 +
40394 memset(iov, 0, sizeof(struct iovec));
40395 memset(path, 0, 512);
40396
40397 diff -urNp linux-2.6.39/drivers/target/target_core_tmr.c linux-2.6.39/drivers/target/target_core_tmr.c
40398 --- linux-2.6.39/drivers/target/target_core_tmr.c 2011-05-19 00:06:34.000000000 -0400
40399 +++ linux-2.6.39/drivers/target/target_core_tmr.c 2011-05-22 19:36:32.000000000 -0400
40400 @@ -262,7 +262,7 @@ int core_tmr_lun_reset(
40401 CMD_TFO(cmd)->get_task_tag(cmd), cmd->pr_res_key,
40402 T_TASK(cmd)->t_task_cdbs,
40403 atomic_read(&T_TASK(cmd)->t_task_cdbs_left),
40404 - atomic_read(&T_TASK(cmd)->t_task_cdbs_sent),
40405 + atomic_read_unchecked(&T_TASK(cmd)->t_task_cdbs_sent),
40406 atomic_read(&T_TASK(cmd)->t_transport_active),
40407 atomic_read(&T_TASK(cmd)->t_transport_stop),
40408 atomic_read(&T_TASK(cmd)->t_transport_sent));
40409 @@ -304,7 +304,7 @@ int core_tmr_lun_reset(
40410 DEBUG_LR("LUN_RESET: got t_transport_active = 1 for"
40411 " task: %p, t_fe_count: %d dev: %p\n", task,
40412 fe_count, dev);
40413 - atomic_set(&T_TASK(cmd)->t_transport_aborted, 1);
40414 + atomic_set_unchecked(&T_TASK(cmd)->t_transport_aborted, 1);
40415 spin_unlock_irqrestore(&T_TASK(cmd)->t_state_lock,
40416 flags);
40417 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
40418 @@ -314,7 +314,7 @@ int core_tmr_lun_reset(
40419 }
40420 DEBUG_LR("LUN_RESET: Got t_transport_active = 0 for task: %p,"
40421 " t_fe_count: %d dev: %p\n", task, fe_count, dev);
40422 - atomic_set(&T_TASK(cmd)->t_transport_aborted, 1);
40423 + atomic_set_unchecked(&T_TASK(cmd)->t_transport_aborted, 1);
40424 spin_unlock_irqrestore(&T_TASK(cmd)->t_state_lock, flags);
40425 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
40426
40427 diff -urNp linux-2.6.39/drivers/target/target_core_transport.c linux-2.6.39/drivers/target/target_core_transport.c
40428 --- linux-2.6.39/drivers/target/target_core_transport.c 2011-05-19 00:06:34.000000000 -0400
40429 +++ linux-2.6.39/drivers/target/target_core_transport.c 2011-05-22 19:36:32.000000000 -0400
40430 @@ -1675,7 +1675,7 @@ struct se_device *transport_add_device_t
40431
40432 dev->queue_depth = dev_limits->queue_depth;
40433 atomic_set(&dev->depth_left, dev->queue_depth);
40434 - atomic_set(&dev->dev_ordered_id, 0);
40435 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
40436
40437 se_dev_set_default_attribs(dev, dev_limits);
40438
40439 @@ -1876,7 +1876,7 @@ static int transport_check_alloc_task_at
40440 * Used to determine when ORDERED commands should go from
40441 * Dormant to Active status.
40442 */
40443 - cmd->se_ordered_id = atomic_inc_return(&SE_DEV(cmd)->dev_ordered_id);
40444 + cmd->se_ordered_id = atomic_inc_return_unchecked(&SE_DEV(cmd)->dev_ordered_id);
40445 smp_mb__after_atomic_inc();
40446 DEBUG_STA("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
40447 cmd->se_ordered_id, cmd->sam_task_attr,
40448 @@ -2156,7 +2156,7 @@ static void transport_generic_request_fa
40449 " t_transport_active: %d t_transport_stop: %d"
40450 " t_transport_sent: %d\n", T_TASK(cmd)->t_task_cdbs,
40451 atomic_read(&T_TASK(cmd)->t_task_cdbs_left),
40452 - atomic_read(&T_TASK(cmd)->t_task_cdbs_sent),
40453 + atomic_read_unchecked(&T_TASK(cmd)->t_task_cdbs_sent),
40454 atomic_read(&T_TASK(cmd)->t_task_cdbs_ex_left),
40455 atomic_read(&T_TASK(cmd)->t_transport_active),
40456 atomic_read(&T_TASK(cmd)->t_transport_stop),
40457 @@ -2660,9 +2660,9 @@ check_depth:
40458 spin_lock_irqsave(&T_TASK(cmd)->t_state_lock, flags);
40459 atomic_set(&task->task_active, 1);
40460 atomic_set(&task->task_sent, 1);
40461 - atomic_inc(&T_TASK(cmd)->t_task_cdbs_sent);
40462 + atomic_inc_unchecked(&T_TASK(cmd)->t_task_cdbs_sent);
40463
40464 - if (atomic_read(&T_TASK(cmd)->t_task_cdbs_sent) ==
40465 + if (atomic_read_unchecked(&T_TASK(cmd)->t_task_cdbs_sent) ==
40466 T_TASK(cmd)->t_task_cdbs)
40467 atomic_set(&cmd->transport_sent, 1);
40468
40469 @@ -5549,7 +5549,7 @@ static void transport_generic_wait_for_t
40470 atomic_set(&T_TASK(cmd)->transport_lun_stop, 0);
40471 }
40472 if (!atomic_read(&T_TASK(cmd)->t_transport_active) ||
40473 - atomic_read(&T_TASK(cmd)->t_transport_aborted))
40474 + atomic_read_unchecked(&T_TASK(cmd)->t_transport_aborted))
40475 goto remove;
40476
40477 atomic_set(&T_TASK(cmd)->t_transport_stop, 1);
40478 @@ -5778,7 +5778,7 @@ int transport_check_aborted_status(struc
40479 {
40480 int ret = 0;
40481
40482 - if (atomic_read(&T_TASK(cmd)->t_transport_aborted) != 0) {
40483 + if (atomic_read_unchecked(&T_TASK(cmd)->t_transport_aborted) != 0) {
40484 if (!(send_status) ||
40485 (cmd->se_cmd_flags & SCF_SENT_DELAYED_TAS))
40486 return 1;
40487 @@ -5806,7 +5806,7 @@ void transport_send_task_abort(struct se
40488 */
40489 if (cmd->data_direction == DMA_TO_DEVICE) {
40490 if (CMD_TFO(cmd)->write_pending_status(cmd) != 0) {
40491 - atomic_inc(&T_TASK(cmd)->t_transport_aborted);
40492 + atomic_inc_unchecked(&T_TASK(cmd)->t_transport_aborted);
40493 smp_mb__after_atomic_inc();
40494 cmd->scsi_status = SAM_STAT_TASK_ABORTED;
40495 transport_new_cmd_failure(cmd);
40496 @@ -5930,7 +5930,7 @@ static void transport_processing_shutdow
40497 CMD_TFO(cmd)->get_task_tag(cmd),
40498 T_TASK(cmd)->t_task_cdbs,
40499 atomic_read(&T_TASK(cmd)->t_task_cdbs_left),
40500 - atomic_read(&T_TASK(cmd)->t_task_cdbs_sent),
40501 + atomic_read_unchecked(&T_TASK(cmd)->t_task_cdbs_sent),
40502 atomic_read(&T_TASK(cmd)->t_transport_active),
40503 atomic_read(&T_TASK(cmd)->t_transport_stop),
40504 atomic_read(&T_TASK(cmd)->t_transport_sent));
40505 diff -urNp linux-2.6.39/drivers/telephony/ixj.c linux-2.6.39/drivers/telephony/ixj.c
40506 --- linux-2.6.39/drivers/telephony/ixj.c 2011-05-19 00:06:34.000000000 -0400
40507 +++ linux-2.6.39/drivers/telephony/ixj.c 2011-05-22 19:36:32.000000000 -0400
40508 @@ -4976,6 +4976,8 @@ static int ixj_daa_cid_read(IXJ *j)
40509 bool mContinue;
40510 char *pIn, *pOut;
40511
40512 + pax_track_stack();
40513 +
40514 if (!SCI_Prepare(j))
40515 return 0;
40516
40517 diff -urNp linux-2.6.39/drivers/tty/hvc/hvc_console.h linux-2.6.39/drivers/tty/hvc/hvc_console.h
40518 --- linux-2.6.39/drivers/tty/hvc/hvc_console.h 2011-05-19 00:06:34.000000000 -0400
40519 +++ linux-2.6.39/drivers/tty/hvc/hvc_console.h 2011-05-22 19:36:32.000000000 -0400
40520 @@ -82,6 +82,7 @@ extern int hvc_instantiate(uint32_t vter
40521 /* register a vterm for hvc tty operation (module_init or hotplug add) */
40522 extern struct hvc_struct * hvc_alloc(uint32_t vtermno, int data,
40523 const struct hv_ops *ops, int outbuf_size);
40524 +
40525 /* remove a vterm from hvc tty operation (module_exit or hotplug remove) */
40526 extern int hvc_remove(struct hvc_struct *hp);
40527
40528 diff -urNp linux-2.6.39/drivers/tty/hvc/hvc_iucv.c linux-2.6.39/drivers/tty/hvc/hvc_iucv.c
40529 --- linux-2.6.39/drivers/tty/hvc/hvc_iucv.c 2011-05-19 00:06:34.000000000 -0400
40530 +++ linux-2.6.39/drivers/tty/hvc/hvc_iucv.c 2011-05-22 19:36:32.000000000 -0400
40531 @@ -1203,7 +1203,7 @@ static int param_get_vmidfilter(char *bu
40532
40533 #define param_check_vmidfilter(name, p) __param_check(name, p, void)
40534
40535 -static struct kernel_param_ops param_ops_vmidfilter = {
40536 +static const struct kernel_param_ops param_ops_vmidfilter = {
40537 .set = param_set_vmidfilter,
40538 .get = param_get_vmidfilter,
40539 };
40540 diff -urNp linux-2.6.39/drivers/tty/hvc/hvcs.c linux-2.6.39/drivers/tty/hvc/hvcs.c
40541 --- linux-2.6.39/drivers/tty/hvc/hvcs.c 2011-05-19 00:06:34.000000000 -0400
40542 +++ linux-2.6.39/drivers/tty/hvc/hvcs.c 2011-05-22 19:36:32.000000000 -0400
40543 @@ -83,6 +83,7 @@
40544 #include <asm/hvcserver.h>
40545 #include <asm/uaccess.h>
40546 #include <asm/vio.h>
40547 +#include <asm/local.h>
40548
40549 /*
40550 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
40551 @@ -270,7 +271,7 @@ struct hvcs_struct {
40552 unsigned int index;
40553
40554 struct tty_struct *tty;
40555 - int open_count;
40556 + local_t open_count;
40557
40558 /*
40559 * Used to tell the driver kernel_thread what operations need to take
40560 @@ -422,7 +423,7 @@ static ssize_t hvcs_vterm_state_store(st
40561
40562 spin_lock_irqsave(&hvcsd->lock, flags);
40563
40564 - if (hvcsd->open_count > 0) {
40565 + if (local_read(&hvcsd->open_count) > 0) {
40566 spin_unlock_irqrestore(&hvcsd->lock, flags);
40567 printk(KERN_INFO "HVCS: vterm state unchanged. "
40568 "The hvcs device node is still in use.\n");
40569 @@ -1145,7 +1146,7 @@ static int hvcs_open(struct tty_struct *
40570 if ((retval = hvcs_partner_connect(hvcsd)))
40571 goto error_release;
40572
40573 - hvcsd->open_count = 1;
40574 + local_set(&hvcsd->open_count, 1);
40575 hvcsd->tty = tty;
40576 tty->driver_data = hvcsd;
40577
40578 @@ -1179,7 +1180,7 @@ fast_open:
40579
40580 spin_lock_irqsave(&hvcsd->lock, flags);
40581 kref_get(&hvcsd->kref);
40582 - hvcsd->open_count++;
40583 + local_inc(&hvcsd->open_count);
40584 hvcsd->todo_mask |= HVCS_SCHED_READ;
40585 spin_unlock_irqrestore(&hvcsd->lock, flags);
40586
40587 @@ -1223,7 +1224,7 @@ static void hvcs_close(struct tty_struct
40588 hvcsd = tty->driver_data;
40589
40590 spin_lock_irqsave(&hvcsd->lock, flags);
40591 - if (--hvcsd->open_count == 0) {
40592 + if (local_dec_and_test(&hvcsd->open_count)) {
40593
40594 vio_disable_interrupts(hvcsd->vdev);
40595
40596 @@ -1249,10 +1250,10 @@ static void hvcs_close(struct tty_struct
40597 free_irq(irq, hvcsd);
40598 kref_put(&hvcsd->kref, destroy_hvcs_struct);
40599 return;
40600 - } else if (hvcsd->open_count < 0) {
40601 + } else if (local_read(&hvcsd->open_count) < 0) {
40602 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
40603 " is missmanaged.\n",
40604 - hvcsd->vdev->unit_address, hvcsd->open_count);
40605 + hvcsd->vdev->unit_address, local_read(&hvcsd->open_count));
40606 }
40607
40608 spin_unlock_irqrestore(&hvcsd->lock, flags);
40609 @@ -1268,7 +1269,7 @@ static void hvcs_hangup(struct tty_struc
40610
40611 spin_lock_irqsave(&hvcsd->lock, flags);
40612 /* Preserve this so that we know how many kref refs to put */
40613 - temp_open_count = hvcsd->open_count;
40614 + temp_open_count = local_read(&hvcsd->open_count);
40615
40616 /*
40617 * Don't kref put inside the spinlock because the destruction
40618 @@ -1283,7 +1284,7 @@ static void hvcs_hangup(struct tty_struc
40619 hvcsd->tty->driver_data = NULL;
40620 hvcsd->tty = NULL;
40621
40622 - hvcsd->open_count = 0;
40623 + local_set(&hvcsd->open_count, 0);
40624
40625 /* This will drop any buffered data on the floor which is OK in a hangup
40626 * scenario. */
40627 @@ -1354,7 +1355,7 @@ static int hvcs_write(struct tty_struct
40628 * the middle of a write operation? This is a crummy place to do this
40629 * but we want to keep it all in the spinlock.
40630 */
40631 - if (hvcsd->open_count <= 0) {
40632 + if (local_read(&hvcsd->open_count) <= 0) {
40633 spin_unlock_irqrestore(&hvcsd->lock, flags);
40634 return -ENODEV;
40635 }
40636 @@ -1428,7 +1429,7 @@ static int hvcs_write_room(struct tty_st
40637 {
40638 struct hvcs_struct *hvcsd = tty->driver_data;
40639
40640 - if (!hvcsd || hvcsd->open_count <= 0)
40641 + if (!hvcsd || local_read(&hvcsd->open_count) <= 0)
40642 return 0;
40643
40644 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
40645 diff -urNp linux-2.6.39/drivers/tty/hvc/hvc_xen.c linux-2.6.39/drivers/tty/hvc/hvc_xen.c
40646 --- linux-2.6.39/drivers/tty/hvc/hvc_xen.c 2011-05-19 00:06:34.000000000 -0400
40647 +++ linux-2.6.39/drivers/tty/hvc/hvc_xen.c 2011-05-22 19:36:32.000000000 -0400
40648 @@ -123,7 +123,7 @@ static int domU_read_console(uint32_t vt
40649 return recv;
40650 }
40651
40652 -static struct hv_ops domU_hvc_ops = {
40653 +static const struct hv_ops domU_hvc_ops = {
40654 .get_chars = domU_read_console,
40655 .put_chars = domU_write_console,
40656 .notifier_add = notifier_add_irq,
40657 @@ -149,7 +149,7 @@ static int dom0_write_console(uint32_t v
40658 return len;
40659 }
40660
40661 -static struct hv_ops dom0_hvc_ops = {
40662 +static const struct hv_ops dom0_hvc_ops = {
40663 .get_chars = dom0_read_console,
40664 .put_chars = dom0_write_console,
40665 .notifier_add = notifier_add_irq,
40666 @@ -160,7 +160,7 @@ static struct hv_ops dom0_hvc_ops = {
40667 static int __init xen_hvc_init(void)
40668 {
40669 struct hvc_struct *hp;
40670 - struct hv_ops *ops;
40671 + const struct hv_ops *ops;
40672
40673 if (!xen_pv_domain())
40674 return -ENODEV;
40675 @@ -205,7 +205,7 @@ static void __exit xen_hvc_fini(void)
40676
40677 static int xen_cons_init(void)
40678 {
40679 - struct hv_ops *ops;
40680 + const struct hv_ops *ops;
40681
40682 if (!xen_pv_domain())
40683 return 0;
40684 diff -urNp linux-2.6.39/drivers/tty/ipwireless/tty.c linux-2.6.39/drivers/tty/ipwireless/tty.c
40685 --- linux-2.6.39/drivers/tty/ipwireless/tty.c 2011-05-19 00:06:34.000000000 -0400
40686 +++ linux-2.6.39/drivers/tty/ipwireless/tty.c 2011-05-22 19:36:32.000000000 -0400
40687 @@ -29,6 +29,7 @@
40688 #include <linux/tty_driver.h>
40689 #include <linux/tty_flip.h>
40690 #include <linux/uaccess.h>
40691 +#include <asm/local.h>
40692
40693 #include "tty.h"
40694 #include "network.h"
40695 @@ -51,7 +52,7 @@ struct ipw_tty {
40696 int tty_type;
40697 struct ipw_network *network;
40698 struct tty_struct *linux_tty;
40699 - int open_count;
40700 + local_t open_count;
40701 unsigned int control_lines;
40702 struct mutex ipw_tty_mutex;
40703 int tx_bytes_queued;
40704 @@ -127,10 +128,10 @@ static int ipw_open(struct tty_struct *l
40705 mutex_unlock(&tty->ipw_tty_mutex);
40706 return -ENODEV;
40707 }
40708 - if (tty->open_count == 0)
40709 + if (local_read(&tty->open_count) == 0)
40710 tty->tx_bytes_queued = 0;
40711
40712 - tty->open_count++;
40713 + local_inc(&tty->open_count);
40714
40715 tty->linux_tty = linux_tty;
40716 linux_tty->driver_data = tty;
40717 @@ -146,9 +147,7 @@ static int ipw_open(struct tty_struct *l
40718
40719 static void do_ipw_close(struct ipw_tty *tty)
40720 {
40721 - tty->open_count--;
40722 -
40723 - if (tty->open_count == 0) {
40724 + if (local_dec_return(&tty->open_count) == 0) {
40725 struct tty_struct *linux_tty = tty->linux_tty;
40726
40727 if (linux_tty != NULL) {
40728 @@ -169,7 +168,7 @@ static void ipw_hangup(struct tty_struct
40729 return;
40730
40731 mutex_lock(&tty->ipw_tty_mutex);
40732 - if (tty->open_count == 0) {
40733 + if (local_read(&tty->open_count) == 0) {
40734 mutex_unlock(&tty->ipw_tty_mutex);
40735 return;
40736 }
40737 @@ -198,7 +197,7 @@ void ipwireless_tty_received(struct ipw_
40738 return;
40739 }
40740
40741 - if (!tty->open_count) {
40742 + if (!local_read(&tty->open_count)) {
40743 mutex_unlock(&tty->ipw_tty_mutex);
40744 return;
40745 }
40746 @@ -240,7 +239,7 @@ static int ipw_write(struct tty_struct *
40747 return -ENODEV;
40748
40749 mutex_lock(&tty->ipw_tty_mutex);
40750 - if (!tty->open_count) {
40751 + if (!local_read(&tty->open_count)) {
40752 mutex_unlock(&tty->ipw_tty_mutex);
40753 return -EINVAL;
40754 }
40755 @@ -280,7 +279,7 @@ static int ipw_write_room(struct tty_str
40756 if (!tty)
40757 return -ENODEV;
40758
40759 - if (!tty->open_count)
40760 + if (!local_read(&tty->open_count))
40761 return -EINVAL;
40762
40763 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
40764 @@ -322,7 +321,7 @@ static int ipw_chars_in_buffer(struct tt
40765 if (!tty)
40766 return 0;
40767
40768 - if (!tty->open_count)
40769 + if (!local_read(&tty->open_count))
40770 return 0;
40771
40772 return tty->tx_bytes_queued;
40773 @@ -403,7 +402,7 @@ static int ipw_tiocmget(struct tty_struc
40774 if (!tty)
40775 return -ENODEV;
40776
40777 - if (!tty->open_count)
40778 + if (!local_read(&tty->open_count))
40779 return -EINVAL;
40780
40781 return get_control_lines(tty);
40782 @@ -419,7 +418,7 @@ ipw_tiocmset(struct tty_struct *linux_tt
40783 if (!tty)
40784 return -ENODEV;
40785
40786 - if (!tty->open_count)
40787 + if (!local_read(&tty->open_count))
40788 return -EINVAL;
40789
40790 return set_control_lines(tty, set, clear);
40791 @@ -433,7 +432,7 @@ static int ipw_ioctl(struct tty_struct *
40792 if (!tty)
40793 return -ENODEV;
40794
40795 - if (!tty->open_count)
40796 + if (!local_read(&tty->open_count))
40797 return -EINVAL;
40798
40799 /* FIXME: Exactly how is the tty object locked here .. */
40800 @@ -582,7 +581,7 @@ void ipwireless_tty_free(struct ipw_tty
40801 against a parallel ioctl etc */
40802 mutex_lock(&ttyj->ipw_tty_mutex);
40803 }
40804 - while (ttyj->open_count)
40805 + while (local_read(&ttyj->open_count))
40806 do_ipw_close(ttyj);
40807 ipwireless_disassociate_network_ttys(network,
40808 ttyj->channel_idx);
40809 diff -urNp linux-2.6.39/drivers/tty/mxser.c linux-2.6.39/drivers/tty/mxser.c
40810 --- linux-2.6.39/drivers/tty/mxser.c 2011-05-19 00:06:34.000000000 -0400
40811 +++ linux-2.6.39/drivers/tty/mxser.c 2011-05-22 19:36:32.000000000 -0400
40812 @@ -2340,7 +2340,7 @@ static const struct tty_operations mxser
40813 .get_icount = mxser_get_icount,
40814 };
40815
40816 -struct tty_port_operations mxser_port_ops = {
40817 +const struct tty_port_operations mxser_port_ops = {
40818 .carrier_raised = mxser_carrier_raised,
40819 .dtr_rts = mxser_dtr_rts,
40820 .activate = mxser_activate,
40821 diff -urNp linux-2.6.39/drivers/tty/n_gsm.c linux-2.6.39/drivers/tty/n_gsm.c
40822 --- linux-2.6.39/drivers/tty/n_gsm.c 2011-05-19 00:06:34.000000000 -0400
40823 +++ linux-2.6.39/drivers/tty/n_gsm.c 2011-05-22 19:36:32.000000000 -0400
40824 @@ -1588,7 +1588,7 @@ static struct gsm_dlci *gsm_dlci_alloc(s
40825 return NULL;
40826 spin_lock_init(&dlci->lock);
40827 dlci->fifo = &dlci->_fifo;
40828 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
40829 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
40830 kfree(dlci);
40831 return NULL;
40832 }
40833 diff -urNp linux-2.6.39/drivers/tty/n_tty.c linux-2.6.39/drivers/tty/n_tty.c
40834 --- linux-2.6.39/drivers/tty/n_tty.c 2011-05-19 00:06:34.000000000 -0400
40835 +++ linux-2.6.39/drivers/tty/n_tty.c 2011-05-22 19:36:32.000000000 -0400
40836 @@ -2122,6 +2122,7 @@ void n_tty_inherit_ops(struct tty_ldisc_
40837 {
40838 *ops = tty_ldisc_N_TTY;
40839 ops->owner = NULL;
40840 - ops->refcount = ops->flags = 0;
40841 + atomic_set(&ops->refcount, 0);
40842 + ops->flags = 0;
40843 }
40844 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
40845 diff -urNp linux-2.6.39/drivers/tty/pty.c linux-2.6.39/drivers/tty/pty.c
40846 --- linux-2.6.39/drivers/tty/pty.c 2011-05-19 00:06:34.000000000 -0400
40847 +++ linux-2.6.39/drivers/tty/pty.c 2011-05-22 19:36:32.000000000 -0400
40848 @@ -699,7 +699,18 @@ out:
40849 return retval;
40850 }
40851
40852 -static struct file_operations ptmx_fops;
40853 +static const struct file_operations ptmx_fops = {
40854 + .llseek = no_llseek,
40855 + .read = tty_read,
40856 + .write = tty_write,
40857 + .poll = tty_poll,
40858 + .unlocked_ioctl = tty_ioctl,
40859 + .compat_ioctl = tty_compat_ioctl,
40860 + .open = ptmx_open,
40861 + .release = tty_release,
40862 + .fasync = tty_fasync,
40863 +};
40864 +
40865
40866 static void __init unix98_pty_init(void)
40867 {
40868 @@ -752,10 +763,6 @@ static void __init unix98_pty_init(void)
40869
40870 register_sysctl_table(pty_root_table);
40871
40872 - /* Now create the /dev/ptmx special device */
40873 - tty_default_fops(&ptmx_fops);
40874 - ptmx_fops.open = ptmx_open;
40875 -
40876 cdev_init(&ptmx_cdev, &ptmx_fops);
40877 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
40878 register_chrdev_region(MKDEV(TTYAUX_MAJOR, 2), 1, "/dev/ptmx") < 0)
40879 diff -urNp linux-2.6.39/drivers/tty/rocket.c linux-2.6.39/drivers/tty/rocket.c
40880 --- linux-2.6.39/drivers/tty/rocket.c 2011-05-19 00:06:34.000000000 -0400
40881 +++ linux-2.6.39/drivers/tty/rocket.c 2011-05-22 19:36:32.000000000 -0400
40882 @@ -1277,6 +1277,8 @@ static int get_ports(struct r_port *info
40883 struct rocket_ports tmp;
40884 int board;
40885
40886 + pax_track_stack();
40887 +
40888 if (!retports)
40889 return -EFAULT;
40890 memset(&tmp, 0, sizeof (tmp));
40891 diff -urNp linux-2.6.39/drivers/tty/serial/21285.c linux-2.6.39/drivers/tty/serial/21285.c
40892 --- linux-2.6.39/drivers/tty/serial/21285.c 2011-05-19 00:06:34.000000000 -0400
40893 +++ linux-2.6.39/drivers/tty/serial/21285.c 2011-05-22 19:36:32.000000000 -0400
40894 @@ -340,7 +340,7 @@ static int serial21285_verify_port(struc
40895 return ret;
40896 }
40897
40898 -static struct uart_ops serial21285_ops = {
40899 +static const struct uart_ops serial21285_ops = {
40900 .tx_empty = serial21285_tx_empty,
40901 .get_mctrl = serial21285_get_mctrl,
40902 .set_mctrl = serial21285_set_mctrl,
40903 diff -urNp linux-2.6.39/drivers/tty/serial/8250.c linux-2.6.39/drivers/tty/serial/8250.c
40904 --- linux-2.6.39/drivers/tty/serial/8250.c 2011-05-19 00:06:34.000000000 -0400
40905 +++ linux-2.6.39/drivers/tty/serial/8250.c 2011-05-22 19:36:32.000000000 -0400
40906 @@ -2708,7 +2708,7 @@ serial8250_type(struct uart_port *port)
40907 return uart_config[type].name;
40908 }
40909
40910 -static struct uart_ops serial8250_pops = {
40911 +static const struct uart_ops serial8250_pops = {
40912 .tx_empty = serial8250_tx_empty,
40913 .set_mctrl = serial8250_set_mctrl,
40914 .get_mctrl = serial8250_get_mctrl,
40915 diff -urNp linux-2.6.39/drivers/tty/serial/altera_jtaguart.c linux-2.6.39/drivers/tty/serial/altera_jtaguart.c
40916 --- linux-2.6.39/drivers/tty/serial/altera_jtaguart.c 2011-05-19 00:06:34.000000000 -0400
40917 +++ linux-2.6.39/drivers/tty/serial/altera_jtaguart.c 2011-05-22 19:36:32.000000000 -0400
40918 @@ -281,7 +281,7 @@ static int altera_jtaguart_verify_port(s
40919 /*
40920 * Define the basic serial functions we support.
40921 */
40922 -static struct uart_ops altera_jtaguart_ops = {
40923 +static const struct uart_ops altera_jtaguart_ops = {
40924 .tx_empty = altera_jtaguart_tx_empty,
40925 .get_mctrl = altera_jtaguart_get_mctrl,
40926 .set_mctrl = altera_jtaguart_set_mctrl,
40927 diff -urNp linux-2.6.39/drivers/tty/serial/altera_uart.c linux-2.6.39/drivers/tty/serial/altera_uart.c
40928 --- linux-2.6.39/drivers/tty/serial/altera_uart.c 2011-05-19 00:06:34.000000000 -0400
40929 +++ linux-2.6.39/drivers/tty/serial/altera_uart.c 2011-05-22 19:36:32.000000000 -0400
40930 @@ -380,7 +380,7 @@ static int altera_uart_verify_port(struc
40931 /*
40932 * Define the basic serial functions we support.
40933 */
40934 -static struct uart_ops altera_uart_ops = {
40935 +static const struct uart_ops altera_uart_ops = {
40936 .tx_empty = altera_uart_tx_empty,
40937 .get_mctrl = altera_uart_get_mctrl,
40938 .set_mctrl = altera_uart_set_mctrl,
40939 diff -urNp linux-2.6.39/drivers/tty/serial/amba-pl010.c linux-2.6.39/drivers/tty/serial/amba-pl010.c
40940 --- linux-2.6.39/drivers/tty/serial/amba-pl010.c 2011-05-19 00:06:34.000000000 -0400
40941 +++ linux-2.6.39/drivers/tty/serial/amba-pl010.c 2011-05-22 19:36:32.000000000 -0400
40942 @@ -529,7 +529,7 @@ static int pl010_verify_port(struct uart
40943 return ret;
40944 }
40945
40946 -static struct uart_ops amba_pl010_pops = {
40947 +static const struct uart_ops amba_pl010_pops = {
40948 .tx_empty = pl010_tx_empty,
40949 .set_mctrl = pl010_set_mctrl,
40950 .get_mctrl = pl010_get_mctrl,
40951 diff -urNp linux-2.6.39/drivers/tty/serial/amba-pl011.c linux-2.6.39/drivers/tty/serial/amba-pl011.c
40952 --- linux-2.6.39/drivers/tty/serial/amba-pl011.c 2011-05-19 00:06:34.000000000 -0400
40953 +++ linux-2.6.39/drivers/tty/serial/amba-pl011.c 2011-05-22 19:36:32.000000000 -0400
40954 @@ -1581,7 +1581,7 @@ static int pl010_verify_port(struct uart
40955 return ret;
40956 }
40957
40958 -static struct uart_ops amba_pl011_pops = {
40959 +static const struct uart_ops amba_pl011_pops = {
40960 .tx_empty = pl01x_tx_empty,
40961 .set_mctrl = pl011_set_mctrl,
40962 .get_mctrl = pl01x_get_mctrl,
40963 diff -urNp linux-2.6.39/drivers/tty/serial/apbuart.c linux-2.6.39/drivers/tty/serial/apbuart.c
40964 --- linux-2.6.39/drivers/tty/serial/apbuart.c 2011-05-19 00:06:34.000000000 -0400
40965 +++ linux-2.6.39/drivers/tty/serial/apbuart.c 2011-05-22 19:36:32.000000000 -0400
40966 @@ -328,7 +328,7 @@ static int apbuart_verify_port(struct ua
40967 return ret;
40968 }
40969
40970 -static struct uart_ops grlib_apbuart_ops = {
40971 +static const struct uart_ops grlib_apbuart_ops = {
40972 .tx_empty = apbuart_tx_empty,
40973 .set_mctrl = apbuart_set_mctrl,
40974 .get_mctrl = apbuart_get_mctrl,
40975 diff -urNp linux-2.6.39/drivers/tty/serial/atmel_serial.c linux-2.6.39/drivers/tty/serial/atmel_serial.c
40976 --- linux-2.6.39/drivers/tty/serial/atmel_serial.c 2011-05-19 00:06:34.000000000 -0400
40977 +++ linux-2.6.39/drivers/tty/serial/atmel_serial.c 2011-05-22 19:36:32.000000000 -0400
40978 @@ -1382,7 +1382,7 @@ atmel_ioctl(struct uart_port *port, unsi
40979
40980
40981
40982 -static struct uart_ops atmel_pops = {
40983 +static const struct uart_ops atmel_pops = {
40984 .tx_empty = atmel_tx_empty,
40985 .set_mctrl = atmel_set_mctrl,
40986 .get_mctrl = atmel_get_mctrl,
40987 diff -urNp linux-2.6.39/drivers/tty/serial/bcm63xx_uart.c linux-2.6.39/drivers/tty/serial/bcm63xx_uart.c
40988 --- linux-2.6.39/drivers/tty/serial/bcm63xx_uart.c 2011-05-19 00:06:34.000000000 -0400
40989 +++ linux-2.6.39/drivers/tty/serial/bcm63xx_uart.c 2011-05-22 19:36:32.000000000 -0400
40990 @@ -636,7 +636,7 @@ static int bcm_uart_verify_port(struct u
40991 }
40992
40993 /* serial core callbacks */
40994 -static struct uart_ops bcm_uart_ops = {
40995 +static const struct uart_ops bcm_uart_ops = {
40996 .tx_empty = bcm_uart_tx_empty,
40997 .get_mctrl = bcm_uart_get_mctrl,
40998 .set_mctrl = bcm_uart_set_mctrl,
40999 diff -urNp linux-2.6.39/drivers/tty/serial/bfin_5xx.c linux-2.6.39/drivers/tty/serial/bfin_5xx.c
41000 --- linux-2.6.39/drivers/tty/serial/bfin_5xx.c 2011-05-19 00:06:34.000000000 -0400
41001 +++ linux-2.6.39/drivers/tty/serial/bfin_5xx.c 2011-05-22 19:36:32.000000000 -0400
41002 @@ -1036,7 +1036,7 @@ static int bfin_kgdboc_port_startup(stru
41003 }
41004 #endif
41005
41006 -static struct uart_ops bfin_serial_pops = {
41007 +static const struct uart_ops bfin_serial_pops = {
41008 .tx_empty = bfin_serial_tx_empty,
41009 .set_mctrl = bfin_serial_set_mctrl,
41010 .get_mctrl = bfin_serial_get_mctrl,
41011 diff -urNp linux-2.6.39/drivers/tty/serial/bfin_sport_uart.c linux-2.6.39/drivers/tty/serial/bfin_sport_uart.c
41012 --- linux-2.6.39/drivers/tty/serial/bfin_sport_uart.c 2011-05-19 00:06:34.000000000 -0400
41013 +++ linux-2.6.39/drivers/tty/serial/bfin_sport_uart.c 2011-05-22 19:36:32.000000000 -0400
41014 @@ -571,7 +571,7 @@ static void sport_set_termios(struct uar
41015 spin_unlock_irqrestore(&up->port.lock, flags);
41016 }
41017
41018 -struct uart_ops sport_uart_ops = {
41019 +const struct uart_ops sport_uart_ops = {
41020 .tx_empty = sport_tx_empty,
41021 .set_mctrl = sport_set_mctrl,
41022 .get_mctrl = sport_get_mctrl,
41023 diff -urNp linux-2.6.39/drivers/tty/serial/clps711x.c linux-2.6.39/drivers/tty/serial/clps711x.c
41024 --- linux-2.6.39/drivers/tty/serial/clps711x.c 2011-05-19 00:06:34.000000000 -0400
41025 +++ linux-2.6.39/drivers/tty/serial/clps711x.c 2011-05-22 19:36:32.000000000 -0400
41026 @@ -380,7 +380,7 @@ static int clps711xuart_request_port(str
41027 return 0;
41028 }
41029
41030 -static struct uart_ops clps711x_pops = {
41031 +static const struct uart_ops clps711x_pops = {
41032 .tx_empty = clps711xuart_tx_empty,
41033 .set_mctrl = clps711xuart_set_mctrl_null,
41034 .get_mctrl = clps711xuart_get_mctrl,
41035 diff -urNp linux-2.6.39/drivers/tty/serial/cpm_uart/cpm_uart_core.c linux-2.6.39/drivers/tty/serial/cpm_uart/cpm_uart_core.c
41036 --- linux-2.6.39/drivers/tty/serial/cpm_uart/cpm_uart_core.c 2011-05-19 00:06:34.000000000 -0400
41037 +++ linux-2.6.39/drivers/tty/serial/cpm_uart/cpm_uart_core.c 2011-05-22 19:36:32.000000000 -0400
41038 @@ -1099,7 +1099,7 @@ static void cpm_put_poll_char(struct uar
41039 }
41040 #endif /* CONFIG_CONSOLE_POLL */
41041
41042 -static struct uart_ops cpm_uart_pops = {
41043 +static const struct uart_ops cpm_uart_pops = {
41044 .tx_empty = cpm_uart_tx_empty,
41045 .set_mctrl = cpm_uart_set_mctrl,
41046 .get_mctrl = cpm_uart_get_mctrl,
41047 diff -urNp linux-2.6.39/drivers/tty/serial/dz.c linux-2.6.39/drivers/tty/serial/dz.c
41048 --- linux-2.6.39/drivers/tty/serial/dz.c 2011-05-19 00:06:34.000000000 -0400
41049 +++ linux-2.6.39/drivers/tty/serial/dz.c 2011-05-22 19:36:32.000000000 -0400
41050 @@ -746,7 +746,7 @@ static int dz_verify_port(struct uart_po
41051 return ret;
41052 }
41053
41054 -static struct uart_ops dz_ops = {
41055 +static const struct uart_ops dz_ops = {
41056 .tx_empty = dz_tx_empty,
41057 .get_mctrl = dz_get_mctrl,
41058 .set_mctrl = dz_set_mctrl,
41059 diff -urNp linux-2.6.39/drivers/tty/serial/imx.c linux-2.6.39/drivers/tty/serial/imx.c
41060 --- linux-2.6.39/drivers/tty/serial/imx.c 2011-05-19 00:06:34.000000000 -0400
41061 +++ linux-2.6.39/drivers/tty/serial/imx.c 2011-05-22 19:36:32.000000000 -0400
41062 @@ -1018,7 +1018,7 @@ imx_verify_port(struct uart_port *port,
41063 return ret;
41064 }
41065
41066 -static struct uart_ops imx_pops = {
41067 +static const struct uart_ops imx_pops = {
41068 .tx_empty = imx_tx_empty,
41069 .set_mctrl = imx_set_mctrl,
41070 .get_mctrl = imx_get_mctrl,
41071 diff -urNp linux-2.6.39/drivers/tty/serial/ioc3_serial.c linux-2.6.39/drivers/tty/serial/ioc3_serial.c
41072 --- linux-2.6.39/drivers/tty/serial/ioc3_serial.c 2011-05-19 00:06:34.000000000 -0400
41073 +++ linux-2.6.39/drivers/tty/serial/ioc3_serial.c 2011-05-22 19:36:32.000000000 -0400
41074 @@ -1874,7 +1874,7 @@ static int ic3_request_port(struct uart_
41075 }
41076
41077 /* Associate the uart functions above - given to serial core */
41078 -static struct uart_ops ioc3_ops = {
41079 +static const struct uart_ops ioc3_ops = {
41080 .tx_empty = ic3_tx_empty,
41081 .set_mctrl = ic3_set_mctrl,
41082 .get_mctrl = ic3_get_mctrl,
41083 diff -urNp linux-2.6.39/drivers/tty/serial/ioc4_serial.c linux-2.6.39/drivers/tty/serial/ioc4_serial.c
41084 --- linux-2.6.39/drivers/tty/serial/ioc4_serial.c 2011-05-19 00:06:34.000000000 -0400
41085 +++ linux-2.6.39/drivers/tty/serial/ioc4_serial.c 2011-05-22 19:36:32.000000000 -0400
41086 @@ -2593,7 +2593,7 @@ static int ic4_request_port(struct uart_
41087
41088 /* Associate the uart functions above - given to serial core */
41089
41090 -static struct uart_ops ioc4_ops = {
41091 +static const struct uart_ops ioc4_ops = {
41092 .tx_empty = ic4_tx_empty,
41093 .set_mctrl = ic4_set_mctrl,
41094 .get_mctrl = ic4_get_mctrl,
41095 diff -urNp linux-2.6.39/drivers/tty/serial/ip22zilog.c linux-2.6.39/drivers/tty/serial/ip22zilog.c
41096 --- linux-2.6.39/drivers/tty/serial/ip22zilog.c 2011-05-19 00:06:34.000000000 -0400
41097 +++ linux-2.6.39/drivers/tty/serial/ip22zilog.c 2011-05-22 19:36:32.000000000 -0400
41098 @@ -928,7 +928,7 @@ static int ip22zilog_verify_port(struct
41099 return -EINVAL;
41100 }
41101
41102 -static struct uart_ops ip22zilog_pops = {
41103 +static const struct uart_ops ip22zilog_pops = {
41104 .tx_empty = ip22zilog_tx_empty,
41105 .set_mctrl = ip22zilog_set_mctrl,
41106 .get_mctrl = ip22zilog_get_mctrl,
41107 diff -urNp linux-2.6.39/drivers/tty/serial/kgdboc.c linux-2.6.39/drivers/tty/serial/kgdboc.c
41108 --- linux-2.6.39/drivers/tty/serial/kgdboc.c 2011-05-19 00:06:34.000000000 -0400
41109 +++ linux-2.6.39/drivers/tty/serial/kgdboc.c 2011-05-22 19:36:32.000000000 -0400
41110 @@ -22,7 +22,7 @@
41111
41112 #define MAX_CONFIG_LEN 40
41113
41114 -static struct kgdb_io kgdboc_io_ops;
41115 +static struct kgdb_io kgdboc_io_ops; /* cannot be const, see configure_kgdboc() */
41116
41117 /* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
41118 static int configured = -1;
41119 @@ -293,7 +293,7 @@ static void kgdboc_post_exp_handler(void
41120 kgdboc_restore_input();
41121 }
41122
41123 -static struct kgdb_io kgdboc_io_ops = {
41124 +static struct kgdb_io kgdboc_io_ops = { /* cannot be const, see configure_kgdboc() */
41125 .name = "kgdboc",
41126 .read_char = kgdboc_get_char,
41127 .write_char = kgdboc_put_char,
41128 diff -urNp linux-2.6.39/drivers/tty/serial/m32r_sio.c linux-2.6.39/drivers/tty/serial/m32r_sio.c
41129 --- linux-2.6.39/drivers/tty/serial/m32r_sio.c 2011-05-19 00:06:34.000000000 -0400
41130 +++ linux-2.6.39/drivers/tty/serial/m32r_sio.c 2011-05-22 19:36:32.000000000 -0400
41131 @@ -939,7 +939,7 @@ m32r_sio_type(struct uart_port *port)
41132 return uart_config[type].name;
41133 }
41134
41135 -static struct uart_ops m32r_sio_pops = {
41136 +static const struct uart_ops m32r_sio_pops = {
41137 .tx_empty = m32r_sio_tx_empty,
41138 .set_mctrl = m32r_sio_set_mctrl,
41139 .get_mctrl = m32r_sio_get_mctrl,
41140 diff -urNp linux-2.6.39/drivers/tty/serial/max3100.c linux-2.6.39/drivers/tty/serial/max3100.c
41141 --- linux-2.6.39/drivers/tty/serial/max3100.c 2011-05-19 00:06:34.000000000 -0400
41142 +++ linux-2.6.39/drivers/tty/serial/max3100.c 2011-05-22 19:36:32.000000000 -0400
41143 @@ -710,7 +710,7 @@ static void max3100_break_ctl(struct uar
41144 dev_dbg(&s->spi->dev, "%s\n", __func__);
41145 }
41146
41147 -static struct uart_ops max3100_ops = {
41148 +static const struct uart_ops max3100_ops = {
41149 .tx_empty = max3100_tx_empty,
41150 .set_mctrl = max3100_set_mctrl,
41151 .get_mctrl = max3100_get_mctrl,
41152 diff -urNp linux-2.6.39/drivers/tty/serial/max3107.c linux-2.6.39/drivers/tty/serial/max3107.c
41153 --- linux-2.6.39/drivers/tty/serial/max3107.c 2011-05-19 00:06:34.000000000 -0400
41154 +++ linux-2.6.39/drivers/tty/serial/max3107.c 2011-05-22 19:36:32.000000000 -0400
41155 @@ -910,7 +910,7 @@ static void max3107_break_ctl(struct uar
41156
41157
41158 /* Port functions */
41159 -static struct uart_ops max3107_ops = {
41160 +static const struct uart_ops max3107_ops = {
41161 .tx_empty = max3107_tx_empty,
41162 .set_mctrl = max3107_set_mctrl,
41163 .get_mctrl = max3107_get_mctrl,
41164 diff -urNp linux-2.6.39/drivers/tty/serial/mfd.c linux-2.6.39/drivers/tty/serial/mfd.c
41165 --- linux-2.6.39/drivers/tty/serial/mfd.c 2011-05-19 00:06:34.000000000 -0400
41166 +++ linux-2.6.39/drivers/tty/serial/mfd.c 2011-05-22 19:36:32.000000000 -0400
41167 @@ -1178,7 +1178,7 @@ static struct console serial_hsu_console
41168 };
41169 #endif
41170
41171 -struct uart_ops serial_hsu_pops = {
41172 +const struct uart_ops serial_hsu_pops = {
41173 .tx_empty = serial_hsu_tx_empty,
41174 .set_mctrl = serial_hsu_set_mctrl,
41175 .get_mctrl = serial_hsu_get_mctrl,
41176 diff -urNp linux-2.6.39/drivers/tty/serial/mpc52xx_uart.c linux-2.6.39/drivers/tty/serial/mpc52xx_uart.c
41177 --- linux-2.6.39/drivers/tty/serial/mpc52xx_uart.c 2011-05-19 00:06:34.000000000 -0400
41178 +++ linux-2.6.39/drivers/tty/serial/mpc52xx_uart.c 2011-05-22 19:36:32.000000000 -0400
41179 @@ -283,7 +283,7 @@ static irqreturn_t mpc52xx_psc_handle_ir
41180 return mpc5xxx_uart_process_int(port);
41181 }
41182
41183 -static struct psc_ops mpc52xx_psc_ops = {
41184 +static const struct psc_ops mpc52xx_psc_ops = {
41185 .fifo_init = mpc52xx_psc_fifo_init,
41186 .raw_rx_rdy = mpc52xx_psc_raw_rx_rdy,
41187 .raw_tx_rdy = mpc52xx_psc_raw_tx_rdy,
41188 @@ -304,7 +304,7 @@ static struct psc_ops mpc52xx_psc_ops =
41189 .handle_irq = mpc52xx_psc_handle_irq,
41190 };
41191
41192 -static struct psc_ops mpc5200b_psc_ops = {
41193 +static const struct psc_ops mpc5200b_psc_ops = {
41194 .fifo_init = mpc52xx_psc_fifo_init,
41195 .raw_rx_rdy = mpc52xx_psc_raw_rx_rdy,
41196 .raw_tx_rdy = mpc52xx_psc_raw_tx_rdy,
41197 @@ -571,7 +571,7 @@ static void mpc512x_psc_get_irq(struct u
41198 port->irq = psc_fifoc_irq;
41199 }
41200
41201 -static struct psc_ops mpc512x_psc_ops = {
41202 +static const struct psc_ops mpc512x_psc_ops = {
41203 .fifo_init = mpc512x_psc_fifo_init,
41204 .raw_rx_rdy = mpc512x_psc_raw_rx_rdy,
41205 .raw_tx_rdy = mpc512x_psc_raw_tx_rdy,
41206 @@ -596,7 +596,7 @@ static struct psc_ops mpc512x_psc_ops =
41207 };
41208 #endif
41209
41210 -static struct psc_ops *psc_ops;
41211 +static const struct psc_ops *psc_ops;
41212
41213 /* ======================================================================== */
41214 /* UART operations */
41215 @@ -905,7 +905,7 @@ mpc52xx_uart_verify_port(struct uart_por
41216 }
41217
41218
41219 -static struct uart_ops mpc52xx_uart_ops = {
41220 +static const struct uart_ops mpc52xx_uart_ops = {
41221 .tx_empty = mpc52xx_uart_tx_empty,
41222 .set_mctrl = mpc52xx_uart_set_mctrl,
41223 .get_mctrl = mpc52xx_uart_get_mctrl,
41224 diff -urNp linux-2.6.39/drivers/tty/serial/mpsc.c linux-2.6.39/drivers/tty/serial/mpsc.c
41225 --- linux-2.6.39/drivers/tty/serial/mpsc.c 2011-05-19 00:06:34.000000000 -0400
41226 +++ linux-2.6.39/drivers/tty/serial/mpsc.c 2011-05-22 19:36:32.000000000 -0400
41227 @@ -1663,7 +1663,7 @@ static void mpsc_put_poll_char(struct ua
41228 }
41229 #endif
41230
41231 -static struct uart_ops mpsc_pops = {
41232 +static const struct uart_ops mpsc_pops = {
41233 .tx_empty = mpsc_tx_empty,
41234 .set_mctrl = mpsc_set_mctrl,
41235 .get_mctrl = mpsc_get_mctrl,
41236 diff -urNp linux-2.6.39/drivers/tty/serial/mrst_max3110.c linux-2.6.39/drivers/tty/serial/mrst_max3110.c
41237 --- linux-2.6.39/drivers/tty/serial/mrst_max3110.c 2011-05-19 00:06:34.000000000 -0400
41238 +++ linux-2.6.39/drivers/tty/serial/mrst_max3110.c 2011-05-22 19:36:32.000000000 -0400
41239 @@ -393,6 +393,8 @@ static void max3110_con_receive(struct u
41240 int loop = 1, num, total = 0;
41241 u8 recv_buf[512], *pbuf;
41242
41243 + pax_track_stack();
41244 +
41245 pbuf = recv_buf;
41246 do {
41247 num = max3110_read_multi(max, pbuf);
41248 @@ -726,7 +728,7 @@ static void serial_m3110_enable_ms(struc
41249 {
41250 }
41251
41252 -struct uart_ops serial_m3110_ops = {
41253 +const struct uart_ops serial_m3110_ops = {
41254 .tx_empty = serial_m3110_tx_empty,
41255 .set_mctrl = serial_m3110_set_mctrl,
41256 .get_mctrl = serial_m3110_get_mctrl,
41257 diff -urNp linux-2.6.39/drivers/tty/serial/msm_serial.c linux-2.6.39/drivers/tty/serial/msm_serial.c
41258 --- linux-2.6.39/drivers/tty/serial/msm_serial.c 2011-05-19 00:06:34.000000000 -0400
41259 +++ linux-2.6.39/drivers/tty/serial/msm_serial.c 2011-05-22 19:36:32.000000000 -0400
41260 @@ -702,7 +702,7 @@ static void msm_power(struct uart_port *
41261 }
41262 }
41263
41264 -static struct uart_ops msm_uart_pops = {
41265 +static const struct uart_ops msm_uart_pops = {
41266 .tx_empty = msm_tx_empty,
41267 .set_mctrl = msm_set_mctrl,
41268 .get_mctrl = msm_get_mctrl,
41269 diff -urNp linux-2.6.39/drivers/tty/serial/msm_serial_hs.c linux-2.6.39/drivers/tty/serial/msm_serial_hs.c
41270 --- linux-2.6.39/drivers/tty/serial/msm_serial_hs.c 2011-05-19 00:06:34.000000000 -0400
41271 +++ linux-2.6.39/drivers/tty/serial/msm_serial_hs.c 2011-05-22 19:36:32.000000000 -0400
41272 @@ -360,7 +360,7 @@ struct msm_hs_port {
41273 static struct msm_hs_port q_uart_port[UARTDM_NR];
41274 static struct platform_driver msm_serial_hs_platform_driver;
41275 static struct uart_driver msm_hs_driver;
41276 -static struct uart_ops msm_hs_ops;
41277 +static const struct uart_ops msm_hs_ops;
41278 static struct workqueue_struct *msm_hs_workqueue;
41279
41280 #define UARTDM_TO_MSM(uart_port) \
41281 @@ -1856,7 +1856,7 @@ static struct uart_driver msm_hs_driver
41282 .cons = 0,
41283 };
41284
41285 -static struct uart_ops msm_hs_ops = {
41286 +static const struct uart_ops msm_hs_ops = {
41287 .tx_empty = msm_hs_tx_empty,
41288 .set_mctrl = msm_hs_set_mctrl_locked,
41289 .get_mctrl = msm_hs_get_mctrl_locked,
41290 diff -urNp linux-2.6.39/drivers/tty/serial/mux.c linux-2.6.39/drivers/tty/serial/mux.c
41291 --- linux-2.6.39/drivers/tty/serial/mux.c 2011-05-19 00:06:34.000000000 -0400
41292 +++ linux-2.6.39/drivers/tty/serial/mux.c 2011-05-22 19:36:32.000000000 -0400
41293 @@ -442,7 +442,7 @@ static struct console mux_console = {
41294 #define MUX_CONSOLE NULL
41295 #endif
41296
41297 -static struct uart_ops mux_pops = {
41298 +static const struct uart_ops mux_pops = {
41299 .tx_empty = mux_tx_empty,
41300 .set_mctrl = mux_set_mctrl,
41301 .get_mctrl = mux_get_mctrl,
41302 diff -urNp linux-2.6.39/drivers/tty/serial/mxs-auart.c linux-2.6.39/drivers/tty/serial/mxs-auart.c
41303 --- linux-2.6.39/drivers/tty/serial/mxs-auart.c 2011-05-19 00:06:34.000000000 -0400
41304 +++ linux-2.6.39/drivers/tty/serial/mxs-auart.c 2011-05-22 19:36:32.000000000 -0400
41305 @@ -499,7 +499,7 @@ static void mxs_auart_enable_ms(struct u
41306 /* just empty */
41307 }
41308
41309 -static struct uart_ops mxs_auart_ops = {
41310 +static const struct uart_ops mxs_auart_ops = {
41311 .tx_empty = mxs_auart_tx_empty,
41312 .start_tx = mxs_auart_start_tx,
41313 .stop_tx = mxs_auart_stop_tx,
41314 diff -urNp linux-2.6.39/drivers/tty/serial/netx-serial.c linux-2.6.39/drivers/tty/serial/netx-serial.c
41315 --- linux-2.6.39/drivers/tty/serial/netx-serial.c 2011-05-19 00:06:34.000000000 -0400
41316 +++ linux-2.6.39/drivers/tty/serial/netx-serial.c 2011-05-22 19:36:32.000000000 -0400
41317 @@ -464,7 +464,7 @@ netx_verify_port(struct uart_port *port,
41318 return ret;
41319 }
41320
41321 -static struct uart_ops netx_pops = {
41322 +static const struct uart_ops netx_pops = {
41323 .tx_empty = netx_tx_empty,
41324 .set_mctrl = netx_set_mctrl,
41325 .get_mctrl = netx_get_mctrl,
41326 diff -urNp linux-2.6.39/drivers/tty/serial/nwpserial.c linux-2.6.39/drivers/tty/serial/nwpserial.c
41327 --- linux-2.6.39/drivers/tty/serial/nwpserial.c 2011-05-19 00:06:34.000000000 -0400
41328 +++ linux-2.6.39/drivers/tty/serial/nwpserial.c 2011-05-22 19:36:32.000000000 -0400
41329 @@ -303,7 +303,7 @@ static unsigned int nwpserial_tx_empty(s
41330 return ret & UART_LSR_TEMT ? TIOCSER_TEMT : 0;
41331 }
41332
41333 -static struct uart_ops nwpserial_pops = {
41334 +static const struct uart_ops nwpserial_pops = {
41335 .tx_empty = nwpserial_tx_empty,
41336 .set_mctrl = nwpserial_set_mctrl,
41337 .get_mctrl = nwpserial_get_mctrl,
41338 diff -urNp linux-2.6.39/drivers/tty/serial/omap-serial.c linux-2.6.39/drivers/tty/serial/omap-serial.c
41339 --- linux-2.6.39/drivers/tty/serial/omap-serial.c 2011-05-19 00:06:34.000000000 -0400
41340 +++ linux-2.6.39/drivers/tty/serial/omap-serial.c 2011-05-22 19:36:32.000000000 -0400
41341 @@ -1029,7 +1029,7 @@ static inline void serial_omap_add_conso
41342
41343 #endif
41344
41345 -static struct uart_ops serial_omap_pops = {
41346 +static const struct uart_ops serial_omap_pops = {
41347 .tx_empty = serial_omap_tx_empty,
41348 .set_mctrl = serial_omap_set_mctrl,
41349 .get_mctrl = serial_omap_get_mctrl,
41350 diff -urNp linux-2.6.39/drivers/tty/serial/pch_uart.c linux-2.6.39/drivers/tty/serial/pch_uart.c
41351 --- linux-2.6.39/drivers/tty/serial/pch_uart.c 2011-05-19 00:06:34.000000000 -0400
41352 +++ linux-2.6.39/drivers/tty/serial/pch_uart.c 2011-05-22 19:36:32.000000000 -0400
41353 @@ -1351,7 +1351,7 @@ static int pch_uart_verify_port(struct u
41354 return 0;
41355 }
41356
41357 -static struct uart_ops pch_uart_ops = {
41358 +static const struct uart_ops pch_uart_ops = {
41359 .tx_empty = pch_uart_tx_empty,
41360 .set_mctrl = pch_uart_set_mctrl,
41361 .get_mctrl = pch_uart_get_mctrl,
41362 diff -urNp linux-2.6.39/drivers/tty/serial/pmac_zilog.c linux-2.6.39/drivers/tty/serial/pmac_zilog.c
41363 --- linux-2.6.39/drivers/tty/serial/pmac_zilog.c 2011-05-19 00:06:34.000000000 -0400
41364 +++ linux-2.6.39/drivers/tty/serial/pmac_zilog.c 2011-05-22 19:36:32.000000000 -0400
41365 @@ -1427,7 +1427,7 @@ static void pmz_poll_put_char(struct uar
41366
41367 #endif /* CONFIG_CONSOLE_POLL */
41368
41369 -static struct uart_ops pmz_pops = {
41370 +static const struct uart_ops pmz_pops = {
41371 .tx_empty = pmz_tx_empty,
41372 .set_mctrl = pmz_set_mctrl,
41373 .get_mctrl = pmz_get_mctrl,
41374 diff -urNp linux-2.6.39/drivers/tty/serial/pnx8xxx_uart.c linux-2.6.39/drivers/tty/serial/pnx8xxx_uart.c
41375 --- linux-2.6.39/drivers/tty/serial/pnx8xxx_uart.c 2011-05-19 00:06:34.000000000 -0400
41376 +++ linux-2.6.39/drivers/tty/serial/pnx8xxx_uart.c 2011-05-22 19:36:32.000000000 -0400
41377 @@ -614,7 +614,7 @@ pnx8xxx_verify_port(struct uart_port *po
41378 return ret;
41379 }
41380
41381 -static struct uart_ops pnx8xxx_pops = {
41382 +static const struct uart_ops pnx8xxx_pops = {
41383 .tx_empty = pnx8xxx_tx_empty,
41384 .set_mctrl = pnx8xxx_set_mctrl,
41385 .get_mctrl = pnx8xxx_get_mctrl,
41386 diff -urNp linux-2.6.39/drivers/tty/serial/pxa.c linux-2.6.39/drivers/tty/serial/pxa.c
41387 --- linux-2.6.39/drivers/tty/serial/pxa.c 2011-05-19 00:06:34.000000000 -0400
41388 +++ linux-2.6.39/drivers/tty/serial/pxa.c 2011-05-22 19:36:32.000000000 -0400
41389 @@ -706,7 +706,7 @@ static struct console serial_pxa_console
41390 #define PXA_CONSOLE NULL
41391 #endif
41392
41393 -struct uart_ops serial_pxa_pops = {
41394 +const struct uart_ops serial_pxa_pops = {
41395 .tx_empty = serial_pxa_tx_empty,
41396 .set_mctrl = serial_pxa_set_mctrl,
41397 .get_mctrl = serial_pxa_get_mctrl,
41398 diff -urNp linux-2.6.39/drivers/tty/serial/sa1100.c linux-2.6.39/drivers/tty/serial/sa1100.c
41399 --- linux-2.6.39/drivers/tty/serial/sa1100.c 2011-05-19 00:06:34.000000000 -0400
41400 +++ linux-2.6.39/drivers/tty/serial/sa1100.c 2011-05-22 19:36:32.000000000 -0400
41401 @@ -577,7 +577,7 @@ sa1100_verify_port(struct uart_port *por
41402 return ret;
41403 }
41404
41405 -static struct uart_ops sa1100_pops = {
41406 +static const struct uart_ops sa1100_pops = {
41407 .tx_empty = sa1100_tx_empty,
41408 .set_mctrl = sa1100_set_mctrl,
41409 .get_mctrl = sa1100_get_mctrl,
41410 diff -urNp linux-2.6.39/drivers/tty/serial/samsung.c linux-2.6.39/drivers/tty/serial/samsung.c
41411 --- linux-2.6.39/drivers/tty/serial/samsung.c 2011-05-19 00:06:34.000000000 -0400
41412 +++ linux-2.6.39/drivers/tty/serial/samsung.c 2011-05-22 19:36:32.000000000 -0400
41413 @@ -860,7 +860,7 @@ static struct console s3c24xx_serial_con
41414 #define S3C24XX_SERIAL_CONSOLE NULL
41415 #endif
41416
41417 -static struct uart_ops s3c24xx_serial_ops = {
41418 +static const struct uart_ops s3c24xx_serial_ops = {
41419 .pm = s3c24xx_serial_pm,
41420 .tx_empty = s3c24xx_serial_tx_empty,
41421 .get_mctrl = s3c24xx_serial_get_mctrl,
41422 diff -urNp linux-2.6.39/drivers/tty/serial/sc26xx.c linux-2.6.39/drivers/tty/serial/sc26xx.c
41423 --- linux-2.6.39/drivers/tty/serial/sc26xx.c 2011-05-19 00:06:34.000000000 -0400
41424 +++ linux-2.6.39/drivers/tty/serial/sc26xx.c 2011-05-22 19:36:32.000000000 -0400
41425 @@ -515,7 +515,7 @@ static int sc26xx_verify_port(struct uar
41426 return -EINVAL;
41427 }
41428
41429 -static struct uart_ops sc26xx_ops = {
41430 +static const struct uart_ops sc26xx_ops = {
41431 .tx_empty = sc26xx_tx_empty,
41432 .set_mctrl = sc26xx_set_mctrl,
41433 .get_mctrl = sc26xx_get_mctrl,
41434 diff -urNp linux-2.6.39/drivers/tty/serial/serial_ks8695.c linux-2.6.39/drivers/tty/serial/serial_ks8695.c
41435 --- linux-2.6.39/drivers/tty/serial/serial_ks8695.c 2011-05-19 00:06:34.000000000 -0400
41436 +++ linux-2.6.39/drivers/tty/serial/serial_ks8695.c 2011-05-22 19:36:32.000000000 -0400
41437 @@ -528,7 +528,7 @@ static int ks8695uart_verify_port(struct
41438 return ret;
41439 }
41440
41441 -static struct uart_ops ks8695uart_pops = {
41442 +static const struct uart_ops ks8695uart_pops = {
41443 .tx_empty = ks8695uart_tx_empty,
41444 .set_mctrl = ks8695uart_set_mctrl,
41445 .get_mctrl = ks8695uart_get_mctrl,
41446 diff -urNp linux-2.6.39/drivers/tty/serial/serial_txx9.c linux-2.6.39/drivers/tty/serial/serial_txx9.c
41447 --- linux-2.6.39/drivers/tty/serial/serial_txx9.c 2011-05-19 00:06:34.000000000 -0400
41448 +++ linux-2.6.39/drivers/tty/serial/serial_txx9.c 2011-05-22 19:36:32.000000000 -0400
41449 @@ -857,7 +857,7 @@ serial_txx9_type(struct uart_port *port)
41450 return "txx9";
41451 }
41452
41453 -static struct uart_ops serial_txx9_pops = {
41454 +static const struct uart_ops serial_txx9_pops = {
41455 .tx_empty = serial_txx9_tx_empty,
41456 .set_mctrl = serial_txx9_set_mctrl,
41457 .get_mctrl = serial_txx9_get_mctrl,
41458 diff -urNp linux-2.6.39/drivers/tty/serial/sn_console.c linux-2.6.39/drivers/tty/serial/sn_console.c
41459 --- linux-2.6.39/drivers/tty/serial/sn_console.c 2011-05-19 00:06:34.000000000 -0400
41460 +++ linux-2.6.39/drivers/tty/serial/sn_console.c 2011-05-22 19:36:32.000000000 -0400
41461 @@ -388,7 +388,7 @@ static void snp_config_port(struct uart_
41462
41463 /* Associate the uart functions above - given to serial core */
41464
41465 -static struct uart_ops sn_console_ops = {
41466 +static const struct uart_ops sn_console_ops = {
41467 .tx_empty = snp_tx_empty,
41468 .set_mctrl = snp_set_mctrl,
41469 .get_mctrl = snp_get_mctrl,
41470 diff -urNp linux-2.6.39/drivers/tty/serial/sunhv.c linux-2.6.39/drivers/tty/serial/sunhv.c
41471 --- linux-2.6.39/drivers/tty/serial/sunhv.c 2011-05-19 00:06:34.000000000 -0400
41472 +++ linux-2.6.39/drivers/tty/serial/sunhv.c 2011-05-22 19:36:32.000000000 -0400
41473 @@ -168,12 +168,12 @@ struct sunhv_ops {
41474 int (*receive_chars)(struct uart_port *port, struct tty_struct *tty);
41475 };
41476
41477 -static struct sunhv_ops bychar_ops = {
41478 +static const struct sunhv_ops bychar_ops = {
41479 .transmit_chars = transmit_chars_putchar,
41480 .receive_chars = receive_chars_getchar,
41481 };
41482
41483 -static struct sunhv_ops bywrite_ops = {
41484 +static const struct sunhv_ops bywrite_ops = {
41485 .transmit_chars = transmit_chars_write,
41486 .receive_chars = receive_chars_read,
41487 };
41488 @@ -370,7 +370,7 @@ static int sunhv_verify_port(struct uart
41489 return -EINVAL;
41490 }
41491
41492 -static struct uart_ops sunhv_pops = {
41493 +static const struct uart_ops sunhv_pops = {
41494 .tx_empty = sunhv_tx_empty,
41495 .set_mctrl = sunhv_set_mctrl,
41496 .get_mctrl = sunhv_get_mctrl,
41497 diff -urNp linux-2.6.39/drivers/tty/serial/sunsab.c linux-2.6.39/drivers/tty/serial/sunsab.c
41498 --- linux-2.6.39/drivers/tty/serial/sunsab.c 2011-05-19 00:06:34.000000000 -0400
41499 +++ linux-2.6.39/drivers/tty/serial/sunsab.c 2011-05-22 19:36:32.000000000 -0400
41500 @@ -804,7 +804,7 @@ static int sunsab_verify_port(struct uar
41501 return -EINVAL;
41502 }
41503
41504 -static struct uart_ops sunsab_pops = {
41505 +static const struct uart_ops sunsab_pops = {
41506 .tx_empty = sunsab_tx_empty,
41507 .set_mctrl = sunsab_set_mctrl,
41508 .get_mctrl = sunsab_get_mctrl,
41509 diff -urNp linux-2.6.39/drivers/tty/serial/sunsu.c linux-2.6.39/drivers/tty/serial/sunsu.c
41510 --- linux-2.6.39/drivers/tty/serial/sunsu.c 2011-05-19 00:06:34.000000000 -0400
41511 +++ linux-2.6.39/drivers/tty/serial/sunsu.c 2011-05-22 19:36:32.000000000 -0400
41512 @@ -946,7 +946,7 @@ sunsu_type(struct uart_port *port)
41513 return uart_config[type].name;
41514 }
41515
41516 -static struct uart_ops sunsu_pops = {
41517 +static const struct uart_ops sunsu_pops = {
41518 .tx_empty = sunsu_tx_empty,
41519 .set_mctrl = sunsu_set_mctrl,
41520 .get_mctrl = sunsu_get_mctrl,
41521 diff -urNp linux-2.6.39/drivers/tty/serial/sunzilog.c linux-2.6.39/drivers/tty/serial/sunzilog.c
41522 --- linux-2.6.39/drivers/tty/serial/sunzilog.c 2011-05-19 00:06:34.000000000 -0400
41523 +++ linux-2.6.39/drivers/tty/serial/sunzilog.c 2011-05-22 19:36:32.000000000 -0400
41524 @@ -1042,7 +1042,7 @@ static void sunzilog_put_poll_char(struc
41525 }
41526 #endif /* CONFIG_CONSOLE_POLL */
41527
41528 -static struct uart_ops sunzilog_pops = {
41529 +static const struct uart_ops sunzilog_pops = {
41530 .tx_empty = sunzilog_tx_empty,
41531 .set_mctrl = sunzilog_set_mctrl,
41532 .get_mctrl = sunzilog_get_mctrl,
41533 diff -urNp linux-2.6.39/drivers/tty/serial/timbuart.c linux-2.6.39/drivers/tty/serial/timbuart.c
41534 --- linux-2.6.39/drivers/tty/serial/timbuart.c 2011-05-19 00:06:34.000000000 -0400
41535 +++ linux-2.6.39/drivers/tty/serial/timbuart.c 2011-05-22 19:36:32.000000000 -0400
41536 @@ -394,7 +394,7 @@ static int timbuart_verify_port(struct u
41537 return -EINVAL;
41538 }
41539
41540 -static struct uart_ops timbuart_ops = {
41541 +static const struct uart_ops timbuart_ops = {
41542 .tx_empty = timbuart_tx_empty,
41543 .set_mctrl = timbuart_set_mctrl,
41544 .get_mctrl = timbuart_get_mctrl,
41545 diff -urNp linux-2.6.39/drivers/tty/serial/uartlite.c linux-2.6.39/drivers/tty/serial/uartlite.c
41546 --- linux-2.6.39/drivers/tty/serial/uartlite.c 2011-05-19 00:06:34.000000000 -0400
41547 +++ linux-2.6.39/drivers/tty/serial/uartlite.c 2011-05-22 19:36:32.000000000 -0400
41548 @@ -331,7 +331,7 @@ static void ulite_put_poll_char(struct u
41549 }
41550 #endif
41551
41552 -static struct uart_ops ulite_ops = {
41553 +static const struct uart_ops ulite_ops = {
41554 .tx_empty = ulite_tx_empty,
41555 .set_mctrl = ulite_set_mctrl,
41556 .get_mctrl = ulite_get_mctrl,
41557 diff -urNp linux-2.6.39/drivers/tty/serial/ucc_uart.c linux-2.6.39/drivers/tty/serial/ucc_uart.c
41558 --- linux-2.6.39/drivers/tty/serial/ucc_uart.c 2011-05-19 00:06:34.000000000 -0400
41559 +++ linux-2.6.39/drivers/tty/serial/ucc_uart.c 2011-05-22 19:36:32.000000000 -0400
41560 @@ -1088,7 +1088,7 @@ static int qe_uart_verify_port(struct ua
41561 *
41562 * Details on these functions can be found in Documentation/serial/driver
41563 */
41564 -static struct uart_ops qe_uart_pops = {
41565 +static const struct uart_ops qe_uart_pops = {
41566 .tx_empty = qe_uart_tx_empty,
41567 .set_mctrl = qe_uart_set_mctrl,
41568 .get_mctrl = qe_uart_get_mctrl,
41569 diff -urNp linux-2.6.39/drivers/tty/serial/vr41xx_siu.c linux-2.6.39/drivers/tty/serial/vr41xx_siu.c
41570 --- linux-2.6.39/drivers/tty/serial/vr41xx_siu.c 2011-05-19 00:06:34.000000000 -0400
41571 +++ linux-2.6.39/drivers/tty/serial/vr41xx_siu.c 2011-05-22 19:36:32.000000000 -0400
41572 @@ -683,7 +683,7 @@ static int siu_verify_port(struct uart_p
41573 return 0;
41574 }
41575
41576 -static struct uart_ops siu_uart_ops = {
41577 +static const struct uart_ops siu_uart_ops = {
41578 .tx_empty = siu_tx_empty,
41579 .set_mctrl = siu_set_mctrl,
41580 .get_mctrl = siu_get_mctrl,
41581 diff -urNp linux-2.6.39/drivers/tty/serial/vt8500_serial.c linux-2.6.39/drivers/tty/serial/vt8500_serial.c
41582 --- linux-2.6.39/drivers/tty/serial/vt8500_serial.c 2011-05-19 00:06:34.000000000 -0400
41583 +++ linux-2.6.39/drivers/tty/serial/vt8500_serial.c 2011-05-22 19:36:32.000000000 -0400
41584 @@ -519,7 +519,7 @@ static struct console vt8500_console = {
41585 #define VT8500_CONSOLE NULL
41586 #endif
41587
41588 -static struct uart_ops vt8500_uart_pops = {
41589 +static const struct uart_ops vt8500_uart_pops = {
41590 .tx_empty = vt8500_tx_empty,
41591 .set_mctrl = vt8500_set_mctrl,
41592 .get_mctrl = vt8500_get_mctrl,
41593 diff -urNp linux-2.6.39/drivers/tty/serial/zs.c linux-2.6.39/drivers/tty/serial/zs.c
41594 --- linux-2.6.39/drivers/tty/serial/zs.c 2011-05-19 00:06:34.000000000 -0400
41595 +++ linux-2.6.39/drivers/tty/serial/zs.c 2011-05-22 19:36:32.000000000 -0400
41596 @@ -1044,7 +1044,7 @@ static int zs_verify_port(struct uart_po
41597 }
41598
41599
41600 -static struct uart_ops zs_ops = {
41601 +static const struct uart_ops zs_ops = {
41602 .tx_empty = zs_tx_empty,
41603 .set_mctrl = zs_set_mctrl,
41604 .get_mctrl = zs_get_mctrl,
41605 diff -urNp linux-2.6.39/drivers/tty/tty_io.c linux-2.6.39/drivers/tty/tty_io.c
41606 --- linux-2.6.39/drivers/tty/tty_io.c 2011-05-19 00:06:34.000000000 -0400
41607 +++ linux-2.6.39/drivers/tty/tty_io.c 2011-05-22 19:36:32.000000000 -0400
41608 @@ -139,21 +139,11 @@ EXPORT_SYMBOL(tty_mutex);
41609 /* Spinlock to protect the tty->tty_files list */
41610 DEFINE_SPINLOCK(tty_files_lock);
41611
41612 -static ssize_t tty_read(struct file *, char __user *, size_t, loff_t *);
41613 -static ssize_t tty_write(struct file *, const char __user *, size_t, loff_t *);
41614 ssize_t redirected_tty_write(struct file *, const char __user *,
41615 size_t, loff_t *);
41616 -static unsigned int tty_poll(struct file *, poll_table *);
41617 static int tty_open(struct inode *, struct file *);
41618 long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
41619 -#ifdef CONFIG_COMPAT
41620 -static long tty_compat_ioctl(struct file *file, unsigned int cmd,
41621 - unsigned long arg);
41622 -#else
41623 -#define tty_compat_ioctl NULL
41624 -#endif
41625 static int __tty_fasync(int fd, struct file *filp, int on);
41626 -static int tty_fasync(int fd, struct file *filp, int on);
41627 static void release_tty(struct tty_struct *tty, int idx);
41628 static void __proc_set_tty(struct task_struct *tsk, struct tty_struct *tty);
41629 static void proc_set_tty(struct task_struct *tsk, struct tty_struct *tty);
41630 @@ -937,7 +927,7 @@ EXPORT_SYMBOL(start_tty);
41631 * read calls may be outstanding in parallel.
41632 */
41633
41634 -static ssize_t tty_read(struct file *file, char __user *buf, size_t count,
41635 +ssize_t tty_read(struct file *file, char __user *buf, size_t count,
41636 loff_t *ppos)
41637 {
41638 int i;
41639 @@ -963,6 +953,8 @@ static ssize_t tty_read(struct file *fil
41640 return i;
41641 }
41642
41643 +EXPORT_SYMBOL(tty_read);
41644 +
41645 void tty_write_unlock(struct tty_struct *tty)
41646 {
41647 mutex_unlock(&tty->atomic_write_lock);
41648 @@ -1112,7 +1104,7 @@ void tty_write_message(struct tty_struct
41649 * write method will not be invoked in parallel for each device.
41650 */
41651
41652 -static ssize_t tty_write(struct file *file, const char __user *buf,
41653 +ssize_t tty_write(struct file *file, const char __user *buf,
41654 size_t count, loff_t *ppos)
41655 {
41656 struct inode *inode = file->f_path.dentry->d_inode;
41657 @@ -1138,6 +1130,8 @@ static ssize_t tty_write(struct file *fi
41658 return ret;
41659 }
41660
41661 +EXPORT_SYMBOL(tty_write);
41662 +
41663 ssize_t redirected_tty_write(struct file *file, const char __user *buf,
41664 size_t count, loff_t *ppos)
41665 {
41666 @@ -1777,6 +1771,8 @@ int tty_release(struct inode *inode, str
41667 return 0;
41668 }
41669
41670 +EXPORT_SYMBOL(tty_release);
41671 +
41672 /**
41673 * tty_open - open a tty device
41674 * @inode: inode of device file
41675 @@ -1968,7 +1964,7 @@ got_driver:
41676 * may be re-entered freely by other callers.
41677 */
41678
41679 -static unsigned int tty_poll(struct file *filp, poll_table *wait)
41680 +unsigned int tty_poll(struct file *filp, poll_table *wait)
41681 {
41682 struct tty_struct *tty = file_tty(filp);
41683 struct tty_ldisc *ld;
41684 @@ -1984,6 +1980,8 @@ static unsigned int tty_poll(struct file
41685 return ret;
41686 }
41687
41688 +EXPORT_SYMBOL(tty_poll);
41689 +
41690 static int __tty_fasync(int fd, struct file *filp, int on)
41691 {
41692 struct tty_struct *tty = file_tty(filp);
41693 @@ -2025,7 +2023,7 @@ out:
41694 return retval;
41695 }
41696
41697 -static int tty_fasync(int fd, struct file *filp, int on)
41698 +int tty_fasync(int fd, struct file *filp, int on)
41699 {
41700 int retval;
41701 tty_lock();
41702 @@ -2034,6 +2032,8 @@ static int tty_fasync(int fd, struct fil
41703 return retval;
41704 }
41705
41706 +EXPORT_SYMBOL(tty_fasync);
41707 +
41708 /**
41709 * tiocsti - fake input character
41710 * @tty: tty to fake input into
41711 @@ -2695,8 +2695,10 @@ long tty_ioctl(struct file *file, unsign
41712 return retval;
41713 }
41714
41715 +EXPORT_SYMBOL(tty_ioctl);
41716 +
41717 #ifdef CONFIG_COMPAT
41718 -static long tty_compat_ioctl(struct file *file, unsigned int cmd,
41719 +long tty_compat_ioctl(struct file *file, unsigned int cmd,
41720 unsigned long arg)
41721 {
41722 struct inode *inode = file->f_dentry->d_inode;
41723 @@ -2720,6 +2722,9 @@ static long tty_compat_ioctl(struct file
41724
41725 return retval;
41726 }
41727 +
41728 +EXPORT_SYMBOL(tty_compat_ioctl);
41729 +
41730 #endif
41731
41732 /*
41733 @@ -3198,11 +3203,6 @@ struct tty_struct *get_current_tty(void)
41734 }
41735 EXPORT_SYMBOL_GPL(get_current_tty);
41736
41737 -void tty_default_fops(struct file_operations *fops)
41738 -{
41739 - *fops = tty_fops;
41740 -}
41741 -
41742 /*
41743 * Initialize the console device. This is called *early*, so
41744 * we can't necessarily depend on lots of kernel help here.
41745 diff -urNp linux-2.6.39/drivers/tty/tty_ldisc.c linux-2.6.39/drivers/tty/tty_ldisc.c
41746 --- linux-2.6.39/drivers/tty/tty_ldisc.c 2011-05-19 00:06:34.000000000 -0400
41747 +++ linux-2.6.39/drivers/tty/tty_ldisc.c 2011-05-22 19:36:32.000000000 -0400
41748 @@ -74,7 +74,7 @@ static void put_ldisc(struct tty_ldisc *
41749 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
41750 struct tty_ldisc_ops *ldo = ld->ops;
41751
41752 - ldo->refcount--;
41753 + atomic_dec(&ldo->refcount);
41754 module_put(ldo->owner);
41755 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
41756
41757 @@ -109,7 +109,7 @@ int tty_register_ldisc(int disc, struct
41758 spin_lock_irqsave(&tty_ldisc_lock, flags);
41759 tty_ldiscs[disc] = new_ldisc;
41760 new_ldisc->num = disc;
41761 - new_ldisc->refcount = 0;
41762 + atomic_set(&new_ldisc->refcount, 0);
41763 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
41764
41765 return ret;
41766 @@ -137,7 +137,7 @@ int tty_unregister_ldisc(int disc)
41767 return -EINVAL;
41768
41769 spin_lock_irqsave(&tty_ldisc_lock, flags);
41770 - if (tty_ldiscs[disc]->refcount)
41771 + if (atomic_read(&tty_ldiscs[disc]->refcount))
41772 ret = -EBUSY;
41773 else
41774 tty_ldiscs[disc] = NULL;
41775 @@ -158,7 +158,7 @@ static struct tty_ldisc_ops *get_ldops(i
41776 if (ldops) {
41777 ret = ERR_PTR(-EAGAIN);
41778 if (try_module_get(ldops->owner)) {
41779 - ldops->refcount++;
41780 + atomic_inc(&ldops->refcount);
41781 ret = ldops;
41782 }
41783 }
41784 @@ -171,7 +171,7 @@ static void put_ldops(struct tty_ldisc_o
41785 unsigned long flags;
41786
41787 spin_lock_irqsave(&tty_ldisc_lock, flags);
41788 - ldops->refcount--;
41789 + atomic_dec(&ldops->refcount);
41790 module_put(ldops->owner);
41791 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
41792 }
41793 diff -urNp linux-2.6.39/drivers/tty/vt/keyboard.c linux-2.6.39/drivers/tty/vt/keyboard.c
41794 --- linux-2.6.39/drivers/tty/vt/keyboard.c 2011-05-19 00:06:34.000000000 -0400
41795 +++ linux-2.6.39/drivers/tty/vt/keyboard.c 2011-05-22 20:32:43.000000000 -0400
41796 @@ -658,6 +658,16 @@ static void k_spec(struct vc_data *vc, u
41797 kbd->kbdmode == VC_OFF) &&
41798 value != KVAL(K_SAK))
41799 return; /* SAK is allowed even in raw mode */
41800 +
41801 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
41802 + {
41803 + void *func = fn_handler[value];
41804 + if (func == fn_show_state || func == fn_show_ptregs ||
41805 + func == fn_show_mem)
41806 + return;
41807 + }
41808 +#endif
41809 +
41810 fn_handler[value](vc);
41811 }
41812
41813 diff -urNp linux-2.6.39/drivers/tty/vt/vt.c linux-2.6.39/drivers/tty/vt/vt.c
41814 --- linux-2.6.39/drivers/tty/vt/vt.c 2011-05-19 00:06:34.000000000 -0400
41815 +++ linux-2.6.39/drivers/tty/vt/vt.c 2011-05-22 19:36:32.000000000 -0400
41816 @@ -261,7 +261,7 @@ EXPORT_SYMBOL_GPL(unregister_vt_notifier
41817
41818 static void notify_write(struct vc_data *vc, unsigned int unicode)
41819 {
41820 - struct vt_notifier_param param = { .vc = vc, unicode = unicode };
41821 + struct vt_notifier_param param = { .vc = vc, .c = unicode };
41822 atomic_notifier_call_chain(&vt_notifier_list, VT_WRITE, &param);
41823 }
41824
41825 diff -urNp linux-2.6.39/drivers/tty/vt/vt_ioctl.c linux-2.6.39/drivers/tty/vt/vt_ioctl.c
41826 --- linux-2.6.39/drivers/tty/vt/vt_ioctl.c 2011-05-19 00:06:34.000000000 -0400
41827 +++ linux-2.6.39/drivers/tty/vt/vt_ioctl.c 2011-05-22 19:41:37.000000000 -0400
41828 @@ -209,9 +209,6 @@ do_kdsk_ioctl(int cmd, struct kbentry __
41829 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
41830 return -EFAULT;
41831
41832 - if (!capable(CAP_SYS_TTY_CONFIG))
41833 - perm = 0;
41834 -
41835 switch (cmd) {
41836 case KDGKBENT:
41837 key_map = key_maps[s];
41838 @@ -223,6 +220,9 @@ do_kdsk_ioctl(int cmd, struct kbentry __
41839 val = (i ? K_HOLE : K_NOSUCHMAP);
41840 return put_user(val, &user_kbe->kb_value);
41841 case KDSKBENT:
41842 + if (!capable(CAP_SYS_TTY_CONFIG))
41843 + perm = 0;
41844 +
41845 if (!perm)
41846 return -EPERM;
41847 if (!i && v == K_NOSUCHMAP) {
41848 @@ -324,9 +324,6 @@ do_kdgkb_ioctl(int cmd, struct kbsentry
41849 int i, j, k;
41850 int ret;
41851
41852 - if (!capable(CAP_SYS_TTY_CONFIG))
41853 - perm = 0;
41854 -
41855 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
41856 if (!kbs) {
41857 ret = -ENOMEM;
41858 @@ -360,6 +357,9 @@ do_kdgkb_ioctl(int cmd, struct kbsentry
41859 kfree(kbs);
41860 return ((p && *p) ? -EOVERFLOW : 0);
41861 case KDSKBSENT:
41862 + if (!capable(CAP_SYS_TTY_CONFIG))
41863 + perm = 0;
41864 +
41865 if (!perm) {
41866 ret = -EPERM;
41867 goto reterr;
41868 diff -urNp linux-2.6.39/drivers/uio/uio.c linux-2.6.39/drivers/uio/uio.c
41869 --- linux-2.6.39/drivers/uio/uio.c 2011-05-19 00:06:34.000000000 -0400
41870 +++ linux-2.6.39/drivers/uio/uio.c 2011-05-22 19:36:32.000000000 -0400
41871 @@ -25,6 +25,7 @@
41872 #include <linux/kobject.h>
41873 #include <linux/cdev.h>
41874 #include <linux/uio_driver.h>
41875 +#include <asm/local.h>
41876
41877 #define UIO_MAX_DEVICES (1U << MINORBITS)
41878
41879 @@ -32,10 +33,10 @@ struct uio_device {
41880 struct module *owner;
41881 struct device *dev;
41882 int minor;
41883 - atomic_t event;
41884 + atomic_unchecked_t event;
41885 struct fasync_struct *async_queue;
41886 wait_queue_head_t wait;
41887 - int vma_count;
41888 + local_t vma_count;
41889 struct uio_info *info;
41890 struct kobject *map_dir;
41891 struct kobject *portio_dir;
41892 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device
41893 struct device_attribute *attr, char *buf)
41894 {
41895 struct uio_device *idev = dev_get_drvdata(dev);
41896 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
41897 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
41898 }
41899
41900 static struct device_attribute uio_class_attributes[] = {
41901 @@ -402,7 +403,7 @@ void uio_event_notify(struct uio_info *i
41902 {
41903 struct uio_device *idev = info->uio_dev;
41904
41905 - atomic_inc(&idev->event);
41906 + atomic_inc_unchecked(&idev->event);
41907 wake_up_interruptible(&idev->wait);
41908 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
41909 }
41910 @@ -455,7 +456,7 @@ static int uio_open(struct inode *inode,
41911 }
41912
41913 listener->dev = idev;
41914 - listener->event_count = atomic_read(&idev->event);
41915 + listener->event_count = atomic_read_unchecked(&idev->event);
41916 filep->private_data = listener;
41917
41918 if (idev->info->open) {
41919 @@ -506,7 +507,7 @@ static unsigned int uio_poll(struct file
41920 return -EIO;
41921
41922 poll_wait(filep, &idev->wait, wait);
41923 - if (listener->event_count != atomic_read(&idev->event))
41924 + if (listener->event_count != atomic_read_unchecked(&idev->event))
41925 return POLLIN | POLLRDNORM;
41926 return 0;
41927 }
41928 @@ -531,7 +532,7 @@ static ssize_t uio_read(struct file *fil
41929 do {
41930 set_current_state(TASK_INTERRUPTIBLE);
41931
41932 - event_count = atomic_read(&idev->event);
41933 + event_count = atomic_read_unchecked(&idev->event);
41934 if (event_count != listener->event_count) {
41935 if (copy_to_user(buf, &event_count, count))
41936 retval = -EFAULT;
41937 @@ -602,13 +603,13 @@ static int uio_find_mem_index(struct vm_
41938 static void uio_vma_open(struct vm_area_struct *vma)
41939 {
41940 struct uio_device *idev = vma->vm_private_data;
41941 - idev->vma_count++;
41942 + local_inc(&idev->vma_count);
41943 }
41944
41945 static void uio_vma_close(struct vm_area_struct *vma)
41946 {
41947 struct uio_device *idev = vma->vm_private_data;
41948 - idev->vma_count--;
41949 + local_dec(&idev->vma_count);
41950 }
41951
41952 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41953 @@ -819,7 +820,7 @@ int __uio_register_device(struct module
41954 idev->owner = owner;
41955 idev->info = info;
41956 init_waitqueue_head(&idev->wait);
41957 - atomic_set(&idev->event, 0);
41958 + atomic_set_unchecked(&idev->event, 0);
41959
41960 ret = uio_get_minor(idev);
41961 if (ret)
41962 diff -urNp linux-2.6.39/drivers/usb/atm/cxacru.c linux-2.6.39/drivers/usb/atm/cxacru.c
41963 --- linux-2.6.39/drivers/usb/atm/cxacru.c 2011-05-19 00:06:34.000000000 -0400
41964 +++ linux-2.6.39/drivers/usb/atm/cxacru.c 2011-05-22 19:36:32.000000000 -0400
41965 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_c
41966 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
41967 if (ret < 2)
41968 return -EINVAL;
41969 - if (index < 0 || index > 0x7f)
41970 + if (index > 0x7f)
41971 return -EINVAL;
41972 pos += tmp;
41973
41974 diff -urNp linux-2.6.39/drivers/usb/atm/usbatm.c linux-2.6.39/drivers/usb/atm/usbatm.c
41975 --- linux-2.6.39/drivers/usb/atm/usbatm.c 2011-05-19 00:06:34.000000000 -0400
41976 +++ linux-2.6.39/drivers/usb/atm/usbatm.c 2011-05-22 19:36:32.000000000 -0400
41977 @@ -332,7 +332,7 @@ static void usbatm_extract_one_cell(stru
41978 if (printk_ratelimit())
41979 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
41980 __func__, vpi, vci);
41981 - atomic_inc(&vcc->stats->rx_err);
41982 + atomic_inc_unchecked(&vcc->stats->rx_err);
41983 return;
41984 }
41985
41986 @@ -360,7 +360,7 @@ static void usbatm_extract_one_cell(stru
41987 if (length > ATM_MAX_AAL5_PDU) {
41988 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
41989 __func__, length, vcc);
41990 - atomic_inc(&vcc->stats->rx_err);
41991 + atomic_inc_unchecked(&vcc->stats->rx_err);
41992 goto out;
41993 }
41994
41995 @@ -369,14 +369,14 @@ static void usbatm_extract_one_cell(stru
41996 if (sarb->len < pdu_length) {
41997 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
41998 __func__, pdu_length, sarb->len, vcc);
41999 - atomic_inc(&vcc->stats->rx_err);
42000 + atomic_inc_unchecked(&vcc->stats->rx_err);
42001 goto out;
42002 }
42003
42004 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
42005 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
42006 __func__, vcc);
42007 - atomic_inc(&vcc->stats->rx_err);
42008 + atomic_inc_unchecked(&vcc->stats->rx_err);
42009 goto out;
42010 }
42011
42012 @@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(stru
42013 if (printk_ratelimit())
42014 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
42015 __func__, length);
42016 - atomic_inc(&vcc->stats->rx_drop);
42017 + atomic_inc_unchecked(&vcc->stats->rx_drop);
42018 goto out;
42019 }
42020
42021 @@ -411,7 +411,7 @@ static void usbatm_extract_one_cell(stru
42022
42023 vcc->push(vcc, skb);
42024
42025 - atomic_inc(&vcc->stats->rx);
42026 + atomic_inc_unchecked(&vcc->stats->rx);
42027 out:
42028 skb_trim(sarb, 0);
42029 }
42030 @@ -614,7 +614,7 @@ static void usbatm_tx_process(unsigned l
42031 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
42032
42033 usbatm_pop(vcc, skb);
42034 - atomic_inc(&vcc->stats->tx);
42035 + atomic_inc_unchecked(&vcc->stats->tx);
42036
42037 skb = skb_dequeue(&instance->sndqueue);
42038 }
42039 @@ -773,11 +773,11 @@ static int usbatm_atm_proc_read(struct a
42040 if (!left--)
42041 return sprintf(page,
42042 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
42043 - atomic_read(&atm_dev->stats.aal5.tx),
42044 - atomic_read(&atm_dev->stats.aal5.tx_err),
42045 - atomic_read(&atm_dev->stats.aal5.rx),
42046 - atomic_read(&atm_dev->stats.aal5.rx_err),
42047 - atomic_read(&atm_dev->stats.aal5.rx_drop));
42048 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
42049 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
42050 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
42051 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
42052 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
42053
42054 if (!left--) {
42055 if (instance->disconnected)
42056 diff -urNp linux-2.6.39/drivers/usb/core/devices.c linux-2.6.39/drivers/usb/core/devices.c
42057 --- linux-2.6.39/drivers/usb/core/devices.c 2011-05-19 00:06:34.000000000 -0400
42058 +++ linux-2.6.39/drivers/usb/core/devices.c 2011-05-22 19:36:32.000000000 -0400
42059 @@ -126,7 +126,7 @@ static const char *format_endpt =
42060 * time it gets called.
42061 */
42062 static struct device_connect_event {
42063 - atomic_t count;
42064 + atomic_unchecked_t count;
42065 wait_queue_head_t wait;
42066 } device_event = {
42067 .count = ATOMIC_INIT(1),
42068 @@ -164,7 +164,7 @@ static const struct class_info clas_info
42069
42070 void usbfs_conn_disc_event(void)
42071 {
42072 - atomic_add(2, &device_event.count);
42073 + atomic_add_unchecked(2, &device_event.count);
42074 wake_up(&device_event.wait);
42075 }
42076
42077 @@ -648,7 +648,7 @@ static unsigned int usb_device_poll(stru
42078
42079 poll_wait(file, &device_event.wait, wait);
42080
42081 - event_count = atomic_read(&device_event.count);
42082 + event_count = atomic_read_unchecked(&device_event.count);
42083 if (file->f_version != event_count) {
42084 file->f_version = event_count;
42085 return POLLIN | POLLRDNORM;
42086 diff -urNp linux-2.6.39/drivers/usb/core/hcd.c linux-2.6.39/drivers/usb/core/hcd.c
42087 --- linux-2.6.39/drivers/usb/core/hcd.c 2011-05-19 00:06:34.000000000 -0400
42088 +++ linux-2.6.39/drivers/usb/core/hcd.c 2011-05-22 19:36:32.000000000 -0400
42089 @@ -2577,7 +2577,7 @@ EXPORT_SYMBOL_GPL(usb_hcd_platform_shutd
42090
42091 #if defined(CONFIG_USB_MON) || defined(CONFIG_USB_MON_MODULE)
42092
42093 -struct usb_mon_operations *mon_ops;
42094 +const struct usb_mon_operations *mon_ops;
42095
42096 /*
42097 * The registration is unlocked.
42098 @@ -2587,7 +2587,7 @@ struct usb_mon_operations *mon_ops;
42099 * symbols from usbcore, usbcore gets referenced and cannot be unloaded first.
42100 */
42101
42102 -int usb_mon_register (struct usb_mon_operations *ops)
42103 +int usb_mon_register (const struct usb_mon_operations *ops)
42104 {
42105
42106 if (mon_ops)
42107 diff -urNp linux-2.6.39/drivers/usb/core/message.c linux-2.6.39/drivers/usb/core/message.c
42108 --- linux-2.6.39/drivers/usb/core/message.c 2011-05-19 00:06:34.000000000 -0400
42109 +++ linux-2.6.39/drivers/usb/core/message.c 2011-05-22 19:36:32.000000000 -0400
42110 @@ -869,8 +869,8 @@ char *usb_cache_string(struct usb_device
42111 buf = kmalloc(MAX_USB_STRING_SIZE, GFP_NOIO);
42112 if (buf) {
42113 len = usb_string(udev, index, buf, MAX_USB_STRING_SIZE);
42114 - if (len > 0) {
42115 - smallbuf = kmalloc(++len, GFP_NOIO);
42116 + if (len++ > 0) {
42117 + smallbuf = kmalloc(len, GFP_NOIO);
42118 if (!smallbuf)
42119 return buf;
42120 memcpy(smallbuf, buf, len);
42121 diff -urNp linux-2.6.39/drivers/usb/early/ehci-dbgp.c linux-2.6.39/drivers/usb/early/ehci-dbgp.c
42122 --- linux-2.6.39/drivers/usb/early/ehci-dbgp.c 2011-05-19 00:06:34.000000000 -0400
42123 +++ linux-2.6.39/drivers/usb/early/ehci-dbgp.c 2011-05-22 19:36:32.000000000 -0400
42124 @@ -96,7 +96,7 @@ static inline u32 dbgp_len_update(u32 x,
42125 }
42126
42127 #ifdef CONFIG_KGDB
42128 -static struct kgdb_io kgdbdbgp_io_ops;
42129 +static struct kgdb_io kgdbdbgp_io_ops; /* cannot be const, see kgdbdbgp_parse_config */
42130 #define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
42131 #else
42132 #define dbgp_kgdb_mode (0)
42133 @@ -1026,7 +1026,7 @@ static void kgdbdbgp_write_char(u8 chr)
42134 early_dbgp_write(NULL, &chr, 1);
42135 }
42136
42137 -static struct kgdb_io kgdbdbgp_io_ops = {
42138 +static struct kgdb_io kgdbdbgp_io_ops = { /* cannot be const, see kgdbdbgp_parse_config() */
42139 .name = "kgdbdbgp",
42140 .read_char = kgdbdbgp_read_char,
42141 .write_char = kgdbdbgp_write_char,
42142 diff -urNp linux-2.6.39/drivers/usb/gadget/fsl_qe_udc.c linux-2.6.39/drivers/usb/gadget/fsl_qe_udc.c
42143 --- linux-2.6.39/drivers/usb/gadget/fsl_qe_udc.c 2011-05-19 00:06:34.000000000 -0400
42144 +++ linux-2.6.39/drivers/usb/gadget/fsl_qe_udc.c 2011-05-22 19:36:32.000000000 -0400
42145 @@ -1859,7 +1859,7 @@ out:
42146 return status;
42147 }
42148
42149 -static struct usb_ep_ops qe_ep_ops = {
42150 +static const struct usb_ep_ops qe_ep_ops = {
42151 .enable = qe_ep_enable,
42152 .disable = qe_ep_disable,
42153
42154 @@ -1928,7 +1928,7 @@ static int qe_pullup(struct usb_gadget *
42155 }
42156
42157 /* defined in usb_gadget.h */
42158 -static struct usb_gadget_ops qe_gadget_ops = {
42159 +static const struct usb_gadget_ops qe_gadget_ops = {
42160 .get_frame = qe_get_frame,
42161 .wakeup = qe_wakeup,
42162 /* .set_selfpowered = qe_set_selfpowered,*/ /* always selfpowered */
42163 diff -urNp linux-2.6.39/drivers/usb/gadget/fsl_udc_core.c linux-2.6.39/drivers/usb/gadget/fsl_udc_core.c
42164 --- linux-2.6.39/drivers/usb/gadget/fsl_udc_core.c 2011-05-19 00:06:34.000000000 -0400
42165 +++ linux-2.6.39/drivers/usb/gadget/fsl_udc_core.c 2011-05-22 19:36:32.000000000 -0400
42166 @@ -1003,7 +1003,7 @@ static void fsl_ep_fifo_flush(struct usb
42167 } while (fsl_readl(&dr_regs->endptstatus) & bits);
42168 }
42169
42170 -static struct usb_ep_ops fsl_ep_ops = {
42171 +static const struct usb_ep_ops fsl_ep_ops = {
42172 .enable = fsl_ep_enable,
42173 .disable = fsl_ep_disable,
42174
42175 @@ -1114,7 +1114,7 @@ static int fsl_pullup(struct usb_gadget
42176 }
42177
42178 /* defined in gadget.h */
42179 -static struct usb_gadget_ops fsl_gadget_ops = {
42180 +static const struct usb_gadget_ops fsl_gadget_ops = {
42181 .get_frame = fsl_get_frame,
42182 .wakeup = fsl_wakeup,
42183 /* .set_selfpowered = fsl_set_selfpowered, */ /* Always selfpowered */
42184 diff -urNp linux-2.6.39/drivers/usb/gadget/fusb300_udc.c linux-2.6.39/drivers/usb/gadget/fusb300_udc.c
42185 --- linux-2.6.39/drivers/usb/gadget/fusb300_udc.c 2011-05-19 00:06:34.000000000 -0400
42186 +++ linux-2.6.39/drivers/usb/gadget/fusb300_udc.c 2011-05-22 19:36:32.000000000 -0400
42187 @@ -527,7 +527,7 @@ static void fusb300_fifo_flush(struct us
42188 {
42189 }
42190
42191 -static struct usb_ep_ops fusb300_ep_ops = {
42192 +static const struct usb_ep_ops fusb300_ep_ops = {
42193 .enable = fusb300_enable,
42194 .disable = fusb300_disable,
42195
42196 @@ -1570,7 +1570,7 @@ static int fusb300_udc_pullup(struct usb
42197 return 0;
42198 }
42199
42200 -static struct usb_gadget_ops fusb300_gadget_ops = {
42201 +static const struct usb_gadget_ops fusb300_gadget_ops = {
42202 .pullup = fusb300_udc_pullup,
42203 };
42204
42205 diff -urNp linux-2.6.39/drivers/usb/gadget/goku_udc.c linux-2.6.39/drivers/usb/gadget/goku_udc.c
42206 --- linux-2.6.39/drivers/usb/gadget/goku_udc.c 2011-05-19 00:06:34.000000000 -0400
42207 +++ linux-2.6.39/drivers/usb/gadget/goku_udc.c 2011-05-22 19:36:32.000000000 -0400
42208 @@ -973,7 +973,7 @@ static void goku_fifo_flush(struct usb_e
42209 command(regs, COMMAND_FIFO_CLEAR, ep->num);
42210 }
42211
42212 -static struct usb_ep_ops goku_ep_ops = {
42213 +static const struct usb_ep_ops goku_ep_ops = {
42214 .enable = goku_ep_enable,
42215 .disable = goku_ep_disable,
42216
42217 diff -urNp linux-2.6.39/drivers/usb/gadget/imx_udc.c linux-2.6.39/drivers/usb/gadget/imx_udc.c
42218 --- linux-2.6.39/drivers/usb/gadget/imx_udc.c 2011-05-19 00:06:34.000000000 -0400
42219 +++ linux-2.6.39/drivers/usb/gadget/imx_udc.c 2011-05-22 19:36:32.000000000 -0400
42220 @@ -937,7 +937,7 @@ static void imx_ep_fifo_flush(struct usb
42221 local_irq_restore(flags);
42222 }
42223
42224 -static struct usb_ep_ops imx_ep_ops = {
42225 +static const struct usb_ep_ops imx_ep_ops = {
42226 .enable = imx_ep_enable,
42227 .disable = imx_ep_disable,
42228
42229 diff -urNp linux-2.6.39/drivers/usb/gadget/m66592-udc.c linux-2.6.39/drivers/usb/gadget/m66592-udc.c
42230 --- linux-2.6.39/drivers/usb/gadget/m66592-udc.c 2011-05-19 00:06:34.000000000 -0400
42231 +++ linux-2.6.39/drivers/usb/gadget/m66592-udc.c 2011-05-22 19:36:32.000000000 -0400
42232 @@ -1437,7 +1437,7 @@ static void m66592_fifo_flush(struct usb
42233 spin_unlock_irqrestore(&ep->m66592->lock, flags);
42234 }
42235
42236 -static struct usb_ep_ops m66592_ep_ops = {
42237 +static const struct usb_ep_ops m66592_ep_ops = {
42238 .enable = m66592_enable,
42239 .disable = m66592_disable,
42240
42241 @@ -1542,7 +1542,7 @@ static int m66592_get_frame(struct usb_g
42242 return m66592_read(m66592, M66592_FRMNUM) & 0x03FF;
42243 }
42244
42245 -static struct usb_gadget_ops m66592_gadget_ops = {
42246 +static const struct usb_gadget_ops m66592_gadget_ops = {
42247 .get_frame = m66592_get_frame,
42248 };
42249
42250 diff -urNp linux-2.6.39/drivers/usb/gadget/mv_udc_core.c linux-2.6.39/drivers/usb/gadget/mv_udc_core.c
42251 --- linux-2.6.39/drivers/usb/gadget/mv_udc_core.c 2011-05-19 00:06:34.000000000 -0400
42252 +++ linux-2.6.39/drivers/usb/gadget/mv_udc_core.c 2011-05-22 19:36:32.000000000 -0400
42253 @@ -972,7 +972,7 @@ static int mv_ep_set_wedge(struct usb_ep
42254 return mv_ep_set_halt_wedge(_ep, 1, 1);
42255 }
42256
42257 -static struct usb_ep_ops mv_ep_ops = {
42258 +static const struct usb_ep_ops mv_ep_ops = {
42259 .enable = mv_ep_enable,
42260 .disable = mv_ep_disable,
42261
42262 diff -urNp linux-2.6.39/drivers/usb/gadget/omap_udc.c linux-2.6.39/drivers/usb/gadget/omap_udc.c
42263 --- linux-2.6.39/drivers/usb/gadget/omap_udc.c 2011-05-19 00:06:34.000000000 -0400
42264 +++ linux-2.6.39/drivers/usb/gadget/omap_udc.c 2011-05-22 19:36:32.000000000 -0400
42265 @@ -1177,7 +1177,7 @@ done:
42266 return status;
42267 }
42268
42269 -static struct usb_ep_ops omap_ep_ops = {
42270 +static const struct usb_ep_ops omap_ep_ops = {
42271 .enable = omap_ep_enable,
42272 .disable = omap_ep_disable,
42273
42274 @@ -1374,7 +1374,7 @@ static int omap_pullup(struct usb_gadget
42275 return 0;
42276 }
42277
42278 -static struct usb_gadget_ops omap_gadget_ops = {
42279 +static const struct usb_gadget_ops omap_gadget_ops = {
42280 .get_frame = omap_get_frame,
42281 .wakeup = omap_wakeup,
42282 .set_selfpowered = omap_set_selfpowered,
42283 diff -urNp linux-2.6.39/drivers/usb/gadget/pxa25x_udc.c linux-2.6.39/drivers/usb/gadget/pxa25x_udc.c
42284 --- linux-2.6.39/drivers/usb/gadget/pxa25x_udc.c 2011-05-19 00:06:34.000000000 -0400
42285 +++ linux-2.6.39/drivers/usb/gadget/pxa25x_udc.c 2011-05-22 19:36:32.000000000 -0400
42286 @@ -896,7 +896,7 @@ static void pxa25x_ep_fifo_flush(struct
42287 }
42288
42289
42290 -static struct usb_ep_ops pxa25x_ep_ops = {
42291 +static const struct usb_ep_ops pxa25x_ep_ops = {
42292 .enable = pxa25x_ep_enable,
42293 .disable = pxa25x_ep_disable,
42294
42295 diff -urNp linux-2.6.39/drivers/usb/gadget/pxa27x_udc.c linux-2.6.39/drivers/usb/gadget/pxa27x_udc.c
42296 --- linux-2.6.39/drivers/usb/gadget/pxa27x_udc.c 2011-05-19 00:06:34.000000000 -0400
42297 +++ linux-2.6.39/drivers/usb/gadget/pxa27x_udc.c 2011-05-22 19:36:32.000000000 -0400
42298 @@ -1491,7 +1491,7 @@ static int pxa_ep_disable(struct usb_ep
42299 return 0;
42300 }
42301
42302 -static struct usb_ep_ops pxa_ep_ops = {
42303 +static const struct usb_ep_ops pxa_ep_ops = {
42304 .enable = pxa_ep_enable,
42305 .disable = pxa_ep_disable,
42306
42307 diff -urNp linux-2.6.39/drivers/usb/gadget/r8a66597-udc.c linux-2.6.39/drivers/usb/gadget/r8a66597-udc.c
42308 --- linux-2.6.39/drivers/usb/gadget/r8a66597-udc.c 2011-05-19 00:06:34.000000000 -0400
42309 +++ linux-2.6.39/drivers/usb/gadget/r8a66597-udc.c 2011-05-22 19:36:32.000000000 -0400
42310 @@ -1392,7 +1392,7 @@ static void r8a66597_fifo_flush(struct u
42311 spin_unlock_irqrestore(&ep->r8a66597->lock, flags);
42312 }
42313
42314 -static struct usb_ep_ops r8a66597_ep_ops = {
42315 +static const struct usb_ep_ops r8a66597_ep_ops = {
42316 .enable = r8a66597_enable,
42317 .disable = r8a66597_disable,
42318
42319 @@ -1497,7 +1497,7 @@ static int r8a66597_get_frame(struct usb
42320 return r8a66597_read(r8a66597, FRMNUM) & 0x03FF;
42321 }
42322
42323 -static struct usb_gadget_ops r8a66597_gadget_ops = {
42324 +static const struct usb_gadget_ops r8a66597_gadget_ops = {
42325 .get_frame = r8a66597_get_frame,
42326 };
42327
42328 diff -urNp linux-2.6.39/drivers/usb/gadget/s3c-hsotg.c linux-2.6.39/drivers/usb/gadget/s3c-hsotg.c
42329 --- linux-2.6.39/drivers/usb/gadget/s3c-hsotg.c 2011-05-19 00:06:34.000000000 -0400
42330 +++ linux-2.6.39/drivers/usb/gadget/s3c-hsotg.c 2011-05-22 19:36:32.000000000 -0400
42331 @@ -2461,7 +2461,7 @@ static int s3c_hsotg_ep_sethalt(struct u
42332 return 0;
42333 }
42334
42335 -static struct usb_ep_ops s3c_hsotg_ep_ops = {
42336 +static const struct usb_ep_ops s3c_hsotg_ep_ops = {
42337 .enable = s3c_hsotg_ep_enable,
42338 .disable = s3c_hsotg_ep_disable,
42339 .alloc_request = s3c_hsotg_ep_alloc_request,
42340 @@ -2725,7 +2725,7 @@ static int s3c_hsotg_gadget_getframe(str
42341 return s3c_hsotg_read_frameno(to_hsotg(gadget));
42342 }
42343
42344 -static struct usb_gadget_ops s3c_hsotg_gadget_ops = {
42345 +static const struct usb_gadget_ops s3c_hsotg_gadget_ops = {
42346 .get_frame = s3c_hsotg_gadget_getframe,
42347 };
42348
42349 diff -urNp linux-2.6.39/drivers/usb/gadget/uvc_queue.c linux-2.6.39/drivers/usb/gadget/uvc_queue.c
42350 --- linux-2.6.39/drivers/usb/gadget/uvc_queue.c 2011-05-19 00:06:34.000000000 -0400
42351 +++ linux-2.6.39/drivers/usb/gadget/uvc_queue.c 2011-05-22 19:36:32.000000000 -0400
42352 @@ -400,7 +400,7 @@ static void uvc_vm_close(struct vm_area_
42353 buffer->vma_use_count--;
42354 }
42355
42356 -static struct vm_operations_struct uvc_vm_ops = {
42357 +static const struct vm_operations_struct uvc_vm_ops = {
42358 .open = uvc_vm_open,
42359 .close = uvc_vm_close,
42360 };
42361 diff -urNp linux-2.6.39/drivers/usb/host/ehci-fsl.c linux-2.6.39/drivers/usb/host/ehci-fsl.c
42362 --- linux-2.6.39/drivers/usb/host/ehci-fsl.c 2011-05-19 00:06:34.000000000 -0400
42363 +++ linux-2.6.39/drivers/usb/host/ehci-fsl.c 2011-05-22 19:36:32.000000000 -0400
42364 @@ -380,7 +380,7 @@ static int ehci_fsl_drv_restore(struct d
42365 return 0;
42366 }
42367
42368 -static struct dev_pm_ops ehci_fsl_pm_ops = {
42369 +static const struct dev_pm_ops ehci_fsl_pm_ops = {
42370 .suspend = ehci_fsl_drv_suspend,
42371 .resume = ehci_fsl_drv_resume,
42372 .restore = ehci_fsl_drv_restore,
42373 diff -urNp linux-2.6.39/drivers/usb/host/xhci-mem.c linux-2.6.39/drivers/usb/host/xhci-mem.c
42374 --- linux-2.6.39/drivers/usb/host/xhci-mem.c 2011-05-19 00:06:34.000000000 -0400
42375 +++ linux-2.6.39/drivers/usb/host/xhci-mem.c 2011-05-22 19:36:32.000000000 -0400
42376 @@ -1671,6 +1671,8 @@ static int xhci_check_trb_in_td_math(str
42377 unsigned int num_tests;
42378 int i, ret;
42379
42380 + pax_track_stack();
42381 +
42382 num_tests = ARRAY_SIZE(simple_test_vector);
42383 for (i = 0; i < num_tests; i++) {
42384 ret = xhci_test_trb_in_td(xhci,
42385 diff -urNp linux-2.6.39/drivers/usb/mon/mon_main.c linux-2.6.39/drivers/usb/mon/mon_main.c
42386 --- linux-2.6.39/drivers/usb/mon/mon_main.c 2011-05-19 00:06:34.000000000 -0400
42387 +++ linux-2.6.39/drivers/usb/mon/mon_main.c 2011-05-22 19:36:32.000000000 -0400
42388 @@ -238,7 +238,7 @@ static struct notifier_block mon_nb = {
42389 /*
42390 * Ops
42391 */
42392 -static struct usb_mon_operations mon_ops_0 = {
42393 +static const struct usb_mon_operations mon_ops_0 = {
42394 .urb_submit = mon_submit,
42395 .urb_submit_error = mon_submit_error,
42396 .urb_complete = mon_complete,
42397 diff -urNp linux-2.6.39/drivers/usb/musb/cppi_dma.h linux-2.6.39/drivers/usb/musb/cppi_dma.h
42398 --- linux-2.6.39/drivers/usb/musb/cppi_dma.h 2011-05-19 00:06:34.000000000 -0400
42399 +++ linux-2.6.39/drivers/usb/musb/cppi_dma.h 2011-05-22 19:36:32.000000000 -0400
42400 @@ -113,7 +113,7 @@ struct cppi_channel {
42401
42402 /* CPPI DMA controller object */
42403 struct cppi {
42404 - struct dma_controller controller;
42405 + const struct dma_controller controller;
42406 struct musb *musb;
42407 void __iomem *mregs; /* Mentor regs */
42408 void __iomem *tibase; /* TI/CPPI regs */
42409 diff -urNp linux-2.6.39/drivers/usb/otg/msm_otg.c linux-2.6.39/drivers/usb/otg/msm_otg.c
42410 --- linux-2.6.39/drivers/usb/otg/msm_otg.c 2011-05-19 00:06:34.000000000 -0400
42411 +++ linux-2.6.39/drivers/usb/otg/msm_otg.c 2011-05-22 19:36:32.000000000 -0400
42412 @@ -95,7 +95,7 @@ static int ulpi_write(struct otg_transce
42413 return 0;
42414 }
42415
42416 -static struct otg_io_access_ops msm_otg_io_ops = {
42417 +static const struct otg_io_access_ops msm_otg_io_ops = {
42418 .read = ulpi_read,
42419 .write = ulpi_write,
42420 };
42421 diff -urNp linux-2.6.39/drivers/usb/otg/ulpi_viewport.c linux-2.6.39/drivers/usb/otg/ulpi_viewport.c
42422 --- linux-2.6.39/drivers/usb/otg/ulpi_viewport.c 2011-05-19 00:06:34.000000000 -0400
42423 +++ linux-2.6.39/drivers/usb/otg/ulpi_viewport.c 2011-05-22 19:36:32.000000000 -0400
42424 @@ -74,7 +74,7 @@ static int ulpi_viewport_write(struct ot
42425 return ulpi_viewport_wait(view, ULPI_VIEW_RUN);
42426 }
42427
42428 -struct otg_io_access_ops ulpi_viewport_access_ops = {
42429 +const struct otg_io_access_ops ulpi_viewport_access_ops = {
42430 .read = ulpi_viewport_read,
42431 .write = ulpi_viewport_write,
42432 };
42433 diff -urNp linux-2.6.39/drivers/usb/serial/ftdi_sio.c linux-2.6.39/drivers/usb/serial/ftdi_sio.c
42434 --- linux-2.6.39/drivers/usb/serial/ftdi_sio.c 2011-05-19 00:06:34.000000000 -0400
42435 +++ linux-2.6.39/drivers/usb/serial/ftdi_sio.c 2011-05-22 19:36:32.000000000 -0400
42436 @@ -104,27 +104,27 @@ static int ftdi_stmclite_probe(struct
42437 static void ftdi_USB_UIRT_setup(struct ftdi_private *priv);
42438 static void ftdi_HE_TIRA1_setup(struct ftdi_private *priv);
42439
42440 -static struct ftdi_sio_quirk ftdi_jtag_quirk = {
42441 +static const struct ftdi_sio_quirk ftdi_jtag_quirk = {
42442 .probe = ftdi_jtag_probe,
42443 };
42444
42445 -static struct ftdi_sio_quirk ftdi_mtxorb_hack_quirk = {
42446 +static const struct ftdi_sio_quirk ftdi_mtxorb_hack_quirk = {
42447 .probe = ftdi_mtxorb_hack_setup,
42448 };
42449
42450 -static struct ftdi_sio_quirk ftdi_NDI_device_quirk = {
42451 +static const struct ftdi_sio_quirk ftdi_NDI_device_quirk = {
42452 .probe = ftdi_NDI_device_setup,
42453 };
42454
42455 -static struct ftdi_sio_quirk ftdi_USB_UIRT_quirk = {
42456 +static const struct ftdi_sio_quirk ftdi_USB_UIRT_quirk = {
42457 .port_probe = ftdi_USB_UIRT_setup,
42458 };
42459
42460 -static struct ftdi_sio_quirk ftdi_HE_TIRA1_quirk = {
42461 +static const struct ftdi_sio_quirk ftdi_HE_TIRA1_quirk = {
42462 .port_probe = ftdi_HE_TIRA1_setup,
42463 };
42464
42465 -static struct ftdi_sio_quirk ftdi_stmclite_quirk = {
42466 +static const struct ftdi_sio_quirk ftdi_stmclite_quirk = {
42467 .probe = ftdi_stmclite_probe,
42468 };
42469
42470 diff -urNp linux-2.6.39/drivers/usb/wusbcore/wa-hc.h linux-2.6.39/drivers/usb/wusbcore/wa-hc.h
42471 --- linux-2.6.39/drivers/usb/wusbcore/wa-hc.h 2011-05-19 00:06:34.000000000 -0400
42472 +++ linux-2.6.39/drivers/usb/wusbcore/wa-hc.h 2011-05-22 19:36:32.000000000 -0400
42473 @@ -192,7 +192,7 @@ struct wahc {
42474 struct list_head xfer_delayed_list;
42475 spinlock_t xfer_list_lock;
42476 struct work_struct xfer_work;
42477 - atomic_t xfer_id_count;
42478 + atomic_unchecked_t xfer_id_count;
42479 };
42480
42481
42482 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *
42483 INIT_LIST_HEAD(&wa->xfer_delayed_list);
42484 spin_lock_init(&wa->xfer_list_lock);
42485 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
42486 - atomic_set(&wa->xfer_id_count, 1);
42487 + atomic_set_unchecked(&wa->xfer_id_count, 1);
42488 }
42489
42490 /**
42491 diff -urNp linux-2.6.39/drivers/usb/wusbcore/wa-xfer.c linux-2.6.39/drivers/usb/wusbcore/wa-xfer.c
42492 --- linux-2.6.39/drivers/usb/wusbcore/wa-xfer.c 2011-05-19 00:06:34.000000000 -0400
42493 +++ linux-2.6.39/drivers/usb/wusbcore/wa-xfer.c 2011-05-22 19:36:32.000000000 -0400
42494 @@ -294,7 +294,7 @@ out:
42495 */
42496 static void wa_xfer_id_init(struct wa_xfer *xfer)
42497 {
42498 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
42499 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
42500 }
42501
42502 /*
42503 diff -urNp linux-2.6.39/drivers/vhost/vhost.c linux-2.6.39/drivers/vhost/vhost.c
42504 --- linux-2.6.39/drivers/vhost/vhost.c 2011-05-19 00:06:34.000000000 -0400
42505 +++ linux-2.6.39/drivers/vhost/vhost.c 2011-05-22 19:36:32.000000000 -0400
42506 @@ -580,7 +580,7 @@ static int init_used(struct vhost_virtqu
42507 return get_user(vq->last_used_idx, &used->idx);
42508 }
42509
42510 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
42511 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
42512 {
42513 struct file *eventfp, *filep = NULL,
42514 *pollstart = NULL, *pollstop = NULL;
42515 diff -urNp linux-2.6.39/drivers/video/backlight/corgi_lcd.c linux-2.6.39/drivers/video/backlight/corgi_lcd.c
42516 --- linux-2.6.39/drivers/video/backlight/corgi_lcd.c 2011-05-19 00:06:34.000000000 -0400
42517 +++ linux-2.6.39/drivers/video/backlight/corgi_lcd.c 2011-05-22 19:36:32.000000000 -0400
42518 @@ -383,7 +383,7 @@ static int corgi_lcd_get_power(struct lc
42519 return lcd->power;
42520 }
42521
42522 -static struct lcd_ops corgi_lcd_ops = {
42523 +static const struct lcd_ops corgi_lcd_ops = {
42524 .get_power = corgi_lcd_get_power,
42525 .set_power = corgi_lcd_set_power,
42526 .set_mode = corgi_lcd_set_mode,
42527 diff -urNp linux-2.6.39/drivers/video/backlight/cr_bllcd.c linux-2.6.39/drivers/video/backlight/cr_bllcd.c
42528 --- linux-2.6.39/drivers/video/backlight/cr_bllcd.c 2011-05-19 00:06:34.000000000 -0400
42529 +++ linux-2.6.39/drivers/video/backlight/cr_bllcd.c 2011-05-22 19:36:32.000000000 -0400
42530 @@ -165,7 +165,7 @@ static int cr_lcd_set_power(struct lcd_d
42531 return 0;
42532 }
42533
42534 -static struct lcd_ops cr_lcd_ops = {
42535 +static const struct lcd_ops cr_lcd_ops = {
42536 .set_power = cr_lcd_set_power,
42537 };
42538
42539 diff -urNp linux-2.6.39/drivers/video/backlight/ili9320.c linux-2.6.39/drivers/video/backlight/ili9320.c
42540 --- linux-2.6.39/drivers/video/backlight/ili9320.c 2011-05-19 00:06:34.000000000 -0400
42541 +++ linux-2.6.39/drivers/video/backlight/ili9320.c 2011-05-22 19:36:32.000000000 -0400
42542 @@ -166,7 +166,7 @@ static int ili9320_get_power(struct lcd_
42543 return lcd->power;
42544 }
42545
42546 -static struct lcd_ops ili9320_ops = {
42547 +static const struct lcd_ops ili9320_ops = {
42548 .get_power = ili9320_get_power,
42549 .set_power = ili9320_set_power,
42550 };
42551 diff -urNp linux-2.6.39/drivers/video/backlight/jornada720_lcd.c linux-2.6.39/drivers/video/backlight/jornada720_lcd.c
42552 --- linux-2.6.39/drivers/video/backlight/jornada720_lcd.c 2011-05-19 00:06:34.000000000 -0400
42553 +++ linux-2.6.39/drivers/video/backlight/jornada720_lcd.c 2011-05-22 19:36:32.000000000 -0400
42554 @@ -87,7 +87,7 @@ static int jornada_lcd_set_power(struct
42555 return 0;
42556 }
42557
42558 -static struct lcd_ops jornada_lcd_props = {
42559 +static const struct lcd_ops jornada_lcd_props = {
42560 .get_contrast = jornada_lcd_get_contrast,
42561 .set_contrast = jornada_lcd_set_contrast,
42562 .get_power = jornada_lcd_get_power,
42563 diff -urNp linux-2.6.39/drivers/video/backlight/l4f00242t03.c linux-2.6.39/drivers/video/backlight/l4f00242t03.c
42564 --- linux-2.6.39/drivers/video/backlight/l4f00242t03.c 2011-05-19 00:06:34.000000000 -0400
42565 +++ linux-2.6.39/drivers/video/backlight/l4f00242t03.c 2011-05-22 19:36:32.000000000 -0400
42566 @@ -149,7 +149,7 @@ static int l4f00242t03_lcd_power_set(str
42567 return 0;
42568 }
42569
42570 -static struct lcd_ops l4f_ops = {
42571 +static const struct lcd_ops l4f_ops = {
42572 .set_power = l4f00242t03_lcd_power_set,
42573 .get_power = l4f00242t03_lcd_power_get,
42574 };
42575 diff -urNp linux-2.6.39/drivers/video/backlight/lcd.c linux-2.6.39/drivers/video/backlight/lcd.c
42576 --- linux-2.6.39/drivers/video/backlight/lcd.c 2011-05-19 00:06:34.000000000 -0400
42577 +++ linux-2.6.39/drivers/video/backlight/lcd.c 2011-05-22 19:36:32.000000000 -0400
42578 @@ -192,7 +192,7 @@ static struct device_attribute lcd_devic
42579 * or a pointer to the newly allocated device.
42580 */
42581 struct lcd_device *lcd_device_register(const char *name, struct device *parent,
42582 - void *devdata, struct lcd_ops *ops)
42583 + void *devdata, const struct lcd_ops *ops)
42584 {
42585 struct lcd_device *new_ld;
42586 int rc;
42587 diff -urNp linux-2.6.39/drivers/video/backlight/ld9040.c linux-2.6.39/drivers/video/backlight/ld9040.c
42588 --- linux-2.6.39/drivers/video/backlight/ld9040.c 2011-05-19 00:06:34.000000000 -0400
42589 +++ linux-2.6.39/drivers/video/backlight/ld9040.c 2011-05-22 19:36:32.000000000 -0400
42590 @@ -651,7 +651,7 @@ static int ld9040_set_brightness(struct
42591 return ret;
42592 }
42593
42594 -static struct lcd_ops ld9040_lcd_ops = {
42595 +static const struct lcd_ops ld9040_lcd_ops = {
42596 .set_power = ld9040_set_power,
42597 .get_power = ld9040_get_power,
42598 };
42599 diff -urNp linux-2.6.39/drivers/video/backlight/lms283gf05.c linux-2.6.39/drivers/video/backlight/lms283gf05.c
42600 --- linux-2.6.39/drivers/video/backlight/lms283gf05.c 2011-05-19 00:06:34.000000000 -0400
42601 +++ linux-2.6.39/drivers/video/backlight/lms283gf05.c 2011-05-22 19:36:32.000000000 -0400
42602 @@ -144,7 +144,7 @@ static int lms283gf05_power_set(struct l
42603 return 0;
42604 }
42605
42606 -static struct lcd_ops lms_ops = {
42607 +static const struct lcd_ops lms_ops = {
42608 .set_power = lms283gf05_power_set,
42609 .get_power = NULL,
42610 };
42611 diff -urNp linux-2.6.39/drivers/video/backlight/ltv350qv.c linux-2.6.39/drivers/video/backlight/ltv350qv.c
42612 --- linux-2.6.39/drivers/video/backlight/ltv350qv.c 2011-05-19 00:06:34.000000000 -0400
42613 +++ linux-2.6.39/drivers/video/backlight/ltv350qv.c 2011-05-22 19:36:32.000000000 -0400
42614 @@ -221,7 +221,7 @@ static int ltv350qv_get_power(struct lcd
42615 return lcd->power;
42616 }
42617
42618 -static struct lcd_ops ltv_ops = {
42619 +static const struct lcd_ops ltv_ops = {
42620 .get_power = ltv350qv_get_power,
42621 .set_power = ltv350qv_set_power,
42622 };
42623 diff -urNp linux-2.6.39/drivers/video/backlight/platform_lcd.c linux-2.6.39/drivers/video/backlight/platform_lcd.c
42624 --- linux-2.6.39/drivers/video/backlight/platform_lcd.c 2011-05-19 00:06:34.000000000 -0400
42625 +++ linux-2.6.39/drivers/video/backlight/platform_lcd.c 2011-05-22 19:36:32.000000000 -0400
42626 @@ -66,7 +66,7 @@ static int platform_lcd_match(struct lcd
42627 return plcd->us->parent == info->device;
42628 }
42629
42630 -static struct lcd_ops platform_lcd_ops = {
42631 +static const struct lcd_ops platform_lcd_ops = {
42632 .get_power = platform_lcd_get_power,
42633 .set_power = platform_lcd_set_power,
42634 .check_fb = platform_lcd_match,
42635 diff -urNp linux-2.6.39/drivers/video/backlight/s6e63m0.c linux-2.6.39/drivers/video/backlight/s6e63m0.c
42636 --- linux-2.6.39/drivers/video/backlight/s6e63m0.c 2011-05-19 00:06:34.000000000 -0400
42637 +++ linux-2.6.39/drivers/video/backlight/s6e63m0.c 2011-05-22 19:36:32.000000000 -0400
42638 @@ -644,7 +644,7 @@ static int s6e63m0_set_brightness(struct
42639 return ret;
42640 }
42641
42642 -static struct lcd_ops s6e63m0_lcd_ops = {
42643 +static const struct lcd_ops s6e63m0_lcd_ops = {
42644 .set_power = s6e63m0_set_power,
42645 .get_power = s6e63m0_get_power,
42646 };
42647 diff -urNp linux-2.6.39/drivers/video/backlight/tdo24m.c linux-2.6.39/drivers/video/backlight/tdo24m.c
42648 --- linux-2.6.39/drivers/video/backlight/tdo24m.c 2011-05-19 00:06:34.000000000 -0400
42649 +++ linux-2.6.39/drivers/video/backlight/tdo24m.c 2011-05-22 19:36:32.000000000 -0400
42650 @@ -322,7 +322,7 @@ static int tdo24m_set_mode(struct lcd_de
42651 return lcd->adj_mode(lcd, mode);
42652 }
42653
42654 -static struct lcd_ops tdo24m_ops = {
42655 +static const struct lcd_ops tdo24m_ops = {
42656 .get_power = tdo24m_get_power,
42657 .set_power = tdo24m_set_power,
42658 .set_mode = tdo24m_set_mode,
42659 diff -urNp linux-2.6.39/drivers/video/backlight/tosa_lcd.c linux-2.6.39/drivers/video/backlight/tosa_lcd.c
42660 --- linux-2.6.39/drivers/video/backlight/tosa_lcd.c 2011-05-19 00:06:34.000000000 -0400
42661 +++ linux-2.6.39/drivers/video/backlight/tosa_lcd.c 2011-05-22 19:36:32.000000000 -0400
42662 @@ -163,7 +163,7 @@ static int tosa_lcd_set_mode(struct lcd_
42663 return 0;
42664 }
42665
42666 -static struct lcd_ops tosa_lcd_ops = {
42667 +static const struct lcd_ops tosa_lcd_ops = {
42668 .set_power = tosa_lcd_set_power,
42669 .get_power = tosa_lcd_get_power,
42670 .set_mode = tosa_lcd_set_mode,
42671 diff -urNp linux-2.6.39/drivers/video/bf537-lq035.c linux-2.6.39/drivers/video/bf537-lq035.c
42672 --- linux-2.6.39/drivers/video/bf537-lq035.c 2011-05-19 00:06:34.000000000 -0400
42673 +++ linux-2.6.39/drivers/video/bf537-lq035.c 2011-05-22 19:36:32.000000000 -0400
42674 @@ -682,7 +682,7 @@ static int bfin_lcd_check_fb(struct lcd_
42675 return 0;
42676 }
42677
42678 -static struct lcd_ops bfin_lcd_ops = {
42679 +static const struct lcd_ops bfin_lcd_ops = {
42680 .get_power = bfin_lcd_get_power,
42681 .set_power = bfin_lcd_set_power,
42682 .get_contrast = bfin_lcd_get_contrast,
42683 diff -urNp linux-2.6.39/drivers/video/bf54x-lq043fb.c linux-2.6.39/drivers/video/bf54x-lq043fb.c
42684 --- linux-2.6.39/drivers/video/bf54x-lq043fb.c 2011-05-19 00:06:34.000000000 -0400
42685 +++ linux-2.6.39/drivers/video/bf54x-lq043fb.c 2011-05-22 19:36:32.000000000 -0400
42686 @@ -467,7 +467,7 @@ static int bfin_lcd_check_fb(struct lcd_
42687 return 0;
42688 }
42689
42690 -static struct lcd_ops bfin_lcd_ops = {
42691 +static const struct lcd_ops bfin_lcd_ops = {
42692 .get_power = bfin_lcd_get_power,
42693 .set_power = bfin_lcd_set_power,
42694 .get_contrast = bfin_lcd_get_contrast,
42695 diff -urNp linux-2.6.39/drivers/video/bfin-t350mcqb-fb.c linux-2.6.39/drivers/video/bfin-t350mcqb-fb.c
42696 --- linux-2.6.39/drivers/video/bfin-t350mcqb-fb.c 2011-05-19 00:06:34.000000000 -0400
42697 +++ linux-2.6.39/drivers/video/bfin-t350mcqb-fb.c 2011-05-22 19:36:32.000000000 -0400
42698 @@ -387,7 +387,7 @@ static int bfin_lcd_check_fb(struct lcd_
42699 return 0;
42700 }
42701
42702 -static struct lcd_ops bfin_lcd_ops = {
42703 +static const struct lcd_ops bfin_lcd_ops = {
42704 .get_power = bfin_lcd_get_power,
42705 .set_power = bfin_lcd_set_power,
42706 .get_contrast = bfin_lcd_get_contrast,
42707 diff -urNp linux-2.6.39/drivers/video/fbcmap.c linux-2.6.39/drivers/video/fbcmap.c
42708 --- linux-2.6.39/drivers/video/fbcmap.c 2011-05-19 00:06:34.000000000 -0400
42709 +++ linux-2.6.39/drivers/video/fbcmap.c 2011-05-22 19:36:32.000000000 -0400
42710 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user
42711 rc = -ENODEV;
42712 goto out;
42713 }
42714 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
42715 - !info->fbops->fb_setcmap)) {
42716 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
42717 rc = -EINVAL;
42718 goto out1;
42719 }
42720 diff -urNp linux-2.6.39/drivers/video/fbmem.c linux-2.6.39/drivers/video/fbmem.c
42721 --- linux-2.6.39/drivers/video/fbmem.c 2011-05-19 00:06:34.000000000 -0400
42722 +++ linux-2.6.39/drivers/video/fbmem.c 2011-05-22 19:36:32.000000000 -0400
42723 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_in
42724 image->dx += image->width + 8;
42725 }
42726 } else if (rotate == FB_ROTATE_UD) {
42727 - for (x = 0; x < num && image->dx >= 0; x++) {
42728 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
42729 info->fbops->fb_imageblit(info, image);
42730 image->dx -= image->width + 8;
42731 }
42732 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_in
42733 image->dy += image->height + 8;
42734 }
42735 } else if (rotate == FB_ROTATE_CCW) {
42736 - for (x = 0; x < num && image->dy >= 0; x++) {
42737 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
42738 info->fbops->fb_imageblit(info, image);
42739 image->dy -= image->height + 8;
42740 }
42741 @@ -939,6 +939,8 @@ fb_set_var(struct fb_info *info, struct
42742 int flags = info->flags;
42743 int ret = 0;
42744
42745 + pax_track_stack();
42746 +
42747 if (var->activate & FB_ACTIVATE_INV_MODE) {
42748 struct fb_videomode mode1, mode2;
42749
42750 @@ -1064,6 +1066,8 @@ static long do_fb_ioctl(struct fb_info *
42751 void __user *argp = (void __user *)arg;
42752 long ret = 0;
42753
42754 + pax_track_stack();
42755 +
42756 switch (cmd) {
42757 case FBIOGET_VSCREENINFO:
42758 if (!lock_fb_info(info))
42759 @@ -1143,7 +1147,7 @@ static long do_fb_ioctl(struct fb_info *
42760 return -EFAULT;
42761 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
42762 return -EINVAL;
42763 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
42764 + if (con2fb.framebuffer >= FB_MAX)
42765 return -EINVAL;
42766 if (!registered_fb[con2fb.framebuffer])
42767 request_module("fb%d", con2fb.framebuffer);
42768 diff -urNp linux-2.6.39/drivers/video/geode/display_gx1.c linux-2.6.39/drivers/video/geode/display_gx1.c
42769 --- linux-2.6.39/drivers/video/geode/display_gx1.c 2011-05-19 00:06:34.000000000 -0400
42770 +++ linux-2.6.39/drivers/video/geode/display_gx1.c 2011-05-22 19:36:32.000000000 -0400
42771 @@ -208,7 +208,7 @@ static void gx1_set_hw_palette_reg(struc
42772 writel(val, par->dc_regs + DC_PAL_DATA);
42773 }
42774
42775 -struct geode_dc_ops gx1_dc_ops = {
42776 +const struct geode_dc_ops gx1_dc_ops = {
42777 .set_mode = gx1_set_mode,
42778 .set_palette_reg = gx1_set_hw_palette_reg,
42779 };
42780 diff -urNp linux-2.6.39/drivers/video/geode/display_gx1.h linux-2.6.39/drivers/video/geode/display_gx1.h
42781 --- linux-2.6.39/drivers/video/geode/display_gx1.h 2011-05-19 00:06:34.000000000 -0400
42782 +++ linux-2.6.39/drivers/video/geode/display_gx1.h 2011-05-22 19:36:32.000000000 -0400
42783 @@ -18,7 +18,7 @@
42784 unsigned gx1_gx_base(void);
42785 int gx1_frame_buffer_size(void);
42786
42787 -extern struct geode_dc_ops gx1_dc_ops;
42788 +extern const struct geode_dc_ops gx1_dc_ops;
42789
42790 /* GX1 configuration I/O registers */
42791
42792 diff -urNp linux-2.6.39/drivers/video/geode/geodefb.h linux-2.6.39/drivers/video/geode/geodefb.h
42793 --- linux-2.6.39/drivers/video/geode/geodefb.h 2011-05-19 00:06:34.000000000 -0400
42794 +++ linux-2.6.39/drivers/video/geode/geodefb.h 2011-05-22 19:36:32.000000000 -0400
42795 @@ -31,8 +31,8 @@ struct geodefb_par {
42796 int panel_y;
42797 void __iomem *dc_regs;
42798 void __iomem *vid_regs;
42799 - struct geode_dc_ops *dc_ops;
42800 - struct geode_vid_ops *vid_ops;
42801 + const struct geode_dc_ops *dc_ops;
42802 + const struct geode_vid_ops *vid_ops;
42803 };
42804
42805 #endif /* !__GEODEFB_H__ */
42806 diff -urNp linux-2.6.39/drivers/video/geode/video_cs5530.c linux-2.6.39/drivers/video/geode/video_cs5530.c
42807 --- linux-2.6.39/drivers/video/geode/video_cs5530.c 2011-05-19 00:06:34.000000000 -0400
42808 +++ linux-2.6.39/drivers/video/geode/video_cs5530.c 2011-05-22 19:36:32.000000000 -0400
42809 @@ -186,7 +186,7 @@ static int cs5530_blank_display(struct f
42810 return 0;
42811 }
42812
42813 -struct geode_vid_ops cs5530_vid_ops = {
42814 +const struct geode_vid_ops cs5530_vid_ops = {
42815 .set_dclk = cs5530_set_dclk_frequency,
42816 .configure_display = cs5530_configure_display,
42817 .blank_display = cs5530_blank_display,
42818 diff -urNp linux-2.6.39/drivers/video/geode/video_cs5530.h linux-2.6.39/drivers/video/geode/video_cs5530.h
42819 --- linux-2.6.39/drivers/video/geode/video_cs5530.h 2011-05-19 00:06:34.000000000 -0400
42820 +++ linux-2.6.39/drivers/video/geode/video_cs5530.h 2011-05-22 19:36:32.000000000 -0400
42821 @@ -15,7 +15,7 @@
42822 #ifndef __VIDEO_CS5530_H__
42823 #define __VIDEO_CS5530_H__
42824
42825 -extern struct geode_vid_ops cs5530_vid_ops;
42826 +extern const struct geode_vid_ops cs5530_vid_ops;
42827
42828 /* CS5530 Video device registers */
42829
42830 diff -urNp linux-2.6.39/drivers/video/i810/i810_accel.c linux-2.6.39/drivers/video/i810/i810_accel.c
42831 --- linux-2.6.39/drivers/video/i810/i810_accel.c 2011-05-19 00:06:34.000000000 -0400
42832 +++ linux-2.6.39/drivers/video/i810/i810_accel.c 2011-05-22 19:36:32.000000000 -0400
42833 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct
42834 }
42835 }
42836 printk("ringbuffer lockup!!!\n");
42837 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
42838 i810_report_error(mmio);
42839 par->dev_flags |= LOCKUP;
42840 info->pixmap.scan_align = 1;
42841 diff -urNp linux-2.6.39/drivers/video/matrox/matroxfb_base.c linux-2.6.39/drivers/video/matrox/matroxfb_base.c
42842 --- linux-2.6.39/drivers/video/matrox/matroxfb_base.c 2011-05-19 00:06:34.000000000 -0400
42843 +++ linux-2.6.39/drivers/video/matrox/matroxfb_base.c 2011-05-22 19:36:32.000000000 -0400
42844 @@ -1232,7 +1232,7 @@ static struct fb_ops matroxfb_ops = {
42845 #define RSText 0x7
42846 #define RSText8 0x8
42847 /* 9-F */
42848 -static struct { struct fb_bitfield red, green, blue, transp; int bits_per_pixel; } colors[] = {
42849 +static const struct { struct fb_bitfield red, green, blue, transp; int bits_per_pixel; } colors[] = {
42850 { { 0, 8, 0}, { 0, 8, 0}, { 0, 8, 0}, { 0, 0, 0}, 8 },
42851 { { 10, 5, 0}, { 5, 5, 0}, { 0, 5, 0}, { 15, 1, 0}, 16 },
42852 { { 11, 5, 0}, { 5, 6, 0}, { 0, 5, 0}, { 0, 0, 0}, 16 },
42853 diff -urNp linux-2.6.39/drivers/video/omap/lcd_ams_delta.c linux-2.6.39/drivers/video/omap/lcd_ams_delta.c
42854 --- linux-2.6.39/drivers/video/omap/lcd_ams_delta.c 2011-05-19 00:06:34.000000000 -0400
42855 +++ linux-2.6.39/drivers/video/omap/lcd_ams_delta.c 2011-05-22 19:36:32.000000000 -0400
42856 @@ -87,7 +87,7 @@ static int ams_delta_lcd_get_contrast(st
42857 return ams_delta_lcd & AMS_DELTA_MAX_CONTRAST;
42858 }
42859
42860 -static struct lcd_ops ams_delta_lcd_ops = {
42861 +static const struct lcd_ops ams_delta_lcd_ops = {
42862 .get_power = ams_delta_lcd_get_power,
42863 .set_power = ams_delta_lcd_set_power,
42864 .get_contrast = ams_delta_lcd_get_contrast,
42865 diff -urNp linux-2.6.39/drivers/video/pxa3xx-gcu.c linux-2.6.39/drivers/video/pxa3xx-gcu.c
42866 --- linux-2.6.39/drivers/video/pxa3xx-gcu.c 2011-05-19 00:06:34.000000000 -0400
42867 +++ linux-2.6.39/drivers/video/pxa3xx-gcu.c 2011-05-22 19:36:32.000000000 -0400
42868 @@ -103,7 +103,7 @@ struct pxa3xx_gcu_priv {
42869 dma_addr_t shared_phys;
42870 struct resource *resource_mem;
42871 struct miscdevice misc_dev;
42872 - struct file_operations misc_fops;
42873 + const struct file_operations misc_fops;
42874 wait_queue_head_t wait_idle;
42875 wait_queue_head_t wait_free;
42876 spinlock_t spinlock;
42877 diff -urNp linux-2.6.39/drivers/video/sh_mobile_lcdcfb.c linux-2.6.39/drivers/video/sh_mobile_lcdcfb.c
42878 --- linux-2.6.39/drivers/video/sh_mobile_lcdcfb.c 2011-05-19 00:06:34.000000000 -0400
42879 +++ linux-2.6.39/drivers/video/sh_mobile_lcdcfb.c 2011-05-22 19:36:32.000000000 -0400
42880 @@ -245,7 +245,7 @@ static unsigned long lcdc_sys_read_data(
42881 return lcdc_read(ch->lcdc, _LDDRDR) & 0x3ffff;
42882 }
42883
42884 -struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
42885 +const struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
42886 lcdc_sys_write_index,
42887 lcdc_sys_write_data,
42888 lcdc_sys_read_data,
42889 diff -urNp linux-2.6.39/drivers/video/udlfb.c linux-2.6.39/drivers/video/udlfb.c
42890 --- linux-2.6.39/drivers/video/udlfb.c 2011-05-19 00:06:34.000000000 -0400
42891 +++ linux-2.6.39/drivers/video/udlfb.c 2011-05-22 19:36:32.000000000 -0400
42892 @@ -584,11 +584,11 @@ int dlfb_handle_damage(struct dlfb_data
42893 dlfb_urb_completion(urb);
42894
42895 error:
42896 - atomic_add(bytes_sent, &dev->bytes_sent);
42897 - atomic_add(bytes_identical, &dev->bytes_identical);
42898 - atomic_add(width*height*2, &dev->bytes_rendered);
42899 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42900 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
42901 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
42902 end_cycles = get_cycles();
42903 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
42904 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
42905 >> 10)), /* Kcycles */
42906 &dev->cpu_kcycles_used);
42907
42908 @@ -709,11 +709,11 @@ static void dlfb_dpy_deferred_io(struct
42909 dlfb_urb_completion(urb);
42910
42911 error:
42912 - atomic_add(bytes_sent, &dev->bytes_sent);
42913 - atomic_add(bytes_identical, &dev->bytes_identical);
42914 - atomic_add(bytes_rendered, &dev->bytes_rendered);
42915 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42916 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
42917 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
42918 end_cycles = get_cycles();
42919 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
42920 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
42921 >> 10)), /* Kcycles */
42922 &dev->cpu_kcycles_used);
42923 }
42924 @@ -1301,7 +1301,7 @@ static ssize_t metrics_bytes_rendered_sh
42925 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42926 struct dlfb_data *dev = fb_info->par;
42927 return snprintf(buf, PAGE_SIZE, "%u\n",
42928 - atomic_read(&dev->bytes_rendered));
42929 + atomic_read_unchecked(&dev->bytes_rendered));
42930 }
42931
42932 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
42933 @@ -1309,7 +1309,7 @@ static ssize_t metrics_bytes_identical_s
42934 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42935 struct dlfb_data *dev = fb_info->par;
42936 return snprintf(buf, PAGE_SIZE, "%u\n",
42937 - atomic_read(&dev->bytes_identical));
42938 + atomic_read_unchecked(&dev->bytes_identical));
42939 }
42940
42941 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
42942 @@ -1317,7 +1317,7 @@ static ssize_t metrics_bytes_sent_show(s
42943 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42944 struct dlfb_data *dev = fb_info->par;
42945 return snprintf(buf, PAGE_SIZE, "%u\n",
42946 - atomic_read(&dev->bytes_sent));
42947 + atomic_read_unchecked(&dev->bytes_sent));
42948 }
42949
42950 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
42951 @@ -1325,7 +1325,7 @@ static ssize_t metrics_cpu_kcycles_used_
42952 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42953 struct dlfb_data *dev = fb_info->par;
42954 return snprintf(buf, PAGE_SIZE, "%u\n",
42955 - atomic_read(&dev->cpu_kcycles_used));
42956 + atomic_read_unchecked(&dev->cpu_kcycles_used));
42957 }
42958
42959 static ssize_t edid_show(
42960 @@ -1382,10 +1382,10 @@ static ssize_t metrics_reset_store(struc
42961 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42962 struct dlfb_data *dev = fb_info->par;
42963
42964 - atomic_set(&dev->bytes_rendered, 0);
42965 - atomic_set(&dev->bytes_identical, 0);
42966 - atomic_set(&dev->bytes_sent, 0);
42967 - atomic_set(&dev->cpu_kcycles_used, 0);
42968 + atomic_set_unchecked(&dev->bytes_rendered, 0);
42969 + atomic_set_unchecked(&dev->bytes_identical, 0);
42970 + atomic_set_unchecked(&dev->bytes_sent, 0);
42971 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
42972
42973 return count;
42974 }
42975 diff -urNp linux-2.6.39/drivers/video/uvesafb.c linux-2.6.39/drivers/video/uvesafb.c
42976 --- linux-2.6.39/drivers/video/uvesafb.c 2011-05-19 00:06:34.000000000 -0400
42977 +++ linux-2.6.39/drivers/video/uvesafb.c 2011-05-22 19:36:32.000000000 -0400
42978 @@ -19,6 +19,7 @@
42979 #include <linux/io.h>
42980 #include <linux/mutex.h>
42981 #include <linux/slab.h>
42982 +#include <linux/moduleloader.h>
42983 #include <video/edid.h>
42984 #include <video/uvesafb.h>
42985 #ifdef CONFIG_X86
42986 @@ -121,7 +122,7 @@ static int uvesafb_helper_start(void)
42987 NULL,
42988 };
42989
42990 - return call_usermodehelper(v86d_path, argv, envp, 1);
42991 + return call_usermodehelper(v86d_path, argv, envp, UMH_WAIT_PROC);
42992 }
42993
42994 /*
42995 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(
42996 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
42997 par->pmi_setpal = par->ypan = 0;
42998 } else {
42999 +
43000 +#ifdef CONFIG_PAX_KERNEXEC
43001 +#ifdef CONFIG_MODULES
43002 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
43003 +#endif
43004 + if (!par->pmi_code) {
43005 + par->pmi_setpal = par->ypan = 0;
43006 + return 0;
43007 + }
43008 +#endif
43009 +
43010 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
43011 + task->t.regs.edi);
43012 +
43013 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43014 + pax_open_kernel();
43015 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
43016 + pax_close_kernel();
43017 +
43018 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
43019 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
43020 +#else
43021 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
43022 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
43023 +#endif
43024 +
43025 printk(KERN_INFO "uvesafb: protected mode interface info at "
43026 "%04x:%04x\n",
43027 (u16)task->t.regs.es, (u16)task->t.regs.edi);
43028 @@ -1821,6 +1844,11 @@ out:
43029 if (par->vbe_modes)
43030 kfree(par->vbe_modes);
43031
43032 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43033 + if (par->pmi_code)
43034 + module_free_exec(NULL, par->pmi_code);
43035 +#endif
43036 +
43037 framebuffer_release(info);
43038 return err;
43039 }
43040 @@ -1847,6 +1875,12 @@ static int uvesafb_remove(struct platfor
43041 kfree(par->vbe_state_orig);
43042 if (par->vbe_state_saved)
43043 kfree(par->vbe_state_saved);
43044 +
43045 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43046 + if (par->pmi_code)
43047 + module_free_exec(NULL, par->pmi_code);
43048 +#endif
43049 +
43050 }
43051
43052 framebuffer_release(info);
43053 @@ -2013,7 +2047,7 @@ static int param_set_scroll(const char *
43054
43055 return 0;
43056 }
43057 -static struct kernel_param_ops param_ops_scroll = {
43058 +static const struct kernel_param_ops param_ops_scroll = {
43059 .set = param_set_scroll,
43060 };
43061 #define param_check_scroll(name, p) __param_check(name, p, void)
43062 diff -urNp linux-2.6.39/drivers/video/vesafb.c linux-2.6.39/drivers/video/vesafb.c
43063 --- linux-2.6.39/drivers/video/vesafb.c 2011-05-19 00:06:34.000000000 -0400
43064 +++ linux-2.6.39/drivers/video/vesafb.c 2011-05-22 19:36:32.000000000 -0400
43065 @@ -9,6 +9,7 @@
43066 */
43067
43068 #include <linux/module.h>
43069 +#include <linux/moduleloader.h>
43070 #include <linux/kernel.h>
43071 #include <linux/errno.h>
43072 #include <linux/string.h>
43073 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /*
43074 static int vram_total __initdata; /* Set total amount of memory */
43075 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
43076 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
43077 -static void (*pmi_start)(void) __read_mostly;
43078 -static void (*pmi_pal) (void) __read_mostly;
43079 +static void (*pmi_start)(void) __read_only;
43080 +static void (*pmi_pal) (void) __read_only;
43081 static int depth __read_mostly;
43082 static int vga_compat __read_mostly;
43083 /* --------------------------------------------------------------------- */
43084 @@ -232,6 +233,7 @@ static int __init vesafb_probe(struct pl
43085 unsigned int size_vmode;
43086 unsigned int size_remap;
43087 unsigned int size_total;
43088 + void *pmi_code = NULL;
43089
43090 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
43091 return -ENODEV;
43092 @@ -274,10 +276,6 @@ static int __init vesafb_probe(struct pl
43093 size_remap = size_total;
43094 vesafb_fix.smem_len = size_remap;
43095
43096 -#ifndef __i386__
43097 - screen_info.vesapm_seg = 0;
43098 -#endif
43099 -
43100 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
43101 printk(KERN_WARNING
43102 "vesafb: cannot reserve video memory at 0x%lx\n",
43103 @@ -306,9 +304,21 @@ static int __init vesafb_probe(struct pl
43104 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
43105 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
43106
43107 +#ifdef __i386__
43108 +
43109 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43110 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
43111 + if (!pmi_code)
43112 +#elif !defined(CONFIG_PAX_KERNEXEC)
43113 + if (0)
43114 +#endif
43115 +
43116 +#endif
43117 + screen_info.vesapm_seg = 0;
43118 +
43119 if (screen_info.vesapm_seg) {
43120 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
43121 - screen_info.vesapm_seg,screen_info.vesapm_off);
43122 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
43123 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
43124 }
43125
43126 if (screen_info.vesapm_seg < 0xc000)
43127 @@ -316,9 +326,25 @@ static int __init vesafb_probe(struct pl
43128
43129 if (ypan || pmi_setpal) {
43130 unsigned short *pmi_base;
43131 - pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
43132 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
43133 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
43134 +
43135 + pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
43136 +
43137 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43138 + pax_open_kernel();
43139 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
43140 +#else
43141 + pmi_code = pmi_base;
43142 +#endif
43143 +
43144 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
43145 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
43146 +
43147 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43148 + pmi_start = ktva_ktla(pmi_start);
43149 + pmi_pal = ktva_ktla(pmi_pal);
43150 + pax_close_kernel();
43151 +#endif
43152 +
43153 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
43154 if (pmi_base[3]) {
43155 printk(KERN_INFO "vesafb: pmi: ports = ");
43156 @@ -487,6 +513,11 @@ static int __init vesafb_probe(struct pl
43157 info->node, info->fix.id);
43158 return 0;
43159 err:
43160 +
43161 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43162 + module_free_exec(NULL, pmi_code);
43163 +#endif
43164 +
43165 if (info->screen_base)
43166 iounmap(info->screen_base);
43167 framebuffer_release(info);
43168 diff -urNp linux-2.6.39/drivers/virtio/virtio_balloon.c linux-2.6.39/drivers/virtio/virtio_balloon.c
43169 --- linux-2.6.39/drivers/virtio/virtio_balloon.c 2011-05-19 00:06:34.000000000 -0400
43170 +++ linux-2.6.39/drivers/virtio/virtio_balloon.c 2011-05-22 19:36:32.000000000 -0400
43171 @@ -176,6 +176,8 @@ static void update_balloon_stats(struct
43172 struct sysinfo i;
43173 int idx = 0;
43174
43175 + pax_track_stack();
43176 +
43177 all_vm_events(events);
43178 si_meminfo(&i);
43179
43180 diff -urNp linux-2.6.39/drivers/xen/gntalloc.c linux-2.6.39/drivers/xen/gntalloc.c
43181 --- linux-2.6.39/drivers/xen/gntalloc.c 2011-05-19 00:06:34.000000000 -0400
43182 +++ linux-2.6.39/drivers/xen/gntalloc.c 2011-05-22 19:36:32.000000000 -0400
43183 @@ -440,7 +440,7 @@ static void gntalloc_vma_close(struct vm
43184 spin_unlock(&gref_lock);
43185 }
43186
43187 -static struct vm_operations_struct gntalloc_vmops = {
43188 +static const struct vm_operations_struct gntalloc_vmops = {
43189 .close = gntalloc_vma_close,
43190 };
43191
43192 diff -urNp linux-2.6.39/drivers/xen/gntdev.c linux-2.6.39/drivers/xen/gntdev.c
43193 --- linux-2.6.39/drivers/xen/gntdev.c 2011-05-19 00:06:34.000000000 -0400
43194 +++ linux-2.6.39/drivers/xen/gntdev.c 2011-05-22 19:36:32.000000000 -0400
43195 @@ -340,7 +340,7 @@ static void gntdev_vma_close(struct vm_a
43196 gntdev_put_map(map);
43197 }
43198
43199 -static struct vm_operations_struct gntdev_vmops = {
43200 +static const struct vm_operations_struct gntdev_vmops = {
43201 .close = gntdev_vma_close,
43202 };
43203
43204 @@ -404,7 +404,7 @@ static void mn_release(struct mmu_notifi
43205 spin_unlock(&priv->lock);
43206 }
43207
43208 -struct mmu_notifier_ops gntdev_mmu_ops = {
43209 +const struct mmu_notifier_ops gntdev_mmu_ops = {
43210 .release = mn_release,
43211 .invalidate_page = mn_invl_page,
43212 .invalidate_range_start = mn_invl_range_start,
43213 diff -urNp linux-2.6.39/drivers/xen/xenfs/privcmd.c linux-2.6.39/drivers/xen/xenfs/privcmd.c
43214 --- linux-2.6.39/drivers/xen/xenfs/privcmd.c 2011-05-19 00:06:34.000000000 -0400
43215 +++ linux-2.6.39/drivers/xen/xenfs/privcmd.c 2011-05-22 19:36:32.000000000 -0400
43216 @@ -268,7 +268,7 @@ static int mmap_return_errors(void *data
43217 return put_user(*mfnp, st->user++);
43218 }
43219
43220 -static struct vm_operations_struct privcmd_vm_ops;
43221 +static const struct vm_operations_struct privcmd_vm_ops;
43222
43223 static long privcmd_ioctl_mmap_batch(void __user *udata)
43224 {
43225 @@ -369,7 +369,7 @@ static int privcmd_fault(struct vm_area_
43226 return VM_FAULT_SIGBUS;
43227 }
43228
43229 -static struct vm_operations_struct privcmd_vm_ops = {
43230 +static const struct vm_operations_struct privcmd_vm_ops = {
43231 .fault = privcmd_fault
43232 };
43233
43234 diff -urNp linux-2.6.39/fs/9p/vfs_inode.c linux-2.6.39/fs/9p/vfs_inode.c
43235 --- linux-2.6.39/fs/9p/vfs_inode.c 2011-05-19 00:06:34.000000000 -0400
43236 +++ linux-2.6.39/fs/9p/vfs_inode.c 2011-05-22 19:36:32.000000000 -0400
43237 @@ -1210,7 +1210,7 @@ static void *v9fs_vfs_follow_link(struct
43238 void
43239 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
43240 {
43241 - char *s = nd_get_link(nd);
43242 + const char *s = nd_get_link(nd);
43243
43244 P9_DPRINTK(P9_DEBUG_VFS, " %s %s\n", dentry->d_name.name,
43245 IS_ERR(s) ? "<error>" : s);
43246 diff -urNp linux-2.6.39/fs/aio.c linux-2.6.39/fs/aio.c
43247 --- linux-2.6.39/fs/aio.c 2011-05-19 00:06:34.000000000 -0400
43248 +++ linux-2.6.39/fs/aio.c 2011-05-22 19:36:32.000000000 -0400
43249 @@ -119,7 +119,7 @@ static int aio_setup_ring(struct kioctx
43250 size += sizeof(struct io_event) * nr_events;
43251 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
43252
43253 - if (nr_pages < 0)
43254 + if (nr_pages <= 0)
43255 return -EINVAL;
43256
43257 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
43258 @@ -1088,6 +1088,8 @@ static int read_events(struct kioctx *ct
43259 struct aio_timeout to;
43260 int retry = 0;
43261
43262 + pax_track_stack();
43263 +
43264 /* needed to zero any padding within an entry (there shouldn't be
43265 * any, but C is fun!
43266 */
43267 diff -urNp linux-2.6.39/fs/attr.c linux-2.6.39/fs/attr.c
43268 --- linux-2.6.39/fs/attr.c 2011-05-19 00:06:34.000000000 -0400
43269 +++ linux-2.6.39/fs/attr.c 2011-05-22 19:41:37.000000000 -0400
43270 @@ -98,6 +98,7 @@ int inode_newsize_ok(const struct inode
43271 unsigned long limit;
43272
43273 limit = rlimit(RLIMIT_FSIZE);
43274 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
43275 if (limit != RLIM_INFINITY && offset > limit)
43276 goto out_sig;
43277 if (offset > inode->i_sb->s_maxbytes)
43278 diff -urNp linux-2.6.39/fs/befs/linuxvfs.c linux-2.6.39/fs/befs/linuxvfs.c
43279 --- linux-2.6.39/fs/befs/linuxvfs.c 2011-05-19 00:06:34.000000000 -0400
43280 +++ linux-2.6.39/fs/befs/linuxvfs.c 2011-05-22 19:36:32.000000000 -0400
43281 @@ -498,7 +498,7 @@ static void befs_put_link(struct dentry
43282 {
43283 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
43284 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
43285 - char *link = nd_get_link(nd);
43286 + const char *link = nd_get_link(nd);
43287 if (!IS_ERR(link))
43288 kfree(link);
43289 }
43290 diff -urNp linux-2.6.39/fs/binfmt_aout.c linux-2.6.39/fs/binfmt_aout.c
43291 --- linux-2.6.39/fs/binfmt_aout.c 2011-05-19 00:06:34.000000000 -0400
43292 +++ linux-2.6.39/fs/binfmt_aout.c 2011-05-22 19:41:37.000000000 -0400
43293 @@ -16,6 +16,7 @@
43294 #include <linux/string.h>
43295 #include <linux/fs.h>
43296 #include <linux/file.h>
43297 +#include <linux/security.h>
43298 #include <linux/stat.h>
43299 #include <linux/fcntl.h>
43300 #include <linux/ptrace.h>
43301 @@ -86,6 +87,8 @@ static int aout_core_dump(struct coredum
43302 #endif
43303 # define START_STACK(u) ((void __user *)u.start_stack)
43304
43305 + memset(&dump, 0, sizeof(dump));
43306 +
43307 fs = get_fs();
43308 set_fs(KERNEL_DS);
43309 has_dumped = 1;
43310 @@ -97,10 +100,12 @@ static int aout_core_dump(struct coredum
43311
43312 /* If the size of the dump file exceeds the rlimit, then see what would happen
43313 if we wrote the stack, but not the data area. */
43314 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
43315 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
43316 dump.u_dsize = 0;
43317
43318 /* Make sure we have enough room to write the stack and data areas. */
43319 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
43320 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
43321 dump.u_ssize = 0;
43322
43323 @@ -234,6 +239,8 @@ static int load_aout_binary(struct linux
43324 rlim = rlimit(RLIMIT_DATA);
43325 if (rlim >= RLIM_INFINITY)
43326 rlim = ~0;
43327 +
43328 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
43329 if (ex.a_data + ex.a_bss > rlim)
43330 return -ENOMEM;
43331
43332 @@ -262,6 +269,27 @@ static int load_aout_binary(struct linux
43333 install_exec_creds(bprm);
43334 current->flags &= ~PF_FORKNOEXEC;
43335
43336 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43337 + current->mm->pax_flags = 0UL;
43338 +#endif
43339 +
43340 +#ifdef CONFIG_PAX_PAGEEXEC
43341 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
43342 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
43343 +
43344 +#ifdef CONFIG_PAX_EMUTRAMP
43345 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
43346 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
43347 +#endif
43348 +
43349 +#ifdef CONFIG_PAX_MPROTECT
43350 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
43351 + current->mm->pax_flags |= MF_PAX_MPROTECT;
43352 +#endif
43353 +
43354 + }
43355 +#endif
43356 +
43357 if (N_MAGIC(ex) == OMAGIC) {
43358 unsigned long text_addr, map_size;
43359 loff_t pos;
43360 @@ -334,7 +362,7 @@ static int load_aout_binary(struct linux
43361
43362 down_write(&current->mm->mmap_sem);
43363 error = do_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
43364 - PROT_READ | PROT_WRITE | PROT_EXEC,
43365 + PROT_READ | PROT_WRITE,
43366 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
43367 fd_offset + ex.a_text);
43368 up_write(&current->mm->mmap_sem);
43369 diff -urNp linux-2.6.39/fs/binfmt_elf.c linux-2.6.39/fs/binfmt_elf.c
43370 --- linux-2.6.39/fs/binfmt_elf.c 2011-05-19 00:06:34.000000000 -0400
43371 +++ linux-2.6.39/fs/binfmt_elf.c 2011-05-22 19:41:37.000000000 -0400
43372 @@ -51,6 +51,10 @@ static int elf_core_dump(struct coredump
43373 #define elf_core_dump NULL
43374 #endif
43375
43376 +#ifdef CONFIG_PAX_MPROTECT
43377 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
43378 +#endif
43379 +
43380 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
43381 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
43382 #else
43383 @@ -70,6 +74,11 @@ static struct linux_binfmt elf_format =
43384 .load_binary = load_elf_binary,
43385 .load_shlib = load_elf_library,
43386 .core_dump = elf_core_dump,
43387 +
43388 +#ifdef CONFIG_PAX_MPROTECT
43389 + .handle_mprotect= elf_handle_mprotect,
43390 +#endif
43391 +
43392 .min_coredump = ELF_EXEC_PAGESIZE,
43393 };
43394
43395 @@ -77,6 +86,8 @@ static struct linux_binfmt elf_format =
43396
43397 static int set_brk(unsigned long start, unsigned long end)
43398 {
43399 + unsigned long e = end;
43400 +
43401 start = ELF_PAGEALIGN(start);
43402 end = ELF_PAGEALIGN(end);
43403 if (end > start) {
43404 @@ -87,7 +98,7 @@ static int set_brk(unsigned long start,
43405 if (BAD_ADDR(addr))
43406 return addr;
43407 }
43408 - current->mm->start_brk = current->mm->brk = end;
43409 + current->mm->start_brk = current->mm->brk = e;
43410 return 0;
43411 }
43412
43413 @@ -148,12 +159,15 @@ create_elf_tables(struct linux_binprm *b
43414 elf_addr_t __user *u_rand_bytes;
43415 const char *k_platform = ELF_PLATFORM;
43416 const char *k_base_platform = ELF_BASE_PLATFORM;
43417 - unsigned char k_rand_bytes[16];
43418 + u32 k_rand_bytes[4];
43419 int items;
43420 elf_addr_t *elf_info;
43421 int ei_index = 0;
43422 const struct cred *cred = current_cred();
43423 struct vm_area_struct *vma;
43424 + unsigned long saved_auxv[AT_VECTOR_SIZE];
43425 +
43426 + pax_track_stack();
43427
43428 /*
43429 * In some cases (e.g. Hyper-Threading), we want to avoid L1
43430 @@ -195,8 +209,12 @@ create_elf_tables(struct linux_binprm *b
43431 * Generate 16 random bytes for userspace PRNG seeding.
43432 */
43433 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
43434 - u_rand_bytes = (elf_addr_t __user *)
43435 - STACK_ALLOC(p, sizeof(k_rand_bytes));
43436 + srandom32(k_rand_bytes[0] ^ random32());
43437 + srandom32(k_rand_bytes[1] ^ random32());
43438 + srandom32(k_rand_bytes[2] ^ random32());
43439 + srandom32(k_rand_bytes[3] ^ random32());
43440 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
43441 + u_rand_bytes = (elf_addr_t __user *) p;
43442 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
43443 return -EFAULT;
43444
43445 @@ -308,9 +326,11 @@ create_elf_tables(struct linux_binprm *b
43446 return -EFAULT;
43447 current->mm->env_end = p;
43448
43449 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
43450 +
43451 /* Put the elf_info on the stack in the right place. */
43452 sp = (elf_addr_t __user *)envp + 1;
43453 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
43454 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
43455 return -EFAULT;
43456 return 0;
43457 }
43458 @@ -381,10 +401,10 @@ static unsigned long load_elf_interp(str
43459 {
43460 struct elf_phdr *elf_phdata;
43461 struct elf_phdr *eppnt;
43462 - unsigned long load_addr = 0;
43463 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
43464 int load_addr_set = 0;
43465 unsigned long last_bss = 0, elf_bss = 0;
43466 - unsigned long error = ~0UL;
43467 + unsigned long error = -EINVAL;
43468 unsigned long total_size;
43469 int retval, i, size;
43470
43471 @@ -430,6 +450,11 @@ static unsigned long load_elf_interp(str
43472 goto out_close;
43473 }
43474
43475 +#ifdef CONFIG_PAX_SEGMEXEC
43476 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
43477 + pax_task_size = SEGMEXEC_TASK_SIZE;
43478 +#endif
43479 +
43480 eppnt = elf_phdata;
43481 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
43482 if (eppnt->p_type == PT_LOAD) {
43483 @@ -473,8 +498,8 @@ static unsigned long load_elf_interp(str
43484 k = load_addr + eppnt->p_vaddr;
43485 if (BAD_ADDR(k) ||
43486 eppnt->p_filesz > eppnt->p_memsz ||
43487 - eppnt->p_memsz > TASK_SIZE ||
43488 - TASK_SIZE - eppnt->p_memsz < k) {
43489 + eppnt->p_memsz > pax_task_size ||
43490 + pax_task_size - eppnt->p_memsz < k) {
43491 error = -ENOMEM;
43492 goto out_close;
43493 }
43494 @@ -528,6 +553,193 @@ out:
43495 return error;
43496 }
43497
43498 +#if (defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)) && defined(CONFIG_PAX_SOFTMODE)
43499 +static unsigned long pax_parse_softmode(const struct elf_phdr * const elf_phdata)
43500 +{
43501 + unsigned long pax_flags = 0UL;
43502 +
43503 +#ifdef CONFIG_PAX_PAGEEXEC
43504 + if (elf_phdata->p_flags & PF_PAGEEXEC)
43505 + pax_flags |= MF_PAX_PAGEEXEC;
43506 +#endif
43507 +
43508 +#ifdef CONFIG_PAX_SEGMEXEC
43509 + if (elf_phdata->p_flags & PF_SEGMEXEC)
43510 + pax_flags |= MF_PAX_SEGMEXEC;
43511 +#endif
43512 +
43513 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
43514 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43515 + if ((__supported_pte_mask & _PAGE_NX))
43516 + pax_flags &= ~MF_PAX_SEGMEXEC;
43517 + else
43518 + pax_flags &= ~MF_PAX_PAGEEXEC;
43519 + }
43520 +#endif
43521 +
43522 +#ifdef CONFIG_PAX_EMUTRAMP
43523 + if (elf_phdata->p_flags & PF_EMUTRAMP)
43524 + pax_flags |= MF_PAX_EMUTRAMP;
43525 +#endif
43526 +
43527 +#ifdef CONFIG_PAX_MPROTECT
43528 + if (elf_phdata->p_flags & PF_MPROTECT)
43529 + pax_flags |= MF_PAX_MPROTECT;
43530 +#endif
43531 +
43532 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43533 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
43534 + pax_flags |= MF_PAX_RANDMMAP;
43535 +#endif
43536 +
43537 + return pax_flags;
43538 +}
43539 +#endif
43540 +
43541 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
43542 +static unsigned long pax_parse_hardmode(const struct elf_phdr * const elf_phdata)
43543 +{
43544 + unsigned long pax_flags = 0UL;
43545 +
43546 +#ifdef CONFIG_PAX_PAGEEXEC
43547 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
43548 + pax_flags |= MF_PAX_PAGEEXEC;
43549 +#endif
43550 +
43551 +#ifdef CONFIG_PAX_SEGMEXEC
43552 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
43553 + pax_flags |= MF_PAX_SEGMEXEC;
43554 +#endif
43555 +
43556 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
43557 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43558 + if ((__supported_pte_mask & _PAGE_NX))
43559 + pax_flags &= ~MF_PAX_SEGMEXEC;
43560 + else
43561 + pax_flags &= ~MF_PAX_PAGEEXEC;
43562 + }
43563 +#endif
43564 +
43565 +#ifdef CONFIG_PAX_EMUTRAMP
43566 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
43567 + pax_flags |= MF_PAX_EMUTRAMP;
43568 +#endif
43569 +
43570 +#ifdef CONFIG_PAX_MPROTECT
43571 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
43572 + pax_flags |= MF_PAX_MPROTECT;
43573 +#endif
43574 +
43575 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43576 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
43577 + pax_flags |= MF_PAX_RANDMMAP;
43578 +#endif
43579 +
43580 + return pax_flags;
43581 +}
43582 +#endif
43583 +
43584 +#ifdef CONFIG_PAX_EI_PAX
43585 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
43586 +{
43587 + unsigned long pax_flags = 0UL;
43588 +
43589 +#ifdef CONFIG_PAX_PAGEEXEC
43590 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
43591 + pax_flags |= MF_PAX_PAGEEXEC;
43592 +#endif
43593 +
43594 +#ifdef CONFIG_PAX_SEGMEXEC
43595 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
43596 + pax_flags |= MF_PAX_SEGMEXEC;
43597 +#endif
43598 +
43599 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
43600 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43601 + if ((__supported_pte_mask & _PAGE_NX))
43602 + pax_flags &= ~MF_PAX_SEGMEXEC;
43603 + else
43604 + pax_flags &= ~MF_PAX_PAGEEXEC;
43605 + }
43606 +#endif
43607 +
43608 +#ifdef CONFIG_PAX_EMUTRAMP
43609 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
43610 + pax_flags |= MF_PAX_EMUTRAMP;
43611 +#endif
43612 +
43613 +#ifdef CONFIG_PAX_MPROTECT
43614 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
43615 + pax_flags |= MF_PAX_MPROTECT;
43616 +#endif
43617 +
43618 +#ifdef CONFIG_PAX_ASLR
43619 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
43620 + pax_flags |= MF_PAX_RANDMMAP;
43621 +#endif
43622 +
43623 + return pax_flags;
43624 +}
43625 +#endif
43626 +
43627 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)
43628 +static long pax_parse_elf_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
43629 +{
43630 + unsigned long pax_flags = 0UL;
43631 +
43632 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
43633 + unsigned long i;
43634 + int found_flags = 0;
43635 +#endif
43636 +
43637 +#ifdef CONFIG_PAX_EI_PAX
43638 + pax_flags = pax_parse_ei_pax(elf_ex);
43639 +#endif
43640 +
43641 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
43642 + for (i = 0UL; i < elf_ex->e_phnum; i++)
43643 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
43644 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
43645 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
43646 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
43647 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
43648 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
43649 + return -EINVAL;
43650 +
43651 +#ifdef CONFIG_PAX_SOFTMODE
43652 + if (pax_softmode)
43653 + pax_flags = pax_parse_softmode(&elf_phdata[i]);
43654 + else
43655 +#endif
43656 +
43657 + pax_flags = pax_parse_hardmode(&elf_phdata[i]);
43658 + found_flags = 1;
43659 + break;
43660 + }
43661 +#endif
43662 +
43663 +#if !defined(CONFIG_PAX_EI_PAX) && defined(CONFIG_PAX_PT_PAX_FLAGS)
43664 + if (found_flags == 0) {
43665 + struct elf_phdr phdr;
43666 + memset(&phdr, 0, sizeof(phdr));
43667 + phdr.p_flags = PF_NOEMUTRAMP;
43668 +#ifdef CONFIG_PAX_SOFTMODE
43669 + if (pax_softmode)
43670 + pax_flags = pax_parse_softmode(&phdr);
43671 + else
43672 +#endif
43673 + pax_flags = pax_parse_hardmode(&phdr);
43674 + }
43675 +#endif
43676 +
43677 + if (0 > pax_check_flags(&pax_flags))
43678 + return -EINVAL;
43679 +
43680 + current->mm->pax_flags = pax_flags;
43681 + return 0;
43682 +}
43683 +#endif
43684 +
43685 /*
43686 * These are the functions used to load ELF style executables and shared
43687 * libraries. There is no binary dependent code anywhere else.
43688 @@ -544,6 +756,11 @@ static unsigned long randomize_stack_top
43689 {
43690 unsigned int random_variable = 0;
43691
43692 +#ifdef CONFIG_PAX_RANDUSTACK
43693 + if (randomize_va_space)
43694 + return stack_top - current->mm->delta_stack;
43695 +#endif
43696 +
43697 if ((current->flags & PF_RANDOMIZE) &&
43698 !(current->personality & ADDR_NO_RANDOMIZE)) {
43699 random_variable = get_random_int() & STACK_RND_MASK;
43700 @@ -562,7 +779,7 @@ static int load_elf_binary(struct linux_
43701 unsigned long load_addr = 0, load_bias = 0;
43702 int load_addr_set = 0;
43703 char * elf_interpreter = NULL;
43704 - unsigned long error;
43705 + unsigned long error = 0;
43706 struct elf_phdr *elf_ppnt, *elf_phdata;
43707 unsigned long elf_bss, elf_brk;
43708 int retval, i;
43709 @@ -572,11 +789,11 @@ static int load_elf_binary(struct linux_
43710 unsigned long start_code, end_code, start_data, end_data;
43711 unsigned long reloc_func_desc __maybe_unused = 0;
43712 int executable_stack = EXSTACK_DEFAULT;
43713 - unsigned long def_flags = 0;
43714 struct {
43715 struct elfhdr elf_ex;
43716 struct elfhdr interp_elf_ex;
43717 } *loc;
43718 + unsigned long pax_task_size = TASK_SIZE;
43719
43720 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
43721 if (!loc) {
43722 @@ -714,11 +931,81 @@ static int load_elf_binary(struct linux_
43723
43724 /* OK, This is the point of no return */
43725 current->flags &= ~PF_FORKNOEXEC;
43726 - current->mm->def_flags = def_flags;
43727 +
43728 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43729 + current->mm->pax_flags = 0UL;
43730 +#endif
43731 +
43732 +#ifdef CONFIG_PAX_DLRESOLVE
43733 + current->mm->call_dl_resolve = 0UL;
43734 +#endif
43735 +
43736 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
43737 + current->mm->call_syscall = 0UL;
43738 +#endif
43739 +
43740 +#ifdef CONFIG_PAX_ASLR
43741 + current->mm->delta_mmap = 0UL;
43742 + current->mm->delta_stack = 0UL;
43743 +#endif
43744 +
43745 + current->mm->def_flags = 0;
43746 +
43747 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)
43748 + if (0 > pax_parse_elf_flags(&loc->elf_ex, elf_phdata)) {
43749 + send_sig(SIGKILL, current, 0);
43750 + goto out_free_dentry;
43751 + }
43752 +#endif
43753 +
43754 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
43755 + pax_set_initial_flags(bprm);
43756 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
43757 + if (pax_set_initial_flags_func)
43758 + (pax_set_initial_flags_func)(bprm);
43759 +#endif
43760 +
43761 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
43762 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
43763 + current->mm->context.user_cs_limit = PAGE_SIZE;
43764 + current->mm->def_flags |= VM_PAGEEXEC;
43765 + }
43766 +#endif
43767 +
43768 +#ifdef CONFIG_PAX_SEGMEXEC
43769 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
43770 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
43771 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
43772 + pax_task_size = SEGMEXEC_TASK_SIZE;
43773 + current->mm->def_flags |= VM_NOHUGEPAGE;
43774 + }
43775 +#endif
43776 +
43777 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
43778 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43779 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
43780 + put_cpu();
43781 + }
43782 +#endif
43783
43784 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
43785 may depend on the personality. */
43786 SET_PERSONALITY(loc->elf_ex);
43787 +
43788 +#ifdef CONFIG_PAX_ASLR
43789 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43790 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
43791 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
43792 + }
43793 +#endif
43794 +
43795 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
43796 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43797 + executable_stack = EXSTACK_DISABLE_X;
43798 + current->personality &= ~READ_IMPLIES_EXEC;
43799 + } else
43800 +#endif
43801 +
43802 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
43803 current->personality |= READ_IMPLIES_EXEC;
43804
43805 @@ -800,6 +1087,20 @@ static int load_elf_binary(struct linux_
43806 #else
43807 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
43808 #endif
43809 +
43810 +#ifdef CONFIG_PAX_RANDMMAP
43811 + /* PaX: randomize base address at the default exe base if requested */
43812 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
43813 +#ifdef CONFIG_SPARC64
43814 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
43815 +#else
43816 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
43817 +#endif
43818 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
43819 + elf_flags |= MAP_FIXED;
43820 + }
43821 +#endif
43822 +
43823 }
43824
43825 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
43826 @@ -832,9 +1133,9 @@ static int load_elf_binary(struct linux_
43827 * allowed task size. Note that p_filesz must always be
43828 * <= p_memsz so it is only necessary to check p_memsz.
43829 */
43830 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43831 - elf_ppnt->p_memsz > TASK_SIZE ||
43832 - TASK_SIZE - elf_ppnt->p_memsz < k) {
43833 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43834 + elf_ppnt->p_memsz > pax_task_size ||
43835 + pax_task_size - elf_ppnt->p_memsz < k) {
43836 /* set_brk can never work. Avoid overflows. */
43837 send_sig(SIGKILL, current, 0);
43838 retval = -EINVAL;
43839 @@ -862,6 +1163,11 @@ static int load_elf_binary(struct linux_
43840 start_data += load_bias;
43841 end_data += load_bias;
43842
43843 +#ifdef CONFIG_PAX_RANDMMAP
43844 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
43845 + elf_brk += PAGE_SIZE + ((pax_get_random_long() & ~PAGE_MASK) << 4);
43846 +#endif
43847 +
43848 /* Calling set_brk effectively mmaps the pages that we need
43849 * for the bss and break sections. We must do this before
43850 * mapping in the interpreter, to make sure it doesn't wind
43851 @@ -873,9 +1179,11 @@ static int load_elf_binary(struct linux_
43852 goto out_free_dentry;
43853 }
43854 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
43855 - send_sig(SIGSEGV, current, 0);
43856 - retval = -EFAULT; /* Nobody gets to see this, but.. */
43857 - goto out_free_dentry;
43858 + /*
43859 + * This bss-zeroing can fail if the ELF
43860 + * file specifies odd protections. So
43861 + * we don't check the return value
43862 + */
43863 }
43864
43865 if (elf_interpreter) {
43866 @@ -1090,7 +1398,7 @@ out:
43867 * Decide what to dump of a segment, part, all or none.
43868 */
43869 static unsigned long vma_dump_size(struct vm_area_struct *vma,
43870 - unsigned long mm_flags)
43871 + unsigned long mm_flags, long signr)
43872 {
43873 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
43874
43875 @@ -1124,7 +1432,7 @@ static unsigned long vma_dump_size(struc
43876 if (vma->vm_file == NULL)
43877 return 0;
43878
43879 - if (FILTER(MAPPED_PRIVATE))
43880 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
43881 goto whole;
43882
43883 /*
43884 @@ -1346,9 +1654,9 @@ static void fill_auxv_note(struct memelf
43885 {
43886 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
43887 int i = 0;
43888 - do
43889 + do {
43890 i += 2;
43891 - while (auxv[i - 2] != AT_NULL);
43892 + } while (auxv[i - 2] != AT_NULL);
43893 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
43894 }
43895
43896 @@ -1854,14 +2162,14 @@ static void fill_extnum_info(struct elfh
43897 }
43898
43899 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
43900 - unsigned long mm_flags)
43901 + struct coredump_params *cprm)
43902 {
43903 struct vm_area_struct *vma;
43904 size_t size = 0;
43905
43906 for (vma = first_vma(current, gate_vma); vma != NULL;
43907 vma = next_vma(vma, gate_vma))
43908 - size += vma_dump_size(vma, mm_flags);
43909 + size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43910 return size;
43911 }
43912
43913 @@ -1955,7 +2263,7 @@ static int elf_core_dump(struct coredump
43914
43915 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
43916
43917 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
43918 + offset += elf_core_vma_data_size(gate_vma, cprm);
43919 offset += elf_core_extra_data_size();
43920 e_shoff = offset;
43921
43922 @@ -1969,10 +2277,12 @@ static int elf_core_dump(struct coredump
43923 offset = dataoff;
43924
43925 size += sizeof(*elf);
43926 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43927 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
43928 goto end_coredump;
43929
43930 size += sizeof(*phdr4note);
43931 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43932 if (size > cprm->limit
43933 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
43934 goto end_coredump;
43935 @@ -1986,7 +2296,7 @@ static int elf_core_dump(struct coredump
43936 phdr.p_offset = offset;
43937 phdr.p_vaddr = vma->vm_start;
43938 phdr.p_paddr = 0;
43939 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
43940 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43941 phdr.p_memsz = vma->vm_end - vma->vm_start;
43942 offset += phdr.p_filesz;
43943 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
43944 @@ -1997,6 +2307,7 @@ static int elf_core_dump(struct coredump
43945 phdr.p_align = ELF_EXEC_PAGESIZE;
43946
43947 size += sizeof(phdr);
43948 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43949 if (size > cprm->limit
43950 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
43951 goto end_coredump;
43952 @@ -2021,7 +2332,7 @@ static int elf_core_dump(struct coredump
43953 unsigned long addr;
43954 unsigned long end;
43955
43956 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
43957 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43958
43959 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
43960 struct page *page;
43961 @@ -2030,6 +2341,7 @@ static int elf_core_dump(struct coredump
43962 page = get_dump_page(addr);
43963 if (page) {
43964 void *kaddr = kmap(page);
43965 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
43966 stop = ((size += PAGE_SIZE) > cprm->limit) ||
43967 !dump_write(cprm->file, kaddr,
43968 PAGE_SIZE);
43969 @@ -2047,6 +2359,7 @@ static int elf_core_dump(struct coredump
43970
43971 if (e_phnum == PN_XNUM) {
43972 size += sizeof(*shdr4extnum);
43973 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43974 if (size > cprm->limit
43975 || !dump_write(cprm->file, shdr4extnum,
43976 sizeof(*shdr4extnum)))
43977 @@ -2067,6 +2380,97 @@ out:
43978
43979 #endif /* CONFIG_ELF_CORE */
43980
43981 +#ifdef CONFIG_PAX_MPROTECT
43982 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
43983 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
43984 + * we'll remove VM_MAYWRITE for good on RELRO segments.
43985 + *
43986 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
43987 + * basis because we want to allow the common case and not the special ones.
43988 + */
43989 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
43990 +{
43991 + struct elfhdr elf_h;
43992 + struct elf_phdr elf_p;
43993 + unsigned long i;
43994 + unsigned long oldflags;
43995 + bool is_textrel_rw, is_textrel_rx, is_relro;
43996 +
43997 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
43998 + return;
43999 +
44000 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
44001 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
44002 +
44003 +#ifdef CONFIG_PAX_ELFRELOCS
44004 + /* possible TEXTREL */
44005 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
44006 + 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);
44007 +#else
44008 + is_textrel_rw = false;
44009 + is_textrel_rx = false;
44010 +#endif
44011 +
44012 + /* possible RELRO */
44013 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
44014 +
44015 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
44016 + return;
44017 +
44018 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
44019 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
44020 +
44021 +#ifdef CONFIG_PAX_ETEXECRELOCS
44022 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
44023 +#else
44024 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
44025 +#endif
44026 +
44027 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
44028 + !elf_check_arch(&elf_h) ||
44029 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
44030 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
44031 + return;
44032 +
44033 + for (i = 0UL; i < elf_h.e_phnum; i++) {
44034 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
44035 + return;
44036 + switch (elf_p.p_type) {
44037 + case PT_DYNAMIC:
44038 + if (!is_textrel_rw && !is_textrel_rx)
44039 + continue;
44040 + i = 0UL;
44041 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
44042 + elf_dyn dyn;
44043 +
44044 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
44045 + return;
44046 + if (dyn.d_tag == DT_NULL)
44047 + return;
44048 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
44049 + gr_log_textrel(vma);
44050 + if (is_textrel_rw)
44051 + vma->vm_flags |= VM_MAYWRITE;
44052 + else
44053 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
44054 + vma->vm_flags &= ~VM_MAYWRITE;
44055 + return;
44056 + }
44057 + i++;
44058 + }
44059 + return;
44060 +
44061 + case PT_GNU_RELRO:
44062 + if (!is_relro)
44063 + continue;
44064 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
44065 + vma->vm_flags &= ~VM_MAYWRITE;
44066 + return;
44067 + }
44068 + }
44069 +}
44070 +#endif
44071 +
44072 static int __init init_elf_binfmt(void)
44073 {
44074 return register_binfmt(&elf_format);
44075 diff -urNp linux-2.6.39/fs/binfmt_flat.c linux-2.6.39/fs/binfmt_flat.c
44076 --- linux-2.6.39/fs/binfmt_flat.c 2011-05-19 00:06:34.000000000 -0400
44077 +++ linux-2.6.39/fs/binfmt_flat.c 2011-05-22 19:36:32.000000000 -0400
44078 @@ -567,7 +567,9 @@ static int load_flat_file(struct linux_b
44079 realdatastart = (unsigned long) -ENOMEM;
44080 printk("Unable to allocate RAM for process data, errno %d\n",
44081 (int)-realdatastart);
44082 + down_write(&current->mm->mmap_sem);
44083 do_munmap(current->mm, textpos, text_len);
44084 + up_write(&current->mm->mmap_sem);
44085 ret = realdatastart;
44086 goto err;
44087 }
44088 @@ -591,8 +593,10 @@ static int load_flat_file(struct linux_b
44089 }
44090 if (IS_ERR_VALUE(result)) {
44091 printk("Unable to read data+bss, errno %d\n", (int)-result);
44092 + down_write(&current->mm->mmap_sem);
44093 do_munmap(current->mm, textpos, text_len);
44094 do_munmap(current->mm, realdatastart, len);
44095 + up_write(&current->mm->mmap_sem);
44096 ret = result;
44097 goto err;
44098 }
44099 @@ -661,8 +665,10 @@ static int load_flat_file(struct linux_b
44100 }
44101 if (IS_ERR_VALUE(result)) {
44102 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
44103 + down_write(&current->mm->mmap_sem);
44104 do_munmap(current->mm, textpos, text_len + data_len + extra +
44105 MAX_SHARED_LIBS * sizeof(unsigned long));
44106 + up_write(&current->mm->mmap_sem);
44107 ret = result;
44108 goto err;
44109 }
44110 diff -urNp linux-2.6.39/fs/bio.c linux-2.6.39/fs/bio.c
44111 --- linux-2.6.39/fs/bio.c 2011-05-19 00:06:34.000000000 -0400
44112 +++ linux-2.6.39/fs/bio.c 2011-05-22 19:36:32.000000000 -0400
44113 @@ -1233,7 +1233,7 @@ static void bio_copy_kern_endio(struct b
44114 const int read = bio_data_dir(bio) == READ;
44115 struct bio_map_data *bmd = bio->bi_private;
44116 int i;
44117 - char *p = bmd->sgvecs[0].iov_base;
44118 + char *p = (__force char *)bmd->sgvecs[0].iov_base;
44119
44120 __bio_for_each_segment(bvec, bio, i, 0) {
44121 char *addr = page_address(bvec->bv_page);
44122 diff -urNp linux-2.6.39/fs/block_dev.c linux-2.6.39/fs/block_dev.c
44123 --- linux-2.6.39/fs/block_dev.c 2011-05-19 00:06:34.000000000 -0400
44124 +++ linux-2.6.39/fs/block_dev.c 2011-05-22 19:36:32.000000000 -0400
44125 @@ -671,7 +671,7 @@ static bool bd_may_claim(struct block_de
44126 else if (bdev->bd_contains == bdev)
44127 return true; /* is a whole device which isn't held */
44128
44129 - else if (whole->bd_holder == bd_may_claim)
44130 + else if (whole->bd_holder == (void *)bd_may_claim)
44131 return true; /* is a partition of a device that is being partitioned */
44132 else if (whole->bd_holder != NULL)
44133 return false; /* is a partition of a held device */
44134 diff -urNp linux-2.6.39/fs/btrfs/compression.c linux-2.6.39/fs/btrfs/compression.c
44135 --- linux-2.6.39/fs/btrfs/compression.c 2011-05-19 00:06:34.000000000 -0400
44136 +++ linux-2.6.39/fs/btrfs/compression.c 2011-05-22 19:36:32.000000000 -0400
44137 @@ -719,7 +719,7 @@ static int comp_num_workspace[BTRFS_COMP
44138 static atomic_t comp_alloc_workspace[BTRFS_COMPRESS_TYPES];
44139 static wait_queue_head_t comp_workspace_wait[BTRFS_COMPRESS_TYPES];
44140
44141 -struct btrfs_compress_op *btrfs_compress_op[] = {
44142 +const struct btrfs_compress_op *btrfs_compress_op[] = {
44143 &btrfs_zlib_compress,
44144 &btrfs_lzo_compress,
44145 };
44146 diff -urNp linux-2.6.39/fs/btrfs/compression.h linux-2.6.39/fs/btrfs/compression.h
44147 --- linux-2.6.39/fs/btrfs/compression.h 2011-05-19 00:06:34.000000000 -0400
44148 +++ linux-2.6.39/fs/btrfs/compression.h 2011-05-22 19:36:32.000000000 -0400
44149 @@ -77,7 +77,7 @@ struct btrfs_compress_op {
44150 size_t srclen, size_t destlen);
44151 };
44152
44153 -extern struct btrfs_compress_op btrfs_zlib_compress;
44154 -extern struct btrfs_compress_op btrfs_lzo_compress;
44155 +extern const struct btrfs_compress_op btrfs_zlib_compress;
44156 +extern const struct btrfs_compress_op btrfs_lzo_compress;
44157
44158 #endif
44159 diff -urNp linux-2.6.39/fs/btrfs/ctree.c linux-2.6.39/fs/btrfs/ctree.c
44160 --- linux-2.6.39/fs/btrfs/ctree.c 2011-05-19 00:06:34.000000000 -0400
44161 +++ linux-2.6.39/fs/btrfs/ctree.c 2011-05-22 19:36:32.000000000 -0400
44162 @@ -461,9 +461,12 @@ static noinline int __btrfs_cow_block(st
44163 free_extent_buffer(buf);
44164 add_root_to_dirty_list(root);
44165 } else {
44166 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
44167 - parent_start = parent->start;
44168 - else
44169 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
44170 + if (parent)
44171 + parent_start = parent->start;
44172 + else
44173 + parent_start = 0;
44174 + } else
44175 parent_start = 0;
44176
44177 WARN_ON(trans->transid != btrfs_header_generation(parent));
44178 @@ -3647,7 +3650,6 @@ setup_items_for_insert(struct btrfs_tran
44179
44180 ret = 0;
44181 if (slot == 0) {
44182 - struct btrfs_disk_key disk_key;
44183 btrfs_cpu_key_to_disk(&disk_key, cpu_key);
44184 ret = fixup_low_keys(trans, root, path, &disk_key, 1);
44185 }
44186 diff -urNp linux-2.6.39/fs/btrfs/disk-io.c linux-2.6.39/fs/btrfs/disk-io.c
44187 --- linux-2.6.39/fs/btrfs/disk-io.c 2011-05-19 00:06:34.000000000 -0400
44188 +++ linux-2.6.39/fs/btrfs/disk-io.c 2011-05-22 19:36:32.000000000 -0400
44189 @@ -42,7 +42,7 @@
44190 #include "tree-log.h"
44191 #include "free-space-cache.h"
44192
44193 -static struct extent_io_ops btree_extent_io_ops;
44194 +static const struct extent_io_ops btree_extent_io_ops;
44195 static void end_workqueue_fn(struct btrfs_work *work);
44196 static void free_fs_root(struct btrfs_root *root);
44197 static void btrfs_check_super_valid(struct btrfs_fs_info *fs_info,
44198 @@ -3070,7 +3070,7 @@ static int btrfs_cleanup_transaction(str
44199 return 0;
44200 }
44201
44202 -static struct extent_io_ops btree_extent_io_ops = {
44203 +static const struct extent_io_ops btree_extent_io_ops = {
44204 .write_cache_pages_lock_hook = btree_lock_page_hook,
44205 .readpage_end_io_hook = btree_readpage_end_io_hook,
44206 .submit_bio_hook = btree_submit_bio_hook,
44207 diff -urNp linux-2.6.39/fs/btrfs/extent_io.h linux-2.6.39/fs/btrfs/extent_io.h
44208 --- linux-2.6.39/fs/btrfs/extent_io.h 2011-05-19 00:06:34.000000000 -0400
44209 +++ linux-2.6.39/fs/btrfs/extent_io.h 2011-05-22 19:36:32.000000000 -0400
44210 @@ -56,36 +56,36 @@ typedef int (extent_submit_bio_hook_t)(s
44211 struct bio *bio, int mirror_num,
44212 unsigned long bio_flags, u64 bio_offset);
44213 struct extent_io_ops {
44214 - int (*fill_delalloc)(struct inode *inode, struct page *locked_page,
44215 + int (* const fill_delalloc)(struct inode *inode, struct page *locked_page,
44216 u64 start, u64 end, int *page_started,
44217 unsigned long *nr_written);
44218 - int (*writepage_start_hook)(struct page *page, u64 start, u64 end);
44219 - int (*writepage_io_hook)(struct page *page, u64 start, u64 end);
44220 + int (* const writepage_start_hook)(struct page *page, u64 start, u64 end);
44221 + int (* const writepage_io_hook)(struct page *page, u64 start, u64 end);
44222 extent_submit_bio_hook_t *submit_bio_hook;
44223 - int (*merge_bio_hook)(struct page *page, unsigned long offset,
44224 + int (* const merge_bio_hook)(struct page *page, unsigned long offset,
44225 size_t size, struct bio *bio,
44226 unsigned long bio_flags);
44227 - int (*readpage_io_hook)(struct page *page, u64 start, u64 end);
44228 - int (*readpage_io_failed_hook)(struct bio *bio, struct page *page,
44229 + int (* const readpage_io_hook)(struct page *page, u64 start, u64 end);
44230 + int (* const readpage_io_failed_hook)(struct bio *bio, struct page *page,
44231 u64 start, u64 end,
44232 struct extent_state *state);
44233 - int (*writepage_io_failed_hook)(struct bio *bio, struct page *page,
44234 + int (* const writepage_io_failed_hook)(struct bio *bio, struct page *page,
44235 u64 start, u64 end,
44236 struct extent_state *state);
44237 - int (*readpage_end_io_hook)(struct page *page, u64 start, u64 end,
44238 + int (* const readpage_end_io_hook)(struct page *page, u64 start, u64 end,
44239 struct extent_state *state);
44240 - int (*writepage_end_io_hook)(struct page *page, u64 start, u64 end,
44241 + int (* const writepage_end_io_hook)(struct page *page, u64 start, u64 end,
44242 struct extent_state *state, int uptodate);
44243 - int (*set_bit_hook)(struct inode *inode, struct extent_state *state,
44244 + int (* const set_bit_hook)(struct inode *inode, struct extent_state *state,
44245 int *bits);
44246 - int (*clear_bit_hook)(struct inode *inode, struct extent_state *state,
44247 + int (* const clear_bit_hook)(struct inode *inode, struct extent_state *state,
44248 int *bits);
44249 - int (*merge_extent_hook)(struct inode *inode,
44250 + int (* const merge_extent_hook)(struct inode *inode,
44251 struct extent_state *new,
44252 struct extent_state *other);
44253 - int (*split_extent_hook)(struct inode *inode,
44254 + int (* const split_extent_hook)(struct inode *inode,
44255 struct extent_state *orig, u64 split);
44256 - int (*write_cache_pages_lock_hook)(struct page *page);
44257 + int (* const write_cache_pages_lock_hook)(struct page *page);
44258 };
44259
44260 struct extent_io_tree {
44261 @@ -95,7 +95,7 @@ struct extent_io_tree {
44262 u64 dirty_bytes;
44263 spinlock_t lock;
44264 spinlock_t buffer_lock;
44265 - struct extent_io_ops *ops;
44266 + const struct extent_io_ops *ops;
44267 };
44268
44269 struct extent_state {
44270 diff -urNp linux-2.6.39/fs/btrfs/free-space-cache.c linux-2.6.39/fs/btrfs/free-space-cache.c
44271 --- linux-2.6.39/fs/btrfs/free-space-cache.c 2011-05-19 00:06:34.000000000 -0400
44272 +++ linux-2.6.39/fs/btrfs/free-space-cache.c 2011-05-22 19:36:32.000000000 -0400
44273 @@ -1910,8 +1910,6 @@ u64 btrfs_alloc_from_cluster(struct btrf
44274 while(1) {
44275 if (entry->bytes < bytes ||
44276 (!entry->bitmap && entry->offset < min_start)) {
44277 - struct rb_node *node;
44278 -
44279 node = rb_next(&entry->offset_index);
44280 if (!node)
44281 break;
44282 @@ -1925,7 +1923,6 @@ u64 btrfs_alloc_from_cluster(struct btrf
44283 cluster, entry, bytes,
44284 min_start);
44285 if (ret == 0) {
44286 - struct rb_node *node;
44287 node = rb_next(&entry->offset_index);
44288 if (!node)
44289 break;
44290 diff -urNp linux-2.6.39/fs/btrfs/inode.c linux-2.6.39/fs/btrfs/inode.c
44291 --- linux-2.6.39/fs/btrfs/inode.c 2011-05-19 00:06:34.000000000 -0400
44292 +++ linux-2.6.39/fs/btrfs/inode.c 2011-05-22 20:42:42.000000000 -0400
44293 @@ -65,7 +65,7 @@ static const struct inode_operations btr
44294 static const struct address_space_operations btrfs_aops;
44295 static const struct address_space_operations btrfs_symlink_aops;
44296 static const struct file_operations btrfs_dir_file_operations;
44297 -static struct extent_io_ops btrfs_extent_io_ops;
44298 +static const struct extent_io_ops btrfs_extent_io_ops;
44299
44300 static struct kmem_cache *btrfs_inode_cachep;
44301 struct kmem_cache *btrfs_trans_handle_cachep;
44302 @@ -6947,7 +6947,7 @@ fail:
44303 return -ENOMEM;
44304 }
44305
44306 -static int btrfs_getattr(struct vfsmount *mnt,
44307 +int btrfs_getattr(struct vfsmount *mnt,
44308 struct dentry *dentry, struct kstat *stat)
44309 {
44310 struct inode *inode = dentry->d_inode;
44311 @@ -6959,6 +6959,14 @@ static int btrfs_getattr(struct vfsmount
44312 return 0;
44313 }
44314
44315 +EXPORT_SYMBOL(btrfs_getattr);
44316 +
44317 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
44318 +{
44319 + return BTRFS_I(inode)->root->anon_super.s_dev;
44320 +}
44321 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
44322 +
44323 /*
44324 * If a file is moved, it will inherit the cow and compression flags of the new
44325 * directory.
44326 @@ -7488,7 +7496,7 @@ static const struct file_operations btrf
44327 .fsync = btrfs_sync_file,
44328 };
44329
44330 -static struct extent_io_ops btrfs_extent_io_ops = {
44331 +static const struct extent_io_ops btrfs_extent_io_ops = {
44332 .fill_delalloc = run_delalloc_range,
44333 .submit_bio_hook = btrfs_submit_bio_hook,
44334 .merge_bio_hook = btrfs_merge_bio_hook,
44335 diff -urNp linux-2.6.39/fs/btrfs/ioctl.c linux-2.6.39/fs/btrfs/ioctl.c
44336 --- linux-2.6.39/fs/btrfs/ioctl.c 2011-05-19 00:06:34.000000000 -0400
44337 +++ linux-2.6.39/fs/btrfs/ioctl.c 2011-05-22 19:41:37.000000000 -0400
44338 @@ -2361,9 +2361,12 @@ long btrfs_ioctl_space_info(struct btrfs
44339 for (i = 0; i < num_types; i++) {
44340 struct btrfs_space_info *tmp;
44341
44342 + /* Don't copy in more than we allocated */
44343 if (!slot_count)
44344 break;
44345
44346 + slot_count--;
44347 +
44348 info = NULL;
44349 rcu_read_lock();
44350 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
44351 @@ -2385,10 +2388,7 @@ long btrfs_ioctl_space_info(struct btrfs
44352 memcpy(dest, &space, sizeof(space));
44353 dest++;
44354 space_args.total_spaces++;
44355 - slot_count--;
44356 }
44357 - if (!slot_count)
44358 - break;
44359 }
44360 up_read(&info->groups_sem);
44361 }
44362 diff -urNp linux-2.6.39/fs/btrfs/lzo.c linux-2.6.39/fs/btrfs/lzo.c
44363 --- linux-2.6.39/fs/btrfs/lzo.c 2011-05-19 00:06:34.000000000 -0400
44364 +++ linux-2.6.39/fs/btrfs/lzo.c 2011-05-22 19:36:32.000000000 -0400
44365 @@ -418,7 +418,7 @@ out:
44366 return ret;
44367 }
44368
44369 -struct btrfs_compress_op btrfs_lzo_compress = {
44370 +const struct btrfs_compress_op btrfs_lzo_compress = {
44371 .alloc_workspace = lzo_alloc_workspace,
44372 .free_workspace = lzo_free_workspace,
44373 .compress_pages = lzo_compress_pages,
44374 diff -urNp linux-2.6.39/fs/btrfs/relocation.c linux-2.6.39/fs/btrfs/relocation.c
44375 --- linux-2.6.39/fs/btrfs/relocation.c 2011-05-19 00:06:34.000000000 -0400
44376 +++ linux-2.6.39/fs/btrfs/relocation.c 2011-05-22 19:36:32.000000000 -0400
44377 @@ -1239,7 +1239,7 @@ static int __update_reloc_root(struct bt
44378 }
44379 spin_unlock(&rc->reloc_root_tree.lock);
44380
44381 - BUG_ON((struct btrfs_root *)node->data != root);
44382 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
44383
44384 if (!del) {
44385 spin_lock(&rc->reloc_root_tree.lock);
44386 diff -urNp linux-2.6.39/fs/btrfs/zlib.c linux-2.6.39/fs/btrfs/zlib.c
44387 --- linux-2.6.39/fs/btrfs/zlib.c 2011-05-19 00:06:34.000000000 -0400
44388 +++ linux-2.6.39/fs/btrfs/zlib.c 2011-05-22 19:36:32.000000000 -0400
44389 @@ -390,7 +390,7 @@ next:
44390 return ret;
44391 }
44392
44393 -struct btrfs_compress_op btrfs_zlib_compress = {
44394 +const struct btrfs_compress_op btrfs_zlib_compress = {
44395 .alloc_workspace = zlib_alloc_workspace,
44396 .free_workspace = zlib_free_workspace,
44397 .compress_pages = zlib_compress_pages,
44398 diff -urNp linux-2.6.39/fs/cachefiles/bind.c linux-2.6.39/fs/cachefiles/bind.c
44399 --- linux-2.6.39/fs/cachefiles/bind.c 2011-05-19 00:06:34.000000000 -0400
44400 +++ linux-2.6.39/fs/cachefiles/bind.c 2011-05-22 19:36:32.000000000 -0400
44401 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachef
44402 args);
44403
44404 /* start by checking things over */
44405 - ASSERT(cache->fstop_percent >= 0 &&
44406 - cache->fstop_percent < cache->fcull_percent &&
44407 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
44408 cache->fcull_percent < cache->frun_percent &&
44409 cache->frun_percent < 100);
44410
44411 - ASSERT(cache->bstop_percent >= 0 &&
44412 - cache->bstop_percent < cache->bcull_percent &&
44413 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
44414 cache->bcull_percent < cache->brun_percent &&
44415 cache->brun_percent < 100);
44416
44417 diff -urNp linux-2.6.39/fs/cachefiles/daemon.c linux-2.6.39/fs/cachefiles/daemon.c
44418 --- linux-2.6.39/fs/cachefiles/daemon.c 2011-05-19 00:06:34.000000000 -0400
44419 +++ linux-2.6.39/fs/cachefiles/daemon.c 2011-05-22 19:36:32.000000000 -0400
44420 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(st
44421 if (n > buflen)
44422 return -EMSGSIZE;
44423
44424 - if (copy_to_user(_buffer, buffer, n) != 0)
44425 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
44426 return -EFAULT;
44427
44428 return n;
44429 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(s
44430 if (test_bit(CACHEFILES_DEAD, &cache->flags))
44431 return -EIO;
44432
44433 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
44434 + if (datalen > PAGE_SIZE - 1)
44435 return -EOPNOTSUPP;
44436
44437 /* drag the command string into the kernel so we can parse it */
44438 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struc
44439 if (args[0] != '%' || args[1] != '\0')
44440 return -EINVAL;
44441
44442 - if (fstop < 0 || fstop >= cache->fcull_percent)
44443 + if (fstop >= cache->fcull_percent)
44444 return cachefiles_daemon_range_error(cache, args);
44445
44446 cache->fstop_percent = fstop;
44447 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struc
44448 if (args[0] != '%' || args[1] != '\0')
44449 return -EINVAL;
44450
44451 - if (bstop < 0 || bstop >= cache->bcull_percent)
44452 + if (bstop >= cache->bcull_percent)
44453 return cachefiles_daemon_range_error(cache, args);
44454
44455 cache->bstop_percent = bstop;
44456 diff -urNp linux-2.6.39/fs/cachefiles/internal.h linux-2.6.39/fs/cachefiles/internal.h
44457 --- linux-2.6.39/fs/cachefiles/internal.h 2011-05-19 00:06:34.000000000 -0400
44458 +++ linux-2.6.39/fs/cachefiles/internal.h 2011-05-22 19:36:32.000000000 -0400
44459 @@ -57,7 +57,7 @@ struct cachefiles_cache {
44460 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
44461 struct rb_root active_nodes; /* active nodes (can't be culled) */
44462 rwlock_t active_lock; /* lock for active_nodes */
44463 - atomic_t gravecounter; /* graveyard uniquifier */
44464 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
44465 unsigned frun_percent; /* when to stop culling (% files) */
44466 unsigned fcull_percent; /* when to start culling (% files) */
44467 unsigned fstop_percent; /* when to stop allocating (% files) */
44468 @@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struc
44469 * proc.c
44470 */
44471 #ifdef CONFIG_CACHEFILES_HISTOGRAM
44472 -extern atomic_t cachefiles_lookup_histogram[HZ];
44473 -extern atomic_t cachefiles_mkdir_histogram[HZ];
44474 -extern atomic_t cachefiles_create_histogram[HZ];
44475 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
44476 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
44477 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
44478
44479 extern int __init cachefiles_proc_init(void);
44480 extern void cachefiles_proc_cleanup(void);
44481 static inline
44482 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
44483 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
44484 {
44485 unsigned long jif = jiffies - start_jif;
44486 if (jif >= HZ)
44487 jif = HZ - 1;
44488 - atomic_inc(&histogram[jif]);
44489 + atomic_inc_unchecked(&histogram[jif]);
44490 }
44491
44492 #else
44493 diff -urNp linux-2.6.39/fs/cachefiles/namei.c linux-2.6.39/fs/cachefiles/namei.c
44494 --- linux-2.6.39/fs/cachefiles/namei.c 2011-05-19 00:06:34.000000000 -0400
44495 +++ linux-2.6.39/fs/cachefiles/namei.c 2011-05-22 19:36:32.000000000 -0400
44496 @@ -318,7 +318,7 @@ try_again:
44497 /* first step is to make up a grave dentry in the graveyard */
44498 sprintf(nbuffer, "%08x%08x",
44499 (uint32_t) get_seconds(),
44500 - (uint32_t) atomic_inc_return(&cache->gravecounter));
44501 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
44502
44503 /* do the multiway lock magic */
44504 trap = lock_rename(cache->graveyard, dir);
44505 diff -urNp linux-2.6.39/fs/cachefiles/proc.c linux-2.6.39/fs/cachefiles/proc.c
44506 --- linux-2.6.39/fs/cachefiles/proc.c 2011-05-19 00:06:34.000000000 -0400
44507 +++ linux-2.6.39/fs/cachefiles/proc.c 2011-05-22 19:36:32.000000000 -0400
44508 @@ -14,9 +14,9 @@
44509 #include <linux/seq_file.h>
44510 #include "internal.h"
44511
44512 -atomic_t cachefiles_lookup_histogram[HZ];
44513 -atomic_t cachefiles_mkdir_histogram[HZ];
44514 -atomic_t cachefiles_create_histogram[HZ];
44515 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
44516 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
44517 +atomic_unchecked_t cachefiles_create_histogram[HZ];
44518
44519 /*
44520 * display the latency histogram
44521 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(str
44522 return 0;
44523 default:
44524 index = (unsigned long) v - 3;
44525 - x = atomic_read(&cachefiles_lookup_histogram[index]);
44526 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
44527 - z = atomic_read(&cachefiles_create_histogram[index]);
44528 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
44529 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
44530 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
44531 if (x == 0 && y == 0 && z == 0)
44532 return 0;
44533
44534 diff -urNp linux-2.6.39/fs/cachefiles/rdwr.c linux-2.6.39/fs/cachefiles/rdwr.c
44535 --- linux-2.6.39/fs/cachefiles/rdwr.c 2011-05-19 00:06:34.000000000 -0400
44536 +++ linux-2.6.39/fs/cachefiles/rdwr.c 2011-05-22 19:36:32.000000000 -0400
44537 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache
44538 old_fs = get_fs();
44539 set_fs(KERNEL_DS);
44540 ret = file->f_op->write(
44541 - file, (const void __user *) data, len, &pos);
44542 + file, (__force const void __user *) data, len, &pos);
44543 set_fs(old_fs);
44544 kunmap(page);
44545 if (ret != len)
44546 diff -urNp linux-2.6.39/fs/ceph/addr.c linux-2.6.39/fs/ceph/addr.c
44547 --- linux-2.6.39/fs/ceph/addr.c 2011-05-19 00:06:34.000000000 -0400
44548 +++ linux-2.6.39/fs/ceph/addr.c 2011-05-22 19:36:32.000000000 -0400
44549 @@ -1164,7 +1164,7 @@ out:
44550 return ret;
44551 }
44552
44553 -static struct vm_operations_struct ceph_vmops = {
44554 +static const struct vm_operations_struct ceph_vmops = {
44555 .fault = filemap_fault,
44556 .page_mkwrite = ceph_page_mkwrite,
44557 };
44558 diff -urNp linux-2.6.39/fs/ceph/dir.c linux-2.6.39/fs/ceph/dir.c
44559 --- linux-2.6.39/fs/ceph/dir.c 2011-05-19 00:06:34.000000000 -0400
44560 +++ linux-2.6.39/fs/ceph/dir.c 2011-05-22 19:36:32.000000000 -0400
44561 @@ -226,7 +226,7 @@ static int ceph_readdir(struct file *fil
44562 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
44563 struct ceph_mds_client *mdsc = fsc->mdsc;
44564 unsigned frag = fpos_frag(filp->f_pos);
44565 - int off = fpos_off(filp->f_pos);
44566 + unsigned int off = fpos_off(filp->f_pos);
44567 int err;
44568 u32 ftype;
44569 struct ceph_mds_reply_info_parsed *rinfo;
44570 @@ -360,7 +360,7 @@ more:
44571 rinfo = &fi->last_readdir->r_reply_info;
44572 dout("readdir frag %x num %d off %d chunkoff %d\n", frag,
44573 rinfo->dir_nr, off, fi->offset);
44574 - while (off - fi->offset >= 0 && off - fi->offset < rinfo->dir_nr) {
44575 + while (off >= fi->offset && off - fi->offset < rinfo->dir_nr) {
44576 u64 pos = ceph_make_fpos(frag, off);
44577 struct ceph_mds_reply_inode *in =
44578 rinfo->dir_in[off - fi->offset].in;
44579 diff -urNp linux-2.6.39/fs/cifs/cifs_debug.c linux-2.6.39/fs/cifs/cifs_debug.c
44580 --- linux-2.6.39/fs/cifs/cifs_debug.c 2011-05-19 00:06:34.000000000 -0400
44581 +++ linux-2.6.39/fs/cifs/cifs_debug.c 2011-05-22 19:36:32.000000000 -0400
44582 @@ -279,25 +279,25 @@ static ssize_t cifs_stats_proc_write(str
44583 tcon = list_entry(tmp3,
44584 struct cifsTconInfo,
44585 tcon_list);
44586 - atomic_set(&tcon->num_smbs_sent, 0);
44587 - atomic_set(&tcon->num_writes, 0);
44588 - atomic_set(&tcon->num_reads, 0);
44589 - atomic_set(&tcon->num_oplock_brks, 0);
44590 - atomic_set(&tcon->num_opens, 0);
44591 - atomic_set(&tcon->num_posixopens, 0);
44592 - atomic_set(&tcon->num_posixmkdirs, 0);
44593 - atomic_set(&tcon->num_closes, 0);
44594 - atomic_set(&tcon->num_deletes, 0);
44595 - atomic_set(&tcon->num_mkdirs, 0);
44596 - atomic_set(&tcon->num_rmdirs, 0);
44597 - atomic_set(&tcon->num_renames, 0);
44598 - atomic_set(&tcon->num_t2renames, 0);
44599 - atomic_set(&tcon->num_ffirst, 0);
44600 - atomic_set(&tcon->num_fnext, 0);
44601 - atomic_set(&tcon->num_fclose, 0);
44602 - atomic_set(&tcon->num_hardlinks, 0);
44603 - atomic_set(&tcon->num_symlinks, 0);
44604 - atomic_set(&tcon->num_locks, 0);
44605 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
44606 + atomic_set_unchecked(&tcon->num_writes, 0);
44607 + atomic_set_unchecked(&tcon->num_reads, 0);
44608 + atomic_set_unchecked(&tcon->num_oplock_brks, 0);
44609 + atomic_set_unchecked(&tcon->num_opens, 0);
44610 + atomic_set_unchecked(&tcon->num_posixopens, 0);
44611 + atomic_set_unchecked(&tcon->num_posixmkdirs, 0);
44612 + atomic_set_unchecked(&tcon->num_closes, 0);
44613 + atomic_set_unchecked(&tcon->num_deletes, 0);
44614 + atomic_set_unchecked(&tcon->num_mkdirs, 0);
44615 + atomic_set_unchecked(&tcon->num_rmdirs, 0);
44616 + atomic_set_unchecked(&tcon->num_renames, 0);
44617 + atomic_set_unchecked(&tcon->num_t2renames, 0);
44618 + atomic_set_unchecked(&tcon->num_ffirst, 0);
44619 + atomic_set_unchecked(&tcon->num_fnext, 0);
44620 + atomic_set_unchecked(&tcon->num_fclose, 0);
44621 + atomic_set_unchecked(&tcon->num_hardlinks, 0);
44622 + atomic_set_unchecked(&tcon->num_symlinks, 0);
44623 + atomic_set_unchecked(&tcon->num_locks, 0);
44624 }
44625 }
44626 }
44627 @@ -357,41 +357,41 @@ static int cifs_stats_proc_show(struct s
44628 if (tcon->need_reconnect)
44629 seq_puts(m, "\tDISCONNECTED ");
44630 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
44631 - atomic_read(&tcon->num_smbs_sent),
44632 - atomic_read(&tcon->num_oplock_brks));
44633 + atomic_read_unchecked(&tcon->num_smbs_sent),
44634 + atomic_read_unchecked(&tcon->num_oplock_brks));
44635 seq_printf(m, "\nReads: %d Bytes: %lld",
44636 - atomic_read(&tcon->num_reads),
44637 + atomic_read_unchecked(&tcon->num_reads),
44638 (long long)(tcon->bytes_read));
44639 seq_printf(m, "\nWrites: %d Bytes: %lld",
44640 - atomic_read(&tcon->num_writes),
44641 + atomic_read_unchecked(&tcon->num_writes),
44642 (long long)(tcon->bytes_written));
44643 seq_printf(m, "\nFlushes: %d",
44644 - atomic_read(&tcon->num_flushes));
44645 + atomic_read_unchecked(&tcon->num_flushes));
44646 seq_printf(m, "\nLocks: %d HardLinks: %d "
44647 "Symlinks: %d",
44648 - atomic_read(&tcon->num_locks),
44649 - atomic_read(&tcon->num_hardlinks),
44650 - atomic_read(&tcon->num_symlinks));
44651 + atomic_read_unchecked(&tcon->num_locks),
44652 + atomic_read_unchecked(&tcon->num_hardlinks),
44653 + atomic_read_unchecked(&tcon->num_symlinks));
44654 seq_printf(m, "\nOpens: %d Closes: %d "
44655 "Deletes: %d",
44656 - atomic_read(&tcon->num_opens),
44657 - atomic_read(&tcon->num_closes),
44658 - atomic_read(&tcon->num_deletes));
44659 + atomic_read_unchecked(&tcon->num_opens),
44660 + atomic_read_unchecked(&tcon->num_closes),
44661 + atomic_read_unchecked(&tcon->num_deletes));
44662 seq_printf(m, "\nPosix Opens: %d "
44663 "Posix Mkdirs: %d",
44664 - atomic_read(&tcon->num_posixopens),
44665 - atomic_read(&tcon->num_posixmkdirs));
44666 + atomic_read_unchecked(&tcon->num_posixopens),
44667 + atomic_read_unchecked(&tcon->num_posixmkdirs));
44668 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
44669 - atomic_read(&tcon->num_mkdirs),
44670 - atomic_read(&tcon->num_rmdirs));
44671 + atomic_read_unchecked(&tcon->num_mkdirs),
44672 + atomic_read_unchecked(&tcon->num_rmdirs));
44673 seq_printf(m, "\nRenames: %d T2 Renames %d",
44674 - atomic_read(&tcon->num_renames),
44675 - atomic_read(&tcon->num_t2renames));
44676 + atomic_read_unchecked(&tcon->num_renames),
44677 + atomic_read_unchecked(&tcon->num_t2renames));
44678 seq_printf(m, "\nFindFirst: %d FNext %d "
44679 "FClose %d",
44680 - atomic_read(&tcon->num_ffirst),
44681 - atomic_read(&tcon->num_fnext),
44682 - atomic_read(&tcon->num_fclose));
44683 + atomic_read_unchecked(&tcon->num_ffirst),
44684 + atomic_read_unchecked(&tcon->num_fnext),
44685 + atomic_read_unchecked(&tcon->num_fclose));
44686 }
44687 }
44688 }
44689 diff -urNp linux-2.6.39/fs/cifs/cifsglob.h linux-2.6.39/fs/cifs/cifsglob.h
44690 --- linux-2.6.39/fs/cifs/cifsglob.h 2011-05-19 00:06:34.000000000 -0400
44691 +++ linux-2.6.39/fs/cifs/cifsglob.h 2011-05-22 19:36:32.000000000 -0400
44692 @@ -305,28 +305,28 @@ struct cifsTconInfo {
44693 __u16 Flags; /* optional support bits */
44694 enum statusEnum tidStatus;
44695 #ifdef CONFIG_CIFS_STATS
44696 - atomic_t num_smbs_sent;
44697 - atomic_t num_writes;
44698 - atomic_t num_reads;
44699 - atomic_t num_flushes;
44700 - atomic_t num_oplock_brks;
44701 - atomic_t num_opens;
44702 - atomic_t num_closes;
44703 - atomic_t num_deletes;
44704 - atomic_t num_mkdirs;
44705 - atomic_t num_posixopens;
44706 - atomic_t num_posixmkdirs;
44707 - atomic_t num_rmdirs;
44708 - atomic_t num_renames;
44709 - atomic_t num_t2renames;
44710 - atomic_t num_ffirst;
44711 - atomic_t num_fnext;
44712 - atomic_t num_fclose;
44713 - atomic_t num_hardlinks;
44714 - atomic_t num_symlinks;
44715 - atomic_t num_locks;
44716 - atomic_t num_acl_get;
44717 - atomic_t num_acl_set;
44718 + atomic_unchecked_t num_smbs_sent;
44719 + atomic_unchecked_t num_writes;
44720 + atomic_unchecked_t num_reads;
44721 + atomic_unchecked_t num_flushes;
44722 + atomic_unchecked_t num_oplock_brks;
44723 + atomic_unchecked_t num_opens;
44724 + atomic_unchecked_t num_closes;
44725 + atomic_unchecked_t num_deletes;
44726 + atomic_unchecked_t num_mkdirs;
44727 + atomic_unchecked_t num_posixopens;
44728 + atomic_unchecked_t num_posixmkdirs;
44729 + atomic_unchecked_t num_rmdirs;
44730 + atomic_unchecked_t num_renames;
44731 + atomic_unchecked_t num_t2renames;
44732 + atomic_unchecked_t num_ffirst;
44733 + atomic_unchecked_t num_fnext;
44734 + atomic_unchecked_t num_fclose;
44735 + atomic_unchecked_t num_hardlinks;
44736 + atomic_unchecked_t num_symlinks;
44737 + atomic_unchecked_t num_locks;
44738 + atomic_unchecked_t num_acl_get;
44739 + atomic_unchecked_t num_acl_set;
44740 #ifdef CONFIG_CIFS_STATS2
44741 unsigned long long time_writes;
44742 unsigned long long time_reads;
44743 @@ -509,7 +509,7 @@ static inline char CIFS_DIR_SEP(const st
44744 }
44745
44746 #ifdef CONFIG_CIFS_STATS
44747 -#define cifs_stats_inc atomic_inc
44748 +#define cifs_stats_inc atomic_inc_unchecked
44749
44750 static inline void cifs_stats_bytes_written(struct cifsTconInfo *tcon,
44751 unsigned int bytes)
44752 diff -urNp linux-2.6.39/fs/cifs/link.c linux-2.6.39/fs/cifs/link.c
44753 --- linux-2.6.39/fs/cifs/link.c 2011-05-19 00:06:34.000000000 -0400
44754 +++ linux-2.6.39/fs/cifs/link.c 2011-05-22 19:36:32.000000000 -0400
44755 @@ -577,7 +577,7 @@ symlink_exit:
44756
44757 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
44758 {
44759 - char *p = nd_get_link(nd);
44760 + const char *p = nd_get_link(nd);
44761 if (!IS_ERR(p))
44762 kfree(p);
44763 }
44764 diff -urNp linux-2.6.39/fs/coda/cache.c linux-2.6.39/fs/coda/cache.c
44765 --- linux-2.6.39/fs/coda/cache.c 2011-05-19 00:06:34.000000000 -0400
44766 +++ linux-2.6.39/fs/coda/cache.c 2011-05-22 19:36:32.000000000 -0400
44767 @@ -24,7 +24,7 @@
44768 #include "coda_linux.h"
44769 #include "coda_cache.h"
44770
44771 -static atomic_t permission_epoch = ATOMIC_INIT(0);
44772 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
44773
44774 /* replace or extend an acl cache hit */
44775 void coda_cache_enter(struct inode *inode, int mask)
44776 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inod
44777 struct coda_inode_info *cii = ITOC(inode);
44778
44779 spin_lock(&cii->c_lock);
44780 - cii->c_cached_epoch = atomic_read(&permission_epoch);
44781 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
44782 if (cii->c_uid != current_fsuid()) {
44783 cii->c_uid = current_fsuid();
44784 cii->c_cached_perm = mask;
44785 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode
44786 {
44787 struct coda_inode_info *cii = ITOC(inode);
44788 spin_lock(&cii->c_lock);
44789 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
44790 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
44791 spin_unlock(&cii->c_lock);
44792 }
44793
44794 /* remove all acl caches */
44795 void coda_cache_clear_all(struct super_block *sb)
44796 {
44797 - atomic_inc(&permission_epoch);
44798 + atomic_inc_unchecked(&permission_epoch);
44799 }
44800
44801
44802 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode
44803 spin_lock(&cii->c_lock);
44804 hit = (mask & cii->c_cached_perm) == mask &&
44805 cii->c_uid == current_fsuid() &&
44806 - cii->c_cached_epoch == atomic_read(&permission_epoch);
44807 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
44808 spin_unlock(&cii->c_lock);
44809
44810 return hit;
44811 diff -urNp linux-2.6.39/fs/compat_binfmt_elf.c linux-2.6.39/fs/compat_binfmt_elf.c
44812 --- linux-2.6.39/fs/compat_binfmt_elf.c 2011-05-19 00:06:34.000000000 -0400
44813 +++ linux-2.6.39/fs/compat_binfmt_elf.c 2011-05-22 19:36:32.000000000 -0400
44814 @@ -30,11 +30,13 @@
44815 #undef elf_phdr
44816 #undef elf_shdr
44817 #undef elf_note
44818 +#undef elf_dyn
44819 #undef elf_addr_t
44820 #define elfhdr elf32_hdr
44821 #define elf_phdr elf32_phdr
44822 #define elf_shdr elf32_shdr
44823 #define elf_note elf32_note
44824 +#define elf_dyn Elf32_Dyn
44825 #define elf_addr_t Elf32_Addr
44826
44827 /*
44828 diff -urNp linux-2.6.39/fs/compat.c linux-2.6.39/fs/compat.c
44829 --- linux-2.6.39/fs/compat.c 2011-05-19 00:06:34.000000000 -0400
44830 +++ linux-2.6.39/fs/compat.c 2011-05-22 19:41:37.000000000 -0400
44831 @@ -566,7 +566,7 @@ ssize_t compat_rw_copy_check_uvector(int
44832 goto out;
44833
44834 ret = -EINVAL;
44835 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
44836 + if (nr_segs > UIO_MAXIOV)
44837 goto out;
44838 if (nr_segs > fast_segs) {
44839 ret = -ENOMEM;
44840 @@ -848,6 +848,7 @@ struct compat_old_linux_dirent {
44841
44842 struct compat_readdir_callback {
44843 struct compat_old_linux_dirent __user *dirent;
44844 + struct file * file;
44845 int result;
44846 };
44847
44848 @@ -865,6 +866,10 @@ static int compat_fillonedir(void *__buf
44849 buf->result = -EOVERFLOW;
44850 return -EOVERFLOW;
44851 }
44852 +
44853 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44854 + return 0;
44855 +
44856 buf->result++;
44857 dirent = buf->dirent;
44858 if (!access_ok(VERIFY_WRITE, dirent,
44859 @@ -897,6 +902,7 @@ asmlinkage long compat_sys_old_readdir(u
44860
44861 buf.result = 0;
44862 buf.dirent = dirent;
44863 + buf.file = file;
44864
44865 error = vfs_readdir(file, compat_fillonedir, &buf);
44866 if (buf.result)
44867 @@ -917,6 +923,7 @@ struct compat_linux_dirent {
44868 struct compat_getdents_callback {
44869 struct compat_linux_dirent __user *current_dir;
44870 struct compat_linux_dirent __user *previous;
44871 + struct file * file;
44872 int count;
44873 int error;
44874 };
44875 @@ -938,6 +945,10 @@ static int compat_filldir(void *__buf, c
44876 buf->error = -EOVERFLOW;
44877 return -EOVERFLOW;
44878 }
44879 +
44880 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44881 + return 0;
44882 +
44883 dirent = buf->previous;
44884 if (dirent) {
44885 if (__put_user(offset, &dirent->d_off))
44886 @@ -985,6 +996,7 @@ asmlinkage long compat_sys_getdents(unsi
44887 buf.previous = NULL;
44888 buf.count = count;
44889 buf.error = 0;
44890 + buf.file = file;
44891
44892 error = vfs_readdir(file, compat_filldir, &buf);
44893 if (error >= 0)
44894 @@ -1006,6 +1018,7 @@ out:
44895 struct compat_getdents_callback64 {
44896 struct linux_dirent64 __user *current_dir;
44897 struct linux_dirent64 __user *previous;
44898 + struct file * file;
44899 int count;
44900 int error;
44901 };
44902 @@ -1022,6 +1035,10 @@ static int compat_filldir64(void * __buf
44903 buf->error = -EINVAL; /* only used if we fail.. */
44904 if (reclen > buf->count)
44905 return -EINVAL;
44906 +
44907 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44908 + return 0;
44909 +
44910 dirent = buf->previous;
44911
44912 if (dirent) {
44913 @@ -1073,6 +1090,7 @@ asmlinkage long compat_sys_getdents64(un
44914 buf.previous = NULL;
44915 buf.count = count;
44916 buf.error = 0;
44917 + buf.file = file;
44918
44919 error = vfs_readdir(file, compat_filldir64, &buf);
44920 if (error >= 0)
44921 @@ -1436,6 +1454,11 @@ int compat_do_execve(char * filename,
44922 compat_uptr_t __user *envp,
44923 struct pt_regs * regs)
44924 {
44925 +#ifdef CONFIG_GRKERNSEC
44926 + struct file *old_exec_file;
44927 + struct acl_subject_label *old_acl;
44928 + struct rlimit old_rlim[RLIM_NLIMITS];
44929 +#endif
44930 struct linux_binprm *bprm;
44931 struct file *file;
44932 struct files_struct *displaced;
44933 @@ -1472,6 +1495,19 @@ int compat_do_execve(char * filename,
44934 bprm->filename = filename;
44935 bprm->interp = filename;
44936
44937 + if (gr_process_user_ban()) {
44938 + retval = -EPERM;
44939 + goto out_file;
44940 + }
44941 +
44942 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
44943 + retval = -EAGAIN;
44944 + if (gr_handle_nproc())
44945 + goto out_file;
44946 + retval = -EACCES;
44947 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt))
44948 + goto out_file;
44949 +
44950 retval = bprm_mm_init(bprm);
44951 if (retval)
44952 goto out_file;
44953 @@ -1501,9 +1537,40 @@ int compat_do_execve(char * filename,
44954 if (retval < 0)
44955 goto out;
44956
44957 + if (!gr_tpe_allow(file)) {
44958 + retval = -EACCES;
44959 + goto out;
44960 + }
44961 +
44962 + if (gr_check_crash_exec(file)) {
44963 + retval = -EACCES;
44964 + goto out;
44965 + }
44966 +
44967 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
44968 +
44969 + gr_handle_exec_args_compat(bprm, argv);
44970 +
44971 +#ifdef CONFIG_GRKERNSEC
44972 + old_acl = current->acl;
44973 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
44974 + old_exec_file = current->exec_file;
44975 + get_file(file);
44976 + current->exec_file = file;
44977 +#endif
44978 +
44979 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
44980 + bprm->unsafe & LSM_UNSAFE_SHARE);
44981 + if (retval < 0)
44982 + goto out_fail;
44983 +
44984 retval = search_binary_handler(bprm, regs);
44985 if (retval < 0)
44986 - goto out;
44987 + goto out_fail;
44988 +#ifdef CONFIG_GRKERNSEC
44989 + if (old_exec_file)
44990 + fput(old_exec_file);
44991 +#endif
44992
44993 /* execve succeeded */
44994 current->fs->in_exec = 0;
44995 @@ -1514,6 +1581,14 @@ int compat_do_execve(char * filename,
44996 put_files_struct(displaced);
44997 return retval;
44998
44999 +out_fail:
45000 +#ifdef CONFIG_GRKERNSEC
45001 + current->acl = old_acl;
45002 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
45003 + fput(current->exec_file);
45004 + current->exec_file = old_exec_file;
45005 +#endif
45006 +
45007 out:
45008 if (bprm->mm) {
45009 acct_arg_size(bprm, 0);
45010 @@ -1681,6 +1756,8 @@ int compat_core_sys_select(int n, compat
45011 struct fdtable *fdt;
45012 long stack_fds[SELECT_STACK_ALLOC/sizeof(long)];
45013
45014 + pax_track_stack();
45015 +
45016 if (n < 0)
45017 goto out_nofds;
45018
45019 diff -urNp linux-2.6.39/fs/compat_ioctl.c linux-2.6.39/fs/compat_ioctl.c
45020 --- linux-2.6.39/fs/compat_ioctl.c 2011-05-19 00:06:34.000000000 -0400
45021 +++ linux-2.6.39/fs/compat_ioctl.c 2011-05-22 19:36:32.000000000 -0400
45022 @@ -208,6 +208,8 @@ static int do_video_set_spu_palette(unsi
45023
45024 err = get_user(palp, &up->palette);
45025 err |= get_user(length, &up->length);
45026 + if (err)
45027 + return -EFAULT;
45028
45029 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
45030 err = put_user(compat_ptr(palp), &up_native->palette);
45031 @@ -1638,8 +1640,8 @@ asmlinkage long compat_sys_ioctl(unsigne
45032 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
45033 {
45034 unsigned int a, b;
45035 - a = *(unsigned int *)p;
45036 - b = *(unsigned int *)q;
45037 + a = *(const unsigned int *)p;
45038 + b = *(const unsigned int *)q;
45039 if (a > b)
45040 return 1;
45041 if (a < b)
45042 diff -urNp linux-2.6.39/fs/configfs/dir.c linux-2.6.39/fs/configfs/dir.c
45043 --- linux-2.6.39/fs/configfs/dir.c 2011-05-19 00:06:34.000000000 -0400
45044 +++ linux-2.6.39/fs/configfs/dir.c 2011-05-22 19:36:32.000000000 -0400
45045 @@ -1575,7 +1575,8 @@ static int configfs_readdir(struct file
45046 }
45047 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
45048 struct configfs_dirent *next;
45049 - const char * name;
45050 + const unsigned char * name;
45051 + char d_name[sizeof(next->s_dentry->d_iname)];
45052 int len;
45053 struct inode *inode = NULL;
45054
45055 @@ -1585,7 +1586,12 @@ static int configfs_readdir(struct file
45056 continue;
45057
45058 name = configfs_get_name(next);
45059 - len = strlen(name);
45060 + if (next->s_dentry && name == next->s_dentry->d_iname) {
45061 + len = next->s_dentry->d_name.len;
45062 + memcpy(d_name, name, len);
45063 + name = d_name;
45064 + } else
45065 + len = strlen(name);
45066
45067 /*
45068 * We'll have a dentry and an inode for
45069 diff -urNp linux-2.6.39/fs/configfs/file.c linux-2.6.39/fs/configfs/file.c
45070 --- linux-2.6.39/fs/configfs/file.c 2011-05-19 00:06:34.000000000 -0400
45071 +++ linux-2.6.39/fs/configfs/file.c 2011-05-22 19:36:32.000000000 -0400
45072 @@ -215,7 +215,7 @@ static int check_perm(struct inode * ino
45073 struct config_item *item = configfs_get_config_item(file->f_path.dentry->d_parent);
45074 struct configfs_attribute * attr = to_attr(file->f_path.dentry);
45075 struct configfs_buffer * buffer;
45076 - struct configfs_item_operations * ops = NULL;
45077 + struct configfs_item_operations *ops = NULL;
45078 int error = 0;
45079
45080 if (!item || !attr)
45081 diff -urNp linux-2.6.39/fs/configfs/item.c linux-2.6.39/fs/configfs/item.c
45082 --- linux-2.6.39/fs/configfs/item.c 2011-05-19 00:06:34.000000000 -0400
45083 +++ linux-2.6.39/fs/configfs/item.c 2011-05-22 19:36:32.000000000 -0400
45084 @@ -123,7 +123,7 @@ void config_item_init_type_name(struct c
45085 EXPORT_SYMBOL(config_item_init_type_name);
45086
45087 void config_group_init_type_name(struct config_group *group, const char *name,
45088 - struct config_item_type *type)
45089 + struct config_item_type *type)
45090 {
45091 config_item_set_name(&group->cg_item, name);
45092 group->cg_item.ci_type = type;
45093 diff -urNp linux-2.6.39/fs/dcache.c linux-2.6.39/fs/dcache.c
45094 --- linux-2.6.39/fs/dcache.c 2011-05-19 00:06:34.000000000 -0400
45095 +++ linux-2.6.39/fs/dcache.c 2011-05-22 19:36:32.000000000 -0400
45096 @@ -3069,7 +3069,7 @@ void __init vfs_caches_init(unsigned lon
45097 mempages -= reserve;
45098
45099 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
45100 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
45101 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
45102
45103 dcache_init();
45104 inode_init();
45105 diff -urNp linux-2.6.39/fs/dlm/lockspace.c linux-2.6.39/fs/dlm/lockspace.c
45106 --- linux-2.6.39/fs/dlm/lockspace.c 2011-05-19 00:06:34.000000000 -0400
45107 +++ linux-2.6.39/fs/dlm/lockspace.c 2011-05-22 19:36:32.000000000 -0400
45108 @@ -200,7 +200,7 @@ static int dlm_uevent(struct kset *kset,
45109 return 0;
45110 }
45111
45112 -static struct kset_uevent_ops dlm_uevent_ops = {
45113 +static const struct kset_uevent_ops dlm_uevent_ops = {
45114 .uevent = dlm_uevent,
45115 };
45116
45117 diff -urNp linux-2.6.39/fs/ecryptfs/inode.c linux-2.6.39/fs/ecryptfs/inode.c
45118 --- linux-2.6.39/fs/ecryptfs/inode.c 2011-05-19 00:06:34.000000000 -0400
45119 +++ linux-2.6.39/fs/ecryptfs/inode.c 2011-05-22 19:36:32.000000000 -0400
45120 @@ -621,7 +621,7 @@ static int ecryptfs_readlink_lower(struc
45121 old_fs = get_fs();
45122 set_fs(get_ds());
45123 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
45124 - (char __user *)lower_buf,
45125 + (__force char __user *)lower_buf,
45126 lower_bufsiz);
45127 set_fs(old_fs);
45128 if (rc < 0)
45129 @@ -667,7 +667,7 @@ static void *ecryptfs_follow_link(struct
45130 }
45131 old_fs = get_fs();
45132 set_fs(get_ds());
45133 - rc = dentry->d_inode->i_op->readlink(dentry, (char __user *)buf, len);
45134 + rc = dentry->d_inode->i_op->readlink(dentry, (__force char __user *)buf, len);
45135 set_fs(old_fs);
45136 if (rc < 0) {
45137 kfree(buf);
45138 @@ -682,7 +682,7 @@ out:
45139 static void
45140 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
45141 {
45142 - char *buf = nd_get_link(nd);
45143 + const char *buf = nd_get_link(nd);
45144 if (!IS_ERR(buf)) {
45145 /* Free the char* */
45146 kfree(buf);
45147 diff -urNp linux-2.6.39/fs/ecryptfs/miscdev.c linux-2.6.39/fs/ecryptfs/miscdev.c
45148 --- linux-2.6.39/fs/ecryptfs/miscdev.c 2011-05-19 00:06:34.000000000 -0400
45149 +++ linux-2.6.39/fs/ecryptfs/miscdev.c 2011-05-22 19:36:32.000000000 -0400
45150 @@ -328,7 +328,7 @@ check_list:
45151 goto out_unlock_msg_ctx;
45152 i = 5;
45153 if (msg_ctx->msg) {
45154 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
45155 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
45156 goto out_unlock_msg_ctx;
45157 i += packet_length_size;
45158 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
45159 diff -urNp linux-2.6.39/fs/exec.c linux-2.6.39/fs/exec.c
45160 --- linux-2.6.39/fs/exec.c 2011-05-19 00:06:34.000000000 -0400
45161 +++ linux-2.6.39/fs/exec.c 2011-05-22 20:44:52.000000000 -0400
45162 @@ -55,12 +55,24 @@
45163 #include <linux/fs_struct.h>
45164 #include <linux/pipe_fs_i.h>
45165 #include <linux/oom.h>
45166 +#include <linux/random.h>
45167 +#include <linux/seq_file.h>
45168 +
45169 +#ifdef CONFIG_PAX_REFCOUNT
45170 +#include <linux/kallsyms.h>
45171 +#include <linux/kdebug.h>
45172 +#endif
45173
45174 #include <asm/uaccess.h>
45175 #include <asm/mmu_context.h>
45176 #include <asm/tlb.h>
45177 #include "internal.h"
45178
45179 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
45180 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
45181 +EXPORT_SYMBOL(pax_set_initial_flags_func);
45182 +#endif
45183 +
45184 int core_uses_pid;
45185 char core_pattern[CORENAME_MAX_SIZE] = "core";
45186 unsigned int core_pipe_limit;
45187 @@ -70,7 +82,7 @@ struct core_name {
45188 char *corename;
45189 int used, size;
45190 };
45191 -static atomic_t call_count = ATOMIC_INIT(1);
45192 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
45193
45194 /* The maximal length of core_pattern is also specified in sysctl.c */
45195
45196 @@ -116,7 +128,7 @@ SYSCALL_DEFINE1(uselib, const char __use
45197 char *tmp = getname(library);
45198 int error = PTR_ERR(tmp);
45199 static const struct open_flags uselib_flags = {
45200 - .open_flag = O_LARGEFILE | O_RDONLY | __FMODE_EXEC,
45201 + .open_flag = O_LARGEFILE | O_RDONLY | __FMODE_EXEC | FMODE_GREXEC,
45202 .acc_mode = MAY_READ | MAY_EXEC | MAY_OPEN,
45203 .intent = LOOKUP_OPEN
45204 };
45205 @@ -190,18 +202,10 @@ struct page *get_arg_page(struct linux_b
45206 int write)
45207 {
45208 struct page *page;
45209 - int ret;
45210
45211 -#ifdef CONFIG_STACK_GROWSUP
45212 - if (write) {
45213 - ret = expand_stack_downwards(bprm->vma, pos);
45214 - if (ret < 0)
45215 - return NULL;
45216 - }
45217 -#endif
45218 - ret = get_user_pages(current, bprm->mm, pos,
45219 - 1, write, 1, &page, NULL);
45220 - if (ret <= 0)
45221 + if (0 > expand_stack_downwards(bprm->vma, pos))
45222 + return NULL;
45223 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
45224 return NULL;
45225
45226 if (write) {
45227 @@ -276,6 +280,11 @@ static int __bprm_mm_init(struct linux_b
45228 vma->vm_end = STACK_TOP_MAX;
45229 vma->vm_start = vma->vm_end - PAGE_SIZE;
45230 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
45231 +
45232 +#ifdef CONFIG_PAX_SEGMEXEC
45233 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
45234 +#endif
45235 +
45236 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
45237 INIT_LIST_HEAD(&vma->anon_vma_chain);
45238
45239 @@ -290,6 +299,12 @@ static int __bprm_mm_init(struct linux_b
45240 mm->stack_vm = mm->total_vm = 1;
45241 up_write(&mm->mmap_sem);
45242 bprm->p = vma->vm_end - sizeof(void *);
45243 +
45244 +#ifdef CONFIG_PAX_RANDUSTACK
45245 + if (randomize_va_space)
45246 + bprm->p ^= (pax_get_random_long() & ~15) & ~PAGE_MASK;
45247 +#endif
45248 +
45249 return 0;
45250 err:
45251 up_write(&mm->mmap_sem);
45252 @@ -525,7 +540,7 @@ int copy_strings_kernel(int argc, const
45253 int r;
45254 mm_segment_t oldfs = get_fs();
45255 set_fs(KERNEL_DS);
45256 - r = copy_strings(argc, (const char __user *const __user *)argv, bprm);
45257 + r = copy_strings(argc, (__force const char __user *const __user *)argv, bprm);
45258 set_fs(oldfs);
45259 return r;
45260 }
45261 @@ -555,7 +570,8 @@ static int shift_arg_pages(struct vm_are
45262 unsigned long new_end = old_end - shift;
45263 struct mmu_gather *tlb;
45264
45265 - BUG_ON(new_start > new_end);
45266 + if (new_start >= new_end || new_start < mmap_min_addr)
45267 + return -ENOMEM;
45268
45269 /*
45270 * ensure there are no vmas between where we want to go
45271 @@ -564,6 +580,10 @@ static int shift_arg_pages(struct vm_are
45272 if (vma != find_vma(mm, new_start))
45273 return -EFAULT;
45274
45275 +#ifdef CONFIG_PAX_SEGMEXEC
45276 + BUG_ON(pax_find_mirror_vma(vma));
45277 +#endif
45278 +
45279 /*
45280 * cover the whole range: [new_start, old_end)
45281 */
45282 @@ -644,10 +664,6 @@ int setup_arg_pages(struct linux_binprm
45283 stack_top = arch_align_stack(stack_top);
45284 stack_top = PAGE_ALIGN(stack_top);
45285
45286 - if (unlikely(stack_top < mmap_min_addr) ||
45287 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
45288 - return -ENOMEM;
45289 -
45290 stack_shift = vma->vm_end - stack_top;
45291
45292 bprm->p -= stack_shift;
45293 @@ -659,8 +675,28 @@ int setup_arg_pages(struct linux_binprm
45294 bprm->exec -= stack_shift;
45295
45296 down_write(&mm->mmap_sem);
45297 +
45298 + /* Move stack pages down in memory. */
45299 + if (stack_shift) {
45300 + ret = shift_arg_pages(vma, stack_shift);
45301 + if (ret)
45302 + goto out_unlock;
45303 + }
45304 +
45305 vm_flags = VM_STACK_FLAGS;
45306
45307 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45308 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45309 + vm_flags &= ~VM_EXEC;
45310 +
45311 +#ifdef CONFIG_PAX_MPROTECT
45312 + if (mm->pax_flags & MF_PAX_MPROTECT)
45313 + vm_flags &= ~VM_MAYEXEC;
45314 +#endif
45315 +
45316 + }
45317 +#endif
45318 +
45319 /*
45320 * Adjust stack execute permissions; explicitly enable for
45321 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
45322 @@ -679,13 +715,6 @@ int setup_arg_pages(struct linux_binprm
45323 goto out_unlock;
45324 BUG_ON(prev != vma);
45325
45326 - /* Move stack pages down in memory. */
45327 - if (stack_shift) {
45328 - ret = shift_arg_pages(vma, stack_shift);
45329 - if (ret)
45330 - goto out_unlock;
45331 - }
45332 -
45333 /* mprotect_fixup is overkill to remove the temporary stack flags */
45334 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
45335
45336 @@ -725,7 +754,7 @@ struct file *open_exec(const char *name)
45337 struct file *file;
45338 int err;
45339 static const struct open_flags open_exec_flags = {
45340 - .open_flag = O_LARGEFILE | O_RDONLY | __FMODE_EXEC,
45341 + .open_flag = O_LARGEFILE | O_RDONLY | __FMODE_EXEC | FMODE_GREXEC,
45342 .acc_mode = MAY_EXEC | MAY_OPEN,
45343 .intent = LOOKUP_OPEN
45344 };
45345 @@ -766,7 +795,7 @@ int kernel_read(struct file *file, loff_
45346 old_fs = get_fs();
45347 set_fs(get_ds());
45348 /* The cast to a user pointer is valid due to the set_fs() */
45349 - result = vfs_read(file, (void __user *)addr, count, &pos);
45350 + result = vfs_read(file, (__force void __user *)addr, count, &pos);
45351 set_fs(old_fs);
45352 return result;
45353 }
45354 @@ -1188,7 +1217,7 @@ int check_unsafe_exec(struct linux_binpr
45355 }
45356 rcu_read_unlock();
45357
45358 - if (p->fs->users > n_fs) {
45359 + if (atomic_read(&p->fs->users) > n_fs) {
45360 bprm->unsafe |= LSM_UNSAFE_SHARE;
45361 } else {
45362 res = -EAGAIN;
45363 @@ -1384,6 +1413,11 @@ int do_execve(const char * filename,
45364 const char __user *const __user *envp,
45365 struct pt_regs * regs)
45366 {
45367 +#ifdef CONFIG_GRKERNSEC
45368 + struct file *old_exec_file;
45369 + struct acl_subject_label *old_acl;
45370 + struct rlimit old_rlim[RLIM_NLIMITS];
45371 +#endif
45372 struct linux_binprm *bprm;
45373 struct file *file;
45374 struct files_struct *displaced;
45375 @@ -1420,6 +1454,23 @@ int do_execve(const char * filename,
45376 bprm->filename = filename;
45377 bprm->interp = filename;
45378
45379 + if (gr_process_user_ban()) {
45380 + retval = -EPERM;
45381 + goto out_file;
45382 + }
45383 +
45384 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
45385 +
45386 + if (gr_handle_nproc()) {
45387 + retval = -EAGAIN;
45388 + goto out_file;
45389 + }
45390 +
45391 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
45392 + retval = -EACCES;
45393 + goto out_file;
45394 + }
45395 +
45396 retval = bprm_mm_init(bprm);
45397 if (retval)
45398 goto out_file;
45399 @@ -1449,9 +1500,40 @@ int do_execve(const char * filename,
45400 if (retval < 0)
45401 goto out;
45402
45403 + if (!gr_tpe_allow(file)) {
45404 + retval = -EACCES;
45405 + goto out;
45406 + }
45407 +
45408 + if (gr_check_crash_exec(file)) {
45409 + retval = -EACCES;
45410 + goto out;
45411 + }
45412 +
45413 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
45414 +
45415 + gr_handle_exec_args(bprm, argv);
45416 +
45417 +#ifdef CONFIG_GRKERNSEC
45418 + old_acl = current->acl;
45419 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
45420 + old_exec_file = current->exec_file;
45421 + get_file(file);
45422 + current->exec_file = file;
45423 +#endif
45424 +
45425 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
45426 + bprm->unsafe & LSM_UNSAFE_SHARE);
45427 + if (retval < 0)
45428 + goto out_fail;
45429 +
45430 retval = search_binary_handler(bprm,regs);
45431 if (retval < 0)
45432 - goto out;
45433 + goto out_fail;
45434 +#ifdef CONFIG_GRKERNSEC
45435 + if (old_exec_file)
45436 + fput(old_exec_file);
45437 +#endif
45438
45439 /* execve succeeded */
45440 current->fs->in_exec = 0;
45441 @@ -1462,6 +1544,14 @@ int do_execve(const char * filename,
45442 put_files_struct(displaced);
45443 return retval;
45444
45445 +out_fail:
45446 +#ifdef CONFIG_GRKERNSEC
45447 + current->acl = old_acl;
45448 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
45449 + fput(current->exec_file);
45450 + current->exec_file = old_exec_file;
45451 +#endif
45452 +
45453 out:
45454 if (bprm->mm) {
45455 acct_arg_size(bprm, 0);
45456 @@ -1507,7 +1597,7 @@ static int expand_corename(struct core_n
45457 {
45458 char *old_corename = cn->corename;
45459
45460 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
45461 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
45462 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
45463
45464 if (!cn->corename) {
45465 @@ -1560,7 +1650,7 @@ static int format_corename(struct core_n
45466 int pid_in_pattern = 0;
45467 int err = 0;
45468
45469 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
45470 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
45471 cn->corename = kmalloc(cn->size, GFP_KERNEL);
45472 cn->used = 0;
45473
45474 @@ -1648,6 +1738,208 @@ out:
45475 return ispipe;
45476 }
45477
45478 +int pax_check_flags(unsigned long *flags)
45479 +{
45480 + int retval = 0;
45481 +
45482 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
45483 + if (*flags & MF_PAX_SEGMEXEC)
45484 + {
45485 + *flags &= ~MF_PAX_SEGMEXEC;
45486 + retval = -EINVAL;
45487 + }
45488 +#endif
45489 +
45490 + if ((*flags & MF_PAX_PAGEEXEC)
45491 +
45492 +#ifdef CONFIG_PAX_PAGEEXEC
45493 + && (*flags & MF_PAX_SEGMEXEC)
45494 +#endif
45495 +
45496 + )
45497 + {
45498 + *flags &= ~MF_PAX_PAGEEXEC;
45499 + retval = -EINVAL;
45500 + }
45501 +
45502 + if ((*flags & MF_PAX_MPROTECT)
45503 +
45504 +#ifdef CONFIG_PAX_MPROTECT
45505 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45506 +#endif
45507 +
45508 + )
45509 + {
45510 + *flags &= ~MF_PAX_MPROTECT;
45511 + retval = -EINVAL;
45512 + }
45513 +
45514 + if ((*flags & MF_PAX_EMUTRAMP)
45515 +
45516 +#ifdef CONFIG_PAX_EMUTRAMP
45517 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45518 +#endif
45519 +
45520 + )
45521 + {
45522 + *flags &= ~MF_PAX_EMUTRAMP;
45523 + retval = -EINVAL;
45524 + }
45525 +
45526 + return retval;
45527 +}
45528 +
45529 +EXPORT_SYMBOL(pax_check_flags);
45530 +
45531 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45532 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
45533 +{
45534 + struct task_struct *tsk = current;
45535 + struct mm_struct *mm = current->mm;
45536 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
45537 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
45538 + char *path_exec = NULL;
45539 + char *path_fault = NULL;
45540 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
45541 +
45542 + if (buffer_exec && buffer_fault) {
45543 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
45544 +
45545 + down_read(&mm->mmap_sem);
45546 + vma = mm->mmap;
45547 + while (vma && (!vma_exec || !vma_fault)) {
45548 + if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
45549 + vma_exec = vma;
45550 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
45551 + vma_fault = vma;
45552 + vma = vma->vm_next;
45553 + }
45554 + if (vma_exec) {
45555 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
45556 + if (IS_ERR(path_exec))
45557 + path_exec = "<path too long>";
45558 + else {
45559 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
45560 + if (path_exec) {
45561 + *path_exec = 0;
45562 + path_exec = buffer_exec;
45563 + } else
45564 + path_exec = "<path too long>";
45565 + }
45566 + }
45567 + if (vma_fault) {
45568 + start = vma_fault->vm_start;
45569 + end = vma_fault->vm_end;
45570 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
45571 + if (vma_fault->vm_file) {
45572 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
45573 + if (IS_ERR(path_fault))
45574 + path_fault = "<path too long>";
45575 + else {
45576 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
45577 + if (path_fault) {
45578 + *path_fault = 0;
45579 + path_fault = buffer_fault;
45580 + } else
45581 + path_fault = "<path too long>";
45582 + }
45583 + } else
45584 + path_fault = "<anonymous mapping>";
45585 + }
45586 + up_read(&mm->mmap_sem);
45587 + }
45588 + if (tsk->signal->curr_ip)
45589 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
45590 + else
45591 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
45592 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
45593 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
45594 + task_uid(tsk), task_euid(tsk), pc, sp);
45595 + free_page((unsigned long)buffer_exec);
45596 + free_page((unsigned long)buffer_fault);
45597 + pax_report_insns(pc, sp);
45598 + do_coredump(SIGKILL, SIGKILL, regs);
45599 +}
45600 +#endif
45601 +
45602 +#ifdef CONFIG_PAX_REFCOUNT
45603 +void pax_report_refcount_overflow(struct pt_regs *regs)
45604 +{
45605 + if (current->signal->curr_ip)
45606 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45607 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
45608 + else
45609 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45610 + current->comm, task_pid_nr(current), current_uid(), current_euid());
45611 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
45612 + show_regs(regs);
45613 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
45614 +}
45615 +#endif
45616 +
45617 +#ifdef CONFIG_PAX_USERCOPY
45618 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
45619 +int object_is_on_stack(const void *obj, unsigned long len)
45620 +{
45621 + const void * const stack = task_stack_page(current);
45622 + const void * const stackend = stack + THREAD_SIZE;
45623 +
45624 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45625 + const void *frame = NULL;
45626 + const void *oldframe;
45627 +#endif
45628 +
45629 + if (obj + len < obj)
45630 + return -1;
45631 +
45632 + if (obj + len <= stack || stackend <= obj)
45633 + return 0;
45634 +
45635 + if (obj < stack || stackend < obj + len)
45636 + return -1;
45637 +
45638 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45639 + oldframe = __builtin_frame_address(1);
45640 + if (oldframe)
45641 + frame = __builtin_frame_address(2);
45642 + /*
45643 + low ----------------------------------------------> high
45644 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
45645 + ^----------------^
45646 + allow copies only within here
45647 + */
45648 + while (stack <= frame && frame < stackend) {
45649 + /* if obj + len extends past the last frame, this
45650 + check won't pass and the next frame will be 0,
45651 + causing us to bail out and correctly report
45652 + the copy as invalid
45653 + */
45654 + if (obj + len <= frame)
45655 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
45656 + oldframe = frame;
45657 + frame = *(const void * const *)frame;
45658 + }
45659 + return -1;
45660 +#else
45661 + return 1;
45662 +#endif
45663 +}
45664 +
45665 +
45666 +void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
45667 +{
45668 + if (current->signal->curr_ip)
45669 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45670 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45671 + else
45672 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45673 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45674 + dump_stack();
45675 + gr_handle_kernel_exploit();
45676 + do_group_exit(SIGKILL);
45677 +}
45678 +#endif
45679 +
45680 static int zap_process(struct task_struct *start, int exit_code)
45681 {
45682 struct task_struct *t;
45683 @@ -1858,17 +2150,17 @@ static void wait_for_dump_helpers(struct
45684 pipe = file->f_path.dentry->d_inode->i_pipe;
45685
45686 pipe_lock(pipe);
45687 - pipe->readers++;
45688 - pipe->writers--;
45689 + atomic_inc(&pipe->readers);
45690 + atomic_dec(&pipe->writers);
45691
45692 - while ((pipe->readers > 1) && (!signal_pending(current))) {
45693 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
45694 wake_up_interruptible_sync(&pipe->wait);
45695 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
45696 pipe_wait(pipe);
45697 }
45698
45699 - pipe->readers--;
45700 - pipe->writers++;
45701 + atomic_dec(&pipe->readers);
45702 + atomic_inc(&pipe->writers);
45703 pipe_unlock(pipe);
45704
45705 }
45706 @@ -1929,7 +2221,7 @@ void do_coredump(long signr, int exit_co
45707 int retval = 0;
45708 int flag = 0;
45709 int ispipe;
45710 - static atomic_t core_dump_count = ATOMIC_INIT(0);
45711 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
45712 struct coredump_params cprm = {
45713 .signr = signr,
45714 .regs = regs,
45715 @@ -1944,6 +2236,9 @@ void do_coredump(long signr, int exit_co
45716
45717 audit_core_dumps(signr);
45718
45719 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
45720 + gr_handle_brute_attach(current, cprm.mm_flags);
45721 +
45722 binfmt = mm->binfmt;
45723 if (!binfmt || !binfmt->core_dump)
45724 goto fail;
45725 @@ -1984,6 +2279,8 @@ void do_coredump(long signr, int exit_co
45726 goto fail_corename;
45727 }
45728
45729 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
45730 +
45731 if (ispipe) {
45732 int dump_count;
45733 char **helper_argv;
45734 @@ -2011,7 +2308,7 @@ void do_coredump(long signr, int exit_co
45735 }
45736 cprm.limit = RLIM_INFINITY;
45737
45738 - dump_count = atomic_inc_return(&core_dump_count);
45739 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
45740 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
45741 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
45742 task_tgid_vnr(current), current->comm);
45743 @@ -2081,7 +2378,7 @@ close_fail:
45744 filp_close(cprm.file, NULL);
45745 fail_dropcount:
45746 if (ispipe)
45747 - atomic_dec(&core_dump_count);
45748 + atomic_dec_unchecked(&core_dump_count);
45749 fail_unlock:
45750 kfree(cn.corename);
45751 fail_corename:
45752 diff -urNp linux-2.6.39/fs/ext2/balloc.c linux-2.6.39/fs/ext2/balloc.c
45753 --- linux-2.6.39/fs/ext2/balloc.c 2011-05-19 00:06:34.000000000 -0400
45754 +++ linux-2.6.39/fs/ext2/balloc.c 2011-05-22 19:41:37.000000000 -0400
45755 @@ -1192,7 +1192,7 @@ static int ext2_has_free_blocks(struct e
45756
45757 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45758 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45759 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45760 + if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
45761 sbi->s_resuid != current_fsuid() &&
45762 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
45763 return 0;
45764 diff -urNp linux-2.6.39/fs/ext3/balloc.c linux-2.6.39/fs/ext3/balloc.c
45765 --- linux-2.6.39/fs/ext3/balloc.c 2011-05-19 00:06:34.000000000 -0400
45766 +++ linux-2.6.39/fs/ext3/balloc.c 2011-05-22 19:41:37.000000000 -0400
45767 @@ -1441,7 +1441,7 @@ static int ext3_has_free_blocks(struct e
45768
45769 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45770 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45771 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45772 + if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
45773 sbi->s_resuid != current_fsuid() &&
45774 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
45775 return 0;
45776 diff -urNp linux-2.6.39/fs/ext4/balloc.c linux-2.6.39/fs/ext4/balloc.c
45777 --- linux-2.6.39/fs/ext4/balloc.c 2011-05-19 00:06:34.000000000 -0400
45778 +++ linux-2.6.39/fs/ext4/balloc.c 2011-05-22 19:41:37.000000000 -0400
45779 @@ -522,7 +522,7 @@ static int ext4_has_free_blocks(struct e
45780 /* Hm, nope. Are (enough) root reserved blocks available? */
45781 if (sbi->s_resuid == current_fsuid() ||
45782 ((sbi->s_resgid != 0) && in_group_p(sbi->s_resgid)) ||
45783 - capable(CAP_SYS_RESOURCE)) {
45784 + capable_nolog(CAP_SYS_RESOURCE)) {
45785 if (free_blocks >= (nblocks + dirty_blocks))
45786 return 1;
45787 }
45788 diff -urNp linux-2.6.39/fs/ext4/ext4.h linux-2.6.39/fs/ext4/ext4.h
45789 --- linux-2.6.39/fs/ext4/ext4.h 2011-05-19 00:06:34.000000000 -0400
45790 +++ linux-2.6.39/fs/ext4/ext4.h 2011-05-22 19:36:32.000000000 -0400
45791 @@ -1166,19 +1166,19 @@ struct ext4_sb_info {
45792 unsigned long s_mb_last_start;
45793
45794 /* stats for buddy allocator */
45795 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
45796 - atomic_t s_bal_success; /* we found long enough chunks */
45797 - atomic_t s_bal_allocated; /* in blocks */
45798 - atomic_t s_bal_ex_scanned; /* total extents scanned */
45799 - atomic_t s_bal_goals; /* goal hits */
45800 - atomic_t s_bal_breaks; /* too long searches */
45801 - atomic_t s_bal_2orders; /* 2^order hits */
45802 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
45803 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
45804 + atomic_unchecked_t s_bal_allocated; /* in blocks */
45805 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
45806 + atomic_unchecked_t s_bal_goals; /* goal hits */
45807 + atomic_unchecked_t s_bal_breaks; /* too long searches */
45808 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
45809 spinlock_t s_bal_lock;
45810 unsigned long s_mb_buddies_generated;
45811 unsigned long long s_mb_generation_time;
45812 - atomic_t s_mb_lost_chunks;
45813 - atomic_t s_mb_preallocated;
45814 - atomic_t s_mb_discarded;
45815 + atomic_unchecked_t s_mb_lost_chunks;
45816 + atomic_unchecked_t s_mb_preallocated;
45817 + atomic_unchecked_t s_mb_discarded;
45818 atomic_t s_lock_busy;
45819
45820 /* locality groups */
45821 diff -urNp linux-2.6.39/fs/ext4/mballoc.c linux-2.6.39/fs/ext4/mballoc.c
45822 --- linux-2.6.39/fs/ext4/mballoc.c 2011-05-19 00:06:34.000000000 -0400
45823 +++ linux-2.6.39/fs/ext4/mballoc.c 2011-05-22 19:36:32.000000000 -0400
45824 @@ -1851,7 +1851,7 @@ void ext4_mb_simple_scan_group(struct ex
45825 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
45826
45827 if (EXT4_SB(sb)->s_mb_stats)
45828 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
45829 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
45830
45831 break;
45832 }
45833 @@ -2145,7 +2145,7 @@ repeat:
45834 ac->ac_status = AC_STATUS_CONTINUE;
45835 ac->ac_flags |= EXT4_MB_HINT_FIRST;
45836 cr = 3;
45837 - atomic_inc(&sbi->s_mb_lost_chunks);
45838 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
45839 goto repeat;
45840 }
45841 }
45842 @@ -2188,6 +2188,8 @@ static int ext4_mb_seq_groups_show(struc
45843 ext4_grpblk_t counters[16];
45844 } sg;
45845
45846 + pax_track_stack();
45847 +
45848 group--;
45849 if (group == 0)
45850 seq_printf(seq, "#%-5s: %-5s %-5s %-5s "
45851 @@ -2611,25 +2613,25 @@ int ext4_mb_release(struct super_block *
45852 if (sbi->s_mb_stats) {
45853 printk(KERN_INFO
45854 "EXT4-fs: mballoc: %u blocks %u reqs (%u success)\n",
45855 - atomic_read(&sbi->s_bal_allocated),
45856 - atomic_read(&sbi->s_bal_reqs),
45857 - atomic_read(&sbi->s_bal_success));
45858 + atomic_read_unchecked(&sbi->s_bal_allocated),
45859 + atomic_read_unchecked(&sbi->s_bal_reqs),
45860 + atomic_read_unchecked(&sbi->s_bal_success));
45861 printk(KERN_INFO
45862 "EXT4-fs: mballoc: %u extents scanned, %u goal hits, "
45863 "%u 2^N hits, %u breaks, %u lost\n",
45864 - atomic_read(&sbi->s_bal_ex_scanned),
45865 - atomic_read(&sbi->s_bal_goals),
45866 - atomic_read(&sbi->s_bal_2orders),
45867 - atomic_read(&sbi->s_bal_breaks),
45868 - atomic_read(&sbi->s_mb_lost_chunks));
45869 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
45870 + atomic_read_unchecked(&sbi->s_bal_goals),
45871 + atomic_read_unchecked(&sbi->s_bal_2orders),
45872 + atomic_read_unchecked(&sbi->s_bal_breaks),
45873 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
45874 printk(KERN_INFO
45875 "EXT4-fs: mballoc: %lu generated and it took %Lu\n",
45876 sbi->s_mb_buddies_generated++,
45877 sbi->s_mb_generation_time);
45878 printk(KERN_INFO
45879 "EXT4-fs: mballoc: %u preallocated, %u discarded\n",
45880 - atomic_read(&sbi->s_mb_preallocated),
45881 - atomic_read(&sbi->s_mb_discarded));
45882 + atomic_read_unchecked(&sbi->s_mb_preallocated),
45883 + atomic_read_unchecked(&sbi->s_mb_discarded));
45884 }
45885
45886 free_percpu(sbi->s_locality_groups);
45887 @@ -3105,16 +3107,16 @@ static void ext4_mb_collect_stats(struct
45888 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
45889
45890 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
45891 - atomic_inc(&sbi->s_bal_reqs);
45892 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45893 + atomic_inc_unchecked(&sbi->s_bal_reqs);
45894 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45895 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
45896 - atomic_inc(&sbi->s_bal_success);
45897 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
45898 + atomic_inc_unchecked(&sbi->s_bal_success);
45899 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
45900 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
45901 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
45902 - atomic_inc(&sbi->s_bal_goals);
45903 + atomic_inc_unchecked(&sbi->s_bal_goals);
45904 if (ac->ac_found > sbi->s_mb_max_to_scan)
45905 - atomic_inc(&sbi->s_bal_breaks);
45906 + atomic_inc_unchecked(&sbi->s_bal_breaks);
45907 }
45908
45909 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
45910 @@ -3512,7 +3514,7 @@ ext4_mb_new_inode_pa(struct ext4_allocat
45911 trace_ext4_mb_new_inode_pa(ac, pa);
45912
45913 ext4_mb_use_inode_pa(ac, pa);
45914 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45915 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45916
45917 ei = EXT4_I(ac->ac_inode);
45918 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45919 @@ -3572,7 +3574,7 @@ ext4_mb_new_group_pa(struct ext4_allocat
45920 trace_ext4_mb_new_group_pa(ac, pa);
45921
45922 ext4_mb_use_group_pa(ac, pa);
45923 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45924 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45925
45926 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45927 lg = ac->ac_lg;
45928 @@ -3659,7 +3661,7 @@ ext4_mb_release_inode_pa(struct ext4_bud
45929 * from the bitmap and continue.
45930 */
45931 }
45932 - atomic_add(free, &sbi->s_mb_discarded);
45933 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
45934
45935 return err;
45936 }
45937 @@ -3677,7 +3679,7 @@ ext4_mb_release_group_pa(struct ext4_bud
45938 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
45939 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
45940 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
45941 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45942 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45943 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
45944
45945 return 0;
45946 diff -urNp linux-2.6.39/fs/fcntl.c linux-2.6.39/fs/fcntl.c
45947 --- linux-2.6.39/fs/fcntl.c 2011-05-19 00:06:34.000000000 -0400
45948 +++ linux-2.6.39/fs/fcntl.c 2011-05-22 20:45:50.000000000 -0400
45949 @@ -224,6 +224,11 @@ int __f_setown(struct file *filp, struct
45950 if (err)
45951 return err;
45952
45953 + if (gr_handle_chroot_fowner(pid, type))
45954 + return -ENOENT;
45955 + if (gr_check_protected_task_fowner(pid, type))
45956 + return -EACCES;
45957 +
45958 f_modown(filp, pid, type, force);
45959 return 0;
45960 }
45961 @@ -348,6 +353,7 @@ static long do_fcntl(int fd, unsigned in
45962 switch (cmd) {
45963 case F_DUPFD:
45964 case F_DUPFD_CLOEXEC:
45965 + gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
45966 if (arg >= rlimit(RLIMIT_NOFILE))
45967 break;
45968 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
45969 @@ -835,14 +841,14 @@ static int __init fcntl_init(void)
45970 * Exceptions: O_NONBLOCK is a two bit define on parisc; O_NDELAY
45971 * is defined as O_NONBLOCK on some platforms and not on others.
45972 */
45973 - BUILD_BUG_ON(19 - 1 /* for O_RDONLY being 0 */ != HWEIGHT32(
45974 + BUILD_BUG_ON(20 - 1 /* for O_RDONLY being 0 */ != HWEIGHT32(
45975 O_RDONLY | O_WRONLY | O_RDWR |
45976 O_CREAT | O_EXCL | O_NOCTTY |
45977 O_TRUNC | O_APPEND | /* O_NONBLOCK | */
45978 __O_SYNC | O_DSYNC | FASYNC |
45979 O_DIRECT | O_LARGEFILE | O_DIRECTORY |
45980 O_NOFOLLOW | O_NOATIME | O_CLOEXEC |
45981 - __FMODE_EXEC | O_PATH
45982 + __FMODE_EXEC | O_PATH | FMODE_GREXEC
45983 ));
45984
45985 fasync_cache = kmem_cache_create("fasync_cache",
45986 diff -urNp linux-2.6.39/fs/fifo.c linux-2.6.39/fs/fifo.c
45987 --- linux-2.6.39/fs/fifo.c 2011-05-19 00:06:34.000000000 -0400
45988 +++ linux-2.6.39/fs/fifo.c 2011-05-22 19:36:32.000000000 -0400
45989 @@ -58,10 +58,10 @@ static int fifo_open(struct inode *inode
45990 */
45991 filp->f_op = &read_pipefifo_fops;
45992 pipe->r_counter++;
45993 - if (pipe->readers++ == 0)
45994 + if (atomic_inc_return(&pipe->readers) == 1)
45995 wake_up_partner(inode);
45996
45997 - if (!pipe->writers) {
45998 + if (!atomic_read(&pipe->writers)) {
45999 if ((filp->f_flags & O_NONBLOCK)) {
46000 /* suppress POLLHUP until we have
46001 * seen a writer */
46002 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode
46003 * errno=ENXIO when there is no process reading the FIFO.
46004 */
46005 ret = -ENXIO;
46006 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
46007 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
46008 goto err;
46009
46010 filp->f_op = &write_pipefifo_fops;
46011 pipe->w_counter++;
46012 - if (!pipe->writers++)
46013 + if (atomic_inc_return(&pipe->writers) == 1)
46014 wake_up_partner(inode);
46015
46016 - if (!pipe->readers) {
46017 + if (!atomic_read(&pipe->readers)) {
46018 wait_for_partner(inode, &pipe->r_counter);
46019 if (signal_pending(current))
46020 goto err_wr;
46021 @@ -105,11 +105,11 @@ static int fifo_open(struct inode *inode
46022 */
46023 filp->f_op = &rdwr_pipefifo_fops;
46024
46025 - pipe->readers++;
46026 - pipe->writers++;
46027 + atomic_inc(&pipe->readers);
46028 + atomic_inc(&pipe->writers);
46029 pipe->r_counter++;
46030 pipe->w_counter++;
46031 - if (pipe->readers == 1 || pipe->writers == 1)
46032 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
46033 wake_up_partner(inode);
46034 break;
46035
46036 @@ -123,19 +123,19 @@ static int fifo_open(struct inode *inode
46037 return 0;
46038
46039 err_rd:
46040 - if (!--pipe->readers)
46041 + if (atomic_dec_and_test(&pipe->readers))
46042 wake_up_interruptible(&pipe->wait);
46043 ret = -ERESTARTSYS;
46044 goto err;
46045
46046 err_wr:
46047 - if (!--pipe->writers)
46048 + if (atomic_dec_and_test(&pipe->writers))
46049 wake_up_interruptible(&pipe->wait);
46050 ret = -ERESTARTSYS;
46051 goto err;
46052
46053 err:
46054 - if (!pipe->readers && !pipe->writers)
46055 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
46056 free_pipe_info(inode);
46057
46058 err_nocleanup:
46059 diff -urNp linux-2.6.39/fs/file.c linux-2.6.39/fs/file.c
46060 --- linux-2.6.39/fs/file.c 2011-05-19 00:06:34.000000000 -0400
46061 +++ linux-2.6.39/fs/file.c 2011-05-22 19:41:37.000000000 -0400
46062 @@ -15,6 +15,7 @@
46063 #include <linux/slab.h>
46064 #include <linux/vmalloc.h>
46065 #include <linux/file.h>
46066 +#include <linux/security.h>
46067 #include <linux/fdtable.h>
46068 #include <linux/bitops.h>
46069 #include <linux/interrupt.h>
46070 @@ -254,6 +255,7 @@ int expand_files(struct files_struct *fi
46071 * N.B. For clone tasks sharing a files structure, this test
46072 * will limit the total number of files that can be opened.
46073 */
46074 + gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
46075 if (nr >= rlimit(RLIMIT_NOFILE))
46076 return -EMFILE;
46077
46078 diff -urNp linux-2.6.39/fs/filesystems.c linux-2.6.39/fs/filesystems.c
46079 --- linux-2.6.39/fs/filesystems.c 2011-05-19 00:06:34.000000000 -0400
46080 +++ linux-2.6.39/fs/filesystems.c 2011-05-22 19:41:37.000000000 -0400
46081 @@ -274,7 +274,12 @@ struct file_system_type *get_fs_type(con
46082 int len = dot ? dot - name : strlen(name);
46083
46084 fs = __get_fs_type(name, len);
46085 +
46086 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
46087 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
46088 +#else
46089 if (!fs && (request_module("%.*s", len, name) == 0))
46090 +#endif
46091 fs = __get_fs_type(name, len);
46092
46093 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
46094 diff -urNp linux-2.6.39/fs/fscache/cookie.c linux-2.6.39/fs/fscache/cookie.c
46095 --- linux-2.6.39/fs/fscache/cookie.c 2011-05-19 00:06:34.000000000 -0400
46096 +++ linux-2.6.39/fs/fscache/cookie.c 2011-05-22 19:36:32.000000000 -0400
46097 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire
46098 parent ? (char *) parent->def->name : "<no-parent>",
46099 def->name, netfs_data);
46100
46101 - fscache_stat(&fscache_n_acquires);
46102 + fscache_stat_unchecked(&fscache_n_acquires);
46103
46104 /* if there's no parent cookie, then we don't create one here either */
46105 if (!parent) {
46106 - fscache_stat(&fscache_n_acquires_null);
46107 + fscache_stat_unchecked(&fscache_n_acquires_null);
46108 _leave(" [no parent]");
46109 return NULL;
46110 }
46111 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire
46112 /* allocate and initialise a cookie */
46113 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
46114 if (!cookie) {
46115 - fscache_stat(&fscache_n_acquires_oom);
46116 + fscache_stat_unchecked(&fscache_n_acquires_oom);
46117 _leave(" [ENOMEM]");
46118 return NULL;
46119 }
46120 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire
46121
46122 switch (cookie->def->type) {
46123 case FSCACHE_COOKIE_TYPE_INDEX:
46124 - fscache_stat(&fscache_n_cookie_index);
46125 + fscache_stat_unchecked(&fscache_n_cookie_index);
46126 break;
46127 case FSCACHE_COOKIE_TYPE_DATAFILE:
46128 - fscache_stat(&fscache_n_cookie_data);
46129 + fscache_stat_unchecked(&fscache_n_cookie_data);
46130 break;
46131 default:
46132 - fscache_stat(&fscache_n_cookie_special);
46133 + fscache_stat_unchecked(&fscache_n_cookie_special);
46134 break;
46135 }
46136
46137 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire
46138 if (fscache_acquire_non_index_cookie(cookie) < 0) {
46139 atomic_dec(&parent->n_children);
46140 __fscache_cookie_put(cookie);
46141 - fscache_stat(&fscache_n_acquires_nobufs);
46142 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
46143 _leave(" = NULL");
46144 return NULL;
46145 }
46146 }
46147
46148 - fscache_stat(&fscache_n_acquires_ok);
46149 + fscache_stat_unchecked(&fscache_n_acquires_ok);
46150 _leave(" = %p", cookie);
46151 return cookie;
46152 }
46153 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_coo
46154 cache = fscache_select_cache_for_object(cookie->parent);
46155 if (!cache) {
46156 up_read(&fscache_addremove_sem);
46157 - fscache_stat(&fscache_n_acquires_no_cache);
46158 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
46159 _leave(" = -ENOMEDIUM [no cache]");
46160 return -ENOMEDIUM;
46161 }
46162 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct f
46163 object = cache->ops->alloc_object(cache, cookie);
46164 fscache_stat_d(&fscache_n_cop_alloc_object);
46165 if (IS_ERR(object)) {
46166 - fscache_stat(&fscache_n_object_no_alloc);
46167 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
46168 ret = PTR_ERR(object);
46169 goto error;
46170 }
46171
46172 - fscache_stat(&fscache_n_object_alloc);
46173 + fscache_stat_unchecked(&fscache_n_object_alloc);
46174
46175 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
46176
46177 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fsca
46178 struct fscache_object *object;
46179 struct hlist_node *_p;
46180
46181 - fscache_stat(&fscache_n_updates);
46182 + fscache_stat_unchecked(&fscache_n_updates);
46183
46184 if (!cookie) {
46185 - fscache_stat(&fscache_n_updates_null);
46186 + fscache_stat_unchecked(&fscache_n_updates_null);
46187 _leave(" [no cookie]");
46188 return;
46189 }
46190 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct
46191 struct fscache_object *object;
46192 unsigned long event;
46193
46194 - fscache_stat(&fscache_n_relinquishes);
46195 + fscache_stat_unchecked(&fscache_n_relinquishes);
46196 if (retire)
46197 - fscache_stat(&fscache_n_relinquishes_retire);
46198 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
46199
46200 if (!cookie) {
46201 - fscache_stat(&fscache_n_relinquishes_null);
46202 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
46203 _leave(" [no cookie]");
46204 return;
46205 }
46206 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct
46207
46208 /* wait for the cookie to finish being instantiated (or to fail) */
46209 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
46210 - fscache_stat(&fscache_n_relinquishes_waitcrt);
46211 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
46212 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
46213 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
46214 }
46215 diff -urNp linux-2.6.39/fs/fscache/internal.h linux-2.6.39/fs/fscache/internal.h
46216 --- linux-2.6.39/fs/fscache/internal.h 2011-05-19 00:06:34.000000000 -0400
46217 +++ linux-2.6.39/fs/fscache/internal.h 2011-05-22 19:36:32.000000000 -0400
46218 @@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
46219 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
46220 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
46221
46222 -extern atomic_t fscache_n_op_pend;
46223 -extern atomic_t fscache_n_op_run;
46224 -extern atomic_t fscache_n_op_enqueue;
46225 -extern atomic_t fscache_n_op_deferred_release;
46226 -extern atomic_t fscache_n_op_release;
46227 -extern atomic_t fscache_n_op_gc;
46228 -extern atomic_t fscache_n_op_cancelled;
46229 -extern atomic_t fscache_n_op_rejected;
46230 -
46231 -extern atomic_t fscache_n_attr_changed;
46232 -extern atomic_t fscache_n_attr_changed_ok;
46233 -extern atomic_t fscache_n_attr_changed_nobufs;
46234 -extern atomic_t fscache_n_attr_changed_nomem;
46235 -extern atomic_t fscache_n_attr_changed_calls;
46236 -
46237 -extern atomic_t fscache_n_allocs;
46238 -extern atomic_t fscache_n_allocs_ok;
46239 -extern atomic_t fscache_n_allocs_wait;
46240 -extern atomic_t fscache_n_allocs_nobufs;
46241 -extern atomic_t fscache_n_allocs_intr;
46242 -extern atomic_t fscache_n_allocs_object_dead;
46243 -extern atomic_t fscache_n_alloc_ops;
46244 -extern atomic_t fscache_n_alloc_op_waits;
46245 -
46246 -extern atomic_t fscache_n_retrievals;
46247 -extern atomic_t fscache_n_retrievals_ok;
46248 -extern atomic_t fscache_n_retrievals_wait;
46249 -extern atomic_t fscache_n_retrievals_nodata;
46250 -extern atomic_t fscache_n_retrievals_nobufs;
46251 -extern atomic_t fscache_n_retrievals_intr;
46252 -extern atomic_t fscache_n_retrievals_nomem;
46253 -extern atomic_t fscache_n_retrievals_object_dead;
46254 -extern atomic_t fscache_n_retrieval_ops;
46255 -extern atomic_t fscache_n_retrieval_op_waits;
46256 -
46257 -extern atomic_t fscache_n_stores;
46258 -extern atomic_t fscache_n_stores_ok;
46259 -extern atomic_t fscache_n_stores_again;
46260 -extern atomic_t fscache_n_stores_nobufs;
46261 -extern atomic_t fscache_n_stores_oom;
46262 -extern atomic_t fscache_n_store_ops;
46263 -extern atomic_t fscache_n_store_calls;
46264 -extern atomic_t fscache_n_store_pages;
46265 -extern atomic_t fscache_n_store_radix_deletes;
46266 -extern atomic_t fscache_n_store_pages_over_limit;
46267 -
46268 -extern atomic_t fscache_n_store_vmscan_not_storing;
46269 -extern atomic_t fscache_n_store_vmscan_gone;
46270 -extern atomic_t fscache_n_store_vmscan_busy;
46271 -extern atomic_t fscache_n_store_vmscan_cancelled;
46272 -
46273 -extern atomic_t fscache_n_marks;
46274 -extern atomic_t fscache_n_uncaches;
46275 -
46276 -extern atomic_t fscache_n_acquires;
46277 -extern atomic_t fscache_n_acquires_null;
46278 -extern atomic_t fscache_n_acquires_no_cache;
46279 -extern atomic_t fscache_n_acquires_ok;
46280 -extern atomic_t fscache_n_acquires_nobufs;
46281 -extern atomic_t fscache_n_acquires_oom;
46282 -
46283 -extern atomic_t fscache_n_updates;
46284 -extern atomic_t fscache_n_updates_null;
46285 -extern atomic_t fscache_n_updates_run;
46286 -
46287 -extern atomic_t fscache_n_relinquishes;
46288 -extern atomic_t fscache_n_relinquishes_null;
46289 -extern atomic_t fscache_n_relinquishes_waitcrt;
46290 -extern atomic_t fscache_n_relinquishes_retire;
46291 -
46292 -extern atomic_t fscache_n_cookie_index;
46293 -extern atomic_t fscache_n_cookie_data;
46294 -extern atomic_t fscache_n_cookie_special;
46295 -
46296 -extern atomic_t fscache_n_object_alloc;
46297 -extern atomic_t fscache_n_object_no_alloc;
46298 -extern atomic_t fscache_n_object_lookups;
46299 -extern atomic_t fscache_n_object_lookups_negative;
46300 -extern atomic_t fscache_n_object_lookups_positive;
46301 -extern atomic_t fscache_n_object_lookups_timed_out;
46302 -extern atomic_t fscache_n_object_created;
46303 -extern atomic_t fscache_n_object_avail;
46304 -extern atomic_t fscache_n_object_dead;
46305 -
46306 -extern atomic_t fscache_n_checkaux_none;
46307 -extern atomic_t fscache_n_checkaux_okay;
46308 -extern atomic_t fscache_n_checkaux_update;
46309 -extern atomic_t fscache_n_checkaux_obsolete;
46310 +extern atomic_unchecked_t fscache_n_op_pend;
46311 +extern atomic_unchecked_t fscache_n_op_run;
46312 +extern atomic_unchecked_t fscache_n_op_enqueue;
46313 +extern atomic_unchecked_t fscache_n_op_deferred_release;
46314 +extern atomic_unchecked_t fscache_n_op_release;
46315 +extern atomic_unchecked_t fscache_n_op_gc;
46316 +extern atomic_unchecked_t fscache_n_op_cancelled;
46317 +extern atomic_unchecked_t fscache_n_op_rejected;
46318 +
46319 +extern atomic_unchecked_t fscache_n_attr_changed;
46320 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
46321 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
46322 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
46323 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
46324 +
46325 +extern atomic_unchecked_t fscache_n_allocs;
46326 +extern atomic_unchecked_t fscache_n_allocs_ok;
46327 +extern atomic_unchecked_t fscache_n_allocs_wait;
46328 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
46329 +extern atomic_unchecked_t fscache_n_allocs_intr;
46330 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
46331 +extern atomic_unchecked_t fscache_n_alloc_ops;
46332 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
46333 +
46334 +extern atomic_unchecked_t fscache_n_retrievals;
46335 +extern atomic_unchecked_t fscache_n_retrievals_ok;
46336 +extern atomic_unchecked_t fscache_n_retrievals_wait;
46337 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
46338 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
46339 +extern atomic_unchecked_t fscache_n_retrievals_intr;
46340 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
46341 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
46342 +extern atomic_unchecked_t fscache_n_retrieval_ops;
46343 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
46344 +
46345 +extern atomic_unchecked_t fscache_n_stores;
46346 +extern atomic_unchecked_t fscache_n_stores_ok;
46347 +extern atomic_unchecked_t fscache_n_stores_again;
46348 +extern atomic_unchecked_t fscache_n_stores_nobufs;
46349 +extern atomic_unchecked_t fscache_n_stores_oom;
46350 +extern atomic_unchecked_t fscache_n_store_ops;
46351 +extern atomic_unchecked_t fscache_n_store_calls;
46352 +extern atomic_unchecked_t fscache_n_store_pages;
46353 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
46354 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
46355 +
46356 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
46357 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
46358 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
46359 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
46360 +
46361 +extern atomic_unchecked_t fscache_n_marks;
46362 +extern atomic_unchecked_t fscache_n_uncaches;
46363 +
46364 +extern atomic_unchecked_t fscache_n_acquires;
46365 +extern atomic_unchecked_t fscache_n_acquires_null;
46366 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
46367 +extern atomic_unchecked_t fscache_n_acquires_ok;
46368 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
46369 +extern atomic_unchecked_t fscache_n_acquires_oom;
46370 +
46371 +extern atomic_unchecked_t fscache_n_updates;
46372 +extern atomic_unchecked_t fscache_n_updates_null;
46373 +extern atomic_unchecked_t fscache_n_updates_run;
46374 +
46375 +extern atomic_unchecked_t fscache_n_relinquishes;
46376 +extern atomic_unchecked_t fscache_n_relinquishes_null;
46377 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
46378 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
46379 +
46380 +extern atomic_unchecked_t fscache_n_cookie_index;
46381 +extern atomic_unchecked_t fscache_n_cookie_data;
46382 +extern atomic_unchecked_t fscache_n_cookie_special;
46383 +
46384 +extern atomic_unchecked_t fscache_n_object_alloc;
46385 +extern atomic_unchecked_t fscache_n_object_no_alloc;
46386 +extern atomic_unchecked_t fscache_n_object_lookups;
46387 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
46388 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
46389 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
46390 +extern atomic_unchecked_t fscache_n_object_created;
46391 +extern atomic_unchecked_t fscache_n_object_avail;
46392 +extern atomic_unchecked_t fscache_n_object_dead;
46393 +
46394 +extern atomic_unchecked_t fscache_n_checkaux_none;
46395 +extern atomic_unchecked_t fscache_n_checkaux_okay;
46396 +extern atomic_unchecked_t fscache_n_checkaux_update;
46397 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
46398
46399 extern atomic_t fscache_n_cop_alloc_object;
46400 extern atomic_t fscache_n_cop_lookup_object;
46401 @@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t
46402 atomic_inc(stat);
46403 }
46404
46405 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
46406 +{
46407 + atomic_inc_unchecked(stat);
46408 +}
46409 +
46410 static inline void fscache_stat_d(atomic_t *stat)
46411 {
46412 atomic_dec(stat);
46413 @@ -267,6 +272,7 @@ extern const struct file_operations fsca
46414
46415 #define __fscache_stat(stat) (NULL)
46416 #define fscache_stat(stat) do {} while (0)
46417 +#define fscache_stat_unchecked(stat) do {} while (0)
46418 #define fscache_stat_d(stat) do {} while (0)
46419 #endif
46420
46421 diff -urNp linux-2.6.39/fs/fscache/object.c linux-2.6.39/fs/fscache/object.c
46422 --- linux-2.6.39/fs/fscache/object.c 2011-05-19 00:06:34.000000000 -0400
46423 +++ linux-2.6.39/fs/fscache/object.c 2011-05-22 19:36:32.000000000 -0400
46424 @@ -128,7 +128,7 @@ static void fscache_object_state_machine
46425 /* update the object metadata on disk */
46426 case FSCACHE_OBJECT_UPDATING:
46427 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
46428 - fscache_stat(&fscache_n_updates_run);
46429 + fscache_stat_unchecked(&fscache_n_updates_run);
46430 fscache_stat(&fscache_n_cop_update_object);
46431 object->cache->ops->update_object(object);
46432 fscache_stat_d(&fscache_n_cop_update_object);
46433 @@ -217,7 +217,7 @@ static void fscache_object_state_machine
46434 spin_lock(&object->lock);
46435 object->state = FSCACHE_OBJECT_DEAD;
46436 spin_unlock(&object->lock);
46437 - fscache_stat(&fscache_n_object_dead);
46438 + fscache_stat_unchecked(&fscache_n_object_dead);
46439 goto terminal_transit;
46440
46441 /* handle the parent cache of this object being withdrawn from
46442 @@ -232,7 +232,7 @@ static void fscache_object_state_machine
46443 spin_lock(&object->lock);
46444 object->state = FSCACHE_OBJECT_DEAD;
46445 spin_unlock(&object->lock);
46446 - fscache_stat(&fscache_n_object_dead);
46447 + fscache_stat_unchecked(&fscache_n_object_dead);
46448 goto terminal_transit;
46449
46450 /* complain about the object being woken up once it is
46451 @@ -461,7 +461,7 @@ static void fscache_lookup_object(struct
46452 parent->cookie->def->name, cookie->def->name,
46453 object->cache->tag->name);
46454
46455 - fscache_stat(&fscache_n_object_lookups);
46456 + fscache_stat_unchecked(&fscache_n_object_lookups);
46457 fscache_stat(&fscache_n_cop_lookup_object);
46458 ret = object->cache->ops->lookup_object(object);
46459 fscache_stat_d(&fscache_n_cop_lookup_object);
46460 @@ -472,7 +472,7 @@ static void fscache_lookup_object(struct
46461 if (ret == -ETIMEDOUT) {
46462 /* probably stuck behind another object, so move this one to
46463 * the back of the queue */
46464 - fscache_stat(&fscache_n_object_lookups_timed_out);
46465 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
46466 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46467 }
46468
46469 @@ -495,7 +495,7 @@ void fscache_object_lookup_negative(stru
46470
46471 spin_lock(&object->lock);
46472 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46473 - fscache_stat(&fscache_n_object_lookups_negative);
46474 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
46475
46476 /* transit here to allow write requests to begin stacking up
46477 * and read requests to begin returning ENODATA */
46478 @@ -541,7 +541,7 @@ void fscache_obtained_object(struct fsca
46479 * result, in which case there may be data available */
46480 spin_lock(&object->lock);
46481 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46482 - fscache_stat(&fscache_n_object_lookups_positive);
46483 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
46484
46485 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
46486
46487 @@ -555,7 +555,7 @@ void fscache_obtained_object(struct fsca
46488 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46489 } else {
46490 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
46491 - fscache_stat(&fscache_n_object_created);
46492 + fscache_stat_unchecked(&fscache_n_object_created);
46493
46494 object->state = FSCACHE_OBJECT_AVAILABLE;
46495 spin_unlock(&object->lock);
46496 @@ -602,7 +602,7 @@ static void fscache_object_available(str
46497 fscache_enqueue_dependents(object);
46498
46499 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
46500 - fscache_stat(&fscache_n_object_avail);
46501 + fscache_stat_unchecked(&fscache_n_object_avail);
46502
46503 _leave("");
46504 }
46505 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(
46506 enum fscache_checkaux result;
46507
46508 if (!object->cookie->def->check_aux) {
46509 - fscache_stat(&fscache_n_checkaux_none);
46510 + fscache_stat_unchecked(&fscache_n_checkaux_none);
46511 return FSCACHE_CHECKAUX_OKAY;
46512 }
46513
46514 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(
46515 switch (result) {
46516 /* entry okay as is */
46517 case FSCACHE_CHECKAUX_OKAY:
46518 - fscache_stat(&fscache_n_checkaux_okay);
46519 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
46520 break;
46521
46522 /* entry requires update */
46523 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
46524 - fscache_stat(&fscache_n_checkaux_update);
46525 + fscache_stat_unchecked(&fscache_n_checkaux_update);
46526 break;
46527
46528 /* entry requires deletion */
46529 case FSCACHE_CHECKAUX_OBSOLETE:
46530 - fscache_stat(&fscache_n_checkaux_obsolete);
46531 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
46532 break;
46533
46534 default:
46535 diff -urNp linux-2.6.39/fs/fscache/operation.c linux-2.6.39/fs/fscache/operation.c
46536 --- linux-2.6.39/fs/fscache/operation.c 2011-05-19 00:06:34.000000000 -0400
46537 +++ linux-2.6.39/fs/fscache/operation.c 2011-05-22 19:36:32.000000000 -0400
46538 @@ -17,7 +17,7 @@
46539 #include <linux/slab.h>
46540 #include "internal.h"
46541
46542 -atomic_t fscache_op_debug_id;
46543 +atomic_unchecked_t fscache_op_debug_id;
46544 EXPORT_SYMBOL(fscache_op_debug_id);
46545
46546 /**
46547 @@ -40,7 +40,7 @@ void fscache_enqueue_operation(struct fs
46548 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
46549 ASSERTCMP(atomic_read(&op->usage), >, 0);
46550
46551 - fscache_stat(&fscache_n_op_enqueue);
46552 + fscache_stat_unchecked(&fscache_n_op_enqueue);
46553 switch (op->flags & FSCACHE_OP_TYPE) {
46554 case FSCACHE_OP_ASYNC:
46555 _debug("queue async");
46556 @@ -73,7 +73,7 @@ static void fscache_run_op(struct fscach
46557 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
46558 if (op->processor)
46559 fscache_enqueue_operation(op);
46560 - fscache_stat(&fscache_n_op_run);
46561 + fscache_stat_unchecked(&fscache_n_op_run);
46562 }
46563
46564 /*
46565 @@ -104,11 +104,11 @@ int fscache_submit_exclusive_op(struct f
46566 if (object->n_ops > 1) {
46567 atomic_inc(&op->usage);
46568 list_add_tail(&op->pend_link, &object->pending_ops);
46569 - fscache_stat(&fscache_n_op_pend);
46570 + fscache_stat_unchecked(&fscache_n_op_pend);
46571 } else if (!list_empty(&object->pending_ops)) {
46572 atomic_inc(&op->usage);
46573 list_add_tail(&op->pend_link, &object->pending_ops);
46574 - fscache_stat(&fscache_n_op_pend);
46575 + fscache_stat_unchecked(&fscache_n_op_pend);
46576 fscache_start_operations(object);
46577 } else {
46578 ASSERTCMP(object->n_in_progress, ==, 0);
46579 @@ -124,7 +124,7 @@ int fscache_submit_exclusive_op(struct f
46580 object->n_exclusive++; /* reads and writes must wait */
46581 atomic_inc(&op->usage);
46582 list_add_tail(&op->pend_link, &object->pending_ops);
46583 - fscache_stat(&fscache_n_op_pend);
46584 + fscache_stat_unchecked(&fscache_n_op_pend);
46585 ret = 0;
46586 } else {
46587 /* not allowed to submit ops in any other state */
46588 @@ -211,11 +211,11 @@ int fscache_submit_op(struct fscache_obj
46589 if (object->n_exclusive > 0) {
46590 atomic_inc(&op->usage);
46591 list_add_tail(&op->pend_link, &object->pending_ops);
46592 - fscache_stat(&fscache_n_op_pend);
46593 + fscache_stat_unchecked(&fscache_n_op_pend);
46594 } else if (!list_empty(&object->pending_ops)) {
46595 atomic_inc(&op->usage);
46596 list_add_tail(&op->pend_link, &object->pending_ops);
46597 - fscache_stat(&fscache_n_op_pend);
46598 + fscache_stat_unchecked(&fscache_n_op_pend);
46599 fscache_start_operations(object);
46600 } else {
46601 ASSERTCMP(object->n_exclusive, ==, 0);
46602 @@ -227,12 +227,12 @@ int fscache_submit_op(struct fscache_obj
46603 object->n_ops++;
46604 atomic_inc(&op->usage);
46605 list_add_tail(&op->pend_link, &object->pending_ops);
46606 - fscache_stat(&fscache_n_op_pend);
46607 + fscache_stat_unchecked(&fscache_n_op_pend);
46608 ret = 0;
46609 } else if (object->state == FSCACHE_OBJECT_DYING ||
46610 object->state == FSCACHE_OBJECT_LC_DYING ||
46611 object->state == FSCACHE_OBJECT_WITHDRAWING) {
46612 - fscache_stat(&fscache_n_op_rejected);
46613 + fscache_stat_unchecked(&fscache_n_op_rejected);
46614 ret = -ENOBUFS;
46615 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
46616 fscache_report_unexpected_submission(object, op, ostate);
46617 @@ -302,7 +302,7 @@ int fscache_cancel_op(struct fscache_ope
46618
46619 ret = -EBUSY;
46620 if (!list_empty(&op->pend_link)) {
46621 - fscache_stat(&fscache_n_op_cancelled);
46622 + fscache_stat_unchecked(&fscache_n_op_cancelled);
46623 list_del_init(&op->pend_link);
46624 object->n_ops--;
46625 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
46626 @@ -341,7 +341,7 @@ void fscache_put_operation(struct fscach
46627 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
46628 BUG();
46629
46630 - fscache_stat(&fscache_n_op_release);
46631 + fscache_stat_unchecked(&fscache_n_op_release);
46632
46633 if (op->release) {
46634 op->release(op);
46635 @@ -358,7 +358,7 @@ void fscache_put_operation(struct fscach
46636 * lock, and defer it otherwise */
46637 if (!spin_trylock(&object->lock)) {
46638 _debug("defer put");
46639 - fscache_stat(&fscache_n_op_deferred_release);
46640 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
46641
46642 cache = object->cache;
46643 spin_lock(&cache->op_gc_list_lock);
46644 @@ -420,7 +420,7 @@ void fscache_operation_gc(struct work_st
46645
46646 _debug("GC DEFERRED REL OBJ%x OP%x",
46647 object->debug_id, op->debug_id);
46648 - fscache_stat(&fscache_n_op_gc);
46649 + fscache_stat_unchecked(&fscache_n_op_gc);
46650
46651 ASSERTCMP(atomic_read(&op->usage), ==, 0);
46652
46653 diff -urNp linux-2.6.39/fs/fscache/page.c linux-2.6.39/fs/fscache/page.c
46654 --- linux-2.6.39/fs/fscache/page.c 2011-05-19 00:06:34.000000000 -0400
46655 +++ linux-2.6.39/fs/fscache/page.c 2011-05-22 19:36:32.000000000 -0400
46656 @@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct
46657 val = radix_tree_lookup(&cookie->stores, page->index);
46658 if (!val) {
46659 rcu_read_unlock();
46660 - fscache_stat(&fscache_n_store_vmscan_not_storing);
46661 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
46662 __fscache_uncache_page(cookie, page);
46663 return true;
46664 }
46665 @@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct
46666 spin_unlock(&cookie->stores_lock);
46667
46668 if (xpage) {
46669 - fscache_stat(&fscache_n_store_vmscan_cancelled);
46670 - fscache_stat(&fscache_n_store_radix_deletes);
46671 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
46672 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46673 ASSERTCMP(xpage, ==, page);
46674 } else {
46675 - fscache_stat(&fscache_n_store_vmscan_gone);
46676 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
46677 }
46678
46679 wake_up_bit(&cookie->flags, 0);
46680 @@ -107,7 +107,7 @@ page_busy:
46681 /* we might want to wait here, but that could deadlock the allocator as
46682 * the work threads writing to the cache may all end up sleeping
46683 * on memory allocation */
46684 - fscache_stat(&fscache_n_store_vmscan_busy);
46685 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
46686 return false;
46687 }
46688 EXPORT_SYMBOL(__fscache_maybe_release_page);
46689 @@ -131,7 +131,7 @@ static void fscache_end_page_write(struc
46690 FSCACHE_COOKIE_STORING_TAG);
46691 if (!radix_tree_tag_get(&cookie->stores, page->index,
46692 FSCACHE_COOKIE_PENDING_TAG)) {
46693 - fscache_stat(&fscache_n_store_radix_deletes);
46694 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46695 xpage = radix_tree_delete(&cookie->stores, page->index);
46696 }
46697 spin_unlock(&cookie->stores_lock);
46698 @@ -152,7 +152,7 @@ static void fscache_attr_changed_op(stru
46699
46700 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
46701
46702 - fscache_stat(&fscache_n_attr_changed_calls);
46703 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
46704
46705 if (fscache_object_is_active(object)) {
46706 fscache_set_op_state(op, "CallFS");
46707 @@ -179,11 +179,11 @@ int __fscache_attr_changed(struct fscach
46708
46709 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46710
46711 - fscache_stat(&fscache_n_attr_changed);
46712 + fscache_stat_unchecked(&fscache_n_attr_changed);
46713
46714 op = kzalloc(sizeof(*op), GFP_KERNEL);
46715 if (!op) {
46716 - fscache_stat(&fscache_n_attr_changed_nomem);
46717 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
46718 _leave(" = -ENOMEM");
46719 return -ENOMEM;
46720 }
46721 @@ -202,7 +202,7 @@ int __fscache_attr_changed(struct fscach
46722 if (fscache_submit_exclusive_op(object, op) < 0)
46723 goto nobufs;
46724 spin_unlock(&cookie->lock);
46725 - fscache_stat(&fscache_n_attr_changed_ok);
46726 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
46727 fscache_put_operation(op);
46728 _leave(" = 0");
46729 return 0;
46730 @@ -210,7 +210,7 @@ int __fscache_attr_changed(struct fscach
46731 nobufs:
46732 spin_unlock(&cookie->lock);
46733 kfree(op);
46734 - fscache_stat(&fscache_n_attr_changed_nobufs);
46735 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
46736 _leave(" = %d", -ENOBUFS);
46737 return -ENOBUFS;
46738 }
46739 @@ -246,7 +246,7 @@ static struct fscache_retrieval *fscache
46740 /* allocate a retrieval operation and attempt to submit it */
46741 op = kzalloc(sizeof(*op), GFP_NOIO);
46742 if (!op) {
46743 - fscache_stat(&fscache_n_retrievals_nomem);
46744 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46745 return NULL;
46746 }
46747
46748 @@ -275,13 +275,13 @@ static int fscache_wait_for_deferred_loo
46749 return 0;
46750 }
46751
46752 - fscache_stat(&fscache_n_retrievals_wait);
46753 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
46754
46755 jif = jiffies;
46756 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
46757 fscache_wait_bit_interruptible,
46758 TASK_INTERRUPTIBLE) != 0) {
46759 - fscache_stat(&fscache_n_retrievals_intr);
46760 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46761 _leave(" = -ERESTARTSYS");
46762 return -ERESTARTSYS;
46763 }
46764 @@ -299,8 +299,8 @@ static int fscache_wait_for_deferred_loo
46765 */
46766 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46767 struct fscache_retrieval *op,
46768 - atomic_t *stat_op_waits,
46769 - atomic_t *stat_object_dead)
46770 + atomic_unchecked_t *stat_op_waits,
46771 + atomic_unchecked_t *stat_object_dead)
46772 {
46773 int ret;
46774
46775 @@ -308,7 +308,7 @@ static int fscache_wait_for_retrieval_ac
46776 goto check_if_dead;
46777
46778 _debug(">>> WT");
46779 - fscache_stat(stat_op_waits);
46780 + fscache_stat_unchecked(stat_op_waits);
46781 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
46782 fscache_wait_bit_interruptible,
46783 TASK_INTERRUPTIBLE) < 0) {
46784 @@ -325,7 +325,7 @@ static int fscache_wait_for_retrieval_ac
46785
46786 check_if_dead:
46787 if (unlikely(fscache_object_is_dead(object))) {
46788 - fscache_stat(stat_object_dead);
46789 + fscache_stat_unchecked(stat_object_dead);
46790 return -ENOBUFS;
46791 }
46792 return 0;
46793 @@ -352,7 +352,7 @@ int __fscache_read_or_alloc_page(struct
46794
46795 _enter("%p,%p,,,", cookie, page);
46796
46797 - fscache_stat(&fscache_n_retrievals);
46798 + fscache_stat_unchecked(&fscache_n_retrievals);
46799
46800 if (hlist_empty(&cookie->backing_objects))
46801 goto nobufs;
46802 @@ -386,7 +386,7 @@ int __fscache_read_or_alloc_page(struct
46803 goto nobufs_unlock;
46804 spin_unlock(&cookie->lock);
46805
46806 - fscache_stat(&fscache_n_retrieval_ops);
46807 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
46808
46809 /* pin the netfs read context in case we need to do the actual netfs
46810 * read because we've encountered a cache read failure */
46811 @@ -416,15 +416,15 @@ int __fscache_read_or_alloc_page(struct
46812
46813 error:
46814 if (ret == -ENOMEM)
46815 - fscache_stat(&fscache_n_retrievals_nomem);
46816 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46817 else if (ret == -ERESTARTSYS)
46818 - fscache_stat(&fscache_n_retrievals_intr);
46819 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46820 else if (ret == -ENODATA)
46821 - fscache_stat(&fscache_n_retrievals_nodata);
46822 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46823 else if (ret < 0)
46824 - fscache_stat(&fscache_n_retrievals_nobufs);
46825 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46826 else
46827 - fscache_stat(&fscache_n_retrievals_ok);
46828 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
46829
46830 fscache_put_retrieval(op);
46831 _leave(" = %d", ret);
46832 @@ -434,7 +434,7 @@ nobufs_unlock:
46833 spin_unlock(&cookie->lock);
46834 kfree(op);
46835 nobufs:
46836 - fscache_stat(&fscache_n_retrievals_nobufs);
46837 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46838 _leave(" = -ENOBUFS");
46839 return -ENOBUFS;
46840 }
46841 @@ -472,7 +472,7 @@ int __fscache_read_or_alloc_pages(struct
46842
46843 _enter("%p,,%d,,,", cookie, *nr_pages);
46844
46845 - fscache_stat(&fscache_n_retrievals);
46846 + fscache_stat_unchecked(&fscache_n_retrievals);
46847
46848 if (hlist_empty(&cookie->backing_objects))
46849 goto nobufs;
46850 @@ -503,7 +503,7 @@ int __fscache_read_or_alloc_pages(struct
46851 goto nobufs_unlock;
46852 spin_unlock(&cookie->lock);
46853
46854 - fscache_stat(&fscache_n_retrieval_ops);
46855 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
46856
46857 /* pin the netfs read context in case we need to do the actual netfs
46858 * read because we've encountered a cache read failure */
46859 @@ -533,15 +533,15 @@ int __fscache_read_or_alloc_pages(struct
46860
46861 error:
46862 if (ret == -ENOMEM)
46863 - fscache_stat(&fscache_n_retrievals_nomem);
46864 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46865 else if (ret == -ERESTARTSYS)
46866 - fscache_stat(&fscache_n_retrievals_intr);
46867 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46868 else if (ret == -ENODATA)
46869 - fscache_stat(&fscache_n_retrievals_nodata);
46870 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46871 else if (ret < 0)
46872 - fscache_stat(&fscache_n_retrievals_nobufs);
46873 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46874 else
46875 - fscache_stat(&fscache_n_retrievals_ok);
46876 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
46877
46878 fscache_put_retrieval(op);
46879 _leave(" = %d", ret);
46880 @@ -551,7 +551,7 @@ nobufs_unlock:
46881 spin_unlock(&cookie->lock);
46882 kfree(op);
46883 nobufs:
46884 - fscache_stat(&fscache_n_retrievals_nobufs);
46885 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46886 _leave(" = -ENOBUFS");
46887 return -ENOBUFS;
46888 }
46889 @@ -575,7 +575,7 @@ int __fscache_alloc_page(struct fscache_
46890
46891 _enter("%p,%p,,,", cookie, page);
46892
46893 - fscache_stat(&fscache_n_allocs);
46894 + fscache_stat_unchecked(&fscache_n_allocs);
46895
46896 if (hlist_empty(&cookie->backing_objects))
46897 goto nobufs;
46898 @@ -602,7 +602,7 @@ int __fscache_alloc_page(struct fscache_
46899 goto nobufs_unlock;
46900 spin_unlock(&cookie->lock);
46901
46902 - fscache_stat(&fscache_n_alloc_ops);
46903 + fscache_stat_unchecked(&fscache_n_alloc_ops);
46904
46905 ret = fscache_wait_for_retrieval_activation(
46906 object, op,
46907 @@ -618,11 +618,11 @@ int __fscache_alloc_page(struct fscache_
46908
46909 error:
46910 if (ret == -ERESTARTSYS)
46911 - fscache_stat(&fscache_n_allocs_intr);
46912 + fscache_stat_unchecked(&fscache_n_allocs_intr);
46913 else if (ret < 0)
46914 - fscache_stat(&fscache_n_allocs_nobufs);
46915 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46916 else
46917 - fscache_stat(&fscache_n_allocs_ok);
46918 + fscache_stat_unchecked(&fscache_n_allocs_ok);
46919
46920 fscache_put_retrieval(op);
46921 _leave(" = %d", ret);
46922 @@ -632,7 +632,7 @@ nobufs_unlock:
46923 spin_unlock(&cookie->lock);
46924 kfree(op);
46925 nobufs:
46926 - fscache_stat(&fscache_n_allocs_nobufs);
46927 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46928 _leave(" = -ENOBUFS");
46929 return -ENOBUFS;
46930 }
46931 @@ -675,7 +675,7 @@ static void fscache_write_op(struct fsca
46932
46933 spin_lock(&cookie->stores_lock);
46934
46935 - fscache_stat(&fscache_n_store_calls);
46936 + fscache_stat_unchecked(&fscache_n_store_calls);
46937
46938 /* find a page to store */
46939 page = NULL;
46940 @@ -686,7 +686,7 @@ static void fscache_write_op(struct fsca
46941 page = results[0];
46942 _debug("gang %d [%lx]", n, page->index);
46943 if (page->index > op->store_limit) {
46944 - fscache_stat(&fscache_n_store_pages_over_limit);
46945 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
46946 goto superseded;
46947 }
46948
46949 @@ -699,7 +699,7 @@ static void fscache_write_op(struct fsca
46950 spin_unlock(&object->lock);
46951
46952 fscache_set_op_state(&op->op, "Store");
46953 - fscache_stat(&fscache_n_store_pages);
46954 + fscache_stat_unchecked(&fscache_n_store_pages);
46955 fscache_stat(&fscache_n_cop_write_page);
46956 ret = object->cache->ops->write_page(op, page);
46957 fscache_stat_d(&fscache_n_cop_write_page);
46958 @@ -769,7 +769,7 @@ int __fscache_write_page(struct fscache_
46959 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46960 ASSERT(PageFsCache(page));
46961
46962 - fscache_stat(&fscache_n_stores);
46963 + fscache_stat_unchecked(&fscache_n_stores);
46964
46965 op = kzalloc(sizeof(*op), GFP_NOIO);
46966 if (!op)
46967 @@ -821,7 +821,7 @@ int __fscache_write_page(struct fscache_
46968 spin_unlock(&cookie->stores_lock);
46969 spin_unlock(&object->lock);
46970
46971 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
46972 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
46973 op->store_limit = object->store_limit;
46974
46975 if (fscache_submit_op(object, &op->op) < 0)
46976 @@ -829,8 +829,8 @@ int __fscache_write_page(struct fscache_
46977
46978 spin_unlock(&cookie->lock);
46979 radix_tree_preload_end();
46980 - fscache_stat(&fscache_n_store_ops);
46981 - fscache_stat(&fscache_n_stores_ok);
46982 + fscache_stat_unchecked(&fscache_n_store_ops);
46983 + fscache_stat_unchecked(&fscache_n_stores_ok);
46984
46985 /* the work queue now carries its own ref on the object */
46986 fscache_put_operation(&op->op);
46987 @@ -838,14 +838,14 @@ int __fscache_write_page(struct fscache_
46988 return 0;
46989
46990 already_queued:
46991 - fscache_stat(&fscache_n_stores_again);
46992 + fscache_stat_unchecked(&fscache_n_stores_again);
46993 already_pending:
46994 spin_unlock(&cookie->stores_lock);
46995 spin_unlock(&object->lock);
46996 spin_unlock(&cookie->lock);
46997 radix_tree_preload_end();
46998 kfree(op);
46999 - fscache_stat(&fscache_n_stores_ok);
47000 + fscache_stat_unchecked(&fscache_n_stores_ok);
47001 _leave(" = 0");
47002 return 0;
47003
47004 @@ -864,14 +864,14 @@ nobufs:
47005 spin_unlock(&cookie->lock);
47006 radix_tree_preload_end();
47007 kfree(op);
47008 - fscache_stat(&fscache_n_stores_nobufs);
47009 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
47010 _leave(" = -ENOBUFS");
47011 return -ENOBUFS;
47012
47013 nomem_free:
47014 kfree(op);
47015 nomem:
47016 - fscache_stat(&fscache_n_stores_oom);
47017 + fscache_stat_unchecked(&fscache_n_stores_oom);
47018 _leave(" = -ENOMEM");
47019 return -ENOMEM;
47020 }
47021 @@ -889,7 +889,7 @@ void __fscache_uncache_page(struct fscac
47022 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
47023 ASSERTCMP(page, !=, NULL);
47024
47025 - fscache_stat(&fscache_n_uncaches);
47026 + fscache_stat_unchecked(&fscache_n_uncaches);
47027
47028 /* cache withdrawal may beat us to it */
47029 if (!PageFsCache(page))
47030 @@ -942,7 +942,7 @@ void fscache_mark_pages_cached(struct fs
47031 unsigned long loop;
47032
47033 #ifdef CONFIG_FSCACHE_STATS
47034 - atomic_add(pagevec->nr, &fscache_n_marks);
47035 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
47036 #endif
47037
47038 for (loop = 0; loop < pagevec->nr; loop++) {
47039 diff -urNp linux-2.6.39/fs/fscache/stats.c linux-2.6.39/fs/fscache/stats.c
47040 --- linux-2.6.39/fs/fscache/stats.c 2011-05-19 00:06:34.000000000 -0400
47041 +++ linux-2.6.39/fs/fscache/stats.c 2011-05-22 19:36:32.000000000 -0400
47042 @@ -18,95 +18,95 @@
47043 /*
47044 * operation counters
47045 */
47046 -atomic_t fscache_n_op_pend;
47047 -atomic_t fscache_n_op_run;
47048 -atomic_t fscache_n_op_enqueue;
47049 -atomic_t fscache_n_op_requeue;
47050 -atomic_t fscache_n_op_deferred_release;
47051 -atomic_t fscache_n_op_release;
47052 -atomic_t fscache_n_op_gc;
47053 -atomic_t fscache_n_op_cancelled;
47054 -atomic_t fscache_n_op_rejected;
47055 -
47056 -atomic_t fscache_n_attr_changed;
47057 -atomic_t fscache_n_attr_changed_ok;
47058 -atomic_t fscache_n_attr_changed_nobufs;
47059 -atomic_t fscache_n_attr_changed_nomem;
47060 -atomic_t fscache_n_attr_changed_calls;
47061 -
47062 -atomic_t fscache_n_allocs;
47063 -atomic_t fscache_n_allocs_ok;
47064 -atomic_t fscache_n_allocs_wait;
47065 -atomic_t fscache_n_allocs_nobufs;
47066 -atomic_t fscache_n_allocs_intr;
47067 -atomic_t fscache_n_allocs_object_dead;
47068 -atomic_t fscache_n_alloc_ops;
47069 -atomic_t fscache_n_alloc_op_waits;
47070 -
47071 -atomic_t fscache_n_retrievals;
47072 -atomic_t fscache_n_retrievals_ok;
47073 -atomic_t fscache_n_retrievals_wait;
47074 -atomic_t fscache_n_retrievals_nodata;
47075 -atomic_t fscache_n_retrievals_nobufs;
47076 -atomic_t fscache_n_retrievals_intr;
47077 -atomic_t fscache_n_retrievals_nomem;
47078 -atomic_t fscache_n_retrievals_object_dead;
47079 -atomic_t fscache_n_retrieval_ops;
47080 -atomic_t fscache_n_retrieval_op_waits;
47081 -
47082 -atomic_t fscache_n_stores;
47083 -atomic_t fscache_n_stores_ok;
47084 -atomic_t fscache_n_stores_again;
47085 -atomic_t fscache_n_stores_nobufs;
47086 -atomic_t fscache_n_stores_oom;
47087 -atomic_t fscache_n_store_ops;
47088 -atomic_t fscache_n_store_calls;
47089 -atomic_t fscache_n_store_pages;
47090 -atomic_t fscache_n_store_radix_deletes;
47091 -atomic_t fscache_n_store_pages_over_limit;
47092 -
47093 -atomic_t fscache_n_store_vmscan_not_storing;
47094 -atomic_t fscache_n_store_vmscan_gone;
47095 -atomic_t fscache_n_store_vmscan_busy;
47096 -atomic_t fscache_n_store_vmscan_cancelled;
47097 -
47098 -atomic_t fscache_n_marks;
47099 -atomic_t fscache_n_uncaches;
47100 -
47101 -atomic_t fscache_n_acquires;
47102 -atomic_t fscache_n_acquires_null;
47103 -atomic_t fscache_n_acquires_no_cache;
47104 -atomic_t fscache_n_acquires_ok;
47105 -atomic_t fscache_n_acquires_nobufs;
47106 -atomic_t fscache_n_acquires_oom;
47107 -
47108 -atomic_t fscache_n_updates;
47109 -atomic_t fscache_n_updates_null;
47110 -atomic_t fscache_n_updates_run;
47111 -
47112 -atomic_t fscache_n_relinquishes;
47113 -atomic_t fscache_n_relinquishes_null;
47114 -atomic_t fscache_n_relinquishes_waitcrt;
47115 -atomic_t fscache_n_relinquishes_retire;
47116 -
47117 -atomic_t fscache_n_cookie_index;
47118 -atomic_t fscache_n_cookie_data;
47119 -atomic_t fscache_n_cookie_special;
47120 -
47121 -atomic_t fscache_n_object_alloc;
47122 -atomic_t fscache_n_object_no_alloc;
47123 -atomic_t fscache_n_object_lookups;
47124 -atomic_t fscache_n_object_lookups_negative;
47125 -atomic_t fscache_n_object_lookups_positive;
47126 -atomic_t fscache_n_object_lookups_timed_out;
47127 -atomic_t fscache_n_object_created;
47128 -atomic_t fscache_n_object_avail;
47129 -atomic_t fscache_n_object_dead;
47130 -
47131 -atomic_t fscache_n_checkaux_none;
47132 -atomic_t fscache_n_checkaux_okay;
47133 -atomic_t fscache_n_checkaux_update;
47134 -atomic_t fscache_n_checkaux_obsolete;
47135 +atomic_unchecked_t fscache_n_op_pend;
47136 +atomic_unchecked_t fscache_n_op_run;
47137 +atomic_unchecked_t fscache_n_op_enqueue;
47138 +atomic_unchecked_t fscache_n_op_requeue;
47139 +atomic_unchecked_t fscache_n_op_deferred_release;
47140 +atomic_unchecked_t fscache_n_op_release;
47141 +atomic_unchecked_t fscache_n_op_gc;
47142 +atomic_unchecked_t fscache_n_op_cancelled;
47143 +atomic_unchecked_t fscache_n_op_rejected;
47144 +
47145 +atomic_unchecked_t fscache_n_attr_changed;
47146 +atomic_unchecked_t fscache_n_attr_changed_ok;
47147 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
47148 +atomic_unchecked_t fscache_n_attr_changed_nomem;
47149 +atomic_unchecked_t fscache_n_attr_changed_calls;
47150 +
47151 +atomic_unchecked_t fscache_n_allocs;
47152 +atomic_unchecked_t fscache_n_allocs_ok;
47153 +atomic_unchecked_t fscache_n_allocs_wait;
47154 +atomic_unchecked_t fscache_n_allocs_nobufs;
47155 +atomic_unchecked_t fscache_n_allocs_intr;
47156 +atomic_unchecked_t fscache_n_allocs_object_dead;
47157 +atomic_unchecked_t fscache_n_alloc_ops;
47158 +atomic_unchecked_t fscache_n_alloc_op_waits;
47159 +
47160 +atomic_unchecked_t fscache_n_retrievals;
47161 +atomic_unchecked_t fscache_n_retrievals_ok;
47162 +atomic_unchecked_t fscache_n_retrievals_wait;
47163 +atomic_unchecked_t fscache_n_retrievals_nodata;
47164 +atomic_unchecked_t fscache_n_retrievals_nobufs;
47165 +atomic_unchecked_t fscache_n_retrievals_intr;
47166 +atomic_unchecked_t fscache_n_retrievals_nomem;
47167 +atomic_unchecked_t fscache_n_retrievals_object_dead;
47168 +atomic_unchecked_t fscache_n_retrieval_ops;
47169 +atomic_unchecked_t fscache_n_retrieval_op_waits;
47170 +
47171 +atomic_unchecked_t fscache_n_stores;
47172 +atomic_unchecked_t fscache_n_stores_ok;
47173 +atomic_unchecked_t fscache_n_stores_again;
47174 +atomic_unchecked_t fscache_n_stores_nobufs;
47175 +atomic_unchecked_t fscache_n_stores_oom;
47176 +atomic_unchecked_t fscache_n_store_ops;
47177 +atomic_unchecked_t fscache_n_store_calls;
47178 +atomic_unchecked_t fscache_n_store_pages;
47179 +atomic_unchecked_t fscache_n_store_radix_deletes;
47180 +atomic_unchecked_t fscache_n_store_pages_over_limit;
47181 +
47182 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
47183 +atomic_unchecked_t fscache_n_store_vmscan_gone;
47184 +atomic_unchecked_t fscache_n_store_vmscan_busy;
47185 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
47186 +
47187 +atomic_unchecked_t fscache_n_marks;
47188 +atomic_unchecked_t fscache_n_uncaches;
47189 +
47190 +atomic_unchecked_t fscache_n_acquires;
47191 +atomic_unchecked_t fscache_n_acquires_null;
47192 +atomic_unchecked_t fscache_n_acquires_no_cache;
47193 +atomic_unchecked_t fscache_n_acquires_ok;
47194 +atomic_unchecked_t fscache_n_acquires_nobufs;
47195 +atomic_unchecked_t fscache_n_acquires_oom;
47196 +
47197 +atomic_unchecked_t fscache_n_updates;
47198 +atomic_unchecked_t fscache_n_updates_null;
47199 +atomic_unchecked_t fscache_n_updates_run;
47200 +
47201 +atomic_unchecked_t fscache_n_relinquishes;
47202 +atomic_unchecked_t fscache_n_relinquishes_null;
47203 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
47204 +atomic_unchecked_t fscache_n_relinquishes_retire;
47205 +
47206 +atomic_unchecked_t fscache_n_cookie_index;
47207 +atomic_unchecked_t fscache_n_cookie_data;
47208 +atomic_unchecked_t fscache_n_cookie_special;
47209 +
47210 +atomic_unchecked_t fscache_n_object_alloc;
47211 +atomic_unchecked_t fscache_n_object_no_alloc;
47212 +atomic_unchecked_t fscache_n_object_lookups;
47213 +atomic_unchecked_t fscache_n_object_lookups_negative;
47214 +atomic_unchecked_t fscache_n_object_lookups_positive;
47215 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
47216 +atomic_unchecked_t fscache_n_object_created;
47217 +atomic_unchecked_t fscache_n_object_avail;
47218 +atomic_unchecked_t fscache_n_object_dead;
47219 +
47220 +atomic_unchecked_t fscache_n_checkaux_none;
47221 +atomic_unchecked_t fscache_n_checkaux_okay;
47222 +atomic_unchecked_t fscache_n_checkaux_update;
47223 +atomic_unchecked_t fscache_n_checkaux_obsolete;
47224
47225 atomic_t fscache_n_cop_alloc_object;
47226 atomic_t fscache_n_cop_lookup_object;
47227 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq
47228 seq_puts(m, "FS-Cache statistics\n");
47229
47230 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
47231 - atomic_read(&fscache_n_cookie_index),
47232 - atomic_read(&fscache_n_cookie_data),
47233 - atomic_read(&fscache_n_cookie_special));
47234 + atomic_read_unchecked(&fscache_n_cookie_index),
47235 + atomic_read_unchecked(&fscache_n_cookie_data),
47236 + atomic_read_unchecked(&fscache_n_cookie_special));
47237
47238 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
47239 - atomic_read(&fscache_n_object_alloc),
47240 - atomic_read(&fscache_n_object_no_alloc),
47241 - atomic_read(&fscache_n_object_avail),
47242 - atomic_read(&fscache_n_object_dead));
47243 + atomic_read_unchecked(&fscache_n_object_alloc),
47244 + atomic_read_unchecked(&fscache_n_object_no_alloc),
47245 + atomic_read_unchecked(&fscache_n_object_avail),
47246 + atomic_read_unchecked(&fscache_n_object_dead));
47247 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
47248 - atomic_read(&fscache_n_checkaux_none),
47249 - atomic_read(&fscache_n_checkaux_okay),
47250 - atomic_read(&fscache_n_checkaux_update),
47251 - atomic_read(&fscache_n_checkaux_obsolete));
47252 + atomic_read_unchecked(&fscache_n_checkaux_none),
47253 + atomic_read_unchecked(&fscache_n_checkaux_okay),
47254 + atomic_read_unchecked(&fscache_n_checkaux_update),
47255 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
47256
47257 seq_printf(m, "Pages : mrk=%u unc=%u\n",
47258 - atomic_read(&fscache_n_marks),
47259 - atomic_read(&fscache_n_uncaches));
47260 + atomic_read_unchecked(&fscache_n_marks),
47261 + atomic_read_unchecked(&fscache_n_uncaches));
47262
47263 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
47264 " oom=%u\n",
47265 - atomic_read(&fscache_n_acquires),
47266 - atomic_read(&fscache_n_acquires_null),
47267 - atomic_read(&fscache_n_acquires_no_cache),
47268 - atomic_read(&fscache_n_acquires_ok),
47269 - atomic_read(&fscache_n_acquires_nobufs),
47270 - atomic_read(&fscache_n_acquires_oom));
47271 + atomic_read_unchecked(&fscache_n_acquires),
47272 + atomic_read_unchecked(&fscache_n_acquires_null),
47273 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
47274 + atomic_read_unchecked(&fscache_n_acquires_ok),
47275 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
47276 + atomic_read_unchecked(&fscache_n_acquires_oom));
47277
47278 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
47279 - atomic_read(&fscache_n_object_lookups),
47280 - atomic_read(&fscache_n_object_lookups_negative),
47281 - atomic_read(&fscache_n_object_lookups_positive),
47282 - atomic_read(&fscache_n_object_created),
47283 - atomic_read(&fscache_n_object_lookups_timed_out));
47284 + atomic_read_unchecked(&fscache_n_object_lookups),
47285 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
47286 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
47287 + atomic_read_unchecked(&fscache_n_object_created),
47288 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
47289
47290 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
47291 - atomic_read(&fscache_n_updates),
47292 - atomic_read(&fscache_n_updates_null),
47293 - atomic_read(&fscache_n_updates_run));
47294 + atomic_read_unchecked(&fscache_n_updates),
47295 + atomic_read_unchecked(&fscache_n_updates_null),
47296 + atomic_read_unchecked(&fscache_n_updates_run));
47297
47298 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
47299 - atomic_read(&fscache_n_relinquishes),
47300 - atomic_read(&fscache_n_relinquishes_null),
47301 - atomic_read(&fscache_n_relinquishes_waitcrt),
47302 - atomic_read(&fscache_n_relinquishes_retire));
47303 + atomic_read_unchecked(&fscache_n_relinquishes),
47304 + atomic_read_unchecked(&fscache_n_relinquishes_null),
47305 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
47306 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
47307
47308 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
47309 - atomic_read(&fscache_n_attr_changed),
47310 - atomic_read(&fscache_n_attr_changed_ok),
47311 - atomic_read(&fscache_n_attr_changed_nobufs),
47312 - atomic_read(&fscache_n_attr_changed_nomem),
47313 - atomic_read(&fscache_n_attr_changed_calls));
47314 + atomic_read_unchecked(&fscache_n_attr_changed),
47315 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
47316 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
47317 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
47318 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
47319
47320 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
47321 - atomic_read(&fscache_n_allocs),
47322 - atomic_read(&fscache_n_allocs_ok),
47323 - atomic_read(&fscache_n_allocs_wait),
47324 - atomic_read(&fscache_n_allocs_nobufs),
47325 - atomic_read(&fscache_n_allocs_intr));
47326 + atomic_read_unchecked(&fscache_n_allocs),
47327 + atomic_read_unchecked(&fscache_n_allocs_ok),
47328 + atomic_read_unchecked(&fscache_n_allocs_wait),
47329 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
47330 + atomic_read_unchecked(&fscache_n_allocs_intr));
47331 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
47332 - atomic_read(&fscache_n_alloc_ops),
47333 - atomic_read(&fscache_n_alloc_op_waits),
47334 - atomic_read(&fscache_n_allocs_object_dead));
47335 + atomic_read_unchecked(&fscache_n_alloc_ops),
47336 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
47337 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
47338
47339 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
47340 " int=%u oom=%u\n",
47341 - atomic_read(&fscache_n_retrievals),
47342 - atomic_read(&fscache_n_retrievals_ok),
47343 - atomic_read(&fscache_n_retrievals_wait),
47344 - atomic_read(&fscache_n_retrievals_nodata),
47345 - atomic_read(&fscache_n_retrievals_nobufs),
47346 - atomic_read(&fscache_n_retrievals_intr),
47347 - atomic_read(&fscache_n_retrievals_nomem));
47348 + atomic_read_unchecked(&fscache_n_retrievals),
47349 + atomic_read_unchecked(&fscache_n_retrievals_ok),
47350 + atomic_read_unchecked(&fscache_n_retrievals_wait),
47351 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
47352 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
47353 + atomic_read_unchecked(&fscache_n_retrievals_intr),
47354 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
47355 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
47356 - atomic_read(&fscache_n_retrieval_ops),
47357 - atomic_read(&fscache_n_retrieval_op_waits),
47358 - atomic_read(&fscache_n_retrievals_object_dead));
47359 + atomic_read_unchecked(&fscache_n_retrieval_ops),
47360 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
47361 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
47362
47363 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
47364 - atomic_read(&fscache_n_stores),
47365 - atomic_read(&fscache_n_stores_ok),
47366 - atomic_read(&fscache_n_stores_again),
47367 - atomic_read(&fscache_n_stores_nobufs),
47368 - atomic_read(&fscache_n_stores_oom));
47369 + atomic_read_unchecked(&fscache_n_stores),
47370 + atomic_read_unchecked(&fscache_n_stores_ok),
47371 + atomic_read_unchecked(&fscache_n_stores_again),
47372 + atomic_read_unchecked(&fscache_n_stores_nobufs),
47373 + atomic_read_unchecked(&fscache_n_stores_oom));
47374 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
47375 - atomic_read(&fscache_n_store_ops),
47376 - atomic_read(&fscache_n_store_calls),
47377 - atomic_read(&fscache_n_store_pages),
47378 - atomic_read(&fscache_n_store_radix_deletes),
47379 - atomic_read(&fscache_n_store_pages_over_limit));
47380 + atomic_read_unchecked(&fscache_n_store_ops),
47381 + atomic_read_unchecked(&fscache_n_store_calls),
47382 + atomic_read_unchecked(&fscache_n_store_pages),
47383 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
47384 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
47385
47386 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
47387 - atomic_read(&fscache_n_store_vmscan_not_storing),
47388 - atomic_read(&fscache_n_store_vmscan_gone),
47389 - atomic_read(&fscache_n_store_vmscan_busy),
47390 - atomic_read(&fscache_n_store_vmscan_cancelled));
47391 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
47392 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
47393 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
47394 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
47395
47396 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
47397 - atomic_read(&fscache_n_op_pend),
47398 - atomic_read(&fscache_n_op_run),
47399 - atomic_read(&fscache_n_op_enqueue),
47400 - atomic_read(&fscache_n_op_cancelled),
47401 - atomic_read(&fscache_n_op_rejected));
47402 + atomic_read_unchecked(&fscache_n_op_pend),
47403 + atomic_read_unchecked(&fscache_n_op_run),
47404 + atomic_read_unchecked(&fscache_n_op_enqueue),
47405 + atomic_read_unchecked(&fscache_n_op_cancelled),
47406 + atomic_read_unchecked(&fscache_n_op_rejected));
47407 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
47408 - atomic_read(&fscache_n_op_deferred_release),
47409 - atomic_read(&fscache_n_op_release),
47410 - atomic_read(&fscache_n_op_gc));
47411 + atomic_read_unchecked(&fscache_n_op_deferred_release),
47412 + atomic_read_unchecked(&fscache_n_op_release),
47413 + atomic_read_unchecked(&fscache_n_op_gc));
47414
47415 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
47416 atomic_read(&fscache_n_cop_alloc_object),
47417 diff -urNp linux-2.6.39/fs/fs_struct.c linux-2.6.39/fs/fs_struct.c
47418 --- linux-2.6.39/fs/fs_struct.c 2011-05-19 00:06:34.000000000 -0400
47419 +++ linux-2.6.39/fs/fs_struct.c 2011-05-22 19:41:37.000000000 -0400
47420 @@ -4,6 +4,7 @@
47421 #include <linux/path.h>
47422 #include <linux/slab.h>
47423 #include <linux/fs_struct.h>
47424 +#include <linux/grsecurity.h>
47425 #include "internal.h"
47426
47427 static inline void path_get_longterm(struct path *path)
47428 @@ -31,6 +32,7 @@ void set_fs_root(struct fs_struct *fs, s
47429 old_root = fs->root;
47430 fs->root = *path;
47431 path_get_longterm(path);
47432 + gr_set_chroot_entries(current, path);
47433 write_seqcount_end(&fs->seq);
47434 spin_unlock(&fs->lock);
47435 if (old_root.dentry)
47436 @@ -74,6 +76,7 @@ void chroot_fs_refs(struct path *old_roo
47437 && fs->root.mnt == old_root->mnt) {
47438 path_get_longterm(new_root);
47439 fs->root = *new_root;
47440 + gr_set_chroot_entries(p, new_root);
47441 count++;
47442 }
47443 if (fs->pwd.dentry == old_root->dentry
47444 @@ -109,7 +112,8 @@ void exit_fs(struct task_struct *tsk)
47445 spin_lock(&fs->lock);
47446 write_seqcount_begin(&fs->seq);
47447 tsk->fs = NULL;
47448 - kill = !--fs->users;
47449 + gr_clear_chroot_entries(tsk);
47450 + kill = !atomic_dec_return(&fs->users);
47451 write_seqcount_end(&fs->seq);
47452 spin_unlock(&fs->lock);
47453 task_unlock(tsk);
47454 @@ -123,7 +127,7 @@ struct fs_struct *copy_fs_struct(struct
47455 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
47456 /* We don't need to lock fs - think why ;-) */
47457 if (fs) {
47458 - fs->users = 1;
47459 + atomic_set(&fs->users, 1);
47460 fs->in_exec = 0;
47461 spin_lock_init(&fs->lock);
47462 seqcount_init(&fs->seq);
47463 @@ -132,6 +136,9 @@ struct fs_struct *copy_fs_struct(struct
47464 spin_lock(&old->lock);
47465 fs->root = old->root;
47466 path_get_longterm(&fs->root);
47467 + /* instead of calling gr_set_chroot_entries here,
47468 + we call it from every caller of this function
47469 + */
47470 fs->pwd = old->pwd;
47471 path_get_longterm(&fs->pwd);
47472 spin_unlock(&old->lock);
47473 @@ -150,8 +157,9 @@ int unshare_fs_struct(void)
47474
47475 task_lock(current);
47476 spin_lock(&fs->lock);
47477 - kill = !--fs->users;
47478 + kill = !atomic_dec_return(&fs->users);
47479 current->fs = new_fs;
47480 + gr_set_chroot_entries(current, &new_fs->root);
47481 spin_unlock(&fs->lock);
47482 task_unlock(current);
47483
47484 @@ -170,7 +178,7 @@ EXPORT_SYMBOL(current_umask);
47485
47486 /* to be mentioned only in INIT_TASK */
47487 struct fs_struct init_fs = {
47488 - .users = 1,
47489 + .users = ATOMIC_INIT(1),
47490 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
47491 .seq = SEQCNT_ZERO,
47492 .umask = 0022,
47493 @@ -186,12 +194,13 @@ void daemonize_fs_struct(void)
47494 task_lock(current);
47495
47496 spin_lock(&init_fs.lock);
47497 - init_fs.users++;
47498 + atomic_inc(&init_fs.users);
47499 spin_unlock(&init_fs.lock);
47500
47501 spin_lock(&fs->lock);
47502 current->fs = &init_fs;
47503 - kill = !--fs->users;
47504 + gr_set_chroot_entries(current, &current->fs->root);
47505 + kill = !atomic_dec_return(&fs->users);
47506 spin_unlock(&fs->lock);
47507
47508 task_unlock(current);
47509 diff -urNp linux-2.6.39/fs/fuse/cuse.c linux-2.6.39/fs/fuse/cuse.c
47510 --- linux-2.6.39/fs/fuse/cuse.c 2011-05-19 00:06:34.000000000 -0400
47511 +++ linux-2.6.39/fs/fuse/cuse.c 2011-05-22 19:36:32.000000000 -0400
47512 @@ -538,8 +538,18 @@ static int cuse_channel_release(struct i
47513 return rc;
47514 }
47515
47516 -static struct file_operations cuse_channel_fops; /* initialized during init */
47517 -
47518 +static const struct file_operations cuse_channel_fops = { /* initialized during init */
47519 + .owner = THIS_MODULE,
47520 + .llseek = no_llseek,
47521 + .read = do_sync_read,
47522 + .aio_read = fuse_dev_read,
47523 + .write = do_sync_write,
47524 + .aio_write = fuse_dev_write,
47525 + .poll = fuse_dev_poll,
47526 + .open = cuse_channel_open,
47527 + .release = cuse_channel_release,
47528 + .fasync = fuse_dev_fasync,
47529 +};
47530
47531 /**************************************************************************
47532 * Misc stuff and module initializatiion
47533 @@ -585,12 +595,6 @@ static int __init cuse_init(void)
47534 for (i = 0; i < CUSE_CONNTBL_LEN; i++)
47535 INIT_LIST_HEAD(&cuse_conntbl[i]);
47536
47537 - /* inherit and extend fuse_dev_operations */
47538 - cuse_channel_fops = fuse_dev_operations;
47539 - cuse_channel_fops.owner = THIS_MODULE;
47540 - cuse_channel_fops.open = cuse_channel_open;
47541 - cuse_channel_fops.release = cuse_channel_release;
47542 -
47543 cuse_class = class_create(THIS_MODULE, "cuse");
47544 if (IS_ERR(cuse_class))
47545 return PTR_ERR(cuse_class);
47546 diff -urNp linux-2.6.39/fs/fuse/dev.c linux-2.6.39/fs/fuse/dev.c
47547 --- linux-2.6.39/fs/fuse/dev.c 2011-05-19 00:06:34.000000000 -0400
47548 +++ linux-2.6.39/fs/fuse/dev.c 2011-05-22 19:36:32.000000000 -0400
47549 @@ -1181,7 +1181,7 @@ static ssize_t fuse_dev_do_read(struct f
47550 return err;
47551 }
47552
47553 -static ssize_t fuse_dev_read(struct kiocb *iocb, const struct iovec *iov,
47554 +ssize_t fuse_dev_read(struct kiocb *iocb, const struct iovec *iov,
47555 unsigned long nr_segs, loff_t pos)
47556 {
47557 struct fuse_copy_state cs;
47558 @@ -1195,6 +1195,8 @@ static ssize_t fuse_dev_read(struct kioc
47559 return fuse_dev_do_read(fc, file, &cs, iov_length(iov, nr_segs));
47560 }
47561
47562 +EXPORT_SYMBOL_GPL(fuse_dev_read);
47563 +
47564 static int fuse_dev_pipe_buf_steal(struct pipe_inode_info *pipe,
47565 struct pipe_buffer *buf)
47566 {
47567 @@ -1238,7 +1240,7 @@ static ssize_t fuse_dev_splice_read(stru
47568 ret = 0;
47569 pipe_lock(pipe);
47570
47571 - if (!pipe->readers) {
47572 + if (!atomic_read(&pipe->readers)) {
47573 send_sig(SIGPIPE, current, 0);
47574 if (!ret)
47575 ret = -EPIPE;
47576 @@ -1731,7 +1733,7 @@ static ssize_t fuse_dev_do_write(struct
47577 return err;
47578 }
47579
47580 -static ssize_t fuse_dev_write(struct kiocb *iocb, const struct iovec *iov,
47581 +ssize_t fuse_dev_write(struct kiocb *iocb, const struct iovec *iov,
47582 unsigned long nr_segs, loff_t pos)
47583 {
47584 struct fuse_copy_state cs;
47585 @@ -1744,6 +1746,8 @@ static ssize_t fuse_dev_write(struct kio
47586 return fuse_dev_do_write(fc, &cs, iov_length(iov, nr_segs));
47587 }
47588
47589 +EXPORT_SYMBOL_GPL(fuse_dev_write);
47590 +
47591 static ssize_t fuse_dev_splice_write(struct pipe_inode_info *pipe,
47592 struct file *out, loff_t *ppos,
47593 size_t len, unsigned int flags)
47594 @@ -1822,7 +1826,7 @@ out:
47595 return ret;
47596 }
47597
47598 -static unsigned fuse_dev_poll(struct file *file, poll_table *wait)
47599 +unsigned fuse_dev_poll(struct file *file, poll_table *wait)
47600 {
47601 unsigned mask = POLLOUT | POLLWRNORM;
47602 struct fuse_conn *fc = fuse_get_conn(file);
47603 @@ -1841,6 +1845,8 @@ static unsigned fuse_dev_poll(struct fil
47604 return mask;
47605 }
47606
47607 +EXPORT_SYMBOL_GPL(fuse_dev_poll);
47608 +
47609 /*
47610 * Abort all requests on the given list (pending or processing)
47611 *
47612 @@ -1977,7 +1983,7 @@ int fuse_dev_release(struct inode *inode
47613 }
47614 EXPORT_SYMBOL_GPL(fuse_dev_release);
47615
47616 -static int fuse_dev_fasync(int fd, struct file *file, int on)
47617 +int fuse_dev_fasync(int fd, struct file *file, int on)
47618 {
47619 struct fuse_conn *fc = fuse_get_conn(file);
47620 if (!fc)
47621 @@ -1987,6 +1993,8 @@ static int fuse_dev_fasync(int fd, struc
47622 return fasync_helper(fd, file, on, &fc->fasync);
47623 }
47624
47625 +EXPORT_SYMBOL_GPL(fuse_dev_fasync);
47626 +
47627 const struct file_operations fuse_dev_operations = {
47628 .owner = THIS_MODULE,
47629 .llseek = no_llseek,
47630 diff -urNp linux-2.6.39/fs/fuse/dir.c linux-2.6.39/fs/fuse/dir.c
47631 --- linux-2.6.39/fs/fuse/dir.c 2011-05-19 00:06:34.000000000 -0400
47632 +++ linux-2.6.39/fs/fuse/dir.c 2011-05-22 19:36:32.000000000 -0400
47633 @@ -1147,7 +1147,7 @@ static char *read_link(struct dentry *de
47634 return link;
47635 }
47636
47637 -static void free_link(char *link)
47638 +static void free_link(const char *link)
47639 {
47640 if (!IS_ERR(link))
47641 free_page((unsigned long) link);
47642 diff -urNp linux-2.6.39/fs/fuse/fuse_i.h linux-2.6.39/fs/fuse/fuse_i.h
47643 --- linux-2.6.39/fs/fuse/fuse_i.h 2011-05-19 00:06:34.000000000 -0400
47644 +++ linux-2.6.39/fs/fuse/fuse_i.h 2011-05-22 19:36:32.000000000 -0400
47645 @@ -540,6 +540,16 @@ extern const struct file_operations fuse
47646
47647 extern const struct dentry_operations fuse_dentry_operations;
47648
47649 +extern ssize_t fuse_dev_read(struct kiocb *iocb, const struct iovec *iov,
47650 + unsigned long nr_segs, loff_t pos);
47651 +
47652 +extern ssize_t fuse_dev_write(struct kiocb *iocb, const struct iovec *iov,
47653 + unsigned long nr_segs, loff_t pos);
47654 +
47655 +extern unsigned fuse_dev_poll(struct file *file, poll_table *wait);
47656 +
47657 +extern int fuse_dev_fasync(int fd, struct file *file, int on);
47658 +
47659 /**
47660 * Inode to nodeid comparison.
47661 */
47662 diff -urNp linux-2.6.39/fs/gfs2/ops_inode.c linux-2.6.39/fs/gfs2/ops_inode.c
47663 --- linux-2.6.39/fs/gfs2/ops_inode.c 2011-05-19 00:06:34.000000000 -0400
47664 +++ linux-2.6.39/fs/gfs2/ops_inode.c 2011-05-22 19:36:32.000000000 -0400
47665 @@ -740,6 +740,8 @@ static int gfs2_rename(struct inode *odi
47666 unsigned int x;
47667 int error;
47668
47669 + pax_track_stack();
47670 +
47671 if (ndentry->d_inode) {
47672 nip = GFS2_I(ndentry->d_inode);
47673 if (ip == nip)
47674 @@ -1019,7 +1021,7 @@ out:
47675
47676 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
47677 {
47678 - char *s = nd_get_link(nd);
47679 + const char *s = nd_get_link(nd);
47680 if (!IS_ERR(s))
47681 kfree(s);
47682 }
47683 diff -urNp linux-2.6.39/fs/hfsplus/catalog.c linux-2.6.39/fs/hfsplus/catalog.c
47684 --- linux-2.6.39/fs/hfsplus/catalog.c 2011-05-19 00:06:34.000000000 -0400
47685 +++ linux-2.6.39/fs/hfsplus/catalog.c 2011-05-22 19:36:32.000000000 -0400
47686 @@ -179,6 +179,8 @@ int hfsplus_find_cat(struct super_block
47687 int err;
47688 u16 type;
47689
47690 + pax_track_stack();
47691 +
47692 hfsplus_cat_build_key(sb, fd->search_key, cnid, NULL);
47693 err = hfs_brec_read(fd, &tmp, sizeof(hfsplus_cat_entry));
47694 if (err)
47695 @@ -210,6 +212,8 @@ int hfsplus_create_cat(u32 cnid, struct
47696 int entry_size;
47697 int err;
47698
47699 + pax_track_stack();
47700 +
47701 dprint(DBG_CAT_MOD, "create_cat: %s,%u(%d)\n",
47702 str->name, cnid, inode->i_nlink);
47703 hfs_find_init(HFSPLUS_SB(sb)->cat_tree, &fd);
47704 @@ -349,6 +353,8 @@ int hfsplus_rename_cat(u32 cnid,
47705 int entry_size, type;
47706 int err = 0;
47707
47708 + pax_track_stack();
47709 +
47710 dprint(DBG_CAT_MOD, "rename_cat: %u - %lu,%s - %lu,%s\n",
47711 cnid, src_dir->i_ino, src_name->name,
47712 dst_dir->i_ino, dst_name->name);
47713 diff -urNp linux-2.6.39/fs/hfsplus/dir.c linux-2.6.39/fs/hfsplus/dir.c
47714 --- linux-2.6.39/fs/hfsplus/dir.c 2011-05-19 00:06:34.000000000 -0400
47715 +++ linux-2.6.39/fs/hfsplus/dir.c 2011-05-22 19:36:32.000000000 -0400
47716 @@ -129,6 +129,8 @@ static int hfsplus_readdir(struct file *
47717 struct hfsplus_readdir_data *rd;
47718 u16 type;
47719
47720 + pax_track_stack();
47721 +
47722 if (filp->f_pos >= inode->i_size)
47723 return 0;
47724
47725 diff -urNp linux-2.6.39/fs/hfsplus/inode.c linux-2.6.39/fs/hfsplus/inode.c
47726 --- linux-2.6.39/fs/hfsplus/inode.c 2011-05-19 00:06:34.000000000 -0400
47727 +++ linux-2.6.39/fs/hfsplus/inode.c 2011-05-22 19:36:32.000000000 -0400
47728 @@ -489,6 +489,8 @@ int hfsplus_cat_read_inode(struct inode
47729 int res = 0;
47730 u16 type;
47731
47732 + pax_track_stack();
47733 +
47734 type = hfs_bnode_read_u16(fd->bnode, fd->entryoffset);
47735
47736 HFSPLUS_I(inode)->linkid = 0;
47737 @@ -552,6 +554,8 @@ int hfsplus_cat_write_inode(struct inode
47738 struct hfs_find_data fd;
47739 hfsplus_cat_entry entry;
47740
47741 + pax_track_stack();
47742 +
47743 if (HFSPLUS_IS_RSRC(inode))
47744 main_inode = HFSPLUS_I(inode)->rsrc_inode;
47745
47746 diff -urNp linux-2.6.39/fs/hfsplus/ioctl.c linux-2.6.39/fs/hfsplus/ioctl.c
47747 --- linux-2.6.39/fs/hfsplus/ioctl.c 2011-05-19 00:06:34.000000000 -0400
47748 +++ linux-2.6.39/fs/hfsplus/ioctl.c 2011-05-22 19:36:32.000000000 -0400
47749 @@ -122,6 +122,8 @@ int hfsplus_setxattr(struct dentry *dent
47750 struct hfsplus_cat_file *file;
47751 int res;
47752
47753 + pax_track_stack();
47754 +
47755 if (!S_ISREG(inode->i_mode) || HFSPLUS_IS_RSRC(inode))
47756 return -EOPNOTSUPP;
47757
47758 @@ -166,6 +168,8 @@ ssize_t hfsplus_getxattr(struct dentry *
47759 struct hfsplus_cat_file *file;
47760 ssize_t res = 0;
47761
47762 + pax_track_stack();
47763 +
47764 if (!S_ISREG(inode->i_mode) || HFSPLUS_IS_RSRC(inode))
47765 return -EOPNOTSUPP;
47766
47767 diff -urNp linux-2.6.39/fs/hfsplus/super.c linux-2.6.39/fs/hfsplus/super.c
47768 --- linux-2.6.39/fs/hfsplus/super.c 2011-05-19 00:06:34.000000000 -0400
47769 +++ linux-2.6.39/fs/hfsplus/super.c 2011-05-22 19:36:32.000000000 -0400
47770 @@ -340,6 +340,8 @@ static int hfsplus_fill_super(struct sup
47771 struct nls_table *nls = NULL;
47772 int err;
47773
47774 + pax_track_stack();
47775 +
47776 err = -EINVAL;
47777 sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
47778 if (!sbi)
47779 diff -urNp linux-2.6.39/fs/hugetlbfs/inode.c linux-2.6.39/fs/hugetlbfs/inode.c
47780 --- linux-2.6.39/fs/hugetlbfs/inode.c 2011-05-19 00:06:34.000000000 -0400
47781 +++ linux-2.6.39/fs/hugetlbfs/inode.c 2011-05-22 19:41:37.000000000 -0400
47782 @@ -914,7 +914,7 @@ static struct file_system_type hugetlbfs
47783 .kill_sb = kill_litter_super,
47784 };
47785
47786 -static struct vfsmount *hugetlbfs_vfsmount;
47787 +struct vfsmount *hugetlbfs_vfsmount;
47788
47789 static int can_do_hugetlb_shm(void)
47790 {
47791 diff -urNp linux-2.6.39/fs/inode.c linux-2.6.39/fs/inode.c
47792 --- linux-2.6.39/fs/inode.c 2011-05-19 00:06:34.000000000 -0400
47793 +++ linux-2.6.39/fs/inode.c 2011-05-22 19:36:32.000000000 -0400
47794 @@ -862,8 +862,8 @@ unsigned int get_next_ino(void)
47795
47796 #ifdef CONFIG_SMP
47797 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
47798 - static atomic_t shared_last_ino;
47799 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
47800 + static atomic_unchecked_t shared_last_ino;
47801 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
47802
47803 res = next - LAST_INO_BATCH;
47804 }
47805 diff -urNp linux-2.6.39/fs/jbd/checkpoint.c linux-2.6.39/fs/jbd/checkpoint.c
47806 --- linux-2.6.39/fs/jbd/checkpoint.c 2011-05-19 00:06:34.000000000 -0400
47807 +++ linux-2.6.39/fs/jbd/checkpoint.c 2011-05-22 19:36:32.000000000 -0400
47808 @@ -350,6 +350,8 @@ int log_do_checkpoint(journal_t *journal
47809 tid_t this_tid;
47810 int result;
47811
47812 + pax_track_stack();
47813 +
47814 jbd_debug(1, "Start checkpoint\n");
47815
47816 /*
47817 diff -urNp linux-2.6.39/fs/jffs2/compr_rtime.c linux-2.6.39/fs/jffs2/compr_rtime.c
47818 --- linux-2.6.39/fs/jffs2/compr_rtime.c 2011-05-19 00:06:34.000000000 -0400
47819 +++ linux-2.6.39/fs/jffs2/compr_rtime.c 2011-05-22 19:36:32.000000000 -0400
47820 @@ -37,6 +37,8 @@ static int jffs2_rtime_compress(unsigned
47821 int outpos = 0;
47822 int pos=0;
47823
47824 + pax_track_stack();
47825 +
47826 memset(positions,0,sizeof(positions));
47827
47828 while (pos < (*sourcelen) && outpos <= (*dstlen)-2) {
47829 @@ -78,6 +80,8 @@ static int jffs2_rtime_decompress(unsign
47830 int outpos = 0;
47831 int pos=0;
47832
47833 + pax_track_stack();
47834 +
47835 memset(positions,0,sizeof(positions));
47836
47837 while (outpos<destlen) {
47838 diff -urNp linux-2.6.39/fs/jffs2/compr_rubin.c linux-2.6.39/fs/jffs2/compr_rubin.c
47839 --- linux-2.6.39/fs/jffs2/compr_rubin.c 2011-05-19 00:06:34.000000000 -0400
47840 +++ linux-2.6.39/fs/jffs2/compr_rubin.c 2011-05-22 19:36:32.000000000 -0400
47841 @@ -314,6 +314,8 @@ static int jffs2_dynrubin_compress(unsig
47842 int ret;
47843 uint32_t mysrclen, mydstlen;
47844
47845 + pax_track_stack();
47846 +
47847 mysrclen = *sourcelen;
47848 mydstlen = *dstlen - 8;
47849
47850 diff -urNp linux-2.6.39/fs/jffs2/erase.c linux-2.6.39/fs/jffs2/erase.c
47851 --- linux-2.6.39/fs/jffs2/erase.c 2011-05-19 00:06:34.000000000 -0400
47852 +++ linux-2.6.39/fs/jffs2/erase.c 2011-05-22 19:36:32.000000000 -0400
47853 @@ -439,7 +439,8 @@ static void jffs2_mark_erased_block(stru
47854 struct jffs2_unknown_node marker = {
47855 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
47856 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47857 - .totlen = cpu_to_je32(c->cleanmarker_size)
47858 + .totlen = cpu_to_je32(c->cleanmarker_size),
47859 + .hdr_crc = cpu_to_je32(0)
47860 };
47861
47862 jffs2_prealloc_raw_node_refs(c, jeb, 1);
47863 diff -urNp linux-2.6.39/fs/jffs2/wbuf.c linux-2.6.39/fs/jffs2/wbuf.c
47864 --- linux-2.6.39/fs/jffs2/wbuf.c 2011-05-19 00:06:34.000000000 -0400
47865 +++ linux-2.6.39/fs/jffs2/wbuf.c 2011-05-22 19:36:32.000000000 -0400
47866 @@ -1012,7 +1012,8 @@ static const struct jffs2_unknown_node o
47867 {
47868 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
47869 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47870 - .totlen = constant_cpu_to_je32(8)
47871 + .totlen = constant_cpu_to_je32(8),
47872 + .hdr_crc = constant_cpu_to_je32(0)
47873 };
47874
47875 /*
47876 diff -urNp linux-2.6.39/fs/jffs2/xattr.c linux-2.6.39/fs/jffs2/xattr.c
47877 --- linux-2.6.39/fs/jffs2/xattr.c 2011-05-19 00:06:34.000000000 -0400
47878 +++ linux-2.6.39/fs/jffs2/xattr.c 2011-05-22 19:36:32.000000000 -0400
47879 @@ -773,6 +773,8 @@ void jffs2_build_xattr_subsystem(struct
47880
47881 BUG_ON(!(c->flags & JFFS2_SB_FLAG_BUILDING));
47882
47883 + pax_track_stack();
47884 +
47885 /* Phase.1 : Merge same xref */
47886 for (i=0; i < XREF_TMPHASH_SIZE; i++)
47887 xref_tmphash[i] = NULL;
47888 diff -urNp linux-2.6.39/fs/Kconfig.binfmt linux-2.6.39/fs/Kconfig.binfmt
47889 --- linux-2.6.39/fs/Kconfig.binfmt 2011-05-19 00:06:34.000000000 -0400
47890 +++ linux-2.6.39/fs/Kconfig.binfmt 2011-05-22 19:36:32.000000000 -0400
47891 @@ -86,7 +86,7 @@ config HAVE_AOUT
47892
47893 config BINFMT_AOUT
47894 tristate "Kernel support for a.out and ECOFF binaries"
47895 - depends on HAVE_AOUT
47896 + depends on HAVE_AOUT && BROKEN
47897 ---help---
47898 A.out (Assembler.OUTput) is a set of formats for libraries and
47899 executables used in the earliest versions of UNIX. Linux used
47900 diff -urNp linux-2.6.39/fs/libfs.c linux-2.6.39/fs/libfs.c
47901 --- linux-2.6.39/fs/libfs.c 2011-05-19 00:06:34.000000000 -0400
47902 +++ linux-2.6.39/fs/libfs.c 2011-05-22 19:36:32.000000000 -0400
47903 @@ -163,6 +163,9 @@ int dcache_readdir(struct file * filp, v
47904
47905 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
47906 struct dentry *next;
47907 + char d_name[sizeof(next->d_iname)];
47908 + const unsigned char *name;
47909 +
47910 next = list_entry(p, struct dentry, d_u.d_child);
47911 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
47912 if (!simple_positive(next)) {
47913 @@ -172,7 +175,12 @@ int dcache_readdir(struct file * filp, v
47914
47915 spin_unlock(&next->d_lock);
47916 spin_unlock(&dentry->d_lock);
47917 - if (filldir(dirent, next->d_name.name,
47918 + name = next->d_name.name;
47919 + if (name == next->d_iname) {
47920 + memcpy(d_name, name, next->d_name.len);
47921 + name = d_name;
47922 + }
47923 + if (filldir(dirent, name,
47924 next->d_name.len, filp->f_pos,
47925 next->d_inode->i_ino,
47926 dt_type(next->d_inode)) < 0)
47927 diff -urNp linux-2.6.39/fs/lockd/clntproc.c linux-2.6.39/fs/lockd/clntproc.c
47928 --- linux-2.6.39/fs/lockd/clntproc.c 2011-05-19 00:06:34.000000000 -0400
47929 +++ linux-2.6.39/fs/lockd/clntproc.c 2011-05-22 19:36:32.000000000 -0400
47930 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt
47931 /*
47932 * Cookie counter for NLM requests
47933 */
47934 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
47935 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
47936
47937 void nlmclnt_next_cookie(struct nlm_cookie *c)
47938 {
47939 - u32 cookie = atomic_inc_return(&nlm_cookie);
47940 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
47941
47942 memcpy(c->data, &cookie, 4);
47943 c->len=4;
47944 @@ -620,6 +620,8 @@ nlmclnt_reclaim(struct nlm_host *host, s
47945 struct nlm_rqst reqst, *req;
47946 int status;
47947
47948 + pax_track_stack();
47949 +
47950 req = &reqst;
47951 memset(req, 0, sizeof(*req));
47952 locks_init_lock(&req->a_args.lock.fl);
47953 diff -urNp linux-2.6.39/fs/lockd/svc.c linux-2.6.39/fs/lockd/svc.c
47954 --- linux-2.6.39/fs/lockd/svc.c 2011-05-19 00:06:34.000000000 -0400
47955 +++ linux-2.6.39/fs/lockd/svc.c 2011-05-22 19:36:32.000000000 -0400
47956 @@ -41,7 +41,7 @@
47957
47958 static struct svc_program nlmsvc_program;
47959
47960 -struct nlmsvc_binding * nlmsvc_ops;
47961 +const struct nlmsvc_binding * nlmsvc_ops;
47962 EXPORT_SYMBOL_GPL(nlmsvc_ops);
47963
47964 static DEFINE_MUTEX(nlmsvc_mutex);
47965 diff -urNp linux-2.6.39/fs/locks.c linux-2.6.39/fs/locks.c
47966 --- linux-2.6.39/fs/locks.c 2011-05-19 00:06:34.000000000 -0400
47967 +++ linux-2.6.39/fs/locks.c 2011-05-22 19:36:32.000000000 -0400
47968 @@ -2033,16 +2033,16 @@ void locks_remove_flock(struct file *fil
47969 return;
47970
47971 if (filp->f_op && filp->f_op->flock) {
47972 - struct file_lock fl = {
47973 + struct file_lock flock = {
47974 .fl_pid = current->tgid,
47975 .fl_file = filp,
47976 .fl_flags = FL_FLOCK,
47977 .fl_type = F_UNLCK,
47978 .fl_end = OFFSET_MAX,
47979 };
47980 - filp->f_op->flock(filp, F_SETLKW, &fl);
47981 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
47982 - fl.fl_ops->fl_release_private(&fl);
47983 + filp->f_op->flock(filp, F_SETLKW, &flock);
47984 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
47985 + flock.fl_ops->fl_release_private(&flock);
47986 }
47987
47988 lock_flocks();
47989 diff -urNp linux-2.6.39/fs/logfs/super.c linux-2.6.39/fs/logfs/super.c
47990 --- linux-2.6.39/fs/logfs/super.c 2011-05-19 00:06:34.000000000 -0400
47991 +++ linux-2.6.39/fs/logfs/super.c 2011-05-22 19:36:32.000000000 -0400
47992 @@ -266,6 +266,8 @@ static int logfs_recover_sb(struct super
47993 struct logfs_disk_super _ds1, *ds1 = &_ds1;
47994 int err, valid0, valid1;
47995
47996 + pax_track_stack();
47997 +
47998 /* read first superblock */
47999 err = wbuf_read(sb, super->s_sb_ofs[0], sizeof(*ds0), ds0);
48000 if (err)
48001 diff -urNp linux-2.6.39/fs/namei.c linux-2.6.39/fs/namei.c
48002 --- linux-2.6.39/fs/namei.c 2011-05-19 00:06:34.000000000 -0400
48003 +++ linux-2.6.39/fs/namei.c 2011-05-23 18:21:41.000000000 -0400
48004 @@ -237,20 +237,30 @@ int generic_permission(struct inode *ino
48005 return ret;
48006
48007 /*
48008 - * Read/write DACs are always overridable.
48009 - * Executable DACs are overridable if at least one exec bit is set.
48010 + * Searching includes executable on directories, else just read.
48011 */
48012 - if (!(mask & MAY_EXEC) || execute_ok(inode))
48013 - if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
48014 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
48015 + if (mask == MAY_READ || (S_ISDIR(inode->i_mode) && !(mask & MAY_WRITE))) {
48016 +#ifdef CONFIG_GRKERNSEC
48017 + if (flags & IPERM_FLAG_RCU)
48018 + return -ECHILD;
48019 +#endif
48020 + if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
48021 return 0;
48022 + }
48023
48024 /*
48025 - * Searching includes executable on directories, else just read.
48026 + * Read/write DACs are always overridable.
48027 + * Executable DACs are overridable if at least one exec bit is set.
48028 */
48029 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
48030 - if (mask == MAY_READ || (S_ISDIR(inode->i_mode) && !(mask & MAY_WRITE)))
48031 - if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
48032 + if (!(mask & MAY_EXEC) || execute_ok(inode)) {
48033 +#ifdef CONFIG_GRKERNSEC
48034 + if (flags & IPERM_FLAG_RCU)
48035 + return -ECHILD;
48036 +#endif
48037 + if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
48038 return 0;
48039 + }
48040
48041 return -EACCES;
48042 }
48043 @@ -626,6 +636,9 @@ static inline int handle_reval_path(stru
48044 struct dentry *dentry = nd->path.dentry;
48045 int status;
48046
48047 + if (!(nd->flags & LOOKUP_PARENT) && !gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt))
48048 + return -ENOENT;
48049 +
48050 if (likely(!(nd->flags & LOOKUP_JUMPED)))
48051 return 0;
48052
48053 @@ -671,9 +684,16 @@ static inline int exec_permission(struct
48054 if (ret == -ECHILD)
48055 return ret;
48056
48057 - if (ns_capable(ns, CAP_DAC_OVERRIDE) ||
48058 - ns_capable(ns, CAP_DAC_READ_SEARCH))
48059 + if (ns_capable_nolog(ns, CAP_DAC_OVERRIDE))
48060 goto ok;
48061 + else {
48062 +#ifdef CONFIG_GRKERNSEC
48063 + if (flags & IPERM_FLAG_RCU)
48064 + return -ECHILD;
48065 +#endif
48066 + if (ns_capable(ns, CAP_DAC_READ_SEARCH) || ns_capable(ns, CAP_DAC_OVERRIDE))
48067 + goto ok;
48068 + }
48069
48070 return ret;
48071 ok:
48072 @@ -781,11 +801,19 @@ follow_link(struct path *link, struct na
48073 return error;
48074 }
48075
48076 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
48077 + dentry->d_inode, dentry, nd->path.mnt)) {
48078 + error = -EACCES;
48079 + *p = ERR_PTR(error); /* no ->put_link(), please */
48080 + path_put(&nd->path);
48081 + return error;
48082 + }
48083 +
48084 nd->last_type = LAST_BIND;
48085 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
48086 error = PTR_ERR(*p);
48087 if (!IS_ERR(*p)) {
48088 - char *s = nd_get_link(nd);
48089 + const char *s = nd_get_link(nd);
48090 error = 0;
48091 if (s)
48092 error = __vfs_follow_link(nd, s);
48093 @@ -1697,6 +1725,9 @@ static int do_path_lookup(int dfd, const
48094 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
48095
48096 if (likely(!retval)) {
48097 + if (*name != '/' && nd->path.dentry && nd->inode && !gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
48098 + return -ENOENT;
48099 +
48100 if (unlikely(!audit_dummy_context())) {
48101 if (nd->path.dentry && nd->inode)
48102 audit_inode(name, nd->path.dentry);
48103 @@ -2007,6 +2038,30 @@ int vfs_create(struct inode *dir, struct
48104 return error;
48105 }
48106
48107 +/*
48108 + * Note that while the flag value (low two bits) for sys_open means:
48109 + * 00 - read-only
48110 + * 01 - write-only
48111 + * 10 - read-write
48112 + * 11 - special
48113 + * it is changed into
48114 + * 00 - no permissions needed
48115 + * 01 - read-permission
48116 + * 10 - write-permission
48117 + * 11 - read-write
48118 + * for the internal routines (ie open_namei()/follow_link() etc)
48119 + * This is more logical, and also allows the 00 "no perm needed"
48120 + * to be used for symlinks (where the permissions are checked
48121 + * later).
48122 + *
48123 +*/
48124 +static inline int open_to_namei_flags(int flag)
48125 +{
48126 + if ((flag+1) & O_ACCMODE)
48127 + flag++;
48128 + return flag;
48129 +}
48130 +
48131 static int may_open(struct path *path, int acc_mode, int flag)
48132 {
48133 struct dentry *dentry = path->dentry;
48134 @@ -2059,7 +2114,27 @@ static int may_open(struct path *path, i
48135 /*
48136 * Ensure there are no outstanding leases on the file.
48137 */
48138 - return break_lease(inode, flag);
48139 + error = break_lease(inode, flag);
48140 +
48141 + if (error)
48142 + return error;
48143 +
48144 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode)) {
48145 + error = -EPERM;
48146 + goto exit;
48147 + }
48148 +
48149 + if (gr_handle_rawio(inode)) {
48150 + error = -EPERM;
48151 + goto exit;
48152 + }
48153 +
48154 + if (!gr_acl_handle_open(dentry, path->mnt, open_to_namei_flags(flag))) {
48155 + error = -EACCES;
48156 + goto exit;
48157 + }
48158 +exit:
48159 + return error;
48160 }
48161
48162 static int handle_truncate(struct file *filp)
48163 @@ -2085,30 +2160,6 @@ static int handle_truncate(struct file *
48164 }
48165
48166 /*
48167 - * Note that while the flag value (low two bits) for sys_open means:
48168 - * 00 - read-only
48169 - * 01 - write-only
48170 - * 10 - read-write
48171 - * 11 - special
48172 - * it is changed into
48173 - * 00 - no permissions needed
48174 - * 01 - read-permission
48175 - * 10 - write-permission
48176 - * 11 - read-write
48177 - * for the internal routines (ie open_namei()/follow_link() etc)
48178 - * This is more logical, and also allows the 00 "no perm needed"
48179 - * to be used for symlinks (where the permissions are checked
48180 - * later).
48181 - *
48182 -*/
48183 -static inline int open_to_namei_flags(int flag)
48184 -{
48185 - if ((flag+1) & O_ACCMODE)
48186 - flag++;
48187 - return flag;
48188 -}
48189 -
48190 -/*
48191 * Handle the last step of open()
48192 */
48193 static struct file *do_last(struct nameidata *nd, struct path *path,
48194 @@ -2117,6 +2168,7 @@ static struct file *do_last(struct namei
48195 struct dentry *dir = nd->path.dentry;
48196 struct dentry *dentry;
48197 int open_flag = op->open_flag;
48198 + int flag = open_to_namei_flags(open_flag);
48199 int will_truncate = open_flag & O_TRUNC;
48200 int want_write = 0;
48201 int acc_mode = op->acc_mode;
48202 @@ -2212,6 +2264,12 @@ static struct file *do_last(struct namei
48203 /* Negative dentry, just create the file */
48204 if (!dentry->d_inode) {
48205 int mode = op->mode;
48206 +
48207 + if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, path->mnt, flag, mode)) {
48208 + error = -EACCES;
48209 + goto exit_mutex_unlock;
48210 + }
48211 +
48212 if (!IS_POSIXACL(dir->d_inode))
48213 mode &= ~current_umask();
48214 /*
48215 @@ -2235,6 +2293,8 @@ static struct file *do_last(struct namei
48216 error = vfs_create(dir->d_inode, dentry, mode, nd);
48217 if (error)
48218 goto exit_mutex_unlock;
48219 + else
48220 + gr_handle_create(path->dentry, path->mnt);
48221 mutex_unlock(&dir->d_inode->i_mutex);
48222 dput(nd->path.dentry);
48223 nd->path.dentry = dentry;
48224 @@ -2244,6 +2304,14 @@ static struct file *do_last(struct namei
48225 /*
48226 * It already exists.
48227 */
48228 +
48229 + /* only check if O_CREAT is specified, all other checks need to go
48230 + into may_open */
48231 + if (gr_handle_fifo(path->dentry, path->mnt, dir, flag, acc_mode)) {
48232 + error = -EACCES;
48233 + goto exit_mutex_unlock;
48234 + }
48235 +
48236 mutex_unlock(&dir->d_inode->i_mutex);
48237 audit_inode(pathname, path->dentry);
48238
48239 @@ -2530,6 +2598,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const
48240 error = may_mknod(mode);
48241 if (error)
48242 goto out_dput;
48243 +
48244 + if (gr_handle_chroot_mknod(dentry, nd.path.mnt, mode)) {
48245 + error = -EPERM;
48246 + goto out_dput;
48247 + }
48248 +
48249 + if (!gr_acl_handle_mknod(dentry, nd.path.dentry, nd.path.mnt, mode)) {
48250 + error = -EACCES;
48251 + goto out_dput;
48252 + }
48253 +
48254 error = mnt_want_write(nd.path.mnt);
48255 if (error)
48256 goto out_dput;
48257 @@ -2550,6 +2629,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const
48258 }
48259 out_drop_write:
48260 mnt_drop_write(nd.path.mnt);
48261 +
48262 + if (!error)
48263 + gr_handle_create(dentry, nd.path.mnt);
48264 out_dput:
48265 dput(dentry);
48266 out_unlock:
48267 @@ -2602,6 +2684,11 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const
48268 if (IS_ERR(dentry))
48269 goto out_unlock;
48270
48271 + if (!gr_acl_handle_mkdir(dentry, nd.path.dentry, nd.path.mnt)) {
48272 + error = -EACCES;
48273 + goto out_dput;
48274 + }
48275 +
48276 if (!IS_POSIXACL(nd.path.dentry->d_inode))
48277 mode &= ~current_umask();
48278 error = mnt_want_write(nd.path.mnt);
48279 @@ -2613,6 +2700,10 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const
48280 error = vfs_mkdir(nd.path.dentry->d_inode, dentry, mode);
48281 out_drop_write:
48282 mnt_drop_write(nd.path.mnt);
48283 +
48284 + if (!error)
48285 + gr_handle_create(dentry, nd.path.mnt);
48286 +
48287 out_dput:
48288 dput(dentry);
48289 out_unlock:
48290 @@ -2692,6 +2783,8 @@ static long do_rmdir(int dfd, const char
48291 char * name;
48292 struct dentry *dentry;
48293 struct nameidata nd;
48294 + ino_t saved_ino = 0;
48295 + dev_t saved_dev = 0;
48296
48297 error = user_path_parent(dfd, pathname, &nd, &name);
48298 if (error)
48299 @@ -2716,6 +2809,19 @@ static long do_rmdir(int dfd, const char
48300 error = PTR_ERR(dentry);
48301 if (IS_ERR(dentry))
48302 goto exit2;
48303 +
48304 + if (dentry->d_inode != NULL) {
48305 + if (dentry->d_inode->i_nlink <= 1) {
48306 + saved_ino = dentry->d_inode->i_ino;
48307 + saved_dev = gr_get_dev_from_dentry(dentry);
48308 + }
48309 +
48310 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
48311 + error = -EACCES;
48312 + goto exit3;
48313 + }
48314 + }
48315 +
48316 error = mnt_want_write(nd.path.mnt);
48317 if (error)
48318 goto exit3;
48319 @@ -2723,6 +2829,8 @@ static long do_rmdir(int dfd, const char
48320 if (error)
48321 goto exit4;
48322 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
48323 + if (!error && (saved_dev || saved_ino))
48324 + gr_handle_delete(saved_ino, saved_dev);
48325 exit4:
48326 mnt_drop_write(nd.path.mnt);
48327 exit3:
48328 @@ -2785,6 +2893,8 @@ static long do_unlinkat(int dfd, const c
48329 struct dentry *dentry;
48330 struct nameidata nd;
48331 struct inode *inode = NULL;
48332 + ino_t saved_ino = 0;
48333 + dev_t saved_dev = 0;
48334
48335 error = user_path_parent(dfd, pathname, &nd, &name);
48336 if (error)
48337 @@ -2804,8 +2914,17 @@ static long do_unlinkat(int dfd, const c
48338 if (nd.last.name[nd.last.len])
48339 goto slashes;
48340 inode = dentry->d_inode;
48341 - if (inode)
48342 + if (inode) {
48343 ihold(inode);
48344 + if (inode->i_nlink <= 1) {
48345 + saved_ino = inode->i_ino;
48346 + saved_dev = gr_get_dev_from_dentry(dentry);
48347 + }
48348 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
48349 + error = -EACCES;
48350 + goto exit2;
48351 + }
48352 + }
48353 error = mnt_want_write(nd.path.mnt);
48354 if (error)
48355 goto exit2;
48356 @@ -2813,6 +2932,8 @@ static long do_unlinkat(int dfd, const c
48357 if (error)
48358 goto exit3;
48359 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
48360 + if (!error && (saved_ino || saved_dev))
48361 + gr_handle_delete(saved_ino, saved_dev);
48362 exit3:
48363 mnt_drop_write(nd.path.mnt);
48364 exit2:
48365 @@ -2890,6 +3011,11 @@ SYSCALL_DEFINE3(symlinkat, const char __
48366 if (IS_ERR(dentry))
48367 goto out_unlock;
48368
48369 + if (!gr_acl_handle_symlink(dentry, nd.path.dentry, nd.path.mnt, from)) {
48370 + error = -EACCES;
48371 + goto out_dput;
48372 + }
48373 +
48374 error = mnt_want_write(nd.path.mnt);
48375 if (error)
48376 goto out_dput;
48377 @@ -2897,6 +3023,8 @@ SYSCALL_DEFINE3(symlinkat, const char __
48378 if (error)
48379 goto out_drop_write;
48380 error = vfs_symlink(nd.path.dentry->d_inode, dentry, from);
48381 + if (!error)
48382 + gr_handle_create(dentry, nd.path.mnt);
48383 out_drop_write:
48384 mnt_drop_write(nd.path.mnt);
48385 out_dput:
48386 @@ -3005,6 +3133,20 @@ SYSCALL_DEFINE5(linkat, int, olddfd, con
48387 error = PTR_ERR(new_dentry);
48388 if (IS_ERR(new_dentry))
48389 goto out_unlock;
48390 +
48391 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
48392 + old_path.dentry->d_inode,
48393 + old_path.dentry->d_inode->i_mode, to)) {
48394 + error = -EACCES;
48395 + goto out_dput;
48396 + }
48397 +
48398 + if (!gr_acl_handle_link(new_dentry, nd.path.dentry, nd.path.mnt,
48399 + old_path.dentry, old_path.mnt, to)) {
48400 + error = -EACCES;
48401 + goto out_dput;
48402 + }
48403 +
48404 error = mnt_want_write(nd.path.mnt);
48405 if (error)
48406 goto out_dput;
48407 @@ -3012,6 +3154,8 @@ SYSCALL_DEFINE5(linkat, int, olddfd, con
48408 if (error)
48409 goto out_drop_write;
48410 error = vfs_link(old_path.dentry, nd.path.dentry->d_inode, new_dentry);
48411 + if (!error)
48412 + gr_handle_create(new_dentry, nd.path.mnt);
48413 out_drop_write:
48414 mnt_drop_write(nd.path.mnt);
48415 out_dput:
48416 @@ -3189,6 +3333,8 @@ SYSCALL_DEFINE4(renameat, int, olddfd, c
48417 char *to;
48418 int error;
48419
48420 + pax_track_stack();
48421 +
48422 error = user_path_parent(olddfd, oldname, &oldnd, &from);
48423 if (error)
48424 goto exit;
48425 @@ -3245,6 +3391,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, c
48426 if (new_dentry == trap)
48427 goto exit5;
48428
48429 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
48430 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
48431 + to);
48432 + if (error)
48433 + goto exit5;
48434 +
48435 error = mnt_want_write(oldnd.path.mnt);
48436 if (error)
48437 goto exit5;
48438 @@ -3254,6 +3406,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, c
48439 goto exit6;
48440 error = vfs_rename(old_dir->d_inode, old_dentry,
48441 new_dir->d_inode, new_dentry);
48442 + if (!error)
48443 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
48444 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
48445 exit6:
48446 mnt_drop_write(oldnd.path.mnt);
48447 exit5:
48448 @@ -3279,6 +3434,8 @@ SYSCALL_DEFINE2(rename, const char __use
48449
48450 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
48451 {
48452 + char tmpbuf[64];
48453 + const char *newlink;
48454 int len;
48455
48456 len = PTR_ERR(link);
48457 @@ -3288,7 +3445,14 @@ int vfs_readlink(struct dentry *dentry,
48458 len = strlen(link);
48459 if (len > (unsigned) buflen)
48460 len = buflen;
48461 - if (copy_to_user(buffer, link, len))
48462 +
48463 + if (len < sizeof(tmpbuf)) {
48464 + memcpy(tmpbuf, link, len);
48465 + newlink = tmpbuf;
48466 + } else
48467 + newlink = link;
48468 +
48469 + if (copy_to_user(buffer, newlink, len))
48470 len = -EFAULT;
48471 out:
48472 return len;
48473 diff -urNp linux-2.6.39/fs/namespace.c linux-2.6.39/fs/namespace.c
48474 --- linux-2.6.39/fs/namespace.c 2011-05-19 00:06:34.000000000 -0400
48475 +++ linux-2.6.39/fs/namespace.c 2011-05-22 20:43:58.000000000 -0400
48476 @@ -1328,6 +1328,9 @@ static int do_umount(struct vfsmount *mn
48477 if (!(sb->s_flags & MS_RDONLY))
48478 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
48479 up_write(&sb->s_umount);
48480 +
48481 + gr_log_remount(mnt->mnt_devname, retval);
48482 +
48483 return retval;
48484 }
48485
48486 @@ -1347,6 +1350,9 @@ static int do_umount(struct vfsmount *mn
48487 br_write_unlock(vfsmount_lock);
48488 up_write(&namespace_sem);
48489 release_mounts(&umount_list);
48490 +
48491 + gr_log_unmount(mnt->mnt_devname, retval);
48492 +
48493 return retval;
48494 }
48495
48496 @@ -2338,6 +2344,16 @@ long do_mount(char *dev_name, char *dir_
48497 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
48498 MS_STRICTATIME);
48499
48500 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
48501 + retval = -EPERM;
48502 + goto dput_out;
48503 + }
48504 +
48505 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
48506 + retval = -EPERM;
48507 + goto dput_out;
48508 + }
48509 +
48510 if (flags & MS_REMOUNT)
48511 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
48512 data_page);
48513 @@ -2352,6 +2368,9 @@ long do_mount(char *dev_name, char *dir_
48514 dev_name, data_page);
48515 dput_out:
48516 path_put(&path);
48517 +
48518 + gr_log_mount(dev_name, dir_name, retval);
48519 +
48520 return retval;
48521 }
48522
48523 @@ -2575,6 +2594,11 @@ SYSCALL_DEFINE2(pivot_root, const char _
48524 if (error)
48525 goto out2;
48526
48527 + if (gr_handle_chroot_pivot()) {
48528 + error = -EPERM;
48529 + goto out2;
48530 + }
48531 +
48532 get_fs_root(current->fs, &root);
48533 error = lock_mount(&old);
48534 if (error)
48535 diff -urNp linux-2.6.39/fs/ncpfs/dir.c linux-2.6.39/fs/ncpfs/dir.c
48536 --- linux-2.6.39/fs/ncpfs/dir.c 2011-05-19 00:06:34.000000000 -0400
48537 +++ linux-2.6.39/fs/ncpfs/dir.c 2011-05-22 19:36:32.000000000 -0400
48538 @@ -299,6 +299,8 @@ ncp_lookup_validate(struct dentry *dentr
48539 int res, val = 0, len;
48540 __u8 __name[NCP_MAXPATHLEN + 1];
48541
48542 + pax_track_stack();
48543 +
48544 if (dentry == dentry->d_sb->s_root)
48545 return 1;
48546
48547 @@ -844,6 +846,8 @@ static struct dentry *ncp_lookup(struct
48548 int error, res, len;
48549 __u8 __name[NCP_MAXPATHLEN + 1];
48550
48551 + pax_track_stack();
48552 +
48553 error = -EIO;
48554 if (!ncp_conn_valid(server))
48555 goto finished;
48556 @@ -931,6 +935,8 @@ int ncp_create_new(struct inode *dir, st
48557 PPRINTK("ncp_create_new: creating %s/%s, mode=%x\n",
48558 dentry->d_parent->d_name.name, dentry->d_name.name, mode);
48559
48560 + pax_track_stack();
48561 +
48562 ncp_age_dentry(server, dentry);
48563 len = sizeof(__name);
48564 error = ncp_io2vol(server, __name, &len, dentry->d_name.name,
48565 @@ -992,6 +998,8 @@ static int ncp_mkdir(struct inode *dir,
48566 int error, len;
48567 __u8 __name[NCP_MAXPATHLEN + 1];
48568
48569 + pax_track_stack();
48570 +
48571 DPRINTK("ncp_mkdir: making %s/%s\n",
48572 dentry->d_parent->d_name.name, dentry->d_name.name);
48573
48574 @@ -1135,6 +1143,8 @@ static int ncp_rename(struct inode *old_
48575 int old_len, new_len;
48576 __u8 __old_name[NCP_MAXPATHLEN + 1], __new_name[NCP_MAXPATHLEN + 1];
48577
48578 + pax_track_stack();
48579 +
48580 DPRINTK("ncp_rename: %s/%s to %s/%s\n",
48581 old_dentry->d_parent->d_name.name, old_dentry->d_name.name,
48582 new_dentry->d_parent->d_name.name, new_dentry->d_name.name);
48583 diff -urNp linux-2.6.39/fs/ncpfs/inode.c linux-2.6.39/fs/ncpfs/inode.c
48584 --- linux-2.6.39/fs/ncpfs/inode.c 2011-05-19 00:06:34.000000000 -0400
48585 +++ linux-2.6.39/fs/ncpfs/inode.c 2011-05-22 19:36:32.000000000 -0400
48586 @@ -461,6 +461,8 @@ static int ncp_fill_super(struct super_b
48587 #endif
48588 struct ncp_entry_info finfo;
48589
48590 + pax_track_stack();
48591 +
48592 data.wdog_pid = NULL;
48593 server = kzalloc(sizeof(struct ncp_server), GFP_KERNEL);
48594 if (!server)
48595 diff -urNp linux-2.6.39/fs/nfs/inode.c linux-2.6.39/fs/nfs/inode.c
48596 --- linux-2.6.39/fs/nfs/inode.c 2011-05-19 00:06:34.000000000 -0400
48597 +++ linux-2.6.39/fs/nfs/inode.c 2011-05-22 19:36:32.000000000 -0400
48598 @@ -999,16 +999,16 @@ static int nfs_size_need_update(const st
48599 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
48600 }
48601
48602 -static atomic_long_t nfs_attr_generation_counter;
48603 +static atomic_long_unchecked_t nfs_attr_generation_counter;
48604
48605 static unsigned long nfs_read_attr_generation_counter(void)
48606 {
48607 - return atomic_long_read(&nfs_attr_generation_counter);
48608 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
48609 }
48610
48611 unsigned long nfs_inc_attr_generation_counter(void)
48612 {
48613 - return atomic_long_inc_return(&nfs_attr_generation_counter);
48614 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
48615 }
48616
48617 void nfs_fattr_init(struct nfs_fattr *fattr)
48618 diff -urNp linux-2.6.39/fs/nfs/nfs4proc.c linux-2.6.39/fs/nfs/nfs4proc.c
48619 --- linux-2.6.39/fs/nfs/nfs4proc.c 2011-05-19 00:06:34.000000000 -0400
48620 +++ linux-2.6.39/fs/nfs/nfs4proc.c 2011-05-22 19:36:32.000000000 -0400
48621 @@ -5840,14 +5840,14 @@ struct nfs4_state_recovery_ops nfs41_nog
48622 };
48623 #endif /* CONFIG_NFS_V4_1 */
48624
48625 -struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = {
48626 +const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = {
48627 .sched_state_renewal = nfs4_proc_async_renew,
48628 .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked,
48629 .renew_lease = nfs4_proc_renew,
48630 };
48631
48632 #if defined(CONFIG_NFS_V4_1)
48633 -struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = {
48634 +const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = {
48635 .sched_state_renewal = nfs41_proc_async_sequence,
48636 .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked,
48637 .renew_lease = nfs4_proc_sequence,
48638 diff -urNp linux-2.6.39/fs/nfsd/lockd.c linux-2.6.39/fs/nfsd/lockd.c
48639 --- linux-2.6.39/fs/nfsd/lockd.c 2011-05-19 00:06:34.000000000 -0400
48640 +++ linux-2.6.39/fs/nfsd/lockd.c 2011-05-22 19:36:32.000000000 -0400
48641 @@ -60,7 +60,7 @@ nlm_fclose(struct file *filp)
48642 fput(filp);
48643 }
48644
48645 -static struct nlmsvc_binding nfsd_nlm_ops = {
48646 +static const struct nlmsvc_binding nfsd_nlm_ops = {
48647 .fopen = nlm_fopen, /* open file for locking */
48648 .fclose = nlm_fclose, /* close file */
48649 };
48650 diff -urNp linux-2.6.39/fs/nfsd/nfs4state.c linux-2.6.39/fs/nfsd/nfs4state.c
48651 --- linux-2.6.39/fs/nfsd/nfs4state.c 2011-05-19 00:06:34.000000000 -0400
48652 +++ linux-2.6.39/fs/nfsd/nfs4state.c 2011-05-22 19:36:32.000000000 -0400
48653 @@ -3784,6 +3784,8 @@ nfsd4_lock(struct svc_rqst *rqstp, struc
48654 unsigned int strhashval;
48655 int err;
48656
48657 + pax_track_stack();
48658 +
48659 dprintk("NFSD: nfsd4_lock: start=%Ld length=%Ld\n",
48660 (long long) lock->lk_offset,
48661 (long long) lock->lk_length);
48662 diff -urNp linux-2.6.39/fs/nfsd/nfs4xdr.c linux-2.6.39/fs/nfsd/nfs4xdr.c
48663 --- linux-2.6.39/fs/nfsd/nfs4xdr.c 2011-05-19 00:06:34.000000000 -0400
48664 +++ linux-2.6.39/fs/nfsd/nfs4xdr.c 2011-05-22 19:36:32.000000000 -0400
48665 @@ -1793,6 +1793,8 @@ nfsd4_encode_fattr(struct svc_fh *fhp, s
48666 .dentry = dentry,
48667 };
48668
48669 + pax_track_stack();
48670 +
48671 BUG_ON(bmval1 & NFSD_WRITEONLY_ATTRS_WORD1);
48672 BUG_ON(bmval0 & ~nfsd_suppattrs0(minorversion));
48673 BUG_ON(bmval1 & ~nfsd_suppattrs1(minorversion));
48674 diff -urNp linux-2.6.39/fs/nfsd/nfsctl.c linux-2.6.39/fs/nfsd/nfsctl.c
48675 --- linux-2.6.39/fs/nfsd/nfsctl.c 2011-05-19 00:06:34.000000000 -0400
48676 +++ linux-2.6.39/fs/nfsd/nfsctl.c 2011-05-22 19:36:32.000000000 -0400
48677 @@ -182,7 +182,7 @@ static int export_features_open(struct i
48678 return single_open(file, export_features_show, NULL);
48679 }
48680
48681 -static struct file_operations export_features_operations = {
48682 +static const struct file_operations export_features_operations = {
48683 .open = export_features_open,
48684 .read = seq_read,
48685 .llseek = seq_lseek,
48686 diff -urNp linux-2.6.39/fs/nfsd/vfs.c linux-2.6.39/fs/nfsd/vfs.c
48687 --- linux-2.6.39/fs/nfsd/vfs.c 2011-05-19 00:06:34.000000000 -0400
48688 +++ linux-2.6.39/fs/nfsd/vfs.c 2011-05-22 19:36:32.000000000 -0400
48689 @@ -898,7 +898,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, st
48690 } else {
48691 oldfs = get_fs();
48692 set_fs(KERNEL_DS);
48693 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
48694 + host_err = vfs_readv(file, (__force struct iovec __user *)vec, vlen, &offset);
48695 set_fs(oldfs);
48696 }
48697
48698 @@ -1002,7 +1002,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, s
48699
48700 /* Write the data. */
48701 oldfs = get_fs(); set_fs(KERNEL_DS);
48702 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
48703 + host_err = vfs_writev(file, (__force struct iovec __user *)vec, vlen, &offset);
48704 set_fs(oldfs);
48705 if (host_err < 0)
48706 goto out_nfserr;
48707 @@ -1525,7 +1525,7 @@ nfsd_readlink(struct svc_rqst *rqstp, st
48708 */
48709
48710 oldfs = get_fs(); set_fs(KERNEL_DS);
48711 - host_err = inode->i_op->readlink(dentry, buf, *lenp);
48712 + host_err = inode->i_op->readlink(dentry, (__force char __user *)buf, *lenp);
48713 set_fs(oldfs);
48714
48715 if (host_err < 0)
48716 diff -urNp linux-2.6.39/fs/nilfs2/segment.c linux-2.6.39/fs/nilfs2/segment.c
48717 --- linux-2.6.39/fs/nilfs2/segment.c 2011-05-19 00:06:34.000000000 -0400
48718 +++ linux-2.6.39/fs/nilfs2/segment.c 2011-05-22 19:36:32.000000000 -0400
48719 @@ -555,7 +555,7 @@ static void nilfs_write_file_node_binfo(
48720 *vblocknr = binfo->bi_v.bi_vblocknr;
48721 }
48722
48723 -static struct nilfs_sc_operations nilfs_sc_file_ops = {
48724 +static const struct nilfs_sc_operations nilfs_sc_file_ops = {
48725 .collect_data = nilfs_collect_file_data,
48726 .collect_node = nilfs_collect_file_node,
48727 .collect_bmap = nilfs_collect_file_bmap,
48728 @@ -604,7 +604,7 @@ static void nilfs_write_dat_node_binfo(s
48729 *binfo_dat = binfo->bi_dat;
48730 }
48731
48732 -static struct nilfs_sc_operations nilfs_sc_dat_ops = {
48733 +static const struct nilfs_sc_operations nilfs_sc_dat_ops = {
48734 .collect_data = nilfs_collect_dat_data,
48735 .collect_node = nilfs_collect_file_node,
48736 .collect_bmap = nilfs_collect_dat_bmap,
48737 @@ -612,7 +612,7 @@ static struct nilfs_sc_operations nilfs_
48738 .write_node_binfo = nilfs_write_dat_node_binfo,
48739 };
48740
48741 -static struct nilfs_sc_operations nilfs_sc_dsync_ops = {
48742 +static const struct nilfs_sc_operations nilfs_sc_dsync_ops = {
48743 .collect_data = nilfs_collect_file_data,
48744 .collect_node = NULL,
48745 .collect_bmap = NULL,
48746 @@ -971,7 +971,7 @@ static size_t nilfs_segctor_buffer_rest(
48747
48748 static int nilfs_segctor_scan_file(struct nilfs_sc_info *sci,
48749 struct inode *inode,
48750 - struct nilfs_sc_operations *sc_ops)
48751 + const struct nilfs_sc_operations *sc_ops)
48752 {
48753 LIST_HEAD(data_buffers);
48754 LIST_HEAD(node_buffers);
48755 @@ -1475,7 +1475,7 @@ nilfs_segctor_update_payload_blocknr(str
48756 sector_t blocknr;
48757 unsigned long nfinfo = segbuf->sb_sum.nfinfo;
48758 unsigned long nblocks = 0, ndatablk = 0;
48759 - struct nilfs_sc_operations *sc_op = NULL;
48760 + const struct nilfs_sc_operations *sc_op = NULL;
48761 struct nilfs_segsum_pointer ssp;
48762 struct nilfs_finfo *finfo = NULL;
48763 union nilfs_binfo binfo;
48764 diff -urNp linux-2.6.39/fs/notify/dnotify/dnotify.c linux-2.6.39/fs/notify/dnotify/dnotify.c
48765 --- linux-2.6.39/fs/notify/dnotify/dnotify.c 2011-05-19 00:06:34.000000000 -0400
48766 +++ linux-2.6.39/fs/notify/dnotify/dnotify.c 2011-05-22 19:36:32.000000000 -0400
48767 @@ -151,7 +151,7 @@ static void dnotify_free_mark(struct fsn
48768 kmem_cache_free(dnotify_mark_cache, dn_mark);
48769 }
48770
48771 -static struct fsnotify_ops dnotify_fsnotify_ops = {
48772 +static const struct fsnotify_ops dnotify_fsnotify_ops = {
48773 .handle_event = dnotify_handle_event,
48774 .should_send_event = dnotify_should_send_event,
48775 .free_group_priv = NULL,
48776 diff -urNp linux-2.6.39/fs/notify/notification.c linux-2.6.39/fs/notify/notification.c
48777 --- linux-2.6.39/fs/notify/notification.c 2011-05-19 00:06:34.000000000 -0400
48778 +++ linux-2.6.39/fs/notify/notification.c 2011-05-22 19:36:32.000000000 -0400
48779 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event
48780 * get set to 0 so it will never get 'freed'
48781 */
48782 static struct fsnotify_event *q_overflow_event;
48783 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48784 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48785
48786 /**
48787 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
48788 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = A
48789 */
48790 u32 fsnotify_get_cookie(void)
48791 {
48792 - return atomic_inc_return(&fsnotify_sync_cookie);
48793 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
48794 }
48795 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
48796
48797 diff -urNp linux-2.6.39/fs/ntfs/dir.c linux-2.6.39/fs/ntfs/dir.c
48798 --- linux-2.6.39/fs/ntfs/dir.c 2011-05-19 00:06:34.000000000 -0400
48799 +++ linux-2.6.39/fs/ntfs/dir.c 2011-05-22 19:36:32.000000000 -0400
48800 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
48801 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
48802 ~(s64)(ndir->itype.index.block_size - 1)));
48803 /* Bounds checks. */
48804 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48805 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48806 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
48807 "inode 0x%lx or driver bug.", vdir->i_ino);
48808 goto err_out;
48809 diff -urNp linux-2.6.39/fs/ntfs/file.c linux-2.6.39/fs/ntfs/file.c
48810 --- linux-2.6.39/fs/ntfs/file.c 2011-05-19 00:06:34.000000000 -0400
48811 +++ linux-2.6.39/fs/ntfs/file.c 2011-05-22 19:36:32.000000000 -0400
48812 @@ -2222,6 +2222,6 @@ const struct inode_operations ntfs_file_
48813 #endif /* NTFS_RW */
48814 };
48815
48816 -const struct file_operations ntfs_empty_file_ops = {};
48817 +const struct file_operations ntfs_empty_file_ops __read_only;
48818
48819 -const struct inode_operations ntfs_empty_inode_ops = {};
48820 +const struct inode_operations ntfs_empty_inode_ops __read_only;
48821 diff -urNp linux-2.6.39/fs/ocfs2/cluster/heartbeat.c linux-2.6.39/fs/ocfs2/cluster/heartbeat.c
48822 --- linux-2.6.39/fs/ocfs2/cluster/heartbeat.c 2011-05-19 00:06:34.000000000 -0400
48823 +++ linux-2.6.39/fs/ocfs2/cluster/heartbeat.c 2011-05-22 19:36:32.000000000 -0400
48824 @@ -2261,7 +2261,7 @@ static struct configfs_item_operations o
48825 .store_attribute = o2hb_heartbeat_group_store,
48826 };
48827
48828 -static struct configfs_group_operations o2hb_heartbeat_group_group_ops = {
48829 +static const struct configfs_group_operations o2hb_heartbeat_group_group_ops = {
48830 .make_item = o2hb_heartbeat_group_make_item,
48831 .drop_item = o2hb_heartbeat_group_drop_item,
48832 };
48833 diff -urNp linux-2.6.39/fs/ocfs2/cluster/nodemanager.c linux-2.6.39/fs/ocfs2/cluster/nodemanager.c
48834 --- linux-2.6.39/fs/ocfs2/cluster/nodemanager.c 2011-05-19 00:06:34.000000000 -0400
48835 +++ linux-2.6.39/fs/ocfs2/cluster/nodemanager.c 2011-05-22 19:36:32.000000000 -0400
48836 @@ -752,7 +752,7 @@ static void o2nm_node_group_drop_item(st
48837 config_item_put(item);
48838 }
48839
48840 -static struct configfs_group_operations o2nm_node_group_group_ops = {
48841 +static const struct configfs_group_operations o2nm_node_group_group_ops = {
48842 .make_item = o2nm_node_group_make_item,
48843 .drop_item = o2nm_node_group_drop_item,
48844 };
48845 @@ -869,7 +869,7 @@ static void o2nm_cluster_group_drop_item
48846 config_item_put(item);
48847 }
48848
48849 -static struct configfs_group_operations o2nm_cluster_group_group_ops = {
48850 +static const struct configfs_group_operations o2nm_cluster_group_group_ops = {
48851 .make_group = o2nm_cluster_group_make_group,
48852 .drop_item = o2nm_cluster_group_drop_item,
48853 };
48854 diff -urNp linux-2.6.39/fs/ocfs2/localalloc.c linux-2.6.39/fs/ocfs2/localalloc.c
48855 --- linux-2.6.39/fs/ocfs2/localalloc.c 2011-05-19 00:06:34.000000000 -0400
48856 +++ linux-2.6.39/fs/ocfs2/localalloc.c 2011-05-22 19:36:32.000000000 -0400
48857 @@ -1283,7 +1283,7 @@ static int ocfs2_local_alloc_slide_windo
48858 goto bail;
48859 }
48860
48861 - atomic_inc(&osb->alloc_stats.moves);
48862 + atomic_inc_unchecked(&osb->alloc_stats.moves);
48863
48864 bail:
48865 if (handle)
48866 diff -urNp linux-2.6.39/fs/ocfs2/namei.c linux-2.6.39/fs/ocfs2/namei.c
48867 --- linux-2.6.39/fs/ocfs2/namei.c 2011-05-19 00:06:34.000000000 -0400
48868 +++ linux-2.6.39/fs/ocfs2/namei.c 2011-05-22 19:36:32.000000000 -0400
48869 @@ -1063,6 +1063,8 @@ static int ocfs2_rename(struct inode *ol
48870 struct ocfs2_dir_lookup_result orphan_insert = { NULL, };
48871 struct ocfs2_dir_lookup_result target_insert = { NULL, };
48872
48873 + pax_track_stack();
48874 +
48875 /* At some point it might be nice to break this function up a
48876 * bit. */
48877
48878 diff -urNp linux-2.6.39/fs/ocfs2/ocfs2.h linux-2.6.39/fs/ocfs2/ocfs2.h
48879 --- linux-2.6.39/fs/ocfs2/ocfs2.h 2011-05-19 00:06:34.000000000 -0400
48880 +++ linux-2.6.39/fs/ocfs2/ocfs2.h 2011-05-22 19:36:32.000000000 -0400
48881 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
48882
48883 struct ocfs2_alloc_stats
48884 {
48885 - atomic_t moves;
48886 - atomic_t local_data;
48887 - atomic_t bitmap_data;
48888 - atomic_t bg_allocs;
48889 - atomic_t bg_extends;
48890 + atomic_unchecked_t moves;
48891 + atomic_unchecked_t local_data;
48892 + atomic_unchecked_t bitmap_data;
48893 + atomic_unchecked_t bg_allocs;
48894 + atomic_unchecked_t bg_extends;
48895 };
48896
48897 enum ocfs2_local_alloc_state
48898 diff -urNp linux-2.6.39/fs/ocfs2/stackglue.h linux-2.6.39/fs/ocfs2/stackglue.h
48899 --- linux-2.6.39/fs/ocfs2/stackglue.h 2011-05-19 00:06:34.000000000 -0400
48900 +++ linux-2.6.39/fs/ocfs2/stackglue.h 2011-05-22 19:36:32.000000000 -0400
48901 @@ -221,13 +221,13 @@ struct ocfs2_stack_operations {
48902 };
48903
48904 /*
48905 - * Each stack plugin must describe itself by registering a
48906 + * Each stack plugin must describe itself by registerin const g a
48907 * ocfs2_stack_plugin structure. This is only seen by stackglue and the
48908 * stack driver.
48909 */
48910 struct ocfs2_stack_plugin {
48911 char *sp_name;
48912 - struct ocfs2_stack_operations *sp_ops;
48913 + const struct ocfs2_stack_operations *sp_ops;
48914 struct module *sp_owner;
48915
48916 /* These are managed by the stackglue code. */
48917 diff -urNp linux-2.6.39/fs/ocfs2/stack_o2cb.c linux-2.6.39/fs/ocfs2/stack_o2cb.c
48918 --- linux-2.6.39/fs/ocfs2/stack_o2cb.c 2011-05-19 00:06:34.000000000 -0400
48919 +++ linux-2.6.39/fs/ocfs2/stack_o2cb.c 2011-05-22 19:36:32.000000000 -0400
48920 @@ -358,7 +358,7 @@ static int o2cb_cluster_this_node(unsign
48921 return 0;
48922 }
48923
48924 -static struct ocfs2_stack_operations o2cb_stack_ops = {
48925 +static const struct ocfs2_stack_operations o2cb_stack_ops = {
48926 .connect = o2cb_cluster_connect,
48927 .disconnect = o2cb_cluster_disconnect,
48928 .this_node = o2cb_cluster_this_node,
48929 @@ -369,7 +369,6 @@ static struct ocfs2_stack_operations o2c
48930 .lock_lvb = o2cb_dlm_lvb,
48931 .dump_lksb = o2cb_dump_lksb,
48932 };
48933 -
48934 static struct ocfs2_stack_plugin o2cb_stack = {
48935 .sp_name = "o2cb",
48936 .sp_ops = &o2cb_stack_ops,
48937 diff -urNp linux-2.6.39/fs/ocfs2/stack_user.c linux-2.6.39/fs/ocfs2/stack_user.c
48938 --- linux-2.6.39/fs/ocfs2/stack_user.c 2011-05-19 00:06:34.000000000 -0400
48939 +++ linux-2.6.39/fs/ocfs2/stack_user.c 2011-05-22 19:36:32.000000000 -0400
48940 @@ -399,7 +399,7 @@ static int ocfs2_control_do_setversion_m
48941 long major, minor;
48942 char *ptr = NULL;
48943 struct ocfs2_control_private *p = file->private_data;
48944 - struct ocfs2_protocol_version *max =
48945 + const struct ocfs2_protocol_version *max =
48946 &ocfs2_user_plugin.sp_max_proto;
48947
48948 if (ocfs2_control_get_handshake_state(file) !=
48949 @@ -861,7 +861,7 @@ static int user_cluster_this_node(unsign
48950 return 0;
48951 }
48952
48953 -static struct ocfs2_stack_operations ocfs2_user_plugin_ops = {
48954 +static const struct ocfs2_stack_operations ocfs2_user_plugin_ops = {
48955 .connect = user_cluster_connect,
48956 .disconnect = user_cluster_disconnect,
48957 .this_node = user_cluster_this_node,
48958 diff -urNp linux-2.6.39/fs/ocfs2/suballoc.c linux-2.6.39/fs/ocfs2/suballoc.c
48959 --- linux-2.6.39/fs/ocfs2/suballoc.c 2011-05-19 00:06:34.000000000 -0400
48960 +++ linux-2.6.39/fs/ocfs2/suballoc.c 2011-05-22 19:36:32.000000000 -0400
48961 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(s
48962 mlog_errno(status);
48963 goto bail;
48964 }
48965 - atomic_inc(&osb->alloc_stats.bg_extends);
48966 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
48967
48968 /* You should never ask for this much metadata */
48969 BUG_ON(bits_wanted >
48970 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handl
48971 mlog_errno(status);
48972 goto bail;
48973 }
48974 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48975 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48976
48977 *suballoc_loc = res.sr_bg_blkno;
48978 *suballoc_bit_start = res.sr_bit_offset;
48979 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_
48980 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
48981 res->sr_bits);
48982
48983 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48984 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48985
48986 BUG_ON(res->sr_bits != 1);
48987
48988 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *hand
48989 mlog_errno(status);
48990 goto bail;
48991 }
48992 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48993 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48994
48995 BUG_ON(res.sr_bits != 1);
48996
48997 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *han
48998 cluster_start,
48999 num_clusters);
49000 if (!status)
49001 - atomic_inc(&osb->alloc_stats.local_data);
49002 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
49003 } else {
49004 if (min_clusters > (osb->bitmap_cpg - 1)) {
49005 /* The only paths asking for contiguousness
49006 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *han
49007 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
49008 res.sr_bg_blkno,
49009 res.sr_bit_offset);
49010 - atomic_inc(&osb->alloc_stats.bitmap_data);
49011 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
49012 *num_clusters = res.sr_bits;
49013 }
49014 }
49015 diff -urNp linux-2.6.39/fs/ocfs2/super.c linux-2.6.39/fs/ocfs2/super.c
49016 --- linux-2.6.39/fs/ocfs2/super.c 2011-05-19 00:06:34.000000000 -0400
49017 +++ linux-2.6.39/fs/ocfs2/super.c 2011-05-22 19:36:32.000000000 -0400
49018 @@ -299,11 +299,11 @@ static int ocfs2_osb_dump(struct ocfs2_s
49019 "%10s => GlobalAllocs: %d LocalAllocs: %d "
49020 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
49021 "Stats",
49022 - atomic_read(&osb->alloc_stats.bitmap_data),
49023 - atomic_read(&osb->alloc_stats.local_data),
49024 - atomic_read(&osb->alloc_stats.bg_allocs),
49025 - atomic_read(&osb->alloc_stats.moves),
49026 - atomic_read(&osb->alloc_stats.bg_extends));
49027 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
49028 + atomic_read_unchecked(&osb->alloc_stats.local_data),
49029 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
49030 + atomic_read_unchecked(&osb->alloc_stats.moves),
49031 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
49032
49033 out += snprintf(buf + out, len - out,
49034 "%10s => State: %u Descriptor: %llu Size: %u bits "
49035 @@ -2111,11 +2111,11 @@ static int ocfs2_initialize_super(struct
49036 spin_lock_init(&osb->osb_xattr_lock);
49037 ocfs2_init_steal_slots(osb);
49038
49039 - atomic_set(&osb->alloc_stats.moves, 0);
49040 - atomic_set(&osb->alloc_stats.local_data, 0);
49041 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
49042 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
49043 - atomic_set(&osb->alloc_stats.bg_extends, 0);
49044 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
49045 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
49046 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
49047 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
49048 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
49049
49050 /* Copy the blockcheck stats from the superblock probe */
49051 osb->osb_ecc_stats = *stats;
49052 diff -urNp linux-2.6.39/fs/ocfs2/symlink.c linux-2.6.39/fs/ocfs2/symlink.c
49053 --- linux-2.6.39/fs/ocfs2/symlink.c 2011-05-19 00:06:34.000000000 -0400
49054 +++ linux-2.6.39/fs/ocfs2/symlink.c 2011-05-22 19:36:32.000000000 -0400
49055 @@ -142,7 +142,7 @@ bail:
49056
49057 static void ocfs2_fast_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
49058 {
49059 - char *link = nd_get_link(nd);
49060 + const char *link = nd_get_link(nd);
49061 if (!IS_ERR(link))
49062 kfree(link);
49063 }
49064 diff -urNp linux-2.6.39/fs/open.c linux-2.6.39/fs/open.c
49065 --- linux-2.6.39/fs/open.c 2011-05-19 00:06:34.000000000 -0400
49066 +++ linux-2.6.39/fs/open.c 2011-05-22 20:46:51.000000000 -0400
49067 @@ -112,6 +112,10 @@ static long do_sys_truncate(const char _
49068 error = locks_verify_truncate(inode, NULL, length);
49069 if (!error)
49070 error = security_path_truncate(&path);
49071 +
49072 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
49073 + error = -EACCES;
49074 +
49075 if (!error)
49076 error = do_truncate(path.dentry, length, 0, NULL);
49077
49078 @@ -358,6 +362,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, con
49079 if (__mnt_is_readonly(path.mnt))
49080 res = -EROFS;
49081
49082 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
49083 + res = -EACCES;
49084 +
49085 out_path_release:
49086 path_put(&path);
49087 out:
49088 @@ -384,6 +391,8 @@ SYSCALL_DEFINE1(chdir, const char __user
49089 if (error)
49090 goto dput_and_out;
49091
49092 + gr_log_chdir(path.dentry, path.mnt);
49093 +
49094 set_fs_pwd(current->fs, &path);
49095
49096 dput_and_out:
49097 @@ -410,6 +419,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd
49098 goto out_putf;
49099
49100 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
49101 +
49102 + if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
49103 + error = -EPERM;
49104 +
49105 + if (!error)
49106 + gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
49107 +
49108 if (!error)
49109 set_fs_pwd(current->fs, &file->f_path);
49110 out_putf:
49111 @@ -438,7 +454,18 @@ SYSCALL_DEFINE1(chroot, const char __use
49112 if (error)
49113 goto dput_and_out;
49114
49115 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
49116 + goto dput_and_out;
49117 +
49118 + if (gr_handle_chroot_caps(&path)) {
49119 + error = -ENOMEM;
49120 + goto dput_and_out;
49121 + }
49122 +
49123 set_fs_root(current->fs, &path);
49124 +
49125 + gr_handle_chroot_chdir(&path);
49126 +
49127 error = 0;
49128 dput_and_out:
49129 path_put(&path);
49130 @@ -466,12 +493,25 @@ SYSCALL_DEFINE2(fchmod, unsigned int, fd
49131 err = mnt_want_write_file(file);
49132 if (err)
49133 goto out_putf;
49134 +
49135 mutex_lock(&inode->i_mutex);
49136 +
49137 + if (!gr_acl_handle_fchmod(dentry, file->f_vfsmnt, mode)) {
49138 + err = -EACCES;
49139 + goto out_unlock;
49140 + }
49141 +
49142 err = security_path_chmod(dentry, file->f_vfsmnt, mode);
49143 if (err)
49144 goto out_unlock;
49145 if (mode == (mode_t) -1)
49146 mode = inode->i_mode;
49147 +
49148 + if (gr_handle_chroot_chmod(dentry, file->f_vfsmnt, mode)) {
49149 + err = -EACCES;
49150 + goto out_unlock;
49151 + }
49152 +
49153 newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
49154 newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
49155 err = notify_change(dentry, &newattrs);
49156 @@ -499,12 +539,25 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
49157 error = mnt_want_write(path.mnt);
49158 if (error)
49159 goto dput_and_out;
49160 +
49161 mutex_lock(&inode->i_mutex);
49162 +
49163 + if (!gr_acl_handle_chmod(path.dentry, path.mnt, mode)) {
49164 + error = -EACCES;
49165 + goto out_unlock;
49166 + }
49167 +
49168 error = security_path_chmod(path.dentry, path.mnt, mode);
49169 if (error)
49170 goto out_unlock;
49171 if (mode == (mode_t) -1)
49172 mode = inode->i_mode;
49173 +
49174 + if (gr_handle_chroot_chmod(path.dentry, path.mnt, mode)) {
49175 + error = -EACCES;
49176 + goto out_unlock;
49177 + }
49178 +
49179 newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
49180 newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
49181 error = notify_change(path.dentry, &newattrs);
49182 @@ -528,6 +581,9 @@ static int chown_common(struct path *pat
49183 int error;
49184 struct iattr newattrs;
49185
49186 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
49187 + return -EACCES;
49188 +
49189 newattrs.ia_valid = ATTR_CTIME;
49190 if (user != (uid_t) -1) {
49191 newattrs.ia_valid |= ATTR_UID;
49192 @@ -998,7 +1054,10 @@ long do_sys_open(int dfd, const char __u
49193 if (!IS_ERR(tmp)) {
49194 fd = get_unused_fd_flags(flags);
49195 if (fd >= 0) {
49196 - struct file *f = do_filp_open(dfd, tmp, &op, lookup);
49197 + struct file *f;
49198 + /* don't allow to be set by userland */
49199 + flags &= ~FMODE_GREXEC;
49200 + f = do_filp_open(dfd, tmp, &op, lookup);
49201 if (IS_ERR(f)) {
49202 put_unused_fd(fd);
49203 fd = PTR_ERR(f);
49204 diff -urNp linux-2.6.39/fs/partitions/ldm.c linux-2.6.39/fs/partitions/ldm.c
49205 --- linux-2.6.39/fs/partitions/ldm.c 2011-05-19 00:06:34.000000000 -0400
49206 +++ linux-2.6.39/fs/partitions/ldm.c 2011-05-22 19:41:37.000000000 -0400
49207 @@ -1311,6 +1311,7 @@ static bool ldm_frag_add (const u8 *data
49208 ldm_error ("A VBLK claims to have %d parts.", num);
49209 return false;
49210 }
49211 +
49212 if (rec >= num) {
49213 ldm_error("REC value (%d) exceeds NUM value (%d)", rec, num);
49214 return false;
49215 @@ -1322,7 +1323,7 @@ static bool ldm_frag_add (const u8 *data
49216 goto found;
49217 }
49218
49219 - f = kmalloc (sizeof (*f) + size*num, GFP_KERNEL);
49220 + f = kmalloc (size*num + sizeof (*f), GFP_KERNEL);
49221 if (!f) {
49222 ldm_crit ("Out of memory.");
49223 return false;
49224 diff -urNp linux-2.6.39/fs/pipe.c linux-2.6.39/fs/pipe.c
49225 --- linux-2.6.39/fs/pipe.c 2011-05-19 00:06:34.000000000 -0400
49226 +++ linux-2.6.39/fs/pipe.c 2011-05-22 19:41:37.000000000 -0400
49227 @@ -420,9 +420,9 @@ redo:
49228 }
49229 if (bufs) /* More to do? */
49230 continue;
49231 - if (!pipe->writers)
49232 + if (!atomic_read(&pipe->writers))
49233 break;
49234 - if (!pipe->waiting_writers) {
49235 + if (!atomic_read(&pipe->waiting_writers)) {
49236 /* syscall merging: Usually we must not sleep
49237 * if O_NONBLOCK is set, or if we got some data.
49238 * But if a writer sleeps in kernel space, then
49239 @@ -481,7 +481,7 @@ pipe_write(struct kiocb *iocb, const str
49240 mutex_lock(&inode->i_mutex);
49241 pipe = inode->i_pipe;
49242
49243 - if (!pipe->readers) {
49244 + if (!atomic_read(&pipe->readers)) {
49245 send_sig(SIGPIPE, current, 0);
49246 ret = -EPIPE;
49247 goto out;
49248 @@ -530,7 +530,7 @@ redo1:
49249 for (;;) {
49250 int bufs;
49251
49252 - if (!pipe->readers) {
49253 + if (!atomic_read(&pipe->readers)) {
49254 send_sig(SIGPIPE, current, 0);
49255 if (!ret)
49256 ret = -EPIPE;
49257 @@ -616,9 +616,9 @@ redo2:
49258 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
49259 do_wakeup = 0;
49260 }
49261 - pipe->waiting_writers++;
49262 + atomic_inc(&pipe->waiting_writers);
49263 pipe_wait(pipe);
49264 - pipe->waiting_writers--;
49265 + atomic_dec(&pipe->waiting_writers);
49266 }
49267 out:
49268 mutex_unlock(&inode->i_mutex);
49269 @@ -685,7 +685,7 @@ pipe_poll(struct file *filp, poll_table
49270 mask = 0;
49271 if (filp->f_mode & FMODE_READ) {
49272 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
49273 - if (!pipe->writers && filp->f_version != pipe->w_counter)
49274 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
49275 mask |= POLLHUP;
49276 }
49277
49278 @@ -695,7 +695,7 @@ pipe_poll(struct file *filp, poll_table
49279 * Most Unices do not set POLLERR for FIFOs but on Linux they
49280 * behave exactly like pipes for poll().
49281 */
49282 - if (!pipe->readers)
49283 + if (!atomic_read(&pipe->readers))
49284 mask |= POLLERR;
49285 }
49286
49287 @@ -709,10 +709,10 @@ pipe_release(struct inode *inode, int de
49288
49289 mutex_lock(&inode->i_mutex);
49290 pipe = inode->i_pipe;
49291 - pipe->readers -= decr;
49292 - pipe->writers -= decw;
49293 + atomic_sub(decr, &pipe->readers);
49294 + atomic_sub(decw, &pipe->writers);
49295
49296 - if (!pipe->readers && !pipe->writers) {
49297 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
49298 free_pipe_info(inode);
49299 } else {
49300 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
49301 @@ -802,7 +802,7 @@ pipe_read_open(struct inode *inode, stru
49302
49303 if (inode->i_pipe) {
49304 ret = 0;
49305 - inode->i_pipe->readers++;
49306 + atomic_inc(&inode->i_pipe->readers);
49307 }
49308
49309 mutex_unlock(&inode->i_mutex);
49310 @@ -819,7 +819,7 @@ pipe_write_open(struct inode *inode, str
49311
49312 if (inode->i_pipe) {
49313 ret = 0;
49314 - inode->i_pipe->writers++;
49315 + atomic_inc(&inode->i_pipe->writers);
49316 }
49317
49318 mutex_unlock(&inode->i_mutex);
49319 @@ -837,9 +837,9 @@ pipe_rdwr_open(struct inode *inode, stru
49320 if (inode->i_pipe) {
49321 ret = 0;
49322 if (filp->f_mode & FMODE_READ)
49323 - inode->i_pipe->readers++;
49324 + atomic_inc(&inode->i_pipe->readers);
49325 if (filp->f_mode & FMODE_WRITE)
49326 - inode->i_pipe->writers++;
49327 + atomic_inc(&inode->i_pipe->writers);
49328 }
49329
49330 mutex_unlock(&inode->i_mutex);
49331 @@ -931,7 +931,7 @@ void free_pipe_info(struct inode *inode)
49332 inode->i_pipe = NULL;
49333 }
49334
49335 -static struct vfsmount *pipe_mnt __read_mostly;
49336 +struct vfsmount *pipe_mnt __read_mostly;
49337
49338 /*
49339 * pipefs_dname() is called from d_path().
49340 @@ -961,7 +961,8 @@ static struct inode * get_pipe_inode(voi
49341 goto fail_iput;
49342 inode->i_pipe = pipe;
49343
49344 - pipe->readers = pipe->writers = 1;
49345 + atomic_set(&pipe->readers, 1);
49346 + atomic_set(&pipe->writers, 1);
49347 inode->i_fop = &rdwr_pipefifo_fops;
49348
49349 /*
49350 diff -urNp linux-2.6.39/fs/proc/array.c linux-2.6.39/fs/proc/array.c
49351 --- linux-2.6.39/fs/proc/array.c 2011-05-19 00:06:34.000000000 -0400
49352 +++ linux-2.6.39/fs/proc/array.c 2011-05-22 19:41:37.000000000 -0400
49353 @@ -60,6 +60,7 @@
49354 #include <linux/tty.h>
49355 #include <linux/string.h>
49356 #include <linux/mman.h>
49357 +#include <linux/grsecurity.h>
49358 #include <linux/proc_fs.h>
49359 #include <linux/ioport.h>
49360 #include <linux/uaccess.h>
49361 @@ -337,6 +338,21 @@ static void task_cpus_allowed(struct seq
49362 seq_putc(m, '\n');
49363 }
49364
49365 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
49366 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
49367 +{
49368 + if (p->mm)
49369 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
49370 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
49371 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
49372 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
49373 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
49374 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
49375 + else
49376 + seq_printf(m, "PaX:\t-----\n");
49377 +}
49378 +#endif
49379 +
49380 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
49381 struct pid *pid, struct task_struct *task)
49382 {
49383 @@ -354,9 +370,24 @@ int proc_pid_status(struct seq_file *m,
49384 task_cpus_allowed(m, task);
49385 cpuset_task_status_allowed(m, task);
49386 task_context_switch_counts(m, task);
49387 +
49388 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
49389 + task_pax(m, task);
49390 +#endif
49391 +
49392 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
49393 + task_grsec_rbac(m, task);
49394 +#endif
49395 +
49396 return 0;
49397 }
49398
49399 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49400 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49401 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
49402 + _mm->pax_flags & MF_PAX_SEGMEXEC))
49403 +#endif
49404 +
49405 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
49406 struct pid *pid, struct task_struct *task, int whole)
49407 {
49408 @@ -375,9 +406,11 @@ static int do_task_stat(struct seq_file
49409 cputime_t cutime, cstime, utime, stime;
49410 cputime_t cgtime, gtime;
49411 unsigned long rsslim = 0;
49412 - char tcomm[sizeof(task->comm)];
49413 + char tcomm[sizeof(task->comm)] = { 0 };
49414 unsigned long flags;
49415
49416 + pax_track_stack();
49417 +
49418 state = *get_task_state(task);
49419 vsize = eip = esp = 0;
49420 permitted = ptrace_may_access(task, PTRACE_MODE_READ);
49421 @@ -449,6 +482,19 @@ static int do_task_stat(struct seq_file
49422 gtime = task->gtime;
49423 }
49424
49425 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49426 + if (PAX_RAND_FLAGS(mm)) {
49427 + eip = 0;
49428 + esp = 0;
49429 + wchan = 0;
49430 + }
49431 +#endif
49432 +#ifdef CONFIG_GRKERNSEC_HIDESYM
49433 + wchan = 0;
49434 + eip =0;
49435 + esp =0;
49436 +#endif
49437 +
49438 /* scale priority and nice values from timeslices to -20..20 */
49439 /* to make it look like a "normal" Unix priority/nice value */
49440 priority = task_prio(task);
49441 @@ -489,9 +535,15 @@ static int do_task_stat(struct seq_file
49442 vsize,
49443 mm ? get_mm_rss(mm) : 0,
49444 rsslim,
49445 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49446 + PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0),
49447 + PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0),
49448 + PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0),
49449 +#else
49450 mm ? (permitted ? mm->start_code : 1) : 0,
49451 mm ? (permitted ? mm->end_code : 1) : 0,
49452 (permitted && mm) ? mm->start_stack : 0,
49453 +#endif
49454 esp,
49455 eip,
49456 /* The signal information here is obsolete.
49457 @@ -544,3 +596,18 @@ int proc_pid_statm(struct seq_file *m, s
49458
49459 return 0;
49460 }
49461 +
49462 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49463 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
49464 +{
49465 + u32 curr_ip = 0;
49466 + unsigned long flags;
49467 +
49468 + if (lock_task_sighand(task, &flags)) {
49469 + curr_ip = task->signal->curr_ip;
49470 + unlock_task_sighand(task, &flags);
49471 + }
49472 +
49473 + return sprintf(buffer, "%pI4\n", &curr_ip);
49474 +}
49475 +#endif
49476 diff -urNp linux-2.6.39/fs/proc/base.c linux-2.6.39/fs/proc/base.c
49477 --- linux-2.6.39/fs/proc/base.c 2011-05-19 00:06:34.000000000 -0400
49478 +++ linux-2.6.39/fs/proc/base.c 2011-05-22 21:50:17.000000000 -0400
49479 @@ -104,6 +104,22 @@ struct pid_entry {
49480 union proc_op op;
49481 };
49482
49483 +struct getdents_callback {
49484 + struct linux_dirent __user * current_dir;
49485 + struct linux_dirent __user * previous;
49486 + struct file * file;
49487 + int count;
49488 + int error;
49489 +};
49490 +
49491 +static int gr_fake_filldir(void * __buf, const char *name, int namlen,
49492 + loff_t offset, u64 ino, unsigned int d_type)
49493 +{
49494 + struct getdents_callback * buf = (struct getdents_callback *) __buf;
49495 + buf->error = -EINVAL;
49496 + return 0;
49497 +}
49498 +
49499 #define NOD(NAME, MODE, IOP, FOP, OP) { \
49500 .name = (NAME), \
49501 .len = sizeof(NAME) - 1, \
49502 @@ -206,6 +222,9 @@ static struct mm_struct *__check_mem_per
49503 if (task == current)
49504 return mm;
49505
49506 + if (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))
49507 + return ERR_PTR(-EPERM);
49508 +
49509 /*
49510 * If current is actively ptrace'ing, and would also be
49511 * permitted to freshly attach with ptrace now, permit it.
49512 @@ -279,6 +298,9 @@ static int proc_pid_cmdline(struct task_
49513 if (!mm->arg_end)
49514 goto out_mm; /* Shh! No looking before we're done */
49515
49516 + if (gr_acl_handle_procpidmem(task))
49517 + goto out_mm;
49518 +
49519 len = mm->arg_end - mm->arg_start;
49520
49521 if (len > PAGE_SIZE)
49522 @@ -306,12 +328,28 @@ out:
49523 return res;
49524 }
49525
49526 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49527 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49528 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
49529 + _mm->pax_flags & MF_PAX_SEGMEXEC))
49530 +#endif
49531 +
49532 static int proc_pid_auxv(struct task_struct *task, char *buffer)
49533 {
49534 struct mm_struct *mm = mm_for_maps(task);
49535 int res = PTR_ERR(mm);
49536 if (mm && !IS_ERR(mm)) {
49537 unsigned int nwords = 0;
49538 +
49539 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49540 + /* allow if we're currently ptracing this task */
49541 + if (PAX_RAND_FLAGS(mm) &&
49542 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
49543 + mmput(mm);
49544 + return res;
49545 + }
49546 +#endif
49547 +
49548 do {
49549 nwords += 2;
49550 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
49551 @@ -325,7 +363,7 @@ static int proc_pid_auxv(struct task_str
49552 }
49553
49554
49555 -#ifdef CONFIG_KALLSYMS
49556 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49557 /*
49558 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
49559 * Returns the resolved symbol. If that fails, simply return the address.
49560 @@ -364,7 +402,7 @@ static void unlock_trace(struct task_str
49561 mutex_unlock(&task->signal->cred_guard_mutex);
49562 }
49563
49564 -#ifdef CONFIG_STACKTRACE
49565 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49566
49567 #define MAX_STACK_TRACE_DEPTH 64
49568
49569 @@ -555,7 +593,7 @@ static int proc_pid_limits(struct task_s
49570 return count;
49571 }
49572
49573 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49574 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49575 static int proc_pid_syscall(struct task_struct *task, char *buffer)
49576 {
49577 long nr;
49578 @@ -584,7 +622,7 @@ static int proc_pid_syscall(struct task_
49579 /************************************************************************/
49580
49581 /* permission checks */
49582 -static int proc_fd_access_allowed(struct inode *inode)
49583 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
49584 {
49585 struct task_struct *task;
49586 int allowed = 0;
49587 @@ -594,7 +632,10 @@ static int proc_fd_access_allowed(struct
49588 */
49589 task = get_proc_task(inode);
49590 if (task) {
49591 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
49592 + if (log)
49593 + allowed = ptrace_may_access_log(task, PTRACE_MODE_READ);
49594 + else
49595 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
49596 put_task_struct(task);
49597 }
49598 return allowed;
49599 @@ -973,6 +1014,9 @@ static ssize_t environ_read(struct file
49600 if (!task)
49601 goto out_no_task;
49602
49603 + if (gr_acl_handle_procpidmem(task))
49604 + goto out;
49605 +
49606 ret = -ENOMEM;
49607 page = (char *)__get_free_page(GFP_TEMPORARY);
49608 if (!page)
49609 @@ -1660,7 +1704,7 @@ static void *proc_pid_follow_link(struct
49610 path_put(&nd->path);
49611
49612 /* Are we allowed to snoop on the tasks file descriptors? */
49613 - if (!proc_fd_access_allowed(inode))
49614 + if (!proc_fd_access_allowed(inode,0))
49615 goto out;
49616
49617 error = PROC_I(inode)->op.proc_get_link(inode, &nd->path);
49618 @@ -1699,8 +1743,18 @@ static int proc_pid_readlink(struct dent
49619 struct path path;
49620
49621 /* Are we allowed to snoop on the tasks file descriptors? */
49622 - if (!proc_fd_access_allowed(inode))
49623 - goto out;
49624 + /* logging this is needed for learning on chromium to work properly,
49625 + but we don't want to flood the logs from 'ps' which does a readlink
49626 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
49627 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
49628 + */
49629 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
49630 + if (!proc_fd_access_allowed(inode,0))
49631 + goto out;
49632 + } else {
49633 + if (!proc_fd_access_allowed(inode,1))
49634 + goto out;
49635 + }
49636
49637 error = PROC_I(inode)->op.proc_get_link(inode, &path);
49638 if (error)
49639 @@ -1766,7 +1820,11 @@ static struct inode *proc_pid_make_inode
49640 rcu_read_lock();
49641 cred = __task_cred(task);
49642 inode->i_uid = cred->euid;
49643 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49644 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
49645 +#else
49646 inode->i_gid = cred->egid;
49647 +#endif
49648 rcu_read_unlock();
49649 }
49650 security_task_to_inode(task, inode);
49651 @@ -1784,6 +1842,9 @@ static int pid_getattr(struct vfsmount *
49652 struct inode *inode = dentry->d_inode;
49653 struct task_struct *task;
49654 const struct cred *cred;
49655 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49656 + const struct cred *tmpcred = current_cred();
49657 +#endif
49658
49659 generic_fillattr(inode, stat);
49660
49661 @@ -1791,12 +1852,34 @@ static int pid_getattr(struct vfsmount *
49662 stat->uid = 0;
49663 stat->gid = 0;
49664 task = pid_task(proc_pid(inode), PIDTYPE_PID);
49665 +
49666 + if (task && (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))) {
49667 + rcu_read_unlock();
49668 + return -ENOENT;
49669 + }
49670 +
49671 if (task) {
49672 + cred = __task_cred(task);
49673 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49674 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
49675 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49676 + || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
49677 +#endif
49678 + )
49679 +#endif
49680 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49681 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49682 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49683 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49684 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49685 +#endif
49686 task_dumpable(task)) {
49687 - cred = __task_cred(task);
49688 stat->uid = cred->euid;
49689 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49690 + stat->gid = CONFIG_GRKERNSEC_PROC_GID;
49691 +#else
49692 stat->gid = cred->egid;
49693 +#endif
49694 }
49695 }
49696 rcu_read_unlock();
49697 @@ -1834,11 +1917,20 @@ static int pid_revalidate(struct dentry
49698
49699 if (task) {
49700 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49701 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49702 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49703 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49704 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49705 +#endif
49706 task_dumpable(task)) {
49707 rcu_read_lock();
49708 cred = __task_cred(task);
49709 inode->i_uid = cred->euid;
49710 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49711 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
49712 +#else
49713 inode->i_gid = cred->egid;
49714 +#endif
49715 rcu_read_unlock();
49716 } else {
49717 inode->i_uid = 0;
49718 @@ -1959,7 +2051,8 @@ static int proc_fd_info(struct inode *in
49719 int fd = proc_fd(inode);
49720
49721 if (task) {
49722 - files = get_files_struct(task);
49723 + if (!gr_acl_handle_procpidmem(task))
49724 + files = get_files_struct(task);
49725 put_task_struct(task);
49726 }
49727 if (files) {
49728 @@ -2219,15 +2312,25 @@ static const struct file_operations proc
49729 */
49730 static int proc_fd_permission(struct inode *inode, int mask, unsigned int flags)
49731 {
49732 + struct task_struct *task;
49733 int rv;
49734
49735 if (flags & IPERM_FLAG_RCU)
49736 return -ECHILD;
49737 rv = generic_permission(inode, mask, flags, NULL);
49738 - if (rv == 0)
49739 - return 0;
49740 +
49741 if (task_pid(current) == proc_pid(inode))
49742 rv = 0;
49743 +
49744 + task = get_proc_task(inode);
49745 + if (task == NULL)
49746 + return rv;
49747 +
49748 + if (gr_acl_handle_procpidmem(task))
49749 + rv = -EACCES;
49750 +
49751 + put_task_struct(task);
49752 +
49753 return rv;
49754 }
49755
49756 @@ -2337,6 +2440,9 @@ static struct dentry *proc_pident_lookup
49757 if (!task)
49758 goto out_no_task;
49759
49760 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49761 + goto out;
49762 +
49763 /*
49764 * Yes, it does not scale. And it should not. Don't add
49765 * new entries into /proc/<tgid>/ without very good reasons.
49766 @@ -2381,6 +2487,9 @@ static int proc_pident_readdir(struct fi
49767 if (!task)
49768 goto out_no_task;
49769
49770 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49771 + goto out;
49772 +
49773 ret = 0;
49774 i = filp->f_pos;
49775 switch (i) {
49776 @@ -2651,7 +2760,7 @@ static void *proc_self_follow_link(struc
49777 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
49778 void *cookie)
49779 {
49780 - char *s = nd_get_link(nd);
49781 + const char *s = nd_get_link(nd);
49782 if (!IS_ERR(s))
49783 __putname(s);
49784 }
49785 @@ -2835,7 +2944,7 @@ static const struct pid_entry tgid_base_
49786 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
49787 #endif
49788 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49789 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49790 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49791 INF("syscall", S_IRUGO, proc_pid_syscall),
49792 #endif
49793 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49794 @@ -2860,10 +2969,10 @@ static const struct pid_entry tgid_base_
49795 #ifdef CONFIG_SECURITY
49796 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49797 #endif
49798 -#ifdef CONFIG_KALLSYMS
49799 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49800 INF("wchan", S_IRUGO, proc_pid_wchan),
49801 #endif
49802 -#ifdef CONFIG_STACKTRACE
49803 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49804 ONE("stack", S_IRUGO, proc_pid_stack),
49805 #endif
49806 #ifdef CONFIG_SCHEDSTATS
49807 @@ -2894,6 +3003,9 @@ static const struct pid_entry tgid_base_
49808 #ifdef CONFIG_TASK_IO_ACCOUNTING
49809 INF("io", S_IRUGO, proc_tgid_io_accounting),
49810 #endif
49811 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49812 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
49813 +#endif
49814 };
49815
49816 static int proc_tgid_base_readdir(struct file * filp,
49817 @@ -3019,7 +3131,14 @@ static struct dentry *proc_pid_instantia
49818 if (!inode)
49819 goto out;
49820
49821 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49822 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
49823 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49824 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
49825 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
49826 +#else
49827 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
49828 +#endif
49829 inode->i_op = &proc_tgid_base_inode_operations;
49830 inode->i_fop = &proc_tgid_base_operations;
49831 inode->i_flags|=S_IMMUTABLE;
49832 @@ -3061,7 +3180,11 @@ struct dentry *proc_pid_lookup(struct in
49833 if (!task)
49834 goto out;
49835
49836 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49837 + goto out_put_task;
49838 +
49839 result = proc_pid_instantiate(dir, dentry, task, NULL);
49840 +out_put_task:
49841 put_task_struct(task);
49842 out:
49843 return result;
49844 @@ -3126,6 +3249,11 @@ int proc_pid_readdir(struct file * filp,
49845 {
49846 unsigned int nr;
49847 struct task_struct *reaper;
49848 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49849 + const struct cred *tmpcred = current_cred();
49850 + const struct cred *itercred;
49851 +#endif
49852 + filldir_t __filldir = filldir;
49853 struct tgid_iter iter;
49854 struct pid_namespace *ns;
49855
49856 @@ -3149,8 +3277,27 @@ int proc_pid_readdir(struct file * filp,
49857 for (iter = next_tgid(ns, iter);
49858 iter.task;
49859 iter.tgid += 1, iter = next_tgid(ns, iter)) {
49860 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49861 + rcu_read_lock();
49862 + itercred = __task_cred(iter.task);
49863 +#endif
49864 + if (gr_pid_is_chrooted(iter.task) || gr_check_hidden_task(iter.task)
49865 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49866 + || (tmpcred->uid && (itercred->uid != tmpcred->uid)
49867 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49868 + && !in_group_p(CONFIG_GRKERNSEC_PROC_GID)
49869 +#endif
49870 + )
49871 +#endif
49872 + )
49873 + __filldir = &gr_fake_filldir;
49874 + else
49875 + __filldir = filldir;
49876 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49877 + rcu_read_unlock();
49878 +#endif
49879 filp->f_pos = iter.tgid + TGID_OFFSET;
49880 - if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
49881 + if (proc_pid_fill_cache(filp, dirent, __filldir, iter) < 0) {
49882 put_task_struct(iter.task);
49883 goto out;
49884 }
49885 @@ -3177,7 +3324,7 @@ static const struct pid_entry tid_base_s
49886 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
49887 #endif
49888 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49889 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49890 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49891 INF("syscall", S_IRUGO, proc_pid_syscall),
49892 #endif
49893 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49894 @@ -3201,10 +3348,10 @@ static const struct pid_entry tid_base_s
49895 #ifdef CONFIG_SECURITY
49896 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49897 #endif
49898 -#ifdef CONFIG_KALLSYMS
49899 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49900 INF("wchan", S_IRUGO, proc_pid_wchan),
49901 #endif
49902 -#ifdef CONFIG_STACKTRACE
49903 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49904 ONE("stack", S_IRUGO, proc_pid_stack),
49905 #endif
49906 #ifdef CONFIG_SCHEDSTATS
49907 diff -urNp linux-2.6.39/fs/proc/cmdline.c linux-2.6.39/fs/proc/cmdline.c
49908 --- linux-2.6.39/fs/proc/cmdline.c 2011-05-19 00:06:34.000000000 -0400
49909 +++ linux-2.6.39/fs/proc/cmdline.c 2011-05-22 19:41:37.000000000 -0400
49910 @@ -23,7 +23,11 @@ static const struct file_operations cmdl
49911
49912 static int __init proc_cmdline_init(void)
49913 {
49914 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49915 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
49916 +#else
49917 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
49918 +#endif
49919 return 0;
49920 }
49921 module_init(proc_cmdline_init);
49922 diff -urNp linux-2.6.39/fs/proc/devices.c linux-2.6.39/fs/proc/devices.c
49923 --- linux-2.6.39/fs/proc/devices.c 2011-05-19 00:06:34.000000000 -0400
49924 +++ linux-2.6.39/fs/proc/devices.c 2011-05-22 19:41:37.000000000 -0400
49925 @@ -64,7 +64,11 @@ static const struct file_operations proc
49926
49927 static int __init proc_devices_init(void)
49928 {
49929 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49930 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
49931 +#else
49932 proc_create("devices", 0, NULL, &proc_devinfo_operations);
49933 +#endif
49934 return 0;
49935 }
49936 module_init(proc_devices_init);
49937 diff -urNp linux-2.6.39/fs/proc/inode.c linux-2.6.39/fs/proc/inode.c
49938 --- linux-2.6.39/fs/proc/inode.c 2011-05-19 00:06:34.000000000 -0400
49939 +++ linux-2.6.39/fs/proc/inode.c 2011-05-22 19:41:37.000000000 -0400
49940 @@ -433,7 +433,11 @@ struct inode *proc_get_inode(struct supe
49941 if (de->mode) {
49942 inode->i_mode = de->mode;
49943 inode->i_uid = de->uid;
49944 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49945 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
49946 +#else
49947 inode->i_gid = de->gid;
49948 +#endif
49949 }
49950 if (de->size)
49951 inode->i_size = de->size;
49952 diff -urNp linux-2.6.39/fs/proc/internal.h linux-2.6.39/fs/proc/internal.h
49953 --- linux-2.6.39/fs/proc/internal.h 2011-05-19 00:06:34.000000000 -0400
49954 +++ linux-2.6.39/fs/proc/internal.h 2011-05-22 19:41:37.000000000 -0400
49955 @@ -51,6 +51,9 @@ extern int proc_pid_status(struct seq_fi
49956 struct pid *pid, struct task_struct *task);
49957 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
49958 struct pid *pid, struct task_struct *task);
49959 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49960 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
49961 +#endif
49962 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
49963
49964 extern const struct file_operations proc_maps_operations;
49965 diff -urNp linux-2.6.39/fs/proc/Kconfig linux-2.6.39/fs/proc/Kconfig
49966 --- linux-2.6.39/fs/proc/Kconfig 2011-05-19 00:06:34.000000000 -0400
49967 +++ linux-2.6.39/fs/proc/Kconfig 2011-05-22 19:41:37.000000000 -0400
49968 @@ -30,12 +30,12 @@ config PROC_FS
49969
49970 config PROC_KCORE
49971 bool "/proc/kcore support" if !ARM
49972 - depends on PROC_FS && MMU
49973 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
49974
49975 config PROC_VMCORE
49976 bool "/proc/vmcore support"
49977 - depends on PROC_FS && CRASH_DUMP
49978 - default y
49979 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
49980 + default n
49981 help
49982 Exports the dump image of crashed kernel in ELF format.
49983
49984 @@ -59,8 +59,8 @@ config PROC_SYSCTL
49985 limited in memory.
49986
49987 config PROC_PAGE_MONITOR
49988 - default y
49989 - depends on PROC_FS && MMU
49990 + default n
49991 + depends on PROC_FS && MMU && !GRKERNSEC
49992 bool "Enable /proc page monitoring" if EXPERT
49993 help
49994 Various /proc files exist to monitor process memory utilization:
49995 diff -urNp linux-2.6.39/fs/proc/kcore.c linux-2.6.39/fs/proc/kcore.c
49996 --- linux-2.6.39/fs/proc/kcore.c 2011-05-19 00:06:34.000000000 -0400
49997 +++ linux-2.6.39/fs/proc/kcore.c 2011-05-22 19:41:37.000000000 -0400
49998 @@ -321,6 +321,8 @@ static void elf_kcore_store_hdr(char *bu
49999 off_t offset = 0;
50000 struct kcore_list *m;
50001
50002 + pax_track_stack();
50003 +
50004 /* setup ELF header */
50005 elf = (struct elfhdr *) bufp;
50006 bufp += sizeof(struct elfhdr);
50007 @@ -478,9 +480,10 @@ read_kcore(struct file *file, char __use
50008 * the addresses in the elf_phdr on our list.
50009 */
50010 start = kc_offset_to_vaddr(*fpos - elf_buflen);
50011 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
50012 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
50013 + if (tsz > buflen)
50014 tsz = buflen;
50015 -
50016 +
50017 while (buflen) {
50018 struct kcore_list *m;
50019
50020 @@ -509,20 +512,23 @@ read_kcore(struct file *file, char __use
50021 kfree(elf_buf);
50022 } else {
50023 if (kern_addr_valid(start)) {
50024 - unsigned long n;
50025 + char *elf_buf;
50026 + mm_segment_t oldfs;
50027
50028 - n = copy_to_user(buffer, (char *)start, tsz);
50029 - /*
50030 - * We cannot distingush between fault on source
50031 - * and fault on destination. When this happens
50032 - * we clear too and hope it will trigger the
50033 - * EFAULT again.
50034 - */
50035 - if (n) {
50036 - if (clear_user(buffer + tsz - n,
50037 - n))
50038 + elf_buf = kmalloc(tsz, GFP_KERNEL);
50039 + if (!elf_buf)
50040 + return -ENOMEM;
50041 + oldfs = get_fs();
50042 + set_fs(KERNEL_DS);
50043 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
50044 + set_fs(oldfs);
50045 + if (copy_to_user(buffer, elf_buf, tsz)) {
50046 + kfree(elf_buf);
50047 return -EFAULT;
50048 + }
50049 }
50050 + set_fs(oldfs);
50051 + kfree(elf_buf);
50052 } else {
50053 if (clear_user(buffer, tsz))
50054 return -EFAULT;
50055 @@ -542,6 +548,9 @@ read_kcore(struct file *file, char __use
50056
50057 static int open_kcore(struct inode *inode, struct file *filp)
50058 {
50059 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
50060 + return -EPERM;
50061 +#endif
50062 if (!capable(CAP_SYS_RAWIO))
50063 return -EPERM;
50064 if (kcore_need_update)
50065 diff -urNp linux-2.6.39/fs/proc/meminfo.c linux-2.6.39/fs/proc/meminfo.c
50066 --- linux-2.6.39/fs/proc/meminfo.c 2011-05-19 00:06:34.000000000 -0400
50067 +++ linux-2.6.39/fs/proc/meminfo.c 2011-05-22 19:36:32.000000000 -0400
50068 @@ -29,6 +29,8 @@ static int meminfo_proc_show(struct seq_
50069 unsigned long pages[NR_LRU_LISTS];
50070 int lru;
50071
50072 + pax_track_stack();
50073 +
50074 /*
50075 * display in kilobytes.
50076 */
50077 @@ -157,7 +159,7 @@ static int meminfo_proc_show(struct seq_
50078 vmi.used >> 10,
50079 vmi.largest_chunk >> 10
50080 #ifdef CONFIG_MEMORY_FAILURE
50081 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
50082 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
50083 #endif
50084 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
50085 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
50086 diff -urNp linux-2.6.39/fs/proc/nommu.c linux-2.6.39/fs/proc/nommu.c
50087 --- linux-2.6.39/fs/proc/nommu.c 2011-05-19 00:06:34.000000000 -0400
50088 +++ linux-2.6.39/fs/proc/nommu.c 2011-05-22 19:36:32.000000000 -0400
50089 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_
50090 if (len < 1)
50091 len = 1;
50092 seq_printf(m, "%*c", len, ' ');
50093 - seq_path(m, &file->f_path, "");
50094 + seq_path(m, &file->f_path, "\n\\");
50095 }
50096
50097 seq_putc(m, '\n');
50098 diff -urNp linux-2.6.39/fs/proc/proc_net.c linux-2.6.39/fs/proc/proc_net.c
50099 --- linux-2.6.39/fs/proc/proc_net.c 2011-05-19 00:06:34.000000000 -0400
50100 +++ linux-2.6.39/fs/proc/proc_net.c 2011-05-22 19:41:37.000000000 -0400
50101 @@ -105,6 +105,17 @@ static struct net *get_proc_task_net(str
50102 struct task_struct *task;
50103 struct nsproxy *ns;
50104 struct net *net = NULL;
50105 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50106 + const struct cred *cred = current_cred();
50107 +#endif
50108 +
50109 +#ifdef CONFIG_GRKERNSEC_PROC_USER
50110 + if (cred->fsuid)
50111 + return net;
50112 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50113 + if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
50114 + return net;
50115 +#endif
50116
50117 rcu_read_lock();
50118 task = pid_task(proc_pid(dir), PIDTYPE_PID);
50119 diff -urNp linux-2.6.39/fs/proc/proc_sysctl.c linux-2.6.39/fs/proc/proc_sysctl.c
50120 --- linux-2.6.39/fs/proc/proc_sysctl.c 2011-05-19 00:06:34.000000000 -0400
50121 +++ linux-2.6.39/fs/proc/proc_sysctl.c 2011-05-22 19:41:37.000000000 -0400
50122 @@ -8,6 +8,8 @@
50123 #include <linux/namei.h>
50124 #include "internal.h"
50125
50126 +extern __u32 gr_handle_sysctl(const struct ctl_table *table, const int op);
50127 +
50128 static const struct dentry_operations proc_sys_dentry_operations;
50129 static const struct file_operations proc_sys_file_operations;
50130 static const struct inode_operations proc_sys_inode_operations;
50131 @@ -111,6 +113,9 @@ static struct dentry *proc_sys_lookup(st
50132 if (!p)
50133 goto out;
50134
50135 + if (gr_handle_sysctl(p, MAY_EXEC))
50136 + goto out;
50137 +
50138 err = ERR_PTR(-ENOMEM);
50139 inode = proc_sys_make_inode(dir->i_sb, h ? h : head, p);
50140 if (h)
50141 @@ -230,6 +235,9 @@ static int scan(struct ctl_table_header
50142 if (*pos < file->f_pos)
50143 continue;
50144
50145 + if (gr_handle_sysctl(table, 0))
50146 + continue;
50147 +
50148 res = proc_sys_fill_cache(file, dirent, filldir, head, table);
50149 if (res)
50150 return res;
50151 @@ -358,6 +366,9 @@ static int proc_sys_getattr(struct vfsmo
50152 if (IS_ERR(head))
50153 return PTR_ERR(head);
50154
50155 + if (table && gr_handle_sysctl(table, MAY_EXEC))
50156 + return -ENOENT;
50157 +
50158 generic_fillattr(inode, stat);
50159 if (table)
50160 stat->mode = (stat->mode & S_IFMT) | table->mode;
50161 diff -urNp linux-2.6.39/fs/proc/root.c linux-2.6.39/fs/proc/root.c
50162 --- linux-2.6.39/fs/proc/root.c 2011-05-19 00:06:34.000000000 -0400
50163 +++ linux-2.6.39/fs/proc/root.c 2011-05-22 19:41:37.000000000 -0400
50164 @@ -122,7 +122,15 @@ void __init proc_root_init(void)
50165 #ifdef CONFIG_PROC_DEVICETREE
50166 proc_device_tree_init();
50167 #endif
50168 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
50169 +#ifdef CONFIG_GRKERNSEC_PROC_USER
50170 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
50171 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50172 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
50173 +#endif
50174 +#else
50175 proc_mkdir("bus", NULL);
50176 +#endif
50177 proc_sys_init();
50178 }
50179
50180 diff -urNp linux-2.6.39/fs/proc/task_mmu.c linux-2.6.39/fs/proc/task_mmu.c
50181 --- linux-2.6.39/fs/proc/task_mmu.c 2011-05-19 00:06:34.000000000 -0400
50182 +++ linux-2.6.39/fs/proc/task_mmu.c 2011-05-22 22:43:29.000000000 -0400
50183 @@ -51,8 +51,13 @@ void task_mem(struct seq_file *m, struct
50184 "VmExe:\t%8lu kB\n"
50185 "VmLib:\t%8lu kB\n"
50186 "VmPTE:\t%8lu kB\n"
50187 - "VmSwap:\t%8lu kB\n",
50188 - hiwater_vm << (PAGE_SHIFT-10),
50189 + "VmSwap:\t%8lu kB\n"
50190 +
50191 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
50192 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
50193 +#endif
50194 +
50195 + ,hiwater_vm << (PAGE_SHIFT-10),
50196 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
50197 mm->locked_vm << (PAGE_SHIFT-10),
50198 hiwater_rss << (PAGE_SHIFT-10),
50199 @@ -60,7 +65,13 @@ void task_mem(struct seq_file *m, struct
50200 data << (PAGE_SHIFT-10),
50201 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
50202 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
50203 - swap << (PAGE_SHIFT-10));
50204 + swap << (PAGE_SHIFT-10)
50205 +
50206 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
50207 + , mm->context.user_cs_base, mm->context.user_cs_limit
50208 +#endif
50209 +
50210 + );
50211 }
50212
50213 unsigned long task_vsize(struct mm_struct *mm)
50214 @@ -207,6 +218,12 @@ static int do_maps_open(struct inode *in
50215 return ret;
50216 }
50217
50218 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50219 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
50220 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
50221 + _mm->pax_flags & MF_PAX_SEGMEXEC))
50222 +#endif
50223 +
50224 static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
50225 {
50226 struct mm_struct *mm = vma->vm_mm;
50227 @@ -225,13 +242,13 @@ static void show_map_vma(struct seq_file
50228 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
50229 }
50230
50231 - /* We don't show the stack guard page in /proc/maps */
50232 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50233 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
50234 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
50235 +#else
50236 start = vma->vm_start;
50237 - if (stack_guard_page_start(vma, start))
50238 - start += PAGE_SIZE;
50239 end = vma->vm_end;
50240 - if (stack_guard_page_end(vma, end))
50241 - end -= PAGE_SIZE;
50242 +#endif
50243
50244 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
50245 start,
50246 @@ -240,7 +257,11 @@ static void show_map_vma(struct seq_file
50247 flags & VM_WRITE ? 'w' : '-',
50248 flags & VM_EXEC ? 'x' : '-',
50249 flags & VM_MAYSHARE ? 's' : 'p',
50250 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50251 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
50252 +#else
50253 pgoff,
50254 +#endif
50255 MAJOR(dev), MINOR(dev), ino, &len);
50256
50257 /*
50258 @@ -249,7 +270,7 @@ static void show_map_vma(struct seq_file
50259 */
50260 if (file) {
50261 pad_len_spaces(m, len);
50262 - seq_path(m, &file->f_path, "\n");
50263 + seq_path(m, &file->f_path, "\n\\");
50264 } else {
50265 const char *name = arch_vma_name(vma);
50266 if (!name) {
50267 @@ -257,8 +278,9 @@ static void show_map_vma(struct seq_file
50268 if (vma->vm_start <= mm->brk &&
50269 vma->vm_end >= mm->start_brk) {
50270 name = "[heap]";
50271 - } else if (vma->vm_start <= mm->start_stack &&
50272 - vma->vm_end >= mm->start_stack) {
50273 + } else if ((vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
50274 + (vma->vm_start <= mm->start_stack &&
50275 + vma->vm_end >= mm->start_stack)) {
50276 name = "[stack]";
50277 }
50278 } else {
50279 @@ -433,11 +455,16 @@ static int show_smap(struct seq_file *m,
50280 };
50281
50282 memset(&mss, 0, sizeof mss);
50283 - mss.vma = vma;
50284 - /* mmap_sem is held in m_start */
50285 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
50286 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
50287 -
50288 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50289 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
50290 +#endif
50291 + mss.vma = vma;
50292 + /* mmap_sem is held in m_start */
50293 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
50294 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
50295 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50296 + }
50297 +#endif
50298 show_map_vma(m, vma);
50299
50300 seq_printf(m,
50301 @@ -455,7 +482,11 @@ static int show_smap(struct seq_file *m,
50302 "KernelPageSize: %8lu kB\n"
50303 "MMUPageSize: %8lu kB\n"
50304 "Locked: %8lu kB\n",
50305 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50306 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
50307 +#else
50308 (vma->vm_end - vma->vm_start) >> 10,
50309 +#endif
50310 mss.resident >> 10,
50311 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
50312 mss.shared_clean >> 10,
50313 diff -urNp linux-2.6.39/fs/proc/task_nommu.c linux-2.6.39/fs/proc/task_nommu.c
50314 --- linux-2.6.39/fs/proc/task_nommu.c 2011-05-19 00:06:34.000000000 -0400
50315 +++ linux-2.6.39/fs/proc/task_nommu.c 2011-05-22 19:36:32.000000000 -0400
50316 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct
50317 else
50318 bytes += kobjsize(mm);
50319
50320 - if (current->fs && current->fs->users > 1)
50321 + if (current->fs && atomic_read(&current->fs->users) > 1)
50322 sbytes += kobjsize(current->fs);
50323 else
50324 bytes += kobjsize(current->fs);
50325 @@ -166,7 +166,7 @@ static int nommu_vma_show(struct seq_fil
50326
50327 if (file) {
50328 pad_len_spaces(m, len);
50329 - seq_path(m, &file->f_path, "");
50330 + seq_path(m, &file->f_path, "\n\\");
50331 } else if (mm) {
50332 if (vma->vm_start <= mm->start_stack &&
50333 vma->vm_end >= mm->start_stack) {
50334 diff -urNp linux-2.6.39/fs/quota/netlink.c linux-2.6.39/fs/quota/netlink.c
50335 --- linux-2.6.39/fs/quota/netlink.c 2011-05-19 00:06:34.000000000 -0400
50336 +++ linux-2.6.39/fs/quota/netlink.c 2011-05-22 19:36:32.000000000 -0400
50337 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_fam
50338 void quota_send_warning(short type, unsigned int id, dev_t dev,
50339 const char warntype)
50340 {
50341 - static atomic_t seq;
50342 + static atomic_unchecked_t seq;
50343 struct sk_buff *skb;
50344 void *msg_head;
50345 int ret;
50346 @@ -49,7 +49,7 @@ void quota_send_warning(short type, unsi
50347 "VFS: Not enough memory to send quota warning.\n");
50348 return;
50349 }
50350 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
50351 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
50352 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
50353 if (!msg_head) {
50354 printk(KERN_ERR
50355 diff -urNp linux-2.6.39/fs/readdir.c linux-2.6.39/fs/readdir.c
50356 --- linux-2.6.39/fs/readdir.c 2011-05-19 00:06:34.000000000 -0400
50357 +++ linux-2.6.39/fs/readdir.c 2011-05-22 19:41:42.000000000 -0400
50358 @@ -17,6 +17,7 @@
50359 #include <linux/security.h>
50360 #include <linux/syscalls.h>
50361 #include <linux/unistd.h>
50362 +#include <linux/namei.h>
50363
50364 #include <asm/uaccess.h>
50365
50366 @@ -67,6 +68,7 @@ struct old_linux_dirent {
50367
50368 struct readdir_callback {
50369 struct old_linux_dirent __user * dirent;
50370 + struct file * file;
50371 int result;
50372 };
50373
50374 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, cons
50375 buf->result = -EOVERFLOW;
50376 return -EOVERFLOW;
50377 }
50378 +
50379 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50380 + return 0;
50381 +
50382 buf->result++;
50383 dirent = buf->dirent;
50384 if (!access_ok(VERIFY_WRITE, dirent,
50385 @@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned in
50386
50387 buf.result = 0;
50388 buf.dirent = dirent;
50389 + buf.file = file;
50390
50391 error = vfs_readdir(file, fillonedir, &buf);
50392 if (buf.result)
50393 @@ -142,6 +149,7 @@ struct linux_dirent {
50394 struct getdents_callback {
50395 struct linux_dirent __user * current_dir;
50396 struct linux_dirent __user * previous;
50397 + struct file * file;
50398 int count;
50399 int error;
50400 };
50401 @@ -163,6 +171,10 @@ static int filldir(void * __buf, const c
50402 buf->error = -EOVERFLOW;
50403 return -EOVERFLOW;
50404 }
50405 +
50406 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50407 + return 0;
50408 +
50409 dirent = buf->previous;
50410 if (dirent) {
50411 if (__put_user(offset, &dirent->d_off))
50412 @@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int,
50413 buf.previous = NULL;
50414 buf.count = count;
50415 buf.error = 0;
50416 + buf.file = file;
50417
50418 error = vfs_readdir(file, filldir, &buf);
50419 if (error >= 0)
50420 @@ -229,6 +242,7 @@ out:
50421 struct getdents_callback64 {
50422 struct linux_dirent64 __user * current_dir;
50423 struct linux_dirent64 __user * previous;
50424 + struct file *file;
50425 int count;
50426 int error;
50427 };
50428 @@ -244,6 +258,10 @@ static int filldir64(void * __buf, const
50429 buf->error = -EINVAL; /* only used if we fail.. */
50430 if (reclen > buf->count)
50431 return -EINVAL;
50432 +
50433 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50434 + return 0;
50435 +
50436 dirent = buf->previous;
50437 if (dirent) {
50438 if (__put_user(offset, &dirent->d_off))
50439 @@ -291,6 +309,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int
50440
50441 buf.current_dir = dirent;
50442 buf.previous = NULL;
50443 + buf.file = file;
50444 buf.count = count;
50445 buf.error = 0;
50446
50447 diff -urNp linux-2.6.39/fs/reiserfs/dir.c linux-2.6.39/fs/reiserfs/dir.c
50448 --- linux-2.6.39/fs/reiserfs/dir.c 2011-05-19 00:06:34.000000000 -0400
50449 +++ linux-2.6.39/fs/reiserfs/dir.c 2011-05-22 19:36:32.000000000 -0400
50450 @@ -66,6 +66,8 @@ int reiserfs_readdir_dentry(struct dentr
50451 struct reiserfs_dir_entry de;
50452 int ret = 0;
50453
50454 + pax_track_stack();
50455 +
50456 reiserfs_write_lock(inode->i_sb);
50457
50458 reiserfs_check_lock_depth(inode->i_sb, "readdir");
50459 diff -urNp linux-2.6.39/fs/reiserfs/do_balan.c linux-2.6.39/fs/reiserfs/do_balan.c
50460 --- linux-2.6.39/fs/reiserfs/do_balan.c 2011-05-19 00:06:34.000000000 -0400
50461 +++ linux-2.6.39/fs/reiserfs/do_balan.c 2011-05-22 19:36:32.000000000 -0400
50462 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb,
50463 return;
50464 }
50465
50466 - atomic_inc(&(fs_generation(tb->tb_sb)));
50467 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
50468 do_balance_starts(tb);
50469
50470 /* balance leaf returns 0 except if combining L R and S into
50471 diff -urNp linux-2.6.39/fs/reiserfs/item_ops.c linux-2.6.39/fs/reiserfs/item_ops.c
50472 --- linux-2.6.39/fs/reiserfs/item_ops.c 2011-05-19 00:06:34.000000000 -0400
50473 +++ linux-2.6.39/fs/reiserfs/item_ops.c 2011-05-22 19:36:32.000000000 -0400
50474 @@ -102,7 +102,7 @@ static void sd_print_vi(struct virtual_i
50475 vi->vi_index, vi->vi_type, vi->vi_ih);
50476 }
50477
50478 -static struct item_operations stat_data_ops = {
50479 +static const struct item_operations stat_data_ops = {
50480 .bytes_number = sd_bytes_number,
50481 .decrement_key = sd_decrement_key,
50482 .is_left_mergeable = sd_is_left_mergeable,
50483 @@ -196,7 +196,7 @@ static void direct_print_vi(struct virtu
50484 vi->vi_index, vi->vi_type, vi->vi_ih);
50485 }
50486
50487 -static struct item_operations direct_ops = {
50488 +static const struct item_operations direct_ops = {
50489 .bytes_number = direct_bytes_number,
50490 .decrement_key = direct_decrement_key,
50491 .is_left_mergeable = direct_is_left_mergeable,
50492 @@ -341,7 +341,7 @@ static void indirect_print_vi(struct vir
50493 vi->vi_index, vi->vi_type, vi->vi_ih);
50494 }
50495
50496 -static struct item_operations indirect_ops = {
50497 +static const struct item_operations indirect_ops = {
50498 .bytes_number = indirect_bytes_number,
50499 .decrement_key = indirect_decrement_key,
50500 .is_left_mergeable = indirect_is_left_mergeable,
50501 @@ -628,7 +628,7 @@ static void direntry_print_vi(struct vir
50502 printk("\n");
50503 }
50504
50505 -static struct item_operations direntry_ops = {
50506 +static const struct item_operations direntry_ops = {
50507 .bytes_number = direntry_bytes_number,
50508 .decrement_key = direntry_decrement_key,
50509 .is_left_mergeable = direntry_is_left_mergeable,
50510 @@ -724,7 +724,7 @@ static void errcatch_print_vi(struct vir
50511 "Invalid item type observed, run fsck ASAP");
50512 }
50513
50514 -static struct item_operations errcatch_ops = {
50515 +static const struct item_operations errcatch_ops = {
50516 errcatch_bytes_number,
50517 errcatch_decrement_key,
50518 errcatch_is_left_mergeable,
50519 @@ -746,7 +746,7 @@ static struct item_operations errcatch_o
50520 #error Item types must use disk-format assigned values.
50521 #endif
50522
50523 -struct item_operations *item_ops[TYPE_ANY + 1] = {
50524 +const struct item_operations * const item_ops[TYPE_ANY + 1] = {
50525 &stat_data_ops,
50526 &indirect_ops,
50527 &direct_ops,
50528 diff -urNp linux-2.6.39/fs/reiserfs/journal.c linux-2.6.39/fs/reiserfs/journal.c
50529 --- linux-2.6.39/fs/reiserfs/journal.c 2011-05-19 00:06:34.000000000 -0400
50530 +++ linux-2.6.39/fs/reiserfs/journal.c 2011-05-22 19:36:32.000000000 -0400
50531 @@ -2299,6 +2299,8 @@ static struct buffer_head *reiserfs_brea
50532 struct buffer_head *bh;
50533 int i, j;
50534
50535 + pax_track_stack();
50536 +
50537 bh = __getblk(dev, block, bufsize);
50538 if (buffer_uptodate(bh))
50539 return (bh);
50540 diff -urNp linux-2.6.39/fs/reiserfs/namei.c linux-2.6.39/fs/reiserfs/namei.c
50541 --- linux-2.6.39/fs/reiserfs/namei.c 2011-05-19 00:06:34.000000000 -0400
50542 +++ linux-2.6.39/fs/reiserfs/namei.c 2011-05-22 19:36:32.000000000 -0400
50543 @@ -1225,6 +1225,8 @@ static int reiserfs_rename(struct inode
50544 unsigned long savelink = 1;
50545 struct timespec ctime;
50546
50547 + pax_track_stack();
50548 +
50549 /* three balancings: (1) old name removal, (2) new name insertion
50550 and (3) maybe "save" link insertion
50551 stat data updates: (1) old directory,
50552 diff -urNp linux-2.6.39/fs/reiserfs/procfs.c linux-2.6.39/fs/reiserfs/procfs.c
50553 --- linux-2.6.39/fs/reiserfs/procfs.c 2011-05-19 00:06:34.000000000 -0400
50554 +++ linux-2.6.39/fs/reiserfs/procfs.c 2011-05-22 19:36:32.000000000 -0400
50555 @@ -113,7 +113,7 @@ static int show_super(struct seq_file *m
50556 "SMALL_TAILS " : "NO_TAILS ",
50557 replay_only(sb) ? "REPLAY_ONLY " : "",
50558 convert_reiserfs(sb) ? "CONV " : "",
50559 - atomic_read(&r->s_generation_counter),
50560 + atomic_read_unchecked(&r->s_generation_counter),
50561 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
50562 SF(s_do_balance), SF(s_unneeded_left_neighbor),
50563 SF(s_good_search_by_key_reada), SF(s_bmaps),
50564 @@ -299,6 +299,8 @@ static int show_journal(struct seq_file
50565 struct journal_params *jp = &rs->s_v1.s_journal;
50566 char b[BDEVNAME_SIZE];
50567
50568 + pax_track_stack();
50569 +
50570 seq_printf(m, /* on-disk fields */
50571 "jp_journal_1st_block: \t%i\n"
50572 "jp_journal_dev: \t%s[%x]\n"
50573 diff -urNp linux-2.6.39/fs/reiserfs/stree.c linux-2.6.39/fs/reiserfs/stree.c
50574 --- linux-2.6.39/fs/reiserfs/stree.c 2011-05-19 00:06:34.000000000 -0400
50575 +++ linux-2.6.39/fs/reiserfs/stree.c 2011-05-22 19:36:32.000000000 -0400
50576 @@ -1196,6 +1196,8 @@ int reiserfs_delete_item(struct reiserfs
50577 int iter = 0;
50578 #endif
50579
50580 + pax_track_stack();
50581 +
50582 BUG_ON(!th->t_trans_id);
50583
50584 init_tb_struct(th, &s_del_balance, sb, path,
50585 @@ -1333,6 +1335,8 @@ void reiserfs_delete_solid_item(struct r
50586 int retval;
50587 int quota_cut_bytes = 0;
50588
50589 + pax_track_stack();
50590 +
50591 BUG_ON(!th->t_trans_id);
50592
50593 le_key2cpu_key(&cpu_key, key);
50594 @@ -1562,6 +1566,8 @@ int reiserfs_cut_from_item(struct reiser
50595 int quota_cut_bytes;
50596 loff_t tail_pos = 0;
50597
50598 + pax_track_stack();
50599 +
50600 BUG_ON(!th->t_trans_id);
50601
50602 init_tb_struct(th, &s_cut_balance, inode->i_sb, path,
50603 @@ -1957,6 +1963,8 @@ int reiserfs_paste_into_item(struct reis
50604 int retval;
50605 int fs_gen;
50606
50607 + pax_track_stack();
50608 +
50609 BUG_ON(!th->t_trans_id);
50610
50611 fs_gen = get_generation(inode->i_sb);
50612 @@ -2045,6 +2053,8 @@ int reiserfs_insert_item(struct reiserfs
50613 int fs_gen = 0;
50614 int quota_bytes = 0;
50615
50616 + pax_track_stack();
50617 +
50618 BUG_ON(!th->t_trans_id);
50619
50620 if (inode) { /* Do we count quotas for item? */
50621 diff -urNp linux-2.6.39/fs/reiserfs/super.c linux-2.6.39/fs/reiserfs/super.c
50622 --- linux-2.6.39/fs/reiserfs/super.c 2011-05-19 00:06:34.000000000 -0400
50623 +++ linux-2.6.39/fs/reiserfs/super.c 2011-05-22 19:36:32.000000000 -0400
50624 @@ -927,6 +927,8 @@ static int reiserfs_parse_options(struct
50625 {.option_name = NULL}
50626 };
50627
50628 + pax_track_stack();
50629 +
50630 *blocks = 0;
50631 if (!options || !*options)
50632 /* use default configuration: create tails, journaling on, no
50633 diff -urNp linux-2.6.39/fs/select.c linux-2.6.39/fs/select.c
50634 --- linux-2.6.39/fs/select.c 2011-05-19 00:06:34.000000000 -0400
50635 +++ linux-2.6.39/fs/select.c 2011-05-22 19:41:42.000000000 -0400
50636 @@ -20,6 +20,7 @@
50637 #include <linux/module.h>
50638 #include <linux/slab.h>
50639 #include <linux/poll.h>
50640 +#include <linux/security.h>
50641 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
50642 #include <linux/file.h>
50643 #include <linux/fdtable.h>
50644 @@ -403,6 +404,8 @@ int do_select(int n, fd_set_bits *fds, s
50645 int retval, i, timed_out = 0;
50646 unsigned long slack = 0;
50647
50648 + pax_track_stack();
50649 +
50650 rcu_read_lock();
50651 retval = max_select_fd(n, fds);
50652 rcu_read_unlock();
50653 @@ -528,6 +531,8 @@ int core_sys_select(int n, fd_set __user
50654 /* Allocate small arguments on the stack to save memory and be faster */
50655 long stack_fds[SELECT_STACK_ALLOC/sizeof(long)];
50656
50657 + pax_track_stack();
50658 +
50659 ret = -EINVAL;
50660 if (n < 0)
50661 goto out_nofds;
50662 @@ -837,6 +842,9 @@ int do_sys_poll(struct pollfd __user *uf
50663 struct poll_list *walk = head;
50664 unsigned long todo = nfds;
50665
50666 + pax_track_stack();
50667 +
50668 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
50669 if (nfds > rlimit(RLIMIT_NOFILE))
50670 return -EINVAL;
50671
50672 diff -urNp linux-2.6.39/fs/seq_file.c linux-2.6.39/fs/seq_file.c
50673 --- linux-2.6.39/fs/seq_file.c 2011-05-19 00:06:34.000000000 -0400
50674 +++ linux-2.6.39/fs/seq_file.c 2011-05-22 19:36:32.000000000 -0400
50675 @@ -76,7 +76,8 @@ static int traverse(struct seq_file *m,
50676 return 0;
50677 }
50678 if (!m->buf) {
50679 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50680 + m->size = PAGE_SIZE;
50681 + m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
50682 if (!m->buf)
50683 return -ENOMEM;
50684 }
50685 @@ -116,7 +117,8 @@ static int traverse(struct seq_file *m,
50686 Eoverflow:
50687 m->op->stop(m, p);
50688 kfree(m->buf);
50689 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50690 + m->size <<= 1;
50691 + m->buf = kmalloc(m->size, GFP_KERNEL);
50692 return !m->buf ? -ENOMEM : -EAGAIN;
50693 }
50694
50695 @@ -169,7 +171,8 @@ ssize_t seq_read(struct file *file, char
50696 m->version = file->f_version;
50697 /* grab buffer if we didn't have one */
50698 if (!m->buf) {
50699 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50700 + m->size = PAGE_SIZE;
50701 + m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
50702 if (!m->buf)
50703 goto Enomem;
50704 }
50705 @@ -210,7 +213,8 @@ ssize_t seq_read(struct file *file, char
50706 goto Fill;
50707 m->op->stop(m, p);
50708 kfree(m->buf);
50709 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50710 + m->size <<= 1;
50711 + m->buf = kmalloc(m->size, GFP_KERNEL);
50712 if (!m->buf)
50713 goto Enomem;
50714 m->count = 0;
50715 diff -urNp linux-2.6.39/fs/splice.c linux-2.6.39/fs/splice.c
50716 --- linux-2.6.39/fs/splice.c 2011-05-19 00:06:34.000000000 -0400
50717 +++ linux-2.6.39/fs/splice.c 2011-05-22 19:36:32.000000000 -0400
50718 @@ -186,7 +186,7 @@ ssize_t splice_to_pipe(struct pipe_inode
50719 pipe_lock(pipe);
50720
50721 for (;;) {
50722 - if (!pipe->readers) {
50723 + if (!atomic_read(&pipe->readers)) {
50724 send_sig(SIGPIPE, current, 0);
50725 if (!ret)
50726 ret = -EPIPE;
50727 @@ -240,9 +240,9 @@ ssize_t splice_to_pipe(struct pipe_inode
50728 do_wakeup = 0;
50729 }
50730
50731 - pipe->waiting_writers++;
50732 + atomic_inc(&pipe->waiting_writers);
50733 pipe_wait(pipe);
50734 - pipe->waiting_writers--;
50735 + atomic_dec(&pipe->waiting_writers);
50736 }
50737
50738 pipe_unlock(pipe);
50739 @@ -316,6 +316,8 @@ __generic_file_splice_read(struct file *
50740 .spd_release = spd_release_page,
50741 };
50742
50743 + pax_track_stack();
50744 +
50745 if (splice_grow_spd(pipe, &spd))
50746 return -ENOMEM;
50747
50748 @@ -556,7 +558,7 @@ static ssize_t kernel_readv(struct file
50749 old_fs = get_fs();
50750 set_fs(get_ds());
50751 /* The cast to a user pointer is valid due to the set_fs() */
50752 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
50753 + res = vfs_readv(file, (__force const struct iovec __user *)vec, vlen, &pos);
50754 set_fs(old_fs);
50755
50756 return res;
50757 @@ -571,7 +573,7 @@ static ssize_t kernel_write(struct file
50758 old_fs = get_fs();
50759 set_fs(get_ds());
50760 /* The cast to a user pointer is valid due to the set_fs() */
50761 - res = vfs_write(file, (const char __user *)buf, count, &pos);
50762 + res = vfs_write(file, (__force const char __user *)buf, count, &pos);
50763 set_fs(old_fs);
50764
50765 return res;
50766 @@ -599,6 +601,8 @@ ssize_t default_file_splice_read(struct
50767 .spd_release = spd_release_page,
50768 };
50769
50770 + pax_track_stack();
50771 +
50772 if (splice_grow_spd(pipe, &spd))
50773 return -ENOMEM;
50774
50775 @@ -622,7 +626,7 @@ ssize_t default_file_splice_read(struct
50776 goto err;
50777
50778 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
50779 - vec[i].iov_base = (void __user *) page_address(page);
50780 + vec[i].iov_base = (__force void __user *) page_address(page);
50781 vec[i].iov_len = this_len;
50782 spd.pages[i] = page;
50783 spd.nr_pages++;
50784 @@ -842,10 +846,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
50785 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
50786 {
50787 while (!pipe->nrbufs) {
50788 - if (!pipe->writers)
50789 + if (!atomic_read(&pipe->writers))
50790 return 0;
50791
50792 - if (!pipe->waiting_writers && sd->num_spliced)
50793 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
50794 return 0;
50795
50796 if (sd->flags & SPLICE_F_NONBLOCK)
50797 @@ -1178,7 +1182,7 @@ ssize_t splice_direct_to_actor(struct fi
50798 * out of the pipe right after the splice_to_pipe(). So set
50799 * PIPE_READERS appropriately.
50800 */
50801 - pipe->readers = 1;
50802 + atomic_set(&pipe->readers, 1);
50803
50804 current->splice_pipe = pipe;
50805 }
50806 @@ -1615,6 +1619,8 @@ static long vmsplice_to_pipe(struct file
50807 };
50808 long ret;
50809
50810 + pax_track_stack();
50811 +
50812 pipe = get_pipe_info(file);
50813 if (!pipe)
50814 return -EBADF;
50815 @@ -1730,9 +1736,9 @@ static int ipipe_prep(struct pipe_inode_
50816 ret = -ERESTARTSYS;
50817 break;
50818 }
50819 - if (!pipe->writers)
50820 + if (!atomic_read(&pipe->writers))
50821 break;
50822 - if (!pipe->waiting_writers) {
50823 + if (!atomic_read(&pipe->waiting_writers)) {
50824 if (flags & SPLICE_F_NONBLOCK) {
50825 ret = -EAGAIN;
50826 break;
50827 @@ -1764,7 +1770,7 @@ static int opipe_prep(struct pipe_inode_
50828 pipe_lock(pipe);
50829
50830 while (pipe->nrbufs >= pipe->buffers) {
50831 - if (!pipe->readers) {
50832 + if (!atomic_read(&pipe->readers)) {
50833 send_sig(SIGPIPE, current, 0);
50834 ret = -EPIPE;
50835 break;
50836 @@ -1777,9 +1783,9 @@ static int opipe_prep(struct pipe_inode_
50837 ret = -ERESTARTSYS;
50838 break;
50839 }
50840 - pipe->waiting_writers++;
50841 + atomic_inc(&pipe->waiting_writers);
50842 pipe_wait(pipe);
50843 - pipe->waiting_writers--;
50844 + atomic_dec(&pipe->waiting_writers);
50845 }
50846
50847 pipe_unlock(pipe);
50848 @@ -1815,14 +1821,14 @@ retry:
50849 pipe_double_lock(ipipe, opipe);
50850
50851 do {
50852 - if (!opipe->readers) {
50853 + if (!atomic_read(&opipe->readers)) {
50854 send_sig(SIGPIPE, current, 0);
50855 if (!ret)
50856 ret = -EPIPE;
50857 break;
50858 }
50859
50860 - if (!ipipe->nrbufs && !ipipe->writers)
50861 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
50862 break;
50863
50864 /*
50865 @@ -1922,7 +1928,7 @@ static int link_pipe(struct pipe_inode_i
50866 pipe_double_lock(ipipe, opipe);
50867
50868 do {
50869 - if (!opipe->readers) {
50870 + if (!atomic_read(&opipe->readers)) {
50871 send_sig(SIGPIPE, current, 0);
50872 if (!ret)
50873 ret = -EPIPE;
50874 @@ -1967,7 +1973,7 @@ static int link_pipe(struct pipe_inode_i
50875 * return EAGAIN if we have the potential of some data in the
50876 * future, otherwise just return 0
50877 */
50878 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
50879 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
50880 ret = -EAGAIN;
50881
50882 pipe_unlock(ipipe);
50883 diff -urNp linux-2.6.39/fs/sysfs/file.c linux-2.6.39/fs/sysfs/file.c
50884 --- linux-2.6.39/fs/sysfs/file.c 2011-05-19 00:06:34.000000000 -0400
50885 +++ linux-2.6.39/fs/sysfs/file.c 2011-05-22 19:36:32.000000000 -0400
50886 @@ -44,7 +44,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent
50887
50888 struct sysfs_open_dirent {
50889 atomic_t refcnt;
50890 - atomic_t event;
50891 + atomic_unchecked_t event;
50892 wait_queue_head_t poll;
50893 struct list_head buffers; /* goes through sysfs_buffer.list */
50894 };
50895 @@ -88,7 +88,7 @@ static int fill_read_buffer(struct dentr
50896 if (!sysfs_get_active(attr_sd))
50897 return -ENODEV;
50898
50899 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
50900 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
50901 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
50902
50903 sysfs_put_active(attr_sd);
50904 @@ -294,7 +294,7 @@ static int sysfs_get_open_dirent(struct
50905 return -ENOMEM;
50906
50907 atomic_set(&new_od->refcnt, 0);
50908 - atomic_set(&new_od->event, 1);
50909 + atomic_set_unchecked(&new_od->event, 1);
50910 init_waitqueue_head(&new_od->poll);
50911 INIT_LIST_HEAD(&new_od->buffers);
50912 goto retry;
50913 @@ -444,7 +444,7 @@ static unsigned int sysfs_poll(struct fi
50914
50915 sysfs_put_active(attr_sd);
50916
50917 - if (buffer->event != atomic_read(&od->event))
50918 + if (buffer->event != atomic_read_unchecked(&od->event))
50919 goto trigger;
50920
50921 return DEFAULT_POLLMASK;
50922 @@ -463,7 +463,7 @@ void sysfs_notify_dirent(struct sysfs_di
50923
50924 od = sd->s_attr.open;
50925 if (od) {
50926 - atomic_inc(&od->event);
50927 + atomic_inc_unchecked(&od->event);
50928 wake_up_interruptible(&od->poll);
50929 }
50930
50931 diff -urNp linux-2.6.39/fs/sysfs/mount.c linux-2.6.39/fs/sysfs/mount.c
50932 --- linux-2.6.39/fs/sysfs/mount.c 2011-05-19 00:06:34.000000000 -0400
50933 +++ linux-2.6.39/fs/sysfs/mount.c 2011-05-22 19:41:42.000000000 -0400
50934 @@ -36,7 +36,11 @@ struct sysfs_dirent sysfs_root = {
50935 .s_name = "",
50936 .s_count = ATOMIC_INIT(1),
50937 .s_flags = SYSFS_DIR | (KOBJ_NS_TYPE_NONE << SYSFS_NS_TYPE_SHIFT),
50938 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
50939 + .s_mode = S_IFDIR | S_IRWXU,
50940 +#else
50941 .s_mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
50942 +#endif
50943 .s_ino = 1,
50944 };
50945
50946 diff -urNp linux-2.6.39/fs/sysfs/symlink.c linux-2.6.39/fs/sysfs/symlink.c
50947 --- linux-2.6.39/fs/sysfs/symlink.c 2011-05-19 00:06:34.000000000 -0400
50948 +++ linux-2.6.39/fs/sysfs/symlink.c 2011-05-22 19:36:32.000000000 -0400
50949 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct de
50950
50951 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
50952 {
50953 - char *page = nd_get_link(nd);
50954 + const char *page = nd_get_link(nd);
50955 if (!IS_ERR(page))
50956 free_page((unsigned long)page);
50957 }
50958 diff -urNp linux-2.6.39/fs/udf/inode.c linux-2.6.39/fs/udf/inode.c
50959 --- linux-2.6.39/fs/udf/inode.c 2011-05-19 00:06:34.000000000 -0400
50960 +++ linux-2.6.39/fs/udf/inode.c 2011-05-22 19:36:32.000000000 -0400
50961 @@ -560,6 +560,8 @@ static struct buffer_head *inode_getblk(
50962 int goal = 0, pgoal = iinfo->i_location.logicalBlockNum;
50963 int lastblock = 0;
50964
50965 + pax_track_stack();
50966 +
50967 prev_epos.offset = udf_file_entry_alloc_offset(inode);
50968 prev_epos.block = iinfo->i_location;
50969 prev_epos.bh = NULL;
50970 diff -urNp linux-2.6.39/fs/udf/misc.c linux-2.6.39/fs/udf/misc.c
50971 --- linux-2.6.39/fs/udf/misc.c 2011-05-19 00:06:34.000000000 -0400
50972 +++ linux-2.6.39/fs/udf/misc.c 2011-05-22 19:36:32.000000000 -0400
50973 @@ -286,7 +286,7 @@ void udf_new_tag(char *data, uint16_t id
50974
50975 u8 udf_tag_checksum(const struct tag *t)
50976 {
50977 - u8 *data = (u8 *)t;
50978 + const u8 *data = (const u8 *)t;
50979 u8 checksum = 0;
50980 int i;
50981 for (i = 0; i < sizeof(struct tag); ++i)
50982 diff -urNp linux-2.6.39/fs/utimes.c linux-2.6.39/fs/utimes.c
50983 --- linux-2.6.39/fs/utimes.c 2011-05-19 00:06:34.000000000 -0400
50984 +++ linux-2.6.39/fs/utimes.c 2011-05-22 19:41:42.000000000 -0400
50985 @@ -1,6 +1,7 @@
50986 #include <linux/compiler.h>
50987 #include <linux/file.h>
50988 #include <linux/fs.h>
50989 +#include <linux/security.h>
50990 #include <linux/linkage.h>
50991 #include <linux/mount.h>
50992 #include <linux/namei.h>
50993 @@ -101,6 +102,12 @@ static int utimes_common(struct path *pa
50994 goto mnt_drop_write_and_out;
50995 }
50996 }
50997 +
50998 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
50999 + error = -EACCES;
51000 + goto mnt_drop_write_and_out;
51001 + }
51002 +
51003 mutex_lock(&inode->i_mutex);
51004 error = notify_change(path->dentry, &newattrs);
51005 mutex_unlock(&inode->i_mutex);
51006 diff -urNp linux-2.6.39/fs/xattr_acl.c linux-2.6.39/fs/xattr_acl.c
51007 --- linux-2.6.39/fs/xattr_acl.c 2011-05-19 00:06:34.000000000 -0400
51008 +++ linux-2.6.39/fs/xattr_acl.c 2011-05-22 19:36:32.000000000 -0400
51009 @@ -17,8 +17,8 @@
51010 struct posix_acl *
51011 posix_acl_from_xattr(const void *value, size_t size)
51012 {
51013 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
51014 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
51015 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
51016 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
51017 int count;
51018 struct posix_acl *acl;
51019 struct posix_acl_entry *acl_e;
51020 diff -urNp linux-2.6.39/fs/xattr.c linux-2.6.39/fs/xattr.c
51021 --- linux-2.6.39/fs/xattr.c 2011-05-19 00:06:34.000000000 -0400
51022 +++ linux-2.6.39/fs/xattr.c 2011-05-22 19:41:42.000000000 -0400
51023 @@ -247,7 +247,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
51024 * Extended attribute SET operations
51025 */
51026 static long
51027 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
51028 +setxattr(struct path *path, const char __user *name, const void __user *value,
51029 size_t size, int flags)
51030 {
51031 int error;
51032 @@ -271,7 +271,13 @@ setxattr(struct dentry *d, const char __
51033 return PTR_ERR(kvalue);
51034 }
51035
51036 - error = vfs_setxattr(d, kname, kvalue, size, flags);
51037 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
51038 + error = -EACCES;
51039 + goto out;
51040 + }
51041 +
51042 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
51043 +out:
51044 kfree(kvalue);
51045 return error;
51046 }
51047 @@ -288,7 +294,7 @@ SYSCALL_DEFINE5(setxattr, const char __u
51048 return error;
51049 error = mnt_want_write(path.mnt);
51050 if (!error) {
51051 - error = setxattr(path.dentry, name, value, size, flags);
51052 + error = setxattr(&path, name, value, size, flags);
51053 mnt_drop_write(path.mnt);
51054 }
51055 path_put(&path);
51056 @@ -307,7 +313,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __
51057 return error;
51058 error = mnt_want_write(path.mnt);
51059 if (!error) {
51060 - error = setxattr(path.dentry, name, value, size, flags);
51061 + error = setxattr(&path, name, value, size, flags);
51062 mnt_drop_write(path.mnt);
51063 }
51064 path_put(&path);
51065 @@ -318,17 +324,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, cons
51066 const void __user *,value, size_t, size, int, flags)
51067 {
51068 struct file *f;
51069 - struct dentry *dentry;
51070 int error = -EBADF;
51071
51072 f = fget(fd);
51073 if (!f)
51074 return error;
51075 - dentry = f->f_path.dentry;
51076 - audit_inode(NULL, dentry);
51077 + audit_inode(NULL, f->f_path.dentry);
51078 error = mnt_want_write_file(f);
51079 if (!error) {
51080 - error = setxattr(dentry, name, value, size, flags);
51081 + error = setxattr(&f->f_path, name, value, size, flags);
51082 mnt_drop_write(f->f_path.mnt);
51083 }
51084 fput(f);
51085 diff -urNp linux-2.6.39/fs/xfs/linux-2.6/xfs_ioctl32.c linux-2.6.39/fs/xfs/linux-2.6/xfs_ioctl32.c
51086 --- linux-2.6.39/fs/xfs/linux-2.6/xfs_ioctl32.c 2011-05-19 00:06:34.000000000 -0400
51087 +++ linux-2.6.39/fs/xfs/linux-2.6/xfs_ioctl32.c 2011-05-22 19:41:42.000000000 -0400
51088 @@ -73,6 +73,7 @@ xfs_compat_ioc_fsgeometry_v1(
51089 xfs_fsop_geom_t fsgeo;
51090 int error;
51091
51092 + memset(&fsgeo, 0, sizeof(fsgeo));
51093 error = xfs_fs_geometry(mp, &fsgeo, 3);
51094 if (error)
51095 return -error;
51096 diff -urNp linux-2.6.39/fs/xfs/linux-2.6/xfs_ioctl.c linux-2.6.39/fs/xfs/linux-2.6/xfs_ioctl.c
51097 --- linux-2.6.39/fs/xfs/linux-2.6/xfs_ioctl.c 2011-05-19 00:06:34.000000000 -0400
51098 +++ linux-2.6.39/fs/xfs/linux-2.6/xfs_ioctl.c 2011-05-22 19:36:32.000000000 -0400
51099 @@ -128,7 +128,7 @@ xfs_find_handle(
51100 }
51101
51102 error = -EFAULT;
51103 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
51104 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
51105 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
51106 goto out_put;
51107
51108 diff -urNp linux-2.6.39/fs/xfs/linux-2.6/xfs_iops.c linux-2.6.39/fs/xfs/linux-2.6/xfs_iops.c
51109 --- linux-2.6.39/fs/xfs/linux-2.6/xfs_iops.c 2011-05-19 00:06:34.000000000 -0400
51110 +++ linux-2.6.39/fs/xfs/linux-2.6/xfs_iops.c 2011-05-22 19:36:32.000000000 -0400
51111 @@ -437,7 +437,7 @@ xfs_vn_put_link(
51112 struct nameidata *nd,
51113 void *p)
51114 {
51115 - char *s = nd_get_link(nd);
51116 + const char *s = nd_get_link(nd);
51117
51118 if (!IS_ERR(s))
51119 kfree(s);
51120 diff -urNp linux-2.6.39/fs/xfs/xfs_bmap.c linux-2.6.39/fs/xfs/xfs_bmap.c
51121 --- linux-2.6.39/fs/xfs/xfs_bmap.c 2011-05-19 00:06:34.000000000 -0400
51122 +++ linux-2.6.39/fs/xfs/xfs_bmap.c 2011-05-22 19:36:32.000000000 -0400
51123 @@ -287,7 +287,7 @@ xfs_bmap_validate_ret(
51124 int nmap,
51125 int ret_nmap);
51126 #else
51127 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
51128 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
51129 #endif /* DEBUG */
51130
51131 STATIC int
51132 diff -urNp linux-2.6.39/fs/xfs/xfs_dir2.c linux-2.6.39/fs/xfs/xfs_dir2.c
51133 --- linux-2.6.39/fs/xfs/xfs_dir2.c 2011-05-19 00:06:34.000000000 -0400
51134 +++ linux-2.6.39/fs/xfs/xfs_dir2.c 2011-05-22 19:36:32.000000000 -0400
51135 @@ -85,7 +85,7 @@ xfs_ascii_ci_compname(
51136 return result;
51137 }
51138
51139 -static struct xfs_nameops xfs_ascii_ci_nameops = {
51140 +static const struct xfs_nameops xfs_ascii_ci_nameops = {
51141 .hashname = xfs_ascii_ci_hashname,
51142 .compname = xfs_ascii_ci_compname,
51143 };
51144 diff -urNp linux-2.6.39/fs/xfs/xfs_dir2_sf.c linux-2.6.39/fs/xfs/xfs_dir2_sf.c
51145 --- linux-2.6.39/fs/xfs/xfs_dir2_sf.c 2011-05-19 00:06:34.000000000 -0400
51146 +++ linux-2.6.39/fs/xfs/xfs_dir2_sf.c 2011-05-22 19:36:32.000000000 -0400
51147 @@ -780,7 +780,15 @@ xfs_dir2_sf_getdents(
51148 }
51149
51150 ino = xfs_dir2_sf_get_inumber(sfp, xfs_dir2_sf_inumberp(sfep));
51151 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
51152 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
51153 + char name[sfep->namelen];
51154 + memcpy(name, sfep->name, sfep->namelen);
51155 + if (filldir(dirent, name, sfep->namelen,
51156 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
51157 + *offset = off & 0x7fffffff;
51158 + return 0;
51159 + }
51160 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
51161 off & 0x7fffffff, ino, DT_UNKNOWN)) {
51162 *offset = off & 0x7fffffff;
51163 return 0;
51164 diff -urNp linux-2.6.39/grsecurity/gracl_alloc.c linux-2.6.39/grsecurity/gracl_alloc.c
51165 --- linux-2.6.39/grsecurity/gracl_alloc.c 1969-12-31 19:00:00.000000000 -0500
51166 +++ linux-2.6.39/grsecurity/gracl_alloc.c 2011-05-22 19:41:42.000000000 -0400
51167 @@ -0,0 +1,105 @@
51168 +#include <linux/kernel.h>
51169 +#include <linux/mm.h>
51170 +#include <linux/slab.h>
51171 +#include <linux/vmalloc.h>
51172 +#include <linux/gracl.h>
51173 +#include <linux/grsecurity.h>
51174 +
51175 +static unsigned long alloc_stack_next = 1;
51176 +static unsigned long alloc_stack_size = 1;
51177 +static void **alloc_stack;
51178 +
51179 +static __inline__ int
51180 +alloc_pop(void)
51181 +{
51182 + if (alloc_stack_next == 1)
51183 + return 0;
51184 +
51185 + kfree(alloc_stack[alloc_stack_next - 2]);
51186 +
51187 + alloc_stack_next--;
51188 +
51189 + return 1;
51190 +}
51191 +
51192 +static __inline__ int
51193 +alloc_push(void *buf)
51194 +{
51195 + if (alloc_stack_next >= alloc_stack_size)
51196 + return 1;
51197 +
51198 + alloc_stack[alloc_stack_next - 1] = buf;
51199 +
51200 + alloc_stack_next++;
51201 +
51202 + return 0;
51203 +}
51204 +
51205 +void *
51206 +acl_alloc(unsigned long len)
51207 +{
51208 + void *ret = NULL;
51209 +
51210 + if (!len || len > PAGE_SIZE)
51211 + goto out;
51212 +
51213 + ret = kmalloc(len, GFP_KERNEL);
51214 +
51215 + if (ret) {
51216 + if (alloc_push(ret)) {
51217 + kfree(ret);
51218 + ret = NULL;
51219 + }
51220 + }
51221 +
51222 +out:
51223 + return ret;
51224 +}
51225 +
51226 +void *
51227 +acl_alloc_num(unsigned long num, unsigned long len)
51228 +{
51229 + if (!len || (num > (PAGE_SIZE / len)))
51230 + return NULL;
51231 +
51232 + return acl_alloc(num * len);
51233 +}
51234 +
51235 +void
51236 +acl_free_all(void)
51237 +{
51238 + if (gr_acl_is_enabled() || !alloc_stack)
51239 + return;
51240 +
51241 + while (alloc_pop()) ;
51242 +
51243 + if (alloc_stack) {
51244 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
51245 + kfree(alloc_stack);
51246 + else
51247 + vfree(alloc_stack);
51248 + }
51249 +
51250 + alloc_stack = NULL;
51251 + alloc_stack_size = 1;
51252 + alloc_stack_next = 1;
51253 +
51254 + return;
51255 +}
51256 +
51257 +int
51258 +acl_alloc_stack_init(unsigned long size)
51259 +{
51260 + if ((size * sizeof (void *)) <= PAGE_SIZE)
51261 + alloc_stack =
51262 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
51263 + else
51264 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
51265 +
51266 + alloc_stack_size = size;
51267 +
51268 + if (!alloc_stack)
51269 + return 0;
51270 + else
51271 + return 1;
51272 +}
51273 diff -urNp linux-2.6.39/grsecurity/gracl.c linux-2.6.39/grsecurity/gracl.c
51274 --- linux-2.6.39/grsecurity/gracl.c 1969-12-31 19:00:00.000000000 -0500
51275 +++ linux-2.6.39/grsecurity/gracl.c 2011-05-22 22:47:25.000000000 -0400
51276 @@ -0,0 +1,4097 @@
51277 +#include <linux/kernel.h>
51278 +#include <linux/module.h>
51279 +#include <linux/sched.h>
51280 +#include <linux/mm.h>
51281 +#include <linux/file.h>
51282 +#include <linux/fs.h>
51283 +#include <linux/namei.h>
51284 +#include <linux/mount.h>
51285 +#include <linux/tty.h>
51286 +#include <linux/proc_fs.h>
51287 +#include <linux/lglock.h>
51288 +#include <linux/slab.h>
51289 +#include <linux/vmalloc.h>
51290 +#include <linux/types.h>
51291 +#include <linux/sysctl.h>
51292 +#include <linux/netdevice.h>
51293 +#include <linux/ptrace.h>
51294 +#include <linux/gracl.h>
51295 +#include <linux/gralloc.h>
51296 +#include <linux/grsecurity.h>
51297 +#include <linux/grinternal.h>
51298 +#include <linux/pid_namespace.h>
51299 +#include <linux/fdtable.h>
51300 +#include <linux/percpu.h>
51301 +
51302 +#include <asm/uaccess.h>
51303 +#include <asm/errno.h>
51304 +#include <asm/mman.h>
51305 +
51306 +static struct acl_role_db acl_role_set;
51307 +static struct name_db name_set;
51308 +static struct inodev_db inodev_set;
51309 +
51310 +/* for keeping track of userspace pointers used for subjects, so we
51311 + can share references in the kernel as well
51312 +*/
51313 +
51314 +static struct path real_root;
51315 +
51316 +static struct acl_subj_map_db subj_map_set;
51317 +
51318 +static struct acl_role_label *default_role;
51319 +
51320 +static struct acl_role_label *role_list;
51321 +
51322 +static u16 acl_sp_role_value;
51323 +
51324 +extern char *gr_shared_page[4];
51325 +static DEFINE_MUTEX(gr_dev_mutex);
51326 +DEFINE_RWLOCK(gr_inode_lock);
51327 +
51328 +struct gr_arg *gr_usermode;
51329 +
51330 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
51331 +
51332 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
51333 +extern void gr_clear_learn_entries(void);
51334 +
51335 +#ifdef CONFIG_GRKERNSEC_RESLOG
51336 +extern void gr_log_resource(const struct task_struct *task,
51337 + const int res, const unsigned long wanted, const int gt);
51338 +#endif
51339 +
51340 +unsigned char *gr_system_salt;
51341 +unsigned char *gr_system_sum;
51342 +
51343 +static struct sprole_pw **acl_special_roles = NULL;
51344 +static __u16 num_sprole_pws = 0;
51345 +
51346 +static struct acl_role_label *kernel_role = NULL;
51347 +
51348 +static unsigned int gr_auth_attempts = 0;
51349 +static unsigned long gr_auth_expires = 0UL;
51350 +
51351 +extern struct vfsmount *sock_mnt;
51352 +extern struct vfsmount *pipe_mnt;
51353 +extern struct vfsmount *shm_mnt;
51354 +#ifdef CONFIG_HUGETLBFS
51355 +extern struct vfsmount *hugetlbfs_vfsmount;
51356 +#endif
51357 +
51358 +static struct acl_object_label *fakefs_obj;
51359 +
51360 +extern int gr_init_uidset(void);
51361 +extern void gr_free_uidset(void);
51362 +extern void gr_remove_uid(uid_t uid);
51363 +extern int gr_find_uid(uid_t uid);
51364 +
51365 +DECLARE_BRLOCK(vfsmount_lock);
51366 +
51367 +__inline__ int
51368 +gr_acl_is_enabled(void)
51369 +{
51370 + return (gr_status & GR_READY);
51371 +}
51372 +
51373 +#ifdef CONFIG_BTRFS_FS
51374 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
51375 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
51376 +#endif
51377 +
51378 +static inline dev_t __get_dev(const struct dentry *dentry)
51379 +{
51380 +#ifdef CONFIG_BTRFS_FS
51381 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
51382 + return get_btrfs_dev_from_inode(dentry->d_inode);
51383 + else
51384 +#endif
51385 + return dentry->d_inode->i_sb->s_dev;
51386 +}
51387 +
51388 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
51389 +{
51390 + return __get_dev(dentry);
51391 +}
51392 +
51393 +static char gr_task_roletype_to_char(struct task_struct *task)
51394 +{
51395 + switch (task->role->roletype &
51396 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
51397 + GR_ROLE_SPECIAL)) {
51398 + case GR_ROLE_DEFAULT:
51399 + return 'D';
51400 + case GR_ROLE_USER:
51401 + return 'U';
51402 + case GR_ROLE_GROUP:
51403 + return 'G';
51404 + case GR_ROLE_SPECIAL:
51405 + return 'S';
51406 + }
51407 +
51408 + return 'X';
51409 +}
51410 +
51411 +char gr_roletype_to_char(void)
51412 +{
51413 + return gr_task_roletype_to_char(current);
51414 +}
51415 +
51416 +__inline__ int
51417 +gr_acl_tpe_check(void)
51418 +{
51419 + if (unlikely(!(gr_status & GR_READY)))
51420 + return 0;
51421 + if (current->role->roletype & GR_ROLE_TPE)
51422 + return 1;
51423 + else
51424 + return 0;
51425 +}
51426 +
51427 +int
51428 +gr_handle_rawio(const struct inode *inode)
51429 +{
51430 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
51431 + if (inode && S_ISBLK(inode->i_mode) &&
51432 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
51433 + !capable(CAP_SYS_RAWIO))
51434 + return 1;
51435 +#endif
51436 + return 0;
51437 +}
51438 +
51439 +static int
51440 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
51441 +{
51442 + if (likely(lena != lenb))
51443 + return 0;
51444 +
51445 + return !memcmp(a, b, lena);
51446 +}
51447 +
51448 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
51449 +{
51450 + *buflen -= namelen;
51451 + if (*buflen < 0)
51452 + return -ENAMETOOLONG;
51453 + *buffer -= namelen;
51454 + memcpy(*buffer, str, namelen);
51455 + return 0;
51456 +}
51457 +
51458 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
51459 +{
51460 + return prepend(buffer, buflen, name->name, name->len);
51461 +}
51462 +
51463 +static int prepend_path(const struct path *path, struct path *root,
51464 + char **buffer, int *buflen)
51465 +{
51466 + struct dentry *dentry = path->dentry;
51467 + struct vfsmount *vfsmnt = path->mnt;
51468 + bool slash = false;
51469 + int error = 0;
51470 +
51471 + while (dentry != root->dentry || vfsmnt != root->mnt) {
51472 + struct dentry * parent;
51473 +
51474 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
51475 + /* Global root? */
51476 + if (vfsmnt->mnt_parent == vfsmnt) {
51477 + goto out;
51478 + }
51479 + dentry = vfsmnt->mnt_mountpoint;
51480 + vfsmnt = vfsmnt->mnt_parent;
51481 + continue;
51482 + }
51483 + parent = dentry->d_parent;
51484 + prefetch(parent);
51485 + spin_lock(&dentry->d_lock);
51486 + error = prepend_name(buffer, buflen, &dentry->d_name);
51487 + spin_unlock(&dentry->d_lock);
51488 + if (!error)
51489 + error = prepend(buffer, buflen, "/", 1);
51490 + if (error)
51491 + break;
51492 +
51493 + slash = true;
51494 + dentry = parent;
51495 + }
51496 +
51497 +out:
51498 + if (!error && !slash)
51499 + error = prepend(buffer, buflen, "/", 1);
51500 +
51501 + return error;
51502 +}
51503 +
51504 +/* this must be called with vfsmount_lock and rename_lock held */
51505 +
51506 +static char *__our_d_path(const struct path *path, struct path *root,
51507 + char *buf, int buflen)
51508 +{
51509 + char *res = buf + buflen;
51510 + int error;
51511 +
51512 + prepend(&res, &buflen, "\0", 1);
51513 + error = prepend_path(path, root, &res, &buflen);
51514 + if (error)
51515 + return ERR_PTR(error);
51516 +
51517 + return res;
51518 +}
51519 +
51520 +static char *
51521 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
51522 +{
51523 + char *retval;
51524 +
51525 + retval = __our_d_path(path, root, buf, buflen);
51526 + if (unlikely(IS_ERR(retval)))
51527 + retval = strcpy(buf, "<path too long>");
51528 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
51529 + retval[1] = '\0';
51530 +
51531 + return retval;
51532 +}
51533 +
51534 +static char *
51535 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51536 + char *buf, int buflen)
51537 +{
51538 + struct path path;
51539 + char *res;
51540 +
51541 + path.dentry = (struct dentry *)dentry;
51542 + path.mnt = (struct vfsmount *)vfsmnt;
51543 +
51544 + /* we can use real_root.dentry, real_root.mnt, because this is only called
51545 + by the RBAC system */
51546 + res = gen_full_path(&path, &real_root, buf, buflen);
51547 +
51548 + return res;
51549 +}
51550 +
51551 +static char *
51552 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51553 + char *buf, int buflen)
51554 +{
51555 + char *res;
51556 + struct path path;
51557 + struct path root;
51558 + struct task_struct *reaper = &init_task;
51559 +
51560 + path.dentry = (struct dentry *)dentry;
51561 + path.mnt = (struct vfsmount *)vfsmnt;
51562 +
51563 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
51564 + get_fs_root(reaper->fs, &root);
51565 +
51566 + write_seqlock(&rename_lock);
51567 + br_read_lock(vfsmount_lock);
51568 + res = gen_full_path(&path, &root, buf, buflen);
51569 + br_read_unlock(vfsmount_lock);
51570 + write_sequnlock(&rename_lock);
51571 +
51572 + path_put(&root);
51573 + return res;
51574 +}
51575 +
51576 +static char *
51577 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51578 +{
51579 + char *ret;
51580 + write_seqlock(&rename_lock);
51581 + br_read_lock(vfsmount_lock);
51582 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51583 + PAGE_SIZE);
51584 + br_read_unlock(vfsmount_lock);
51585 + write_sequnlock(&rename_lock);
51586 + return ret;
51587 +}
51588 +
51589 +char *
51590 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
51591 +{
51592 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51593 + PAGE_SIZE);
51594 +}
51595 +
51596 +char *
51597 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
51598 +{
51599 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
51600 + PAGE_SIZE);
51601 +}
51602 +
51603 +char *
51604 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
51605 +{
51606 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
51607 + PAGE_SIZE);
51608 +}
51609 +
51610 +char *
51611 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
51612 +{
51613 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
51614 + PAGE_SIZE);
51615 +}
51616 +
51617 +char *
51618 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
51619 +{
51620 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
51621 + PAGE_SIZE);
51622 +}
51623 +
51624 +__inline__ __u32
51625 +to_gr_audit(const __u32 reqmode)
51626 +{
51627 + /* masks off auditable permission flags, then shifts them to create
51628 + auditing flags, and adds the special case of append auditing if
51629 + we're requesting write */
51630 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
51631 +}
51632 +
51633 +struct acl_subject_label *
51634 +lookup_subject_map(const struct acl_subject_label *userp)
51635 +{
51636 + unsigned int index = shash(userp, subj_map_set.s_size);
51637 + struct subject_map *match;
51638 +
51639 + match = subj_map_set.s_hash[index];
51640 +
51641 + while (match && match->user != userp)
51642 + match = match->next;
51643 +
51644 + if (match != NULL)
51645 + return match->kernel;
51646 + else
51647 + return NULL;
51648 +}
51649 +
51650 +static void
51651 +insert_subj_map_entry(struct subject_map *subjmap)
51652 +{
51653 + unsigned int index = shash(subjmap->user, subj_map_set.s_size);
51654 + struct subject_map **curr;
51655 +
51656 + subjmap->prev = NULL;
51657 +
51658 + curr = &subj_map_set.s_hash[index];
51659 + if (*curr != NULL)
51660 + (*curr)->prev = subjmap;
51661 +
51662 + subjmap->next = *curr;
51663 + *curr = subjmap;
51664 +
51665 + return;
51666 +}
51667 +
51668 +static struct acl_role_label *
51669 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
51670 + const gid_t gid)
51671 +{
51672 + unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
51673 + struct acl_role_label *match;
51674 + struct role_allowed_ip *ipp;
51675 + unsigned int x;
51676 + u32 curr_ip = task->signal->curr_ip;
51677 +
51678 + task->signal->saved_ip = curr_ip;
51679 +
51680 + match = acl_role_set.r_hash[index];
51681 +
51682 + while (match) {
51683 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
51684 + for (x = 0; x < match->domain_child_num; x++) {
51685 + if (match->domain_children[x] == uid)
51686 + goto found;
51687 + }
51688 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
51689 + break;
51690 + match = match->next;
51691 + }
51692 +found:
51693 + if (match == NULL) {
51694 + try_group:
51695 + index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
51696 + match = acl_role_set.r_hash[index];
51697 +
51698 + while (match) {
51699 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
51700 + for (x = 0; x < match->domain_child_num; x++) {
51701 + if (match->domain_children[x] == gid)
51702 + goto found2;
51703 + }
51704 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
51705 + break;
51706 + match = match->next;
51707 + }
51708 +found2:
51709 + if (match == NULL)
51710 + match = default_role;
51711 + if (match->allowed_ips == NULL)
51712 + return match;
51713 + else {
51714 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51715 + if (likely
51716 + ((ntohl(curr_ip) & ipp->netmask) ==
51717 + (ntohl(ipp->addr) & ipp->netmask)))
51718 + return match;
51719 + }
51720 + match = default_role;
51721 + }
51722 + } else if (match->allowed_ips == NULL) {
51723 + return match;
51724 + } else {
51725 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51726 + if (likely
51727 + ((ntohl(curr_ip) & ipp->netmask) ==
51728 + (ntohl(ipp->addr) & ipp->netmask)))
51729 + return match;
51730 + }
51731 + goto try_group;
51732 + }
51733 +
51734 + return match;
51735 +}
51736 +
51737 +struct acl_subject_label *
51738 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
51739 + const struct acl_role_label *role)
51740 +{
51741 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
51742 + struct acl_subject_label *match;
51743 +
51744 + match = role->subj_hash[index];
51745 +
51746 + while (match && (match->inode != ino || match->device != dev ||
51747 + (match->mode & GR_DELETED))) {
51748 + match = match->next;
51749 + }
51750 +
51751 + if (match && !(match->mode & GR_DELETED))
51752 + return match;
51753 + else
51754 + return NULL;
51755 +}
51756 +
51757 +struct acl_subject_label *
51758 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
51759 + const struct acl_role_label *role)
51760 +{
51761 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
51762 + struct acl_subject_label *match;
51763 +
51764 + match = role->subj_hash[index];
51765 +
51766 + while (match && (match->inode != ino || match->device != dev ||
51767 + !(match->mode & GR_DELETED))) {
51768 + match = match->next;
51769 + }
51770 +
51771 + if (match && (match->mode & GR_DELETED))
51772 + return match;
51773 + else
51774 + return NULL;
51775 +}
51776 +
51777 +static struct acl_object_label *
51778 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
51779 + const struct acl_subject_label *subj)
51780 +{
51781 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51782 + struct acl_object_label *match;
51783 +
51784 + match = subj->obj_hash[index];
51785 +
51786 + while (match && (match->inode != ino || match->device != dev ||
51787 + (match->mode & GR_DELETED))) {
51788 + match = match->next;
51789 + }
51790 +
51791 + if (match && !(match->mode & GR_DELETED))
51792 + return match;
51793 + else
51794 + return NULL;
51795 +}
51796 +
51797 +static struct acl_object_label *
51798 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
51799 + const struct acl_subject_label *subj)
51800 +{
51801 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51802 + struct acl_object_label *match;
51803 +
51804 + match = subj->obj_hash[index];
51805 +
51806 + while (match && (match->inode != ino || match->device != dev ||
51807 + !(match->mode & GR_DELETED))) {
51808 + match = match->next;
51809 + }
51810 +
51811 + if (match && (match->mode & GR_DELETED))
51812 + return match;
51813 +
51814 + match = subj->obj_hash[index];
51815 +
51816 + while (match && (match->inode != ino || match->device != dev ||
51817 + (match->mode & GR_DELETED))) {
51818 + match = match->next;
51819 + }
51820 +
51821 + if (match && !(match->mode & GR_DELETED))
51822 + return match;
51823 + else
51824 + return NULL;
51825 +}
51826 +
51827 +static struct name_entry *
51828 +lookup_name_entry(const char *name)
51829 +{
51830 + unsigned int len = strlen(name);
51831 + unsigned int key = full_name_hash(name, len);
51832 + unsigned int index = key % name_set.n_size;
51833 + struct name_entry *match;
51834 +
51835 + match = name_set.n_hash[index];
51836 +
51837 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
51838 + match = match->next;
51839 +
51840 + return match;
51841 +}
51842 +
51843 +static struct name_entry *
51844 +lookup_name_entry_create(const char *name)
51845 +{
51846 + unsigned int len = strlen(name);
51847 + unsigned int key = full_name_hash(name, len);
51848 + unsigned int index = key % name_set.n_size;
51849 + struct name_entry *match;
51850 +
51851 + match = name_set.n_hash[index];
51852 +
51853 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
51854 + !match->deleted))
51855 + match = match->next;
51856 +
51857 + if (match && match->deleted)
51858 + return match;
51859 +
51860 + match = name_set.n_hash[index];
51861 +
51862 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
51863 + match->deleted))
51864 + match = match->next;
51865 +
51866 + if (match && !match->deleted)
51867 + return match;
51868 + else
51869 + return NULL;
51870 +}
51871 +
51872 +static struct inodev_entry *
51873 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
51874 +{
51875 + unsigned int index = fhash(ino, dev, inodev_set.i_size);
51876 + struct inodev_entry *match;
51877 +
51878 + match = inodev_set.i_hash[index];
51879 +
51880 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
51881 + match = match->next;
51882 +
51883 + return match;
51884 +}
51885 +
51886 +static void
51887 +insert_inodev_entry(struct inodev_entry *entry)
51888 +{
51889 + unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
51890 + inodev_set.i_size);
51891 + struct inodev_entry **curr;
51892 +
51893 + entry->prev = NULL;
51894 +
51895 + curr = &inodev_set.i_hash[index];
51896 + if (*curr != NULL)
51897 + (*curr)->prev = entry;
51898 +
51899 + entry->next = *curr;
51900 + *curr = entry;
51901 +
51902 + return;
51903 +}
51904 +
51905 +static void
51906 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
51907 +{
51908 + unsigned int index =
51909 + rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
51910 + struct acl_role_label **curr;
51911 + struct acl_role_label *tmp;
51912 +
51913 + curr = &acl_role_set.r_hash[index];
51914 +
51915 + /* if role was already inserted due to domains and already has
51916 + a role in the same bucket as it attached, then we need to
51917 + combine these two buckets
51918 + */
51919 + if (role->next) {
51920 + tmp = role->next;
51921 + while (tmp->next)
51922 + tmp = tmp->next;
51923 + tmp->next = *curr;
51924 + } else
51925 + role->next = *curr;
51926 + *curr = role;
51927 +
51928 + return;
51929 +}
51930 +
51931 +static void
51932 +insert_acl_role_label(struct acl_role_label *role)
51933 +{
51934 + int i;
51935 +
51936 + if (role_list == NULL) {
51937 + role_list = role;
51938 + role->prev = NULL;
51939 + } else {
51940 + role->prev = role_list;
51941 + role_list = role;
51942 + }
51943 +
51944 + /* used for hash chains */
51945 + role->next = NULL;
51946 +
51947 + if (role->roletype & GR_ROLE_DOMAIN) {
51948 + for (i = 0; i < role->domain_child_num; i++)
51949 + __insert_acl_role_label(role, role->domain_children[i]);
51950 + } else
51951 + __insert_acl_role_label(role, role->uidgid);
51952 +}
51953 +
51954 +static int
51955 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
51956 +{
51957 + struct name_entry **curr, *nentry;
51958 + struct inodev_entry *ientry;
51959 + unsigned int len = strlen(name);
51960 + unsigned int key = full_name_hash(name, len);
51961 + unsigned int index = key % name_set.n_size;
51962 +
51963 + curr = &name_set.n_hash[index];
51964 +
51965 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
51966 + curr = &((*curr)->next);
51967 +
51968 + if (*curr != NULL)
51969 + return 1;
51970 +
51971 + nentry = acl_alloc(sizeof (struct name_entry));
51972 + if (nentry == NULL)
51973 + return 0;
51974 + ientry = acl_alloc(sizeof (struct inodev_entry));
51975 + if (ientry == NULL)
51976 + return 0;
51977 + ientry->nentry = nentry;
51978 +
51979 + nentry->key = key;
51980 + nentry->name = name;
51981 + nentry->inode = inode;
51982 + nentry->device = device;
51983 + nentry->len = len;
51984 + nentry->deleted = deleted;
51985 +
51986 + nentry->prev = NULL;
51987 + curr = &name_set.n_hash[index];
51988 + if (*curr != NULL)
51989 + (*curr)->prev = nentry;
51990 + nentry->next = *curr;
51991 + *curr = nentry;
51992 +
51993 + /* insert us into the table searchable by inode/dev */
51994 + insert_inodev_entry(ientry);
51995 +
51996 + return 1;
51997 +}
51998 +
51999 +static void
52000 +insert_acl_obj_label(struct acl_object_label *obj,
52001 + struct acl_subject_label *subj)
52002 +{
52003 + unsigned int index =
52004 + fhash(obj->inode, obj->device, subj->obj_hash_size);
52005 + struct acl_object_label **curr;
52006 +
52007 +
52008 + obj->prev = NULL;
52009 +
52010 + curr = &subj->obj_hash[index];
52011 + if (*curr != NULL)
52012 + (*curr)->prev = obj;
52013 +
52014 + obj->next = *curr;
52015 + *curr = obj;
52016 +
52017 + return;
52018 +}
52019 +
52020 +static void
52021 +insert_acl_subj_label(struct acl_subject_label *obj,
52022 + struct acl_role_label *role)
52023 +{
52024 + unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
52025 + struct acl_subject_label **curr;
52026 +
52027 + obj->prev = NULL;
52028 +
52029 + curr = &role->subj_hash[index];
52030 + if (*curr != NULL)
52031 + (*curr)->prev = obj;
52032 +
52033 + obj->next = *curr;
52034 + *curr = obj;
52035 +
52036 + return;
52037 +}
52038 +
52039 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
52040 +
52041 +static void *
52042 +create_table(__u32 * len, int elementsize)
52043 +{
52044 + unsigned int table_sizes[] = {
52045 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
52046 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
52047 + 4194301, 8388593, 16777213, 33554393, 67108859
52048 + };
52049 + void *newtable = NULL;
52050 + unsigned int pwr = 0;
52051 +
52052 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
52053 + table_sizes[pwr] <= *len)
52054 + pwr++;
52055 +
52056 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
52057 + return newtable;
52058 +
52059 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
52060 + newtable =
52061 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
52062 + else
52063 + newtable = vmalloc(table_sizes[pwr] * elementsize);
52064 +
52065 + *len = table_sizes[pwr];
52066 +
52067 + return newtable;
52068 +}
52069 +
52070 +static int
52071 +init_variables(const struct gr_arg *arg)
52072 +{
52073 + struct task_struct *reaper = &init_task;
52074 + unsigned int stacksize;
52075 +
52076 + subj_map_set.s_size = arg->role_db.num_subjects;
52077 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
52078 + name_set.n_size = arg->role_db.num_objects;
52079 + inodev_set.i_size = arg->role_db.num_objects;
52080 +
52081 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
52082 + !name_set.n_size || !inodev_set.i_size)
52083 + return 1;
52084 +
52085 + if (!gr_init_uidset())
52086 + return 1;
52087 +
52088 + /* set up the stack that holds allocation info */
52089 +
52090 + stacksize = arg->role_db.num_pointers + 5;
52091 +
52092 + if (!acl_alloc_stack_init(stacksize))
52093 + return 1;
52094 +
52095 + /* grab reference for the real root dentry and vfsmount */
52096 + get_fs_root(reaper->fs, &real_root);
52097 +
52098 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52099 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
52100 +#endif
52101 +
52102 + fakefs_obj = acl_alloc(sizeof(struct acl_object_label));
52103 + if (fakefs_obj == NULL)
52104 + return 1;
52105 + fakefs_obj->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
52106 +
52107 + subj_map_set.s_hash =
52108 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
52109 + acl_role_set.r_hash =
52110 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
52111 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
52112 + inodev_set.i_hash =
52113 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
52114 +
52115 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
52116 + !name_set.n_hash || !inodev_set.i_hash)
52117 + return 1;
52118 +
52119 + memset(subj_map_set.s_hash, 0,
52120 + sizeof(struct subject_map *) * subj_map_set.s_size);
52121 + memset(acl_role_set.r_hash, 0,
52122 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
52123 + memset(name_set.n_hash, 0,
52124 + sizeof (struct name_entry *) * name_set.n_size);
52125 + memset(inodev_set.i_hash, 0,
52126 + sizeof (struct inodev_entry *) * inodev_set.i_size);
52127 +
52128 + return 0;
52129 +}
52130 +
52131 +/* free information not needed after startup
52132 + currently contains user->kernel pointer mappings for subjects
52133 +*/
52134 +
52135 +static void
52136 +free_init_variables(void)
52137 +{
52138 + __u32 i;
52139 +
52140 + if (subj_map_set.s_hash) {
52141 + for (i = 0; i < subj_map_set.s_size; i++) {
52142 + if (subj_map_set.s_hash[i]) {
52143 + kfree(subj_map_set.s_hash[i]);
52144 + subj_map_set.s_hash[i] = NULL;
52145 + }
52146 + }
52147 +
52148 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
52149 + PAGE_SIZE)
52150 + kfree(subj_map_set.s_hash);
52151 + else
52152 + vfree(subj_map_set.s_hash);
52153 + }
52154 +
52155 + return;
52156 +}
52157 +
52158 +static void
52159 +free_variables(void)
52160 +{
52161 + struct acl_subject_label *s;
52162 + struct acl_role_label *r;
52163 + struct task_struct *task, *task2;
52164 + unsigned int x;
52165 +
52166 + gr_clear_learn_entries();
52167 +
52168 + read_lock(&tasklist_lock);
52169 + do_each_thread(task2, task) {
52170 + task->acl_sp_role = 0;
52171 + task->acl_role_id = 0;
52172 + task->acl = NULL;
52173 + task->role = NULL;
52174 + } while_each_thread(task2, task);
52175 + read_unlock(&tasklist_lock);
52176 +
52177 + /* release the reference to the real root dentry and vfsmount */
52178 + path_put(&real_root);
52179 +
52180 + /* free all object hash tables */
52181 +
52182 + FOR_EACH_ROLE_START(r)
52183 + if (r->subj_hash == NULL)
52184 + goto next_role;
52185 + FOR_EACH_SUBJECT_START(r, s, x)
52186 + if (s->obj_hash == NULL)
52187 + break;
52188 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52189 + kfree(s->obj_hash);
52190 + else
52191 + vfree(s->obj_hash);
52192 + FOR_EACH_SUBJECT_END(s, x)
52193 + FOR_EACH_NESTED_SUBJECT_START(r, s)
52194 + if (s->obj_hash == NULL)
52195 + break;
52196 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52197 + kfree(s->obj_hash);
52198 + else
52199 + vfree(s->obj_hash);
52200 + FOR_EACH_NESTED_SUBJECT_END(s)
52201 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
52202 + kfree(r->subj_hash);
52203 + else
52204 + vfree(r->subj_hash);
52205 + r->subj_hash = NULL;
52206 +next_role:
52207 + FOR_EACH_ROLE_END(r)
52208 +
52209 + acl_free_all();
52210 +
52211 + if (acl_role_set.r_hash) {
52212 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
52213 + PAGE_SIZE)
52214 + kfree(acl_role_set.r_hash);
52215 + else
52216 + vfree(acl_role_set.r_hash);
52217 + }
52218 + if (name_set.n_hash) {
52219 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
52220 + PAGE_SIZE)
52221 + kfree(name_set.n_hash);
52222 + else
52223 + vfree(name_set.n_hash);
52224 + }
52225 +
52226 + if (inodev_set.i_hash) {
52227 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
52228 + PAGE_SIZE)
52229 + kfree(inodev_set.i_hash);
52230 + else
52231 + vfree(inodev_set.i_hash);
52232 + }
52233 +
52234 + gr_free_uidset();
52235 +
52236 + memset(&name_set, 0, sizeof (struct name_db));
52237 + memset(&inodev_set, 0, sizeof (struct inodev_db));
52238 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
52239 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
52240 +
52241 + default_role = NULL;
52242 + role_list = NULL;
52243 +
52244 + return;
52245 +}
52246 +
52247 +static __u32
52248 +count_user_objs(struct acl_object_label *userp)
52249 +{
52250 + struct acl_object_label o_tmp;
52251 + __u32 num = 0;
52252 +
52253 + while (userp) {
52254 + if (copy_from_user(&o_tmp, userp,
52255 + sizeof (struct acl_object_label)))
52256 + break;
52257 +
52258 + userp = o_tmp.prev;
52259 + num++;
52260 + }
52261 +
52262 + return num;
52263 +}
52264 +
52265 +static struct acl_subject_label *
52266 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
52267 +
52268 +static int
52269 +copy_user_glob(struct acl_object_label *obj)
52270 +{
52271 + struct acl_object_label *g_tmp, **guser;
52272 + unsigned int len;
52273 + char *tmp;
52274 +
52275 + if (obj->globbed == NULL)
52276 + return 0;
52277 +
52278 + guser = &obj->globbed;
52279 + while (*guser) {
52280 + g_tmp = (struct acl_object_label *)
52281 + acl_alloc(sizeof (struct acl_object_label));
52282 + if (g_tmp == NULL)
52283 + return -ENOMEM;
52284 +
52285 + if (copy_from_user(g_tmp, *guser,
52286 + sizeof (struct acl_object_label)))
52287 + return -EFAULT;
52288 +
52289 + len = strnlen_user(g_tmp->filename, PATH_MAX);
52290 +
52291 + if (!len || len >= PATH_MAX)
52292 + return -EINVAL;
52293 +
52294 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52295 + return -ENOMEM;
52296 +
52297 + if (copy_from_user(tmp, g_tmp->filename, len))
52298 + return -EFAULT;
52299 + tmp[len-1] = '\0';
52300 + g_tmp->filename = tmp;
52301 +
52302 + *guser = g_tmp;
52303 + guser = &(g_tmp->next);
52304 + }
52305 +
52306 + return 0;
52307 +}
52308 +
52309 +static int
52310 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
52311 + struct acl_role_label *role)
52312 +{
52313 + struct acl_object_label *o_tmp;
52314 + unsigned int len;
52315 + int ret;
52316 + char *tmp;
52317 +
52318 + while (userp) {
52319 + if ((o_tmp = (struct acl_object_label *)
52320 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
52321 + return -ENOMEM;
52322 +
52323 + if (copy_from_user(o_tmp, userp,
52324 + sizeof (struct acl_object_label)))
52325 + return -EFAULT;
52326 +
52327 + userp = o_tmp->prev;
52328 +
52329 + len = strnlen_user(o_tmp->filename, PATH_MAX);
52330 +
52331 + if (!len || len >= PATH_MAX)
52332 + return -EINVAL;
52333 +
52334 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52335 + return -ENOMEM;
52336 +
52337 + if (copy_from_user(tmp, o_tmp->filename, len))
52338 + return -EFAULT;
52339 + tmp[len-1] = '\0';
52340 + o_tmp->filename = tmp;
52341 +
52342 + insert_acl_obj_label(o_tmp, subj);
52343 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
52344 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
52345 + return -ENOMEM;
52346 +
52347 + ret = copy_user_glob(o_tmp);
52348 + if (ret)
52349 + return ret;
52350 +
52351 + if (o_tmp->nested) {
52352 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
52353 + if (IS_ERR(o_tmp->nested))
52354 + return PTR_ERR(o_tmp->nested);
52355 +
52356 + /* insert into nested subject list */
52357 + o_tmp->nested->next = role->hash->first;
52358 + role->hash->first = o_tmp->nested;
52359 + }
52360 + }
52361 +
52362 + return 0;
52363 +}
52364 +
52365 +static __u32
52366 +count_user_subjs(struct acl_subject_label *userp)
52367 +{
52368 + struct acl_subject_label s_tmp;
52369 + __u32 num = 0;
52370 +
52371 + while (userp) {
52372 + if (copy_from_user(&s_tmp, userp,
52373 + sizeof (struct acl_subject_label)))
52374 + break;
52375 +
52376 + userp = s_tmp.prev;
52377 + /* do not count nested subjects against this count, since
52378 + they are not included in the hash table, but are
52379 + attached to objects. We have already counted
52380 + the subjects in userspace for the allocation
52381 + stack
52382 + */
52383 + if (!(s_tmp.mode & GR_NESTED))
52384 + num++;
52385 + }
52386 +
52387 + return num;
52388 +}
52389 +
52390 +static int
52391 +copy_user_allowedips(struct acl_role_label *rolep)
52392 +{
52393 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
52394 +
52395 + ruserip = rolep->allowed_ips;
52396 +
52397 + while (ruserip) {
52398 + rlast = rtmp;
52399 +
52400 + if ((rtmp = (struct role_allowed_ip *)
52401 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
52402 + return -ENOMEM;
52403 +
52404 + if (copy_from_user(rtmp, ruserip,
52405 + sizeof (struct role_allowed_ip)))
52406 + return -EFAULT;
52407 +
52408 + ruserip = rtmp->prev;
52409 +
52410 + if (!rlast) {
52411 + rtmp->prev = NULL;
52412 + rolep->allowed_ips = rtmp;
52413 + } else {
52414 + rlast->next = rtmp;
52415 + rtmp->prev = rlast;
52416 + }
52417 +
52418 + if (!ruserip)
52419 + rtmp->next = NULL;
52420 + }
52421 +
52422 + return 0;
52423 +}
52424 +
52425 +static int
52426 +copy_user_transitions(struct acl_role_label *rolep)
52427 +{
52428 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
52429 +
52430 + unsigned int len;
52431 + char *tmp;
52432 +
52433 + rusertp = rolep->transitions;
52434 +
52435 + while (rusertp) {
52436 + rlast = rtmp;
52437 +
52438 + if ((rtmp = (struct role_transition *)
52439 + acl_alloc(sizeof (struct role_transition))) == NULL)
52440 + return -ENOMEM;
52441 +
52442 + if (copy_from_user(rtmp, rusertp,
52443 + sizeof (struct role_transition)))
52444 + return -EFAULT;
52445 +
52446 + rusertp = rtmp->prev;
52447 +
52448 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
52449 +
52450 + if (!len || len >= GR_SPROLE_LEN)
52451 + return -EINVAL;
52452 +
52453 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52454 + return -ENOMEM;
52455 +
52456 + if (copy_from_user(tmp, rtmp->rolename, len))
52457 + return -EFAULT;
52458 + tmp[len-1] = '\0';
52459 + rtmp->rolename = tmp;
52460 +
52461 + if (!rlast) {
52462 + rtmp->prev = NULL;
52463 + rolep->transitions = rtmp;
52464 + } else {
52465 + rlast->next = rtmp;
52466 + rtmp->prev = rlast;
52467 + }
52468 +
52469 + if (!rusertp)
52470 + rtmp->next = NULL;
52471 + }
52472 +
52473 + return 0;
52474 +}
52475 +
52476 +static struct acl_subject_label *
52477 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
52478 +{
52479 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
52480 + unsigned int len;
52481 + char *tmp;
52482 + __u32 num_objs;
52483 + struct acl_ip_label **i_tmp, *i_utmp2;
52484 + struct gr_hash_struct ghash;
52485 + struct subject_map *subjmap;
52486 + unsigned int i_num;
52487 + int err;
52488 +
52489 + s_tmp = lookup_subject_map(userp);
52490 +
52491 + /* we've already copied this subject into the kernel, just return
52492 + the reference to it, and don't copy it over again
52493 + */
52494 + if (s_tmp)
52495 + return(s_tmp);
52496 +
52497 + if ((s_tmp = (struct acl_subject_label *)
52498 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
52499 + return ERR_PTR(-ENOMEM);
52500 +
52501 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
52502 + if (subjmap == NULL)
52503 + return ERR_PTR(-ENOMEM);
52504 +
52505 + subjmap->user = userp;
52506 + subjmap->kernel = s_tmp;
52507 + insert_subj_map_entry(subjmap);
52508 +
52509 + if (copy_from_user(s_tmp, userp,
52510 + sizeof (struct acl_subject_label)))
52511 + return ERR_PTR(-EFAULT);
52512 +
52513 + len = strnlen_user(s_tmp->filename, PATH_MAX);
52514 +
52515 + if (!len || len >= PATH_MAX)
52516 + return ERR_PTR(-EINVAL);
52517 +
52518 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52519 + return ERR_PTR(-ENOMEM);
52520 +
52521 + if (copy_from_user(tmp, s_tmp->filename, len))
52522 + return ERR_PTR(-EFAULT);
52523 + tmp[len-1] = '\0';
52524 + s_tmp->filename = tmp;
52525 +
52526 + if (!strcmp(s_tmp->filename, "/"))
52527 + role->root_label = s_tmp;
52528 +
52529 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
52530 + return ERR_PTR(-EFAULT);
52531 +
52532 + /* copy user and group transition tables */
52533 +
52534 + if (s_tmp->user_trans_num) {
52535 + uid_t *uidlist;
52536 +
52537 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
52538 + if (uidlist == NULL)
52539 + return ERR_PTR(-ENOMEM);
52540 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
52541 + return ERR_PTR(-EFAULT);
52542 +
52543 + s_tmp->user_transitions = uidlist;
52544 + }
52545 +
52546 + if (s_tmp->group_trans_num) {
52547 + gid_t *gidlist;
52548 +
52549 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
52550 + if (gidlist == NULL)
52551 + return ERR_PTR(-ENOMEM);
52552 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
52553 + return ERR_PTR(-EFAULT);
52554 +
52555 + s_tmp->group_transitions = gidlist;
52556 + }
52557 +
52558 + /* set up object hash table */
52559 + num_objs = count_user_objs(ghash.first);
52560 +
52561 + s_tmp->obj_hash_size = num_objs;
52562 + s_tmp->obj_hash =
52563 + (struct acl_object_label **)
52564 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
52565 +
52566 + if (!s_tmp->obj_hash)
52567 + return ERR_PTR(-ENOMEM);
52568 +
52569 + memset(s_tmp->obj_hash, 0,
52570 + s_tmp->obj_hash_size *
52571 + sizeof (struct acl_object_label *));
52572 +
52573 + /* add in objects */
52574 + err = copy_user_objs(ghash.first, s_tmp, role);
52575 +
52576 + if (err)
52577 + return ERR_PTR(err);
52578 +
52579 + /* set pointer for parent subject */
52580 + if (s_tmp->parent_subject) {
52581 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
52582 +
52583 + if (IS_ERR(s_tmp2))
52584 + return s_tmp2;
52585 +
52586 + s_tmp->parent_subject = s_tmp2;
52587 + }
52588 +
52589 + /* add in ip acls */
52590 +
52591 + if (!s_tmp->ip_num) {
52592 + s_tmp->ips = NULL;
52593 + goto insert;
52594 + }
52595 +
52596 + i_tmp =
52597 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
52598 + sizeof (struct acl_ip_label *));
52599 +
52600 + if (!i_tmp)
52601 + return ERR_PTR(-ENOMEM);
52602 +
52603 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
52604 + *(i_tmp + i_num) =
52605 + (struct acl_ip_label *)
52606 + acl_alloc(sizeof (struct acl_ip_label));
52607 + if (!*(i_tmp + i_num))
52608 + return ERR_PTR(-ENOMEM);
52609 +
52610 + if (copy_from_user
52611 + (&i_utmp2, s_tmp->ips + i_num,
52612 + sizeof (struct acl_ip_label *)))
52613 + return ERR_PTR(-EFAULT);
52614 +
52615 + if (copy_from_user
52616 + (*(i_tmp + i_num), i_utmp2,
52617 + sizeof (struct acl_ip_label)))
52618 + return ERR_PTR(-EFAULT);
52619 +
52620 + if ((*(i_tmp + i_num))->iface == NULL)
52621 + continue;
52622 +
52623 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
52624 + if (!len || len >= IFNAMSIZ)
52625 + return ERR_PTR(-EINVAL);
52626 + tmp = acl_alloc(len);
52627 + if (tmp == NULL)
52628 + return ERR_PTR(-ENOMEM);
52629 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
52630 + return ERR_PTR(-EFAULT);
52631 + (*(i_tmp + i_num))->iface = tmp;
52632 + }
52633 +
52634 + s_tmp->ips = i_tmp;
52635 +
52636 +insert:
52637 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
52638 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
52639 + return ERR_PTR(-ENOMEM);
52640 +
52641 + return s_tmp;
52642 +}
52643 +
52644 +static int
52645 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
52646 +{
52647 + struct acl_subject_label s_pre;
52648 + struct acl_subject_label * ret;
52649 + int err;
52650 +
52651 + while (userp) {
52652 + if (copy_from_user(&s_pre, userp,
52653 + sizeof (struct acl_subject_label)))
52654 + return -EFAULT;
52655 +
52656 + /* do not add nested subjects here, add
52657 + while parsing objects
52658 + */
52659 +
52660 + if (s_pre.mode & GR_NESTED) {
52661 + userp = s_pre.prev;
52662 + continue;
52663 + }
52664 +
52665 + ret = do_copy_user_subj(userp, role);
52666 +
52667 + err = PTR_ERR(ret);
52668 + if (IS_ERR(ret))
52669 + return err;
52670 +
52671 + insert_acl_subj_label(ret, role);
52672 +
52673 + userp = s_pre.prev;
52674 + }
52675 +
52676 + return 0;
52677 +}
52678 +
52679 +static int
52680 +copy_user_acl(struct gr_arg *arg)
52681 +{
52682 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
52683 + struct sprole_pw *sptmp;
52684 + struct gr_hash_struct *ghash;
52685 + uid_t *domainlist;
52686 + unsigned int r_num;
52687 + unsigned int len;
52688 + char *tmp;
52689 + int err = 0;
52690 + __u16 i;
52691 + __u32 num_subjs;
52692 +
52693 + /* we need a default and kernel role */
52694 + if (arg->role_db.num_roles < 2)
52695 + return -EINVAL;
52696 +
52697 + /* copy special role authentication info from userspace */
52698 +
52699 + num_sprole_pws = arg->num_sprole_pws;
52700 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
52701 +
52702 + if (!acl_special_roles) {
52703 + err = -ENOMEM;
52704 + goto cleanup;
52705 + }
52706 +
52707 + for (i = 0; i < num_sprole_pws; i++) {
52708 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
52709 + if (!sptmp) {
52710 + err = -ENOMEM;
52711 + goto cleanup;
52712 + }
52713 + if (copy_from_user(sptmp, arg->sprole_pws + i,
52714 + sizeof (struct sprole_pw))) {
52715 + err = -EFAULT;
52716 + goto cleanup;
52717 + }
52718 +
52719 + len =
52720 + strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
52721 +
52722 + if (!len || len >= GR_SPROLE_LEN) {
52723 + err = -EINVAL;
52724 + goto cleanup;
52725 + }
52726 +
52727 + if ((tmp = (char *) acl_alloc(len)) == NULL) {
52728 + err = -ENOMEM;
52729 + goto cleanup;
52730 + }
52731 +
52732 + if (copy_from_user(tmp, sptmp->rolename, len)) {
52733 + err = -EFAULT;
52734 + goto cleanup;
52735 + }
52736 + tmp[len-1] = '\0';
52737 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52738 + printk(KERN_ALERT "Copying special role %s\n", tmp);
52739 +#endif
52740 + sptmp->rolename = tmp;
52741 + acl_special_roles[i] = sptmp;
52742 + }
52743 +
52744 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
52745 +
52746 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
52747 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
52748 +
52749 + if (!r_tmp) {
52750 + err = -ENOMEM;
52751 + goto cleanup;
52752 + }
52753 +
52754 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
52755 + sizeof (struct acl_role_label *))) {
52756 + err = -EFAULT;
52757 + goto cleanup;
52758 + }
52759 +
52760 + if (copy_from_user(r_tmp, r_utmp2,
52761 + sizeof (struct acl_role_label))) {
52762 + err = -EFAULT;
52763 + goto cleanup;
52764 + }
52765 +
52766 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
52767 +
52768 + if (!len || len >= PATH_MAX) {
52769 + err = -EINVAL;
52770 + goto cleanup;
52771 + }
52772 +
52773 + if ((tmp = (char *) acl_alloc(len)) == NULL) {
52774 + err = -ENOMEM;
52775 + goto cleanup;
52776 + }
52777 + if (copy_from_user(tmp, r_tmp->rolename, len)) {
52778 + err = -EFAULT;
52779 + goto cleanup;
52780 + }
52781 + tmp[len-1] = '\0';
52782 + r_tmp->rolename = tmp;
52783 +
52784 + if (!strcmp(r_tmp->rolename, "default")
52785 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
52786 + default_role = r_tmp;
52787 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
52788 + kernel_role = r_tmp;
52789 + }
52790 +
52791 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL) {
52792 + err = -ENOMEM;
52793 + goto cleanup;
52794 + }
52795 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct))) {
52796 + err = -EFAULT;
52797 + goto cleanup;
52798 + }
52799 +
52800 + r_tmp->hash = ghash;
52801 +
52802 + num_subjs = count_user_subjs(r_tmp->hash->first);
52803 +
52804 + r_tmp->subj_hash_size = num_subjs;
52805 + r_tmp->subj_hash =
52806 + (struct acl_subject_label **)
52807 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
52808 +
52809 + if (!r_tmp->subj_hash) {
52810 + err = -ENOMEM;
52811 + goto cleanup;
52812 + }
52813 +
52814 + err = copy_user_allowedips(r_tmp);
52815 + if (err)
52816 + goto cleanup;
52817 +
52818 + /* copy domain info */
52819 + if (r_tmp->domain_children != NULL) {
52820 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
52821 + if (domainlist == NULL) {
52822 + err = -ENOMEM;
52823 + goto cleanup;
52824 + }
52825 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t))) {
52826 + err = -EFAULT;
52827 + goto cleanup;
52828 + }
52829 + r_tmp->domain_children = domainlist;
52830 + }
52831 +
52832 + err = copy_user_transitions(r_tmp);
52833 + if (err)
52834 + goto cleanup;
52835 +
52836 + memset(r_tmp->subj_hash, 0,
52837 + r_tmp->subj_hash_size *
52838 + sizeof (struct acl_subject_label *));
52839 +
52840 + err = copy_user_subjs(r_tmp->hash->first, r_tmp);
52841 +
52842 + if (err)
52843 + goto cleanup;
52844 +
52845 + /* set nested subject list to null */
52846 + r_tmp->hash->first = NULL;
52847 +
52848 + insert_acl_role_label(r_tmp);
52849 + }
52850 +
52851 + goto return_err;
52852 + cleanup:
52853 + free_variables();
52854 + return_err:
52855 + return err;
52856 +
52857 +}
52858 +
52859 +static int
52860 +gracl_init(struct gr_arg *args)
52861 +{
52862 + int error = 0;
52863 +
52864 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
52865 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
52866 +
52867 + if (init_variables(args)) {
52868 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
52869 + error = -ENOMEM;
52870 + free_variables();
52871 + goto out;
52872 + }
52873 +
52874 + error = copy_user_acl(args);
52875 + free_init_variables();
52876 + if (error) {
52877 + free_variables();
52878 + goto out;
52879 + }
52880 +
52881 + if ((error = gr_set_acls(0))) {
52882 + free_variables();
52883 + goto out;
52884 + }
52885 +
52886 + pax_open_kernel();
52887 + gr_status |= GR_READY;
52888 + pax_close_kernel();
52889 +
52890 + out:
52891 + return error;
52892 +}
52893 +
52894 +/* derived from glibc fnmatch() 0: match, 1: no match*/
52895 +
52896 +static int
52897 +glob_match(const char *p, const char *n)
52898 +{
52899 + char c;
52900 +
52901 + while ((c = *p++) != '\0') {
52902 + switch (c) {
52903 + case '?':
52904 + if (*n == '\0')
52905 + return 1;
52906 + else if (*n == '/')
52907 + return 1;
52908 + break;
52909 + case '\\':
52910 + if (*n != c)
52911 + return 1;
52912 + break;
52913 + case '*':
52914 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
52915 + if (*n == '/')
52916 + return 1;
52917 + else if (c == '?') {
52918 + if (*n == '\0')
52919 + return 1;
52920 + else
52921 + ++n;
52922 + }
52923 + }
52924 + if (c == '\0') {
52925 + return 0;
52926 + } else {
52927 + const char *endp;
52928 +
52929 + if ((endp = strchr(n, '/')) == NULL)
52930 + endp = n + strlen(n);
52931 +
52932 + if (c == '[') {
52933 + for (--p; n < endp; ++n)
52934 + if (!glob_match(p, n))
52935 + return 0;
52936 + } else if (c == '/') {
52937 + while (*n != '\0' && *n != '/')
52938 + ++n;
52939 + if (*n == '/' && !glob_match(p, n + 1))
52940 + return 0;
52941 + } else {
52942 + for (--p; n < endp; ++n)
52943 + if (*n == c && !glob_match(p, n))
52944 + return 0;
52945 + }
52946 +
52947 + return 1;
52948 + }
52949 + case '[':
52950 + {
52951 + int not;
52952 + char cold;
52953 +
52954 + if (*n == '\0' || *n == '/')
52955 + return 1;
52956 +
52957 + not = (*p == '!' || *p == '^');
52958 + if (not)
52959 + ++p;
52960 +
52961 + c = *p++;
52962 + for (;;) {
52963 + unsigned char fn = (unsigned char)*n;
52964 +
52965 + if (c == '\0')
52966 + return 1;
52967 + else {
52968 + if (c == fn)
52969 + goto matched;
52970 + cold = c;
52971 + c = *p++;
52972 +
52973 + if (c == '-' && *p != ']') {
52974 + unsigned char cend = *p++;
52975 +
52976 + if (cend == '\0')
52977 + return 1;
52978 +
52979 + if (cold <= fn && fn <= cend)
52980 + goto matched;
52981 +
52982 + c = *p++;
52983 + }
52984 + }
52985 +
52986 + if (c == ']')
52987 + break;
52988 + }
52989 + if (!not)
52990 + return 1;
52991 + break;
52992 + matched:
52993 + while (c != ']') {
52994 + if (c == '\0')
52995 + return 1;
52996 +
52997 + c = *p++;
52998 + }
52999 + if (not)
53000 + return 1;
53001 + }
53002 + break;
53003 + default:
53004 + if (c != *n)
53005 + return 1;
53006 + }
53007 +
53008 + ++n;
53009 + }
53010 +
53011 + if (*n == '\0')
53012 + return 0;
53013 +
53014 + if (*n == '/')
53015 + return 0;
53016 +
53017 + return 1;
53018 +}
53019 +
53020 +static struct acl_object_label *
53021 +chk_glob_label(struct acl_object_label *globbed,
53022 + struct dentry *dentry, struct vfsmount *mnt, char **path)
53023 +{
53024 + struct acl_object_label *tmp;
53025 +
53026 + if (*path == NULL)
53027 + *path = gr_to_filename_nolock(dentry, mnt);
53028 +
53029 + tmp = globbed;
53030 +
53031 + while (tmp) {
53032 + if (!glob_match(tmp->filename, *path))
53033 + return tmp;
53034 + tmp = tmp->next;
53035 + }
53036 +
53037 + return NULL;
53038 +}
53039 +
53040 +static struct acl_object_label *
53041 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53042 + const ino_t curr_ino, const dev_t curr_dev,
53043 + const struct acl_subject_label *subj, char **path, const int checkglob)
53044 +{
53045 + struct acl_subject_label *tmpsubj;
53046 + struct acl_object_label *retval;
53047 + struct acl_object_label *retval2;
53048 +
53049 + tmpsubj = (struct acl_subject_label *) subj;
53050 + read_lock(&gr_inode_lock);
53051 + do {
53052 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
53053 + if (retval) {
53054 + if (checkglob && retval->globbed) {
53055 + retval2 = chk_glob_label(retval->globbed, (struct dentry *)orig_dentry,
53056 + (struct vfsmount *)orig_mnt, path);
53057 + if (retval2)
53058 + retval = retval2;
53059 + }
53060 + break;
53061 + }
53062 + } while ((tmpsubj = tmpsubj->parent_subject));
53063 + read_unlock(&gr_inode_lock);
53064 +
53065 + return retval;
53066 +}
53067 +
53068 +static __inline__ struct acl_object_label *
53069 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53070 + struct dentry *curr_dentry,
53071 + const struct acl_subject_label *subj, char **path, const int checkglob)
53072 +{
53073 + int newglob = checkglob;
53074 + ino_t inode;
53075 + dev_t device;
53076 +
53077 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
53078 + as we don't want a / * rule to match instead of the / object
53079 + don't do this for create lookups that call this function though, since they're looking up
53080 + on the parent and thus need globbing checks on all paths
53081 + */
53082 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
53083 + newglob = GR_NO_GLOB;
53084 +
53085 + spin_lock(&curr_dentry->d_lock);
53086 + inode = curr_dentry->d_inode->i_ino;
53087 + device = __get_dev(curr_dentry);
53088 + spin_unlock(&curr_dentry->d_lock);
53089 +
53090 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
53091 +}
53092 +
53093 +static struct acl_object_label *
53094 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53095 + const struct acl_subject_label *subj, char *path, const int checkglob)
53096 +{
53097 + struct dentry *dentry = (struct dentry *) l_dentry;
53098 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53099 + struct acl_object_label *retval;
53100 + struct dentry *parent;
53101 +
53102 + write_seqlock(&rename_lock);
53103 + br_read_lock(vfsmount_lock);
53104 +
53105 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt || mnt == sock_mnt ||
53106 +#ifdef CONFIG_HUGETLBFS
53107 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
53108 +#endif
53109 + /* ignore Eric Biederman */
53110 + IS_PRIVATE(l_dentry->d_inode))) {
53111 + retval = fakefs_obj;
53112 + goto out;
53113 + }
53114 +
53115 + for (;;) {
53116 + if (dentry == real_root.dentry && mnt == real_root.mnt)
53117 + break;
53118 +
53119 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53120 + if (mnt->mnt_parent == mnt)
53121 + break;
53122 +
53123 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53124 + if (retval != NULL)
53125 + goto out;
53126 +
53127 + dentry = mnt->mnt_mountpoint;
53128 + mnt = mnt->mnt_parent;
53129 + continue;
53130 + }
53131 +
53132 + parent = dentry->d_parent;
53133 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53134 + if (retval != NULL)
53135 + goto out;
53136 +
53137 + dentry = parent;
53138 + }
53139 +
53140 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53141 +
53142 + /* real_root is pinned so we don't have to hold a reference */
53143 + if (retval == NULL)
53144 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
53145 +out:
53146 + br_read_unlock(vfsmount_lock);
53147 + write_sequnlock(&rename_lock);
53148 +
53149 + BUG_ON(retval == NULL);
53150 +
53151 + return retval;
53152 +}
53153 +
53154 +static __inline__ struct acl_object_label *
53155 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53156 + const struct acl_subject_label *subj)
53157 +{
53158 + char *path = NULL;
53159 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
53160 +}
53161 +
53162 +static __inline__ struct acl_object_label *
53163 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53164 + const struct acl_subject_label *subj)
53165 +{
53166 + char *path = NULL;
53167 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
53168 +}
53169 +
53170 +static __inline__ struct acl_object_label *
53171 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53172 + const struct acl_subject_label *subj, char *path)
53173 +{
53174 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
53175 +}
53176 +
53177 +static struct acl_subject_label *
53178 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53179 + const struct acl_role_label *role)
53180 +{
53181 + struct dentry *dentry = (struct dentry *) l_dentry;
53182 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53183 + struct acl_subject_label *retval;
53184 + struct dentry *parent;
53185 +
53186 + write_seqlock(&rename_lock);
53187 + br_read_lock(vfsmount_lock);
53188 +
53189 + for (;;) {
53190 + if (dentry == real_root.dentry && mnt == real_root.mnt)
53191 + break;
53192 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53193 + if (mnt->mnt_parent == mnt)
53194 + break;
53195 +
53196 + spin_lock(&dentry->d_lock);
53197 + read_lock(&gr_inode_lock);
53198 + retval =
53199 + lookup_acl_subj_label(dentry->d_inode->i_ino,
53200 + __get_dev(dentry), role);
53201 + read_unlock(&gr_inode_lock);
53202 + spin_unlock(&dentry->d_lock);
53203 + if (retval != NULL)
53204 + goto out;
53205 +
53206 + dentry = mnt->mnt_mountpoint;
53207 + mnt = mnt->mnt_parent;
53208 + continue;
53209 + }
53210 +
53211 + spin_lock(&dentry->d_lock);
53212 + read_lock(&gr_inode_lock);
53213 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53214 + __get_dev(dentry), role);
53215 + read_unlock(&gr_inode_lock);
53216 + parent = dentry->d_parent;
53217 + spin_unlock(&dentry->d_lock);
53218 +
53219 + if (retval != NULL)
53220 + goto out;
53221 +
53222 + dentry = parent;
53223 + }
53224 +
53225 + spin_lock(&dentry->d_lock);
53226 + read_lock(&gr_inode_lock);
53227 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53228 + __get_dev(dentry), role);
53229 + read_unlock(&gr_inode_lock);
53230 + spin_unlock(&dentry->d_lock);
53231 +
53232 + if (unlikely(retval == NULL)) {
53233 + /* real_root is pinned, we don't need to hold a reference */
53234 + read_lock(&gr_inode_lock);
53235 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
53236 + __get_dev(real_root.dentry), role);
53237 + read_unlock(&gr_inode_lock);
53238 + }
53239 +out:
53240 + br_read_unlock(vfsmount_lock);
53241 + write_sequnlock(&rename_lock);
53242 +
53243 + BUG_ON(retval == NULL);
53244 +
53245 + return retval;
53246 +}
53247 +
53248 +static void
53249 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
53250 +{
53251 + struct task_struct *task = current;
53252 + const struct cred *cred = current_cred();
53253 +
53254 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
53255 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53256 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53257 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
53258 +
53259 + return;
53260 +}
53261 +
53262 +static void
53263 +gr_log_learn_sysctl(const char *path, const __u32 mode)
53264 +{
53265 + struct task_struct *task = current;
53266 + const struct cred *cred = current_cred();
53267 +
53268 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
53269 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53270 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53271 + 1UL, 1UL, path, (unsigned long) mode, &task->signal->saved_ip);
53272 +
53273 + return;
53274 +}
53275 +
53276 +static void
53277 +gr_log_learn_id_change(const char type, const unsigned int real,
53278 + const unsigned int effective, const unsigned int fs)
53279 +{
53280 + struct task_struct *task = current;
53281 + const struct cred *cred = current_cred();
53282 +
53283 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
53284 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53285 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53286 + type, real, effective, fs, &task->signal->saved_ip);
53287 +
53288 + return;
53289 +}
53290 +
53291 +__u32
53292 +gr_check_link(const struct dentry * new_dentry,
53293 + const struct dentry * parent_dentry,
53294 + const struct vfsmount * parent_mnt,
53295 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
53296 +{
53297 + struct acl_object_label *obj;
53298 + __u32 oldmode, newmode;
53299 + __u32 needmode;
53300 +
53301 + if (unlikely(!(gr_status & GR_READY)))
53302 + return (GR_CREATE | GR_LINK);
53303 +
53304 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
53305 + oldmode = obj->mode;
53306 +
53307 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53308 + oldmode |= (GR_CREATE | GR_LINK);
53309 +
53310 + needmode = GR_CREATE | GR_AUDIT_CREATE | GR_SUPPRESS;
53311 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
53312 + needmode |= GR_SETID | GR_AUDIT_SETID;
53313 +
53314 + newmode =
53315 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
53316 + oldmode | needmode);
53317 +
53318 + needmode = newmode & (GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC |
53319 + GR_SETID | GR_READ | GR_FIND | GR_DELETE |
53320 + GR_INHERIT | GR_AUDIT_INHERIT);
53321 +
53322 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID) && !(newmode & GR_SETID))
53323 + goto bad;
53324 +
53325 + if ((oldmode & needmode) != needmode)
53326 + goto bad;
53327 +
53328 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
53329 + if ((newmode & needmode) != needmode)
53330 + goto bad;
53331 +
53332 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
53333 + return newmode;
53334 +bad:
53335 + needmode = oldmode;
53336 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
53337 + needmode |= GR_SETID;
53338 +
53339 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
53340 + gr_log_learn(old_dentry, old_mnt, needmode);
53341 + return (GR_CREATE | GR_LINK);
53342 + } else if (newmode & GR_SUPPRESS)
53343 + return GR_SUPPRESS;
53344 + else
53345 + return 0;
53346 +}
53347 +
53348 +__u32
53349 +gr_search_file(const struct dentry * dentry, const __u32 mode,
53350 + const struct vfsmount * mnt)
53351 +{
53352 + __u32 retval = mode;
53353 + struct acl_subject_label *curracl;
53354 + struct acl_object_label *currobj;
53355 +
53356 + if (unlikely(!(gr_status & GR_READY)))
53357 + return (mode & ~GR_AUDITS);
53358 +
53359 + curracl = current->acl;
53360 +
53361 + currobj = chk_obj_label(dentry, mnt, curracl);
53362 + retval = currobj->mode & mode;
53363 +
53364 + /* if we're opening a specified transfer file for writing
53365 + (e.g. /dev/initctl), then transfer our role to init
53366 + */
53367 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
53368 + current->role->roletype & GR_ROLE_PERSIST)) {
53369 + struct task_struct *task = init_pid_ns.child_reaper;
53370 +
53371 + if (task->role != current->role) {
53372 + task->acl_sp_role = 0;
53373 + task->acl_role_id = current->acl_role_id;
53374 + task->role = current->role;
53375 + rcu_read_lock();
53376 + read_lock(&grsec_exec_file_lock);
53377 + gr_apply_subject_to_task(task);
53378 + read_unlock(&grsec_exec_file_lock);
53379 + rcu_read_unlock();
53380 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
53381 + }
53382 + }
53383 +
53384 + if (unlikely
53385 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
53386 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
53387 + __u32 new_mode = mode;
53388 +
53389 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53390 +
53391 + retval = new_mode;
53392 +
53393 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
53394 + new_mode |= GR_INHERIT;
53395 +
53396 + if (!(mode & GR_NOLEARN))
53397 + gr_log_learn(dentry, mnt, new_mode);
53398 + }
53399 +
53400 + return retval;
53401 +}
53402 +
53403 +__u32
53404 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
53405 + const struct vfsmount * mnt, const __u32 mode)
53406 +{
53407 + struct name_entry *match;
53408 + struct acl_object_label *matchpo;
53409 + struct acl_subject_label *curracl;
53410 + char *path;
53411 + __u32 retval;
53412 +
53413 + if (unlikely(!(gr_status & GR_READY)))
53414 + return (mode & ~GR_AUDITS);
53415 +
53416 + preempt_disable();
53417 + path = gr_to_filename_rbac(new_dentry, mnt);
53418 + match = lookup_name_entry_create(path);
53419 +
53420 + if (!match)
53421 + goto check_parent;
53422 +
53423 + curracl = current->acl;
53424 +
53425 + read_lock(&gr_inode_lock);
53426 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
53427 + read_unlock(&gr_inode_lock);
53428 +
53429 + if (matchpo) {
53430 + if ((matchpo->mode & mode) !=
53431 + (mode & ~(GR_AUDITS | GR_SUPPRESS))
53432 + && curracl->mode & (GR_LEARN | GR_INHERITLEARN)) {
53433 + __u32 new_mode = mode;
53434 +
53435 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53436 +
53437 + gr_log_learn(new_dentry, mnt, new_mode);
53438 +
53439 + preempt_enable();
53440 + return new_mode;
53441 + }
53442 + preempt_enable();
53443 + return (matchpo->mode & mode);
53444 + }
53445 +
53446 + check_parent:
53447 + curracl = current->acl;
53448 +
53449 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
53450 + retval = matchpo->mode & mode;
53451 +
53452 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
53453 + && (curracl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53454 + __u32 new_mode = mode;
53455 +
53456 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53457 +
53458 + gr_log_learn(new_dentry, mnt, new_mode);
53459 + preempt_enable();
53460 + return new_mode;
53461 + }
53462 +
53463 + preempt_enable();
53464 + return retval;
53465 +}
53466 +
53467 +int
53468 +gr_check_hidden_task(const struct task_struct *task)
53469 +{
53470 + if (unlikely(!(gr_status & GR_READY)))
53471 + return 0;
53472 +
53473 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
53474 + return 1;
53475 +
53476 + return 0;
53477 +}
53478 +
53479 +int
53480 +gr_check_protected_task(const struct task_struct *task)
53481 +{
53482 + if (unlikely(!(gr_status & GR_READY) || !task))
53483 + return 0;
53484 +
53485 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53486 + task->acl != current->acl)
53487 + return 1;
53488 +
53489 + return 0;
53490 +}
53491 +
53492 +int
53493 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
53494 +{
53495 + struct task_struct *p;
53496 + int ret = 0;
53497 +
53498 + if (unlikely(!(gr_status & GR_READY) || !pid))
53499 + return ret;
53500 +
53501 + read_lock(&tasklist_lock);
53502 + do_each_pid_task(pid, type, p) {
53503 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53504 + p->acl != current->acl) {
53505 + ret = 1;
53506 + goto out;
53507 + }
53508 + } while_each_pid_task(pid, type, p);
53509 +out:
53510 + read_unlock(&tasklist_lock);
53511 +
53512 + return ret;
53513 +}
53514 +
53515 +void
53516 +gr_copy_label(struct task_struct *tsk)
53517 +{
53518 + tsk->signal->used_accept = 0;
53519 + tsk->acl_sp_role = 0;
53520 + tsk->acl_role_id = current->acl_role_id;
53521 + tsk->acl = current->acl;
53522 + tsk->role = current->role;
53523 + tsk->signal->curr_ip = current->signal->curr_ip;
53524 + tsk->signal->saved_ip = current->signal->saved_ip;
53525 + if (current->exec_file)
53526 + get_file(current->exec_file);
53527 + tsk->exec_file = current->exec_file;
53528 + tsk->is_writable = current->is_writable;
53529 + if (unlikely(current->signal->used_accept)) {
53530 + current->signal->curr_ip = 0;
53531 + current->signal->saved_ip = 0;
53532 + }
53533 +
53534 + return;
53535 +}
53536 +
53537 +static void
53538 +gr_set_proc_res(struct task_struct *task)
53539 +{
53540 + struct acl_subject_label *proc;
53541 + unsigned short i;
53542 +
53543 + proc = task->acl;
53544 +
53545 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
53546 + return;
53547 +
53548 + for (i = 0; i < RLIM_NLIMITS; i++) {
53549 + if (!(proc->resmask & (1 << i)))
53550 + continue;
53551 +
53552 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
53553 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
53554 + }
53555 +
53556 + return;
53557 +}
53558 +
53559 +extern int __gr_process_user_ban(struct user_struct *user);
53560 +
53561 +int
53562 +gr_check_user_change(int real, int effective, int fs)
53563 +{
53564 + unsigned int i;
53565 + __u16 num;
53566 + uid_t *uidlist;
53567 + int curuid;
53568 + int realok = 0;
53569 + int effectiveok = 0;
53570 + int fsok = 0;
53571 +
53572 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
53573 + struct user_struct *user;
53574 +
53575 + if (real == -1)
53576 + goto skipit;
53577 +
53578 + user = find_user(real);
53579 + if (user == NULL)
53580 + goto skipit;
53581 +
53582 + if (__gr_process_user_ban(user)) {
53583 + /* for find_user */
53584 + free_uid(user);
53585 + return 1;
53586 + }
53587 +
53588 + /* for find_user */
53589 + free_uid(user);
53590 +
53591 +skipit:
53592 +#endif
53593 +
53594 + if (unlikely(!(gr_status & GR_READY)))
53595 + return 0;
53596 +
53597 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53598 + gr_log_learn_id_change('u', real, effective, fs);
53599 +
53600 + num = current->acl->user_trans_num;
53601 + uidlist = current->acl->user_transitions;
53602 +
53603 + if (uidlist == NULL)
53604 + return 0;
53605 +
53606 + if (real == -1)
53607 + realok = 1;
53608 + if (effective == -1)
53609 + effectiveok = 1;
53610 + if (fs == -1)
53611 + fsok = 1;
53612 +
53613 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
53614 + for (i = 0; i < num; i++) {
53615 + curuid = (int)uidlist[i];
53616 + if (real == curuid)
53617 + realok = 1;
53618 + if (effective == curuid)
53619 + effectiveok = 1;
53620 + if (fs == curuid)
53621 + fsok = 1;
53622 + }
53623 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
53624 + for (i = 0; i < num; i++) {
53625 + curuid = (int)uidlist[i];
53626 + if (real == curuid)
53627 + break;
53628 + if (effective == curuid)
53629 + break;
53630 + if (fs == curuid)
53631 + break;
53632 + }
53633 + /* not in deny list */
53634 + if (i == num) {
53635 + realok = 1;
53636 + effectiveok = 1;
53637 + fsok = 1;
53638 + }
53639 + }
53640 +
53641 + if (realok && effectiveok && fsok)
53642 + return 0;
53643 + else {
53644 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53645 + return 1;
53646 + }
53647 +}
53648 +
53649 +int
53650 +gr_check_group_change(int real, int effective, int fs)
53651 +{
53652 + unsigned int i;
53653 + __u16 num;
53654 + gid_t *gidlist;
53655 + int curgid;
53656 + int realok = 0;
53657 + int effectiveok = 0;
53658 + int fsok = 0;
53659 +
53660 + if (unlikely(!(gr_status & GR_READY)))
53661 + return 0;
53662 +
53663 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53664 + gr_log_learn_id_change('g', real, effective, fs);
53665 +
53666 + num = current->acl->group_trans_num;
53667 + gidlist = current->acl->group_transitions;
53668 +
53669 + if (gidlist == NULL)
53670 + return 0;
53671 +
53672 + if (real == -1)
53673 + realok = 1;
53674 + if (effective == -1)
53675 + effectiveok = 1;
53676 + if (fs == -1)
53677 + fsok = 1;
53678 +
53679 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
53680 + for (i = 0; i < num; i++) {
53681 + curgid = (int)gidlist[i];
53682 + if (real == curgid)
53683 + realok = 1;
53684 + if (effective == curgid)
53685 + effectiveok = 1;
53686 + if (fs == curgid)
53687 + fsok = 1;
53688 + }
53689 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
53690 + for (i = 0; i < num; i++) {
53691 + curgid = (int)gidlist[i];
53692 + if (real == curgid)
53693 + break;
53694 + if (effective == curgid)
53695 + break;
53696 + if (fs == curgid)
53697 + break;
53698 + }
53699 + /* not in deny list */
53700 + if (i == num) {
53701 + realok = 1;
53702 + effectiveok = 1;
53703 + fsok = 1;
53704 + }
53705 + }
53706 +
53707 + if (realok && effectiveok && fsok)
53708 + return 0;
53709 + else {
53710 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53711 + return 1;
53712 + }
53713 +}
53714 +
53715 +void
53716 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
53717 +{
53718 + struct acl_role_label *role = task->role;
53719 + struct acl_subject_label *subj = NULL;
53720 + struct acl_object_label *obj;
53721 + struct file *filp;
53722 +
53723 + if (unlikely(!(gr_status & GR_READY)))
53724 + return;
53725 +
53726 + filp = task->exec_file;
53727 +
53728 + /* kernel process, we'll give them the kernel role */
53729 + if (unlikely(!filp)) {
53730 + task->role = kernel_role;
53731 + task->acl = kernel_role->root_label;
53732 + return;
53733 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
53734 + role = lookup_acl_role_label(task, uid, gid);
53735 +
53736 + /* perform subject lookup in possibly new role
53737 + we can use this result below in the case where role == task->role
53738 + */
53739 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
53740 +
53741 + /* if we changed uid/gid, but result in the same role
53742 + and are using inheritance, don't lose the inherited subject
53743 + if current subject is other than what normal lookup
53744 + would result in, we arrived via inheritance, don't
53745 + lose subject
53746 + */
53747 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
53748 + (subj == task->acl)))
53749 + task->acl = subj;
53750 +
53751 + task->role = role;
53752 +
53753 + task->is_writable = 0;
53754 +
53755 + /* ignore additional mmap checks for processes that are writable
53756 + by the default ACL */
53757 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53758 + if (unlikely(obj->mode & GR_WRITE))
53759 + task->is_writable = 1;
53760 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
53761 + if (unlikely(obj->mode & GR_WRITE))
53762 + task->is_writable = 1;
53763 +
53764 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53765 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53766 +#endif
53767 +
53768 + gr_set_proc_res(task);
53769 +
53770 + return;
53771 +}
53772 +
53773 +int
53774 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
53775 + const int unsafe_share)
53776 +{
53777 + struct task_struct *task = current;
53778 + struct acl_subject_label *newacl;
53779 + struct acl_object_label *obj;
53780 + __u32 retmode;
53781 +
53782 + if (unlikely(!(gr_status & GR_READY)))
53783 + return 0;
53784 +
53785 + newacl = chk_subj_label(dentry, mnt, task->role);
53786 +
53787 + task_lock(task);
53788 + if ((((task->ptrace & PT_PTRACED) || unsafe_share) &&
53789 + !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
53790 + !(task->role->roletype & GR_ROLE_GOD) &&
53791 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
53792 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN)))) {
53793 + task_unlock(task);
53794 + if (unsafe_share)
53795 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
53796 + else
53797 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
53798 + return -EACCES;
53799 + }
53800 + task_unlock(task);
53801 +
53802 + obj = chk_obj_label(dentry, mnt, task->acl);
53803 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
53804 +
53805 + if (!(task->acl->mode & GR_INHERITLEARN) &&
53806 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
53807 + if (obj->nested)
53808 + task->acl = obj->nested;
53809 + else
53810 + task->acl = newacl;
53811 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
53812 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
53813 +
53814 + task->is_writable = 0;
53815 +
53816 + /* ignore additional mmap checks for processes that are writable
53817 + by the default ACL */
53818 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
53819 + if (unlikely(obj->mode & GR_WRITE))
53820 + task->is_writable = 1;
53821 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
53822 + if (unlikely(obj->mode & GR_WRITE))
53823 + task->is_writable = 1;
53824 +
53825 + gr_set_proc_res(task);
53826 +
53827 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53828 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53829 +#endif
53830 + return 0;
53831 +}
53832 +
53833 +/* always called with valid inodev ptr */
53834 +static void
53835 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
53836 +{
53837 + struct acl_object_label *matchpo;
53838 + struct acl_subject_label *matchps;
53839 + struct acl_subject_label *subj;
53840 + struct acl_role_label *role;
53841 + unsigned int x;
53842 +
53843 + FOR_EACH_ROLE_START(role)
53844 + FOR_EACH_SUBJECT_START(role, subj, x)
53845 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
53846 + matchpo->mode |= GR_DELETED;
53847 + FOR_EACH_SUBJECT_END(subj,x)
53848 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
53849 + if (subj->inode == ino && subj->device == dev)
53850 + subj->mode |= GR_DELETED;
53851 + FOR_EACH_NESTED_SUBJECT_END(subj)
53852 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
53853 + matchps->mode |= GR_DELETED;
53854 + FOR_EACH_ROLE_END(role)
53855 +
53856 + inodev->nentry->deleted = 1;
53857 +
53858 + return;
53859 +}
53860 +
53861 +void
53862 +gr_handle_delete(const ino_t ino, const dev_t dev)
53863 +{
53864 + struct inodev_entry *inodev;
53865 +
53866 + if (unlikely(!(gr_status & GR_READY)))
53867 + return;
53868 +
53869 + write_lock(&gr_inode_lock);
53870 + inodev = lookup_inodev_entry(ino, dev);
53871 + if (inodev != NULL)
53872 + do_handle_delete(inodev, ino, dev);
53873 + write_unlock(&gr_inode_lock);
53874 +
53875 + return;
53876 +}
53877 +
53878 +static void
53879 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
53880 + const ino_t newinode, const dev_t newdevice,
53881 + struct acl_subject_label *subj)
53882 +{
53883 + unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
53884 + struct acl_object_label *match;
53885 +
53886 + match = subj->obj_hash[index];
53887 +
53888 + while (match && (match->inode != oldinode ||
53889 + match->device != olddevice ||
53890 + !(match->mode & GR_DELETED)))
53891 + match = match->next;
53892 +
53893 + if (match && (match->inode == oldinode)
53894 + && (match->device == olddevice)
53895 + && (match->mode & GR_DELETED)) {
53896 + if (match->prev == NULL) {
53897 + subj->obj_hash[index] = match->next;
53898 + if (match->next != NULL)
53899 + match->next->prev = NULL;
53900 + } else {
53901 + match->prev->next = match->next;
53902 + if (match->next != NULL)
53903 + match->next->prev = match->prev;
53904 + }
53905 + match->prev = NULL;
53906 + match->next = NULL;
53907 + match->inode = newinode;
53908 + match->device = newdevice;
53909 + match->mode &= ~GR_DELETED;
53910 +
53911 + insert_acl_obj_label(match, subj);
53912 + }
53913 +
53914 + return;
53915 +}
53916 +
53917 +static void
53918 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
53919 + const ino_t newinode, const dev_t newdevice,
53920 + struct acl_role_label *role)
53921 +{
53922 + unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
53923 + struct acl_subject_label *match;
53924 +
53925 + match = role->subj_hash[index];
53926 +
53927 + while (match && (match->inode != oldinode ||
53928 + match->device != olddevice ||
53929 + !(match->mode & GR_DELETED)))
53930 + match = match->next;
53931 +
53932 + if (match && (match->inode == oldinode)
53933 + && (match->device == olddevice)
53934 + && (match->mode & GR_DELETED)) {
53935 + if (match->prev == NULL) {
53936 + role->subj_hash[index] = match->next;
53937 + if (match->next != NULL)
53938 + match->next->prev = NULL;
53939 + } else {
53940 + match->prev->next = match->next;
53941 + if (match->next != NULL)
53942 + match->next->prev = match->prev;
53943 + }
53944 + match->prev = NULL;
53945 + match->next = NULL;
53946 + match->inode = newinode;
53947 + match->device = newdevice;
53948 + match->mode &= ~GR_DELETED;
53949 +
53950 + insert_acl_subj_label(match, role);
53951 + }
53952 +
53953 + return;
53954 +}
53955 +
53956 +static void
53957 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
53958 + const ino_t newinode, const dev_t newdevice)
53959 +{
53960 + unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
53961 + struct inodev_entry *match;
53962 +
53963 + match = inodev_set.i_hash[index];
53964 +
53965 + while (match && (match->nentry->inode != oldinode ||
53966 + match->nentry->device != olddevice || !match->nentry->deleted))
53967 + match = match->next;
53968 +
53969 + if (match && (match->nentry->inode == oldinode)
53970 + && (match->nentry->device == olddevice) &&
53971 + match->nentry->deleted) {
53972 + if (match->prev == NULL) {
53973 + inodev_set.i_hash[index] = match->next;
53974 + if (match->next != NULL)
53975 + match->next->prev = NULL;
53976 + } else {
53977 + match->prev->next = match->next;
53978 + if (match->next != NULL)
53979 + match->next->prev = match->prev;
53980 + }
53981 + match->prev = NULL;
53982 + match->next = NULL;
53983 + match->nentry->inode = newinode;
53984 + match->nentry->device = newdevice;
53985 + match->nentry->deleted = 0;
53986 +
53987 + insert_inodev_entry(match);
53988 + }
53989 +
53990 + return;
53991 +}
53992 +
53993 +static void
53994 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
53995 + const struct vfsmount *mnt)
53996 +{
53997 + struct acl_subject_label *subj;
53998 + struct acl_role_label *role;
53999 + unsigned int x;
54000 + ino_t ino = dentry->d_inode->i_ino;
54001 + dev_t dev = __get_dev(dentry);
54002 +
54003 + FOR_EACH_ROLE_START(role)
54004 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
54005 +
54006 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
54007 + if ((subj->inode == ino) && (subj->device == dev)) {
54008 + subj->inode = ino;
54009 + subj->device = dev;
54010 + }
54011 + FOR_EACH_NESTED_SUBJECT_END(subj)
54012 + FOR_EACH_SUBJECT_START(role, subj, x)
54013 + update_acl_obj_label(matchn->inode, matchn->device,
54014 + ino, dev, subj);
54015 + FOR_EACH_SUBJECT_END(subj,x)
54016 + FOR_EACH_ROLE_END(role)
54017 +
54018 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
54019 +
54020 + return;
54021 +}
54022 +
54023 +void
54024 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
54025 +{
54026 + struct name_entry *matchn;
54027 +
54028 + if (unlikely(!(gr_status & GR_READY)))
54029 + return;
54030 +
54031 + preempt_disable();
54032 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
54033 +
54034 + if (unlikely((unsigned long)matchn)) {
54035 + write_lock(&gr_inode_lock);
54036 + do_handle_create(matchn, dentry, mnt);
54037 + write_unlock(&gr_inode_lock);
54038 + }
54039 + preempt_enable();
54040 +
54041 + return;
54042 +}
54043 +
54044 +void
54045 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
54046 + struct dentry *old_dentry,
54047 + struct dentry *new_dentry,
54048 + struct vfsmount *mnt, const __u8 replace)
54049 +{
54050 + struct name_entry *matchn;
54051 + struct inodev_entry *inodev;
54052 + ino_t old_ino = old_dentry->d_inode->i_ino;
54053 + dev_t old_dev = __get_dev(old_dentry);
54054 +
54055 + /* vfs_rename swaps the name and parent link for old_dentry and
54056 + new_dentry
54057 + at this point, old_dentry has the new name, parent link, and inode
54058 + for the renamed file
54059 + if a file is being replaced by a rename, new_dentry has the inode
54060 + and name for the replaced file
54061 + */
54062 +
54063 + if (unlikely(!(gr_status & GR_READY)))
54064 + return;
54065 +
54066 + preempt_disable();
54067 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
54068 +
54069 + /* we wouldn't have to check d_inode if it weren't for
54070 + NFS silly-renaming
54071 + */
54072 +
54073 + write_lock(&gr_inode_lock);
54074 + if (unlikely(replace && new_dentry->d_inode)) {
54075 + ino_t new_ino = new_dentry->d_inode->i_ino;
54076 + dev_t new_dev = __get_dev(new_dentry);
54077 +
54078 + inodev = lookup_inodev_entry(new_ino, new_dev);
54079 + if (inodev != NULL && (new_dentry->d_inode->i_nlink <= 1))
54080 + do_handle_delete(inodev, new_ino, new_dev);
54081 + }
54082 +
54083 + inodev = lookup_inodev_entry(old_ino, old_dev);
54084 + if (inodev != NULL && (old_dentry->d_inode->i_nlink <= 1))
54085 + do_handle_delete(inodev, old_ino, old_dev);
54086 +
54087 + if (unlikely((unsigned long)matchn))
54088 + do_handle_create(matchn, old_dentry, mnt);
54089 +
54090 + write_unlock(&gr_inode_lock);
54091 + preempt_enable();
54092 +
54093 + return;
54094 +}
54095 +
54096 +static int
54097 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
54098 + unsigned char **sum)
54099 +{
54100 + struct acl_role_label *r;
54101 + struct role_allowed_ip *ipp;
54102 + struct role_transition *trans;
54103 + unsigned int i;
54104 + int found = 0;
54105 + u32 curr_ip = current->signal->curr_ip;
54106 +
54107 + current->signal->saved_ip = curr_ip;
54108 +
54109 + /* check transition table */
54110 +
54111 + for (trans = current->role->transitions; trans; trans = trans->next) {
54112 + if (!strcmp(rolename, trans->rolename)) {
54113 + found = 1;
54114 + break;
54115 + }
54116 + }
54117 +
54118 + if (!found)
54119 + return 0;
54120 +
54121 + /* handle special roles that do not require authentication
54122 + and check ip */
54123 +
54124 + FOR_EACH_ROLE_START(r)
54125 + if (!strcmp(rolename, r->rolename) &&
54126 + (r->roletype & GR_ROLE_SPECIAL)) {
54127 + found = 0;
54128 + if (r->allowed_ips != NULL) {
54129 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
54130 + if ((ntohl(curr_ip) & ipp->netmask) ==
54131 + (ntohl(ipp->addr) & ipp->netmask))
54132 + found = 1;
54133 + }
54134 + } else
54135 + found = 2;
54136 + if (!found)
54137 + return 0;
54138 +
54139 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
54140 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
54141 + *salt = NULL;
54142 + *sum = NULL;
54143 + return 1;
54144 + }
54145 + }
54146 + FOR_EACH_ROLE_END(r)
54147 +
54148 + for (i = 0; i < num_sprole_pws; i++) {
54149 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
54150 + *salt = acl_special_roles[i]->salt;
54151 + *sum = acl_special_roles[i]->sum;
54152 + return 1;
54153 + }
54154 + }
54155 +
54156 + return 0;
54157 +}
54158 +
54159 +static void
54160 +assign_special_role(char *rolename)
54161 +{
54162 + struct acl_object_label *obj;
54163 + struct acl_role_label *r;
54164 + struct acl_role_label *assigned = NULL;
54165 + struct task_struct *tsk;
54166 + struct file *filp;
54167 +
54168 + FOR_EACH_ROLE_START(r)
54169 + if (!strcmp(rolename, r->rolename) &&
54170 + (r->roletype & GR_ROLE_SPECIAL)) {
54171 + assigned = r;
54172 + break;
54173 + }
54174 + FOR_EACH_ROLE_END(r)
54175 +
54176 + if (!assigned)
54177 + return;
54178 +
54179 + read_lock(&tasklist_lock);
54180 + read_lock(&grsec_exec_file_lock);
54181 +
54182 + tsk = current->real_parent;
54183 + if (tsk == NULL)
54184 + goto out_unlock;
54185 +
54186 + filp = tsk->exec_file;
54187 + if (filp == NULL)
54188 + goto out_unlock;
54189 +
54190 + tsk->is_writable = 0;
54191 +
54192 + tsk->acl_sp_role = 1;
54193 + tsk->acl_role_id = ++acl_sp_role_value;
54194 + tsk->role = assigned;
54195 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
54196 +
54197 + /* ignore additional mmap checks for processes that are writable
54198 + by the default ACL */
54199 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54200 + if (unlikely(obj->mode & GR_WRITE))
54201 + tsk->is_writable = 1;
54202 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
54203 + if (unlikely(obj->mode & GR_WRITE))
54204 + tsk->is_writable = 1;
54205 +
54206 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54207 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
54208 +#endif
54209 +
54210 +out_unlock:
54211 + read_unlock(&grsec_exec_file_lock);
54212 + read_unlock(&tasklist_lock);
54213 + return;
54214 +}
54215 +
54216 +int gr_check_secure_terminal(struct task_struct *task)
54217 +{
54218 + struct task_struct *p, *p2, *p3;
54219 + struct files_struct *files;
54220 + struct fdtable *fdt;
54221 + struct file *our_file = NULL, *file;
54222 + int i;
54223 +
54224 + if (task->signal->tty == NULL)
54225 + return 1;
54226 +
54227 + files = get_files_struct(task);
54228 + if (files != NULL) {
54229 + rcu_read_lock();
54230 + fdt = files_fdtable(files);
54231 + for (i=0; i < fdt->max_fds; i++) {
54232 + file = fcheck_files(files, i);
54233 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
54234 + get_file(file);
54235 + our_file = file;
54236 + }
54237 + }
54238 + rcu_read_unlock();
54239 + put_files_struct(files);
54240 + }
54241 +
54242 + if (our_file == NULL)
54243 + return 1;
54244 +
54245 + read_lock(&tasklist_lock);
54246 + do_each_thread(p2, p) {
54247 + files = get_files_struct(p);
54248 + if (files == NULL ||
54249 + (p->signal && p->signal->tty == task->signal->tty)) {
54250 + if (files != NULL)
54251 + put_files_struct(files);
54252 + continue;
54253 + }
54254 + rcu_read_lock();
54255 + fdt = files_fdtable(files);
54256 + for (i=0; i < fdt->max_fds; i++) {
54257 + file = fcheck_files(files, i);
54258 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
54259 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
54260 + p3 = task;
54261 + while (p3->pid > 0) {
54262 + if (p3 == p)
54263 + break;
54264 + p3 = p3->real_parent;
54265 + }
54266 + if (p3 == p)
54267 + break;
54268 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
54269 + gr_handle_alertkill(p);
54270 + rcu_read_unlock();
54271 + put_files_struct(files);
54272 + read_unlock(&tasklist_lock);
54273 + fput(our_file);
54274 + return 0;
54275 + }
54276 + }
54277 + rcu_read_unlock();
54278 + put_files_struct(files);
54279 + } while_each_thread(p2, p);
54280 + read_unlock(&tasklist_lock);
54281 +
54282 + fput(our_file);
54283 + return 1;
54284 +}
54285 +
54286 +ssize_t
54287 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
54288 +{
54289 + struct gr_arg_wrapper uwrap;
54290 + unsigned char *sprole_salt = NULL;
54291 + unsigned char *sprole_sum = NULL;
54292 + int error = sizeof (struct gr_arg_wrapper);
54293 + int error2 = 0;
54294 +
54295 + mutex_lock(&gr_dev_mutex);
54296 +
54297 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
54298 + error = -EPERM;
54299 + goto out;
54300 + }
54301 +
54302 + if (count != sizeof (struct gr_arg_wrapper)) {
54303 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
54304 + error = -EINVAL;
54305 + goto out;
54306 + }
54307 +
54308 +
54309 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
54310 + gr_auth_expires = 0;
54311 + gr_auth_attempts = 0;
54312 + }
54313 +
54314 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
54315 + error = -EFAULT;
54316 + goto out;
54317 + }
54318 +
54319 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
54320 + error = -EINVAL;
54321 + goto out;
54322 + }
54323 +
54324 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
54325 + error = -EFAULT;
54326 + goto out;
54327 + }
54328 +
54329 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54330 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54331 + time_after(gr_auth_expires, get_seconds())) {
54332 + error = -EBUSY;
54333 + goto out;
54334 + }
54335 +
54336 + /* if non-root trying to do anything other than use a special role,
54337 + do not attempt authentication, do not count towards authentication
54338 + locking
54339 + */
54340 +
54341 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
54342 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54343 + current_uid()) {
54344 + error = -EPERM;
54345 + goto out;
54346 + }
54347 +
54348 + /* ensure pw and special role name are null terminated */
54349 +
54350 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
54351 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
54352 +
54353 + /* Okay.
54354 + * We have our enough of the argument structure..(we have yet
54355 + * to copy_from_user the tables themselves) . Copy the tables
54356 + * only if we need them, i.e. for loading operations. */
54357 +
54358 + switch (gr_usermode->mode) {
54359 + case GR_STATUS:
54360 + if (gr_status & GR_READY) {
54361 + error = 1;
54362 + if (!gr_check_secure_terminal(current))
54363 + error = 3;
54364 + } else
54365 + error = 2;
54366 + goto out;
54367 + case GR_SHUTDOWN:
54368 + if ((gr_status & GR_READY)
54369 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54370 + pax_open_kernel();
54371 + gr_status &= ~GR_READY;
54372 + pax_close_kernel();
54373 +
54374 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
54375 + free_variables();
54376 + memset(gr_usermode, 0, sizeof (struct gr_arg));
54377 + memset(gr_system_salt, 0, GR_SALT_LEN);
54378 + memset(gr_system_sum, 0, GR_SHA_LEN);
54379 + } else if (gr_status & GR_READY) {
54380 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
54381 + error = -EPERM;
54382 + } else {
54383 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
54384 + error = -EAGAIN;
54385 + }
54386 + break;
54387 + case GR_ENABLE:
54388 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
54389 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
54390 + else {
54391 + if (gr_status & GR_READY)
54392 + error = -EAGAIN;
54393 + else
54394 + error = error2;
54395 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
54396 + }
54397 + break;
54398 + case GR_RELOAD:
54399 + if (!(gr_status & GR_READY)) {
54400 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
54401 + error = -EAGAIN;
54402 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54403 + preempt_disable();
54404 +
54405 + pax_open_kernel();
54406 + gr_status &= ~GR_READY;
54407 + pax_close_kernel();
54408 +
54409 + free_variables();
54410 + if (!(error2 = gracl_init(gr_usermode))) {
54411 + preempt_enable();
54412 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
54413 + } else {
54414 + preempt_enable();
54415 + error = error2;
54416 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54417 + }
54418 + } else {
54419 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54420 + error = -EPERM;
54421 + }
54422 + break;
54423 + case GR_SEGVMOD:
54424 + if (unlikely(!(gr_status & GR_READY))) {
54425 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
54426 + error = -EAGAIN;
54427 + break;
54428 + }
54429 +
54430 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54431 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
54432 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
54433 + struct acl_subject_label *segvacl;
54434 + segvacl =
54435 + lookup_acl_subj_label(gr_usermode->segv_inode,
54436 + gr_usermode->segv_device,
54437 + current->role);
54438 + if (segvacl) {
54439 + segvacl->crashes = 0;
54440 + segvacl->expires = 0;
54441 + }
54442 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
54443 + gr_remove_uid(gr_usermode->segv_uid);
54444 + }
54445 + } else {
54446 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
54447 + error = -EPERM;
54448 + }
54449 + break;
54450 + case GR_SPROLE:
54451 + case GR_SPROLEPAM:
54452 + if (unlikely(!(gr_status & GR_READY))) {
54453 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
54454 + error = -EAGAIN;
54455 + break;
54456 + }
54457 +
54458 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
54459 + current->role->expires = 0;
54460 + current->role->auth_attempts = 0;
54461 + }
54462 +
54463 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54464 + time_after(current->role->expires, get_seconds())) {
54465 + error = -EBUSY;
54466 + goto out;
54467 + }
54468 +
54469 + if (lookup_special_role_auth
54470 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
54471 + && ((!sprole_salt && !sprole_sum)
54472 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
54473 + char *p = "";
54474 + assign_special_role(gr_usermode->sp_role);
54475 + read_lock(&tasklist_lock);
54476 + if (current->real_parent)
54477 + p = current->real_parent->role->rolename;
54478 + read_unlock(&tasklist_lock);
54479 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
54480 + p, acl_sp_role_value);
54481 + } else {
54482 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
54483 + error = -EPERM;
54484 + if(!(current->role->auth_attempts++))
54485 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54486 +
54487 + goto out;
54488 + }
54489 + break;
54490 + case GR_UNSPROLE:
54491 + if (unlikely(!(gr_status & GR_READY))) {
54492 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
54493 + error = -EAGAIN;
54494 + break;
54495 + }
54496 +
54497 + if (current->role->roletype & GR_ROLE_SPECIAL) {
54498 + char *p = "";
54499 + int i = 0;
54500 +
54501 + read_lock(&tasklist_lock);
54502 + if (current->real_parent) {
54503 + p = current->real_parent->role->rolename;
54504 + i = current->real_parent->acl_role_id;
54505 + }
54506 + read_unlock(&tasklist_lock);
54507 +
54508 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
54509 + gr_set_acls(1);
54510 + } else {
54511 + error = -EPERM;
54512 + goto out;
54513 + }
54514 + break;
54515 + default:
54516 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
54517 + error = -EINVAL;
54518 + break;
54519 + }
54520 +
54521 + if (error != -EPERM)
54522 + goto out;
54523 +
54524 + if(!(gr_auth_attempts++))
54525 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54526 +
54527 + out:
54528 + mutex_unlock(&gr_dev_mutex);
54529 + return error;
54530 +}
54531 +
54532 +/* must be called with
54533 + rcu_read_lock();
54534 + read_lock(&tasklist_lock);
54535 + read_lock(&grsec_exec_file_lock);
54536 +*/
54537 +int gr_apply_subject_to_task(struct task_struct *task)
54538 +{
54539 + struct acl_object_label *obj;
54540 + char *tmpname;
54541 + struct acl_subject_label *tmpsubj;
54542 + struct file *filp;
54543 + struct name_entry *nmatch;
54544 +
54545 + filp = task->exec_file;
54546 + if (filp == NULL)
54547 + return 0;
54548 +
54549 + /* the following is to apply the correct subject
54550 + on binaries running when the RBAC system
54551 + is enabled, when the binaries have been
54552 + replaced or deleted since their execution
54553 + -----
54554 + when the RBAC system starts, the inode/dev
54555 + from exec_file will be one the RBAC system
54556 + is unaware of. It only knows the inode/dev
54557 + of the present file on disk, or the absence
54558 + of it.
54559 + */
54560 + preempt_disable();
54561 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
54562 +
54563 + nmatch = lookup_name_entry(tmpname);
54564 + preempt_enable();
54565 + tmpsubj = NULL;
54566 + if (nmatch) {
54567 + if (nmatch->deleted)
54568 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
54569 + else
54570 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
54571 + if (tmpsubj != NULL)
54572 + task->acl = tmpsubj;
54573 + }
54574 + if (tmpsubj == NULL)
54575 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
54576 + task->role);
54577 + if (task->acl) {
54578 + struct acl_subject_label *curr;
54579 + curr = task->acl;
54580 +
54581 + task->is_writable = 0;
54582 + /* ignore additional mmap checks for processes that are writable
54583 + by the default ACL */
54584 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54585 + if (unlikely(obj->mode & GR_WRITE))
54586 + task->is_writable = 1;
54587 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54588 + if (unlikely(obj->mode & GR_WRITE))
54589 + task->is_writable = 1;
54590 +
54591 + gr_set_proc_res(task);
54592 +
54593 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54594 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54595 +#endif
54596 + } else {
54597 + return 1;
54598 + }
54599 +
54600 + return 0;
54601 +}
54602 +
54603 +int
54604 +gr_set_acls(const int type)
54605 +{
54606 + struct task_struct *task, *task2;
54607 + struct acl_role_label *role = current->role;
54608 + __u16 acl_role_id = current->acl_role_id;
54609 + const struct cred *cred;
54610 + int ret;
54611 +
54612 + rcu_read_lock();
54613 + read_lock(&tasklist_lock);
54614 + read_lock(&grsec_exec_file_lock);
54615 + do_each_thread(task2, task) {
54616 + /* check to see if we're called from the exit handler,
54617 + if so, only replace ACLs that have inherited the admin
54618 + ACL */
54619 +
54620 + if (type && (task->role != role ||
54621 + task->acl_role_id != acl_role_id))
54622 + continue;
54623 +
54624 + task->acl_role_id = 0;
54625 + task->acl_sp_role = 0;
54626 +
54627 + if (task->exec_file) {
54628 + cred = __task_cred(task);
54629 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
54630 + ret = gr_apply_subject_to_task(task);
54631 + if (ret) {
54632 + read_unlock(&grsec_exec_file_lock);
54633 + read_unlock(&tasklist_lock);
54634 + rcu_read_unlock();
54635 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
54636 + return ret;
54637 + }
54638 + } else {
54639 + // it's a kernel process
54640 + task->role = kernel_role;
54641 + task->acl = kernel_role->root_label;
54642 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
54643 + task->acl->mode &= ~GR_PROCFIND;
54644 +#endif
54645 + }
54646 + } while_each_thread(task2, task);
54647 + read_unlock(&grsec_exec_file_lock);
54648 + read_unlock(&tasklist_lock);
54649 + rcu_read_unlock();
54650 +
54651 + return 0;
54652 +}
54653 +
54654 +void
54655 +gr_learn_resource(const struct task_struct *task,
54656 + const int res, const unsigned long wanted, const int gt)
54657 +{
54658 + struct acl_subject_label *acl;
54659 + const struct cred *cred;
54660 +
54661 + if (unlikely((gr_status & GR_READY) &&
54662 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
54663 + goto skip_reslog;
54664 +
54665 +#ifdef CONFIG_GRKERNSEC_RESLOG
54666 + gr_log_resource(task, res, wanted, gt);
54667 +#endif
54668 + skip_reslog:
54669 +
54670 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
54671 + return;
54672 +
54673 + acl = task->acl;
54674 +
54675 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
54676 + !(acl->resmask & (1 << (unsigned short) res))))
54677 + return;
54678 +
54679 + if (wanted >= acl->res[res].rlim_cur) {
54680 + unsigned long res_add;
54681 +
54682 + res_add = wanted;
54683 + switch (res) {
54684 + case RLIMIT_CPU:
54685 + res_add += GR_RLIM_CPU_BUMP;
54686 + break;
54687 + case RLIMIT_FSIZE:
54688 + res_add += GR_RLIM_FSIZE_BUMP;
54689 + break;
54690 + case RLIMIT_DATA:
54691 + res_add += GR_RLIM_DATA_BUMP;
54692 + break;
54693 + case RLIMIT_STACK:
54694 + res_add += GR_RLIM_STACK_BUMP;
54695 + break;
54696 + case RLIMIT_CORE:
54697 + res_add += GR_RLIM_CORE_BUMP;
54698 + break;
54699 + case RLIMIT_RSS:
54700 + res_add += GR_RLIM_RSS_BUMP;
54701 + break;
54702 + case RLIMIT_NPROC:
54703 + res_add += GR_RLIM_NPROC_BUMP;
54704 + break;
54705 + case RLIMIT_NOFILE:
54706 + res_add += GR_RLIM_NOFILE_BUMP;
54707 + break;
54708 + case RLIMIT_MEMLOCK:
54709 + res_add += GR_RLIM_MEMLOCK_BUMP;
54710 + break;
54711 + case RLIMIT_AS:
54712 + res_add += GR_RLIM_AS_BUMP;
54713 + break;
54714 + case RLIMIT_LOCKS:
54715 + res_add += GR_RLIM_LOCKS_BUMP;
54716 + break;
54717 + case RLIMIT_SIGPENDING:
54718 + res_add += GR_RLIM_SIGPENDING_BUMP;
54719 + break;
54720 + case RLIMIT_MSGQUEUE:
54721 + res_add += GR_RLIM_MSGQUEUE_BUMP;
54722 + break;
54723 + case RLIMIT_NICE:
54724 + res_add += GR_RLIM_NICE_BUMP;
54725 + break;
54726 + case RLIMIT_RTPRIO:
54727 + res_add += GR_RLIM_RTPRIO_BUMP;
54728 + break;
54729 + case RLIMIT_RTTIME:
54730 + res_add += GR_RLIM_RTTIME_BUMP;
54731 + break;
54732 + }
54733 +
54734 + acl->res[res].rlim_cur = res_add;
54735 +
54736 + if (wanted > acl->res[res].rlim_max)
54737 + acl->res[res].rlim_max = res_add;
54738 +
54739 + /* only log the subject filename, since resource logging is supported for
54740 + single-subject learning only */
54741 + rcu_read_lock();
54742 + cred = __task_cred(task);
54743 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
54744 + task->role->roletype, cred->uid, cred->gid, acl->filename,
54745 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
54746 + "", (unsigned long) res, &task->signal->saved_ip);
54747 + rcu_read_unlock();
54748 + }
54749 +
54750 + return;
54751 +}
54752 +
54753 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
54754 +void
54755 +pax_set_initial_flags(struct linux_binprm *bprm)
54756 +{
54757 + struct task_struct *task = current;
54758 + struct acl_subject_label *proc;
54759 + unsigned long flags;
54760 +
54761 + if (unlikely(!(gr_status & GR_READY)))
54762 + return;
54763 +
54764 + flags = pax_get_flags(task);
54765 +
54766 + proc = task->acl;
54767 +
54768 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
54769 + flags &= ~MF_PAX_PAGEEXEC;
54770 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
54771 + flags &= ~MF_PAX_SEGMEXEC;
54772 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
54773 + flags &= ~MF_PAX_RANDMMAP;
54774 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
54775 + flags &= ~MF_PAX_EMUTRAMP;
54776 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
54777 + flags &= ~MF_PAX_MPROTECT;
54778 +
54779 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
54780 + flags |= MF_PAX_PAGEEXEC;
54781 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
54782 + flags |= MF_PAX_SEGMEXEC;
54783 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
54784 + flags |= MF_PAX_RANDMMAP;
54785 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
54786 + flags |= MF_PAX_EMUTRAMP;
54787 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
54788 + flags |= MF_PAX_MPROTECT;
54789 +
54790 + pax_set_flags(task, flags);
54791 +
54792 + return;
54793 +}
54794 +#endif
54795 +
54796 +#ifdef CONFIG_SYSCTL
54797 +/* Eric Biederman likes breaking userland ABI and every inode-based security
54798 + system to save 35kb of memory */
54799 +
54800 +/* we modify the passed in filename, but adjust it back before returning */
54801 +static struct acl_object_label *gr_lookup_by_name(char *name, unsigned int len)
54802 +{
54803 + struct name_entry *nmatch;
54804 + char *p, *lastp = NULL;
54805 + struct acl_object_label *obj = NULL, *tmp;
54806 + struct acl_subject_label *tmpsubj;
54807 + char c = '\0';
54808 +
54809 + read_lock(&gr_inode_lock);
54810 +
54811 + p = name + len - 1;
54812 + do {
54813 + nmatch = lookup_name_entry(name);
54814 + if (lastp != NULL)
54815 + *lastp = c;
54816 +
54817 + if (nmatch == NULL)
54818 + goto next_component;
54819 + tmpsubj = current->acl;
54820 + do {
54821 + obj = lookup_acl_obj_label(nmatch->inode, nmatch->device, tmpsubj);
54822 + if (obj != NULL) {
54823 + tmp = obj->globbed;
54824 + while (tmp) {
54825 + if (!glob_match(tmp->filename, name)) {
54826 + obj = tmp;
54827 + goto found_obj;
54828 + }
54829 + tmp = tmp->next;
54830 + }
54831 + goto found_obj;
54832 + }
54833 + } while ((tmpsubj = tmpsubj->parent_subject));
54834 +next_component:
54835 + /* end case */
54836 + if (p == name)
54837 + break;
54838 +
54839 + while (*p != '/')
54840 + p--;
54841 + if (p == name)
54842 + lastp = p + 1;
54843 + else {
54844 + lastp = p;
54845 + p--;
54846 + }
54847 + c = *lastp;
54848 + *lastp = '\0';
54849 + } while (1);
54850 +found_obj:
54851 + read_unlock(&gr_inode_lock);
54852 + /* obj returned will always be non-null */
54853 + return obj;
54854 +}
54855 +
54856 +/* returns 0 when allowing, non-zero on error
54857 + op of 0 is used for readdir, so we don't log the names of hidden files
54858 +*/
54859 +__u32
54860 +gr_handle_sysctl(const struct ctl_table *table, const int op)
54861 +{
54862 + struct ctl_table *tmp;
54863 + const char *proc_sys = "/proc/sys";
54864 + char *path;
54865 + struct acl_object_label *obj;
54866 + unsigned short len = 0, pos = 0, depth = 0, i;
54867 + __u32 err = 0;
54868 + __u32 mode = 0;
54869 +
54870 + if (unlikely(!(gr_status & GR_READY)))
54871 + return 0;
54872 +
54873 + /* for now, ignore operations on non-sysctl entries if it's not a
54874 + readdir*/
54875 + if (table->child != NULL && op != 0)
54876 + return 0;
54877 +
54878 + mode |= GR_FIND;
54879 + /* it's only a read if it's an entry, read on dirs is for readdir */
54880 + if (op & MAY_READ)
54881 + mode |= GR_READ;
54882 + if (op & MAY_WRITE)
54883 + mode |= GR_WRITE;
54884 +
54885 + preempt_disable();
54886 +
54887 + path = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
54888 +
54889 + /* it's only a read/write if it's an actual entry, not a dir
54890 + (which are opened for readdir)
54891 + */
54892 +
54893 + /* convert the requested sysctl entry into a pathname */
54894 +
54895 + for (tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
54896 + len += strlen(tmp->procname);
54897 + len++;
54898 + depth++;
54899 + }
54900 +
54901 + if ((len + depth + strlen(proc_sys) + 1) > PAGE_SIZE) {
54902 + /* deny */
54903 + goto out;
54904 + }
54905 +
54906 + memset(path, 0, PAGE_SIZE);
54907 +
54908 + memcpy(path, proc_sys, strlen(proc_sys));
54909 +
54910 + pos += strlen(proc_sys);
54911 +
54912 + for (; depth > 0; depth--) {
54913 + path[pos] = '/';
54914 + pos++;
54915 + for (i = 1, tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
54916 + if (depth == i) {
54917 + memcpy(path + pos, tmp->procname,
54918 + strlen(tmp->procname));
54919 + pos += strlen(tmp->procname);
54920 + }
54921 + i++;
54922 + }
54923 + }
54924 +
54925 + obj = gr_lookup_by_name(path, pos);
54926 + err = obj->mode & (mode | to_gr_audit(mode) | GR_SUPPRESS);
54927 +
54928 + if (unlikely((current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) &&
54929 + ((err & mode) != mode))) {
54930 + __u32 new_mode = mode;
54931 +
54932 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
54933 +
54934 + err = 0;
54935 + gr_log_learn_sysctl(path, new_mode);
54936 + } else if (!(err & GR_FIND) && !(err & GR_SUPPRESS) && op != 0) {
54937 + gr_log_hidden_sysctl(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, path);
54938 + err = -ENOENT;
54939 + } else if (!(err & GR_FIND)) {
54940 + err = -ENOENT;
54941 + } else if (((err & mode) & ~GR_FIND) != (mode & ~GR_FIND) && !(err & GR_SUPPRESS)) {
54942 + gr_log_str4(GR_DONT_AUDIT, GR_SYSCTL_ACL_MSG, "denied",
54943 + path, (mode & GR_READ) ? " reading" : "",
54944 + (mode & GR_WRITE) ? " writing" : "");
54945 + err = -EACCES;
54946 + } else if ((err & mode) != mode) {
54947 + err = -EACCES;
54948 + } else if ((((err & mode) & ~GR_FIND) == (mode & ~GR_FIND)) && (err & GR_AUDITS)) {
54949 + gr_log_str4(GR_DO_AUDIT, GR_SYSCTL_ACL_MSG, "successful",
54950 + path, (mode & GR_READ) ? " reading" : "",
54951 + (mode & GR_WRITE) ? " writing" : "");
54952 + err = 0;
54953 + } else
54954 + err = 0;
54955 +
54956 + out:
54957 + preempt_enable();
54958 +
54959 + return err;
54960 +}
54961 +#endif
54962 +
54963 +int
54964 +gr_handle_proc_ptrace(struct task_struct *task)
54965 +{
54966 + struct file *filp;
54967 + struct task_struct *tmp = task;
54968 + struct task_struct *curtemp = current;
54969 + __u32 retmode;
54970 +
54971 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
54972 + if (unlikely(!(gr_status & GR_READY)))
54973 + return 0;
54974 +#endif
54975 +
54976 + read_lock(&tasklist_lock);
54977 + read_lock(&grsec_exec_file_lock);
54978 + filp = task->exec_file;
54979 +
54980 + while (tmp->pid > 0) {
54981 + if (tmp == curtemp)
54982 + break;
54983 + tmp = tmp->real_parent;
54984 + }
54985 +
54986 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
54987 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
54988 + read_unlock(&grsec_exec_file_lock);
54989 + read_unlock(&tasklist_lock);
54990 + return 1;
54991 + }
54992 +
54993 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
54994 + if (!(gr_status & GR_READY)) {
54995 + read_unlock(&grsec_exec_file_lock);
54996 + read_unlock(&tasklist_lock);
54997 + return 0;
54998 + }
54999 +#endif
55000 +
55001 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
55002 + read_unlock(&grsec_exec_file_lock);
55003 + read_unlock(&tasklist_lock);
55004 +
55005 + if (retmode & GR_NOPTRACE)
55006 + return 1;
55007 +
55008 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
55009 + && (current->acl != task->acl || (current->acl != current->role->root_label
55010 + && current->pid != task->pid)))
55011 + return 1;
55012 +
55013 + return 0;
55014 +}
55015 +
55016 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
55017 +{
55018 + if (unlikely(!(gr_status & GR_READY)))
55019 + return;
55020 +
55021 + if (!(current->role->roletype & GR_ROLE_GOD))
55022 + return;
55023 +
55024 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
55025 + p->role->rolename, gr_task_roletype_to_char(p),
55026 + p->acl->filename);
55027 +}
55028 +
55029 +int
55030 +gr_handle_ptrace(struct task_struct *task, const long request)
55031 +{
55032 + struct task_struct *tmp = task;
55033 + struct task_struct *curtemp = current;
55034 + __u32 retmode;
55035 +
55036 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55037 + if (unlikely(!(gr_status & GR_READY)))
55038 + return 0;
55039 +#endif
55040 +
55041 + read_lock(&tasklist_lock);
55042 + while (tmp->pid > 0) {
55043 + if (tmp == curtemp)
55044 + break;
55045 + tmp = tmp->real_parent;
55046 + }
55047 +
55048 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
55049 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
55050 + read_unlock(&tasklist_lock);
55051 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55052 + return 1;
55053 + }
55054 + read_unlock(&tasklist_lock);
55055 +
55056 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55057 + if (!(gr_status & GR_READY))
55058 + return 0;
55059 +#endif
55060 +
55061 + read_lock(&grsec_exec_file_lock);
55062 + if (unlikely(!task->exec_file)) {
55063 + read_unlock(&grsec_exec_file_lock);
55064 + return 0;
55065 + }
55066 +
55067 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
55068 + read_unlock(&grsec_exec_file_lock);
55069 +
55070 + if (retmode & GR_NOPTRACE) {
55071 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55072 + return 1;
55073 + }
55074 +
55075 + if (retmode & GR_PTRACERD) {
55076 + switch (request) {
55077 + case PTRACE_POKETEXT:
55078 + case PTRACE_POKEDATA:
55079 + case PTRACE_POKEUSR:
55080 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
55081 + case PTRACE_SETREGS:
55082 + case PTRACE_SETFPREGS:
55083 +#endif
55084 +#ifdef CONFIG_X86
55085 + case PTRACE_SETFPXREGS:
55086 +#endif
55087 +#ifdef CONFIG_ALTIVEC
55088 + case PTRACE_SETVRREGS:
55089 +#endif
55090 + return 1;
55091 + default:
55092 + return 0;
55093 + }
55094 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
55095 + !(current->role->roletype & GR_ROLE_GOD) &&
55096 + (current->acl != task->acl)) {
55097 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55098 + return 1;
55099 + }
55100 +
55101 + return 0;
55102 +}
55103 +
55104 +static int is_writable_mmap(const struct file *filp)
55105 +{
55106 + struct task_struct *task = current;
55107 + struct acl_object_label *obj, *obj2;
55108 +
55109 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
55110 + !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))) {
55111 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55112 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
55113 + task->role->root_label);
55114 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
55115 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
55116 + return 1;
55117 + }
55118 + }
55119 + return 0;
55120 +}
55121 +
55122 +int
55123 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
55124 +{
55125 + __u32 mode;
55126 +
55127 + if (unlikely(!file || !(prot & PROT_EXEC)))
55128 + return 1;
55129 +
55130 + if (is_writable_mmap(file))
55131 + return 0;
55132 +
55133 + mode =
55134 + gr_search_file(file->f_path.dentry,
55135 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55136 + file->f_path.mnt);
55137 +
55138 + if (!gr_tpe_allow(file))
55139 + return 0;
55140 +
55141 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55142 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55143 + return 0;
55144 + } else if (unlikely(!(mode & GR_EXEC))) {
55145 + return 0;
55146 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55147 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55148 + return 1;
55149 + }
55150 +
55151 + return 1;
55152 +}
55153 +
55154 +int
55155 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
55156 +{
55157 + __u32 mode;
55158 +
55159 + if (unlikely(!file || !(prot & PROT_EXEC)))
55160 + return 1;
55161 +
55162 + if (is_writable_mmap(file))
55163 + return 0;
55164 +
55165 + mode =
55166 + gr_search_file(file->f_path.dentry,
55167 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55168 + file->f_path.mnt);
55169 +
55170 + if (!gr_tpe_allow(file))
55171 + return 0;
55172 +
55173 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55174 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55175 + return 0;
55176 + } else if (unlikely(!(mode & GR_EXEC))) {
55177 + return 0;
55178 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55179 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55180 + return 1;
55181 + }
55182 +
55183 + return 1;
55184 +}
55185 +
55186 +void
55187 +gr_acl_handle_psacct(struct task_struct *task, const long code)
55188 +{
55189 + unsigned long runtime;
55190 + unsigned long cputime;
55191 + unsigned int wday, cday;
55192 + __u8 whr, chr;
55193 + __u8 wmin, cmin;
55194 + __u8 wsec, csec;
55195 + struct timespec timeval;
55196 +
55197 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
55198 + !(task->acl->mode & GR_PROCACCT)))
55199 + return;
55200 +
55201 + do_posix_clock_monotonic_gettime(&timeval);
55202 + runtime = timeval.tv_sec - task->start_time.tv_sec;
55203 + wday = runtime / (3600 * 24);
55204 + runtime -= wday * (3600 * 24);
55205 + whr = runtime / 3600;
55206 + runtime -= whr * 3600;
55207 + wmin = runtime / 60;
55208 + runtime -= wmin * 60;
55209 + wsec = runtime;
55210 +
55211 + cputime = (task->utime + task->stime) / HZ;
55212 + cday = cputime / (3600 * 24);
55213 + cputime -= cday * (3600 * 24);
55214 + chr = cputime / 3600;
55215 + cputime -= chr * 3600;
55216 + cmin = cputime / 60;
55217 + cputime -= cmin * 60;
55218 + csec = cputime;
55219 +
55220 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
55221 +
55222 + return;
55223 +}
55224 +
55225 +void gr_set_kernel_label(struct task_struct *task)
55226 +{
55227 + if (gr_status & GR_READY) {
55228 + task->role = kernel_role;
55229 + task->acl = kernel_role->root_label;
55230 + }
55231 + return;
55232 +}
55233 +
55234 +#ifdef CONFIG_TASKSTATS
55235 +int gr_is_taskstats_denied(int pid)
55236 +{
55237 + struct task_struct *task;
55238 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55239 + const struct cred *cred;
55240 +#endif
55241 + int ret = 0;
55242 +
55243 + /* restrict taskstats viewing to un-chrooted root users
55244 + who have the 'view' subject flag if the RBAC system is enabled
55245 + */
55246 +
55247 + rcu_read_lock();
55248 + read_lock(&tasklist_lock);
55249 + task = find_task_by_vpid(pid);
55250 + if (task) {
55251 +#ifdef CONFIG_GRKERNSEC_CHROOT
55252 + if (proc_is_chrooted(task))
55253 + ret = -EACCES;
55254 +#endif
55255 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55256 + cred = __task_cred(task);
55257 +#ifdef CONFIG_GRKERNSEC_PROC_USER
55258 + if (cred->uid != 0)
55259 + ret = -EACCES;
55260 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55261 + if (cred->uid != 0 && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
55262 + ret = -EACCES;
55263 +#endif
55264 +#endif
55265 + if (gr_status & GR_READY) {
55266 + if (!(task->acl->mode & GR_VIEW))
55267 + ret = -EACCES;
55268 + }
55269 + } else
55270 + ret = -ENOENT;
55271 +
55272 + read_unlock(&tasklist_lock);
55273 + rcu_read_unlock();
55274 +
55275 + return ret;
55276 +}
55277 +#endif
55278 +
55279 +/* AUXV entries are filled via a descendant of search_binary_handler
55280 + after we've already applied the subject for the target
55281 +*/
55282 +int gr_acl_enable_at_secure(void)
55283 +{
55284 + if (unlikely(!(gr_status & GR_READY)))
55285 + return 0;
55286 +
55287 + if (current->acl->mode & GR_ATSECURE)
55288 + return 1;
55289 +
55290 + return 0;
55291 +}
55292 +
55293 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
55294 +{
55295 + struct task_struct *task = current;
55296 + struct dentry *dentry = file->f_path.dentry;
55297 + struct vfsmount *mnt = file->f_path.mnt;
55298 + struct acl_object_label *obj, *tmp;
55299 + struct acl_subject_label *subj;
55300 + unsigned int bufsize;
55301 + int is_not_root;
55302 + char *path;
55303 + dev_t dev = __get_dev(dentry);
55304 +
55305 + if (unlikely(!(gr_status & GR_READY)))
55306 + return 1;
55307 +
55308 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
55309 + return 1;
55310 +
55311 + /* ignore Eric Biederman */
55312 + if (IS_PRIVATE(dentry->d_inode))
55313 + return 1;
55314 +
55315 + subj = task->acl;
55316 + do {
55317 + obj = lookup_acl_obj_label(ino, dev, subj);
55318 + if (obj != NULL)
55319 + return (obj->mode & GR_FIND) ? 1 : 0;
55320 + } while ((subj = subj->parent_subject));
55321 +
55322 + /* this is purely an optimization since we're looking for an object
55323 + for the directory we're doing a readdir on
55324 + if it's possible for any globbed object to match the entry we're
55325 + filling into the directory, then the object we find here will be
55326 + an anchor point with attached globbed objects
55327 + */
55328 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
55329 + if (obj->globbed == NULL)
55330 + return (obj->mode & GR_FIND) ? 1 : 0;
55331 +
55332 + is_not_root = ((obj->filename[0] == '/') &&
55333 + (obj->filename[1] == '\0')) ? 0 : 1;
55334 + bufsize = PAGE_SIZE - namelen - is_not_root;
55335 +
55336 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
55337 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
55338 + return 1;
55339 +
55340 + preempt_disable();
55341 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
55342 + bufsize);
55343 +
55344 + bufsize = strlen(path);
55345 +
55346 + /* if base is "/", don't append an additional slash */
55347 + if (is_not_root)
55348 + *(path + bufsize) = '/';
55349 + memcpy(path + bufsize + is_not_root, name, namelen);
55350 + *(path + bufsize + namelen + is_not_root) = '\0';
55351 +
55352 + tmp = obj->globbed;
55353 + while (tmp) {
55354 + if (!glob_match(tmp->filename, path)) {
55355 + preempt_enable();
55356 + return (tmp->mode & GR_FIND) ? 1 : 0;
55357 + }
55358 + tmp = tmp->next;
55359 + }
55360 + preempt_enable();
55361 + return (obj->mode & GR_FIND) ? 1 : 0;
55362 +}
55363 +
55364 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
55365 +EXPORT_SYMBOL(gr_acl_is_enabled);
55366 +#endif
55367 +EXPORT_SYMBOL(gr_learn_resource);
55368 +EXPORT_SYMBOL(gr_set_kernel_label);
55369 +#ifdef CONFIG_SECURITY
55370 +EXPORT_SYMBOL(gr_check_user_change);
55371 +EXPORT_SYMBOL(gr_check_group_change);
55372 +#endif
55373 +
55374 diff -urNp linux-2.6.39/grsecurity/gracl_cap.c linux-2.6.39/grsecurity/gracl_cap.c
55375 --- linux-2.6.39/grsecurity/gracl_cap.c 1969-12-31 19:00:00.000000000 -0500
55376 +++ linux-2.6.39/grsecurity/gracl_cap.c 2011-05-22 19:41:42.000000000 -0400
55377 @@ -0,0 +1,139 @@
55378 +#include <linux/kernel.h>
55379 +#include <linux/module.h>
55380 +#include <linux/sched.h>
55381 +#include <linux/gracl.h>
55382 +#include <linux/grsecurity.h>
55383 +#include <linux/grinternal.h>
55384 +
55385 +static const char *captab_log[] = {
55386 + "CAP_CHOWN",
55387 + "CAP_DAC_OVERRIDE",
55388 + "CAP_DAC_READ_SEARCH",
55389 + "CAP_FOWNER",
55390 + "CAP_FSETID",
55391 + "CAP_KILL",
55392 + "CAP_SETGID",
55393 + "CAP_SETUID",
55394 + "CAP_SETPCAP",
55395 + "CAP_LINUX_IMMUTABLE",
55396 + "CAP_NET_BIND_SERVICE",
55397 + "CAP_NET_BROADCAST",
55398 + "CAP_NET_ADMIN",
55399 + "CAP_NET_RAW",
55400 + "CAP_IPC_LOCK",
55401 + "CAP_IPC_OWNER",
55402 + "CAP_SYS_MODULE",
55403 + "CAP_SYS_RAWIO",
55404 + "CAP_SYS_CHROOT",
55405 + "CAP_SYS_PTRACE",
55406 + "CAP_SYS_PACCT",
55407 + "CAP_SYS_ADMIN",
55408 + "CAP_SYS_BOOT",
55409 + "CAP_SYS_NICE",
55410 + "CAP_SYS_RESOURCE",
55411 + "CAP_SYS_TIME",
55412 + "CAP_SYS_TTY_CONFIG",
55413 + "CAP_MKNOD",
55414 + "CAP_LEASE",
55415 + "CAP_AUDIT_WRITE",
55416 + "CAP_AUDIT_CONTROL",
55417 + "CAP_SETFCAP",
55418 + "CAP_MAC_OVERRIDE",
55419 + "CAP_MAC_ADMIN",
55420 + "CAP_SYSLOG"
55421 +};
55422 +
55423 +EXPORT_SYMBOL(gr_is_capable);
55424 +EXPORT_SYMBOL(gr_is_capable_nolog);
55425 +
55426 +int
55427 +gr_is_capable(const int cap)
55428 +{
55429 + struct task_struct *task = current;
55430 + const struct cred *cred = current_cred();
55431 + struct acl_subject_label *curracl;
55432 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55433 + kernel_cap_t cap_audit = __cap_empty_set;
55434 +
55435 + if (!gr_acl_is_enabled())
55436 + return 1;
55437 +
55438 + curracl = task->acl;
55439 +
55440 + cap_drop = curracl->cap_lower;
55441 + cap_mask = curracl->cap_mask;
55442 + cap_audit = curracl->cap_invert_audit;
55443 +
55444 + while ((curracl = curracl->parent_subject)) {
55445 + /* if the cap isn't specified in the current computed mask but is specified in the
55446 + current level subject, and is lowered in the current level subject, then add
55447 + it to the set of dropped capabilities
55448 + otherwise, add the current level subject's mask to the current computed mask
55449 + */
55450 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55451 + cap_raise(cap_mask, cap);
55452 + if (cap_raised(curracl->cap_lower, cap))
55453 + cap_raise(cap_drop, cap);
55454 + if (cap_raised(curracl->cap_invert_audit, cap))
55455 + cap_raise(cap_audit, cap);
55456 + }
55457 + }
55458 +
55459 + if (!cap_raised(cap_drop, cap)) {
55460 + if (cap_raised(cap_audit, cap))
55461 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
55462 + return 1;
55463 + }
55464 +
55465 + curracl = task->acl;
55466 +
55467 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
55468 + && cap_raised(cred->cap_effective, cap)) {
55469 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55470 + task->role->roletype, cred->uid,
55471 + cred->gid, task->exec_file ?
55472 + gr_to_filename(task->exec_file->f_path.dentry,
55473 + task->exec_file->f_path.mnt) : curracl->filename,
55474 + curracl->filename, 0UL,
55475 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
55476 + return 1;
55477 + }
55478 +
55479 + if ((cap >= 0) && (cap < (sizeof(captab_log)/sizeof(captab_log[0]))) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
55480 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
55481 + return 0;
55482 +}
55483 +
55484 +int
55485 +gr_is_capable_nolog(const int cap)
55486 +{
55487 + struct acl_subject_label *curracl;
55488 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55489 +
55490 + if (!gr_acl_is_enabled())
55491 + return 1;
55492 +
55493 + curracl = current->acl;
55494 +
55495 + cap_drop = curracl->cap_lower;
55496 + cap_mask = curracl->cap_mask;
55497 +
55498 + while ((curracl = curracl->parent_subject)) {
55499 + /* if the cap isn't specified in the current computed mask but is specified in the
55500 + current level subject, and is lowered in the current level subject, then add
55501 + it to the set of dropped capabilities
55502 + otherwise, add the current level subject's mask to the current computed mask
55503 + */
55504 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55505 + cap_raise(cap_mask, cap);
55506 + if (cap_raised(curracl->cap_lower, cap))
55507 + cap_raise(cap_drop, cap);
55508 + }
55509 + }
55510 +
55511 + if (!cap_raised(cap_drop, cap))
55512 + return 1;
55513 +
55514 + return 0;
55515 +}
55516 +
55517 diff -urNp linux-2.6.39/grsecurity/gracl_fs.c linux-2.6.39/grsecurity/gracl_fs.c
55518 --- linux-2.6.39/grsecurity/gracl_fs.c 1969-12-31 19:00:00.000000000 -0500
55519 +++ linux-2.6.39/grsecurity/gracl_fs.c 2011-05-22 19:41:42.000000000 -0400
55520 @@ -0,0 +1,431 @@
55521 +#include <linux/kernel.h>
55522 +#include <linux/sched.h>
55523 +#include <linux/types.h>
55524 +#include <linux/fs.h>
55525 +#include <linux/file.h>
55526 +#include <linux/stat.h>
55527 +#include <linux/grsecurity.h>
55528 +#include <linux/grinternal.h>
55529 +#include <linux/gracl.h>
55530 +
55531 +__u32
55532 +gr_acl_handle_hidden_file(const struct dentry * dentry,
55533 + const struct vfsmount * mnt)
55534 +{
55535 + __u32 mode;
55536 +
55537 + if (unlikely(!dentry->d_inode))
55538 + return GR_FIND;
55539 +
55540 + mode =
55541 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
55542 +
55543 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
55544 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55545 + return mode;
55546 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
55547 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55548 + return 0;
55549 + } else if (unlikely(!(mode & GR_FIND)))
55550 + return 0;
55551 +
55552 + return GR_FIND;
55553 +}
55554 +
55555 +__u32
55556 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
55557 + const int fmode)
55558 +{
55559 + __u32 reqmode = GR_FIND;
55560 + __u32 mode;
55561 +
55562 + if (unlikely(!dentry->d_inode))
55563 + return reqmode;
55564 +
55565 + if (unlikely(fmode & O_APPEND))
55566 + reqmode |= GR_APPEND;
55567 + else if (unlikely(fmode & FMODE_WRITE))
55568 + reqmode |= GR_WRITE;
55569 + if (likely((fmode & FMODE_READ) && !(fmode & O_DIRECTORY)))
55570 + reqmode |= GR_READ;
55571 + if ((fmode & FMODE_GREXEC) && (fmode & __FMODE_EXEC))
55572 + reqmode &= ~GR_READ;
55573 + mode =
55574 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55575 + mnt);
55576 +
55577 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55578 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55579 + reqmode & GR_READ ? " reading" : "",
55580 + reqmode & GR_WRITE ? " writing" : reqmode &
55581 + GR_APPEND ? " appending" : "");
55582 + return reqmode;
55583 + } else
55584 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55585 + {
55586 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55587 + reqmode & GR_READ ? " reading" : "",
55588 + reqmode & GR_WRITE ? " writing" : reqmode &
55589 + GR_APPEND ? " appending" : "");
55590 + return 0;
55591 + } else if (unlikely((mode & reqmode) != reqmode))
55592 + return 0;
55593 +
55594 + return reqmode;
55595 +}
55596 +
55597 +__u32
55598 +gr_acl_handle_creat(const struct dentry * dentry,
55599 + const struct dentry * p_dentry,
55600 + const struct vfsmount * p_mnt, const int fmode,
55601 + const int imode)
55602 +{
55603 + __u32 reqmode = GR_WRITE | GR_CREATE;
55604 + __u32 mode;
55605 +
55606 + if (unlikely(fmode & O_APPEND))
55607 + reqmode |= GR_APPEND;
55608 + if (unlikely((fmode & FMODE_READ) && !(fmode & O_DIRECTORY)))
55609 + reqmode |= GR_READ;
55610 + if (unlikely((fmode & O_CREAT) && (imode & (S_ISUID | S_ISGID))))
55611 + reqmode |= GR_SETID;
55612 +
55613 + mode =
55614 + gr_check_create(dentry, p_dentry, p_mnt,
55615 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55616 +
55617 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55618 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55619 + reqmode & GR_READ ? " reading" : "",
55620 + reqmode & GR_WRITE ? " writing" : reqmode &
55621 + GR_APPEND ? " appending" : "");
55622 + return reqmode;
55623 + } else
55624 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55625 + {
55626 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55627 + reqmode & GR_READ ? " reading" : "",
55628 + reqmode & GR_WRITE ? " writing" : reqmode &
55629 + GR_APPEND ? " appending" : "");
55630 + return 0;
55631 + } else if (unlikely((mode & reqmode) != reqmode))
55632 + return 0;
55633 +
55634 + return reqmode;
55635 +}
55636 +
55637 +__u32
55638 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
55639 + const int fmode)
55640 +{
55641 + __u32 mode, reqmode = GR_FIND;
55642 +
55643 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
55644 + reqmode |= GR_EXEC;
55645 + if (fmode & S_IWOTH)
55646 + reqmode |= GR_WRITE;
55647 + if (fmode & S_IROTH)
55648 + reqmode |= GR_READ;
55649 +
55650 + mode =
55651 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55652 + mnt);
55653 +
55654 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55655 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55656 + reqmode & GR_READ ? " reading" : "",
55657 + reqmode & GR_WRITE ? " writing" : "",
55658 + reqmode & GR_EXEC ? " executing" : "");
55659 + return reqmode;
55660 + } else
55661 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55662 + {
55663 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55664 + reqmode & GR_READ ? " reading" : "",
55665 + reqmode & GR_WRITE ? " writing" : "",
55666 + reqmode & GR_EXEC ? " executing" : "");
55667 + return 0;
55668 + } else if (unlikely((mode & reqmode) != reqmode))
55669 + return 0;
55670 +
55671 + return reqmode;
55672 +}
55673 +
55674 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
55675 +{
55676 + __u32 mode;
55677 +
55678 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
55679 +
55680 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55681 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
55682 + return mode;
55683 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55684 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
55685 + return 0;
55686 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
55687 + return 0;
55688 +
55689 + return (reqmode);
55690 +}
55691 +
55692 +__u32
55693 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
55694 +{
55695 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
55696 +}
55697 +
55698 +__u32
55699 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
55700 +{
55701 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
55702 +}
55703 +
55704 +__u32
55705 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
55706 +{
55707 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
55708 +}
55709 +
55710 +__u32
55711 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
55712 +{
55713 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
55714 +}
55715 +
55716 +__u32
55717 +gr_acl_handle_fchmod(const struct dentry *dentry, const struct vfsmount *mnt,
55718 + mode_t mode)
55719 +{
55720 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
55721 + return 1;
55722 +
55723 + if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
55724 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
55725 + GR_FCHMOD_ACL_MSG);
55726 + } else {
55727 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_FCHMOD_ACL_MSG);
55728 + }
55729 +}
55730 +
55731 +__u32
55732 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
55733 + mode_t mode)
55734 +{
55735 + if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
55736 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
55737 + GR_CHMOD_ACL_MSG);
55738 + } else {
55739 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
55740 + }
55741 +}
55742 +
55743 +__u32
55744 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
55745 +{
55746 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
55747 +}
55748 +
55749 +__u32
55750 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
55751 +{
55752 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
55753 +}
55754 +
55755 +__u32
55756 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
55757 +{
55758 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
55759 +}
55760 +
55761 +__u32
55762 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
55763 +{
55764 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
55765 + GR_UNIXCONNECT_ACL_MSG);
55766 +}
55767 +
55768 +/* hardlinks require at minimum create permission,
55769 + any additional privilege required is based on the
55770 + privilege of the file being linked to
55771 +*/
55772 +__u32
55773 +gr_acl_handle_link(const struct dentry * new_dentry,
55774 + const struct dentry * parent_dentry,
55775 + const struct vfsmount * parent_mnt,
55776 + const struct dentry * old_dentry,
55777 + const struct vfsmount * old_mnt, const char *to)
55778 +{
55779 + __u32 mode;
55780 + __u32 needmode = GR_CREATE | GR_LINK;
55781 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
55782 +
55783 + mode =
55784 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
55785 + old_mnt);
55786 +
55787 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
55788 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55789 + return mode;
55790 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55791 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55792 + return 0;
55793 + } else if (unlikely((mode & needmode) != needmode))
55794 + return 0;
55795 +
55796 + return 1;
55797 +}
55798 +
55799 +__u32
55800 +gr_acl_handle_symlink(const struct dentry * new_dentry,
55801 + const struct dentry * parent_dentry,
55802 + const struct vfsmount * parent_mnt, const char *from)
55803 +{
55804 + __u32 needmode = GR_WRITE | GR_CREATE;
55805 + __u32 mode;
55806 +
55807 + mode =
55808 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
55809 + GR_CREATE | GR_AUDIT_CREATE |
55810 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
55811 +
55812 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
55813 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55814 + return mode;
55815 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55816 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55817 + return 0;
55818 + } else if (unlikely((mode & needmode) != needmode))
55819 + return 0;
55820 +
55821 + return (GR_WRITE | GR_CREATE);
55822 +}
55823 +
55824 +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)
55825 +{
55826 + __u32 mode;
55827 +
55828 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55829 +
55830 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55831 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
55832 + return mode;
55833 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55834 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
55835 + return 0;
55836 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
55837 + return 0;
55838 +
55839 + return (reqmode);
55840 +}
55841 +
55842 +__u32
55843 +gr_acl_handle_mknod(const struct dentry * new_dentry,
55844 + const struct dentry * parent_dentry,
55845 + const struct vfsmount * parent_mnt,
55846 + const int mode)
55847 +{
55848 + __u32 reqmode = GR_WRITE | GR_CREATE;
55849 + if (unlikely(mode & (S_ISUID | S_ISGID)))
55850 + reqmode |= GR_SETID;
55851 +
55852 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
55853 + reqmode, GR_MKNOD_ACL_MSG);
55854 +}
55855 +
55856 +__u32
55857 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
55858 + const struct dentry *parent_dentry,
55859 + const struct vfsmount *parent_mnt)
55860 +{
55861 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
55862 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
55863 +}
55864 +
55865 +#define RENAME_CHECK_SUCCESS(old, new) \
55866 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
55867 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
55868 +
55869 +int
55870 +gr_acl_handle_rename(struct dentry *new_dentry,
55871 + struct dentry *parent_dentry,
55872 + const struct vfsmount *parent_mnt,
55873 + struct dentry *old_dentry,
55874 + struct inode *old_parent_inode,
55875 + struct vfsmount *old_mnt, const char *newname)
55876 +{
55877 + __u32 comp1, comp2;
55878 + int error = 0;
55879 +
55880 + if (unlikely(!gr_acl_is_enabled()))
55881 + return 0;
55882 +
55883 + if (!new_dentry->d_inode) {
55884 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
55885 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
55886 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
55887 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
55888 + GR_DELETE | GR_AUDIT_DELETE |
55889 + GR_AUDIT_READ | GR_AUDIT_WRITE |
55890 + GR_SUPPRESS, old_mnt);
55891 + } else {
55892 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
55893 + GR_CREATE | GR_DELETE |
55894 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
55895 + GR_AUDIT_READ | GR_AUDIT_WRITE |
55896 + GR_SUPPRESS, parent_mnt);
55897 + comp2 =
55898 + gr_search_file(old_dentry,
55899 + GR_READ | GR_WRITE | GR_AUDIT_READ |
55900 + GR_DELETE | GR_AUDIT_DELETE |
55901 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
55902 + }
55903 +
55904 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
55905 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
55906 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
55907 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
55908 + && !(comp2 & GR_SUPPRESS)) {
55909 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
55910 + error = -EACCES;
55911 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
55912 + error = -EACCES;
55913 +
55914 + return error;
55915 +}
55916 +
55917 +void
55918 +gr_acl_handle_exit(void)
55919 +{
55920 + u16 id;
55921 + char *rolename;
55922 + struct file *exec_file;
55923 +
55924 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
55925 + !(current->role->roletype & GR_ROLE_PERSIST))) {
55926 + id = current->acl_role_id;
55927 + rolename = current->role->rolename;
55928 + gr_set_acls(1);
55929 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
55930 + }
55931 +
55932 + write_lock(&grsec_exec_file_lock);
55933 + exec_file = current->exec_file;
55934 + current->exec_file = NULL;
55935 + write_unlock(&grsec_exec_file_lock);
55936 +
55937 + if (exec_file)
55938 + fput(exec_file);
55939 +}
55940 +
55941 +int
55942 +gr_acl_handle_procpidmem(const struct task_struct *task)
55943 +{
55944 + if (unlikely(!gr_acl_is_enabled()))
55945 + return 0;
55946 +
55947 + if (task != current && task->acl->mode & GR_PROTPROCFD)
55948 + return -EACCES;
55949 +
55950 + return 0;
55951 +}
55952 diff -urNp linux-2.6.39/grsecurity/gracl_ip.c linux-2.6.39/grsecurity/gracl_ip.c
55953 --- linux-2.6.39/grsecurity/gracl_ip.c 1969-12-31 19:00:00.000000000 -0500
55954 +++ linux-2.6.39/grsecurity/gracl_ip.c 2011-05-22 22:47:31.000000000 -0400
55955 @@ -0,0 +1,381 @@
55956 +#include <linux/kernel.h>
55957 +#include <asm/uaccess.h>
55958 +#include <asm/errno.h>
55959 +#include <net/sock.h>
55960 +#include <linux/file.h>
55961 +#include <linux/fs.h>
55962 +#include <linux/net.h>
55963 +#include <linux/in.h>
55964 +#include <linux/skbuff.h>
55965 +#include <linux/ip.h>
55966 +#include <linux/udp.h>
55967 +#include <linux/types.h>
55968 +#include <linux/sched.h>
55969 +#include <linux/netdevice.h>
55970 +#include <linux/inetdevice.h>
55971 +#include <linux/gracl.h>
55972 +#include <linux/grsecurity.h>
55973 +#include <linux/grinternal.h>
55974 +
55975 +#define GR_BIND 0x01
55976 +#define GR_CONNECT 0x02
55977 +#define GR_INVERT 0x04
55978 +#define GR_BINDOVERRIDE 0x08
55979 +#define GR_CONNECTOVERRIDE 0x10
55980 +#define GR_SOCK_FAMILY 0x20
55981 +
55982 +static const char * gr_protocols[IPPROTO_MAX] = {
55983 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
55984 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
55985 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
55986 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
55987 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
55988 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
55989 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
55990 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
55991 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
55992 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
55993 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
55994 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
55995 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
55996 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
55997 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
55998 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
55999 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
56000 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
56001 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
56002 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
56003 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
56004 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
56005 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
56006 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
56007 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
56008 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
56009 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
56010 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
56011 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
56012 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
56013 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
56014 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
56015 + };
56016 +
56017 +static const char * gr_socktypes[SOCK_MAX] = {
56018 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
56019 + "unknown:7", "unknown:8", "unknown:9", "packet"
56020 + };
56021 +
56022 +static const char * gr_sockfamilies[AF_MAX+1] = {
56023 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
56024 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
56025 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
56026 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
56027 + };
56028 +
56029 +const char *
56030 +gr_proto_to_name(unsigned char proto)
56031 +{
56032 + return gr_protocols[proto];
56033 +}
56034 +
56035 +const char *
56036 +gr_socktype_to_name(unsigned char type)
56037 +{
56038 + return gr_socktypes[type];
56039 +}
56040 +
56041 +const char *
56042 +gr_sockfamily_to_name(unsigned char family)
56043 +{
56044 + return gr_sockfamilies[family];
56045 +}
56046 +
56047 +int
56048 +gr_search_socket(const int domain, const int type, const int protocol)
56049 +{
56050 + struct acl_subject_label *curr;
56051 + const struct cred *cred = current_cred();
56052 +
56053 + if (unlikely(!gr_acl_is_enabled()))
56054 + goto exit;
56055 +
56056 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
56057 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
56058 + goto exit; // let the kernel handle it
56059 +
56060 + curr = current->acl;
56061 +
56062 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
56063 + /* the family is allowed, if this is PF_INET allow it only if
56064 + the extra sock type/protocol checks pass */
56065 + if (domain == PF_INET)
56066 + goto inet_check;
56067 + goto exit;
56068 + } else {
56069 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56070 + __u32 fakeip = 0;
56071 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56072 + current->role->roletype, cred->uid,
56073 + cred->gid, current->exec_file ?
56074 + gr_to_filename(current->exec_file->f_path.dentry,
56075 + current->exec_file->f_path.mnt) :
56076 + curr->filename, curr->filename,
56077 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
56078 + &current->signal->saved_ip);
56079 + goto exit;
56080 + }
56081 + goto exit_fail;
56082 + }
56083 +
56084 +inet_check:
56085 + /* the rest of this checking is for IPv4 only */
56086 + if (!curr->ips)
56087 + goto exit;
56088 +
56089 + if ((curr->ip_type & (1 << type)) &&
56090 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
56091 + goto exit;
56092 +
56093 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56094 + /* we don't place acls on raw sockets , and sometimes
56095 + dgram/ip sockets are opened for ioctl and not
56096 + bind/connect, so we'll fake a bind learn log */
56097 + if (type == SOCK_RAW || type == SOCK_PACKET) {
56098 + __u32 fakeip = 0;
56099 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56100 + current->role->roletype, cred->uid,
56101 + cred->gid, current->exec_file ?
56102 + gr_to_filename(current->exec_file->f_path.dentry,
56103 + current->exec_file->f_path.mnt) :
56104 + curr->filename, curr->filename,
56105 + &fakeip, 0, type,
56106 + protocol, GR_CONNECT, &current->signal->saved_ip);
56107 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
56108 + __u32 fakeip = 0;
56109 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56110 + current->role->roletype, cred->uid,
56111 + cred->gid, current->exec_file ?
56112 + gr_to_filename(current->exec_file->f_path.dentry,
56113 + current->exec_file->f_path.mnt) :
56114 + curr->filename, curr->filename,
56115 + &fakeip, 0, type,
56116 + protocol, GR_BIND, &current->signal->saved_ip);
56117 + }
56118 + /* we'll log when they use connect or bind */
56119 + goto exit;
56120 + }
56121 +
56122 +exit_fail:
56123 + if (domain == PF_INET)
56124 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
56125 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
56126 + else
56127 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
56128 + gr_socktype_to_name(type), protocol);
56129 +
56130 + return 0;
56131 +exit:
56132 + return 1;
56133 +}
56134 +
56135 +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)
56136 +{
56137 + if ((ip->mode & mode) &&
56138 + (ip_port >= ip->low) &&
56139 + (ip_port <= ip->high) &&
56140 + ((ntohl(ip_addr) & our_netmask) ==
56141 + (ntohl(our_addr) & our_netmask))
56142 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
56143 + && (ip->type & (1 << type))) {
56144 + if (ip->mode & GR_INVERT)
56145 + return 2; // specifically denied
56146 + else
56147 + return 1; // allowed
56148 + }
56149 +
56150 + return 0; // not specifically allowed, may continue parsing
56151 +}
56152 +
56153 +static int
56154 +gr_search_connectbind(const int full_mode, struct sock *sk,
56155 + struct sockaddr_in *addr, const int type)
56156 +{
56157 + char iface[IFNAMSIZ] = {0};
56158 + struct acl_subject_label *curr;
56159 + struct acl_ip_label *ip;
56160 + struct inet_sock *isk;
56161 + struct net_device *dev;
56162 + struct in_device *idev;
56163 + unsigned long i;
56164 + int ret;
56165 + int mode = full_mode & (GR_BIND | GR_CONNECT);
56166 + __u32 ip_addr = 0;
56167 + __u32 our_addr;
56168 + __u32 our_netmask;
56169 + char *p;
56170 + __u16 ip_port = 0;
56171 + const struct cred *cred = current_cred();
56172 +
56173 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
56174 + return 0;
56175 +
56176 + curr = current->acl;
56177 + isk = inet_sk(sk);
56178 +
56179 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
56180 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
56181 + addr->sin_addr.s_addr = curr->inaddr_any_override;
56182 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
56183 + struct sockaddr_in saddr;
56184 + int err;
56185 +
56186 + saddr.sin_family = AF_INET;
56187 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
56188 + saddr.sin_port = isk->inet_sport;
56189 +
56190 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56191 + if (err)
56192 + return err;
56193 +
56194 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56195 + if (err)
56196 + return err;
56197 + }
56198 +
56199 + if (!curr->ips)
56200 + return 0;
56201 +
56202 + ip_addr = addr->sin_addr.s_addr;
56203 + ip_port = ntohs(addr->sin_port);
56204 +
56205 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56206 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56207 + current->role->roletype, cred->uid,
56208 + cred->gid, current->exec_file ?
56209 + gr_to_filename(current->exec_file->f_path.dentry,
56210 + current->exec_file->f_path.mnt) :
56211 + curr->filename, curr->filename,
56212 + &ip_addr, ip_port, type,
56213 + sk->sk_protocol, mode, &current->signal->saved_ip);
56214 + return 0;
56215 + }
56216 +
56217 + for (i = 0; i < curr->ip_num; i++) {
56218 + ip = *(curr->ips + i);
56219 + if (ip->iface != NULL) {
56220 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
56221 + p = strchr(iface, ':');
56222 + if (p != NULL)
56223 + *p = '\0';
56224 + dev = dev_get_by_name(sock_net(sk), iface);
56225 + if (dev == NULL)
56226 + continue;
56227 + idev = in_dev_get(dev);
56228 + if (idev == NULL) {
56229 + dev_put(dev);
56230 + continue;
56231 + }
56232 + rcu_read_lock();
56233 + for_ifa(idev) {
56234 + if (!strcmp(ip->iface, ifa->ifa_label)) {
56235 + our_addr = ifa->ifa_address;
56236 + our_netmask = 0xffffffff;
56237 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56238 + if (ret == 1) {
56239 + rcu_read_unlock();
56240 + in_dev_put(idev);
56241 + dev_put(dev);
56242 + return 0;
56243 + } else if (ret == 2) {
56244 + rcu_read_unlock();
56245 + in_dev_put(idev);
56246 + dev_put(dev);
56247 + goto denied;
56248 + }
56249 + }
56250 + } endfor_ifa(idev);
56251 + rcu_read_unlock();
56252 + in_dev_put(idev);
56253 + dev_put(dev);
56254 + } else {
56255 + our_addr = ip->addr;
56256 + our_netmask = ip->netmask;
56257 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56258 + if (ret == 1)
56259 + return 0;
56260 + else if (ret == 2)
56261 + goto denied;
56262 + }
56263 + }
56264 +
56265 +denied:
56266 + if (mode == GR_BIND)
56267 + 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));
56268 + else if (mode == GR_CONNECT)
56269 + 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));
56270 +
56271 + return -EACCES;
56272 +}
56273 +
56274 +int
56275 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
56276 +{
56277 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
56278 +}
56279 +
56280 +int
56281 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
56282 +{
56283 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
56284 +}
56285 +
56286 +int gr_search_listen(struct socket *sock)
56287 +{
56288 + struct sock *sk = sock->sk;
56289 + struct sockaddr_in addr;
56290 +
56291 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56292 + addr.sin_port = inet_sk(sk)->inet_sport;
56293 +
56294 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56295 +}
56296 +
56297 +int gr_search_accept(struct socket *sock)
56298 +{
56299 + struct sock *sk = sock->sk;
56300 + struct sockaddr_in addr;
56301 +
56302 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56303 + addr.sin_port = inet_sk(sk)->inet_sport;
56304 +
56305 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56306 +}
56307 +
56308 +int
56309 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
56310 +{
56311 + if (addr)
56312 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
56313 + else {
56314 + struct sockaddr_in sin;
56315 + const struct inet_sock *inet = inet_sk(sk);
56316 +
56317 + sin.sin_addr.s_addr = inet->inet_daddr;
56318 + sin.sin_port = inet->inet_dport;
56319 +
56320 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56321 + }
56322 +}
56323 +
56324 +int
56325 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
56326 +{
56327 + struct sockaddr_in sin;
56328 +
56329 + if (unlikely(skb->len < sizeof (struct udphdr)))
56330 + return 0; // skip this packet
56331 +
56332 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
56333 + sin.sin_port = udp_hdr(skb)->source;
56334 +
56335 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56336 +}
56337 diff -urNp linux-2.6.39/grsecurity/gracl_learn.c linux-2.6.39/grsecurity/gracl_learn.c
56338 --- linux-2.6.39/grsecurity/gracl_learn.c 1969-12-31 19:00:00.000000000 -0500
56339 +++ linux-2.6.39/grsecurity/gracl_learn.c 2011-05-22 22:47:45.000000000 -0400
56340 @@ -0,0 +1,210 @@
56341 +#include <linux/kernel.h>
56342 +#include <linux/mm.h>
56343 +#include <linux/sched.h>
56344 +#include <linux/poll.h>
56345 +#include <linux/string.h>
56346 +#include <linux/file.h>
56347 +#include <linux/types.h>
56348 +#include <linux/vmalloc.h>
56349 +#include <linux/grinternal.h>
56350 +
56351 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
56352 + size_t count, loff_t *ppos);
56353 +extern int gr_acl_is_enabled(void);
56354 +
56355 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
56356 +static int gr_learn_attached;
56357 +
56358 +/* use a 512k buffer */
56359 +#define LEARN_BUFFER_SIZE (512 * 1024)
56360 +
56361 +static DEFINE_SPINLOCK(gr_learn_lock);
56362 +static DEFINE_MUTEX(gr_learn_user_mutex);
56363 +
56364 +/* we need to maintain two buffers, so that the kernel context of grlearn
56365 + uses a semaphore around the userspace copying, and the other kernel contexts
56366 + use a spinlock when copying into the buffer, since they cannot sleep
56367 +*/
56368 +static char *learn_buffer;
56369 +static char *learn_buffer_user;
56370 +static int learn_buffer_len;
56371 +static int learn_buffer_user_len;
56372 +
56373 +static ssize_t
56374 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
56375 +{
56376 + DECLARE_WAITQUEUE(wait, current);
56377 + ssize_t retval = 0;
56378 +
56379 + add_wait_queue(&learn_wait, &wait);
56380 + set_current_state(TASK_INTERRUPTIBLE);
56381 + do {
56382 + mutex_lock(&gr_learn_user_mutex);
56383 + spin_lock(&gr_learn_lock);
56384 + if (learn_buffer_len)
56385 + break;
56386 + spin_unlock(&gr_learn_lock);
56387 + mutex_unlock(&gr_learn_user_mutex);
56388 + if (file->f_flags & O_NONBLOCK) {
56389 + retval = -EAGAIN;
56390 + goto out;
56391 + }
56392 + if (signal_pending(current)) {
56393 + retval = -ERESTARTSYS;
56394 + goto out;
56395 + }
56396 +
56397 + schedule();
56398 + } while (1);
56399 +
56400 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
56401 + learn_buffer_user_len = learn_buffer_len;
56402 + retval = learn_buffer_len;
56403 + learn_buffer_len = 0;
56404 +
56405 + spin_unlock(&gr_learn_lock);
56406 +
56407 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
56408 + retval = -EFAULT;
56409 +
56410 + mutex_unlock(&gr_learn_user_mutex);
56411 +out:
56412 + set_current_state(TASK_RUNNING);
56413 + remove_wait_queue(&learn_wait, &wait);
56414 + return retval;
56415 +}
56416 +
56417 +static unsigned int
56418 +poll_learn(struct file * file, poll_table * wait)
56419 +{
56420 + poll_wait(file, &learn_wait, wait);
56421 +
56422 + if (learn_buffer_len)
56423 + return (POLLIN | POLLRDNORM);
56424 +
56425 + return 0;
56426 +}
56427 +
56428 +void
56429 +gr_clear_learn_entries(void)
56430 +{
56431 + char *tmp;
56432 +
56433 + mutex_lock(&gr_learn_user_mutex);
56434 + if (learn_buffer != NULL) {
56435 + spin_lock(&gr_learn_lock);
56436 + tmp = learn_buffer;
56437 + learn_buffer = NULL;
56438 + spin_unlock(&gr_learn_lock);
56439 + vfree(learn_buffer);
56440 + }
56441 + if (learn_buffer_user != NULL) {
56442 + vfree(learn_buffer_user);
56443 + learn_buffer_user = NULL;
56444 + }
56445 + learn_buffer_len = 0;
56446 + mutex_unlock(&gr_learn_user_mutex);
56447 +
56448 + return;
56449 +}
56450 +
56451 +void
56452 +gr_add_learn_entry(const char *fmt, ...)
56453 +{
56454 + va_list args;
56455 + unsigned int len;
56456 +
56457 + if (!gr_learn_attached)
56458 + return;
56459 +
56460 + spin_lock(&gr_learn_lock);
56461 +
56462 + /* leave a gap at the end so we know when it's "full" but don't have to
56463 + compute the exact length of the string we're trying to append
56464 + */
56465 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
56466 + spin_unlock(&gr_learn_lock);
56467 + wake_up_interruptible(&learn_wait);
56468 + return;
56469 + }
56470 + if (learn_buffer == NULL) {
56471 + spin_unlock(&gr_learn_lock);
56472 + return;
56473 + }
56474 +
56475 + va_start(args, fmt);
56476 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
56477 + va_end(args);
56478 +
56479 + learn_buffer_len += len + 1;
56480 +
56481 + spin_unlock(&gr_learn_lock);
56482 + wake_up_interruptible(&learn_wait);
56483 +
56484 + return;
56485 +}
56486 +
56487 +static int
56488 +open_learn(struct inode *inode, struct file *file)
56489 +{
56490 + if (file->f_mode & FMODE_READ && gr_learn_attached)
56491 + return -EBUSY;
56492 + if (file->f_mode & FMODE_READ) {
56493 + int retval = 0;
56494 + mutex_lock(&gr_learn_user_mutex);
56495 + if (learn_buffer == NULL)
56496 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
56497 + if (learn_buffer_user == NULL)
56498 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
56499 + if (learn_buffer == NULL) {
56500 + retval = -ENOMEM;
56501 + goto out_error;
56502 + }
56503 + if (learn_buffer_user == NULL) {
56504 + retval = -ENOMEM;
56505 + goto out_error;
56506 + }
56507 + learn_buffer_len = 0;
56508 + learn_buffer_user_len = 0;
56509 + gr_learn_attached = 1;
56510 +out_error:
56511 + mutex_unlock(&gr_learn_user_mutex);
56512 + return retval;
56513 + }
56514 + return 0;
56515 +}
56516 +
56517 +static int
56518 +close_learn(struct inode *inode, struct file *file)
56519 +{
56520 + char *tmp;
56521 +
56522 + if (file->f_mode & FMODE_READ) {
56523 + mutex_lock(&gr_learn_user_mutex);
56524 + if (learn_buffer != NULL) {
56525 + spin_lock(&gr_learn_lock);
56526 + tmp = learn_buffer;
56527 + learn_buffer = NULL;
56528 + spin_unlock(&gr_learn_lock);
56529 + vfree(tmp);
56530 + }
56531 + if (learn_buffer_user != NULL) {
56532 + vfree(learn_buffer_user);
56533 + learn_buffer_user = NULL;
56534 + }
56535 + learn_buffer_len = 0;
56536 + learn_buffer_user_len = 0;
56537 + gr_learn_attached = 0;
56538 + mutex_unlock(&gr_learn_user_mutex);
56539 + }
56540 +
56541 + return 0;
56542 +}
56543 +
56544 +const struct file_operations grsec_fops = {
56545 + .read = read_learn,
56546 + .write = write_grsec_handler,
56547 + .open = open_learn,
56548 + .release = close_learn,
56549 + .poll = poll_learn,
56550 +};
56551 diff -urNp linux-2.6.39/grsecurity/gracl_res.c linux-2.6.39/grsecurity/gracl_res.c
56552 --- linux-2.6.39/grsecurity/gracl_res.c 1969-12-31 19:00:00.000000000 -0500
56553 +++ linux-2.6.39/grsecurity/gracl_res.c 2011-05-22 19:41:42.000000000 -0400
56554 @@ -0,0 +1,68 @@
56555 +#include <linux/kernel.h>
56556 +#include <linux/sched.h>
56557 +#include <linux/gracl.h>
56558 +#include <linux/grinternal.h>
56559 +
56560 +static const char *restab_log[] = {
56561 + [RLIMIT_CPU] = "RLIMIT_CPU",
56562 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
56563 + [RLIMIT_DATA] = "RLIMIT_DATA",
56564 + [RLIMIT_STACK] = "RLIMIT_STACK",
56565 + [RLIMIT_CORE] = "RLIMIT_CORE",
56566 + [RLIMIT_RSS] = "RLIMIT_RSS",
56567 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
56568 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
56569 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
56570 + [RLIMIT_AS] = "RLIMIT_AS",
56571 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
56572 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
56573 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
56574 + [RLIMIT_NICE] = "RLIMIT_NICE",
56575 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
56576 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
56577 + [GR_CRASH_RES] = "RLIMIT_CRASH"
56578 +};
56579 +
56580 +void
56581 +gr_log_resource(const struct task_struct *task,
56582 + const int res, const unsigned long wanted, const int gt)
56583 +{
56584 + const struct cred *cred;
56585 + unsigned long rlim;
56586 +
56587 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
56588 + return;
56589 +
56590 + // not yet supported resource
56591 + if (unlikely(!restab_log[res]))
56592 + return;
56593 +
56594 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
56595 + rlim = task_rlimit_max(task, res);
56596 + else
56597 + rlim = task_rlimit(task, res);
56598 +
56599 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
56600 + return;
56601 +
56602 + rcu_read_lock();
56603 + cred = __task_cred(task);
56604 +
56605 + if (res == RLIMIT_NPROC &&
56606 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
56607 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
56608 + goto out_rcu_unlock;
56609 + else if (res == RLIMIT_MEMLOCK &&
56610 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
56611 + goto out_rcu_unlock;
56612 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
56613 + goto out_rcu_unlock;
56614 + rcu_read_unlock();
56615 +
56616 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
56617 +
56618 + return;
56619 +out_rcu_unlock:
56620 + rcu_read_unlock();
56621 + return;
56622 +}
56623 diff -urNp linux-2.6.39/grsecurity/gracl_segv.c linux-2.6.39/grsecurity/gracl_segv.c
56624 --- linux-2.6.39/grsecurity/gracl_segv.c 1969-12-31 19:00:00.000000000 -0500
56625 +++ linux-2.6.39/grsecurity/gracl_segv.c 2011-05-22 22:47:39.000000000 -0400
56626 @@ -0,0 +1,299 @@
56627 +#include <linux/kernel.h>
56628 +#include <linux/mm.h>
56629 +#include <asm/uaccess.h>
56630 +#include <asm/errno.h>
56631 +#include <asm/mman.h>
56632 +#include <net/sock.h>
56633 +#include <linux/file.h>
56634 +#include <linux/fs.h>
56635 +#include <linux/net.h>
56636 +#include <linux/in.h>
56637 +#include <linux/slab.h>
56638 +#include <linux/types.h>
56639 +#include <linux/sched.h>
56640 +#include <linux/timer.h>
56641 +#include <linux/gracl.h>
56642 +#include <linux/grsecurity.h>
56643 +#include <linux/grinternal.h>
56644 +
56645 +static struct crash_uid *uid_set;
56646 +static unsigned short uid_used;
56647 +static DEFINE_SPINLOCK(gr_uid_lock);
56648 +extern rwlock_t gr_inode_lock;
56649 +extern struct acl_subject_label *
56650 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
56651 + struct acl_role_label *role);
56652 +
56653 +#ifdef CONFIG_BTRFS_FS
56654 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
56655 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
56656 +#endif
56657 +
56658 +static inline dev_t __get_dev(const struct dentry *dentry)
56659 +{
56660 +#ifdef CONFIG_BTRFS_FS
56661 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
56662 + return get_btrfs_dev_from_inode(dentry->d_inode);
56663 + else
56664 +#endif
56665 + return dentry->d_inode->i_sb->s_dev;
56666 +}
56667 +
56668 +int
56669 +gr_init_uidset(void)
56670 +{
56671 + uid_set =
56672 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
56673 + uid_used = 0;
56674 +
56675 + return uid_set ? 1 : 0;
56676 +}
56677 +
56678 +void
56679 +gr_free_uidset(void)
56680 +{
56681 + if (uid_set)
56682 + kfree(uid_set);
56683 +
56684 + return;
56685 +}
56686 +
56687 +int
56688 +gr_find_uid(const uid_t uid)
56689 +{
56690 + struct crash_uid *tmp = uid_set;
56691 + uid_t buid;
56692 + int low = 0, high = uid_used - 1, mid;
56693 +
56694 + while (high >= low) {
56695 + mid = (low + high) >> 1;
56696 + buid = tmp[mid].uid;
56697 + if (buid == uid)
56698 + return mid;
56699 + if (buid > uid)
56700 + high = mid - 1;
56701 + if (buid < uid)
56702 + low = mid + 1;
56703 + }
56704 +
56705 + return -1;
56706 +}
56707 +
56708 +static __inline__ void
56709 +gr_insertsort(void)
56710 +{
56711 + unsigned short i, j;
56712 + struct crash_uid index;
56713 +
56714 + for (i = 1; i < uid_used; i++) {
56715 + index = uid_set[i];
56716 + j = i;
56717 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
56718 + uid_set[j] = uid_set[j - 1];
56719 + j--;
56720 + }
56721 + uid_set[j] = index;
56722 + }
56723 +
56724 + return;
56725 +}
56726 +
56727 +static __inline__ void
56728 +gr_insert_uid(const uid_t uid, const unsigned long expires)
56729 +{
56730 + int loc;
56731 +
56732 + if (uid_used == GR_UIDTABLE_MAX)
56733 + return;
56734 +
56735 + loc = gr_find_uid(uid);
56736 +
56737 + if (loc >= 0) {
56738 + uid_set[loc].expires = expires;
56739 + return;
56740 + }
56741 +
56742 + uid_set[uid_used].uid = uid;
56743 + uid_set[uid_used].expires = expires;
56744 + uid_used++;
56745 +
56746 + gr_insertsort();
56747 +
56748 + return;
56749 +}
56750 +
56751 +void
56752 +gr_remove_uid(const unsigned short loc)
56753 +{
56754 + unsigned short i;
56755 +
56756 + for (i = loc + 1; i < uid_used; i++)
56757 + uid_set[i - 1] = uid_set[i];
56758 +
56759 + uid_used--;
56760 +
56761 + return;
56762 +}
56763 +
56764 +int
56765 +gr_check_crash_uid(const uid_t uid)
56766 +{
56767 + int loc;
56768 + int ret = 0;
56769 +
56770 + if (unlikely(!gr_acl_is_enabled()))
56771 + return 0;
56772 +
56773 + spin_lock(&gr_uid_lock);
56774 + loc = gr_find_uid(uid);
56775 +
56776 + if (loc < 0)
56777 + goto out_unlock;
56778 +
56779 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
56780 + gr_remove_uid(loc);
56781 + else
56782 + ret = 1;
56783 +
56784 +out_unlock:
56785 + spin_unlock(&gr_uid_lock);
56786 + return ret;
56787 +}
56788 +
56789 +static __inline__ int
56790 +proc_is_setxid(const struct cred *cred)
56791 +{
56792 + if (cred->uid != cred->euid || cred->uid != cred->suid ||
56793 + cred->uid != cred->fsuid)
56794 + return 1;
56795 + if (cred->gid != cred->egid || cred->gid != cred->sgid ||
56796 + cred->gid != cred->fsgid)
56797 + return 1;
56798 +
56799 + return 0;
56800 +}
56801 +
56802 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
56803 +
56804 +void
56805 +gr_handle_crash(struct task_struct *task, const int sig)
56806 +{
56807 + struct acl_subject_label *curr;
56808 + struct acl_subject_label *curr2;
56809 + struct task_struct *tsk, *tsk2;
56810 + const struct cred *cred;
56811 + const struct cred *cred2;
56812 +
56813 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
56814 + return;
56815 +
56816 + if (unlikely(!gr_acl_is_enabled()))
56817 + return;
56818 +
56819 + curr = task->acl;
56820 +
56821 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
56822 + return;
56823 +
56824 + if (time_before_eq(curr->expires, get_seconds())) {
56825 + curr->expires = 0;
56826 + curr->crashes = 0;
56827 + }
56828 +
56829 + curr->crashes++;
56830 +
56831 + if (!curr->expires)
56832 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
56833 +
56834 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
56835 + time_after(curr->expires, get_seconds())) {
56836 + rcu_read_lock();
56837 + cred = __task_cred(task);
56838 + if (cred->uid && proc_is_setxid(cred)) {
56839 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
56840 + spin_lock(&gr_uid_lock);
56841 + gr_insert_uid(cred->uid, curr->expires);
56842 + spin_unlock(&gr_uid_lock);
56843 + curr->expires = 0;
56844 + curr->crashes = 0;
56845 + read_lock(&tasklist_lock);
56846 + do_each_thread(tsk2, tsk) {
56847 + cred2 = __task_cred(tsk);
56848 + if (tsk != task && cred2->uid == cred->uid)
56849 + gr_fake_force_sig(SIGKILL, tsk);
56850 + } while_each_thread(tsk2, tsk);
56851 + read_unlock(&tasklist_lock);
56852 + } else {
56853 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
56854 + read_lock(&tasklist_lock);
56855 + do_each_thread(tsk2, tsk) {
56856 + if (likely(tsk != task)) {
56857 + curr2 = tsk->acl;
56858 +
56859 + if (curr2->device == curr->device &&
56860 + curr2->inode == curr->inode)
56861 + gr_fake_force_sig(SIGKILL, tsk);
56862 + }
56863 + } while_each_thread(tsk2, tsk);
56864 + read_unlock(&tasklist_lock);
56865 + }
56866 + rcu_read_unlock();
56867 + }
56868 +
56869 + return;
56870 +}
56871 +
56872 +int
56873 +gr_check_crash_exec(const struct file *filp)
56874 +{
56875 + struct acl_subject_label *curr;
56876 +
56877 + if (unlikely(!gr_acl_is_enabled()))
56878 + return 0;
56879 +
56880 + read_lock(&gr_inode_lock);
56881 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
56882 + __get_dev(filp->f_path.dentry),
56883 + current->role);
56884 + read_unlock(&gr_inode_lock);
56885 +
56886 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
56887 + (!curr->crashes && !curr->expires))
56888 + return 0;
56889 +
56890 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
56891 + time_after(curr->expires, get_seconds()))
56892 + return 1;
56893 + else if (time_before_eq(curr->expires, get_seconds())) {
56894 + curr->crashes = 0;
56895 + curr->expires = 0;
56896 + }
56897 +
56898 + return 0;
56899 +}
56900 +
56901 +void
56902 +gr_handle_alertkill(struct task_struct *task)
56903 +{
56904 + struct acl_subject_label *curracl;
56905 + __u32 curr_ip;
56906 + struct task_struct *p, *p2;
56907 +
56908 + if (unlikely(!gr_acl_is_enabled()))
56909 + return;
56910 +
56911 + curracl = task->acl;
56912 + curr_ip = task->signal->curr_ip;
56913 +
56914 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
56915 + read_lock(&tasklist_lock);
56916 + do_each_thread(p2, p) {
56917 + if (p->signal->curr_ip == curr_ip)
56918 + gr_fake_force_sig(SIGKILL, p);
56919 + } while_each_thread(p2, p);
56920 + read_unlock(&tasklist_lock);
56921 + } else if (curracl->mode & GR_KILLPROC)
56922 + gr_fake_force_sig(SIGKILL, task);
56923 +
56924 + return;
56925 +}
56926 diff -urNp linux-2.6.39/grsecurity/gracl_shm.c linux-2.6.39/grsecurity/gracl_shm.c
56927 --- linux-2.6.39/grsecurity/gracl_shm.c 1969-12-31 19:00:00.000000000 -0500
56928 +++ linux-2.6.39/grsecurity/gracl_shm.c 2011-05-22 19:41:42.000000000 -0400
56929 @@ -0,0 +1,40 @@
56930 +#include <linux/kernel.h>
56931 +#include <linux/mm.h>
56932 +#include <linux/sched.h>
56933 +#include <linux/file.h>
56934 +#include <linux/ipc.h>
56935 +#include <linux/gracl.h>
56936 +#include <linux/grsecurity.h>
56937 +#include <linux/grinternal.h>
56938 +
56939 +int
56940 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
56941 + const time_t shm_createtime, const uid_t cuid, const int shmid)
56942 +{
56943 + struct task_struct *task;
56944 +
56945 + if (!gr_acl_is_enabled())
56946 + return 1;
56947 +
56948 + rcu_read_lock();
56949 + read_lock(&tasklist_lock);
56950 +
56951 + task = find_task_by_vpid(shm_cprid);
56952 +
56953 + if (unlikely(!task))
56954 + task = find_task_by_vpid(shm_lapid);
56955 +
56956 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
56957 + (task->pid == shm_lapid)) &&
56958 + (task->acl->mode & GR_PROTSHM) &&
56959 + (task->acl != current->acl))) {
56960 + read_unlock(&tasklist_lock);
56961 + rcu_read_unlock();
56962 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
56963 + return 0;
56964 + }
56965 + read_unlock(&tasklist_lock);
56966 + rcu_read_unlock();
56967 +
56968 + return 1;
56969 +}
56970 diff -urNp linux-2.6.39/grsecurity/grsec_chdir.c linux-2.6.39/grsecurity/grsec_chdir.c
56971 --- linux-2.6.39/grsecurity/grsec_chdir.c 1969-12-31 19:00:00.000000000 -0500
56972 +++ linux-2.6.39/grsecurity/grsec_chdir.c 2011-05-22 19:41:42.000000000 -0400
56973 @@ -0,0 +1,19 @@
56974 +#include <linux/kernel.h>
56975 +#include <linux/sched.h>
56976 +#include <linux/fs.h>
56977 +#include <linux/file.h>
56978 +#include <linux/grsecurity.h>
56979 +#include <linux/grinternal.h>
56980 +
56981 +void
56982 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
56983 +{
56984 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
56985 + if ((grsec_enable_chdir && grsec_enable_group &&
56986 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
56987 + !grsec_enable_group)) {
56988 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
56989 + }
56990 +#endif
56991 + return;
56992 +}
56993 diff -urNp linux-2.6.39/grsecurity/grsec_chroot.c linux-2.6.39/grsecurity/grsec_chroot.c
56994 --- linux-2.6.39/grsecurity/grsec_chroot.c 1969-12-31 19:00:00.000000000 -0500
56995 +++ linux-2.6.39/grsecurity/grsec_chroot.c 2011-05-22 19:41:42.000000000 -0400
56996 @@ -0,0 +1,355 @@
56997 +#include <linux/kernel.h>
56998 +#include <linux/module.h>
56999 +#include <linux/sched.h>
57000 +#include <linux/file.h>
57001 +#include <linux/fs.h>
57002 +#include <linux/mount.h>
57003 +#include <linux/types.h>
57004 +#include <linux/pid_namespace.h>
57005 +#include <linux/grsecurity.h>
57006 +#include <linux/grinternal.h>
57007 +
57008 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
57009 +{
57010 +#ifdef CONFIG_GRKERNSEC
57011 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
57012 + path->dentry != task->nsproxy->mnt_ns->root->mnt_root)
57013 + task->gr_is_chrooted = 1;
57014 + else
57015 + task->gr_is_chrooted = 0;
57016 +
57017 + task->gr_chroot_dentry = path->dentry;
57018 +#endif
57019 + return;
57020 +}
57021 +
57022 +void gr_clear_chroot_entries(struct task_struct *task)
57023 +{
57024 +#ifdef CONFIG_GRKERNSEC
57025 + task->gr_is_chrooted = 0;
57026 + task->gr_chroot_dentry = NULL;
57027 +#endif
57028 + return;
57029 +}
57030 +
57031 +int
57032 +gr_handle_chroot_unix(struct pid *pid)
57033 +{
57034 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57035 + struct task_struct *p;
57036 +
57037 + if (unlikely(!grsec_enable_chroot_unix))
57038 + return 1;
57039 +
57040 + if (likely(!proc_is_chrooted(current)))
57041 + return 1;
57042 +
57043 + rcu_read_lock();
57044 + read_lock(&tasklist_lock);
57045 + p = pid_task(pid, PIDTYPE_PID);
57046 + if (unlikely(p && !have_same_root(current, p))) {
57047 + read_unlock(&tasklist_lock);
57048 + rcu_read_unlock();
57049 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
57050 + return 0;
57051 + }
57052 + read_unlock(&tasklist_lock);
57053 + rcu_read_unlock();
57054 +#endif
57055 + return 1;
57056 +}
57057 +
57058 +int
57059 +gr_handle_chroot_nice(void)
57060 +{
57061 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57062 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
57063 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
57064 + return -EPERM;
57065 + }
57066 +#endif
57067 + return 0;
57068 +}
57069 +
57070 +int
57071 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
57072 +{
57073 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57074 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
57075 + && proc_is_chrooted(current)) {
57076 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
57077 + return -EACCES;
57078 + }
57079 +#endif
57080 + return 0;
57081 +}
57082 +
57083 +int
57084 +gr_handle_chroot_rawio(const struct inode *inode)
57085 +{
57086 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57087 + if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
57088 + inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
57089 + return 1;
57090 +#endif
57091 + return 0;
57092 +}
57093 +
57094 +int
57095 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
57096 +{
57097 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57098 + struct task_struct *p;
57099 + int ret = 0;
57100 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
57101 + return ret;
57102 +
57103 + read_lock(&tasklist_lock);
57104 + do_each_pid_task(pid, type, p) {
57105 + if (!have_same_root(current, p)) {
57106 + ret = 1;
57107 + goto out;
57108 + }
57109 + } while_each_pid_task(pid, type, p);
57110 +out:
57111 + read_unlock(&tasklist_lock);
57112 + return ret;
57113 +#endif
57114 + return 0;
57115 +}
57116 +
57117 +int
57118 +gr_pid_is_chrooted(struct task_struct *p)
57119 +{
57120 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57121 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
57122 + return 0;
57123 +
57124 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
57125 + !have_same_root(current, p)) {
57126 + return 1;
57127 + }
57128 +#endif
57129 + return 0;
57130 +}
57131 +
57132 +EXPORT_SYMBOL(gr_pid_is_chrooted);
57133 +
57134 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
57135 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
57136 +{
57137 + struct path path, currentroot;
57138 + int ret = 0;
57139 +
57140 + path.dentry = (struct dentry *)u_dentry;
57141 + path.mnt = (struct vfsmount *)u_mnt;
57142 + get_fs_root(current->fs, &currentroot);
57143 + if (path_is_under(&path, &currentroot))
57144 + ret = 1;
57145 + path_put(&currentroot);
57146 +
57147 + return ret;
57148 +}
57149 +#endif
57150 +
57151 +int
57152 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
57153 +{
57154 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
57155 + if (!grsec_enable_chroot_fchdir)
57156 + return 1;
57157 +
57158 + if (!proc_is_chrooted(current))
57159 + return 1;
57160 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
57161 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
57162 + return 0;
57163 + }
57164 +#endif
57165 + return 1;
57166 +}
57167 +
57168 +int
57169 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57170 + const time_t shm_createtime)
57171 +{
57172 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
57173 + struct pid *pid = NULL;
57174 + time_t starttime;
57175 +
57176 + if (unlikely(!grsec_enable_chroot_shmat))
57177 + return 1;
57178 +
57179 + if (likely(!proc_is_chrooted(current)))
57180 + return 1;
57181 +
57182 + rcu_read_lock();
57183 + read_lock(&tasklist_lock);
57184 +
57185 + pid = find_vpid(shm_cprid);
57186 + if (pid) {
57187 + struct task_struct *p;
57188 + p = pid_task(pid, PIDTYPE_PID);
57189 + if (p == NULL)
57190 + goto unlock;
57191 + starttime = p->start_time.tv_sec;
57192 + if (unlikely(!have_same_root(current, p) &&
57193 + time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime))) {
57194 + read_unlock(&tasklist_lock);
57195 + rcu_read_unlock();
57196 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57197 + return 0;
57198 + }
57199 + } else {
57200 + pid = find_vpid(shm_lapid);
57201 + if (pid) {
57202 + struct task_struct *p;
57203 + p = pid_task(pid, PIDTYPE_PID);
57204 + if (p == NULL)
57205 + goto unlock;
57206 + if (unlikely(!have_same_root(current, p))) {
57207 + read_unlock(&tasklist_lock);
57208 + rcu_read_unlock();
57209 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57210 + return 0;
57211 + }
57212 + }
57213 + }
57214 +unlock:
57215 + read_unlock(&tasklist_lock);
57216 + rcu_read_unlock();
57217 +#endif
57218 + return 1;
57219 +}
57220 +
57221 +void
57222 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
57223 +{
57224 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
57225 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
57226 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
57227 +#endif
57228 + return;
57229 +}
57230 +
57231 +int
57232 +gr_handle_chroot_mknod(const struct dentry *dentry,
57233 + const struct vfsmount *mnt, const int mode)
57234 +{
57235 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
57236 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
57237 + proc_is_chrooted(current)) {
57238 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
57239 + return -EPERM;
57240 + }
57241 +#endif
57242 + return 0;
57243 +}
57244 +
57245 +int
57246 +gr_handle_chroot_mount(const struct dentry *dentry,
57247 + const struct vfsmount *mnt, const char *dev_name)
57248 +{
57249 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57250 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
57251 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name, dentry, mnt);
57252 + return -EPERM;
57253 + }
57254 +#endif
57255 + return 0;
57256 +}
57257 +
57258 +int
57259 +gr_handle_chroot_pivot(void)
57260 +{
57261 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
57262 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
57263 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
57264 + return -EPERM;
57265 + }
57266 +#endif
57267 + return 0;
57268 +}
57269 +
57270 +int
57271 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
57272 +{
57273 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
57274 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
57275 + !gr_is_outside_chroot(dentry, mnt)) {
57276 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
57277 + return -EPERM;
57278 + }
57279 +#endif
57280 + return 0;
57281 +}
57282 +
57283 +int
57284 +gr_handle_chroot_caps(struct path *path)
57285 +{
57286 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57287 + if (grsec_enable_chroot_caps && current->pid > 1 && current->fs != NULL &&
57288 + (init_task.fs->root.dentry != path->dentry) &&
57289 + (current->nsproxy->mnt_ns->root->mnt_root != path->dentry)) {
57290 +
57291 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57292 + const struct cred *old = current_cred();
57293 + struct cred *new = prepare_creds();
57294 + if (new == NULL)
57295 + return 1;
57296 +
57297 + new->cap_permitted = cap_drop(old->cap_permitted,
57298 + chroot_caps);
57299 + new->cap_inheritable = cap_drop(old->cap_inheritable,
57300 + chroot_caps);
57301 + new->cap_effective = cap_drop(old->cap_effective,
57302 + chroot_caps);
57303 +
57304 + commit_creds(new);
57305 +
57306 + return 0;
57307 + }
57308 +#endif
57309 + return 0;
57310 +}
57311 +
57312 +int
57313 +gr_handle_chroot_sysctl(const int op)
57314 +{
57315 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
57316 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
57317 + proc_is_chrooted(current))
57318 + return -EACCES;
57319 +#endif
57320 + return 0;
57321 +}
57322 +
57323 +void
57324 +gr_handle_chroot_chdir(struct path *path)
57325 +{
57326 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
57327 + if (grsec_enable_chroot_chdir)
57328 + set_fs_pwd(current->fs, path);
57329 +#endif
57330 + return;
57331 +}
57332 +
57333 +int
57334 +gr_handle_chroot_chmod(const struct dentry *dentry,
57335 + const struct vfsmount *mnt, const int mode)
57336 +{
57337 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
57338 + /* allow chmod +s on directories, but not files */
57339 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
57340 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
57341 + proc_is_chrooted(current)) {
57342 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
57343 + return -EPERM;
57344 + }
57345 +#endif
57346 + return 0;
57347 +}
57348 +
57349 +#ifdef CONFIG_SECURITY
57350 +EXPORT_SYMBOL(gr_handle_chroot_caps);
57351 +#endif
57352 diff -urNp linux-2.6.39/grsecurity/grsec_disabled.c linux-2.6.39/grsecurity/grsec_disabled.c
57353 --- linux-2.6.39/grsecurity/grsec_disabled.c 1969-12-31 19:00:00.000000000 -0500
57354 +++ linux-2.6.39/grsecurity/grsec_disabled.c 2011-05-22 19:41:42.000000000 -0400
57355 @@ -0,0 +1,447 @@
57356 +#include <linux/kernel.h>
57357 +#include <linux/module.h>
57358 +#include <linux/sched.h>
57359 +#include <linux/file.h>
57360 +#include <linux/fs.h>
57361 +#include <linux/kdev_t.h>
57362 +#include <linux/net.h>
57363 +#include <linux/in.h>
57364 +#include <linux/ip.h>
57365 +#include <linux/skbuff.h>
57366 +#include <linux/sysctl.h>
57367 +
57368 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
57369 +void
57370 +pax_set_initial_flags(struct linux_binprm *bprm)
57371 +{
57372 + return;
57373 +}
57374 +#endif
57375 +
57376 +#ifdef CONFIG_SYSCTL
57377 +__u32
57378 +gr_handle_sysctl(const struct ctl_table * table, const int op)
57379 +{
57380 + return 0;
57381 +}
57382 +#endif
57383 +
57384 +#ifdef CONFIG_TASKSTATS
57385 +int gr_is_taskstats_denied(int pid)
57386 +{
57387 + return 0;
57388 +}
57389 +#endif
57390 +
57391 +int
57392 +gr_acl_is_enabled(void)
57393 +{
57394 + return 0;
57395 +}
57396 +
57397 +int
57398 +gr_handle_rawio(const struct inode *inode)
57399 +{
57400 + return 0;
57401 +}
57402 +
57403 +void
57404 +gr_acl_handle_psacct(struct task_struct *task, const long code)
57405 +{
57406 + return;
57407 +}
57408 +
57409 +int
57410 +gr_handle_ptrace(struct task_struct *task, const long request)
57411 +{
57412 + return 0;
57413 +}
57414 +
57415 +int
57416 +gr_handle_proc_ptrace(struct task_struct *task)
57417 +{
57418 + return 0;
57419 +}
57420 +
57421 +void
57422 +gr_learn_resource(const struct task_struct *task,
57423 + const int res, const unsigned long wanted, const int gt)
57424 +{
57425 + return;
57426 +}
57427 +
57428 +int
57429 +gr_set_acls(const int type)
57430 +{
57431 + return 0;
57432 +}
57433 +
57434 +int
57435 +gr_check_hidden_task(const struct task_struct *tsk)
57436 +{
57437 + return 0;
57438 +}
57439 +
57440 +int
57441 +gr_check_protected_task(const struct task_struct *task)
57442 +{
57443 + return 0;
57444 +}
57445 +
57446 +int
57447 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
57448 +{
57449 + return 0;
57450 +}
57451 +
57452 +void
57453 +gr_copy_label(struct task_struct *tsk)
57454 +{
57455 + return;
57456 +}
57457 +
57458 +void
57459 +gr_set_pax_flags(struct task_struct *task)
57460 +{
57461 + return;
57462 +}
57463 +
57464 +int
57465 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
57466 + const int unsafe_share)
57467 +{
57468 + return 0;
57469 +}
57470 +
57471 +void
57472 +gr_handle_delete(const ino_t ino, const dev_t dev)
57473 +{
57474 + return;
57475 +}
57476 +
57477 +void
57478 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
57479 +{
57480 + return;
57481 +}
57482 +
57483 +void
57484 +gr_handle_crash(struct task_struct *task, const int sig)
57485 +{
57486 + return;
57487 +}
57488 +
57489 +int
57490 +gr_check_crash_exec(const struct file *filp)
57491 +{
57492 + return 0;
57493 +}
57494 +
57495 +int
57496 +gr_check_crash_uid(const uid_t uid)
57497 +{
57498 + return 0;
57499 +}
57500 +
57501 +void
57502 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
57503 + struct dentry *old_dentry,
57504 + struct dentry *new_dentry,
57505 + struct vfsmount *mnt, const __u8 replace)
57506 +{
57507 + return;
57508 +}
57509 +
57510 +int
57511 +gr_search_socket(const int family, const int type, const int protocol)
57512 +{
57513 + return 1;
57514 +}
57515 +
57516 +int
57517 +gr_search_connectbind(const int mode, const struct socket *sock,
57518 + const struct sockaddr_in *addr)
57519 +{
57520 + return 0;
57521 +}
57522 +
57523 +int
57524 +gr_is_capable(const int cap)
57525 +{
57526 + return 1;
57527 +}
57528 +
57529 +int
57530 +gr_is_capable_nolog(const int cap)
57531 +{
57532 + return 1;
57533 +}
57534 +
57535 +void
57536 +gr_handle_alertkill(struct task_struct *task)
57537 +{
57538 + return;
57539 +}
57540 +
57541 +__u32
57542 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
57543 +{
57544 + return 1;
57545 +}
57546 +
57547 +__u32
57548 +gr_acl_handle_hidden_file(const struct dentry * dentry,
57549 + const struct vfsmount * mnt)
57550 +{
57551 + return 1;
57552 +}
57553 +
57554 +__u32
57555 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
57556 + const int fmode)
57557 +{
57558 + return 1;
57559 +}
57560 +
57561 +__u32
57562 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
57563 +{
57564 + return 1;
57565 +}
57566 +
57567 +__u32
57568 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
57569 +{
57570 + return 1;
57571 +}
57572 +
57573 +int
57574 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
57575 + unsigned int *vm_flags)
57576 +{
57577 + return 1;
57578 +}
57579 +
57580 +__u32
57581 +gr_acl_handle_truncate(const struct dentry * dentry,
57582 + const struct vfsmount * mnt)
57583 +{
57584 + return 1;
57585 +}
57586 +
57587 +__u32
57588 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
57589 +{
57590 + return 1;
57591 +}
57592 +
57593 +__u32
57594 +gr_acl_handle_access(const struct dentry * dentry,
57595 + const struct vfsmount * mnt, const int fmode)
57596 +{
57597 + return 1;
57598 +}
57599 +
57600 +__u32
57601 +gr_acl_handle_fchmod(const struct dentry * dentry, const struct vfsmount * mnt,
57602 + mode_t mode)
57603 +{
57604 + return 1;
57605 +}
57606 +
57607 +__u32
57608 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
57609 + mode_t mode)
57610 +{
57611 + return 1;
57612 +}
57613 +
57614 +__u32
57615 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
57616 +{
57617 + return 1;
57618 +}
57619 +
57620 +__u32
57621 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
57622 +{
57623 + return 1;
57624 +}
57625 +
57626 +void
57627 +grsecurity_init(void)
57628 +{
57629 + return;
57630 +}
57631 +
57632 +__u32
57633 +gr_acl_handle_mknod(const struct dentry * new_dentry,
57634 + const struct dentry * parent_dentry,
57635 + const struct vfsmount * parent_mnt,
57636 + const int mode)
57637 +{
57638 + return 1;
57639 +}
57640 +
57641 +__u32
57642 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
57643 + const struct dentry * parent_dentry,
57644 + const struct vfsmount * parent_mnt)
57645 +{
57646 + return 1;
57647 +}
57648 +
57649 +__u32
57650 +gr_acl_handle_symlink(const struct dentry * new_dentry,
57651 + const struct dentry * parent_dentry,
57652 + const struct vfsmount * parent_mnt, const char *from)
57653 +{
57654 + return 1;
57655 +}
57656 +
57657 +__u32
57658 +gr_acl_handle_link(const struct dentry * new_dentry,
57659 + const struct dentry * parent_dentry,
57660 + const struct vfsmount * parent_mnt,
57661 + const struct dentry * old_dentry,
57662 + const struct vfsmount * old_mnt, const char *to)
57663 +{
57664 + return 1;
57665 +}
57666 +
57667 +int
57668 +gr_acl_handle_rename(const struct dentry *new_dentry,
57669 + const struct dentry *parent_dentry,
57670 + const struct vfsmount *parent_mnt,
57671 + const struct dentry *old_dentry,
57672 + const struct inode *old_parent_inode,
57673 + const struct vfsmount *old_mnt, const char *newname)
57674 +{
57675 + return 0;
57676 +}
57677 +
57678 +int
57679 +gr_acl_handle_filldir(const struct file *file, const char *name,
57680 + const int namelen, const ino_t ino)
57681 +{
57682 + return 1;
57683 +}
57684 +
57685 +int
57686 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57687 + const time_t shm_createtime, const uid_t cuid, const int shmid)
57688 +{
57689 + return 1;
57690 +}
57691 +
57692 +int
57693 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
57694 +{
57695 + return 0;
57696 +}
57697 +
57698 +int
57699 +gr_search_accept(const struct socket *sock)
57700 +{
57701 + return 0;
57702 +}
57703 +
57704 +int
57705 +gr_search_listen(const struct socket *sock)
57706 +{
57707 + return 0;
57708 +}
57709 +
57710 +int
57711 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
57712 +{
57713 + return 0;
57714 +}
57715 +
57716 +__u32
57717 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
57718 +{
57719 + return 1;
57720 +}
57721 +
57722 +__u32
57723 +gr_acl_handle_creat(const struct dentry * dentry,
57724 + const struct dentry * p_dentry,
57725 + const struct vfsmount * p_mnt, const int fmode,
57726 + const int imode)
57727 +{
57728 + return 1;
57729 +}
57730 +
57731 +void
57732 +gr_acl_handle_exit(void)
57733 +{
57734 + return;
57735 +}
57736 +
57737 +int
57738 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
57739 +{
57740 + return 1;
57741 +}
57742 +
57743 +void
57744 +gr_set_role_label(const uid_t uid, const gid_t gid)
57745 +{
57746 + return;
57747 +}
57748 +
57749 +int
57750 +gr_acl_handle_procpidmem(const struct task_struct *task)
57751 +{
57752 + return 0;
57753 +}
57754 +
57755 +int
57756 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
57757 +{
57758 + return 0;
57759 +}
57760 +
57761 +int
57762 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
57763 +{
57764 + return 0;
57765 +}
57766 +
57767 +void
57768 +gr_set_kernel_label(struct task_struct *task)
57769 +{
57770 + return;
57771 +}
57772 +
57773 +int
57774 +gr_check_user_change(int real, int effective, int fs)
57775 +{
57776 + return 0;
57777 +}
57778 +
57779 +int
57780 +gr_check_group_change(int real, int effective, int fs)
57781 +{
57782 + return 0;
57783 +}
57784 +
57785 +int gr_acl_enable_at_secure(void)
57786 +{
57787 + return 0;
57788 +}
57789 +
57790 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
57791 +{
57792 + return dentry->d_inode->i_sb->s_dev;
57793 +}
57794 +
57795 +EXPORT_SYMBOL(gr_is_capable);
57796 +EXPORT_SYMBOL(gr_is_capable_nolog);
57797 +EXPORT_SYMBOL(gr_learn_resource);
57798 +EXPORT_SYMBOL(gr_set_kernel_label);
57799 +#ifdef CONFIG_SECURITY
57800 +EXPORT_SYMBOL(gr_check_user_change);
57801 +EXPORT_SYMBOL(gr_check_group_change);
57802 +#endif
57803 diff -urNp linux-2.6.39/grsecurity/grsec_exec.c linux-2.6.39/grsecurity/grsec_exec.c
57804 --- linux-2.6.39/grsecurity/grsec_exec.c 1969-12-31 19:00:00.000000000 -0500
57805 +++ linux-2.6.39/grsecurity/grsec_exec.c 2011-05-22 22:41:29.000000000 -0400
57806 @@ -0,0 +1,146 @@
57807 +#include <linux/kernel.h>
57808 +#include <linux/sched.h>
57809 +#include <linux/file.h>
57810 +#include <linux/binfmts.h>
57811 +#include <linux/fs.h>
57812 +#include <linux/types.h>
57813 +#include <linux/grdefs.h>
57814 +#include <linux/grinternal.h>
57815 +#include <linux/capability.h>
57816 +#include <linux/compat.h>
57817 +
57818 +#include <asm/uaccess.h>
57819 +
57820 +#ifdef CONFIG_GRKERNSEC_EXECLOG
57821 +static char gr_exec_arg_buf[132];
57822 +static DEFINE_MUTEX(gr_exec_arg_mutex);
57823 +#endif
57824 +
57825 +int
57826 +gr_handle_nproc(void)
57827 +{
57828 +#ifdef CONFIG_GRKERNSEC_EXECVE
57829 + const struct cred *cred = current_cred();
57830 + if (grsec_enable_execve && cred->user &&
57831 + (atomic_read(&cred->user->processes) > rlimit(RLIMIT_NPROC)) &&
57832 + !capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE)) {
57833 + gr_log_noargs(GR_DONT_AUDIT, GR_NPROC_MSG);
57834 + return -EAGAIN;
57835 + }
57836 +#endif
57837 + return 0;
57838 +}
57839 +
57840 +void
57841 +gr_handle_exec_args(struct linux_binprm *bprm, const char __user *const __user *argv)
57842 +{
57843 +#ifdef CONFIG_GRKERNSEC_EXECLOG
57844 + char *grarg = gr_exec_arg_buf;
57845 + unsigned int i, x, execlen = 0;
57846 + char c;
57847 +
57848 + if (!((grsec_enable_execlog && grsec_enable_group &&
57849 + in_group_p(grsec_audit_gid))
57850 + || (grsec_enable_execlog && !grsec_enable_group)))
57851 + return;
57852 +
57853 + mutex_lock(&gr_exec_arg_mutex);
57854 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
57855 +
57856 + if (unlikely(argv == NULL))
57857 + goto log;
57858 +
57859 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
57860 + const char __user *p;
57861 + unsigned int len;
57862 +
57863 + if (copy_from_user(&p, argv + i, sizeof(p)))
57864 + goto log;
57865 + if (!p)
57866 + goto log;
57867 + len = strnlen_user(p, 128 - execlen);
57868 + if (len > 128 - execlen)
57869 + len = 128 - execlen;
57870 + else if (len > 0)
57871 + len--;
57872 + if (copy_from_user(grarg + execlen, p, len))
57873 + goto log;
57874 +
57875 + /* rewrite unprintable characters */
57876 + for (x = 0; x < len; x++) {
57877 + c = *(grarg + execlen + x);
57878 + if (c < 32 || c > 126)
57879 + *(grarg + execlen + x) = ' ';
57880 + }
57881 +
57882 + execlen += len;
57883 + *(grarg + execlen) = ' ';
57884 + *(grarg + execlen + 1) = '\0';
57885 + execlen++;
57886 + }
57887 +
57888 + log:
57889 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
57890 + bprm->file->f_path.mnt, grarg);
57891 + mutex_unlock(&gr_exec_arg_mutex);
57892 +#endif
57893 + return;
57894 +}
57895 +
57896 +#ifdef CONFIG_COMPAT
57897 +void
57898 +gr_handle_exec_args_compat(struct linux_binprm *bprm, compat_uptr_t __user *argv)
57899 +{
57900 +#ifdef CONFIG_GRKERNSEC_EXECLOG
57901 + char *grarg = gr_exec_arg_buf;
57902 + unsigned int i, x, execlen = 0;
57903 + char c;
57904 +
57905 + if (!((grsec_enable_execlog && grsec_enable_group &&
57906 + in_group_p(grsec_audit_gid))
57907 + || (grsec_enable_execlog && !grsec_enable_group)))
57908 + return;
57909 +
57910 + mutex_lock(&gr_exec_arg_mutex);
57911 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
57912 +
57913 + if (unlikely(argv == NULL))
57914 + goto log;
57915 +
57916 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
57917 + compat_uptr_t p;
57918 + unsigned int len;
57919 +
57920 + if (get_user(p, argv + i))
57921 + goto log;
57922 + len = strnlen_user(compat_ptr(p), 128 - execlen);
57923 + if (len > 128 - execlen)
57924 + len = 128 - execlen;
57925 + else if (len > 0)
57926 + len--;
57927 + else
57928 + goto log;
57929 + if (copy_from_user(grarg + execlen, compat_ptr(p), len))
57930 + goto log;
57931 +
57932 + /* rewrite unprintable characters */
57933 + for (x = 0; x < len; x++) {
57934 + c = *(grarg + execlen + x);
57935 + if (c < 32 || c > 126)
57936 + *(grarg + execlen + x) = ' ';
57937 + }
57938 +
57939 + execlen += len;
57940 + *(grarg + execlen) = ' ';
57941 + *(grarg + execlen + 1) = '\0';
57942 + execlen++;
57943 + }
57944 +
57945 + log:
57946 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
57947 + bprm->file->f_path.mnt, grarg);
57948 + mutex_unlock(&gr_exec_arg_mutex);
57949 +#endif
57950 + return;
57951 +}
57952 +#endif
57953 diff -urNp linux-2.6.39/grsecurity/grsec_fifo.c linux-2.6.39/grsecurity/grsec_fifo.c
57954 --- linux-2.6.39/grsecurity/grsec_fifo.c 1969-12-31 19:00:00.000000000 -0500
57955 +++ linux-2.6.39/grsecurity/grsec_fifo.c 2011-05-22 19:41:42.000000000 -0400
57956 @@ -0,0 +1,24 @@
57957 +#include <linux/kernel.h>
57958 +#include <linux/sched.h>
57959 +#include <linux/fs.h>
57960 +#include <linux/file.h>
57961 +#include <linux/grinternal.h>
57962 +
57963 +int
57964 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
57965 + const struct dentry *dir, const int flag, const int acc_mode)
57966 +{
57967 +#ifdef CONFIG_GRKERNSEC_FIFO
57968 + const struct cred *cred = current_cred();
57969 +
57970 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
57971 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
57972 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
57973 + (cred->fsuid != dentry->d_inode->i_uid)) {
57974 + if (!inode_permission(dentry->d_inode, acc_mode))
57975 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
57976 + return -EACCES;
57977 + }
57978 +#endif
57979 + return 0;
57980 +}
57981 diff -urNp linux-2.6.39/grsecurity/grsec_fork.c linux-2.6.39/grsecurity/grsec_fork.c
57982 --- linux-2.6.39/grsecurity/grsec_fork.c 1969-12-31 19:00:00.000000000 -0500
57983 +++ linux-2.6.39/grsecurity/grsec_fork.c 2011-05-22 19:41:42.000000000 -0400
57984 @@ -0,0 +1,23 @@
57985 +#include <linux/kernel.h>
57986 +#include <linux/sched.h>
57987 +#include <linux/grsecurity.h>
57988 +#include <linux/grinternal.h>
57989 +#include <linux/errno.h>
57990 +
57991 +void
57992 +gr_log_forkfail(const int retval)
57993 +{
57994 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
57995 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
57996 + switch (retval) {
57997 + case -EAGAIN:
57998 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
57999 + break;
58000 + case -ENOMEM:
58001 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
58002 + break;
58003 + }
58004 + }
58005 +#endif
58006 + return;
58007 +}
58008 diff -urNp linux-2.6.39/grsecurity/grsec_init.c linux-2.6.39/grsecurity/grsec_init.c
58009 --- linux-2.6.39/grsecurity/grsec_init.c 1969-12-31 19:00:00.000000000 -0500
58010 +++ linux-2.6.39/grsecurity/grsec_init.c 2011-05-22 22:47:15.000000000 -0400
58011 @@ -0,0 +1,269 @@
58012 +#include <linux/kernel.h>
58013 +#include <linux/sched.h>
58014 +#include <linux/mm.h>
58015 +#include <linux/gracl.h>
58016 +#include <linux/slab.h>
58017 +#include <linux/vmalloc.h>
58018 +#include <linux/percpu.h>
58019 +#include <linux/module.h>
58020 +
58021 +int grsec_enable_link;
58022 +int grsec_enable_dmesg;
58023 +int grsec_enable_harden_ptrace;
58024 +int grsec_enable_fifo;
58025 +int grsec_enable_execve;
58026 +int grsec_enable_execlog;
58027 +int grsec_enable_signal;
58028 +int grsec_enable_forkfail;
58029 +int grsec_enable_audit_ptrace;
58030 +int grsec_enable_time;
58031 +int grsec_enable_audit_textrel;
58032 +int grsec_enable_group;
58033 +int grsec_audit_gid;
58034 +int grsec_enable_chdir;
58035 +int grsec_enable_mount;
58036 +int grsec_enable_rofs;
58037 +int grsec_enable_chroot_findtask;
58038 +int grsec_enable_chroot_mount;
58039 +int grsec_enable_chroot_shmat;
58040 +int grsec_enable_chroot_fchdir;
58041 +int grsec_enable_chroot_double;
58042 +int grsec_enable_chroot_pivot;
58043 +int grsec_enable_chroot_chdir;
58044 +int grsec_enable_chroot_chmod;
58045 +int grsec_enable_chroot_mknod;
58046 +int grsec_enable_chroot_nice;
58047 +int grsec_enable_chroot_execlog;
58048 +int grsec_enable_chroot_caps;
58049 +int grsec_enable_chroot_sysctl;
58050 +int grsec_enable_chroot_unix;
58051 +int grsec_enable_tpe;
58052 +int grsec_tpe_gid;
58053 +int grsec_enable_blackhole;
58054 +#ifdef CONFIG_IPV6_MODULE
58055 +EXPORT_SYMBOL(grsec_enable_blackhole);
58056 +#endif
58057 +int grsec_lastack_retries;
58058 +int grsec_enable_tpe_all;
58059 +int grsec_enable_tpe_invert;
58060 +int grsec_enable_socket_all;
58061 +int grsec_socket_all_gid;
58062 +int grsec_enable_socket_client;
58063 +int grsec_socket_client_gid;
58064 +int grsec_enable_socket_server;
58065 +int grsec_socket_server_gid;
58066 +int grsec_resource_logging;
58067 +int grsec_disable_privio;
58068 +int grsec_enable_log_rwxmaps;
58069 +int grsec_lock;
58070 +
58071 +DEFINE_SPINLOCK(grsec_alert_lock);
58072 +unsigned long grsec_alert_wtime = 0;
58073 +unsigned long grsec_alert_fyet = 0;
58074 +
58075 +DEFINE_SPINLOCK(grsec_audit_lock);
58076 +
58077 +DEFINE_RWLOCK(grsec_exec_file_lock);
58078 +
58079 +char *gr_shared_page[4];
58080 +
58081 +char *gr_alert_log_fmt;
58082 +char *gr_audit_log_fmt;
58083 +char *gr_alert_log_buf;
58084 +char *gr_audit_log_buf;
58085 +
58086 +extern struct gr_arg *gr_usermode;
58087 +extern unsigned char *gr_system_salt;
58088 +extern unsigned char *gr_system_sum;
58089 +
58090 +void __init
58091 +grsecurity_init(void)
58092 +{
58093 + int j;
58094 + /* create the per-cpu shared pages */
58095 +
58096 +#ifdef CONFIG_X86
58097 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
58098 +#endif
58099 +
58100 + for (j = 0; j < 4; j++) {
58101 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
58102 + if (gr_shared_page[j] == NULL) {
58103 + panic("Unable to allocate grsecurity shared page");
58104 + return;
58105 + }
58106 + }
58107 +
58108 + /* allocate log buffers */
58109 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
58110 + if (!gr_alert_log_fmt) {
58111 + panic("Unable to allocate grsecurity alert log format buffer");
58112 + return;
58113 + }
58114 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
58115 + if (!gr_audit_log_fmt) {
58116 + panic("Unable to allocate grsecurity audit log format buffer");
58117 + return;
58118 + }
58119 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58120 + if (!gr_alert_log_buf) {
58121 + panic("Unable to allocate grsecurity alert log buffer");
58122 + return;
58123 + }
58124 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58125 + if (!gr_audit_log_buf) {
58126 + panic("Unable to allocate grsecurity audit log buffer");
58127 + return;
58128 + }
58129 +
58130 + /* allocate memory for authentication structure */
58131 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
58132 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
58133 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
58134 +
58135 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
58136 + panic("Unable to allocate grsecurity authentication structure");
58137 + return;
58138 + }
58139 +
58140 +
58141 +#ifdef CONFIG_GRKERNSEC_IO
58142 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
58143 + grsec_disable_privio = 1;
58144 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58145 + grsec_disable_privio = 1;
58146 +#else
58147 + grsec_disable_privio = 0;
58148 +#endif
58149 +#endif
58150 +
58151 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
58152 + /* for backward compatibility, tpe_invert always defaults to on if
58153 + enabled in the kernel
58154 + */
58155 + grsec_enable_tpe_invert = 1;
58156 +#endif
58157 +
58158 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58159 +#ifndef CONFIG_GRKERNSEC_SYSCTL
58160 + grsec_lock = 1;
58161 +#endif
58162 +
58163 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58164 + grsec_enable_audit_textrel = 1;
58165 +#endif
58166 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58167 + grsec_enable_log_rwxmaps = 1;
58168 +#endif
58169 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
58170 + grsec_enable_group = 1;
58171 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
58172 +#endif
58173 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
58174 + grsec_enable_chdir = 1;
58175 +#endif
58176 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
58177 + grsec_enable_harden_ptrace = 1;
58178 +#endif
58179 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58180 + grsec_enable_mount = 1;
58181 +#endif
58182 +#ifdef CONFIG_GRKERNSEC_LINK
58183 + grsec_enable_link = 1;
58184 +#endif
58185 +#ifdef CONFIG_GRKERNSEC_DMESG
58186 + grsec_enable_dmesg = 1;
58187 +#endif
58188 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
58189 + grsec_enable_blackhole = 1;
58190 + grsec_lastack_retries = 4;
58191 +#endif
58192 +#ifdef CONFIG_GRKERNSEC_FIFO
58193 + grsec_enable_fifo = 1;
58194 +#endif
58195 +#ifdef CONFIG_GRKERNSEC_EXECVE
58196 + grsec_enable_execve = 1;
58197 +#endif
58198 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58199 + grsec_enable_execlog = 1;
58200 +#endif
58201 +#ifdef CONFIG_GRKERNSEC_SIGNAL
58202 + grsec_enable_signal = 1;
58203 +#endif
58204 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
58205 + grsec_enable_forkfail = 1;
58206 +#endif
58207 +#ifdef CONFIG_GRKERNSEC_TIME
58208 + grsec_enable_time = 1;
58209 +#endif
58210 +#ifdef CONFIG_GRKERNSEC_RESLOG
58211 + grsec_resource_logging = 1;
58212 +#endif
58213 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
58214 + grsec_enable_chroot_findtask = 1;
58215 +#endif
58216 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
58217 + grsec_enable_chroot_unix = 1;
58218 +#endif
58219 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
58220 + grsec_enable_chroot_mount = 1;
58221 +#endif
58222 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
58223 + grsec_enable_chroot_fchdir = 1;
58224 +#endif
58225 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
58226 + grsec_enable_chroot_shmat = 1;
58227 +#endif
58228 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58229 + grsec_enable_audit_ptrace = 1;
58230 +#endif
58231 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
58232 + grsec_enable_chroot_double = 1;
58233 +#endif
58234 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
58235 + grsec_enable_chroot_pivot = 1;
58236 +#endif
58237 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
58238 + grsec_enable_chroot_chdir = 1;
58239 +#endif
58240 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
58241 + grsec_enable_chroot_chmod = 1;
58242 +#endif
58243 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
58244 + grsec_enable_chroot_mknod = 1;
58245 +#endif
58246 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58247 + grsec_enable_chroot_nice = 1;
58248 +#endif
58249 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
58250 + grsec_enable_chroot_execlog = 1;
58251 +#endif
58252 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58253 + grsec_enable_chroot_caps = 1;
58254 +#endif
58255 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
58256 + grsec_enable_chroot_sysctl = 1;
58257 +#endif
58258 +#ifdef CONFIG_GRKERNSEC_TPE
58259 + grsec_enable_tpe = 1;
58260 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
58261 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
58262 + grsec_enable_tpe_all = 1;
58263 +#endif
58264 +#endif
58265 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58266 + grsec_enable_socket_all = 1;
58267 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
58268 +#endif
58269 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58270 + grsec_enable_socket_client = 1;
58271 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
58272 +#endif
58273 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58274 + grsec_enable_socket_server = 1;
58275 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
58276 +#endif
58277 +#endif
58278 +
58279 + return;
58280 +}
58281 diff -urNp linux-2.6.39/grsecurity/grsec_link.c linux-2.6.39/grsecurity/grsec_link.c
58282 --- linux-2.6.39/grsecurity/grsec_link.c 1969-12-31 19:00:00.000000000 -0500
58283 +++ linux-2.6.39/grsecurity/grsec_link.c 2011-05-22 19:41:42.000000000 -0400
58284 @@ -0,0 +1,43 @@
58285 +#include <linux/kernel.h>
58286 +#include <linux/sched.h>
58287 +#include <linux/fs.h>
58288 +#include <linux/file.h>
58289 +#include <linux/grinternal.h>
58290 +
58291 +int
58292 +gr_handle_follow_link(const struct inode *parent,
58293 + const struct inode *inode,
58294 + const struct dentry *dentry, const struct vfsmount *mnt)
58295 +{
58296 +#ifdef CONFIG_GRKERNSEC_LINK
58297 + const struct cred *cred = current_cred();
58298 +
58299 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
58300 + (parent->i_mode & S_ISVTX) && (parent->i_uid != inode->i_uid) &&
58301 + (parent->i_mode & S_IWOTH) && (cred->fsuid != inode->i_uid)) {
58302 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
58303 + return -EACCES;
58304 + }
58305 +#endif
58306 + return 0;
58307 +}
58308 +
58309 +int
58310 +gr_handle_hardlink(const struct dentry *dentry,
58311 + const struct vfsmount *mnt,
58312 + struct inode *inode, const int mode, const char *to)
58313 +{
58314 +#ifdef CONFIG_GRKERNSEC_LINK
58315 + const struct cred *cred = current_cred();
58316 +
58317 + if (grsec_enable_link && cred->fsuid != inode->i_uid &&
58318 + (!S_ISREG(mode) || (mode & S_ISUID) ||
58319 + ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
58320 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
58321 + !capable(CAP_FOWNER) && cred->uid) {
58322 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
58323 + return -EPERM;
58324 + }
58325 +#endif
58326 + return 0;
58327 +}
58328 diff -urNp linux-2.6.39/grsecurity/grsec_log.c linux-2.6.39/grsecurity/grsec_log.c
58329 --- linux-2.6.39/grsecurity/grsec_log.c 1969-12-31 19:00:00.000000000 -0500
58330 +++ linux-2.6.39/grsecurity/grsec_log.c 2011-05-22 19:41:42.000000000 -0400
58331 @@ -0,0 +1,310 @@
58332 +#include <linux/kernel.h>
58333 +#include <linux/sched.h>
58334 +#include <linux/file.h>
58335 +#include <linux/tty.h>
58336 +#include <linux/fs.h>
58337 +#include <linux/grinternal.h>
58338 +
58339 +#ifdef CONFIG_TREE_PREEMPT_RCU
58340 +#define DISABLE_PREEMPT() preempt_disable()
58341 +#define ENABLE_PREEMPT() preempt_enable()
58342 +#else
58343 +#define DISABLE_PREEMPT()
58344 +#define ENABLE_PREEMPT()
58345 +#endif
58346 +
58347 +#define BEGIN_LOCKS(x) \
58348 + DISABLE_PREEMPT(); \
58349 + rcu_read_lock(); \
58350 + read_lock(&tasklist_lock); \
58351 + read_lock(&grsec_exec_file_lock); \
58352 + if (x != GR_DO_AUDIT) \
58353 + spin_lock(&grsec_alert_lock); \
58354 + else \
58355 + spin_lock(&grsec_audit_lock)
58356 +
58357 +#define END_LOCKS(x) \
58358 + if (x != GR_DO_AUDIT) \
58359 + spin_unlock(&grsec_alert_lock); \
58360 + else \
58361 + spin_unlock(&grsec_audit_lock); \
58362 + read_unlock(&grsec_exec_file_lock); \
58363 + read_unlock(&tasklist_lock); \
58364 + rcu_read_unlock(); \
58365 + ENABLE_PREEMPT(); \
58366 + if (x == GR_DONT_AUDIT) \
58367 + gr_handle_alertkill(current)
58368 +
58369 +enum {
58370 + FLOODING,
58371 + NO_FLOODING
58372 +};
58373 +
58374 +extern char *gr_alert_log_fmt;
58375 +extern char *gr_audit_log_fmt;
58376 +extern char *gr_alert_log_buf;
58377 +extern char *gr_audit_log_buf;
58378 +
58379 +static int gr_log_start(int audit)
58380 +{
58381 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
58382 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
58383 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58384 +
58385 + if (audit == GR_DO_AUDIT)
58386 + goto set_fmt;
58387 +
58388 + if (!grsec_alert_wtime || jiffies - grsec_alert_wtime > CONFIG_GRKERNSEC_FLOODTIME * HZ) {
58389 + grsec_alert_wtime = jiffies;
58390 + grsec_alert_fyet = 0;
58391 + } else if ((jiffies - grsec_alert_wtime < CONFIG_GRKERNSEC_FLOODTIME * HZ) && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
58392 + grsec_alert_fyet++;
58393 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
58394 + grsec_alert_wtime = jiffies;
58395 + grsec_alert_fyet++;
58396 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
58397 + return FLOODING;
58398 + } else return FLOODING;
58399 +
58400 +set_fmt:
58401 + memset(buf, 0, PAGE_SIZE);
58402 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
58403 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
58404 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58405 + } else if (current->signal->curr_ip) {
58406 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
58407 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
58408 + } else if (gr_acl_is_enabled()) {
58409 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
58410 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58411 + } else {
58412 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
58413 + strcpy(buf, fmt);
58414 + }
58415 +
58416 + return NO_FLOODING;
58417 +}
58418 +
58419 +static void gr_log_middle(int audit, const char *msg, va_list ap)
58420 + __attribute__ ((format (printf, 2, 0)));
58421 +
58422 +static void gr_log_middle(int audit, const char *msg, va_list ap)
58423 +{
58424 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58425 + unsigned int len = strlen(buf);
58426 +
58427 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58428 +
58429 + return;
58430 +}
58431 +
58432 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
58433 + __attribute__ ((format (printf, 2, 3)));
58434 +
58435 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
58436 +{
58437 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58438 + unsigned int len = strlen(buf);
58439 + va_list ap;
58440 +
58441 + va_start(ap, msg);
58442 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58443 + va_end(ap);
58444 +
58445 + return;
58446 +}
58447 +
58448 +static void gr_log_end(int audit)
58449 +{
58450 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58451 + unsigned int len = strlen(buf);
58452 +
58453 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
58454 + printk("%s\n", buf);
58455 +
58456 + return;
58457 +}
58458 +
58459 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
58460 +{
58461 + int logtype;
58462 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
58463 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
58464 + void *voidptr = NULL;
58465 + int num1 = 0, num2 = 0;
58466 + unsigned long ulong1 = 0, ulong2 = 0;
58467 + struct dentry *dentry = NULL;
58468 + struct vfsmount *mnt = NULL;
58469 + struct file *file = NULL;
58470 + struct task_struct *task = NULL;
58471 + const struct cred *cred, *pcred;
58472 + va_list ap;
58473 +
58474 + BEGIN_LOCKS(audit);
58475 + logtype = gr_log_start(audit);
58476 + if (logtype == FLOODING) {
58477 + END_LOCKS(audit);
58478 + return;
58479 + }
58480 + va_start(ap, argtypes);
58481 + switch (argtypes) {
58482 + case GR_TTYSNIFF:
58483 + task = va_arg(ap, struct task_struct *);
58484 + 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);
58485 + break;
58486 + case GR_SYSCTL_HIDDEN:
58487 + str1 = va_arg(ap, char *);
58488 + gr_log_middle_varargs(audit, msg, result, str1);
58489 + break;
58490 + case GR_RBAC:
58491 + dentry = va_arg(ap, struct dentry *);
58492 + mnt = va_arg(ap, struct vfsmount *);
58493 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
58494 + break;
58495 + case GR_RBAC_STR:
58496 + dentry = va_arg(ap, struct dentry *);
58497 + mnt = va_arg(ap, struct vfsmount *);
58498 + str1 = va_arg(ap, char *);
58499 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
58500 + break;
58501 + case GR_STR_RBAC:
58502 + str1 = va_arg(ap, char *);
58503 + dentry = va_arg(ap, struct dentry *);
58504 + mnt = va_arg(ap, struct vfsmount *);
58505 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
58506 + break;
58507 + case GR_RBAC_MODE2:
58508 + dentry = va_arg(ap, struct dentry *);
58509 + mnt = va_arg(ap, struct vfsmount *);
58510 + str1 = va_arg(ap, char *);
58511 + str2 = va_arg(ap, char *);
58512 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
58513 + break;
58514 + case GR_RBAC_MODE3:
58515 + dentry = va_arg(ap, struct dentry *);
58516 + mnt = va_arg(ap, struct vfsmount *);
58517 + str1 = va_arg(ap, char *);
58518 + str2 = va_arg(ap, char *);
58519 + str3 = va_arg(ap, char *);
58520 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
58521 + break;
58522 + case GR_FILENAME:
58523 + dentry = va_arg(ap, struct dentry *);
58524 + mnt = va_arg(ap, struct vfsmount *);
58525 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
58526 + break;
58527 + case GR_STR_FILENAME:
58528 + str1 = va_arg(ap, char *);
58529 + dentry = va_arg(ap, struct dentry *);
58530 + mnt = va_arg(ap, struct vfsmount *);
58531 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
58532 + break;
58533 + case GR_FILENAME_STR:
58534 + dentry = va_arg(ap, struct dentry *);
58535 + mnt = va_arg(ap, struct vfsmount *);
58536 + str1 = va_arg(ap, char *);
58537 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
58538 + break;
58539 + case GR_FILENAME_TWO_INT:
58540 + dentry = va_arg(ap, struct dentry *);
58541 + mnt = va_arg(ap, struct vfsmount *);
58542 + num1 = va_arg(ap, int);
58543 + num2 = va_arg(ap, int);
58544 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
58545 + break;
58546 + case GR_FILENAME_TWO_INT_STR:
58547 + dentry = va_arg(ap, struct dentry *);
58548 + mnt = va_arg(ap, struct vfsmount *);
58549 + num1 = va_arg(ap, int);
58550 + num2 = va_arg(ap, int);
58551 + str1 = va_arg(ap, char *);
58552 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
58553 + break;
58554 + case GR_TEXTREL:
58555 + file = va_arg(ap, struct file *);
58556 + ulong1 = va_arg(ap, unsigned long);
58557 + ulong2 = va_arg(ap, unsigned long);
58558 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
58559 + break;
58560 + case GR_PTRACE:
58561 + task = va_arg(ap, struct task_struct *);
58562 + 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);
58563 + break;
58564 + case GR_RESOURCE:
58565 + task = va_arg(ap, struct task_struct *);
58566 + cred = __task_cred(task);
58567 + pcred = __task_cred(task->real_parent);
58568 + ulong1 = va_arg(ap, unsigned long);
58569 + str1 = va_arg(ap, char *);
58570 + ulong2 = va_arg(ap, unsigned long);
58571 + 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);
58572 + break;
58573 + case GR_CAP:
58574 + task = va_arg(ap, struct task_struct *);
58575 + cred = __task_cred(task);
58576 + pcred = __task_cred(task->real_parent);
58577 + str1 = va_arg(ap, char *);
58578 + 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);
58579 + break;
58580 + case GR_SIG:
58581 + str1 = va_arg(ap, char *);
58582 + voidptr = va_arg(ap, void *);
58583 + gr_log_middle_varargs(audit, msg, str1, voidptr);
58584 + break;
58585 + case GR_SIG2:
58586 + task = va_arg(ap, struct task_struct *);
58587 + cred = __task_cred(task);
58588 + pcred = __task_cred(task->real_parent);
58589 + num1 = va_arg(ap, int);
58590 + 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);
58591 + break;
58592 + case GR_CRASH1:
58593 + task = va_arg(ap, struct task_struct *);
58594 + cred = __task_cred(task);
58595 + pcred = __task_cred(task->real_parent);
58596 + ulong1 = va_arg(ap, unsigned long);
58597 + 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);
58598 + break;
58599 + case GR_CRASH2:
58600 + task = va_arg(ap, struct task_struct *);
58601 + cred = __task_cred(task);
58602 + pcred = __task_cred(task->real_parent);
58603 + ulong1 = va_arg(ap, unsigned long);
58604 + 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);
58605 + break;
58606 + case GR_RWXMAP:
58607 + file = va_arg(ap, struct file *);
58608 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
58609 + break;
58610 + case GR_PSACCT:
58611 + {
58612 + unsigned int wday, cday;
58613 + __u8 whr, chr;
58614 + __u8 wmin, cmin;
58615 + __u8 wsec, csec;
58616 + char cur_tty[64] = { 0 };
58617 + char parent_tty[64] = { 0 };
58618 +
58619 + task = va_arg(ap, struct task_struct *);
58620 + wday = va_arg(ap, unsigned int);
58621 + cday = va_arg(ap, unsigned int);
58622 + whr = va_arg(ap, int);
58623 + chr = va_arg(ap, int);
58624 + wmin = va_arg(ap, int);
58625 + cmin = va_arg(ap, int);
58626 + wsec = va_arg(ap, int);
58627 + csec = va_arg(ap, int);
58628 + ulong1 = va_arg(ap, unsigned long);
58629 + cred = __task_cred(task);
58630 + pcred = __task_cred(task->real_parent);
58631 +
58632 + 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);
58633 + }
58634 + break;
58635 + default:
58636 + gr_log_middle(audit, msg, ap);
58637 + }
58638 + va_end(ap);
58639 + gr_log_end(audit);
58640 + END_LOCKS(audit);
58641 +}
58642 diff -urNp linux-2.6.39/grsecurity/grsec_mem.c linux-2.6.39/grsecurity/grsec_mem.c
58643 --- linux-2.6.39/grsecurity/grsec_mem.c 1969-12-31 19:00:00.000000000 -0500
58644 +++ linux-2.6.39/grsecurity/grsec_mem.c 2011-05-22 19:41:42.000000000 -0400
58645 @@ -0,0 +1,33 @@
58646 +#include <linux/kernel.h>
58647 +#include <linux/sched.h>
58648 +#include <linux/mm.h>
58649 +#include <linux/mman.h>
58650 +#include <linux/grinternal.h>
58651 +
58652 +void
58653 +gr_handle_ioperm(void)
58654 +{
58655 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
58656 + return;
58657 +}
58658 +
58659 +void
58660 +gr_handle_iopl(void)
58661 +{
58662 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
58663 + return;
58664 +}
58665 +
58666 +void
58667 +gr_handle_mem_readwrite(u64 from, u64 to)
58668 +{
58669 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
58670 + return;
58671 +}
58672 +
58673 +void
58674 +gr_handle_vm86(void)
58675 +{
58676 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
58677 + return;
58678 +}
58679 diff -urNp linux-2.6.39/grsecurity/grsec_mount.c linux-2.6.39/grsecurity/grsec_mount.c
58680 --- linux-2.6.39/grsecurity/grsec_mount.c 1969-12-31 19:00:00.000000000 -0500
58681 +++ linux-2.6.39/grsecurity/grsec_mount.c 2011-05-22 19:41:42.000000000 -0400
58682 @@ -0,0 +1,62 @@
58683 +#include <linux/kernel.h>
58684 +#include <linux/sched.h>
58685 +#include <linux/mount.h>
58686 +#include <linux/grsecurity.h>
58687 +#include <linux/grinternal.h>
58688 +
58689 +void
58690 +gr_log_remount(const char *devname, const int retval)
58691 +{
58692 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58693 + if (grsec_enable_mount && (retval >= 0))
58694 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
58695 +#endif
58696 + return;
58697 +}
58698 +
58699 +void
58700 +gr_log_unmount(const char *devname, const int retval)
58701 +{
58702 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58703 + if (grsec_enable_mount && (retval >= 0))
58704 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
58705 +#endif
58706 + return;
58707 +}
58708 +
58709 +void
58710 +gr_log_mount(const char *from, const char *to, const int retval)
58711 +{
58712 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58713 + if (grsec_enable_mount && (retval >= 0))
58714 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from, to);
58715 +#endif
58716 + return;
58717 +}
58718 +
58719 +int
58720 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
58721 +{
58722 +#ifdef CONFIG_GRKERNSEC_ROFS
58723 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
58724 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
58725 + return -EPERM;
58726 + } else
58727 + return 0;
58728 +#endif
58729 + return 0;
58730 +}
58731 +
58732 +int
58733 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
58734 +{
58735 +#ifdef CONFIG_GRKERNSEC_ROFS
58736 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
58737 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
58738 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
58739 + return -EPERM;
58740 + } else
58741 + return 0;
58742 +#endif
58743 + return 0;
58744 +}
58745 diff -urNp linux-2.6.39/grsecurity/grsec_pax.c linux-2.6.39/grsecurity/grsec_pax.c
58746 --- linux-2.6.39/grsecurity/grsec_pax.c 1969-12-31 19:00:00.000000000 -0500
58747 +++ linux-2.6.39/grsecurity/grsec_pax.c 2011-05-22 19:41:42.000000000 -0400
58748 @@ -0,0 +1,36 @@
58749 +#include <linux/kernel.h>
58750 +#include <linux/sched.h>
58751 +#include <linux/mm.h>
58752 +#include <linux/file.h>
58753 +#include <linux/grinternal.h>
58754 +#include <linux/grsecurity.h>
58755 +
58756 +void
58757 +gr_log_textrel(struct vm_area_struct * vma)
58758 +{
58759 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58760 + if (grsec_enable_audit_textrel)
58761 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
58762 +#endif
58763 + return;
58764 +}
58765 +
58766 +void
58767 +gr_log_rwxmmap(struct file *file)
58768 +{
58769 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58770 + if (grsec_enable_log_rwxmaps)
58771 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
58772 +#endif
58773 + return;
58774 +}
58775 +
58776 +void
58777 +gr_log_rwxmprotect(struct file *file)
58778 +{
58779 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58780 + if (grsec_enable_log_rwxmaps)
58781 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
58782 +#endif
58783 + return;
58784 +}
58785 diff -urNp linux-2.6.39/grsecurity/grsec_ptrace.c linux-2.6.39/grsecurity/grsec_ptrace.c
58786 --- linux-2.6.39/grsecurity/grsec_ptrace.c 1969-12-31 19:00:00.000000000 -0500
58787 +++ linux-2.6.39/grsecurity/grsec_ptrace.c 2011-05-22 19:41:42.000000000 -0400
58788 @@ -0,0 +1,14 @@
58789 +#include <linux/kernel.h>
58790 +#include <linux/sched.h>
58791 +#include <linux/grinternal.h>
58792 +#include <linux/grsecurity.h>
58793 +
58794 +void
58795 +gr_audit_ptrace(struct task_struct *task)
58796 +{
58797 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58798 + if (grsec_enable_audit_ptrace)
58799 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
58800 +#endif
58801 + return;
58802 +}
58803 diff -urNp linux-2.6.39/grsecurity/grsec_sig.c linux-2.6.39/grsecurity/grsec_sig.c
58804 --- linux-2.6.39/grsecurity/grsec_sig.c 1969-12-31 19:00:00.000000000 -0500
58805 +++ linux-2.6.39/grsecurity/grsec_sig.c 2011-05-22 19:41:42.000000000 -0400
58806 @@ -0,0 +1,203 @@
58807 +#include <linux/kernel.h>
58808 +#include <linux/sched.h>
58809 +#include <linux/delay.h>
58810 +#include <linux/grsecurity.h>
58811 +#include <linux/grinternal.h>
58812 +#include <linux/hardirq.h>
58813 +
58814 +char *signames[] = {
58815 + [SIGSEGV] = "Segmentation fault",
58816 + [SIGILL] = "Illegal instruction",
58817 + [SIGABRT] = "Abort",
58818 + [SIGBUS] = "Invalid alignment/Bus error"
58819 +};
58820 +
58821 +void
58822 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
58823 +{
58824 +#ifdef CONFIG_GRKERNSEC_SIGNAL
58825 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
58826 + (sig == SIGABRT) || (sig == SIGBUS))) {
58827 + if (t->pid == current->pid) {
58828 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
58829 + } else {
58830 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
58831 + }
58832 + }
58833 +#endif
58834 + return;
58835 +}
58836 +
58837 +int
58838 +gr_handle_signal(const struct task_struct *p, const int sig)
58839 +{
58840 +#ifdef CONFIG_GRKERNSEC
58841 + if (current->pid > 1 && gr_check_protected_task(p)) {
58842 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
58843 + return -EPERM;
58844 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
58845 + return -EPERM;
58846 + }
58847 +#endif
58848 + return 0;
58849 +}
58850 +
58851 +#ifdef CONFIG_GRKERNSEC
58852 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
58853 +
58854 +int gr_fake_force_sig(int sig, struct task_struct *t)
58855 +{
58856 + unsigned long int flags;
58857 + int ret, blocked, ignored;
58858 + struct k_sigaction *action;
58859 +
58860 + spin_lock_irqsave(&t->sighand->siglock, flags);
58861 + action = &t->sighand->action[sig-1];
58862 + ignored = action->sa.sa_handler == SIG_IGN;
58863 + blocked = sigismember(&t->blocked, sig);
58864 + if (blocked || ignored) {
58865 + action->sa.sa_handler = SIG_DFL;
58866 + if (blocked) {
58867 + sigdelset(&t->blocked, sig);
58868 + recalc_sigpending_and_wake(t);
58869 + }
58870 + }
58871 + if (action->sa.sa_handler == SIG_DFL)
58872 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
58873 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
58874 +
58875 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
58876 +
58877 + return ret;
58878 +}
58879 +#endif
58880 +
58881 +#ifdef CONFIG_GRKERNSEC_BRUTE
58882 +#define GR_USER_BAN_TIME (15 * 60)
58883 +
58884 +static int __get_dumpable(unsigned long mm_flags)
58885 +{
58886 + int ret;
58887 +
58888 + ret = mm_flags & MMF_DUMPABLE_MASK;
58889 + return (ret >= 2) ? 2 : ret;
58890 +}
58891 +#endif
58892 +
58893 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
58894 +{
58895 +#ifdef CONFIG_GRKERNSEC_BRUTE
58896 + uid_t uid = 0;
58897 +
58898 + rcu_read_lock();
58899 + read_lock(&tasklist_lock);
58900 + read_lock(&grsec_exec_file_lock);
58901 + if (p->real_parent && p->real_parent->exec_file == p->exec_file)
58902 + p->real_parent->brute = 1;
58903 + else {
58904 + const struct cred *cred = __task_cred(p), *cred2;
58905 + struct task_struct *tsk, *tsk2;
58906 +
58907 + if (!__get_dumpable(mm_flags) && cred->uid) {
58908 + struct user_struct *user;
58909 +
58910 + uid = cred->uid;
58911 +
58912 + /* this is put upon execution past expiration */
58913 + user = find_user(uid);
58914 + if (user == NULL)
58915 + goto unlock;
58916 + user->banned = 1;
58917 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
58918 + if (user->ban_expires == ~0UL)
58919 + user->ban_expires--;
58920 +
58921 + do_each_thread(tsk2, tsk) {
58922 + cred2 = __task_cred(tsk);
58923 + if (tsk != p && cred2->uid == uid)
58924 + gr_fake_force_sig(SIGKILL, tsk);
58925 + } while_each_thread(tsk2, tsk);
58926 + }
58927 + }
58928 +unlock:
58929 + read_unlock(&grsec_exec_file_lock);
58930 + read_unlock(&tasklist_lock);
58931 + rcu_read_unlock();
58932 +
58933 + if (uid)
58934 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n", uid, GR_USER_BAN_TIME / 60);
58935 +
58936 +#endif
58937 + return;
58938 +}
58939 +
58940 +void gr_handle_brute_check(void)
58941 +{
58942 +#ifdef CONFIG_GRKERNSEC_BRUTE
58943 + if (current->brute)
58944 + msleep(30 * 1000);
58945 +#endif
58946 + return;
58947 +}
58948 +
58949 +void gr_handle_kernel_exploit(void)
58950 +{
58951 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
58952 + const struct cred *cred;
58953 + struct task_struct *tsk, *tsk2;
58954 + struct user_struct *user;
58955 + uid_t uid;
58956 +
58957 + if (in_irq() || in_serving_softirq() || in_nmi())
58958 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
58959 +
58960 + uid = current_uid();
58961 +
58962 + if (uid == 0)
58963 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
58964 + else {
58965 + /* kill all the processes of this user, hold a reference
58966 + to their creds struct, and prevent them from creating
58967 + another process until system reset
58968 + */
58969 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n", uid);
58970 + /* we intentionally leak this ref */
58971 + user = get_uid(current->cred->user);
58972 + if (user) {
58973 + user->banned = 1;
58974 + user->ban_expires = ~0UL;
58975 + }
58976 +
58977 + read_lock(&tasklist_lock);
58978 + do_each_thread(tsk2, tsk) {
58979 + cred = __task_cred(tsk);
58980 + if (cred->uid == uid)
58981 + gr_fake_force_sig(SIGKILL, tsk);
58982 + } while_each_thread(tsk2, tsk);
58983 + read_unlock(&tasklist_lock);
58984 + }
58985 +#endif
58986 +}
58987 +
58988 +int __gr_process_user_ban(struct user_struct *user)
58989 +{
58990 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
58991 + if (unlikely(user->banned)) {
58992 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
58993 + user->banned = 0;
58994 + user->ban_expires = 0;
58995 + free_uid(user);
58996 + } else
58997 + return -EPERM;
58998 + }
58999 +#endif
59000 + return 0;
59001 +}
59002 +
59003 +int gr_process_user_ban(void)
59004 +{
59005 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59006 + return __gr_process_user_ban(current->cred->user);
59007 +#endif
59008 + return 0;
59009 +}
59010 diff -urNp linux-2.6.39/grsecurity/grsec_sock.c linux-2.6.39/grsecurity/grsec_sock.c
59011 --- linux-2.6.39/grsecurity/grsec_sock.c 1969-12-31 19:00:00.000000000 -0500
59012 +++ linux-2.6.39/grsecurity/grsec_sock.c 2011-05-22 20:29:21.000000000 -0400
59013 @@ -0,0 +1,244 @@
59014 +#include <linux/kernel.h>
59015 +#include <linux/module.h>
59016 +#include <linux/sched.h>
59017 +#include <linux/file.h>
59018 +#include <linux/net.h>
59019 +#include <linux/in.h>
59020 +#include <linux/ip.h>
59021 +#include <net/sock.h>
59022 +#include <net/inet_sock.h>
59023 +#include <linux/grsecurity.h>
59024 +#include <linux/grinternal.h>
59025 +#include <linux/gracl.h>
59026 +
59027 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
59028 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
59029 +
59030 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
59031 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
59032 +
59033 +#ifdef CONFIG_UNIX_MODULE
59034 +EXPORT_SYMBOL(gr_acl_handle_unix);
59035 +EXPORT_SYMBOL(gr_acl_handle_mknod);
59036 +EXPORT_SYMBOL(gr_handle_chroot_unix);
59037 +EXPORT_SYMBOL(gr_handle_create);
59038 +#endif
59039 +
59040 +#ifdef CONFIG_GRKERNSEC
59041 +#define gr_conn_table_size 32749
59042 +struct conn_table_entry {
59043 + struct conn_table_entry *next;
59044 + struct signal_struct *sig;
59045 +};
59046 +
59047 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
59048 +DEFINE_SPINLOCK(gr_conn_table_lock);
59049 +
59050 +extern const char * gr_socktype_to_name(unsigned char type);
59051 +extern const char * gr_proto_to_name(unsigned char proto);
59052 +extern const char * gr_sockfamily_to_name(unsigned char family);
59053 +
59054 +static __inline__ int
59055 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
59056 +{
59057 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
59058 +}
59059 +
59060 +static __inline__ int
59061 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
59062 + __u16 sport, __u16 dport)
59063 +{
59064 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
59065 + sig->gr_sport == sport && sig->gr_dport == dport))
59066 + return 1;
59067 + else
59068 + return 0;
59069 +}
59070 +
59071 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
59072 +{
59073 + struct conn_table_entry **match;
59074 + unsigned int index;
59075 +
59076 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59077 + sig->gr_sport, sig->gr_dport,
59078 + gr_conn_table_size);
59079 +
59080 + newent->sig = sig;
59081 +
59082 + match = &gr_conn_table[index];
59083 + newent->next = *match;
59084 + *match = newent;
59085 +
59086 + return;
59087 +}
59088 +
59089 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
59090 +{
59091 + struct conn_table_entry *match, *last = NULL;
59092 + unsigned int index;
59093 +
59094 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59095 + sig->gr_sport, sig->gr_dport,
59096 + gr_conn_table_size);
59097 +
59098 + match = gr_conn_table[index];
59099 + while (match && !conn_match(match->sig,
59100 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
59101 + sig->gr_dport)) {
59102 + last = match;
59103 + match = match->next;
59104 + }
59105 +
59106 + if (match) {
59107 + if (last)
59108 + last->next = match->next;
59109 + else
59110 + gr_conn_table[index] = NULL;
59111 + kfree(match);
59112 + }
59113 +
59114 + return;
59115 +}
59116 +
59117 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
59118 + __u16 sport, __u16 dport)
59119 +{
59120 + struct conn_table_entry *match;
59121 + unsigned int index;
59122 +
59123 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
59124 +
59125 + match = gr_conn_table[index];
59126 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
59127 + match = match->next;
59128 +
59129 + if (match)
59130 + return match->sig;
59131 + else
59132 + return NULL;
59133 +}
59134 +
59135 +#endif
59136 +
59137 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
59138 +{
59139 +#ifdef CONFIG_GRKERNSEC
59140 + struct signal_struct *sig = task->signal;
59141 + struct conn_table_entry *newent;
59142 +
59143 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
59144 + if (newent == NULL)
59145 + return;
59146 + /* no bh lock needed since we are called with bh disabled */
59147 + spin_lock(&gr_conn_table_lock);
59148 + gr_del_task_from_ip_table_nolock(sig);
59149 + sig->gr_saddr = inet->inet_rcv_saddr;
59150 + sig->gr_daddr = inet->inet_daddr;
59151 + sig->gr_sport = inet->inet_sport;
59152 + sig->gr_dport = inet->inet_dport;
59153 + gr_add_to_task_ip_table_nolock(sig, newent);
59154 + spin_unlock(&gr_conn_table_lock);
59155 +#endif
59156 + return;
59157 +}
59158 +
59159 +void gr_del_task_from_ip_table(struct task_struct *task)
59160 +{
59161 +#ifdef CONFIG_GRKERNSEC
59162 + spin_lock_bh(&gr_conn_table_lock);
59163 + gr_del_task_from_ip_table_nolock(task->signal);
59164 + spin_unlock_bh(&gr_conn_table_lock);
59165 +#endif
59166 + return;
59167 +}
59168 +
59169 +void
59170 +gr_attach_curr_ip(const struct sock *sk)
59171 +{
59172 +#ifdef CONFIG_GRKERNSEC
59173 + struct signal_struct *p, *set;
59174 + const struct inet_sock *inet = inet_sk(sk);
59175 +
59176 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
59177 + return;
59178 +
59179 + set = current->signal;
59180 +
59181 + spin_lock_bh(&gr_conn_table_lock);
59182 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
59183 + inet->inet_dport, inet->inet_sport);
59184 + if (unlikely(p != NULL)) {
59185 + set->curr_ip = p->curr_ip;
59186 + set->used_accept = 1;
59187 + gr_del_task_from_ip_table_nolock(p);
59188 + spin_unlock_bh(&gr_conn_table_lock);
59189 + return;
59190 + }
59191 + spin_unlock_bh(&gr_conn_table_lock);
59192 +
59193 + set->curr_ip = inet->inet_daddr;
59194 + set->used_accept = 1;
59195 +#endif
59196 + return;
59197 +}
59198 +
59199 +int
59200 +gr_handle_sock_all(const int family, const int type, const int protocol)
59201 +{
59202 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59203 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
59204 + (family != AF_UNIX)) {
59205 + if (family == AF_INET)
59206 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
59207 + else
59208 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
59209 + return -EACCES;
59210 + }
59211 +#endif
59212 + return 0;
59213 +}
59214 +
59215 +int
59216 +gr_handle_sock_server(const struct sockaddr *sck)
59217 +{
59218 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59219 + if (grsec_enable_socket_server &&
59220 + in_group_p(grsec_socket_server_gid) &&
59221 + sck && (sck->sa_family != AF_UNIX) &&
59222 + (sck->sa_family != AF_LOCAL)) {
59223 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59224 + return -EACCES;
59225 + }
59226 +#endif
59227 + return 0;
59228 +}
59229 +
59230 +int
59231 +gr_handle_sock_server_other(const struct sock *sck)
59232 +{
59233 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59234 + if (grsec_enable_socket_server &&
59235 + in_group_p(grsec_socket_server_gid) &&
59236 + sck && (sck->sk_family != AF_UNIX) &&
59237 + (sck->sk_family != AF_LOCAL)) {
59238 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59239 + return -EACCES;
59240 + }
59241 +#endif
59242 + return 0;
59243 +}
59244 +
59245 +int
59246 +gr_handle_sock_client(const struct sockaddr *sck)
59247 +{
59248 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59249 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
59250 + sck && (sck->sa_family != AF_UNIX) &&
59251 + (sck->sa_family != AF_LOCAL)) {
59252 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
59253 + return -EACCES;
59254 + }
59255 +#endif
59256 + return 0;
59257 +}
59258 diff -urNp linux-2.6.39/grsecurity/grsec_sysctl.c linux-2.6.39/grsecurity/grsec_sysctl.c
59259 --- linux-2.6.39/grsecurity/grsec_sysctl.c 1969-12-31 19:00:00.000000000 -0500
59260 +++ linux-2.6.39/grsecurity/grsec_sysctl.c 2011-05-22 19:41:42.000000000 -0400
59261 @@ -0,0 +1,433 @@
59262 +#include <linux/kernel.h>
59263 +#include <linux/sched.h>
59264 +#include <linux/sysctl.h>
59265 +#include <linux/grsecurity.h>
59266 +#include <linux/grinternal.h>
59267 +
59268 +int
59269 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
59270 +{
59271 +#ifdef CONFIG_GRKERNSEC_SYSCTL
59272 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
59273 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
59274 + return -EACCES;
59275 + }
59276 +#endif
59277 + return 0;
59278 +}
59279 +
59280 +#ifdef CONFIG_GRKERNSEC_ROFS
59281 +static int __maybe_unused one = 1;
59282 +#endif
59283 +
59284 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
59285 +struct ctl_table grsecurity_table[] = {
59286 +#ifdef CONFIG_GRKERNSEC_SYSCTL
59287 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
59288 +#ifdef CONFIG_GRKERNSEC_IO
59289 + {
59290 + .procname = "disable_priv_io",
59291 + .data = &grsec_disable_privio,
59292 + .maxlen = sizeof(int),
59293 + .mode = 0600,
59294 + .proc_handler = &proc_dointvec,
59295 + },
59296 +#endif
59297 +#endif
59298 +#ifdef CONFIG_GRKERNSEC_LINK
59299 + {
59300 + .procname = "linking_restrictions",
59301 + .data = &grsec_enable_link,
59302 + .maxlen = sizeof(int),
59303 + .mode = 0600,
59304 + .proc_handler = &proc_dointvec,
59305 + },
59306 +#endif
59307 +#ifdef CONFIG_GRKERNSEC_FIFO
59308 + {
59309 + .procname = "fifo_restrictions",
59310 + .data = &grsec_enable_fifo,
59311 + .maxlen = sizeof(int),
59312 + .mode = 0600,
59313 + .proc_handler = &proc_dointvec,
59314 + },
59315 +#endif
59316 +#ifdef CONFIG_GRKERNSEC_EXECVE
59317 + {
59318 + .procname = "execve_limiting",
59319 + .data = &grsec_enable_execve,
59320 + .maxlen = sizeof(int),
59321 + .mode = 0600,
59322 + .proc_handler = &proc_dointvec,
59323 + },
59324 +#endif
59325 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
59326 + {
59327 + .procname = "ip_blackhole",
59328 + .data = &grsec_enable_blackhole,
59329 + .maxlen = sizeof(int),
59330 + .mode = 0600,
59331 + .proc_handler = &proc_dointvec,
59332 + },
59333 + {
59334 + .procname = "lastack_retries",
59335 + .data = &grsec_lastack_retries,
59336 + .maxlen = sizeof(int),
59337 + .mode = 0600,
59338 + .proc_handler = &proc_dointvec,
59339 + },
59340 +#endif
59341 +#ifdef CONFIG_GRKERNSEC_EXECLOG
59342 + {
59343 + .procname = "exec_logging",
59344 + .data = &grsec_enable_execlog,
59345 + .maxlen = sizeof(int),
59346 + .mode = 0600,
59347 + .proc_handler = &proc_dointvec,
59348 + },
59349 +#endif
59350 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59351 + {
59352 + .procname = "rwxmap_logging",
59353 + .data = &grsec_enable_log_rwxmaps,
59354 + .maxlen = sizeof(int),
59355 + .mode = 0600,
59356 + .proc_handler = &proc_dointvec,
59357 + },
59358 +#endif
59359 +#ifdef CONFIG_GRKERNSEC_SIGNAL
59360 + {
59361 + .procname = "signal_logging",
59362 + .data = &grsec_enable_signal,
59363 + .maxlen = sizeof(int),
59364 + .mode = 0600,
59365 + .proc_handler = &proc_dointvec,
59366 + },
59367 +#endif
59368 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
59369 + {
59370 + .procname = "forkfail_logging",
59371 + .data = &grsec_enable_forkfail,
59372 + .maxlen = sizeof(int),
59373 + .mode = 0600,
59374 + .proc_handler = &proc_dointvec,
59375 + },
59376 +#endif
59377 +#ifdef CONFIG_GRKERNSEC_TIME
59378 + {
59379 + .procname = "timechange_logging",
59380 + .data = &grsec_enable_time,
59381 + .maxlen = sizeof(int),
59382 + .mode = 0600,
59383 + .proc_handler = &proc_dointvec,
59384 + },
59385 +#endif
59386 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
59387 + {
59388 + .procname = "chroot_deny_shmat",
59389 + .data = &grsec_enable_chroot_shmat,
59390 + .maxlen = sizeof(int),
59391 + .mode = 0600,
59392 + .proc_handler = &proc_dointvec,
59393 + },
59394 +#endif
59395 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
59396 + {
59397 + .procname = "chroot_deny_unix",
59398 + .data = &grsec_enable_chroot_unix,
59399 + .maxlen = sizeof(int),
59400 + .mode = 0600,
59401 + .proc_handler = &proc_dointvec,
59402 + },
59403 +#endif
59404 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
59405 + {
59406 + .procname = "chroot_deny_mount",
59407 + .data = &grsec_enable_chroot_mount,
59408 + .maxlen = sizeof(int),
59409 + .mode = 0600,
59410 + .proc_handler = &proc_dointvec,
59411 + },
59412 +#endif
59413 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
59414 + {
59415 + .procname = "chroot_deny_fchdir",
59416 + .data = &grsec_enable_chroot_fchdir,
59417 + .maxlen = sizeof(int),
59418 + .mode = 0600,
59419 + .proc_handler = &proc_dointvec,
59420 + },
59421 +#endif
59422 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
59423 + {
59424 + .procname = "chroot_deny_chroot",
59425 + .data = &grsec_enable_chroot_double,
59426 + .maxlen = sizeof(int),
59427 + .mode = 0600,
59428 + .proc_handler = &proc_dointvec,
59429 + },
59430 +#endif
59431 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
59432 + {
59433 + .procname = "chroot_deny_pivot",
59434 + .data = &grsec_enable_chroot_pivot,
59435 + .maxlen = sizeof(int),
59436 + .mode = 0600,
59437 + .proc_handler = &proc_dointvec,
59438 + },
59439 +#endif
59440 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
59441 + {
59442 + .procname = "chroot_enforce_chdir",
59443 + .data = &grsec_enable_chroot_chdir,
59444 + .maxlen = sizeof(int),
59445 + .mode = 0600,
59446 + .proc_handler = &proc_dointvec,
59447 + },
59448 +#endif
59449 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
59450 + {
59451 + .procname = "chroot_deny_chmod",
59452 + .data = &grsec_enable_chroot_chmod,
59453 + .maxlen = sizeof(int),
59454 + .mode = 0600,
59455 + .proc_handler = &proc_dointvec,
59456 + },
59457 +#endif
59458 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
59459 + {
59460 + .procname = "chroot_deny_mknod",
59461 + .data = &grsec_enable_chroot_mknod,
59462 + .maxlen = sizeof(int),
59463 + .mode = 0600,
59464 + .proc_handler = &proc_dointvec,
59465 + },
59466 +#endif
59467 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59468 + {
59469 + .procname = "chroot_restrict_nice",
59470 + .data = &grsec_enable_chroot_nice,
59471 + .maxlen = sizeof(int),
59472 + .mode = 0600,
59473 + .proc_handler = &proc_dointvec,
59474 + },
59475 +#endif
59476 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
59477 + {
59478 + .procname = "chroot_execlog",
59479 + .data = &grsec_enable_chroot_execlog,
59480 + .maxlen = sizeof(int),
59481 + .mode = 0600,
59482 + .proc_handler = &proc_dointvec,
59483 + },
59484 +#endif
59485 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59486 + {
59487 + .procname = "chroot_caps",
59488 + .data = &grsec_enable_chroot_caps,
59489 + .maxlen = sizeof(int),
59490 + .mode = 0600,
59491 + .proc_handler = &proc_dointvec,
59492 + },
59493 +#endif
59494 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
59495 + {
59496 + .procname = "chroot_deny_sysctl",
59497 + .data = &grsec_enable_chroot_sysctl,
59498 + .maxlen = sizeof(int),
59499 + .mode = 0600,
59500 + .proc_handler = &proc_dointvec,
59501 + },
59502 +#endif
59503 +#ifdef CONFIG_GRKERNSEC_TPE
59504 + {
59505 + .procname = "tpe",
59506 + .data = &grsec_enable_tpe,
59507 + .maxlen = sizeof(int),
59508 + .mode = 0600,
59509 + .proc_handler = &proc_dointvec,
59510 + },
59511 + {
59512 + .procname = "tpe_gid",
59513 + .data = &grsec_tpe_gid,
59514 + .maxlen = sizeof(int),
59515 + .mode = 0600,
59516 + .proc_handler = &proc_dointvec,
59517 + },
59518 +#endif
59519 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59520 + {
59521 + .procname = "tpe_invert",
59522 + .data = &grsec_enable_tpe_invert,
59523 + .maxlen = sizeof(int),
59524 + .mode = 0600,
59525 + .proc_handler = &proc_dointvec,
59526 + },
59527 +#endif
59528 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
59529 + {
59530 + .procname = "tpe_restrict_all",
59531 + .data = &grsec_enable_tpe_all,
59532 + .maxlen = sizeof(int),
59533 + .mode = 0600,
59534 + .proc_handler = &proc_dointvec,
59535 + },
59536 +#endif
59537 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59538 + {
59539 + .procname = "socket_all",
59540 + .data = &grsec_enable_socket_all,
59541 + .maxlen = sizeof(int),
59542 + .mode = 0600,
59543 + .proc_handler = &proc_dointvec,
59544 + },
59545 + {
59546 + .procname = "socket_all_gid",
59547 + .data = &grsec_socket_all_gid,
59548 + .maxlen = sizeof(int),
59549 + .mode = 0600,
59550 + .proc_handler = &proc_dointvec,
59551 + },
59552 +#endif
59553 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59554 + {
59555 + .procname = "socket_client",
59556 + .data = &grsec_enable_socket_client,
59557 + .maxlen = sizeof(int),
59558 + .mode = 0600,
59559 + .proc_handler = &proc_dointvec,
59560 + },
59561 + {
59562 + .procname = "socket_client_gid",
59563 + .data = &grsec_socket_client_gid,
59564 + .maxlen = sizeof(int),
59565 + .mode = 0600,
59566 + .proc_handler = &proc_dointvec,
59567 + },
59568 +#endif
59569 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59570 + {
59571 + .procname = "socket_server",
59572 + .data = &grsec_enable_socket_server,
59573 + .maxlen = sizeof(int),
59574 + .mode = 0600,
59575 + .proc_handler = &proc_dointvec,
59576 + },
59577 + {
59578 + .procname = "socket_server_gid",
59579 + .data = &grsec_socket_server_gid,
59580 + .maxlen = sizeof(int),
59581 + .mode = 0600,
59582 + .proc_handler = &proc_dointvec,
59583 + },
59584 +#endif
59585 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
59586 + {
59587 + .procname = "audit_group",
59588 + .data = &grsec_enable_group,
59589 + .maxlen = sizeof(int),
59590 + .mode = 0600,
59591 + .proc_handler = &proc_dointvec,
59592 + },
59593 + {
59594 + .procname = "audit_gid",
59595 + .data = &grsec_audit_gid,
59596 + .maxlen = sizeof(int),
59597 + .mode = 0600,
59598 + .proc_handler = &proc_dointvec,
59599 + },
59600 +#endif
59601 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
59602 + {
59603 + .procname = "audit_chdir",
59604 + .data = &grsec_enable_chdir,
59605 + .maxlen = sizeof(int),
59606 + .mode = 0600,
59607 + .proc_handler = &proc_dointvec,
59608 + },
59609 +#endif
59610 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59611 + {
59612 + .procname = "audit_mount",
59613 + .data = &grsec_enable_mount,
59614 + .maxlen = sizeof(int),
59615 + .mode = 0600,
59616 + .proc_handler = &proc_dointvec,
59617 + },
59618 +#endif
59619 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59620 + {
59621 + .procname = "audit_textrel",
59622 + .data = &grsec_enable_audit_textrel,
59623 + .maxlen = sizeof(int),
59624 + .mode = 0600,
59625 + .proc_handler = &proc_dointvec,
59626 + },
59627 +#endif
59628 +#ifdef CONFIG_GRKERNSEC_DMESG
59629 + {
59630 + .procname = "dmesg",
59631 + .data = &grsec_enable_dmesg,
59632 + .maxlen = sizeof(int),
59633 + .mode = 0600,
59634 + .proc_handler = &proc_dointvec,
59635 + },
59636 +#endif
59637 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59638 + {
59639 + .procname = "chroot_findtask",
59640 + .data = &grsec_enable_chroot_findtask,
59641 + .maxlen = sizeof(int),
59642 + .mode = 0600,
59643 + .proc_handler = &proc_dointvec,
59644 + },
59645 +#endif
59646 +#ifdef CONFIG_GRKERNSEC_RESLOG
59647 + {
59648 + .procname = "resource_logging",
59649 + .data = &grsec_resource_logging,
59650 + .maxlen = sizeof(int),
59651 + .mode = 0600,
59652 + .proc_handler = &proc_dointvec,
59653 + },
59654 +#endif
59655 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59656 + {
59657 + .procname = "audit_ptrace",
59658 + .data = &grsec_enable_audit_ptrace,
59659 + .maxlen = sizeof(int),
59660 + .mode = 0600,
59661 + .proc_handler = &proc_dointvec,
59662 + },
59663 +#endif
59664 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
59665 + {
59666 + .procname = "harden_ptrace",
59667 + .data = &grsec_enable_harden_ptrace,
59668 + .maxlen = sizeof(int),
59669 + .mode = 0600,
59670 + .proc_handler = &proc_dointvec,
59671 + },
59672 +#endif
59673 + {
59674 + .procname = "grsec_lock",
59675 + .data = &grsec_lock,
59676 + .maxlen = sizeof(int),
59677 + .mode = 0600,
59678 + .proc_handler = &proc_dointvec,
59679 + },
59680 +#endif
59681 +#ifdef CONFIG_GRKERNSEC_ROFS
59682 + {
59683 + .procname = "romount_protect",
59684 + .data = &grsec_enable_rofs,
59685 + .maxlen = sizeof(int),
59686 + .mode = 0600,
59687 + .proc_handler = &proc_dointvec_minmax,
59688 + .extra1 = &one,
59689 + .extra2 = &one,
59690 + },
59691 +#endif
59692 + { }
59693 +};
59694 +#endif
59695 diff -urNp linux-2.6.39/grsecurity/grsec_time.c linux-2.6.39/grsecurity/grsec_time.c
59696 --- linux-2.6.39/grsecurity/grsec_time.c 1969-12-31 19:00:00.000000000 -0500
59697 +++ linux-2.6.39/grsecurity/grsec_time.c 2011-05-22 19:41:42.000000000 -0400
59698 @@ -0,0 +1,16 @@
59699 +#include <linux/kernel.h>
59700 +#include <linux/sched.h>
59701 +#include <linux/grinternal.h>
59702 +#include <linux/module.h>
59703 +
59704 +void
59705 +gr_log_timechange(void)
59706 +{
59707 +#ifdef CONFIG_GRKERNSEC_TIME
59708 + if (grsec_enable_time)
59709 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
59710 +#endif
59711 + return;
59712 +}
59713 +
59714 +EXPORT_SYMBOL(gr_log_timechange);
59715 diff -urNp linux-2.6.39/grsecurity/grsec_tpe.c linux-2.6.39/grsecurity/grsec_tpe.c
59716 --- linux-2.6.39/grsecurity/grsec_tpe.c 1969-12-31 19:00:00.000000000 -0500
59717 +++ linux-2.6.39/grsecurity/grsec_tpe.c 2011-05-22 19:41:42.000000000 -0400
59718 @@ -0,0 +1,39 @@
59719 +#include <linux/kernel.h>
59720 +#include <linux/sched.h>
59721 +#include <linux/file.h>
59722 +#include <linux/fs.h>
59723 +#include <linux/grinternal.h>
59724 +
59725 +extern int gr_acl_tpe_check(void);
59726 +
59727 +int
59728 +gr_tpe_allow(const struct file *file)
59729 +{
59730 +#ifdef CONFIG_GRKERNSEC
59731 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
59732 + const struct cred *cred = current_cred();
59733 +
59734 + if (cred->uid && ((grsec_enable_tpe &&
59735 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59736 + ((grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid)) ||
59737 + (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid)))
59738 +#else
59739 + in_group_p(grsec_tpe_gid)
59740 +#endif
59741 + ) || gr_acl_tpe_check()) &&
59742 + (inode->i_uid || (!inode->i_uid && ((inode->i_mode & S_IWGRP) ||
59743 + (inode->i_mode & S_IWOTH))))) {
59744 + gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt);
59745 + return 0;
59746 + }
59747 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
59748 + if (cred->uid && grsec_enable_tpe && grsec_enable_tpe_all &&
59749 + ((inode->i_uid && (inode->i_uid != cred->uid)) ||
59750 + (inode->i_mode & S_IWGRP) || (inode->i_mode & S_IWOTH))) {
59751 + gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt);
59752 + return 0;
59753 + }
59754 +#endif
59755 +#endif
59756 + return 1;
59757 +}
59758 diff -urNp linux-2.6.39/grsecurity/grsum.c linux-2.6.39/grsecurity/grsum.c
59759 --- linux-2.6.39/grsecurity/grsum.c 1969-12-31 19:00:00.000000000 -0500
59760 +++ linux-2.6.39/grsecurity/grsum.c 2011-05-22 19:41:42.000000000 -0400
59761 @@ -0,0 +1,61 @@
59762 +#include <linux/err.h>
59763 +#include <linux/kernel.h>
59764 +#include <linux/sched.h>
59765 +#include <linux/mm.h>
59766 +#include <linux/scatterlist.h>
59767 +#include <linux/crypto.h>
59768 +#include <linux/gracl.h>
59769 +
59770 +
59771 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
59772 +#error "crypto and sha256 must be built into the kernel"
59773 +#endif
59774 +
59775 +int
59776 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
59777 +{
59778 + char *p;
59779 + struct crypto_hash *tfm;
59780 + struct hash_desc desc;
59781 + struct scatterlist sg;
59782 + unsigned char temp_sum[GR_SHA_LEN];
59783 + volatile int retval = 0;
59784 + volatile int dummy = 0;
59785 + unsigned int i;
59786 +
59787 + sg_init_table(&sg, 1);
59788 +
59789 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
59790 + if (IS_ERR(tfm)) {
59791 + /* should never happen, since sha256 should be built in */
59792 + return 1;
59793 + }
59794 +
59795 + desc.tfm = tfm;
59796 + desc.flags = 0;
59797 +
59798 + crypto_hash_init(&desc);
59799 +
59800 + p = salt;
59801 + sg_set_buf(&sg, p, GR_SALT_LEN);
59802 + crypto_hash_update(&desc, &sg, sg.length);
59803 +
59804 + p = entry->pw;
59805 + sg_set_buf(&sg, p, strlen(p));
59806 +
59807 + crypto_hash_update(&desc, &sg, sg.length);
59808 +
59809 + crypto_hash_final(&desc, temp_sum);
59810 +
59811 + memset(entry->pw, 0, GR_PW_LEN);
59812 +
59813 + for (i = 0; i < GR_SHA_LEN; i++)
59814 + if (sum[i] != temp_sum[i])
59815 + retval = 1;
59816 + else
59817 + dummy = 1; // waste a cycle
59818 +
59819 + crypto_free_hash(tfm);
59820 +
59821 + return retval;
59822 +}
59823 diff -urNp linux-2.6.39/grsecurity/Kconfig linux-2.6.39/grsecurity/Kconfig
59824 --- linux-2.6.39/grsecurity/Kconfig 1969-12-31 19:00:00.000000000 -0500
59825 +++ linux-2.6.39/grsecurity/Kconfig 2011-05-22 19:41:42.000000000 -0400
59826 @@ -0,0 +1,1045 @@
59827 +#
59828 +# grecurity configuration
59829 +#
59830 +
59831 +menu "Grsecurity"
59832 +
59833 +config GRKERNSEC
59834 + bool "Grsecurity"
59835 + select CRYPTO
59836 + select CRYPTO_SHA256
59837 + help
59838 + If you say Y here, you will be able to configure many features
59839 + that will enhance the security of your system. It is highly
59840 + recommended that you say Y here and read through the help
59841 + for each option so that you fully understand the features and
59842 + can evaluate their usefulness for your machine.
59843 +
59844 +choice
59845 + prompt "Security Level"
59846 + depends on GRKERNSEC
59847 + default GRKERNSEC_CUSTOM
59848 +
59849 +config GRKERNSEC_LOW
59850 + bool "Low"
59851 + select GRKERNSEC_LINK
59852 + select GRKERNSEC_FIFO
59853 + select GRKERNSEC_EXECVE
59854 + select GRKERNSEC_RANDNET
59855 + select GRKERNSEC_DMESG
59856 + select GRKERNSEC_CHROOT
59857 + select GRKERNSEC_CHROOT_CHDIR
59858 +
59859 + help
59860 + If you choose this option, several of the grsecurity options will
59861 + be enabled that will give you greater protection against a number
59862 + of attacks, while assuring that none of your software will have any
59863 + conflicts with the additional security measures. If you run a lot
59864 + of unusual software, or you are having problems with the higher
59865 + security levels, you should say Y here. With this option, the
59866 + following features are enabled:
59867 +
59868 + - Linking restrictions
59869 + - FIFO restrictions
59870 + - Enforcing RLIMIT_NPROC on execve
59871 + - Restricted dmesg
59872 + - Enforced chdir("/") on chroot
59873 + - Runtime module disabling
59874 +
59875 +config GRKERNSEC_MEDIUM
59876 + bool "Medium"
59877 + select PAX
59878 + select PAX_EI_PAX
59879 + select PAX_PT_PAX_FLAGS
59880 + select PAX_HAVE_ACL_FLAGS
59881 + select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
59882 + select GRKERNSEC_CHROOT
59883 + select GRKERNSEC_CHROOT_SYSCTL
59884 + select GRKERNSEC_LINK
59885 + select GRKERNSEC_FIFO
59886 + select GRKERNSEC_EXECVE
59887 + select GRKERNSEC_DMESG
59888 + select GRKERNSEC_RANDNET
59889 + select GRKERNSEC_FORKFAIL
59890 + select GRKERNSEC_TIME
59891 + select GRKERNSEC_SIGNAL
59892 + select GRKERNSEC_CHROOT
59893 + select GRKERNSEC_CHROOT_UNIX
59894 + select GRKERNSEC_CHROOT_MOUNT
59895 + select GRKERNSEC_CHROOT_PIVOT
59896 + select GRKERNSEC_CHROOT_DOUBLE
59897 + select GRKERNSEC_CHROOT_CHDIR
59898 + select GRKERNSEC_CHROOT_MKNOD
59899 + select GRKERNSEC_PROC
59900 + select GRKERNSEC_PROC_USERGROUP
59901 + select PAX_RANDUSTACK
59902 + select PAX_ASLR
59903 + select PAX_RANDMMAP
59904 + select PAX_REFCOUNT if (X86 || SPARC64)
59905 + select PAX_USERCOPY if ((X86 || SPARC32 || SPARC64 || PPC) && (SLAB || SLUB || SLOB))
59906 +
59907 + help
59908 + If you say Y here, several features in addition to those included
59909 + in the low additional security level will be enabled. These
59910 + features provide even more security to your system, though in rare
59911 + cases they may be incompatible with very old or poorly written
59912 + software. If you enable this option, make sure that your auth
59913 + service (identd) is running as gid 1001. With this option,
59914 + the following features (in addition to those provided in the
59915 + low additional security level) will be enabled:
59916 +
59917 + - Failed fork logging
59918 + - Time change logging
59919 + - Signal logging
59920 + - Deny mounts in chroot
59921 + - Deny double chrooting
59922 + - Deny sysctl writes in chroot
59923 + - Deny mknod in chroot
59924 + - Deny access to abstract AF_UNIX sockets out of chroot
59925 + - Deny pivot_root in chroot
59926 + - Denied writes of /dev/kmem, /dev/mem, and /dev/port
59927 + - /proc restrictions with special GID set to 10 (usually wheel)
59928 + - Address Space Layout Randomization (ASLR)
59929 + - Prevent exploitation of most refcount overflows
59930 + - Bounds checking of copying between the kernel and userland
59931 +
59932 +config GRKERNSEC_HIGH
59933 + bool "High"
59934 + select GRKERNSEC_LINK
59935 + select GRKERNSEC_FIFO
59936 + select GRKERNSEC_EXECVE
59937 + select GRKERNSEC_DMESG
59938 + select GRKERNSEC_FORKFAIL
59939 + select GRKERNSEC_TIME
59940 + select GRKERNSEC_SIGNAL
59941 + select GRKERNSEC_CHROOT
59942 + select GRKERNSEC_CHROOT_SHMAT
59943 + select GRKERNSEC_CHROOT_UNIX
59944 + select GRKERNSEC_CHROOT_MOUNT
59945 + select GRKERNSEC_CHROOT_FCHDIR
59946 + select GRKERNSEC_CHROOT_PIVOT
59947 + select GRKERNSEC_CHROOT_DOUBLE
59948 + select GRKERNSEC_CHROOT_CHDIR
59949 + select GRKERNSEC_CHROOT_MKNOD
59950 + select GRKERNSEC_CHROOT_CAPS
59951 + select GRKERNSEC_CHROOT_SYSCTL
59952 + select GRKERNSEC_CHROOT_FINDTASK
59953 + select GRKERNSEC_SYSFS_RESTRICT
59954 + select GRKERNSEC_PROC
59955 + select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
59956 + select GRKERNSEC_HIDESYM
59957 + select GRKERNSEC_BRUTE
59958 + select GRKERNSEC_PROC_USERGROUP
59959 + select GRKERNSEC_KMEM
59960 + select GRKERNSEC_RESLOG
59961 + select GRKERNSEC_RANDNET
59962 + select GRKERNSEC_PROC_ADD
59963 + select GRKERNSEC_CHROOT_CHMOD
59964 + select GRKERNSEC_CHROOT_NICE
59965 + select GRKERNSEC_AUDIT_MOUNT
59966 + select GRKERNSEC_MODHARDEN if (MODULES)
59967 + select GRKERNSEC_HARDEN_PTRACE
59968 + select GRKERNSEC_VM86 if (X86_32)
59969 + select GRKERNSEC_KERN_LOCKOUT if (X86)
59970 + select PAX
59971 + select PAX_RANDUSTACK
59972 + select PAX_ASLR
59973 + select PAX_RANDMMAP
59974 + select PAX_NOEXEC
59975 + select PAX_MPROTECT
59976 + select PAX_EI_PAX
59977 + select PAX_PT_PAX_FLAGS
59978 + select PAX_HAVE_ACL_FLAGS
59979 + select PAX_KERNEXEC if ((PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN)
59980 + select PAX_MEMORY_UDEREF if (X86 && !XEN)
59981 + select PAX_RANDKSTACK if (X86_TSC && X86)
59982 + select PAX_SEGMEXEC if (X86_32)
59983 + select PAX_PAGEEXEC
59984 + select PAX_EMUPLT if (ALPHA || PARISC || SPARC32 || SPARC64)
59985 + select PAX_EMUTRAMP if (PARISC)
59986 + select PAX_EMUSIGRT if (PARISC)
59987 + select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
59988 + select PAX_ELFRELOCS if (PAX_ETEXECRELOCS || (IA64 || PPC || X86))
59989 + select PAX_REFCOUNT if (X86 || SPARC64)
59990 + select PAX_USERCOPY if ((X86 || PPC || SPARC32 || SPARC64) && (SLAB || SLUB || SLOB))
59991 + help
59992 + If you say Y here, many of the features of grsecurity will be
59993 + enabled, which will protect you against many kinds of attacks
59994 + against your system. The heightened security comes at a cost
59995 + of an increased chance of incompatibilities with rare software
59996 + on your machine. Since this security level enables PaX, you should
59997 + view <http://pax.grsecurity.net> and read about the PaX
59998 + project. While you are there, download chpax and run it on
59999 + binaries that cause problems with PaX. Also remember that
60000 + since the /proc restrictions are enabled, you must run your
60001 + identd as gid 1001. This security level enables the following
60002 + features in addition to those listed in the low and medium
60003 + security levels:
60004 +
60005 + - Additional /proc restrictions
60006 + - Chmod restrictions in chroot
60007 + - No signals, ptrace, or viewing of processes outside of chroot
60008 + - Capability restrictions in chroot
60009 + - Deny fchdir out of chroot
60010 + - Priority restrictions in chroot
60011 + - Segmentation-based implementation of PaX
60012 + - Mprotect restrictions
60013 + - Removal of addresses from /proc/<pid>/[smaps|maps|stat]
60014 + - Kernel stack randomization
60015 + - Mount/unmount/remount logging
60016 + - Kernel symbol hiding
60017 + - Prevention of memory exhaustion-based exploits
60018 + - Hardening of module auto-loading
60019 + - Ptrace restrictions
60020 + - Restricted vm86 mode
60021 + - Restricted sysfs/debugfs
60022 + - Active kernel exploit response
60023 +
60024 +config GRKERNSEC_CUSTOM
60025 + bool "Custom"
60026 + help
60027 + If you say Y here, you will be able to configure every grsecurity
60028 + option, which allows you to enable many more features that aren't
60029 + covered in the basic security levels. These additional features
60030 + include TPE, socket restrictions, and the sysctl system for
60031 + grsecurity. It is advised that you read through the help for
60032 + each option to determine its usefulness in your situation.
60033 +
60034 +endchoice
60035 +
60036 +menu "Address Space Protection"
60037 +depends on GRKERNSEC
60038 +
60039 +config GRKERNSEC_KMEM
60040 + bool "Deny writing to /dev/kmem, /dev/mem, and /dev/port"
60041 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
60042 + help
60043 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
60044 + be written to via mmap or otherwise to modify the running kernel.
60045 + /dev/port will also not be allowed to be opened. If you have module
60046 + support disabled, enabling this will close up four ways that are
60047 + currently used to insert malicious code into the running kernel.
60048 + Even with all these features enabled, we still highly recommend that
60049 + you use the RBAC system, as it is still possible for an attacker to
60050 + modify the running kernel through privileged I/O granted by ioperm/iopl.
60051 + If you are not using XFree86, you may be able to stop this additional
60052 + case by enabling the 'Disable privileged I/O' option. Though nothing
60053 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
60054 + but only to video memory, which is the only writing we allow in this
60055 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
60056 + not be allowed to mprotect it with PROT_WRITE later.
60057 + It is highly recommended that you say Y here if you meet all the
60058 + conditions above.
60059 +
60060 +config GRKERNSEC_VM86
60061 + bool "Restrict VM86 mode"
60062 + depends on X86_32
60063 +
60064 + help
60065 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
60066 + make use of a special execution mode on 32bit x86 processors called
60067 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
60068 + video cards and will still work with this option enabled. The purpose
60069 + of the option is to prevent exploitation of emulation errors in
60070 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
60071 + Nearly all users should be able to enable this option.
60072 +
60073 +config GRKERNSEC_IO
60074 + bool "Disable privileged I/O"
60075 + depends on X86
60076 + select RTC_CLASS
60077 + select RTC_INTF_DEV
60078 + select RTC_DRV_CMOS
60079 +
60080 + help
60081 + If you say Y here, all ioperm and iopl calls will return an error.
60082 + Ioperm and iopl can be used to modify the running kernel.
60083 + Unfortunately, some programs need this access to operate properly,
60084 + the most notable of which are XFree86 and hwclock. hwclock can be
60085 + remedied by having RTC support in the kernel, so real-time
60086 + clock support is enabled if this option is enabled, to ensure
60087 + that hwclock operates correctly. XFree86 still will not
60088 + operate correctly with this option enabled, so DO NOT CHOOSE Y
60089 + IF YOU USE XFree86. If you use XFree86 and you still want to
60090 + protect your kernel against modification, use the RBAC system.
60091 +
60092 +config GRKERNSEC_PROC_MEMMAP
60093 + bool "Remove addresses from /proc/<pid>/[smaps|maps|stat]"
60094 + default y if (PAX_NOEXEC || PAX_ASLR)
60095 + depends on PAX_NOEXEC || PAX_ASLR
60096 + help
60097 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
60098 + give no information about the addresses of its mappings if
60099 + PaX features that rely on random addresses are enabled on the task.
60100 + If you use PaX it is greatly recommended that you say Y here as it
60101 + closes up a hole that makes the full ASLR useless for suid
60102 + binaries.
60103 +
60104 +config GRKERNSEC_BRUTE
60105 + bool "Deter exploit bruteforcing"
60106 + help
60107 + If you say Y here, attempts to bruteforce exploits against forking
60108 + daemons such as apache or sshd, as well as against suid/sgid binaries
60109 + will be deterred. When a child of a forking daemon is killed by PaX
60110 + or crashes due to an illegal instruction or other suspicious signal,
60111 + the parent process will be delayed 30 seconds upon every subsequent
60112 + fork until the administrator is able to assess the situation and
60113 + restart the daemon.
60114 + In the suid/sgid case, the attempt is logged, the user has all their
60115 + processes terminated, and they are prevented from executing any further
60116 + processes for 15 minutes.
60117 + It is recommended that you also enable signal logging in the auditing
60118 + section so that logs are generated when a process triggers a suspicious
60119 + signal.
60120 +
60121 +config GRKERNSEC_MODHARDEN
60122 + bool "Harden module auto-loading"
60123 + depends on MODULES
60124 + help
60125 + If you say Y here, module auto-loading in response to use of some
60126 + feature implemented by an unloaded module will be restricted to
60127 + root users. Enabling this option helps defend against attacks
60128 + by unprivileged users who abuse the auto-loading behavior to
60129 + cause a vulnerable module to load that is then exploited.
60130 +
60131 + If this option prevents a legitimate use of auto-loading for a
60132 + non-root user, the administrator can execute modprobe manually
60133 + with the exact name of the module mentioned in the alert log.
60134 + Alternatively, the administrator can add the module to the list
60135 + of modules loaded at boot by modifying init scripts.
60136 +
60137 + Modification of init scripts will most likely be needed on
60138 + Ubuntu servers with encrypted home directory support enabled,
60139 + as the first non-root user logging in will cause the ecb(aes),
60140 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
60141 +
60142 +config GRKERNSEC_HIDESYM
60143 + bool "Hide kernel symbols"
60144 + help
60145 + If you say Y here, getting information on loaded modules, and
60146 + displaying all kernel symbols through a syscall will be restricted
60147 + to users with CAP_SYS_MODULE. For software compatibility reasons,
60148 + /proc/kallsyms will be restricted to the root user. The RBAC
60149 + system can hide that entry even from root.
60150 +
60151 + This option also prevents leaking of kernel addresses through
60152 + several /proc entries.
60153 +
60154 + Note that this option is only effective provided the following
60155 + conditions are met:
60156 + 1) The kernel using grsecurity is not precompiled by some distribution
60157 + 2) You have also enabled GRKERNSEC_DMESG
60158 + 3) You are using the RBAC system and hiding other files such as your
60159 + kernel image and System.map. Alternatively, enabling this option
60160 + causes the permissions on /boot, /lib/modules, and the kernel
60161 + source directory to change at compile time to prevent
60162 + reading by non-root users.
60163 + If the above conditions are met, this option will aid in providing a
60164 + useful protection against local kernel exploitation of overflows
60165 + and arbitrary read/write vulnerabilities.
60166 +
60167 +config GRKERNSEC_KERN_LOCKOUT
60168 + bool "Active kernel exploit response"
60169 + depends on X86
60170 + help
60171 + If you say Y here, when a PaX alert is triggered due to suspicious
60172 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
60173 + or an OOPs occurs due to bad memory accesses, instead of just
60174 + terminating the offending process (and potentially allowing
60175 + a subsequent exploit from the same user), we will take one of two
60176 + actions:
60177 + If the user was root, we will panic the system
60178 + If the user was non-root, we will log the attempt, terminate
60179 + all processes owned by the user, then prevent them from creating
60180 + any new processes until the system is restarted
60181 + This deters repeated kernel exploitation/bruteforcing attempts
60182 + and is useful for later forensics.
60183 +
60184 +endmenu
60185 +menu "Role Based Access Control Options"
60186 +depends on GRKERNSEC
60187 +
60188 +config GRKERNSEC_RBAC_DEBUG
60189 + bool
60190 +
60191 +config GRKERNSEC_NO_RBAC
60192 + bool "Disable RBAC system"
60193 + help
60194 + If you say Y here, the /dev/grsec device will be removed from the kernel,
60195 + preventing the RBAC system from being enabled. You should only say Y
60196 + here if you have no intention of using the RBAC system, so as to prevent
60197 + an attacker with root access from misusing the RBAC system to hide files
60198 + and processes when loadable module support and /dev/[k]mem have been
60199 + locked down.
60200 +
60201 +config GRKERNSEC_ACL_HIDEKERN
60202 + bool "Hide kernel processes"
60203 + help
60204 + If you say Y here, all kernel threads will be hidden to all
60205 + processes but those whose subject has the "view hidden processes"
60206 + flag.
60207 +
60208 +config GRKERNSEC_ACL_MAXTRIES
60209 + int "Maximum tries before password lockout"
60210 + default 3
60211 + help
60212 + This option enforces the maximum number of times a user can attempt
60213 + to authorize themselves with the grsecurity RBAC system before being
60214 + denied the ability to attempt authorization again for a specified time.
60215 + The lower the number, the harder it will be to brute-force a password.
60216 +
60217 +config GRKERNSEC_ACL_TIMEOUT
60218 + int "Time to wait after max password tries, in seconds"
60219 + default 30
60220 + help
60221 + This option specifies the time the user must wait after attempting to
60222 + authorize to the RBAC system with the maximum number of invalid
60223 + passwords. The higher the number, the harder it will be to brute-force
60224 + a password.
60225 +
60226 +endmenu
60227 +menu "Filesystem Protections"
60228 +depends on GRKERNSEC
60229 +
60230 +config GRKERNSEC_PROC
60231 + bool "Proc restrictions"
60232 + help
60233 + If you say Y here, the permissions of the /proc filesystem
60234 + will be altered to enhance system security and privacy. You MUST
60235 + choose either a user only restriction or a user and group restriction.
60236 + Depending upon the option you choose, you can either restrict users to
60237 + see only the processes they themselves run, or choose a group that can
60238 + view all processes and files normally restricted to root if you choose
60239 + the "restrict to user only" option. NOTE: If you're running identd as
60240 + a non-root user, you will have to run it as the group you specify here.
60241 +
60242 +config GRKERNSEC_PROC_USER
60243 + bool "Restrict /proc to user only"
60244 + depends on GRKERNSEC_PROC
60245 + help
60246 + If you say Y here, non-root users will only be able to view their own
60247 + processes, and restricts them from viewing network-related information,
60248 + and viewing kernel symbol and module information.
60249 +
60250 +config GRKERNSEC_PROC_USERGROUP
60251 + bool "Allow special group"
60252 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
60253 + help
60254 + If you say Y here, you will be able to select a group that will be
60255 + able to view all processes and network-related information. If you've
60256 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
60257 + remain hidden. This option is useful if you want to run identd as
60258 + a non-root user.
60259 +
60260 +config GRKERNSEC_PROC_GID
60261 + int "GID for special group"
60262 + depends on GRKERNSEC_PROC_USERGROUP
60263 + default 1001
60264 +
60265 +config GRKERNSEC_PROC_ADD
60266 + bool "Additional restrictions"
60267 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
60268 + help
60269 + If you say Y here, additional restrictions will be placed on
60270 + /proc that keep normal users from viewing device information and
60271 + slabinfo information that could be useful for exploits.
60272 +
60273 +config GRKERNSEC_LINK
60274 + bool "Linking restrictions"
60275 + help
60276 + If you say Y here, /tmp race exploits will be prevented, since users
60277 + will no longer be able to follow symlinks owned by other users in
60278 + world-writable +t directories (e.g. /tmp), unless the owner of the
60279 + symlink is the owner of the directory. users will also not be
60280 + able to hardlink to files they do not own. If the sysctl option is
60281 + enabled, a sysctl option with name "linking_restrictions" is created.
60282 +
60283 +config GRKERNSEC_FIFO
60284 + bool "FIFO restrictions"
60285 + help
60286 + If you say Y here, users will not be able to write to FIFOs they don't
60287 + own in world-writable +t directories (e.g. /tmp), unless the owner of
60288 + the FIFO is the same owner of the directory it's held in. If the sysctl
60289 + option is enabled, a sysctl option with name "fifo_restrictions" is
60290 + created.
60291 +
60292 +config GRKERNSEC_SYSFS_RESTRICT
60293 + bool "Sysfs/debugfs restriction"
60294 + depends on SYSFS
60295 + help
60296 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
60297 + any filesystem normally mounted under it (e.g. debugfs) will only
60298 + be accessible by root. These filesystems generally provide access
60299 + to hardware and debug information that isn't appropriate for unprivileged
60300 + users of the system. Sysfs and debugfs have also become a large source
60301 + of new vulnerabilities, ranging from infoleaks to local compromise.
60302 + There has been very little oversight with an eye toward security involved
60303 + in adding new exporters of information to these filesystems, so their
60304 + use is discouraged.
60305 + This option is equivalent to a chmod 0700 of the mount paths.
60306 +
60307 +config GRKERNSEC_ROFS
60308 + bool "Runtime read-only mount protection"
60309 + help
60310 + If you say Y here, a sysctl option with name "romount_protect" will
60311 + be created. By setting this option to 1 at runtime, filesystems
60312 + will be protected in the following ways:
60313 + * No new writable mounts will be allowed
60314 + * Existing read-only mounts won't be able to be remounted read/write
60315 + * Write operations will be denied on all block devices
60316 + This option acts independently of grsec_lock: once it is set to 1,
60317 + it cannot be turned off. Therefore, please be mindful of the resulting
60318 + behavior if this option is enabled in an init script on a read-only
60319 + filesystem. This feature is mainly intended for secure embedded systems.
60320 +
60321 +config GRKERNSEC_CHROOT
60322 + bool "Chroot jail restrictions"
60323 + help
60324 + If you say Y here, you will be able to choose several options that will
60325 + make breaking out of a chrooted jail much more difficult. If you
60326 + encounter no software incompatibilities with the following options, it
60327 + is recommended that you enable each one.
60328 +
60329 +config GRKERNSEC_CHROOT_MOUNT
60330 + bool "Deny mounts"
60331 + depends on GRKERNSEC_CHROOT
60332 + help
60333 + If you say Y here, processes inside a chroot will not be able to
60334 + mount or remount filesystems. If the sysctl option is enabled, a
60335 + sysctl option with name "chroot_deny_mount" is created.
60336 +
60337 +config GRKERNSEC_CHROOT_DOUBLE
60338 + bool "Deny double-chroots"
60339 + depends on GRKERNSEC_CHROOT
60340 + help
60341 + If you say Y here, processes inside a chroot will not be able to chroot
60342 + again outside the chroot. This is a widely used method of breaking
60343 + out of a chroot jail and should not be allowed. If the sysctl
60344 + option is enabled, a sysctl option with name
60345 + "chroot_deny_chroot" is created.
60346 +
60347 +config GRKERNSEC_CHROOT_PIVOT
60348 + bool "Deny pivot_root in chroot"
60349 + depends on GRKERNSEC_CHROOT
60350 + help
60351 + If you say Y here, processes inside a chroot will not be able to use
60352 + a function called pivot_root() that was introduced in Linux 2.3.41. It
60353 + works similar to chroot in that it changes the root filesystem. This
60354 + function could be misused in a chrooted process to attempt to break out
60355 + of the chroot, and therefore should not be allowed. If the sysctl
60356 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
60357 + created.
60358 +
60359 +config GRKERNSEC_CHROOT_CHDIR
60360 + bool "Enforce chdir(\"/\") on all chroots"
60361 + depends on GRKERNSEC_CHROOT
60362 + help
60363 + If you say Y here, the current working directory of all newly-chrooted
60364 + applications will be set to the the root directory of the chroot.
60365 + The man page on chroot(2) states:
60366 + Note that this call does not change the current working
60367 + directory, so that `.' can be outside the tree rooted at
60368 + `/'. In particular, the super-user can escape from a
60369 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
60370 +
60371 + It is recommended that you say Y here, since it's not known to break
60372 + any software. If the sysctl option is enabled, a sysctl option with
60373 + name "chroot_enforce_chdir" is created.
60374 +
60375 +config GRKERNSEC_CHROOT_CHMOD
60376 + bool "Deny (f)chmod +s"
60377 + depends on GRKERNSEC_CHROOT
60378 + help
60379 + If you say Y here, processes inside a chroot will not be able to chmod
60380 + or fchmod files to make them have suid or sgid bits. This protects
60381 + against another published method of breaking a chroot. If the sysctl
60382 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
60383 + created.
60384 +
60385 +config GRKERNSEC_CHROOT_FCHDIR
60386 + bool "Deny fchdir out of chroot"
60387 + depends on GRKERNSEC_CHROOT
60388 + help
60389 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
60390 + to a file descriptor of the chrooting process that points to a directory
60391 + outside the filesystem will be stopped. If the sysctl option
60392 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
60393 +
60394 +config GRKERNSEC_CHROOT_MKNOD
60395 + bool "Deny mknod"
60396 + depends on GRKERNSEC_CHROOT
60397 + help
60398 + If you say Y here, processes inside a chroot will not be allowed to
60399 + mknod. The problem with using mknod inside a chroot is that it
60400 + would allow an attacker to create a device entry that is the same
60401 + as one on the physical root of your system, which could range from
60402 + anything from the console device to a device for your harddrive (which
60403 + they could then use to wipe the drive or steal data). It is recommended
60404 + that you say Y here, unless you run into software incompatibilities.
60405 + If the sysctl option is enabled, a sysctl option with name
60406 + "chroot_deny_mknod" is created.
60407 +
60408 +config GRKERNSEC_CHROOT_SHMAT
60409 + bool "Deny shmat() out of chroot"
60410 + depends on GRKERNSEC_CHROOT
60411 + help
60412 + If you say Y here, processes inside a chroot will not be able to attach
60413 + to shared memory segments that were created outside of the chroot jail.
60414 + It is recommended that you say Y here. If the sysctl option is enabled,
60415 + a sysctl option with name "chroot_deny_shmat" is created.
60416 +
60417 +config GRKERNSEC_CHROOT_UNIX
60418 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
60419 + depends on GRKERNSEC_CHROOT
60420 + help
60421 + If you say Y here, processes inside a chroot will not be able to
60422 + connect to abstract (meaning not belonging to a filesystem) Unix
60423 + domain sockets that were bound outside of a chroot. It is recommended
60424 + that you say Y here. If the sysctl option is enabled, a sysctl option
60425 + with name "chroot_deny_unix" is created.
60426 +
60427 +config GRKERNSEC_CHROOT_FINDTASK
60428 + bool "Protect outside processes"
60429 + depends on GRKERNSEC_CHROOT
60430 + help
60431 + If you say Y here, processes inside a chroot will not be able to
60432 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
60433 + getsid, or view any process outside of the chroot. If the sysctl
60434 + option is enabled, a sysctl option with name "chroot_findtask" is
60435 + created.
60436 +
60437 +config GRKERNSEC_CHROOT_NICE
60438 + bool "Restrict priority changes"
60439 + depends on GRKERNSEC_CHROOT
60440 + help
60441 + If you say Y here, processes inside a chroot will not be able to raise
60442 + the priority of processes in the chroot, or alter the priority of
60443 + processes outside the chroot. This provides more security than simply
60444 + removing CAP_SYS_NICE from the process' capability set. If the
60445 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
60446 + is created.
60447 +
60448 +config GRKERNSEC_CHROOT_SYSCTL
60449 + bool "Deny sysctl writes"
60450 + depends on GRKERNSEC_CHROOT
60451 + help
60452 + If you say Y here, an attacker in a chroot will not be able to
60453 + write to sysctl entries, either by sysctl(2) or through a /proc
60454 + interface. It is strongly recommended that you say Y here. If the
60455 + sysctl option is enabled, a sysctl option with name
60456 + "chroot_deny_sysctl" is created.
60457 +
60458 +config GRKERNSEC_CHROOT_CAPS
60459 + bool "Capability restrictions"
60460 + depends on GRKERNSEC_CHROOT
60461 + help
60462 + If you say Y here, the capabilities on all root processes within a
60463 + chroot jail will be lowered to stop module insertion, raw i/o,
60464 + system and net admin tasks, rebooting the system, modifying immutable
60465 + files, modifying IPC owned by another, and changing the system time.
60466 + This is left an option because it can break some apps. Disable this
60467 + if your chrooted apps are having problems performing those kinds of
60468 + tasks. If the sysctl option is enabled, a sysctl option with
60469 + name "chroot_caps" is created.
60470 +
60471 +endmenu
60472 +menu "Kernel Auditing"
60473 +depends on GRKERNSEC
60474 +
60475 +config GRKERNSEC_AUDIT_GROUP
60476 + bool "Single group for auditing"
60477 + help
60478 + If you say Y here, the exec, chdir, and (un)mount logging features
60479 + will only operate on a group you specify. This option is recommended
60480 + if you only want to watch certain users instead of having a large
60481 + amount of logs from the entire system. If the sysctl option is enabled,
60482 + a sysctl option with name "audit_group" is created.
60483 +
60484 +config GRKERNSEC_AUDIT_GID
60485 + int "GID for auditing"
60486 + depends on GRKERNSEC_AUDIT_GROUP
60487 + default 1007
60488 +
60489 +config GRKERNSEC_EXECLOG
60490 + bool "Exec logging"
60491 + help
60492 + If you say Y here, all execve() calls will be logged (since the
60493 + other exec*() calls are frontends to execve(), all execution
60494 + will be logged). Useful for shell-servers that like to keep track
60495 + of their users. If the sysctl option is enabled, a sysctl option with
60496 + name "exec_logging" is created.
60497 + WARNING: This option when enabled will produce a LOT of logs, especially
60498 + on an active system.
60499 +
60500 +config GRKERNSEC_RESLOG
60501 + bool "Resource logging"
60502 + help
60503 + If you say Y here, all attempts to overstep resource limits will
60504 + be logged with the resource name, the requested size, and the current
60505 + limit. It is highly recommended that you say Y here. If the sysctl
60506 + option is enabled, a sysctl option with name "resource_logging" is
60507 + created. If the RBAC system is enabled, the sysctl value is ignored.
60508 +
60509 +config GRKERNSEC_CHROOT_EXECLOG
60510 + bool "Log execs within chroot"
60511 + help
60512 + If you say Y here, all executions inside a chroot jail will be logged
60513 + to syslog. This can cause a large amount of logs if certain
60514 + applications (eg. djb's daemontools) are installed on the system, and
60515 + is therefore left as an option. If the sysctl option is enabled, a
60516 + sysctl option with name "chroot_execlog" is created.
60517 +
60518 +config GRKERNSEC_AUDIT_PTRACE
60519 + bool "Ptrace logging"
60520 + help
60521 + If you say Y here, all attempts to attach to a process via ptrace
60522 + will be logged. If the sysctl option is enabled, a sysctl option
60523 + with name "audit_ptrace" is created.
60524 +
60525 +config GRKERNSEC_AUDIT_CHDIR
60526 + bool "Chdir logging"
60527 + help
60528 + If you say Y here, all chdir() calls will be logged. If the sysctl
60529 + option is enabled, a sysctl option with name "audit_chdir" is created.
60530 +
60531 +config GRKERNSEC_AUDIT_MOUNT
60532 + bool "(Un)Mount logging"
60533 + help
60534 + If you say Y here, all mounts and unmounts will be logged. If the
60535 + sysctl option is enabled, a sysctl option with name "audit_mount" is
60536 + created.
60537 +
60538 +config GRKERNSEC_SIGNAL
60539 + bool "Signal logging"
60540 + help
60541 + If you say Y here, certain important signals will be logged, such as
60542 + SIGSEGV, which will as a result inform you of when a error in a program
60543 + occurred, which in some cases could mean a possible exploit attempt.
60544 + If the sysctl option is enabled, a sysctl option with name
60545 + "signal_logging" is created.
60546 +
60547 +config GRKERNSEC_FORKFAIL
60548 + bool "Fork failure logging"
60549 + help
60550 + If you say Y here, all failed fork() attempts will be logged.
60551 + This could suggest a fork bomb, or someone attempting to overstep
60552 + their process limit. If the sysctl option is enabled, a sysctl option
60553 + with name "forkfail_logging" is created.
60554 +
60555 +config GRKERNSEC_TIME
60556 + bool "Time change logging"
60557 + help
60558 + If you say Y here, any changes of the system clock will be logged.
60559 + If the sysctl option is enabled, a sysctl option with name
60560 + "timechange_logging" is created.
60561 +
60562 +config GRKERNSEC_PROC_IPADDR
60563 + bool "/proc/<pid>/ipaddr support"
60564 + help
60565 + If you say Y here, a new entry will be added to each /proc/<pid>
60566 + directory that contains the IP address of the person using the task.
60567 + The IP is carried across local TCP and AF_UNIX stream sockets.
60568 + This information can be useful for IDS/IPSes to perform remote response
60569 + to a local attack. The entry is readable by only the owner of the
60570 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
60571 + the RBAC system), and thus does not create privacy concerns.
60572 +
60573 +config GRKERNSEC_RWXMAP_LOG
60574 + bool 'Denied RWX mmap/mprotect logging'
60575 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
60576 + help
60577 + If you say Y here, calls to mmap() and mprotect() with explicit
60578 + usage of PROT_WRITE and PROT_EXEC together will be logged when
60579 + denied by the PAX_MPROTECT feature. If the sysctl option is
60580 + enabled, a sysctl option with name "rwxmap_logging" is created.
60581 +
60582 +config GRKERNSEC_AUDIT_TEXTREL
60583 + bool 'ELF text relocations logging (READ HELP)'
60584 + depends on PAX_MPROTECT
60585 + help
60586 + If you say Y here, text relocations will be logged with the filename
60587 + of the offending library or binary. The purpose of the feature is
60588 + to help Linux distribution developers get rid of libraries and
60589 + binaries that need text relocations which hinder the future progress
60590 + of PaX. Only Linux distribution developers should say Y here, and
60591 + never on a production machine, as this option creates an information
60592 + leak that could aid an attacker in defeating the randomization of
60593 + a single memory region. If the sysctl option is enabled, a sysctl
60594 + option with name "audit_textrel" is created.
60595 +
60596 +endmenu
60597 +
60598 +menu "Executable Protections"
60599 +depends on GRKERNSEC
60600 +
60601 +config GRKERNSEC_EXECVE
60602 + bool "Enforce RLIMIT_NPROC on execs"
60603 + help
60604 + If you say Y here, users with a resource limit on processes will
60605 + have the value checked during execve() calls. The current system
60606 + only checks the system limit during fork() calls. If the sysctl option
60607 + is enabled, a sysctl option with name "execve_limiting" is created.
60608 +
60609 +config GRKERNSEC_DMESG
60610 + bool "Dmesg(8) restriction"
60611 + help
60612 + If you say Y here, non-root users will not be able to use dmesg(8)
60613 + to view up to the last 4kb of messages in the kernel's log buffer.
60614 + The kernel's log buffer often contains kernel addresses and other
60615 + identifying information useful to an attacker in fingerprinting a
60616 + system for a targeted exploit.
60617 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
60618 + created.
60619 +
60620 +config GRKERNSEC_HARDEN_PTRACE
60621 + bool "Deter ptrace-based process snooping"
60622 + help
60623 + If you say Y here, TTY sniffers and other malicious monitoring
60624 + programs implemented through ptrace will be defeated. If you
60625 + have been using the RBAC system, this option has already been
60626 + enabled for several years for all users, with the ability to make
60627 + fine-grained exceptions.
60628 +
60629 + This option only affects the ability of non-root users to ptrace
60630 + processes that are not a descendent of the ptracing process.
60631 + This means that strace ./binary and gdb ./binary will still work,
60632 + but attaching to arbitrary processes will not. If the sysctl
60633 + option is enabled, a sysctl option with name "harden_ptrace" is
60634 + created.
60635 +
60636 +config GRKERNSEC_TPE
60637 + bool "Trusted Path Execution (TPE)"
60638 + help
60639 + If you say Y here, you will be able to choose a gid to add to the
60640 + supplementary groups of users you want to mark as "untrusted."
60641 + These users will not be able to execute any files that are not in
60642 + root-owned directories writable only by root. If the sysctl option
60643 + is enabled, a sysctl option with name "tpe" is created.
60644 +
60645 +config GRKERNSEC_TPE_ALL
60646 + bool "Partially restrict all non-root users"
60647 + depends on GRKERNSEC_TPE
60648 + help
60649 + If you say Y here, all non-root users will be covered under
60650 + a weaker TPE restriction. This is separate from, and in addition to,
60651 + the main TPE options that you have selected elsewhere. Thus, if a
60652 + "trusted" GID is chosen, this restriction applies to even that GID.
60653 + Under this restriction, all non-root users will only be allowed to
60654 + execute files in directories they own that are not group or
60655 + world-writable, or in directories owned by root and writable only by
60656 + root. If the sysctl option is enabled, a sysctl option with name
60657 + "tpe_restrict_all" is created.
60658 +
60659 +config GRKERNSEC_TPE_INVERT
60660 + bool "Invert GID option"
60661 + depends on GRKERNSEC_TPE
60662 + help
60663 + If you say Y here, the group you specify in the TPE configuration will
60664 + decide what group TPE restrictions will be *disabled* for. This
60665 + option is useful if you want TPE restrictions to be applied to most
60666 + users on the system. If the sysctl option is enabled, a sysctl option
60667 + with name "tpe_invert" is created. Unlike other sysctl options, this
60668 + entry will default to on for backward-compatibility.
60669 +
60670 +config GRKERNSEC_TPE_GID
60671 + int "GID for untrusted users"
60672 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
60673 + default 1005
60674 + help
60675 + Setting this GID determines what group TPE restrictions will be
60676 + *enabled* for. If the sysctl option is enabled, a sysctl option
60677 + with name "tpe_gid" is created.
60678 +
60679 +config GRKERNSEC_TPE_GID
60680 + int "GID for trusted users"
60681 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
60682 + default 1005
60683 + help
60684 + Setting this GID determines what group TPE restrictions will be
60685 + *disabled* for. If the sysctl option is enabled, a sysctl option
60686 + with name "tpe_gid" is created.
60687 +
60688 +endmenu
60689 +menu "Network Protections"
60690 +depends on GRKERNSEC
60691 +
60692 +config GRKERNSEC_RANDNET
60693 + bool "Larger entropy pools"
60694 + help
60695 + If you say Y here, the entropy pools used for many features of Linux
60696 + and grsecurity will be doubled in size. Since several grsecurity
60697 + features use additional randomness, it is recommended that you say Y
60698 + here. Saying Y here has a similar effect as modifying
60699 + /proc/sys/kernel/random/poolsize.
60700 +
60701 +config GRKERNSEC_BLACKHOLE
60702 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
60703 + help
60704 + If you say Y here, neither TCP resets nor ICMP
60705 + destination-unreachable packets will be sent in response to packets
60706 + sent to ports for which no associated listening process exists.
60707 + This feature supports both IPV4 and IPV6 and exempts the
60708 + loopback interface from blackholing. Enabling this feature
60709 + makes a host more resilient to DoS attacks and reduces network
60710 + visibility against scanners.
60711 +
60712 + The blackhole feature as-implemented is equivalent to the FreeBSD
60713 + blackhole feature, as it prevents RST responses to all packets, not
60714 + just SYNs. Under most application behavior this causes no
60715 + problems, but applications (like haproxy) may not close certain
60716 + connections in a way that cleanly terminates them on the remote
60717 + end, leaving the remote host in LAST_ACK state. Because of this
60718 + side-effect and to prevent intentional LAST_ACK DoSes, this
60719 + feature also adds automatic mitigation against such attacks.
60720 + The mitigation drastically reduces the amount of time a socket
60721 + can spend in LAST_ACK state. If you're using haproxy and not
60722 + all servers it connects to have this option enabled, consider
60723 + disabling this feature on the haproxy host.
60724 +
60725 + If the sysctl option is enabled, two sysctl options with names
60726 + "ip_blackhole" and "lastack_retries" will be created.
60727 + While "ip_blackhole" takes the standard zero/non-zero on/off
60728 + toggle, "lastack_retries" uses the same kinds of values as
60729 + "tcp_retries1" and "tcp_retries2". The default value of 4
60730 + prevents a socket from lasting more than 45 seconds in LAST_ACK
60731 + state.
60732 +
60733 +config GRKERNSEC_SOCKET
60734 + bool "Socket restrictions"
60735 + help
60736 + If you say Y here, you will be able to choose from several options.
60737 + If you assign a GID on your system and add it to the supplementary
60738 + groups of users you want to restrict socket access to, this patch
60739 + will perform up to three things, based on the option(s) you choose.
60740 +
60741 +config GRKERNSEC_SOCKET_ALL
60742 + bool "Deny any sockets to group"
60743 + depends on GRKERNSEC_SOCKET
60744 + help
60745 + If you say Y here, you will be able to choose a GID of whose users will
60746 + be unable to connect to other hosts from your machine or run server
60747 + applications from your machine. If the sysctl option is enabled, a
60748 + sysctl option with name "socket_all" is created.
60749 +
60750 +config GRKERNSEC_SOCKET_ALL_GID
60751 + int "GID to deny all sockets for"
60752 + depends on GRKERNSEC_SOCKET_ALL
60753 + default 1004
60754 + help
60755 + Here you can choose the GID to disable socket access for. Remember to
60756 + add the users you want socket access disabled for to the GID
60757 + specified here. If the sysctl option is enabled, a sysctl option
60758 + with name "socket_all_gid" is created.
60759 +
60760 +config GRKERNSEC_SOCKET_CLIENT
60761 + bool "Deny client sockets to group"
60762 + depends on GRKERNSEC_SOCKET
60763 + help
60764 + If you say Y here, you will be able to choose a GID of whose users will
60765 + be unable to connect to other hosts from your machine, but will be
60766 + able to run servers. If this option is enabled, all users in the group
60767 + you specify will have to use passive mode when initiating ftp transfers
60768 + from the shell on your machine. If the sysctl option is enabled, a
60769 + sysctl option with name "socket_client" is created.
60770 +
60771 +config GRKERNSEC_SOCKET_CLIENT_GID
60772 + int "GID to deny client sockets for"
60773 + depends on GRKERNSEC_SOCKET_CLIENT
60774 + default 1003
60775 + help
60776 + Here you can choose the GID to disable client socket access for.
60777 + Remember to add the users you want client socket access disabled for to
60778 + the GID specified here. If the sysctl option is enabled, a sysctl
60779 + option with name "socket_client_gid" is created.
60780 +
60781 +config GRKERNSEC_SOCKET_SERVER
60782 + bool "Deny server sockets to group"
60783 + depends on GRKERNSEC_SOCKET
60784 + help
60785 + If you say Y here, you will be able to choose a GID of whose users will
60786 + be unable to run server applications from your machine. If the sysctl
60787 + option is enabled, a sysctl option with name "socket_server" is created.
60788 +
60789 +config GRKERNSEC_SOCKET_SERVER_GID
60790 + int "GID to deny server sockets for"
60791 + depends on GRKERNSEC_SOCKET_SERVER
60792 + default 1002
60793 + help
60794 + Here you can choose the GID to disable server socket access for.
60795 + Remember to add the users you want server socket access disabled for to
60796 + the GID specified here. If the sysctl option is enabled, a sysctl
60797 + option with name "socket_server_gid" is created.
60798 +
60799 +endmenu
60800 +menu "Sysctl support"
60801 +depends on GRKERNSEC && SYSCTL
60802 +
60803 +config GRKERNSEC_SYSCTL
60804 + bool "Sysctl support"
60805 + help
60806 + If you say Y here, you will be able to change the options that
60807 + grsecurity runs with at bootup, without having to recompile your
60808 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
60809 + to enable (1) or disable (0) various features. All the sysctl entries
60810 + are mutable until the "grsec_lock" entry is set to a non-zero value.
60811 + All features enabled in the kernel configuration are disabled at boot
60812 + if you do not say Y to the "Turn on features by default" option.
60813 + All options should be set at startup, and the grsec_lock entry should
60814 + be set to a non-zero value after all the options are set.
60815 + *THIS IS EXTREMELY IMPORTANT*
60816 +
60817 +config GRKERNSEC_SYSCTL_DISTRO
60818 + bool "Extra sysctl support for distro makers (READ HELP)"
60819 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
60820 + help
60821 + If you say Y here, additional sysctl options will be created
60822 + for features that affect processes running as root. Therefore,
60823 + it is critical when using this option that the grsec_lock entry be
60824 + enabled after boot. Only distros with prebuilt kernel packages
60825 + with this option enabled that can ensure grsec_lock is enabled
60826 + after boot should use this option.
60827 + *Failure to set grsec_lock after boot makes all grsec features
60828 + this option covers useless*
60829 +
60830 + Currently this option creates the following sysctl entries:
60831 + "Disable Privileged I/O": "disable_priv_io"
60832 +
60833 +config GRKERNSEC_SYSCTL_ON
60834 + bool "Turn on features by default"
60835 + depends on GRKERNSEC_SYSCTL
60836 + help
60837 + If you say Y here, instead of having all features enabled in the
60838 + kernel configuration disabled at boot time, the features will be
60839 + enabled at boot time. It is recommended you say Y here unless
60840 + there is some reason you would want all sysctl-tunable features to
60841 + be disabled by default. As mentioned elsewhere, it is important
60842 + to enable the grsec_lock entry once you have finished modifying
60843 + the sysctl entries.
60844 +
60845 +endmenu
60846 +menu "Logging Options"
60847 +depends on GRKERNSEC
60848 +
60849 +config GRKERNSEC_FLOODTIME
60850 + int "Seconds in between log messages (minimum)"
60851 + default 10
60852 + help
60853 + This option allows you to enforce the number of seconds between
60854 + grsecurity log messages. The default should be suitable for most
60855 + people, however, if you choose to change it, choose a value small enough
60856 + to allow informative logs to be produced, but large enough to
60857 + prevent flooding.
60858 +
60859 +config GRKERNSEC_FLOODBURST
60860 + int "Number of messages in a burst (maximum)"
60861 + default 4
60862 + help
60863 + This option allows you to choose the maximum number of messages allowed
60864 + within the flood time interval you chose in a separate option. The
60865 + default should be suitable for most people, however if you find that
60866 + many of your logs are being interpreted as flooding, you may want to
60867 + raise this value.
60868 +
60869 +endmenu
60870 +
60871 +endmenu
60872 diff -urNp linux-2.6.39/grsecurity/Makefile linux-2.6.39/grsecurity/Makefile
60873 --- linux-2.6.39/grsecurity/Makefile 1969-12-31 19:00:00.000000000 -0500
60874 +++ linux-2.6.39/grsecurity/Makefile 2011-05-22 19:41:42.000000000 -0400
60875 @@ -0,0 +1,29 @@
60876 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
60877 +# during 2001-2009 it has been completely redesigned by Brad Spengler
60878 +# into an RBAC system
60879 +#
60880 +# All code in this directory and various hooks inserted throughout the kernel
60881 +# are copyright Brad Spengler - Open Source Security, Inc., and released
60882 +# under the GPL v2 or higher
60883 +
60884 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
60885 + grsec_mount.o grsec_sig.o grsec_sock.o grsec_sysctl.o \
60886 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
60887 +
60888 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_ip.o gracl_segv.o \
60889 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
60890 + gracl_learn.o grsec_log.o
60891 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
60892 +
60893 +ifndef CONFIG_GRKERNSEC
60894 +obj-y += grsec_disabled.o
60895 +endif
60896 +
60897 +ifdef CONFIG_GRKERNSEC_HIDESYM
60898 +extra-y := grsec_hidesym.o
60899 +$(obj)/grsec_hidesym.o:
60900 + @-chmod -f 500 /boot
60901 + @-chmod -f 500 /lib/modules
60902 + @-chmod -f 700 .
60903 + @echo ' grsec: protected kernel image paths'
60904 +endif
60905 diff -urNp linux-2.6.39/include/acpi/acpi_drivers.h linux-2.6.39/include/acpi/acpi_drivers.h
60906 --- linux-2.6.39/include/acpi/acpi_drivers.h 2011-05-19 00:06:34.000000000 -0400
60907 +++ linux-2.6.39/include/acpi/acpi_drivers.h 2011-05-22 19:36:32.000000000 -0400
60908 @@ -119,8 +119,8 @@ void pci_acpi_crs_quirks(void);
60909 Dock Station
60910 -------------------------------------------------------------------------- */
60911 struct acpi_dock_ops {
60912 - acpi_notify_handler handler;
60913 - acpi_notify_handler uevent;
60914 + const acpi_notify_handler handler;
60915 + const acpi_notify_handler uevent;
60916 };
60917
60918 #if defined(CONFIG_ACPI_DOCK) || defined(CONFIG_ACPI_DOCK_MODULE)
60919 @@ -128,7 +128,7 @@ extern int is_dock_device(acpi_handle ha
60920 extern int register_dock_notifier(struct notifier_block *nb);
60921 extern void unregister_dock_notifier(struct notifier_block *nb);
60922 extern int register_hotplug_dock_device(acpi_handle handle,
60923 - struct acpi_dock_ops *ops,
60924 + const struct acpi_dock_ops *ops,
60925 void *context);
60926 extern void unregister_hotplug_dock_device(acpi_handle handle);
60927 #else
60928 @@ -144,7 +144,7 @@ static inline void unregister_dock_notif
60929 {
60930 }
60931 static inline int register_hotplug_dock_device(acpi_handle handle,
60932 - struct acpi_dock_ops *ops,
60933 + const struct acpi_dock_ops *ops,
60934 void *context)
60935 {
60936 return -ENODEV;
60937 diff -urNp linux-2.6.39/include/acpi/processor.h linux-2.6.39/include/acpi/processor.h
60938 --- linux-2.6.39/include/acpi/processor.h 2011-05-19 00:06:34.000000000 -0400
60939 +++ linux-2.6.39/include/acpi/processor.h 2011-05-22 19:36:32.000000000 -0400
60940 @@ -344,7 +344,7 @@ extern struct cpuidle_driver acpi_idle_d
60941
60942 /* in processor_thermal.c */
60943 int acpi_processor_get_limit_info(struct acpi_processor *pr);
60944 -extern struct thermal_cooling_device_ops processor_cooling_ops;
60945 +extern const struct thermal_cooling_device_ops processor_cooling_ops;
60946 #ifdef CONFIG_CPU_FREQ
60947 void acpi_thermal_cpufreq_init(void);
60948 void acpi_thermal_cpufreq_exit(void);
60949 diff -urNp linux-2.6.39/include/asm-generic/atomic-long.h linux-2.6.39/include/asm-generic/atomic-long.h
60950 --- linux-2.6.39/include/asm-generic/atomic-long.h 2011-05-19 00:06:34.000000000 -0400
60951 +++ linux-2.6.39/include/asm-generic/atomic-long.h 2011-05-22 19:36:32.000000000 -0400
60952 @@ -22,6 +22,12 @@
60953
60954 typedef atomic64_t atomic_long_t;
60955
60956 +#ifdef CONFIG_PAX_REFCOUNT
60957 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
60958 +#else
60959 +typedef atomic64_t atomic_long_unchecked_t;
60960 +#endif
60961 +
60962 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
60963
60964 static inline long atomic_long_read(atomic_long_t *l)
60965 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atom
60966 return (long)atomic64_read(v);
60967 }
60968
60969 +#ifdef CONFIG_PAX_REFCOUNT
60970 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
60971 +{
60972 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60973 +
60974 + return (long)atomic64_read_unchecked(v);
60975 +}
60976 +#endif
60977 +
60978 static inline void atomic_long_set(atomic_long_t *l, long i)
60979 {
60980 atomic64_t *v = (atomic64_t *)l;
60981 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomi
60982 atomic64_set(v, i);
60983 }
60984
60985 +#ifdef CONFIG_PAX_REFCOUNT
60986 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
60987 +{
60988 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60989 +
60990 + atomic64_set_unchecked(v, i);
60991 +}
60992 +#endif
60993 +
60994 static inline void atomic_long_inc(atomic_long_t *l)
60995 {
60996 atomic64_t *v = (atomic64_t *)l;
60997 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomi
60998 atomic64_inc(v);
60999 }
61000
61001 +#ifdef CONFIG_PAX_REFCOUNT
61002 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
61003 +{
61004 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61005 +
61006 + atomic64_inc_unchecked(v);
61007 +}
61008 +#endif
61009 +
61010 static inline void atomic_long_dec(atomic_long_t *l)
61011 {
61012 atomic64_t *v = (atomic64_t *)l;
61013 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomi
61014 atomic64_dec(v);
61015 }
61016
61017 +#ifdef CONFIG_PAX_REFCOUNT
61018 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
61019 +{
61020 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61021 +
61022 + atomic64_dec_unchecked(v);
61023 +}
61024 +#endif
61025 +
61026 static inline void atomic_long_add(long i, atomic_long_t *l)
61027 {
61028 atomic64_t *v = (atomic64_t *)l;
61029 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long
61030 atomic64_add(i, v);
61031 }
61032
61033 +#ifdef CONFIG_PAX_REFCOUNT
61034 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
61035 +{
61036 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61037 +
61038 + atomic64_add_unchecked(i, v);
61039 +}
61040 +#endif
61041 +
61042 static inline void atomic_long_sub(long i, atomic_long_t *l)
61043 {
61044 atomic64_t *v = (atomic64_t *)l;
61045 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long
61046 atomic64_sub(i, v);
61047 }
61048
61049 +#ifdef CONFIG_PAX_REFCOUNT
61050 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
61051 +{
61052 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61053 +
61054 + atomic64_sub_unchecked(i, v);
61055 +}
61056 +#endif
61057 +
61058 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
61059 {
61060 atomic64_t *v = (atomic64_t *)l;
61061 @@ -115,6 +175,15 @@ static inline long atomic_long_inc_retur
61062 return (long)atomic64_inc_return(v);
61063 }
61064
61065 +#ifdef CONFIG_PAX_REFCOUNT
61066 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
61067 +{
61068 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61069 +
61070 + return (long)atomic64_inc_return_unchecked(v);
61071 +}
61072 +#endif
61073 +
61074 static inline long atomic_long_dec_return(atomic_long_t *l)
61075 {
61076 atomic64_t *v = (atomic64_t *)l;
61077 @@ -140,6 +209,12 @@ static inline long atomic_long_add_unles
61078
61079 typedef atomic_t atomic_long_t;
61080
61081 +#ifdef CONFIG_PAX_REFCOUNT
61082 +typedef atomic_unchecked_t atomic_long_unchecked_t;
61083 +#else
61084 +typedef atomic_t atomic_long_unchecked_t;
61085 +#endif
61086 +
61087 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
61088 static inline long atomic_long_read(atomic_long_t *l)
61089 {
61090 @@ -148,6 +223,15 @@ static inline long atomic_long_read(atom
61091 return (long)atomic_read(v);
61092 }
61093
61094 +#ifdef CONFIG_PAX_REFCOUNT
61095 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
61096 +{
61097 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61098 +
61099 + return (long)atomic_read_unchecked(v);
61100 +}
61101 +#endif
61102 +
61103 static inline void atomic_long_set(atomic_long_t *l, long i)
61104 {
61105 atomic_t *v = (atomic_t *)l;
61106 @@ -155,6 +239,15 @@ static inline void atomic_long_set(atomi
61107 atomic_set(v, i);
61108 }
61109
61110 +#ifdef CONFIG_PAX_REFCOUNT
61111 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
61112 +{
61113 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61114 +
61115 + atomic_set_unchecked(v, i);
61116 +}
61117 +#endif
61118 +
61119 static inline void atomic_long_inc(atomic_long_t *l)
61120 {
61121 atomic_t *v = (atomic_t *)l;
61122 @@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomi
61123 atomic_inc(v);
61124 }
61125
61126 +#ifdef CONFIG_PAX_REFCOUNT
61127 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
61128 +{
61129 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61130 +
61131 + atomic_inc_unchecked(v);
61132 +}
61133 +#endif
61134 +
61135 static inline void atomic_long_dec(atomic_long_t *l)
61136 {
61137 atomic_t *v = (atomic_t *)l;
61138 @@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomi
61139 atomic_dec(v);
61140 }
61141
61142 +#ifdef CONFIG_PAX_REFCOUNT
61143 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
61144 +{
61145 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61146 +
61147 + atomic_dec_unchecked(v);
61148 +}
61149 +#endif
61150 +
61151 static inline void atomic_long_add(long i, atomic_long_t *l)
61152 {
61153 atomic_t *v = (atomic_t *)l;
61154 @@ -176,6 +287,15 @@ static inline void atomic_long_add(long
61155 atomic_add(i, v);
61156 }
61157
61158 +#ifdef CONFIG_PAX_REFCOUNT
61159 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
61160 +{
61161 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61162 +
61163 + atomic_add_unchecked(i, v);
61164 +}
61165 +#endif
61166 +
61167 static inline void atomic_long_sub(long i, atomic_long_t *l)
61168 {
61169 atomic_t *v = (atomic_t *)l;
61170 @@ -183,6 +303,15 @@ static inline void atomic_long_sub(long
61171 atomic_sub(i, v);
61172 }
61173
61174 +#ifdef CONFIG_PAX_REFCOUNT
61175 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
61176 +{
61177 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61178 +
61179 + atomic_sub_unchecked(i, v);
61180 +}
61181 +#endif
61182 +
61183 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
61184 {
61185 atomic_t *v = (atomic_t *)l;
61186 @@ -232,6 +361,15 @@ static inline long atomic_long_inc_retur
61187 return (long)atomic_inc_return(v);
61188 }
61189
61190 +#ifdef CONFIG_PAX_REFCOUNT
61191 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
61192 +{
61193 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61194 +
61195 + return (long)atomic_inc_return_unchecked(v);
61196 +}
61197 +#endif
61198 +
61199 static inline long atomic_long_dec_return(atomic_long_t *l)
61200 {
61201 atomic_t *v = (atomic_t *)l;
61202 @@ -255,4 +393,49 @@ static inline long atomic_long_add_unles
61203
61204 #endif /* BITS_PER_LONG == 64 */
61205
61206 +#ifdef CONFIG_PAX_REFCOUNT
61207 +static inline void pax_refcount_needs_these_functions(void)
61208 +{
61209 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
61210 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
61211 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
61212 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
61213 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
61214 + atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
61215 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
61216 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
61217 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
61218 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
61219 + atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
61220 +
61221 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
61222 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
61223 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
61224 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
61225 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
61226 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
61227 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
61228 +}
61229 +#else
61230 +#define atomic_read_unchecked(v) atomic_read(v)
61231 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
61232 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
61233 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
61234 +#define atomic_inc_unchecked(v) atomic_inc(v)
61235 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
61236 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
61237 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
61238 +#define atomic_dec_unchecked(v) atomic_dec(v)
61239 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
61240 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
61241 +
61242 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
61243 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
61244 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
61245 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
61246 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
61247 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
61248 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
61249 +#endif
61250 +
61251 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
61252 diff -urNp linux-2.6.39/include/asm-generic/cache.h linux-2.6.39/include/asm-generic/cache.h
61253 --- linux-2.6.39/include/asm-generic/cache.h 2011-05-19 00:06:34.000000000 -0400
61254 +++ linux-2.6.39/include/asm-generic/cache.h 2011-05-22 19:36:32.000000000 -0400
61255 @@ -6,7 +6,7 @@
61256 * cache lines need to provide their own cache.h.
61257 */
61258
61259 -#define L1_CACHE_SHIFT 5
61260 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
61261 +#define L1_CACHE_SHIFT 5U
61262 +#define L1_CACHE_BYTES (1U << L1_CACHE_SHIFT)
61263
61264 #endif /* __ASM_GENERIC_CACHE_H */
61265 diff -urNp linux-2.6.39/include/asm-generic/dma-mapping-common.h linux-2.6.39/include/asm-generic/dma-mapping-common.h
61266 --- linux-2.6.39/include/asm-generic/dma-mapping-common.h 2011-05-19 00:06:34.000000000 -0400
61267 +++ linux-2.6.39/include/asm-generic/dma-mapping-common.h 2011-05-22 19:36:32.000000000 -0400
61268 @@ -11,7 +11,7 @@ static inline dma_addr_t dma_map_single_
61269 enum dma_data_direction dir,
61270 struct dma_attrs *attrs)
61271 {
61272 - struct dma_map_ops *ops = get_dma_ops(dev);
61273 + const struct dma_map_ops *ops = get_dma_ops(dev);
61274 dma_addr_t addr;
61275
61276 kmemcheck_mark_initialized(ptr, size);
61277 @@ -30,7 +30,7 @@ static inline void dma_unmap_single_attr
61278 enum dma_data_direction dir,
61279 struct dma_attrs *attrs)
61280 {
61281 - struct dma_map_ops *ops = get_dma_ops(dev);
61282 + const struct dma_map_ops *ops = get_dma_ops(dev);
61283
61284 BUG_ON(!valid_dma_direction(dir));
61285 if (ops->unmap_page)
61286 @@ -42,7 +42,7 @@ static inline int dma_map_sg_attrs(struc
61287 int nents, enum dma_data_direction dir,
61288 struct dma_attrs *attrs)
61289 {
61290 - struct dma_map_ops *ops = get_dma_ops(dev);
61291 + const struct dma_map_ops *ops = get_dma_ops(dev);
61292 int i, ents;
61293 struct scatterlist *s;
61294
61295 @@ -59,7 +59,7 @@ static inline void dma_unmap_sg_attrs(st
61296 int nents, enum dma_data_direction dir,
61297 struct dma_attrs *attrs)
61298 {
61299 - struct dma_map_ops *ops = get_dma_ops(dev);
61300 + const struct dma_map_ops *ops = get_dma_ops(dev);
61301
61302 BUG_ON(!valid_dma_direction(dir));
61303 debug_dma_unmap_sg(dev, sg, nents, dir);
61304 @@ -71,7 +71,7 @@ static inline dma_addr_t dma_map_page(st
61305 size_t offset, size_t size,
61306 enum dma_data_direction dir)
61307 {
61308 - struct dma_map_ops *ops = get_dma_ops(dev);
61309 + const struct dma_map_ops *ops = get_dma_ops(dev);
61310 dma_addr_t addr;
61311
61312 kmemcheck_mark_initialized(page_address(page) + offset, size);
61313 @@ -85,7 +85,7 @@ static inline dma_addr_t dma_map_page(st
61314 static inline void dma_unmap_page(struct device *dev, dma_addr_t addr,
61315 size_t size, enum dma_data_direction dir)
61316 {
61317 - struct dma_map_ops *ops = get_dma_ops(dev);
61318 + const struct dma_map_ops *ops = get_dma_ops(dev);
61319
61320 BUG_ON(!valid_dma_direction(dir));
61321 if (ops->unmap_page)
61322 @@ -97,7 +97,7 @@ static inline void dma_sync_single_for_c
61323 size_t size,
61324 enum dma_data_direction dir)
61325 {
61326 - struct dma_map_ops *ops = get_dma_ops(dev);
61327 + const struct dma_map_ops *ops = get_dma_ops(dev);
61328
61329 BUG_ON(!valid_dma_direction(dir));
61330 if (ops->sync_single_for_cpu)
61331 @@ -109,7 +109,7 @@ static inline void dma_sync_single_for_d
61332 dma_addr_t addr, size_t size,
61333 enum dma_data_direction dir)
61334 {
61335 - struct dma_map_ops *ops = get_dma_ops(dev);
61336 + const struct dma_map_ops *ops = get_dma_ops(dev);
61337
61338 BUG_ON(!valid_dma_direction(dir));
61339 if (ops->sync_single_for_device)
61340 @@ -139,7 +139,7 @@ static inline void
61341 dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
61342 int nelems, enum dma_data_direction dir)
61343 {
61344 - struct dma_map_ops *ops = get_dma_ops(dev);
61345 + const struct dma_map_ops *ops = get_dma_ops(dev);
61346
61347 BUG_ON(!valid_dma_direction(dir));
61348 if (ops->sync_sg_for_cpu)
61349 @@ -151,7 +151,7 @@ static inline void
61350 dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
61351 int nelems, enum dma_data_direction dir)
61352 {
61353 - struct dma_map_ops *ops = get_dma_ops(dev);
61354 + const struct dma_map_ops *ops = get_dma_ops(dev);
61355
61356 BUG_ON(!valid_dma_direction(dir));
61357 if (ops->sync_sg_for_device)
61358 diff -urNp linux-2.6.39/include/asm-generic/int-l64.h linux-2.6.39/include/asm-generic/int-l64.h
61359 --- linux-2.6.39/include/asm-generic/int-l64.h 2011-05-19 00:06:34.000000000 -0400
61360 +++ linux-2.6.39/include/asm-generic/int-l64.h 2011-05-22 19:36:32.000000000 -0400
61361 @@ -46,6 +46,8 @@ typedef unsigned int u32;
61362 typedef signed long s64;
61363 typedef unsigned long u64;
61364
61365 +typedef unsigned int intoverflow_t __attribute__ ((mode(TI)));
61366 +
61367 #define S8_C(x) x
61368 #define U8_C(x) x ## U
61369 #define S16_C(x) x
61370 diff -urNp linux-2.6.39/include/asm-generic/int-ll64.h linux-2.6.39/include/asm-generic/int-ll64.h
61371 --- linux-2.6.39/include/asm-generic/int-ll64.h 2011-05-19 00:06:34.000000000 -0400
61372 +++ linux-2.6.39/include/asm-generic/int-ll64.h 2011-05-22 19:36:32.000000000 -0400
61373 @@ -51,6 +51,8 @@ typedef unsigned int u32;
61374 typedef signed long long s64;
61375 typedef unsigned long long u64;
61376
61377 +typedef unsigned long long intoverflow_t;
61378 +
61379 #define S8_C(x) x
61380 #define U8_C(x) x ## U
61381 #define S16_C(x) x
61382 diff -urNp linux-2.6.39/include/asm-generic/kmap_types.h linux-2.6.39/include/asm-generic/kmap_types.h
61383 --- linux-2.6.39/include/asm-generic/kmap_types.h 2011-05-19 00:06:34.000000000 -0400
61384 +++ linux-2.6.39/include/asm-generic/kmap_types.h 2011-05-22 19:36:32.000000000 -0400
61385 @@ -29,10 +29,11 @@ KMAP_D(16) KM_IRQ_PTE,
61386 KMAP_D(17) KM_NMI,
61387 KMAP_D(18) KM_NMI_PTE,
61388 KMAP_D(19) KM_KDB,
61389 +KMAP_D(20) KM_CLEARPAGE,
61390 /*
61391 * Remember to update debug_kmap_atomic() when adding new kmap types!
61392 */
61393 -KMAP_D(20) KM_TYPE_NR
61394 +KMAP_D(21) KM_TYPE_NR
61395 };
61396
61397 #undef KMAP_D
61398 diff -urNp linux-2.6.39/include/asm-generic/pgtable.h linux-2.6.39/include/asm-generic/pgtable.h
61399 --- linux-2.6.39/include/asm-generic/pgtable.h 2011-05-19 00:06:34.000000000 -0400
61400 +++ linux-2.6.39/include/asm-generic/pgtable.h 2011-05-22 19:36:32.000000000 -0400
61401 @@ -447,6 +447,14 @@ static inline int pmd_write(pmd_t pmd)
61402 #endif /* __HAVE_ARCH_PMD_WRITE */
61403 #endif
61404
61405 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
61406 +static inline unsigned long pax_open_kernel(void) { return 0; }
61407 +#endif
61408 +
61409 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
61410 +static inline unsigned long pax_close_kernel(void) { return 0; }
61411 +#endif
61412 +
61413 #endif /* !__ASSEMBLY__ */
61414
61415 #endif /* _ASM_GENERIC_PGTABLE_H */
61416 diff -urNp linux-2.6.39/include/asm-generic/pgtable-nopmd.h linux-2.6.39/include/asm-generic/pgtable-nopmd.h
61417 --- linux-2.6.39/include/asm-generic/pgtable-nopmd.h 2011-05-19 00:06:34.000000000 -0400
61418 +++ linux-2.6.39/include/asm-generic/pgtable-nopmd.h 2011-05-22 19:36:32.000000000 -0400
61419 @@ -1,14 +1,19 @@
61420 #ifndef _PGTABLE_NOPMD_H
61421 #define _PGTABLE_NOPMD_H
61422
61423 -#ifndef __ASSEMBLY__
61424 -
61425 #include <asm-generic/pgtable-nopud.h>
61426
61427 -struct mm_struct;
61428 -
61429 #define __PAGETABLE_PMD_FOLDED
61430
61431 +#define PMD_SHIFT PUD_SHIFT
61432 +#define PTRS_PER_PMD 1
61433 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
61434 +#define PMD_MASK (~(PMD_SIZE-1))
61435 +
61436 +#ifndef __ASSEMBLY__
61437 +
61438 +struct mm_struct;
61439 +
61440 /*
61441 * Having the pmd type consist of a pud gets the size right, and allows
61442 * us to conceptually access the pud entry that this pmd is folded into
61443 @@ -16,11 +21,6 @@ struct mm_struct;
61444 */
61445 typedef struct { pud_t pud; } pmd_t;
61446
61447 -#define PMD_SHIFT PUD_SHIFT
61448 -#define PTRS_PER_PMD 1
61449 -#define PMD_SIZE (1UL << PMD_SHIFT)
61450 -#define PMD_MASK (~(PMD_SIZE-1))
61451 -
61452 /*
61453 * The "pud_xxx()" functions here are trivial for a folded two-level
61454 * setup: the pmd is never bad, and a pmd always exists (as it's folded
61455 diff -urNp linux-2.6.39/include/asm-generic/pgtable-nopud.h linux-2.6.39/include/asm-generic/pgtable-nopud.h
61456 --- linux-2.6.39/include/asm-generic/pgtable-nopud.h 2011-05-19 00:06:34.000000000 -0400
61457 +++ linux-2.6.39/include/asm-generic/pgtable-nopud.h 2011-05-22 19:36:32.000000000 -0400
61458 @@ -1,10 +1,15 @@
61459 #ifndef _PGTABLE_NOPUD_H
61460 #define _PGTABLE_NOPUD_H
61461
61462 -#ifndef __ASSEMBLY__
61463 -
61464 #define __PAGETABLE_PUD_FOLDED
61465
61466 +#define PUD_SHIFT PGDIR_SHIFT
61467 +#define PTRS_PER_PUD 1
61468 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
61469 +#define PUD_MASK (~(PUD_SIZE-1))
61470 +
61471 +#ifndef __ASSEMBLY__
61472 +
61473 /*
61474 * Having the pud type consist of a pgd gets the size right, and allows
61475 * us to conceptually access the pgd entry that this pud is folded into
61476 @@ -12,11 +17,6 @@
61477 */
61478 typedef struct { pgd_t pgd; } pud_t;
61479
61480 -#define PUD_SHIFT PGDIR_SHIFT
61481 -#define PTRS_PER_PUD 1
61482 -#define PUD_SIZE (1UL << PUD_SHIFT)
61483 -#define PUD_MASK (~(PUD_SIZE-1))
61484 -
61485 /*
61486 * The "pgd_xxx()" functions here are trivial for a folded two-level
61487 * setup: the pud is never bad, and a pud always exists (as it's folded
61488 diff -urNp linux-2.6.39/include/asm-generic/vmlinux.lds.h linux-2.6.39/include/asm-generic/vmlinux.lds.h
61489 --- linux-2.6.39/include/asm-generic/vmlinux.lds.h 2011-05-19 00:06:34.000000000 -0400
61490 +++ linux-2.6.39/include/asm-generic/vmlinux.lds.h 2011-05-22 19:36:32.000000000 -0400
61491 @@ -213,6 +213,7 @@
61492 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
61493 VMLINUX_SYMBOL(__start_rodata) = .; \
61494 *(.rodata) *(.rodata.*) \
61495 + *(.data..read_only) \
61496 *(__vermagic) /* Kernel version magic */ \
61497 . = ALIGN(8); \
61498 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
61499 @@ -707,14 +708,15 @@
61500 * section in the linker script will go there too. @phdr should have
61501 * a leading colon.
61502 *
61503 - * Note that this macros defines __per_cpu_load as an absolute symbol.
61504 + * Note that this macros defines per_cpu_load as an absolute symbol.
61505 * If there is no need to put the percpu section at a predetermined
61506 * address, use PERCPU().
61507 */
61508 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
61509 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
61510 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
61511 + per_cpu_load = .; \
61512 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
61513 - LOAD_OFFSET) { \
61514 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
61515 VMLINUX_SYMBOL(__per_cpu_start) = .; \
61516 *(.data..percpu..first) \
61517 . = ALIGN(PAGE_SIZE); \
61518 @@ -726,7 +728,7 @@
61519 *(.data..percpu..shared_aligned) \
61520 VMLINUX_SYMBOL(__per_cpu_end) = .; \
61521 } phdr \
61522 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
61523 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
61524
61525 /**
61526 * PERCPU - define output section for percpu area, simple version
61527 diff -urNp linux-2.6.39/include/drm/drmP.h linux-2.6.39/include/drm/drmP.h
61528 --- linux-2.6.39/include/drm/drmP.h 2011-05-19 00:06:34.000000000 -0400
61529 +++ linux-2.6.39/include/drm/drmP.h 2011-05-22 19:41:42.000000000 -0400
61530 @@ -73,6 +73,7 @@
61531 #include <linux/workqueue.h>
61532 #include <linux/poll.h>
61533 #include <asm/pgalloc.h>
61534 +#include <asm/local.h>
61535 #include "drm.h"
61536
61537 #include <linux/idr.h>
61538 @@ -908,7 +909,7 @@ struct drm_driver {
61539 uint32_t handle);
61540
61541 /* Driver private ops for this object */
61542 - struct vm_operations_struct *gem_vm_ops;
61543 + const struct vm_operations_struct *gem_vm_ops;
61544
61545 int major;
61546 int minor;
61547 @@ -1023,7 +1024,7 @@ struct drm_device {
61548
61549 /** \name Usage Counters */
61550 /*@{ */
61551 - int open_count; /**< Outstanding files open */
61552 + local_t open_count; /**< Outstanding files open */
61553 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
61554 atomic_t vma_count; /**< Outstanding vma areas open */
61555 int buf_use; /**< Buffers in use -- cannot alloc */
61556 @@ -1034,7 +1035,7 @@ struct drm_device {
61557 /*@{ */
61558 unsigned long counters;
61559 enum drm_stat_type types[15];
61560 - atomic_t counts[15];
61561 + atomic_unchecked_t counts[15];
61562 /*@} */
61563
61564 struct list_head filelist;
61565 diff -urNp linux-2.6.39/include/linux/a.out.h linux-2.6.39/include/linux/a.out.h
61566 --- linux-2.6.39/include/linux/a.out.h 2011-05-19 00:06:34.000000000 -0400
61567 +++ linux-2.6.39/include/linux/a.out.h 2011-05-22 19:36:32.000000000 -0400
61568 @@ -39,6 +39,14 @@ enum machine_type {
61569 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
61570 };
61571
61572 +/* Constants for the N_FLAGS field */
61573 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
61574 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
61575 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
61576 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
61577 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
61578 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
61579 +
61580 #if !defined (N_MAGIC)
61581 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
61582 #endif
61583 diff -urNp linux-2.6.39/include/linux/atmdev.h linux-2.6.39/include/linux/atmdev.h
61584 --- linux-2.6.39/include/linux/atmdev.h 2011-05-19 00:06:34.000000000 -0400
61585 +++ linux-2.6.39/include/linux/atmdev.h 2011-05-22 19:36:32.000000000 -0400
61586 @@ -237,7 +237,7 @@ struct compat_atm_iobuf {
61587 #endif
61588
61589 struct k_atm_aal_stats {
61590 -#define __HANDLE_ITEM(i) atomic_t i
61591 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
61592 __AAL_STAT_ITEMS
61593 #undef __HANDLE_ITEM
61594 };
61595 diff -urNp linux-2.6.39/include/linux/binfmts.h linux-2.6.39/include/linux/binfmts.h
61596 --- linux-2.6.39/include/linux/binfmts.h 2011-05-19 00:06:34.000000000 -0400
61597 +++ linux-2.6.39/include/linux/binfmts.h 2011-05-22 19:36:32.000000000 -0400
61598 @@ -92,6 +92,7 @@ struct linux_binfmt {
61599 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
61600 int (*load_shlib)(struct file *);
61601 int (*core_dump)(struct coredump_params *cprm);
61602 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
61603 unsigned long min_coredump; /* minimal dump size */
61604 };
61605
61606 diff -urNp linux-2.6.39/include/linux/blkdev.h linux-2.6.39/include/linux/blkdev.h
61607 --- linux-2.6.39/include/linux/blkdev.h 2011-05-19 00:06:34.000000000 -0400
61608 +++ linux-2.6.39/include/linux/blkdev.h 2011-05-22 19:36:32.000000000 -0400
61609 @@ -1281,22 +1281,22 @@ queue_max_integrity_segments(struct requ
61610 #endif /* CONFIG_BLK_DEV_INTEGRITY */
61611
61612 struct block_device_operations {
61613 - int (*open) (struct block_device *, fmode_t);
61614 - int (*release) (struct gendisk *, fmode_t);
61615 - int (*ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
61616 - int (*compat_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
61617 - int (*direct_access) (struct block_device *, sector_t,
61618 + int (* const open) (struct block_device *, fmode_t);
61619 + int (* const release) (struct gendisk *, fmode_t);
61620 + int (* const ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
61621 + int (* const compat_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
61622 + int (* const direct_access) (struct block_device *, sector_t,
61623 void **, unsigned long *);
61624 - unsigned int (*check_events) (struct gendisk *disk,
61625 + unsigned int (* const check_events) (struct gendisk *disk,
61626 unsigned int clearing);
61627 /* ->media_changed() is DEPRECATED, use ->check_events() instead */
61628 - int (*media_changed) (struct gendisk *);
61629 - void (*unlock_native_capacity) (struct gendisk *);
61630 - int (*revalidate_disk) (struct gendisk *);
61631 - int (*getgeo)(struct block_device *, struct hd_geometry *);
61632 + int (* const media_changed) (struct gendisk *);
61633 + void (* const unlock_native_capacity) (struct gendisk *);
61634 + int (* const revalidate_disk) (struct gendisk *);
61635 + int (* const getgeo)(struct block_device *, struct hd_geometry *);
61636 /* this callback is with swap_lock and sometimes page table lock held */
61637 - void (*swap_slot_free_notify) (struct block_device *, unsigned long);
61638 - struct module *owner;
61639 + void (* const swap_slot_free_notify) (struct block_device *, unsigned long);
61640 + struct module * const owner;
61641 };
61642
61643 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
61644 diff -urNp linux-2.6.39/include/linux/blktrace_api.h linux-2.6.39/include/linux/blktrace_api.h
61645 --- linux-2.6.39/include/linux/blktrace_api.h 2011-05-19 00:06:34.000000000 -0400
61646 +++ linux-2.6.39/include/linux/blktrace_api.h 2011-05-22 19:36:32.000000000 -0400
61647 @@ -161,7 +161,7 @@ struct blk_trace {
61648 struct dentry *dir;
61649 struct dentry *dropped_file;
61650 struct dentry *msg_file;
61651 - atomic_t dropped;
61652 + atomic_unchecked_t dropped;
61653 };
61654
61655 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
61656 diff -urNp linux-2.6.39/include/linux/byteorder/little_endian.h linux-2.6.39/include/linux/byteorder/little_endian.h
61657 --- linux-2.6.39/include/linux/byteorder/little_endian.h 2011-05-19 00:06:34.000000000 -0400
61658 +++ linux-2.6.39/include/linux/byteorder/little_endian.h 2011-05-22 19:36:32.000000000 -0400
61659 @@ -42,51 +42,51 @@
61660
61661 static inline __le64 __cpu_to_le64p(const __u64 *p)
61662 {
61663 - return (__force __le64)*p;
61664 + return (__force const __le64)*p;
61665 }
61666 static inline __u64 __le64_to_cpup(const __le64 *p)
61667 {
61668 - return (__force __u64)*p;
61669 + return (__force const __u64)*p;
61670 }
61671 static inline __le32 __cpu_to_le32p(const __u32 *p)
61672 {
61673 - return (__force __le32)*p;
61674 + return (__force const __le32)*p;
61675 }
61676 static inline __u32 __le32_to_cpup(const __le32 *p)
61677 {
61678 - return (__force __u32)*p;
61679 + return (__force const __u32)*p;
61680 }
61681 static inline __le16 __cpu_to_le16p(const __u16 *p)
61682 {
61683 - return (__force __le16)*p;
61684 + return (__force const __le16)*p;
61685 }
61686 static inline __u16 __le16_to_cpup(const __le16 *p)
61687 {
61688 - return (__force __u16)*p;
61689 + return (__force const __u16)*p;
61690 }
61691 static inline __be64 __cpu_to_be64p(const __u64 *p)
61692 {
61693 - return (__force __be64)__swab64p(p);
61694 + return (__force const __be64)__swab64p(p);
61695 }
61696 static inline __u64 __be64_to_cpup(const __be64 *p)
61697 {
61698 - return __swab64p((__u64 *)p);
61699 + return __swab64p((const __u64 *)p);
61700 }
61701 static inline __be32 __cpu_to_be32p(const __u32 *p)
61702 {
61703 - return (__force __be32)__swab32p(p);
61704 + return (__force const __be32)__swab32p(p);
61705 }
61706 static inline __u32 __be32_to_cpup(const __be32 *p)
61707 {
61708 - return __swab32p((__u32 *)p);
61709 + return __swab32p((const __u32 *)p);
61710 }
61711 static inline __be16 __cpu_to_be16p(const __u16 *p)
61712 {
61713 - return (__force __be16)__swab16p(p);
61714 + return (__force const __be16)__swab16p(p);
61715 }
61716 static inline __u16 __be16_to_cpup(const __be16 *p)
61717 {
61718 - return __swab16p((__u16 *)p);
61719 + return __swab16p((const __u16 *)p);
61720 }
61721 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
61722 #define __le64_to_cpus(x) do { (void)(x); } while (0)
61723 diff -urNp linux-2.6.39/include/linux/cache.h linux-2.6.39/include/linux/cache.h
61724 --- linux-2.6.39/include/linux/cache.h 2011-05-19 00:06:34.000000000 -0400
61725 +++ linux-2.6.39/include/linux/cache.h 2011-05-22 19:36:32.000000000 -0400
61726 @@ -16,6 +16,10 @@
61727 #define __read_mostly
61728 #endif
61729
61730 +#ifndef __read_only
61731 +#define __read_only __read_mostly
61732 +#endif
61733 +
61734 #ifndef ____cacheline_aligned
61735 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
61736 #endif
61737 diff -urNp linux-2.6.39/include/linux/capability.h linux-2.6.39/include/linux/capability.h
61738 --- linux-2.6.39/include/linux/capability.h 2011-05-19 00:06:34.000000000 -0400
61739 +++ linux-2.6.39/include/linux/capability.h 2011-05-22 21:02:47.000000000 -0400
61740 @@ -547,6 +547,9 @@ extern bool capable(int cap);
61741 extern bool ns_capable(struct user_namespace *ns, int cap);
61742 extern bool task_ns_capable(struct task_struct *t, int cap);
61743 extern bool nsown_capable(int cap);
61744 +extern bool task_ns_capable_nolog(struct task_struct *t, int cap);
61745 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
61746 +extern bool capable_nolog(int cap);
61747
61748 /* audit system wants to get cap info from files as well */
61749 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
61750 diff -urNp linux-2.6.39/include/linux/compiler-gcc4.h linux-2.6.39/include/linux/compiler-gcc4.h
61751 --- linux-2.6.39/include/linux/compiler-gcc4.h 2011-05-19 00:06:34.000000000 -0400
61752 +++ linux-2.6.39/include/linux/compiler-gcc4.h 2011-05-22 19:36:32.000000000 -0400
61753 @@ -46,6 +46,11 @@
61754 #define __noclone __attribute__((__noclone__))
61755
61756 #endif
61757 +
61758 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
61759 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
61760 +#define __bos0(ptr) __bos((ptr), 0)
61761 +#define __bos1(ptr) __bos((ptr), 1)
61762 #endif
61763
61764 #if __GNUC_MINOR__ > 0
61765 diff -urNp linux-2.6.39/include/linux/compiler.h linux-2.6.39/include/linux/compiler.h
61766 --- linux-2.6.39/include/linux/compiler.h 2011-05-19 00:06:34.000000000 -0400
61767 +++ linux-2.6.39/include/linux/compiler.h 2011-05-22 19:36:32.000000000 -0400
61768 @@ -273,6 +273,22 @@ void ftrace_likely_update(struct ftrace_
61769 #define __cold
61770 #endif
61771
61772 +#ifndef __alloc_size
61773 +#define __alloc_size
61774 +#endif
61775 +
61776 +#ifndef __bos
61777 +#define __bos
61778 +#endif
61779 +
61780 +#ifndef __bos0
61781 +#define __bos0
61782 +#endif
61783 +
61784 +#ifndef __bos1
61785 +#define __bos1
61786 +#endif
61787 +
61788 /* Simple shorthand for a section definition */
61789 #ifndef __section
61790 # define __section(S) __attribute__ ((__section__(#S)))
61791 @@ -306,6 +322,7 @@ void ftrace_likely_update(struct ftrace_
61792 * use is to mediate communication between process-level code and irq/NMI
61793 * handlers, all running on the same CPU.
61794 */
61795 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
61796 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
61797 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
61798
61799 #endif /* __LINUX_COMPILER_H */
61800 diff -urNp linux-2.6.39/include/linux/concap.h linux-2.6.39/include/linux/concap.h
61801 --- linux-2.6.39/include/linux/concap.h 2011-05-19 00:06:34.000000000 -0400
61802 +++ linux-2.6.39/include/linux/concap.h 2011-05-22 19:36:32.000000000 -0400
61803 @@ -30,7 +30,7 @@ struct concap_device_ops;
61804 struct concap_proto{
61805 struct net_device *net_dev; /* net device using our service */
61806 struct concap_device_ops *dops; /* callbacks provided by device */
61807 - struct concap_proto_ops *pops; /* callbacks provided by us */
61808 + const struct concap_proto_ops *pops; /* callbacks provided by us */
61809 spinlock_t lock;
61810 int flags;
61811 void *proto_data; /* protocol specific private data, to
61812 diff -urNp linux-2.6.39/include/linux/configfs.h linux-2.6.39/include/linux/configfs.h
61813 --- linux-2.6.39/include/linux/configfs.h 2011-05-19 00:06:34.000000000 -0400
61814 +++ linux-2.6.39/include/linux/configfs.h 2011-05-22 19:36:32.000000000 -0400
61815 @@ -82,7 +82,7 @@ extern void config_item_put(struct confi
61816 struct config_item_type {
61817 struct module *ct_owner;
61818 struct configfs_item_operations *ct_item_ops;
61819 - struct configfs_group_operations *ct_group_ops;
61820 + const struct configfs_group_operations *ct_group_ops;
61821 struct configfs_attribute **ct_attrs;
61822 };
61823
61824 diff -urNp linux-2.6.39/include/linux/cpuset.h linux-2.6.39/include/linux/cpuset.h
61825 --- linux-2.6.39/include/linux/cpuset.h 2011-05-19 00:06:34.000000000 -0400
61826 +++ linux-2.6.39/include/linux/cpuset.h 2011-05-22 19:36:32.000000000 -0400
61827 @@ -118,7 +118,7 @@ static inline void put_mems_allowed(void
61828 * nodemask.
61829 */
61830 smp_mb();
61831 - --ACCESS_ONCE(current->mems_allowed_change_disable);
61832 + --ACCESS_ONCE_RW(current->mems_allowed_change_disable);
61833 }
61834
61835 static inline void set_mems_allowed(nodemask_t nodemask)
61836 diff -urNp linux-2.6.39/include/linux/dca.h linux-2.6.39/include/linux/dca.h
61837 --- linux-2.6.39/include/linux/dca.h 2011-05-19 00:06:34.000000000 -0400
61838 +++ linux-2.6.39/include/linux/dca.h 2011-05-22 19:36:32.000000000 -0400
61839 @@ -34,7 +34,7 @@ void dca_unregister_notify(struct notifi
61840
61841 struct dca_provider {
61842 struct list_head node;
61843 - struct dca_ops *ops;
61844 + const struct dca_ops *ops;
61845 struct device *cd;
61846 int id;
61847 };
61848 @@ -53,7 +53,7 @@ struct dca_ops {
61849 int (*dev_managed) (struct dca_provider *, struct device *);
61850 };
61851
61852 -struct dca_provider *alloc_dca_provider(struct dca_ops *ops, int priv_size);
61853 +struct dca_provider *alloc_dca_provider(const struct dca_ops *ops, int priv_size);
61854 void free_dca_provider(struct dca_provider *dca);
61855 int register_dca_provider(struct dca_provider *dca, struct device *dev);
61856 void unregister_dca_provider(struct dca_provider *dca, struct device *dev);
61857 diff -urNp linux-2.6.39/include/linux/decompress/mm.h linux-2.6.39/include/linux/decompress/mm.h
61858 --- linux-2.6.39/include/linux/decompress/mm.h 2011-05-19 00:06:34.000000000 -0400
61859 +++ linux-2.6.39/include/linux/decompress/mm.h 2011-05-22 19:36:33.000000000 -0400
61860 @@ -77,7 +77,7 @@ static void free(void *where)
61861 * warnings when not needed (indeed large_malloc / large_free are not
61862 * needed by inflate */
61863
61864 -#define malloc(a) kmalloc(a, GFP_KERNEL)
61865 +#define malloc(a) kmalloc((a), GFP_KERNEL)
61866 #define free(a) kfree(a)
61867
61868 #define large_malloc(a) vmalloc(a)
61869 diff -urNp linux-2.6.39/include/linux/dma-mapping.h linux-2.6.39/include/linux/dma-mapping.h
61870 --- linux-2.6.39/include/linux/dma-mapping.h 2011-05-19 00:06:34.000000000 -0400
61871 +++ linux-2.6.39/include/linux/dma-mapping.h 2011-05-22 19:36:33.000000000 -0400
61872 @@ -16,40 +16,40 @@ enum dma_data_direction {
61873 };
61874
61875 struct dma_map_ops {
61876 - void* (*alloc_coherent)(struct device *dev, size_t size,
61877 + void* (* const alloc_coherent)(struct device *dev, size_t size,
61878 dma_addr_t *dma_handle, gfp_t gfp);
61879 - void (*free_coherent)(struct device *dev, size_t size,
61880 + void (* const free_coherent)(struct device *dev, size_t size,
61881 void *vaddr, dma_addr_t dma_handle);
61882 - dma_addr_t (*map_page)(struct device *dev, struct page *page,
61883 + dma_addr_t (* const map_page)(struct device *dev, struct page *page,
61884 unsigned long offset, size_t size,
61885 enum dma_data_direction dir,
61886 struct dma_attrs *attrs);
61887 - void (*unmap_page)(struct device *dev, dma_addr_t dma_handle,
61888 + void (* const unmap_page)(struct device *dev, dma_addr_t dma_handle,
61889 size_t size, enum dma_data_direction dir,
61890 struct dma_attrs *attrs);
61891 - int (*map_sg)(struct device *dev, struct scatterlist *sg,
61892 + int (* const map_sg)(struct device *dev, struct scatterlist *sg,
61893 int nents, enum dma_data_direction dir,
61894 struct dma_attrs *attrs);
61895 - void (*unmap_sg)(struct device *dev,
61896 + void (* const unmap_sg)(struct device *dev,
61897 struct scatterlist *sg, int nents,
61898 enum dma_data_direction dir,
61899 struct dma_attrs *attrs);
61900 - void (*sync_single_for_cpu)(struct device *dev,
61901 + void (* const sync_single_for_cpu)(struct device *dev,
61902 dma_addr_t dma_handle, size_t size,
61903 enum dma_data_direction dir);
61904 - void (*sync_single_for_device)(struct device *dev,
61905 + void (* const sync_single_for_device)(struct device *dev,
61906 dma_addr_t dma_handle, size_t size,
61907 enum dma_data_direction dir);
61908 - void (*sync_sg_for_cpu)(struct device *dev,
61909 + void (* const sync_sg_for_cpu)(struct device *dev,
61910 struct scatterlist *sg, int nents,
61911 enum dma_data_direction dir);
61912 - void (*sync_sg_for_device)(struct device *dev,
61913 + void (* const sync_sg_for_device)(struct device *dev,
61914 struct scatterlist *sg, int nents,
61915 enum dma_data_direction dir);
61916 - int (*mapping_error)(struct device *dev, dma_addr_t dma_addr);
61917 - int (*dma_supported)(struct device *dev, u64 mask);
61918 - int (*set_dma_mask)(struct device *dev, u64 mask);
61919 - int is_phys;
61920 + int (* const mapping_error)(struct device *dev, dma_addr_t dma_addr);
61921 + int (* const dma_supported)(struct device *dev, u64 mask);
61922 + int (* set_dma_mask)(struct device *dev, u64 mask);
61923 + const int is_phys;
61924 };
61925
61926 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
61927 diff -urNp linux-2.6.39/include/linux/elf.h linux-2.6.39/include/linux/elf.h
61928 --- linux-2.6.39/include/linux/elf.h 2011-05-19 00:06:34.000000000 -0400
61929 +++ linux-2.6.39/include/linux/elf.h 2011-05-22 19:36:33.000000000 -0400
61930 @@ -49,6 +49,17 @@ typedef __s64 Elf64_Sxword;
61931 #define PT_GNU_EH_FRAME 0x6474e550
61932
61933 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
61934 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
61935 +
61936 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
61937 +
61938 +/* Constants for the e_flags field */
61939 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
61940 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
61941 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
61942 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
61943 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
61944 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
61945
61946 /*
61947 * Extended Numbering
61948 @@ -106,6 +117,8 @@ typedef __s64 Elf64_Sxword;
61949 #define DT_DEBUG 21
61950 #define DT_TEXTREL 22
61951 #define DT_JMPREL 23
61952 +#define DT_FLAGS 30
61953 + #define DF_TEXTREL 0x00000004
61954 #define DT_ENCODING 32
61955 #define OLD_DT_LOOS 0x60000000
61956 #define DT_LOOS 0x6000000d
61957 @@ -252,6 +265,19 @@ typedef struct elf64_hdr {
61958 #define PF_W 0x2
61959 #define PF_X 0x1
61960
61961 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
61962 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
61963 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
61964 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
61965 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
61966 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
61967 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
61968 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
61969 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
61970 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
61971 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
61972 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
61973 +
61974 typedef struct elf32_phdr{
61975 Elf32_Word p_type;
61976 Elf32_Off p_offset;
61977 @@ -344,6 +370,8 @@ typedef struct elf64_shdr {
61978 #define EI_OSABI 7
61979 #define EI_PAD 8
61980
61981 +#define EI_PAX 14
61982 +
61983 #define ELFMAG0 0x7f /* EI_MAG */
61984 #define ELFMAG1 'E'
61985 #define ELFMAG2 'L'
61986 @@ -421,6 +449,7 @@ extern Elf32_Dyn _DYNAMIC [];
61987 #define elf_note elf32_note
61988 #define elf_addr_t Elf32_Off
61989 #define Elf_Half Elf32_Half
61990 +#define elf_dyn Elf32_Dyn
61991
61992 #else
61993
61994 @@ -431,6 +460,7 @@ extern Elf64_Dyn _DYNAMIC [];
61995 #define elf_note elf64_note
61996 #define elf_addr_t Elf64_Off
61997 #define Elf_Half Elf64_Half
61998 +#define elf_dyn Elf64_Dyn
61999
62000 #endif
62001
62002 diff -urNp linux-2.6.39/include/linux/enclosure.h linux-2.6.39/include/linux/enclosure.h
62003 --- linux-2.6.39/include/linux/enclosure.h 2011-05-19 00:06:34.000000000 -0400
62004 +++ linux-2.6.39/include/linux/enclosure.h 2011-05-22 19:36:33.000000000 -0400
62005 @@ -98,7 +98,7 @@ struct enclosure_device {
62006 void *scratch;
62007 struct list_head node;
62008 struct device edev;
62009 - struct enclosure_component_callbacks *cb;
62010 + const struct enclosure_component_callbacks *cb;
62011 int components;
62012 struct enclosure_component component[0];
62013 };
62014 diff -urNp linux-2.6.39/include/linux/fscache-cache.h linux-2.6.39/include/linux/fscache-cache.h
62015 --- linux-2.6.39/include/linux/fscache-cache.h 2011-05-19 00:06:34.000000000 -0400
62016 +++ linux-2.6.39/include/linux/fscache-cache.h 2011-05-22 19:36:33.000000000 -0400
62017 @@ -113,7 +113,7 @@ struct fscache_operation {
62018 #endif
62019 };
62020
62021 -extern atomic_t fscache_op_debug_id;
62022 +extern atomic_unchecked_t fscache_op_debug_id;
62023 extern void fscache_op_work_func(struct work_struct *work);
62024
62025 extern void fscache_enqueue_operation(struct fscache_operation *);
62026 @@ -133,7 +133,7 @@ static inline void fscache_operation_ini
62027 {
62028 INIT_WORK(&op->work, fscache_op_work_func);
62029 atomic_set(&op->usage, 1);
62030 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
62031 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
62032 op->processor = processor;
62033 op->release = release;
62034 INIT_LIST_HEAD(&op->pend_link);
62035 diff -urNp linux-2.6.39/include/linux/fs.h linux-2.6.39/include/linux/fs.h
62036 --- linux-2.6.39/include/linux/fs.h 2011-05-19 00:06:34.000000000 -0400
62037 +++ linux-2.6.39/include/linux/fs.h 2011-05-22 19:41:42.000000000 -0400
62038 @@ -108,6 +108,11 @@ struct inodes_stat_t {
62039 /* File was opened by fanotify and shouldn't generate fanotify events */
62040 #define FMODE_NONOTIFY ((__force fmode_t)0x1000000)
62041
62042 +/* Hack for grsec so as not to require read permission simply to execute
62043 + * a binary
62044 + */
62045 +#define FMODE_GREXEC ((__force fmode_t)0x2000000)
62046 +
62047 /*
62048 * The below are the various read and write types that we support. Some of
62049 * them include behavioral modifiers that send information down to the
62050 @@ -575,41 +580,41 @@ typedef int (*read_actor_t)(read_descrip
62051 unsigned long, unsigned long);
62052
62053 struct address_space_operations {
62054 - int (*writepage)(struct page *page, struct writeback_control *wbc);
62055 - int (*readpage)(struct file *, struct page *);
62056 + int (* const writepage)(struct page *page, struct writeback_control *wbc);
62057 + int (* const readpage)(struct file *, struct page *);
62058
62059 /* Write back some dirty pages from this mapping. */
62060 - int (*writepages)(struct address_space *, struct writeback_control *);
62061 + int (* const writepages)(struct address_space *, struct writeback_control *);
62062
62063 /* Set a page dirty. Return true if this dirtied it */
62064 - int (*set_page_dirty)(struct page *page);
62065 + int (* const set_page_dirty)(struct page *page);
62066
62067 - int (*readpages)(struct file *filp, struct address_space *mapping,
62068 + int (* const readpages)(struct file *filp, struct address_space *mapping,
62069 struct list_head *pages, unsigned nr_pages);
62070
62071 - int (*write_begin)(struct file *, struct address_space *mapping,
62072 + int (* const write_begin)(struct file *, struct address_space *mapping,
62073 loff_t pos, unsigned len, unsigned flags,
62074 struct page **pagep, void **fsdata);
62075 - int (*write_end)(struct file *, struct address_space *mapping,
62076 + int (* const write_end)(struct file *, struct address_space *mapping,
62077 loff_t pos, unsigned len, unsigned copied,
62078 struct page *page, void *fsdata);
62079
62080 /* Unfortunately this kludge is needed for FIBMAP. Don't use it */
62081 - sector_t (*bmap)(struct address_space *, sector_t);
62082 - void (*invalidatepage) (struct page *, unsigned long);
62083 - int (*releasepage) (struct page *, gfp_t);
62084 - void (*freepage)(struct page *);
62085 - ssize_t (*direct_IO)(int, struct kiocb *, const struct iovec *iov,
62086 + sector_t (* const bmap)(struct address_space *, sector_t);
62087 + void (* const invalidatepage) (struct page *, unsigned long);
62088 + int (* const releasepage) (struct page *, gfp_t);
62089 + void (* const freepage)(struct page *);
62090 + ssize_t (* const direct_IO)(int, struct kiocb *, const struct iovec *iov,
62091 loff_t offset, unsigned long nr_segs);
62092 - int (*get_xip_mem)(struct address_space *, pgoff_t, int,
62093 + int (* const get_xip_mem)(struct address_space *, pgoff_t, int,
62094 void **, unsigned long *);
62095 /* migrate the contents of a page to the specified target */
62096 - int (*migratepage) (struct address_space *,
62097 + int (* const migratepage) (struct address_space *,
62098 struct page *, struct page *);
62099 - int (*launder_page) (struct page *);
62100 - int (*is_partially_uptodate) (struct page *, read_descriptor_t *,
62101 + int (* const launder_page) (struct page *);
62102 + int (* const is_partially_uptodate) (struct page *, read_descriptor_t *,
62103 unsigned long);
62104 - int (*error_remove_page)(struct address_space *, struct page *);
62105 + int (* const error_remove_page)(struct address_space *, struct page *);
62106 };
62107
62108 extern const struct address_space_operations empty_aops;
62109 @@ -1060,17 +1065,17 @@ static inline int file_check_writeable(s
62110 typedef struct files_struct *fl_owner_t;
62111
62112 struct file_lock_operations {
62113 - void (*fl_copy_lock)(struct file_lock *, struct file_lock *);
62114 - void (*fl_release_private)(struct file_lock *);
62115 + void (* const fl_copy_lock)(struct file_lock *, struct file_lock *);
62116 + void (* const fl_release_private)(struct file_lock *);
62117 };
62118
62119 struct lock_manager_operations {
62120 - int (*fl_compare_owner)(struct file_lock *, struct file_lock *);
62121 - void (*fl_notify)(struct file_lock *); /* unblock callback */
62122 - int (*fl_grant)(struct file_lock *, struct file_lock *, int);
62123 - void (*fl_release_private)(struct file_lock *);
62124 - void (*fl_break)(struct file_lock *);
62125 - int (*fl_change)(struct file_lock **, int);
62126 + int (* const fl_compare_owner)(struct file_lock *, struct file_lock *);
62127 + void (* const fl_notify)(struct file_lock *); /* unblock callback */
62128 + int (* const fl_grant)(struct file_lock *, struct file_lock *, int);
62129 + void (* const fl_release_private)(struct file_lock *);
62130 + void (* const fl_break)(struct file_lock *);
62131 + int (* const fl_change)(struct file_lock **, int);
62132 };
62133
62134 struct lock_manager {
62135 @@ -1611,31 +1616,31 @@ extern ssize_t vfs_writev(struct file *,
62136 unsigned long, loff_t *);
62137
62138 struct super_operations {
62139 - struct inode *(*alloc_inode)(struct super_block *sb);
62140 - void (*destroy_inode)(struct inode *);
62141 + struct inode *(* const alloc_inode)(struct super_block *sb);
62142 + void (* const destroy_inode)(struct inode *);
62143
62144 - void (*dirty_inode) (struct inode *);
62145 - int (*write_inode) (struct inode *, struct writeback_control *wbc);
62146 - int (*drop_inode) (struct inode *);
62147 - void (*evict_inode) (struct inode *);
62148 - void (*put_super) (struct super_block *);
62149 - void (*write_super) (struct super_block *);
62150 - int (*sync_fs)(struct super_block *sb, int wait);
62151 - int (*freeze_fs) (struct super_block *);
62152 - int (*unfreeze_fs) (struct super_block *);
62153 - int (*statfs) (struct dentry *, struct kstatfs *);
62154 - int (*remount_fs) (struct super_block *, int *, char *);
62155 - void (*umount_begin) (struct super_block *);
62156 -
62157 - int (*show_options)(struct seq_file *, struct vfsmount *);
62158 - int (*show_devname)(struct seq_file *, struct vfsmount *);
62159 - int (*show_path)(struct seq_file *, struct vfsmount *);
62160 - int (*show_stats)(struct seq_file *, struct vfsmount *);
62161 + void (* const dirty_inode) (struct inode *);
62162 + int (* const write_inode) (struct inode *, struct writeback_control *wbc);
62163 + int (* const drop_inode) (struct inode *);
62164 + void (* const evict_inode) (struct inode *);
62165 + void (* const put_super) (struct super_block *);
62166 + void (* const write_super) (struct super_block *);
62167 + int (* const sync_fs)(struct super_block *sb, int wait);
62168 + int (* const freeze_fs) (struct super_block *);
62169 + int (* const unfreeze_fs) (struct super_block *);
62170 + int (* const statfs) (struct dentry *, struct kstatfs *);
62171 + int (* const remount_fs) (struct super_block *, int *, char *);
62172 + void (* const umount_begin) (struct super_block *);
62173 +
62174 + int (* const show_options)(struct seq_file *, struct vfsmount *);
62175 + int (* const show_devname)(struct seq_file *, struct vfsmount *);
62176 + int (* const show_path)(struct seq_file *, struct vfsmount *);
62177 + int (* const show_stats)(struct seq_file *, struct vfsmount *);
62178 #ifdef CONFIG_QUOTA
62179 - ssize_t (*quota_read)(struct super_block *, int, char *, size_t, loff_t);
62180 - ssize_t (*quota_write)(struct super_block *, int, const char *, size_t, loff_t);
62181 + ssize_t (* const quota_read)(struct super_block *, int, char *, size_t, loff_t);
62182 + ssize_t (* const quota_write)(struct super_block *, int, const char *, size_t, loff_t);
62183 #endif
62184 - int (*bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t);
62185 + int (* const bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t);
62186 };
62187
62188 /*
62189 diff -urNp linux-2.6.39/include/linux/fs_struct.h linux-2.6.39/include/linux/fs_struct.h
62190 --- linux-2.6.39/include/linux/fs_struct.h 2011-05-19 00:06:34.000000000 -0400
62191 +++ linux-2.6.39/include/linux/fs_struct.h 2011-05-22 19:36:33.000000000 -0400
62192 @@ -6,7 +6,7 @@
62193 #include <linux/seqlock.h>
62194
62195 struct fs_struct {
62196 - int users;
62197 + atomic_t users;
62198 spinlock_t lock;
62199 seqcount_t seq;
62200 int umask;
62201 diff -urNp linux-2.6.39/include/linux/ftrace_event.h linux-2.6.39/include/linux/ftrace_event.h
62202 --- linux-2.6.39/include/linux/ftrace_event.h 2011-05-19 00:06:34.000000000 -0400
62203 +++ linux-2.6.39/include/linux/ftrace_event.h 2011-05-22 19:36:33.000000000 -0400
62204 @@ -235,7 +235,7 @@ extern int trace_define_field(struct ftr
62205 extern int trace_add_event_call(struct ftrace_event_call *call);
62206 extern void trace_remove_event_call(struct ftrace_event_call *call);
62207
62208 -#define is_signed_type(type) (((type)(-1)) < 0)
62209 +#define is_signed_type(type) (((type)(-1)) < (type)1)
62210
62211 int trace_set_clr_event(const char *system, const char *event, int set);
62212
62213 diff -urNp linux-2.6.39/include/linux/ftrace.h linux-2.6.39/include/linux/ftrace.h
62214 --- linux-2.6.39/include/linux/ftrace.h 2011-05-19 00:06:34.000000000 -0400
62215 +++ linux-2.6.39/include/linux/ftrace.h 2011-05-22 19:36:33.000000000 -0400
62216 @@ -140,7 +140,7 @@ extern void
62217 unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
62218 void *data);
62219 extern void
62220 -unregister_ftrace_function_probe_func(char *glob, struct ftrace_probe_ops *ops);
62221 +unregister_ftrace_function_probe_func(char *glob, const struct ftrace_probe_ops *ops);
62222 extern void unregister_ftrace_function_probe_all(char *glob);
62223
62224 extern int ftrace_text_reserved(void *start, void *end);
62225 diff -urNp linux-2.6.39/include/linux/genhd.h linux-2.6.39/include/linux/genhd.h
62226 --- linux-2.6.39/include/linux/genhd.h 2011-05-19 00:06:34.000000000 -0400
62227 +++ linux-2.6.39/include/linux/genhd.h 2011-05-22 19:36:33.000000000 -0400
62228 @@ -183,7 +183,7 @@ struct gendisk {
62229 struct kobject *slave_dir;
62230
62231 struct timer_rand_state *random;
62232 - atomic_t sync_io; /* RAID */
62233 + atomic_unchecked_t sync_io; /* RAID */
62234 struct disk_events *ev;
62235 #ifdef CONFIG_BLK_DEV_INTEGRITY
62236 struct blk_integrity *integrity;
62237 diff -urNp linux-2.6.39/include/linux/gracl.h linux-2.6.39/include/linux/gracl.h
62238 --- linux-2.6.39/include/linux/gracl.h 1969-12-31 19:00:00.000000000 -0500
62239 +++ linux-2.6.39/include/linux/gracl.h 2011-05-22 19:41:42.000000000 -0400
62240 @@ -0,0 +1,317 @@
62241 +#ifndef GR_ACL_H
62242 +#define GR_ACL_H
62243 +
62244 +#include <linux/grdefs.h>
62245 +#include <linux/resource.h>
62246 +#include <linux/capability.h>
62247 +#include <linux/dcache.h>
62248 +#include <asm/resource.h>
62249 +
62250 +/* Major status information */
62251 +
62252 +#define GR_VERSION "grsecurity 2.2.2"
62253 +#define GRSECURITY_VERSION 0x2202
62254 +
62255 +enum {
62256 + GR_SHUTDOWN = 0,
62257 + GR_ENABLE = 1,
62258 + GR_SPROLE = 2,
62259 + GR_RELOAD = 3,
62260 + GR_SEGVMOD = 4,
62261 + GR_STATUS = 5,
62262 + GR_UNSPROLE = 6,
62263 + GR_PASSSET = 7,
62264 + GR_SPROLEPAM = 8,
62265 +};
62266 +
62267 +/* Password setup definitions
62268 + * kernel/grhash.c */
62269 +enum {
62270 + GR_PW_LEN = 128,
62271 + GR_SALT_LEN = 16,
62272 + GR_SHA_LEN = 32,
62273 +};
62274 +
62275 +enum {
62276 + GR_SPROLE_LEN = 64,
62277 +};
62278 +
62279 +enum {
62280 + GR_NO_GLOB = 0,
62281 + GR_REG_GLOB,
62282 + GR_CREATE_GLOB
62283 +};
62284 +
62285 +#define GR_NLIMITS 32
62286 +
62287 +/* Begin Data Structures */
62288 +
62289 +struct sprole_pw {
62290 + unsigned char *rolename;
62291 + unsigned char salt[GR_SALT_LEN];
62292 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
62293 +};
62294 +
62295 +struct name_entry {
62296 + __u32 key;
62297 + ino_t inode;
62298 + dev_t device;
62299 + char *name;
62300 + __u16 len;
62301 + __u8 deleted;
62302 + struct name_entry *prev;
62303 + struct name_entry *next;
62304 +};
62305 +
62306 +struct inodev_entry {
62307 + struct name_entry *nentry;
62308 + struct inodev_entry *prev;
62309 + struct inodev_entry *next;
62310 +};
62311 +
62312 +struct acl_role_db {
62313 + struct acl_role_label **r_hash;
62314 + __u32 r_size;
62315 +};
62316 +
62317 +struct inodev_db {
62318 + struct inodev_entry **i_hash;
62319 + __u32 i_size;
62320 +};
62321 +
62322 +struct name_db {
62323 + struct name_entry **n_hash;
62324 + __u32 n_size;
62325 +};
62326 +
62327 +struct crash_uid {
62328 + uid_t uid;
62329 + unsigned long expires;
62330 +};
62331 +
62332 +struct gr_hash_struct {
62333 + void **table;
62334 + void **nametable;
62335 + void *first;
62336 + __u32 table_size;
62337 + __u32 used_size;
62338 + int type;
62339 +};
62340 +
62341 +/* Userspace Grsecurity ACL data structures */
62342 +
62343 +struct acl_subject_label {
62344 + char *filename;
62345 + ino_t inode;
62346 + dev_t device;
62347 + __u32 mode;
62348 + kernel_cap_t cap_mask;
62349 + kernel_cap_t cap_lower;
62350 + kernel_cap_t cap_invert_audit;
62351 +
62352 + struct rlimit res[GR_NLIMITS];
62353 + __u32 resmask;
62354 +
62355 + __u8 user_trans_type;
62356 + __u8 group_trans_type;
62357 + uid_t *user_transitions;
62358 + gid_t *group_transitions;
62359 + __u16 user_trans_num;
62360 + __u16 group_trans_num;
62361 +
62362 + __u32 sock_families[2];
62363 + __u32 ip_proto[8];
62364 + __u32 ip_type;
62365 + struct acl_ip_label **ips;
62366 + __u32 ip_num;
62367 + __u32 inaddr_any_override;
62368 +
62369 + __u32 crashes;
62370 + unsigned long expires;
62371 +
62372 + struct acl_subject_label *parent_subject;
62373 + struct gr_hash_struct *hash;
62374 + struct acl_subject_label *prev;
62375 + struct acl_subject_label *next;
62376 +
62377 + struct acl_object_label **obj_hash;
62378 + __u32 obj_hash_size;
62379 + __u16 pax_flags;
62380 +};
62381 +
62382 +struct role_allowed_ip {
62383 + __u32 addr;
62384 + __u32 netmask;
62385 +
62386 + struct role_allowed_ip *prev;
62387 + struct role_allowed_ip *next;
62388 +};
62389 +
62390 +struct role_transition {
62391 + char *rolename;
62392 +
62393 + struct role_transition *prev;
62394 + struct role_transition *next;
62395 +};
62396 +
62397 +struct acl_role_label {
62398 + char *rolename;
62399 + uid_t uidgid;
62400 + __u16 roletype;
62401 +
62402 + __u16 auth_attempts;
62403 + unsigned long expires;
62404 +
62405 + struct acl_subject_label *root_label;
62406 + struct gr_hash_struct *hash;
62407 +
62408 + struct acl_role_label *prev;
62409 + struct acl_role_label *next;
62410 +
62411 + struct role_transition *transitions;
62412 + struct role_allowed_ip *allowed_ips;
62413 + uid_t *domain_children;
62414 + __u16 domain_child_num;
62415 +
62416 + struct acl_subject_label **subj_hash;
62417 + __u32 subj_hash_size;
62418 +};
62419 +
62420 +struct user_acl_role_db {
62421 + struct acl_role_label **r_table;
62422 + __u32 num_pointers; /* Number of allocations to track */
62423 + __u32 num_roles; /* Number of roles */
62424 + __u32 num_domain_children; /* Number of domain children */
62425 + __u32 num_subjects; /* Number of subjects */
62426 + __u32 num_objects; /* Number of objects */
62427 +};
62428 +
62429 +struct acl_object_label {
62430 + char *filename;
62431 + ino_t inode;
62432 + dev_t device;
62433 + __u32 mode;
62434 +
62435 + struct acl_subject_label *nested;
62436 + struct acl_object_label *globbed;
62437 +
62438 + /* next two structures not used */
62439 +
62440 + struct acl_object_label *prev;
62441 + struct acl_object_label *next;
62442 +};
62443 +
62444 +struct acl_ip_label {
62445 + char *iface;
62446 + __u32 addr;
62447 + __u32 netmask;
62448 + __u16 low, high;
62449 + __u8 mode;
62450 + __u32 type;
62451 + __u32 proto[8];
62452 +
62453 + /* next two structures not used */
62454 +
62455 + struct acl_ip_label *prev;
62456 + struct acl_ip_label *next;
62457 +};
62458 +
62459 +struct gr_arg {
62460 + struct user_acl_role_db role_db;
62461 + unsigned char pw[GR_PW_LEN];
62462 + unsigned char salt[GR_SALT_LEN];
62463 + unsigned char sum[GR_SHA_LEN];
62464 + unsigned char sp_role[GR_SPROLE_LEN];
62465 + struct sprole_pw *sprole_pws;
62466 + dev_t segv_device;
62467 + ino_t segv_inode;
62468 + uid_t segv_uid;
62469 + __u16 num_sprole_pws;
62470 + __u16 mode;
62471 +};
62472 +
62473 +struct gr_arg_wrapper {
62474 + struct gr_arg *arg;
62475 + __u32 version;
62476 + __u32 size;
62477 +};
62478 +
62479 +struct subject_map {
62480 + struct acl_subject_label *user;
62481 + struct acl_subject_label *kernel;
62482 + struct subject_map *prev;
62483 + struct subject_map *next;
62484 +};
62485 +
62486 +struct acl_subj_map_db {
62487 + struct subject_map **s_hash;
62488 + __u32 s_size;
62489 +};
62490 +
62491 +/* End Data Structures Section */
62492 +
62493 +/* Hash functions generated by empirical testing by Brad Spengler
62494 + Makes good use of the low bits of the inode. Generally 0-1 times
62495 + in loop for successful match. 0-3 for unsuccessful match.
62496 + Shift/add algorithm with modulus of table size and an XOR*/
62497 +
62498 +static __inline__ unsigned int
62499 +rhash(const uid_t uid, const __u16 type, const unsigned int sz)
62500 +{
62501 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
62502 +}
62503 +
62504 + static __inline__ unsigned int
62505 +shash(const struct acl_subject_label *userp, const unsigned int sz)
62506 +{
62507 + return ((const unsigned long)userp % sz);
62508 +}
62509 +
62510 +static __inline__ unsigned int
62511 +fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
62512 +{
62513 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
62514 +}
62515 +
62516 +static __inline__ unsigned int
62517 +nhash(const char *name, const __u16 len, const unsigned int sz)
62518 +{
62519 + return full_name_hash((const unsigned char *)name, len) % sz;
62520 +}
62521 +
62522 +#define FOR_EACH_ROLE_START(role) \
62523 + role = role_list; \
62524 + while (role) {
62525 +
62526 +#define FOR_EACH_ROLE_END(role) \
62527 + role = role->prev; \
62528 + }
62529 +
62530 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
62531 + subj = NULL; \
62532 + iter = 0; \
62533 + while (iter < role->subj_hash_size) { \
62534 + if (subj == NULL) \
62535 + subj = role->subj_hash[iter]; \
62536 + if (subj == NULL) { \
62537 + iter++; \
62538 + continue; \
62539 + }
62540 +
62541 +#define FOR_EACH_SUBJECT_END(subj,iter) \
62542 + subj = subj->next; \
62543 + if (subj == NULL) \
62544 + iter++; \
62545 + }
62546 +
62547 +
62548 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
62549 + subj = role->hash->first; \
62550 + while (subj != NULL) {
62551 +
62552 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
62553 + subj = subj->next; \
62554 + }
62555 +
62556 +#endif
62557 +
62558 diff -urNp linux-2.6.39/include/linux/gralloc.h linux-2.6.39/include/linux/gralloc.h
62559 --- linux-2.6.39/include/linux/gralloc.h 1969-12-31 19:00:00.000000000 -0500
62560 +++ linux-2.6.39/include/linux/gralloc.h 2011-05-22 19:41:42.000000000 -0400
62561 @@ -0,0 +1,9 @@
62562 +#ifndef __GRALLOC_H
62563 +#define __GRALLOC_H
62564 +
62565 +void acl_free_all(void);
62566 +int acl_alloc_stack_init(unsigned long size);
62567 +void *acl_alloc(unsigned long len);
62568 +void *acl_alloc_num(unsigned long num, unsigned long len);
62569 +
62570 +#endif
62571 diff -urNp linux-2.6.39/include/linux/grdefs.h linux-2.6.39/include/linux/grdefs.h
62572 --- linux-2.6.39/include/linux/grdefs.h 1969-12-31 19:00:00.000000000 -0500
62573 +++ linux-2.6.39/include/linux/grdefs.h 2011-05-22 19:41:42.000000000 -0400
62574 @@ -0,0 +1,139 @@
62575 +#ifndef GRDEFS_H
62576 +#define GRDEFS_H
62577 +
62578 +/* Begin grsecurity status declarations */
62579 +
62580 +enum {
62581 + GR_READY = 0x01,
62582 + GR_STATUS_INIT = 0x00 // disabled state
62583 +};
62584 +
62585 +/* Begin ACL declarations */
62586 +
62587 +/* Role flags */
62588 +
62589 +enum {
62590 + GR_ROLE_USER = 0x0001,
62591 + GR_ROLE_GROUP = 0x0002,
62592 + GR_ROLE_DEFAULT = 0x0004,
62593 + GR_ROLE_SPECIAL = 0x0008,
62594 + GR_ROLE_AUTH = 0x0010,
62595 + GR_ROLE_NOPW = 0x0020,
62596 + GR_ROLE_GOD = 0x0040,
62597 + GR_ROLE_LEARN = 0x0080,
62598 + GR_ROLE_TPE = 0x0100,
62599 + GR_ROLE_DOMAIN = 0x0200,
62600 + GR_ROLE_PAM = 0x0400,
62601 + GR_ROLE_PERSIST = 0x0800
62602 +};
62603 +
62604 +/* ACL Subject and Object mode flags */
62605 +enum {
62606 + GR_DELETED = 0x80000000
62607 +};
62608 +
62609 +/* ACL Object-only mode flags */
62610 +enum {
62611 + GR_READ = 0x00000001,
62612 + GR_APPEND = 0x00000002,
62613 + GR_WRITE = 0x00000004,
62614 + GR_EXEC = 0x00000008,
62615 + GR_FIND = 0x00000010,
62616 + GR_INHERIT = 0x00000020,
62617 + GR_SETID = 0x00000040,
62618 + GR_CREATE = 0x00000080,
62619 + GR_DELETE = 0x00000100,
62620 + GR_LINK = 0x00000200,
62621 + GR_AUDIT_READ = 0x00000400,
62622 + GR_AUDIT_APPEND = 0x00000800,
62623 + GR_AUDIT_WRITE = 0x00001000,
62624 + GR_AUDIT_EXEC = 0x00002000,
62625 + GR_AUDIT_FIND = 0x00004000,
62626 + GR_AUDIT_INHERIT= 0x00008000,
62627 + GR_AUDIT_SETID = 0x00010000,
62628 + GR_AUDIT_CREATE = 0x00020000,
62629 + GR_AUDIT_DELETE = 0x00040000,
62630 + GR_AUDIT_LINK = 0x00080000,
62631 + GR_PTRACERD = 0x00100000,
62632 + GR_NOPTRACE = 0x00200000,
62633 + GR_SUPPRESS = 0x00400000,
62634 + GR_NOLEARN = 0x00800000,
62635 + GR_INIT_TRANSFER= 0x01000000
62636 +};
62637 +
62638 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
62639 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
62640 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
62641 +
62642 +/* ACL subject-only mode flags */
62643 +enum {
62644 + GR_KILL = 0x00000001,
62645 + GR_VIEW = 0x00000002,
62646 + GR_PROTECTED = 0x00000004,
62647 + GR_LEARN = 0x00000008,
62648 + GR_OVERRIDE = 0x00000010,
62649 + /* just a placeholder, this mode is only used in userspace */
62650 + GR_DUMMY = 0x00000020,
62651 + GR_PROTSHM = 0x00000040,
62652 + GR_KILLPROC = 0x00000080,
62653 + GR_KILLIPPROC = 0x00000100,
62654 + /* just a placeholder, this mode is only used in userspace */
62655 + GR_NOTROJAN = 0x00000200,
62656 + GR_PROTPROCFD = 0x00000400,
62657 + GR_PROCACCT = 0x00000800,
62658 + GR_RELAXPTRACE = 0x00001000,
62659 + GR_NESTED = 0x00002000,
62660 + GR_INHERITLEARN = 0x00004000,
62661 + GR_PROCFIND = 0x00008000,
62662 + GR_POVERRIDE = 0x00010000,
62663 + GR_KERNELAUTH = 0x00020000,
62664 + GR_ATSECURE = 0x00040000
62665 +};
62666 +
62667 +enum {
62668 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
62669 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
62670 + GR_PAX_ENABLE_MPROTECT = 0x0004,
62671 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
62672 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
62673 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
62674 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
62675 + GR_PAX_DISABLE_MPROTECT = 0x0400,
62676 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
62677 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
62678 +};
62679 +
62680 +enum {
62681 + GR_ID_USER = 0x01,
62682 + GR_ID_GROUP = 0x02,
62683 +};
62684 +
62685 +enum {
62686 + GR_ID_ALLOW = 0x01,
62687 + GR_ID_DENY = 0x02,
62688 +};
62689 +
62690 +#define GR_CRASH_RES 31
62691 +#define GR_UIDTABLE_MAX 500
62692 +
62693 +/* begin resource learning section */
62694 +enum {
62695 + GR_RLIM_CPU_BUMP = 60,
62696 + GR_RLIM_FSIZE_BUMP = 50000,
62697 + GR_RLIM_DATA_BUMP = 10000,
62698 + GR_RLIM_STACK_BUMP = 1000,
62699 + GR_RLIM_CORE_BUMP = 10000,
62700 + GR_RLIM_RSS_BUMP = 500000,
62701 + GR_RLIM_NPROC_BUMP = 1,
62702 + GR_RLIM_NOFILE_BUMP = 5,
62703 + GR_RLIM_MEMLOCK_BUMP = 50000,
62704 + GR_RLIM_AS_BUMP = 500000,
62705 + GR_RLIM_LOCKS_BUMP = 2,
62706 + GR_RLIM_SIGPENDING_BUMP = 5,
62707 + GR_RLIM_MSGQUEUE_BUMP = 10000,
62708 + GR_RLIM_NICE_BUMP = 1,
62709 + GR_RLIM_RTPRIO_BUMP = 1,
62710 + GR_RLIM_RTTIME_BUMP = 1000000
62711 +};
62712 +
62713 +#endif
62714 diff -urNp linux-2.6.39/include/linux/grinternal.h linux-2.6.39/include/linux/grinternal.h
62715 --- linux-2.6.39/include/linux/grinternal.h 1969-12-31 19:00:00.000000000 -0500
62716 +++ linux-2.6.39/include/linux/grinternal.h 2011-05-22 19:41:42.000000000 -0400
62717 @@ -0,0 +1,219 @@
62718 +#ifndef __GRINTERNAL_H
62719 +#define __GRINTERNAL_H
62720 +
62721 +#ifdef CONFIG_GRKERNSEC
62722 +
62723 +#include <linux/fs.h>
62724 +#include <linux/mnt_namespace.h>
62725 +#include <linux/nsproxy.h>
62726 +#include <linux/gracl.h>
62727 +#include <linux/grdefs.h>
62728 +#include <linux/grmsg.h>
62729 +
62730 +void gr_add_learn_entry(const char *fmt, ...)
62731 + __attribute__ ((format (printf, 1, 2)));
62732 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
62733 + const struct vfsmount *mnt);
62734 +__u32 gr_check_create(const struct dentry *new_dentry,
62735 + const struct dentry *parent,
62736 + const struct vfsmount *mnt, const __u32 mode);
62737 +int gr_check_protected_task(const struct task_struct *task);
62738 +__u32 to_gr_audit(const __u32 reqmode);
62739 +int gr_set_acls(const int type);
62740 +int gr_apply_subject_to_task(struct task_struct *task);
62741 +int gr_acl_is_enabled(void);
62742 +char gr_roletype_to_char(void);
62743 +
62744 +void gr_handle_alertkill(struct task_struct *task);
62745 +char *gr_to_filename(const struct dentry *dentry,
62746 + const struct vfsmount *mnt);
62747 +char *gr_to_filename1(const struct dentry *dentry,
62748 + const struct vfsmount *mnt);
62749 +char *gr_to_filename2(const struct dentry *dentry,
62750 + const struct vfsmount *mnt);
62751 +char *gr_to_filename3(const struct dentry *dentry,
62752 + const struct vfsmount *mnt);
62753 +
62754 +extern int grsec_enable_harden_ptrace;
62755 +extern int grsec_enable_link;
62756 +extern int grsec_enable_fifo;
62757 +extern int grsec_enable_execve;
62758 +extern int grsec_enable_shm;
62759 +extern int grsec_enable_execlog;
62760 +extern int grsec_enable_signal;
62761 +extern int grsec_enable_audit_ptrace;
62762 +extern int grsec_enable_forkfail;
62763 +extern int grsec_enable_time;
62764 +extern int grsec_enable_rofs;
62765 +extern int grsec_enable_chroot_shmat;
62766 +extern int grsec_enable_chroot_findtask;
62767 +extern int grsec_enable_chroot_mount;
62768 +extern int grsec_enable_chroot_double;
62769 +extern int grsec_enable_chroot_pivot;
62770 +extern int grsec_enable_chroot_chdir;
62771 +extern int grsec_enable_chroot_chmod;
62772 +extern int grsec_enable_chroot_mknod;
62773 +extern int grsec_enable_chroot_fchdir;
62774 +extern int grsec_enable_chroot_nice;
62775 +extern int grsec_enable_chroot_execlog;
62776 +extern int grsec_enable_chroot_caps;
62777 +extern int grsec_enable_chroot_sysctl;
62778 +extern int grsec_enable_chroot_unix;
62779 +extern int grsec_enable_tpe;
62780 +extern int grsec_tpe_gid;
62781 +extern int grsec_enable_tpe_all;
62782 +extern int grsec_enable_tpe_invert;
62783 +extern int grsec_enable_socket_all;
62784 +extern int grsec_socket_all_gid;
62785 +extern int grsec_enable_socket_client;
62786 +extern int grsec_socket_client_gid;
62787 +extern int grsec_enable_socket_server;
62788 +extern int grsec_socket_server_gid;
62789 +extern int grsec_audit_gid;
62790 +extern int grsec_enable_group;
62791 +extern int grsec_enable_audit_textrel;
62792 +extern int grsec_enable_log_rwxmaps;
62793 +extern int grsec_enable_mount;
62794 +extern int grsec_enable_chdir;
62795 +extern int grsec_resource_logging;
62796 +extern int grsec_enable_blackhole;
62797 +extern int grsec_lastack_retries;
62798 +extern int grsec_lock;
62799 +
62800 +extern spinlock_t grsec_alert_lock;
62801 +extern unsigned long grsec_alert_wtime;
62802 +extern unsigned long grsec_alert_fyet;
62803 +
62804 +extern spinlock_t grsec_audit_lock;
62805 +
62806 +extern rwlock_t grsec_exec_file_lock;
62807 +
62808 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
62809 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
62810 + (tsk)->exec_file->f_vfsmnt) : "/")
62811 +
62812 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
62813 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
62814 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62815 +
62816 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
62817 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
62818 + (tsk)->exec_file->f_vfsmnt) : "/")
62819 +
62820 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
62821 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
62822 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62823 +
62824 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
62825 +
62826 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
62827 +
62828 +#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
62829 + (task)->pid, (cred)->uid, \
62830 + (cred)->euid, (cred)->gid, (cred)->egid, \
62831 + gr_parent_task_fullpath(task), \
62832 + (task)->real_parent->comm, (task)->real_parent->pid, \
62833 + (pcred)->uid, (pcred)->euid, \
62834 + (pcred)->gid, (pcred)->egid
62835 +
62836 +#define GR_CHROOT_CAPS {{ \
62837 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
62838 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
62839 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
62840 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
62841 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
62842 + CAP_TO_MASK(CAP_IPC_OWNER) , 0 }}
62843 +
62844 +#define security_learn(normal_msg,args...) \
62845 +({ \
62846 + read_lock(&grsec_exec_file_lock); \
62847 + gr_add_learn_entry(normal_msg "\n", ## args); \
62848 + read_unlock(&grsec_exec_file_lock); \
62849 +})
62850 +
62851 +enum {
62852 + GR_DO_AUDIT,
62853 + GR_DONT_AUDIT,
62854 + /* used for non-audit messages that we shouldn't kill the task on */
62855 + GR_DONT_AUDIT_GOOD
62856 +};
62857 +
62858 +enum {
62859 + GR_TTYSNIFF,
62860 + GR_RBAC,
62861 + GR_RBAC_STR,
62862 + GR_STR_RBAC,
62863 + GR_RBAC_MODE2,
62864 + GR_RBAC_MODE3,
62865 + GR_FILENAME,
62866 + GR_SYSCTL_HIDDEN,
62867 + GR_NOARGS,
62868 + GR_ONE_INT,
62869 + GR_ONE_INT_TWO_STR,
62870 + GR_ONE_STR,
62871 + GR_STR_INT,
62872 + GR_TWO_STR_INT,
62873 + GR_TWO_INT,
62874 + GR_TWO_U64,
62875 + GR_THREE_INT,
62876 + GR_FIVE_INT_TWO_STR,
62877 + GR_TWO_STR,
62878 + GR_THREE_STR,
62879 + GR_FOUR_STR,
62880 + GR_STR_FILENAME,
62881 + GR_FILENAME_STR,
62882 + GR_FILENAME_TWO_INT,
62883 + GR_FILENAME_TWO_INT_STR,
62884 + GR_TEXTREL,
62885 + GR_PTRACE,
62886 + GR_RESOURCE,
62887 + GR_CAP,
62888 + GR_SIG,
62889 + GR_SIG2,
62890 + GR_CRASH1,
62891 + GR_CRASH2,
62892 + GR_PSACCT,
62893 + GR_RWXMAP
62894 +};
62895 +
62896 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
62897 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
62898 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
62899 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
62900 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
62901 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
62902 +#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)
62903 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
62904 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
62905 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
62906 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
62907 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
62908 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
62909 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
62910 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
62911 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
62912 +#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)
62913 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
62914 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
62915 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
62916 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
62917 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
62918 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
62919 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
62920 +#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)
62921 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
62922 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
62923 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
62924 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
62925 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
62926 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
62927 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
62928 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
62929 +#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)
62930 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
62931 +
62932 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
62933 +
62934 +#endif
62935 +
62936 +#endif
62937 diff -urNp linux-2.6.39/include/linux/grmsg.h linux-2.6.39/include/linux/grmsg.h
62938 --- linux-2.6.39/include/linux/grmsg.h 1969-12-31 19:00:00.000000000 -0500
62939 +++ linux-2.6.39/include/linux/grmsg.h 2011-05-22 19:41:42.000000000 -0400
62940 @@ -0,0 +1,108 @@
62941 +#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"
62942 +#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"
62943 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
62944 +#define GR_STOPMOD_MSG "denied modification of module state by "
62945 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
62946 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
62947 +#define GR_IOPERM_MSG "denied use of ioperm() by "
62948 +#define GR_IOPL_MSG "denied use of iopl() by "
62949 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
62950 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
62951 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
62952 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
62953 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
62954 +#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"
62955 +#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"
62956 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
62957 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
62958 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
62959 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
62960 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
62961 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
62962 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
62963 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
62964 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
62965 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
62966 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
62967 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
62968 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
62969 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
62970 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
62971 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
62972 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
62973 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
62974 +#define GR_NPROC_MSG "denied overstep of process limit by "
62975 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
62976 +#define GR_EXEC_TPE_MSG "denied untrusted exec of %.950s by "
62977 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
62978 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
62979 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
62980 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
62981 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
62982 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
62983 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
62984 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
62985 +#define GR_FCHMOD_ACL_MSG "%s fchmod of %.950s by "
62986 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
62987 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
62988 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
62989 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
62990 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
62991 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
62992 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
62993 +#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"
62994 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbaged by "
62995 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
62996 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
62997 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
62998 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
62999 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
63000 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
63001 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
63002 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
63003 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
63004 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
63005 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
63006 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
63007 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
63008 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
63009 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
63010 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
63011 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
63012 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
63013 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
63014 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
63015 +#define GR_NICE_CHROOT_MSG "denied priority change by "
63016 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
63017 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
63018 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
63019 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
63020 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
63021 +#define GR_TIME_MSG "time set by "
63022 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
63023 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
63024 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
63025 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
63026 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
63027 +#define GR_BIND_MSG "denied bind() by "
63028 +#define GR_CONNECT_MSG "denied connect() by "
63029 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
63030 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
63031 +#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"
63032 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
63033 +#define GR_CAP_ACL_MSG "use of %s denied for "
63034 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
63035 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
63036 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
63037 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
63038 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
63039 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
63040 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
63041 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
63042 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
63043 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
63044 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
63045 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
63046 +#define GR_VM86_MSG "denied use of vm86 by "
63047 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
63048 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
63049 diff -urNp linux-2.6.39/include/linux/grsecurity.h linux-2.6.39/include/linux/grsecurity.h
63050 --- linux-2.6.39/include/linux/grsecurity.h 1969-12-31 19:00:00.000000000 -0500
63051 +++ linux-2.6.39/include/linux/grsecurity.h 2011-05-22 19:41:42.000000000 -0400
63052 @@ -0,0 +1,212 @@
63053 +#ifndef GR_SECURITY_H
63054 +#define GR_SECURITY_H
63055 +#include <linux/fs.h>
63056 +#include <linux/fs_struct.h>
63057 +#include <linux/binfmts.h>
63058 +#include <linux/gracl.h>
63059 +#include <linux/compat.h>
63060 +
63061 +/* notify of brain-dead configs */
63062 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
63063 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
63064 +#endif
63065 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
63066 +#error "CONFIG_PAX_NOEXEC enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled."
63067 +#endif
63068 +#if defined(CONFIG_PAX_ASLR) && (defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
63069 +#error "CONFIG_PAX_ASLR enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled."
63070 +#endif
63071 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
63072 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
63073 +#endif
63074 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
63075 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
63076 +#endif
63077 +
63078 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
63079 +void gr_handle_brute_check(void);
63080 +void gr_handle_kernel_exploit(void);
63081 +int gr_process_user_ban(void);
63082 +
63083 +char gr_roletype_to_char(void);
63084 +
63085 +int gr_acl_enable_at_secure(void);
63086 +
63087 +int gr_check_user_change(int real, int effective, int fs);
63088 +int gr_check_group_change(int real, int effective, int fs);
63089 +
63090 +void gr_del_task_from_ip_table(struct task_struct *p);
63091 +
63092 +int gr_pid_is_chrooted(struct task_struct *p);
63093 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
63094 +int gr_handle_chroot_nice(void);
63095 +int gr_handle_chroot_sysctl(const int op);
63096 +int gr_handle_chroot_setpriority(struct task_struct *p,
63097 + const int niceval);
63098 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
63099 +int gr_handle_chroot_chroot(const struct dentry *dentry,
63100 + const struct vfsmount *mnt);
63101 +int gr_handle_chroot_caps(struct path *path);
63102 +void gr_handle_chroot_chdir(struct path *path);
63103 +int gr_handle_chroot_chmod(const struct dentry *dentry,
63104 + const struct vfsmount *mnt, const int mode);
63105 +int gr_handle_chroot_mknod(const struct dentry *dentry,
63106 + const struct vfsmount *mnt, const int mode);
63107 +int gr_handle_chroot_mount(const struct dentry *dentry,
63108 + const struct vfsmount *mnt,
63109 + const char *dev_name);
63110 +int gr_handle_chroot_pivot(void);
63111 +int gr_handle_chroot_unix(struct pid *pid);
63112 +
63113 +int gr_handle_rawio(const struct inode *inode);
63114 +int gr_handle_nproc(void);
63115 +
63116 +void gr_handle_ioperm(void);
63117 +void gr_handle_iopl(void);
63118 +
63119 +int gr_tpe_allow(const struct file *file);
63120 +
63121 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
63122 +void gr_clear_chroot_entries(struct task_struct *task);
63123 +
63124 +void gr_log_forkfail(const int retval);
63125 +void gr_log_timechange(void);
63126 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
63127 +void gr_log_chdir(const struct dentry *dentry,
63128 + const struct vfsmount *mnt);
63129 +void gr_log_chroot_exec(const struct dentry *dentry,
63130 + const struct vfsmount *mnt);
63131 +void gr_handle_exec_args(struct linux_binprm *bprm, const char __user *const __user *argv);
63132 +#ifdef CONFIG_COMPAT
63133 +void gr_handle_exec_args_compat(struct linux_binprm *bprm, compat_uptr_t __user *argv);
63134 +#endif
63135 +void gr_log_remount(const char *devname, const int retval);
63136 +void gr_log_unmount(const char *devname, const int retval);
63137 +void gr_log_mount(const char *from, const char *to, const int retval);
63138 +void gr_log_textrel(struct vm_area_struct *vma);
63139 +void gr_log_rwxmmap(struct file *file);
63140 +void gr_log_rwxmprotect(struct file *file);
63141 +
63142 +int gr_handle_follow_link(const struct inode *parent,
63143 + const struct inode *inode,
63144 + const struct dentry *dentry,
63145 + const struct vfsmount *mnt);
63146 +int gr_handle_fifo(const struct dentry *dentry,
63147 + const struct vfsmount *mnt,
63148 + const struct dentry *dir, const int flag,
63149 + const int acc_mode);
63150 +int gr_handle_hardlink(const struct dentry *dentry,
63151 + const struct vfsmount *mnt,
63152 + struct inode *inode,
63153 + const int mode, const char *to);
63154 +
63155 +int gr_is_capable(const int cap);
63156 +int gr_is_capable_nolog(const int cap);
63157 +void gr_learn_resource(const struct task_struct *task, const int limit,
63158 + const unsigned long wanted, const int gt);
63159 +void gr_copy_label(struct task_struct *tsk);
63160 +void gr_handle_crash(struct task_struct *task, const int sig);
63161 +int gr_handle_signal(const struct task_struct *p, const int sig);
63162 +int gr_check_crash_uid(const uid_t uid);
63163 +int gr_check_protected_task(const struct task_struct *task);
63164 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
63165 +int gr_acl_handle_mmap(const struct file *file,
63166 + const unsigned long prot);
63167 +int gr_acl_handle_mprotect(const struct file *file,
63168 + const unsigned long prot);
63169 +int gr_check_hidden_task(const struct task_struct *tsk);
63170 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
63171 + const struct vfsmount *mnt);
63172 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
63173 + const struct vfsmount *mnt);
63174 +__u32 gr_acl_handle_access(const struct dentry *dentry,
63175 + const struct vfsmount *mnt, const int fmode);
63176 +__u32 gr_acl_handle_fchmod(const struct dentry *dentry,
63177 + const struct vfsmount *mnt, mode_t mode);
63178 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
63179 + const struct vfsmount *mnt, mode_t mode);
63180 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
63181 + const struct vfsmount *mnt);
63182 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
63183 + const struct vfsmount *mnt);
63184 +int gr_handle_ptrace(struct task_struct *task, const long request);
63185 +int gr_handle_proc_ptrace(struct task_struct *task);
63186 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
63187 + const struct vfsmount *mnt);
63188 +int gr_check_crash_exec(const struct file *filp);
63189 +int gr_acl_is_enabled(void);
63190 +void gr_set_kernel_label(struct task_struct *task);
63191 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
63192 + const gid_t gid);
63193 +int gr_set_proc_label(const struct dentry *dentry,
63194 + const struct vfsmount *mnt,
63195 + const int unsafe_share);
63196 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
63197 + const struct vfsmount *mnt);
63198 +__u32 gr_acl_handle_open(const struct dentry *dentry,
63199 + const struct vfsmount *mnt, const int fmode);
63200 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
63201 + const struct dentry *p_dentry,
63202 + const struct vfsmount *p_mnt, const int fmode,
63203 + const int imode);
63204 +void gr_handle_create(const struct dentry *dentry,
63205 + const struct vfsmount *mnt);
63206 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
63207 + const struct dentry *parent_dentry,
63208 + const struct vfsmount *parent_mnt,
63209 + const int mode);
63210 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
63211 + const struct dentry *parent_dentry,
63212 + const struct vfsmount *parent_mnt);
63213 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
63214 + const struct vfsmount *mnt);
63215 +void gr_handle_delete(const ino_t ino, const dev_t dev);
63216 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
63217 + const struct vfsmount *mnt);
63218 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
63219 + const struct dentry *parent_dentry,
63220 + const struct vfsmount *parent_mnt,
63221 + const char *from);
63222 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
63223 + const struct dentry *parent_dentry,
63224 + const struct vfsmount *parent_mnt,
63225 + const struct dentry *old_dentry,
63226 + const struct vfsmount *old_mnt, const char *to);
63227 +int gr_acl_handle_rename(struct dentry *new_dentry,
63228 + struct dentry *parent_dentry,
63229 + const struct vfsmount *parent_mnt,
63230 + struct dentry *old_dentry,
63231 + struct inode *old_parent_inode,
63232 + struct vfsmount *old_mnt, const char *newname);
63233 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
63234 + struct dentry *old_dentry,
63235 + struct dentry *new_dentry,
63236 + struct vfsmount *mnt, const __u8 replace);
63237 +__u32 gr_check_link(const struct dentry *new_dentry,
63238 + const struct dentry *parent_dentry,
63239 + const struct vfsmount *parent_mnt,
63240 + const struct dentry *old_dentry,
63241 + const struct vfsmount *old_mnt);
63242 +int gr_acl_handle_filldir(const struct file *file, const char *name,
63243 + const unsigned int namelen, const ino_t ino);
63244 +
63245 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
63246 + const struct vfsmount *mnt);
63247 +void gr_acl_handle_exit(void);
63248 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
63249 +int gr_acl_handle_procpidmem(const struct task_struct *task);
63250 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
63251 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
63252 +void gr_audit_ptrace(struct task_struct *task);
63253 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
63254 +
63255 +#ifdef CONFIG_GRKERNSEC
63256 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
63257 +void gr_handle_vm86(void);
63258 +void gr_handle_mem_readwrite(u64 from, u64 to);
63259 +
63260 +extern int grsec_enable_dmesg;
63261 +extern int grsec_disable_privio;
63262 +#endif
63263 +
63264 +#endif
63265 diff -urNp linux-2.6.39/include/linux/grsock.h linux-2.6.39/include/linux/grsock.h
63266 --- linux-2.6.39/include/linux/grsock.h 1969-12-31 19:00:00.000000000 -0500
63267 +++ linux-2.6.39/include/linux/grsock.h 2011-05-22 19:41:42.000000000 -0400
63268 @@ -0,0 +1,19 @@
63269 +#ifndef __GRSOCK_H
63270 +#define __GRSOCK_H
63271 +
63272 +extern void gr_attach_curr_ip(const struct sock *sk);
63273 +extern int gr_handle_sock_all(const int family, const int type,
63274 + const int protocol);
63275 +extern int gr_handle_sock_server(const struct sockaddr *sck);
63276 +extern int gr_handle_sock_server_other(const struct sock *sck);
63277 +extern int gr_handle_sock_client(const struct sockaddr *sck);
63278 +extern int gr_search_connect(struct socket * sock,
63279 + struct sockaddr_in * addr);
63280 +extern int gr_search_bind(struct socket * sock,
63281 + struct sockaddr_in * addr);
63282 +extern int gr_search_listen(struct socket * sock);
63283 +extern int gr_search_accept(struct socket * sock);
63284 +extern int gr_search_socket(const int domain, const int type,
63285 + const int protocol);
63286 +
63287 +#endif
63288 diff -urNp linux-2.6.39/include/linux/highmem.h linux-2.6.39/include/linux/highmem.h
63289 --- linux-2.6.39/include/linux/highmem.h 2011-05-19 00:06:34.000000000 -0400
63290 +++ linux-2.6.39/include/linux/highmem.h 2011-05-22 19:36:33.000000000 -0400
63291 @@ -185,6 +185,18 @@ static inline void clear_highpage(struct
63292 kunmap_atomic(kaddr, KM_USER0);
63293 }
63294
63295 +static inline void sanitize_highpage(struct page *page)
63296 +{
63297 + void *kaddr;
63298 + unsigned long flags;
63299 +
63300 + local_irq_save(flags);
63301 + kaddr = kmap_atomic(page, KM_CLEARPAGE);
63302 + clear_page(kaddr);
63303 + kunmap_atomic(kaddr, KM_CLEARPAGE);
63304 + local_irq_restore(flags);
63305 +}
63306 +
63307 static inline void zero_user_segments(struct page *page,
63308 unsigned start1, unsigned end1,
63309 unsigned start2, unsigned end2)
63310 diff -urNp linux-2.6.39/include/linux/i2o.h linux-2.6.39/include/linux/i2o.h
63311 --- linux-2.6.39/include/linux/i2o.h 2011-05-19 00:06:34.000000000 -0400
63312 +++ linux-2.6.39/include/linux/i2o.h 2011-05-22 19:36:33.000000000 -0400
63313 @@ -564,7 +564,7 @@ struct i2o_controller {
63314 struct i2o_device *exec; /* Executive */
63315 #if BITS_PER_LONG == 64
63316 spinlock_t context_list_lock; /* lock for context_list */
63317 - atomic_t context_list_counter; /* needed for unique contexts */
63318 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
63319 struct list_head context_list; /* list of context id's
63320 and pointers */
63321 #endif
63322 diff -urNp linux-2.6.39/include/linux/if_phonet.h linux-2.6.39/include/linux/if_phonet.h
63323 --- linux-2.6.39/include/linux/if_phonet.h 2011-05-19 00:06:34.000000000 -0400
63324 +++ linux-2.6.39/include/linux/if_phonet.h 2011-05-22 19:36:33.000000000 -0400
63325 @@ -13,7 +13,7 @@
63326 #define PHONET_DEV_MTU PHONET_MAX_MTU
63327
63328 #ifdef __KERNEL__
63329 -extern struct header_ops phonet_header_ops;
63330 +extern const struct header_ops phonet_header_ops;
63331 #endif
63332
63333 #endif
63334 diff -urNp linux-2.6.39/include/linux/init.h linux-2.6.39/include/linux/init.h
63335 --- linux-2.6.39/include/linux/init.h 2011-05-19 00:06:34.000000000 -0400
63336 +++ linux-2.6.39/include/linux/init.h 2011-05-22 19:36:33.000000000 -0400
63337 @@ -293,13 +293,13 @@ void __init parse_early_options(char *cm
63338
63339 /* Each module must use one module_init(). */
63340 #define module_init(initfn) \
63341 - static inline initcall_t __inittest(void) \
63342 + static inline __used initcall_t __inittest(void) \
63343 { return initfn; } \
63344 int init_module(void) __attribute__((alias(#initfn)));
63345
63346 /* This is only required if you want to be unloadable. */
63347 #define module_exit(exitfn) \
63348 - static inline exitcall_t __exittest(void) \
63349 + static inline __used exitcall_t __exittest(void) \
63350 { return exitfn; } \
63351 void cleanup_module(void) __attribute__((alias(#exitfn)));
63352
63353 diff -urNp linux-2.6.39/include/linux/init_task.h linux-2.6.39/include/linux/init_task.h
63354 --- linux-2.6.39/include/linux/init_task.h 2011-05-19 00:06:34.000000000 -0400
63355 +++ linux-2.6.39/include/linux/init_task.h 2011-05-22 19:36:33.000000000 -0400
63356 @@ -83,6 +83,12 @@ extern struct group_info init_groups;
63357 #define INIT_IDS
63358 #endif
63359
63360 +#ifdef CONFIG_X86
63361 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
63362 +#else
63363 +#define INIT_TASK_THREAD_INFO
63364 +#endif
63365 +
63366 /*
63367 * Because of the reduced scope of CAP_SETPCAP when filesystem
63368 * capabilities are in effect, it is safe to allow CAP_SETPCAP to
63369 @@ -163,6 +169,7 @@ extern struct cred init_cred;
63370 RCU_INIT_POINTER(.cred, &init_cred), \
63371 .comm = "swapper", \
63372 .thread = INIT_THREAD, \
63373 + INIT_TASK_THREAD_INFO \
63374 .fs = &init_fs, \
63375 .files = &init_files, \
63376 .signal = &init_signals, \
63377 diff -urNp linux-2.6.39/include/linux/interrupt.h linux-2.6.39/include/linux/interrupt.h
63378 --- linux-2.6.39/include/linux/interrupt.h 2011-05-19 00:06:34.000000000 -0400
63379 +++ linux-2.6.39/include/linux/interrupt.h 2011-05-22 19:36:33.000000000 -0400
63380 @@ -422,7 +422,7 @@ enum
63381 /* map softirq index to softirq name. update 'softirq_to_name' in
63382 * kernel/softirq.c when adding a new softirq.
63383 */
63384 -extern char *softirq_to_name[NR_SOFTIRQS];
63385 +extern const char * const softirq_to_name[NR_SOFTIRQS];
63386
63387 /* softirq mask and active fields moved to irq_cpustat_t in
63388 * asm/hardirq.h to get better cache usage. KAO
63389 @@ -430,12 +430,12 @@ extern char *softirq_to_name[NR_SOFTIRQS
63390
63391 struct softirq_action
63392 {
63393 - void (*action)(struct softirq_action *);
63394 + void (*action)(void);
63395 };
63396
63397 asmlinkage void do_softirq(void);
63398 asmlinkage void __do_softirq(void);
63399 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
63400 +extern void open_softirq(int nr, void (*action)(void));
63401 extern void softirq_init(void);
63402 static inline void __raise_softirq_irqoff(unsigned int nr)
63403 {
63404 diff -urNp linux-2.6.39/include/linux/iommu.h linux-2.6.39/include/linux/iommu.h
63405 --- linux-2.6.39/include/linux/iommu.h 2011-05-19 00:06:34.000000000 -0400
63406 +++ linux-2.6.39/include/linux/iommu.h 2011-05-22 19:36:33.000000000 -0400
63407 @@ -49,7 +49,7 @@ struct iommu_ops {
63408
63409 #ifdef CONFIG_IOMMU_API
63410
63411 -extern void register_iommu(struct iommu_ops *ops);
63412 +extern void register_iommu(const struct iommu_ops *ops);
63413 extern bool iommu_found(void);
63414 extern struct iommu_domain *iommu_domain_alloc(void);
63415 extern void iommu_domain_free(struct iommu_domain *domain);
63416 diff -urNp linux-2.6.39/include/linux/ipmi.h linux-2.6.39/include/linux/ipmi.h
63417 --- linux-2.6.39/include/linux/ipmi.h 2011-05-19 00:06:34.000000000 -0400
63418 +++ linux-2.6.39/include/linux/ipmi.h 2011-05-22 19:36:33.000000000 -0400
63419 @@ -282,7 +282,7 @@ struct ipmi_user_hndl {
63420
63421 /* Create a new user of the IPMI layer on the given interface number. */
63422 int ipmi_create_user(unsigned int if_num,
63423 - struct ipmi_user_hndl *handler,
63424 + const struct ipmi_user_hndl *handler,
63425 void *handler_data,
63426 ipmi_user_t *user);
63427
63428 diff -urNp linux-2.6.39/include/linux/kallsyms.h linux-2.6.39/include/linux/kallsyms.h
63429 --- linux-2.6.39/include/linux/kallsyms.h 2011-05-19 00:06:34.000000000 -0400
63430 +++ linux-2.6.39/include/linux/kallsyms.h 2011-05-22 22:52:54.000000000 -0400
63431 @@ -15,7 +15,8 @@
63432
63433 struct module;
63434
63435 -#ifdef CONFIG_KALLSYMS
63436 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
63437 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63438 /* Lookup the address for a symbol. Returns 0 if not found. */
63439 unsigned long kallsyms_lookup_name(const char *name);
63440
63441 @@ -99,6 +100,16 @@ static inline int lookup_symbol_attrs(un
63442 /* Stupid that this does nothing, but I didn't create this mess. */
63443 #define __print_symbol(fmt, addr)
63444 #endif /*CONFIG_KALLSYMS*/
63445 +#else /* when included by kallsyms.c, vsnprintf.c, or
63446 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
63447 +extern void __print_symbol(const char *fmt, unsigned long address);
63448 +extern int sprint_backtrace(char *buffer, unsigned long address);
63449 +extern int sprint_symbol(char *buffer, unsigned long address);
63450 +const char *kallsyms_lookup(unsigned long addr,
63451 + unsigned long *symbolsize,
63452 + unsigned long *offset,
63453 + char **modname, char *namebuf);
63454 +#endif
63455
63456 /* This macro allows us to keep printk typechecking */
63457 static void __check_printsym_format(const char *fmt, ...)
63458 diff -urNp linux-2.6.39/include/linux/kgdb.h linux-2.6.39/include/linux/kgdb.h
63459 --- linux-2.6.39/include/linux/kgdb.h 2011-05-19 00:06:34.000000000 -0400
63460 +++ linux-2.6.39/include/linux/kgdb.h 2011-05-22 19:36:33.000000000 -0400
63461 @@ -53,7 +53,7 @@ extern int kgdb_connected;
63462 extern int kgdb_io_module_registered;
63463
63464 extern atomic_t kgdb_setting_breakpoint;
63465 -extern atomic_t kgdb_cpu_doing_single_step;
63466 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
63467
63468 extern struct task_struct *kgdb_usethread;
63469 extern struct task_struct *kgdb_contthread;
63470 @@ -269,22 +269,22 @@ struct kgdb_arch {
63471 */
63472 struct kgdb_io {
63473 const char *name;
63474 - int (*read_char) (void);
63475 - void (*write_char) (u8);
63476 - void (*flush) (void);
63477 - int (*init) (void);
63478 - void (*pre_exception) (void);
63479 - void (*post_exception) (void);
63480 + int (* const read_char) (void);
63481 + void (* const write_char) (u8);
63482 + void (* const flush) (void);
63483 + int (* const init) (void);
63484 + void (* const pre_exception) (void);
63485 + void (* const post_exception) (void);
63486 int is_console;
63487 };
63488
63489 -extern struct kgdb_arch arch_kgdb_ops;
63490 +extern const struct kgdb_arch arch_kgdb_ops;
63491
63492 extern unsigned long __weak kgdb_arch_pc(int exception, struct pt_regs *regs);
63493
63494 -extern int kgdb_register_io_module(struct kgdb_io *local_kgdb_io_ops);
63495 -extern void kgdb_unregister_io_module(struct kgdb_io *local_kgdb_io_ops);
63496 -extern struct kgdb_io *dbg_io_ops;
63497 +extern int kgdb_register_io_module(const struct kgdb_io *local_kgdb_io_ops);
63498 +extern void kgdb_unregister_io_module(const struct kgdb_io *local_kgdb_io_ops);
63499 +extern const struct kgdb_io *dbg_io_ops;
63500
63501 extern int kgdb_hex2long(char **ptr, unsigned long *long_val);
63502 extern char *kgdb_mem2hex(char *mem, char *buf, int count);
63503 diff -urNp linux-2.6.39/include/linux/kmod.h linux-2.6.39/include/linux/kmod.h
63504 --- linux-2.6.39/include/linux/kmod.h 2011-05-19 00:06:34.000000000 -0400
63505 +++ linux-2.6.39/include/linux/kmod.h 2011-05-22 19:41:42.000000000 -0400
63506 @@ -33,6 +33,8 @@ extern char modprobe_path[]; /* for sysc
63507 * usually useless though. */
63508 extern int __request_module(bool wait, const char *name, ...) \
63509 __attribute__((format(printf, 2, 3)));
63510 +extern int ___request_module(bool wait, char *param_name, const char *name, ...) \
63511 + __attribute__((format(printf, 3, 4)));
63512 #define request_module(mod...) __request_module(true, mod)
63513 #define request_module_nowait(mod...) __request_module(false, mod)
63514 #define try_then_request_module(x, mod...) \
63515 diff -urNp linux-2.6.39/include/linux/kvm_host.h linux-2.6.39/include/linux/kvm_host.h
63516 --- linux-2.6.39/include/linux/kvm_host.h 2011-05-19 00:06:34.000000000 -0400
63517 +++ linux-2.6.39/include/linux/kvm_host.h 2011-05-22 19:36:33.000000000 -0400
63518 @@ -302,7 +302,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vc
63519 void vcpu_load(struct kvm_vcpu *vcpu);
63520 void vcpu_put(struct kvm_vcpu *vcpu);
63521
63522 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63523 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63524 struct module *module);
63525 void kvm_exit(void);
63526
63527 @@ -442,7 +442,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(
63528 struct kvm_guest_debug *dbg);
63529 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
63530
63531 -int kvm_arch_init(void *opaque);
63532 +int kvm_arch_init(const void *opaque);
63533 void kvm_arch_exit(void);
63534
63535 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
63536 diff -urNp linux-2.6.39/include/linux/lapb.h linux-2.6.39/include/linux/lapb.h
63537 --- linux-2.6.39/include/linux/lapb.h 2011-05-19 00:06:34.000000000 -0400
63538 +++ linux-2.6.39/include/linux/lapb.h 2011-05-22 19:36:33.000000000 -0400
63539 @@ -44,7 +44,7 @@ struct lapb_parms_struct {
63540 unsigned int mode;
63541 };
63542
63543 -extern int lapb_register(struct net_device *dev, struct lapb_register_struct *callbacks);
63544 +extern int lapb_register(struct net_device *dev, const struct lapb_register_struct *callbacks);
63545 extern int lapb_unregister(struct net_device *dev);
63546 extern int lapb_getparms(struct net_device *dev, struct lapb_parms_struct *parms);
63547 extern int lapb_setparms(struct net_device *dev, struct lapb_parms_struct *parms);
63548 diff -urNp linux-2.6.39/include/linux/lcd.h linux-2.6.39/include/linux/lcd.h
63549 --- linux-2.6.39/include/linux/lcd.h 2011-05-19 00:06:34.000000000 -0400
63550 +++ linux-2.6.39/include/linux/lcd.h 2011-05-22 19:36:33.000000000 -0400
63551 @@ -60,7 +60,7 @@ struct lcd_device {
63552 points to something in the body of that driver, it is also invalid. */
63553 struct mutex ops_lock;
63554 /* If this is NULL, the backing module is unloaded */
63555 - struct lcd_ops *ops;
63556 + const struct lcd_ops *ops;
63557 /* Serialise access to set_power method */
63558 struct mutex update_lock;
63559 /* The framebuffer notifier block */
63560 @@ -101,7 +101,7 @@ static inline void lcd_set_power(struct
63561 }
63562
63563 extern struct lcd_device *lcd_device_register(const char *name,
63564 - struct device *parent, void *devdata, struct lcd_ops *ops);
63565 + struct device *parent, void *devdata, const struct lcd_ops *ops);
63566 extern void lcd_device_unregister(struct lcd_device *ld);
63567
63568 #define to_lcd_device(obj) container_of(obj, struct lcd_device, dev)
63569 diff -urNp linux-2.6.39/include/linux/libata.h linux-2.6.39/include/linux/libata.h
63570 --- linux-2.6.39/include/linux/libata.h 2011-05-19 00:06:34.000000000 -0400
63571 +++ linux-2.6.39/include/linux/libata.h 2011-05-22 19:36:33.000000000 -0400
63572 @@ -524,11 +524,11 @@ struct ata_ioports {
63573
63574 struct ata_host {
63575 spinlock_t lock;
63576 - struct device *dev;
63577 + struct device *dev;
63578 void __iomem * const *iomap;
63579 unsigned int n_ports;
63580 void *private_data;
63581 - struct ata_port_operations *ops;
63582 + const struct ata_port_operations *ops;
63583 unsigned long flags;
63584
63585 struct mutex eh_mutex;
63586 @@ -719,7 +719,7 @@ struct ata_link {
63587
63588 struct ata_port {
63589 struct Scsi_Host *scsi_host; /* our co-allocated scsi host */
63590 - struct ata_port_operations *ops;
63591 + const struct ata_port_operations *ops;
63592 spinlock_t *lock;
63593 /* Flags owned by the EH context. Only EH should touch these once the
63594 port is active */
63595 @@ -907,7 +907,7 @@ struct ata_port_info {
63596 unsigned long pio_mask;
63597 unsigned long mwdma_mask;
63598 unsigned long udma_mask;
63599 - struct ata_port_operations *port_ops;
63600 + const struct ata_port_operations *port_ops;
63601 void *private_data;
63602 };
63603
63604 @@ -931,7 +931,7 @@ extern const unsigned long sata_deb_timi
63605 extern const unsigned long sata_deb_timing_hotplug[];
63606 extern const unsigned long sata_deb_timing_long[];
63607
63608 -extern struct ata_port_operations ata_dummy_port_ops;
63609 +extern const struct ata_port_operations ata_dummy_port_ops;
63610 extern const struct ata_port_info ata_dummy_port_info;
63611
63612 static inline const unsigned long *
63613 @@ -977,7 +977,7 @@ extern int ata_host_activate(struct ata_
63614 struct scsi_host_template *sht);
63615 extern void ata_host_detach(struct ata_host *host);
63616 extern void ata_host_init(struct ata_host *, struct device *,
63617 - unsigned long, struct ata_port_operations *);
63618 + unsigned long, const struct ata_port_operations *);
63619 extern int ata_scsi_detect(struct scsi_host_template *sht);
63620 extern int ata_scsi_ioctl(struct scsi_device *dev, int cmd, void __user *arg);
63621 extern int ata_scsi_queuecmd(struct Scsi_Host *h, struct scsi_cmnd *cmd);
63622 diff -urNp linux-2.6.39/include/linux/lockd/bind.h linux-2.6.39/include/linux/lockd/bind.h
63623 --- linux-2.6.39/include/linux/lockd/bind.h 2011-05-19 00:06:34.000000000 -0400
63624 +++ linux-2.6.39/include/linux/lockd/bind.h 2011-05-22 19:36:33.000000000 -0400
63625 @@ -23,13 +23,13 @@ struct svc_rqst;
63626 * This is the set of functions for lockd->nfsd communication
63627 */
63628 struct nlmsvc_binding {
63629 - __be32 (*fopen)(struct svc_rqst *,
63630 + __be32 (* const fopen)(struct svc_rqst *,
63631 struct nfs_fh *,
63632 struct file **);
63633 - void (*fclose)(struct file *);
63634 + void (* const fclose)(struct file *);
63635 };
63636
63637 -extern struct nlmsvc_binding * nlmsvc_ops;
63638 +extern const struct nlmsvc_binding * nlmsvc_ops;
63639
63640 /*
63641 * Similar to nfs_client_initdata, but without the NFS-specific
63642 diff -urNp linux-2.6.39/include/linux/mfd/abx500.h linux-2.6.39/include/linux/mfd/abx500.h
63643 --- linux-2.6.39/include/linux/mfd/abx500.h 2011-05-19 00:06:34.000000000 -0400
63644 +++ linux-2.6.39/include/linux/mfd/abx500.h 2011-05-22 19:36:33.000000000 -0400
63645 @@ -227,6 +227,6 @@ struct abx500_ops {
63646 int (*startup_irq_enabled) (struct device *, unsigned int);
63647 };
63648
63649 -int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
63650 +int abx500_register_ops(struct device *core_dev, const struct abx500_ops *ops);
63651 void abx500_remove_ops(struct device *dev);
63652 #endif
63653 diff -urNp linux-2.6.39/include/linux/mm.h linux-2.6.39/include/linux/mm.h
63654 --- linux-2.6.39/include/linux/mm.h 2011-05-19 00:06:34.000000000 -0400
63655 +++ linux-2.6.39/include/linux/mm.h 2011-05-22 19:36:33.000000000 -0400
63656 @@ -113,7 +113,14 @@ extern unsigned int kobjsize(const void
63657
63658 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
63659 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
63660 +
63661 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
63662 +#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
63663 +#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
63664 +#else
63665 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
63666 +#endif
63667 +
63668 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
63669 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
63670
63671 @@ -1010,34 +1017,6 @@ int set_page_dirty(struct page *page);
63672 int set_page_dirty_lock(struct page *page);
63673 int clear_page_dirty_for_io(struct page *page);
63674
63675 -/* Is the vma a continuation of the stack vma above it? */
63676 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
63677 -{
63678 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
63679 -}
63680 -
63681 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
63682 - unsigned long addr)
63683 -{
63684 - return (vma->vm_flags & VM_GROWSDOWN) &&
63685 - (vma->vm_start == addr) &&
63686 - !vma_growsdown(vma->vm_prev, addr);
63687 -}
63688 -
63689 -/* Is the vma a continuation of the stack vma below it? */
63690 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
63691 -{
63692 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
63693 -}
63694 -
63695 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
63696 - unsigned long addr)
63697 -{
63698 - return (vma->vm_flags & VM_GROWSUP) &&
63699 - (vma->vm_end == addr) &&
63700 - !vma_growsup(vma->vm_next, addr);
63701 -}
63702 -
63703 extern unsigned long move_page_tables(struct vm_area_struct *vma,
63704 unsigned long old_addr, struct vm_area_struct *new_vma,
63705 unsigned long new_addr, unsigned long len);
63706 @@ -1189,6 +1168,15 @@ struct shrinker {
63707 extern void register_shrinker(struct shrinker *);
63708 extern void unregister_shrinker(struct shrinker *);
63709
63710 +#ifdef CONFIG_MMU
63711 +pgprot_t vm_get_page_prot(unsigned long vm_flags);
63712 +#else
63713 +static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
63714 +{
63715 + return __pgprot(0);
63716 +}
63717 +#endif
63718 +
63719 int vma_wants_writenotify(struct vm_area_struct *vma);
63720
63721 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
63722 @@ -1476,6 +1464,7 @@ out:
63723 }
63724
63725 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
63726 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
63727
63728 extern unsigned long do_brk(unsigned long, unsigned long);
63729
63730 @@ -1532,6 +1521,10 @@ extern struct vm_area_struct * find_vma(
63731 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
63732 struct vm_area_struct **pprev);
63733
63734 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
63735 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
63736 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
63737 +
63738 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
63739 NULL if none. Assume start_addr < end_addr. */
63740 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
63741 @@ -1548,15 +1541,6 @@ static inline unsigned long vma_pages(st
63742 return (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
63743 }
63744
63745 -#ifdef CONFIG_MMU
63746 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
63747 -#else
63748 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
63749 -{
63750 - return __pgprot(0);
63751 -}
63752 -#endif
63753 -
63754 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
63755 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
63756 unsigned long pfn, unsigned long size, pgprot_t);
63757 @@ -1668,7 +1652,7 @@ extern int unpoison_memory(unsigned long
63758 extern int sysctl_memory_failure_early_kill;
63759 extern int sysctl_memory_failure_recovery;
63760 extern void shake_page(struct page *p, int access);
63761 -extern atomic_long_t mce_bad_pages;
63762 +extern atomic_long_unchecked_t mce_bad_pages;
63763 extern int soft_offline_page(struct page *page, int flags);
63764
63765 extern void dump_page(struct page *page);
63766 @@ -1682,5 +1666,11 @@ extern void copy_user_huge_page(struct p
63767 unsigned int pages_per_huge_page);
63768 #endif /* CONFIG_TRANSPARENT_HUGEPAGE || CONFIG_HUGETLBFS */
63769
63770 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
63771 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
63772 +#else
63773 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
63774 +#endif
63775 +
63776 #endif /* __KERNEL__ */
63777 #endif /* _LINUX_MM_H */
63778 diff -urNp linux-2.6.39/include/linux/mm_types.h linux-2.6.39/include/linux/mm_types.h
63779 --- linux-2.6.39/include/linux/mm_types.h 2011-05-19 00:06:34.000000000 -0400
63780 +++ linux-2.6.39/include/linux/mm_types.h 2011-05-22 19:36:33.000000000 -0400
63781 @@ -183,6 +183,8 @@ struct vm_area_struct {
63782 #ifdef CONFIG_NUMA
63783 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
63784 #endif
63785 +
63786 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
63787 };
63788
63789 struct core_thread {
63790 @@ -317,6 +319,24 @@ struct mm_struct {
63791 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
63792 pgtable_t pmd_huge_pte; /* protected by page_table_lock */
63793 #endif
63794 +
63795 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63796 + unsigned long pax_flags;
63797 +#endif
63798 +
63799 +#ifdef CONFIG_PAX_DLRESOLVE
63800 + unsigned long call_dl_resolve;
63801 +#endif
63802 +
63803 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
63804 + unsigned long call_syscall;
63805 +#endif
63806 +
63807 +#ifdef CONFIG_PAX_ASLR
63808 + unsigned long delta_mmap; /* randomized offset */
63809 + unsigned long delta_stack; /* randomized offset */
63810 +#endif
63811 +
63812 };
63813
63814 /* Future-safe accessor for struct mm_struct's cpu_vm_mask. */
63815 diff -urNp linux-2.6.39/include/linux/mmu_notifier.h linux-2.6.39/include/linux/mmu_notifier.h
63816 --- linux-2.6.39/include/linux/mmu_notifier.h 2011-05-19 00:06:34.000000000 -0400
63817 +++ linux-2.6.39/include/linux/mmu_notifier.h 2011-05-22 19:36:33.000000000 -0400
63818 @@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destr
63819 */
63820 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
63821 ({ \
63822 - pte_t __pte; \
63823 + pte_t ___pte; \
63824 struct vm_area_struct *___vma = __vma; \
63825 unsigned long ___address = __address; \
63826 - __pte = ptep_clear_flush(___vma, ___address, __ptep); \
63827 + ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
63828 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
63829 - __pte; \
63830 + ___pte; \
63831 })
63832
63833 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
63834 diff -urNp linux-2.6.39/include/linux/mmzone.h linux-2.6.39/include/linux/mmzone.h
63835 --- linux-2.6.39/include/linux/mmzone.h 2011-05-19 00:06:34.000000000 -0400
63836 +++ linux-2.6.39/include/linux/mmzone.h 2011-05-22 19:36:33.000000000 -0400
63837 @@ -355,7 +355,7 @@ struct zone {
63838 unsigned long flags; /* zone flags, see below */
63839
63840 /* Zone statistics */
63841 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63842 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63843
63844 /*
63845 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
63846 diff -urNp linux-2.6.39/include/linux/mod_devicetable.h linux-2.6.39/include/linux/mod_devicetable.h
63847 --- linux-2.6.39/include/linux/mod_devicetable.h 2011-05-19 00:06:34.000000000 -0400
63848 +++ linux-2.6.39/include/linux/mod_devicetable.h 2011-05-22 19:36:33.000000000 -0400
63849 @@ -12,7 +12,7 @@
63850 typedef unsigned long kernel_ulong_t;
63851 #endif
63852
63853 -#define PCI_ANY_ID (~0)
63854 +#define PCI_ANY_ID ((__u16)~0)
63855
63856 struct pci_device_id {
63857 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
63858 @@ -131,7 +131,7 @@ struct usb_device_id {
63859 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
63860 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
63861
63862 -#define HID_ANY_ID (~0)
63863 +#define HID_ANY_ID (~0U)
63864
63865 struct hid_device_id {
63866 __u16 bus;
63867 diff -urNp linux-2.6.39/include/linux/module.h linux-2.6.39/include/linux/module.h
63868 --- linux-2.6.39/include/linux/module.h 2011-05-19 00:06:34.000000000 -0400
63869 +++ linux-2.6.39/include/linux/module.h 2011-05-22 19:36:33.000000000 -0400
63870 @@ -324,19 +324,16 @@ struct module
63871 int (*init)(void);
63872
63873 /* If this is non-NULL, vfree after init() returns */
63874 - void *module_init;
63875 + void *module_init_rx, *module_init_rw;
63876
63877 /* Here is the actual code + data, vfree'd on unload. */
63878 - void *module_core;
63879 + void *module_core_rx, *module_core_rw;
63880
63881 /* Here are the sizes of the init and core sections */
63882 - unsigned int init_size, core_size;
63883 + unsigned int init_size_rw, core_size_rw;
63884
63885 /* The size of the executable code in each section. */
63886 - unsigned int init_text_size, core_text_size;
63887 -
63888 - /* Size of RO sections of the module (text+rodata) */
63889 - unsigned int init_ro_size, core_ro_size;
63890 + unsigned int init_size_rx, core_size_rx;
63891
63892 /* Arch-specific module values */
63893 struct mod_arch_specific arch;
63894 @@ -441,16 +438,46 @@ bool is_module_address(unsigned long add
63895 bool is_module_percpu_address(unsigned long addr);
63896 bool is_module_text_address(unsigned long addr);
63897
63898 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
63899 +{
63900 +
63901 +#ifdef CONFIG_PAX_KERNEXEC
63902 + if (ktla_ktva(addr) >= (unsigned long)start &&
63903 + ktla_ktva(addr) < (unsigned long)start + size)
63904 + return 1;
63905 +#endif
63906 +
63907 + return ((void *)addr >= start && (void *)addr < start + size);
63908 +}
63909 +
63910 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
63911 +{
63912 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
63913 +}
63914 +
63915 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
63916 +{
63917 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
63918 +}
63919 +
63920 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
63921 +{
63922 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
63923 +}
63924 +
63925 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
63926 +{
63927 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
63928 +}
63929 +
63930 static inline int within_module_core(unsigned long addr, struct module *mod)
63931 {
63932 - return (unsigned long)mod->module_core <= addr &&
63933 - addr < (unsigned long)mod->module_core + mod->core_size;
63934 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
63935 }
63936
63937 static inline int within_module_init(unsigned long addr, struct module *mod)
63938 {
63939 - return (unsigned long)mod->module_init <= addr &&
63940 - addr < (unsigned long)mod->module_init + mod->init_size;
63941 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
63942 }
63943
63944 /* Search for module by name: must hold module_mutex. */
63945 diff -urNp linux-2.6.39/include/linux/moduleloader.h linux-2.6.39/include/linux/moduleloader.h
63946 --- linux-2.6.39/include/linux/moduleloader.h 2011-05-19 00:06:34.000000000 -0400
63947 +++ linux-2.6.39/include/linux/moduleloader.h 2011-05-22 19:36:33.000000000 -0400
63948 @@ -20,9 +20,21 @@ unsigned int arch_mod_section_prepend(st
63949 sections. Returns NULL on failure. */
63950 void *module_alloc(unsigned long size);
63951
63952 +#ifdef CONFIG_PAX_KERNEXEC
63953 +void *module_alloc_exec(unsigned long size);
63954 +#else
63955 +#define module_alloc_exec(x) module_alloc(x)
63956 +#endif
63957 +
63958 /* Free memory returned from module_alloc. */
63959 void module_free(struct module *mod, void *module_region);
63960
63961 +#ifdef CONFIG_PAX_KERNEXEC
63962 +void module_free_exec(struct module *mod, void *module_region);
63963 +#else
63964 +#define module_free_exec(x, y) module_free((x), (y))
63965 +#endif
63966 +
63967 /* Apply the given relocation to the (simplified) ELF. Return -error
63968 or 0. */
63969 int apply_relocate(Elf_Shdr *sechdrs,
63970 diff -urNp linux-2.6.39/include/linux/moduleparam.h linux-2.6.39/include/linux/moduleparam.h
63971 --- linux-2.6.39/include/linux/moduleparam.h 2011-05-19 00:06:34.000000000 -0400
63972 +++ linux-2.6.39/include/linux/moduleparam.h 2011-05-22 19:36:33.000000000 -0400
63973 @@ -255,7 +255,7 @@ static inline void __kernel_param_unlock
63974 * @len is usually just sizeof(string).
63975 */
63976 #define module_param_string(name, string, len, perm) \
63977 - static const struct kparam_string __param_string_##name \
63978 + static const struct kparam_string __param_string_##name __used \
63979 = { len, string }; \
63980 __module_param_call(MODULE_PARAM_PREFIX, name, \
63981 &param_ops_string, \
63982 @@ -285,48 +285,48 @@ static inline void destroy_params(const
63983 #define __param_check(name, p, type) \
63984 static inline type *__check_##name(void) { return(p); }
63985
63986 -extern struct kernel_param_ops param_ops_byte;
63987 +extern const struct kernel_param_ops param_ops_byte;
63988 extern int param_set_byte(const char *val, const struct kernel_param *kp);
63989 extern int param_get_byte(char *buffer, const struct kernel_param *kp);
63990 #define param_check_byte(name, p) __param_check(name, p, unsigned char)
63991
63992 -extern struct kernel_param_ops param_ops_short;
63993 +extern const struct kernel_param_ops param_ops_short;
63994 extern int param_set_short(const char *val, const struct kernel_param *kp);
63995 extern int param_get_short(char *buffer, const struct kernel_param *kp);
63996 #define param_check_short(name, p) __param_check(name, p, short)
63997
63998 -extern struct kernel_param_ops param_ops_ushort;
63999 +extern const struct kernel_param_ops param_ops_ushort;
64000 extern int param_set_ushort(const char *val, const struct kernel_param *kp);
64001 extern int param_get_ushort(char *buffer, const struct kernel_param *kp);
64002 #define param_check_ushort(name, p) __param_check(name, p, unsigned short)
64003
64004 -extern struct kernel_param_ops param_ops_int;
64005 +extern const struct kernel_param_ops param_ops_int;
64006 extern int param_set_int(const char *val, const struct kernel_param *kp);
64007 extern int param_get_int(char *buffer, const struct kernel_param *kp);
64008 #define param_check_int(name, p) __param_check(name, p, int)
64009
64010 -extern struct kernel_param_ops param_ops_uint;
64011 +extern const struct kernel_param_ops param_ops_uint;
64012 extern int param_set_uint(const char *val, const struct kernel_param *kp);
64013 extern int param_get_uint(char *buffer, const struct kernel_param *kp);
64014 #define param_check_uint(name, p) __param_check(name, p, unsigned int)
64015
64016 -extern struct kernel_param_ops param_ops_long;
64017 +extern const struct kernel_param_ops param_ops_long;
64018 extern int param_set_long(const char *val, const struct kernel_param *kp);
64019 extern int param_get_long(char *buffer, const struct kernel_param *kp);
64020 #define param_check_long(name, p) __param_check(name, p, long)
64021
64022 -extern struct kernel_param_ops param_ops_ulong;
64023 +extern const struct kernel_param_ops param_ops_ulong;
64024 extern int param_set_ulong(const char *val, const struct kernel_param *kp);
64025 extern int param_get_ulong(char *buffer, const struct kernel_param *kp);
64026 #define param_check_ulong(name, p) __param_check(name, p, unsigned long)
64027
64028 -extern struct kernel_param_ops param_ops_charp;
64029 +extern const struct kernel_param_ops param_ops_charp;
64030 extern int param_set_charp(const char *val, const struct kernel_param *kp);
64031 extern int param_get_charp(char *buffer, const struct kernel_param *kp);
64032 #define param_check_charp(name, p) __param_check(name, p, char *)
64033
64034 /* For historical reasons "bool" parameters can be (unsigned) "int". */
64035 -extern struct kernel_param_ops param_ops_bool;
64036 +extern const struct kernel_param_ops param_ops_bool;
64037 extern int param_set_bool(const char *val, const struct kernel_param *kp);
64038 extern int param_get_bool(char *buffer, const struct kernel_param *kp);
64039 #define param_check_bool(name, p) \
64040 @@ -337,7 +337,7 @@ extern int param_get_bool(char *buffer,
64041 !__same_type((p), int *)); \
64042 }
64043
64044 -extern struct kernel_param_ops param_ops_invbool;
64045 +extern const struct kernel_param_ops param_ops_invbool;
64046 extern int param_set_invbool(const char *val, const struct kernel_param *kp);
64047 extern int param_get_invbool(char *buffer, const struct kernel_param *kp);
64048 #define param_check_invbool(name, p) __param_check(name, p, bool)
64049 @@ -370,7 +370,7 @@ extern int param_get_invbool(char *buffe
64050 * module_param_named() for why this might be necessary.
64051 */
64052 #define module_param_array_named(name, array, type, nump, perm) \
64053 - static const struct kparam_array __param_arr_##name \
64054 + static const struct kparam_array __param_arr_##name __used \
64055 = { ARRAY_SIZE(array), nump, &param_ops_##type, \
64056 sizeof(array[0]), array }; \
64057 __module_param_call(MODULE_PARAM_PREFIX, name, \
64058 @@ -379,9 +379,9 @@ extern int param_get_invbool(char *buffe
64059 __same_type(array[0], bool), perm); \
64060 __MODULE_PARM_TYPE(name, "array of " #type)
64061
64062 -extern struct kernel_param_ops param_array_ops;
64063 +extern const struct kernel_param_ops param_array_ops;
64064
64065 -extern struct kernel_param_ops param_ops_string;
64066 +extern const struct kernel_param_ops param_ops_string;
64067 extern int param_set_copystring(const char *val, const struct kernel_param *);
64068 extern int param_get_string(char *buffer, const struct kernel_param *kp);
64069
64070 diff -urNp linux-2.6.39/include/linux/mutex.h linux-2.6.39/include/linux/mutex.h
64071 --- linux-2.6.39/include/linux/mutex.h 2011-05-19 00:06:34.000000000 -0400
64072 +++ linux-2.6.39/include/linux/mutex.h 2011-05-22 19:36:33.000000000 -0400
64073 @@ -51,7 +51,7 @@ struct mutex {
64074 spinlock_t wait_lock;
64075 struct list_head wait_list;
64076 #if defined(CONFIG_DEBUG_MUTEXES) || defined(CONFIG_SMP)
64077 - struct thread_info *owner;
64078 + struct task_struct *owner;
64079 #endif
64080 #ifdef CONFIG_DEBUG_MUTEXES
64081 const char *name;
64082 diff -urNp linux-2.6.39/include/linux/namei.h linux-2.6.39/include/linux/namei.h
64083 --- linux-2.6.39/include/linux/namei.h 2011-05-19 00:06:34.000000000 -0400
64084 +++ linux-2.6.39/include/linux/namei.h 2011-05-22 19:36:33.000000000 -0400
64085 @@ -24,7 +24,7 @@ struct nameidata {
64086 unsigned seq;
64087 int last_type;
64088 unsigned depth;
64089 - char *saved_names[MAX_NESTED_LINKS + 1];
64090 + const char *saved_names[MAX_NESTED_LINKS + 1];
64091
64092 /* Intent data */
64093 union {
64094 @@ -91,12 +91,12 @@ extern int follow_up(struct path *);
64095 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
64096 extern void unlock_rename(struct dentry *, struct dentry *);
64097
64098 -static inline void nd_set_link(struct nameidata *nd, char *path)
64099 +static inline void nd_set_link(struct nameidata *nd, const char *path)
64100 {
64101 nd->saved_names[nd->depth] = path;
64102 }
64103
64104 -static inline char *nd_get_link(struct nameidata *nd)
64105 +static inline const char *nd_get_link(const struct nameidata *nd)
64106 {
64107 return nd->saved_names[nd->depth];
64108 }
64109 diff -urNp linux-2.6.39/include/linux/netfilter/xt_gradm.h linux-2.6.39/include/linux/netfilter/xt_gradm.h
64110 --- linux-2.6.39/include/linux/netfilter/xt_gradm.h 1969-12-31 19:00:00.000000000 -0500
64111 +++ linux-2.6.39/include/linux/netfilter/xt_gradm.h 2011-05-22 19:41:42.000000000 -0400
64112 @@ -0,0 +1,9 @@
64113 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
64114 +#define _LINUX_NETFILTER_XT_GRADM_H 1
64115 +
64116 +struct xt_gradm_mtinfo {
64117 + __u16 flags;
64118 + __u16 invflags;
64119 +};
64120 +
64121 +#endif
64122 diff -urNp linux-2.6.39/include/linux/oprofile.h linux-2.6.39/include/linux/oprofile.h
64123 --- linux-2.6.39/include/linux/oprofile.h 2011-05-19 00:06:34.000000000 -0400
64124 +++ linux-2.6.39/include/linux/oprofile.h 2011-05-22 19:36:33.000000000 -0400
64125 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super
64126 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
64127 char const * name, ulong * val);
64128
64129 -/** Create a file for read-only access to an atomic_t. */
64130 +/** Create a file for read-only access to an atomic_unchecked_t. */
64131 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
64132 - char const * name, atomic_t * val);
64133 + char const * name, atomic_unchecked_t * val);
64134
64135 /** create a directory */
64136 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
64137 diff -urNp linux-2.6.39/include/linux/padata.h linux-2.6.39/include/linux/padata.h
64138 --- linux-2.6.39/include/linux/padata.h 2011-05-19 00:06:34.000000000 -0400
64139 +++ linux-2.6.39/include/linux/padata.h 2011-05-22 19:36:33.000000000 -0400
64140 @@ -129,7 +129,7 @@ struct parallel_data {
64141 struct padata_instance *pinst;
64142 struct padata_parallel_queue __percpu *pqueue;
64143 struct padata_serial_queue __percpu *squeue;
64144 - atomic_t seq_nr;
64145 + atomic_unchecked_t seq_nr;
64146 atomic_t reorder_objects;
64147 atomic_t refcnt;
64148 unsigned int max_seq_nr;
64149 diff -urNp linux-2.6.39/include/linux/pci.h linux-2.6.39/include/linux/pci.h
64150 --- linux-2.6.39/include/linux/pci.h 2011-05-19 00:06:34.000000000 -0400
64151 +++ linux-2.6.39/include/linux/pci.h 2011-05-22 19:36:33.000000000 -0400
64152 @@ -411,7 +411,7 @@ struct pci_bus {
64153 struct resource *resource[PCI_BRIDGE_RESOURCE_NUM];
64154 struct list_head resources; /* address space routed to this bus */
64155
64156 - struct pci_ops *ops; /* configuration access functions */
64157 + const struct pci_ops *ops; /* configuration access functions */
64158 void *sysdata; /* hook for sys-specific extension */
64159 struct proc_dir_entry *procdir; /* directory entry in /proc/bus/pci */
64160
64161 @@ -550,7 +550,7 @@ struct pci_driver {
64162 int (*resume_early) (struct pci_dev *dev);
64163 int (*resume) (struct pci_dev *dev); /* Device woken up */
64164 void (*shutdown) (struct pci_dev *dev);
64165 - struct pci_error_handlers *err_handler;
64166 + const struct pci_error_handlers *err_handler;
64167 struct device_driver driver;
64168 struct pci_dynids dynids;
64169 };
64170 @@ -639,7 +639,7 @@ void pcibios_scan_specific_bus(int busn)
64171 extern struct pci_bus *pci_find_bus(int domain, int busnr);
64172 void pci_bus_add_devices(const struct pci_bus *bus);
64173 struct pci_bus *pci_scan_bus_parented(struct device *parent, int bus,
64174 - struct pci_ops *ops, void *sysdata);
64175 + const struct pci_ops *ops, void *sysdata);
64176 static inline struct pci_bus * __devinit pci_scan_bus(int bus, struct pci_ops *ops,
64177 void *sysdata)
64178 {
64179 @@ -650,7 +650,7 @@ static inline struct pci_bus * __devinit
64180 return root_bus;
64181 }
64182 struct pci_bus *pci_create_bus(struct device *parent, int bus,
64183 - struct pci_ops *ops, void *sysdata);
64184 + const struct pci_ops *ops, void *sysdata);
64185 struct pci_bus *pci_add_new_bus(struct pci_bus *parent, struct pci_dev *dev,
64186 int busnr);
64187 void pcie_update_link_speed(struct pci_bus *bus, u16 link_status);
64188 @@ -727,7 +727,7 @@ int pci_bus_write_config_word(struct pci
64189 int where, u16 val);
64190 int pci_bus_write_config_dword(struct pci_bus *bus, unsigned int devfn,
64191 int where, u32 val);
64192 -struct pci_ops *pci_bus_set_ops(struct pci_bus *bus, struct pci_ops *ops);
64193 +const struct pci_ops *pci_bus_set_ops(struct pci_bus *bus, const struct pci_ops *ops);
64194
64195 static inline int pci_read_config_byte(struct pci_dev *dev, int where, u8 *val)
64196 {
64197 diff -urNp linux-2.6.39/include/linux/perf_event.h linux-2.6.39/include/linux/perf_event.h
64198 --- linux-2.6.39/include/linux/perf_event.h 2011-05-19 00:06:34.000000000 -0400
64199 +++ linux-2.6.39/include/linux/perf_event.h 2011-05-22 19:36:33.000000000 -0400
64200 @@ -759,8 +759,8 @@ struct perf_event {
64201
64202 enum perf_event_active_state state;
64203 unsigned int attach_state;
64204 - local64_t count;
64205 - atomic64_t child_count;
64206 + local64_t count; /* PaX: fix it one day */
64207 + atomic64_unchecked_t child_count;
64208
64209 /*
64210 * These are the total time in nanoseconds that the event
64211 @@ -811,8 +811,8 @@ struct perf_event {
64212 * These accumulate total time (in nanoseconds) that children
64213 * events have been enabled and running, respectively.
64214 */
64215 - atomic64_t child_total_time_enabled;
64216 - atomic64_t child_total_time_running;
64217 + atomic64_unchecked_t child_total_time_enabled;
64218 + atomic64_unchecked_t child_total_time_running;
64219
64220 /*
64221 * Protect attach/detach and child_list:
64222 @@ -1090,9 +1090,9 @@ void perf_event_task_sched_out(struct ta
64223 }
64224
64225 extern void perf_event_mmap(struct vm_area_struct *vma);
64226 -extern struct perf_guest_info_callbacks *perf_guest_cbs;
64227 -extern int perf_register_guest_info_callbacks(struct perf_guest_info_callbacks *callbacks);
64228 -extern int perf_unregister_guest_info_callbacks(struct perf_guest_info_callbacks *callbacks);
64229 +extern const struct perf_guest_info_callbacks *perf_guest_cbs;
64230 +extern int perf_register_guest_info_callbacks(const struct perf_guest_info_callbacks *callbacks);
64231 +extern int perf_unregister_guest_info_callbacks(const struct perf_guest_info_callbacks *callbacks);
64232
64233 extern void perf_event_comm(struct task_struct *tsk);
64234 extern void perf_event_fork(struct task_struct *tsk);
64235 diff -urNp linux-2.6.39/include/linux/pipe_fs_i.h linux-2.6.39/include/linux/pipe_fs_i.h
64236 --- linux-2.6.39/include/linux/pipe_fs_i.h 2011-05-19 00:06:34.000000000 -0400
64237 +++ linux-2.6.39/include/linux/pipe_fs_i.h 2011-05-22 19:36:33.000000000 -0400
64238 @@ -46,9 +46,9 @@ struct pipe_buffer {
64239 struct pipe_inode_info {
64240 wait_queue_head_t wait;
64241 unsigned int nrbufs, curbuf, buffers;
64242 - unsigned int readers;
64243 - unsigned int writers;
64244 - unsigned int waiting_writers;
64245 + atomic_t readers;
64246 + atomic_t writers;
64247 + atomic_t waiting_writers;
64248 unsigned int r_counter;
64249 unsigned int w_counter;
64250 struct page *tmp_page;
64251 diff -urNp linux-2.6.39/include/linux/pm.h linux-2.6.39/include/linux/pm.h
64252 --- linux-2.6.39/include/linux/pm.h 2011-05-19 00:06:34.000000000 -0400
64253 +++ linux-2.6.39/include/linux/pm.h 2011-05-22 19:36:33.000000000 -0400
64254 @@ -268,7 +268,7 @@ const struct dev_pm_ops name = { \
64255 * runtime PM, make the pm member point to generic_subsys_pm_ops.
64256 */
64257 #ifdef CONFIG_PM
64258 -extern struct dev_pm_ops generic_subsys_pm_ops;
64259 +extern const struct dev_pm_ops generic_subsys_pm_ops;
64260 #define GENERIC_SUBSYS_PM_OPS (&generic_subsys_pm_ops)
64261 #else
64262 #define GENERIC_SUBSYS_PM_OPS NULL
64263 @@ -471,7 +471,7 @@ extern void update_pm_runtime_accounting
64264 * subsystem-level and driver-level callbacks.
64265 */
64266 struct dev_power_domain {
64267 - struct dev_pm_ops ops;
64268 + const struct dev_pm_ops ops;
64269 };
64270
64271 /*
64272 diff -urNp linux-2.6.39/include/linux/pm_runtime.h linux-2.6.39/include/linux/pm_runtime.h
64273 --- linux-2.6.39/include/linux/pm_runtime.h 2011-05-19 00:06:34.000000000 -0400
64274 +++ linux-2.6.39/include/linux/pm_runtime.h 2011-05-22 19:36:33.000000000 -0400
64275 @@ -94,7 +94,7 @@ static inline bool pm_runtime_callbacks_
64276
64277 static inline void pm_runtime_mark_last_busy(struct device *dev)
64278 {
64279 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
64280 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
64281 }
64282
64283 #else /* !CONFIG_PM_RUNTIME */
64284 diff -urNp linux-2.6.39/include/linux/poison.h linux-2.6.39/include/linux/poison.h
64285 --- linux-2.6.39/include/linux/poison.h 2011-05-19 00:06:34.000000000 -0400
64286 +++ linux-2.6.39/include/linux/poison.h 2011-05-22 19:36:33.000000000 -0400
64287 @@ -19,8 +19,8 @@
64288 * under normal circumstances, used to verify that nobody uses
64289 * non-initialized list entries.
64290 */
64291 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
64292 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
64293 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
64294 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
64295
64296 /********** include/linux/timer.h **********/
64297 /*
64298 diff -urNp linux-2.6.39/include/linux/posix-timers.h linux-2.6.39/include/linux/posix-timers.h
64299 --- linux-2.6.39/include/linux/posix-timers.h 2011-05-19 00:06:34.000000000 -0400
64300 +++ linux-2.6.39/include/linux/posix-timers.h 2011-05-22 19:36:33.000000000 -0400
64301 @@ -102,10 +102,10 @@ struct k_clock {
64302 struct itimerspec * cur_setting);
64303 };
64304
64305 -extern struct k_clock clock_posix_cpu;
64306 -extern struct k_clock clock_posix_dynamic;
64307 +extern const struct k_clock clock_posix_cpu;
64308 +extern const struct k_clock clock_posix_dynamic;
64309
64310 -void posix_timers_register_clock(const clockid_t clock_id, struct k_clock *new_clock);
64311 +void posix_timers_register_clock(const clockid_t clock_id, const struct k_clock *new_clock);
64312
64313 /* function to call to trigger timer event */
64314 int posix_timer_event(struct k_itimer *timr, int si_private);
64315 diff -urNp linux-2.6.39/include/linux/proc_fs.h linux-2.6.39/include/linux/proc_fs.h
64316 --- linux-2.6.39/include/linux/proc_fs.h 2011-05-19 00:06:34.000000000 -0400
64317 +++ linux-2.6.39/include/linux/proc_fs.h 2011-05-22 19:41:42.000000000 -0400
64318 @@ -155,6 +155,19 @@ static inline struct proc_dir_entry *pro
64319 return proc_create_data(name, mode, parent, proc_fops, NULL);
64320 }
64321
64322 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, mode_t mode,
64323 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
64324 +{
64325 +#ifdef CONFIG_GRKERNSEC_PROC_USER
64326 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
64327 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64328 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
64329 +#else
64330 + return proc_create_data(name, mode, parent, proc_fops, NULL);
64331 +#endif
64332 +}
64333 +
64334 +
64335 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
64336 mode_t mode, struct proc_dir_entry *base,
64337 read_proc_t *read_proc, void * data)
64338 diff -urNp linux-2.6.39/include/linux/ptrace.h linux-2.6.39/include/linux/ptrace.h
64339 --- linux-2.6.39/include/linux/ptrace.h 2011-05-19 00:06:34.000000000 -0400
64340 +++ linux-2.6.39/include/linux/ptrace.h 2011-05-22 19:41:42.000000000 -0400
64341 @@ -115,10 +115,10 @@ extern void __ptrace_unlink(struct task_
64342 extern void exit_ptrace(struct task_struct *tracer);
64343 #define PTRACE_MODE_READ 1
64344 #define PTRACE_MODE_ATTACH 2
64345 -/* Returns 0 on success, -errno on denial. */
64346 -extern int __ptrace_may_access(struct task_struct *task, unsigned int mode);
64347 /* Returns true on success, false on denial. */
64348 extern bool ptrace_may_access(struct task_struct *task, unsigned int mode);
64349 +/* Returns true on success, false on denial. */
64350 +extern bool ptrace_may_access_log(struct task_struct *task, unsigned int mode);
64351
64352 static inline int ptrace_reparented(struct task_struct *child)
64353 {
64354 diff -urNp linux-2.6.39/include/linux/random.h linux-2.6.39/include/linux/random.h
64355 --- linux-2.6.39/include/linux/random.h 2011-05-19 00:06:34.000000000 -0400
64356 +++ linux-2.6.39/include/linux/random.h 2011-05-22 19:36:33.000000000 -0400
64357 @@ -80,12 +80,17 @@ void srandom32(u32 seed);
64358
64359 u32 prandom32(struct rnd_state *);
64360
64361 +static inline unsigned long pax_get_random_long(void)
64362 +{
64363 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
64364 +}
64365 +
64366 /*
64367 * Handle minimum values for seeds
64368 */
64369 static inline u32 __seed(u32 x, u32 m)
64370 {
64371 - return (x < m) ? x + m : x;
64372 + return (x <= m) ? x + m + 1 : x;
64373 }
64374
64375 /**
64376 diff -urNp linux-2.6.39/include/linux/reboot.h linux-2.6.39/include/linux/reboot.h
64377 --- linux-2.6.39/include/linux/reboot.h 2011-05-19 00:06:34.000000000 -0400
64378 +++ linux-2.6.39/include/linux/reboot.h 2011-05-22 19:36:33.000000000 -0400
64379 @@ -47,9 +47,9 @@ extern int unregister_reboot_notifier(st
64380 * Architecture-specific implementations of sys_reboot commands.
64381 */
64382
64383 -extern void machine_restart(char *cmd);
64384 -extern void machine_halt(void);
64385 -extern void machine_power_off(void);
64386 +extern void machine_restart(char *cmd) __noreturn;
64387 +extern void machine_halt(void) __noreturn;
64388 +extern void machine_power_off(void) __noreturn;
64389
64390 extern void machine_shutdown(void);
64391 struct pt_regs;
64392 @@ -60,9 +60,9 @@ extern void machine_crash_shutdown(struc
64393 */
64394
64395 extern void kernel_restart_prepare(char *cmd);
64396 -extern void kernel_restart(char *cmd);
64397 -extern void kernel_halt(void);
64398 -extern void kernel_power_off(void);
64399 +extern void kernel_restart(char *cmd) __noreturn;
64400 +extern void kernel_halt(void) __noreturn;
64401 +extern void kernel_power_off(void) __noreturn;
64402
64403 extern int C_A_D; /* for sysctl */
64404 void ctrl_alt_del(void);
64405 @@ -76,7 +76,7 @@ extern int orderly_poweroff(bool force);
64406 * Emergency restart, callable from an interrupt handler.
64407 */
64408
64409 -extern void emergency_restart(void);
64410 +extern void emergency_restart(void) __noreturn;
64411 #include <asm/emergency-restart.h>
64412
64413 #endif
64414 diff -urNp linux-2.6.39/include/linux/reiserfs_fs.h linux-2.6.39/include/linux/reiserfs_fs.h
64415 --- linux-2.6.39/include/linux/reiserfs_fs.h 2011-05-19 00:06:34.000000000 -0400
64416 +++ linux-2.6.39/include/linux/reiserfs_fs.h 2011-05-22 19:36:33.000000000 -0400
64417 @@ -1406,7 +1406,7 @@ static inline loff_t max_reiserfs_offset
64418 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
64419
64420 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
64421 -#define get_generation(s) atomic_read (&fs_generation(s))
64422 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
64423 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
64424 #define __fs_changed(gen,s) (gen != get_generation (s))
64425 #define fs_changed(gen,s) \
64426 @@ -1618,24 +1618,24 @@ static inline struct super_block *sb_fro
64427 */
64428
64429 struct item_operations {
64430 - int (*bytes_number) (struct item_head * ih, int block_size);
64431 - void (*decrement_key) (struct cpu_key *);
64432 - int (*is_left_mergeable) (struct reiserfs_key * ih,
64433 + int (* const bytes_number) (struct item_head * ih, int block_size);
64434 + void (* const decrement_key) (struct cpu_key *);
64435 + int (* const is_left_mergeable) (struct reiserfs_key * ih,
64436 unsigned long bsize);
64437 - void (*print_item) (struct item_head *, char *item);
64438 - void (*check_item) (struct item_head *, char *item);
64439 + void (* const print_item) (struct item_head *, char *item);
64440 + void (* const check_item) (struct item_head *, char *item);
64441
64442 - int (*create_vi) (struct virtual_node * vn, struct virtual_item * vi,
64443 + int (* const create_vi) (struct virtual_node * vn, struct virtual_item * vi,
64444 int is_affected, int insert_size);
64445 - int (*check_left) (struct virtual_item * vi, int free,
64446 + int (* const check_left) (struct virtual_item * vi, int free,
64447 int start_skip, int end_skip);
64448 - int (*check_right) (struct virtual_item * vi, int free);
64449 - int (*part_size) (struct virtual_item * vi, int from, int to);
64450 - int (*unit_num) (struct virtual_item * vi);
64451 - void (*print_vi) (struct virtual_item * vi);
64452 + int (* const check_right) (struct virtual_item * vi, int free);
64453 + int (* const part_size) (struct virtual_item * vi, int from, int to);
64454 + int (* const unit_num) (struct virtual_item * vi);
64455 + void (* const print_vi) (struct virtual_item * vi);
64456 };
64457
64458 -extern struct item_operations *item_ops[TYPE_ANY + 1];
64459 +extern const struct item_operations * const item_ops[TYPE_ANY + 1];
64460
64461 #define op_bytes_number(ih,bsize) item_ops[le_ih_k_type (ih)]->bytes_number (ih, bsize)
64462 #define op_is_left_mergeable(key,bsize) item_ops[le_key_k_type (le_key_version (key), key)]->is_left_mergeable (key, bsize)
64463 diff -urNp linux-2.6.39/include/linux/reiserfs_fs_sb.h linux-2.6.39/include/linux/reiserfs_fs_sb.h
64464 --- linux-2.6.39/include/linux/reiserfs_fs_sb.h 2011-05-19 00:06:34.000000000 -0400
64465 +++ linux-2.6.39/include/linux/reiserfs_fs_sb.h 2011-05-22 19:36:33.000000000 -0400
64466 @@ -386,7 +386,7 @@ struct reiserfs_sb_info {
64467 /* Comment? -Hans */
64468 wait_queue_head_t s_wait;
64469 /* To be obsoleted soon by per buffer seals.. -Hans */
64470 - atomic_t s_generation_counter; // increased by one every time the
64471 + atomic_unchecked_t s_generation_counter; // increased by one every time the
64472 // tree gets re-balanced
64473 unsigned long s_properties; /* File system properties. Currently holds
64474 on-disk FS format */
64475 diff -urNp linux-2.6.39/include/linux/rmap.h linux-2.6.39/include/linux/rmap.h
64476 --- linux-2.6.39/include/linux/rmap.h 2011-05-19 00:06:34.000000000 -0400
64477 +++ linux-2.6.39/include/linux/rmap.h 2011-05-22 19:36:33.000000000 -0400
64478 @@ -119,8 +119,8 @@ static inline void anon_vma_unlock(struc
64479 void anon_vma_init(void); /* create anon_vma_cachep */
64480 int anon_vma_prepare(struct vm_area_struct *);
64481 void unlink_anon_vmas(struct vm_area_struct *);
64482 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
64483 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
64484 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
64485 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
64486 void __anon_vma_link(struct vm_area_struct *);
64487
64488 static inline void anon_vma_merge(struct vm_area_struct *vma,
64489 diff -urNp linux-2.6.39/include/linux/sched.h linux-2.6.39/include/linux/sched.h
64490 --- linux-2.6.39/include/linux/sched.h 2011-05-19 00:06:34.000000000 -0400
64491 +++ linux-2.6.39/include/linux/sched.h 2011-05-22 19:41:42.000000000 -0400
64492 @@ -100,6 +100,7 @@ struct bio_list;
64493 struct fs_struct;
64494 struct perf_event_context;
64495 struct blk_plug;
64496 +struct linux_binprm;
64497
64498 /*
64499 * List of flags we want to share for kernel threads,
64500 @@ -360,7 +361,7 @@ extern signed long schedule_timeout_inte
64501 extern signed long schedule_timeout_killable(signed long timeout);
64502 extern signed long schedule_timeout_uninterruptible(signed long timeout);
64503 asmlinkage void schedule(void);
64504 -extern int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner);
64505 +extern int mutex_spin_on_owner(struct mutex *lock, struct task_struct *owner);
64506
64507 struct nsproxy;
64508 struct user_namespace;
64509 @@ -381,10 +382,13 @@ struct user_namespace;
64510 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
64511
64512 extern int sysctl_max_map_count;
64513 +extern unsigned long sysctl_heap_stack_gap;
64514
64515 #include <linux/aio.h>
64516
64517 #ifdef CONFIG_MMU
64518 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
64519 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
64520 extern void arch_pick_mmap_layout(struct mm_struct *mm);
64521 extern unsigned long
64522 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
64523 @@ -629,6 +633,17 @@ struct signal_struct {
64524 #ifdef CONFIG_TASKSTATS
64525 struct taskstats *stats;
64526 #endif
64527 +
64528 +#ifdef CONFIG_GRKERNSEC
64529 + u32 curr_ip;
64530 + u32 saved_ip;
64531 + u32 gr_saddr;
64532 + u32 gr_daddr;
64533 + u16 gr_sport;
64534 + u16 gr_dport;
64535 + u8 used_accept:1;
64536 +#endif
64537 +
64538 #ifdef CONFIG_AUDIT
64539 unsigned audit_tty;
64540 struct tty_audit_buf *tty_audit_buf;
64541 @@ -701,6 +716,11 @@ struct user_struct {
64542 struct key *session_keyring; /* UID's default session keyring */
64543 #endif
64544
64545 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
64546 + unsigned int banned;
64547 + unsigned long ban_expires;
64548 +#endif
64549 +
64550 /* Hash table maintenance information */
64551 struct hlist_node uidhash_node;
64552 uid_t uid;
64553 @@ -1310,8 +1330,8 @@ struct task_struct {
64554 struct list_head thread_group;
64555
64556 struct completion *vfork_done; /* for vfork() */
64557 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
64558 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64559 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
64560 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64561
64562 cputime_t utime, stime, utimescaled, stimescaled;
64563 cputime_t gtime;
64564 @@ -1327,13 +1347,6 @@ struct task_struct {
64565 struct task_cputime cputime_expires;
64566 struct list_head cpu_timers[3];
64567
64568 -/* process credentials */
64569 - const struct cred __rcu *real_cred; /* objective and real subjective task
64570 - * credentials (COW) */
64571 - const struct cred __rcu *cred; /* effective (overridable) subjective task
64572 - * credentials (COW) */
64573 - struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
64574 -
64575 char comm[TASK_COMM_LEN]; /* executable name excluding path
64576 - access with [gs]et_task_comm (which lock
64577 it with task_lock())
64578 @@ -1350,8 +1363,16 @@ struct task_struct {
64579 #endif
64580 /* CPU-specific state of this task */
64581 struct thread_struct thread;
64582 +/* thread_info moved to task_struct */
64583 +#ifdef CONFIG_X86
64584 + struct thread_info tinfo;
64585 +#endif
64586 /* filesystem information */
64587 struct fs_struct *fs;
64588 +
64589 + const struct cred __rcu *cred; /* effective (overridable) subjective task
64590 + * credentials (COW) */
64591 +
64592 /* open file information */
64593 struct files_struct *files;
64594 /* namespaces */
64595 @@ -1398,6 +1419,11 @@ struct task_struct {
64596 struct rt_mutex_waiter *pi_blocked_on;
64597 #endif
64598
64599 +/* process credentials */
64600 + const struct cred __rcu *real_cred; /* objective and real subjective task
64601 + * credentials (COW) */
64602 + struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
64603 +
64604 #ifdef CONFIG_DEBUG_MUTEXES
64605 /* mutex deadlock detection */
64606 struct mutex_waiter *blocked_on;
64607 @@ -1508,6 +1534,21 @@ struct task_struct {
64608 unsigned long default_timer_slack_ns;
64609
64610 struct list_head *scm_work_list;
64611 +
64612 +#ifdef CONFIG_GRKERNSEC
64613 + /* grsecurity */
64614 + struct dentry *gr_chroot_dentry;
64615 + struct acl_subject_label *acl;
64616 + struct acl_role_label *role;
64617 + struct file *exec_file;
64618 + u16 acl_role_id;
64619 + /* is this the task that authenticated to the special role */
64620 + u8 acl_sp_role;
64621 + u8 is_writable;
64622 + u8 brute;
64623 + u8 gr_is_chrooted;
64624 +#endif
64625 +
64626 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
64627 /* Index of current stored address in ret_stack */
64628 int curr_ret_stack;
64629 @@ -1542,6 +1583,63 @@ struct task_struct {
64630 #endif
64631 };
64632
64633 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
64634 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
64635 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
64636 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
64637 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
64638 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
64639 +
64640 +#ifdef CONFIG_PAX_SOFTMODE
64641 +extern unsigned int pax_softmode;
64642 +#endif
64643 +
64644 +extern int pax_check_flags(unsigned long *);
64645 +
64646 +/* if tsk != current then task_lock must be held on it */
64647 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
64648 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
64649 +{
64650 + if (likely(tsk->mm))
64651 + return tsk->mm->pax_flags;
64652 + else
64653 + return 0UL;
64654 +}
64655 +
64656 +/* if tsk != current then task_lock must be held on it */
64657 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
64658 +{
64659 + if (likely(tsk->mm)) {
64660 + tsk->mm->pax_flags = flags;
64661 + return 0;
64662 + }
64663 + return -EINVAL;
64664 +}
64665 +#endif
64666 +
64667 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
64668 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
64669 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
64670 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
64671 +#endif
64672 +
64673 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
64674 +void pax_report_insns(void *pc, void *sp);
64675 +void pax_report_refcount_overflow(struct pt_regs *regs);
64676 +void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type);
64677 +
64678 +static inline void pax_track_stack(void)
64679 +{
64680 +
64681 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
64682 + unsigned long sp = current_stack_pointer;
64683 + if (current_thread_info()->lowest_stack > sp &&
64684 + (unsigned long)task_stack_page(current) < sp)
64685 + current_thread_info()->lowest_stack = sp;
64686 +#endif
64687 +
64688 +}
64689 +
64690 /* Future-safe accessor for struct task_struct's cpus_allowed. */
64691 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
64692
64693 @@ -2009,7 +2107,9 @@ void yield(void);
64694 extern struct exec_domain default_exec_domain;
64695
64696 union thread_union {
64697 +#ifndef CONFIG_X86
64698 struct thread_info thread_info;
64699 +#endif
64700 unsigned long stack[THREAD_SIZE/sizeof(long)];
64701 };
64702
64703 @@ -2179,7 +2279,7 @@ extern void __cleanup_sighand(struct sig
64704 extern void exit_itimers(struct signal_struct *);
64705 extern void flush_itimer_signals(void);
64706
64707 -extern NORET_TYPE void do_group_exit(int);
64708 +extern NORET_TYPE void do_group_exit(int) ATTRIB_NORET;
64709
64710 extern void daemonize(const char *, ...);
64711 extern int allow_signal(int);
64712 @@ -2320,13 +2420,17 @@ static inline unsigned long *end_of_stac
64713
64714 #endif
64715
64716 -static inline int object_is_on_stack(void *obj)
64717 +static inline int object_starts_on_stack(void *obj)
64718 {
64719 - void *stack = task_stack_page(current);
64720 + const void *stack = task_stack_page(current);
64721
64722 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
64723 }
64724
64725 +#ifdef CONFIG_PAX_USERCOPY
64726 +extern int object_is_on_stack(const void *obj, unsigned long len);
64727 +#endif
64728 +
64729 extern void thread_info_cache_init(void);
64730
64731 #ifdef CONFIG_DEBUG_STACK_USAGE
64732 diff -urNp linux-2.6.39/include/linux/screen_info.h linux-2.6.39/include/linux/screen_info.h
64733 --- linux-2.6.39/include/linux/screen_info.h 2011-05-19 00:06:34.000000000 -0400
64734 +++ linux-2.6.39/include/linux/screen_info.h 2011-05-22 19:36:33.000000000 -0400
64735 @@ -43,7 +43,8 @@ struct screen_info {
64736 __u16 pages; /* 0x32 */
64737 __u16 vesa_attributes; /* 0x34 */
64738 __u32 capabilities; /* 0x36 */
64739 - __u8 _reserved[6]; /* 0x3a */
64740 + __u16 vesapm_size; /* 0x3a */
64741 + __u8 _reserved[4]; /* 0x3c */
64742 } __attribute__((packed));
64743
64744 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
64745 diff -urNp linux-2.6.39/include/linux/security.h linux-2.6.39/include/linux/security.h
64746 --- linux-2.6.39/include/linux/security.h 2011-05-19 00:06:34.000000000 -0400
64747 +++ linux-2.6.39/include/linux/security.h 2011-05-22 19:41:42.000000000 -0400
64748 @@ -36,6 +36,7 @@
64749 #include <linux/key.h>
64750 #include <linux/xfrm.h>
64751 #include <linux/slab.h>
64752 +#include <linux/grsecurity.h>
64753 #include <net/flow.h>
64754
64755 /* Maximum number of letters for an LSM name string */
64756 diff -urNp linux-2.6.39/include/linux/shm.h linux-2.6.39/include/linux/shm.h
64757 --- linux-2.6.39/include/linux/shm.h 2011-05-19 00:06:34.000000000 -0400
64758 +++ linux-2.6.39/include/linux/shm.h 2011-05-22 19:41:42.000000000 -0400
64759 @@ -95,6 +95,10 @@ struct shmid_kernel /* private to the ke
64760 pid_t shm_cprid;
64761 pid_t shm_lprid;
64762 struct user_struct *mlock_user;
64763 +#ifdef CONFIG_GRKERNSEC
64764 + time_t shm_createtime;
64765 + pid_t shm_lapid;
64766 +#endif
64767 };
64768
64769 /* shm_mode upper byte flags */
64770 diff -urNp linux-2.6.39/include/linux/skbuff.h linux-2.6.39/include/linux/skbuff.h
64771 --- linux-2.6.39/include/linux/skbuff.h 2011-05-19 00:06:34.000000000 -0400
64772 +++ linux-2.6.39/include/linux/skbuff.h 2011-05-22 19:36:33.000000000 -0400
64773 @@ -592,7 +592,7 @@ static inline struct skb_shared_hwtstamp
64774 */
64775 static inline int skb_queue_empty(const struct sk_buff_head *list)
64776 {
64777 - return list->next == (struct sk_buff *)list;
64778 + return list->next == (const struct sk_buff *)list;
64779 }
64780
64781 /**
64782 @@ -605,7 +605,7 @@ static inline int skb_queue_empty(const
64783 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
64784 const struct sk_buff *skb)
64785 {
64786 - return skb->next == (struct sk_buff *)list;
64787 + return skb->next == (const struct sk_buff *)list;
64788 }
64789
64790 /**
64791 @@ -618,7 +618,7 @@ static inline bool skb_queue_is_last(con
64792 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
64793 const struct sk_buff *skb)
64794 {
64795 - return skb->prev == (struct sk_buff *)list;
64796 + return skb->prev == (const struct sk_buff *)list;
64797 }
64798
64799 /**
64800 @@ -1435,7 +1435,7 @@ static inline int pskb_network_may_pull(
64801 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
64802 */
64803 #ifndef NET_SKB_PAD
64804 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
64805 +#define NET_SKB_PAD max(_AC(32,U), L1_CACHE_BYTES)
64806 #endif
64807
64808 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
64809 diff -urNp linux-2.6.39/include/linux/slab_def.h linux-2.6.39/include/linux/slab_def.h
64810 --- linux-2.6.39/include/linux/slab_def.h 2011-05-19 00:06:34.000000000 -0400
64811 +++ linux-2.6.39/include/linux/slab_def.h 2011-05-22 19:36:33.000000000 -0400
64812 @@ -96,10 +96,10 @@ struct kmem_cache {
64813 unsigned long node_allocs;
64814 unsigned long node_frees;
64815 unsigned long node_overflow;
64816 - atomic_t allochit;
64817 - atomic_t allocmiss;
64818 - atomic_t freehit;
64819 - atomic_t freemiss;
64820 + atomic_unchecked_t allochit;
64821 + atomic_unchecked_t allocmiss;
64822 + atomic_unchecked_t freehit;
64823 + atomic_unchecked_t freemiss;
64824
64825 /*
64826 * If debugging is enabled, then the allocator can add additional
64827 diff -urNp linux-2.6.39/include/linux/slab.h linux-2.6.39/include/linux/slab.h
64828 --- linux-2.6.39/include/linux/slab.h 2011-05-19 00:06:34.000000000 -0400
64829 +++ linux-2.6.39/include/linux/slab.h 2011-05-23 17:07:00.000000000 -0400
64830 @@ -11,12 +11,20 @@
64831
64832 #include <linux/gfp.h>
64833 #include <linux/types.h>
64834 +#include <linux/err.h>
64835
64836 /*
64837 * Flags to pass to kmem_cache_create().
64838 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
64839 */
64840 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
64841 +
64842 +#ifdef CONFIG_PAX_USERCOPY
64843 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
64844 +#else
64845 +#define SLAB_USERCOPY 0x00000000UL
64846 +#endif
64847 +
64848 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
64849 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
64850 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
64851 @@ -87,10 +95,13 @@
64852 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
64853 * Both make kfree a no-op.
64854 */
64855 -#define ZERO_SIZE_PTR ((void *)16)
64856 +#define ZERO_SIZE_PTR \
64857 +({ \
64858 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
64859 + (void *)(-MAX_ERRNO-1L); \
64860 +})
64861
64862 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
64863 - (unsigned long)ZERO_SIZE_PTR)
64864 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
64865
64866 /*
64867 * struct kmem_cache related prototypes
64868 @@ -141,6 +152,7 @@ void * __must_check krealloc(const void
64869 void kfree(const void *);
64870 void kzfree(const void *);
64871 size_t ksize(const void *);
64872 +void check_object_size(const void *ptr, unsigned long n, bool to);
64873
64874 /*
64875 * Allocator specific definitions. These are mainly used to establish optimized
64876 @@ -333,4 +345,59 @@ static inline void *kzalloc_node(size_t
64877
64878 void __init kmem_cache_init_late(void);
64879
64880 +#define kmalloc(x, y) \
64881 +({ \
64882 + void *___retval; \
64883 + intoverflow_t ___x = (intoverflow_t)x; \
64884 + if (WARN(___x > ULONG_MAX, "kmalloc size overflow\n")) \
64885 + ___retval = NULL; \
64886 + else \
64887 + ___retval = kmalloc((size_t)___x, (y)); \
64888 + ___retval; \
64889 +})
64890 +
64891 +#define kmalloc_node(x, y, z) \
64892 +({ \
64893 + void *___retval; \
64894 + intoverflow_t ___x = (intoverflow_t)x; \
64895 + if (WARN(___x > ULONG_MAX, "kmalloc_node size overflow\n"))\
64896 + ___retval = NULL; \
64897 + else \
64898 + ___retval = kmalloc_node((size_t)___x, (y), (z));\
64899 + ___retval; \
64900 +})
64901 +
64902 +#define kzalloc(x, y) \
64903 +({ \
64904 + void *___retval; \
64905 + intoverflow_t ___x = (intoverflow_t)x; \
64906 + if (WARN(___x > ULONG_MAX, "kzalloc size overflow\n")) \
64907 + ___retval = NULL; \
64908 + else \
64909 + ___retval = kzalloc((size_t)___x, (y)); \
64910 + ___retval; \
64911 +})
64912 +
64913 +#define __krealloc(x, y, z) \
64914 +({ \
64915 + void *___retval; \
64916 + intoverflow_t ___y = (intoverflow_t)y; \
64917 + if (WARN(___y > ULONG_MAX, "__krealloc size overflow\n"))\
64918 + ___retval = NULL; \
64919 + else \
64920 + ___retval = __krealloc((x), (size_t)___y, (z)); \
64921 + ___retval; \
64922 +})
64923 +
64924 +#define krealloc(x, y, z) \
64925 +({ \
64926 + void *___retval; \
64927 + intoverflow_t ___y = (intoverflow_t)y; \
64928 + if (WARN(___y > ULONG_MAX, "krealloc size overflow\n")) \
64929 + ___retval = NULL; \
64930 + else \
64931 + ___retval = krealloc((x), (size_t)___y, (z)); \
64932 + ___retval; \
64933 +})
64934 +
64935 #endif /* _LINUX_SLAB_H */
64936 diff -urNp linux-2.6.39/include/linux/slub_def.h linux-2.6.39/include/linux/slub_def.h
64937 --- linux-2.6.39/include/linux/slub_def.h 2011-05-19 00:06:34.000000000 -0400
64938 +++ linux-2.6.39/include/linux/slub_def.h 2011-05-22 19:36:33.000000000 -0400
64939 @@ -84,7 +84,7 @@ struct kmem_cache {
64940 struct kmem_cache_order_objects max;
64941 struct kmem_cache_order_objects min;
64942 gfp_t allocflags; /* gfp flags to use on each alloc */
64943 - int refcount; /* Refcount for slab cache destroy */
64944 + atomic_t refcount; /* Refcount for slab cache destroy */
64945 void (*ctor)(void *);
64946 int inuse; /* Offset to metadata */
64947 int align; /* Alignment */
64948 diff -urNp linux-2.6.39/include/linux/sonet.h linux-2.6.39/include/linux/sonet.h
64949 --- linux-2.6.39/include/linux/sonet.h 2011-05-19 00:06:34.000000000 -0400
64950 +++ linux-2.6.39/include/linux/sonet.h 2011-05-22 19:36:33.000000000 -0400
64951 @@ -61,7 +61,7 @@ struct sonet_stats {
64952 #include <asm/atomic.h>
64953
64954 struct k_sonet_stats {
64955 -#define __HANDLE_ITEM(i) atomic_t i
64956 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
64957 __SONET_ITEMS
64958 #undef __HANDLE_ITEM
64959 };
64960 diff -urNp linux-2.6.39/include/linux/ssb/ssb_driver_gige.h linux-2.6.39/include/linux/ssb/ssb_driver_gige.h
64961 --- linux-2.6.39/include/linux/ssb/ssb_driver_gige.h 2011-05-19 00:06:34.000000000 -0400
64962 +++ linux-2.6.39/include/linux/ssb/ssb_driver_gige.h 2011-05-22 19:36:33.000000000 -0400
64963 @@ -44,7 +44,7 @@ struct ssb_gige {
64964
64965 /* The PCI controller device. */
64966 struct pci_controller pci_controller;
64967 - struct pci_ops pci_ops;
64968 + const struct pci_ops pci_ops;
64969 struct resource mem_resource;
64970 struct resource io_resource;
64971 };
64972 diff -urNp linux-2.6.39/include/linux/sunrpc/clnt.h linux-2.6.39/include/linux/sunrpc/clnt.h
64973 --- linux-2.6.39/include/linux/sunrpc/clnt.h 2011-05-19 00:06:34.000000000 -0400
64974 +++ linux-2.6.39/include/linux/sunrpc/clnt.h 2011-05-22 19:36:33.000000000 -0400
64975 @@ -169,9 +169,9 @@ static inline unsigned short rpc_get_por
64976 {
64977 switch (sap->sa_family) {
64978 case AF_INET:
64979 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
64980 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
64981 case AF_INET6:
64982 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
64983 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
64984 }
64985 return 0;
64986 }
64987 @@ -204,7 +204,7 @@ static inline bool __rpc_cmp_addr4(const
64988 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
64989 const struct sockaddr *src)
64990 {
64991 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
64992 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
64993 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
64994
64995 dsin->sin_family = ssin->sin_family;
64996 @@ -301,7 +301,7 @@ static inline u32 rpc_get_scope_id(const
64997 if (sa->sa_family != AF_INET6)
64998 return 0;
64999
65000 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
65001 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
65002 }
65003
65004 #endif /* __KERNEL__ */
65005 diff -urNp linux-2.6.39/include/linux/sunrpc/svc_rdma.h linux-2.6.39/include/linux/sunrpc/svc_rdma.h
65006 --- linux-2.6.39/include/linux/sunrpc/svc_rdma.h 2011-05-19 00:06:34.000000000 -0400
65007 +++ linux-2.6.39/include/linux/sunrpc/svc_rdma.h 2011-05-22 19:36:33.000000000 -0400
65008 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
65009 extern unsigned int svcrdma_max_requests;
65010 extern unsigned int svcrdma_max_req_size;
65011
65012 -extern atomic_t rdma_stat_recv;
65013 -extern atomic_t rdma_stat_read;
65014 -extern atomic_t rdma_stat_write;
65015 -extern atomic_t rdma_stat_sq_starve;
65016 -extern atomic_t rdma_stat_rq_starve;
65017 -extern atomic_t rdma_stat_rq_poll;
65018 -extern atomic_t rdma_stat_rq_prod;
65019 -extern atomic_t rdma_stat_sq_poll;
65020 -extern atomic_t rdma_stat_sq_prod;
65021 +extern atomic_unchecked_t rdma_stat_recv;
65022 +extern atomic_unchecked_t rdma_stat_read;
65023 +extern atomic_unchecked_t rdma_stat_write;
65024 +extern atomic_unchecked_t rdma_stat_sq_starve;
65025 +extern atomic_unchecked_t rdma_stat_rq_starve;
65026 +extern atomic_unchecked_t rdma_stat_rq_poll;
65027 +extern atomic_unchecked_t rdma_stat_rq_prod;
65028 +extern atomic_unchecked_t rdma_stat_sq_poll;
65029 +extern atomic_unchecked_t rdma_stat_sq_prod;
65030
65031 #define RPCRDMA_VERSION 1
65032
65033 diff -urNp linux-2.6.39/include/linux/suspend.h linux-2.6.39/include/linux/suspend.h
65034 --- linux-2.6.39/include/linux/suspend.h 2011-05-19 00:06:34.000000000 -0400
65035 +++ linux-2.6.39/include/linux/suspend.h 2011-05-22 19:36:33.000000000 -0400
65036 @@ -106,15 +106,15 @@ typedef int __bitwise suspend_state_t;
65037 * which require special recovery actions in that situation.
65038 */
65039 struct platform_suspend_ops {
65040 - int (*valid)(suspend_state_t state);
65041 - int (*begin)(suspend_state_t state);
65042 - int (*prepare)(void);
65043 - int (*prepare_late)(void);
65044 - int (*enter)(suspend_state_t state);
65045 - void (*wake)(void);
65046 - void (*finish)(void);
65047 - void (*end)(void);
65048 - void (*recover)(void);
65049 + int (* const valid)(suspend_state_t state);
65050 + int (* const begin)(suspend_state_t state);
65051 + int (* const prepare)(void);
65052 + int (* const prepare_late)(void);
65053 + int (* const enter)(suspend_state_t state);
65054 + void (* const wake)(void);
65055 + void (* const finish)(void);
65056 + void (* const end)(void);
65057 + void (* const recover)(void);
65058 };
65059
65060 #ifdef CONFIG_SUSPEND
65061 @@ -217,16 +217,16 @@ extern void mark_free_pages(struct zone
65062 * platforms which require special recovery actions in that situation.
65063 */
65064 struct platform_hibernation_ops {
65065 - int (*begin)(void);
65066 - void (*end)(void);
65067 - int (*pre_snapshot)(void);
65068 - void (*finish)(void);
65069 - int (*prepare)(void);
65070 - int (*enter)(void);
65071 - void (*leave)(void);
65072 - int (*pre_restore)(void);
65073 - void (*restore_cleanup)(void);
65074 - void (*recover)(void);
65075 + int (* const begin)(void);
65076 + void (* const end)(void);
65077 + int (* const pre_snapshot)(void);
65078 + void (* const finish)(void);
65079 + int (* const prepare)(void);
65080 + int (* const enter)(void);
65081 + void (* const leave)(void);
65082 + int (* const pre_restore)(void);
65083 + void (* const restore_cleanup)(void);
65084 + void (* const recover)(void);
65085 };
65086
65087 #ifdef CONFIG_HIBERNATION
65088 diff -urNp linux-2.6.39/include/linux/sysctl.h linux-2.6.39/include/linux/sysctl.h
65089 --- linux-2.6.39/include/linux/sysctl.h 2011-05-19 00:06:34.000000000 -0400
65090 +++ linux-2.6.39/include/linux/sysctl.h 2011-05-22 19:41:42.000000000 -0400
65091 @@ -155,7 +155,11 @@ enum
65092 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
65093 };
65094
65095 -
65096 +#ifdef CONFIG_PAX_SOFTMODE
65097 +enum {
65098 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
65099 +};
65100 +#endif
65101
65102 /* CTL_VM names: */
65103 enum
65104 @@ -967,6 +971,8 @@ typedef int proc_handler (struct ctl_tab
65105
65106 extern int proc_dostring(struct ctl_table *, int,
65107 void __user *, size_t *, loff_t *);
65108 +extern int proc_dostring_modpriv(struct ctl_table *, int,
65109 + void __user *, size_t *, loff_t *);
65110 extern int proc_dointvec(struct ctl_table *, int,
65111 void __user *, size_t *, loff_t *);
65112 extern int proc_dointvec_minmax(struct ctl_table *, int,
65113 diff -urNp linux-2.6.39/include/linux/sysfs.h linux-2.6.39/include/linux/sysfs.h
65114 --- linux-2.6.39/include/linux/sysfs.h 2011-05-19 00:06:34.000000000 -0400
65115 +++ linux-2.6.39/include/linux/sysfs.h 2011-05-22 19:36:33.000000000 -0400
65116 @@ -110,8 +110,8 @@ struct bin_attribute {
65117 #define sysfs_bin_attr_init(bin_attr) sysfs_attr_init(&(bin_attr)->attr)
65118
65119 struct sysfs_ops {
65120 - ssize_t (*show)(struct kobject *, struct attribute *,char *);
65121 - ssize_t (*store)(struct kobject *,struct attribute *,const char *, size_t);
65122 + ssize_t (* const show)(struct kobject *, struct attribute *,char *);
65123 + ssize_t (* const store)(struct kobject *,struct attribute *,const char *, size_t);
65124 };
65125
65126 struct sysfs_dirent;
65127 diff -urNp linux-2.6.39/include/linux/tty.h linux-2.6.39/include/linux/tty.h
65128 --- linux-2.6.39/include/linux/tty.h 2011-05-19 00:06:34.000000000 -0400
65129 +++ linux-2.6.39/include/linux/tty.h 2011-05-22 19:36:33.000000000 -0400
65130 @@ -13,6 +13,7 @@
65131 #include <linux/tty_driver.h>
65132 #include <linux/tty_ldisc.h>
65133 #include <linux/mutex.h>
65134 +#include <linux/poll.h>
65135
65136 #include <asm/system.h>
65137
65138 @@ -466,7 +467,6 @@ extern int tty_perform_flush(struct tty_
65139 extern dev_t tty_devnum(struct tty_struct *tty);
65140 extern void proc_clear_tty(struct task_struct *p);
65141 extern struct tty_struct *get_current_tty(void);
65142 -extern void tty_default_fops(struct file_operations *fops);
65143 extern struct tty_struct *alloc_tty_struct(void);
65144 extern int tty_add_file(struct tty_struct *tty, struct file *file);
65145 extern void free_tty_struct(struct tty_struct *tty);
65146 @@ -529,6 +529,18 @@ extern void tty_ldisc_begin(void);
65147 /* This last one is just for the tty layer internals and shouldn't be used elsewhere */
65148 extern void tty_ldisc_enable(struct tty_struct *tty);
65149
65150 +/* tty_io.c */
65151 +extern ssize_t tty_read(struct file *, char __user *, size_t, loff_t *);
65152 +extern ssize_t tty_write(struct file *, const char __user *, size_t, loff_t *);
65153 +extern unsigned int tty_poll(struct file *, poll_table *);
65154 +#ifdef CONFIG_COMPAT
65155 +extern long tty_compat_ioctl(struct file *file, unsigned int cmd,
65156 + unsigned long arg);
65157 +#else
65158 +#define tty_compat_ioctl NULL
65159 +#endif
65160 +extern int tty_release(struct inode *, struct file *);
65161 +extern int tty_fasync(int fd, struct file *filp, int on);
65162
65163 /* n_tty.c */
65164 extern struct tty_ldisc_ops tty_ldisc_N_TTY;
65165 diff -urNp linux-2.6.39/include/linux/tty_ldisc.h linux-2.6.39/include/linux/tty_ldisc.h
65166 --- linux-2.6.39/include/linux/tty_ldisc.h 2011-05-19 00:06:34.000000000 -0400
65167 +++ linux-2.6.39/include/linux/tty_ldisc.h 2011-05-22 19:36:33.000000000 -0400
65168 @@ -148,7 +148,7 @@ struct tty_ldisc_ops {
65169
65170 struct module *owner;
65171
65172 - int refcount;
65173 + atomic_t refcount;
65174 };
65175
65176 struct tty_ldisc {
65177 diff -urNp linux-2.6.39/include/linux/types.h linux-2.6.39/include/linux/types.h
65178 --- linux-2.6.39/include/linux/types.h 2011-05-19 00:06:34.000000000 -0400
65179 +++ linux-2.6.39/include/linux/types.h 2011-05-22 19:36:33.000000000 -0400
65180 @@ -213,10 +213,26 @@ typedef struct {
65181 int counter;
65182 } atomic_t;
65183
65184 +#ifdef CONFIG_PAX_REFCOUNT
65185 +typedef struct {
65186 + int counter;
65187 +} atomic_unchecked_t;
65188 +#else
65189 +typedef atomic_t atomic_unchecked_t;
65190 +#endif
65191 +
65192 #ifdef CONFIG_64BIT
65193 typedef struct {
65194 long counter;
65195 } atomic64_t;
65196 +
65197 +#ifdef CONFIG_PAX_REFCOUNT
65198 +typedef struct {
65199 + long counter;
65200 +} atomic64_unchecked_t;
65201 +#else
65202 +typedef atomic64_t atomic64_unchecked_t;
65203 +#endif
65204 #endif
65205
65206 struct list_head {
65207 diff -urNp linux-2.6.39/include/linux/uaccess.h linux-2.6.39/include/linux/uaccess.h
65208 --- linux-2.6.39/include/linux/uaccess.h 2011-05-19 00:06:34.000000000 -0400
65209 +++ linux-2.6.39/include/linux/uaccess.h 2011-05-22 19:36:33.000000000 -0400
65210 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_
65211 long ret; \
65212 mm_segment_t old_fs = get_fs(); \
65213 \
65214 - set_fs(KERNEL_DS); \
65215 pagefault_disable(); \
65216 + set_fs(KERNEL_DS); \
65217 ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
65218 - pagefault_enable(); \
65219 set_fs(old_fs); \
65220 + pagefault_enable(); \
65221 ret; \
65222 })
65223
65224 @@ -93,8 +93,8 @@ static inline unsigned long __copy_from_
65225 * Safely read from address @src to the buffer at @dst. If a kernel fault
65226 * happens, handle that and return -EFAULT.
65227 */
65228 -extern long probe_kernel_read(void *dst, void *src, size_t size);
65229 -extern long __probe_kernel_read(void *dst, void *src, size_t size);
65230 +extern long probe_kernel_read(void *dst, const void *src, size_t size);
65231 +extern long __probe_kernel_read(void *dst, const void *src, size_t size);
65232
65233 /*
65234 * probe_kernel_write(): safely attempt to write to a location
65235 @@ -105,7 +105,7 @@ extern long __probe_kernel_read(void *ds
65236 * Safely write to address @dst from the buffer at @src. If a kernel fault
65237 * happens, handle that and return -EFAULT.
65238 */
65239 -extern long notrace probe_kernel_write(void *dst, void *src, size_t size);
65240 -extern long notrace __probe_kernel_write(void *dst, void *src, size_t size);
65241 +extern long notrace probe_kernel_write(void *dst, const void *src, size_t size);
65242 +extern long notrace __probe_kernel_write(void *dst, const void *src, size_t size);
65243
65244 #endif /* __LINUX_UACCESS_H__ */
65245 diff -urNp linux-2.6.39/include/linux/unaligned/access_ok.h linux-2.6.39/include/linux/unaligned/access_ok.h
65246 --- linux-2.6.39/include/linux/unaligned/access_ok.h 2011-05-19 00:06:34.000000000 -0400
65247 +++ linux-2.6.39/include/linux/unaligned/access_ok.h 2011-05-22 19:36:33.000000000 -0400
65248 @@ -6,32 +6,32 @@
65249
65250 static inline u16 get_unaligned_le16(const void *p)
65251 {
65252 - return le16_to_cpup((__le16 *)p);
65253 + return le16_to_cpup((const __le16 *)p);
65254 }
65255
65256 static inline u32 get_unaligned_le32(const void *p)
65257 {
65258 - return le32_to_cpup((__le32 *)p);
65259 + return le32_to_cpup((const __le32 *)p);
65260 }
65261
65262 static inline u64 get_unaligned_le64(const void *p)
65263 {
65264 - return le64_to_cpup((__le64 *)p);
65265 + return le64_to_cpup((const __le64 *)p);
65266 }
65267
65268 static inline u16 get_unaligned_be16(const void *p)
65269 {
65270 - return be16_to_cpup((__be16 *)p);
65271 + return be16_to_cpup((const __be16 *)p);
65272 }
65273
65274 static inline u32 get_unaligned_be32(const void *p)
65275 {
65276 - return be32_to_cpup((__be32 *)p);
65277 + return be32_to_cpup((const __be32 *)p);
65278 }
65279
65280 static inline u64 get_unaligned_be64(const void *p)
65281 {
65282 - return be64_to_cpup((__be64 *)p);
65283 + return be64_to_cpup((const __be64 *)p);
65284 }
65285
65286 static inline void put_unaligned_le16(u16 val, void *p)
65287 diff -urNp linux-2.6.39/include/linux/usb/hcd.h linux-2.6.39/include/linux/usb/hcd.h
65288 --- linux-2.6.39/include/linux/usb/hcd.h 2011-05-19 00:06:34.000000000 -0400
65289 +++ linux-2.6.39/include/linux/usb/hcd.h 2011-05-22 19:36:33.000000000 -0400
65290 @@ -615,7 +615,7 @@ struct usb_mon_operations {
65291 /* void (*urb_unlink)(struct usb_bus *bus, struct urb *urb); */
65292 };
65293
65294 -extern struct usb_mon_operations *mon_ops;
65295 +extern const struct usb_mon_operations *mon_ops;
65296
65297 static inline void usbmon_urb_submit(struct usb_bus *bus, struct urb *urb)
65298 {
65299 @@ -637,7 +637,7 @@ static inline void usbmon_urb_complete(s
65300 (*mon_ops->urb_complete)(bus, urb, status);
65301 }
65302
65303 -int usb_mon_register(struct usb_mon_operations *ops);
65304 +int usb_mon_register(const struct usb_mon_operations *ops);
65305 void usb_mon_deregister(void);
65306
65307 #else
65308 diff -urNp linux-2.6.39/include/linux/usb/intel_mid_otg.h linux-2.6.39/include/linux/usb/intel_mid_otg.h
65309 --- linux-2.6.39/include/linux/usb/intel_mid_otg.h 2011-05-19 00:06:34.000000000 -0400
65310 +++ linux-2.6.39/include/linux/usb/intel_mid_otg.h 2011-05-22 19:36:33.000000000 -0400
65311 @@ -115,7 +115,7 @@ struct intel_mid_otg_xceiv {
65312 void __iomem *base;
65313
65314 /* ops to access ulpi */
65315 - struct iotg_ulpi_access_ops ulpi_ops;
65316 + const struct iotg_ulpi_access_ops ulpi_ops;
65317
65318 /* atomic notifier for interrupt context */
65319 struct atomic_notifier_head iotg_notifier;
65320 diff -urNp linux-2.6.39/include/linux/usb/ulpi.h linux-2.6.39/include/linux/usb/ulpi.h
65321 --- linux-2.6.39/include/linux/usb/ulpi.h 2011-05-19 00:06:34.000000000 -0400
65322 +++ linux-2.6.39/include/linux/usb/ulpi.h 2011-05-22 19:36:33.000000000 -0400
65323 @@ -186,7 +186,7 @@ struct otg_transceiver *otg_ulpi_create(
65324
65325 #ifdef CONFIG_USB_ULPI_VIEWPORT
65326 /* access ops for controllers with a viewport register */
65327 -extern struct otg_io_access_ops ulpi_viewport_access_ops;
65328 +extern const struct otg_io_access_ops ulpi_viewport_access_ops;
65329 #endif
65330
65331 #endif /* __LINUX_USB_ULPI_H */
65332 diff -urNp linux-2.6.39/include/linux/vga_switcheroo.h linux-2.6.39/include/linux/vga_switcheroo.h
65333 --- linux-2.6.39/include/linux/vga_switcheroo.h 2011-05-19 00:06:34.000000000 -0400
65334 +++ linux-2.6.39/include/linux/vga_switcheroo.h 2011-05-22 19:36:33.000000000 -0400
65335 @@ -39,7 +39,7 @@ int vga_switcheroo_register_client(struc
65336 void vga_switcheroo_client_fb_set(struct pci_dev *dev,
65337 struct fb_info *info);
65338
65339 -int vga_switcheroo_register_handler(struct vga_switcheroo_handler *handler);
65340 +int vga_switcheroo_register_handler(const struct vga_switcheroo_handler *handler);
65341 void vga_switcheroo_unregister_handler(void);
65342
65343 int vga_switcheroo_process_delayed_switch(void);
65344 @@ -52,7 +52,7 @@ static inline int vga_switcheroo_registe
65345 void (*reprobe)(struct pci_dev *dev),
65346 bool (*can_switch)(struct pci_dev *dev)) { return 0; }
65347 static inline void vga_switcheroo_client_fb_set(struct pci_dev *dev, struct fb_info *info) {}
65348 -static inline int vga_switcheroo_register_handler(struct vga_switcheroo_handler *handler) { return 0; }
65349 +static inline int vga_switcheroo_register_handler(const struct vga_switcheroo_handler *handler) { return 0; }
65350 static inline void vga_switcheroo_unregister_handler(void) {}
65351 static inline int vga_switcheroo_process_delayed_switch(void) { return 0; }
65352
65353 diff -urNp linux-2.6.39/include/linux/virtio.h linux-2.6.39/include/linux/virtio.h
65354 --- linux-2.6.39/include/linux/virtio.h 2011-05-19 00:06:34.000000000 -0400
65355 +++ linux-2.6.39/include/linux/virtio.h 2011-05-22 19:36:33.000000000 -0400
65356 @@ -102,7 +102,7 @@ struct virtio_device {
65357 int index;
65358 struct device dev;
65359 struct virtio_device_id id;
65360 - struct virtio_config_ops *config;
65361 + const struct virtio_config_ops *config;
65362 struct list_head vqs;
65363 /* Note that this is a Linux set_bit-style bitmap. */
65364 unsigned long features[1];
65365 diff -urNp linux-2.6.39/include/linux/vmalloc.h linux-2.6.39/include/linux/vmalloc.h
65366 --- linux-2.6.39/include/linux/vmalloc.h 2011-05-19 00:06:34.000000000 -0400
65367 +++ linux-2.6.39/include/linux/vmalloc.h 2011-05-22 19:36:33.000000000 -0400
65368 @@ -13,6 +13,11 @@ struct vm_area_struct; /* vma defining
65369 #define VM_MAP 0x00000004 /* vmap()ed pages */
65370 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
65371 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
65372 +
65373 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
65374 +#define VM_KERNEXEC 0x00000020 /* allocate from executable kernel memory range */
65375 +#endif
65376 +
65377 /* bits [20..32] reserved for arch specific ioremap internals */
65378
65379 /*
65380 @@ -155,4 +160,103 @@ pcpu_free_vm_areas(struct vm_struct **vm
65381 # endif
65382 #endif
65383
65384 +#define vmalloc(x) \
65385 +({ \
65386 + void *___retval; \
65387 + intoverflow_t ___x = (intoverflow_t)x; \
65388 + if (WARN(___x > ULONG_MAX, "vmalloc size overflow\n")) \
65389 + ___retval = NULL; \
65390 + else \
65391 + ___retval = vmalloc((unsigned long)___x); \
65392 + ___retval; \
65393 +})
65394 +
65395 +#define vzalloc(x) \
65396 +({ \
65397 + void *___retval; \
65398 + intoverflow_t ___x = (intoverflow_t)x; \
65399 + if (WARN(___x > ULONG_MAX, "vzalloc size overflow\n")) \
65400 + ___retval = NULL; \
65401 + else \
65402 + ___retval = vzalloc((unsigned long)___x); \
65403 + ___retval; \
65404 +})
65405 +
65406 +#define __vmalloc(x, y, z) \
65407 +({ \
65408 + void *___retval; \
65409 + intoverflow_t ___x = (intoverflow_t)x; \
65410 + if (WARN(___x > ULONG_MAX, "__vmalloc size overflow\n"))\
65411 + ___retval = NULL; \
65412 + else \
65413 + ___retval = __vmalloc((unsigned long)___x, (y), (z));\
65414 + ___retval; \
65415 +})
65416 +
65417 +#define vmalloc_user(x) \
65418 +({ \
65419 + void *___retval; \
65420 + intoverflow_t ___x = (intoverflow_t)x; \
65421 + if (WARN(___x > ULONG_MAX, "vmalloc_user size overflow\n"))\
65422 + ___retval = NULL; \
65423 + else \
65424 + ___retval = vmalloc_user((unsigned long)___x); \
65425 + ___retval; \
65426 +})
65427 +
65428 +#define vmalloc_exec(x) \
65429 +({ \
65430 + void *___retval; \
65431 + intoverflow_t ___x = (intoverflow_t)x; \
65432 + if (WARN(___x > ULONG_MAX, "vmalloc_exec size overflow\n"))\
65433 + ___retval = NULL; \
65434 + else \
65435 + ___retval = vmalloc_exec((unsigned long)___x); \
65436 + ___retval; \
65437 +})
65438 +
65439 +#define vmalloc_node(x, y) \
65440 +({ \
65441 + void *___retval; \
65442 + intoverflow_t ___x = (intoverflow_t)x; \
65443 + if (WARN(___x > ULONG_MAX, "vmalloc_node size overflow\n"))\
65444 + ___retval = NULL; \
65445 + else \
65446 + ___retval = vmalloc_node((unsigned long)___x, (y));\
65447 + ___retval; \
65448 +})
65449 +
65450 +#define vzalloc_node(x, y) \
65451 +({ \
65452 + void *___retval; \
65453 + intoverflow_t ___x = (intoverflow_t)x; \
65454 + if (WARN(___x > ULONG_MAX, "vzalloc_node size overflow\n"))\
65455 + ___retval = NULL; \
65456 + else \
65457 + ___retval = vzalloc_node((unsigned long)___x, (y));\
65458 + ___retval; \
65459 +})
65460 +
65461 +#define vmalloc_32(x) \
65462 +({ \
65463 + void *___retval; \
65464 + intoverflow_t ___x = (intoverflow_t)x; \
65465 + if (WARN(___x > ULONG_MAX, "vmalloc_32 size overflow\n"))\
65466 + ___retval = NULL; \
65467 + else \
65468 + ___retval = vmalloc_32((unsigned long)___x); \
65469 + ___retval; \
65470 +})
65471 +
65472 +#define vmalloc_32_user(x) \
65473 +({ \
65474 +void *___retval; \
65475 + intoverflow_t ___x = (intoverflow_t)x; \
65476 + if (WARN(___x > ULONG_MAX, "vmalloc_32_user size overflow\n"))\
65477 + ___retval = NULL; \
65478 + else \
65479 + ___retval = vmalloc_32_user((unsigned long)___x);\
65480 + ___retval; \
65481 +})
65482 +
65483 #endif /* _LINUX_VMALLOC_H */
65484 diff -urNp linux-2.6.39/include/linux/vmstat.h linux-2.6.39/include/linux/vmstat.h
65485 --- linux-2.6.39/include/linux/vmstat.h 2011-05-19 00:06:34.000000000 -0400
65486 +++ linux-2.6.39/include/linux/vmstat.h 2011-05-22 19:36:33.000000000 -0400
65487 @@ -147,18 +147,18 @@ static inline void vm_events_fold_cpu(in
65488 /*
65489 * Zone based page accounting with per cpu differentials.
65490 */
65491 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65492 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65493
65494 static inline void zone_page_state_add(long x, struct zone *zone,
65495 enum zone_stat_item item)
65496 {
65497 - atomic_long_add(x, &zone->vm_stat[item]);
65498 - atomic_long_add(x, &vm_stat[item]);
65499 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
65500 + atomic_long_add_unchecked(x, &vm_stat[item]);
65501 }
65502
65503 static inline unsigned long global_page_state(enum zone_stat_item item)
65504 {
65505 - long x = atomic_long_read(&vm_stat[item]);
65506 + long x = atomic_long_read_unchecked(&vm_stat[item]);
65507 #ifdef CONFIG_SMP
65508 if (x < 0)
65509 x = 0;
65510 @@ -169,7 +169,7 @@ static inline unsigned long global_page_
65511 static inline unsigned long zone_page_state(struct zone *zone,
65512 enum zone_stat_item item)
65513 {
65514 - long x = atomic_long_read(&zone->vm_stat[item]);
65515 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
65516 #ifdef CONFIG_SMP
65517 if (x < 0)
65518 x = 0;
65519 @@ -186,7 +186,7 @@ static inline unsigned long zone_page_st
65520 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
65521 enum zone_stat_item item)
65522 {
65523 - long x = atomic_long_read(&zone->vm_stat[item]);
65524 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
65525
65526 #ifdef CONFIG_SMP
65527 int cpu;
65528 @@ -280,8 +280,8 @@ static inline void __mod_zone_page_state
65529
65530 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
65531 {
65532 - atomic_long_inc(&zone->vm_stat[item]);
65533 - atomic_long_inc(&vm_stat[item]);
65534 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
65535 + atomic_long_inc_unchecked(&vm_stat[item]);
65536 }
65537
65538 static inline void __inc_zone_page_state(struct page *page,
65539 @@ -292,8 +292,8 @@ static inline void __inc_zone_page_state
65540
65541 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
65542 {
65543 - atomic_long_dec(&zone->vm_stat[item]);
65544 - atomic_long_dec(&vm_stat[item]);
65545 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
65546 + atomic_long_dec_unchecked(&vm_stat[item]);
65547 }
65548
65549 static inline void __dec_zone_page_state(struct page *page,
65550 diff -urNp linux-2.6.39/include/media/saa7146_vv.h linux-2.6.39/include/media/saa7146_vv.h
65551 --- linux-2.6.39/include/media/saa7146_vv.h 2011-05-19 00:06:34.000000000 -0400
65552 +++ linux-2.6.39/include/media/saa7146_vv.h 2011-05-22 19:36:33.000000000 -0400
65553 @@ -202,13 +202,13 @@ void saa7146_set_gpio(struct saa7146_dev
65554
65555 /* from saa7146_video.c */
65556 extern const struct v4l2_ioctl_ops saa7146_video_ioctl_ops;
65557 -extern struct saa7146_use_ops saa7146_video_uops;
65558 +extern const struct saa7146_use_ops saa7146_video_uops;
65559 int saa7146_start_preview(struct saa7146_fh *fh);
65560 int saa7146_stop_preview(struct saa7146_fh *fh);
65561 long saa7146_video_do_ioctl(struct file *file, unsigned int cmd, void *arg);
65562
65563 /* from saa7146_vbi.c */
65564 -extern struct saa7146_use_ops saa7146_vbi_uops;
65565 +extern const struct saa7146_use_ops saa7146_vbi_uops;
65566
65567 /* resource management functions */
65568 int saa7146_res_get(struct saa7146_fh *fh, unsigned int bit);
65569 diff -urNp linux-2.6.39/include/media/v4l2-device.h linux-2.6.39/include/media/v4l2-device.h
65570 --- linux-2.6.39/include/media/v4l2-device.h 2011-05-19 00:06:34.000000000 -0400
65571 +++ linux-2.6.39/include/media/v4l2-device.h 2011-05-22 19:36:33.000000000 -0400
65572 @@ -95,7 +95,7 @@ int __must_check v4l2_device_register(st
65573 this function returns 0. If the name ends with a digit (e.g. cx18),
65574 then the name will be set to cx18-0 since cx180 looks really odd. */
65575 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
65576 - atomic_t *instance);
65577 + atomic_unchecked_t *instance);
65578
65579 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
65580 Since the parent disappears this ensures that v4l2_dev doesn't have an
65581 diff -urNp linux-2.6.39/include/net/caif/cfctrl.h linux-2.6.39/include/net/caif/cfctrl.h
65582 --- linux-2.6.39/include/net/caif/cfctrl.h 2011-05-19 00:06:34.000000000 -0400
65583 +++ linux-2.6.39/include/net/caif/cfctrl.h 2011-05-22 19:36:33.000000000 -0400
65584 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
65585 struct cfctrl {
65586 struct cfsrvl serv;
65587 struct cfctrl_rsp res;
65588 - atomic_t req_seq_no;
65589 - atomic_t rsp_seq_no;
65590 + atomic_unchecked_t req_seq_no;
65591 + atomic_unchecked_t rsp_seq_no;
65592 struct list_head list;
65593 /* Protects from simultaneous access to first_req list */
65594 spinlock_t info_list_lock;
65595 diff -urNp linux-2.6.39/include/net/flow.h linux-2.6.39/include/net/flow.h
65596 --- linux-2.6.39/include/net/flow.h 2011-05-19 00:06:34.000000000 -0400
65597 +++ linux-2.6.39/include/net/flow.h 2011-05-22 19:36:33.000000000 -0400
65598 @@ -167,6 +167,6 @@ extern struct flow_cache_object *flow_ca
65599 u8 dir, flow_resolve_t resolver, void *ctx);
65600
65601 extern void flow_cache_flush(void);
65602 -extern atomic_t flow_cache_genid;
65603 +extern atomic_unchecked_t flow_cache_genid;
65604
65605 #endif
65606 diff -urNp linux-2.6.39/include/net/inetpeer.h linux-2.6.39/include/net/inetpeer.h
65607 --- linux-2.6.39/include/net/inetpeer.h 2011-05-19 00:06:34.000000000 -0400
65608 +++ linux-2.6.39/include/net/inetpeer.h 2011-05-22 19:36:33.000000000 -0400
65609 @@ -43,8 +43,8 @@ struct inet_peer {
65610 */
65611 union {
65612 struct {
65613 - atomic_t rid; /* Frag reception counter */
65614 - atomic_t ip_id_count; /* IP ID for the next packet */
65615 + atomic_unchecked_t rid; /* Frag reception counter */
65616 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
65617 __u32 tcp_ts;
65618 __u32 tcp_ts_stamp;
65619 u32 metrics[RTAX_MAX];
65620 @@ -108,7 +108,7 @@ static inline __u16 inet_getid(struct in
65621 {
65622 more++;
65623 inet_peer_refcheck(p);
65624 - return atomic_add_return(more, &p->ip_id_count) - more;
65625 + return atomic_add_return_unchecked(more, &p->ip_id_count) - more;
65626 }
65627
65628 #endif /* _NET_INETPEER_H */
65629 diff -urNp linux-2.6.39/include/net/ip_fib.h linux-2.6.39/include/net/ip_fib.h
65630 --- linux-2.6.39/include/net/ip_fib.h 2011-05-19 00:06:34.000000000 -0400
65631 +++ linux-2.6.39/include/net/ip_fib.h 2011-05-22 19:36:33.000000000 -0400
65632 @@ -146,7 +146,7 @@ extern __be32 fib_info_update_nh_saddr(s
65633
65634 #define FIB_RES_SADDR(net, res) \
65635 ((FIB_RES_NH(res).nh_saddr_genid == \
65636 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
65637 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
65638 FIB_RES_NH(res).nh_saddr : \
65639 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
65640 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
65641 diff -urNp linux-2.6.39/include/net/ip_vs.h linux-2.6.39/include/net/ip_vs.h
65642 --- linux-2.6.39/include/net/ip_vs.h 2011-05-19 00:06:34.000000000 -0400
65643 +++ linux-2.6.39/include/net/ip_vs.h 2011-05-22 19:36:33.000000000 -0400
65644 @@ -512,7 +512,7 @@ struct ip_vs_conn {
65645 struct ip_vs_conn *control; /* Master control connection */
65646 atomic_t n_control; /* Number of controlled ones */
65647 struct ip_vs_dest *dest; /* real server */
65648 - atomic_t in_pkts; /* incoming packet counter */
65649 + atomic_unchecked_t in_pkts; /* incoming packet counter */
65650
65651 /* packet transmitter for different forwarding methods. If it
65652 mangles the packet, it must return NF_DROP or better NF_STOLEN,
65653 @@ -650,7 +650,7 @@ struct ip_vs_dest {
65654 __be16 port; /* port number of the server */
65655 union nf_inet_addr addr; /* IP address of the server */
65656 volatile unsigned flags; /* dest status flags */
65657 - atomic_t conn_flags; /* flags to copy to conn */
65658 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
65659 atomic_t weight; /* server weight */
65660
65661 atomic_t refcnt; /* reference counter */
65662 diff -urNp linux-2.6.39/include/net/irda/ircomm_tty.h linux-2.6.39/include/net/irda/ircomm_tty.h
65663 --- linux-2.6.39/include/net/irda/ircomm_tty.h 2011-05-19 00:06:34.000000000 -0400
65664 +++ linux-2.6.39/include/net/irda/ircomm_tty.h 2011-05-22 19:36:33.000000000 -0400
65665 @@ -35,6 +35,7 @@
65666 #include <linux/termios.h>
65667 #include <linux/timer.h>
65668 #include <linux/tty.h> /* struct tty_struct */
65669 +#include <asm/local.h>
65670
65671 #include <net/irda/irias_object.h>
65672 #include <net/irda/ircomm_core.h>
65673 @@ -105,8 +106,8 @@ struct ircomm_tty_cb {
65674 unsigned short close_delay;
65675 unsigned short closing_wait; /* time to wait before closing */
65676
65677 - int open_count;
65678 - int blocked_open; /* # of blocked opens */
65679 + local_t open_count;
65680 + local_t blocked_open; /* # of blocked opens */
65681
65682 /* Protect concurent access to :
65683 * o self->open_count
65684 diff -urNp linux-2.6.39/include/net/iucv/af_iucv.h linux-2.6.39/include/net/iucv/af_iucv.h
65685 --- linux-2.6.39/include/net/iucv/af_iucv.h 2011-05-19 00:06:34.000000000 -0400
65686 +++ linux-2.6.39/include/net/iucv/af_iucv.h 2011-05-22 19:36:33.000000000 -0400
65687 @@ -87,7 +87,7 @@ struct iucv_sock {
65688 struct iucv_sock_list {
65689 struct hlist_head head;
65690 rwlock_t lock;
65691 - atomic_t autobind_name;
65692 + atomic_unchecked_t autobind_name;
65693 };
65694
65695 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
65696 diff -urNp linux-2.6.39/include/net/neighbour.h linux-2.6.39/include/net/neighbour.h
65697 --- linux-2.6.39/include/net/neighbour.h 2011-05-19 00:06:34.000000000 -0400
65698 +++ linux-2.6.39/include/net/neighbour.h 2011-05-22 19:36:33.000000000 -0400
65699 @@ -118,12 +118,12 @@ struct neighbour {
65700
65701 struct neigh_ops {
65702 int family;
65703 - void (*solicit)(struct neighbour *, struct sk_buff*);
65704 - void (*error_report)(struct neighbour *, struct sk_buff*);
65705 - int (*output)(struct sk_buff*);
65706 - int (*connected_output)(struct sk_buff*);
65707 - int (*hh_output)(struct sk_buff*);
65708 - int (*queue_xmit)(struct sk_buff*);
65709 + void (* const solicit)(struct neighbour *, struct sk_buff*);
65710 + void (* const error_report)(struct neighbour *, struct sk_buff*);
65711 + int (* const output)(struct sk_buff*);
65712 + int (* const connected_output)(struct sk_buff*);
65713 + int (* const hh_output)(struct sk_buff*);
65714 + int (* const queue_xmit)(struct sk_buff*);
65715 };
65716
65717 struct pneigh_entry {
65718 diff -urNp linux-2.6.39/include/net/netfilter/nf_conntrack_ecache.h linux-2.6.39/include/net/netfilter/nf_conntrack_ecache.h
65719 --- linux-2.6.39/include/net/netfilter/nf_conntrack_ecache.h 2011-05-19 00:06:34.000000000 -0400
65720 +++ linux-2.6.39/include/net/netfilter/nf_conntrack_ecache.h 2011-05-22 19:36:33.000000000 -0400
65721 @@ -95,7 +95,7 @@ nf_conntrack_eventmask_report(unsigned i
65722 int report)
65723 {
65724 int ret = 0;
65725 - struct nf_ct_event_notifier *notify;
65726 + const struct nf_ct_event_notifier *notify;
65727 struct nf_conntrack_ecache *e;
65728
65729 rcu_read_lock();
65730 @@ -174,7 +174,7 @@ nf_ct_expect_event_report(enum ip_conntr
65731 u32 pid,
65732 int report)
65733 {
65734 - struct nf_exp_event_notifier *notify;
65735 + const struct nf_exp_event_notifier *notify;
65736 struct nf_conntrack_ecache *e;
65737
65738 rcu_read_lock();
65739 diff -urNp linux-2.6.39/include/net/netlink.h linux-2.6.39/include/net/netlink.h
65740 --- linux-2.6.39/include/net/netlink.h 2011-05-19 00:06:34.000000000 -0400
65741 +++ linux-2.6.39/include/net/netlink.h 2011-05-22 19:36:33.000000000 -0400
65742 @@ -562,7 +562,7 @@ static inline void *nlmsg_get_pos(struct
65743 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
65744 {
65745 if (mark)
65746 - skb_trim(skb, (unsigned char *) mark - skb->data);
65747 + skb_trim(skb, (const unsigned char *) mark - skb->data);
65748 }
65749
65750 /**
65751 diff -urNp linux-2.6.39/include/net/netns/ipv4.h linux-2.6.39/include/net/netns/ipv4.h
65752 --- linux-2.6.39/include/net/netns/ipv4.h 2011-05-19 00:06:34.000000000 -0400
65753 +++ linux-2.6.39/include/net/netns/ipv4.h 2011-05-22 19:36:33.000000000 -0400
65754 @@ -54,8 +54,8 @@ struct netns_ipv4 {
65755 int sysctl_rt_cache_rebuild_count;
65756 int current_rt_cache_rebuild_count;
65757
65758 - atomic_t rt_genid;
65759 - atomic_t dev_addr_genid;
65760 + atomic_unchecked_t rt_genid;
65761 + atomic_unchecked_t dev_addr_genid;
65762
65763 #ifdef CONFIG_IP_MROUTE
65764 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
65765 diff -urNp linux-2.6.39/include/net/sctp/sctp.h linux-2.6.39/include/net/sctp/sctp.h
65766 --- linux-2.6.39/include/net/sctp/sctp.h 2011-05-19 00:06:34.000000000 -0400
65767 +++ linux-2.6.39/include/net/sctp/sctp.h 2011-05-22 19:36:33.000000000 -0400
65768 @@ -316,9 +316,9 @@ do { \
65769
65770 #else /* SCTP_DEBUG */
65771
65772 -#define SCTP_DEBUG_PRINTK(whatever...)
65773 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
65774 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
65775 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
65776 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
65777 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
65778 #define SCTP_ENABLE_DEBUG
65779 #define SCTP_DISABLE_DEBUG
65780 #define SCTP_ASSERT(expr, str, func)
65781 diff -urNp linux-2.6.39/include/net/sock.h linux-2.6.39/include/net/sock.h
65782 --- linux-2.6.39/include/net/sock.h 2011-05-19 00:06:34.000000000 -0400
65783 +++ linux-2.6.39/include/net/sock.h 2011-05-22 19:36:33.000000000 -0400
65784 @@ -277,7 +277,7 @@ struct sock {
65785 #ifdef CONFIG_RPS
65786 __u32 sk_rxhash;
65787 #endif
65788 - atomic_t sk_drops;
65789 + atomic_unchecked_t sk_drops;
65790 int sk_rcvbuf;
65791
65792 struct sk_filter __rcu *sk_filter;
65793 diff -urNp linux-2.6.39/include/net/tcp.h linux-2.6.39/include/net/tcp.h
65794 --- linux-2.6.39/include/net/tcp.h 2011-05-19 00:06:34.000000000 -0400
65795 +++ linux-2.6.39/include/net/tcp.h 2011-05-22 19:36:33.000000000 -0400
65796 @@ -1374,7 +1374,7 @@ enum tcp_seq_states {
65797 struct tcp_seq_afinfo {
65798 char *name;
65799 sa_family_t family;
65800 - struct file_operations seq_fops;
65801 + struct file_operations seq_fops; /* cannot be const */
65802 struct seq_operations seq_ops;
65803 };
65804
65805 diff -urNp linux-2.6.39/include/net/udp.h linux-2.6.39/include/net/udp.h
65806 --- linux-2.6.39/include/net/udp.h 2011-05-19 00:06:34.000000000 -0400
65807 +++ linux-2.6.39/include/net/udp.h 2011-05-22 19:36:33.000000000 -0400
65808 @@ -234,7 +234,7 @@ struct udp_seq_afinfo {
65809 char *name;
65810 sa_family_t family;
65811 struct udp_table *udp_table;
65812 - struct file_operations seq_fops;
65813 + struct file_operations seq_fops; /* cannot be const */
65814 struct seq_operations seq_ops;
65815 };
65816
65817 diff -urNp linux-2.6.39/include/net/xfrm.h linux-2.6.39/include/net/xfrm.h
65818 --- linux-2.6.39/include/net/xfrm.h 2011-05-19 00:06:34.000000000 -0400
65819 +++ linux-2.6.39/include/net/xfrm.h 2011-05-22 19:36:33.000000000 -0400
65820 @@ -505,7 +505,7 @@ struct xfrm_policy {
65821 struct timer_list timer;
65822
65823 struct flow_cache_object flo;
65824 - atomic_t genid;
65825 + atomic_unchecked_t genid;
65826 u32 priority;
65827 u32 index;
65828 struct xfrm_mark mark;
65829 diff -urNp linux-2.6.39/include/pcmcia/ss.h linux-2.6.39/include/pcmcia/ss.h
65830 --- linux-2.6.39/include/pcmcia/ss.h 2011-05-19 00:06:34.000000000 -0400
65831 +++ linux-2.6.39/include/pcmcia/ss.h 2011-05-22 19:36:33.000000000 -0400
65832 @@ -241,9 +241,9 @@ struct pcmcia_socket {
65833 * "select PCCARD_NONSTATIC" in Kconfig.
65834 *
65835 */
65836 -extern struct pccard_resource_ops pccard_static_ops;
65837 +extern const struct pccard_resource_ops pccard_static_ops;
65838 #if defined(CONFIG_PCMCIA) || defined(CONFIG_PCMCIA_MODULE)
65839 -extern struct pccard_resource_ops pccard_iodyn_ops;
65840 +extern const struct pccard_resource_ops pccard_iodyn_ops;
65841 extern struct pccard_resource_ops pccard_nonstatic_ops;
65842 #else
65843 /* If PCMCIA is not used, but only CARDBUS, these functions are not used
65844 diff -urNp linux-2.6.39/include/rdma/ib_verbs.h linux-2.6.39/include/rdma/ib_verbs.h
65845 --- linux-2.6.39/include/rdma/ib_verbs.h 2011-05-19 00:06:34.000000000 -0400
65846 +++ linux-2.6.39/include/rdma/ib_verbs.h 2011-05-22 19:36:33.000000000 -0400
65847 @@ -1149,7 +1149,7 @@ struct ib_device {
65848 struct ib_mad *in_mad,
65849 struct ib_mad *out_mad);
65850
65851 - struct ib_dma_mapping_ops *dma_ops;
65852 + const struct ib_dma_mapping_ops *dma_ops;
65853
65854 struct module *owner;
65855 struct device dev;
65856 diff -urNp linux-2.6.39/include/scsi/libfc.h linux-2.6.39/include/scsi/libfc.h
65857 --- linux-2.6.39/include/scsi/libfc.h 2011-05-19 00:06:34.000000000 -0400
65858 +++ linux-2.6.39/include/scsi/libfc.h 2011-05-22 19:36:33.000000000 -0400
65859 @@ -202,7 +202,7 @@ struct fc_rport_priv {
65860 struct mutex rp_mutex;
65861 struct delayed_work retry_work;
65862 enum fc_rport_event event;
65863 - struct fc_rport_operations *ops;
65864 + const struct fc_rport_operations *ops;
65865 struct list_head peers;
65866 struct work_struct event_work;
65867 u32 supported_classes;
65868 diff -urNp linux-2.6.39/include/scsi/scsi_device.h linux-2.6.39/include/scsi/scsi_device.h
65869 --- linux-2.6.39/include/scsi/scsi_device.h 2011-05-19 00:06:34.000000000 -0400
65870 +++ linux-2.6.39/include/scsi/scsi_device.h 2011-05-22 19:36:33.000000000 -0400
65871 @@ -161,9 +161,9 @@ struct scsi_device {
65872 unsigned int max_device_blocked; /* what device_blocked counts down from */
65873 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
65874
65875 - atomic_t iorequest_cnt;
65876 - atomic_t iodone_cnt;
65877 - atomic_t ioerr_cnt;
65878 + atomic_unchecked_t iorequest_cnt;
65879 + atomic_unchecked_t iodone_cnt;
65880 + atomic_unchecked_t ioerr_cnt;
65881
65882 struct device sdev_gendev,
65883 sdev_dev;
65884 diff -urNp linux-2.6.39/include/sound/ac97_codec.h linux-2.6.39/include/sound/ac97_codec.h
65885 --- linux-2.6.39/include/sound/ac97_codec.h 2011-05-19 00:06:34.000000000 -0400
65886 +++ linux-2.6.39/include/sound/ac97_codec.h 2011-05-22 19:36:33.000000000 -0400
65887 @@ -424,15 +424,15 @@
65888 struct snd_ac97;
65889
65890 struct snd_ac97_build_ops {
65891 - int (*build_3d) (struct snd_ac97 *ac97);
65892 - int (*build_specific) (struct snd_ac97 *ac97);
65893 - int (*build_spdif) (struct snd_ac97 *ac97);
65894 - int (*build_post_spdif) (struct snd_ac97 *ac97);
65895 + int (* const build_3d) (struct snd_ac97 *ac97);
65896 + int (* const build_specific) (struct snd_ac97 *ac97);
65897 + int (* const build_spdif) (struct snd_ac97 *ac97);
65898 + int (* const build_post_spdif) (struct snd_ac97 *ac97);
65899 #ifdef CONFIG_PM
65900 - void (*suspend) (struct snd_ac97 *ac97);
65901 - void (*resume) (struct snd_ac97 *ac97);
65902 + void (* const suspend) (struct snd_ac97 *ac97);
65903 + void (* const resume) (struct snd_ac97 *ac97);
65904 #endif
65905 - void (*update_jacks) (struct snd_ac97 *ac97); /* for jack-sharing */
65906 + void (* const update_jacks) (struct snd_ac97 *ac97); /* for jack-sharing */
65907 };
65908
65909 struct snd_ac97_bus_ops {
65910 @@ -446,7 +446,7 @@ struct snd_ac97_bus_ops {
65911
65912 struct snd_ac97_bus {
65913 /* -- lowlevel (hardware) driver specific -- */
65914 - struct snd_ac97_bus_ops *ops;
65915 + const struct snd_ac97_bus_ops *ops;
65916 void *private_data;
65917 void (*private_free) (struct snd_ac97_bus *bus);
65918 /* --- */
65919 @@ -556,7 +556,7 @@ static inline int ac97_can_spdif(struct
65920
65921 /* functions */
65922 /* create new AC97 bus */
65923 -int snd_ac97_bus(struct snd_card *card, int num, struct snd_ac97_bus_ops *ops,
65924 +int snd_ac97_bus(struct snd_card *card, int num, const struct snd_ac97_bus_ops *ops,
65925 void *private_data, struct snd_ac97_bus **rbus);
65926 /* create mixer controls */
65927 int snd_ac97_mixer(struct snd_ac97_bus *bus, struct snd_ac97_template *template,
65928 diff -urNp linux-2.6.39/include/sound/core.h linux-2.6.39/include/sound/core.h
65929 --- linux-2.6.39/include/sound/core.h 2011-05-19 00:06:34.000000000 -0400
65930 +++ linux-2.6.39/include/sound/core.h 2011-05-22 19:36:33.000000000 -0400
65931 @@ -88,7 +88,7 @@ struct snd_device {
65932 snd_device_state_t state; /* state of the device */
65933 snd_device_type_t type; /* device type */
65934 void *device_data; /* device structure */
65935 - struct snd_device_ops *ops; /* operations */
65936 + const struct snd_device_ops *ops; /* operations */
65937 };
65938
65939 #define snd_device(n) list_entry(n, struct snd_device, list)
65940 @@ -301,7 +301,7 @@ int snd_card_file_remove(struct snd_card
65941 /* device.c */
65942
65943 int snd_device_new(struct snd_card *card, snd_device_type_t type,
65944 - void *device_data, struct snd_device_ops *ops);
65945 + void *device_data, const struct snd_device_ops *ops);
65946 int snd_device_register(struct snd_card *card, void *device_data);
65947 int snd_device_register_all(struct snd_card *card);
65948 int snd_device_disconnect(struct snd_card *card, void *device_data);
65949 diff -urNp linux-2.6.39/include/sound/pcm.h linux-2.6.39/include/sound/pcm.h
65950 --- linux-2.6.39/include/sound/pcm.h 2011-05-19 00:06:34.000000000 -0400
65951 +++ linux-2.6.39/include/sound/pcm.h 2011-05-22 19:36:33.000000000 -0400
65952 @@ -379,7 +379,7 @@ struct snd_pcm_substream {
65953 unsigned int dma_buf_id;
65954 size_t dma_max;
65955 /* -- hardware operations -- */
65956 - struct snd_pcm_ops *ops;
65957 + const struct snd_pcm_ops *ops;
65958 /* -- runtime information -- */
65959 struct snd_pcm_runtime *runtime;
65960 /* -- timer section -- */
65961 @@ -845,7 +845,7 @@ const unsigned char *snd_pcm_format_sile
65962 int snd_pcm_format_set_silence(snd_pcm_format_t format, void *buf, unsigned int frames);
65963 snd_pcm_format_t snd_pcm_build_linear_format(int width, int unsignd, int big_endian);
65964
65965 -void snd_pcm_set_ops(struct snd_pcm * pcm, int direction, struct snd_pcm_ops *ops);
65966 +void snd_pcm_set_ops(struct snd_pcm * pcm, int direction, const struct snd_pcm_ops *ops);
65967 void snd_pcm_set_sync(struct snd_pcm_substream *substream);
65968 int snd_pcm_lib_interleave_len(struct snd_pcm_substream *substream);
65969 int snd_pcm_lib_ioctl(struct snd_pcm_substream *substream,
65970 diff -urNp linux-2.6.39/include/sound/rawmidi.h linux-2.6.39/include/sound/rawmidi.h
65971 --- linux-2.6.39/include/sound/rawmidi.h 2011-05-19 00:06:34.000000000 -0400
65972 +++ linux-2.6.39/include/sound/rawmidi.h 2011-05-22 19:36:33.000000000 -0400
65973 @@ -100,7 +100,7 @@ struct snd_rawmidi_substream {
65974 struct snd_rawmidi_runtime *runtime;
65975 struct pid *pid;
65976 /* hardware layer */
65977 - struct snd_rawmidi_ops *ops;
65978 + const struct snd_rawmidi_ops *ops;
65979 };
65980
65981 struct snd_rawmidi_file {
65982 @@ -127,7 +127,7 @@ struct snd_rawmidi {
65983 int ossreg;
65984 #endif
65985
65986 - struct snd_rawmidi_global_ops *ops;
65987 + const struct snd_rawmidi_global_ops *ops;
65988
65989 struct snd_rawmidi_str streams[2];
65990
65991 @@ -151,7 +151,7 @@ int snd_rawmidi_new(struct snd_card *car
65992 int output_count, int input_count,
65993 struct snd_rawmidi **rmidi);
65994 void snd_rawmidi_set_ops(struct snd_rawmidi *rmidi, int stream,
65995 - struct snd_rawmidi_ops *ops);
65996 + const struct snd_rawmidi_ops *ops);
65997
65998 /* callbacks */
65999
66000 diff -urNp linux-2.6.39/include/sound/seq_device.h linux-2.6.39/include/sound/seq_device.h
66001 --- linux-2.6.39/include/sound/seq_device.h 2011-05-19 00:06:34.000000000 -0400
66002 +++ linux-2.6.39/include/sound/seq_device.h 2011-05-22 19:36:33.000000000 -0400
66003 @@ -69,7 +69,7 @@ struct snd_seq_dev_ops {
66004 */
66005 void snd_seq_device_load_drivers(void);
66006 int snd_seq_device_new(struct snd_card *card, int device, char *id, int argsize, struct snd_seq_device **result);
66007 -int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry, int argsize);
66008 +int snd_seq_device_register_driver(char *id, const struct snd_seq_dev_ops *entry, int argsize);
66009 int snd_seq_device_unregister_driver(char *id);
66010
66011 #define SNDRV_SEQ_DEVICE_ARGPTR(dev) (void *)((char *)(dev) + sizeof(struct snd_seq_device))
66012 diff -urNp linux-2.6.39/include/sound/snd_wavefront.h linux-2.6.39/include/sound/snd_wavefront.h
66013 --- linux-2.6.39/include/sound/snd_wavefront.h 2011-05-19 00:06:34.000000000 -0400
66014 +++ linux-2.6.39/include/sound/snd_wavefront.h 2011-05-22 19:36:33.000000000 -0400
66015 @@ -37,8 +37,8 @@ struct _snd_wavefront_midi {
66016 #define MPU_ACK 0xFE
66017 #define UART_MODE_ON 0x3F
66018
66019 -extern struct snd_rawmidi_ops snd_wavefront_midi_output;
66020 -extern struct snd_rawmidi_ops snd_wavefront_midi_input;
66021 +extern const struct snd_rawmidi_ops snd_wavefront_midi_output;
66022 +extern const struct snd_rawmidi_ops snd_wavefront_midi_input;
66023
66024 extern void snd_wavefront_midi_enable_virtual (snd_wavefront_card_t *);
66025 extern void snd_wavefront_midi_disable_virtual (snd_wavefront_card_t *);
66026 diff -urNp linux-2.6.39/include/sound/soc.h linux-2.6.39/include/sound/soc.h
66027 --- linux-2.6.39/include/sound/soc.h 2011-05-19 00:06:34.000000000 -0400
66028 +++ linux-2.6.39/include/sound/soc.h 2011-05-22 19:36:33.000000000 -0400
66029 @@ -245,7 +245,7 @@ struct snd_soc_jack_gpio;
66030
66031 typedef int (*hw_write_t)(void *,const char* ,int);
66032
66033 -extern struct snd_ac97_bus_ops soc_ac97_ops;
66034 +extern const struct snd_ac97_bus_ops soc_ac97_ops;
66035
66036 enum snd_soc_control_type {
66037 SND_SOC_CUSTOM,
66038 diff -urNp linux-2.6.39/include/sound/ymfpci.h linux-2.6.39/include/sound/ymfpci.h
66039 --- linux-2.6.39/include/sound/ymfpci.h 2011-05-19 00:06:34.000000000 -0400
66040 +++ linux-2.6.39/include/sound/ymfpci.h 2011-05-22 19:36:33.000000000 -0400
66041 @@ -358,7 +358,7 @@ struct snd_ymfpci {
66042 spinlock_t reg_lock;
66043 spinlock_t voice_lock;
66044 wait_queue_head_t interrupt_sleep;
66045 - atomic_t interrupt_sleep_count;
66046 + atomic_unchecked_t interrupt_sleep_count;
66047 struct snd_info_entry *proc_entry;
66048 const struct firmware *dsp_microcode;
66049 const struct firmware *controller_microcode;
66050 diff -urNp linux-2.6.39/include/target/target_core_base.h linux-2.6.39/include/target/target_core_base.h
66051 --- linux-2.6.39/include/target/target_core_base.h 2011-05-19 00:06:34.000000000 -0400
66052 +++ linux-2.6.39/include/target/target_core_base.h 2011-05-22 19:36:33.000000000 -0400
66053 @@ -431,8 +431,8 @@ struct se_transport_task {
66054 atomic_t t_task_cdbs_left;
66055 atomic_t t_task_cdbs_ex_left;
66056 atomic_t t_task_cdbs_timeout_left;
66057 - atomic_t t_task_cdbs_sent;
66058 - atomic_t t_transport_aborted;
66059 + atomic_unchecked_t t_task_cdbs_sent;
66060 + atomic_unchecked_t t_transport_aborted;
66061 atomic_t t_transport_active;
66062 atomic_t t_transport_complete;
66063 atomic_t t_transport_queue_active;
66064 @@ -773,7 +773,7 @@ struct se_device {
66065 atomic_t active_cmds;
66066 atomic_t simple_cmds;
66067 atomic_t depth_left;
66068 - atomic_t dev_ordered_id;
66069 + atomic_unchecked_t dev_ordered_id;
66070 atomic_t dev_tur_active;
66071 atomic_t execute_tasks;
66072 atomic_t dev_status_thr_count;
66073 diff -urNp linux-2.6.39/include/trace/events/irq.h linux-2.6.39/include/trace/events/irq.h
66074 --- linux-2.6.39/include/trace/events/irq.h 2011-05-19 00:06:34.000000000 -0400
66075 +++ linux-2.6.39/include/trace/events/irq.h 2011-05-22 19:36:33.000000000 -0400
66076 @@ -36,7 +36,7 @@ struct softirq_action;
66077 */
66078 TRACE_EVENT(irq_handler_entry,
66079
66080 - TP_PROTO(int irq, struct irqaction *action),
66081 + TP_PROTO(int irq, const struct irqaction *action),
66082
66083 TP_ARGS(irq, action),
66084
66085 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
66086 */
66087 TRACE_EVENT(irq_handler_exit,
66088
66089 - TP_PROTO(int irq, struct irqaction *action, int ret),
66090 + TP_PROTO(int irq, const struct irqaction *action, int ret),
66091
66092 TP_ARGS(irq, action, ret),
66093
66094 diff -urNp linux-2.6.39/include/video/udlfb.h linux-2.6.39/include/video/udlfb.h
66095 --- linux-2.6.39/include/video/udlfb.h 2011-05-19 00:06:34.000000000 -0400
66096 +++ linux-2.6.39/include/video/udlfb.h 2011-05-22 19:36:33.000000000 -0400
66097 @@ -51,10 +51,10 @@ struct dlfb_data {
66098 int base8;
66099 u32 pseudo_palette[256];
66100 /* blit-only rendering path metrics, exposed through sysfs */
66101 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
66102 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
66103 - atomic_t bytes_sent; /* to usb, after compression including overhead */
66104 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
66105 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
66106 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
66107 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
66108 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
66109 };
66110
66111 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
66112 diff -urNp linux-2.6.39/include/video/uvesafb.h linux-2.6.39/include/video/uvesafb.h
66113 --- linux-2.6.39/include/video/uvesafb.h 2011-05-19 00:06:34.000000000 -0400
66114 +++ linux-2.6.39/include/video/uvesafb.h 2011-05-22 19:36:33.000000000 -0400
66115 @@ -177,6 +177,7 @@ struct uvesafb_par {
66116 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
66117 u8 pmi_setpal; /* PMI for palette changes */
66118 u16 *pmi_base; /* protected mode interface location */
66119 + u8 *pmi_code; /* protected mode code location */
66120 void *pmi_start;
66121 void *pmi_pal;
66122 u8 *vbe_state_orig; /*
66123 diff -urNp linux-2.6.39/init/do_mounts.c linux-2.6.39/init/do_mounts.c
66124 --- linux-2.6.39/init/do_mounts.c 2011-05-19 00:06:34.000000000 -0400
66125 +++ linux-2.6.39/init/do_mounts.c 2011-05-22 19:36:33.000000000 -0400
66126 @@ -287,7 +287,7 @@ static void __init get_fs_names(char *pa
66127
66128 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
66129 {
66130 - int err = sys_mount(name, "/root", fs, flags, data);
66131 + int err = sys_mount((__force char __user *)name, (__force char __user *)"/root", (__force char __user *)fs, flags, (__force void __user *)data);
66132 if (err)
66133 return err;
66134
66135 @@ -383,18 +383,18 @@ void __init change_floppy(char *fmt, ...
66136 va_start(args, fmt);
66137 vsprintf(buf, fmt, args);
66138 va_end(args);
66139 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
66140 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
66141 if (fd >= 0) {
66142 sys_ioctl(fd, FDEJECT, 0);
66143 sys_close(fd);
66144 }
66145 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
66146 - fd = sys_open("/dev/console", O_RDWR, 0);
66147 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
66148 if (fd >= 0) {
66149 sys_ioctl(fd, TCGETS, (long)&termios);
66150 termios.c_lflag &= ~ICANON;
66151 sys_ioctl(fd, TCSETSF, (long)&termios);
66152 - sys_read(fd, &c, 1);
66153 + sys_read(fd, (char __user *)&c, 1);
66154 termios.c_lflag |= ICANON;
66155 sys_ioctl(fd, TCSETSF, (long)&termios);
66156 sys_close(fd);
66157 @@ -488,6 +488,6 @@ void __init prepare_namespace(void)
66158 mount_root();
66159 out:
66160 devtmpfs_mount("dev");
66161 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
66162 + sys_mount((__force char __user *)".", (__force char __user *)"/", NULL, MS_MOVE, NULL);
66163 sys_chroot((const char __user __force *)".");
66164 }
66165 diff -urNp linux-2.6.39/init/do_mounts.h linux-2.6.39/init/do_mounts.h
66166 --- linux-2.6.39/init/do_mounts.h 2011-05-19 00:06:34.000000000 -0400
66167 +++ linux-2.6.39/init/do_mounts.h 2011-05-22 19:36:33.000000000 -0400
66168 @@ -15,15 +15,15 @@ extern int root_mountflags;
66169
66170 static inline int create_dev(char *name, dev_t dev)
66171 {
66172 - sys_unlink(name);
66173 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
66174 + sys_unlink((__force char __user *)name);
66175 + return sys_mknod((__force char __user *)name, S_IFBLK|0600, new_encode_dev(dev));
66176 }
66177
66178 #if BITS_PER_LONG == 32
66179 static inline u32 bstat(char *name)
66180 {
66181 struct stat64 stat;
66182 - if (sys_stat64(name, &stat) != 0)
66183 + if (sys_stat64((__force char __user *)name, (__force struct stat64 __user *)&stat) != 0)
66184 return 0;
66185 if (!S_ISBLK(stat.st_mode))
66186 return 0;
66187 diff -urNp linux-2.6.39/init/do_mounts_initrd.c linux-2.6.39/init/do_mounts_initrd.c
66188 --- linux-2.6.39/init/do_mounts_initrd.c 2011-05-19 00:06:34.000000000 -0400
66189 +++ linux-2.6.39/init/do_mounts_initrd.c 2011-05-22 19:36:33.000000000 -0400
66190 @@ -44,13 +44,13 @@ static void __init handle_initrd(void)
66191 create_dev("/dev/root.old", Root_RAM0);
66192 /* mount initrd on rootfs' /root */
66193 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
66194 - sys_mkdir("/old", 0700);
66195 - root_fd = sys_open("/", 0, 0);
66196 - old_fd = sys_open("/old", 0, 0);
66197 + sys_mkdir((__force const char __user *)"/old", 0700);
66198 + root_fd = sys_open((__force const char __user *)"/", 0, 0);
66199 + old_fd = sys_open((__force const char __user *)"/old", 0, 0);
66200 /* move initrd over / and chdir/chroot in initrd root */
66201 - sys_chdir("/root");
66202 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
66203 - sys_chroot(".");
66204 + sys_chdir((__force const char __user *)"/root");
66205 + sys_mount((__force char __user *)".", (__force char __user *)"/", NULL, MS_MOVE, NULL);
66206 + sys_chroot((__force const char __user *)".");
66207
66208 /*
66209 * In case that a resume from disk is carried out by linuxrc or one of
66210 @@ -67,15 +67,15 @@ static void __init handle_initrd(void)
66211
66212 /* move initrd to rootfs' /old */
66213 sys_fchdir(old_fd);
66214 - sys_mount("/", ".", NULL, MS_MOVE, NULL);
66215 + sys_mount((__force char __user *)"/", (__force char __user *)".", NULL, MS_MOVE, NULL);
66216 /* switch root and cwd back to / of rootfs */
66217 sys_fchdir(root_fd);
66218 - sys_chroot(".");
66219 + sys_chroot((__force const char __user *)".");
66220 sys_close(old_fd);
66221 sys_close(root_fd);
66222
66223 if (new_decode_dev(real_root_dev) == Root_RAM0) {
66224 - sys_chdir("/old");
66225 + sys_chdir((__force const char __user *)"/old");
66226 return;
66227 }
66228
66229 @@ -83,17 +83,17 @@ static void __init handle_initrd(void)
66230 mount_root();
66231
66232 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
66233 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
66234 + error = sys_mount((__force char __user *)"/old", (__force char __user *)"/root/initrd", NULL, MS_MOVE, NULL);
66235 if (!error)
66236 printk("okay\n");
66237 else {
66238 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
66239 + int fd = sys_open((__force const char __user *)"/dev/root.old", O_RDWR, 0);
66240 if (error == -ENOENT)
66241 printk("/initrd does not exist. Ignored.\n");
66242 else
66243 printk("failed\n");
66244 printk(KERN_NOTICE "Unmounting old root\n");
66245 - sys_umount("/old", MNT_DETACH);
66246 + sys_umount((__force char __user *)"/old", MNT_DETACH);
66247 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
66248 if (fd < 0) {
66249 error = fd;
66250 @@ -116,11 +116,11 @@ int __init initrd_load(void)
66251 * mounted in the normal path.
66252 */
66253 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
66254 - sys_unlink("/initrd.image");
66255 + sys_unlink((__force const char __user *)"/initrd.image");
66256 handle_initrd();
66257 return 1;
66258 }
66259 }
66260 - sys_unlink("/initrd.image");
66261 + sys_unlink((__force const char __user *)"/initrd.image");
66262 return 0;
66263 }
66264 diff -urNp linux-2.6.39/init/do_mounts_md.c linux-2.6.39/init/do_mounts_md.c
66265 --- linux-2.6.39/init/do_mounts_md.c 2011-05-19 00:06:34.000000000 -0400
66266 +++ linux-2.6.39/init/do_mounts_md.c 2011-05-22 19:36:33.000000000 -0400
66267 @@ -170,7 +170,7 @@ static void __init md_setup_drive(void)
66268 partitioned ? "_d" : "", minor,
66269 md_setup_args[ent].device_names);
66270
66271 - fd = sys_open(name, 0, 0);
66272 + fd = sys_open((__force char __user *)name, 0, 0);
66273 if (fd < 0) {
66274 printk(KERN_ERR "md: open failed - cannot start "
66275 "array %s\n", name);
66276 @@ -233,7 +233,7 @@ static void __init md_setup_drive(void)
66277 * array without it
66278 */
66279 sys_close(fd);
66280 - fd = sys_open(name, 0, 0);
66281 + fd = sys_open((__force char __user *)name, 0, 0);
66282 sys_ioctl(fd, BLKRRPART, 0);
66283 }
66284 sys_close(fd);
66285 diff -urNp linux-2.6.39/init/initramfs.c linux-2.6.39/init/initramfs.c
66286 --- linux-2.6.39/init/initramfs.c 2011-05-19 00:06:34.000000000 -0400
66287 +++ linux-2.6.39/init/initramfs.c 2011-05-22 19:36:33.000000000 -0400
66288 @@ -74,7 +74,7 @@ static void __init free_hash(void)
66289 }
66290 }
66291
66292 -static long __init do_utime(char __user *filename, time_t mtime)
66293 +static long __init do_utime(__force char __user *filename, time_t mtime)
66294 {
66295 struct timespec t[2];
66296
66297 @@ -109,7 +109,7 @@ static void __init dir_utime(void)
66298 struct dir_entry *de, *tmp;
66299 list_for_each_entry_safe(de, tmp, &dir_list, list) {
66300 list_del(&de->list);
66301 - do_utime(de->name, de->mtime);
66302 + do_utime((__force char __user *)de->name, de->mtime);
66303 kfree(de->name);
66304 kfree(de);
66305 }
66306 @@ -271,7 +271,7 @@ static int __init maybe_link(void)
66307 if (nlink >= 2) {
66308 char *old = find_link(major, minor, ino, mode, collected);
66309 if (old)
66310 - return (sys_link(old, collected) < 0) ? -1 : 1;
66311 + return (sys_link((__force char __user *)old, (__force char __user *)collected) < 0) ? -1 : 1;
66312 }
66313 return 0;
66314 }
66315 @@ -280,11 +280,11 @@ static void __init clean_path(char *path
66316 {
66317 struct stat st;
66318
66319 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
66320 + if (!sys_newlstat((__force char __user *)path, (__force struct stat __user *)&st) && (st.st_mode^mode) & S_IFMT) {
66321 if (S_ISDIR(st.st_mode))
66322 - sys_rmdir(path);
66323 + sys_rmdir((__force char __user *)path);
66324 else
66325 - sys_unlink(path);
66326 + sys_unlink((__force char __user *)path);
66327 }
66328 }
66329
66330 @@ -305,7 +305,7 @@ static int __init do_name(void)
66331 int openflags = O_WRONLY|O_CREAT;
66332 if (ml != 1)
66333 openflags |= O_TRUNC;
66334 - wfd = sys_open(collected, openflags, mode);
66335 + wfd = sys_open((__force char __user *)collected, openflags, mode);
66336
66337 if (wfd >= 0) {
66338 sys_fchown(wfd, uid, gid);
66339 @@ -317,17 +317,17 @@ static int __init do_name(void)
66340 }
66341 }
66342 } else if (S_ISDIR(mode)) {
66343 - sys_mkdir(collected, mode);
66344 - sys_chown(collected, uid, gid);
66345 - sys_chmod(collected, mode);
66346 + sys_mkdir((__force char __user *)collected, mode);
66347 + sys_chown((__force char __user *)collected, uid, gid);
66348 + sys_chmod((__force char __user *)collected, mode);
66349 dir_add(collected, mtime);
66350 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
66351 S_ISFIFO(mode) || S_ISSOCK(mode)) {
66352 if (maybe_link() == 0) {
66353 - sys_mknod(collected, mode, rdev);
66354 - sys_chown(collected, uid, gid);
66355 - sys_chmod(collected, mode);
66356 - do_utime(collected, mtime);
66357 + sys_mknod((__force char __user *)collected, mode, rdev);
66358 + sys_chown((__force char __user *)collected, uid, gid);
66359 + sys_chmod((__force char __user *)collected, mode);
66360 + do_utime((__force char __user *)collected, mtime);
66361 }
66362 }
66363 return 0;
66364 @@ -336,15 +336,15 @@ static int __init do_name(void)
66365 static int __init do_copy(void)
66366 {
66367 if (count >= body_len) {
66368 - sys_write(wfd, victim, body_len);
66369 + sys_write(wfd, (__force char __user *)victim, body_len);
66370 sys_close(wfd);
66371 - do_utime(vcollected, mtime);
66372 + do_utime((__force char __user *)vcollected, mtime);
66373 kfree(vcollected);
66374 eat(body_len);
66375 state = SkipIt;
66376 return 0;
66377 } else {
66378 - sys_write(wfd, victim, count);
66379 + sys_write(wfd, (__force char __user *)victim, count);
66380 body_len -= count;
66381 eat(count);
66382 return 1;
66383 @@ -355,9 +355,9 @@ static int __init do_symlink(void)
66384 {
66385 collected[N_ALIGN(name_len) + body_len] = '\0';
66386 clean_path(collected, 0);
66387 - sys_symlink(collected + N_ALIGN(name_len), collected);
66388 - sys_lchown(collected, uid, gid);
66389 - do_utime(collected, mtime);
66390 + sys_symlink((__force char __user *)collected + N_ALIGN(name_len), (__force char __user *)collected);
66391 + sys_lchown((__force char __user *)collected, uid, gid);
66392 + do_utime((__force char __user *)collected, mtime);
66393 state = SkipIt;
66394 next_state = Reset;
66395 return 0;
66396 diff -urNp linux-2.6.39/init/Kconfig linux-2.6.39/init/Kconfig
66397 --- linux-2.6.39/init/Kconfig 2011-05-19 00:06:34.000000000 -0400
66398 +++ linux-2.6.39/init/Kconfig 2011-05-22 19:36:33.000000000 -0400
66399 @@ -1202,7 +1202,7 @@ config SLUB_DEBUG
66400
66401 config COMPAT_BRK
66402 bool "Disable heap randomization"
66403 - default y
66404 + default n
66405 help
66406 Randomizing heap placement makes heap exploits harder, but it
66407 also breaks ancient binaries (including anything libc5 based).
66408 diff -urNp linux-2.6.39/init/main.c linux-2.6.39/init/main.c
66409 --- linux-2.6.39/init/main.c 2011-05-19 00:06:34.000000000 -0400
66410 +++ linux-2.6.39/init/main.c 2011-05-22 19:41:42.000000000 -0400
66411 @@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void)
66412 extern void tc_init(void);
66413 #endif
66414
66415 +extern void grsecurity_init(void);
66416 +
66417 /*
66418 * Debug helper: via this flag we know that we are in 'early bootup code'
66419 * where only the boot processor is running with IRQ disabled. This means
66420 @@ -149,6 +151,49 @@ static int __init set_reset_devices(char
66421
66422 __setup("reset_devices", set_reset_devices);
66423
66424 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
66425 +extern char pax_enter_kernel_user[];
66426 +extern char pax_exit_kernel_user[];
66427 +extern pgdval_t clone_pgd_mask;
66428 +#endif
66429 +
66430 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
66431 +static int __init setup_pax_nouderef(char *str)
66432 +{
66433 +#ifdef CONFIG_X86_32
66434 + unsigned int cpu;
66435 + struct desc_struct *gdt;
66436 +
66437 + for (cpu = 0; cpu < NR_CPUS; cpu++) {
66438 + gdt = get_cpu_gdt_table(cpu);
66439 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
66440 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
66441 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
66442 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
66443 + }
66444 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
66445 +#else
66446 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
66447 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
66448 + clone_pgd_mask = ~(pgdval_t)0UL;
66449 +#endif
66450 +
66451 + return 0;
66452 +}
66453 +early_param("pax_nouderef", setup_pax_nouderef);
66454 +#endif
66455 +
66456 +#ifdef CONFIG_PAX_SOFTMODE
66457 +unsigned int pax_softmode;
66458 +
66459 +static int __init setup_pax_softmode(char *str)
66460 +{
66461 + get_option(&str, &pax_softmode);
66462 + return 1;
66463 +}
66464 +__setup("pax_softmode=", setup_pax_softmode);
66465 +#endif
66466 +
66467 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
66468 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
66469 static const char *panic_later, *panic_param;
66470 @@ -663,6 +708,7 @@ int __init_or_module do_one_initcall(ini
66471 {
66472 int count = preempt_count();
66473 int ret;
66474 + const char *msg1 = "", *msg2 = "";
66475
66476 if (initcall_debug)
66477 ret = do_one_initcall_debug(fn);
66478 @@ -675,15 +721,15 @@ int __init_or_module do_one_initcall(ini
66479 sprintf(msgbuf, "error code %d ", ret);
66480
66481 if (preempt_count() != count) {
66482 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
66483 + msg1 = " preemption imbalance";
66484 preempt_count() = count;
66485 }
66486 if (irqs_disabled()) {
66487 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
66488 + msg2 = " disabled interrupts";
66489 local_irq_enable();
66490 }
66491 - if (msgbuf[0]) {
66492 - printk("initcall %pF returned with %s\n", fn, msgbuf);
66493 + if (msgbuf[0] || *msg1 || *msg2) {
66494 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
66495 }
66496
66497 return ret;
66498 @@ -801,7 +847,7 @@ static int __init kernel_init(void * unu
66499 do_basic_setup();
66500
66501 /* Open the /dev/console on the rootfs, this should never fail */
66502 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
66503 + if (sys_open((__force const char __user *) "/dev/console", O_RDWR, 0) < 0)
66504 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
66505
66506 (void) sys_dup(0);
66507 @@ -814,11 +860,13 @@ static int __init kernel_init(void * unu
66508 if (!ramdisk_execute_command)
66509 ramdisk_execute_command = "/init";
66510
66511 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
66512 + if (sys_access((__force const char __user *) ramdisk_execute_command, 0) != 0) {
66513 ramdisk_execute_command = NULL;
66514 prepare_namespace();
66515 }
66516
66517 + grsecurity_init();
66518 +
66519 /*
66520 * Ok, we have completed the initial bootup, and
66521 * we're essentially up and running. Get rid of the
66522 diff -urNp linux-2.6.39/ipc/mqueue.c linux-2.6.39/ipc/mqueue.c
66523 --- linux-2.6.39/ipc/mqueue.c 2011-05-19 00:06:34.000000000 -0400
66524 +++ linux-2.6.39/ipc/mqueue.c 2011-05-22 19:41:42.000000000 -0400
66525 @@ -154,6 +154,7 @@ static struct inode *mqueue_get_inode(st
66526 mq_bytes = (mq_msg_tblsz +
66527 (info->attr.mq_maxmsg * info->attr.mq_msgsize));
66528
66529 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
66530 spin_lock(&mq_lock);
66531 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
66532 u->mq_bytes + mq_bytes >
66533 diff -urNp linux-2.6.39/ipc/sem.c linux-2.6.39/ipc/sem.c
66534 --- linux-2.6.39/ipc/sem.c 2011-05-19 00:06:34.000000000 -0400
66535 +++ linux-2.6.39/ipc/sem.c 2011-05-22 19:36:33.000000000 -0400
66536 @@ -854,6 +854,8 @@ static int semctl_main(struct ipc_namesp
66537 int nsems;
66538 struct list_head tasks;
66539
66540 + pax_track_stack();
66541 +
66542 sma = sem_lock_check(ns, semid);
66543 if (IS_ERR(sma))
66544 return PTR_ERR(sma);
66545 @@ -1301,6 +1303,8 @@ SYSCALL_DEFINE4(semtimedop, int, semid,
66546 struct ipc_namespace *ns;
66547 struct list_head tasks;
66548
66549 + pax_track_stack();
66550 +
66551 ns = current->nsproxy->ipc_ns;
66552
66553 if (nsops < 1 || semid < 0)
66554 diff -urNp linux-2.6.39/ipc/shm.c linux-2.6.39/ipc/shm.c
66555 --- linux-2.6.39/ipc/shm.c 2011-05-19 00:06:34.000000000 -0400
66556 +++ linux-2.6.39/ipc/shm.c 2011-05-22 19:41:42.000000000 -0400
66557 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_name
66558 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
66559 #endif
66560
66561 +#ifdef CONFIG_GRKERNSEC
66562 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66563 + const time_t shm_createtime, const uid_t cuid,
66564 + const int shmid);
66565 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66566 + const time_t shm_createtime);
66567 +#endif
66568 +
66569 void shm_init_ns(struct ipc_namespace *ns)
66570 {
66571 ns->shm_ctlmax = SHMMAX;
66572 @@ -401,6 +409,14 @@ static int newseg(struct ipc_namespace *
66573 shp->shm_lprid = 0;
66574 shp->shm_atim = shp->shm_dtim = 0;
66575 shp->shm_ctim = get_seconds();
66576 +#ifdef CONFIG_GRKERNSEC
66577 + {
66578 + struct timespec timeval;
66579 + do_posix_clock_monotonic_gettime(&timeval);
66580 +
66581 + shp->shm_createtime = timeval.tv_sec;
66582 + }
66583 +#endif
66584 shp->shm_segsz = size;
66585 shp->shm_nattch = 0;
66586 shp->shm_file = file;
66587 @@ -762,8 +778,6 @@ SYSCALL_DEFINE3(shmctl, int, shmid, int,
66588 case SHM_LOCK:
66589 case SHM_UNLOCK:
66590 {
66591 - struct file *uninitialized_var(shm_file);
66592 -
66593 lru_add_drain_all(); /* drain pagevecs to lru lists */
66594
66595 shp = shm_lock_check(ns, shmid);
66596 @@ -896,9 +910,21 @@ long do_shmat(int shmid, char __user *sh
66597 if (err)
66598 goto out_unlock;
66599
66600 +#ifdef CONFIG_GRKERNSEC
66601 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
66602 + shp->shm_perm.cuid, shmid) ||
66603 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
66604 + err = -EACCES;
66605 + goto out_unlock;
66606 + }
66607 +#endif
66608 +
66609 path = shp->shm_file->f_path;
66610 path_get(&path);
66611 shp->shm_nattch++;
66612 +#ifdef CONFIG_GRKERNSEC
66613 + shp->shm_lapid = current->pid;
66614 +#endif
66615 size = i_size_read(path.dentry->d_inode);
66616 shm_unlock(shp);
66617
66618 diff -urNp linux-2.6.39/kernel/acct.c linux-2.6.39/kernel/acct.c
66619 --- linux-2.6.39/kernel/acct.c 2011-05-19 00:06:34.000000000 -0400
66620 +++ linux-2.6.39/kernel/acct.c 2011-05-22 19:36:33.000000000 -0400
66621 @@ -570,7 +570,7 @@ static void do_acct_process(struct bsd_a
66622 */
66623 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
66624 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
66625 - file->f_op->write(file, (char *)&ac,
66626 + file->f_op->write(file, (__force char __user *)&ac,
66627 sizeof(acct_t), &file->f_pos);
66628 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
66629 set_fs(fs);
66630 diff -urNp linux-2.6.39/kernel/audit.c linux-2.6.39/kernel/audit.c
66631 --- linux-2.6.39/kernel/audit.c 2011-05-19 00:06:34.000000000 -0400
66632 +++ linux-2.6.39/kernel/audit.c 2011-05-22 19:36:33.000000000 -0400
66633 @@ -112,7 +112,7 @@ u32 audit_sig_sid = 0;
66634 3) suppressed due to audit_rate_limit
66635 4) suppressed due to audit_backlog_limit
66636 */
66637 -static atomic_t audit_lost = ATOMIC_INIT(0);
66638 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
66639
66640 /* The netlink socket. */
66641 static struct sock *audit_sock;
66642 @@ -234,7 +234,7 @@ void audit_log_lost(const char *message)
66643 unsigned long now;
66644 int print;
66645
66646 - atomic_inc(&audit_lost);
66647 + atomic_inc_unchecked(&audit_lost);
66648
66649 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
66650
66651 @@ -253,7 +253,7 @@ void audit_log_lost(const char *message)
66652 printk(KERN_WARNING
66653 "audit: audit_lost=%d audit_rate_limit=%d "
66654 "audit_backlog_limit=%d\n",
66655 - atomic_read(&audit_lost),
66656 + atomic_read_unchecked(&audit_lost),
66657 audit_rate_limit,
66658 audit_backlog_limit);
66659 audit_panic(message);
66660 @@ -686,7 +686,7 @@ static int audit_receive_msg(struct sk_b
66661 status_set.pid = audit_pid;
66662 status_set.rate_limit = audit_rate_limit;
66663 status_set.backlog_limit = audit_backlog_limit;
66664 - status_set.lost = atomic_read(&audit_lost);
66665 + status_set.lost = atomic_read_unchecked(&audit_lost);
66666 status_set.backlog = skb_queue_len(&audit_skb_queue);
66667 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
66668 &status_set, sizeof(status_set));
66669 diff -urNp linux-2.6.39/kernel/auditsc.c linux-2.6.39/kernel/auditsc.c
66670 --- linux-2.6.39/kernel/auditsc.c 2011-05-19 00:06:34.000000000 -0400
66671 +++ linux-2.6.39/kernel/auditsc.c 2011-05-22 19:36:33.000000000 -0400
66672 @@ -2111,7 +2111,7 @@ int auditsc_get_stamp(struct audit_conte
66673 }
66674
66675 /* global counter which is incremented every time something logs in */
66676 -static atomic_t session_id = ATOMIC_INIT(0);
66677 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
66678
66679 /**
66680 * audit_set_loginuid - set a task's audit_context loginuid
66681 @@ -2124,7 +2124,7 @@ static atomic_t session_id = ATOMIC_INIT
66682 */
66683 int audit_set_loginuid(struct task_struct *task, uid_t loginuid)
66684 {
66685 - unsigned int sessionid = atomic_inc_return(&session_id);
66686 + unsigned int sessionid = atomic_inc_return_unchecked(&session_id);
66687 struct audit_context *context = task->audit_context;
66688
66689 if (context && context->in_syscall) {
66690 diff -urNp linux-2.6.39/kernel/capability.c linux-2.6.39/kernel/capability.c
66691 --- linux-2.6.39/kernel/capability.c 2011-05-19 00:06:34.000000000 -0400
66692 +++ linux-2.6.39/kernel/capability.c 2011-05-22 21:02:23.000000000 -0400
66693 @@ -206,6 +206,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_
66694 * before modification is attempted and the application
66695 * fails.
66696 */
66697 + if (tocopy > ARRAY_SIZE(kdata))
66698 + return -EFAULT;
66699 +
66700 if (copy_to_user(dataptr, kdata, tocopy
66701 * sizeof(struct __user_cap_data_struct))) {
66702 return -EFAULT;
66703 @@ -378,7 +381,7 @@ bool ns_capable(struct user_namespace *n
66704 BUG();
66705 }
66706
66707 - if (security_capable(ns, current_cred(), cap) == 0) {
66708 + if (security_capable(ns, current_cred(), cap) == 0 && gr_is_capable(cap)) {
66709 current->flags |= PF_SUPERPRIV;
66710 return true;
66711 }
66712 @@ -386,6 +389,27 @@ bool ns_capable(struct user_namespace *n
66713 }
66714 EXPORT_SYMBOL(ns_capable);
66715
66716 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
66717 +{
66718 + if (unlikely(!cap_valid(cap))) {
66719 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
66720 + BUG();
66721 + }
66722 +
66723 + if (security_capable(ns, current_cred(), cap) == 0 && gr_is_capable_nolog(cap)) {
66724 + current->flags |= PF_SUPERPRIV;
66725 + return true;
66726 + }
66727 + return false;
66728 +}
66729 +EXPORT_SYMBOL(ns_capable_nolog);
66730 +
66731 +bool capable_nolog(int cap)
66732 +{
66733 + return ns_capable_nolog(&init_user_ns, cap);
66734 +}
66735 +EXPORT_SYMBOL(capable_nolog);
66736 +
66737 /**
66738 * task_ns_capable - Determine whether current task has a superior
66739 * capability targeted at a specific task's user namespace.
66740 @@ -400,6 +424,12 @@ bool task_ns_capable(struct task_struct
66741 }
66742 EXPORT_SYMBOL(task_ns_capable);
66743
66744 +bool task_ns_capable_nolog(struct task_struct *t, int cap)
66745 +{
66746 + return ns_capable_nolog(task_cred_xxx(t, user)->user_ns, cap);
66747 +}
66748 +EXPORT_SYMBOL(task_ns_capable_nolog);
66749 +
66750 /**
66751 * nsown_capable - Check superior capability to one's own user_ns
66752 * @cap: The capability in question
66753 diff -urNp linux-2.6.39/kernel/cgroup.c linux-2.6.39/kernel/cgroup.c
66754 --- linux-2.6.39/kernel/cgroup.c 2011-05-19 00:06:34.000000000 -0400
66755 +++ linux-2.6.39/kernel/cgroup.c 2011-05-22 19:36:33.000000000 -0400
66756 @@ -598,6 +598,8 @@ static struct css_set *find_css_set(
66757 struct hlist_head *hhead;
66758 struct cg_cgroup_link *link;
66759
66760 + pax_track_stack();
66761 +
66762 /* First see if we already have a cgroup group that matches
66763 * the desired set */
66764 read_lock(&css_set_lock);
66765 diff -urNp linux-2.6.39/kernel/compat.c linux-2.6.39/kernel/compat.c
66766 --- linux-2.6.39/kernel/compat.c 2011-05-19 00:06:34.000000000 -0400
66767 +++ linux-2.6.39/kernel/compat.c 2011-05-22 19:41:42.000000000 -0400
66768 @@ -13,6 +13,7 @@
66769
66770 #include <linux/linkage.h>
66771 #include <linux/compat.h>
66772 +#include <linux/module.h>
66773 #include <linux/errno.h>
66774 #include <linux/time.h>
66775 #include <linux/signal.h>
66776 diff -urNp linux-2.6.39/kernel/configs.c linux-2.6.39/kernel/configs.c
66777 --- linux-2.6.39/kernel/configs.c 2011-05-19 00:06:34.000000000 -0400
66778 +++ linux-2.6.39/kernel/configs.c 2011-05-22 19:41:42.000000000 -0400
66779 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
66780 struct proc_dir_entry *entry;
66781
66782 /* create the current config file */
66783 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
66784 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
66785 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
66786 + &ikconfig_file_ops);
66787 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66788 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
66789 + &ikconfig_file_ops);
66790 +#endif
66791 +#else
66792 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
66793 &ikconfig_file_ops);
66794 +#endif
66795 +
66796 if (!entry)
66797 return -ENOMEM;
66798
66799 diff -urNp linux-2.6.39/kernel/cred.c linux-2.6.39/kernel/cred.c
66800 --- linux-2.6.39/kernel/cred.c 2011-05-19 00:06:34.000000000 -0400
66801 +++ linux-2.6.39/kernel/cred.c 2011-05-22 19:41:42.000000000 -0400
66802 @@ -158,6 +158,8 @@ static void put_cred_rcu(struct rcu_head
66803 */
66804 void __put_cred(struct cred *cred)
66805 {
66806 + pax_track_stack();
66807 +
66808 kdebug("__put_cred(%p{%d,%d})", cred,
66809 atomic_read(&cred->usage),
66810 read_cred_subscribers(cred));
66811 @@ -182,6 +184,8 @@ void exit_creds(struct task_struct *tsk)
66812 {
66813 struct cred *cred;
66814
66815 + pax_track_stack();
66816 +
66817 kdebug("exit_creds(%u,%p,%p,{%d,%d})", tsk->pid, tsk->real_cred, tsk->cred,
66818 atomic_read(&tsk->cred->usage),
66819 read_cred_subscribers(tsk->cred));
66820 @@ -220,6 +224,8 @@ const struct cred *get_task_cred(struct
66821 {
66822 const struct cred *cred;
66823
66824 + pax_track_stack();
66825 +
66826 rcu_read_lock();
66827
66828 do {
66829 @@ -239,6 +245,8 @@ struct cred *cred_alloc_blank(void)
66830 {
66831 struct cred *new;
66832
66833 + pax_track_stack();
66834 +
66835 new = kmem_cache_zalloc(cred_jar, GFP_KERNEL);
66836 if (!new)
66837 return NULL;
66838 @@ -287,6 +295,8 @@ struct cred *prepare_creds(void)
66839 const struct cred *old;
66840 struct cred *new;
66841
66842 + pax_track_stack();
66843 +
66844 validate_process_creds();
66845
66846 new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
66847 @@ -333,6 +343,8 @@ struct cred *prepare_exec_creds(void)
66848 struct thread_group_cred *tgcred = NULL;
66849 struct cred *new;
66850
66851 + pax_track_stack();
66852 +
66853 #ifdef CONFIG_KEYS
66854 tgcred = kmalloc(sizeof(*tgcred), GFP_KERNEL);
66855 if (!tgcred)
66856 @@ -385,6 +397,8 @@ int copy_creds(struct task_struct *p, un
66857 struct cred *new;
66858 int ret;
66859
66860 + pax_track_stack();
66861 +
66862 if (
66863 #ifdef CONFIG_KEYS
66864 !p->cred->thread_keyring &&
66865 @@ -475,6 +489,8 @@ int commit_creds(struct cred *new)
66866 struct task_struct *task = current;
66867 const struct cred *old = task->real_cred;
66868
66869 + pax_track_stack();
66870 +
66871 kdebug("commit_creds(%p{%d,%d})", new,
66872 atomic_read(&new->usage),
66873 read_cred_subscribers(new));
66874 @@ -489,6 +505,8 @@ int commit_creds(struct cred *new)
66875
66876 get_cred(new); /* we will require a ref for the subj creds too */
66877
66878 + gr_set_role_label(task, new->uid, new->gid);
66879 +
66880 /* dumpability changes */
66881 if (old->euid != new->euid ||
66882 old->egid != new->egid ||
66883 @@ -551,6 +569,8 @@ EXPORT_SYMBOL(commit_creds);
66884 */
66885 void abort_creds(struct cred *new)
66886 {
66887 + pax_track_stack();
66888 +
66889 kdebug("abort_creds(%p{%d,%d})", new,
66890 atomic_read(&new->usage),
66891 read_cred_subscribers(new));
66892 @@ -574,6 +594,8 @@ const struct cred *override_creds(const
66893 {
66894 const struct cred *old = current->cred;
66895
66896 + pax_track_stack();
66897 +
66898 kdebug("override_creds(%p{%d,%d})", new,
66899 atomic_read(&new->usage),
66900 read_cred_subscribers(new));
66901 @@ -603,6 +625,8 @@ void revert_creds(const struct cred *old
66902 {
66903 const struct cred *override = current->cred;
66904
66905 + pax_track_stack();
66906 +
66907 kdebug("revert_creds(%p{%d,%d})", old,
66908 atomic_read(&old->usage),
66909 read_cred_subscribers(old));
66910 @@ -649,6 +673,8 @@ struct cred *prepare_kernel_cred(struct
66911 const struct cred *old;
66912 struct cred *new;
66913
66914 + pax_track_stack();
66915 +
66916 new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
66917 if (!new)
66918 return NULL;
66919 @@ -703,6 +729,8 @@ EXPORT_SYMBOL(prepare_kernel_cred);
66920 */
66921 int set_security_override(struct cred *new, u32 secid)
66922 {
66923 + pax_track_stack();
66924 +
66925 return security_kernel_act_as(new, secid);
66926 }
66927 EXPORT_SYMBOL(set_security_override);
66928 @@ -722,6 +750,8 @@ int set_security_override_from_ctx(struc
66929 u32 secid;
66930 int ret;
66931
66932 + pax_track_stack();
66933 +
66934 ret = security_secctx_to_secid(secctx, strlen(secctx), &secid);
66935 if (ret < 0)
66936 return ret;
66937 diff -urNp linux-2.6.39/kernel/debug/debug_core.c linux-2.6.39/kernel/debug/debug_core.c
66938 --- linux-2.6.39/kernel/debug/debug_core.c 2011-05-19 00:06:34.000000000 -0400
66939 +++ linux-2.6.39/kernel/debug/debug_core.c 2011-05-22 19:36:33.000000000 -0400
66940 @@ -72,7 +72,7 @@ int kgdb_io_module_registered;
66941 /* Guard for recursive entry */
66942 static int exception_level;
66943
66944 -struct kgdb_io *dbg_io_ops;
66945 +const struct kgdb_io *dbg_io_ops;
66946 static DEFINE_SPINLOCK(kgdb_registration_lock);
66947
66948 /* kgdb console driver is loaded */
66949 @@ -119,7 +119,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_loc
66950 */
66951 static atomic_t masters_in_kgdb;
66952 static atomic_t slaves_in_kgdb;
66953 -static atomic_t kgdb_break_tasklet_var;
66954 +static atomic_unchecked_t kgdb_break_tasklet_var;
66955 atomic_t kgdb_setting_breakpoint;
66956
66957 struct task_struct *kgdb_usethread;
66958 @@ -129,7 +129,7 @@ int kgdb_single_step;
66959 static pid_t kgdb_sstep_pid;
66960
66961 /* to keep track of the CPU which is doing the single stepping*/
66962 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
66963 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
66964
66965 /*
66966 * If you are debugging a problem where roundup (the collection of
66967 @@ -542,7 +542,7 @@ return_normal:
66968 * kernel will only try for the value of sstep_tries before
66969 * giving up and continuing on.
66970 */
66971 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
66972 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
66973 (kgdb_info[cpu].task &&
66974 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
66975 atomic_set(&kgdb_active, -1);
66976 @@ -636,8 +636,8 @@ cpu_master_loop:
66977 }
66978
66979 kgdb_restore:
66980 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
66981 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
66982 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
66983 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
66984 if (kgdb_info[sstep_cpu].task)
66985 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
66986 else
66987 @@ -834,18 +834,18 @@ static void kgdb_unregister_callbacks(vo
66988 static void kgdb_tasklet_bpt(unsigned long ing)
66989 {
66990 kgdb_breakpoint();
66991 - atomic_set(&kgdb_break_tasklet_var, 0);
66992 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
66993 }
66994
66995 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
66996
66997 void kgdb_schedule_breakpoint(void)
66998 {
66999 - if (atomic_read(&kgdb_break_tasklet_var) ||
67000 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
67001 atomic_read(&kgdb_active) != -1 ||
67002 atomic_read(&kgdb_setting_breakpoint))
67003 return;
67004 - atomic_inc(&kgdb_break_tasklet_var);
67005 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
67006 tasklet_schedule(&kgdb_tasklet_breakpoint);
67007 }
67008 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
67009 @@ -864,7 +864,7 @@ static void kgdb_initial_breakpoint(void
67010 *
67011 * Register it with the KGDB core.
67012 */
67013 -int kgdb_register_io_module(struct kgdb_io *new_dbg_io_ops)
67014 +int kgdb_register_io_module(const struct kgdb_io *new_dbg_io_ops)
67015 {
67016 int err;
67017
67018 @@ -909,7 +909,7 @@ EXPORT_SYMBOL_GPL(kgdb_register_io_modul
67019 *
67020 * Unregister it with the KGDB core.
67021 */
67022 -void kgdb_unregister_io_module(struct kgdb_io *old_dbg_io_ops)
67023 +void kgdb_unregister_io_module(const struct kgdb_io *old_dbg_io_ops)
67024 {
67025 BUG_ON(kgdb_connected);
67026
67027 diff -urNp linux-2.6.39/kernel/debug/kdb/kdb_main.c linux-2.6.39/kernel/debug/kdb/kdb_main.c
67028 --- linux-2.6.39/kernel/debug/kdb/kdb_main.c 2011-05-19 00:06:34.000000000 -0400
67029 +++ linux-2.6.39/kernel/debug/kdb/kdb_main.c 2011-05-22 19:36:33.000000000 -0400
67030 @@ -1980,7 +1980,7 @@ static int kdb_lsmod(int argc, const cha
67031 list_for_each_entry(mod, kdb_modules, list) {
67032
67033 kdb_printf("%-20s%8u 0x%p ", mod->name,
67034 - mod->core_size, (void *)mod);
67035 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
67036 #ifdef CONFIG_MODULE_UNLOAD
67037 kdb_printf("%4d ", module_refcount(mod));
67038 #endif
67039 @@ -1990,7 +1990,7 @@ static int kdb_lsmod(int argc, const cha
67040 kdb_printf(" (Loading)");
67041 else
67042 kdb_printf(" (Live)");
67043 - kdb_printf(" 0x%p", mod->module_core);
67044 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
67045
67046 #ifdef CONFIG_MODULE_UNLOAD
67047 {
67048 diff -urNp linux-2.6.39/kernel/exit.c linux-2.6.39/kernel/exit.c
67049 --- linux-2.6.39/kernel/exit.c 2011-05-19 00:06:34.000000000 -0400
67050 +++ linux-2.6.39/kernel/exit.c 2011-05-22 20:02:30.000000000 -0400
67051 @@ -57,6 +57,10 @@
67052 #include <asm/pgtable.h>
67053 #include <asm/mmu_context.h>
67054
67055 +#ifdef CONFIG_GRKERNSEC
67056 +extern rwlock_t grsec_exec_file_lock;
67057 +#endif
67058 +
67059 static void exit_mm(struct task_struct * tsk);
67060
67061 static void __unhash_process(struct task_struct *p, bool group_dead)
67062 @@ -169,6 +173,8 @@ void release_task(struct task_struct * p
67063 struct task_struct *leader;
67064 int zap_leader;
67065 repeat:
67066 + gr_del_task_from_ip_table(p);
67067 +
67068 tracehook_prepare_release_task(p);
67069 /* don't need to get the RCU readlock here - the process is dead and
67070 * can't be modifying its own credentials. But shut RCU-lockdep up */
67071 @@ -338,11 +344,22 @@ static void reparent_to_kthreadd(void)
67072 {
67073 write_lock_irq(&tasklist_lock);
67074
67075 +#ifdef CONFIG_GRKERNSEC
67076 + write_lock(&grsec_exec_file_lock);
67077 + if (current->exec_file) {
67078 + fput(current->exec_file);
67079 + current->exec_file = NULL;
67080 + }
67081 + write_unlock(&grsec_exec_file_lock);
67082 +#endif
67083 +
67084 ptrace_unlink(current);
67085 /* Reparent to init */
67086 current->real_parent = current->parent = kthreadd_task;
67087 list_move_tail(&current->sibling, &current->real_parent->children);
67088
67089 + gr_set_kernel_label(current);
67090 +
67091 /* Set the exit signal to SIGCHLD so we signal init on exit */
67092 current->exit_signal = SIGCHLD;
67093
67094 @@ -394,7 +411,7 @@ int allow_signal(int sig)
67095 * know it'll be handled, so that they don't get converted to
67096 * SIGKILL or just silently dropped.
67097 */
67098 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
67099 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
67100 recalc_sigpending();
67101 spin_unlock_irq(&current->sighand->siglock);
67102 return 0;
67103 @@ -430,6 +447,17 @@ void daemonize(const char *name, ...)
67104 vsnprintf(current->comm, sizeof(current->comm), name, args);
67105 va_end(args);
67106
67107 +#ifdef CONFIG_GRKERNSEC
67108 + write_lock(&grsec_exec_file_lock);
67109 + if (current->exec_file) {
67110 + fput(current->exec_file);
67111 + current->exec_file = NULL;
67112 + }
67113 + write_unlock(&grsec_exec_file_lock);
67114 +#endif
67115 +
67116 + gr_set_kernel_label(current);
67117 +
67118 /*
67119 * If we were started as result of loading a module, close all of the
67120 * user space pages. We don't need them, and if we didn't close them
67121 @@ -905,15 +933,8 @@ NORET_TYPE void do_exit(long code)
67122 struct task_struct *tsk = current;
67123 int group_dead;
67124
67125 - profile_task_exit(tsk);
67126 -
67127 - WARN_ON(atomic_read(&tsk->fs_excl));
67128 - WARN_ON(blk_needs_flush_plug(tsk));
67129 -
67130 if (unlikely(in_interrupt()))
67131 panic("Aiee, killing interrupt handler!");
67132 - if (unlikely(!tsk->pid))
67133 - panic("Attempted to kill the idle task!");
67134
67135 /*
67136 * If do_exit is called because this processes oopsed, it's possible
67137 @@ -924,6 +945,14 @@ NORET_TYPE void do_exit(long code)
67138 */
67139 set_fs(USER_DS);
67140
67141 + profile_task_exit(tsk);
67142 +
67143 + WARN_ON(atomic_read(&tsk->fs_excl));
67144 + WARN_ON(blk_needs_flush_plug(tsk));
67145 +
67146 + if (unlikely(!tsk->pid))
67147 + panic("Attempted to kill the idle task!");
67148 +
67149 tracehook_report_exit(&code);
67150
67151 validate_creds_for_do_exit(tsk);
67152 @@ -984,6 +1013,9 @@ NORET_TYPE void do_exit(long code)
67153 tsk->exit_code = code;
67154 taskstats_exit(tsk, group_dead);
67155
67156 + gr_acl_handle_psacct(tsk, code);
67157 + gr_acl_handle_exit();
67158 +
67159 exit_mm(tsk);
67160
67161 if (group_dead)
67162 diff -urNp linux-2.6.39/kernel/fork.c linux-2.6.39/kernel/fork.c
67163 --- linux-2.6.39/kernel/fork.c 2011-05-19 00:06:34.000000000 -0400
67164 +++ linux-2.6.39/kernel/fork.c 2011-05-22 19:41:42.000000000 -0400
67165 @@ -287,7 +287,7 @@ static struct task_struct *dup_task_stru
67166 *stackend = STACK_END_MAGIC; /* for overflow detection */
67167
67168 #ifdef CONFIG_CC_STACKPROTECTOR
67169 - tsk->stack_canary = get_random_int();
67170 + tsk->stack_canary = pax_get_random_long();
67171 #endif
67172
67173 /* One for us, one for whoever does the "release_task()" (usually parent) */
67174 @@ -309,13 +309,78 @@ out:
67175 }
67176
67177 #ifdef CONFIG_MMU
67178 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct vm_area_struct *mpnt)
67179 +{
67180 + struct vm_area_struct *tmp;
67181 + unsigned long charge;
67182 + struct mempolicy *pol;
67183 + struct file *file;
67184 +
67185 + charge = 0;
67186 + if (mpnt->vm_flags & VM_ACCOUNT) {
67187 + unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
67188 + if (security_vm_enough_memory(len))
67189 + goto fail_nomem;
67190 + charge = len;
67191 + }
67192 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67193 + if (!tmp)
67194 + goto fail_nomem;
67195 + *tmp = *mpnt;
67196 + tmp->vm_mm = mm;
67197 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
67198 + pol = mpol_dup(vma_policy(mpnt));
67199 + if (IS_ERR(pol))
67200 + goto fail_nomem_policy;
67201 + vma_set_policy(tmp, pol);
67202 + if (anon_vma_fork(tmp, mpnt))
67203 + goto fail_nomem_anon_vma_fork;
67204 + tmp->vm_flags &= ~VM_LOCKED;
67205 + tmp->vm_next = tmp->vm_prev = NULL;
67206 + tmp->vm_mirror = NULL;
67207 + file = tmp->vm_file;
67208 + if (file) {
67209 + struct inode *inode = file->f_path.dentry->d_inode;
67210 + struct address_space *mapping = file->f_mapping;
67211 +
67212 + get_file(file);
67213 + if (tmp->vm_flags & VM_DENYWRITE)
67214 + atomic_dec(&inode->i_writecount);
67215 + spin_lock(&mapping->i_mmap_lock);
67216 + if (tmp->vm_flags & VM_SHARED)
67217 + mapping->i_mmap_writable++;
67218 + tmp->vm_truncate_count = mpnt->vm_truncate_count;
67219 + flush_dcache_mmap_lock(mapping);
67220 + /* insert tmp into the share list, just after mpnt */
67221 + vma_prio_tree_add(tmp, mpnt);
67222 + flush_dcache_mmap_unlock(mapping);
67223 + spin_unlock(&mapping->i_mmap_lock);
67224 + }
67225 +
67226 + /*
67227 + * Clear hugetlb-related page reserves for children. This only
67228 + * affects MAP_PRIVATE mappings. Faults generated by the child
67229 + * are not guaranteed to succeed, even if read-only
67230 + */
67231 + if (is_vm_hugetlb_page(tmp))
67232 + reset_vma_resv_huge_pages(tmp);
67233 +
67234 + return tmp;
67235 +
67236 +fail_nomem_anon_vma_fork:
67237 + mpol_put(pol);
67238 +fail_nomem_policy:
67239 + kmem_cache_free(vm_area_cachep, tmp);
67240 +fail_nomem:
67241 + vm_unacct_memory(charge);
67242 + return NULL;
67243 +}
67244 +
67245 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67246 {
67247 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
67248 struct rb_node **rb_link, *rb_parent;
67249 int retval;
67250 - unsigned long charge;
67251 - struct mempolicy *pol;
67252
67253 down_write(&oldmm->mmap_sem);
67254 flush_cache_dup_mm(oldmm);
67255 @@ -327,8 +392,8 @@ static int dup_mmap(struct mm_struct *mm
67256 mm->locked_vm = 0;
67257 mm->mmap = NULL;
67258 mm->mmap_cache = NULL;
67259 - mm->free_area_cache = oldmm->mmap_base;
67260 - mm->cached_hole_size = ~0UL;
67261 + mm->free_area_cache = oldmm->free_area_cache;
67262 + mm->cached_hole_size = oldmm->cached_hole_size;
67263 mm->map_count = 0;
67264 cpumask_clear(mm_cpumask(mm));
67265 mm->mm_rb = RB_ROOT;
67266 @@ -344,8 +409,6 @@ static int dup_mmap(struct mm_struct *mm
67267
67268 prev = NULL;
67269 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
67270 - struct file *file;
67271 -
67272 if (mpnt->vm_flags & VM_DONTCOPY) {
67273 long pages = vma_pages(mpnt);
67274 mm->total_vm -= pages;
67275 @@ -353,56 +416,13 @@ static int dup_mmap(struct mm_struct *mm
67276 -pages);
67277 continue;
67278 }
67279 - charge = 0;
67280 - if (mpnt->vm_flags & VM_ACCOUNT) {
67281 - unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
67282 - if (security_vm_enough_memory(len))
67283 - goto fail_nomem;
67284 - charge = len;
67285 - }
67286 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67287 - if (!tmp)
67288 - goto fail_nomem;
67289 - *tmp = *mpnt;
67290 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
67291 - pol = mpol_dup(vma_policy(mpnt));
67292 - retval = PTR_ERR(pol);
67293 - if (IS_ERR(pol))
67294 - goto fail_nomem_policy;
67295 - vma_set_policy(tmp, pol);
67296 - tmp->vm_mm = mm;
67297 - if (anon_vma_fork(tmp, mpnt))
67298 - goto fail_nomem_anon_vma_fork;
67299 - tmp->vm_flags &= ~VM_LOCKED;
67300 - tmp->vm_next = tmp->vm_prev = NULL;
67301 - file = tmp->vm_file;
67302 - if (file) {
67303 - struct inode *inode = file->f_path.dentry->d_inode;
67304 - struct address_space *mapping = file->f_mapping;
67305 -
67306 - get_file(file);
67307 - if (tmp->vm_flags & VM_DENYWRITE)
67308 - atomic_dec(&inode->i_writecount);
67309 - spin_lock(&mapping->i_mmap_lock);
67310 - if (tmp->vm_flags & VM_SHARED)
67311 - mapping->i_mmap_writable++;
67312 - tmp->vm_truncate_count = mpnt->vm_truncate_count;
67313 - flush_dcache_mmap_lock(mapping);
67314 - /* insert tmp into the share list, just after mpnt */
67315 - vma_prio_tree_add(tmp, mpnt);
67316 - flush_dcache_mmap_unlock(mapping);
67317 - spin_unlock(&mapping->i_mmap_lock);
67318 + tmp = dup_vma(mm, mpnt);
67319 + if (!tmp) {
67320 + retval = -ENOMEM;
67321 + goto out;
67322 }
67323
67324 /*
67325 - * Clear hugetlb-related page reserves for children. This only
67326 - * affects MAP_PRIVATE mappings. Faults generated by the child
67327 - * are not guaranteed to succeed, even if read-only
67328 - */
67329 - if (is_vm_hugetlb_page(tmp))
67330 - reset_vma_resv_huge_pages(tmp);
67331 -
67332 - /*
67333 * Link in the new vma and copy the page table entries.
67334 */
67335 *pprev = tmp;
67336 @@ -423,6 +443,31 @@ static int dup_mmap(struct mm_struct *mm
67337 if (retval)
67338 goto out;
67339 }
67340 +
67341 +#ifdef CONFIG_PAX_SEGMEXEC
67342 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
67343 + struct vm_area_struct *mpnt_m;
67344 +
67345 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
67346 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
67347 +
67348 + if (!mpnt->vm_mirror)
67349 + continue;
67350 +
67351 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
67352 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
67353 + mpnt->vm_mirror = mpnt_m;
67354 + } else {
67355 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
67356 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
67357 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
67358 + mpnt->vm_mirror->vm_mirror = mpnt;
67359 + }
67360 + }
67361 + BUG_ON(mpnt_m);
67362 + }
67363 +#endif
67364 +
67365 /* a new mm has just been created */
67366 arch_dup_mmap(oldmm, mm);
67367 retval = 0;
67368 @@ -431,14 +476,6 @@ out:
67369 flush_tlb_mm(oldmm);
67370 up_write(&oldmm->mmap_sem);
67371 return retval;
67372 -fail_nomem_anon_vma_fork:
67373 - mpol_put(pol);
67374 -fail_nomem_policy:
67375 - kmem_cache_free(vm_area_cachep, tmp);
67376 -fail_nomem:
67377 - retval = -ENOMEM;
67378 - vm_unacct_memory(charge);
67379 - goto out;
67380 }
67381
67382 static inline int mm_alloc_pgd(struct mm_struct * mm)
67383 @@ -785,13 +822,14 @@ static int copy_fs(unsigned long clone_f
67384 spin_unlock(&fs->lock);
67385 return -EAGAIN;
67386 }
67387 - fs->users++;
67388 + atomic_inc(&fs->users);
67389 spin_unlock(&fs->lock);
67390 return 0;
67391 }
67392 tsk->fs = copy_fs_struct(fs);
67393 if (!tsk->fs)
67394 return -ENOMEM;
67395 + gr_set_chroot_entries(tsk, &tsk->fs->root);
67396 return 0;
67397 }
67398
67399 @@ -1049,10 +1087,13 @@ static struct task_struct *copy_process(
67400 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
67401 #endif
67402 retval = -EAGAIN;
67403 +
67404 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
67405 +
67406 if (atomic_read(&p->real_cred->user->processes) >=
67407 task_rlimit(p, RLIMIT_NPROC)) {
67408 - if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
67409 - p->real_cred->user != INIT_USER)
67410 + if (p->real_cred->user != INIT_USER &&
67411 + !capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE))
67412 goto bad_fork_free;
67413 }
67414
67415 @@ -1200,6 +1241,8 @@ static struct task_struct *copy_process(
67416 goto bad_fork_free_pid;
67417 }
67418
67419 + gr_copy_label(p);
67420 +
67421 p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
67422 /*
67423 * Clear TID on mm_release()?
67424 @@ -1360,6 +1403,8 @@ bad_fork_cleanup_count:
67425 bad_fork_free:
67426 free_task(p);
67427 fork_out:
67428 + gr_log_forkfail(retval);
67429 +
67430 return ERR_PTR(retval);
67431 }
67432
67433 @@ -1448,6 +1493,8 @@ long do_fork(unsigned long clone_flags,
67434 if (clone_flags & CLONE_PARENT_SETTID)
67435 put_user(nr, parent_tidptr);
67436
67437 + gr_handle_brute_check();
67438 +
67439 if (clone_flags & CLONE_VFORK) {
67440 p->vfork_done = &vfork;
67441 init_completion(&vfork);
67442 @@ -1549,7 +1596,7 @@ static int unshare_fs(unsigned long unsh
67443 return 0;
67444
67445 /* don't need lock here; in the worst case we'll do useless copy */
67446 - if (fs->users == 1)
67447 + if (atomic_read(&fs->users) == 1)
67448 return 0;
67449
67450 *new_fsp = copy_fs_struct(fs);
67451 @@ -1636,7 +1683,8 @@ SYSCALL_DEFINE1(unshare, unsigned long,
67452 fs = current->fs;
67453 spin_lock(&fs->lock);
67454 current->fs = new_fs;
67455 - if (--fs->users)
67456 + gr_set_chroot_entries(current, &current->fs->root);
67457 + if (atomic_dec_return(&fs->users))
67458 new_fs = NULL;
67459 else
67460 new_fs = fs;
67461 diff -urNp linux-2.6.39/kernel/futex.c linux-2.6.39/kernel/futex.c
67462 --- linux-2.6.39/kernel/futex.c 2011-05-19 00:06:34.000000000 -0400
67463 +++ linux-2.6.39/kernel/futex.c 2011-05-22 22:41:57.000000000 -0400
67464 @@ -54,6 +54,7 @@
67465 #include <linux/mount.h>
67466 #include <linux/pagemap.h>
67467 #include <linux/syscalls.h>
67468 +#include <linux/ptrace.h>
67469 #include <linux/signal.h>
67470 #include <linux/module.h>
67471 #include <linux/magic.h>
67472 @@ -236,6 +237,11 @@ get_futex_key(u32 __user *uaddr, int fsh
67473 struct page *page, *page_head;
67474 int err;
67475
67476 +#ifdef CONFIG_PAX_SEGMEXEC
67477 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
67478 + return -EFAULT;
67479 +#endif
67480 +
67481 /*
67482 * The futex address must be "naturally" aligned.
67483 */
67484 @@ -1833,6 +1839,8 @@ static int futex_wait(u32 __user *uaddr,
67485 struct futex_q q = futex_q_init;
67486 int ret;
67487
67488 + pax_track_stack();
67489 +
67490 if (!bitset)
67491 return -EINVAL;
67492 q.bitset = bitset;
67493 @@ -2229,6 +2237,8 @@ static int futex_wait_requeue_pi(u32 __u
67494 struct futex_q q = futex_q_init;
67495 int res, ret;
67496
67497 + pax_track_stack();
67498 +
67499 if (!bitset)
67500 return -EINVAL;
67501
67502 @@ -2401,7 +2411,9 @@ SYSCALL_DEFINE3(get_robust_list, int, pi
67503 {
67504 struct robust_list_head __user *head;
67505 unsigned long ret;
67506 +#ifndef CONFIG_GRKERNSEC_PROC_MEMMAP
67507 const struct cred *cred = current_cred(), *pcred;
67508 +#endif
67509
67510 if (!futex_cmpxchg_enabled)
67511 return -ENOSYS;
67512 @@ -2417,6 +2429,10 @@ SYSCALL_DEFINE3(get_robust_list, int, pi
67513 if (!p)
67514 goto err_unlock;
67515 ret = -EPERM;
67516 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67517 + if (!ptrace_may_access(p, PTRACE_MODE_READ))
67518 + goto err_unlock;
67519 +#else
67520 pcred = __task_cred(p);
67521 /* If victim is in different user_ns, then uids are not
67522 comparable, so we must have CAP_SYS_PTRACE */
67523 @@ -2431,6 +2447,7 @@ SYSCALL_DEFINE3(get_robust_list, int, pi
67524 !ns_capable(pcred->user->user_ns, CAP_SYS_PTRACE))
67525 goto err_unlock;
67526 ok:
67527 +#endif
67528 head = p->robust_list;
67529 rcu_read_unlock();
67530 }
67531 @@ -2682,6 +2699,7 @@ static int __init futex_init(void)
67532 {
67533 u32 curval;
67534 int i;
67535 + mm_segment_t oldfs;
67536
67537 /*
67538 * This will fail and we want it. Some arch implementations do
67539 @@ -2693,8 +2711,11 @@ static int __init futex_init(void)
67540 * implementation, the non-functional ones will return
67541 * -ENOSYS.
67542 */
67543 + oldfs = get_fs();
67544 + set_fs(USER_DS);
67545 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
67546 futex_cmpxchg_enabled = 1;
67547 + set_fs(oldfs);
67548
67549 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
67550 plist_head_init(&futex_queues[i].chain, &futex_queues[i].lock);
67551 diff -urNp linux-2.6.39/kernel/futex_compat.c linux-2.6.39/kernel/futex_compat.c
67552 --- linux-2.6.39/kernel/futex_compat.c 2011-05-19 00:06:34.000000000 -0400
67553 +++ linux-2.6.39/kernel/futex_compat.c 2011-05-22 22:42:09.000000000 -0400
67554 @@ -10,6 +10,7 @@
67555 #include <linux/compat.h>
67556 #include <linux/nsproxy.h>
67557 #include <linux/futex.h>
67558 +#include <linux/ptrace.h>
67559
67560 #include <asm/uaccess.h>
67561
67562 @@ -136,7 +137,10 @@ compat_sys_get_robust_list(int pid, comp
67563 {
67564 struct compat_robust_list_head __user *head;
67565 unsigned long ret;
67566 - const struct cred *cred = current_cred(), *pcred;
67567 +#ifndef CONFIG_GRKERNSEC_PROC_MEMMAP
67568 + const struct cred *cred = current_cred();
67569 + const struct cred *pcred;
67570 +#endif
67571
67572 if (!futex_cmpxchg_enabled)
67573 return -ENOSYS;
67574 @@ -152,6 +156,10 @@ compat_sys_get_robust_list(int pid, comp
67575 if (!p)
67576 goto err_unlock;
67577 ret = -EPERM;
67578 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67579 + if (!ptrace_may_access(p, PTRACE_MODE_READ))
67580 + goto err_unlock;
67581 +#else
67582 pcred = __task_cred(p);
67583 /* If victim is in different user_ns, then uids are not
67584 comparable, so we must have CAP_SYS_PTRACE */
67585 @@ -166,6 +174,7 @@ compat_sys_get_robust_list(int pid, comp
67586 !ns_capable(pcred->user->user_ns, CAP_SYS_PTRACE))
67587 goto err_unlock;
67588 ok:
67589 +#endif
67590 head = p->compat_robust_list;
67591 rcu_read_unlock();
67592 }
67593 diff -urNp linux-2.6.39/kernel/gcov/base.c linux-2.6.39/kernel/gcov/base.c
67594 --- linux-2.6.39/kernel/gcov/base.c 2011-05-19 00:06:34.000000000 -0400
67595 +++ linux-2.6.39/kernel/gcov/base.c 2011-05-22 19:36:33.000000000 -0400
67596 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
67597 }
67598
67599 #ifdef CONFIG_MODULES
67600 -static inline int within(void *addr, void *start, unsigned long size)
67601 -{
67602 - return ((addr >= start) && (addr < start + size));
67603 -}
67604 -
67605 /* Update list and generate events when modules are unloaded. */
67606 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
67607 void *data)
67608 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct n
67609 prev = NULL;
67610 /* Remove entries located in module from linked list. */
67611 for (info = gcov_info_head; info; info = info->next) {
67612 - if (within(info, mod->module_core, mod->core_size)) {
67613 + if (within_module_core_rw((unsigned long)info, mod)) {
67614 if (prev)
67615 prev->next = info->next;
67616 else
67617 diff -urNp linux-2.6.39/kernel/hrtimer.c linux-2.6.39/kernel/hrtimer.c
67618 --- linux-2.6.39/kernel/hrtimer.c 2011-05-19 00:06:34.000000000 -0400
67619 +++ linux-2.6.39/kernel/hrtimer.c 2011-05-22 19:36:33.000000000 -0400
67620 @@ -1383,7 +1383,7 @@ void hrtimer_peek_ahead_timers(void)
67621 local_irq_restore(flags);
67622 }
67623
67624 -static void run_hrtimer_softirq(struct softirq_action *h)
67625 +static void run_hrtimer_softirq(void)
67626 {
67627 hrtimer_peek_ahead_timers();
67628 }
67629 diff -urNp linux-2.6.39/kernel/jump_label.c linux-2.6.39/kernel/jump_label.c
67630 --- linux-2.6.39/kernel/jump_label.c 2011-05-19 00:06:34.000000000 -0400
67631 +++ linux-2.6.39/kernel/jump_label.c 2011-05-22 19:36:33.000000000 -0400
67632 @@ -49,6 +49,17 @@ void jump_label_unlock(void)
67633 mutex_unlock(&jump_label_mutex);
67634 }
67635
67636 +static void jump_label_swap(void *a, void *b, int size)
67637 +{
67638 + struct jump_entry t;
67639 +
67640 + t = *(struct jump_entry *)a;
67641 + pax_open_kernel();
67642 + *(struct jump_entry *)a = *(struct jump_entry *)b;
67643 + *(struct jump_entry *)b = t;
67644 + pax_close_kernel();
67645 +}
67646 +
67647 static int jump_label_cmp(const void *a, const void *b)
67648 {
67649 const struct jump_entry *jea = a;
67650 @@ -70,7 +81,7 @@ sort_jump_label_entries(struct jump_entr
67651
67652 size = (((unsigned long)stop - (unsigned long)start)
67653 / sizeof(struct jump_entry));
67654 - sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
67655 + sort(start, size, sizeof(struct jump_entry), jump_label_cmp, jump_label_swap);
67656 }
67657
67658 static struct jump_label_entry *get_jump_label_entry(jump_label_t key)
67659 @@ -407,8 +418,11 @@ static void remove_jump_label_module_ini
67660 count = e_module->nr_entries;
67661 iter = e_module->table;
67662 while (count--) {
67663 - if (within_module_init(iter->code, mod))
67664 + if (within_module_init(iter->code, mod)) {
67665 + pax_open_kernel();
67666 iter->key = 0;
67667 + pax_close_kernel();
67668 + }
67669 iter++;
67670 }
67671 }
67672 diff -urNp linux-2.6.39/kernel/kallsyms.c linux-2.6.39/kernel/kallsyms.c
67673 --- linux-2.6.39/kernel/kallsyms.c 2011-05-19 00:06:34.000000000 -0400
67674 +++ linux-2.6.39/kernel/kallsyms.c 2011-05-22 19:41:42.000000000 -0400
67675 @@ -11,6 +11,9 @@
67676 * Changed the compression method from stem compression to "table lookup"
67677 * compression (see scripts/kallsyms.c for a more complete description)
67678 */
67679 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67680 +#define __INCLUDED_BY_HIDESYM 1
67681 +#endif
67682 #include <linux/kallsyms.h>
67683 #include <linux/module.h>
67684 #include <linux/init.h>
67685 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_mark
67686
67687 static inline int is_kernel_inittext(unsigned long addr)
67688 {
67689 + if (system_state != SYSTEM_BOOTING)
67690 + return 0;
67691 +
67692 if (addr >= (unsigned long)_sinittext
67693 && addr <= (unsigned long)_einittext)
67694 return 1;
67695 return 0;
67696 }
67697
67698 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67699 +#ifdef CONFIG_MODULES
67700 +static inline int is_module_text(unsigned long addr)
67701 +{
67702 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
67703 + return 1;
67704 +
67705 + addr = ktla_ktva(addr);
67706 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
67707 +}
67708 +#else
67709 +static inline int is_module_text(unsigned long addr)
67710 +{
67711 + return 0;
67712 +}
67713 +#endif
67714 +#endif
67715 +
67716 static inline int is_kernel_text(unsigned long addr)
67717 {
67718 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
67719 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigne
67720
67721 static inline int is_kernel(unsigned long addr)
67722 {
67723 +
67724 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67725 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
67726 + return 1;
67727 +
67728 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
67729 +#else
67730 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
67731 +#endif
67732 +
67733 return 1;
67734 return in_gate_area_no_mm(addr);
67735 }
67736
67737 static int is_ksym_addr(unsigned long addr)
67738 {
67739 +
67740 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67741 + if (is_module_text(addr))
67742 + return 0;
67743 +#endif
67744 +
67745 if (all_var)
67746 return is_kernel(addr);
67747
67748 @@ -454,7 +493,6 @@ static unsigned long get_ksymbol_core(st
67749
67750 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
67751 {
67752 - iter->name[0] = '\0';
67753 iter->nameoff = get_symbol_offset(new_pos);
67754 iter->pos = new_pos;
67755 }
67756 @@ -502,6 +540,11 @@ static int s_show(struct seq_file *m, vo
67757 {
67758 struct kallsym_iter *iter = m->private;
67759
67760 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67761 + if (current_uid())
67762 + return 0;
67763 +#endif
67764 +
67765 /* Some debugging symbols have no name. Ignore them. */
67766 if (!iter->name[0])
67767 return 0;
67768 @@ -540,7 +583,7 @@ static int kallsyms_open(struct inode *i
67769 struct kallsym_iter *iter;
67770 int ret;
67771
67772 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
67773 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
67774 if (!iter)
67775 return -ENOMEM;
67776 reset_iter(iter, 0);
67777 diff -urNp linux-2.6.39/kernel/kmod.c linux-2.6.39/kernel/kmod.c
67778 --- linux-2.6.39/kernel/kmod.c 2011-05-19 00:06:34.000000000 -0400
67779 +++ linux-2.6.39/kernel/kmod.c 2011-05-22 19:41:42.000000000 -0400
67780 @@ -65,13 +65,12 @@ char modprobe_path[KMOD_PATH_LEN] = "/sb
67781 * If module auto-loading support is disabled then this function
67782 * becomes a no-operation.
67783 */
67784 -int __request_module(bool wait, const char *fmt, ...)
67785 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
67786 {
67787 - va_list args;
67788 char module_name[MODULE_NAME_LEN];
67789 unsigned int max_modprobes;
67790 int ret;
67791 - char *argv[] = { modprobe_path, "-q", "--", module_name, NULL };
67792 + char *argv[] = { modprobe_path, "-q", "--", module_name, module_param, NULL };
67793 static char *envp[] = { "HOME=/",
67794 "TERM=linux",
67795 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
67796 @@ -80,9 +79,7 @@ int __request_module(bool wait, const ch
67797 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
67798 static int kmod_loop_msg;
67799
67800 - va_start(args, fmt);
67801 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
67802 - va_end(args);
67803 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
67804 if (ret >= MODULE_NAME_LEN)
67805 return -ENAMETOOLONG;
67806
67807 @@ -90,6 +87,20 @@ int __request_module(bool wait, const ch
67808 if (ret)
67809 return ret;
67810
67811 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67812 + if (!current_uid()) {
67813 + /* hack to workaround consolekit/udisks stupidity */
67814 + read_lock(&tasklist_lock);
67815 + if (!strcmp(current->comm, "mount") &&
67816 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
67817 + read_unlock(&tasklist_lock);
67818 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
67819 + return -EPERM;
67820 + }
67821 + read_unlock(&tasklist_lock);
67822 + }
67823 +#endif
67824 +
67825 /* If modprobe needs a service that is in a module, we get a recursive
67826 * loop. Limit the number of running kmod threads to max_threads/2 or
67827 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
67828 @@ -123,6 +134,47 @@ int __request_module(bool wait, const ch
67829 atomic_dec(&kmod_concurrent);
67830 return ret;
67831 }
67832 +
67833 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
67834 +{
67835 + va_list args;
67836 + int ret;
67837 +
67838 + va_start(args, fmt);
67839 + ret = ____request_module(wait, module_param, fmt, args);
67840 + va_end(args);
67841 +
67842 + return ret;
67843 +}
67844 +
67845 +int __request_module(bool wait, const char *fmt, ...)
67846 +{
67847 + va_list args;
67848 + int ret;
67849 +
67850 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67851 + if (current_uid()) {
67852 + char module_param[MODULE_NAME_LEN];
67853 +
67854 + memset(module_param, 0, sizeof(module_param));
67855 +
67856 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
67857 +
67858 + va_start(args, fmt);
67859 + ret = ____request_module(wait, module_param, fmt, args);
67860 + va_end(args);
67861 +
67862 + return ret;
67863 + }
67864 +#endif
67865 +
67866 + va_start(args, fmt);
67867 + ret = ____request_module(wait, NULL, fmt, args);
67868 + va_end(args);
67869 +
67870 + return ret;
67871 +}
67872 +
67873 EXPORT_SYMBOL(__request_module);
67874 #endif /* CONFIG_MODULES */
67875
67876 diff -urNp linux-2.6.39/kernel/kprobes.c linux-2.6.39/kernel/kprobes.c
67877 --- linux-2.6.39/kernel/kprobes.c 2011-05-19 00:06:34.000000000 -0400
67878 +++ linux-2.6.39/kernel/kprobes.c 2011-05-22 19:36:33.000000000 -0400
67879 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_
67880 * kernel image and loaded module images reside. This is required
67881 * so x86_64 can correctly handle the %rip-relative fixups.
67882 */
67883 - kip->insns = module_alloc(PAGE_SIZE);
67884 + kip->insns = module_alloc_exec(PAGE_SIZE);
67885 if (!kip->insns) {
67886 kfree(kip);
67887 return NULL;
67888 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(st
67889 */
67890 if (!list_is_singular(&kip->list)) {
67891 list_del(&kip->list);
67892 - module_free(NULL, kip->insns);
67893 + module_free_exec(NULL, kip->insns);
67894 kfree(kip);
67895 }
67896 return 1;
67897 @@ -1936,7 +1936,7 @@ static int __init init_kprobes(void)
67898 {
67899 int i, err = 0;
67900 unsigned long offset = 0, size = 0;
67901 - char *modname, namebuf[128];
67902 + char *modname, namebuf[KSYM_NAME_LEN];
67903 const char *symbol_name;
67904 void *addr;
67905 struct kprobe_blackpoint *kb;
67906 @@ -2062,7 +2062,7 @@ static int __kprobes show_kprobe_addr(st
67907 const char *sym = NULL;
67908 unsigned int i = *(loff_t *) v;
67909 unsigned long offset = 0;
67910 - char *modname, namebuf[128];
67911 + char *modname, namebuf[KSYM_NAME_LEN];
67912
67913 head = &kprobe_table[i];
67914 preempt_disable();
67915 diff -urNp linux-2.6.39/kernel/lockdep.c linux-2.6.39/kernel/lockdep.c
67916 --- linux-2.6.39/kernel/lockdep.c 2011-05-19 00:06:34.000000000 -0400
67917 +++ linux-2.6.39/kernel/lockdep.c 2011-05-22 19:36:33.000000000 -0400
67918 @@ -571,6 +571,10 @@ static int static_obj(void *obj)
67919 end = (unsigned long) &_end,
67920 addr = (unsigned long) obj;
67921
67922 +#ifdef CONFIG_PAX_KERNEXEC
67923 + start = ktla_ktva(start);
67924 +#endif
67925 +
67926 /*
67927 * static variable?
67928 */
67929 @@ -706,6 +710,7 @@ register_lock_class(struct lockdep_map *
67930 if (!static_obj(lock->key)) {
67931 debug_locks_off();
67932 printk("INFO: trying to register non-static key.\n");
67933 + printk("lock:%pS key:%pS.\n", lock, lock->key);
67934 printk("the code is fine but needs lockdep annotation.\n");
67935 printk("turning off the locking correctness validator.\n");
67936 dump_stack();
67937 @@ -2752,7 +2757,7 @@ static int __lock_acquire(struct lockdep
67938 if (!class)
67939 return 0;
67940 }
67941 - atomic_inc((atomic_t *)&class->ops);
67942 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
67943 if (very_verbose(class)) {
67944 printk("\nacquire class [%p] %s", class->key, class->name);
67945 if (class->name_version > 1)
67946 diff -urNp linux-2.6.39/kernel/lockdep_proc.c linux-2.6.39/kernel/lockdep_proc.c
67947 --- linux-2.6.39/kernel/lockdep_proc.c 2011-05-19 00:06:34.000000000 -0400
67948 +++ linux-2.6.39/kernel/lockdep_proc.c 2011-05-22 19:36:33.000000000 -0400
67949 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, v
67950
67951 static void print_name(struct seq_file *m, struct lock_class *class)
67952 {
67953 - char str[128];
67954 + char str[KSYM_NAME_LEN];
67955 const char *name = class->name;
67956
67957 if (!name) {
67958 diff -urNp linux-2.6.39/kernel/module.c linux-2.6.39/kernel/module.c
67959 --- linux-2.6.39/kernel/module.c 2011-05-19 00:06:34.000000000 -0400
67960 +++ linux-2.6.39/kernel/module.c 2011-05-22 19:41:42.000000000 -0400
67961 @@ -57,6 +57,7 @@
67962 #include <linux/kmemleak.h>
67963 #include <linux/jump_label.h>
67964 #include <linux/pfn.h>
67965 +#include <linux/grsecurity.h>
67966
67967 #define CREATE_TRACE_POINTS
67968 #include <trace/events/module.h>
67969 @@ -118,7 +119,8 @@ static BLOCKING_NOTIFIER_HEAD(module_not
67970
67971 /* Bounds of module allocation, for speeding __module_address.
67972 * Protected by module_mutex. */
67973 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
67974 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
67975 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
67976
67977 int register_module_notifier(struct notifier_block * nb)
67978 {
67979 @@ -282,7 +284,7 @@ bool each_symbol(bool (*fn)(const struct
67980 return true;
67981
67982 list_for_each_entry_rcu(mod, &modules, list) {
67983 - struct symsearch arr[] = {
67984 + struct symsearch modarr[] = {
67985 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
67986 NOT_GPL_ONLY, false },
67987 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
67988 @@ -304,7 +306,7 @@ bool each_symbol(bool (*fn)(const struct
67989 #endif
67990 };
67991
67992 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
67993 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
67994 return true;
67995 }
67996 return false;
67997 @@ -415,7 +417,7 @@ static inline void __percpu *mod_percpu(
67998 static int percpu_modalloc(struct module *mod,
67999 unsigned long size, unsigned long align)
68000 {
68001 - if (align > PAGE_SIZE) {
68002 + if (align-1 >= PAGE_SIZE) {
68003 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
68004 mod->name, align, PAGE_SIZE);
68005 align = PAGE_SIZE;
68006 @@ -1143,7 +1145,7 @@ resolve_symbol_wait(struct module *mod,
68007 */
68008 #ifdef CONFIG_SYSFS
68009
68010 -#ifdef CONFIG_KALLSYMS
68011 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
68012 static inline bool sect_empty(const Elf_Shdr *sect)
68013 {
68014 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
68015 @@ -1612,17 +1614,17 @@ void unset_section_ro_nx(struct module *
68016 {
68017 unsigned long total_pages;
68018
68019 - if (mod->module_core == module_region) {
68020 + if (mod->module_core_rx == module_region) {
68021 /* Set core as NX+RW */
68022 - total_pages = MOD_NUMBER_OF_PAGES(mod->module_core, mod->core_size);
68023 - set_memory_nx((unsigned long)mod->module_core, total_pages);
68024 - set_memory_rw((unsigned long)mod->module_core, total_pages);
68025 + total_pages = MOD_NUMBER_OF_PAGES(mod->module_core_rx, mod->core_size_rx);
68026 + set_memory_nx((unsigned long)mod->module_core_rx, total_pages);
68027 + set_memory_rw((unsigned long)mod->module_core_rx, total_pages);
68028
68029 - } else if (mod->module_init == module_region) {
68030 + } else if (mod->module_init_rx == module_region) {
68031 /* Set init as NX+RW */
68032 - total_pages = MOD_NUMBER_OF_PAGES(mod->module_init, mod->init_size);
68033 - set_memory_nx((unsigned long)mod->module_init, total_pages);
68034 - set_memory_rw((unsigned long)mod->module_init, total_pages);
68035 + total_pages = MOD_NUMBER_OF_PAGES(mod->module_init_rx, mod->init_size_rx);
68036 + set_memory_nx((unsigned long)mod->module_init_rx, total_pages);
68037 + set_memory_rw((unsigned long)mod->module_init_rx, total_pages);
68038 }
68039 }
68040
68041 @@ -1633,14 +1635,14 @@ void set_all_modules_text_rw()
68042
68043 mutex_lock(&module_mutex);
68044 list_for_each_entry_rcu(mod, &modules, list) {
68045 - if ((mod->module_core) && (mod->core_text_size)) {
68046 - set_page_attributes(mod->module_core,
68047 - mod->module_core + mod->core_text_size,
68048 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
68049 + set_page_attributes(mod->module_core_rx,
68050 + mod->module_core_rx + mod->core_size_rx,
68051 set_memory_rw);
68052 }
68053 - if ((mod->module_init) && (mod->init_text_size)) {
68054 - set_page_attributes(mod->module_init,
68055 - mod->module_init + mod->init_text_size,
68056 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
68057 + set_page_attributes(mod->module_init_rx,
68058 + mod->module_init_rx + mod->init_size_rx,
68059 set_memory_rw);
68060 }
68061 }
68062 @@ -1654,14 +1656,14 @@ void set_all_modules_text_ro()
68063
68064 mutex_lock(&module_mutex);
68065 list_for_each_entry_rcu(mod, &modules, list) {
68066 - if ((mod->module_core) && (mod->core_text_size)) {
68067 - set_page_attributes(mod->module_core,
68068 - mod->module_core + mod->core_text_size,
68069 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
68070 + set_page_attributes(mod->module_core_rx,
68071 + mod->module_core_rx + mod->core_size_rx,
68072 set_memory_ro);
68073 }
68074 - if ((mod->module_init) && (mod->init_text_size)) {
68075 - set_page_attributes(mod->module_init,
68076 - mod->module_init + mod->init_text_size,
68077 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
68078 + set_page_attributes(mod->module_init_rx,
68079 + mod->module_init_rx + mod->init_size_rx,
68080 set_memory_ro);
68081 }
68082 }
68083 @@ -1696,17 +1698,20 @@ static void free_module(struct module *m
68084 destroy_params(mod->kp, mod->num_kp);
68085
68086 /* This may be NULL, but that's OK */
68087 - unset_section_ro_nx(mod, mod->module_init);
68088 - module_free(mod, mod->module_init);
68089 + unset_section_ro_nx(mod, mod->module_init_rx);
68090 + module_free(mod, mod->module_init_rw);
68091 + module_free_exec(mod, mod->module_init_rx);
68092 kfree(mod->args);
68093 percpu_modfree(mod);
68094
68095 /* Free lock-classes: */
68096 - lockdep_free_key_range(mod->module_core, mod->core_size);
68097 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
68098 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
68099
68100 /* Finally, free the core (containing the module structure) */
68101 - unset_section_ro_nx(mod, mod->module_core);
68102 - module_free(mod, mod->module_core);
68103 + unset_section_ro_nx(mod, mod->module_core_rx);
68104 + module_free_exec(mod, mod->module_core_rx);
68105 + module_free(mod, mod->module_core_rw);
68106
68107 #ifdef CONFIG_MPU
68108 update_protections(current->mm);
68109 @@ -1775,10 +1780,31 @@ static int simplify_symbols(struct modul
68110 unsigned int i;
68111 int ret = 0;
68112 const struct kernel_symbol *ksym;
68113 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68114 + int is_fs_load = 0;
68115 + int register_filesystem_found = 0;
68116 + char *p;
68117 +
68118 + p = strstr(mod->args, "grsec_modharden_fs");
68119 + if (p) {
68120 + char *endptr = p + strlen("grsec_modharden_fs");
68121 + /* copy \0 as well */
68122 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
68123 + is_fs_load = 1;
68124 + }
68125 +#endif
68126
68127 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
68128 const char *name = info->strtab + sym[i].st_name;
68129
68130 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68131 + /* it's a real shame this will never get ripped and copied
68132 + upstream! ;(
68133 + */
68134 + if (is_fs_load && !strcmp(name, "register_filesystem"))
68135 + register_filesystem_found = 1;
68136 +#endif
68137 +
68138 switch (sym[i].st_shndx) {
68139 case SHN_COMMON:
68140 /* We compiled with -fno-common. These are not
68141 @@ -1799,7 +1825,9 @@ static int simplify_symbols(struct modul
68142 ksym = resolve_symbol_wait(mod, info, name);
68143 /* Ok if resolved. */
68144 if (ksym && !IS_ERR(ksym)) {
68145 + pax_open_kernel();
68146 sym[i].st_value = ksym->value;
68147 + pax_close_kernel();
68148 break;
68149 }
68150
68151 @@ -1818,11 +1846,20 @@ static int simplify_symbols(struct modul
68152 secbase = (unsigned long)mod_percpu(mod);
68153 else
68154 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
68155 + pax_open_kernel();
68156 sym[i].st_value += secbase;
68157 + pax_close_kernel();
68158 break;
68159 }
68160 }
68161
68162 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68163 + if (is_fs_load && !register_filesystem_found) {
68164 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
68165 + ret = -EPERM;
68166 + }
68167 +#endif
68168 +
68169 return ret;
68170 }
68171
68172 @@ -1906,22 +1943,12 @@ static void layout_sections(struct modul
68173 || s->sh_entsize != ~0UL
68174 || strstarts(sname, ".init"))
68175 continue;
68176 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
68177 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68178 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
68179 + else
68180 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
68181 DEBUGP("\t%s\n", name);
68182 }
68183 - switch (m) {
68184 - case 0: /* executable */
68185 - mod->core_size = debug_align(mod->core_size);
68186 - mod->core_text_size = mod->core_size;
68187 - break;
68188 - case 1: /* RO: text and ro-data */
68189 - mod->core_size = debug_align(mod->core_size);
68190 - mod->core_ro_size = mod->core_size;
68191 - break;
68192 - case 3: /* whole core */
68193 - mod->core_size = debug_align(mod->core_size);
68194 - break;
68195 - }
68196 }
68197
68198 DEBUGP("Init section allocation order:\n");
68199 @@ -1935,23 +1962,13 @@ static void layout_sections(struct modul
68200 || s->sh_entsize != ~0UL
68201 || !strstarts(sname, ".init"))
68202 continue;
68203 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
68204 - | INIT_OFFSET_MASK);
68205 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68206 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
68207 + else
68208 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
68209 + s->sh_entsize |= INIT_OFFSET_MASK;
68210 DEBUGP("\t%s\n", sname);
68211 }
68212 - switch (m) {
68213 - case 0: /* executable */
68214 - mod->init_size = debug_align(mod->init_size);
68215 - mod->init_text_size = mod->init_size;
68216 - break;
68217 - case 1: /* RO: text and ro-data */
68218 - mod->init_size = debug_align(mod->init_size);
68219 - mod->init_ro_size = mod->init_size;
68220 - break;
68221 - case 3: /* whole init */
68222 - mod->init_size = debug_align(mod->init_size);
68223 - break;
68224 - }
68225 }
68226 }
68227
68228 @@ -2119,7 +2136,7 @@ static void layout_symtab(struct module
68229
68230 /* Put symbol section at end of init part of module. */
68231 symsect->sh_flags |= SHF_ALLOC;
68232 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
68233 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
68234 info->index.sym) | INIT_OFFSET_MASK;
68235 DEBUGP("\t%s\n", info->secstrings + symsect->sh_name);
68236
68237 @@ -2136,19 +2153,19 @@ static void layout_symtab(struct module
68238 }
68239
68240 /* Append room for core symbols at end of core part. */
68241 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
68242 - mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
68243 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
68244 + mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
68245
68246 /* Put string table section at end of init part of module. */
68247 strsect->sh_flags |= SHF_ALLOC;
68248 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
68249 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
68250 info->index.str) | INIT_OFFSET_MASK;
68251 DEBUGP("\t%s\n", info->secstrings + strsect->sh_name);
68252
68253 /* Append room for core symbols' strings at end of core part. */
68254 - info->stroffs = mod->core_size;
68255 + info->stroffs = mod->core_size_rx;
68256 __set_bit(0, info->strmap);
68257 - mod->core_size += bitmap_weight(info->strmap, strsect->sh_size);
68258 + mod->core_size_rx += bitmap_weight(info->strmap, strsect->sh_size);
68259 }
68260
68261 static void add_kallsyms(struct module *mod, const struct load_info *info)
68262 @@ -2164,11 +2181,13 @@ static void add_kallsyms(struct module *
68263 /* Make sure we get permanent strtab: don't use info->strtab. */
68264 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
68265
68266 + pax_open_kernel();
68267 +
68268 /* Set types up while we still have access to sections. */
68269 for (i = 0; i < mod->num_symtab; i++)
68270 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
68271
68272 - mod->core_symtab = dst = mod->module_core + info->symoffs;
68273 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
68274 src = mod->symtab;
68275 *dst = *src;
68276 for (ndst = i = 1; i < mod->num_symtab; ++i, ++src) {
68277 @@ -2181,10 +2200,12 @@ static void add_kallsyms(struct module *
68278 }
68279 mod->core_num_syms = ndst;
68280
68281 - mod->core_strtab = s = mod->module_core + info->stroffs;
68282 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
68283 for (*s = 0, i = 1; i < info->sechdrs[info->index.str].sh_size; ++i)
68284 if (test_bit(i, info->strmap))
68285 *++s = mod->strtab[i];
68286 +
68287 + pax_close_kernel();
68288 }
68289 #else
68290 static inline void layout_symtab(struct module *mod, struct load_info *info)
68291 @@ -2213,17 +2234,33 @@ static void dynamic_debug_remove(struct
68292 ddebug_remove_module(debug->modname);
68293 }
68294
68295 -static void *module_alloc_update_bounds(unsigned long size)
68296 +static void *module_alloc_update_bounds_rw(unsigned long size)
68297 {
68298 void *ret = module_alloc(size);
68299
68300 if (ret) {
68301 mutex_lock(&module_mutex);
68302 /* Update module bounds. */
68303 - if ((unsigned long)ret < module_addr_min)
68304 - module_addr_min = (unsigned long)ret;
68305 - if ((unsigned long)ret + size > module_addr_max)
68306 - module_addr_max = (unsigned long)ret + size;
68307 + if ((unsigned long)ret < module_addr_min_rw)
68308 + module_addr_min_rw = (unsigned long)ret;
68309 + if ((unsigned long)ret + size > module_addr_max_rw)
68310 + module_addr_max_rw = (unsigned long)ret + size;
68311 + mutex_unlock(&module_mutex);
68312 + }
68313 + return ret;
68314 +}
68315 +
68316 +static void *module_alloc_update_bounds_rx(unsigned long size)
68317 +{
68318 + void *ret = module_alloc_exec(size);
68319 +
68320 + if (ret) {
68321 + mutex_lock(&module_mutex);
68322 + /* Update module bounds. */
68323 + if ((unsigned long)ret < module_addr_min_rx)
68324 + module_addr_min_rx = (unsigned long)ret;
68325 + if ((unsigned long)ret + size > module_addr_max_rx)
68326 + module_addr_max_rx = (unsigned long)ret + size;
68327 mutex_unlock(&module_mutex);
68328 }
68329 return ret;
68330 @@ -2516,7 +2553,7 @@ static int move_module(struct module *mo
68331 void *ptr;
68332
68333 /* Do the allocs. */
68334 - ptr = module_alloc_update_bounds(mod->core_size);
68335 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
68336 /*
68337 * The pointer to this block is stored in the module structure
68338 * which is inside the block. Just mark it as not being a
68339 @@ -2526,23 +2563,50 @@ static int move_module(struct module *mo
68340 if (!ptr)
68341 return -ENOMEM;
68342
68343 - memset(ptr, 0, mod->core_size);
68344 - mod->module_core = ptr;
68345 + memset(ptr, 0, mod->core_size_rw);
68346 + mod->module_core_rw = ptr;
68347
68348 - ptr = module_alloc_update_bounds(mod->init_size);
68349 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
68350 /*
68351 * The pointer to this block is stored in the module structure
68352 * which is inside the block. This block doesn't need to be
68353 * scanned as it contains data and code that will be freed
68354 * after the module is initialized.
68355 */
68356 - kmemleak_ignore(ptr);
68357 - if (!ptr && mod->init_size) {
68358 - module_free(mod, mod->module_core);
68359 + kmemleak_not_leak(ptr);
68360 + if (!ptr && mod->init_size_rw) {
68361 + module_free(mod, mod->module_core_rw);
68362 return -ENOMEM;
68363 }
68364 - memset(ptr, 0, mod->init_size);
68365 - mod->module_init = ptr;
68366 + memset(ptr, 0, mod->init_size_rw);
68367 + mod->module_init_rw = ptr;
68368 +
68369 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
68370 + kmemleak_not_leak(ptr);
68371 + if (!ptr) {
68372 + module_free(mod, mod->module_init_rw);
68373 + module_free(mod, mod->module_core_rw);
68374 + return -ENOMEM;
68375 + }
68376 +
68377 + pax_open_kernel();
68378 + memset(ptr, 0, mod->core_size_rx);
68379 + pax_close_kernel();
68380 + mod->module_core_rx = ptr;
68381 +
68382 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
68383 + kmemleak_not_leak(ptr);
68384 + if (!ptr && mod->init_size_rx) {
68385 + module_free_exec(mod, mod->module_core_rx);
68386 + module_free(mod, mod->module_init_rw);
68387 + module_free(mod, mod->module_core_rw);
68388 + return -ENOMEM;
68389 + }
68390 +
68391 + pax_open_kernel();
68392 + memset(ptr, 0, mod->init_size_rx);
68393 + pax_close_kernel();
68394 + mod->module_init_rx = ptr;
68395
68396 /* Transfer each section which specifies SHF_ALLOC */
68397 DEBUGP("final section addresses:\n");
68398 @@ -2553,16 +2617,45 @@ static int move_module(struct module *mo
68399 if (!(shdr->sh_flags & SHF_ALLOC))
68400 continue;
68401
68402 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
68403 - dest = mod->module_init
68404 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68405 - else
68406 - dest = mod->module_core + shdr->sh_entsize;
68407 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
68408 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
68409 + dest = mod->module_init_rw
68410 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68411 + else
68412 + dest = mod->module_init_rx
68413 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68414 + } else {
68415 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
68416 + dest = mod->module_core_rw + shdr->sh_entsize;
68417 + else
68418 + dest = mod->module_core_rx + shdr->sh_entsize;
68419 + }
68420 +
68421 + if (shdr->sh_type != SHT_NOBITS) {
68422 +
68423 +#ifdef CONFIG_PAX_KERNEXEC
68424 +#ifdef CONFIG_X86_64
68425 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
68426 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
68427 +#endif
68428 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
68429 + pax_open_kernel();
68430 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
68431 + pax_close_kernel();
68432 + } else
68433 +#endif
68434
68435 - if (shdr->sh_type != SHT_NOBITS)
68436 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
68437 + }
68438 /* Update sh_addr to point to copy in image. */
68439 - shdr->sh_addr = (unsigned long)dest;
68440 +
68441 +#ifdef CONFIG_PAX_KERNEXEC
68442 + if (shdr->sh_flags & SHF_EXECINSTR)
68443 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
68444 + else
68445 +#endif
68446 +
68447 + shdr->sh_addr = (unsigned long)dest;
68448 DEBUGP("\t0x%lx %s\n",
68449 shdr->sh_addr, info->secstrings + shdr->sh_name);
68450 }
68451 @@ -2613,12 +2706,12 @@ static void flush_module_icache(const st
68452 * Do it before processing of module parameters, so the module
68453 * can provide parameter accessor functions of its own.
68454 */
68455 - if (mod->module_init)
68456 - flush_icache_range((unsigned long)mod->module_init,
68457 - (unsigned long)mod->module_init
68458 - + mod->init_size);
68459 - flush_icache_range((unsigned long)mod->module_core,
68460 - (unsigned long)mod->module_core + mod->core_size);
68461 + if (mod->module_init_rx)
68462 + flush_icache_range((unsigned long)mod->module_init_rx,
68463 + (unsigned long)mod->module_init_rx
68464 + + mod->init_size_rx);
68465 + flush_icache_range((unsigned long)mod->module_core_rx,
68466 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
68467
68468 set_fs(old_fs);
68469 }
68470 @@ -2690,8 +2783,10 @@ static void module_deallocate(struct mod
68471 {
68472 kfree(info->strmap);
68473 percpu_modfree(mod);
68474 - module_free(mod, mod->module_init);
68475 - module_free(mod, mod->module_core);
68476 + module_free_exec(mod, mod->module_init_rx);
68477 + module_free_exec(mod, mod->module_core_rx);
68478 + module_free(mod, mod->module_init_rw);
68479 + module_free(mod, mod->module_core_rw);
68480 }
68481
68482 static int post_relocation(struct module *mod, const struct load_info *info)
68483 @@ -2748,9 +2843,38 @@ static struct module *load_module(void _
68484 if (err)
68485 goto free_unload;
68486
68487 + /* Now copy in args */
68488 + mod->args = strndup_user(uargs, ~0UL >> 1);
68489 + if (IS_ERR(mod->args)) {
68490 + err = PTR_ERR(mod->args);
68491 + goto free_unload;
68492 + }
68493 +
68494 /* Set up MODINFO_ATTR fields */
68495 setup_modinfo(mod, &info);
68496
68497 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68498 + {
68499 + char *p, *p2;
68500 +
68501 + if (strstr(mod->args, "grsec_modharden_netdev")) {
68502 + 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);
68503 + err = -EPERM;
68504 + goto free_modinfo;
68505 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
68506 + p += strlen("grsec_modharden_normal");
68507 + p2 = strstr(p, "_");
68508 + if (p2) {
68509 + *p2 = '\0';
68510 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
68511 + *p2 = '_';
68512 + }
68513 + err = -EPERM;
68514 + goto free_modinfo;
68515 + }
68516 + }
68517 +#endif
68518 +
68519 /* Fix up syms, so that st_value is a pointer to location. */
68520 err = simplify_symbols(mod, &info);
68521 if (err < 0)
68522 @@ -2766,13 +2890,6 @@ static struct module *load_module(void _
68523
68524 flush_module_icache(mod);
68525
68526 - /* Now copy in args */
68527 - mod->args = strndup_user(uargs, ~0UL >> 1);
68528 - if (IS_ERR(mod->args)) {
68529 - err = PTR_ERR(mod->args);
68530 - goto free_arch_cleanup;
68531 - }
68532 -
68533 /* Mark state as coming so strong_try_module_get() ignores us. */
68534 mod->state = MODULE_STATE_COMING;
68535
68536 @@ -2832,11 +2949,10 @@ static struct module *load_module(void _
68537 unlock:
68538 mutex_unlock(&module_mutex);
68539 synchronize_sched();
68540 - kfree(mod->args);
68541 - free_arch_cleanup:
68542 module_arch_cleanup(mod);
68543 free_modinfo:
68544 free_modinfo(mod);
68545 + kfree(mod->args);
68546 free_unload:
68547 module_unload_free(mod);
68548 free_module:
68549 @@ -2877,16 +2993,16 @@ SYSCALL_DEFINE3(init_module, void __user
68550 MODULE_STATE_COMING, mod);
68551
68552 /* Set RO and NX regions for core */
68553 - set_section_ro_nx(mod->module_core,
68554 - mod->core_text_size,
68555 - mod->core_ro_size,
68556 - mod->core_size);
68557 + set_section_ro_nx(mod->module_core_rx,
68558 + mod->core_size_rx,
68559 + mod->core_size_rx,
68560 + mod->core_size_rx);
68561
68562 /* Set RO and NX regions for init */
68563 - set_section_ro_nx(mod->module_init,
68564 - mod->init_text_size,
68565 - mod->init_ro_size,
68566 - mod->init_size);
68567 + set_section_ro_nx(mod->module_init_rx,
68568 + mod->init_size_rx,
68569 + mod->init_size_rx,
68570 + mod->init_size_rx);
68571
68572 do_mod_ctors(mod);
68573 /* Start the module */
68574 @@ -2931,11 +3047,13 @@ SYSCALL_DEFINE3(init_module, void __user
68575 mod->symtab = mod->core_symtab;
68576 mod->strtab = mod->core_strtab;
68577 #endif
68578 - unset_section_ro_nx(mod, mod->module_init);
68579 - module_free(mod, mod->module_init);
68580 - mod->module_init = NULL;
68581 - mod->init_size = 0;
68582 - mod->init_text_size = 0;
68583 + unset_section_ro_nx(mod, mod->module_init_rx);
68584 + module_free(mod, mod->module_init_rw);
68585 + module_free_exec(mod, mod->module_init_rx);
68586 + mod->module_init_rw = NULL;
68587 + mod->module_init_rx = NULL;
68588 + mod->init_size_rw = 0;
68589 + mod->init_size_rx = 0;
68590 mutex_unlock(&module_mutex);
68591
68592 return 0;
68593 @@ -2966,10 +3084,16 @@ static const char *get_ksymbol(struct mo
68594 unsigned long nextval;
68595
68596 /* At worse, next value is at end of module */
68597 - if (within_module_init(addr, mod))
68598 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
68599 + if (within_module_init_rx(addr, mod))
68600 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
68601 + else if (within_module_init_rw(addr, mod))
68602 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
68603 + else if (within_module_core_rx(addr, mod))
68604 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
68605 + else if (within_module_core_rw(addr, mod))
68606 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
68607 else
68608 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
68609 + return NULL;
68610
68611 /* Scan for closest preceding symbol, and next symbol. (ELF
68612 starts real symbols at 1). */
68613 @@ -3215,7 +3339,7 @@ static int m_show(struct seq_file *m, vo
68614 char buf[8];
68615
68616 seq_printf(m, "%s %u",
68617 - mod->name, mod->init_size + mod->core_size);
68618 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
68619 print_unload_info(m, mod);
68620
68621 /* Informative for users. */
68622 @@ -3224,7 +3348,7 @@ static int m_show(struct seq_file *m, vo
68623 mod->state == MODULE_STATE_COMING ? "Loading":
68624 "Live");
68625 /* Used by oprofile and other similar tools. */
68626 - seq_printf(m, " 0x%pK", mod->module_core);
68627 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
68628
68629 /* Taints info */
68630 if (mod->taints)
68631 @@ -3260,7 +3384,17 @@ static const struct file_operations proc
68632
68633 static int __init proc_modules_init(void)
68634 {
68635 +#ifndef CONFIG_GRKERNSEC_HIDESYM
68636 +#ifdef CONFIG_GRKERNSEC_PROC_USER
68637 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
68638 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68639 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
68640 +#else
68641 proc_create("modules", 0, NULL, &proc_modules_operations);
68642 +#endif
68643 +#else
68644 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
68645 +#endif
68646 return 0;
68647 }
68648 module_init(proc_modules_init);
68649 @@ -3319,12 +3453,12 @@ struct module *__module_address(unsigned
68650 {
68651 struct module *mod;
68652
68653 - if (addr < module_addr_min || addr > module_addr_max)
68654 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
68655 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
68656 return NULL;
68657
68658 list_for_each_entry_rcu(mod, &modules, list)
68659 - if (within_module_core(addr, mod)
68660 - || within_module_init(addr, mod))
68661 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
68662 return mod;
68663 return NULL;
68664 }
68665 @@ -3358,11 +3492,20 @@ bool is_module_text_address(unsigned lon
68666 */
68667 struct module *__module_text_address(unsigned long addr)
68668 {
68669 - struct module *mod = __module_address(addr);
68670 + struct module *mod;
68671 +
68672 +#ifdef CONFIG_X86_32
68673 + addr = ktla_ktva(addr);
68674 +#endif
68675 +
68676 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
68677 + return NULL;
68678 +
68679 + mod = __module_address(addr);
68680 +
68681 if (mod) {
68682 /* Make sure it's within the text section. */
68683 - if (!within(addr, mod->module_init, mod->init_text_size)
68684 - && !within(addr, mod->module_core, mod->core_text_size))
68685 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
68686 mod = NULL;
68687 }
68688 return mod;
68689 diff -urNp linux-2.6.39/kernel/mutex.c linux-2.6.39/kernel/mutex.c
68690 --- linux-2.6.39/kernel/mutex.c 2011-05-19 00:06:34.000000000 -0400
68691 +++ linux-2.6.39/kernel/mutex.c 2011-05-22 19:36:33.000000000 -0400
68692 @@ -160,7 +160,7 @@ __mutex_lock_common(struct mutex *lock,
68693 */
68694
68695 for (;;) {
68696 - struct thread_info *owner;
68697 + struct task_struct *owner;
68698
68699 /*
68700 * If we own the BKL, then don't spin. The owner of
68701 @@ -205,7 +205,7 @@ __mutex_lock_common(struct mutex *lock,
68702 spin_lock_mutex(&lock->wait_lock, flags);
68703
68704 debug_mutex_lock_common(lock, &waiter);
68705 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
68706 + debug_mutex_add_waiter(lock, &waiter, task);
68707
68708 /* add waiting tasks to the end of the waitqueue (FIFO): */
68709 list_add_tail(&waiter.list, &lock->wait_list);
68710 @@ -234,8 +234,7 @@ __mutex_lock_common(struct mutex *lock,
68711 * TASK_UNINTERRUPTIBLE case.)
68712 */
68713 if (unlikely(signal_pending_state(state, task))) {
68714 - mutex_remove_waiter(lock, &waiter,
68715 - task_thread_info(task));
68716 + mutex_remove_waiter(lock, &waiter, task);
68717 mutex_release(&lock->dep_map, 1, ip);
68718 spin_unlock_mutex(&lock->wait_lock, flags);
68719
68720 @@ -256,7 +255,7 @@ __mutex_lock_common(struct mutex *lock,
68721 done:
68722 lock_acquired(&lock->dep_map, ip);
68723 /* got the lock - rejoice! */
68724 - mutex_remove_waiter(lock, &waiter, current_thread_info());
68725 + mutex_remove_waiter(lock, &waiter, task);
68726 mutex_set_owner(lock);
68727
68728 /* set it to 0 if there are no waiters left: */
68729 diff -urNp linux-2.6.39/kernel/mutex-debug.c linux-2.6.39/kernel/mutex-debug.c
68730 --- linux-2.6.39/kernel/mutex-debug.c 2011-05-19 00:06:34.000000000 -0400
68731 +++ linux-2.6.39/kernel/mutex-debug.c 2011-05-22 19:36:33.000000000 -0400
68732 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mute
68733 }
68734
68735 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68736 - struct thread_info *ti)
68737 + struct task_struct *task)
68738 {
68739 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
68740
68741 /* Mark the current thread as blocked on the lock: */
68742 - ti->task->blocked_on = waiter;
68743 + task->blocked_on = waiter;
68744 }
68745
68746 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68747 - struct thread_info *ti)
68748 + struct task_struct *task)
68749 {
68750 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
68751 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
68752 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
68753 - ti->task->blocked_on = NULL;
68754 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
68755 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
68756 + task->blocked_on = NULL;
68757
68758 list_del_init(&waiter->list);
68759 waiter->task = NULL;
68760 @@ -75,7 +75,7 @@ void debug_mutex_unlock(struct mutex *lo
68761 return;
68762
68763 DEBUG_LOCKS_WARN_ON(lock->magic != lock);
68764 - DEBUG_LOCKS_WARN_ON(lock->owner != current_thread_info());
68765 + DEBUG_LOCKS_WARN_ON(lock->owner != current);
68766 DEBUG_LOCKS_WARN_ON(!lock->wait_list.prev && !lock->wait_list.next);
68767 mutex_clear_owner(lock);
68768 }
68769 diff -urNp linux-2.6.39/kernel/mutex-debug.h linux-2.6.39/kernel/mutex-debug.h
68770 --- linux-2.6.39/kernel/mutex-debug.h 2011-05-19 00:06:34.000000000 -0400
68771 +++ linux-2.6.39/kernel/mutex-debug.h 2011-05-22 19:36:33.000000000 -0400
68772 @@ -20,16 +20,16 @@ extern void debug_mutex_wake_waiter(stru
68773 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
68774 extern void debug_mutex_add_waiter(struct mutex *lock,
68775 struct mutex_waiter *waiter,
68776 - struct thread_info *ti);
68777 + struct task_struct *task);
68778 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68779 - struct thread_info *ti);
68780 + struct task_struct *task);
68781 extern void debug_mutex_unlock(struct mutex *lock);
68782 extern void debug_mutex_init(struct mutex *lock, const char *name,
68783 struct lock_class_key *key);
68784
68785 static inline void mutex_set_owner(struct mutex *lock)
68786 {
68787 - lock->owner = current_thread_info();
68788 + lock->owner = current;
68789 }
68790
68791 static inline void mutex_clear_owner(struct mutex *lock)
68792 diff -urNp linux-2.6.39/kernel/mutex.h linux-2.6.39/kernel/mutex.h
68793 --- linux-2.6.39/kernel/mutex.h 2011-05-19 00:06:34.000000000 -0400
68794 +++ linux-2.6.39/kernel/mutex.h 2011-05-22 19:36:33.000000000 -0400
68795 @@ -19,7 +19,7 @@
68796 #ifdef CONFIG_SMP
68797 static inline void mutex_set_owner(struct mutex *lock)
68798 {
68799 - lock->owner = current_thread_info();
68800 + lock->owner = current;
68801 }
68802
68803 static inline void mutex_clear_owner(struct mutex *lock)
68804 diff -urNp linux-2.6.39/kernel/padata.c linux-2.6.39/kernel/padata.c
68805 --- linux-2.6.39/kernel/padata.c 2011-05-19 00:06:34.000000000 -0400
68806 +++ linux-2.6.39/kernel/padata.c 2011-05-22 19:36:33.000000000 -0400
68807 @@ -132,10 +132,10 @@ int padata_do_parallel(struct padata_ins
68808 padata->pd = pd;
68809 padata->cb_cpu = cb_cpu;
68810
68811 - if (unlikely(atomic_read(&pd->seq_nr) == pd->max_seq_nr))
68812 - atomic_set(&pd->seq_nr, -1);
68813 + if (unlikely(atomic_read_unchecked(&pd->seq_nr) == pd->max_seq_nr))
68814 + atomic_set_unchecked(&pd->seq_nr, -1);
68815
68816 - padata->seq_nr = atomic_inc_return(&pd->seq_nr);
68817 + padata->seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
68818
68819 target_cpu = padata_cpu_hash(padata);
68820 queue = per_cpu_ptr(pd->pqueue, target_cpu);
68821 @@ -444,7 +444,7 @@ static struct parallel_data *padata_allo
68822 padata_init_pqueues(pd);
68823 padata_init_squeues(pd);
68824 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
68825 - atomic_set(&pd->seq_nr, -1);
68826 + atomic_set_unchecked(&pd->seq_nr, -1);
68827 atomic_set(&pd->reorder_objects, 0);
68828 atomic_set(&pd->refcnt, 0);
68829 pd->pinst = pinst;
68830 diff -urNp linux-2.6.39/kernel/panic.c linux-2.6.39/kernel/panic.c
68831 --- linux-2.6.39/kernel/panic.c 2011-05-19 00:06:34.000000000 -0400
68832 +++ linux-2.6.39/kernel/panic.c 2011-05-22 19:41:42.000000000 -0400
68833 @@ -369,7 +369,7 @@ static void warn_slowpath_common(const c
68834 const char *board;
68835
68836 printk(KERN_WARNING "------------[ cut here ]------------\n");
68837 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
68838 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
68839 board = dmi_get_system_info(DMI_PRODUCT_NAME);
68840 if (board)
68841 printk(KERN_WARNING "Hardware name: %s\n", board);
68842 @@ -424,7 +424,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
68843 */
68844 void __stack_chk_fail(void)
68845 {
68846 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
68847 + dump_stack();
68848 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
68849 __builtin_return_address(0));
68850 }
68851 EXPORT_SYMBOL(__stack_chk_fail);
68852 diff -urNp linux-2.6.39/kernel/params.c linux-2.6.39/kernel/params.c
68853 --- linux-2.6.39/kernel/params.c 2011-05-19 00:06:34.000000000 -0400
68854 +++ linux-2.6.39/kernel/params.c 2011-05-22 19:36:33.000000000 -0400
68855 @@ -234,7 +234,7 @@ int parse_args(const char *name,
68856 { \
68857 return sprintf(buffer, format, *((type *)kp->arg)); \
68858 } \
68859 - struct kernel_param_ops param_ops_##name = { \
68860 + const struct kernel_param_ops param_ops_##name = { \
68861 .set = param_set_##name, \
68862 .get = param_get_##name, \
68863 }; \
68864 @@ -286,7 +286,7 @@ static void param_free_charp(void *arg)
68865 maybe_kfree_parameter(*((char **)arg));
68866 }
68867
68868 -struct kernel_param_ops param_ops_charp = {
68869 +const struct kernel_param_ops param_ops_charp = {
68870 .set = param_set_charp,
68871 .get = param_get_charp,
68872 .free = param_free_charp,
68873 @@ -334,7 +334,7 @@ int param_get_bool(char *buffer, const s
68874 }
68875 EXPORT_SYMBOL(param_get_bool);
68876
68877 -struct kernel_param_ops param_ops_bool = {
68878 +const struct kernel_param_ops param_ops_bool = {
68879 .set = param_set_bool,
68880 .get = param_get_bool,
68881 };
68882 @@ -362,7 +362,7 @@ int param_get_invbool(char *buffer, cons
68883 }
68884 EXPORT_SYMBOL(param_get_invbool);
68885
68886 -struct kernel_param_ops param_ops_invbool = {
68887 +const struct kernel_param_ops param_ops_invbool = {
68888 .set = param_set_invbool,
68889 .get = param_get_invbool,
68890 };
68891 @@ -460,7 +460,7 @@ static void param_array_free(void *arg)
68892 arr->ops->free(arr->elem + arr->elemsize * i);
68893 }
68894
68895 -struct kernel_param_ops param_array_ops = {
68896 +const struct kernel_param_ops param_array_ops = {
68897 .set = param_array_set,
68898 .get = param_array_get,
68899 .free = param_array_free,
68900 @@ -488,7 +488,7 @@ int param_get_string(char *buffer, const
68901 }
68902 EXPORT_SYMBOL(param_get_string);
68903
68904 -struct kernel_param_ops param_ops_string = {
68905 +const struct kernel_param_ops param_ops_string = {
68906 .set = param_set_copystring,
68907 .get = param_get_string,
68908 };
68909 diff -urNp linux-2.6.39/kernel/perf_event.c linux-2.6.39/kernel/perf_event.c
68910 --- linux-2.6.39/kernel/perf_event.c 2011-05-19 00:06:34.000000000 -0400
68911 +++ linux-2.6.39/kernel/perf_event.c 2011-05-22 19:36:33.000000000 -0400
68912 @@ -170,7 +170,7 @@ int perf_proc_update_handler(struct ctl_
68913 return 0;
68914 }
68915
68916 -static atomic64_t perf_event_id;
68917 +static atomic64_unchecked_t perf_event_id;
68918
68919 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
68920 enum event_type_t event_type);
68921 @@ -2496,7 +2496,7 @@ static void __perf_event_read(void *info
68922
68923 static inline u64 perf_event_count(struct perf_event *event)
68924 {
68925 - return local64_read(&event->count) + atomic64_read(&event->child_count);
68926 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
68927 }
68928
68929 static u64 perf_event_read(struct perf_event *event)
68930 @@ -3031,9 +3031,9 @@ u64 perf_event_read_value(struct perf_ev
68931 mutex_lock(&event->child_mutex);
68932 total += perf_event_read(event);
68933 *enabled += event->total_time_enabled +
68934 - atomic64_read(&event->child_total_time_enabled);
68935 + atomic64_read_unchecked(&event->child_total_time_enabled);
68936 *running += event->total_time_running +
68937 - atomic64_read(&event->child_total_time_running);
68938 + atomic64_read_unchecked(&event->child_total_time_running);
68939
68940 list_for_each_entry(child, &event->child_list, child_list) {
68941 total += perf_event_read(child);
68942 @@ -3396,10 +3396,10 @@ void perf_event_update_userpage(struct p
68943 userpg->offset -= local64_read(&event->hw.prev_count);
68944
68945 userpg->time_enabled = event->total_time_enabled +
68946 - atomic64_read(&event->child_total_time_enabled);
68947 + atomic64_read_unchecked(&event->child_total_time_enabled);
68948
68949 userpg->time_running = event->total_time_running +
68950 - atomic64_read(&event->child_total_time_running);
68951 + atomic64_read_unchecked(&event->child_total_time_running);
68952
68953 barrier();
68954 ++userpg->lock;
68955 @@ -3884,16 +3884,16 @@ static void perf_pending_event(struct ir
68956 * Later on, we might change it to a list if there is
68957 * another virtualization implementation supporting the callbacks.
68958 */
68959 -struct perf_guest_info_callbacks *perf_guest_cbs;
68960 +const struct perf_guest_info_callbacks *perf_guest_cbs;
68961
68962 -int perf_register_guest_info_callbacks(struct perf_guest_info_callbacks *cbs)
68963 +int perf_register_guest_info_callbacks(const struct perf_guest_info_callbacks *cbs)
68964 {
68965 perf_guest_cbs = cbs;
68966 return 0;
68967 }
68968 EXPORT_SYMBOL_GPL(perf_register_guest_info_callbacks);
68969
68970 -int perf_unregister_guest_info_callbacks(struct perf_guest_info_callbacks *cbs)
68971 +int perf_unregister_guest_info_callbacks(const struct perf_guest_info_callbacks *cbs)
68972 {
68973 perf_guest_cbs = NULL;
68974 return 0;
68975 @@ -4196,11 +4196,11 @@ static void perf_output_read_one(struct
68976 values[n++] = perf_event_count(event);
68977 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
68978 values[n++] = enabled +
68979 - atomic64_read(&event->child_total_time_enabled);
68980 + atomic64_read_unchecked(&event->child_total_time_enabled);
68981 }
68982 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
68983 values[n++] = running +
68984 - atomic64_read(&event->child_total_time_running);
68985 + atomic64_read_unchecked(&event->child_total_time_running);
68986 }
68987 if (read_format & PERF_FORMAT_ID)
68988 values[n++] = primary_event_id(event);
68989 @@ -6201,7 +6201,7 @@ perf_event_alloc(struct perf_event_attr
68990 event->parent = parent_event;
68991
68992 event->ns = get_pid_ns(current->nsproxy->pid_ns);
68993 - event->id = atomic64_inc_return(&perf_event_id);
68994 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
68995
68996 event->state = PERF_EVENT_STATE_INACTIVE;
68997
68998 @@ -6724,10 +6724,10 @@ static void sync_child_event(struct perf
68999 /*
69000 * Add back the child's count to the parent's count:
69001 */
69002 - atomic64_add(child_val, &parent_event->child_count);
69003 - atomic64_add(child_event->total_time_enabled,
69004 + atomic64_add_unchecked(child_val, &parent_event->child_count);
69005 + atomic64_add_unchecked(child_event->total_time_enabled,
69006 &parent_event->child_total_time_enabled);
69007 - atomic64_add(child_event->total_time_running,
69008 + atomic64_add_unchecked(child_event->total_time_running,
69009 &parent_event->child_total_time_running);
69010
69011 /*
69012 diff -urNp linux-2.6.39/kernel/pid.c linux-2.6.39/kernel/pid.c
69013 --- linux-2.6.39/kernel/pid.c 2011-05-19 00:06:34.000000000 -0400
69014 +++ linux-2.6.39/kernel/pid.c 2011-05-22 19:41:42.000000000 -0400
69015 @@ -33,6 +33,7 @@
69016 #include <linux/rculist.h>
69017 #include <linux/bootmem.h>
69018 #include <linux/hash.h>
69019 +#include <linux/security.h>
69020 #include <linux/pid_namespace.h>
69021 #include <linux/init_task.h>
69022 #include <linux/syscalls.h>
69023 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT
69024
69025 int pid_max = PID_MAX_DEFAULT;
69026
69027 -#define RESERVED_PIDS 300
69028 +#define RESERVED_PIDS 500
69029
69030 int pid_max_min = RESERVED_PIDS + 1;
69031 int pid_max_max = PID_MAX_LIMIT;
69032 @@ -419,8 +420,15 @@ EXPORT_SYMBOL(pid_task);
69033 */
69034 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
69035 {
69036 + struct task_struct *task;
69037 +
69038 rcu_lockdep_assert(rcu_read_lock_held());
69039 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
69040 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
69041 +
69042 + if (gr_pid_is_chrooted(task))
69043 + return NULL;
69044 +
69045 + return task;
69046 }
69047
69048 struct task_struct *find_task_by_vpid(pid_t vnr)
69049 diff -urNp linux-2.6.39/kernel/posix-cpu-timers.c linux-2.6.39/kernel/posix-cpu-timers.c
69050 --- linux-2.6.39/kernel/posix-cpu-timers.c 2011-05-19 00:06:34.000000000 -0400
69051 +++ linux-2.6.39/kernel/posix-cpu-timers.c 2011-05-22 19:41:42.000000000 -0400
69052 @@ -6,6 +6,7 @@
69053 #include <linux/posix-timers.h>
69054 #include <linux/errno.h>
69055 #include <linux/math64.h>
69056 +#include <linux/security.h>
69057 #include <asm/uaccess.h>
69058 #include <linux/kernel_stat.h>
69059 #include <trace/events/timer.h>
69060 @@ -1590,7 +1591,7 @@ static int thread_cpu_timer_create(struc
69061 return posix_cpu_timer_create(timer);
69062 }
69063
69064 -struct k_clock clock_posix_cpu = {
69065 +const struct k_clock clock_posix_cpu = {
69066 .clock_getres = posix_cpu_clock_getres,
69067 .clock_set = posix_cpu_clock_set,
69068 .clock_get = posix_cpu_clock_get,
69069 @@ -1604,14 +1605,14 @@ struct k_clock clock_posix_cpu = {
69070
69071 static __init int init_posix_cpu_timers(void)
69072 {
69073 - struct k_clock process = {
69074 + const struct k_clock process = {
69075 .clock_getres = process_cpu_clock_getres,
69076 .clock_get = process_cpu_clock_get,
69077 .timer_create = process_cpu_timer_create,
69078 .nsleep = process_cpu_nsleep,
69079 .nsleep_restart = process_cpu_nsleep_restart,
69080 };
69081 - struct k_clock thread = {
69082 + const struct k_clock thread = {
69083 .clock_getres = thread_cpu_clock_getres,
69084 .clock_get = thread_cpu_clock_get,
69085 .timer_create = thread_cpu_timer_create,
69086 diff -urNp linux-2.6.39/kernel/posix-timers.c linux-2.6.39/kernel/posix-timers.c
69087 --- linux-2.6.39/kernel/posix-timers.c 2011-05-19 00:06:34.000000000 -0400
69088 +++ linux-2.6.39/kernel/posix-timers.c 2011-05-22 20:13:41.000000000 -0400
69089 @@ -43,6 +43,7 @@
69090 #include <linux/idr.h>
69091 #include <linux/posix-clock.h>
69092 #include <linux/posix-timers.h>
69093 +#include <linux/grsecurity.h>
69094 #include <linux/syscalls.h>
69095 #include <linux/wait.h>
69096 #include <linux/workqueue.h>
69097 @@ -227,7 +228,7 @@ static int posix_get_boottime(const cloc
69098 */
69099 static __init int init_posix_timers(void)
69100 {
69101 - struct k_clock clock_realtime = {
69102 + const struct k_clock clock_realtime = {
69103 .clock_getres = hrtimer_get_res,
69104 .clock_get = posix_clock_realtime_get,
69105 .clock_set = posix_clock_realtime_set,
69106 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void
69107 .timer_get = common_timer_get,
69108 .timer_del = common_timer_del,
69109 };
69110 - struct k_clock clock_monotonic = {
69111 + const struct k_clock clock_monotonic = {
69112 .clock_getres = hrtimer_get_res,
69113 .clock_get = posix_ktime_get_ts,
69114 .nsleep = common_nsleep,
69115 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void
69116 .timer_get = common_timer_get,
69117 .timer_del = common_timer_del,
69118 };
69119 - struct k_clock clock_monotonic_raw = {
69120 + const struct k_clock clock_monotonic_raw = {
69121 .clock_getres = hrtimer_get_res,
69122 .clock_get = posix_get_monotonic_raw,
69123 };
69124 - struct k_clock clock_realtime_coarse = {
69125 + const struct k_clock clock_realtime_coarse = {
69126 .clock_getres = posix_get_coarse_res,
69127 .clock_get = posix_get_realtime_coarse,
69128 };
69129 - struct k_clock clock_monotonic_coarse = {
69130 + const struct k_clock clock_monotonic_coarse = {
69131 .clock_getres = posix_get_coarse_res,
69132 .clock_get = posix_get_monotonic_coarse,
69133 };
69134 - struct k_clock clock_boottime = {
69135 + const struct k_clock clock_boottime = {
69136 .clock_getres = hrtimer_get_res,
69137 .clock_get = posix_get_boottime,
69138 .nsleep = common_nsleep,
69139 @@ -272,6 +273,8 @@ static __init int init_posix_timers(void
69140 .timer_del = common_timer_del,
69141 };
69142
69143 + pax_track_stack();
69144 +
69145 posix_timers_register_clock(CLOCK_REALTIME, &clock_realtime);
69146 posix_timers_register_clock(CLOCK_MONOTONIC, &clock_monotonic);
69147 posix_timers_register_clock(CLOCK_MONOTONIC_RAW, &clock_monotonic_raw);
69148 @@ -454,7 +457,7 @@ static struct pid *good_sigevent(sigeven
69149 }
69150
69151 void posix_timers_register_clock(const clockid_t clock_id,
69152 - struct k_clock *new_clock)
69153 + const struct k_clock *new_clock)
69154 {
69155 if ((unsigned) clock_id >= MAX_CLOCKS) {
69156 printk(KERN_WARNING "POSIX clock register failed for clock_id %d\n",
69157 @@ -506,7 +509,7 @@ static void release_posix_timer(struct k
69158 kmem_cache_free(posix_timers_cache, tmr);
69159 }
69160
69161 -static struct k_clock *clockid_to_kclock(const clockid_t id)
69162 +static const struct k_clock *clockid_to_kclock(const clockid_t id)
69163 {
69164 if (id < 0)
69165 return (id & CLOCKFD_MASK) == CLOCKFD ?
69166 @@ -529,7 +532,7 @@ SYSCALL_DEFINE3(timer_create, const cloc
69167 struct sigevent __user *, timer_event_spec,
69168 timer_t __user *, created_timer_id)
69169 {
69170 - struct k_clock *kc = clockid_to_kclock(which_clock);
69171 + const struct k_clock *kc = clockid_to_kclock(which_clock);
69172 struct k_itimer *new_timer;
69173 int error, new_timer_id;
69174 sigevent_t event;
69175 @@ -714,7 +717,7 @@ SYSCALL_DEFINE2(timer_gettime, timer_t,
69176 {
69177 struct itimerspec cur_setting;
69178 struct k_itimer *timr;
69179 - struct k_clock *kc;
69180 + const struct k_clock *kc;
69181 unsigned long flags;
69182 int ret = 0;
69183
69184 @@ -822,7 +825,7 @@ SYSCALL_DEFINE4(timer_settime, timer_t,
69185 int error = 0;
69186 unsigned long flag;
69187 struct itimerspec *rtn = old_setting ? &old_spec : NULL;
69188 - struct k_clock *kc;
69189 + const struct k_clock *kc;
69190
69191 if (!new_setting)
69192 return -EINVAL;
69193 @@ -868,7 +871,7 @@ static int common_timer_del(struct k_iti
69194
69195 static inline int timer_delete_hook(struct k_itimer *timer)
69196 {
69197 - struct k_clock *kc = clockid_to_kclock(timer->it_clock);
69198 + const struct k_clock *kc = clockid_to_kclock(timer->it_clock);
69199
69200 if (WARN_ON_ONCE(!kc || !kc->timer_del))
69201 return -EINVAL;
69202 @@ -947,7 +950,7 @@ void exit_itimers(struct signal_struct *
69203 SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
69204 const struct timespec __user *, tp)
69205 {
69206 - struct k_clock *kc = clockid_to_kclock(which_clock);
69207 + const struct k_clock *kc = clockid_to_kclock(which_clock);
69208 struct timespec new_tp;
69209
69210 if (!kc || !kc->clock_set)
69211 @@ -956,13 +959,20 @@ SYSCALL_DEFINE2(clock_settime, const clo
69212 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
69213 return -EFAULT;
69214
69215 + /* only the CLOCK_REALTIME clock can be set, all other clocks
69216 + have their clock_set fptr set to a nosettime dummy function
69217 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
69218 + call common_clock_set, which calls do_sys_settimeofday, which
69219 + we hook
69220 + */
69221 +
69222 return kc->clock_set(which_clock, &new_tp);
69223 }
69224
69225 SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock,
69226 struct timespec __user *,tp)
69227 {
69228 - struct k_clock *kc = clockid_to_kclock(which_clock);
69229 + const struct k_clock *kc = clockid_to_kclock(which_clock);
69230 struct timespec kernel_tp;
69231 int error;
69232
69233 @@ -980,7 +990,7 @@ SYSCALL_DEFINE2(clock_gettime, const clo
69234 SYSCALL_DEFINE2(clock_adjtime, const clockid_t, which_clock,
69235 struct timex __user *, utx)
69236 {
69237 - struct k_clock *kc = clockid_to_kclock(which_clock);
69238 + const struct k_clock *kc = clockid_to_kclock(which_clock);
69239 struct timex ktx;
69240 int err;
69241
69242 @@ -1003,7 +1013,7 @@ SYSCALL_DEFINE2(clock_adjtime, const clo
69243 SYSCALL_DEFINE2(clock_getres, const clockid_t, which_clock,
69244 struct timespec __user *, tp)
69245 {
69246 - struct k_clock *kc = clockid_to_kclock(which_clock);
69247 + const struct k_clock *kc = clockid_to_kclock(which_clock);
69248 struct timespec rtn_tp;
69249 int error;
69250
69251 @@ -1033,7 +1043,7 @@ SYSCALL_DEFINE4(clock_nanosleep, const c
69252 const struct timespec __user *, rqtp,
69253 struct timespec __user *, rmtp)
69254 {
69255 - struct k_clock *kc = clockid_to_kclock(which_clock);
69256 + const struct k_clock *kc = clockid_to_kclock(which_clock);
69257 struct timespec t;
69258
69259 if (!kc)
69260 @@ -1057,7 +1067,7 @@ SYSCALL_DEFINE4(clock_nanosleep, const c
69261 long clock_nanosleep_restart(struct restart_block *restart_block)
69262 {
69263 clockid_t which_clock = restart_block->nanosleep.index;
69264 - struct k_clock *kc = clockid_to_kclock(which_clock);
69265 + const struct k_clock *kc = clockid_to_kclock(which_clock);
69266
69267 if (WARN_ON_ONCE(!kc || !kc->nsleep_restart))
69268 return -EINVAL;
69269 diff -urNp linux-2.6.39/kernel/power/poweroff.c linux-2.6.39/kernel/power/poweroff.c
69270 --- linux-2.6.39/kernel/power/poweroff.c 2011-05-19 00:06:34.000000000 -0400
69271 +++ linux-2.6.39/kernel/power/poweroff.c 2011-05-22 19:36:33.000000000 -0400
69272 @@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_powerof
69273 .enable_mask = SYSRQ_ENABLE_BOOT,
69274 };
69275
69276 -static int pm_sysrq_init(void)
69277 +static int __init pm_sysrq_init(void)
69278 {
69279 register_sysrq_key('o', &sysrq_poweroff_op);
69280 return 0;
69281 diff -urNp linux-2.6.39/kernel/power/process.c linux-2.6.39/kernel/power/process.c
69282 --- linux-2.6.39/kernel/power/process.c 2011-05-19 00:06:34.000000000 -0400
69283 +++ linux-2.6.39/kernel/power/process.c 2011-05-22 19:36:33.000000000 -0400
69284 @@ -41,6 +41,7 @@ static int try_to_freeze_tasks(bool sig_
69285 u64 elapsed_csecs64;
69286 unsigned int elapsed_csecs;
69287 bool wakeup = false;
69288 + bool timedout = false;
69289
69290 do_gettimeofday(&start);
69291
69292 @@ -51,6 +52,8 @@ static int try_to_freeze_tasks(bool sig_
69293
69294 while (true) {
69295 todo = 0;
69296 + if (time_after(jiffies, end_time))
69297 + timedout = true;
69298 read_lock(&tasklist_lock);
69299 do_each_thread(g, p) {
69300 if (frozen(p) || !freezable(p))
69301 @@ -71,9 +74,13 @@ static int try_to_freeze_tasks(bool sig_
69302 * try_to_stop() after schedule() in ptrace/signal
69303 * stop sees TIF_FREEZE.
69304 */
69305 - if (!task_is_stopped_or_traced(p) &&
69306 - !freezer_should_skip(p))
69307 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
69308 todo++;
69309 + if (timedout) {
69310 + printk(KERN_ERR "Task refusing to freeze:\n");
69311 + sched_show_task(p);
69312 + }
69313 + }
69314 } while_each_thread(g, p);
69315 read_unlock(&tasklist_lock);
69316
69317 @@ -82,7 +89,7 @@ static int try_to_freeze_tasks(bool sig_
69318 todo += wq_busy;
69319 }
69320
69321 - if (!todo || time_after(jiffies, end_time))
69322 + if (!todo || timedout)
69323 break;
69324
69325 if (pm_wakeup_pending()) {
69326 diff -urNp linux-2.6.39/kernel/printk.c linux-2.6.39/kernel/printk.c
69327 --- linux-2.6.39/kernel/printk.c 2011-05-19 00:06:34.000000000 -0400
69328 +++ linux-2.6.39/kernel/printk.c 2011-05-22 19:41:42.000000000 -0400
69329 @@ -284,12 +284,17 @@ static int check_syslog_permissions(int
69330 if (from_file && type != SYSLOG_ACTION_OPEN)
69331 return 0;
69332
69333 +#ifdef CONFIG_GRKERNSEC_DMESG
69334 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
69335 + return -EPERM;
69336 +#endif
69337 +
69338 if (syslog_action_restricted(type)) {
69339 if (capable(CAP_SYSLOG))
69340 return 0;
69341 /* For historical reasons, accept CAP_SYS_ADMIN too, with a warning */
69342 if (capable(CAP_SYS_ADMIN)) {
69343 - WARN_ONCE(1, "Attempt to access syslog with CAP_SYS_ADMIN "
69344 + printk_once(KERN_WARNING "Attempt to access syslog with CAP_SYS_ADMIN "
69345 "but no CAP_SYSLOG (deprecated).\n");
69346 return 0;
69347 }
69348 diff -urNp linux-2.6.39/kernel/profile.c linux-2.6.39/kernel/profile.c
69349 --- linux-2.6.39/kernel/profile.c 2011-05-19 00:06:34.000000000 -0400
69350 +++ linux-2.6.39/kernel/profile.c 2011-05-22 19:36:33.000000000 -0400
69351 @@ -39,7 +39,7 @@ struct profile_hit {
69352 /* Oprofile timer tick hook */
69353 static int (*timer_hook)(struct pt_regs *) __read_mostly;
69354
69355 -static atomic_t *prof_buffer;
69356 +static atomic_unchecked_t *prof_buffer;
69357 static unsigned long prof_len, prof_shift;
69358
69359 int prof_on __read_mostly;
69360 @@ -283,7 +283,7 @@ static void profile_flip_buffers(void)
69361 hits[i].pc = 0;
69362 continue;
69363 }
69364 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69365 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69366 hits[i].hits = hits[i].pc = 0;
69367 }
69368 }
69369 @@ -346,9 +346,9 @@ void profile_hits(int type, void *__pc,
69370 * Add the current hit(s) and flush the write-queue out
69371 * to the global buffer:
69372 */
69373 - atomic_add(nr_hits, &prof_buffer[pc]);
69374 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
69375 for (i = 0; i < NR_PROFILE_HIT; ++i) {
69376 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69377 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69378 hits[i].pc = hits[i].hits = 0;
69379 }
69380 out:
69381 @@ -426,7 +426,7 @@ void profile_hits(int type, void *__pc,
69382 if (prof_on != type || !prof_buffer)
69383 return;
69384 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
69385 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69386 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69387 }
69388 #endif /* !CONFIG_SMP */
69389 EXPORT_SYMBOL_GPL(profile_hits);
69390 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __u
69391 return -EFAULT;
69392 buf++; p++; count--; read++;
69393 }
69394 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
69395 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
69396 if (copy_to_user(buf, (void *)pnt, count))
69397 return -EFAULT;
69398 read += count;
69399 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file
69400 }
69401 #endif
69402 profile_discard_flip_buffers();
69403 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
69404 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
69405 return count;
69406 }
69407
69408 diff -urNp linux-2.6.39/kernel/ptrace.c linux-2.6.39/kernel/ptrace.c
69409 --- linux-2.6.39/kernel/ptrace.c 2011-05-19 00:06:34.000000000 -0400
69410 +++ linux-2.6.39/kernel/ptrace.c 2011-05-23 17:07:00.000000000 -0400
69411 @@ -117,7 +117,8 @@ int ptrace_check_attach(struct task_stru
69412 return ret;
69413 }
69414
69415 -int __ptrace_may_access(struct task_struct *task, unsigned int mode)
69416 +static int __ptrace_may_access(struct task_struct *task, unsigned int mode,
69417 + unsigned int log)
69418 {
69419 const struct cred *cred = current_cred(), *tcred;
69420
69421 @@ -143,7 +144,8 @@ int __ptrace_may_access(struct task_stru
69422 cred->gid == tcred->sgid &&
69423 cred->gid == tcred->gid))
69424 goto ok;
69425 - if (ns_capable(tcred->user->user_ns, CAP_SYS_PTRACE))
69426 + if ((!log && ns_capable_nolog(tcred->user->user_ns, CAP_SYS_PTRACE)) ||
69427 + (log && ns_capable(tcred->user->user_ns, CAP_SYS_PTRACE)))
69428 goto ok;
69429 rcu_read_unlock();
69430 return -EPERM;
69431 @@ -152,7 +154,9 @@ ok:
69432 smp_rmb();
69433 if (task->mm)
69434 dumpable = get_dumpable(task->mm);
69435 - if (!dumpable && !task_ns_capable(task, CAP_SYS_PTRACE))
69436 + if (!dumpable &&
69437 + ((!log && !task_ns_capable_nolog(task, CAP_SYS_PTRACE)) ||
69438 + (log && !task_ns_capable(task, CAP_SYS_PTRACE))))
69439 return -EPERM;
69440
69441 return security_ptrace_access_check(task, mode);
69442 @@ -162,7 +166,16 @@ bool ptrace_may_access(struct task_struc
69443 {
69444 int err;
69445 task_lock(task);
69446 - err = __ptrace_may_access(task, mode);
69447 + err = __ptrace_may_access(task, mode, 0);
69448 + task_unlock(task);
69449 + return !err;
69450 +}
69451 +
69452 +bool ptrace_may_access_log(struct task_struct *task, unsigned int mode)
69453 +{
69454 + int err;
69455 + task_lock(task);
69456 + err = __ptrace_may_access(task, mode, 1);
69457 task_unlock(task);
69458 return !err;
69459 }
69460 @@ -189,7 +202,7 @@ static int ptrace_attach(struct task_str
69461 goto out;
69462
69463 task_lock(task);
69464 - retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH);
69465 + retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH, 1);
69466 task_unlock(task);
69467 if (retval)
69468 goto unlock_creds;
69469 @@ -202,7 +215,7 @@ static int ptrace_attach(struct task_str
69470 goto unlock_tasklist;
69471
69472 task->ptrace = PT_PTRACED;
69473 - if (task_ns_capable(task, CAP_SYS_PTRACE))
69474 + if (task_ns_capable_nolog(task, CAP_SYS_PTRACE))
69475 task->ptrace |= PT_PTRACE_CAP;
69476
69477 __ptrace_link(task, current);
69478 @@ -362,6 +375,8 @@ int ptrace_readdata(struct task_struct *
69479 {
69480 int copied = 0;
69481
69482 + pax_track_stack();
69483 +
69484 while (len > 0) {
69485 char buf[128];
69486 int this_len, retval;
69487 @@ -373,7 +388,7 @@ int ptrace_readdata(struct task_struct *
69488 break;
69489 return -EIO;
69490 }
69491 - if (copy_to_user(dst, buf, retval))
69492 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
69493 return -EFAULT;
69494 copied += retval;
69495 src += retval;
69496 @@ -387,6 +402,8 @@ int ptrace_writedata(struct task_struct
69497 {
69498 int copied = 0;
69499
69500 + pax_track_stack();
69501 +
69502 while (len > 0) {
69503 char buf[128];
69504 int this_len, retval;
69505 @@ -569,9 +586,11 @@ int ptrace_request(struct task_struct *c
69506 {
69507 int ret = -EIO;
69508 siginfo_t siginfo;
69509 - void __user *datavp = (void __user *) data;
69510 + void __user *datavp = (__force void __user *) data;
69511 unsigned long __user *datalp = datavp;
69512
69513 + pax_track_stack();
69514 +
69515 switch (request) {
69516 case PTRACE_PEEKTEXT:
69517 case PTRACE_PEEKDATA:
69518 @@ -717,14 +736,21 @@ SYSCALL_DEFINE4(ptrace, long, request, l
69519 goto out;
69520 }
69521
69522 + if (gr_handle_ptrace(child, request)) {
69523 + ret = -EPERM;
69524 + goto out_put_task_struct;
69525 + }
69526 +
69527 if (request == PTRACE_ATTACH) {
69528 ret = ptrace_attach(child);
69529 /*
69530 * Some architectures need to do book-keeping after
69531 * a ptrace attach.
69532 */
69533 - if (!ret)
69534 + if (!ret) {
69535 arch_ptrace_attach(child);
69536 + gr_audit_ptrace(child);
69537 + }
69538 goto out_put_task_struct;
69539 }
69540
69541 @@ -749,7 +775,7 @@ int generic_ptrace_peekdata(struct task_
69542 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
69543 if (copied != sizeof(tmp))
69544 return -EIO;
69545 - return put_user(tmp, (unsigned long __user *)data);
69546 + return put_user(tmp, (__force unsigned long __user *)data);
69547 }
69548
69549 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
69550 @@ -772,6 +798,8 @@ int compat_ptrace_request(struct task_st
69551 siginfo_t siginfo;
69552 int ret;
69553
69554 + pax_track_stack();
69555 +
69556 switch (request) {
69557 case PTRACE_PEEKTEXT:
69558 case PTRACE_PEEKDATA:
69559 @@ -859,14 +887,21 @@ asmlinkage long compat_sys_ptrace(compat
69560 goto out;
69561 }
69562
69563 + if (gr_handle_ptrace(child, request)) {
69564 + ret = -EPERM;
69565 + goto out_put_task_struct;
69566 + }
69567 +
69568 if (request == PTRACE_ATTACH) {
69569 ret = ptrace_attach(child);
69570 /*
69571 * Some architectures need to do book-keeping after
69572 * a ptrace attach.
69573 */
69574 - if (!ret)
69575 + if (!ret) {
69576 arch_ptrace_attach(child);
69577 + gr_audit_ptrace(child);
69578 + }
69579 goto out_put_task_struct;
69580 }
69581
69582 diff -urNp linux-2.6.39/kernel/rcutorture.c linux-2.6.39/kernel/rcutorture.c
69583 --- linux-2.6.39/kernel/rcutorture.c 2011-05-19 00:06:34.000000000 -0400
69584 +++ linux-2.6.39/kernel/rcutorture.c 2011-05-22 19:36:33.000000000 -0400
69585 @@ -138,12 +138,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_
69586 { 0 };
69587 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
69588 { 0 };
69589 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69590 -static atomic_t n_rcu_torture_alloc;
69591 -static atomic_t n_rcu_torture_alloc_fail;
69592 -static atomic_t n_rcu_torture_free;
69593 -static atomic_t n_rcu_torture_mberror;
69594 -static atomic_t n_rcu_torture_error;
69595 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69596 +static atomic_unchecked_t n_rcu_torture_alloc;
69597 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
69598 +static atomic_unchecked_t n_rcu_torture_free;
69599 +static atomic_unchecked_t n_rcu_torture_mberror;
69600 +static atomic_unchecked_t n_rcu_torture_error;
69601 static long n_rcu_torture_boost_ktrerror;
69602 static long n_rcu_torture_boost_rterror;
69603 static long n_rcu_torture_boost_allocerror;
69604 @@ -225,11 +225,11 @@ rcu_torture_alloc(void)
69605
69606 spin_lock_bh(&rcu_torture_lock);
69607 if (list_empty(&rcu_torture_freelist)) {
69608 - atomic_inc(&n_rcu_torture_alloc_fail);
69609 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
69610 spin_unlock_bh(&rcu_torture_lock);
69611 return NULL;
69612 }
69613 - atomic_inc(&n_rcu_torture_alloc);
69614 + atomic_inc_unchecked(&n_rcu_torture_alloc);
69615 p = rcu_torture_freelist.next;
69616 list_del_init(p);
69617 spin_unlock_bh(&rcu_torture_lock);
69618 @@ -242,7 +242,7 @@ rcu_torture_alloc(void)
69619 static void
69620 rcu_torture_free(struct rcu_torture *p)
69621 {
69622 - atomic_inc(&n_rcu_torture_free);
69623 + atomic_inc_unchecked(&n_rcu_torture_free);
69624 spin_lock_bh(&rcu_torture_lock);
69625 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
69626 spin_unlock_bh(&rcu_torture_lock);
69627 @@ -362,7 +362,7 @@ rcu_torture_cb(struct rcu_head *p)
69628 i = rp->rtort_pipe_count;
69629 if (i > RCU_TORTURE_PIPE_LEN)
69630 i = RCU_TORTURE_PIPE_LEN;
69631 - atomic_inc(&rcu_torture_wcount[i]);
69632 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69633 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
69634 rp->rtort_mbtest = 0;
69635 rcu_torture_free(rp);
69636 @@ -409,7 +409,7 @@ static void rcu_sync_torture_deferred_fr
69637 i = rp->rtort_pipe_count;
69638 if (i > RCU_TORTURE_PIPE_LEN)
69639 i = RCU_TORTURE_PIPE_LEN;
69640 - atomic_inc(&rcu_torture_wcount[i]);
69641 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69642 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
69643 rp->rtort_mbtest = 0;
69644 list_del(&rp->rtort_free);
69645 @@ -882,7 +882,7 @@ rcu_torture_writer(void *arg)
69646 i = old_rp->rtort_pipe_count;
69647 if (i > RCU_TORTURE_PIPE_LEN)
69648 i = RCU_TORTURE_PIPE_LEN;
69649 - atomic_inc(&rcu_torture_wcount[i]);
69650 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69651 old_rp->rtort_pipe_count++;
69652 cur_ops->deferred_free(old_rp);
69653 }
69654 @@ -951,7 +951,7 @@ static void rcu_torture_timer(unsigned l
69655 return;
69656 }
69657 if (p->rtort_mbtest == 0)
69658 - atomic_inc(&n_rcu_torture_mberror);
69659 + atomic_inc_unchecked(&n_rcu_torture_mberror);
69660 spin_lock(&rand_lock);
69661 cur_ops->read_delay(&rand);
69662 n_rcu_torture_timers++;
69663 @@ -1013,7 +1013,7 @@ rcu_torture_reader(void *arg)
69664 continue;
69665 }
69666 if (p->rtort_mbtest == 0)
69667 - atomic_inc(&n_rcu_torture_mberror);
69668 + atomic_inc_unchecked(&n_rcu_torture_mberror);
69669 cur_ops->read_delay(&rand);
69670 preempt_disable();
69671 pipe_count = p->rtort_pipe_count;
69672 @@ -1072,10 +1072,10 @@ rcu_torture_printk(char *page)
69673 rcu_torture_current,
69674 rcu_torture_current_version,
69675 list_empty(&rcu_torture_freelist),
69676 - atomic_read(&n_rcu_torture_alloc),
69677 - atomic_read(&n_rcu_torture_alloc_fail),
69678 - atomic_read(&n_rcu_torture_free),
69679 - atomic_read(&n_rcu_torture_mberror),
69680 + atomic_read_unchecked(&n_rcu_torture_alloc),
69681 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
69682 + atomic_read_unchecked(&n_rcu_torture_free),
69683 + atomic_read_unchecked(&n_rcu_torture_mberror),
69684 n_rcu_torture_boost_ktrerror,
69685 n_rcu_torture_boost_rterror,
69686 n_rcu_torture_boost_allocerror,
69687 @@ -1083,7 +1083,7 @@ rcu_torture_printk(char *page)
69688 n_rcu_torture_boost_failure,
69689 n_rcu_torture_boosts,
69690 n_rcu_torture_timers);
69691 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
69692 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
69693 n_rcu_torture_boost_ktrerror != 0 ||
69694 n_rcu_torture_boost_rterror != 0 ||
69695 n_rcu_torture_boost_allocerror != 0 ||
69696 @@ -1093,7 +1093,7 @@ rcu_torture_printk(char *page)
69697 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
69698 if (i > 1) {
69699 cnt += sprintf(&page[cnt], "!!! ");
69700 - atomic_inc(&n_rcu_torture_error);
69701 + atomic_inc_unchecked(&n_rcu_torture_error);
69702 WARN_ON_ONCE(1);
69703 }
69704 cnt += sprintf(&page[cnt], "Reader Pipe: ");
69705 @@ -1107,7 +1107,7 @@ rcu_torture_printk(char *page)
69706 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
69707 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
69708 cnt += sprintf(&page[cnt], " %d",
69709 - atomic_read(&rcu_torture_wcount[i]));
69710 + atomic_read_unchecked(&rcu_torture_wcount[i]));
69711 }
69712 cnt += sprintf(&page[cnt], "\n");
69713 if (cur_ops->stats)
69714 @@ -1415,7 +1415,7 @@ rcu_torture_cleanup(void)
69715
69716 if (cur_ops->cleanup)
69717 cur_ops->cleanup();
69718 - if (atomic_read(&n_rcu_torture_error))
69719 + if (atomic_read_unchecked(&n_rcu_torture_error))
69720 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
69721 else
69722 rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS");
69723 @@ -1479,11 +1479,11 @@ rcu_torture_init(void)
69724
69725 rcu_torture_current = NULL;
69726 rcu_torture_current_version = 0;
69727 - atomic_set(&n_rcu_torture_alloc, 0);
69728 - atomic_set(&n_rcu_torture_alloc_fail, 0);
69729 - atomic_set(&n_rcu_torture_free, 0);
69730 - atomic_set(&n_rcu_torture_mberror, 0);
69731 - atomic_set(&n_rcu_torture_error, 0);
69732 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
69733 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
69734 + atomic_set_unchecked(&n_rcu_torture_free, 0);
69735 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
69736 + atomic_set_unchecked(&n_rcu_torture_error, 0);
69737 n_rcu_torture_boost_ktrerror = 0;
69738 n_rcu_torture_boost_rterror = 0;
69739 n_rcu_torture_boost_allocerror = 0;
69740 @@ -1491,7 +1491,7 @@ rcu_torture_init(void)
69741 n_rcu_torture_boost_failure = 0;
69742 n_rcu_torture_boosts = 0;
69743 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
69744 - atomic_set(&rcu_torture_wcount[i], 0);
69745 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
69746 for_each_possible_cpu(cpu) {
69747 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
69748 per_cpu(rcu_torture_count, cpu)[i] = 0;
69749 diff -urNp linux-2.6.39/kernel/rcutree.c linux-2.6.39/kernel/rcutree.c
69750 --- linux-2.6.39/kernel/rcutree.c 2011-05-19 00:06:34.000000000 -0400
69751 +++ linux-2.6.39/kernel/rcutree.c 2011-05-22 19:36:33.000000000 -0400
69752 @@ -1389,7 +1389,7 @@ __rcu_process_callbacks(struct rcu_state
69753 /*
69754 * Do softirq processing for the current CPU.
69755 */
69756 -static void rcu_process_callbacks(struct softirq_action *unused)
69757 +static void rcu_process_callbacks(void)
69758 {
69759 /*
69760 * Memory references from any prior RCU read-side critical sections
69761 diff -urNp linux-2.6.39/kernel/rcutree_plugin.h linux-2.6.39/kernel/rcutree_plugin.h
69762 --- linux-2.6.39/kernel/rcutree_plugin.h 2011-05-19 00:06:34.000000000 -0400
69763 +++ linux-2.6.39/kernel/rcutree_plugin.h 2011-05-22 19:36:33.000000000 -0400
69764 @@ -730,7 +730,7 @@ void synchronize_rcu_expedited(void)
69765
69766 /* Clean up and exit. */
69767 smp_mb(); /* ensure expedited GP seen before counter increment. */
69768 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
69769 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
69770 unlock_mb_ret:
69771 mutex_unlock(&sync_rcu_preempt_exp_mutex);
69772 mb_ret:
69773 @@ -1025,8 +1025,8 @@ EXPORT_SYMBOL_GPL(synchronize_sched_expe
69774
69775 #else /* #ifndef CONFIG_SMP */
69776
69777 -static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
69778 -static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
69779 +static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
69780 +static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
69781
69782 static int synchronize_sched_expedited_cpu_stop(void *data)
69783 {
69784 @@ -1081,7 +1081,7 @@ void synchronize_sched_expedited(void)
69785 int firstsnap, s, snap, trycount = 0;
69786
69787 /* Note that atomic_inc_return() implies full memory barrier. */
69788 - firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
69789 + firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
69790 get_online_cpus();
69791
69792 /*
69793 @@ -1102,7 +1102,7 @@ void synchronize_sched_expedited(void)
69794 }
69795
69796 /* Check to see if someone else did our work for us. */
69797 - s = atomic_read(&sync_sched_expedited_done);
69798 + s = atomic_read_unchecked(&sync_sched_expedited_done);
69799 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
69800 smp_mb(); /* ensure test happens before caller kfree */
69801 return;
69802 @@ -1117,7 +1117,7 @@ void synchronize_sched_expedited(void)
69803 * grace period works for us.
69804 */
69805 get_online_cpus();
69806 - snap = atomic_read(&sync_sched_expedited_started) - 1;
69807 + snap = atomic_read_unchecked(&sync_sched_expedited_started) - 1;
69808 smp_mb(); /* ensure read is before try_stop_cpus(). */
69809 }
69810
69811 @@ -1128,12 +1128,12 @@ void synchronize_sched_expedited(void)
69812 * than we did beat us to the punch.
69813 */
69814 do {
69815 - s = atomic_read(&sync_sched_expedited_done);
69816 + s = atomic_read_unchecked(&sync_sched_expedited_done);
69817 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
69818 smp_mb(); /* ensure test happens before caller kfree */
69819 break;
69820 }
69821 - } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
69822 + } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
69823
69824 put_online_cpus();
69825 }
69826 diff -urNp linux-2.6.39/kernel/relay.c linux-2.6.39/kernel/relay.c
69827 --- linux-2.6.39/kernel/relay.c 2011-05-19 00:06:34.000000000 -0400
69828 +++ linux-2.6.39/kernel/relay.c 2011-05-22 19:36:33.000000000 -0400
69829 @@ -1236,6 +1236,8 @@ static ssize_t subbuf_splice_actor(struc
69830 };
69831 ssize_t ret;
69832
69833 + pax_track_stack();
69834 +
69835 if (rbuf->subbufs_produced == rbuf->subbufs_consumed)
69836 return 0;
69837 if (splice_grow_spd(pipe, &spd))
69838 diff -urNp linux-2.6.39/kernel/resource.c linux-2.6.39/kernel/resource.c
69839 --- linux-2.6.39/kernel/resource.c 2011-05-19 00:06:34.000000000 -0400
69840 +++ linux-2.6.39/kernel/resource.c 2011-05-22 19:41:42.000000000 -0400
69841 @@ -133,8 +133,18 @@ static const struct file_operations proc
69842
69843 static int __init ioresources_init(void)
69844 {
69845 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
69846 +#ifdef CONFIG_GRKERNSEC_PROC_USER
69847 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
69848 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
69849 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69850 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
69851 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
69852 +#endif
69853 +#else
69854 proc_create("ioports", 0, NULL, &proc_ioports_operations);
69855 proc_create("iomem", 0, NULL, &proc_iomem_operations);
69856 +#endif
69857 return 0;
69858 }
69859 __initcall(ioresources_init);
69860 diff -urNp linux-2.6.39/kernel/rtmutex-tester.c linux-2.6.39/kernel/rtmutex-tester.c
69861 --- linux-2.6.39/kernel/rtmutex-tester.c 2011-05-19 00:06:34.000000000 -0400
69862 +++ linux-2.6.39/kernel/rtmutex-tester.c 2011-05-22 19:36:33.000000000 -0400
69863 @@ -20,7 +20,7 @@
69864 #define MAX_RT_TEST_MUTEXES 8
69865
69866 static spinlock_t rttest_lock;
69867 -static atomic_t rttest_event;
69868 +static atomic_unchecked_t rttest_event;
69869
69870 struct test_thread_data {
69871 int opcode;
69872 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_
69873
69874 case RTTEST_LOCKCONT:
69875 td->mutexes[td->opdata] = 1;
69876 - td->event = atomic_add_return(1, &rttest_event);
69877 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69878 return 0;
69879
69880 case RTTEST_RESET:
69881 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_
69882 return 0;
69883
69884 case RTTEST_RESETEVENT:
69885 - atomic_set(&rttest_event, 0);
69886 + atomic_set_unchecked(&rttest_event, 0);
69887 return 0;
69888
69889 default:
69890 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_
69891 return ret;
69892
69893 td->mutexes[id] = 1;
69894 - td->event = atomic_add_return(1, &rttest_event);
69895 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69896 rt_mutex_lock(&mutexes[id]);
69897 - td->event = atomic_add_return(1, &rttest_event);
69898 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69899 td->mutexes[id] = 4;
69900 return 0;
69901
69902 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_
69903 return ret;
69904
69905 td->mutexes[id] = 1;
69906 - td->event = atomic_add_return(1, &rttest_event);
69907 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69908 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
69909 - td->event = atomic_add_return(1, &rttest_event);
69910 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69911 td->mutexes[id] = ret ? 0 : 4;
69912 return ret ? -EINTR : 0;
69913
69914 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_
69915 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
69916 return ret;
69917
69918 - td->event = atomic_add_return(1, &rttest_event);
69919 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69920 rt_mutex_unlock(&mutexes[id]);
69921 - td->event = atomic_add_return(1, &rttest_event);
69922 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69923 td->mutexes[id] = 0;
69924 return 0;
69925
69926 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mu
69927 break;
69928
69929 td->mutexes[dat] = 2;
69930 - td->event = atomic_add_return(1, &rttest_event);
69931 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69932 break;
69933
69934 default:
69935 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mu
69936 return;
69937
69938 td->mutexes[dat] = 3;
69939 - td->event = atomic_add_return(1, &rttest_event);
69940 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69941 break;
69942
69943 case RTTEST_LOCKNOWAIT:
69944 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mu
69945 return;
69946
69947 td->mutexes[dat] = 1;
69948 - td->event = atomic_add_return(1, &rttest_event);
69949 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69950 return;
69951
69952 default:
69953 diff -urNp linux-2.6.39/kernel/sched_autogroup.c linux-2.6.39/kernel/sched_autogroup.c
69954 --- linux-2.6.39/kernel/sched_autogroup.c 2011-05-19 00:06:34.000000000 -0400
69955 +++ linux-2.6.39/kernel/sched_autogroup.c 2011-05-22 19:36:33.000000000 -0400
69956 @@ -7,7 +7,7 @@
69957
69958 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
69959 static struct autogroup autogroup_default;
69960 -static atomic_t autogroup_seq_nr;
69961 +static atomic_unchecked_t autogroup_seq_nr;
69962
69963 static void __init autogroup_init(struct task_struct *init_task)
69964 {
69965 @@ -78,7 +78,7 @@ static inline struct autogroup *autogrou
69966
69967 kref_init(&ag->kref);
69968 init_rwsem(&ag->lock);
69969 - ag->id = atomic_inc_return(&autogroup_seq_nr);
69970 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
69971 ag->tg = tg;
69972 #ifdef CONFIG_RT_GROUP_SCHED
69973 /*
69974 diff -urNp linux-2.6.39/kernel/sched.c linux-2.6.39/kernel/sched.c
69975 --- linux-2.6.39/kernel/sched.c 2011-05-19 00:06:34.000000000 -0400
69976 +++ linux-2.6.39/kernel/sched.c 2011-05-23 17:07:00.000000000 -0400
69977 @@ -4078,6 +4078,8 @@ asmlinkage void __sched schedule(void)
69978 struct rq *rq;
69979 int cpu;
69980
69981 + pax_track_stack();
69982 +
69983 need_resched:
69984 preempt_disable();
69985 cpu = smp_processor_id();
69986 @@ -4165,7 +4167,7 @@ EXPORT_SYMBOL(schedule);
69987 * Look out! "owner" is an entirely speculative pointer
69988 * access and not reliable.
69989 */
69990 -int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner)
69991 +int mutex_spin_on_owner(struct mutex *lock, struct task_struct *owner)
69992 {
69993 unsigned int cpu;
69994 struct rq *rq;
69995 @@ -4179,10 +4181,10 @@ int mutex_spin_on_owner(struct mutex *lo
69996 * DEBUG_PAGEALLOC could have unmapped it if
69997 * the mutex owner just released it and exited.
69998 */
69999 - if (probe_kernel_address(&owner->cpu, cpu))
70000 + if (probe_kernel_address(&task_thread_info(owner)->cpu, cpu))
70001 return 0;
70002 #else
70003 - cpu = owner->cpu;
70004 + cpu = task_thread_info(owner)->cpu;
70005 #endif
70006
70007 /*
70008 @@ -4219,7 +4221,7 @@ int mutex_spin_on_owner(struct mutex *lo
70009 /*
70010 * Is that owner really running on that cpu?
70011 */
70012 - if (task_thread_info(rq->curr) != owner || need_resched())
70013 + if (rq->curr != owner || need_resched())
70014 return 0;
70015
70016 arch_mutex_cpu_relax();
70017 @@ -4778,6 +4780,8 @@ int can_nice(const struct task_struct *p
70018 /* convert nice value [19,-20] to rlimit style value [1,40] */
70019 int nice_rlim = 20 - nice;
70020
70021 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
70022 +
70023 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
70024 capable(CAP_SYS_NICE));
70025 }
70026 @@ -4811,7 +4815,8 @@ SYSCALL_DEFINE1(nice, int, increment)
70027 if (nice > 19)
70028 nice = 19;
70029
70030 - if (increment < 0 && !can_nice(current, nice))
70031 + if (increment < 0 && (!can_nice(current, nice) ||
70032 + gr_handle_chroot_nice()))
70033 return -EPERM;
70034
70035 retval = security_task_setnice(current, nice);
70036 @@ -4957,6 +4962,7 @@ recheck:
70037 unsigned long rlim_rtprio =
70038 task_rlimit(p, RLIMIT_RTPRIO);
70039
70040 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
70041 /* can't set/change the rt policy */
70042 if (policy != p->policy && !rlim_rtprio)
70043 return -EPERM;
70044 @@ -7164,7 +7170,7 @@ static void init_sched_groups_power(int
70045 long power;
70046 int weight;
70047
70048 - WARN_ON(!sd || !sd->groups);
70049 + BUG_ON(!sd || !sd->groups);
70050
70051 if (cpu != group_first_cpu(sd->groups))
70052 return;
70053 diff -urNp linux-2.6.39/kernel/sched_fair.c linux-2.6.39/kernel/sched_fair.c
70054 --- linux-2.6.39/kernel/sched_fair.c 2011-05-19 00:06:34.000000000 -0400
70055 +++ linux-2.6.39/kernel/sched_fair.c 2011-05-22 19:36:33.000000000 -0400
70056 @@ -3999,7 +3999,7 @@ static void nohz_idle_balance(int this_c
70057 * run_rebalance_domains is triggered when needed from the scheduler tick.
70058 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
70059 */
70060 -static void run_rebalance_domains(struct softirq_action *h)
70061 +static void run_rebalance_domains(void)
70062 {
70063 int this_cpu = smp_processor_id();
70064 struct rq *this_rq = cpu_rq(this_cpu);
70065 diff -urNp linux-2.6.39/kernel/signal.c linux-2.6.39/kernel/signal.c
70066 --- linux-2.6.39/kernel/signal.c 2011-05-19 00:06:34.000000000 -0400
70067 +++ linux-2.6.39/kernel/signal.c 2011-05-23 17:07:00.000000000 -0400
70068 @@ -45,12 +45,12 @@ static struct kmem_cache *sigqueue_cache
70069
70070 int print_fatal_signals __read_mostly;
70071
70072 -static void __user *sig_handler(struct task_struct *t, int sig)
70073 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
70074 {
70075 return t->sighand->action[sig - 1].sa.sa_handler;
70076 }
70077
70078 -static int sig_handler_ignored(void __user *handler, int sig)
70079 +static int sig_handler_ignored(__sighandler_t handler, int sig)
70080 {
70081 /* Is it explicitly or implicitly ignored? */
70082 return handler == SIG_IGN ||
70083 @@ -60,7 +60,7 @@ static int sig_handler_ignored(void __us
70084 static int sig_task_ignored(struct task_struct *t, int sig,
70085 int from_ancestor_ns)
70086 {
70087 - void __user *handler;
70088 + __sighandler_t handler;
70089
70090 handler = sig_handler(t, sig);
70091
70092 @@ -243,6 +243,9 @@ __sigqueue_alloc(int sig, struct task_st
70093 atomic_inc(&user->sigpending);
70094 rcu_read_unlock();
70095
70096 + if (!override_rlimit)
70097 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
70098 +
70099 if (override_rlimit ||
70100 atomic_read(&user->sigpending) <=
70101 task_rlimit(t, RLIMIT_SIGPENDING)) {
70102 @@ -367,7 +370,7 @@ flush_signal_handlers(struct task_struct
70103
70104 int unhandled_signal(struct task_struct *tsk, int sig)
70105 {
70106 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
70107 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
70108 if (is_global_init(tsk))
70109 return 1;
70110 if (handler != SIG_IGN && handler != SIG_DFL)
70111 @@ -693,6 +696,9 @@ static int check_kill_permission(int sig
70112 }
70113 }
70114
70115 + if (gr_handle_signal(t, sig))
70116 + return -EPERM;
70117 +
70118 return security_task_kill(t, info, sig, 0);
70119 }
70120
70121 @@ -1041,7 +1047,7 @@ __group_send_sig_info(int sig, struct si
70122 return send_signal(sig, info, p, 1);
70123 }
70124
70125 -static int
70126 +int
70127 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70128 {
70129 return send_signal(sig, info, t, 0);
70130 @@ -1078,6 +1084,7 @@ force_sig_info(int sig, struct siginfo *
70131 unsigned long int flags;
70132 int ret, blocked, ignored;
70133 struct k_sigaction *action;
70134 + int is_unhandled = 0;
70135
70136 spin_lock_irqsave(&t->sighand->siglock, flags);
70137 action = &t->sighand->action[sig-1];
70138 @@ -1092,9 +1099,18 @@ force_sig_info(int sig, struct siginfo *
70139 }
70140 if (action->sa.sa_handler == SIG_DFL)
70141 t->signal->flags &= ~SIGNAL_UNKILLABLE;
70142 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
70143 + is_unhandled = 1;
70144 ret = specific_send_sig_info(sig, info, t);
70145 spin_unlock_irqrestore(&t->sighand->siglock, flags);
70146
70147 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
70148 + normal operation */
70149 + if (is_unhandled) {
70150 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
70151 + gr_handle_crash(t, sig);
70152 + }
70153 +
70154 return ret;
70155 }
70156
70157 @@ -1153,8 +1169,11 @@ int group_send_sig_info(int sig, struct
70158 ret = check_kill_permission(sig, info, p);
70159 rcu_read_unlock();
70160
70161 - if (!ret && sig)
70162 + if (!ret && sig) {
70163 ret = do_send_sig_info(sig, info, p, true);
70164 + if (!ret)
70165 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
70166 + }
70167
70168 return ret;
70169 }
70170 @@ -1718,6 +1737,8 @@ void ptrace_notify(int exit_code)
70171 {
70172 siginfo_t info;
70173
70174 + pax_track_stack();
70175 +
70176 BUG_ON((exit_code & (0x7f | ~0xffff)) != SIGTRAP);
70177
70178 memset(&info, 0, sizeof info);
70179 diff -urNp linux-2.6.39/kernel/smp.c linux-2.6.39/kernel/smp.c
70180 --- linux-2.6.39/kernel/smp.c 2011-05-19 00:06:34.000000000 -0400
70181 +++ linux-2.6.39/kernel/smp.c 2011-05-22 19:36:33.000000000 -0400
70182 @@ -583,22 +583,22 @@ int smp_call_function(smp_call_func_t fu
70183 }
70184 EXPORT_SYMBOL(smp_call_function);
70185
70186 -void ipi_call_lock(void)
70187 +void ipi_call_lock(void) __acquires(call_function.lock)
70188 {
70189 raw_spin_lock(&call_function.lock);
70190 }
70191
70192 -void ipi_call_unlock(void)
70193 +void ipi_call_unlock(void) __releases(call_function.lock)
70194 {
70195 raw_spin_unlock(&call_function.lock);
70196 }
70197
70198 -void ipi_call_lock_irq(void)
70199 +void ipi_call_lock_irq(void) __acquires(call_function.lock)
70200 {
70201 raw_spin_lock_irq(&call_function.lock);
70202 }
70203
70204 -void ipi_call_unlock_irq(void)
70205 +void ipi_call_unlock_irq(void) __releases(call_function.lock)
70206 {
70207 raw_spin_unlock_irq(&call_function.lock);
70208 }
70209 diff -urNp linux-2.6.39/kernel/softirq.c linux-2.6.39/kernel/softirq.c
70210 --- linux-2.6.39/kernel/softirq.c 2011-05-19 00:06:34.000000000 -0400
70211 +++ linux-2.6.39/kernel/softirq.c 2011-05-22 19:36:33.000000000 -0400
70212 @@ -56,7 +56,7 @@ static struct softirq_action softirq_vec
70213
70214 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
70215
70216 -char *softirq_to_name[NR_SOFTIRQS] = {
70217 +const char * const softirq_to_name[NR_SOFTIRQS] = {
70218 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
70219 "TASKLET", "SCHED", "HRTIMER", "RCU"
70220 };
70221 @@ -206,7 +206,7 @@ EXPORT_SYMBOL(local_bh_enable_ip);
70222
70223 asmlinkage void __do_softirq(void)
70224 {
70225 - struct softirq_action *h;
70226 + const struct softirq_action *h;
70227 __u32 pending;
70228 int max_restart = MAX_SOFTIRQ_RESTART;
70229 int cpu;
70230 @@ -235,7 +235,7 @@ restart:
70231 kstat_incr_softirqs_this_cpu(vec_nr);
70232
70233 trace_softirq_entry(vec_nr);
70234 - h->action(h);
70235 + h->action();
70236 trace_softirq_exit(vec_nr);
70237 if (unlikely(prev_count != preempt_count())) {
70238 printk(KERN_ERR "huh, entered softirq %u %s %p"
70239 @@ -377,7 +377,7 @@ void raise_softirq(unsigned int nr)
70240 local_irq_restore(flags);
70241 }
70242
70243 -void open_softirq(int nr, void (*action)(struct softirq_action *))
70244 +void open_softirq(int nr, void (*action)(void))
70245 {
70246 softirq_vec[nr].action = action;
70247 }
70248 @@ -433,7 +433,7 @@ void __tasklet_hi_schedule_first(struct
70249
70250 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
70251
70252 -static void tasklet_action(struct softirq_action *a)
70253 +static void tasklet_action(void)
70254 {
70255 struct tasklet_struct *list;
70256
70257 @@ -468,7 +468,7 @@ static void tasklet_action(struct softir
70258 }
70259 }
70260
70261 -static void tasklet_hi_action(struct softirq_action *a)
70262 +static void tasklet_hi_action(void)
70263 {
70264 struct tasklet_struct *list;
70265
70266 diff -urNp linux-2.6.39/kernel/sys.c linux-2.6.39/kernel/sys.c
70267 --- linux-2.6.39/kernel/sys.c 2011-05-19 00:06:34.000000000 -0400
70268 +++ linux-2.6.39/kernel/sys.c 2011-05-22 21:08:10.000000000 -0400
70269 @@ -154,6 +154,12 @@ static int set_one_prio(struct task_stru
70270 error = -EACCES;
70271 goto out;
70272 }
70273 +
70274 + if (gr_handle_chroot_setpriority(p, niceval)) {
70275 + error = -EACCES;
70276 + goto out;
70277 + }
70278 +
70279 no_nice = security_task_setnice(p, niceval);
70280 if (no_nice) {
70281 error = no_nice;
70282 @@ -538,6 +544,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, g
70283 goto error;
70284 }
70285
70286 + if (gr_check_group_change(new->gid, new->egid, -1))
70287 + goto error;
70288 +
70289 if (rgid != (gid_t) -1 ||
70290 (egid != (gid_t) -1 && egid != old->gid))
70291 new->sgid = new->egid;
70292 @@ -567,6 +576,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
70293 old = current_cred();
70294
70295 retval = -EPERM;
70296 +
70297 + if (gr_check_group_change(gid, gid, gid))
70298 + goto error;
70299 +
70300 if (nsown_capable(CAP_SETGID))
70301 new->gid = new->egid = new->sgid = new->fsgid = gid;
70302 else if (gid == old->gid || gid == old->sgid)
70303 @@ -647,6 +660,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, u
70304 goto error;
70305 }
70306
70307 + if (gr_check_user_change(new->uid, new->euid, -1))
70308 + goto error;
70309 +
70310 if (new->uid != old->uid) {
70311 retval = set_user(new);
70312 if (retval < 0)
70313 @@ -691,6 +707,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
70314 old = current_cred();
70315
70316 retval = -EPERM;
70317 +
70318 + if (gr_check_crash_uid(uid))
70319 + goto error;
70320 + if (gr_check_user_change(uid, uid, uid))
70321 + goto error;
70322 +
70323 if (nsown_capable(CAP_SETUID)) {
70324 new->suid = new->uid = uid;
70325 if (uid != old->uid) {
70326 @@ -745,6 +767,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid,
70327 goto error;
70328 }
70329
70330 + if (gr_check_user_change(ruid, euid, -1))
70331 + goto error;
70332 +
70333 if (ruid != (uid_t) -1) {
70334 new->uid = ruid;
70335 if (ruid != old->uid) {
70336 @@ -809,6 +834,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid,
70337 goto error;
70338 }
70339
70340 + if (gr_check_group_change(rgid, egid, -1))
70341 + goto error;
70342 +
70343 if (rgid != (gid_t) -1)
70344 new->gid = rgid;
70345 if (egid != (gid_t) -1)
70346 @@ -855,6 +883,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70347 old = current_cred();
70348 old_fsuid = old->fsuid;
70349
70350 + if (gr_check_user_change(-1, -1, uid))
70351 + goto error;
70352 +
70353 if (uid == old->uid || uid == old->euid ||
70354 uid == old->suid || uid == old->fsuid ||
70355 nsown_capable(CAP_SETUID)) {
70356 @@ -865,6 +896,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70357 }
70358 }
70359
70360 +error:
70361 abort_creds(new);
70362 return old_fsuid;
70363
70364 @@ -891,12 +923,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
70365 if (gid == old->gid || gid == old->egid ||
70366 gid == old->sgid || gid == old->fsgid ||
70367 nsown_capable(CAP_SETGID)) {
70368 + if (gr_check_group_change(-1, -1, gid))
70369 + goto error;
70370 +
70371 if (gid != old_fsgid) {
70372 new->fsgid = gid;
70373 goto change_okay;
70374 }
70375 }
70376
70377 +error:
70378 abort_creds(new);
70379 return old_fsgid;
70380
70381 @@ -1643,7 +1679,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsi
70382 error = get_dumpable(me->mm);
70383 break;
70384 case PR_SET_DUMPABLE:
70385 - if (arg2 < 0 || arg2 > 1) {
70386 + if (arg2 > 1) {
70387 error = -EINVAL;
70388 break;
70389 }
70390 diff -urNp linux-2.6.39/kernel/sysctl.c linux-2.6.39/kernel/sysctl.c
70391 --- linux-2.6.39/kernel/sysctl.c 2011-05-19 00:06:34.000000000 -0400
70392 +++ linux-2.6.39/kernel/sysctl.c 2011-05-22 20:23:10.000000000 -0400
70393 @@ -84,6 +84,13 @@
70394
70395
70396 #if defined(CONFIG_SYSCTL)
70397 +#include <linux/grsecurity.h>
70398 +#include <linux/grinternal.h>
70399 +
70400 +extern __u32 gr_handle_sysctl(const ctl_table *table, const int op);
70401 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
70402 + const int op);
70403 +extern int gr_handle_chroot_sysctl(const int op);
70404
70405 /* External variables not in a header file. */
70406 extern int sysctl_overcommit_memory;
70407 @@ -196,6 +203,7 @@ static int sysrq_sysctl_handler(ctl_tabl
70408 }
70409
70410 #endif
70411 +extern struct ctl_table grsecurity_table[];
70412
70413 static struct ctl_table root_table[];
70414 static struct ctl_table_root sysctl_table_root;
70415 @@ -225,6 +233,20 @@ extern struct ctl_table epoll_table[];
70416 int sysctl_legacy_va_layout;
70417 #endif
70418
70419 +#ifdef CONFIG_PAX_SOFTMODE
70420 +static ctl_table pax_table[] = {
70421 + {
70422 + .procname = "softmode",
70423 + .data = &pax_softmode,
70424 + .maxlen = sizeof(unsigned int),
70425 + .mode = 0600,
70426 + .proc_handler = &proc_dointvec,
70427 + },
70428 +
70429 + { }
70430 +};
70431 +#endif
70432 +
70433 /* The default sysctl tables: */
70434
70435 static struct ctl_table root_table[] = {
70436 @@ -271,6 +293,22 @@ static int max_extfrag_threshold = 1000;
70437 #endif
70438
70439 static struct ctl_table kern_table[] = {
70440 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
70441 + {
70442 + .procname = "grsecurity",
70443 + .mode = 0500,
70444 + .child = grsecurity_table,
70445 + },
70446 +#endif
70447 +
70448 +#ifdef CONFIG_PAX_SOFTMODE
70449 + {
70450 + .procname = "pax",
70451 + .mode = 0500,
70452 + .child = pax_table,
70453 + },
70454 +#endif
70455 +
70456 {
70457 .procname = "sched_child_runs_first",
70458 .data = &sysctl_sched_child_runs_first,
70459 @@ -545,7 +583,7 @@ static struct ctl_table kern_table[] = {
70460 .data = &modprobe_path,
70461 .maxlen = KMOD_PATH_LEN,
70462 .mode = 0644,
70463 - .proc_handler = proc_dostring,
70464 + .proc_handler = proc_dostring_modpriv,
70465 },
70466 {
70467 .procname = "modules_disabled",
70468 @@ -707,16 +745,20 @@ static struct ctl_table kern_table[] = {
70469 .extra1 = &zero,
70470 .extra2 = &one,
70471 },
70472 +#endif
70473 {
70474 .procname = "kptr_restrict",
70475 .data = &kptr_restrict,
70476 .maxlen = sizeof(int),
70477 .mode = 0644,
70478 .proc_handler = proc_dmesg_restrict,
70479 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70480 + .extra1 = &two,
70481 +#else
70482 .extra1 = &zero,
70483 +#endif
70484 .extra2 = &two,
70485 },
70486 -#endif
70487 {
70488 .procname = "ngroups_max",
70489 .data = &ngroups_max,
70490 @@ -1189,6 +1231,13 @@ static struct ctl_table vm_table[] = {
70491 .proc_handler = proc_dointvec_minmax,
70492 .extra1 = &zero,
70493 },
70494 + {
70495 + .procname = "heap_stack_gap",
70496 + .data = &sysctl_heap_stack_gap,
70497 + .maxlen = sizeof(sysctl_heap_stack_gap),
70498 + .mode = 0644,
70499 + .proc_handler = proc_doulongvec_minmax,
70500 + },
70501 #else
70502 {
70503 .procname = "nr_trim_pages",
70504 @@ -1698,6 +1747,17 @@ static int test_perm(int mode, int op)
70505 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
70506 {
70507 int mode;
70508 + int error;
70509 +
70510 + if (table->parent != NULL && table->parent->procname != NULL &&
70511 + table->procname != NULL &&
70512 + gr_handle_sysctl_mod(table->parent->procname, table->procname, op))
70513 + return -EACCES;
70514 + if (gr_handle_chroot_sysctl(op))
70515 + return -EACCES;
70516 + error = gr_handle_sysctl(table, op);
70517 + if (error)
70518 + return error;
70519
70520 if (root->permissions)
70521 mode = root->permissions(root, current->nsproxy, table);
70522 @@ -2102,6 +2162,16 @@ int proc_dostring(struct ctl_table *tabl
70523 buffer, lenp, ppos);
70524 }
70525
70526 +int proc_dostring_modpriv(struct ctl_table *table, int write,
70527 + void __user *buffer, size_t *lenp, loff_t *ppos)
70528 +{
70529 + if (write && !capable(CAP_SYS_MODULE))
70530 + return -EPERM;
70531 +
70532 + return _proc_do_string(table->data, table->maxlen, write,
70533 + buffer, lenp, ppos);
70534 +}
70535 +
70536 static size_t proc_skip_spaces(char **buf)
70537 {
70538 size_t ret;
70539 @@ -2207,6 +2277,8 @@ static int proc_put_long(void __user **b
70540 len = strlen(tmp);
70541 if (len > *size)
70542 len = *size;
70543 + if (len > sizeof(tmp))
70544 + len = sizeof(tmp);
70545 if (copy_to_user(*buf, tmp, len))
70546 return -EFAULT;
70547 *size -= len;
70548 @@ -2523,8 +2595,11 @@ static int __do_proc_doulongvec_minmax(v
70549 *i = val;
70550 } else {
70551 val = convdiv * (*i) / convmul;
70552 - if (!first)
70553 + if (!first) {
70554 err = proc_put_char(&buffer, &left, '\t');
70555 + if (err)
70556 + break;
70557 + }
70558 err = proc_put_long(&buffer, &left, val, false);
70559 if (err)
70560 break;
70561 @@ -2919,6 +2994,12 @@ int proc_dostring(struct ctl_table *tabl
70562 return -ENOSYS;
70563 }
70564
70565 +int proc_dostring_modpriv(struct ctl_table *table, int write,
70566 + void __user *buffer, size_t *lenp, loff_t *ppos)
70567 +{
70568 + return -ENOSYS;
70569 +}
70570 +
70571 int proc_dointvec(struct ctl_table *table, int write,
70572 void __user *buffer, size_t *lenp, loff_t *ppos)
70573 {
70574 @@ -2975,6 +3056,7 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
70575 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
70576 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
70577 EXPORT_SYMBOL(proc_dostring);
70578 +EXPORT_SYMBOL(proc_dostring_modpriv);
70579 EXPORT_SYMBOL(proc_doulongvec_minmax);
70580 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
70581 EXPORT_SYMBOL(register_sysctl_table);
70582 diff -urNp linux-2.6.39/kernel/sysctl_check.c linux-2.6.39/kernel/sysctl_check.c
70583 --- linux-2.6.39/kernel/sysctl_check.c 2011-05-19 00:06:34.000000000 -0400
70584 +++ linux-2.6.39/kernel/sysctl_check.c 2011-05-22 19:41:42.000000000 -0400
70585 @@ -129,6 +129,7 @@ int sysctl_check_table(struct nsproxy *n
70586 set_fail(&fail, table, "Directory with extra2");
70587 } else {
70588 if ((table->proc_handler == proc_dostring) ||
70589 + (table->proc_handler == proc_dostring_modpriv) ||
70590 (table->proc_handler == proc_dointvec) ||
70591 (table->proc_handler == proc_dointvec_minmax) ||
70592 (table->proc_handler == proc_dointvec_jiffies) ||
70593 diff -urNp linux-2.6.39/kernel/taskstats.c linux-2.6.39/kernel/taskstats.c
70594 --- linux-2.6.39/kernel/taskstats.c 2011-05-19 00:06:34.000000000 -0400
70595 +++ linux-2.6.39/kernel/taskstats.c 2011-05-22 19:41:42.000000000 -0400
70596 @@ -27,9 +27,12 @@
70597 #include <linux/cgroup.h>
70598 #include <linux/fs.h>
70599 #include <linux/file.h>
70600 +#include <linux/grsecurity.h>
70601 #include <net/genetlink.h>
70602 #include <asm/atomic.h>
70603
70604 +extern int gr_is_taskstats_denied(int pid);
70605 +
70606 /*
70607 * Maximum length of a cpumask that can be specified in
70608 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
70609 @@ -549,6 +552,9 @@ err:
70610
70611 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
70612 {
70613 + if (gr_is_taskstats_denied(current->pid))
70614 + return -EACCES;
70615 +
70616 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
70617 return cmd_attr_register_cpumask(info);
70618 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
70619 diff -urNp linux-2.6.39/kernel/time/posix-clock.c linux-2.6.39/kernel/time/posix-clock.c
70620 --- linux-2.6.39/kernel/time/posix-clock.c 2011-05-19 00:06:34.000000000 -0400
70621 +++ linux-2.6.39/kernel/time/posix-clock.c 2011-05-22 19:36:33.000000000 -0400
70622 @@ -433,7 +433,7 @@ static int pc_timer_settime(struct k_iti
70623 return err;
70624 }
70625
70626 -struct k_clock clock_posix_dynamic = {
70627 +const struct k_clock clock_posix_dynamic = {
70628 .clock_getres = pc_clock_getres,
70629 .clock_set = pc_clock_settime,
70630 .clock_get = pc_clock_gettime,
70631 diff -urNp linux-2.6.39/kernel/time/tick-broadcast.c linux-2.6.39/kernel/time/tick-broadcast.c
70632 --- linux-2.6.39/kernel/time/tick-broadcast.c 2011-05-19 00:06:34.000000000 -0400
70633 +++ linux-2.6.39/kernel/time/tick-broadcast.c 2011-05-22 19:36:33.000000000 -0400
70634 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct cl
70635 * then clear the broadcast bit.
70636 */
70637 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
70638 - int cpu = smp_processor_id();
70639 + cpu = smp_processor_id();
70640
70641 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
70642 tick_broadcast_clear_oneshot(cpu);
70643 diff -urNp linux-2.6.39/kernel/time/timekeeping.c linux-2.6.39/kernel/time/timekeeping.c
70644 --- linux-2.6.39/kernel/time/timekeeping.c 2011-05-19 00:06:34.000000000 -0400
70645 +++ linux-2.6.39/kernel/time/timekeeping.c 2011-05-22 20:40:50.000000000 -0400
70646 @@ -14,6 +14,7 @@
70647 #include <linux/init.h>
70648 #include <linux/mm.h>
70649 #include <linux/sched.h>
70650 +#include <linux/grsecurity.h>
70651 #include <linux/syscore_ops.h>
70652 #include <linux/clocksource.h>
70653 #include <linux/jiffies.h>
70654 @@ -361,6 +362,8 @@ int do_settimeofday(const struct timespe
70655 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
70656 return -EINVAL;
70657
70658 + gr_log_timechange();
70659 +
70660 write_seqlock_irqsave(&xtime_lock, flags);
70661
70662 timekeeping_forward_now();
70663 diff -urNp linux-2.6.39/kernel/time/timer_list.c linux-2.6.39/kernel/time/timer_list.c
70664 --- linux-2.6.39/kernel/time/timer_list.c 2011-05-19 00:06:34.000000000 -0400
70665 +++ linux-2.6.39/kernel/time/timer_list.c 2011-05-22 19:41:42.000000000 -0400
70666 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base,
70667
70668 static void print_name_offset(struct seq_file *m, void *sym)
70669 {
70670 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70671 + SEQ_printf(m, "<%p>", NULL);
70672 +#else
70673 char symname[KSYM_NAME_LEN];
70674
70675 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
70676 SEQ_printf(m, "<%pK>", sym);
70677 else
70678 SEQ_printf(m, "%s", symname);
70679 +#endif
70680 }
70681
70682 static void
70683 @@ -112,7 +116,11 @@ next_one:
70684 static void
70685 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
70686 {
70687 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70688 + SEQ_printf(m, " .base: %p\n", NULL);
70689 +#else
70690 SEQ_printf(m, " .base: %pK\n", base);
70691 +#endif
70692 SEQ_printf(m, " .index: %d\n",
70693 base->index);
70694 SEQ_printf(m, " .resolution: %Lu nsecs\n",
70695 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs
70696 {
70697 struct proc_dir_entry *pe;
70698
70699 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
70700 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
70701 +#else
70702 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
70703 +#endif
70704 if (!pe)
70705 return -ENOMEM;
70706 return 0;
70707 diff -urNp linux-2.6.39/kernel/time/timer_stats.c linux-2.6.39/kernel/time/timer_stats.c
70708 --- linux-2.6.39/kernel/time/timer_stats.c 2011-05-19 00:06:34.000000000 -0400
70709 +++ linux-2.6.39/kernel/time/timer_stats.c 2011-05-22 19:41:42.000000000 -0400
70710 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
70711 static unsigned long nr_entries;
70712 static struct entry entries[MAX_ENTRIES];
70713
70714 -static atomic_t overflow_count;
70715 +static atomic_unchecked_t overflow_count;
70716
70717 /*
70718 * The entries are in a hash-table, for fast lookup:
70719 @@ -140,7 +140,7 @@ static void reset_entries(void)
70720 nr_entries = 0;
70721 memset(entries, 0, sizeof(entries));
70722 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
70723 - atomic_set(&overflow_count, 0);
70724 + atomic_set_unchecked(&overflow_count, 0);
70725 }
70726
70727 static struct entry *alloc_entry(void)
70728 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *time
70729 if (likely(entry))
70730 entry->count++;
70731 else
70732 - atomic_inc(&overflow_count);
70733 + atomic_inc_unchecked(&overflow_count);
70734
70735 out_unlock:
70736 raw_spin_unlock_irqrestore(lock, flags);
70737 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *time
70738
70739 static void print_name_offset(struct seq_file *m, unsigned long addr)
70740 {
70741 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70742 + seq_printf(m, "<%p>", NULL);
70743 +#else
70744 char symname[KSYM_NAME_LEN];
70745
70746 if (lookup_symbol_name(addr, symname) < 0)
70747 seq_printf(m, "<%p>", (void *)addr);
70748 else
70749 seq_printf(m, "%s", symname);
70750 +#endif
70751 }
70752
70753 static int tstats_show(struct seq_file *m, void *v)
70754 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *
70755
70756 seq_puts(m, "Timer Stats Version: v0.2\n");
70757 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
70758 - if (atomic_read(&overflow_count))
70759 + if (atomic_read_unchecked(&overflow_count))
70760 seq_printf(m, "Overflow: %d entries\n",
70761 - atomic_read(&overflow_count));
70762 + atomic_read_unchecked(&overflow_count));
70763
70764 for (i = 0; i < nr_entries; i++) {
70765 entry = entries + i;
70766 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(voi
70767 {
70768 struct proc_dir_entry *pe;
70769
70770 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
70771 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
70772 +#else
70773 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
70774 +#endif
70775 if (!pe)
70776 return -ENOMEM;
70777 return 0;
70778 diff -urNp linux-2.6.39/kernel/time.c linux-2.6.39/kernel/time.c
70779 --- linux-2.6.39/kernel/time.c 2011-05-19 00:06:34.000000000 -0400
70780 +++ linux-2.6.39/kernel/time.c 2011-05-22 19:41:42.000000000 -0400
70781 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct tim
70782 return error;
70783
70784 if (tz) {
70785 + /* we log in do_settimeofday called below, so don't log twice
70786 + */
70787 + if (!tv)
70788 + gr_log_timechange();
70789 +
70790 /* SMP safe, global irq locking makes it work. */
70791 sys_tz = *tz;
70792 update_vsyscall_tz();
70793 diff -urNp linux-2.6.39/kernel/timer.c linux-2.6.39/kernel/timer.c
70794 --- linux-2.6.39/kernel/timer.c 2011-05-19 00:06:34.000000000 -0400
70795 +++ linux-2.6.39/kernel/timer.c 2011-05-22 19:36:33.000000000 -0400
70796 @@ -1305,7 +1305,7 @@ void update_process_times(int user_tick)
70797 /*
70798 * This function runs timers and the timer-tq in bottom half context.
70799 */
70800 -static void run_timer_softirq(struct softirq_action *h)
70801 +static void run_timer_softirq(void)
70802 {
70803 struct tvec_base *base = __this_cpu_read(tvec_bases);
70804
70805 diff -urNp linux-2.6.39/kernel/trace/blktrace.c linux-2.6.39/kernel/trace/blktrace.c
70806 --- linux-2.6.39/kernel/trace/blktrace.c 2011-05-19 00:06:34.000000000 -0400
70807 +++ linux-2.6.39/kernel/trace/blktrace.c 2011-05-22 19:36:33.000000000 -0400
70808 @@ -321,7 +321,7 @@ static ssize_t blk_dropped_read(struct f
70809 struct blk_trace *bt = filp->private_data;
70810 char buf[16];
70811
70812 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
70813 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
70814
70815 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
70816 }
70817 @@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(str
70818 return 1;
70819
70820 bt = buf->chan->private_data;
70821 - atomic_inc(&bt->dropped);
70822 + atomic_inc_unchecked(&bt->dropped);
70823 return 0;
70824 }
70825
70826 @@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_qu
70827
70828 bt->dir = dir;
70829 bt->dev = dev;
70830 - atomic_set(&bt->dropped, 0);
70831 + atomic_set_unchecked(&bt->dropped, 0);
70832
70833 ret = -EIO;
70834 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
70835 diff -urNp linux-2.6.39/kernel/trace/ftrace.c linux-2.6.39/kernel/trace/ftrace.c
70836 --- linux-2.6.39/kernel/trace/ftrace.c 2011-05-19 00:06:34.000000000 -0400
70837 +++ linux-2.6.39/kernel/trace/ftrace.c 2011-05-22 19:36:33.000000000 -0400
70838 @@ -1107,13 +1107,18 @@ ftrace_code_disable(struct module *mod,
70839
70840 ip = rec->ip;
70841
70842 + ret = ftrace_arch_code_modify_prepare();
70843 + FTRACE_WARN_ON(ret);
70844 + if (ret)
70845 + return 0;
70846 +
70847 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
70848 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
70849 if (ret) {
70850 ftrace_bug(ret, ip);
70851 rec->flags |= FTRACE_FL_FAILED;
70852 - return 0;
70853 }
70854 - return 1;
70855 + return ret ? 0 : 1;
70856 }
70857
70858 /*
70859 @@ -2011,7 +2016,7 @@ static void ftrace_free_entry_rcu(struct
70860
70861 int
70862 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
70863 - void *data)
70864 + void *data)
70865 {
70866 struct ftrace_func_probe *entry;
70867 struct ftrace_page *pg;
70868 @@ -2083,7 +2088,7 @@ enum {
70869 };
70870
70871 static void
70872 -__unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
70873 +__unregister_ftrace_function_probe(char *glob, const struct ftrace_probe_ops *ops,
70874 void *data, int flags)
70875 {
70876 struct ftrace_func_probe *entry;
70877 @@ -2144,7 +2149,7 @@ unregister_ftrace_function_probe(char *g
70878 }
70879
70880 void
70881 -unregister_ftrace_function_probe_func(char *glob, struct ftrace_probe_ops *ops)
70882 +unregister_ftrace_function_probe_func(char *glob, const struct ftrace_probe_ops *ops)
70883 {
70884 __unregister_ftrace_function_probe(glob, ops, NULL, PROBE_TEST_FUNC);
70885 }
70886 diff -urNp linux-2.6.39/kernel/trace/trace.c linux-2.6.39/kernel/trace/trace.c
70887 --- linux-2.6.39/kernel/trace/trace.c 2011-05-19 00:06:34.000000000 -0400
70888 +++ linux-2.6.39/kernel/trace/trace.c 2011-05-22 19:36:33.000000000 -0400
70889 @@ -3330,6 +3330,8 @@ static ssize_t tracing_splice_read_pipe(
70890 size_t rem;
70891 unsigned int i;
70892
70893 + pax_track_stack();
70894 +
70895 if (splice_grow_spd(pipe, &spd))
70896 return -ENOMEM;
70897
70898 @@ -3813,6 +3815,8 @@ tracing_buffers_splice_read(struct file
70899 int entries, size, i;
70900 size_t ret;
70901
70902 + pax_track_stack();
70903 +
70904 if (splice_grow_spd(pipe, &spd))
70905 return -ENOMEM;
70906
70907 @@ -3981,10 +3985,9 @@ static const struct file_operations trac
70908 };
70909 #endif
70910
70911 -static struct dentry *d_tracer;
70912 -
70913 struct dentry *tracing_init_dentry(void)
70914 {
70915 + static struct dentry *d_tracer;
70916 static int once;
70917
70918 if (d_tracer)
70919 @@ -4004,10 +4007,9 @@ struct dentry *tracing_init_dentry(void)
70920 return d_tracer;
70921 }
70922
70923 -static struct dentry *d_percpu;
70924 -
70925 struct dentry *tracing_dentry_percpu(void)
70926 {
70927 + static struct dentry *d_percpu;
70928 static int once;
70929 struct dentry *d_tracer;
70930
70931 diff -urNp linux-2.6.39/kernel/trace/trace_events.c linux-2.6.39/kernel/trace/trace_events.c
70932 --- linux-2.6.39/kernel/trace/trace_events.c 2011-05-19 00:06:34.000000000 -0400
70933 +++ linux-2.6.39/kernel/trace/trace_events.c 2011-05-22 19:36:33.000000000 -0400
70934 @@ -1241,10 +1241,10 @@ static LIST_HEAD(ftrace_module_file_list
70935 struct ftrace_module_file_ops {
70936 struct list_head list;
70937 struct module *mod;
70938 - struct file_operations id;
70939 - struct file_operations enable;
70940 - struct file_operations format;
70941 - struct file_operations filter;
70942 + struct file_operations id; /* cannot be const, see trace_create_file_ops() */
70943 + struct file_operations enable; /* cannot be const, see trace_create_file_ops() */
70944 + struct file_operations format; /* cannot be const, see trace_create_file_ops() */
70945 + struct file_operations filter; /* cannot be const, see trace_create_file_ops() */
70946 };
70947
70948 static struct ftrace_module_file_ops *
70949 diff -urNp linux-2.6.39/kernel/trace/trace_functions.c linux-2.6.39/kernel/trace/trace_functions.c
70950 --- linux-2.6.39/kernel/trace/trace_functions.c 2011-05-19 00:06:34.000000000 -0400
70951 +++ linux-2.6.39/kernel/trace/trace_functions.c 2011-05-22 19:36:33.000000000 -0400
70952 @@ -308,7 +308,7 @@ ftrace_trace_onoff_print(struct seq_file
70953 static int
70954 ftrace_trace_onoff_unreg(char *glob, char *cmd, char *param)
70955 {
70956 - struct ftrace_probe_ops *ops;
70957 + const struct ftrace_probe_ops *ops;
70958
70959 /* we register both traceon and traceoff to this callback */
70960 if (strcmp(cmd, "traceon") == 0)
70961 diff -urNp linux-2.6.39/kernel/trace/trace_mmiotrace.c linux-2.6.39/kernel/trace/trace_mmiotrace.c
70962 --- linux-2.6.39/kernel/trace/trace_mmiotrace.c 2011-05-19 00:06:34.000000000 -0400
70963 +++ linux-2.6.39/kernel/trace/trace_mmiotrace.c 2011-05-22 19:36:33.000000000 -0400
70964 @@ -24,7 +24,7 @@ struct header_iter {
70965 static struct trace_array *mmio_trace_array;
70966 static bool overrun_detected;
70967 static unsigned long prev_overruns;
70968 -static atomic_t dropped_count;
70969 +static atomic_unchecked_t dropped_count;
70970
70971 static void mmio_reset_data(struct trace_array *tr)
70972 {
70973 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iter
70974
70975 static unsigned long count_overruns(struct trace_iterator *iter)
70976 {
70977 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
70978 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
70979 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
70980
70981 if (over > prev_overruns)
70982 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct
70983 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
70984 sizeof(*entry), 0, pc);
70985 if (!event) {
70986 - atomic_inc(&dropped_count);
70987 + atomic_inc_unchecked(&dropped_count);
70988 return;
70989 }
70990 entry = ring_buffer_event_data(event);
70991 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct
70992 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
70993 sizeof(*entry), 0, pc);
70994 if (!event) {
70995 - atomic_inc(&dropped_count);
70996 + atomic_inc_unchecked(&dropped_count);
70997 return;
70998 }
70999 entry = ring_buffer_event_data(event);
71000 diff -urNp linux-2.6.39/kernel/trace/trace_output.c linux-2.6.39/kernel/trace/trace_output.c
71001 --- linux-2.6.39/kernel/trace/trace_output.c 2011-05-19 00:06:34.000000000 -0400
71002 +++ linux-2.6.39/kernel/trace/trace_output.c 2011-05-22 19:36:33.000000000 -0400
71003 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s,
71004
71005 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
71006 if (!IS_ERR(p)) {
71007 - p = mangle_path(s->buffer + s->len, p, "\n");
71008 + p = mangle_path(s->buffer + s->len, p, "\n\\");
71009 if (p) {
71010 s->len = p - s->buffer;
71011 return 1;
71012 diff -urNp linux-2.6.39/kernel/trace/trace_stack.c linux-2.6.39/kernel/trace/trace_stack.c
71013 --- linux-2.6.39/kernel/trace/trace_stack.c 2011-05-19 00:06:34.000000000 -0400
71014 +++ linux-2.6.39/kernel/trace/trace_stack.c 2011-05-22 19:36:33.000000000 -0400
71015 @@ -50,7 +50,7 @@ static inline void check_stack(void)
71016 return;
71017
71018 /* we do not handle interrupt stacks yet */
71019 - if (!object_is_on_stack(&this_size))
71020 + if (!object_starts_on_stack(&this_size))
71021 return;
71022
71023 local_irq_save(flags);
71024 diff -urNp linux-2.6.39/kernel/trace/trace_workqueue.c linux-2.6.39/kernel/trace/trace_workqueue.c
71025 --- linux-2.6.39/kernel/trace/trace_workqueue.c 2011-05-19 00:06:34.000000000 -0400
71026 +++ linux-2.6.39/kernel/trace/trace_workqueue.c 2011-05-22 19:36:33.000000000 -0400
71027 @@ -22,7 +22,7 @@ struct cpu_workqueue_stats {
71028 int cpu;
71029 pid_t pid;
71030 /* Can be inserted from interrupt or user context, need to be atomic */
71031 - atomic_t inserted;
71032 + atomic_unchecked_t inserted;
71033 /*
71034 * Don't need to be atomic, works are serialized in a single workqueue thread
71035 * on a single CPU.
71036 @@ -60,7 +60,7 @@ probe_workqueue_insertion(void *ignore,
71037 spin_lock_irqsave(&workqueue_cpu_stat(cpu)->lock, flags);
71038 list_for_each_entry(node, &workqueue_cpu_stat(cpu)->list, list) {
71039 if (node->pid == wq_thread->pid) {
71040 - atomic_inc(&node->inserted);
71041 + atomic_inc_unchecked(&node->inserted);
71042 goto found;
71043 }
71044 }
71045 @@ -210,7 +210,7 @@ static int workqueue_stat_show(struct se
71046 tsk = get_pid_task(pid, PIDTYPE_PID);
71047 if (tsk) {
71048 seq_printf(s, "%3d %6d %6u %s\n", cws->cpu,
71049 - atomic_read(&cws->inserted), cws->executed,
71050 + atomic_read_unchecked(&cws->inserted), cws->executed,
71051 tsk->comm);
71052 put_task_struct(tsk);
71053 }
71054 diff -urNp linux-2.6.39/lib/bug.c linux-2.6.39/lib/bug.c
71055 --- linux-2.6.39/lib/bug.c 2011-05-19 00:06:34.000000000 -0400
71056 +++ linux-2.6.39/lib/bug.c 2011-05-22 19:36:33.000000000 -0400
71057 @@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned l
71058 return BUG_TRAP_TYPE_NONE;
71059
71060 bug = find_bug(bugaddr);
71061 + if (!bug)
71062 + return BUG_TRAP_TYPE_NONE;
71063
71064 file = NULL;
71065 line = 0;
71066 diff -urNp linux-2.6.39/lib/debugobjects.c linux-2.6.39/lib/debugobjects.c
71067 --- linux-2.6.39/lib/debugobjects.c 2011-05-19 00:06:34.000000000 -0400
71068 +++ linux-2.6.39/lib/debugobjects.c 2011-05-22 19:36:33.000000000 -0400
71069 @@ -284,7 +284,7 @@ static void debug_object_is_on_stack(voi
71070 if (limit > 4)
71071 return;
71072
71073 - is_on_stack = object_is_on_stack(addr);
71074 + is_on_stack = object_starts_on_stack(addr);
71075 if (is_on_stack == onstack)
71076 return;
71077
71078 diff -urNp linux-2.6.39/lib/dma-debug.c linux-2.6.39/lib/dma-debug.c
71079 --- linux-2.6.39/lib/dma-debug.c 2011-05-19 00:06:34.000000000 -0400
71080 +++ linux-2.6.39/lib/dma-debug.c 2011-05-22 19:36:33.000000000 -0400
71081 @@ -862,7 +862,7 @@ out:
71082
71083 static void check_for_stack(struct device *dev, void *addr)
71084 {
71085 - if (object_is_on_stack(addr))
71086 + if (object_starts_on_stack(addr))
71087 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
71088 "stack [addr=%p]\n", addr);
71089 }
71090 diff -urNp linux-2.6.39/lib/inflate.c linux-2.6.39/lib/inflate.c
71091 --- linux-2.6.39/lib/inflate.c 2011-05-19 00:06:34.000000000 -0400
71092 +++ linux-2.6.39/lib/inflate.c 2011-05-22 19:36:33.000000000 -0400
71093 @@ -269,7 +269,7 @@ static void free(void *where)
71094 malloc_ptr = free_mem_ptr;
71095 }
71096 #else
71097 -#define malloc(a) kmalloc(a, GFP_KERNEL)
71098 +#define malloc(a) kmalloc((a), GFP_KERNEL)
71099 #define free(a) kfree(a)
71100 #endif
71101
71102 diff -urNp linux-2.6.39/lib/Kconfig.debug linux-2.6.39/lib/Kconfig.debug
71103 --- linux-2.6.39/lib/Kconfig.debug 2011-05-19 00:06:34.000000000 -0400
71104 +++ linux-2.6.39/lib/Kconfig.debug 2011-05-22 19:41:42.000000000 -0400
71105 @@ -1078,6 +1078,7 @@ config LATENCYTOP
71106 depends on DEBUG_KERNEL
71107 depends on STACKTRACE_SUPPORT
71108 depends on PROC_FS
71109 + depends on !GRKERNSEC_HIDESYM
71110 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE
71111 select KALLSYMS
71112 select KALLSYMS_ALL
71113 diff -urNp linux-2.6.39/lib/kref.c linux-2.6.39/lib/kref.c
71114 --- linux-2.6.39/lib/kref.c 2011-05-19 00:06:34.000000000 -0400
71115 +++ linux-2.6.39/lib/kref.c 2011-05-22 19:36:33.000000000 -0400
71116 @@ -52,7 +52,7 @@ void kref_get(struct kref *kref)
71117 */
71118 int kref_put(struct kref *kref, void (*release)(struct kref *kref))
71119 {
71120 - WARN_ON(release == NULL);
71121 + BUG_ON(release == NULL);
71122 WARN_ON(release == (void (*)(struct kref *))kfree);
71123
71124 if (atomic_dec_and_test(&kref->refcount)) {
71125 diff -urNp linux-2.6.39/lib/radix-tree.c linux-2.6.39/lib/radix-tree.c
71126 --- linux-2.6.39/lib/radix-tree.c 2011-05-19 00:06:34.000000000 -0400
71127 +++ linux-2.6.39/lib/radix-tree.c 2011-05-22 19:36:33.000000000 -0400
71128 @@ -80,7 +80,7 @@ struct radix_tree_preload {
71129 int nr;
71130 struct radix_tree_node *nodes[RADIX_TREE_MAX_PATH];
71131 };
71132 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
71133 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
71134
71135 static inline void *ptr_to_indirect(void *ptr)
71136 {
71137 diff -urNp linux-2.6.39/lib/vsprintf.c linux-2.6.39/lib/vsprintf.c
71138 --- linux-2.6.39/lib/vsprintf.c 2011-05-19 00:06:34.000000000 -0400
71139 +++ linux-2.6.39/lib/vsprintf.c 2011-05-22 20:54:59.000000000 -0400
71140 @@ -16,6 +16,9 @@
71141 * - scnprintf and vscnprintf
71142 */
71143
71144 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71145 +#define __INCLUDED_BY_HIDESYM 1
71146 +#endif
71147 #include <stdarg.h>
71148 #include <linux/module.h>
71149 #include <linux/types.h>
71150 @@ -435,7 +438,7 @@ char *symbol_string(char *buf, char *end
71151 char sym[KSYM_SYMBOL_LEN];
71152 if (ext == 'B')
71153 sprint_backtrace(sym, value);
71154 - else if (ext != 'f' && ext != 's')
71155 + else if (ext != 'f' && ext != 's' && ext != 'a')
71156 sprint_symbol(sym, value);
71157 else
71158 kallsyms_lookup(value, NULL, NULL, NULL, sym);
71159 @@ -797,7 +800,11 @@ char *uuid_string(char *buf, char *end,
71160 return string(buf, end, uuid, spec);
71161 }
71162
71163 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71164 +int kptr_restrict __read_mostly = 2;
71165 +#else
71166 int kptr_restrict __read_mostly;
71167 +#endif
71168
71169 /*
71170 * Show a '%p' thing. A kernel extension is that the '%p' is followed
71171 @@ -811,6 +818,8 @@ int kptr_restrict __read_mostly;
71172 * - 'S' For symbolic direct pointers with offset
71173 * - 's' For symbolic direct pointers without offset
71174 * - 'B' For backtraced symbolic direct pointers with offset
71175 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
71176 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
71177 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
71178 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
71179 * - 'M' For a 6-byte MAC address, it prints the address in the
71180 @@ -855,12 +864,12 @@ char *pointer(const char *fmt, char *buf
71181 {
71182 if (!ptr && *fmt != 'K') {
71183 /*
71184 - * Print (null) with the same width as a pointer so it makes
71185 + * Print (nil) with the same width as a pointer so it makes
71186 * tabular output look nice.
71187 */
71188 if (spec.field_width == -1)
71189 spec.field_width = 2 * sizeof(void *);
71190 - return string(buf, end, "(null)", spec);
71191 + return string(buf, end, "(nil)", spec);
71192 }
71193
71194 switch (*fmt) {
71195 @@ -870,6 +879,13 @@ char *pointer(const char *fmt, char *buf
71196 /* Fallthrough */
71197 case 'S':
71198 case 's':
71199 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71200 + break;
71201 +#else
71202 + return symbol_string(buf, end, ptr, spec, *fmt);
71203 +#endif
71204 + case 'A':
71205 + case 'a':
71206 case 'B':
71207 return symbol_string(buf, end, ptr, spec, *fmt);
71208 case 'R':
71209 @@ -1632,11 +1648,11 @@ int bstr_printf(char *buf, size_t size,
71210 typeof(type) value; \
71211 if (sizeof(type) == 8) { \
71212 args = PTR_ALIGN(args, sizeof(u32)); \
71213 - *(u32 *)&value = *(u32 *)args; \
71214 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
71215 + *(u32 *)&value = *(const u32 *)args; \
71216 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
71217 } else { \
71218 args = PTR_ALIGN(args, sizeof(type)); \
71219 - value = *(typeof(type) *)args; \
71220 + value = *(const typeof(type) *)args; \
71221 } \
71222 args += sizeof(type); \
71223 value; \
71224 @@ -1699,7 +1715,7 @@ int bstr_printf(char *buf, size_t size,
71225 case FORMAT_TYPE_STR: {
71226 const char *str_arg = args;
71227 args += strlen(str_arg) + 1;
71228 - str = string(str, end, (char *)str_arg, spec);
71229 + str = string(str, end, str_arg, spec);
71230 break;
71231 }
71232
71233 diff -urNp linux-2.6.39/localversion-grsec linux-2.6.39/localversion-grsec
71234 --- linux-2.6.39/localversion-grsec 1969-12-31 19:00:00.000000000 -0500
71235 +++ linux-2.6.39/localversion-grsec 2011-05-22 19:41:42.000000000 -0400
71236 @@ -0,0 +1 @@
71237 +-grsec
71238 diff -urNp linux-2.6.39/Makefile linux-2.6.39/Makefile
71239 --- linux-2.6.39/Makefile 2011-05-19 00:06:34.000000000 -0400
71240 +++ linux-2.6.39/Makefile 2011-05-22 19:41:42.000000000 -0400
71241 @@ -237,8 +237,8 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH"
71242
71243 HOSTCC = gcc
71244 HOSTCXX = g++
71245 -HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
71246 -HOSTCXXFLAGS = -O2
71247 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-empty-body -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
71248 +HOSTCXXFLAGS = -O2 -fno-delete-null-pointer-checks
71249
71250 # Decide whether to build built-in, modular, or both.
71251 # Normally, just do built-in.
71252 @@ -356,6 +356,7 @@ LINUXINCLUDE := -I$(srctree)/arch/$(h
71253 KBUILD_CPPFLAGS := -D__KERNEL__
71254
71255 KBUILD_CFLAGS := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
71256 + -W -Wno-empty-body -Wno-unused-parameter -Wno-missing-field-initializers \
71257 -fno-strict-aliasing -fno-common \
71258 -Werror-implicit-function-declaration \
71259 -Wno-format-security \
71260 @@ -685,7 +686,7 @@ export mod_strip_cmd
71261
71262
71263 ifeq ($(KBUILD_EXTMOD),)
71264 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
71265 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
71266
71267 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
71268 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
71269 diff -urNp linux-2.6.39/mm/filemap.c linux-2.6.39/mm/filemap.c
71270 --- linux-2.6.39/mm/filemap.c 2011-05-19 00:06:34.000000000 -0400
71271 +++ linux-2.6.39/mm/filemap.c 2011-05-22 19:41:42.000000000 -0400
71272 @@ -1724,7 +1724,7 @@ int generic_file_mmap(struct file * file
71273 struct address_space *mapping = file->f_mapping;
71274
71275 if (!mapping->a_ops->readpage)
71276 - return -ENOEXEC;
71277 + return -ENODEV;
71278 file_accessed(file);
71279 vma->vm_ops = &generic_file_vm_ops;
71280 vma->vm_flags |= VM_CAN_NONLINEAR;
71281 @@ -2120,6 +2120,7 @@ inline int generic_write_checks(struct f
71282 *pos = i_size_read(inode);
71283
71284 if (limit != RLIM_INFINITY) {
71285 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
71286 if (*pos >= limit) {
71287 send_sig(SIGXFSZ, current, 0);
71288 return -EFBIG;
71289 diff -urNp linux-2.6.39/mm/fremap.c linux-2.6.39/mm/fremap.c
71290 --- linux-2.6.39/mm/fremap.c 2011-05-19 00:06:34.000000000 -0400
71291 +++ linux-2.6.39/mm/fremap.c 2011-05-22 19:36:33.000000000 -0400
71292 @@ -156,6 +156,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsign
71293 retry:
71294 vma = find_vma(mm, start);
71295
71296 +#ifdef CONFIG_PAX_SEGMEXEC
71297 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
71298 + goto out;
71299 +#endif
71300 +
71301 /*
71302 * Make sure the vma is shared, that it supports prefaulting,
71303 * and that the remapped range is valid and fully within
71304 @@ -224,7 +229,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsign
71305 /*
71306 * drop PG_Mlocked flag for over-mapped range
71307 */
71308 - unsigned int saved_flags = vma->vm_flags;
71309 + unsigned long saved_flags = vma->vm_flags;
71310 munlock_vma_pages_range(vma, start, start + size);
71311 vma->vm_flags = saved_flags;
71312 }
71313 diff -urNp linux-2.6.39/mm/highmem.c linux-2.6.39/mm/highmem.c
71314 --- linux-2.6.39/mm/highmem.c 2011-05-19 00:06:34.000000000 -0400
71315 +++ linux-2.6.39/mm/highmem.c 2011-05-22 19:36:33.000000000 -0400
71316 @@ -125,9 +125,10 @@ static void flush_all_zero_pkmaps(void)
71317 * So no dangers, even with speculative execution.
71318 */
71319 page = pte_page(pkmap_page_table[i]);
71320 + pax_open_kernel();
71321 pte_clear(&init_mm, (unsigned long)page_address(page),
71322 &pkmap_page_table[i]);
71323 -
71324 + pax_close_kernel();
71325 set_page_address(page, NULL);
71326 need_flush = 1;
71327 }
71328 @@ -186,9 +187,11 @@ start:
71329 }
71330 }
71331 vaddr = PKMAP_ADDR(last_pkmap_nr);
71332 +
71333 + pax_open_kernel();
71334 set_pte_at(&init_mm, vaddr,
71335 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
71336 -
71337 + pax_close_kernel();
71338 pkmap_count[last_pkmap_nr] = 1;
71339 set_page_address(page, (void *)vaddr);
71340
71341 diff -urNp linux-2.6.39/mm/huge_memory.c linux-2.6.39/mm/huge_memory.c
71342 --- linux-2.6.39/mm/huge_memory.c 2011-05-19 00:06:34.000000000 -0400
71343 +++ linux-2.6.39/mm/huge_memory.c 2011-05-22 19:36:33.000000000 -0400
71344 @@ -702,7 +702,7 @@ out:
71345 * run pte_offset_map on the pmd, if an huge pmd could
71346 * materialize from under us from a different thread.
71347 */
71348 - if (unlikely(__pte_alloc(mm, vma, pmd, address)))
71349 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
71350 return VM_FAULT_OOM;
71351 /* if an huge pmd materialized from under us just retry later */
71352 if (unlikely(pmd_trans_huge(*pmd)))
71353 diff -urNp linux-2.6.39/mm/hugetlb.c linux-2.6.39/mm/hugetlb.c
71354 --- linux-2.6.39/mm/hugetlb.c 2011-05-19 00:06:34.000000000 -0400
71355 +++ linux-2.6.39/mm/hugetlb.c 2011-05-22 19:36:33.000000000 -0400
71356 @@ -2331,6 +2331,27 @@ static int unmap_ref_private(struct mm_s
71357 return 1;
71358 }
71359
71360 +#ifdef CONFIG_PAX_SEGMEXEC
71361 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
71362 +{
71363 + struct mm_struct *mm = vma->vm_mm;
71364 + struct vm_area_struct *vma_m;
71365 + unsigned long address_m;
71366 + pte_t *ptep_m;
71367 +
71368 + vma_m = pax_find_mirror_vma(vma);
71369 + if (!vma_m)
71370 + return;
71371 +
71372 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71373 + address_m = address + SEGMEXEC_TASK_SIZE;
71374 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
71375 + get_page(page_m);
71376 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
71377 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
71378 +}
71379 +#endif
71380 +
71381 /*
71382 * Hugetlb_cow() should be called with page lock of the original hugepage held.
71383 */
71384 @@ -2432,6 +2453,11 @@ retry_avoidcopy:
71385 make_huge_pte(vma, new_page, 1));
71386 page_remove_rmap(old_page);
71387 hugepage_add_new_anon_rmap(new_page, vma, address);
71388 +
71389 +#ifdef CONFIG_PAX_SEGMEXEC
71390 + pax_mirror_huge_pte(vma, address, new_page);
71391 +#endif
71392 +
71393 /* Make the old page be freed below */
71394 new_page = old_page;
71395 mmu_notifier_invalidate_range_end(mm,
71396 @@ -2583,6 +2609,10 @@ retry:
71397 && (vma->vm_flags & VM_SHARED)));
71398 set_huge_pte_at(mm, address, ptep, new_pte);
71399
71400 +#ifdef CONFIG_PAX_SEGMEXEC
71401 + pax_mirror_huge_pte(vma, address, page);
71402 +#endif
71403 +
71404 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
71405 /* Optimization, do the COW without a second fault */
71406 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
71407 @@ -2612,6 +2642,10 @@ int hugetlb_fault(struct mm_struct *mm,
71408 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
71409 struct hstate *h = hstate_vma(vma);
71410
71411 +#ifdef CONFIG_PAX_SEGMEXEC
71412 + struct vm_area_struct *vma_m;
71413 +#endif
71414 +
71415 ptep = huge_pte_offset(mm, address);
71416 if (ptep) {
71417 entry = huge_ptep_get(ptep);
71418 @@ -2623,6 +2657,26 @@ int hugetlb_fault(struct mm_struct *mm,
71419 VM_FAULT_SET_HINDEX(h - hstates);
71420 }
71421
71422 +#ifdef CONFIG_PAX_SEGMEXEC
71423 + vma_m = pax_find_mirror_vma(vma);
71424 + if (vma_m) {
71425 + unsigned long address_m;
71426 +
71427 + if (vma->vm_start > vma_m->vm_start) {
71428 + address_m = address;
71429 + address -= SEGMEXEC_TASK_SIZE;
71430 + vma = vma_m;
71431 + h = hstate_vma(vma);
71432 + } else
71433 + address_m = address + SEGMEXEC_TASK_SIZE;
71434 +
71435 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
71436 + return VM_FAULT_OOM;
71437 + address_m &= HPAGE_MASK;
71438 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
71439 + }
71440 +#endif
71441 +
71442 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
71443 if (!ptep)
71444 return VM_FAULT_OOM;
71445 diff -urNp linux-2.6.39/mm/Kconfig linux-2.6.39/mm/Kconfig
71446 --- linux-2.6.39/mm/Kconfig 2011-05-19 00:06:34.000000000 -0400
71447 +++ linux-2.6.39/mm/Kconfig 2011-05-22 19:41:42.000000000 -0400
71448 @@ -240,7 +240,7 @@ config KSM
71449 config DEFAULT_MMAP_MIN_ADDR
71450 int "Low address space to protect from user allocation"
71451 depends on MMU
71452 - default 4096
71453 + default 65536
71454 help
71455 This is the portion of low virtual memory which should be protected
71456 from userspace allocation. Keeping a user from writing to low pages
71457 diff -urNp linux-2.6.39/mm/kmemleak.c linux-2.6.39/mm/kmemleak.c
71458 --- linux-2.6.39/mm/kmemleak.c 2011-05-19 00:06:34.000000000 -0400
71459 +++ linux-2.6.39/mm/kmemleak.c 2011-05-22 19:41:42.000000000 -0400
71460 @@ -357,7 +357,7 @@ static void print_unreferenced(struct se
71461
71462 for (i = 0; i < object->trace_len; i++) {
71463 void *ptr = (void *)object->trace[i];
71464 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
71465 + seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
71466 }
71467 }
71468
71469 diff -urNp linux-2.6.39/mm/maccess.c linux-2.6.39/mm/maccess.c
71470 --- linux-2.6.39/mm/maccess.c 2011-05-19 00:06:34.000000000 -0400
71471 +++ linux-2.6.39/mm/maccess.c 2011-05-22 19:36:33.000000000 -0400
71472 @@ -15,10 +15,10 @@
71473 * happens, handle that and return -EFAULT.
71474 */
71475
71476 -long __weak probe_kernel_read(void *dst, void *src, size_t size)
71477 +long __weak probe_kernel_read(void *dst, const void *src, size_t size)
71478 __attribute__((alias("__probe_kernel_read")));
71479
71480 -long __probe_kernel_read(void *dst, void *src, size_t size)
71481 +long __probe_kernel_read(void *dst, const void *src, size_t size)
71482 {
71483 long ret;
71484 mm_segment_t old_fs = get_fs();
71485 @@ -43,10 +43,10 @@ EXPORT_SYMBOL_GPL(probe_kernel_read);
71486 * Safely write to address @dst from the buffer at @src. If a kernel fault
71487 * happens, handle that and return -EFAULT.
71488 */
71489 -long __weak probe_kernel_write(void *dst, void *src, size_t size)
71490 +long __weak probe_kernel_write(void *dst, const void *src, size_t size)
71491 __attribute__((alias("__probe_kernel_write")));
71492
71493 -long __probe_kernel_write(void *dst, void *src, size_t size)
71494 +long __probe_kernel_write(void *dst, const void *src, size_t size)
71495 {
71496 long ret;
71497 mm_segment_t old_fs = get_fs();
71498 diff -urNp linux-2.6.39/mm/madvise.c linux-2.6.39/mm/madvise.c
71499 --- linux-2.6.39/mm/madvise.c 2011-05-19 00:06:34.000000000 -0400
71500 +++ linux-2.6.39/mm/madvise.c 2011-05-22 19:36:33.000000000 -0400
71501 @@ -45,6 +45,10 @@ static long madvise_behavior(struct vm_a
71502 pgoff_t pgoff;
71503 unsigned long new_flags = vma->vm_flags;
71504
71505 +#ifdef CONFIG_PAX_SEGMEXEC
71506 + struct vm_area_struct *vma_m;
71507 +#endif
71508 +
71509 switch (behavior) {
71510 case MADV_NORMAL:
71511 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
71512 @@ -110,6 +114,13 @@ success:
71513 /*
71514 * vm_flags is protected by the mmap_sem held in write mode.
71515 */
71516 +
71517 +#ifdef CONFIG_PAX_SEGMEXEC
71518 + vma_m = pax_find_mirror_vma(vma);
71519 + if (vma_m)
71520 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
71521 +#endif
71522 +
71523 vma->vm_flags = new_flags;
71524
71525 out:
71526 @@ -168,6 +179,11 @@ static long madvise_dontneed(struct vm_a
71527 struct vm_area_struct ** prev,
71528 unsigned long start, unsigned long end)
71529 {
71530 +
71531 +#ifdef CONFIG_PAX_SEGMEXEC
71532 + struct vm_area_struct *vma_m;
71533 +#endif
71534 +
71535 *prev = vma;
71536 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
71537 return -EINVAL;
71538 @@ -180,6 +196,21 @@ static long madvise_dontneed(struct vm_a
71539 zap_page_range(vma, start, end - start, &details);
71540 } else
71541 zap_page_range(vma, start, end - start, NULL);
71542 +
71543 +#ifdef CONFIG_PAX_SEGMEXEC
71544 + vma_m = pax_find_mirror_vma(vma);
71545 + if (vma_m) {
71546 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
71547 + struct zap_details details = {
71548 + .nonlinear_vma = vma_m,
71549 + .last_index = ULONG_MAX,
71550 + };
71551 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
71552 + } else
71553 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
71554 + }
71555 +#endif
71556 +
71557 return 0;
71558 }
71559
71560 @@ -376,6 +407,16 @@ SYSCALL_DEFINE3(madvise, unsigned long,
71561 if (end < start)
71562 goto out;
71563
71564 +#ifdef CONFIG_PAX_SEGMEXEC
71565 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
71566 + if (end > SEGMEXEC_TASK_SIZE)
71567 + goto out;
71568 + } else
71569 +#endif
71570 +
71571 + if (end > TASK_SIZE)
71572 + goto out;
71573 +
71574 error = 0;
71575 if (end == start)
71576 goto out;
71577 diff -urNp linux-2.6.39/mm/memory.c linux-2.6.39/mm/memory.c
71578 --- linux-2.6.39/mm/memory.c 2011-05-19 00:06:34.000000000 -0400
71579 +++ linux-2.6.39/mm/memory.c 2011-05-22 19:36:33.000000000 -0400
71580 @@ -259,8 +259,12 @@ static inline void free_pmd_range(struct
71581 return;
71582
71583 pmd = pmd_offset(pud, start);
71584 +
71585 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
71586 pud_clear(pud);
71587 pmd_free_tlb(tlb, pmd, start);
71588 +#endif
71589 +
71590 }
71591
71592 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71593 @@ -291,9 +295,12 @@ static inline void free_pud_range(struct
71594 if (end - 1 > ceiling - 1)
71595 return;
71596
71597 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
71598 pud = pud_offset(pgd, start);
71599 pgd_clear(pgd);
71600 pud_free_tlb(tlb, pud, start);
71601 +#endif
71602 +
71603 }
71604
71605 /*
71606 @@ -1410,12 +1417,6 @@ no_page_table:
71607 return page;
71608 }
71609
71610 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
71611 -{
71612 - return stack_guard_page_start(vma, addr) ||
71613 - stack_guard_page_end(vma, addr+PAGE_SIZE);
71614 -}
71615 -
71616 /**
71617 * __get_user_pages() - pin user pages in memory
71618 * @tsk: task_struct of target task
71619 @@ -1488,10 +1489,10 @@ int __get_user_pages(struct task_struct
71620 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
71621 i = 0;
71622
71623 - do {
71624 + while (nr_pages) {
71625 struct vm_area_struct *vma;
71626
71627 - vma = find_extend_vma(mm, start);
71628 + vma = find_vma(mm, start);
71629 if (!vma && in_gate_area(mm, start)) {
71630 unsigned long pg = start & PAGE_MASK;
71631 pgd_t *pgd;
71632 @@ -1539,7 +1540,7 @@ int __get_user_pages(struct task_struct
71633 goto next_page;
71634 }
71635
71636 - if (!vma ||
71637 + if (!vma || start < vma->vm_start ||
71638 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
71639 !(vm_flags & vma->vm_flags))
71640 return i ? : -EFAULT;
71641 @@ -1566,11 +1567,6 @@ int __get_user_pages(struct task_struct
71642 int ret;
71643 unsigned int fault_flags = 0;
71644
71645 - /* For mlock, just skip the stack guard page. */
71646 - if (foll_flags & FOLL_MLOCK) {
71647 - if (stack_guard_page(vma, start))
71648 - goto next_page;
71649 - }
71650 if (foll_flags & FOLL_WRITE)
71651 fault_flags |= FAULT_FLAG_WRITE;
71652 if (nonblocking)
71653 @@ -1644,7 +1640,7 @@ next_page:
71654 start += PAGE_SIZE;
71655 nr_pages--;
71656 } while (nr_pages && start < vma->vm_end);
71657 - } while (nr_pages);
71658 + }
71659 return i;
71660 }
71661 EXPORT_SYMBOL(__get_user_pages);
71662 @@ -1795,6 +1791,10 @@ static int insert_page(struct vm_area_st
71663 page_add_file_rmap(page);
71664 set_pte_at(mm, addr, pte, mk_pte(page, prot));
71665
71666 +#ifdef CONFIG_PAX_SEGMEXEC
71667 + pax_mirror_file_pte(vma, addr, page, ptl);
71668 +#endif
71669 +
71670 retval = 0;
71671 pte_unmap_unlock(pte, ptl);
71672 return retval;
71673 @@ -1829,10 +1829,22 @@ out:
71674 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
71675 struct page *page)
71676 {
71677 +
71678 +#ifdef CONFIG_PAX_SEGMEXEC
71679 + struct vm_area_struct *vma_m;
71680 +#endif
71681 +
71682 if (addr < vma->vm_start || addr >= vma->vm_end)
71683 return -EFAULT;
71684 if (!page_count(page))
71685 return -EINVAL;
71686 +
71687 +#ifdef CONFIG_PAX_SEGMEXEC
71688 + vma_m = pax_find_mirror_vma(vma);
71689 + if (vma_m)
71690 + vma_m->vm_flags |= VM_INSERTPAGE;
71691 +#endif
71692 +
71693 vma->vm_flags |= VM_INSERTPAGE;
71694 return insert_page(vma, addr, page, vma->vm_page_prot);
71695 }
71696 @@ -1918,6 +1930,7 @@ int vm_insert_mixed(struct vm_area_struc
71697 unsigned long pfn)
71698 {
71699 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
71700 + BUG_ON(vma->vm_mirror);
71701
71702 if (addr < vma->vm_start || addr >= vma->vm_end)
71703 return -EFAULT;
71704 @@ -2233,6 +2246,186 @@ static inline void cow_user_page(struct
71705 copy_user_highpage(dst, src, va, vma);
71706 }
71707
71708 +#ifdef CONFIG_PAX_SEGMEXEC
71709 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
71710 +{
71711 + struct mm_struct *mm = vma->vm_mm;
71712 + spinlock_t *ptl;
71713 + pte_t *pte, entry;
71714 +
71715 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
71716 + entry = *pte;
71717 + if (!pte_present(entry)) {
71718 + if (!pte_none(entry)) {
71719 + BUG_ON(pte_file(entry));
71720 + free_swap_and_cache(pte_to_swp_entry(entry));
71721 + pte_clear_not_present_full(mm, address, pte, 0);
71722 + }
71723 + } else {
71724 + struct page *page;
71725 +
71726 + flush_cache_page(vma, address, pte_pfn(entry));
71727 + entry = ptep_clear_flush(vma, address, pte);
71728 + BUG_ON(pte_dirty(entry));
71729 + page = vm_normal_page(vma, address, entry);
71730 + if (page) {
71731 + update_hiwater_rss(mm);
71732 + if (PageAnon(page))
71733 + dec_mm_counter_fast(mm, MM_ANONPAGES);
71734 + else
71735 + dec_mm_counter_fast(mm, MM_FILEPAGES);
71736 + page_remove_rmap(page);
71737 + page_cache_release(page);
71738 + }
71739 + }
71740 + pte_unmap_unlock(pte, ptl);
71741 +}
71742 +
71743 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
71744 + *
71745 + * the ptl of the lower mapped page is held on entry and is not released on exit
71746 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
71747 + */
71748 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
71749 +{
71750 + struct mm_struct *mm = vma->vm_mm;
71751 + unsigned long address_m;
71752 + spinlock_t *ptl_m;
71753 + struct vm_area_struct *vma_m;
71754 + pmd_t *pmd_m;
71755 + pte_t *pte_m, entry_m;
71756 +
71757 + BUG_ON(!page_m || !PageAnon(page_m));
71758 +
71759 + vma_m = pax_find_mirror_vma(vma);
71760 + if (!vma_m)
71761 + return;
71762 +
71763 + BUG_ON(!PageLocked(page_m));
71764 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71765 + address_m = address + SEGMEXEC_TASK_SIZE;
71766 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71767 + pte_m = pte_offset_map(pmd_m, address_m);
71768 + ptl_m = pte_lockptr(mm, pmd_m);
71769 + if (ptl != ptl_m) {
71770 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71771 + if (!pte_none(*pte_m))
71772 + goto out;
71773 + }
71774 +
71775 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
71776 + page_cache_get(page_m);
71777 + page_add_anon_rmap(page_m, vma_m, address_m);
71778 + inc_mm_counter_fast(mm, MM_ANONPAGES);
71779 + set_pte_at(mm, address_m, pte_m, entry_m);
71780 + update_mmu_cache(vma_m, address_m, entry_m);
71781 +out:
71782 + if (ptl != ptl_m)
71783 + spin_unlock(ptl_m);
71784 + pte_unmap(pte_m);
71785 + unlock_page(page_m);
71786 +}
71787 +
71788 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
71789 +{
71790 + struct mm_struct *mm = vma->vm_mm;
71791 + unsigned long address_m;
71792 + spinlock_t *ptl_m;
71793 + struct vm_area_struct *vma_m;
71794 + pmd_t *pmd_m;
71795 + pte_t *pte_m, entry_m;
71796 +
71797 + BUG_ON(!page_m || PageAnon(page_m));
71798 +
71799 + vma_m = pax_find_mirror_vma(vma);
71800 + if (!vma_m)
71801 + return;
71802 +
71803 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71804 + address_m = address + SEGMEXEC_TASK_SIZE;
71805 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71806 + pte_m = pte_offset_map(pmd_m, address_m);
71807 + ptl_m = pte_lockptr(mm, pmd_m);
71808 + if (ptl != ptl_m) {
71809 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71810 + if (!pte_none(*pte_m))
71811 + goto out;
71812 + }
71813 +
71814 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
71815 + page_cache_get(page_m);
71816 + page_add_file_rmap(page_m);
71817 + inc_mm_counter_fast(mm, MM_FILEPAGES);
71818 + set_pte_at(mm, address_m, pte_m, entry_m);
71819 + update_mmu_cache(vma_m, address_m, entry_m);
71820 +out:
71821 + if (ptl != ptl_m)
71822 + spin_unlock(ptl_m);
71823 + pte_unmap(pte_m);
71824 +}
71825 +
71826 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
71827 +{
71828 + struct mm_struct *mm = vma->vm_mm;
71829 + unsigned long address_m;
71830 + spinlock_t *ptl_m;
71831 + struct vm_area_struct *vma_m;
71832 + pmd_t *pmd_m;
71833 + pte_t *pte_m, entry_m;
71834 +
71835 + vma_m = pax_find_mirror_vma(vma);
71836 + if (!vma_m)
71837 + return;
71838 +
71839 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71840 + address_m = address + SEGMEXEC_TASK_SIZE;
71841 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71842 + pte_m = pte_offset_map(pmd_m, address_m);
71843 + ptl_m = pte_lockptr(mm, pmd_m);
71844 + if (ptl != ptl_m) {
71845 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71846 + if (!pte_none(*pte_m))
71847 + goto out;
71848 + }
71849 +
71850 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
71851 + set_pte_at(mm, address_m, pte_m, entry_m);
71852 +out:
71853 + if (ptl != ptl_m)
71854 + spin_unlock(ptl_m);
71855 + pte_unmap(pte_m);
71856 +}
71857 +
71858 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
71859 +{
71860 + struct page *page_m;
71861 + pte_t entry;
71862 +
71863 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
71864 + goto out;
71865 +
71866 + entry = *pte;
71867 + page_m = vm_normal_page(vma, address, entry);
71868 + if (!page_m)
71869 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
71870 + else if (PageAnon(page_m)) {
71871 + if (pax_find_mirror_vma(vma)) {
71872 + pte_unmap_unlock(pte, ptl);
71873 + lock_page(page_m);
71874 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
71875 + if (pte_same(entry, *pte))
71876 + pax_mirror_anon_pte(vma, address, page_m, ptl);
71877 + else
71878 + unlock_page(page_m);
71879 + }
71880 + } else
71881 + pax_mirror_file_pte(vma, address, page_m, ptl);
71882 +
71883 +out:
71884 + pte_unmap_unlock(pte, ptl);
71885 +}
71886 +#endif
71887 +
71888 /*
71889 * This routine handles present pages, when users try to write
71890 * to a shared page. It is done by copying the page to a new address
71891 @@ -2444,6 +2637,12 @@ gotten:
71892 */
71893 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
71894 if (likely(pte_same(*page_table, orig_pte))) {
71895 +
71896 +#ifdef CONFIG_PAX_SEGMEXEC
71897 + if (pax_find_mirror_vma(vma))
71898 + BUG_ON(!trylock_page(new_page));
71899 +#endif
71900 +
71901 if (old_page) {
71902 if (!PageAnon(old_page)) {
71903 dec_mm_counter_fast(mm, MM_FILEPAGES);
71904 @@ -2495,6 +2694,10 @@ gotten:
71905 page_remove_rmap(old_page);
71906 }
71907
71908 +#ifdef CONFIG_PAX_SEGMEXEC
71909 + pax_mirror_anon_pte(vma, address, new_page, ptl);
71910 +#endif
71911 +
71912 /* Free the old page.. */
71913 new_page = old_page;
71914 ret |= VM_FAULT_WRITE;
71915 @@ -2905,6 +3108,11 @@ static int do_swap_page(struct mm_struct
71916 swap_free(entry);
71917 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
71918 try_to_free_swap(page);
71919 +
71920 +#ifdef CONFIG_PAX_SEGMEXEC
71921 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
71922 +#endif
71923 +
71924 unlock_page(page);
71925 if (swapcache) {
71926 /*
71927 @@ -2928,6 +3136,11 @@ static int do_swap_page(struct mm_struct
71928
71929 /* No need to invalidate - it was non-present before */
71930 update_mmu_cache(vma, address, page_table);
71931 +
71932 +#ifdef CONFIG_PAX_SEGMEXEC
71933 + pax_mirror_anon_pte(vma, address, page, ptl);
71934 +#endif
71935 +
71936 unlock:
71937 pte_unmap_unlock(page_table, ptl);
71938 out:
71939 @@ -2947,40 +3160,6 @@ out_release:
71940 }
71941
71942 /*
71943 - * This is like a special single-page "expand_{down|up}wards()",
71944 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
71945 - * doesn't hit another vma.
71946 - */
71947 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
71948 -{
71949 - address &= PAGE_MASK;
71950 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
71951 - struct vm_area_struct *prev = vma->vm_prev;
71952 -
71953 - /*
71954 - * Is there a mapping abutting this one below?
71955 - *
71956 - * That's only ok if it's the same stack mapping
71957 - * that has gotten split..
71958 - */
71959 - if (prev && prev->vm_end == address)
71960 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
71961 -
71962 - expand_stack(vma, address - PAGE_SIZE);
71963 - }
71964 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
71965 - struct vm_area_struct *next = vma->vm_next;
71966 -
71967 - /* As VM_GROWSDOWN but s/below/above/ */
71968 - if (next && next->vm_start == address + PAGE_SIZE)
71969 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
71970 -
71971 - expand_upwards(vma, address + PAGE_SIZE);
71972 - }
71973 - return 0;
71974 -}
71975 -
71976 -/*
71977 * We enter with non-exclusive mmap_sem (to exclude vma changes,
71978 * but allow concurrent faults), and pte mapped but not yet locked.
71979 * We return with mmap_sem still held, but pte unmapped and unlocked.
71980 @@ -2989,27 +3168,23 @@ static int do_anonymous_page(struct mm_s
71981 unsigned long address, pte_t *page_table, pmd_t *pmd,
71982 unsigned int flags)
71983 {
71984 - struct page *page;
71985 + struct page *page = NULL;
71986 spinlock_t *ptl;
71987 pte_t entry;
71988
71989 - pte_unmap(page_table);
71990 -
71991 - /* Check if we need to add a guard page to the stack */
71992 - if (check_stack_guard_page(vma, address) < 0)
71993 - return VM_FAULT_SIGBUS;
71994 -
71995 - /* Use the zero-page for reads */
71996 if (!(flags & FAULT_FLAG_WRITE)) {
71997 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
71998 vma->vm_page_prot));
71999 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72000 + ptl = pte_lockptr(mm, pmd);
72001 + spin_lock(ptl);
72002 if (!pte_none(*page_table))
72003 goto unlock;
72004 goto setpte;
72005 }
72006
72007 /* Allocate our own private page. */
72008 + pte_unmap(page_table);
72009 +
72010 if (unlikely(anon_vma_prepare(vma)))
72011 goto oom;
72012 page = alloc_zeroed_user_highpage_movable(vma, address);
72013 @@ -3028,6 +3203,11 @@ static int do_anonymous_page(struct mm_s
72014 if (!pte_none(*page_table))
72015 goto release;
72016
72017 +#ifdef CONFIG_PAX_SEGMEXEC
72018 + if (pax_find_mirror_vma(vma))
72019 + BUG_ON(!trylock_page(page));
72020 +#endif
72021 +
72022 inc_mm_counter_fast(mm, MM_ANONPAGES);
72023 page_add_new_anon_rmap(page, vma, address);
72024 setpte:
72025 @@ -3035,6 +3215,12 @@ setpte:
72026
72027 /* No need to invalidate - it was non-present before */
72028 update_mmu_cache(vma, address, page_table);
72029 +
72030 +#ifdef CONFIG_PAX_SEGMEXEC
72031 + if (page)
72032 + pax_mirror_anon_pte(vma, address, page, ptl);
72033 +#endif
72034 +
72035 unlock:
72036 pte_unmap_unlock(page_table, ptl);
72037 return 0;
72038 @@ -3172,6 +3358,12 @@ static int __do_fault(struct mm_struct *
72039 */
72040 /* Only go through if we didn't race with anybody else... */
72041 if (likely(pte_same(*page_table, orig_pte))) {
72042 +
72043 +#ifdef CONFIG_PAX_SEGMEXEC
72044 + if (anon && pax_find_mirror_vma(vma))
72045 + BUG_ON(!trylock_page(page));
72046 +#endif
72047 +
72048 flush_icache_page(vma, page);
72049 entry = mk_pte(page, vma->vm_page_prot);
72050 if (flags & FAULT_FLAG_WRITE)
72051 @@ -3191,6 +3383,14 @@ static int __do_fault(struct mm_struct *
72052
72053 /* no need to invalidate: a not-present page won't be cached */
72054 update_mmu_cache(vma, address, page_table);
72055 +
72056 +#ifdef CONFIG_PAX_SEGMEXEC
72057 + if (anon)
72058 + pax_mirror_anon_pte(vma, address, page, ptl);
72059 + else
72060 + pax_mirror_file_pte(vma, address, page, ptl);
72061 +#endif
72062 +
72063 } else {
72064 if (charged)
72065 mem_cgroup_uncharge_page(page);
72066 @@ -3338,6 +3538,12 @@ int handle_pte_fault(struct mm_struct *m
72067 if (flags & FAULT_FLAG_WRITE)
72068 flush_tlb_fix_spurious_fault(vma, address);
72069 }
72070 +
72071 +#ifdef CONFIG_PAX_SEGMEXEC
72072 + pax_mirror_pte(vma, address, pte, pmd, ptl);
72073 + return 0;
72074 +#endif
72075 +
72076 unlock:
72077 pte_unmap_unlock(pte, ptl);
72078 return 0;
72079 @@ -3354,6 +3560,10 @@ int handle_mm_fault(struct mm_struct *mm
72080 pmd_t *pmd;
72081 pte_t *pte;
72082
72083 +#ifdef CONFIG_PAX_SEGMEXEC
72084 + struct vm_area_struct *vma_m;
72085 +#endif
72086 +
72087 __set_current_state(TASK_RUNNING);
72088
72089 count_vm_event(PGFAULT);
72090 @@ -3364,6 +3574,34 @@ int handle_mm_fault(struct mm_struct *mm
72091 if (unlikely(is_vm_hugetlb_page(vma)))
72092 return hugetlb_fault(mm, vma, address, flags);
72093
72094 +#ifdef CONFIG_PAX_SEGMEXEC
72095 + vma_m = pax_find_mirror_vma(vma);
72096 + if (vma_m) {
72097 + unsigned long address_m;
72098 + pgd_t *pgd_m;
72099 + pud_t *pud_m;
72100 + pmd_t *pmd_m;
72101 +
72102 + if (vma->vm_start > vma_m->vm_start) {
72103 + address_m = address;
72104 + address -= SEGMEXEC_TASK_SIZE;
72105 + vma = vma_m;
72106 + } else
72107 + address_m = address + SEGMEXEC_TASK_SIZE;
72108 +
72109 + pgd_m = pgd_offset(mm, address_m);
72110 + pud_m = pud_alloc(mm, pgd_m, address_m);
72111 + if (!pud_m)
72112 + return VM_FAULT_OOM;
72113 + pmd_m = pmd_alloc(mm, pud_m, address_m);
72114 + if (!pmd_m)
72115 + return VM_FAULT_OOM;
72116 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
72117 + return VM_FAULT_OOM;
72118 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
72119 + }
72120 +#endif
72121 +
72122 pgd = pgd_offset(mm, address);
72123 pud = pud_alloc(mm, pgd, address);
72124 if (!pud)
72125 @@ -3393,7 +3631,7 @@ int handle_mm_fault(struct mm_struct *mm
72126 * run pte_offset_map on the pmd, if an huge pmd could
72127 * materialize from under us from a different thread.
72128 */
72129 - if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
72130 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
72131 return VM_FAULT_OOM;
72132 /* if an huge pmd materialized from under us just retry later */
72133 if (unlikely(pmd_trans_huge(*pmd)))
72134 @@ -3497,7 +3735,7 @@ static int __init gate_vma_init(void)
72135 gate_vma.vm_start = FIXADDR_USER_START;
72136 gate_vma.vm_end = FIXADDR_USER_END;
72137 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
72138 - gate_vma.vm_page_prot = __P101;
72139 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
72140 /*
72141 * Make sure the vDSO gets into every core dump.
72142 * Dumping its contents makes post-mortem fully interpretable later
72143 diff -urNp linux-2.6.39/mm/memory-failure.c linux-2.6.39/mm/memory-failure.c
72144 --- linux-2.6.39/mm/memory-failure.c 2011-05-19 00:06:34.000000000 -0400
72145 +++ linux-2.6.39/mm/memory-failure.c 2011-05-22 19:36:33.000000000 -0400
72146 @@ -58,7 +58,7 @@ int sysctl_memory_failure_early_kill __r
72147
72148 int sysctl_memory_failure_recovery __read_mostly = 1;
72149
72150 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
72151 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
72152
72153 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
72154
72155 @@ -1012,7 +1012,7 @@ int __memory_failure(unsigned long pfn,
72156 }
72157
72158 nr_pages = 1 << compound_trans_order(hpage);
72159 - atomic_long_add(nr_pages, &mce_bad_pages);
72160 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
72161
72162 /*
72163 * We need/can do nothing about count=0 pages.
72164 @@ -1042,7 +1042,7 @@ int __memory_failure(unsigned long pfn,
72165 if (!PageHWPoison(hpage)
72166 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
72167 || (p != hpage && TestSetPageHWPoison(hpage))) {
72168 - atomic_long_sub(nr_pages, &mce_bad_pages);
72169 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72170 return 0;
72171 }
72172 set_page_hwpoison_huge_page(hpage);
72173 @@ -1100,7 +1100,7 @@ int __memory_failure(unsigned long pfn,
72174 }
72175 if (hwpoison_filter(p)) {
72176 if (TestClearPageHWPoison(p))
72177 - atomic_long_sub(nr_pages, &mce_bad_pages);
72178 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72179 unlock_page(hpage);
72180 put_page(hpage);
72181 return 0;
72182 @@ -1226,7 +1226,7 @@ int unpoison_memory(unsigned long pfn)
72183 return 0;
72184 }
72185 if (TestClearPageHWPoison(p))
72186 - atomic_long_sub(nr_pages, &mce_bad_pages);
72187 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72188 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
72189 return 0;
72190 }
72191 @@ -1240,7 +1240,7 @@ int unpoison_memory(unsigned long pfn)
72192 */
72193 if (TestClearPageHWPoison(page)) {
72194 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
72195 - atomic_long_sub(nr_pages, &mce_bad_pages);
72196 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72197 freeit = 1;
72198 if (PageHuge(page))
72199 clear_page_hwpoison_huge_page(page);
72200 @@ -1353,7 +1353,7 @@ static int soft_offline_huge_page(struct
72201 }
72202 done:
72203 if (!PageHWPoison(hpage))
72204 - atomic_long_add(1 << compound_trans_order(hpage), &mce_bad_pages);
72205 + atomic_long_add_unchecked(1 << compound_trans_order(hpage), &mce_bad_pages);
72206 set_page_hwpoison_huge_page(hpage);
72207 dequeue_hwpoisoned_huge_page(hpage);
72208 /* keep elevated page count for bad page */
72209 @@ -1482,7 +1482,7 @@ int soft_offline_page(struct page *page,
72210 return ret;
72211
72212 done:
72213 - atomic_long_add(1, &mce_bad_pages);
72214 + atomic_long_add_unchecked(1, &mce_bad_pages);
72215 SetPageHWPoison(page);
72216 /* keep elevated page count for bad page */
72217 return ret;
72218 diff -urNp linux-2.6.39/mm/mempolicy.c linux-2.6.39/mm/mempolicy.c
72219 --- linux-2.6.39/mm/mempolicy.c 2011-05-19 00:06:34.000000000 -0400
72220 +++ linux-2.6.39/mm/mempolicy.c 2011-05-22 19:41:42.000000000 -0400
72221 @@ -643,6 +643,10 @@ static int mbind_range(struct mm_struct
72222 unsigned long vmstart;
72223 unsigned long vmend;
72224
72225 +#ifdef CONFIG_PAX_SEGMEXEC
72226 + struct vm_area_struct *vma_m;
72227 +#endif
72228 +
72229 vma = find_vma_prev(mm, start, &prev);
72230 if (!vma || vma->vm_start > start)
72231 return -EFAULT;
72232 @@ -673,6 +677,16 @@ static int mbind_range(struct mm_struct
72233 err = policy_vma(vma, new_pol);
72234 if (err)
72235 goto out;
72236 +
72237 +#ifdef CONFIG_PAX_SEGMEXEC
72238 + vma_m = pax_find_mirror_vma(vma);
72239 + if (vma_m) {
72240 + err = policy_vma(vma_m, new_pol);
72241 + if (err)
72242 + goto out;
72243 + }
72244 +#endif
72245 +
72246 }
72247
72248 out:
72249 @@ -1106,6 +1120,17 @@ static long do_mbind(unsigned long start
72250
72251 if (end < start)
72252 return -EINVAL;
72253 +
72254 +#ifdef CONFIG_PAX_SEGMEXEC
72255 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
72256 + if (end > SEGMEXEC_TASK_SIZE)
72257 + return -EINVAL;
72258 + } else
72259 +#endif
72260 +
72261 + if (end > TASK_SIZE)
72262 + return -EINVAL;
72263 +
72264 if (end == start)
72265 return 0;
72266
72267 @@ -1324,6 +1349,14 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pi
72268 if (!mm)
72269 goto out;
72270
72271 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
72272 + if (mm != current->mm &&
72273 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
72274 + err = -EPERM;
72275 + goto out;
72276 + }
72277 +#endif
72278 +
72279 /*
72280 * Check if this process has the right to modify the specified
72281 * process. The right exists if the process has administrative
72282 @@ -1333,8 +1366,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pi
72283 rcu_read_lock();
72284 tcred = __task_cred(task);
72285 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
72286 - cred->uid != tcred->suid && cred->uid != tcred->uid &&
72287 - !capable(CAP_SYS_NICE)) {
72288 + cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
72289 rcu_read_unlock();
72290 err = -EPERM;
72291 goto out;
72292 @@ -2634,7 +2666,7 @@ int show_numa_map(struct seq_file *m, vo
72293
72294 if (file) {
72295 seq_printf(m, " file=");
72296 - seq_path(m, &file->f_path, "\n\t= ");
72297 + seq_path(m, &file->f_path, "\n\t\\= ");
72298 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
72299 seq_printf(m, " heap");
72300 } else if (vma->vm_start <= mm->start_stack &&
72301 diff -urNp linux-2.6.39/mm/migrate.c linux-2.6.39/mm/migrate.c
72302 --- linux-2.6.39/mm/migrate.c 2011-05-19 00:06:34.000000000 -0400
72303 +++ linux-2.6.39/mm/migrate.c 2011-05-22 19:41:42.000000000 -0400
72304 @@ -1133,6 +1133,8 @@ static int do_pages_move(struct mm_struc
72305 unsigned long chunk_start;
72306 int err;
72307
72308 + pax_track_stack();
72309 +
72310 task_nodes = cpuset_mems_allowed(task);
72311
72312 err = -ENOMEM;
72313 @@ -1317,6 +1319,14 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid,
72314 if (!mm)
72315 return -EINVAL;
72316
72317 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
72318 + if (mm != current->mm &&
72319 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
72320 + err = -EPERM;
72321 + goto out;
72322 + }
72323 +#endif
72324 +
72325 /*
72326 * Check if this process has the right to modify the specified
72327 * process. The right exists if the process has administrative
72328 @@ -1326,8 +1336,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid,
72329 rcu_read_lock();
72330 tcred = __task_cred(task);
72331 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
72332 - cred->uid != tcred->suid && cred->uid != tcred->uid &&
72333 - !capable(CAP_SYS_NICE)) {
72334 + cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
72335 rcu_read_unlock();
72336 err = -EPERM;
72337 goto out;
72338 diff -urNp linux-2.6.39/mm/mlock.c linux-2.6.39/mm/mlock.c
72339 --- linux-2.6.39/mm/mlock.c 2011-05-19 00:06:34.000000000 -0400
72340 +++ linux-2.6.39/mm/mlock.c 2011-05-22 19:41:42.000000000 -0400
72341 @@ -13,6 +13,7 @@
72342 #include <linux/pagemap.h>
72343 #include <linux/mempolicy.h>
72344 #include <linux/syscalls.h>
72345 +#include <linux/security.h>
72346 #include <linux/sched.h>
72347 #include <linux/module.h>
72348 #include <linux/rmap.h>
72349 @@ -377,6 +378,9 @@ static int do_mlock(unsigned long start,
72350 return -EINVAL;
72351 if (end == start)
72352 return 0;
72353 + if (end > TASK_SIZE)
72354 + return -EINVAL;
72355 +
72356 vma = find_vma_prev(current->mm, start, &prev);
72357 if (!vma || vma->vm_start > start)
72358 return -ENOMEM;
72359 @@ -387,6 +391,11 @@ static int do_mlock(unsigned long start,
72360 for (nstart = start ; ; ) {
72361 unsigned int newflags;
72362
72363 +#ifdef CONFIG_PAX_SEGMEXEC
72364 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
72365 + break;
72366 +#endif
72367 +
72368 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
72369
72370 newflags = vma->vm_flags | VM_LOCKED;
72371 @@ -492,6 +501,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, st
72372 lock_limit >>= PAGE_SHIFT;
72373
72374 /* check against resource limits */
72375 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
72376 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
72377 error = do_mlock(start, len, 1);
72378 up_write(&current->mm->mmap_sem);
72379 @@ -515,17 +525,23 @@ SYSCALL_DEFINE2(munlock, unsigned long,
72380 static int do_mlockall(int flags)
72381 {
72382 struct vm_area_struct * vma, * prev = NULL;
72383 - unsigned int def_flags = 0;
72384
72385 if (flags & MCL_FUTURE)
72386 - def_flags = VM_LOCKED;
72387 - current->mm->def_flags = def_flags;
72388 + current->mm->def_flags |= VM_LOCKED;
72389 + else
72390 + current->mm->def_flags &= ~VM_LOCKED;
72391 if (flags == MCL_FUTURE)
72392 goto out;
72393
72394 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
72395 - unsigned int newflags;
72396 + unsigned long newflags;
72397 +
72398 +#ifdef CONFIG_PAX_SEGMEXEC
72399 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
72400 + break;
72401 +#endif
72402
72403 + BUG_ON(vma->vm_end > TASK_SIZE);
72404 newflags = vma->vm_flags | VM_LOCKED;
72405 if (!(flags & MCL_CURRENT))
72406 newflags &= ~VM_LOCKED;
72407 @@ -557,6 +573,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
72408 lock_limit >>= PAGE_SHIFT;
72409
72410 ret = -ENOMEM;
72411 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
72412 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
72413 capable(CAP_IPC_LOCK))
72414 ret = do_mlockall(flags);
72415 diff -urNp linux-2.6.39/mm/mmap.c linux-2.6.39/mm/mmap.c
72416 --- linux-2.6.39/mm/mmap.c 2011-05-19 00:06:34.000000000 -0400
72417 +++ linux-2.6.39/mm/mmap.c 2011-05-22 19:41:42.000000000 -0400
72418 @@ -46,6 +46,16 @@
72419 #define arch_rebalance_pgtables(addr, len) (addr)
72420 #endif
72421
72422 +static inline void verify_mm_writelocked(struct mm_struct *mm)
72423 +{
72424 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
72425 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
72426 + up_read(&mm->mmap_sem);
72427 + BUG();
72428 + }
72429 +#endif
72430 +}
72431 +
72432 static void unmap_region(struct mm_struct *mm,
72433 struct vm_area_struct *vma, struct vm_area_struct *prev,
72434 unsigned long start, unsigned long end);
72435 @@ -71,22 +81,32 @@ static void unmap_region(struct mm_struc
72436 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
72437 *
72438 */
72439 -pgprot_t protection_map[16] = {
72440 +pgprot_t protection_map[16] __read_only = {
72441 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
72442 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
72443 };
72444
72445 pgprot_t vm_get_page_prot(unsigned long vm_flags)
72446 {
72447 - return __pgprot(pgprot_val(protection_map[vm_flags &
72448 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
72449 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
72450 pgprot_val(arch_vm_get_page_prot(vm_flags)));
72451 +
72452 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72453 + if (!(__supported_pte_mask & _PAGE_NX) &&
72454 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
72455 + (vm_flags & (VM_READ | VM_WRITE)))
72456 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
72457 +#endif
72458 +
72459 + return prot;
72460 }
72461 EXPORT_SYMBOL(vm_get_page_prot);
72462
72463 int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
72464 int sysctl_overcommit_ratio = 50; /* default is 50% */
72465 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
72466 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
72467 struct percpu_counter vm_committed_as;
72468
72469 /*
72470 @@ -232,6 +252,7 @@ static struct vm_area_struct *remove_vma
72471 struct vm_area_struct *next = vma->vm_next;
72472
72473 might_sleep();
72474 + BUG_ON(vma->vm_mirror);
72475 if (vma->vm_ops && vma->vm_ops->close)
72476 vma->vm_ops->close(vma);
72477 if (vma->vm_file) {
72478 @@ -276,6 +297,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
72479 * not page aligned -Ram Gupta
72480 */
72481 rlim = rlimit(RLIMIT_DATA);
72482 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
72483 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
72484 (mm->end_data - mm->start_data) > rlim)
72485 goto out;
72486 @@ -719,6 +741,12 @@ static int
72487 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
72488 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
72489 {
72490 +
72491 +#ifdef CONFIG_PAX_SEGMEXEC
72492 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
72493 + return 0;
72494 +#endif
72495 +
72496 if (is_mergeable_vma(vma, file, vm_flags) &&
72497 is_mergeable_anon_vma(anon_vma, vma->anon_vma)) {
72498 if (vma->vm_pgoff == vm_pgoff)
72499 @@ -738,6 +766,12 @@ static int
72500 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
72501 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
72502 {
72503 +
72504 +#ifdef CONFIG_PAX_SEGMEXEC
72505 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
72506 + return 0;
72507 +#endif
72508 +
72509 if (is_mergeable_vma(vma, file, vm_flags) &&
72510 is_mergeable_anon_vma(anon_vma, vma->anon_vma)) {
72511 pgoff_t vm_pglen;
72512 @@ -780,13 +814,20 @@ can_vma_merge_after(struct vm_area_struc
72513 struct vm_area_struct *vma_merge(struct mm_struct *mm,
72514 struct vm_area_struct *prev, unsigned long addr,
72515 unsigned long end, unsigned long vm_flags,
72516 - struct anon_vma *anon_vma, struct file *file,
72517 + struct anon_vma *anon_vma, struct file *file,
72518 pgoff_t pgoff, struct mempolicy *policy)
72519 {
72520 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
72521 struct vm_area_struct *area, *next;
72522 int err;
72523
72524 +#ifdef CONFIG_PAX_SEGMEXEC
72525 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
72526 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
72527 +
72528 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
72529 +#endif
72530 +
72531 /*
72532 * We later require that vma->vm_flags == vm_flags,
72533 * so this tests vma->vm_flags & VM_SPECIAL, too.
72534 @@ -802,6 +843,15 @@ struct vm_area_struct *vma_merge(struct
72535 if (next && next->vm_end == end) /* cases 6, 7, 8 */
72536 next = next->vm_next;
72537
72538 +#ifdef CONFIG_PAX_SEGMEXEC
72539 + if (prev)
72540 + prev_m = pax_find_mirror_vma(prev);
72541 + if (area)
72542 + area_m = pax_find_mirror_vma(area);
72543 + if (next)
72544 + next_m = pax_find_mirror_vma(next);
72545 +#endif
72546 +
72547 /*
72548 * Can it merge with the predecessor?
72549 */
72550 @@ -821,9 +871,24 @@ struct vm_area_struct *vma_merge(struct
72551 /* cases 1, 6 */
72552 err = vma_adjust(prev, prev->vm_start,
72553 next->vm_end, prev->vm_pgoff, NULL);
72554 - } else /* cases 2, 5, 7 */
72555 +
72556 +#ifdef CONFIG_PAX_SEGMEXEC
72557 + if (!err && prev_m)
72558 + err = vma_adjust(prev_m, prev_m->vm_start,
72559 + next_m->vm_end, prev_m->vm_pgoff, NULL);
72560 +#endif
72561 +
72562 + } else { /* cases 2, 5, 7 */
72563 err = vma_adjust(prev, prev->vm_start,
72564 end, prev->vm_pgoff, NULL);
72565 +
72566 +#ifdef CONFIG_PAX_SEGMEXEC
72567 + if (!err && prev_m)
72568 + err = vma_adjust(prev_m, prev_m->vm_start,
72569 + end_m, prev_m->vm_pgoff, NULL);
72570 +#endif
72571 +
72572 + }
72573 if (err)
72574 return NULL;
72575 khugepaged_enter_vma_merge(prev);
72576 @@ -837,12 +902,27 @@ struct vm_area_struct *vma_merge(struct
72577 mpol_equal(policy, vma_policy(next)) &&
72578 can_vma_merge_before(next, vm_flags,
72579 anon_vma, file, pgoff+pglen)) {
72580 - if (prev && addr < prev->vm_end) /* case 4 */
72581 + if (prev && addr < prev->vm_end) { /* case 4 */
72582 err = vma_adjust(prev, prev->vm_start,
72583 addr, prev->vm_pgoff, NULL);
72584 - else /* cases 3, 8 */
72585 +
72586 +#ifdef CONFIG_PAX_SEGMEXEC
72587 + if (!err && prev_m)
72588 + err = vma_adjust(prev_m, prev_m->vm_start,
72589 + addr_m, prev_m->vm_pgoff, NULL);
72590 +#endif
72591 +
72592 + } else { /* cases 3, 8 */
72593 err = vma_adjust(area, addr, next->vm_end,
72594 next->vm_pgoff - pglen, NULL);
72595 +
72596 +#ifdef CONFIG_PAX_SEGMEXEC
72597 + if (!err && area_m)
72598 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
72599 + next_m->vm_pgoff - pglen, NULL);
72600 +#endif
72601 +
72602 + }
72603 if (err)
72604 return NULL;
72605 khugepaged_enter_vma_merge(area);
72606 @@ -958,14 +1038,11 @@ none:
72607 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
72608 struct file *file, long pages)
72609 {
72610 - const unsigned long stack_flags
72611 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
72612 -
72613 if (file) {
72614 mm->shared_vm += pages;
72615 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
72616 mm->exec_vm += pages;
72617 - } else if (flags & stack_flags)
72618 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
72619 mm->stack_vm += pages;
72620 if (flags & (VM_RESERVED|VM_IO))
72621 mm->reserved_vm += pages;
72622 @@ -992,7 +1069,7 @@ unsigned long do_mmap_pgoff(struct file
72623 * (the exception is when the underlying filesystem is noexec
72624 * mounted, in which case we dont add PROT_EXEC.)
72625 */
72626 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
72627 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
72628 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
72629 prot |= PROT_EXEC;
72630
72631 @@ -1018,7 +1095,7 @@ unsigned long do_mmap_pgoff(struct file
72632 /* Obtain the address to map to. we verify (or select) it and ensure
72633 * that it represents a valid section of the address space.
72634 */
72635 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
72636 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
72637 if (addr & ~PAGE_MASK)
72638 return addr;
72639
72640 @@ -1029,6 +1106,36 @@ unsigned long do_mmap_pgoff(struct file
72641 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
72642 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
72643
72644 +#ifdef CONFIG_PAX_MPROTECT
72645 + if (mm->pax_flags & MF_PAX_MPROTECT) {
72646 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
72647 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
72648 + gr_log_rwxmmap(file);
72649 +
72650 +#ifdef CONFIG_PAX_EMUPLT
72651 + vm_flags &= ~VM_EXEC;
72652 +#else
72653 + return -EPERM;
72654 +#endif
72655 +
72656 + }
72657 +
72658 + if (!(vm_flags & VM_EXEC))
72659 + vm_flags &= ~VM_MAYEXEC;
72660 +#else
72661 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
72662 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
72663 +#endif
72664 + else
72665 + vm_flags &= ~VM_MAYWRITE;
72666 + }
72667 +#endif
72668 +
72669 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72670 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
72671 + vm_flags &= ~VM_PAGEEXEC;
72672 +#endif
72673 +
72674 if (flags & MAP_LOCKED)
72675 if (!can_do_mlock())
72676 return -EPERM;
72677 @@ -1040,6 +1147,7 @@ unsigned long do_mmap_pgoff(struct file
72678 locked += mm->locked_vm;
72679 lock_limit = rlimit(RLIMIT_MEMLOCK);
72680 lock_limit >>= PAGE_SHIFT;
72681 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
72682 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
72683 return -EAGAIN;
72684 }
72685 @@ -1110,6 +1218,9 @@ unsigned long do_mmap_pgoff(struct file
72686 if (error)
72687 return error;
72688
72689 + if (!gr_acl_handle_mmap(file, prot))
72690 + return -EACCES;
72691 +
72692 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
72693 }
72694 EXPORT_SYMBOL(do_mmap_pgoff);
72695 @@ -1187,10 +1298,10 @@ SYSCALL_DEFINE1(old_mmap, struct mmap_ar
72696 */
72697 int vma_wants_writenotify(struct vm_area_struct *vma)
72698 {
72699 - unsigned int vm_flags = vma->vm_flags;
72700 + unsigned long vm_flags = vma->vm_flags;
72701
72702 /* If it was private or non-writable, the write bit is already clear */
72703 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
72704 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
72705 return 0;
72706
72707 /* The backer wishes to know when pages are first written to? */
72708 @@ -1239,14 +1350,24 @@ unsigned long mmap_region(struct file *f
72709 unsigned long charged = 0;
72710 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
72711
72712 +#ifdef CONFIG_PAX_SEGMEXEC
72713 + struct vm_area_struct *vma_m = NULL;
72714 +#endif
72715 +
72716 + /*
72717 + * mm->mmap_sem is required to protect against another thread
72718 + * changing the mappings in case we sleep.
72719 + */
72720 + verify_mm_writelocked(mm);
72721 +
72722 /* Clear old maps */
72723 error = -ENOMEM;
72724 -munmap_back:
72725 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72726 if (vma && vma->vm_start < addr + len) {
72727 if (do_munmap(mm, addr, len))
72728 return -ENOMEM;
72729 - goto munmap_back;
72730 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72731 + BUG_ON(vma && vma->vm_start < addr + len);
72732 }
72733
72734 /* Check against address space limit. */
72735 @@ -1295,6 +1416,16 @@ munmap_back:
72736 goto unacct_error;
72737 }
72738
72739 +#ifdef CONFIG_PAX_SEGMEXEC
72740 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
72741 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72742 + if (!vma_m) {
72743 + error = -ENOMEM;
72744 + goto free_vma;
72745 + }
72746 + }
72747 +#endif
72748 +
72749 vma->vm_mm = mm;
72750 vma->vm_start = addr;
72751 vma->vm_end = addr + len;
72752 @@ -1318,6 +1449,19 @@ munmap_back:
72753 error = file->f_op->mmap(file, vma);
72754 if (error)
72755 goto unmap_and_free_vma;
72756 +
72757 +#ifdef CONFIG_PAX_SEGMEXEC
72758 + if (vma_m && (vm_flags & VM_EXECUTABLE))
72759 + added_exe_file_vma(mm);
72760 +#endif
72761 +
72762 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72763 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
72764 + vma->vm_flags |= VM_PAGEEXEC;
72765 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
72766 + }
72767 +#endif
72768 +
72769 if (vm_flags & VM_EXECUTABLE)
72770 added_exe_file_vma(mm);
72771
72772 @@ -1353,6 +1497,11 @@ munmap_back:
72773 vma_link(mm, vma, prev, rb_link, rb_parent);
72774 file = vma->vm_file;
72775
72776 +#ifdef CONFIG_PAX_SEGMEXEC
72777 + if (vma_m)
72778 + BUG_ON(pax_mirror_vma(vma_m, vma));
72779 +#endif
72780 +
72781 /* Once vma denies write, undo our temporary denial count */
72782 if (correct_wcount)
72783 atomic_inc(&inode->i_writecount);
72784 @@ -1361,6 +1510,7 @@ out:
72785
72786 mm->total_vm += len >> PAGE_SHIFT;
72787 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
72788 + track_exec_limit(mm, addr, addr + len, vm_flags);
72789 if (vm_flags & VM_LOCKED) {
72790 if (!mlock_vma_pages_range(vma, addr, addr + len))
72791 mm->locked_vm += (len >> PAGE_SHIFT);
72792 @@ -1378,6 +1528,12 @@ unmap_and_free_vma:
72793 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
72794 charged = 0;
72795 free_vma:
72796 +
72797 +#ifdef CONFIG_PAX_SEGMEXEC
72798 + if (vma_m)
72799 + kmem_cache_free(vm_area_cachep, vma_m);
72800 +#endif
72801 +
72802 kmem_cache_free(vm_area_cachep, vma);
72803 unacct_error:
72804 if (charged)
72805 @@ -1385,6 +1541,44 @@ unacct_error:
72806 return error;
72807 }
72808
72809 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
72810 +{
72811 + if (!vma) {
72812 +#ifdef CONFIG_STACK_GROWSUP
72813 + if (addr > sysctl_heap_stack_gap)
72814 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
72815 + else
72816 + vma = find_vma(current->mm, 0);
72817 + if (vma && (vma->vm_flags & VM_GROWSUP))
72818 + return false;
72819 +#endif
72820 + return true;
72821 + }
72822 +
72823 + if (addr + len > vma->vm_start)
72824 + return false;
72825 +
72826 + if (vma->vm_flags & VM_GROWSDOWN)
72827 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
72828 +#ifdef CONFIG_STACK_GROWSUP
72829 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
72830 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
72831 +#endif
72832 +
72833 + return true;
72834 +}
72835 +
72836 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
72837 +{
72838 + if (vma->vm_start < len)
72839 + return -ENOMEM;
72840 + if (!(vma->vm_flags & VM_GROWSDOWN))
72841 + return vma->vm_start - len;
72842 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
72843 + return vma->vm_start - len - sysctl_heap_stack_gap;
72844 + return -ENOMEM;
72845 +}
72846 +
72847 /* Get an address range which is currently unmapped.
72848 * For shmat() with addr=0.
72849 *
72850 @@ -1411,18 +1605,23 @@ arch_get_unmapped_area(struct file *filp
72851 if (flags & MAP_FIXED)
72852 return addr;
72853
72854 +#ifdef CONFIG_PAX_RANDMMAP
72855 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
72856 +#endif
72857 +
72858 if (addr) {
72859 addr = PAGE_ALIGN(addr);
72860 - vma = find_vma(mm, addr);
72861 - if (TASK_SIZE - len >= addr &&
72862 - (!vma || addr + len <= vma->vm_start))
72863 - return addr;
72864 + if (TASK_SIZE - len >= addr) {
72865 + vma = find_vma(mm, addr);
72866 + if (check_heap_stack_gap(vma, addr, len))
72867 + return addr;
72868 + }
72869 }
72870 if (len > mm->cached_hole_size) {
72871 - start_addr = addr = mm->free_area_cache;
72872 + start_addr = addr = mm->free_area_cache;
72873 } else {
72874 - start_addr = addr = TASK_UNMAPPED_BASE;
72875 - mm->cached_hole_size = 0;
72876 + start_addr = addr = mm->mmap_base;
72877 + mm->cached_hole_size = 0;
72878 }
72879
72880 full_search:
72881 @@ -1433,34 +1632,40 @@ full_search:
72882 * Start a new search - just in case we missed
72883 * some holes.
72884 */
72885 - if (start_addr != TASK_UNMAPPED_BASE) {
72886 - addr = TASK_UNMAPPED_BASE;
72887 - start_addr = addr;
72888 + if (start_addr != mm->mmap_base) {
72889 + start_addr = addr = mm->mmap_base;
72890 mm->cached_hole_size = 0;
72891 goto full_search;
72892 }
72893 return -ENOMEM;
72894 }
72895 - if (!vma || addr + len <= vma->vm_start) {
72896 - /*
72897 - * Remember the place where we stopped the search:
72898 - */
72899 - mm->free_area_cache = addr + len;
72900 - return addr;
72901 - }
72902 + if (check_heap_stack_gap(vma, addr, len))
72903 + break;
72904 if (addr + mm->cached_hole_size < vma->vm_start)
72905 mm->cached_hole_size = vma->vm_start - addr;
72906 addr = vma->vm_end;
72907 }
72908 +
72909 + /*
72910 + * Remember the place where we stopped the search:
72911 + */
72912 + mm->free_area_cache = addr + len;
72913 + return addr;
72914 }
72915 #endif
72916
72917 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
72918 {
72919 +
72920 +#ifdef CONFIG_PAX_SEGMEXEC
72921 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
72922 + return;
72923 +#endif
72924 +
72925 /*
72926 * Is this a new hole at the lowest possible address?
72927 */
72928 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache) {
72929 + if (addr >= mm->mmap_base && addr < mm->free_area_cache) {
72930 mm->free_area_cache = addr;
72931 mm->cached_hole_size = ~0UL;
72932 }
72933 @@ -1478,7 +1683,7 @@ arch_get_unmapped_area_topdown(struct fi
72934 {
72935 struct vm_area_struct *vma;
72936 struct mm_struct *mm = current->mm;
72937 - unsigned long addr = addr0;
72938 + unsigned long base = mm->mmap_base, addr = addr0;
72939
72940 /* requested length too big for entire address space */
72941 if (len > TASK_SIZE)
72942 @@ -1487,13 +1692,18 @@ arch_get_unmapped_area_topdown(struct fi
72943 if (flags & MAP_FIXED)
72944 return addr;
72945
72946 +#ifdef CONFIG_PAX_RANDMMAP
72947 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
72948 +#endif
72949 +
72950 /* requesting a specific address */
72951 if (addr) {
72952 addr = PAGE_ALIGN(addr);
72953 - vma = find_vma(mm, addr);
72954 - if (TASK_SIZE - len >= addr &&
72955 - (!vma || addr + len <= vma->vm_start))
72956 - return addr;
72957 + if (TASK_SIZE - len >= addr) {
72958 + vma = find_vma(mm, addr);
72959 + if (check_heap_stack_gap(vma, addr, len))
72960 + return addr;
72961 + }
72962 }
72963
72964 /* check if free_area_cache is useful for us */
72965 @@ -1508,7 +1718,7 @@ arch_get_unmapped_area_topdown(struct fi
72966 /* make sure it can fit in the remaining address space */
72967 if (addr > len) {
72968 vma = find_vma(mm, addr-len);
72969 - if (!vma || addr <= vma->vm_start)
72970 + if (check_heap_stack_gap(vma, addr - len, len))
72971 /* remember the address as a hint for next time */
72972 return (mm->free_area_cache = addr-len);
72973 }
72974 @@ -1525,7 +1735,7 @@ arch_get_unmapped_area_topdown(struct fi
72975 * return with success:
72976 */
72977 vma = find_vma(mm, addr);
72978 - if (!vma || addr+len <= vma->vm_start)
72979 + if (check_heap_stack_gap(vma, addr, len))
72980 /* remember the address as a hint for next time */
72981 return (mm->free_area_cache = addr);
72982
72983 @@ -1534,8 +1744,8 @@ arch_get_unmapped_area_topdown(struct fi
72984 mm->cached_hole_size = vma->vm_start - addr;
72985
72986 /* try just below the current vma->vm_start */
72987 - addr = vma->vm_start-len;
72988 - } while (len < vma->vm_start);
72989 + addr = skip_heap_stack_gap(vma, len);
72990 + } while (!IS_ERR_VALUE(addr));
72991
72992 bottomup:
72993 /*
72994 @@ -1544,13 +1754,21 @@ bottomup:
72995 * can happen with large stack limits and large mmap()
72996 * allocations.
72997 */
72998 + mm->mmap_base = TASK_UNMAPPED_BASE;
72999 +
73000 +#ifdef CONFIG_PAX_RANDMMAP
73001 + if (mm->pax_flags & MF_PAX_RANDMMAP)
73002 + mm->mmap_base += mm->delta_mmap;
73003 +#endif
73004 +
73005 + mm->free_area_cache = mm->mmap_base;
73006 mm->cached_hole_size = ~0UL;
73007 - mm->free_area_cache = TASK_UNMAPPED_BASE;
73008 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
73009 /*
73010 * Restore the topdown base:
73011 */
73012 - mm->free_area_cache = mm->mmap_base;
73013 + mm->mmap_base = base;
73014 + mm->free_area_cache = base;
73015 mm->cached_hole_size = ~0UL;
73016
73017 return addr;
73018 @@ -1559,6 +1777,12 @@ bottomup:
73019
73020 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
73021 {
73022 +
73023 +#ifdef CONFIG_PAX_SEGMEXEC
73024 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
73025 + return;
73026 +#endif
73027 +
73028 /*
73029 * Is this a new hole at the highest possible address?
73030 */
73031 @@ -1566,8 +1790,10 @@ void arch_unmap_area_topdown(struct mm_s
73032 mm->free_area_cache = addr;
73033
73034 /* dont allow allocations above current base */
73035 - if (mm->free_area_cache > mm->mmap_base)
73036 + if (mm->free_area_cache > mm->mmap_base) {
73037 mm->free_area_cache = mm->mmap_base;
73038 + mm->cached_hole_size = ~0UL;
73039 + }
73040 }
73041
73042 unsigned long
73043 @@ -1675,6 +1901,28 @@ out:
73044 return prev ? prev->vm_next : vma;
73045 }
73046
73047 +#ifdef CONFIG_PAX_SEGMEXEC
73048 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
73049 +{
73050 + struct vm_area_struct *vma_m;
73051 +
73052 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
73053 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
73054 + BUG_ON(vma->vm_mirror);
73055 + return NULL;
73056 + }
73057 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
73058 + vma_m = vma->vm_mirror;
73059 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
73060 + BUG_ON(vma->vm_file != vma_m->vm_file);
73061 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
73062 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
73063 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
73064 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
73065 + return vma_m;
73066 +}
73067 +#endif
73068 +
73069 /*
73070 * Verify that the stack growth is acceptable and
73071 * update accounting. This is shared with both the
73072 @@ -1691,6 +1939,7 @@ static int acct_stack_growth(struct vm_a
73073 return -ENOMEM;
73074
73075 /* Stack limit test */
73076 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
73077 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
73078 return -ENOMEM;
73079
73080 @@ -1701,6 +1950,7 @@ static int acct_stack_growth(struct vm_a
73081 locked = mm->locked_vm + grow;
73082 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
73083 limit >>= PAGE_SHIFT;
73084 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
73085 if (locked > limit && !capable(CAP_IPC_LOCK))
73086 return -ENOMEM;
73087 }
73088 @@ -1731,37 +1981,48 @@ static int acct_stack_growth(struct vm_a
73089 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
73090 * vma is the last one with address > vma->vm_end. Have to extend vma.
73091 */
73092 +#ifndef CONFIG_IA64
73093 +static
73094 +#endif
73095 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
73096 {
73097 int error;
73098 + bool locknext;
73099
73100 if (!(vma->vm_flags & VM_GROWSUP))
73101 return -EFAULT;
73102
73103 + /* Also guard against wrapping around to address 0. */
73104 + if (address < PAGE_ALIGN(address+1))
73105 + address = PAGE_ALIGN(address+1);
73106 + else
73107 + return -ENOMEM;
73108 +
73109 /*
73110 * We must make sure the anon_vma is allocated
73111 * so that the anon_vma locking is not a noop.
73112 */
73113 if (unlikely(anon_vma_prepare(vma)))
73114 return -ENOMEM;
73115 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
73116 + if (locknext && anon_vma_prepare(vma->vm_next))
73117 + return -ENOMEM;
73118 vma_lock_anon_vma(vma);
73119 + if (locknext)
73120 + vma_lock_anon_vma(vma->vm_next);
73121
73122 /*
73123 * vma->vm_start/vm_end cannot change under us because the caller
73124 * is required to hold the mmap_sem in read mode. We need the
73125 - * anon_vma lock to serialize against concurrent expand_stacks.
73126 - * Also guard against wrapping around to address 0.
73127 + * anon_vma locks to serialize against concurrent expand_stacks
73128 + * and expand_upwards.
73129 */
73130 - if (address < PAGE_ALIGN(address+4))
73131 - address = PAGE_ALIGN(address+4);
73132 - else {
73133 - vma_unlock_anon_vma(vma);
73134 - return -ENOMEM;
73135 - }
73136 error = 0;
73137
73138 /* Somebody else might have raced and expanded it already */
73139 - if (address > vma->vm_end) {
73140 + 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)
73141 + error = -ENOMEM;
73142 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
73143 unsigned long size, grow;
73144
73145 size = address - vma->vm_start;
73146 @@ -1776,6 +2037,8 @@ int expand_upwards(struct vm_area_struct
73147 }
73148 }
73149 }
73150 + if (locknext)
73151 + vma_unlock_anon_vma(vma->vm_next);
73152 vma_unlock_anon_vma(vma);
73153 khugepaged_enter_vma_merge(vma);
73154 return error;
73155 @@ -1789,6 +2052,8 @@ static int expand_downwards(struct vm_ar
73156 unsigned long address)
73157 {
73158 int error;
73159 + bool lockprev = false;
73160 + struct vm_area_struct *prev;
73161
73162 /*
73163 * We must make sure the anon_vma is allocated
73164 @@ -1802,6 +2067,15 @@ static int expand_downwards(struct vm_ar
73165 if (error)
73166 return error;
73167
73168 + prev = vma->vm_prev;
73169 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
73170 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
73171 +#endif
73172 + if (lockprev && anon_vma_prepare(prev))
73173 + return -ENOMEM;
73174 + if (lockprev)
73175 + vma_lock_anon_vma(prev);
73176 +
73177 vma_lock_anon_vma(vma);
73178
73179 /*
73180 @@ -1811,9 +2085,17 @@ static int expand_downwards(struct vm_ar
73181 */
73182
73183 /* Somebody else might have raced and expanded it already */
73184 - if (address < vma->vm_start) {
73185 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
73186 + error = -ENOMEM;
73187 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
73188 unsigned long size, grow;
73189
73190 +#ifdef CONFIG_PAX_SEGMEXEC
73191 + struct vm_area_struct *vma_m;
73192 +
73193 + vma_m = pax_find_mirror_vma(vma);
73194 +#endif
73195 +
73196 size = vma->vm_end - address;
73197 grow = (vma->vm_start - address) >> PAGE_SHIFT;
73198
73199 @@ -1823,11 +2105,22 @@ static int expand_downwards(struct vm_ar
73200 if (!error) {
73201 vma->vm_start = address;
73202 vma->vm_pgoff -= grow;
73203 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
73204 +
73205 +#ifdef CONFIG_PAX_SEGMEXEC
73206 + if (vma_m) {
73207 + vma_m->vm_start -= grow << PAGE_SHIFT;
73208 + vma_m->vm_pgoff -= grow;
73209 + }
73210 +#endif
73211 +
73212 perf_event_mmap(vma);
73213 }
73214 }
73215 }
73216 vma_unlock_anon_vma(vma);
73217 + if (lockprev)
73218 + vma_unlock_anon_vma(prev);
73219 khugepaged_enter_vma_merge(vma);
73220 return error;
73221 }
73222 @@ -1902,6 +2195,13 @@ static void remove_vma_list(struct mm_st
73223 do {
73224 long nrpages = vma_pages(vma);
73225
73226 +#ifdef CONFIG_PAX_SEGMEXEC
73227 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
73228 + vma = remove_vma(vma);
73229 + continue;
73230 + }
73231 +#endif
73232 +
73233 mm->total_vm -= nrpages;
73234 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
73235 vma = remove_vma(vma);
73236 @@ -1947,6 +2247,16 @@ detach_vmas_to_be_unmapped(struct mm_str
73237 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
73238 vma->vm_prev = NULL;
73239 do {
73240 +
73241 +#ifdef CONFIG_PAX_SEGMEXEC
73242 + if (vma->vm_mirror) {
73243 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
73244 + vma->vm_mirror->vm_mirror = NULL;
73245 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
73246 + vma->vm_mirror = NULL;
73247 + }
73248 +#endif
73249 +
73250 rb_erase(&vma->vm_rb, &mm->mm_rb);
73251 mm->map_count--;
73252 tail_vma = vma;
73253 @@ -1975,14 +2285,33 @@ static int __split_vma(struct mm_struct
73254 struct vm_area_struct *new;
73255 int err = -ENOMEM;
73256
73257 +#ifdef CONFIG_PAX_SEGMEXEC
73258 + struct vm_area_struct *vma_m, *new_m = NULL;
73259 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
73260 +#endif
73261 +
73262 if (is_vm_hugetlb_page(vma) && (addr &
73263 ~(huge_page_mask(hstate_vma(vma)))))
73264 return -EINVAL;
73265
73266 +#ifdef CONFIG_PAX_SEGMEXEC
73267 + vma_m = pax_find_mirror_vma(vma);
73268 +#endif
73269 +
73270 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73271 if (!new)
73272 goto out_err;
73273
73274 +#ifdef CONFIG_PAX_SEGMEXEC
73275 + if (vma_m) {
73276 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73277 + if (!new_m) {
73278 + kmem_cache_free(vm_area_cachep, new);
73279 + goto out_err;
73280 + }
73281 + }
73282 +#endif
73283 +
73284 /* most fields are the same, copy all, and then fixup */
73285 *new = *vma;
73286
73287 @@ -1995,6 +2324,22 @@ static int __split_vma(struct mm_struct
73288 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
73289 }
73290
73291 +#ifdef CONFIG_PAX_SEGMEXEC
73292 + if (vma_m) {
73293 + *new_m = *vma_m;
73294 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
73295 + new_m->vm_mirror = new;
73296 + new->vm_mirror = new_m;
73297 +
73298 + if (new_below)
73299 + new_m->vm_end = addr_m;
73300 + else {
73301 + new_m->vm_start = addr_m;
73302 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
73303 + }
73304 + }
73305 +#endif
73306 +
73307 pol = mpol_dup(vma_policy(vma));
73308 if (IS_ERR(pol)) {
73309 err = PTR_ERR(pol);
73310 @@ -2020,6 +2365,42 @@ static int __split_vma(struct mm_struct
73311 else
73312 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
73313
73314 +#ifdef CONFIG_PAX_SEGMEXEC
73315 + if (!err && vma_m) {
73316 + if (anon_vma_clone(new_m, vma_m))
73317 + goto out_free_mpol;
73318 +
73319 + mpol_get(pol);
73320 + vma_set_policy(new_m, pol);
73321 +
73322 + if (new_m->vm_file) {
73323 + get_file(new_m->vm_file);
73324 + if (vma_m->vm_flags & VM_EXECUTABLE)
73325 + added_exe_file_vma(mm);
73326 + }
73327 +
73328 + if (new_m->vm_ops && new_m->vm_ops->open)
73329 + new_m->vm_ops->open(new_m);
73330 +
73331 + if (new_below)
73332 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
73333 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
73334 + else
73335 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
73336 +
73337 + if (err) {
73338 + if (new_m->vm_ops && new_m->vm_ops->close)
73339 + new_m->vm_ops->close(new_m);
73340 + if (new_m->vm_file) {
73341 + if (vma_m->vm_flags & VM_EXECUTABLE)
73342 + removed_exe_file_vma(mm);
73343 + fput(new_m->vm_file);
73344 + }
73345 + mpol_put(pol);
73346 + }
73347 + }
73348 +#endif
73349 +
73350 /* Success. */
73351 if (!err)
73352 return 0;
73353 @@ -2032,10 +2413,18 @@ static int __split_vma(struct mm_struct
73354 removed_exe_file_vma(mm);
73355 fput(new->vm_file);
73356 }
73357 - unlink_anon_vmas(new);
73358 out_free_mpol:
73359 mpol_put(pol);
73360 out_free_vma:
73361 +
73362 +#ifdef CONFIG_PAX_SEGMEXEC
73363 + if (new_m) {
73364 + unlink_anon_vmas(new_m);
73365 + kmem_cache_free(vm_area_cachep, new_m);
73366 + }
73367 +#endif
73368 +
73369 + unlink_anon_vmas(new);
73370 kmem_cache_free(vm_area_cachep, new);
73371 out_err:
73372 return err;
73373 @@ -2048,6 +2437,15 @@ static int __split_vma(struct mm_struct
73374 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73375 unsigned long addr, int new_below)
73376 {
73377 +
73378 +#ifdef CONFIG_PAX_SEGMEXEC
73379 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
73380 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
73381 + if (mm->map_count >= sysctl_max_map_count-1)
73382 + return -ENOMEM;
73383 + } else
73384 +#endif
73385 +
73386 if (mm->map_count >= sysctl_max_map_count)
73387 return -ENOMEM;
73388
73389 @@ -2059,11 +2457,30 @@ int split_vma(struct mm_struct *mm, stru
73390 * work. This now handles partial unmappings.
73391 * Jeremy Fitzhardinge <jeremy@goop.org>
73392 */
73393 +#ifdef CONFIG_PAX_SEGMEXEC
73394 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73395 +{
73396 + int ret = __do_munmap(mm, start, len);
73397 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
73398 + return ret;
73399 +
73400 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
73401 +}
73402 +
73403 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73404 +#else
73405 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73406 +#endif
73407 {
73408 unsigned long end;
73409 struct vm_area_struct *vma, *prev, *last;
73410
73411 + /*
73412 + * mm->mmap_sem is required to protect against another thread
73413 + * changing the mappings in case we sleep.
73414 + */
73415 + verify_mm_writelocked(mm);
73416 +
73417 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
73418 return -EINVAL;
73419
73420 @@ -2137,6 +2554,8 @@ int do_munmap(struct mm_struct *mm, unsi
73421 /* Fix up all other VM information */
73422 remove_vma_list(mm, vma);
73423
73424 + track_exec_limit(mm, start, end, 0UL);
73425 +
73426 return 0;
73427 }
73428
73429 @@ -2149,22 +2568,18 @@ SYSCALL_DEFINE2(munmap, unsigned long, a
73430
73431 profile_munmap(addr);
73432
73433 +#ifdef CONFIG_PAX_SEGMEXEC
73434 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
73435 + (len > SEGMEXEC_TASK_SIZE || addr > SEGMEXEC_TASK_SIZE-len))
73436 + return -EINVAL;
73437 +#endif
73438 +
73439 down_write(&mm->mmap_sem);
73440 ret = do_munmap(mm, addr, len);
73441 up_write(&mm->mmap_sem);
73442 return ret;
73443 }
73444
73445 -static inline void verify_mm_writelocked(struct mm_struct *mm)
73446 -{
73447 -#ifdef CONFIG_DEBUG_VM
73448 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
73449 - WARN_ON(1);
73450 - up_read(&mm->mmap_sem);
73451 - }
73452 -#endif
73453 -}
73454 -
73455 /*
73456 * this is really a simplified "do_mmap". it only handles
73457 * anonymous maps. eventually we may be able to do some
73458 @@ -2178,6 +2593,7 @@ unsigned long do_brk(unsigned long addr,
73459 struct rb_node ** rb_link, * rb_parent;
73460 pgoff_t pgoff = addr >> PAGE_SHIFT;
73461 int error;
73462 + unsigned long charged;
73463
73464 len = PAGE_ALIGN(len);
73465 if (!len)
73466 @@ -2189,16 +2605,30 @@ unsigned long do_brk(unsigned long addr,
73467
73468 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
73469
73470 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
73471 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
73472 + flags &= ~VM_EXEC;
73473 +
73474 +#ifdef CONFIG_PAX_MPROTECT
73475 + if (mm->pax_flags & MF_PAX_MPROTECT)
73476 + flags &= ~VM_MAYEXEC;
73477 +#endif
73478 +
73479 + }
73480 +#endif
73481 +
73482 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
73483 if (error & ~PAGE_MASK)
73484 return error;
73485
73486 + charged = len >> PAGE_SHIFT;
73487 +
73488 /*
73489 * mlock MCL_FUTURE?
73490 */
73491 if (mm->def_flags & VM_LOCKED) {
73492 unsigned long locked, lock_limit;
73493 - locked = len >> PAGE_SHIFT;
73494 + locked = charged;
73495 locked += mm->locked_vm;
73496 lock_limit = rlimit(RLIMIT_MEMLOCK);
73497 lock_limit >>= PAGE_SHIFT;
73498 @@ -2215,22 +2645,22 @@ unsigned long do_brk(unsigned long addr,
73499 /*
73500 * Clear old maps. this also does some error checking for us
73501 */
73502 - munmap_back:
73503 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73504 if (vma && vma->vm_start < addr + len) {
73505 if (do_munmap(mm, addr, len))
73506 return -ENOMEM;
73507 - goto munmap_back;
73508 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73509 + BUG_ON(vma && vma->vm_start < addr + len);
73510 }
73511
73512 /* Check against address space limits *after* clearing old maps... */
73513 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
73514 + if (!may_expand_vm(mm, charged))
73515 return -ENOMEM;
73516
73517 if (mm->map_count > sysctl_max_map_count)
73518 return -ENOMEM;
73519
73520 - if (security_vm_enough_memory(len >> PAGE_SHIFT))
73521 + if (security_vm_enough_memory(charged))
73522 return -ENOMEM;
73523
73524 /* Can we just expand an old private anonymous mapping? */
73525 @@ -2244,7 +2674,7 @@ unsigned long do_brk(unsigned long addr,
73526 */
73527 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73528 if (!vma) {
73529 - vm_unacct_memory(len >> PAGE_SHIFT);
73530 + vm_unacct_memory(charged);
73531 return -ENOMEM;
73532 }
73533
73534 @@ -2258,11 +2688,12 @@ unsigned long do_brk(unsigned long addr,
73535 vma_link(mm, vma, prev, rb_link, rb_parent);
73536 out:
73537 perf_event_mmap(vma);
73538 - mm->total_vm += len >> PAGE_SHIFT;
73539 + mm->total_vm += charged;
73540 if (flags & VM_LOCKED) {
73541 if (!mlock_vma_pages_range(vma, addr, addr + len))
73542 - mm->locked_vm += (len >> PAGE_SHIFT);
73543 + mm->locked_vm += charged;
73544 }
73545 + track_exec_limit(mm, addr, addr + len, flags);
73546 return addr;
73547 }
73548
73549 @@ -2309,8 +2740,10 @@ void exit_mmap(struct mm_struct *mm)
73550 * Walk the list again, actually closing and freeing it,
73551 * with preemption enabled, without holding any MM locks.
73552 */
73553 - while (vma)
73554 + while (vma) {
73555 + vma->vm_mirror = NULL;
73556 vma = remove_vma(vma);
73557 + }
73558
73559 BUG_ON(mm->nr_ptes > (FIRST_USER_ADDRESS+PMD_SIZE-1)>>PMD_SHIFT);
73560 }
73561 @@ -2324,6 +2757,13 @@ int insert_vm_struct(struct mm_struct *
73562 struct vm_area_struct * __vma, * prev;
73563 struct rb_node ** rb_link, * rb_parent;
73564
73565 +#ifdef CONFIG_PAX_SEGMEXEC
73566 + struct vm_area_struct *vma_m = NULL;
73567 +#endif
73568 +
73569 + if (security_file_mmap(NULL, 0, 0, 0, vma->vm_start, 1))
73570 + return -EPERM;
73571 +
73572 /*
73573 * The vm_pgoff of a purely anonymous vma should be irrelevant
73574 * until its first write fault, when page's anon_vma and index
73575 @@ -2346,7 +2786,22 @@ int insert_vm_struct(struct mm_struct *
73576 if ((vma->vm_flags & VM_ACCOUNT) &&
73577 security_vm_enough_memory_mm(mm, vma_pages(vma)))
73578 return -ENOMEM;
73579 +
73580 +#ifdef CONFIG_PAX_SEGMEXEC
73581 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
73582 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73583 + if (!vma_m)
73584 + return -ENOMEM;
73585 + }
73586 +#endif
73587 +
73588 vma_link(mm, vma, prev, rb_link, rb_parent);
73589 +
73590 +#ifdef CONFIG_PAX_SEGMEXEC
73591 + if (vma_m)
73592 + BUG_ON(pax_mirror_vma(vma_m, vma));
73593 +#endif
73594 +
73595 return 0;
73596 }
73597
73598 @@ -2364,6 +2819,8 @@ struct vm_area_struct *copy_vma(struct v
73599 struct rb_node **rb_link, *rb_parent;
73600 struct mempolicy *pol;
73601
73602 + BUG_ON(vma->vm_mirror);
73603 +
73604 /*
73605 * If anonymous vma has not yet been faulted, update new pgoff
73606 * to match new location, to increase its chance of merging.
73607 @@ -2413,6 +2870,39 @@ struct vm_area_struct *copy_vma(struct v
73608 kmem_cache_free(vm_area_cachep, new_vma);
73609 return NULL;
73610 }
73611 +
73612 +#ifdef CONFIG_PAX_SEGMEXEC
73613 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
73614 +{
73615 + struct vm_area_struct *prev_m;
73616 + struct rb_node **rb_link_m, *rb_parent_m;
73617 + struct mempolicy *pol_m;
73618 +
73619 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
73620 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
73621 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
73622 + *vma_m = *vma;
73623 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
73624 + if (anon_vma_clone(vma_m, vma))
73625 + return -ENOMEM;
73626 + pol_m = vma_policy(vma_m);
73627 + mpol_get(pol_m);
73628 + vma_set_policy(vma_m, pol_m);
73629 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
73630 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
73631 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
73632 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
73633 + if (vma_m->vm_file)
73634 + get_file(vma_m->vm_file);
73635 + if (vma_m->vm_ops && vma_m->vm_ops->open)
73636 + vma_m->vm_ops->open(vma_m);
73637 + find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
73638 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
73639 + vma_m->vm_mirror = vma;
73640 + vma->vm_mirror = vma_m;
73641 + return 0;
73642 +}
73643 +#endif
73644
73645 /*
73646 * Return true if the calling process may expand its vm space by the passed
73647 @@ -2424,7 +2914,7 @@ int may_expand_vm(struct mm_struct *mm,
73648 unsigned long lim;
73649
73650 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
73651 -
73652 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
73653 if (cur + npages > lim)
73654 return 0;
73655 return 1;
73656 @@ -2495,6 +2985,22 @@ int install_special_mapping(struct mm_st
73657 vma->vm_start = addr;
73658 vma->vm_end = addr + len;
73659
73660 +#ifdef CONFIG_PAX_MPROTECT
73661 + if (mm->pax_flags & MF_PAX_MPROTECT) {
73662 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
73663 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
73664 + return -EPERM;
73665 + if (!(vm_flags & VM_EXEC))
73666 + vm_flags &= ~VM_MAYEXEC;
73667 +#else
73668 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
73669 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
73670 +#endif
73671 + else
73672 + vm_flags &= ~VM_MAYWRITE;
73673 + }
73674 +#endif
73675 +
73676 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
73677 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
73678
73679 diff -urNp linux-2.6.39/mm/mprotect.c linux-2.6.39/mm/mprotect.c
73680 --- linux-2.6.39/mm/mprotect.c 2011-05-19 00:06:34.000000000 -0400
73681 +++ linux-2.6.39/mm/mprotect.c 2011-05-22 19:41:42.000000000 -0400
73682 @@ -23,10 +23,16 @@
73683 #include <linux/mmu_notifier.h>
73684 #include <linux/migrate.h>
73685 #include <linux/perf_event.h>
73686 +
73687 +#ifdef CONFIG_PAX_MPROTECT
73688 +#include <linux/elf.h>
73689 +#endif
73690 +
73691 #include <asm/uaccess.h>
73692 #include <asm/pgtable.h>
73693 #include <asm/cacheflush.h>
73694 #include <asm/tlbflush.h>
73695 +#include <asm/mmu_context.h>
73696
73697 #ifndef pgprot_modify
73698 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
73699 @@ -141,6 +147,48 @@ static void change_protection(struct vm_
73700 flush_tlb_range(vma, start, end);
73701 }
73702
73703 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
73704 +/* called while holding the mmap semaphor for writing except stack expansion */
73705 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
73706 +{
73707 + unsigned long oldlimit, newlimit = 0UL;
73708 +
73709 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
73710 + return;
73711 +
73712 + spin_lock(&mm->page_table_lock);
73713 + oldlimit = mm->context.user_cs_limit;
73714 + if ((prot & VM_EXEC) && oldlimit < end)
73715 + /* USER_CS limit moved up */
73716 + newlimit = end;
73717 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
73718 + /* USER_CS limit moved down */
73719 + newlimit = start;
73720 +
73721 + if (newlimit) {
73722 + mm->context.user_cs_limit = newlimit;
73723 +
73724 +#ifdef CONFIG_SMP
73725 + wmb();
73726 + cpus_clear(mm->context.cpu_user_cs_mask);
73727 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
73728 +#endif
73729 +
73730 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
73731 + }
73732 + spin_unlock(&mm->page_table_lock);
73733 + if (newlimit == end) {
73734 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
73735 +
73736 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
73737 + if (is_vm_hugetlb_page(vma))
73738 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
73739 + else
73740 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
73741 + }
73742 +}
73743 +#endif
73744 +
73745 int
73746 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73747 unsigned long start, unsigned long end, unsigned long newflags)
73748 @@ -153,11 +201,29 @@ mprotect_fixup(struct vm_area_struct *vm
73749 int error;
73750 int dirty_accountable = 0;
73751
73752 +#ifdef CONFIG_PAX_SEGMEXEC
73753 + struct vm_area_struct *vma_m = NULL;
73754 + unsigned long start_m, end_m;
73755 +
73756 + start_m = start + SEGMEXEC_TASK_SIZE;
73757 + end_m = end + SEGMEXEC_TASK_SIZE;
73758 +#endif
73759 +
73760 if (newflags == oldflags) {
73761 *pprev = vma;
73762 return 0;
73763 }
73764
73765 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
73766 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
73767 +
73768 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
73769 + return -ENOMEM;
73770 +
73771 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
73772 + return -ENOMEM;
73773 + }
73774 +
73775 /*
73776 * If we make a private mapping writable we increase our commit;
73777 * but (without finer accounting) cannot reduce our commit if we
73778 @@ -174,6 +240,42 @@ mprotect_fixup(struct vm_area_struct *vm
73779 }
73780 }
73781
73782 +#ifdef CONFIG_PAX_SEGMEXEC
73783 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
73784 + if (start != vma->vm_start) {
73785 + error = split_vma(mm, vma, start, 1);
73786 + if (error)
73787 + goto fail;
73788 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
73789 + *pprev = (*pprev)->vm_next;
73790 + }
73791 +
73792 + if (end != vma->vm_end) {
73793 + error = split_vma(mm, vma, end, 0);
73794 + if (error)
73795 + goto fail;
73796 + }
73797 +
73798 + if (pax_find_mirror_vma(vma)) {
73799 + error = __do_munmap(mm, start_m, end_m - start_m);
73800 + if (error)
73801 + goto fail;
73802 + } else {
73803 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73804 + if (!vma_m) {
73805 + error = -ENOMEM;
73806 + goto fail;
73807 + }
73808 + vma->vm_flags = newflags;
73809 + error = pax_mirror_vma(vma_m, vma);
73810 + if (error) {
73811 + vma->vm_flags = oldflags;
73812 + goto fail;
73813 + }
73814 + }
73815 + }
73816 +#endif
73817 +
73818 /*
73819 * First try to merge with previous and/or next vma.
73820 */
73821 @@ -204,9 +306,21 @@ success:
73822 * vm_flags and vm_page_prot are protected by the mmap_sem
73823 * held in write mode.
73824 */
73825 +
73826 +#ifdef CONFIG_PAX_SEGMEXEC
73827 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
73828 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
73829 +#endif
73830 +
73831 vma->vm_flags = newflags;
73832 +
73833 +#ifdef CONFIG_PAX_MPROTECT
73834 + if (mm->binfmt && mm->binfmt->handle_mprotect)
73835 + mm->binfmt->handle_mprotect(vma, newflags);
73836 +#endif
73837 +
73838 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
73839 - vm_get_page_prot(newflags));
73840 + vm_get_page_prot(vma->vm_flags));
73841
73842 if (vma_wants_writenotify(vma)) {
73843 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
73844 @@ -248,6 +362,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
73845 end = start + len;
73846 if (end <= start)
73847 return -ENOMEM;
73848 +
73849 +#ifdef CONFIG_PAX_SEGMEXEC
73850 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
73851 + if (end > SEGMEXEC_TASK_SIZE)
73852 + return -EINVAL;
73853 + } else
73854 +#endif
73855 +
73856 + if (end > TASK_SIZE)
73857 + return -EINVAL;
73858 +
73859 if (!arch_validate_prot(prot))
73860 return -EINVAL;
73861
73862 @@ -255,7 +380,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
73863 /*
73864 * Does the application expect PROT_READ to imply PROT_EXEC:
73865 */
73866 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
73867 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
73868 prot |= PROT_EXEC;
73869
73870 vm_flags = calc_vm_prot_bits(prot);
73871 @@ -287,6 +412,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
73872 if (start > vma->vm_start)
73873 prev = vma;
73874
73875 +#ifdef CONFIG_PAX_MPROTECT
73876 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
73877 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
73878 +#endif
73879 +
73880 for (nstart = start ; ; ) {
73881 unsigned long newflags;
73882
73883 @@ -296,6 +426,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
73884
73885 /* newflags >> 4 shift VM_MAY% in place of VM_% */
73886 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
73887 + if (prot & (PROT_WRITE | PROT_EXEC))
73888 + gr_log_rwxmprotect(vma->vm_file);
73889 +
73890 + error = -EACCES;
73891 + goto out;
73892 + }
73893 +
73894 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
73895 error = -EACCES;
73896 goto out;
73897 }
73898 @@ -310,6 +448,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
73899 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
73900 if (error)
73901 goto out;
73902 +
73903 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
73904 +
73905 nstart = tmp;
73906
73907 if (nstart < prev->vm_end)
73908 diff -urNp linux-2.6.39/mm/mremap.c linux-2.6.39/mm/mremap.c
73909 --- linux-2.6.39/mm/mremap.c 2011-05-19 00:06:34.000000000 -0400
73910 +++ linux-2.6.39/mm/mremap.c 2011-05-22 19:36:33.000000000 -0400
73911 @@ -114,6 +114,12 @@ static void move_ptes(struct vm_area_str
73912 continue;
73913 pte = ptep_clear_flush(vma, old_addr, old_pte);
73914 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
73915 +
73916 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
73917 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
73918 + pte = pte_exprotect(pte);
73919 +#endif
73920 +
73921 set_pte_at(mm, new_addr, new_pte, pte);
73922 }
73923
73924 @@ -273,6 +279,11 @@ static struct vm_area_struct *vma_to_res
73925 if (is_vm_hugetlb_page(vma))
73926 goto Einval;
73927
73928 +#ifdef CONFIG_PAX_SEGMEXEC
73929 + if (pax_find_mirror_vma(vma))
73930 + goto Einval;
73931 +#endif
73932 +
73933 /* We can't remap across vm area boundaries */
73934 if (old_len > vma->vm_end - addr)
73935 goto Efault;
73936 @@ -329,20 +340,25 @@ static unsigned long mremap_to(unsigned
73937 unsigned long ret = -EINVAL;
73938 unsigned long charged = 0;
73939 unsigned long map_flags;
73940 + unsigned long pax_task_size = TASK_SIZE;
73941
73942 if (new_addr & ~PAGE_MASK)
73943 goto out;
73944
73945 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
73946 +#ifdef CONFIG_PAX_SEGMEXEC
73947 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
73948 + pax_task_size = SEGMEXEC_TASK_SIZE;
73949 +#endif
73950 +
73951 + pax_task_size -= PAGE_SIZE;
73952 +
73953 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
73954 goto out;
73955
73956 /* Check if the location we're moving into overlaps the
73957 * old location at all, and fail if it does.
73958 */
73959 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
73960 - goto out;
73961 -
73962 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
73963 + if (addr + old_len > new_addr && new_addr + new_len > addr)
73964 goto out;
73965
73966 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
73967 @@ -414,6 +430,7 @@ unsigned long do_mremap(unsigned long ad
73968 struct vm_area_struct *vma;
73969 unsigned long ret = -EINVAL;
73970 unsigned long charged = 0;
73971 + unsigned long pax_task_size = TASK_SIZE;
73972
73973 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
73974 goto out;
73975 @@ -432,6 +449,17 @@ unsigned long do_mremap(unsigned long ad
73976 if (!new_len)
73977 goto out;
73978
73979 +#ifdef CONFIG_PAX_SEGMEXEC
73980 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
73981 + pax_task_size = SEGMEXEC_TASK_SIZE;
73982 +#endif
73983 +
73984 + pax_task_size -= PAGE_SIZE;
73985 +
73986 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
73987 + old_len > pax_task_size || addr > pax_task_size-old_len)
73988 + goto out;
73989 +
73990 if (flags & MREMAP_FIXED) {
73991 if (flags & MREMAP_MAYMOVE)
73992 ret = mremap_to(addr, old_len, new_addr, new_len);
73993 @@ -481,6 +509,7 @@ unsigned long do_mremap(unsigned long ad
73994 addr + new_len);
73995 }
73996 ret = addr;
73997 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
73998 goto out;
73999 }
74000 }
74001 @@ -507,7 +536,13 @@ unsigned long do_mremap(unsigned long ad
74002 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
74003 if (ret)
74004 goto out;
74005 +
74006 + map_flags = vma->vm_flags;
74007 ret = move_vma(vma, addr, old_len, new_len, new_addr);
74008 + if (!(ret & ~PAGE_MASK)) {
74009 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
74010 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
74011 + }
74012 }
74013 out:
74014 if (ret & ~PAGE_MASK)
74015 diff -urNp linux-2.6.39/mm/nobootmem.c linux-2.6.39/mm/nobootmem.c
74016 --- linux-2.6.39/mm/nobootmem.c 2011-05-19 00:06:34.000000000 -0400
74017 +++ linux-2.6.39/mm/nobootmem.c 2011-05-22 19:36:33.000000000 -0400
74018 @@ -110,19 +110,30 @@ static void __init __free_pages_memory(u
74019 unsigned long __init free_all_memory_core_early(int nodeid)
74020 {
74021 int i;
74022 - u64 start, end;
74023 + u64 start, end, startrange, endrange;
74024 unsigned long count = 0;
74025 - struct range *range = NULL;
74026 + struct range *range = NULL, rangerange = { 0, 0 };
74027 int nr_range;
74028
74029 nr_range = get_free_all_memory_range(&range, nodeid);
74030 + startrange = __pa(range) >> PAGE_SHIFT;
74031 + endrange = (__pa(range + nr_range) - 1) >> PAGE_SHIFT;
74032
74033 for (i = 0; i < nr_range; i++) {
74034 start = range[i].start;
74035 end = range[i].end;
74036 + if (start <= endrange && startrange < end) {
74037 + BUG_ON(rangerange.start | rangerange.end);
74038 + rangerange = range[i];
74039 + continue;
74040 + }
74041 count += end - start;
74042 __free_pages_memory(start, end);
74043 }
74044 + start = rangerange.start;
74045 + end = rangerange.end;
74046 + count += end - start;
74047 + __free_pages_memory(start, end);
74048
74049 return count;
74050 }
74051 diff -urNp linux-2.6.39/mm/nommu.c linux-2.6.39/mm/nommu.c
74052 --- linux-2.6.39/mm/nommu.c 2011-05-19 00:06:34.000000000 -0400
74053 +++ linux-2.6.39/mm/nommu.c 2011-05-22 19:36:33.000000000 -0400
74054 @@ -63,7 +63,6 @@ int sysctl_overcommit_memory = OVERCOMMI
74055 int sysctl_overcommit_ratio = 50; /* default is 50% */
74056 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
74057 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
74058 -int heap_stack_gap = 0;
74059
74060 atomic_long_t mmap_pages_allocated;
74061
74062 @@ -833,15 +832,6 @@ struct vm_area_struct *find_vma(struct m
74063 EXPORT_SYMBOL(find_vma);
74064
74065 /*
74066 - * find a VMA
74067 - * - we don't extend stack VMAs under NOMMU conditions
74068 - */
74069 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
74070 -{
74071 - return find_vma(mm, addr);
74072 -}
74073 -
74074 -/*
74075 * expand a stack to a given address
74076 * - not supported under NOMMU conditions
74077 */
74078 @@ -1563,6 +1553,7 @@ int split_vma(struct mm_struct *mm, stru
74079
74080 /* most fields are the same, copy all, and then fixup */
74081 *new = *vma;
74082 + INIT_LIST_HEAD(&new->anon_vma_chain);
74083 *region = *vma->vm_region;
74084 new->vm_region = region;
74085
74086 diff -urNp linux-2.6.39/mm/page_alloc.c linux-2.6.39/mm/page_alloc.c
74087 --- linux-2.6.39/mm/page_alloc.c 2011-05-19 00:06:34.000000000 -0400
74088 +++ linux-2.6.39/mm/page_alloc.c 2011-05-22 19:36:33.000000000 -0400
74089 @@ -650,6 +650,10 @@ static bool free_pages_prepare(struct pa
74090 int i;
74091 int bad = 0;
74092
74093 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
74094 + unsigned long index = 1UL << order;
74095 +#endif
74096 +
74097 trace_mm_page_free_direct(page, order);
74098 kmemcheck_free_shadow(page, order);
74099
74100 @@ -665,6 +669,12 @@ static bool free_pages_prepare(struct pa
74101 debug_check_no_obj_freed(page_address(page),
74102 PAGE_SIZE << order);
74103 }
74104 +
74105 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
74106 + for (; index; --index)
74107 + sanitize_highpage(page + index - 1);
74108 +#endif
74109 +
74110 arch_free_page(page, order);
74111 kernel_map_pages(page, 1 << order, 0);
74112
74113 @@ -780,8 +790,10 @@ static int prep_new_page(struct page *pa
74114 arch_alloc_page(page, order);
74115 kernel_map_pages(page, 1 << order, 1);
74116
74117 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
74118 if (gfp_flags & __GFP_ZERO)
74119 prep_zero_page(page, order, gfp_flags);
74120 +#endif
74121
74122 if (order && (gfp_flags & __GFP_COMP))
74123 prep_compound_page(page, order);
74124 @@ -2504,6 +2516,8 @@ void __show_free_areas(unsigned int filt
74125 int cpu;
74126 struct zone *zone;
74127
74128 + pax_track_stack();
74129 +
74130 for_each_populated_zone(zone) {
74131 if (skip_free_areas_zone(filter, zone))
74132 continue;
74133 diff -urNp linux-2.6.39/mm/percpu.c linux-2.6.39/mm/percpu.c
74134 --- linux-2.6.39/mm/percpu.c 2011-05-19 00:06:34.000000000 -0400
74135 +++ linux-2.6.39/mm/percpu.c 2011-05-22 19:36:33.000000000 -0400
74136 @@ -121,7 +121,7 @@ static unsigned int pcpu_first_unit_cpu
74137 static unsigned int pcpu_last_unit_cpu __read_mostly;
74138
74139 /* the address of the first chunk which starts with the kernel static area */
74140 -void *pcpu_base_addr __read_mostly;
74141 +void *pcpu_base_addr __read_only;
74142 EXPORT_SYMBOL_GPL(pcpu_base_addr);
74143
74144 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
74145 diff -urNp linux-2.6.39/mm/rmap.c linux-2.6.39/mm/rmap.c
74146 --- linux-2.6.39/mm/rmap.c 2011-05-19 00:06:34.000000000 -0400
74147 +++ linux-2.6.39/mm/rmap.c 2011-05-22 19:36:33.000000000 -0400
74148 @@ -131,6 +131,10 @@ int anon_vma_prepare(struct vm_area_stru
74149 struct anon_vma *anon_vma = vma->anon_vma;
74150 struct anon_vma_chain *avc;
74151
74152 +#ifdef CONFIG_PAX_SEGMEXEC
74153 + struct anon_vma_chain *avc_m = NULL;
74154 +#endif
74155 +
74156 might_sleep();
74157 if (unlikely(!anon_vma)) {
74158 struct mm_struct *mm = vma->vm_mm;
74159 @@ -140,6 +144,12 @@ int anon_vma_prepare(struct vm_area_stru
74160 if (!avc)
74161 goto out_enomem;
74162
74163 +#ifdef CONFIG_PAX_SEGMEXEC
74164 + avc_m = anon_vma_chain_alloc();
74165 + if (!avc_m)
74166 + goto out_enomem_free_avc;
74167 +#endif
74168 +
74169 anon_vma = find_mergeable_anon_vma(vma);
74170 allocated = NULL;
74171 if (!anon_vma) {
74172 @@ -153,6 +163,21 @@ int anon_vma_prepare(struct vm_area_stru
74173 /* page_table_lock to protect against threads */
74174 spin_lock(&mm->page_table_lock);
74175 if (likely(!vma->anon_vma)) {
74176 +
74177 +#ifdef CONFIG_PAX_SEGMEXEC
74178 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
74179 +
74180 + if (vma_m) {
74181 + BUG_ON(vma_m->anon_vma);
74182 + vma_m->anon_vma = anon_vma;
74183 + avc_m->anon_vma = anon_vma;
74184 + avc_m->vma = vma;
74185 + list_add(&avc_m->same_vma, &vma_m->anon_vma_chain);
74186 + list_add(&avc_m->same_anon_vma, &anon_vma->head);
74187 + avc_m = NULL;
74188 + }
74189 +#endif
74190 +
74191 vma->anon_vma = anon_vma;
74192 avc->anon_vma = anon_vma;
74193 avc->vma = vma;
74194 @@ -166,12 +191,24 @@ int anon_vma_prepare(struct vm_area_stru
74195
74196 if (unlikely(allocated))
74197 put_anon_vma(allocated);
74198 +
74199 +#ifdef CONFIG_PAX_SEGMEXEC
74200 + if (unlikely(avc_m))
74201 + anon_vma_chain_free(avc_m);
74202 +#endif
74203 +
74204 if (unlikely(avc))
74205 anon_vma_chain_free(avc);
74206 }
74207 return 0;
74208
74209 out_enomem_free_avc:
74210 +
74211 +#ifdef CONFIG_PAX_SEGMEXEC
74212 + if (avc_m)
74213 + anon_vma_chain_free(avc_m);
74214 +#endif
74215 +
74216 anon_vma_chain_free(avc);
74217 out_enomem:
74218 return -ENOMEM;
74219 @@ -198,7 +235,7 @@ static void anon_vma_chain_link(struct v
74220 * Attach the anon_vmas from src to dst.
74221 * Returns 0 on success, -ENOMEM on failure.
74222 */
74223 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
74224 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
74225 {
74226 struct anon_vma_chain *avc, *pavc;
74227
74228 @@ -220,7 +257,7 @@ int anon_vma_clone(struct vm_area_struct
74229 * the corresponding VMA in the parent process is attached to.
74230 * Returns 0 on success, non-zero on failure.
74231 */
74232 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
74233 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
74234 {
74235 struct anon_vma_chain *avc;
74236 struct anon_vma *anon_vma;
74237 diff -urNp linux-2.6.39/mm/shmem.c linux-2.6.39/mm/shmem.c
74238 --- linux-2.6.39/mm/shmem.c 2011-05-19 00:06:34.000000000 -0400
74239 +++ linux-2.6.39/mm/shmem.c 2011-05-22 19:41:42.000000000 -0400
74240 @@ -31,7 +31,7 @@
74241 #include <linux/percpu_counter.h>
74242 #include <linux/swap.h>
74243
74244 -static struct vfsmount *shm_mnt;
74245 +struct vfsmount *shm_mnt;
74246
74247 #ifdef CONFIG_SHMEM
74248 /*
74249 @@ -1086,6 +1086,8 @@ static int shmem_writepage(struct page *
74250 goto unlock;
74251 }
74252 entry = shmem_swp_entry(info, index, NULL);
74253 + if (!entry)
74254 + goto unlock;
74255 if (entry->val) {
74256 /*
74257 * The more uptodate page coming down from a stacked
74258 @@ -1157,6 +1159,8 @@ static struct page *shmem_swapin(swp_ent
74259 struct vm_area_struct pvma;
74260 struct page *page;
74261
74262 + pax_track_stack();
74263 +
74264 spol = mpol_cond_copy(&mpol,
74265 mpol_shared_policy_lookup(&info->policy, idx));
74266
74267 @@ -2013,7 +2017,7 @@ static int shmem_symlink(struct inode *d
74268
74269 info = SHMEM_I(inode);
74270 inode->i_size = len-1;
74271 - if (len <= (char *)inode - (char *)info) {
74272 + if (len <= (char *)inode - (char *)info && len <= 64) {
74273 /* do it inline */
74274 memcpy(info, symname, len);
74275 inode->i_op = &shmem_symlink_inline_operations;
74276 @@ -2361,8 +2365,7 @@ int shmem_fill_super(struct super_block
74277 int err = -ENOMEM;
74278
74279 /* Round up to L1_CACHE_BYTES to resist false sharing */
74280 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
74281 - L1_CACHE_BYTES), GFP_KERNEL);
74282 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
74283 if (!sbinfo)
74284 return -ENOMEM;
74285
74286 diff -urNp linux-2.6.39/mm/slab.c linux-2.6.39/mm/slab.c
74287 --- linux-2.6.39/mm/slab.c 2011-05-19 00:06:34.000000000 -0400
74288 +++ linux-2.6.39/mm/slab.c 2011-05-22 19:41:42.000000000 -0400
74289 @@ -150,7 +150,7 @@
74290
74291 /* Legal flag mask for kmem_cache_create(). */
74292 #if DEBUG
74293 -# define CREATE_MASK (SLAB_RED_ZONE | \
74294 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
74295 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
74296 SLAB_CACHE_DMA | \
74297 SLAB_STORE_USER | \
74298 @@ -158,7 +158,7 @@
74299 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
74300 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
74301 #else
74302 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
74303 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
74304 SLAB_CACHE_DMA | \
74305 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
74306 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
74307 @@ -287,7 +287,7 @@ struct kmem_list3 {
74308 * Need this for bootstrapping a per node allocator.
74309 */
74310 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
74311 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
74312 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
74313 #define CACHE_CACHE 0
74314 #define SIZE_AC MAX_NUMNODES
74315 #define SIZE_L3 (2 * MAX_NUMNODES)
74316 @@ -388,10 +388,10 @@ static void kmem_list3_init(struct kmem_
74317 if ((x)->max_freeable < i) \
74318 (x)->max_freeable = i; \
74319 } while (0)
74320 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
74321 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
74322 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
74323 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
74324 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
74325 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
74326 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
74327 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
74328 #else
74329 #define STATS_INC_ACTIVE(x) do { } while (0)
74330 #define STATS_DEC_ACTIVE(x) do { } while (0)
74331 @@ -537,7 +537,7 @@ static inline void *index_to_obj(struct
74332 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
74333 */
74334 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
74335 - const struct slab *slab, void *obj)
74336 + const struct slab *slab, const void *obj)
74337 {
74338 u32 offset = (obj - slab->s_mem);
74339 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
74340 @@ -563,7 +563,7 @@ struct cache_names {
74341 static struct cache_names __initdata cache_names[] = {
74342 #define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
74343 #include <linux/kmalloc_sizes.h>
74344 - {NULL,}
74345 + {NULL}
74346 #undef CACHE
74347 };
74348
74349 @@ -1529,7 +1529,7 @@ void __init kmem_cache_init(void)
74350 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
74351 sizes[INDEX_AC].cs_size,
74352 ARCH_KMALLOC_MINALIGN,
74353 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74354 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74355 NULL);
74356
74357 if (INDEX_AC != INDEX_L3) {
74358 @@ -1537,7 +1537,7 @@ void __init kmem_cache_init(void)
74359 kmem_cache_create(names[INDEX_L3].name,
74360 sizes[INDEX_L3].cs_size,
74361 ARCH_KMALLOC_MINALIGN,
74362 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74363 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74364 NULL);
74365 }
74366
74367 @@ -1555,7 +1555,7 @@ void __init kmem_cache_init(void)
74368 sizes->cs_cachep = kmem_cache_create(names->name,
74369 sizes->cs_size,
74370 ARCH_KMALLOC_MINALIGN,
74371 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74372 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74373 NULL);
74374 }
74375 #ifdef CONFIG_ZONE_DMA
74376 @@ -4270,10 +4270,10 @@ static int s_show(struct seq_file *m, vo
74377 }
74378 /* cpu stats */
74379 {
74380 - unsigned long allochit = atomic_read(&cachep->allochit);
74381 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
74382 - unsigned long freehit = atomic_read(&cachep->freehit);
74383 - unsigned long freemiss = atomic_read(&cachep->freemiss);
74384 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
74385 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
74386 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
74387 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
74388
74389 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
74390 allochit, allocmiss, freehit, freemiss);
74391 @@ -4530,15 +4530,66 @@ static const struct file_operations proc
74392
74393 static int __init slab_proc_init(void)
74394 {
74395 - proc_create("slabinfo",S_IWUSR|S_IRUGO,NULL,&proc_slabinfo_operations);
74396 + mode_t gr_mode = S_IRUGO;
74397 +
74398 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
74399 + gr_mode = S_IRUSR;
74400 +#endif
74401 +
74402 + proc_create("slabinfo",S_IWUSR|gr_mode,NULL,&proc_slabinfo_operations);
74403 #ifdef CONFIG_DEBUG_SLAB_LEAK
74404 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
74405 + proc_create("slab_allocators", gr_mode, NULL, &proc_slabstats_operations);
74406 #endif
74407 return 0;
74408 }
74409 module_init(slab_proc_init);
74410 #endif
74411
74412 +void check_object_size(const void *ptr, unsigned long n, bool to)
74413 +{
74414 +
74415 +#ifdef CONFIG_PAX_USERCOPY
74416 + struct page *page;
74417 + struct kmem_cache *cachep = NULL;
74418 + struct slab *slabp;
74419 + unsigned int objnr;
74420 + unsigned long offset;
74421 +
74422 + if (!n)
74423 + return;
74424 +
74425 + if (ZERO_OR_NULL_PTR(ptr))
74426 + goto report;
74427 +
74428 + if (!virt_addr_valid(ptr))
74429 + return;
74430 +
74431 + page = virt_to_head_page(ptr);
74432 +
74433 + if (!PageSlab(page)) {
74434 + if (object_is_on_stack(ptr, n) == -1)
74435 + goto report;
74436 + return;
74437 + }
74438 +
74439 + cachep = page_get_cache(page);
74440 + if (!(cachep->flags & SLAB_USERCOPY))
74441 + goto report;
74442 +
74443 + slabp = page_get_slab(page);
74444 + objnr = obj_to_index(cachep, slabp, ptr);
74445 + BUG_ON(objnr >= cachep->num);
74446 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
74447 + if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
74448 + return;
74449 +
74450 +report:
74451 + pax_report_usercopy(ptr, n, to, cachep ? cachep->name : NULL);
74452 +#endif
74453 +
74454 +}
74455 +EXPORT_SYMBOL(check_object_size);
74456 +
74457 /**
74458 * ksize - get the actual amount of memory allocated for a given object
74459 * @objp: Pointer to the object
74460 diff -urNp linux-2.6.39/mm/slob.c linux-2.6.39/mm/slob.c
74461 --- linux-2.6.39/mm/slob.c 2011-05-19 00:06:34.000000000 -0400
74462 +++ linux-2.6.39/mm/slob.c 2011-05-22 19:36:33.000000000 -0400
74463 @@ -29,7 +29,7 @@
74464 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
74465 * alloc_pages() directly, allocating compound pages so the page order
74466 * does not have to be separately tracked, and also stores the exact
74467 - * allocation size in page->private so that it can be used to accurately
74468 + * allocation size in slob_page->size so that it can be used to accurately
74469 * provide ksize(). These objects are detected in kfree() because slob_page()
74470 * is false for them.
74471 *
74472 @@ -58,6 +58,7 @@
74473 */
74474
74475 #include <linux/kernel.h>
74476 +#include <linux/sched.h>
74477 #include <linux/slab.h>
74478 #include <linux/mm.h>
74479 #include <linux/swap.h> /* struct reclaim_state */
74480 @@ -102,7 +103,8 @@ struct slob_page {
74481 unsigned long flags; /* mandatory */
74482 atomic_t _count; /* mandatory */
74483 slobidx_t units; /* free units left in page */
74484 - unsigned long pad[2];
74485 + unsigned long pad[1];
74486 + unsigned long size; /* size when >=PAGE_SIZE */
74487 slob_t *free; /* first free slob_t in page */
74488 struct list_head list; /* linked list of free pages */
74489 };
74490 @@ -135,7 +137,7 @@ static LIST_HEAD(free_slob_large);
74491 */
74492 static inline int is_slob_page(struct slob_page *sp)
74493 {
74494 - return PageSlab((struct page *)sp);
74495 + return PageSlab((struct page *)sp) && !sp->size;
74496 }
74497
74498 static inline void set_slob_page(struct slob_page *sp)
74499 @@ -150,7 +152,7 @@ static inline void clear_slob_page(struc
74500
74501 static inline struct slob_page *slob_page(const void *addr)
74502 {
74503 - return (struct slob_page *)virt_to_page(addr);
74504 + return (struct slob_page *)virt_to_head_page(addr);
74505 }
74506
74507 /*
74508 @@ -210,7 +212,7 @@ static void set_slob(slob_t *s, slobidx_
74509 /*
74510 * Return the size of a slob block.
74511 */
74512 -static slobidx_t slob_units(slob_t *s)
74513 +static slobidx_t slob_units(const slob_t *s)
74514 {
74515 if (s->units > 0)
74516 return s->units;
74517 @@ -220,7 +222,7 @@ static slobidx_t slob_units(slob_t *s)
74518 /*
74519 * Return the next free slob block pointer after this one.
74520 */
74521 -static slob_t *slob_next(slob_t *s)
74522 +static slob_t *slob_next(const slob_t *s)
74523 {
74524 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
74525 slobidx_t next;
74526 @@ -235,7 +237,7 @@ static slob_t *slob_next(slob_t *s)
74527 /*
74528 * Returns true if s is the last free block in its page.
74529 */
74530 -static int slob_last(slob_t *s)
74531 +static int slob_last(const slob_t *s)
74532 {
74533 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
74534 }
74535 @@ -254,6 +256,7 @@ static void *slob_new_pages(gfp_t gfp, i
74536 if (!page)
74537 return NULL;
74538
74539 + set_slob_page(page);
74540 return page_address(page);
74541 }
74542
74543 @@ -370,11 +373,11 @@ static void *slob_alloc(size_t size, gfp
74544 if (!b)
74545 return NULL;
74546 sp = slob_page(b);
74547 - set_slob_page(sp);
74548
74549 spin_lock_irqsave(&slob_lock, flags);
74550 sp->units = SLOB_UNITS(PAGE_SIZE);
74551 sp->free = b;
74552 + sp->size = 0;
74553 INIT_LIST_HEAD(&sp->list);
74554 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
74555 set_slob_page_free(sp, slob_list);
74556 @@ -476,10 +479,9 @@ out:
74557 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
74558 */
74559
74560 -void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74561 +static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
74562 {
74563 - unsigned int *m;
74564 - int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74565 + slob_t *m;
74566 void *ret;
74567
74568 lockdep_trace_alloc(gfp);
74569 @@ -492,7 +494,10 @@ void *__kmalloc_node(size_t size, gfp_t
74570
74571 if (!m)
74572 return NULL;
74573 - *m = size;
74574 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
74575 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
74576 + m[0].units = size;
74577 + m[1].units = align;
74578 ret = (void *)m + align;
74579
74580 trace_kmalloc_node(_RET_IP_, ret,
74581 @@ -504,9 +509,9 @@ void *__kmalloc_node(size_t size, gfp_t
74582 gfp |= __GFP_COMP;
74583 ret = slob_new_pages(gfp, order, node);
74584 if (ret) {
74585 - struct page *page;
74586 - page = virt_to_page(ret);
74587 - page->private = size;
74588 + struct slob_page *sp;
74589 + sp = slob_page(ret);
74590 + sp->size = size;
74591 }
74592
74593 trace_kmalloc_node(_RET_IP_, ret,
74594 @@ -516,6 +521,13 @@ void *__kmalloc_node(size_t size, gfp_t
74595 kmemleak_alloc(ret, size, 1, gfp);
74596 return ret;
74597 }
74598 +
74599 +void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74600 +{
74601 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74602 +
74603 + return __kmalloc_node_align(size, gfp, node, align);
74604 +}
74605 EXPORT_SYMBOL(__kmalloc_node);
74606
74607 void kfree(const void *block)
74608 @@ -531,13 +543,81 @@ void kfree(const void *block)
74609 sp = slob_page(block);
74610 if (is_slob_page(sp)) {
74611 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74612 - unsigned int *m = (unsigned int *)(block - align);
74613 - slob_free(m, *m + align);
74614 - } else
74615 + slob_t *m = (slob_t *)(block - align);
74616 + slob_free(m, m[0].units + align);
74617 + } else {
74618 + clear_slob_page(sp);
74619 + free_slob_page(sp);
74620 + sp->size = 0;
74621 put_page(&sp->page);
74622 + }
74623 }
74624 EXPORT_SYMBOL(kfree);
74625
74626 +void check_object_size(const void *ptr, unsigned long n, bool to)
74627 +{
74628 +
74629 +#ifdef CONFIG_PAX_USERCOPY
74630 + struct slob_page *sp;
74631 + const slob_t *free;
74632 + const void *base;
74633 +
74634 + if (!n)
74635 + return;
74636 +
74637 + if (ZERO_OR_NULL_PTR(ptr))
74638 + goto report;
74639 +
74640 + if (!virt_addr_valid(ptr))
74641 + return;
74642 +
74643 + sp = slob_page(ptr);
74644 + if (!PageSlab((struct page*)sp)) {
74645 + if (object_is_on_stack(ptr, n) == -1)
74646 + goto report;
74647 + return;
74648 + }
74649 +
74650 + if (sp->size) {
74651 + base = page_address(&sp->page);
74652 + if (base <= ptr && n <= sp->size - (ptr - base))
74653 + return;
74654 + goto report;
74655 + }
74656 +
74657 + /* some tricky double walking to find the chunk */
74658 + base = (void *)((unsigned long)ptr & PAGE_MASK);
74659 + free = sp->free;
74660 +
74661 + while (!slob_last(free) && (void *)free <= ptr) {
74662 + base = free + slob_units(free);
74663 + free = slob_next(free);
74664 + }
74665 +
74666 + while (base < (void *)free) {
74667 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
74668 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
74669 + int offset;
74670 +
74671 + if (ptr < base + align)
74672 + goto report;
74673 +
74674 + offset = ptr - base - align;
74675 + if (offset < m) {
74676 + if (n <= m - offset)
74677 + return;
74678 + goto report;
74679 + }
74680 + base += size;
74681 + }
74682 +
74683 +report:
74684 + pax_report_usercopy(ptr, n, to, NULL);
74685 +#endif
74686 +
74687 +}
74688 +EXPORT_SYMBOL(check_object_size);
74689 +
74690 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
74691 size_t ksize(const void *block)
74692 {
74693 @@ -550,10 +630,10 @@ size_t ksize(const void *block)
74694 sp = slob_page(block);
74695 if (is_slob_page(sp)) {
74696 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74697 - unsigned int *m = (unsigned int *)(block - align);
74698 - return SLOB_UNITS(*m) * SLOB_UNIT;
74699 + slob_t *m = (slob_t *)(block - align);
74700 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
74701 } else
74702 - return sp->page.private;
74703 + return sp->size;
74704 }
74705 EXPORT_SYMBOL(ksize);
74706
74707 @@ -608,17 +688,25 @@ void *kmem_cache_alloc_node(struct kmem_
74708 {
74709 void *b;
74710
74711 +#ifdef CONFIG_PAX_USERCOPY
74712 + b = __kmalloc_node_align(c->size, flags, node, c->align);
74713 +#else
74714 if (c->size < PAGE_SIZE) {
74715 b = slob_alloc(c->size, flags, c->align, node);
74716 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
74717 SLOB_UNITS(c->size) * SLOB_UNIT,
74718 flags, node);
74719 } else {
74720 + struct slob_page *sp;
74721 +
74722 b = slob_new_pages(flags, get_order(c->size), node);
74723 + sp = slob_page(b);
74724 + sp->size = c->size;
74725 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
74726 PAGE_SIZE << get_order(c->size),
74727 flags, node);
74728 }
74729 +#endif
74730
74731 if (c->ctor)
74732 c->ctor(b);
74733 @@ -630,10 +718,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
74734
74735 static void __kmem_cache_free(void *b, int size)
74736 {
74737 - if (size < PAGE_SIZE)
74738 + struct slob_page *sp = slob_page(b);
74739 +
74740 + if (is_slob_page(sp))
74741 slob_free(b, size);
74742 - else
74743 + else {
74744 + clear_slob_page(sp);
74745 + free_slob_page(sp);
74746 + sp->size = 0;
74747 slob_free_pages(b, get_order(size));
74748 + }
74749 }
74750
74751 static void kmem_rcu_free(struct rcu_head *head)
74752 @@ -646,14 +740,23 @@ static void kmem_rcu_free(struct rcu_hea
74753
74754 void kmem_cache_free(struct kmem_cache *c, void *b)
74755 {
74756 + int size = c->size;
74757 +
74758 +#ifdef CONFIG_PAX_USERCOPY
74759 + if (size + c->align < PAGE_SIZE) {
74760 + size += c->align;
74761 + b -= c->align;
74762 + }
74763 +#endif
74764 +
74765 kmemleak_free_recursive(b, c->flags);
74766 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
74767 struct slob_rcu *slob_rcu;
74768 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
74769 - slob_rcu->size = c->size;
74770 + slob_rcu = b + (size - sizeof(struct slob_rcu));
74771 + slob_rcu->size = size;
74772 call_rcu(&slob_rcu->head, kmem_rcu_free);
74773 } else {
74774 - __kmem_cache_free(b, c->size);
74775 + __kmem_cache_free(b, size);
74776 }
74777
74778 trace_kmem_cache_free(_RET_IP_, b);
74779 diff -urNp linux-2.6.39/mm/slub.c linux-2.6.39/mm/slub.c
74780 --- linux-2.6.39/mm/slub.c 2011-05-19 00:06:34.000000000 -0400
74781 +++ linux-2.6.39/mm/slub.c 2011-05-22 19:41:42.000000000 -0400
74782 @@ -419,7 +419,7 @@ static void print_track(const char *s, s
74783 if (!t->addr)
74784 return;
74785
74786 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
74787 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
74788 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
74789 }
74790
74791 @@ -2171,6 +2171,8 @@ void kmem_cache_free(struct kmem_cache *
74792
74793 page = virt_to_head_page(x);
74794
74795 + BUG_ON(!PageSlab(page));
74796 +
74797 slab_free(s, page, x, _RET_IP_);
74798
74799 trace_kmem_cache_free(_RET_IP_, x);
74800 @@ -2204,7 +2206,7 @@ static int slub_min_objects;
74801 * Merge control. If this is set then no merging of slab caches will occur.
74802 * (Could be removed. This was introduced to pacify the merge skeptics.)
74803 */
74804 -static int slub_nomerge;
74805 +static int slub_nomerge = 1;
74806
74807 /*
74808 * Calculate the order of allocation given an slab object size.
74809 @@ -2632,7 +2634,7 @@ static int kmem_cache_open(struct kmem_c
74810 * list to avoid pounding the page allocator excessively.
74811 */
74812 set_min_partial(s, ilog2(s->size));
74813 - s->refcount = 1;
74814 + atomic_set(&s->refcount, 1);
74815 #ifdef CONFIG_NUMA
74816 s->remote_node_defrag_ratio = 1000;
74817 #endif
74818 @@ -2738,8 +2740,7 @@ static inline int kmem_cache_close(struc
74819 void kmem_cache_destroy(struct kmem_cache *s)
74820 {
74821 down_write(&slub_lock);
74822 - s->refcount--;
74823 - if (!s->refcount) {
74824 + if (atomic_dec_and_test(&s->refcount)) {
74825 list_del(&s->list);
74826 if (kmem_cache_close(s)) {
74827 printk(KERN_ERR "SLUB %s: %s called for cache that "
74828 @@ -2949,6 +2950,46 @@ void *__kmalloc_node(size_t size, gfp_t
74829 EXPORT_SYMBOL(__kmalloc_node);
74830 #endif
74831
74832 +void check_object_size(const void *ptr, unsigned long n, bool to)
74833 +{
74834 +
74835 +#ifdef CONFIG_PAX_USERCOPY
74836 + struct page *page;
74837 + struct kmem_cache *s = NULL;
74838 + unsigned long offset;
74839 +
74840 + if (!n)
74841 + return;
74842 +
74843 + if (ZERO_OR_NULL_PTR(ptr))
74844 + goto report;
74845 +
74846 + if (!virt_addr_valid(ptr))
74847 + return;
74848 +
74849 + page = virt_to_head_page(ptr);
74850 +
74851 + if (!PageSlab(page)) {
74852 + if (object_is_on_stack(ptr, n) == -1)
74853 + goto report;
74854 + return;
74855 + }
74856 +
74857 + s = page->slab;
74858 + if (!(s->flags & SLAB_USERCOPY))
74859 + goto report;
74860 +
74861 + offset = (ptr - page_address(page)) % s->size;
74862 + if (offset <= s->objsize && n <= s->objsize - offset)
74863 + return;
74864 +
74865 +report:
74866 + pax_report_usercopy(ptr, n, to, s ? s->name : NULL);
74867 +#endif
74868 +
74869 +}
74870 +EXPORT_SYMBOL(check_object_size);
74871 +
74872 size_t ksize(const void *object)
74873 {
74874 struct page *page;
74875 @@ -3193,7 +3234,7 @@ static void __init kmem_cache_bootstrap_
74876 int node;
74877
74878 list_add(&s->list, &slab_caches);
74879 - s->refcount = -1;
74880 + atomic_set(&s->refcount, -1);
74881
74882 for_each_node_state(node, N_NORMAL_MEMORY) {
74883 struct kmem_cache_node *n = get_node(s, node);
74884 @@ -3310,17 +3351,17 @@ void __init kmem_cache_init(void)
74885
74886 /* Caches that are not of the two-to-the-power-of size */
74887 if (KMALLOC_MIN_SIZE <= 32) {
74888 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
74889 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
74890 caches++;
74891 }
74892
74893 if (KMALLOC_MIN_SIZE <= 64) {
74894 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
74895 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
74896 caches++;
74897 }
74898
74899 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
74900 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
74901 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
74902 caches++;
74903 }
74904
74905 @@ -3388,7 +3429,7 @@ static int slab_unmergeable(struct kmem_
74906 /*
74907 * We may have set a slab to be unmergeable during bootstrap.
74908 */
74909 - if (s->refcount < 0)
74910 + if (atomic_read(&s->refcount) < 0)
74911 return 1;
74912
74913 return 0;
74914 @@ -3447,7 +3488,7 @@ struct kmem_cache *kmem_cache_create(con
74915 down_write(&slub_lock);
74916 s = find_mergeable(size, align, flags, name, ctor);
74917 if (s) {
74918 - s->refcount++;
74919 + atomic_inc(&s->refcount);
74920 /*
74921 * Adjust the object sizes so that we clear
74922 * the complete object on kzalloc.
74923 @@ -3456,7 +3497,7 @@ struct kmem_cache *kmem_cache_create(con
74924 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
74925
74926 if (sysfs_slab_alias(s, name)) {
74927 - s->refcount--;
74928 + atomic_dec(&s->refcount);
74929 goto err;
74930 }
74931 up_write(&slub_lock);
74932 @@ -4189,7 +4230,7 @@ SLAB_ATTR_RO(ctor);
74933
74934 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
74935 {
74936 - return sprintf(buf, "%d\n", s->refcount - 1);
74937 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
74938 }
74939 SLAB_ATTR_RO(aliases);
74940
74941 @@ -4933,7 +4974,13 @@ static const struct file_operations proc
74942
74943 static int __init slab_proc_init(void)
74944 {
74945 - proc_create("slabinfo", S_IRUGO, NULL, &proc_slabinfo_operations);
74946 + mode_t gr_mode = S_IRUGO;
74947 +
74948 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
74949 + gr_mode = S_IRUSR;
74950 +#endif
74951 +
74952 + proc_create("slabinfo", gr_mode, NULL, &proc_slabinfo_operations);
74953 return 0;
74954 }
74955 module_init(slab_proc_init);
74956 diff -urNp linux-2.6.39/mm/swapfile.c linux-2.6.39/mm/swapfile.c
74957 --- linux-2.6.39/mm/swapfile.c 2011-05-19 00:06:34.000000000 -0400
74958 +++ linux-2.6.39/mm/swapfile.c 2011-05-22 19:36:33.000000000 -0400
74959 @@ -61,7 +61,7 @@ static DEFINE_MUTEX(swapon_mutex);
74960
74961 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
74962 /* Activity counter to indicate that a swapon or swapoff has occurred */
74963 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
74964 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
74965
74966 static inline unsigned char swap_count(unsigned char ent)
74967 {
74968 @@ -1669,7 +1669,7 @@ SYSCALL_DEFINE1(swapoff, const char __us
74969 }
74970 filp_close(swap_file, NULL);
74971 err = 0;
74972 - atomic_inc(&proc_poll_event);
74973 + atomic_inc_unchecked(&proc_poll_event);
74974 wake_up_interruptible(&proc_poll_wait);
74975
74976 out_dput:
74977 @@ -1690,8 +1690,8 @@ static unsigned swaps_poll(struct file *
74978
74979 poll_wait(file, &proc_poll_wait, wait);
74980
74981 - if (s->event != atomic_read(&proc_poll_event)) {
74982 - s->event = atomic_read(&proc_poll_event);
74983 + if (s->event != atomic_read_unchecked(&proc_poll_event)) {
74984 + s->event = atomic_read_unchecked(&proc_poll_event);
74985 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
74986 }
74987
74988 @@ -1797,7 +1797,7 @@ static int swaps_open(struct inode *inod
74989 }
74990
74991 s->seq.private = s;
74992 - s->event = atomic_read(&proc_poll_event);
74993 + s->event = atomic_read_unchecked(&proc_poll_event);
74994 return ret;
74995 }
74996
74997 @@ -2131,7 +2131,7 @@ SYSCALL_DEFINE2(swapon, const char __use
74998 (p->flags & SWP_DISCARDABLE) ? "D" : "");
74999
75000 mutex_unlock(&swapon_mutex);
75001 - atomic_inc(&proc_poll_event);
75002 + atomic_inc_unchecked(&proc_poll_event);
75003 wake_up_interruptible(&proc_poll_wait);
75004
75005 if (S_ISREG(inode->i_mode))
75006 diff -urNp linux-2.6.39/mm/util.c linux-2.6.39/mm/util.c
75007 --- linux-2.6.39/mm/util.c 2011-05-19 00:06:34.000000000 -0400
75008 +++ linux-2.6.39/mm/util.c 2011-05-23 17:07:00.000000000 -0400
75009 @@ -112,6 +112,7 @@ EXPORT_SYMBOL(memdup_user);
75010 * allocated buffer. Use this if you don't want to free the buffer immediately
75011 * like, for example, with RCU.
75012 */
75013 +#undef __krealloc
75014 void *__krealloc(const void *p, size_t new_size, gfp_t flags)
75015 {
75016 void *ret;
75017 @@ -145,6 +146,7 @@ EXPORT_SYMBOL(__krealloc);
75018 * behaves exactly like kmalloc(). If @size is 0 and @p is not a
75019 * %NULL pointer, the object pointed to is freed.
75020 */
75021 +#undef krealloc
75022 void *krealloc(const void *p, size_t new_size, gfp_t flags)
75023 {
75024 void *ret;
75025 @@ -219,6 +221,12 @@ EXPORT_SYMBOL(strndup_user);
75026 void arch_pick_mmap_layout(struct mm_struct *mm)
75027 {
75028 mm->mmap_base = TASK_UNMAPPED_BASE;
75029 +
75030 +#ifdef CONFIG_PAX_RANDMMAP
75031 + if (mm->pax_flags & MF_PAX_RANDMMAP)
75032 + mm->mmap_base += mm->delta_mmap;
75033 +#endif
75034 +
75035 mm->get_unmapped_area = arch_get_unmapped_area;
75036 mm->unmap_area = arch_unmap_area;
75037 }
75038 diff -urNp linux-2.6.39/mm/vmalloc.c linux-2.6.39/mm/vmalloc.c
75039 --- linux-2.6.39/mm/vmalloc.c 2011-05-19 00:06:34.000000000 -0400
75040 +++ linux-2.6.39/mm/vmalloc.c 2011-05-22 19:36:33.000000000 -0400
75041 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd,
75042
75043 pte = pte_offset_kernel(pmd, addr);
75044 do {
75045 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
75046 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
75047 +
75048 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75049 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
75050 + BUG_ON(!pte_exec(*pte));
75051 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
75052 + continue;
75053 + }
75054 +#endif
75055 +
75056 + {
75057 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
75058 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
75059 + }
75060 } while (pte++, addr += PAGE_SIZE, addr != end);
75061 }
75062
75063 @@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, un
75064 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
75065 {
75066 pte_t *pte;
75067 + int ret = -ENOMEM;
75068
75069 /*
75070 * nr is a running index into the array which helps higher level
75071 @@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, un
75072 pte = pte_alloc_kernel(pmd, addr);
75073 if (!pte)
75074 return -ENOMEM;
75075 +
75076 + pax_open_kernel();
75077 do {
75078 struct page *page = pages[*nr];
75079
75080 - if (WARN_ON(!pte_none(*pte)))
75081 - return -EBUSY;
75082 - if (WARN_ON(!page))
75083 - return -ENOMEM;
75084 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75085 + if (pgprot_val(prot) & _PAGE_NX)
75086 +#endif
75087 +
75088 + if (WARN_ON(!pte_none(*pte))) {
75089 + ret = -EBUSY;
75090 + goto out;
75091 + }
75092 + if (WARN_ON(!page)) {
75093 + ret = -ENOMEM;
75094 + goto out;
75095 + }
75096 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
75097 (*nr)++;
75098 } while (pte++, addr += PAGE_SIZE, addr != end);
75099 - return 0;
75100 + ret = 0;
75101 +out:
75102 + pax_close_kernel();
75103 + return ret;
75104 }
75105
75106 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
75107 @@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void
75108 * and fall back on vmalloc() if that fails. Others
75109 * just put it in the vmalloc space.
75110 */
75111 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
75112 +#ifdef CONFIG_MODULES
75113 +#ifdef MODULES_VADDR
75114 unsigned long addr = (unsigned long)x;
75115 if (addr >= MODULES_VADDR && addr < MODULES_END)
75116 return 1;
75117 #endif
75118 +
75119 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75120 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
75121 + return 1;
75122 +#endif
75123 +
75124 +#endif
75125 +
75126 return is_vmalloc_addr(x);
75127 }
75128
75129 @@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void
75130
75131 if (!pgd_none(*pgd)) {
75132 pud_t *pud = pud_offset(pgd, addr);
75133 +#ifdef CONFIG_X86
75134 + if (!pud_large(*pud))
75135 +#endif
75136 if (!pud_none(*pud)) {
75137 pmd_t *pmd = pmd_offset(pud, addr);
75138 +#ifdef CONFIG_X86
75139 + if (!pmd_large(*pmd))
75140 +#endif
75141 if (!pmd_none(*pmd)) {
75142 pte_t *ptep, pte;
75143
75144 @@ -1296,6 +1336,16 @@ static struct vm_struct *__get_vm_area_n
75145 struct vm_struct *area;
75146
75147 BUG_ON(in_interrupt());
75148 +
75149 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75150 + if (flags & VM_KERNEXEC) {
75151 + if (start != VMALLOC_START || end != VMALLOC_END)
75152 + return NULL;
75153 + start = (unsigned long)MODULES_EXEC_VADDR;
75154 + end = (unsigned long)MODULES_EXEC_END;
75155 + }
75156 +#endif
75157 +
75158 if (flags & VM_IOREMAP) {
75159 int bit = fls(size);
75160
75161 @@ -1514,6 +1564,11 @@ void *vmap(struct page **pages, unsigned
75162 if (count > totalram_pages)
75163 return NULL;
75164
75165 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75166 + if (!(pgprot_val(prot) & _PAGE_NX))
75167 + flags |= VM_KERNEXEC;
75168 +#endif
75169 +
75170 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
75171 __builtin_return_address(0));
75172 if (!area)
75173 @@ -1610,6 +1665,13 @@ void *__vmalloc_node_range(unsigned long
75174 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
75175 return NULL;
75176
75177 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75178 + if (!(pgprot_val(prot) & _PAGE_NX))
75179 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_KERNEXEC, VMALLOC_START, VMALLOC_END,
75180 + node, gfp_mask, caller);
75181 + else
75182 +#endif
75183 +
75184 area = __get_vm_area_node(size, align, VM_ALLOC, start, end, node,
75185 gfp_mask, caller);
75186
75187 @@ -1649,6 +1711,7 @@ static void *__vmalloc_node(unsigned lon
75188 gfp_mask, prot, node, caller);
75189 }
75190
75191 +#undef __vmalloc
75192 void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot)
75193 {
75194 return __vmalloc_node(size, 1, gfp_mask, prot, -1,
75195 @@ -1672,6 +1735,7 @@ static inline void *__vmalloc_node_flags
75196 * For tight control over page level allocator and protection flags
75197 * use __vmalloc() instead.
75198 */
75199 +#undef vmalloc
75200 void *vmalloc(unsigned long size)
75201 {
75202 return __vmalloc_node_flags(size, -1, GFP_KERNEL | __GFP_HIGHMEM);
75203 @@ -1688,6 +1752,7 @@ EXPORT_SYMBOL(vmalloc);
75204 * For tight control over page level allocator and protection flags
75205 * use __vmalloc() instead.
75206 */
75207 +#undef vzalloc
75208 void *vzalloc(unsigned long size)
75209 {
75210 return __vmalloc_node_flags(size, -1,
75211 @@ -1702,6 +1767,7 @@ EXPORT_SYMBOL(vzalloc);
75212 * The resulting memory area is zeroed so it can be mapped to userspace
75213 * without leaking data.
75214 */
75215 +#undef vmalloc_user
75216 void *vmalloc_user(unsigned long size)
75217 {
75218 struct vm_struct *area;
75219 @@ -1729,6 +1795,7 @@ EXPORT_SYMBOL(vmalloc_user);
75220 * For tight control over page level allocator and protection flags
75221 * use __vmalloc() instead.
75222 */
75223 +#undef vmalloc_node
75224 void *vmalloc_node(unsigned long size, int node)
75225 {
75226 return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL,
75227 @@ -1748,6 +1815,7 @@ EXPORT_SYMBOL(vmalloc_node);
75228 * For tight control over page level allocator and protection flags
75229 * use __vmalloc_node() instead.
75230 */
75231 +#undef vzalloc_node
75232 void *vzalloc_node(unsigned long size, int node)
75233 {
75234 return __vmalloc_node_flags(size, node,
75235 @@ -1770,10 +1838,10 @@ EXPORT_SYMBOL(vzalloc_node);
75236 * For tight control over page level allocator and protection flags
75237 * use __vmalloc() instead.
75238 */
75239 -
75240 +#undef vmalloc_exec
75241 void *vmalloc_exec(unsigned long size)
75242 {
75243 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
75244 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
75245 -1, __builtin_return_address(0));
75246 }
75247
75248 @@ -1792,6 +1860,7 @@ void *vmalloc_exec(unsigned long size)
75249 * Allocate enough 32bit PA addressable pages to cover @size from the
75250 * page level allocator and map them into contiguous kernel virtual space.
75251 */
75252 +#undef vmalloc_32
75253 void *vmalloc_32(unsigned long size)
75254 {
75255 return __vmalloc_node(size, 1, GFP_VMALLOC32, PAGE_KERNEL,
75256 @@ -1806,6 +1875,7 @@ EXPORT_SYMBOL(vmalloc_32);
75257 * The resulting memory area is 32bit addressable and zeroed so it can be
75258 * mapped to userspace without leaking data.
75259 */
75260 +#undef vmalloc_32_user
75261 void *vmalloc_32_user(unsigned long size)
75262 {
75263 struct vm_struct *area;
75264 @@ -2068,6 +2138,8 @@ int remap_vmalloc_range(struct vm_area_s
75265 unsigned long uaddr = vma->vm_start;
75266 unsigned long usize = vma->vm_end - vma->vm_start;
75267
75268 + BUG_ON(vma->vm_mirror);
75269 +
75270 if ((PAGE_SIZE-1) & (unsigned long)addr)
75271 return -EINVAL;
75272
75273 diff -urNp linux-2.6.39/mm/vmstat.c linux-2.6.39/mm/vmstat.c
75274 --- linux-2.6.39/mm/vmstat.c 2011-05-19 00:06:34.000000000 -0400
75275 +++ linux-2.6.39/mm/vmstat.c 2011-05-22 19:41:42.000000000 -0400
75276 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
75277 *
75278 * vm_stat contains the global counters
75279 */
75280 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
75281 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
75282 EXPORT_SYMBOL(vm_stat);
75283
75284 #ifdef CONFIG_SMP
75285 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
75286 v = p->vm_stat_diff[i];
75287 p->vm_stat_diff[i] = 0;
75288 local_irq_restore(flags);
75289 - atomic_long_add(v, &zone->vm_stat[i]);
75290 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
75291 global_diff[i] += v;
75292 #ifdef CONFIG_NUMA
75293 /* 3 seconds idle till flush */
75294 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
75295
75296 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
75297 if (global_diff[i])
75298 - atomic_long_add(global_diff[i], &vm_stat[i]);
75299 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
75300 }
75301
75302 #endif
75303 @@ -1205,10 +1205,20 @@ static int __init setup_vmstat(void)
75304 start_cpu_timer(cpu);
75305 #endif
75306 #ifdef CONFIG_PROC_FS
75307 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
75308 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
75309 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
75310 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
75311 + {
75312 + mode_t gr_mode = S_IRUGO;
75313 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
75314 + gr_mode = S_IRUSR;
75315 +#endif
75316 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
75317 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
75318 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
75319 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
75320 +#else
75321 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
75322 +#endif
75323 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
75324 + }
75325 #endif
75326 return 0;
75327 }
75328 diff -urNp linux-2.6.39/net/8021q/vlan.c linux-2.6.39/net/8021q/vlan.c
75329 --- linux-2.6.39/net/8021q/vlan.c 2011-05-19 00:06:34.000000000 -0400
75330 +++ linux-2.6.39/net/8021q/vlan.c 2011-05-22 19:36:33.000000000 -0400
75331 @@ -592,8 +592,7 @@ static int vlan_ioctl_handler(struct net
75332 err = -EPERM;
75333 if (!capable(CAP_NET_ADMIN))
75334 break;
75335 - if ((args.u.name_type >= 0) &&
75336 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
75337 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
75338 struct vlan_net *vn;
75339
75340 vn = net_generic(net, vlan_net_id);
75341 diff -urNp linux-2.6.39/net/atm/atm_misc.c linux-2.6.39/net/atm/atm_misc.c
75342 --- linux-2.6.39/net/atm/atm_misc.c 2011-05-19 00:06:34.000000000 -0400
75343 +++ linux-2.6.39/net/atm/atm_misc.c 2011-05-22 19:36:33.000000000 -0400
75344 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int
75345 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
75346 return 1;
75347 atm_return(vcc, truesize);
75348 - atomic_inc(&vcc->stats->rx_drop);
75349 + atomic_inc_unchecked(&vcc->stats->rx_drop);
75350 return 0;
75351 }
75352 EXPORT_SYMBOL(atm_charge);
75353 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct
75354 }
75355 }
75356 atm_return(vcc, guess);
75357 - atomic_inc(&vcc->stats->rx_drop);
75358 + atomic_inc_unchecked(&vcc->stats->rx_drop);
75359 return NULL;
75360 }
75361 EXPORT_SYMBOL(atm_alloc_charge);
75362 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
75363
75364 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
75365 {
75366 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
75367 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
75368 __SONET_ITEMS
75369 #undef __HANDLE_ITEM
75370 }
75371 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
75372
75373 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
75374 {
75375 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
75376 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
75377 __SONET_ITEMS
75378 #undef __HANDLE_ITEM
75379 }
75380 diff -urNp linux-2.6.39/net/atm/mpoa_caches.c linux-2.6.39/net/atm/mpoa_caches.c
75381 --- linux-2.6.39/net/atm/mpoa_caches.c 2011-05-19 00:06:34.000000000 -0400
75382 +++ linux-2.6.39/net/atm/mpoa_caches.c 2011-05-22 19:36:33.000000000 -0400
75383 @@ -255,6 +255,8 @@ static void check_resolving_entries(stru
75384 struct timeval now;
75385 struct k_message msg;
75386
75387 + pax_track_stack();
75388 +
75389 do_gettimeofday(&now);
75390
75391 read_lock_bh(&client->ingress_lock);
75392 diff -urNp linux-2.6.39/net/atm/proc.c linux-2.6.39/net/atm/proc.c
75393 --- linux-2.6.39/net/atm/proc.c 2011-05-19 00:06:34.000000000 -0400
75394 +++ linux-2.6.39/net/atm/proc.c 2011-05-22 19:41:42.000000000 -0400
75395 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *s
75396 const struct k_atm_aal_stats *stats)
75397 {
75398 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
75399 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
75400 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
75401 - atomic_read(&stats->rx_drop));
75402 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
75403 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
75404 + atomic_read_unchecked(&stats->rx_drop));
75405 }
75406
75407 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
75408 @@ -191,7 +191,12 @@ static void vcc_info(struct seq_file *se
75409 {
75410 struct sock *sk = sk_atm(vcc);
75411
75412 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75413 + seq_printf(seq, "%p ", NULL);
75414 +#else
75415 seq_printf(seq, "%p ", vcc);
75416 +#endif
75417 +
75418 if (!vcc->dev)
75419 seq_printf(seq, "Unassigned ");
75420 else
75421 @@ -218,7 +223,11 @@ static void svc_info(struct seq_file *se
75422 {
75423 if (!vcc->dev)
75424 seq_printf(seq, sizeof(void *) == 4 ?
75425 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75426 + "N/A@%p%10s" : "N/A@%p%2s", NULL, "");
75427 +#else
75428 "N/A@%p%10s" : "N/A@%p%2s", vcc, "");
75429 +#endif
75430 else
75431 seq_printf(seq, "%3d %3d %5d ",
75432 vcc->dev->number, vcc->vpi, vcc->vci);
75433 diff -urNp linux-2.6.39/net/atm/resources.c linux-2.6.39/net/atm/resources.c
75434 --- linux-2.6.39/net/atm/resources.c 2011-05-19 00:06:34.000000000 -0400
75435 +++ linux-2.6.39/net/atm/resources.c 2011-05-22 19:36:33.000000000 -0400
75436 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
75437 static void copy_aal_stats(struct k_atm_aal_stats *from,
75438 struct atm_aal_stats *to)
75439 {
75440 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
75441 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
75442 __AAL_STAT_ITEMS
75443 #undef __HANDLE_ITEM
75444 }
75445 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_
75446 static void subtract_aal_stats(struct k_atm_aal_stats *from,
75447 struct atm_aal_stats *to)
75448 {
75449 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
75450 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
75451 __AAL_STAT_ITEMS
75452 #undef __HANDLE_ITEM
75453 }
75454 diff -urNp linux-2.6.39/net/batman-adv/hard-interface.c linux-2.6.39/net/batman-adv/hard-interface.c
75455 --- linux-2.6.39/net/batman-adv/hard-interface.c 2011-05-19 00:06:34.000000000 -0400
75456 +++ linux-2.6.39/net/batman-adv/hard-interface.c 2011-05-22 19:36:33.000000000 -0400
75457 @@ -339,8 +339,8 @@ int hardif_enable_interface(struct hard_
75458 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
75459 dev_add_pack(&hard_iface->batman_adv_ptype);
75460
75461 - atomic_set(&hard_iface->seqno, 1);
75462 - atomic_set(&hard_iface->frag_seqno, 1);
75463 + atomic_set_unchecked(&hard_iface->seqno, 1);
75464 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
75465 bat_info(hard_iface->soft_iface, "Adding interface: %s\n",
75466 hard_iface->net_dev->name);
75467
75468 diff -urNp linux-2.6.39/net/batman-adv/routing.c linux-2.6.39/net/batman-adv/routing.c
75469 --- linux-2.6.39/net/batman-adv/routing.c 2011-05-19 00:06:34.000000000 -0400
75470 +++ linux-2.6.39/net/batman-adv/routing.c 2011-05-22 19:36:33.000000000 -0400
75471 @@ -625,7 +625,7 @@ void receive_bat_packet(struct ethhdr *e
75472 return;
75473
75474 /* could be changed by schedule_own_packet() */
75475 - if_incoming_seqno = atomic_read(&if_incoming->seqno);
75476 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
75477
75478 has_directlink_flag = (batman_packet->flags & DIRECTLINK ? 1 : 0);
75479
75480 diff -urNp linux-2.6.39/net/batman-adv/send.c linux-2.6.39/net/batman-adv/send.c
75481 --- linux-2.6.39/net/batman-adv/send.c 2011-05-19 00:06:34.000000000 -0400
75482 +++ linux-2.6.39/net/batman-adv/send.c 2011-05-22 19:36:33.000000000 -0400
75483 @@ -277,7 +277,7 @@ void schedule_own_packet(struct hard_ifa
75484
75485 /* change sequence number to network order */
75486 batman_packet->seqno =
75487 - htonl((uint32_t)atomic_read(&hard_iface->seqno));
75488 + htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
75489
75490 if (vis_server == VIS_TYPE_SERVER_SYNC)
75491 batman_packet->flags |= VIS_SERVER;
75492 @@ -291,7 +291,7 @@ void schedule_own_packet(struct hard_ifa
75493 else
75494 batman_packet->gw_flags = 0;
75495
75496 - atomic_inc(&hard_iface->seqno);
75497 + atomic_inc_unchecked(&hard_iface->seqno);
75498
75499 slide_own_bcast_window(hard_iface);
75500 send_time = own_send_time(bat_priv);
75501 diff -urNp linux-2.6.39/net/batman-adv/soft-interface.c linux-2.6.39/net/batman-adv/soft-interface.c
75502 --- linux-2.6.39/net/batman-adv/soft-interface.c 2011-05-19 00:06:34.000000000 -0400
75503 +++ linux-2.6.39/net/batman-adv/soft-interface.c 2011-05-22 19:36:33.000000000 -0400
75504 @@ -386,7 +386,7 @@ int interface_tx(struct sk_buff *skb, st
75505
75506 /* set broadcast sequence number */
75507 bcast_packet->seqno =
75508 - htonl(atomic_inc_return(&bat_priv->bcast_seqno));
75509 + htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
75510
75511 add_bcast_packet_to_list(bat_priv, skb);
75512
75513 @@ -579,7 +579,7 @@ struct net_device *softif_create(char *n
75514 atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);
75515
75516 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
75517 - atomic_set(&bat_priv->bcast_seqno, 1);
75518 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
75519 atomic_set(&bat_priv->hna_local_changed, 0);
75520
75521 bat_priv->primary_if = NULL;
75522 diff -urNp linux-2.6.39/net/batman-adv/types.h linux-2.6.39/net/batman-adv/types.h
75523 --- linux-2.6.39/net/batman-adv/types.h 2011-05-19 00:06:34.000000000 -0400
75524 +++ linux-2.6.39/net/batman-adv/types.h 2011-05-22 19:36:33.000000000 -0400
75525 @@ -38,8 +38,8 @@ struct hard_iface {
75526 int16_t if_num;
75527 char if_status;
75528 struct net_device *net_dev;
75529 - atomic_t seqno;
75530 - atomic_t frag_seqno;
75531 + atomic_unchecked_t seqno;
75532 + atomic_unchecked_t frag_seqno;
75533 unsigned char *packet_buff;
75534 int packet_len;
75535 struct kobject *hardif_obj;
75536 @@ -141,7 +141,7 @@ struct bat_priv {
75537 atomic_t orig_interval; /* uint */
75538 atomic_t hop_penalty; /* uint */
75539 atomic_t log_level; /* uint */
75540 - atomic_t bcast_seqno;
75541 + atomic_unchecked_t bcast_seqno;
75542 atomic_t bcast_queue_left;
75543 atomic_t batman_queue_left;
75544 char num_ifaces;
75545 diff -urNp linux-2.6.39/net/batman-adv/unicast.c linux-2.6.39/net/batman-adv/unicast.c
75546 --- linux-2.6.39/net/batman-adv/unicast.c 2011-05-19 00:06:34.000000000 -0400
75547 +++ linux-2.6.39/net/batman-adv/unicast.c 2011-05-22 19:36:33.000000000 -0400
75548 @@ -263,7 +263,7 @@ int frag_send_skb(struct sk_buff *skb, s
75549 frag1->flags = UNI_FRAG_HEAD | large_tail;
75550 frag2->flags = large_tail;
75551
75552 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
75553 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
75554 frag1->seqno = htons(seqno - 1);
75555 frag2->seqno = htons(seqno);
75556
75557 diff -urNp linux-2.6.39/net/bridge/br_multicast.c linux-2.6.39/net/bridge/br_multicast.c
75558 --- linux-2.6.39/net/bridge/br_multicast.c 2011-05-19 00:06:34.000000000 -0400
75559 +++ linux-2.6.39/net/bridge/br_multicast.c 2011-05-22 19:36:33.000000000 -0400
75560 @@ -1482,7 +1482,7 @@ static int br_multicast_ipv6_rcv(struct
75561 nexthdr = ip6h->nexthdr;
75562 offset = ipv6_skip_exthdr(skb, sizeof(*ip6h), &nexthdr);
75563
75564 - if (offset < 0 || nexthdr != IPPROTO_ICMPV6)
75565 + if (nexthdr != IPPROTO_ICMPV6)
75566 return 0;
75567
75568 /* Okay, we found ICMPv6 header */
75569 diff -urNp linux-2.6.39/net/bridge/netfilter/ebtables.c linux-2.6.39/net/bridge/netfilter/ebtables.c
75570 --- linux-2.6.39/net/bridge/netfilter/ebtables.c 2011-05-19 00:06:34.000000000 -0400
75571 +++ linux-2.6.39/net/bridge/netfilter/ebtables.c 2011-05-22 19:36:33.000000000 -0400
75572 @@ -1512,7 +1512,7 @@ static int do_ebt_get_ctl(struct sock *s
75573 tmp.valid_hooks = t->table->valid_hooks;
75574 }
75575 mutex_unlock(&ebt_mutex);
75576 - if (copy_to_user(user, &tmp, *len) != 0){
75577 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
75578 BUGPRINT("c2u Didn't work\n");
75579 ret = -EFAULT;
75580 break;
75581 @@ -1780,6 +1780,8 @@ static int compat_copy_everything_to_use
75582 int ret;
75583 void __user *pos;
75584
75585 + pax_track_stack();
75586 +
75587 memset(&tinfo, 0, sizeof(tinfo));
75588
75589 if (cmd == EBT_SO_GET_ENTRIES) {
75590 diff -urNp linux-2.6.39/net/caif/caif_socket.c linux-2.6.39/net/caif/caif_socket.c
75591 --- linux-2.6.39/net/caif/caif_socket.c 2011-05-19 00:06:34.000000000 -0400
75592 +++ linux-2.6.39/net/caif/caif_socket.c 2011-05-22 19:36:33.000000000 -0400
75593 @@ -48,18 +48,19 @@ static struct dentry *debugfsdir;
75594 #ifdef CONFIG_DEBUG_FS
75595 struct debug_fs_counter {
75596 atomic_t caif_nr_socks;
75597 - atomic_t num_connect_req;
75598 - atomic_t num_connect_resp;
75599 - atomic_t num_connect_fail_resp;
75600 - atomic_t num_disconnect;
75601 - atomic_t num_remote_shutdown_ind;
75602 - atomic_t num_tx_flow_off_ind;
75603 - atomic_t num_tx_flow_on_ind;
75604 - atomic_t num_rx_flow_off;
75605 - atomic_t num_rx_flow_on;
75606 + atomic_unchecked_t num_connect_req;
75607 + atomic_unchecked_t num_connect_resp;
75608 + atomic_unchecked_t num_connect_fail_resp;
75609 + atomic_unchecked_t num_disconnect;
75610 + atomic_unchecked_t num_remote_shutdown_ind;
75611 + atomic_unchecked_t num_tx_flow_off_ind;
75612 + atomic_unchecked_t num_tx_flow_on_ind;
75613 + atomic_unchecked_t num_rx_flow_off;
75614 + atomic_unchecked_t num_rx_flow_on;
75615 };
75616 static struct debug_fs_counter cnt;
75617 #define dbfs_atomic_inc(v) atomic_inc(v)
75618 +#define dbfs_atomic_inc_unchecked(v) atomic_inc_unchecked(v)
75619 #define dbfs_atomic_dec(v) atomic_dec(v)
75620 #else
75621 #define dbfs_atomic_inc(v)
75622 @@ -159,7 +160,7 @@ static int caif_queue_rcv_skb(struct soc
75623 atomic_read(&cf_sk->sk.sk_rmem_alloc),
75624 sk_rcvbuf_lowwater(cf_sk));
75625 set_rx_flow_off(cf_sk);
75626 - dbfs_atomic_inc(&cnt.num_rx_flow_off);
75627 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
75628 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
75629 }
75630
75631 @@ -169,7 +170,7 @@ static int caif_queue_rcv_skb(struct soc
75632 if (!sk_rmem_schedule(sk, skb->truesize) && rx_flow_is_on(cf_sk)) {
75633 set_rx_flow_off(cf_sk);
75634 pr_debug("sending flow OFF due to rmem_schedule\n");
75635 - dbfs_atomic_inc(&cnt.num_rx_flow_off);
75636 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
75637 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
75638 }
75639 skb->dev = NULL;
75640 @@ -218,21 +219,21 @@ static void caif_ctrl_cb(struct cflayer
75641 switch (flow) {
75642 case CAIF_CTRLCMD_FLOW_ON_IND:
75643 /* OK from modem to start sending again */
75644 - dbfs_atomic_inc(&cnt.num_tx_flow_on_ind);
75645 + dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_on_ind);
75646 set_tx_flow_on(cf_sk);
75647 cf_sk->sk.sk_state_change(&cf_sk->sk);
75648 break;
75649
75650 case CAIF_CTRLCMD_FLOW_OFF_IND:
75651 /* Modem asks us to shut up */
75652 - dbfs_atomic_inc(&cnt.num_tx_flow_off_ind);
75653 + dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_off_ind);
75654 set_tx_flow_off(cf_sk);
75655 cf_sk->sk.sk_state_change(&cf_sk->sk);
75656 break;
75657
75658 case CAIF_CTRLCMD_INIT_RSP:
75659 /* We're now connected */
75660 - dbfs_atomic_inc(&cnt.num_connect_resp);
75661 + dbfs_atomic_inc_unchecked(&cnt.num_connect_resp);
75662 cf_sk->sk.sk_state = CAIF_CONNECTED;
75663 set_tx_flow_on(cf_sk);
75664 cf_sk->sk.sk_state_change(&cf_sk->sk);
75665 @@ -247,7 +248,7 @@ static void caif_ctrl_cb(struct cflayer
75666
75667 case CAIF_CTRLCMD_INIT_FAIL_RSP:
75668 /* Connect request failed */
75669 - dbfs_atomic_inc(&cnt.num_connect_fail_resp);
75670 + dbfs_atomic_inc_unchecked(&cnt.num_connect_fail_resp);
75671 cf_sk->sk.sk_err = ECONNREFUSED;
75672 cf_sk->sk.sk_state = CAIF_DISCONNECTED;
75673 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
75674 @@ -261,7 +262,7 @@ static void caif_ctrl_cb(struct cflayer
75675
75676 case CAIF_CTRLCMD_REMOTE_SHUTDOWN_IND:
75677 /* Modem has closed this connection, or device is down. */
75678 - dbfs_atomic_inc(&cnt.num_remote_shutdown_ind);
75679 + dbfs_atomic_inc_unchecked(&cnt.num_remote_shutdown_ind);
75680 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
75681 cf_sk->sk.sk_err = ECONNRESET;
75682 set_rx_flow_on(cf_sk);
75683 @@ -281,7 +282,7 @@ static void caif_check_flow_release(stru
75684 return;
75685
75686 if (atomic_read(&sk->sk_rmem_alloc) <= sk_rcvbuf_lowwater(cf_sk)) {
75687 - dbfs_atomic_inc(&cnt.num_rx_flow_on);
75688 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_on);
75689 set_rx_flow_on(cf_sk);
75690 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_ON_REQ);
75691 }
75692 @@ -864,7 +865,7 @@ static int caif_connect(struct socket *s
75693 /*ifindex = id of the interface.*/
75694 cf_sk->conn_req.ifindex = cf_sk->sk.sk_bound_dev_if;
75695
75696 - dbfs_atomic_inc(&cnt.num_connect_req);
75697 + dbfs_atomic_inc_unchecked(&cnt.num_connect_req);
75698 cf_sk->layer.receive = caif_sktrecv_cb;
75699 err = caif_connect_client(&cf_sk->conn_req,
75700 &cf_sk->layer, &ifindex, &headroom, &tailroom);
75701 @@ -952,7 +953,7 @@ static int caif_release(struct socket *s
75702 spin_unlock(&sk->sk_receive_queue.lock);
75703 sock->sk = NULL;
75704
75705 - dbfs_atomic_inc(&cnt.num_disconnect);
75706 + dbfs_atomic_inc_unchecked(&cnt.num_disconnect);
75707
75708 if (cf_sk->debugfs_socket_dir != NULL)
75709 debugfs_remove_recursive(cf_sk->debugfs_socket_dir);
75710 diff -urNp linux-2.6.39/net/caif/cfctrl.c linux-2.6.39/net/caif/cfctrl.c
75711 --- linux-2.6.39/net/caif/cfctrl.c 2011-05-19 00:06:34.000000000 -0400
75712 +++ linux-2.6.39/net/caif/cfctrl.c 2011-05-22 19:36:33.000000000 -0400
75713 @@ -9,6 +9,7 @@
75714 #include <linux/stddef.h>
75715 #include <linux/spinlock.h>
75716 #include <linux/slab.h>
75717 +#include <linux/sched.h>
75718 #include <net/caif/caif_layer.h>
75719 #include <net/caif/cfpkt.h>
75720 #include <net/caif/cfctrl.h>
75721 @@ -46,8 +47,8 @@ struct cflayer *cfctrl_create(void)
75722 dev_info.id = 0xff;
75723 memset(this, 0, sizeof(*this));
75724 cfsrvl_init(&this->serv, 0, &dev_info, false);
75725 - atomic_set(&this->req_seq_no, 1);
75726 - atomic_set(&this->rsp_seq_no, 1);
75727 + atomic_set_unchecked(&this->req_seq_no, 1);
75728 + atomic_set_unchecked(&this->rsp_seq_no, 1);
75729 this->serv.layer.receive = cfctrl_recv;
75730 sprintf(this->serv.layer.name, "ctrl");
75731 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
75732 @@ -116,8 +117,8 @@ void cfctrl_insert_req(struct cfctrl *ct
75733 struct cfctrl_request_info *req)
75734 {
75735 spin_lock(&ctrl->info_list_lock);
75736 - atomic_inc(&ctrl->req_seq_no);
75737 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
75738 + atomic_inc_unchecked(&ctrl->req_seq_no);
75739 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
75740 list_add_tail(&req->list, &ctrl->list);
75741 spin_unlock(&ctrl->info_list_lock);
75742 }
75743 @@ -136,7 +137,7 @@ struct cfctrl_request_info *cfctrl_remov
75744 if (p != first)
75745 pr_warn("Requests are not received in order\n");
75746
75747 - atomic_set(&ctrl->rsp_seq_no,
75748 + atomic_set_unchecked(&ctrl->rsp_seq_no,
75749 p->sequence_no);
75750 list_del(&p->list);
75751 goto out;
75752 @@ -385,6 +386,7 @@ static int cfctrl_recv(struct cflayer *l
75753 struct cfctrl *cfctrl = container_obj(layer);
75754 struct cfctrl_request_info rsp, *req;
75755
75756 + pax_track_stack();
75757
75758 cfpkt_extr_head(pkt, &cmdrsp, 1);
75759 cmd = cmdrsp & CFCTRL_CMD_MASK;
75760 diff -urNp linux-2.6.39/net/can/bcm.c linux-2.6.39/net/can/bcm.c
75761 --- linux-2.6.39/net/can/bcm.c 2011-05-19 00:06:34.000000000 -0400
75762 +++ linux-2.6.39/net/can/bcm.c 2011-05-22 19:41:42.000000000 -0400
75763 @@ -165,9 +165,15 @@ static int bcm_proc_show(struct seq_file
75764 struct bcm_sock *bo = bcm_sk(sk);
75765 struct bcm_op *op;
75766
75767 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75768 + seq_printf(m, ">>> socket %p", NULL);
75769 + seq_printf(m, " / sk %p", NULL);
75770 + seq_printf(m, " / bo %p", NULL);
75771 +#else
75772 seq_printf(m, ">>> socket %p", sk->sk_socket);
75773 seq_printf(m, " / sk %p", sk);
75774 seq_printf(m, " / bo %p", bo);
75775 +#endif
75776 seq_printf(m, " / dropped %lu", bo->dropped_usr_msgs);
75777 seq_printf(m, " / bound %s", bcm_proc_getifname(ifname, bo->ifindex));
75778 seq_printf(m, " <<<\n");
75779 diff -urNp linux-2.6.39/net/core/datagram.c linux-2.6.39/net/core/datagram.c
75780 --- linux-2.6.39/net/core/datagram.c 2011-05-19 00:06:34.000000000 -0400
75781 +++ linux-2.6.39/net/core/datagram.c 2011-05-22 19:36:33.000000000 -0400
75782 @@ -285,7 +285,7 @@ int skb_kill_datagram(struct sock *sk, s
75783 }
75784
75785 kfree_skb(skb);
75786 - atomic_inc(&sk->sk_drops);
75787 + atomic_inc_unchecked(&sk->sk_drops);
75788 sk_mem_reclaim_partial(sk);
75789
75790 return err;
75791 diff -urNp linux-2.6.39/net/core/dev.c linux-2.6.39/net/core/dev.c
75792 --- linux-2.6.39/net/core/dev.c 2011-05-19 00:06:34.000000000 -0400
75793 +++ linux-2.6.39/net/core/dev.c 2011-05-22 19:41:42.000000000 -0400
75794 @@ -1125,10 +1125,14 @@ void dev_load(struct net *net, const cha
75795 if (no_module && capable(CAP_NET_ADMIN))
75796 no_module = request_module("netdev-%s", name);
75797 if (no_module && capable(CAP_SYS_MODULE)) {
75798 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
75799 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
75800 +#else
75801 if (!request_module("%s", name))
75802 pr_err("Loading kernel module for a network device "
75803 "with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s "
75804 "instead\n", name);
75805 +#endif
75806 }
75807 }
75808 EXPORT_SYMBOL(dev_load);
75809 @@ -1957,7 +1961,7 @@ struct dev_gso_cb {
75810
75811 static void dev_gso_skb_destructor(struct sk_buff *skb)
75812 {
75813 - struct dev_gso_cb *cb;
75814 + const struct dev_gso_cb *cb;
75815
75816 do {
75817 struct sk_buff *nskb = skb->next;
75818 @@ -2901,7 +2905,7 @@ int netif_rx_ni(struct sk_buff *skb)
75819 }
75820 EXPORT_SYMBOL(netif_rx_ni);
75821
75822 -static void net_tx_action(struct softirq_action *h)
75823 +static void net_tx_action(void)
75824 {
75825 struct softnet_data *sd = &__get_cpu_var(softnet_data);
75826
75827 @@ -3765,7 +3769,7 @@ void netif_napi_del(struct napi_struct *
75828 }
75829 EXPORT_SYMBOL(netif_napi_del);
75830
75831 -static void net_rx_action(struct softirq_action *h)
75832 +static void net_rx_action(void)
75833 {
75834 struct softnet_data *sd = &__get_cpu_var(softnet_data);
75835 unsigned long time_limit = jiffies + 2;
75836 diff -urNp linux-2.6.39/net/core/flow.c linux-2.6.39/net/core/flow.c
75837 --- linux-2.6.39/net/core/flow.c 2011-05-19 00:06:34.000000000 -0400
75838 +++ linux-2.6.39/net/core/flow.c 2011-05-22 19:36:34.000000000 -0400
75839 @@ -60,7 +60,7 @@ struct flow_cache {
75840 struct timer_list rnd_timer;
75841 };
75842
75843 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
75844 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
75845 EXPORT_SYMBOL(flow_cache_genid);
75846 static struct flow_cache flow_cache_global;
75847 static struct kmem_cache *flow_cachep __read_mostly;
75848 @@ -85,7 +85,7 @@ static void flow_cache_new_hashrnd(unsig
75849
75850 static int flow_entry_valid(struct flow_cache_entry *fle)
75851 {
75852 - if (atomic_read(&flow_cache_genid) != fle->genid)
75853 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
75854 return 0;
75855 if (fle->object && !fle->object->ops->check(fle->object))
75856 return 0;
75857 @@ -253,7 +253,7 @@ flow_cache_lookup(struct net *net, const
75858 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
75859 fcp->hash_count++;
75860 }
75861 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
75862 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
75863 flo = fle->object;
75864 if (!flo)
75865 goto ret_object;
75866 @@ -274,7 +274,7 @@ nocache:
75867 }
75868 flo = resolver(net, key, family, dir, flo, ctx);
75869 if (fle) {
75870 - fle->genid = atomic_read(&flow_cache_genid);
75871 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
75872 if (!IS_ERR(flo))
75873 fle->object = flo;
75874 else
75875 diff -urNp linux-2.6.39/net/core/skbuff.c linux-2.6.39/net/core/skbuff.c
75876 --- linux-2.6.39/net/core/skbuff.c 2011-05-19 00:06:34.000000000 -0400
75877 +++ linux-2.6.39/net/core/skbuff.c 2011-05-22 19:36:34.000000000 -0400
75878 @@ -1542,6 +1542,8 @@ int skb_splice_bits(struct sk_buff *skb,
75879 struct sock *sk = skb->sk;
75880 int ret = 0;
75881
75882 + pax_track_stack();
75883 +
75884 if (splice_grow_spd(pipe, &spd))
75885 return -ENOMEM;
75886
75887 diff -urNp linux-2.6.39/net/core/sock.c linux-2.6.39/net/core/sock.c
75888 --- linux-2.6.39/net/core/sock.c 2011-05-19 00:06:34.000000000 -0400
75889 +++ linux-2.6.39/net/core/sock.c 2011-05-22 19:36:34.000000000 -0400
75890 @@ -291,7 +291,7 @@ int sock_queue_rcv_skb(struct sock *sk,
75891 */
75892 if (atomic_read(&sk->sk_rmem_alloc) + skb->truesize >=
75893 (unsigned)sk->sk_rcvbuf) {
75894 - atomic_inc(&sk->sk_drops);
75895 + atomic_inc_unchecked(&sk->sk_drops);
75896 return -ENOMEM;
75897 }
75898
75899 @@ -300,7 +300,7 @@ int sock_queue_rcv_skb(struct sock *sk,
75900 return err;
75901
75902 if (!sk_rmem_schedule(sk, skb->truesize)) {
75903 - atomic_inc(&sk->sk_drops);
75904 + atomic_inc_unchecked(&sk->sk_drops);
75905 return -ENOBUFS;
75906 }
75907
75908 @@ -320,7 +320,7 @@ int sock_queue_rcv_skb(struct sock *sk,
75909 skb_dst_force(skb);
75910
75911 spin_lock_irqsave(&list->lock, flags);
75912 - skb->dropcount = atomic_read(&sk->sk_drops);
75913 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
75914 __skb_queue_tail(list, skb);
75915 spin_unlock_irqrestore(&list->lock, flags);
75916
75917 @@ -340,7 +340,7 @@ int sk_receive_skb(struct sock *sk, stru
75918 skb->dev = NULL;
75919
75920 if (sk_rcvqueues_full(sk, skb)) {
75921 - atomic_inc(&sk->sk_drops);
75922 + atomic_inc_unchecked(&sk->sk_drops);
75923 goto discard_and_relse;
75924 }
75925 if (nested)
75926 @@ -358,7 +358,7 @@ int sk_receive_skb(struct sock *sk, stru
75927 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
75928 } else if (sk_add_backlog(sk, skb)) {
75929 bh_unlock_sock(sk);
75930 - atomic_inc(&sk->sk_drops);
75931 + atomic_inc_unchecked(&sk->sk_drops);
75932 goto discard_and_relse;
75933 }
75934
75935 @@ -934,7 +934,7 @@ int sock_getsockopt(struct socket *sock,
75936 return -ENOTCONN;
75937 if (lv < len)
75938 return -EINVAL;
75939 - if (copy_to_user(optval, address, len))
75940 + if (len > sizeof(address) || copy_to_user(optval, address, len))
75941 return -EFAULT;
75942 goto lenout;
75943 }
75944 @@ -967,7 +967,7 @@ int sock_getsockopt(struct socket *sock,
75945
75946 if (len > lv)
75947 len = lv;
75948 - if (copy_to_user(optval, &v, len))
75949 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
75950 return -EFAULT;
75951 lenout:
75952 if (put_user(len, optlen))
75953 @@ -2023,7 +2023,7 @@ void sock_init_data(struct socket *sock,
75954 */
75955 smp_wmb();
75956 atomic_set(&sk->sk_refcnt, 1);
75957 - atomic_set(&sk->sk_drops, 0);
75958 + atomic_set_unchecked(&sk->sk_drops, 0);
75959 }
75960 EXPORT_SYMBOL(sock_init_data);
75961
75962 diff -urNp linux-2.6.39/net/decnet/sysctl_net_decnet.c linux-2.6.39/net/decnet/sysctl_net_decnet.c
75963 --- linux-2.6.39/net/decnet/sysctl_net_decnet.c 2011-05-19 00:06:34.000000000 -0400
75964 +++ linux-2.6.39/net/decnet/sysctl_net_decnet.c 2011-05-22 19:36:34.000000000 -0400
75965 @@ -173,7 +173,7 @@ static int dn_node_address_handler(ctl_t
75966
75967 if (len > *lenp) len = *lenp;
75968
75969 - if (copy_to_user(buffer, addr, len))
75970 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
75971 return -EFAULT;
75972
75973 *lenp = len;
75974 @@ -236,7 +236,7 @@ static int dn_def_dev_handler(ctl_table
75975
75976 if (len > *lenp) len = *lenp;
75977
75978 - if (copy_to_user(buffer, devname, len))
75979 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
75980 return -EFAULT;
75981
75982 *lenp = len;
75983 diff -urNp linux-2.6.39/net/econet/Kconfig linux-2.6.39/net/econet/Kconfig
75984 --- linux-2.6.39/net/econet/Kconfig 2011-05-19 00:06:34.000000000 -0400
75985 +++ linux-2.6.39/net/econet/Kconfig 2011-05-22 19:41:42.000000000 -0400
75986 @@ -4,7 +4,7 @@
75987
75988 config ECONET
75989 tristate "Acorn Econet/AUN protocols (EXPERIMENTAL)"
75990 - depends on EXPERIMENTAL && INET
75991 + depends on EXPERIMENTAL && INET && BROKEN
75992 ---help---
75993 Econet is a fairly old and slow networking protocol mainly used by
75994 Acorn computers to access file and print servers. It uses native
75995 diff -urNp linux-2.6.39/net/ipv4/fib_frontend.c linux-2.6.39/net/ipv4/fib_frontend.c
75996 --- linux-2.6.39/net/ipv4/fib_frontend.c 2011-05-19 00:06:34.000000000 -0400
75997 +++ linux-2.6.39/net/ipv4/fib_frontend.c 2011-05-22 19:36:34.000000000 -0400
75998 @@ -968,12 +968,12 @@ static int fib_inetaddr_event(struct not
75999 #ifdef CONFIG_IP_ROUTE_MULTIPATH
76000 fib_sync_up(dev);
76001 #endif
76002 - atomic_inc(&net->ipv4.dev_addr_genid);
76003 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76004 rt_cache_flush(dev_net(dev), -1);
76005 break;
76006 case NETDEV_DOWN:
76007 fib_del_ifaddr(ifa, NULL);
76008 - atomic_inc(&net->ipv4.dev_addr_genid);
76009 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76010 if (ifa->ifa_dev->ifa_list == NULL) {
76011 /* Last address was deleted from this interface.
76012 * Disable IP.
76013 @@ -1009,7 +1009,7 @@ static int fib_netdev_event(struct notif
76014 #ifdef CONFIG_IP_ROUTE_MULTIPATH
76015 fib_sync_up(dev);
76016 #endif
76017 - atomic_inc(&net->ipv4.dev_addr_genid);
76018 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76019 rt_cache_flush(dev_net(dev), -1);
76020 break;
76021 case NETDEV_DOWN:
76022 diff -urNp linux-2.6.39/net/ipv4/fib_semantics.c linux-2.6.39/net/ipv4/fib_semantics.c
76023 --- linux-2.6.39/net/ipv4/fib_semantics.c 2011-05-19 00:06:34.000000000 -0400
76024 +++ linux-2.6.39/net/ipv4/fib_semantics.c 2011-05-22 19:36:34.000000000 -0400
76025 @@ -701,7 +701,7 @@ __be32 fib_info_update_nh_saddr(struct n
76026 nh->nh_saddr = inet_select_addr(nh->nh_dev,
76027 nh->nh_gw,
76028 nh->nh_parent->fib_scope);
76029 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
76030 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
76031
76032 return nh->nh_saddr;
76033 }
76034 diff -urNp linux-2.6.39/net/ipv4/inet_diag.c linux-2.6.39/net/ipv4/inet_diag.c
76035 --- linux-2.6.39/net/ipv4/inet_diag.c 2011-05-19 00:06:34.000000000 -0400
76036 +++ linux-2.6.39/net/ipv4/inet_diag.c 2011-05-22 19:41:42.000000000 -0400
76037 @@ -114,8 +114,14 @@ static int inet_csk_diag_fill(struct soc
76038 r->idiag_retrans = 0;
76039
76040 r->id.idiag_if = sk->sk_bound_dev_if;
76041 +
76042 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76043 + r->id.idiag_cookie[0] = 0;
76044 + r->id.idiag_cookie[1] = 0;
76045 +#else
76046 r->id.idiag_cookie[0] = (u32)(unsigned long)sk;
76047 r->id.idiag_cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
76048 +#endif
76049
76050 r->id.idiag_sport = inet->inet_sport;
76051 r->id.idiag_dport = inet->inet_dport;
76052 @@ -201,8 +207,15 @@ static int inet_twsk_diag_fill(struct in
76053 r->idiag_family = tw->tw_family;
76054 r->idiag_retrans = 0;
76055 r->id.idiag_if = tw->tw_bound_dev_if;
76056 +
76057 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76058 + r->id.idiag_cookie[0] = 0;
76059 + r->id.idiag_cookie[1] = 0;
76060 +#else
76061 r->id.idiag_cookie[0] = (u32)(unsigned long)tw;
76062 r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
76063 +#endif
76064 +
76065 r->id.idiag_sport = tw->tw_sport;
76066 r->id.idiag_dport = tw->tw_dport;
76067 r->id.idiag_src[0] = tw->tw_rcv_saddr;
76068 @@ -285,12 +298,14 @@ static int inet_diag_get_exact(struct sk
76069 if (sk == NULL)
76070 goto unlock;
76071
76072 +#ifndef CONFIG_GRKERNSEC_HIDESYM
76073 err = -ESTALE;
76074 if ((req->id.idiag_cookie[0] != INET_DIAG_NOCOOKIE ||
76075 req->id.idiag_cookie[1] != INET_DIAG_NOCOOKIE) &&
76076 ((u32)(unsigned long)sk != req->id.idiag_cookie[0] ||
76077 (u32)((((unsigned long)sk) >> 31) >> 1) != req->id.idiag_cookie[1]))
76078 goto out;
76079 +#endif
76080
76081 err = -ENOMEM;
76082 rep = alloc_skb(NLMSG_SPACE((sizeof(struct inet_diag_msg) +
76083 @@ -582,8 +597,14 @@ static int inet_diag_fill_req(struct sk_
76084 r->idiag_retrans = req->retrans;
76085
76086 r->id.idiag_if = sk->sk_bound_dev_if;
76087 +
76088 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76089 + r->id.idiag_cookie[0] = 0;
76090 + r->id.idiag_cookie[1] = 0;
76091 +#else
76092 r->id.idiag_cookie[0] = (u32)(unsigned long)req;
76093 r->id.idiag_cookie[1] = (u32)(((unsigned long)req >> 31) >> 1);
76094 +#endif
76095
76096 tmo = req->expires - jiffies;
76097 if (tmo < 0)
76098 diff -urNp linux-2.6.39/net/ipv4/inet_hashtables.c linux-2.6.39/net/ipv4/inet_hashtables.c
76099 --- linux-2.6.39/net/ipv4/inet_hashtables.c 2011-05-19 00:06:34.000000000 -0400
76100 +++ linux-2.6.39/net/ipv4/inet_hashtables.c 2011-05-22 19:41:42.000000000 -0400
76101 @@ -18,11 +18,14 @@
76102 #include <linux/sched.h>
76103 #include <linux/slab.h>
76104 #include <linux/wait.h>
76105 +#include <linux/security.h>
76106
76107 #include <net/inet_connection_sock.h>
76108 #include <net/inet_hashtables.h>
76109 #include <net/ip.h>
76110
76111 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
76112 +
76113 /*
76114 * Allocate and initialize a new local port bind bucket.
76115 * The bindhash mutex for snum's hash chain must be held here.
76116 @@ -529,6 +532,8 @@ ok:
76117 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
76118 spin_unlock(&head->lock);
76119
76120 + gr_update_task_in_ip_table(current, inet_sk(sk));
76121 +
76122 if (tw) {
76123 inet_twsk_deschedule(tw, death_row);
76124 while (twrefcnt) {
76125 diff -urNp linux-2.6.39/net/ipv4/inetpeer.c linux-2.6.39/net/ipv4/inetpeer.c
76126 --- linux-2.6.39/net/ipv4/inetpeer.c 2011-05-19 00:06:34.000000000 -0400
76127 +++ linux-2.6.39/net/ipv4/inetpeer.c 2011-05-22 19:36:34.000000000 -0400
76128 @@ -467,6 +467,8 @@ struct inet_peer *inet_getpeer(struct in
76129 unsigned int sequence;
76130 int invalidated;
76131
76132 + pax_track_stack();
76133 +
76134 /* Look up for the address quickly, lockless.
76135 * Because of a concurrent writer, we might not find an existing entry.
76136 */
76137 @@ -504,8 +506,8 @@ struct inet_peer *inet_getpeer(struct in
76138 if (p) {
76139 p->daddr = *daddr;
76140 atomic_set(&p->refcnt, 1);
76141 - atomic_set(&p->rid, 0);
76142 - atomic_set(&p->ip_id_count, secure_ip_id(daddr->addr.a4));
76143 + atomic_set_unchecked(&p->rid, 0);
76144 + atomic_set_unchecked(&p->ip_id_count, secure_ip_id(daddr->addr.a4));
76145 p->tcp_ts_stamp = 0;
76146 p->metrics[RTAX_LOCK-1] = INETPEER_METRICS_NEW;
76147 p->rate_tokens = 0;
76148 diff -urNp linux-2.6.39/net/ipv4/ip_fragment.c linux-2.6.39/net/ipv4/ip_fragment.c
76149 --- linux-2.6.39/net/ipv4/ip_fragment.c 2011-05-19 00:06:34.000000000 -0400
76150 +++ linux-2.6.39/net/ipv4/ip_fragment.c 2011-05-22 19:36:34.000000000 -0400
76151 @@ -297,7 +297,7 @@ static inline int ip_frag_too_far(struct
76152 return 0;
76153
76154 start = qp->rid;
76155 - end = atomic_inc_return(&peer->rid);
76156 + end = atomic_inc_return_unchecked(&peer->rid);
76157 qp->rid = end;
76158
76159 rc = qp->q.fragments && (end - start) > max;
76160 diff -urNp linux-2.6.39/net/ipv4/ip_sockglue.c linux-2.6.39/net/ipv4/ip_sockglue.c
76161 --- linux-2.6.39/net/ipv4/ip_sockglue.c 2011-05-19 00:06:34.000000000 -0400
76162 +++ linux-2.6.39/net/ipv4/ip_sockglue.c 2011-05-22 19:36:34.000000000 -0400
76163 @@ -1064,6 +1064,8 @@ static int do_ip_getsockopt(struct sock
76164 int val;
76165 int len;
76166
76167 + pax_track_stack();
76168 +
76169 if (level != SOL_IP)
76170 return -EOPNOTSUPP;
76171
76172 diff -urNp linux-2.6.39/net/ipv4/netfilter/nf_nat_snmp_basic.c linux-2.6.39/net/ipv4/netfilter/nf_nat_snmp_basic.c
76173 --- linux-2.6.39/net/ipv4/netfilter/nf_nat_snmp_basic.c 2011-05-19 00:06:34.000000000 -0400
76174 +++ linux-2.6.39/net/ipv4/netfilter/nf_nat_snmp_basic.c 2011-05-22 19:36:34.000000000 -0400
76175 @@ -399,7 +399,7 @@ static unsigned char asn1_octets_decode(
76176
76177 *len = 0;
76178
76179 - *octets = kmalloc(eoc - ctx->pointer, GFP_ATOMIC);
76180 + *octets = kmalloc((eoc - ctx->pointer), GFP_ATOMIC);
76181 if (*octets == NULL) {
76182 if (net_ratelimit())
76183 pr_notice("OOM in bsalg (%d)\n", __LINE__);
76184 diff -urNp linux-2.6.39/net/ipv4/raw.c linux-2.6.39/net/ipv4/raw.c
76185 --- linux-2.6.39/net/ipv4/raw.c 2011-05-19 00:06:34.000000000 -0400
76186 +++ linux-2.6.39/net/ipv4/raw.c 2011-05-22 19:41:42.000000000 -0400
76187 @@ -302,7 +302,7 @@ static int raw_rcv_skb(struct sock * sk,
76188 int raw_rcv(struct sock *sk, struct sk_buff *skb)
76189 {
76190 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
76191 - atomic_inc(&sk->sk_drops);
76192 + atomic_inc_unchecked(&sk->sk_drops);
76193 kfree_skb(skb);
76194 return NET_RX_DROP;
76195 }
76196 @@ -730,15 +730,19 @@ static int raw_init(struct sock *sk)
76197
76198 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
76199 {
76200 + struct icmp_filter filter;
76201 +
76202 if (optlen > sizeof(struct icmp_filter))
76203 optlen = sizeof(struct icmp_filter);
76204 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
76205 + if (copy_from_user(&filter, optval, optlen))
76206 return -EFAULT;
76207 + memcpy(&raw_sk(sk)->filter, &filter, sizeof(filter));
76208 return 0;
76209 }
76210
76211 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
76212 {
76213 + struct icmp_filter filter;
76214 int len, ret = -EFAULT;
76215
76216 if (get_user(len, optlen))
76217 @@ -749,8 +753,9 @@ static int raw_geticmpfilter(struct sock
76218 if (len > sizeof(struct icmp_filter))
76219 len = sizeof(struct icmp_filter);
76220 ret = -EFAULT;
76221 + memcpy(&filter, &raw_sk(sk)->filter, len);
76222 if (put_user(len, optlen) ||
76223 - copy_to_user(optval, &raw_sk(sk)->filter, len))
76224 + copy_to_user(optval, &filter, len))
76225 goto out;
76226 ret = 0;
76227 out: return ret;
76228 @@ -978,7 +983,13 @@ static void raw_sock_seq_show(struct seq
76229 sk_wmem_alloc_get(sp),
76230 sk_rmem_alloc_get(sp),
76231 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76232 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
76233 + atomic_read(&sp->sk_refcnt),
76234 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76235 + NULL,
76236 +#else
76237 + sp,
76238 +#endif
76239 + atomic_read_unchecked(&sp->sk_drops));
76240 }
76241
76242 static int raw_seq_show(struct seq_file *seq, void *v)
76243 diff -urNp linux-2.6.39/net/ipv4/route.c linux-2.6.39/net/ipv4/route.c
76244 --- linux-2.6.39/net/ipv4/route.c 2011-05-19 00:06:34.000000000 -0400
76245 +++ linux-2.6.39/net/ipv4/route.c 2011-05-22 19:36:34.000000000 -0400
76246 @@ -303,7 +303,7 @@ static inline unsigned int rt_hash(__be3
76247
76248 static inline int rt_genid(struct net *net)
76249 {
76250 - return atomic_read(&net->ipv4.rt_genid);
76251 + return atomic_read_unchecked(&net->ipv4.rt_genid);
76252 }
76253
76254 #ifdef CONFIG_PROC_FS
76255 @@ -831,7 +831,7 @@ static void rt_cache_invalidate(struct n
76256 unsigned char shuffle;
76257
76258 get_random_bytes(&shuffle, sizeof(shuffle));
76259 - atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
76260 + atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
76261 }
76262
76263 /*
76264 @@ -2835,7 +2835,7 @@ static int rt_fill_info(struct net *net,
76265 rt->peer->pmtu_expires - jiffies : 0;
76266 if (rt->peer) {
76267 inet_peer_refcheck(rt->peer);
76268 - id = atomic_read(&rt->peer->ip_id_count) & 0xffff;
76269 + id = atomic_read_unchecked(&rt->peer->ip_id_count) & 0xffff;
76270 if (rt->peer->tcp_ts_stamp) {
76271 ts = rt->peer->tcp_ts;
76272 tsage = get_seconds() - rt->peer->tcp_ts_stamp;
76273 diff -urNp linux-2.6.39/net/ipv4/tcp.c linux-2.6.39/net/ipv4/tcp.c
76274 --- linux-2.6.39/net/ipv4/tcp.c 2011-05-19 00:06:34.000000000 -0400
76275 +++ linux-2.6.39/net/ipv4/tcp.c 2011-05-22 19:36:34.000000000 -0400
76276 @@ -2121,6 +2121,8 @@ static int do_tcp_setsockopt(struct sock
76277 int val;
76278 int err = 0;
76279
76280 + pax_track_stack();
76281 +
76282 /* These are data/string values, all the others are ints */
76283 switch (optname) {
76284 case TCP_CONGESTION: {
76285 @@ -2500,6 +2502,8 @@ static int do_tcp_getsockopt(struct sock
76286 struct tcp_sock *tp = tcp_sk(sk);
76287 int val, len;
76288
76289 + pax_track_stack();
76290 +
76291 if (get_user(len, optlen))
76292 return -EFAULT;
76293
76294 diff -urNp linux-2.6.39/net/ipv4/tcp_ipv4.c linux-2.6.39/net/ipv4/tcp_ipv4.c
76295 --- linux-2.6.39/net/ipv4/tcp_ipv4.c 2011-05-19 00:06:34.000000000 -0400
76296 +++ linux-2.6.39/net/ipv4/tcp_ipv4.c 2011-05-22 19:41:42.000000000 -0400
76297 @@ -86,6 +86,9 @@ int sysctl_tcp_tw_reuse __read_mostly;
76298 int sysctl_tcp_low_latency __read_mostly;
76299 EXPORT_SYMBOL(sysctl_tcp_low_latency);
76300
76301 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76302 +extern int grsec_enable_blackhole;
76303 +#endif
76304
76305 #ifdef CONFIG_TCP_MD5SIG
76306 static struct tcp_md5sig_key *tcp_v4_md5_do_lookup(struct sock *sk,
76307 @@ -1594,6 +1597,9 @@ int tcp_v4_do_rcv(struct sock *sk, struc
76308 return 0;
76309
76310 reset:
76311 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76312 + if (!grsec_enable_blackhole)
76313 +#endif
76314 tcp_v4_send_reset(rsk, skb);
76315 discard:
76316 kfree_skb(skb);
76317 @@ -1656,12 +1662,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
76318 TCP_SKB_CB(skb)->sacked = 0;
76319
76320 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
76321 - if (!sk)
76322 + if (!sk) {
76323 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76324 + ret = 1;
76325 +#endif
76326 goto no_tcp_socket;
76327 -
76328 + }
76329 process:
76330 - if (sk->sk_state == TCP_TIME_WAIT)
76331 + if (sk->sk_state == TCP_TIME_WAIT) {
76332 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76333 + ret = 2;
76334 +#endif
76335 goto do_time_wait;
76336 + }
76337
76338 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
76339 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
76340 @@ -1711,6 +1724,10 @@ no_tcp_socket:
76341 bad_packet:
76342 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
76343 } else {
76344 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76345 + if (!grsec_enable_blackhole || (ret == 1 &&
76346 + (skb->dev->flags & IFF_LOOPBACK)))
76347 +#endif
76348 tcp_v4_send_reset(NULL, skb);
76349 }
76350
76351 @@ -2374,7 +2391,11 @@ static void get_openreq4(struct sock *sk
76352 0, /* non standard timer */
76353 0, /* open_requests have no inode */
76354 atomic_read(&sk->sk_refcnt),
76355 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76356 + NULL,
76357 +#else
76358 req,
76359 +#endif
76360 len);
76361 }
76362
76363 @@ -2424,7 +2445,12 @@ static void get_tcp4_sock(struct sock *s
76364 sock_i_uid(sk),
76365 icsk->icsk_probes_out,
76366 sock_i_ino(sk),
76367 - atomic_read(&sk->sk_refcnt), sk,
76368 + atomic_read(&sk->sk_refcnt),
76369 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76370 + NULL,
76371 +#else
76372 + sk,
76373 +#endif
76374 jiffies_to_clock_t(icsk->icsk_rto),
76375 jiffies_to_clock_t(icsk->icsk_ack.ato),
76376 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
76377 @@ -2452,7 +2478,13 @@ static void get_timewait4_sock(struct in
76378 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p%n",
76379 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
76380 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
76381 - atomic_read(&tw->tw_refcnt), tw, len);
76382 + atomic_read(&tw->tw_refcnt),
76383 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76384 + NULL,
76385 +#else
76386 + tw,
76387 +#endif
76388 + len);
76389 }
76390
76391 #define TMPSZ 150
76392 diff -urNp linux-2.6.39/net/ipv4/tcp_minisocks.c linux-2.6.39/net/ipv4/tcp_minisocks.c
76393 --- linux-2.6.39/net/ipv4/tcp_minisocks.c 2011-05-19 00:06:34.000000000 -0400
76394 +++ linux-2.6.39/net/ipv4/tcp_minisocks.c 2011-05-22 19:41:42.000000000 -0400
76395 @@ -27,6 +27,10 @@
76396 #include <net/inet_common.h>
76397 #include <net/xfrm.h>
76398
76399 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76400 +extern int grsec_enable_blackhole;
76401 +#endif
76402 +
76403 int sysctl_tcp_syncookies __read_mostly = 1;
76404 EXPORT_SYMBOL(sysctl_tcp_syncookies);
76405
76406 @@ -745,6 +749,10 @@ listen_overflow:
76407
76408 embryonic_reset:
76409 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
76410 +
76411 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76412 + if (!grsec_enable_blackhole)
76413 +#endif
76414 if (!(flg & TCP_FLAG_RST))
76415 req->rsk_ops->send_reset(sk, skb);
76416
76417 diff -urNp linux-2.6.39/net/ipv4/tcp_output.c linux-2.6.39/net/ipv4/tcp_output.c
76418 --- linux-2.6.39/net/ipv4/tcp_output.c 2011-05-19 00:06:34.000000000 -0400
76419 +++ linux-2.6.39/net/ipv4/tcp_output.c 2011-05-22 19:36:34.000000000 -0400
76420 @@ -2421,6 +2421,8 @@ struct sk_buff *tcp_make_synack(struct s
76421 int mss;
76422 int s_data_desired = 0;
76423
76424 + pax_track_stack();
76425 +
76426 if (cvp != NULL && cvp->s_data_constant && cvp->s_data_desired)
76427 s_data_desired = cvp->s_data_desired;
76428 skb = sock_wmalloc(sk, MAX_TCP_HEADER + 15 + s_data_desired, 1, GFP_ATOMIC);
76429 diff -urNp linux-2.6.39/net/ipv4/tcp_probe.c linux-2.6.39/net/ipv4/tcp_probe.c
76430 --- linux-2.6.39/net/ipv4/tcp_probe.c 2011-05-19 00:06:34.000000000 -0400
76431 +++ linux-2.6.39/net/ipv4/tcp_probe.c 2011-05-22 19:36:34.000000000 -0400
76432 @@ -202,7 +202,7 @@ static ssize_t tcpprobe_read(struct file
76433 if (cnt + width >= len)
76434 break;
76435
76436 - if (copy_to_user(buf + cnt, tbuf, width))
76437 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
76438 return -EFAULT;
76439 cnt += width;
76440 }
76441 diff -urNp linux-2.6.39/net/ipv4/tcp_timer.c linux-2.6.39/net/ipv4/tcp_timer.c
76442 --- linux-2.6.39/net/ipv4/tcp_timer.c 2011-05-19 00:06:34.000000000 -0400
76443 +++ linux-2.6.39/net/ipv4/tcp_timer.c 2011-05-22 19:41:42.000000000 -0400
76444 @@ -22,6 +22,10 @@
76445 #include <linux/gfp.h>
76446 #include <net/tcp.h>
76447
76448 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76449 +extern int grsec_lastack_retries;
76450 +#endif
76451 +
76452 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
76453 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
76454 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
76455 @@ -199,6 +203,13 @@ static int tcp_write_timeout(struct sock
76456 }
76457 }
76458
76459 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76460 + if ((sk->sk_state == TCP_LAST_ACK) &&
76461 + (grsec_lastack_retries > 0) &&
76462 + (grsec_lastack_retries < retry_until))
76463 + retry_until = grsec_lastack_retries;
76464 +#endif
76465 +
76466 if (retransmits_timed_out(sk, retry_until,
76467 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
76468 /* Has it gone just too far? */
76469 diff -urNp linux-2.6.39/net/ipv4/udp.c linux-2.6.39/net/ipv4/udp.c
76470 --- linux-2.6.39/net/ipv4/udp.c 2011-05-19 00:06:34.000000000 -0400
76471 +++ linux-2.6.39/net/ipv4/udp.c 2011-05-22 19:41:42.000000000 -0400
76472 @@ -86,6 +86,7 @@
76473 #include <linux/types.h>
76474 #include <linux/fcntl.h>
76475 #include <linux/module.h>
76476 +#include <linux/security.h>
76477 #include <linux/socket.h>
76478 #include <linux/sockios.h>
76479 #include <linux/igmp.h>
76480 @@ -107,6 +108,10 @@
76481 #include <net/xfrm.h>
76482 #include "udp_impl.h"
76483
76484 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76485 +extern int grsec_enable_blackhole;
76486 +#endif
76487 +
76488 struct udp_table udp_table __read_mostly;
76489 EXPORT_SYMBOL(udp_table);
76490
76491 @@ -564,6 +569,9 @@ found:
76492 return s;
76493 }
76494
76495 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
76496 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
76497 +
76498 /*
76499 * This routine is called by the ICMP module when it gets some
76500 * sort of error condition. If err < 0 then the socket should
76501 @@ -853,9 +861,18 @@ int udp_sendmsg(struct kiocb *iocb, stru
76502 dport = usin->sin_port;
76503 if (dport == 0)
76504 return -EINVAL;
76505 +
76506 + err = gr_search_udp_sendmsg(sk, usin);
76507 + if (err)
76508 + return err;
76509 } else {
76510 if (sk->sk_state != TCP_ESTABLISHED)
76511 return -EDESTADDRREQ;
76512 +
76513 + err = gr_search_udp_sendmsg(sk, NULL);
76514 + if (err)
76515 + return err;
76516 +
76517 daddr = inet->inet_daddr;
76518 dport = inet->inet_dport;
76519 /* Open fast path for connected socket.
76520 @@ -1090,7 +1107,7 @@ static unsigned int first_packet_length(
76521 udp_lib_checksum_complete(skb)) {
76522 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
76523 IS_UDPLITE(sk));
76524 - atomic_inc(&sk->sk_drops);
76525 + atomic_inc_unchecked(&sk->sk_drops);
76526 __skb_unlink(skb, rcvq);
76527 __skb_queue_tail(&list_kill, skb);
76528 }
76529 @@ -1176,6 +1193,10 @@ try_again:
76530 if (!skb)
76531 goto out;
76532
76533 + err = gr_search_udp_recvmsg(sk, skb);
76534 + if (err)
76535 + goto out_free;
76536 +
76537 ulen = skb->len - sizeof(struct udphdr);
76538 if (len > ulen)
76539 len = ulen;
76540 @@ -1472,7 +1493,7 @@ int udp_queue_rcv_skb(struct sock *sk, s
76541
76542 drop:
76543 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
76544 - atomic_inc(&sk->sk_drops);
76545 + atomic_inc_unchecked(&sk->sk_drops);
76546 kfree_skb(skb);
76547 return -1;
76548 }
76549 @@ -1491,7 +1512,7 @@ static void flush_stack(struct sock **st
76550 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
76551
76552 if (!skb1) {
76553 - atomic_inc(&sk->sk_drops);
76554 + atomic_inc_unchecked(&sk->sk_drops);
76555 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
76556 IS_UDPLITE(sk));
76557 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
76558 @@ -1660,6 +1681,9 @@ int __udp4_lib_rcv(struct sk_buff *skb,
76559 goto csum_error;
76560
76561 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
76562 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76563 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
76564 +#endif
76565 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
76566
76567 /*
76568 @@ -2087,8 +2111,13 @@ static void udp4_format_sock(struct sock
76569 sk_wmem_alloc_get(sp),
76570 sk_rmem_alloc_get(sp),
76571 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76572 - atomic_read(&sp->sk_refcnt), sp,
76573 - atomic_read(&sp->sk_drops), len);
76574 + atomic_read(&sp->sk_refcnt),
76575 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76576 + NULL,
76577 +#else
76578 + sp,
76579 +#endif
76580 + atomic_read_unchecked(&sp->sk_drops), len);
76581 }
76582
76583 int udp4_seq_show(struct seq_file *seq, void *v)
76584 diff -urNp linux-2.6.39/net/ipv6/inet6_connection_sock.c linux-2.6.39/net/ipv6/inet6_connection_sock.c
76585 --- linux-2.6.39/net/ipv6/inet6_connection_sock.c 2011-05-19 00:06:34.000000000 -0400
76586 +++ linux-2.6.39/net/ipv6/inet6_connection_sock.c 2011-05-22 19:36:34.000000000 -0400
76587 @@ -178,7 +178,7 @@ void __inet6_csk_dst_store(struct sock *
76588 #ifdef CONFIG_XFRM
76589 {
76590 struct rt6_info *rt = (struct rt6_info *)dst;
76591 - rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
76592 + rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
76593 }
76594 #endif
76595 }
76596 @@ -193,7 +193,7 @@ struct dst_entry *__inet6_csk_dst_check(
76597 #ifdef CONFIG_XFRM
76598 if (dst) {
76599 struct rt6_info *rt = (struct rt6_info *)dst;
76600 - if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
76601 + if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
76602 __sk_dst_reset(sk);
76603 dst = NULL;
76604 }
76605 diff -urNp linux-2.6.39/net/ipv6/ipv6_sockglue.c linux-2.6.39/net/ipv6/ipv6_sockglue.c
76606 --- linux-2.6.39/net/ipv6/ipv6_sockglue.c 2011-05-19 00:06:34.000000000 -0400
76607 +++ linux-2.6.39/net/ipv6/ipv6_sockglue.c 2011-05-22 19:36:34.000000000 -0400
76608 @@ -129,6 +129,8 @@ static int do_ipv6_setsockopt(struct soc
76609 int val, valbool;
76610 int retv = -ENOPROTOOPT;
76611
76612 + pax_track_stack();
76613 +
76614 if (optval == NULL)
76615 val=0;
76616 else {
76617 @@ -919,6 +921,8 @@ static int do_ipv6_getsockopt(struct soc
76618 int len;
76619 int val;
76620
76621 + pax_track_stack();
76622 +
76623 if (ip6_mroute_opt(optname))
76624 return ip6_mroute_getsockopt(sk, optname, optval, optlen);
76625
76626 diff -urNp linux-2.6.39/net/ipv6/raw.c linux-2.6.39/net/ipv6/raw.c
76627 --- linux-2.6.39/net/ipv6/raw.c 2011-05-19 00:06:34.000000000 -0400
76628 +++ linux-2.6.39/net/ipv6/raw.c 2011-05-22 19:41:42.000000000 -0400
76629 @@ -376,7 +376,7 @@ static inline int rawv6_rcv_skb(struct s
76630 {
76631 if ((raw6_sk(sk)->checksum || rcu_dereference_raw(sk->sk_filter)) &&
76632 skb_checksum_complete(skb)) {
76633 - atomic_inc(&sk->sk_drops);
76634 + atomic_inc_unchecked(&sk->sk_drops);
76635 kfree_skb(skb);
76636 return NET_RX_DROP;
76637 }
76638 @@ -403,7 +403,7 @@ int rawv6_rcv(struct sock *sk, struct sk
76639 struct raw6_sock *rp = raw6_sk(sk);
76640
76641 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
76642 - atomic_inc(&sk->sk_drops);
76643 + atomic_inc_unchecked(&sk->sk_drops);
76644 kfree_skb(skb);
76645 return NET_RX_DROP;
76646 }
76647 @@ -427,7 +427,7 @@ int rawv6_rcv(struct sock *sk, struct sk
76648
76649 if (inet->hdrincl) {
76650 if (skb_checksum_complete(skb)) {
76651 - atomic_inc(&sk->sk_drops);
76652 + atomic_inc_unchecked(&sk->sk_drops);
76653 kfree_skb(skb);
76654 return NET_RX_DROP;
76655 }
76656 @@ -601,7 +601,7 @@ out:
76657 return err;
76658 }
76659
76660 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
76661 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
76662 struct flowi6 *fl6, struct dst_entry **dstp,
76663 unsigned int flags)
76664 {
76665 @@ -742,6 +742,8 @@ static int rawv6_sendmsg(struct kiocb *i
76666 u16 proto;
76667 int err;
76668
76669 + pax_track_stack();
76670 +
76671 /* Rough check on arithmetic overflow,
76672 better check is made in ip6_append_data().
76673 */
76674 @@ -909,12 +911,15 @@ do_confirm:
76675 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
76676 char __user *optval, int optlen)
76677 {
76678 + struct icmp6_filter filter;
76679 +
76680 switch (optname) {
76681 case ICMPV6_FILTER:
76682 if (optlen > sizeof(struct icmp6_filter))
76683 optlen = sizeof(struct icmp6_filter);
76684 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
76685 + if (copy_from_user(&filter, optval, optlen))
76686 return -EFAULT;
76687 + memcpy(&raw6_sk(sk)->filter, &filter, optlen);
76688 return 0;
76689 default:
76690 return -ENOPROTOOPT;
76691 @@ -926,6 +931,7 @@ static int rawv6_seticmpfilter(struct so
76692 static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
76693 char __user *optval, int __user *optlen)
76694 {
76695 + struct icmp6_filter filter;
76696 int len;
76697
76698 switch (optname) {
76699 @@ -938,7 +944,8 @@ static int rawv6_geticmpfilter(struct so
76700 len = sizeof(struct icmp6_filter);
76701 if (put_user(len, optlen))
76702 return -EFAULT;
76703 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
76704 + memcpy(&filter, &raw6_sk(sk)->filter, len);
76705 + if (copy_to_user(optval, &filter, len))
76706 return -EFAULT;
76707 return 0;
76708 default:
76709 @@ -1252,7 +1259,13 @@ static void raw6_sock_seq_show(struct se
76710 0, 0L, 0,
76711 sock_i_uid(sp), 0,
76712 sock_i_ino(sp),
76713 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
76714 + atomic_read(&sp->sk_refcnt),
76715 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76716 + NULL,
76717 +#else
76718 + sp,
76719 +#endif
76720 + atomic_read_unchecked(&sp->sk_drops));
76721 }
76722
76723 static int raw6_seq_show(struct seq_file *seq, void *v)
76724 diff -urNp linux-2.6.39/net/ipv6/tcp_ipv6.c linux-2.6.39/net/ipv6/tcp_ipv6.c
76725 --- linux-2.6.39/net/ipv6/tcp_ipv6.c 2011-05-19 00:06:34.000000000 -0400
76726 +++ linux-2.6.39/net/ipv6/tcp_ipv6.c 2011-05-22 19:41:42.000000000 -0400
76727 @@ -92,6 +92,10 @@ static struct tcp_md5sig_key *tcp_v6_md5
76728 }
76729 #endif
76730
76731 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76732 +extern int grsec_enable_blackhole;
76733 +#endif
76734 +
76735 static void tcp_v6_hash(struct sock *sk)
76736 {
76737 if (sk->sk_state != TCP_CLOSE) {
76738 @@ -1660,6 +1664,9 @@ static int tcp_v6_do_rcv(struct sock *sk
76739 return 0;
76740
76741 reset:
76742 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76743 + if (!grsec_enable_blackhole)
76744 +#endif
76745 tcp_v6_send_reset(sk, skb);
76746 discard:
76747 if (opt_skb)
76748 @@ -1739,12 +1746,20 @@ static int tcp_v6_rcv(struct sk_buff *sk
76749 TCP_SKB_CB(skb)->sacked = 0;
76750
76751 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
76752 - if (!sk)
76753 + if (!sk) {
76754 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76755 + ret = 1;
76756 +#endif
76757 goto no_tcp_socket;
76758 + }
76759
76760 process:
76761 - if (sk->sk_state == TCP_TIME_WAIT)
76762 + if (sk->sk_state == TCP_TIME_WAIT) {
76763 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76764 + ret = 2;
76765 +#endif
76766 goto do_time_wait;
76767 + }
76768
76769 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
76770 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
76771 @@ -1792,6 +1807,10 @@ no_tcp_socket:
76772 bad_packet:
76773 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
76774 } else {
76775 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76776 + if (!grsec_enable_blackhole || (ret == 1 &&
76777 + (skb->dev->flags & IFF_LOOPBACK)))
76778 +#endif
76779 tcp_v6_send_reset(NULL, skb);
76780 }
76781
76782 @@ -2052,7 +2071,13 @@ static void get_openreq6(struct seq_file
76783 uid,
76784 0, /* non standard timer */
76785 0, /* open_requests have no inode */
76786 - 0, req);
76787 + 0,
76788 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76789 + NULL
76790 +#else
76791 + req
76792 +#endif
76793 + );
76794 }
76795
76796 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
76797 @@ -2102,7 +2127,12 @@ static void get_tcp6_sock(struct seq_fil
76798 sock_i_uid(sp),
76799 icsk->icsk_probes_out,
76800 sock_i_ino(sp),
76801 - atomic_read(&sp->sk_refcnt), sp,
76802 + atomic_read(&sp->sk_refcnt),
76803 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76804 + NULL,
76805 +#else
76806 + sp,
76807 +#endif
76808 jiffies_to_clock_t(icsk->icsk_rto),
76809 jiffies_to_clock_t(icsk->icsk_ack.ato),
76810 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
76811 @@ -2137,7 +2167,13 @@ static void get_timewait6_sock(struct se
76812 dest->s6_addr32[2], dest->s6_addr32[3], destp,
76813 tw->tw_substate, 0, 0,
76814 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
76815 - atomic_read(&tw->tw_refcnt), tw);
76816 + atomic_read(&tw->tw_refcnt),
76817 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76818 + NULL
76819 +#else
76820 + tw
76821 +#endif
76822 + );
76823 }
76824
76825 static int tcp6_seq_show(struct seq_file *seq, void *v)
76826 diff -urNp linux-2.6.39/net/ipv6/udp.c linux-2.6.39/net/ipv6/udp.c
76827 --- linux-2.6.39/net/ipv6/udp.c 2011-05-19 00:06:34.000000000 -0400
76828 +++ linux-2.6.39/net/ipv6/udp.c 2011-05-22 19:41:42.000000000 -0400
76829 @@ -50,6 +50,10 @@
76830 #include <linux/seq_file.h>
76831 #include "udp_impl.h"
76832
76833 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76834 +extern int grsec_enable_blackhole;
76835 +#endif
76836 +
76837 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
76838 {
76839 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
76840 @@ -545,7 +549,7 @@ int udpv6_queue_rcv_skb(struct sock * sk
76841
76842 return 0;
76843 drop:
76844 - atomic_inc(&sk->sk_drops);
76845 + atomic_inc_unchecked(&sk->sk_drops);
76846 drop_no_sk_drops_inc:
76847 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
76848 kfree_skb(skb);
76849 @@ -621,7 +625,7 @@ static void flush_stack(struct sock **st
76850 continue;
76851 }
76852 drop:
76853 - atomic_inc(&sk->sk_drops);
76854 + atomic_inc_unchecked(&sk->sk_drops);
76855 UDP6_INC_STATS_BH(sock_net(sk),
76856 UDP_MIB_RCVBUFERRORS, IS_UDPLITE(sk));
76857 UDP6_INC_STATS_BH(sock_net(sk),
76858 @@ -776,6 +780,9 @@ int __udp6_lib_rcv(struct sk_buff *skb,
76859 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS,
76860 proto == IPPROTO_UDPLITE);
76861
76862 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76863 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
76864 +#endif
76865 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
76866
76867 kfree_skb(skb);
76868 @@ -792,7 +799,7 @@ int __udp6_lib_rcv(struct sk_buff *skb,
76869 if (!sock_owned_by_user(sk))
76870 udpv6_queue_rcv_skb(sk, skb);
76871 else if (sk_add_backlog(sk, skb)) {
76872 - atomic_inc(&sk->sk_drops);
76873 + atomic_inc_unchecked(&sk->sk_drops);
76874 bh_unlock_sock(sk);
76875 sock_put(sk);
76876 goto discard;
76877 @@ -1403,8 +1410,13 @@ static void udp6_sock_seq_show(struct se
76878 0, 0L, 0,
76879 sock_i_uid(sp), 0,
76880 sock_i_ino(sp),
76881 - atomic_read(&sp->sk_refcnt), sp,
76882 - atomic_read(&sp->sk_drops));
76883 + atomic_read(&sp->sk_refcnt),
76884 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76885 + NULL,
76886 +#else
76887 + sp,
76888 +#endif
76889 + atomic_read_unchecked(&sp->sk_drops));
76890 }
76891
76892 int udp6_seq_show(struct seq_file *seq, void *v)
76893 diff -urNp linux-2.6.39/net/irda/ircomm/ircomm_tty.c linux-2.6.39/net/irda/ircomm/ircomm_tty.c
76894 --- linux-2.6.39/net/irda/ircomm/ircomm_tty.c 2011-05-19 00:06:34.000000000 -0400
76895 +++ linux-2.6.39/net/irda/ircomm/ircomm_tty.c 2011-05-22 19:36:34.000000000 -0400
76896 @@ -281,16 +281,16 @@ static int ircomm_tty_block_til_ready(st
76897 add_wait_queue(&self->open_wait, &wait);
76898
76899 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
76900 - __FILE__,__LINE__, tty->driver->name, self->open_count );
76901 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
76902
76903 /* As far as I can see, we protect open_count - Jean II */
76904 spin_lock_irqsave(&self->spinlock, flags);
76905 if (!tty_hung_up_p(filp)) {
76906 extra_count = 1;
76907 - self->open_count--;
76908 + local_dec(&self->open_count);
76909 }
76910 spin_unlock_irqrestore(&self->spinlock, flags);
76911 - self->blocked_open++;
76912 + local_inc(&self->blocked_open);
76913
76914 while (1) {
76915 if (tty->termios->c_cflag & CBAUD) {
76916 @@ -330,7 +330,7 @@ static int ircomm_tty_block_til_ready(st
76917 }
76918
76919 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
76920 - __FILE__,__LINE__, tty->driver->name, self->open_count );
76921 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
76922
76923 schedule();
76924 }
76925 @@ -341,13 +341,13 @@ static int ircomm_tty_block_til_ready(st
76926 if (extra_count) {
76927 /* ++ is not atomic, so this should be protected - Jean II */
76928 spin_lock_irqsave(&self->spinlock, flags);
76929 - self->open_count++;
76930 + local_inc(&self->open_count);
76931 spin_unlock_irqrestore(&self->spinlock, flags);
76932 }
76933 - self->blocked_open--;
76934 + local_dec(&self->blocked_open);
76935
76936 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
76937 - __FILE__,__LINE__, tty->driver->name, self->open_count);
76938 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
76939
76940 if (!retval)
76941 self->flags |= ASYNC_NORMAL_ACTIVE;
76942 @@ -416,14 +416,14 @@ static int ircomm_tty_open(struct tty_st
76943 }
76944 /* ++ is not atomic, so this should be protected - Jean II */
76945 spin_lock_irqsave(&self->spinlock, flags);
76946 - self->open_count++;
76947 + local_inc(&self->open_count);
76948
76949 tty->driver_data = self;
76950 self->tty = tty;
76951 spin_unlock_irqrestore(&self->spinlock, flags);
76952
76953 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
76954 - self->line, self->open_count);
76955 + self->line, local_read(&self->open_count));
76956
76957 /* Not really used by us, but lets do it anyway */
76958 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
76959 @@ -509,7 +509,7 @@ static void ircomm_tty_close(struct tty_
76960 return;
76961 }
76962
76963 - if ((tty->count == 1) && (self->open_count != 1)) {
76964 + if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
76965 /*
76966 * Uh, oh. tty->count is 1, which means that the tty
76967 * structure will be freed. state->count should always
76968 @@ -519,16 +519,16 @@ static void ircomm_tty_close(struct tty_
76969 */
76970 IRDA_DEBUG(0, "%s(), bad serial port count; "
76971 "tty->count is 1, state->count is %d\n", __func__ ,
76972 - self->open_count);
76973 - self->open_count = 1;
76974 + local_read(&self->open_count));
76975 + local_set(&self->open_count, 1);
76976 }
76977
76978 - if (--self->open_count < 0) {
76979 + if (local_dec_return(&self->open_count) < 0) {
76980 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
76981 - __func__, self->line, self->open_count);
76982 - self->open_count = 0;
76983 + __func__, self->line, local_read(&self->open_count));
76984 + local_set(&self->open_count, 0);
76985 }
76986 - if (self->open_count) {
76987 + if (local_read(&self->open_count)) {
76988 spin_unlock_irqrestore(&self->spinlock, flags);
76989
76990 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
76991 @@ -560,7 +560,7 @@ static void ircomm_tty_close(struct tty_
76992 tty->closing = 0;
76993 self->tty = NULL;
76994
76995 - if (self->blocked_open) {
76996 + if (local_read(&self->blocked_open)) {
76997 if (self->close_delay)
76998 schedule_timeout_interruptible(self->close_delay);
76999 wake_up_interruptible(&self->open_wait);
77000 @@ -1012,7 +1012,7 @@ static void ircomm_tty_hangup(struct tty
77001 spin_lock_irqsave(&self->spinlock, flags);
77002 self->flags &= ~ASYNC_NORMAL_ACTIVE;
77003 self->tty = NULL;
77004 - self->open_count = 0;
77005 + local_set(&self->open_count, 0);
77006 spin_unlock_irqrestore(&self->spinlock, flags);
77007
77008 wake_up_interruptible(&self->open_wait);
77009 @@ -1364,7 +1364,7 @@ static void ircomm_tty_line_info(struct
77010 seq_putc(m, '\n');
77011
77012 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
77013 - seq_printf(m, "Open count: %d\n", self->open_count);
77014 + seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
77015 seq_printf(m, "Max data size: %d\n", self->max_data_size);
77016 seq_printf(m, "Max header size: %d\n", self->max_header_size);
77017
77018 diff -urNp linux-2.6.39/net/iucv/af_iucv.c linux-2.6.39/net/iucv/af_iucv.c
77019 --- linux-2.6.39/net/iucv/af_iucv.c 2011-05-19 00:06:34.000000000 -0400
77020 +++ linux-2.6.39/net/iucv/af_iucv.c 2011-05-22 19:36:34.000000000 -0400
77021 @@ -653,10 +653,10 @@ static int iucv_sock_autobind(struct soc
77022
77023 write_lock_bh(&iucv_sk_list.lock);
77024
77025 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
77026 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
77027 while (__iucv_get_sock_by_name(name)) {
77028 sprintf(name, "%08x",
77029 - atomic_inc_return(&iucv_sk_list.autobind_name));
77030 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
77031 }
77032
77033 write_unlock_bh(&iucv_sk_list.lock);
77034 diff -urNp linux-2.6.39/net/key/af_key.c linux-2.6.39/net/key/af_key.c
77035 --- linux-2.6.39/net/key/af_key.c 2011-05-19 00:06:34.000000000 -0400
77036 +++ linux-2.6.39/net/key/af_key.c 2011-05-22 19:41:42.000000000 -0400
77037 @@ -2481,6 +2481,8 @@ static int pfkey_migrate(struct sock *sk
77038 struct xfrm_migrate m[XFRM_MAX_DEPTH];
77039 struct xfrm_kmaddress k;
77040
77041 + pax_track_stack();
77042 +
77043 if (!present_and_same_family(ext_hdrs[SADB_EXT_ADDRESS_SRC - 1],
77044 ext_hdrs[SADB_EXT_ADDRESS_DST - 1]) ||
77045 !ext_hdrs[SADB_X_EXT_POLICY - 1]) {
77046 @@ -3016,10 +3018,10 @@ static int pfkey_send_policy_notify(stru
77047 static u32 get_acqseq(void)
77048 {
77049 u32 res;
77050 - static atomic_t acqseq;
77051 + static atomic_unchecked_t acqseq;
77052
77053 do {
77054 - res = atomic_inc_return(&acqseq);
77055 + res = atomic_inc_return_unchecked(&acqseq);
77056 } while (!res);
77057 return res;
77058 }
77059 @@ -3657,7 +3659,11 @@ static int pfkey_seq_show(struct seq_fil
77060 seq_printf(f ,"sk RefCnt Rmem Wmem User Inode\n");
77061 else
77062 seq_printf(f ,"%p %-6d %-6u %-6u %-6u %-6lu\n",
77063 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77064 + NULL,
77065 +#else
77066 s,
77067 +#endif
77068 atomic_read(&s->sk_refcnt),
77069 sk_rmem_alloc_get(s),
77070 sk_wmem_alloc_get(s),
77071 diff -urNp linux-2.6.39/net/l2tp/l2tp_ip.c linux-2.6.39/net/l2tp/l2tp_ip.c
77072 --- linux-2.6.39/net/l2tp/l2tp_ip.c 2011-05-19 00:06:34.000000000 -0400
77073 +++ linux-2.6.39/net/l2tp/l2tp_ip.c 2011-05-22 19:36:34.000000000 -0400
77074 @@ -625,7 +625,7 @@ static struct inet_protosw l2tp_ip_proto
77075 .no_check = 0,
77076 };
77077
77078 -static struct net_protocol l2tp_ip_protocol __read_mostly = {
77079 +static const struct net_protocol l2tp_ip_protocol = {
77080 .handler = l2tp_ip_recv,
77081 };
77082
77083 diff -urNp linux-2.6.39/net/lapb/lapb_iface.c linux-2.6.39/net/lapb/lapb_iface.c
77084 --- linux-2.6.39/net/lapb/lapb_iface.c 2011-05-19 00:06:34.000000000 -0400
77085 +++ linux-2.6.39/net/lapb/lapb_iface.c 2011-05-22 19:36:34.000000000 -0400
77086 @@ -138,8 +138,7 @@ static struct lapb_cb *lapb_create_cb(vo
77087 out:
77088 return lapb;
77089 }
77090 -
77091 -int lapb_register(struct net_device *dev, struct lapb_register_struct *callbacks)
77092 +int lapb_register(struct net_device *dev, const struct lapb_register_struct *callbacks)
77093 {
77094 struct lapb_cb *lapb;
77095 int rc = LAPB_BADTOKEN;
77096 diff -urNp linux-2.6.39/net/mac80211/cfg.c linux-2.6.39/net/mac80211/cfg.c
77097 --- linux-2.6.39/net/mac80211/cfg.c 2011-05-19 00:06:34.000000000 -0400
77098 +++ linux-2.6.39/net/mac80211/cfg.c 2011-05-22 19:36:34.000000000 -0400
77099 @@ -2029,7 +2029,7 @@ static void ieee80211_get_ringparam(stru
77100 drv_get_ringparam(local, tx, tx_max, rx, rx_max);
77101 }
77102
77103 -struct cfg80211_ops mac80211_config_ops = {
77104 +const struct cfg80211_ops mac80211_config_ops = {
77105 .add_virtual_intf = ieee80211_add_iface,
77106 .del_virtual_intf = ieee80211_del_iface,
77107 .change_virtual_intf = ieee80211_change_iface,
77108 diff -urNp linux-2.6.39/net/mac80211/cfg.h linux-2.6.39/net/mac80211/cfg.h
77109 --- linux-2.6.39/net/mac80211/cfg.h 2011-05-19 00:06:34.000000000 -0400
77110 +++ linux-2.6.39/net/mac80211/cfg.h 2011-05-22 19:36:34.000000000 -0400
77111 @@ -4,6 +4,6 @@
77112 #ifndef __CFG_H
77113 #define __CFG_H
77114
77115 -extern struct cfg80211_ops mac80211_config_ops;
77116 +extern const struct cfg80211_ops mac80211_config_ops;
77117
77118 #endif /* __CFG_H */
77119 diff -urNp linux-2.6.39/net/mac80211/debugfs_sta.c linux-2.6.39/net/mac80211/debugfs_sta.c
77120 --- linux-2.6.39/net/mac80211/debugfs_sta.c 2011-05-19 00:06:34.000000000 -0400
77121 +++ linux-2.6.39/net/mac80211/debugfs_sta.c 2011-05-22 19:36:34.000000000 -0400
77122 @@ -115,6 +115,8 @@ static ssize_t sta_agg_status_read(struc
77123 struct tid_ampdu_rx *tid_rx;
77124 struct tid_ampdu_tx *tid_tx;
77125
77126 + pax_track_stack();
77127 +
77128 rcu_read_lock();
77129
77130 p += scnprintf(p, sizeof(buf) + buf - p, "next dialog_token: %#02x\n",
77131 @@ -215,6 +217,8 @@ static ssize_t sta_ht_capa_read(struct f
77132 struct sta_info *sta = file->private_data;
77133 struct ieee80211_sta_ht_cap *htc = &sta->sta.ht_cap;
77134
77135 + pax_track_stack();
77136 +
77137 p += scnprintf(p, sizeof(buf) + buf - p, "ht %ssupported\n",
77138 htc->ht_supported ? "" : "not ");
77139 if (htc->ht_supported) {
77140 diff -urNp linux-2.6.39/net/mac80211/ieee80211_i.h linux-2.6.39/net/mac80211/ieee80211_i.h
77141 --- linux-2.6.39/net/mac80211/ieee80211_i.h 2011-05-19 00:06:34.000000000 -0400
77142 +++ linux-2.6.39/net/mac80211/ieee80211_i.h 2011-05-22 19:36:34.000000000 -0400
77143 @@ -27,6 +27,7 @@
77144 #include <net/ieee80211_radiotap.h>
77145 #include <net/cfg80211.h>
77146 #include <net/mac80211.h>
77147 +#include <asm/local.h>
77148 #include "key.h"
77149 #include "sta_info.h"
77150
77151 @@ -714,7 +715,7 @@ struct ieee80211_local {
77152 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
77153 spinlock_t queue_stop_reason_lock;
77154
77155 - int open_count;
77156 + local_t open_count;
77157 int monitors, cooked_mntrs;
77158 /* number of interfaces with corresponding FIF_ flags */
77159 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
77160 diff -urNp linux-2.6.39/net/mac80211/iface.c linux-2.6.39/net/mac80211/iface.c
77161 --- linux-2.6.39/net/mac80211/iface.c 2011-05-19 00:06:34.000000000 -0400
77162 +++ linux-2.6.39/net/mac80211/iface.c 2011-05-22 19:36:34.000000000 -0400
77163 @@ -211,7 +211,7 @@ static int ieee80211_do_open(struct net_
77164 break;
77165 }
77166
77167 - if (local->open_count == 0) {
77168 + if (local_read(&local->open_count) == 0) {
77169 res = drv_start(local);
77170 if (res)
77171 goto err_del_bss;
77172 @@ -235,7 +235,7 @@ static int ieee80211_do_open(struct net_
77173 memcpy(dev->perm_addr, dev->dev_addr, ETH_ALEN);
77174
77175 if (!is_valid_ether_addr(dev->dev_addr)) {
77176 - if (!local->open_count)
77177 + if (!local_read(&local->open_count))
77178 drv_stop(local);
77179 return -EADDRNOTAVAIL;
77180 }
77181 @@ -327,7 +327,7 @@ static int ieee80211_do_open(struct net_
77182 mutex_unlock(&local->mtx);
77183
77184 if (coming_up)
77185 - local->open_count++;
77186 + local_inc(&local->open_count);
77187
77188 if (hw_reconf_flags) {
77189 ieee80211_hw_config(local, hw_reconf_flags);
77190 @@ -347,7 +347,7 @@ static int ieee80211_do_open(struct net_
77191 err_del_interface:
77192 drv_remove_interface(local, &sdata->vif);
77193 err_stop:
77194 - if (!local->open_count)
77195 + if (!local_read(&local->open_count))
77196 drv_stop(local);
77197 err_del_bss:
77198 sdata->bss = NULL;
77199 @@ -474,7 +474,7 @@ static void ieee80211_do_stop(struct iee
77200 }
77201
77202 if (going_down)
77203 - local->open_count--;
77204 + local_dec(&local->open_count);
77205
77206 switch (sdata->vif.type) {
77207 case NL80211_IFTYPE_AP_VLAN:
77208 @@ -533,7 +533,7 @@ static void ieee80211_do_stop(struct iee
77209
77210 ieee80211_recalc_ps(local, -1);
77211
77212 - if (local->open_count == 0) {
77213 + if (local_read(&local->open_count) == 0) {
77214 if (local->ops->napi_poll)
77215 napi_disable(&local->napi);
77216 ieee80211_clear_tx_pending(local);
77217 diff -urNp linux-2.6.39/net/mac80211/main.c linux-2.6.39/net/mac80211/main.c
77218 --- linux-2.6.39/net/mac80211/main.c 2011-05-19 00:06:34.000000000 -0400
77219 +++ linux-2.6.39/net/mac80211/main.c 2011-05-22 19:36:34.000000000 -0400
77220 @@ -215,7 +215,7 @@ int ieee80211_hw_config(struct ieee80211
77221 local->hw.conf.power_level = power;
77222 }
77223
77224 - if (changed && local->open_count) {
77225 + if (changed && local_read(&local->open_count)) {
77226 ret = drv_config(local, changed);
77227 /*
77228 * Goal:
77229 diff -urNp linux-2.6.39/net/mac80211/mlme.c linux-2.6.39/net/mac80211/mlme.c
77230 --- linux-2.6.39/net/mac80211/mlme.c 2011-05-19 00:06:34.000000000 -0400
77231 +++ linux-2.6.39/net/mac80211/mlme.c 2011-05-22 19:36:34.000000000 -0400
77232 @@ -1431,6 +1431,8 @@ static bool ieee80211_assoc_success(stru
77233 bool have_higher_than_11mbit = false;
77234 u16 ap_ht_cap_flags;
77235
77236 + pax_track_stack();
77237 +
77238 /* AssocResp and ReassocResp have identical structure */
77239
77240 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
77241 diff -urNp linux-2.6.39/net/mac80211/pm.c linux-2.6.39/net/mac80211/pm.c
77242 --- linux-2.6.39/net/mac80211/pm.c 2011-05-19 00:06:34.000000000 -0400
77243 +++ linux-2.6.39/net/mac80211/pm.c 2011-05-22 19:36:34.000000000 -0400
77244 @@ -95,7 +95,7 @@ int __ieee80211_suspend(struct ieee80211
77245 }
77246
77247 /* stop hardware - this must stop RX */
77248 - if (local->open_count)
77249 + if (local_read(&local->open_count))
77250 ieee80211_stop_device(local);
77251
77252 local->suspended = true;
77253 diff -urNp linux-2.6.39/net/mac80211/rate.c linux-2.6.39/net/mac80211/rate.c
77254 --- linux-2.6.39/net/mac80211/rate.c 2011-05-19 00:06:34.000000000 -0400
77255 +++ linux-2.6.39/net/mac80211/rate.c 2011-05-22 19:36:34.000000000 -0400
77256 @@ -371,7 +371,7 @@ int ieee80211_init_rate_ctrl_alg(struct
77257
77258 ASSERT_RTNL();
77259
77260 - if (local->open_count)
77261 + if (local_read(&local->open_count))
77262 return -EBUSY;
77263
77264 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
77265 diff -urNp linux-2.6.39/net/mac80211/rc80211_pid_debugfs.c linux-2.6.39/net/mac80211/rc80211_pid_debugfs.c
77266 --- linux-2.6.39/net/mac80211/rc80211_pid_debugfs.c 2011-05-19 00:06:34.000000000 -0400
77267 +++ linux-2.6.39/net/mac80211/rc80211_pid_debugfs.c 2011-05-22 19:36:34.000000000 -0400
77268 @@ -192,7 +192,7 @@ static ssize_t rate_control_pid_events_r
77269
77270 spin_unlock_irqrestore(&events->lock, status);
77271
77272 - if (copy_to_user(buf, pb, p))
77273 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
77274 return -EFAULT;
77275
77276 return p;
77277 diff -urNp linux-2.6.39/net/mac80211/util.c linux-2.6.39/net/mac80211/util.c
77278 --- linux-2.6.39/net/mac80211/util.c 2011-05-19 00:06:34.000000000 -0400
77279 +++ linux-2.6.39/net/mac80211/util.c 2011-05-22 19:36:34.000000000 -0400
77280 @@ -1129,7 +1129,7 @@ int ieee80211_reconfig(struct ieee80211_
77281 local->resuming = true;
77282
77283 /* restart hardware */
77284 - if (local->open_count) {
77285 + if (local_read(&local->open_count)) {
77286 /*
77287 * Upon resume hardware can sometimes be goofy due to
77288 * various platform / driver / bus issues, so restarting
77289 diff -urNp linux-2.6.39/net/netfilter/ipvs/ip_vs_conn.c linux-2.6.39/net/netfilter/ipvs/ip_vs_conn.c
77290 --- linux-2.6.39/net/netfilter/ipvs/ip_vs_conn.c 2011-05-19 00:06:34.000000000 -0400
77291 +++ linux-2.6.39/net/netfilter/ipvs/ip_vs_conn.c 2011-05-22 19:36:34.000000000 -0400
77292 @@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, s
77293 /* Increase the refcnt counter of the dest */
77294 atomic_inc(&dest->refcnt);
77295
77296 - conn_flags = atomic_read(&dest->conn_flags);
77297 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
77298 if (cp->protocol != IPPROTO_UDP)
77299 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
77300 /* Bind with the destination and its corresponding transmitter */
77301 @@ -861,7 +861,7 @@ ip_vs_conn_new(const struct ip_vs_conn_p
77302 atomic_set(&cp->refcnt, 1);
77303
77304 atomic_set(&cp->n_control, 0);
77305 - atomic_set(&cp->in_pkts, 0);
77306 + atomic_set_unchecked(&cp->in_pkts, 0);
77307
77308 atomic_inc(&ipvs->conn_count);
77309 if (flags & IP_VS_CONN_F_NO_CPORT)
77310 @@ -1141,7 +1141,7 @@ static inline int todrop_entry(struct ip
77311
77312 /* Don't drop the entry if its number of incoming packets is not
77313 located in [0, 8] */
77314 - i = atomic_read(&cp->in_pkts);
77315 + i = atomic_read_unchecked(&cp->in_pkts);
77316 if (i > 8 || i < 0) return 0;
77317
77318 if (!todrop_rate[i]) return 0;
77319 diff -urNp linux-2.6.39/net/netfilter/ipvs/ip_vs_core.c linux-2.6.39/net/netfilter/ipvs/ip_vs_core.c
77320 --- linux-2.6.39/net/netfilter/ipvs/ip_vs_core.c 2011-05-19 00:06:34.000000000 -0400
77321 +++ linux-2.6.39/net/netfilter/ipvs/ip_vs_core.c 2011-05-22 19:36:34.000000000 -0400
77322 @@ -563,7 +563,7 @@ int ip_vs_leave(struct ip_vs_service *sv
77323 ret = cp->packet_xmit(skb, cp, pd->pp);
77324 /* do not touch skb anymore */
77325
77326 - atomic_inc(&cp->in_pkts);
77327 + atomic_inc_unchecked(&cp->in_pkts);
77328 ip_vs_conn_put(cp);
77329 return ret;
77330 }
77331 @@ -1633,7 +1633,7 @@ ip_vs_in(unsigned int hooknum, struct sk
77332 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
77333 pkts = sysctl_sync_threshold(ipvs);
77334 else
77335 - pkts = atomic_add_return(1, &cp->in_pkts);
77336 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
77337
77338 if ((ipvs->sync_state & IP_VS_STATE_MASTER) &&
77339 cp->protocol == IPPROTO_SCTP) {
77340 diff -urNp linux-2.6.39/net/netfilter/ipvs/ip_vs_ctl.c linux-2.6.39/net/netfilter/ipvs/ip_vs_ctl.c
77341 --- linux-2.6.39/net/netfilter/ipvs/ip_vs_ctl.c 2011-05-19 00:06:34.000000000 -0400
77342 +++ linux-2.6.39/net/netfilter/ipvs/ip_vs_ctl.c 2011-05-22 19:36:34.000000000 -0400
77343 @@ -782,7 +782,7 @@ __ip_vs_update_dest(struct ip_vs_service
77344 ip_vs_rs_hash(ipvs, dest);
77345 write_unlock_bh(&ipvs->rs_lock);
77346 }
77347 - atomic_set(&dest->conn_flags, conn_flags);
77348 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
77349
77350 /* bind the service */
77351 if (!dest->svc) {
77352 @@ -2027,7 +2027,7 @@ static int ip_vs_info_seq_show(struct se
77353 " %-7s %-6d %-10d %-10d\n",
77354 &dest->addr.in6,
77355 ntohs(dest->port),
77356 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
77357 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
77358 atomic_read(&dest->weight),
77359 atomic_read(&dest->activeconns),
77360 atomic_read(&dest->inactconns));
77361 @@ -2038,7 +2038,7 @@ static int ip_vs_info_seq_show(struct se
77362 "%-7s %-6d %-10d %-10d\n",
77363 ntohl(dest->addr.ip),
77364 ntohs(dest->port),
77365 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
77366 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
77367 atomic_read(&dest->weight),
77368 atomic_read(&dest->activeconns),
77369 atomic_read(&dest->inactconns));
77370 @@ -2287,6 +2287,8 @@ do_ip_vs_set_ctl(struct sock *sk, int cm
77371 struct ip_vs_dest_user *udest_compat;
77372 struct ip_vs_dest_user_kern udest;
77373
77374 + pax_track_stack();
77375 +
77376 if (!capable(CAP_NET_ADMIN))
77377 return -EPERM;
77378
77379 @@ -2501,7 +2503,7 @@ __ip_vs_get_dest_entries(struct net *net
77380
77381 entry.addr = dest->addr.ip;
77382 entry.port = dest->port;
77383 - entry.conn_flags = atomic_read(&dest->conn_flags);
77384 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
77385 entry.weight = atomic_read(&dest->weight);
77386 entry.u_threshold = dest->u_threshold;
77387 entry.l_threshold = dest->l_threshold;
77388 @@ -3029,7 +3031,7 @@ static int ip_vs_genl_fill_dest(struct s
77389 NLA_PUT_U16(skb, IPVS_DEST_ATTR_PORT, dest->port);
77390
77391 NLA_PUT_U32(skb, IPVS_DEST_ATTR_FWD_METHOD,
77392 - atomic_read(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
77393 + atomic_read_unchecked(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
77394 NLA_PUT_U32(skb, IPVS_DEST_ATTR_WEIGHT, atomic_read(&dest->weight));
77395 NLA_PUT_U32(skb, IPVS_DEST_ATTR_U_THRESH, dest->u_threshold);
77396 NLA_PUT_U32(skb, IPVS_DEST_ATTR_L_THRESH, dest->l_threshold);
77397 diff -urNp linux-2.6.39/net/netfilter/ipvs/ip_vs_sync.c linux-2.6.39/net/netfilter/ipvs/ip_vs_sync.c
77398 --- linux-2.6.39/net/netfilter/ipvs/ip_vs_sync.c 2011-05-19 00:06:34.000000000 -0400
77399 +++ linux-2.6.39/net/netfilter/ipvs/ip_vs_sync.c 2011-05-22 19:36:34.000000000 -0400
77400 @@ -648,7 +648,7 @@ control:
77401 * i.e only increment in_pkts for Templates.
77402 */
77403 if (cp->flags & IP_VS_CONN_F_TEMPLATE) {
77404 - int pkts = atomic_add_return(1, &cp->in_pkts);
77405 + int pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
77406
77407 if (pkts % sysctl_sync_period(ipvs) != 1)
77408 return;
77409 @@ -794,7 +794,7 @@ static void ip_vs_proc_conn(struct net *
77410
77411 if (opt)
77412 memcpy(&cp->in_seq, opt, sizeof(*opt));
77413 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
77414 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
77415 cp->state = state;
77416 cp->old_state = cp->state;
77417 /*
77418 diff -urNp linux-2.6.39/net/netfilter/ipvs/ip_vs_xmit.c linux-2.6.39/net/netfilter/ipvs/ip_vs_xmit.c
77419 --- linux-2.6.39/net/netfilter/ipvs/ip_vs_xmit.c 2011-05-19 00:06:34.000000000 -0400
77420 +++ linux-2.6.39/net/netfilter/ipvs/ip_vs_xmit.c 2011-05-22 19:36:34.000000000 -0400
77421 @@ -1127,7 +1127,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, str
77422 else
77423 rc = NF_ACCEPT;
77424 /* do not touch skb anymore */
77425 - atomic_inc(&cp->in_pkts);
77426 + atomic_inc_unchecked(&cp->in_pkts);
77427 goto out;
77428 }
77429
77430 @@ -1245,7 +1245,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb,
77431 else
77432 rc = NF_ACCEPT;
77433 /* do not touch skb anymore */
77434 - atomic_inc(&cp->in_pkts);
77435 + atomic_inc_unchecked(&cp->in_pkts);
77436 goto out;
77437 }
77438
77439 diff -urNp linux-2.6.39/net/netfilter/Kconfig linux-2.6.39/net/netfilter/Kconfig
77440 --- linux-2.6.39/net/netfilter/Kconfig 2011-05-19 00:06:34.000000000 -0400
77441 +++ linux-2.6.39/net/netfilter/Kconfig 2011-05-22 19:41:42.000000000 -0400
77442 @@ -781,6 +781,16 @@ config NETFILTER_XT_MATCH_ESP
77443
77444 To compile it as a module, choose M here. If unsure, say N.
77445
77446 +config NETFILTER_XT_MATCH_GRADM
77447 + tristate '"gradm" match support'
77448 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
77449 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
77450 + ---help---
77451 + The gradm match allows to match on grsecurity RBAC being enabled.
77452 + It is useful when iptables rules are applied early on bootup to
77453 + prevent connections to the machine (except from a trusted host)
77454 + while the RBAC system is disabled.
77455 +
77456 config NETFILTER_XT_MATCH_HASHLIMIT
77457 tristate '"hashlimit" match support'
77458 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
77459 diff -urNp linux-2.6.39/net/netfilter/Makefile linux-2.6.39/net/netfilter/Makefile
77460 --- linux-2.6.39/net/netfilter/Makefile 2011-05-19 00:06:34.000000000 -0400
77461 +++ linux-2.6.39/net/netfilter/Makefile 2011-05-22 20:40:16.000000000 -0400
77462 @@ -81,6 +81,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DCCP) +=
77463 obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
77464 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
77465 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
77466 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
77467 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
77468 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
77469 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
77470 diff -urNp linux-2.6.39/net/netfilter/nfnetlink_log.c linux-2.6.39/net/netfilter/nfnetlink_log.c
77471 --- linux-2.6.39/net/netfilter/nfnetlink_log.c 2011-05-19 00:06:34.000000000 -0400
77472 +++ linux-2.6.39/net/netfilter/nfnetlink_log.c 2011-05-22 19:36:35.000000000 -0400
77473 @@ -70,7 +70,7 @@ struct nfulnl_instance {
77474 };
77475
77476 static DEFINE_SPINLOCK(instances_lock);
77477 -static atomic_t global_seq;
77478 +static atomic_unchecked_t global_seq;
77479
77480 #define INSTANCE_BUCKETS 16
77481 static struct hlist_head instance_table[INSTANCE_BUCKETS];
77482 @@ -506,7 +506,7 @@ __build_packet_message(struct nfulnl_ins
77483 /* global sequence number */
77484 if (inst->flags & NFULNL_CFG_F_SEQ_GLOBAL)
77485 NLA_PUT_BE32(inst->skb, NFULA_SEQ_GLOBAL,
77486 - htonl(atomic_inc_return(&global_seq)));
77487 + htonl(atomic_inc_return_unchecked(&global_seq)));
77488
77489 if (data_len) {
77490 struct nlattr *nla;
77491 diff -urNp linux-2.6.39/net/netfilter/nfnetlink_queue.c linux-2.6.39/net/netfilter/nfnetlink_queue.c
77492 --- linux-2.6.39/net/netfilter/nfnetlink_queue.c 2011-05-19 00:06:34.000000000 -0400
77493 +++ linux-2.6.39/net/netfilter/nfnetlink_queue.c 2011-05-22 19:36:35.000000000 -0400
77494 @@ -58,7 +58,7 @@ struct nfqnl_instance {
77495 */
77496 spinlock_t lock;
77497 unsigned int queue_total;
77498 - atomic_t id_sequence; /* 'sequence' of pkt ids */
77499 + atomic_unchecked_t id_sequence; /* 'sequence' of pkt ids */
77500 struct list_head queue_list; /* packets in queue */
77501 };
77502
77503 @@ -272,7 +272,7 @@ nfqnl_build_packet_message(struct nfqnl_
77504 nfmsg->version = NFNETLINK_V0;
77505 nfmsg->res_id = htons(queue->queue_num);
77506
77507 - entry->id = atomic_inc_return(&queue->id_sequence);
77508 + entry->id = atomic_inc_return_unchecked(&queue->id_sequence);
77509 pmsg.packet_id = htonl(entry->id);
77510 pmsg.hw_protocol = entskb->protocol;
77511 pmsg.hook = entry->hook;
77512 @@ -869,7 +869,7 @@ static int seq_show(struct seq_file *s,
77513 inst->peer_pid, inst->queue_total,
77514 inst->copy_mode, inst->copy_range,
77515 inst->queue_dropped, inst->queue_user_dropped,
77516 - atomic_read(&inst->id_sequence), 1);
77517 + atomic_read_unchecked(&inst->id_sequence), 1);
77518 }
77519
77520 static const struct seq_operations nfqnl_seq_ops = {
77521 diff -urNp linux-2.6.39/net/netfilter/xt_gradm.c linux-2.6.39/net/netfilter/xt_gradm.c
77522 --- linux-2.6.39/net/netfilter/xt_gradm.c 1969-12-31 19:00:00.000000000 -0500
77523 +++ linux-2.6.39/net/netfilter/xt_gradm.c 2011-05-22 19:41:42.000000000 -0400
77524 @@ -0,0 +1,51 @@
77525 +/*
77526 + * gradm match for netfilter
77527 + * Copyright © Zbigniew Krzystolik, 2010
77528 + *
77529 + * This program is free software; you can redistribute it and/or modify
77530 + * it under the terms of the GNU General Public License; either version
77531 + * 2 or 3 as published by the Free Software Foundation.
77532 + */
77533 +#include <linux/module.h>
77534 +#include <linux/moduleparam.h>
77535 +#include <linux/skbuff.h>
77536 +#include <linux/netfilter/x_tables.h>
77537 +#include <linux/grsecurity.h>
77538 +#include <linux/netfilter/xt_gradm.h>
77539 +
77540 +static bool
77541 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
77542 +{
77543 + const struct xt_gradm_mtinfo *info = par->matchinfo;
77544 + bool retval = false;
77545 + if (gr_acl_is_enabled())
77546 + retval = true;
77547 + return retval ^ info->invflags;
77548 +}
77549 +
77550 +static struct xt_match gradm_mt_reg __read_mostly = {
77551 + .name = "gradm",
77552 + .revision = 0,
77553 + .family = NFPROTO_UNSPEC,
77554 + .match = gradm_mt,
77555 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
77556 + .me = THIS_MODULE,
77557 +};
77558 +
77559 +static int __init gradm_mt_init(void)
77560 +{
77561 + return xt_register_match(&gradm_mt_reg);
77562 +}
77563 +
77564 +static void __exit gradm_mt_exit(void)
77565 +{
77566 + xt_unregister_match(&gradm_mt_reg);
77567 +}
77568 +
77569 +module_init(gradm_mt_init);
77570 +module_exit(gradm_mt_exit);
77571 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
77572 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
77573 +MODULE_LICENSE("GPL");
77574 +MODULE_ALIAS("ipt_gradm");
77575 +MODULE_ALIAS("ip6t_gradm");
77576 diff -urNp linux-2.6.39/net/netfilter/xt_statistic.c linux-2.6.39/net/netfilter/xt_statistic.c
77577 --- linux-2.6.39/net/netfilter/xt_statistic.c 2011-05-19 00:06:34.000000000 -0400
77578 +++ linux-2.6.39/net/netfilter/xt_statistic.c 2011-05-22 19:36:35.000000000 -0400
77579 @@ -18,7 +18,7 @@
77580 #include <linux/netfilter/x_tables.h>
77581
77582 struct xt_statistic_priv {
77583 - atomic_t count;
77584 + atomic_unchecked_t count;
77585 } ____cacheline_aligned_in_smp;
77586
77587 MODULE_LICENSE("GPL");
77588 @@ -41,9 +41,9 @@ statistic_mt(const struct sk_buff *skb,
77589 break;
77590 case XT_STATISTIC_MODE_NTH:
77591 do {
77592 - oval = atomic_read(&info->master->count);
77593 + oval = atomic_read_unchecked(&info->master->count);
77594 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
77595 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
77596 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
77597 if (nval == 0)
77598 ret = !ret;
77599 break;
77600 @@ -63,7 +63,7 @@ static int statistic_mt_check(const stru
77601 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
77602 if (info->master == NULL)
77603 return -ENOMEM;
77604 - atomic_set(&info->master->count, info->u.nth.count);
77605 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
77606
77607 return 0;
77608 }
77609 diff -urNp linux-2.6.39/net/netlink/af_netlink.c linux-2.6.39/net/netlink/af_netlink.c
77610 --- linux-2.6.39/net/netlink/af_netlink.c 2011-05-19 00:06:34.000000000 -0400
77611 +++ linux-2.6.39/net/netlink/af_netlink.c 2011-05-22 19:41:42.000000000 -0400
77612 @@ -742,7 +742,7 @@ static void netlink_overrun(struct sock
77613 sk->sk_error_report(sk);
77614 }
77615 }
77616 - atomic_inc(&sk->sk_drops);
77617 + atomic_inc_unchecked(&sk->sk_drops);
77618 }
77619
77620 static struct sock *netlink_getsockbypid(struct sock *ssk, u32 pid)
77621 @@ -1992,15 +1992,23 @@ static int netlink_seq_show(struct seq_f
77622 struct netlink_sock *nlk = nlk_sk(s);
77623
77624 seq_printf(seq, "%p %-3d %-6d %08x %-8d %-8d %p %-8d %-8d %-8lu\n",
77625 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77626 + NULL,
77627 +#else
77628 s,
77629 +#endif
77630 s->sk_protocol,
77631 nlk->pid,
77632 nlk->groups ? (u32)nlk->groups[0] : 0,
77633 sk_rmem_alloc_get(s),
77634 sk_wmem_alloc_get(s),
77635 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77636 + NULL,
77637 +#else
77638 nlk->cb,
77639 +#endif
77640 atomic_read(&s->sk_refcnt),
77641 - atomic_read(&s->sk_drops),
77642 + atomic_read_unchecked(&s->sk_drops),
77643 sock_i_ino(s)
77644 );
77645
77646 diff -urNp linux-2.6.39/net/netrom/af_netrom.c linux-2.6.39/net/netrom/af_netrom.c
77647 --- linux-2.6.39/net/netrom/af_netrom.c 2011-05-19 00:06:34.000000000 -0400
77648 +++ linux-2.6.39/net/netrom/af_netrom.c 2011-05-22 19:41:42.000000000 -0400
77649 @@ -840,6 +840,7 @@ static int nr_getname(struct socket *soc
77650 struct sock *sk = sock->sk;
77651 struct nr_sock *nr = nr_sk(sk);
77652
77653 + memset(sax, 0, sizeof(*sax));
77654 lock_sock(sk);
77655 if (peer != 0) {
77656 if (sk->sk_state != TCP_ESTABLISHED) {
77657 @@ -854,7 +855,6 @@ static int nr_getname(struct socket *soc
77658 *uaddr_len = sizeof(struct full_sockaddr_ax25);
77659 } else {
77660 sax->fsa_ax25.sax25_family = AF_NETROM;
77661 - sax->fsa_ax25.sax25_ndigis = 0;
77662 sax->fsa_ax25.sax25_call = nr->source_addr;
77663 *uaddr_len = sizeof(struct sockaddr_ax25);
77664 }
77665 diff -urNp linux-2.6.39/net/packet/af_packet.c linux-2.6.39/net/packet/af_packet.c
77666 --- linux-2.6.39/net/packet/af_packet.c 2011-05-19 00:06:34.000000000 -0400
77667 +++ linux-2.6.39/net/packet/af_packet.c 2011-05-22 19:41:42.000000000 -0400
77668 @@ -647,14 +647,14 @@ static int packet_rcv(struct sk_buff *sk
77669
77670 spin_lock(&sk->sk_receive_queue.lock);
77671 po->stats.tp_packets++;
77672 - skb->dropcount = atomic_read(&sk->sk_drops);
77673 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
77674 __skb_queue_tail(&sk->sk_receive_queue, skb);
77675 spin_unlock(&sk->sk_receive_queue.lock);
77676 sk->sk_data_ready(sk, skb->len);
77677 return 0;
77678
77679 drop_n_acct:
77680 - po->stats.tp_drops = atomic_inc_return(&sk->sk_drops);
77681 + po->stats.tp_drops = atomic_inc_return_unchecked(&sk->sk_drops);
77682
77683 drop_n_restore:
77684 if (skb_head != skb->data && skb_shared(skb)) {
77685 @@ -2157,7 +2157,7 @@ static int packet_getsockopt(struct sock
77686 case PACKET_HDRLEN:
77687 if (len > sizeof(int))
77688 len = sizeof(int);
77689 - if (copy_from_user(&val, optval, len))
77690 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
77691 return -EFAULT;
77692 switch (val) {
77693 case TPACKET_V1:
77694 @@ -2195,7 +2195,7 @@ static int packet_getsockopt(struct sock
77695
77696 if (put_user(len, optlen))
77697 return -EFAULT;
77698 - if (copy_to_user(optval, data, len))
77699 + if (len > sizeof(st) || copy_to_user(optval, data, len))
77700 return -EFAULT;
77701 return 0;
77702 }
77703 @@ -2707,7 +2707,11 @@ static int packet_seq_show(struct seq_fi
77704
77705 seq_printf(seq,
77706 "%p %-6d %-4d %04x %-5d %1d %-6u %-6u %-6lu\n",
77707 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77708 + NULL,
77709 +#else
77710 s,
77711 +#endif
77712 atomic_read(&s->sk_refcnt),
77713 s->sk_type,
77714 ntohs(po->num),
77715 diff -urNp linux-2.6.39/net/phonet/af_phonet.c linux-2.6.39/net/phonet/af_phonet.c
77716 --- linux-2.6.39/net/phonet/af_phonet.c 2011-05-19 00:06:34.000000000 -0400
77717 +++ linux-2.6.39/net/phonet/af_phonet.c 2011-05-22 19:41:42.000000000 -0400
77718 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_pr
77719 {
77720 struct phonet_protocol *pp;
77721
77722 - if (protocol >= PHONET_NPROTO)
77723 + if (protocol < 0 || protocol >= PHONET_NPROTO)
77724 return NULL;
77725
77726 rcu_read_lock();
77727 @@ -149,7 +149,7 @@ static int pn_header_parse(const struct
77728 return 1;
77729 }
77730
77731 -struct header_ops phonet_header_ops = {
77732 +const struct header_ops phonet_header_ops = {
77733 .create = pn_header_create,
77734 .parse = pn_header_parse,
77735 };
77736 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_regist
77737 {
77738 int err = 0;
77739
77740 - if (protocol >= PHONET_NPROTO)
77741 + if (protocol < 0 || protocol >= PHONET_NPROTO)
77742 return -EINVAL;
77743
77744 err = proto_register(pp->prot, 1);
77745 diff -urNp linux-2.6.39/net/phonet/pep.c linux-2.6.39/net/phonet/pep.c
77746 --- linux-2.6.39/net/phonet/pep.c 2011-05-19 00:06:34.000000000 -0400
77747 +++ linux-2.6.39/net/phonet/pep.c 2011-05-22 19:36:35.000000000 -0400
77748 @@ -387,7 +387,7 @@ static int pipe_do_rcv(struct sock *sk,
77749
77750 case PNS_PEP_CTRL_REQ:
77751 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
77752 - atomic_inc(&sk->sk_drops);
77753 + atomic_inc_unchecked(&sk->sk_drops);
77754 break;
77755 }
77756 __skb_pull(skb, 4);
77757 @@ -408,7 +408,7 @@ static int pipe_do_rcv(struct sock *sk,
77758 }
77759
77760 if (pn->rx_credits == 0) {
77761 - atomic_inc(&sk->sk_drops);
77762 + atomic_inc_unchecked(&sk->sk_drops);
77763 err = -ENOBUFS;
77764 break;
77765 }
77766 @@ -556,7 +556,7 @@ static int pipe_handler_do_rcv(struct so
77767 }
77768
77769 if (pn->rx_credits == 0) {
77770 - atomic_inc(&sk->sk_drops);
77771 + atomic_inc_unchecked(&sk->sk_drops);
77772 err = NET_RX_DROP;
77773 break;
77774 }
77775 diff -urNp linux-2.6.39/net/phonet/socket.c linux-2.6.39/net/phonet/socket.c
77776 --- linux-2.6.39/net/phonet/socket.c 2011-05-19 00:06:34.000000000 -0400
77777 +++ linux-2.6.39/net/phonet/socket.c 2011-05-22 20:39:26.000000000 -0400
77778 @@ -613,8 +613,13 @@ static int pn_sock_seq_show(struct seq_f
77779 pn->resource, sk->sk_state,
77780 sk_wmem_alloc_get(sk), sk_rmem_alloc_get(sk),
77781 sock_i_uid(sk), sock_i_ino(sk),
77782 - atomic_read(&sk->sk_refcnt), sk,
77783 - atomic_read(&sk->sk_drops), &len);
77784 + atomic_read(&sk->sk_refcnt),
77785 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77786 + NULL,
77787 +#else
77788 + sk,
77789 +#endif
77790 + atomic_read_unchecked(&sk->sk_drops), &len);
77791 }
77792 seq_printf(seq, "%*s\n", 127 - len, "");
77793 return 0;
77794 diff -urNp linux-2.6.39/net/rds/cong.c linux-2.6.39/net/rds/cong.c
77795 --- linux-2.6.39/net/rds/cong.c 2011-05-19 00:06:34.000000000 -0400
77796 +++ linux-2.6.39/net/rds/cong.c 2011-05-22 19:36:35.000000000 -0400
77797 @@ -77,7 +77,7 @@
77798 * finds that the saved generation number is smaller than the global generation
77799 * number, it wakes up the process.
77800 */
77801 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
77802 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
77803
77804 /*
77805 * Congestion monitoring
77806 @@ -232,7 +232,7 @@ void rds_cong_map_updated(struct rds_con
77807 rdsdebug("waking map %p for %pI4\n",
77808 map, &map->m_addr);
77809 rds_stats_inc(s_cong_update_received);
77810 - atomic_inc(&rds_cong_generation);
77811 + atomic_inc_unchecked(&rds_cong_generation);
77812 if (waitqueue_active(&map->m_waitq))
77813 wake_up(&map->m_waitq);
77814 if (waitqueue_active(&rds_poll_waitq))
77815 @@ -258,7 +258,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
77816
77817 int rds_cong_updated_since(unsigned long *recent)
77818 {
77819 - unsigned long gen = atomic_read(&rds_cong_generation);
77820 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
77821
77822 if (likely(*recent == gen))
77823 return 0;
77824 diff -urNp linux-2.6.39/net/rds/ib_cm.c linux-2.6.39/net/rds/ib_cm.c
77825 --- linux-2.6.39/net/rds/ib_cm.c 2011-05-19 00:06:34.000000000 -0400
77826 +++ linux-2.6.39/net/rds/ib_cm.c 2011-05-22 19:36:35.000000000 -0400
77827 @@ -720,7 +720,7 @@ void rds_ib_conn_shutdown(struct rds_con
77828 /* Clear the ACK state */
77829 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
77830 #ifdef KERNEL_HAS_ATOMIC64
77831 - atomic64_set(&ic->i_ack_next, 0);
77832 + atomic64_set_unchecked(&ic->i_ack_next, 0);
77833 #else
77834 ic->i_ack_next = 0;
77835 #endif
77836 diff -urNp linux-2.6.39/net/rds/ib.h linux-2.6.39/net/rds/ib.h
77837 --- linux-2.6.39/net/rds/ib.h 2011-05-19 00:06:34.000000000 -0400
77838 +++ linux-2.6.39/net/rds/ib.h 2011-05-22 19:36:35.000000000 -0400
77839 @@ -127,7 +127,7 @@ struct rds_ib_connection {
77840 /* sending acks */
77841 unsigned long i_ack_flags;
77842 #ifdef KERNEL_HAS_ATOMIC64
77843 - atomic64_t i_ack_next; /* next ACK to send */
77844 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
77845 #else
77846 spinlock_t i_ack_lock; /* protect i_ack_next */
77847 u64 i_ack_next; /* next ACK to send */
77848 diff -urNp linux-2.6.39/net/rds/ib_recv.c linux-2.6.39/net/rds/ib_recv.c
77849 --- linux-2.6.39/net/rds/ib_recv.c 2011-05-19 00:06:34.000000000 -0400
77850 +++ linux-2.6.39/net/rds/ib_recv.c 2011-05-22 19:36:35.000000000 -0400
77851 @@ -592,7 +592,7 @@ static u64 rds_ib_get_ack(struct rds_ib_
77852 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
77853 int ack_required)
77854 {
77855 - atomic64_set(&ic->i_ack_next, seq);
77856 + atomic64_set_unchecked(&ic->i_ack_next, seq);
77857 if (ack_required) {
77858 smp_mb__before_clear_bit();
77859 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77860 @@ -604,7 +604,7 @@ static u64 rds_ib_get_ack(struct rds_ib_
77861 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77862 smp_mb__after_clear_bit();
77863
77864 - return atomic64_read(&ic->i_ack_next);
77865 + return atomic64_read_unchecked(&ic->i_ack_next);
77866 }
77867 #endif
77868
77869 diff -urNp linux-2.6.39/net/rds/iw_cm.c linux-2.6.39/net/rds/iw_cm.c
77870 --- linux-2.6.39/net/rds/iw_cm.c 2011-05-19 00:06:34.000000000 -0400
77871 +++ linux-2.6.39/net/rds/iw_cm.c 2011-05-22 19:36:35.000000000 -0400
77872 @@ -664,7 +664,7 @@ void rds_iw_conn_shutdown(struct rds_con
77873 /* Clear the ACK state */
77874 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
77875 #ifdef KERNEL_HAS_ATOMIC64
77876 - atomic64_set(&ic->i_ack_next, 0);
77877 + atomic64_set_unchecked(&ic->i_ack_next, 0);
77878 #else
77879 ic->i_ack_next = 0;
77880 #endif
77881 diff -urNp linux-2.6.39/net/rds/iw.h linux-2.6.39/net/rds/iw.h
77882 --- linux-2.6.39/net/rds/iw.h 2011-05-19 00:06:34.000000000 -0400
77883 +++ linux-2.6.39/net/rds/iw.h 2011-05-22 19:36:35.000000000 -0400
77884 @@ -133,7 +133,7 @@ struct rds_iw_connection {
77885 /* sending acks */
77886 unsigned long i_ack_flags;
77887 #ifdef KERNEL_HAS_ATOMIC64
77888 - atomic64_t i_ack_next; /* next ACK to send */
77889 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
77890 #else
77891 spinlock_t i_ack_lock; /* protect i_ack_next */
77892 u64 i_ack_next; /* next ACK to send */
77893 diff -urNp linux-2.6.39/net/rds/iw_rdma.c linux-2.6.39/net/rds/iw_rdma.c
77894 --- linux-2.6.39/net/rds/iw_rdma.c 2011-05-19 00:06:34.000000000 -0400
77895 +++ linux-2.6.39/net/rds/iw_rdma.c 2011-05-22 19:36:35.000000000 -0400
77896 @@ -182,6 +182,8 @@ int rds_iw_update_cm_id(struct rds_iw_de
77897 struct rdma_cm_id *pcm_id;
77898 int rc;
77899
77900 + pax_track_stack();
77901 +
77902 src_addr = (struct sockaddr_in *)&cm_id->route.addr.src_addr;
77903 dst_addr = (struct sockaddr_in *)&cm_id->route.addr.dst_addr;
77904
77905 diff -urNp linux-2.6.39/net/rds/iw_recv.c linux-2.6.39/net/rds/iw_recv.c
77906 --- linux-2.6.39/net/rds/iw_recv.c 2011-05-19 00:06:34.000000000 -0400
77907 +++ linux-2.6.39/net/rds/iw_recv.c 2011-05-22 19:36:35.000000000 -0400
77908 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_
77909 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
77910 int ack_required)
77911 {
77912 - atomic64_set(&ic->i_ack_next, seq);
77913 + atomic64_set_unchecked(&ic->i_ack_next, seq);
77914 if (ack_required) {
77915 smp_mb__before_clear_bit();
77916 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77917 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_
77918 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77919 smp_mb__after_clear_bit();
77920
77921 - return atomic64_read(&ic->i_ack_next);
77922 + return atomic64_read_unchecked(&ic->i_ack_next);
77923 }
77924 #endif
77925
77926 diff -urNp linux-2.6.39/net/rxrpc/af_rxrpc.c linux-2.6.39/net/rxrpc/af_rxrpc.c
77927 --- linux-2.6.39/net/rxrpc/af_rxrpc.c 2011-05-19 00:06:34.000000000 -0400
77928 +++ linux-2.6.39/net/rxrpc/af_rxrpc.c 2011-05-22 19:36:35.000000000 -0400
77929 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_
77930 __be32 rxrpc_epoch;
77931
77932 /* current debugging ID */
77933 -atomic_t rxrpc_debug_id;
77934 +atomic_unchecked_t rxrpc_debug_id;
77935
77936 /* count of skbs currently in use */
77937 atomic_t rxrpc_n_skbs;
77938 diff -urNp linux-2.6.39/net/rxrpc/ar-ack.c linux-2.6.39/net/rxrpc/ar-ack.c
77939 --- linux-2.6.39/net/rxrpc/ar-ack.c 2011-05-19 00:06:34.000000000 -0400
77940 +++ linux-2.6.39/net/rxrpc/ar-ack.c 2011-05-22 19:36:35.000000000 -0400
77941 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_ca
77942
77943 _enter("{%d,%d,%d,%d},",
77944 call->acks_hard, call->acks_unacked,
77945 - atomic_read(&call->sequence),
77946 + atomic_read_unchecked(&call->sequence),
77947 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
77948
77949 stop = 0;
77950 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_ca
77951
77952 /* each Tx packet has a new serial number */
77953 sp->hdr.serial =
77954 - htonl(atomic_inc_return(&call->conn->serial));
77955 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
77956
77957 hdr = (struct rxrpc_header *) txb->head;
77958 hdr->serial = sp->hdr.serial;
77959 @@ -405,7 +405,7 @@ static void rxrpc_rotate_tx_window(struc
77960 */
77961 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
77962 {
77963 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
77964 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
77965 }
77966
77967 /*
77968 @@ -631,7 +631,7 @@ process_further:
77969
77970 latest = ntohl(sp->hdr.serial);
77971 hard = ntohl(ack.firstPacket);
77972 - tx = atomic_read(&call->sequence);
77973 + tx = atomic_read_unchecked(&call->sequence);
77974
77975 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
77976 latest,
77977 @@ -844,6 +844,8 @@ void rxrpc_process_call(struct work_stru
77978 u32 abort_code = RX_PROTOCOL_ERROR;
77979 u8 *acks = NULL;
77980
77981 + pax_track_stack();
77982 +
77983 //printk("\n--------------------\n");
77984 _enter("{%d,%s,%lx} [%lu]",
77985 call->debug_id, rxrpc_call_states[call->state], call->events,
77986 @@ -1163,7 +1165,7 @@ void rxrpc_process_call(struct work_stru
77987 goto maybe_reschedule;
77988
77989 send_ACK_with_skew:
77990 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
77991 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
77992 ntohl(ack.serial));
77993 send_ACK:
77994 mtu = call->conn->trans->peer->if_mtu;
77995 @@ -1175,7 +1177,7 @@ send_ACK:
77996 ackinfo.rxMTU = htonl(5692);
77997 ackinfo.jumbo_max = htonl(4);
77998
77999 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
78000 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
78001 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
78002 ntohl(hdr.serial),
78003 ntohs(ack.maxSkew),
78004 @@ -1193,7 +1195,7 @@ send_ACK:
78005 send_message:
78006 _debug("send message");
78007
78008 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
78009 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
78010 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
78011 send_message_2:
78012
78013 diff -urNp linux-2.6.39/net/rxrpc/ar-call.c linux-2.6.39/net/rxrpc/ar-call.c
78014 --- linux-2.6.39/net/rxrpc/ar-call.c 2011-05-19 00:06:34.000000000 -0400
78015 +++ linux-2.6.39/net/rxrpc/ar-call.c 2011-05-22 19:36:35.000000000 -0400
78016 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_ca
78017 spin_lock_init(&call->lock);
78018 rwlock_init(&call->state_lock);
78019 atomic_set(&call->usage, 1);
78020 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
78021 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78022 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
78023
78024 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
78025 diff -urNp linux-2.6.39/net/rxrpc/ar-connection.c linux-2.6.39/net/rxrpc/ar-connection.c
78026 --- linux-2.6.39/net/rxrpc/ar-connection.c 2011-05-19 00:06:34.000000000 -0400
78027 +++ linux-2.6.39/net/rxrpc/ar-connection.c 2011-05-22 19:36:35.000000000 -0400
78028 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_al
78029 rwlock_init(&conn->lock);
78030 spin_lock_init(&conn->state_lock);
78031 atomic_set(&conn->usage, 1);
78032 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
78033 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78034 conn->avail_calls = RXRPC_MAXCALLS;
78035 conn->size_align = 4;
78036 conn->header_size = sizeof(struct rxrpc_header);
78037 diff -urNp linux-2.6.39/net/rxrpc/ar-connevent.c linux-2.6.39/net/rxrpc/ar-connevent.c
78038 --- linux-2.6.39/net/rxrpc/ar-connevent.c 2011-05-19 00:06:34.000000000 -0400
78039 +++ linux-2.6.39/net/rxrpc/ar-connevent.c 2011-05-22 19:36:35.000000000 -0400
78040 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct
78041
78042 len = iov[0].iov_len + iov[1].iov_len;
78043
78044 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
78045 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
78046 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
78047
78048 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
78049 diff -urNp linux-2.6.39/net/rxrpc/ar-input.c linux-2.6.39/net/rxrpc/ar-input.c
78050 --- linux-2.6.39/net/rxrpc/ar-input.c 2011-05-19 00:06:34.000000000 -0400
78051 +++ linux-2.6.39/net/rxrpc/ar-input.c 2011-05-22 19:36:35.000000000 -0400
78052 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rx
78053 /* track the latest serial number on this connection for ACK packet
78054 * information */
78055 serial = ntohl(sp->hdr.serial);
78056 - hi_serial = atomic_read(&call->conn->hi_serial);
78057 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
78058 while (serial > hi_serial)
78059 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
78060 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
78061 serial);
78062
78063 /* request ACK generation for any ACK or DATA packet that requests
78064 diff -urNp linux-2.6.39/net/rxrpc/ar-internal.h linux-2.6.39/net/rxrpc/ar-internal.h
78065 --- linux-2.6.39/net/rxrpc/ar-internal.h 2011-05-19 00:06:34.000000000 -0400
78066 +++ linux-2.6.39/net/rxrpc/ar-internal.h 2011-05-22 19:36:35.000000000 -0400
78067 @@ -272,8 +272,8 @@ struct rxrpc_connection {
78068 int error; /* error code for local abort */
78069 int debug_id; /* debug ID for printks */
78070 unsigned call_counter; /* call ID counter */
78071 - atomic_t serial; /* packet serial number counter */
78072 - atomic_t hi_serial; /* highest serial number received */
78073 + atomic_unchecked_t serial; /* packet serial number counter */
78074 + atomic_unchecked_t hi_serial; /* highest serial number received */
78075 u8 avail_calls; /* number of calls available */
78076 u8 size_align; /* data size alignment (for security) */
78077 u8 header_size; /* rxrpc + security header size */
78078 @@ -346,7 +346,7 @@ struct rxrpc_call {
78079 spinlock_t lock;
78080 rwlock_t state_lock; /* lock for state transition */
78081 atomic_t usage;
78082 - atomic_t sequence; /* Tx data packet sequence counter */
78083 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
78084 u32 abort_code; /* local/remote abort code */
78085 enum { /* current state of call */
78086 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
78087 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(stru
78088 */
78089 extern atomic_t rxrpc_n_skbs;
78090 extern __be32 rxrpc_epoch;
78091 -extern atomic_t rxrpc_debug_id;
78092 +extern atomic_unchecked_t rxrpc_debug_id;
78093 extern struct workqueue_struct *rxrpc_workqueue;
78094
78095 /*
78096 diff -urNp linux-2.6.39/net/rxrpc/ar-local.c linux-2.6.39/net/rxrpc/ar-local.c
78097 --- linux-2.6.39/net/rxrpc/ar-local.c 2011-05-19 00:06:34.000000000 -0400
78098 +++ linux-2.6.39/net/rxrpc/ar-local.c 2011-05-22 19:36:35.000000000 -0400
78099 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(st
78100 spin_lock_init(&local->lock);
78101 rwlock_init(&local->services_lock);
78102 atomic_set(&local->usage, 1);
78103 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
78104 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78105 memcpy(&local->srx, srx, sizeof(*srx));
78106 }
78107
78108 diff -urNp linux-2.6.39/net/rxrpc/ar-output.c linux-2.6.39/net/rxrpc/ar-output.c
78109 --- linux-2.6.39/net/rxrpc/ar-output.c 2011-05-19 00:06:34.000000000 -0400
78110 +++ linux-2.6.39/net/rxrpc/ar-output.c 2011-05-22 19:36:35.000000000 -0400
78111 @@ -681,9 +681,9 @@ static int rxrpc_send_data(struct kiocb
78112 sp->hdr.cid = call->cid;
78113 sp->hdr.callNumber = call->call_id;
78114 sp->hdr.seq =
78115 - htonl(atomic_inc_return(&call->sequence));
78116 + htonl(atomic_inc_return_unchecked(&call->sequence));
78117 sp->hdr.serial =
78118 - htonl(atomic_inc_return(&conn->serial));
78119 + htonl(atomic_inc_return_unchecked(&conn->serial));
78120 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
78121 sp->hdr.userStatus = 0;
78122 sp->hdr.securityIndex = conn->security_ix;
78123 diff -urNp linux-2.6.39/net/rxrpc/ar-peer.c linux-2.6.39/net/rxrpc/ar-peer.c
78124 --- linux-2.6.39/net/rxrpc/ar-peer.c 2011-05-19 00:06:34.000000000 -0400
78125 +++ linux-2.6.39/net/rxrpc/ar-peer.c 2011-05-22 19:36:35.000000000 -0400
78126 @@ -71,7 +71,7 @@ static struct rxrpc_peer *rxrpc_alloc_pe
78127 INIT_LIST_HEAD(&peer->error_targets);
78128 spin_lock_init(&peer->lock);
78129 atomic_set(&peer->usage, 1);
78130 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
78131 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78132 memcpy(&peer->srx, srx, sizeof(*srx));
78133
78134 rxrpc_assess_MTU_size(peer);
78135 diff -urNp linux-2.6.39/net/rxrpc/ar-proc.c linux-2.6.39/net/rxrpc/ar-proc.c
78136 --- linux-2.6.39/net/rxrpc/ar-proc.c 2011-05-19 00:06:34.000000000 -0400
78137 +++ linux-2.6.39/net/rxrpc/ar-proc.c 2011-05-22 19:36:35.000000000 -0400
78138 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(str
78139 atomic_read(&conn->usage),
78140 rxrpc_conn_states[conn->state],
78141 key_serial(conn->key),
78142 - atomic_read(&conn->serial),
78143 - atomic_read(&conn->hi_serial));
78144 + atomic_read_unchecked(&conn->serial),
78145 + atomic_read_unchecked(&conn->hi_serial));
78146
78147 return 0;
78148 }
78149 diff -urNp linux-2.6.39/net/rxrpc/ar-transport.c linux-2.6.39/net/rxrpc/ar-transport.c
78150 --- linux-2.6.39/net/rxrpc/ar-transport.c 2011-05-19 00:06:34.000000000 -0400
78151 +++ linux-2.6.39/net/rxrpc/ar-transport.c 2011-05-22 19:36:35.000000000 -0400
78152 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_all
78153 spin_lock_init(&trans->client_lock);
78154 rwlock_init(&trans->conn_lock);
78155 atomic_set(&trans->usage, 1);
78156 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
78157 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78158
78159 if (peer->srx.transport.family == AF_INET) {
78160 switch (peer->srx.transport_type) {
78161 diff -urNp linux-2.6.39/net/rxrpc/rxkad.c linux-2.6.39/net/rxrpc/rxkad.c
78162 --- linux-2.6.39/net/rxrpc/rxkad.c 2011-05-19 00:06:34.000000000 -0400
78163 +++ linux-2.6.39/net/rxrpc/rxkad.c 2011-05-22 19:36:35.000000000 -0400
78164 @@ -211,6 +211,8 @@ static int rxkad_secure_packet_encrypt(c
78165 u16 check;
78166 int nsg;
78167
78168 + pax_track_stack();
78169 +
78170 sp = rxrpc_skb(skb);
78171
78172 _enter("");
78173 @@ -338,6 +340,8 @@ static int rxkad_verify_packet_auth(cons
78174 u16 check;
78175 int nsg;
78176
78177 + pax_track_stack();
78178 +
78179 _enter("");
78180
78181 sp = rxrpc_skb(skb);
78182 @@ -610,7 +614,7 @@ static int rxkad_issue_challenge(struct
78183
78184 len = iov[0].iov_len + iov[1].iov_len;
78185
78186 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
78187 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
78188 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
78189
78190 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
78191 @@ -660,7 +664,7 @@ static int rxkad_send_response(struct rx
78192
78193 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
78194
78195 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
78196 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
78197 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
78198
78199 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
78200 diff -urNp linux-2.6.39/net/sched/em_meta.c linux-2.6.39/net/sched/em_meta.c
78201 --- linux-2.6.39/net/sched/em_meta.c 2011-05-19 00:06:34.000000000 -0400
78202 +++ linux-2.6.39/net/sched/em_meta.c 2011-05-22 19:36:35.000000000 -0400
78203 @@ -832,7 +832,7 @@ static int em_meta_dump(struct sk_buff *
78204 {
78205 struct meta_match *meta = (struct meta_match *) em->data;
78206 struct tcf_meta_hdr hdr;
78207 - struct meta_type_ops *ops;
78208 + const struct meta_type_ops *ops;
78209
78210 memset(&hdr, 0, sizeof(hdr));
78211 memcpy(&hdr.left, &meta->lvalue.hdr, sizeof(hdr.left));
78212 diff -urNp linux-2.6.39/net/sctp/proc.c linux-2.6.39/net/sctp/proc.c
78213 --- linux-2.6.39/net/sctp/proc.c 2011-05-19 00:06:34.000000000 -0400
78214 +++ linux-2.6.39/net/sctp/proc.c 2011-05-22 19:41:42.000000000 -0400
78215 @@ -212,7 +212,12 @@ static int sctp_eps_seq_show(struct seq_
78216 sctp_for_each_hentry(epb, node, &head->chain) {
78217 ep = sctp_ep(epb);
78218 sk = epb->sk;
78219 - seq_printf(seq, "%8p %8p %-3d %-3d %-4d %-5d %5d %5lu ", ep, sk,
78220 + seq_printf(seq, "%8p %8p %-3d %-3d %-4d %-5d %5d %5lu ",
78221 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78222 + NULL, NULL,
78223 +#else
78224 + ep, sk,
78225 +#endif
78226 sctp_sk(sk)->type, sk->sk_state, hash,
78227 epb->bind_addr.port,
78228 sock_i_uid(sk), sock_i_ino(sk));
78229 @@ -318,7 +323,12 @@ static int sctp_assocs_seq_show(struct s
78230 seq_printf(seq,
78231 "%8p %8p %-3d %-3d %-2d %-4d "
78232 "%4d %8d %8d %7d %5lu %-5d %5d ",
78233 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
78234 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78235 + NULL, NULL,
78236 +#else
78237 + assoc, sk,
78238 +#endif
78239 + sctp_sk(sk)->type, sk->sk_state,
78240 assoc->state, hash,
78241 assoc->assoc_id,
78242 assoc->sndbuf_used,
78243 diff -urNp linux-2.6.39/net/sctp/socket.c linux-2.6.39/net/sctp/socket.c
78244 --- linux-2.6.39/net/sctp/socket.c 2011-05-19 00:06:34.000000000 -0400
78245 +++ linux-2.6.39/net/sctp/socket.c 2011-05-22 19:36:35.000000000 -0400
78246 @@ -4433,7 +4433,7 @@ static int sctp_getsockopt_peer_addrs(st
78247 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
78248 if (space_left < addrlen)
78249 return -ENOMEM;
78250 - if (copy_to_user(to, &temp, addrlen))
78251 + if (addrlen > sizeof(temp) || copy_to_user(to, &temp, addrlen))
78252 return -EFAULT;
78253 to += addrlen;
78254 cnt++;
78255 diff -urNp linux-2.6.39/net/socket.c linux-2.6.39/net/socket.c
78256 --- linux-2.6.39/net/socket.c 2011-05-19 00:06:34.000000000 -0400
78257 +++ linux-2.6.39/net/socket.c 2011-05-22 19:41:42.000000000 -0400
78258 @@ -88,6 +88,7 @@
78259 #include <linux/nsproxy.h>
78260 #include <linux/magic.h>
78261 #include <linux/slab.h>
78262 +#include <linux/in.h>
78263
78264 #include <asm/uaccess.h>
78265 #include <asm/unistd.h>
78266 @@ -105,6 +106,8 @@
78267 #include <linux/sockios.h>
78268 #include <linux/atalk.h>
78269
78270 +#include <linux/grsock.h>
78271 +
78272 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
78273 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
78274 unsigned long nr_segs, loff_t pos);
78275 @@ -330,7 +333,7 @@ static struct dentry *sockfs_mount(struc
78276 &sockfs_dentry_operations, SOCKFS_MAGIC);
78277 }
78278
78279 -static struct vfsmount *sock_mnt __read_mostly;
78280 +struct vfsmount *sock_mnt __read_mostly;
78281
78282 static struct file_system_type sock_fs_type = {
78283 .name = "sockfs",
78284 @@ -1179,6 +1182,8 @@ int __sock_create(struct net *net, int f
78285 return -EAFNOSUPPORT;
78286 if (type < 0 || type >= SOCK_MAX)
78287 return -EINVAL;
78288 + if (protocol < 0)
78289 + return -EINVAL;
78290
78291 /* Compatibility.
78292
78293 @@ -1311,6 +1316,16 @@ SYSCALL_DEFINE3(socket, int, family, int
78294 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
78295 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
78296
78297 + if(!gr_search_socket(family, type, protocol)) {
78298 + retval = -EACCES;
78299 + goto out;
78300 + }
78301 +
78302 + if (gr_handle_sock_all(family, type, protocol)) {
78303 + retval = -EACCES;
78304 + goto out;
78305 + }
78306 +
78307 retval = sock_create(family, type, protocol, &sock);
78308 if (retval < 0)
78309 goto out;
78310 @@ -1423,6 +1438,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct so
78311 if (sock) {
78312 err = move_addr_to_kernel(umyaddr, addrlen, (struct sockaddr *)&address);
78313 if (err >= 0) {
78314 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
78315 + err = -EACCES;
78316 + goto error;
78317 + }
78318 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
78319 + if (err)
78320 + goto error;
78321 +
78322 err = security_socket_bind(sock,
78323 (struct sockaddr *)&address,
78324 addrlen);
78325 @@ -1431,6 +1454,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct so
78326 (struct sockaddr *)
78327 &address, addrlen);
78328 }
78329 +error:
78330 fput_light(sock->file, fput_needed);
78331 }
78332 return err;
78333 @@ -1454,10 +1478,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, ba
78334 if ((unsigned)backlog > somaxconn)
78335 backlog = somaxconn;
78336
78337 + if (gr_handle_sock_server_other(sock->sk)) {
78338 + err = -EPERM;
78339 + goto error;
78340 + }
78341 +
78342 + err = gr_search_listen(sock);
78343 + if (err)
78344 + goto error;
78345 +
78346 err = security_socket_listen(sock, backlog);
78347 if (!err)
78348 err = sock->ops->listen(sock, backlog);
78349
78350 +error:
78351 fput_light(sock->file, fput_needed);
78352 }
78353 return err;
78354 @@ -1501,6 +1535,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct
78355 newsock->type = sock->type;
78356 newsock->ops = sock->ops;
78357
78358 + if (gr_handle_sock_server_other(sock->sk)) {
78359 + err = -EPERM;
78360 + sock_release(newsock);
78361 + goto out_put;
78362 + }
78363 +
78364 + err = gr_search_accept(sock);
78365 + if (err) {
78366 + sock_release(newsock);
78367 + goto out_put;
78368 + }
78369 +
78370 /*
78371 * We don't need try_module_get here, as the listening socket (sock)
78372 * has the protocol module (sock->ops->owner) held.
78373 @@ -1539,6 +1585,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct
78374 fd_install(newfd, newfile);
78375 err = newfd;
78376
78377 + gr_attach_curr_ip(newsock->sk);
78378 +
78379 out_put:
78380 fput_light(sock->file, fput_needed);
78381 out:
78382 @@ -1571,6 +1619,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct
78383 int, addrlen)
78384 {
78385 struct socket *sock;
78386 + struct sockaddr *sck;
78387 struct sockaddr_storage address;
78388 int err, fput_needed;
78389
78390 @@ -1581,6 +1630,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct
78391 if (err < 0)
78392 goto out_put;
78393
78394 + sck = (struct sockaddr *)&address;
78395 +
78396 + if (gr_handle_sock_client(sck)) {
78397 + err = -EACCES;
78398 + goto out_put;
78399 + }
78400 +
78401 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
78402 + if (err)
78403 + goto out_put;
78404 +
78405 err =
78406 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
78407 if (err)
78408 @@ -1882,6 +1942,8 @@ SYSCALL_DEFINE3(sendmsg, int, fd, struct
78409 int err, ctl_len, iov_size, total_len;
78410 int fput_needed;
78411
78412 + pax_track_stack();
78413 +
78414 err = -EFAULT;
78415 if (MSG_CMSG_COMPAT & flags) {
78416 if (get_compat_msghdr(&msg_sys, msg_compat))
78417 diff -urNp linux-2.6.39/net/sunrpc/sched.c linux-2.6.39/net/sunrpc/sched.c
78418 --- linux-2.6.39/net/sunrpc/sched.c 2011-05-19 00:06:34.000000000 -0400
78419 +++ linux-2.6.39/net/sunrpc/sched.c 2011-05-22 19:36:35.000000000 -0400
78420 @@ -234,9 +234,9 @@ static int rpc_wait_bit_killable(void *w
78421 #ifdef RPC_DEBUG
78422 static void rpc_task_set_debuginfo(struct rpc_task *task)
78423 {
78424 - static atomic_t rpc_pid;
78425 + static atomic_unchecked_t rpc_pid;
78426
78427 - task->tk_pid = atomic_inc_return(&rpc_pid);
78428 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
78429 }
78430 #else
78431 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
78432 diff -urNp linux-2.6.39/net/sunrpc/xprtrdma/svc_rdma.c linux-2.6.39/net/sunrpc/xprtrdma/svc_rdma.c
78433 --- linux-2.6.39/net/sunrpc/xprtrdma/svc_rdma.c 2011-05-19 00:06:34.000000000 -0400
78434 +++ linux-2.6.39/net/sunrpc/xprtrdma/svc_rdma.c 2011-05-22 19:36:35.000000000 -0400
78435 @@ -61,15 +61,15 @@ unsigned int svcrdma_max_req_size = RPCR
78436 static unsigned int min_max_inline = 4096;
78437 static unsigned int max_max_inline = 65536;
78438
78439 -atomic_t rdma_stat_recv;
78440 -atomic_t rdma_stat_read;
78441 -atomic_t rdma_stat_write;
78442 -atomic_t rdma_stat_sq_starve;
78443 -atomic_t rdma_stat_rq_starve;
78444 -atomic_t rdma_stat_rq_poll;
78445 -atomic_t rdma_stat_rq_prod;
78446 -atomic_t rdma_stat_sq_poll;
78447 -atomic_t rdma_stat_sq_prod;
78448 +atomic_unchecked_t rdma_stat_recv;
78449 +atomic_unchecked_t rdma_stat_read;
78450 +atomic_unchecked_t rdma_stat_write;
78451 +atomic_unchecked_t rdma_stat_sq_starve;
78452 +atomic_unchecked_t rdma_stat_rq_starve;
78453 +atomic_unchecked_t rdma_stat_rq_poll;
78454 +atomic_unchecked_t rdma_stat_rq_prod;
78455 +atomic_unchecked_t rdma_stat_sq_poll;
78456 +atomic_unchecked_t rdma_stat_sq_prod;
78457
78458 /* Temporary NFS request map and context caches */
78459 struct kmem_cache *svc_rdma_map_cachep;
78460 @@ -109,7 +109,7 @@ static int read_reset_stat(ctl_table *ta
78461 len -= *ppos;
78462 if (len > *lenp)
78463 len = *lenp;
78464 - if (len && copy_to_user(buffer, str_buf, len))
78465 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
78466 return -EFAULT;
78467 *lenp = len;
78468 *ppos += len;
78469 @@ -150,63 +150,63 @@ static ctl_table svcrdma_parm_table[] =
78470 {
78471 .procname = "rdma_stat_read",
78472 .data = &rdma_stat_read,
78473 - .maxlen = sizeof(atomic_t),
78474 + .maxlen = sizeof(atomic_unchecked_t),
78475 .mode = 0644,
78476 .proc_handler = read_reset_stat,
78477 },
78478 {
78479 .procname = "rdma_stat_recv",
78480 .data = &rdma_stat_recv,
78481 - .maxlen = sizeof(atomic_t),
78482 + .maxlen = sizeof(atomic_unchecked_t),
78483 .mode = 0644,
78484 .proc_handler = read_reset_stat,
78485 },
78486 {
78487 .procname = "rdma_stat_write",
78488 .data = &rdma_stat_write,
78489 - .maxlen = sizeof(atomic_t),
78490 + .maxlen = sizeof(atomic_unchecked_t),
78491 .mode = 0644,
78492 .proc_handler = read_reset_stat,
78493 },
78494 {
78495 .procname = "rdma_stat_sq_starve",
78496 .data = &rdma_stat_sq_starve,
78497 - .maxlen = sizeof(atomic_t),
78498 + .maxlen = sizeof(atomic_unchecked_t),
78499 .mode = 0644,
78500 .proc_handler = read_reset_stat,
78501 },
78502 {
78503 .procname = "rdma_stat_rq_starve",
78504 .data = &rdma_stat_rq_starve,
78505 - .maxlen = sizeof(atomic_t),
78506 + .maxlen = sizeof(atomic_unchecked_t),
78507 .mode = 0644,
78508 .proc_handler = read_reset_stat,
78509 },
78510 {
78511 .procname = "rdma_stat_rq_poll",
78512 .data = &rdma_stat_rq_poll,
78513 - .maxlen = sizeof(atomic_t),
78514 + .maxlen = sizeof(atomic_unchecked_t),
78515 .mode = 0644,
78516 .proc_handler = read_reset_stat,
78517 },
78518 {
78519 .procname = "rdma_stat_rq_prod",
78520 .data = &rdma_stat_rq_prod,
78521 - .maxlen = sizeof(atomic_t),
78522 + .maxlen = sizeof(atomic_unchecked_t),
78523 .mode = 0644,
78524 .proc_handler = read_reset_stat,
78525 },
78526 {
78527 .procname = "rdma_stat_sq_poll",
78528 .data = &rdma_stat_sq_poll,
78529 - .maxlen = sizeof(atomic_t),
78530 + .maxlen = sizeof(atomic_unchecked_t),
78531 .mode = 0644,
78532 .proc_handler = read_reset_stat,
78533 },
78534 {
78535 .procname = "rdma_stat_sq_prod",
78536 .data = &rdma_stat_sq_prod,
78537 - .maxlen = sizeof(atomic_t),
78538 + .maxlen = sizeof(atomic_unchecked_t),
78539 .mode = 0644,
78540 .proc_handler = read_reset_stat,
78541 },
78542 diff -urNp linux-2.6.39/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c linux-2.6.39/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
78543 --- linux-2.6.39/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c 2011-05-19 00:06:34.000000000 -0400
78544 +++ linux-2.6.39/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c 2011-05-22 19:36:35.000000000 -0400
78545 @@ -499,7 +499,7 @@ next_sge:
78546 svc_rdma_put_context(ctxt, 0);
78547 goto out;
78548 }
78549 - atomic_inc(&rdma_stat_read);
78550 + atomic_inc_unchecked(&rdma_stat_read);
78551
78552 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
78553 chl_map->ch[ch_no].count -= read_wr.num_sge;
78554 @@ -609,7 +609,7 @@ int svc_rdma_recvfrom(struct svc_rqst *r
78555 dto_q);
78556 list_del_init(&ctxt->dto_q);
78557 } else {
78558 - atomic_inc(&rdma_stat_rq_starve);
78559 + atomic_inc_unchecked(&rdma_stat_rq_starve);
78560 clear_bit(XPT_DATA, &xprt->xpt_flags);
78561 ctxt = NULL;
78562 }
78563 @@ -629,7 +629,7 @@ int svc_rdma_recvfrom(struct svc_rqst *r
78564 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
78565 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
78566 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
78567 - atomic_inc(&rdma_stat_recv);
78568 + atomic_inc_unchecked(&rdma_stat_recv);
78569
78570 /* Build up the XDR from the receive buffers. */
78571 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
78572 diff -urNp linux-2.6.39/net/sunrpc/xprtrdma/svc_rdma_sendto.c linux-2.6.39/net/sunrpc/xprtrdma/svc_rdma_sendto.c
78573 --- linux-2.6.39/net/sunrpc/xprtrdma/svc_rdma_sendto.c 2011-05-19 00:06:34.000000000 -0400
78574 +++ linux-2.6.39/net/sunrpc/xprtrdma/svc_rdma_sendto.c 2011-05-22 19:36:35.000000000 -0400
78575 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdm
78576 write_wr.wr.rdma.remote_addr = to;
78577
78578 /* Post It */
78579 - atomic_inc(&rdma_stat_write);
78580 + atomic_inc_unchecked(&rdma_stat_write);
78581 if (svc_rdma_send(xprt, &write_wr))
78582 goto err;
78583 return 0;
78584 diff -urNp linux-2.6.39/net/sunrpc/xprtrdma/svc_rdma_transport.c linux-2.6.39/net/sunrpc/xprtrdma/svc_rdma_transport.c
78585 --- linux-2.6.39/net/sunrpc/xprtrdma/svc_rdma_transport.c 2011-05-19 00:06:34.000000000 -0400
78586 +++ linux-2.6.39/net/sunrpc/xprtrdma/svc_rdma_transport.c 2011-05-22 19:36:35.000000000 -0400
78587 @@ -298,7 +298,7 @@ static void rq_cq_reap(struct svcxprt_rd
78588 return;
78589
78590 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
78591 - atomic_inc(&rdma_stat_rq_poll);
78592 + atomic_inc_unchecked(&rdma_stat_rq_poll);
78593
78594 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
78595 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
78596 @@ -320,7 +320,7 @@ static void rq_cq_reap(struct svcxprt_rd
78597 }
78598
78599 if (ctxt)
78600 - atomic_inc(&rdma_stat_rq_prod);
78601 + atomic_inc_unchecked(&rdma_stat_rq_prod);
78602
78603 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
78604 /*
78605 @@ -392,7 +392,7 @@ static void sq_cq_reap(struct svcxprt_rd
78606 return;
78607
78608 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
78609 - atomic_inc(&rdma_stat_sq_poll);
78610 + atomic_inc_unchecked(&rdma_stat_sq_poll);
78611 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
78612 if (wc.status != IB_WC_SUCCESS)
78613 /* Close the transport */
78614 @@ -410,7 +410,7 @@ static void sq_cq_reap(struct svcxprt_rd
78615 }
78616
78617 if (ctxt)
78618 - atomic_inc(&rdma_stat_sq_prod);
78619 + atomic_inc_unchecked(&rdma_stat_sq_prod);
78620 }
78621
78622 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
78623 @@ -1271,7 +1271,7 @@ int svc_rdma_send(struct svcxprt_rdma *x
78624 spin_lock_bh(&xprt->sc_lock);
78625 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
78626 spin_unlock_bh(&xprt->sc_lock);
78627 - atomic_inc(&rdma_stat_sq_starve);
78628 + atomic_inc_unchecked(&rdma_stat_sq_starve);
78629
78630 /* See if we can opportunistically reap SQ WR to make room */
78631 sq_cq_reap(xprt);
78632 diff -urNp linux-2.6.39/net/sysctl_net.c linux-2.6.39/net/sysctl_net.c
78633 --- linux-2.6.39/net/sysctl_net.c 2011-05-19 00:06:34.000000000 -0400
78634 +++ linux-2.6.39/net/sysctl_net.c 2011-05-22 19:41:42.000000000 -0400
78635 @@ -46,7 +46,7 @@ static int net_ctl_permissions(struct ct
78636 struct ctl_table *table)
78637 {
78638 /* Allow network administrator to have same access as root. */
78639 - if (capable(CAP_NET_ADMIN)) {
78640 + if (capable_nolog(CAP_NET_ADMIN)) {
78641 int mode = (table->mode >> 6) & 7;
78642 return (mode << 6) | (mode << 3) | mode;
78643 }
78644 diff -urNp linux-2.6.39/net/unix/af_unix.c linux-2.6.39/net/unix/af_unix.c
78645 --- linux-2.6.39/net/unix/af_unix.c 2011-05-19 00:06:34.000000000 -0400
78646 +++ linux-2.6.39/net/unix/af_unix.c 2011-05-22 19:41:42.000000000 -0400
78647 @@ -767,6 +767,12 @@ static struct sock *unix_find_other(stru
78648 err = -ECONNREFUSED;
78649 if (!S_ISSOCK(inode->i_mode))
78650 goto put_fail;
78651 +
78652 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
78653 + err = -EACCES;
78654 + goto put_fail;
78655 + }
78656 +
78657 u = unix_find_socket_byinode(inode);
78658 if (!u)
78659 goto put_fail;
78660 @@ -787,6 +793,13 @@ static struct sock *unix_find_other(stru
78661 if (u) {
78662 struct dentry *dentry;
78663 dentry = unix_sk(u)->dentry;
78664 +
78665 + if (!gr_handle_chroot_unix(u->sk_peer_pid)) {
78666 + err = -EPERM;
78667 + sock_put(u);
78668 + goto fail;
78669 + }
78670 +
78671 if (dentry)
78672 touch_atime(unix_sk(u)->mnt, dentry);
78673 } else
78674 @@ -872,11 +885,18 @@ static int unix_bind(struct socket *sock
78675 err = security_path_mknod(&nd.path, dentry, mode, 0);
78676 if (err)
78677 goto out_mknod_drop_write;
78678 + if (!gr_acl_handle_mknod(dentry, nd.path.dentry, nd.path.mnt, mode)) {
78679 + err = -EACCES;
78680 + goto out_mknod_drop_write;
78681 + }
78682 err = vfs_mknod(nd.path.dentry->d_inode, dentry, mode, 0);
78683 out_mknod_drop_write:
78684 mnt_drop_write(nd.path.mnt);
78685 if (err)
78686 goto out_mknod_dput;
78687 +
78688 + gr_handle_create(dentry, nd.path.mnt);
78689 +
78690 mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
78691 dput(nd.path.dentry);
78692 nd.path.dentry = dentry;
78693 @@ -894,6 +914,11 @@ out_mknod_drop_write:
78694 goto out_unlock;
78695 }
78696
78697 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
78698 + put_pid(sk->sk_peer_pid);
78699 + sk->sk_peer_pid = get_pid(task_tgid(current));
78700 +#endif
78701 +
78702 list = &unix_socket_table[addr->hash];
78703 } else {
78704 list = &unix_socket_table[dentry->d_inode->i_ino & (UNIX_HASH_SIZE-1)];
78705 @@ -2255,7 +2280,11 @@ static int unix_seq_show(struct seq_file
78706 unix_state_lock(s);
78707
78708 seq_printf(seq, "%p: %08X %08X %08X %04X %02X %5lu",
78709 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78710 + NULL,
78711 +#else
78712 s,
78713 +#endif
78714 atomic_read(&s->sk_refcnt),
78715 0,
78716 s->sk_state == TCP_LISTEN ? __SO_ACCEPTCON : 0,
78717 diff -urNp linux-2.6.39/net/wireless/wext-core.c linux-2.6.39/net/wireless/wext-core.c
78718 --- linux-2.6.39/net/wireless/wext-core.c 2011-05-19 00:06:34.000000000 -0400
78719 +++ linux-2.6.39/net/wireless/wext-core.c 2011-05-22 19:36:35.000000000 -0400
78720 @@ -746,8 +746,7 @@ static int ioctl_standard_iw_point(struc
78721 */
78722
78723 /* Support for very large requests */
78724 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
78725 - (user_length > descr->max_tokens)) {
78726 + if (user_length > descr->max_tokens) {
78727 /* Allow userspace to GET more than max so
78728 * we can support any size GET requests.
78729 * There is still a limit : -ENOMEM.
78730 @@ -784,22 +783,6 @@ static int ioctl_standard_iw_point(struc
78731 }
78732 }
78733
78734 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
78735 - /*
78736 - * If this is a GET, but not NOMAX, it means that the extra
78737 - * data is not bounded by userspace, but by max_tokens. Thus
78738 - * set the length to max_tokens. This matches the extra data
78739 - * allocation.
78740 - * The driver should fill it with the number of tokens it
78741 - * provided, and it may check iwp->length rather than having
78742 - * knowledge of max_tokens. If the driver doesn't change the
78743 - * iwp->length, this ioctl just copies back max_token tokens
78744 - * filled with zeroes. Hopefully the driver isn't claiming
78745 - * them to be valid data.
78746 - */
78747 - iwp->length = descr->max_tokens;
78748 - }
78749 -
78750 err = handler(dev, info, (union iwreq_data *) iwp, extra);
78751
78752 iwp->length += essid_compat;
78753 diff -urNp linux-2.6.39/net/xfrm/xfrm_policy.c linux-2.6.39/net/xfrm/xfrm_policy.c
78754 --- linux-2.6.39/net/xfrm/xfrm_policy.c 2011-05-19 00:06:34.000000000 -0400
78755 +++ linux-2.6.39/net/xfrm/xfrm_policy.c 2011-05-22 19:36:35.000000000 -0400
78756 @@ -299,7 +299,7 @@ static void xfrm_policy_kill(struct xfrm
78757 {
78758 policy->walk.dead = 1;
78759
78760 - atomic_inc(&policy->genid);
78761 + atomic_inc_unchecked(&policy->genid);
78762
78763 if (del_timer(&policy->timer))
78764 xfrm_pol_put(policy);
78765 @@ -583,7 +583,7 @@ int xfrm_policy_insert(int dir, struct x
78766 hlist_add_head(&policy->bydst, chain);
78767 xfrm_pol_hold(policy);
78768 net->xfrm.policy_count[dir]++;
78769 - atomic_inc(&flow_cache_genid);
78770 + atomic_inc_unchecked(&flow_cache_genid);
78771 if (delpol)
78772 __xfrm_policy_unlink(delpol, dir);
78773 policy->index = delpol ? delpol->index : xfrm_gen_index(net, dir);
78774 @@ -1527,7 +1527,7 @@ free_dst:
78775 goto out;
78776 }
78777
78778 -static int inline
78779 +static inline int
78780 xfrm_dst_alloc_copy(void **target, const void *src, int size)
78781 {
78782 if (!*target) {
78783 @@ -1539,7 +1539,7 @@ xfrm_dst_alloc_copy(void **target, const
78784 return 0;
78785 }
78786
78787 -static int inline
78788 +static inline int
78789 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
78790 {
78791 #ifdef CONFIG_XFRM_SUB_POLICY
78792 @@ -1551,7 +1551,7 @@ xfrm_dst_update_parent(struct dst_entry
78793 #endif
78794 }
78795
78796 -static int inline
78797 +static inline int
78798 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
78799 {
78800 #ifdef CONFIG_XFRM_SUB_POLICY
78801 @@ -1645,7 +1645,7 @@ xfrm_resolve_and_create_bundle(struct xf
78802
78803 xdst->num_pols = num_pols;
78804 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
78805 - xdst->policy_genid = atomic_read(&pols[0]->genid);
78806 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
78807
78808 return xdst;
78809 }
78810 @@ -2332,7 +2332,7 @@ static int xfrm_bundle_ok(struct xfrm_ds
78811 if (xdst->xfrm_genid != dst->xfrm->genid)
78812 return 0;
78813 if (xdst->num_pols > 0 &&
78814 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
78815 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
78816 return 0;
78817
78818 mtu = dst_mtu(dst->child);
78819 @@ -2860,7 +2860,7 @@ static int xfrm_policy_migrate(struct xf
78820 sizeof(pol->xfrm_vec[i].saddr));
78821 pol->xfrm_vec[i].encap_family = mp->new_family;
78822 /* flush bundles */
78823 - atomic_inc(&pol->genid);
78824 + atomic_inc_unchecked(&pol->genid);
78825 }
78826 }
78827
78828 diff -urNp linux-2.6.39/net/xfrm/xfrm_user.c linux-2.6.39/net/xfrm/xfrm_user.c
78829 --- linux-2.6.39/net/xfrm/xfrm_user.c 2011-05-19 00:06:34.000000000 -0400
78830 +++ linux-2.6.39/net/xfrm/xfrm_user.c 2011-05-22 19:36:35.000000000 -0400
78831 @@ -1394,6 +1394,8 @@ static int copy_to_user_tmpl(struct xfrm
78832 struct xfrm_user_tmpl vec[XFRM_MAX_DEPTH];
78833 int i;
78834
78835 + pax_track_stack();
78836 +
78837 if (xp->xfrm_nr == 0)
78838 return 0;
78839
78840 @@ -2062,6 +2064,8 @@ static int xfrm_do_migrate(struct sk_buf
78841 int err;
78842 int n = 0;
78843
78844 + pax_track_stack();
78845 +
78846 if (attrs[XFRMA_MIGRATE] == NULL)
78847 return -EINVAL;
78848
78849 diff -urNp linux-2.6.39/scripts/basic/fixdep.c linux-2.6.39/scripts/basic/fixdep.c
78850 --- linux-2.6.39/scripts/basic/fixdep.c 2011-05-19 00:06:34.000000000 -0400
78851 +++ linux-2.6.39/scripts/basic/fixdep.c 2011-05-22 19:36:35.000000000 -0400
78852 @@ -235,9 +235,9 @@ static void use_config(const char *m, in
78853
78854 static void parse_config_file(const char *map, size_t len)
78855 {
78856 - const int *end = (const int *) (map + len);
78857 + const unsigned int *end = (const unsigned int *) (map + len);
78858 /* start at +1, so that p can never be < map */
78859 - const int *m = (const int *) map + 1;
78860 + const unsigned int *m = (const unsigned int *) map + 1;
78861 const char *p, *q;
78862
78863 for (; m < end; m++) {
78864 @@ -405,7 +405,7 @@ static void print_deps(void)
78865 static void traps(void)
78866 {
78867 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
78868 - int *p = (int *)test;
78869 + unsigned int *p = (unsigned int *)test;
78870
78871 if (*p != INT_CONF) {
78872 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
78873 diff -urNp linux-2.6.39/scripts/dtc/flattree.c linux-2.6.39/scripts/dtc/flattree.c
78874 --- linux-2.6.39/scripts/dtc/flattree.c 2011-05-19 00:06:34.000000000 -0400
78875 +++ linux-2.6.39/scripts/dtc/flattree.c 2011-05-22 19:36:35.000000000 -0400
78876 @@ -104,7 +104,7 @@ static void bin_emit_property(void *e, s
78877 bin_emit_cell(e, FDT_PROP);
78878 }
78879
78880 -static struct emitter bin_emitter = {
78881 +static const struct emitter bin_emitter = {
78882 .cell = bin_emit_cell,
78883 .string = bin_emit_string,
78884 .align = bin_emit_align,
78885 @@ -230,7 +230,7 @@ static void asm_emit_property(void *e, s
78886 asm_emit_cell(e, FDT_PROP);
78887 }
78888
78889 -static struct emitter asm_emitter = {
78890 +static const struct emitter asm_emitter = {
78891 .cell = asm_emit_cell,
78892 .string = asm_emit_string,
78893 .align = asm_emit_align,
78894 diff -urNp linux-2.6.39/scripts/mod/file2alias.c linux-2.6.39/scripts/mod/file2alias.c
78895 --- linux-2.6.39/scripts/mod/file2alias.c 2011-05-19 00:06:34.000000000 -0400
78896 +++ linux-2.6.39/scripts/mod/file2alias.c 2011-05-22 19:36:35.000000000 -0400
78897 @@ -72,7 +72,7 @@ static void device_id_check(const char *
78898 unsigned long size, unsigned long id_size,
78899 void *symval)
78900 {
78901 - int i;
78902 + unsigned int i;
78903
78904 if (size % id_size || size < id_size) {
78905 if (cross_build != 0)
78906 @@ -102,7 +102,7 @@ static void device_id_check(const char *
78907 /* USB is special because the bcdDevice can be matched against a numeric range */
78908 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipN" */
78909 static void do_usb_entry(struct usb_device_id *id,
78910 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
78911 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
78912 unsigned char range_lo, unsigned char range_hi,
78913 unsigned char max, struct module *mod)
78914 {
78915 @@ -437,7 +437,7 @@ static void do_pnp_device_entry(void *sy
78916 for (i = 0; i < count; i++) {
78917 const char *id = (char *)devs[i].id;
78918 char acpi_id[sizeof(devs[0].id)];
78919 - int j;
78920 + unsigned int j;
78921
78922 buf_printf(&mod->dev_table_buf,
78923 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
78924 @@ -467,7 +467,7 @@ static void do_pnp_card_entries(void *sy
78925
78926 for (j = 0; j < PNP_MAX_DEVICES; j++) {
78927 const char *id = (char *)card->devs[j].id;
78928 - int i2, j2;
78929 + unsigned int i2, j2;
78930 int dup = 0;
78931
78932 if (!id[0])
78933 @@ -493,7 +493,7 @@ static void do_pnp_card_entries(void *sy
78934 /* add an individual alias for every device entry */
78935 if (!dup) {
78936 char acpi_id[sizeof(card->devs[0].id)];
78937 - int k;
78938 + unsigned int k;
78939
78940 buf_printf(&mod->dev_table_buf,
78941 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
78942 @@ -768,7 +768,7 @@ static void dmi_ascii_filter(char *d, co
78943 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
78944 char *alias)
78945 {
78946 - int i, j;
78947 + unsigned int i, j;
78948
78949 sprintf(alias, "dmi*");
78950
78951 diff -urNp linux-2.6.39/scripts/mod/modpost.c linux-2.6.39/scripts/mod/modpost.c
78952 --- linux-2.6.39/scripts/mod/modpost.c 2011-05-19 00:06:34.000000000 -0400
78953 +++ linux-2.6.39/scripts/mod/modpost.c 2011-05-22 19:36:35.000000000 -0400
78954 @@ -896,6 +896,7 @@ enum mismatch {
78955 ANY_INIT_TO_ANY_EXIT,
78956 ANY_EXIT_TO_ANY_INIT,
78957 EXPORT_TO_INIT_EXIT,
78958 + DATA_TO_TEXT
78959 };
78960
78961 struct sectioncheck {
78962 @@ -1004,6 +1005,12 @@ const struct sectioncheck sectioncheck[]
78963 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
78964 .mismatch = EXPORT_TO_INIT_EXIT,
78965 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
78966 +},
78967 +/* Do not reference code from writable data */
78968 +{
78969 + .fromsec = { DATA_SECTIONS, NULL },
78970 + .tosec = { TEXT_SECTIONS, NULL },
78971 + .mismatch = DATA_TO_TEXT
78972 }
78973 };
78974
78975 @@ -1126,10 +1133,10 @@ static Elf_Sym *find_elf_symbol(struct e
78976 continue;
78977 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
78978 continue;
78979 - if (sym->st_value == addr)
78980 - return sym;
78981 /* Find a symbol nearby - addr are maybe negative */
78982 d = sym->st_value - addr;
78983 + if (d == 0)
78984 + return sym;
78985 if (d < 0)
78986 d = addr - sym->st_value;
78987 if (d < distance) {
78988 @@ -1408,6 +1415,14 @@ static void report_sec_mismatch(const ch
78989 tosym, prl_to, prl_to, tosym);
78990 free(prl_to);
78991 break;
78992 + case DATA_TO_TEXT:
78993 +/*
78994 + fprintf(stderr,
78995 + "The variable %s references\n"
78996 + "the %s %s%s%s\n",
78997 + fromsym, to, sec2annotation(tosec), tosym, to_p);
78998 +*/
78999 + break;
79000 }
79001 fprintf(stderr, "\n");
79002 }
79003 @@ -1731,7 +1746,7 @@ void __attribute__((format(printf, 2, 3)
79004 va_end(ap);
79005 }
79006
79007 -void buf_write(struct buffer *buf, const char *s, int len)
79008 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
79009 {
79010 if (buf->size - buf->pos < len) {
79011 buf->size += len + SZ;
79012 @@ -1943,7 +1958,7 @@ static void write_if_changed(struct buff
79013 if (fstat(fileno(file), &st) < 0)
79014 goto close_write;
79015
79016 - if (st.st_size != b->pos)
79017 + if (st.st_size != (off_t)b->pos)
79018 goto close_write;
79019
79020 tmp = NOFAIL(malloc(b->pos));
79021 diff -urNp linux-2.6.39/scripts/mod/modpost.h linux-2.6.39/scripts/mod/modpost.h
79022 --- linux-2.6.39/scripts/mod/modpost.h 2011-05-19 00:06:34.000000000 -0400
79023 +++ linux-2.6.39/scripts/mod/modpost.h 2011-05-22 19:36:35.000000000 -0400
79024 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *e
79025
79026 struct buffer {
79027 char *p;
79028 - int pos;
79029 - int size;
79030 + unsigned int pos;
79031 + unsigned int size;
79032 };
79033
79034 void __attribute__((format(printf, 2, 3)))
79035 buf_printf(struct buffer *buf, const char *fmt, ...);
79036
79037 void
79038 -buf_write(struct buffer *buf, const char *s, int len);
79039 +buf_write(struct buffer *buf, const char *s, unsigned int len);
79040
79041 struct module {
79042 struct module *next;
79043 diff -urNp linux-2.6.39/scripts/mod/sumversion.c linux-2.6.39/scripts/mod/sumversion.c
79044 --- linux-2.6.39/scripts/mod/sumversion.c 2011-05-19 00:06:34.000000000 -0400
79045 +++ linux-2.6.39/scripts/mod/sumversion.c 2011-05-22 19:36:35.000000000 -0400
79046 @@ -470,7 +470,7 @@ static void write_version(const char *fi
79047 goto out;
79048 }
79049
79050 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
79051 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
79052 warn("writing sum in %s failed: %s\n",
79053 filename, strerror(errno));
79054 goto out;
79055 diff -urNp linux-2.6.39/scripts/pnmtologo.c linux-2.6.39/scripts/pnmtologo.c
79056 --- linux-2.6.39/scripts/pnmtologo.c 2011-05-19 00:06:34.000000000 -0400
79057 +++ linux-2.6.39/scripts/pnmtologo.c 2011-05-22 19:36:35.000000000 -0400
79058 @@ -237,14 +237,14 @@ static void write_header(void)
79059 fprintf(out, " * Linux logo %s\n", logoname);
79060 fputs(" */\n\n", out);
79061 fputs("#include <linux/linux_logo.h>\n\n", out);
79062 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
79063 + fprintf(out, "static unsigned char %s_data[] = {\n",
79064 logoname);
79065 }
79066
79067 static void write_footer(void)
79068 {
79069 fputs("\n};\n\n", out);
79070 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
79071 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
79072 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
79073 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
79074 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
79075 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
79076 fputs("\n};\n\n", out);
79077
79078 /* write logo clut */
79079 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
79080 + fprintf(out, "static unsigned char %s_clut[] = {\n",
79081 logoname);
79082 write_hex_cnt = 0;
79083 for (i = 0; i < logo_clutsize; i++) {
79084 diff -urNp linux-2.6.39/security/apparmor/lsm.c linux-2.6.39/security/apparmor/lsm.c
79085 --- linux-2.6.39/security/apparmor/lsm.c 2011-05-19 00:06:34.000000000 -0400
79086 +++ linux-2.6.39/security/apparmor/lsm.c 2011-05-22 19:41:42.000000000 -0400
79087 @@ -620,7 +620,7 @@ static int apparmor_task_setrlimit(struc
79088 return error;
79089 }
79090
79091 -static struct security_operations apparmor_ops = {
79092 +static struct security_operations apparmor_ops __read_only = {
79093 .name = "apparmor",
79094
79095 .ptrace_access_check = apparmor_ptrace_access_check,
79096 @@ -671,7 +671,7 @@ static struct security_operations apparm
79097 static int param_set_aabool(const char *val, const struct kernel_param *kp);
79098 static int param_get_aabool(char *buffer, const struct kernel_param *kp);
79099 #define param_check_aabool(name, p) __param_check(name, p, int)
79100 -static struct kernel_param_ops param_ops_aabool = {
79101 +static const struct kernel_param_ops param_ops_aabool = {
79102 .set = param_set_aabool,
79103 .get = param_get_aabool
79104 };
79105 @@ -679,7 +679,7 @@ static struct kernel_param_ops param_ops
79106 static int param_set_aauint(const char *val, const struct kernel_param *kp);
79107 static int param_get_aauint(char *buffer, const struct kernel_param *kp);
79108 #define param_check_aauint(name, p) __param_check(name, p, int)
79109 -static struct kernel_param_ops param_ops_aauint = {
79110 +static const struct kernel_param_ops param_ops_aauint = {
79111 .set = param_set_aauint,
79112 .get = param_get_aauint
79113 };
79114 @@ -687,7 +687,7 @@ static struct kernel_param_ops param_ops
79115 static int param_set_aalockpolicy(const char *val, const struct kernel_param *kp);
79116 static int param_get_aalockpolicy(char *buffer, const struct kernel_param *kp);
79117 #define param_check_aalockpolicy(name, p) __param_check(name, p, int)
79118 -static struct kernel_param_ops param_ops_aalockpolicy = {
79119 +static const struct kernel_param_ops param_ops_aalockpolicy = {
79120 .set = param_set_aalockpolicy,
79121 .get = param_get_aalockpolicy
79122 };
79123 diff -urNp linux-2.6.39/security/commoncap.c linux-2.6.39/security/commoncap.c
79124 --- linux-2.6.39/security/commoncap.c 2011-05-19 00:06:34.000000000 -0400
79125 +++ linux-2.6.39/security/commoncap.c 2011-05-22 20:28:59.000000000 -0400
79126 @@ -28,6 +28,7 @@
79127 #include <linux/prctl.h>
79128 #include <linux/securebits.h>
79129 #include <linux/user_namespace.h>
79130 +#include <net/sock.h>
79131
79132 /*
79133 * If a non-root user executes a setuid-root binary in
79134 @@ -58,7 +59,7 @@ int cap_netlink_send(struct sock *sk, st
79135
79136 int cap_netlink_recv(struct sk_buff *skb, int cap)
79137 {
79138 - if (!cap_raised(current_cap(), cap))
79139 + if (!cap_raised(current_cap(), cap) || !gr_is_capable(cap))
79140 return -EPERM;
79141 return 0;
79142 }
79143 @@ -580,6 +581,9 @@ int cap_bprm_secureexec(struct linux_bin
79144 {
79145 const struct cred *cred = current_cred();
79146
79147 + if (gr_acl_enable_at_secure())
79148 + return 1;
79149 +
79150 if (cred->uid != 0) {
79151 if (bprm->cap_effective)
79152 return 1;
79153 diff -urNp linux-2.6.39/security/integrity/ima/ima_api.c linux-2.6.39/security/integrity/ima/ima_api.c
79154 --- linux-2.6.39/security/integrity/ima/ima_api.c 2011-05-19 00:06:34.000000000 -0400
79155 +++ linux-2.6.39/security/integrity/ima/ima_api.c 2011-05-22 19:36:35.000000000 -0400
79156 @@ -75,7 +75,7 @@ void ima_add_violation(struct inode *ino
79157 int result;
79158
79159 /* can overflow, only indicator */
79160 - atomic_long_inc(&ima_htable.violations);
79161 + atomic_long_inc_unchecked(&ima_htable.violations);
79162
79163 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
79164 if (!entry) {
79165 diff -urNp linux-2.6.39/security/integrity/ima/ima_fs.c linux-2.6.39/security/integrity/ima/ima_fs.c
79166 --- linux-2.6.39/security/integrity/ima/ima_fs.c 2011-05-19 00:06:34.000000000 -0400
79167 +++ linux-2.6.39/security/integrity/ima/ima_fs.c 2011-05-22 19:36:35.000000000 -0400
79168 @@ -28,12 +28,12 @@
79169 static int valid_policy = 1;
79170 #define TMPBUFLEN 12
79171 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
79172 - loff_t *ppos, atomic_long_t *val)
79173 + loff_t *ppos, atomic_long_unchecked_t *val)
79174 {
79175 char tmpbuf[TMPBUFLEN];
79176 ssize_t len;
79177
79178 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
79179 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
79180 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
79181 }
79182
79183 diff -urNp linux-2.6.39/security/integrity/ima/ima.h linux-2.6.39/security/integrity/ima/ima.h
79184 --- linux-2.6.39/security/integrity/ima/ima.h 2011-05-19 00:06:34.000000000 -0400
79185 +++ linux-2.6.39/security/integrity/ima/ima.h 2011-05-22 19:36:35.000000000 -0400
79186 @@ -85,8 +85,8 @@ void ima_add_violation(struct inode *ino
79187 extern spinlock_t ima_queue_lock;
79188
79189 struct ima_h_table {
79190 - atomic_long_t len; /* number of stored measurements in the list */
79191 - atomic_long_t violations;
79192 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
79193 + atomic_long_unchecked_t violations;
79194 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
79195 };
79196 extern struct ima_h_table ima_htable;
79197 diff -urNp linux-2.6.39/security/integrity/ima/ima_queue.c linux-2.6.39/security/integrity/ima/ima_queue.c
79198 --- linux-2.6.39/security/integrity/ima/ima_queue.c 2011-05-19 00:06:34.000000000 -0400
79199 +++ linux-2.6.39/security/integrity/ima/ima_queue.c 2011-05-22 19:36:35.000000000 -0400
79200 @@ -79,7 +79,7 @@ static int ima_add_digest_entry(struct i
79201 INIT_LIST_HEAD(&qe->later);
79202 list_add_tail_rcu(&qe->later, &ima_measurements);
79203
79204 - atomic_long_inc(&ima_htable.len);
79205 + atomic_long_inc_unchecked(&ima_htable.len);
79206 key = ima_hash_key(entry->digest);
79207 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
79208 return 0;
79209 diff -urNp linux-2.6.39/security/Kconfig linux-2.6.39/security/Kconfig
79210 --- linux-2.6.39/security/Kconfig 2011-05-19 00:06:34.000000000 -0400
79211 +++ linux-2.6.39/security/Kconfig 2011-05-22 19:41:42.000000000 -0400
79212 @@ -4,6 +4,548 @@
79213
79214 menu "Security options"
79215
79216 +source grsecurity/Kconfig
79217 +
79218 +menu "PaX"
79219 +
79220 + config ARCH_TRACK_EXEC_LIMIT
79221 + bool
79222 +
79223 + config PAX_PER_CPU_PGD
79224 + bool
79225 +
79226 + config TASK_SIZE_MAX_SHIFT
79227 + int
79228 + depends on X86_64
79229 + default 47 if !PAX_PER_CPU_PGD
79230 + default 42 if PAX_PER_CPU_PGD
79231 +
79232 + config PAX_ENABLE_PAE
79233 + bool
79234 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
79235 +
79236 +config PAX
79237 + bool "Enable various PaX features"
79238 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
79239 + help
79240 + This allows you to enable various PaX features. PaX adds
79241 + intrusion prevention mechanisms to the kernel that reduce
79242 + the risks posed by exploitable memory corruption bugs.
79243 +
79244 +menu "PaX Control"
79245 + depends on PAX
79246 +
79247 +config PAX_SOFTMODE
79248 + bool 'Support soft mode'
79249 + select PAX_PT_PAX_FLAGS
79250 + help
79251 + Enabling this option will allow you to run PaX in soft mode, that
79252 + is, PaX features will not be enforced by default, only on executables
79253 + marked explicitly. You must also enable PT_PAX_FLAGS support as it
79254 + is the only way to mark executables for soft mode use.
79255 +
79256 + Soft mode can be activated by using the "pax_softmode=1" kernel command
79257 + line option on boot. Furthermore you can control various PaX features
79258 + at runtime via the entries in /proc/sys/kernel/pax.
79259 +
79260 +config PAX_EI_PAX
79261 + bool 'Use legacy ELF header marking'
79262 + help
79263 + Enabling this option will allow you to control PaX features on
79264 + a per executable basis via the 'chpax' utility available at
79265 + http://pax.grsecurity.net/. The control flags will be read from
79266 + an otherwise reserved part of the ELF header. This marking has
79267 + numerous drawbacks (no support for soft-mode, toolchain does not
79268 + know about the non-standard use of the ELF header) therefore it
79269 + has been deprecated in favour of PT_PAX_FLAGS support.
79270 +
79271 + Note that if you enable PT_PAX_FLAGS marking support as well,
79272 + the PT_PAX_FLAG marks will override the legacy EI_PAX marks.
79273 +
79274 +config PAX_PT_PAX_FLAGS
79275 + bool 'Use ELF program header marking'
79276 + help
79277 + Enabling this option will allow you to control PaX features on
79278 + a per executable basis via the 'paxctl' utility available at
79279 + http://pax.grsecurity.net/. The control flags will be read from
79280 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
79281 + has the benefits of supporting both soft mode and being fully
79282 + integrated into the toolchain (the binutils patch is available
79283 + from http://pax.grsecurity.net).
79284 +
79285 + If your toolchain does not support PT_PAX_FLAGS markings,
79286 + you can create one in most cases with 'paxctl -C'.
79287 +
79288 + Note that if you enable the legacy EI_PAX marking support as well,
79289 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
79290 +
79291 +choice
79292 + prompt 'MAC system integration'
79293 + default PAX_HAVE_ACL_FLAGS
79294 + help
79295 + Mandatory Access Control systems have the option of controlling
79296 + PaX flags on a per executable basis, choose the method supported
79297 + by your particular system.
79298 +
79299 + - "none": if your MAC system does not interact with PaX,
79300 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
79301 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
79302 +
79303 + NOTE: this option is for developers/integrators only.
79304 +
79305 + config PAX_NO_ACL_FLAGS
79306 + bool 'none'
79307 +
79308 + config PAX_HAVE_ACL_FLAGS
79309 + bool 'direct'
79310 +
79311 + config PAX_HOOK_ACL_FLAGS
79312 + bool 'hook'
79313 +endchoice
79314 +
79315 +endmenu
79316 +
79317 +menu "Non-executable pages"
79318 + depends on PAX
79319 +
79320 +config PAX_NOEXEC
79321 + bool "Enforce non-executable pages"
79322 + 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)
79323 + help
79324 + By design some architectures do not allow for protecting memory
79325 + pages against execution or even if they do, Linux does not make
79326 + use of this feature. In practice this means that if a page is
79327 + readable (such as the stack or heap) it is also executable.
79328 +
79329 + There is a well known exploit technique that makes use of this
79330 + fact and a common programming mistake where an attacker can
79331 + introduce code of his choice somewhere in the attacked program's
79332 + memory (typically the stack or the heap) and then execute it.
79333 +
79334 + If the attacked program was running with different (typically
79335 + higher) privileges than that of the attacker, then he can elevate
79336 + his own privilege level (e.g. get a root shell, write to files for
79337 + which he does not have write access to, etc).
79338 +
79339 + Enabling this option will let you choose from various features
79340 + that prevent the injection and execution of 'foreign' code in
79341 + a program.
79342 +
79343 + This will also break programs that rely on the old behaviour and
79344 + expect that dynamically allocated memory via the malloc() family
79345 + of functions is executable (which it is not). Notable examples
79346 + are the XFree86 4.x server, the java runtime and wine.
79347 +
79348 +config PAX_PAGEEXEC
79349 + bool "Paging based non-executable pages"
79350 + 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)
79351 + select S390_SWITCH_AMODE if S390
79352 + select S390_EXEC_PROTECT if S390
79353 + select ARCH_TRACK_EXEC_LIMIT if X86_32
79354 + help
79355 + This implementation is based on the paging feature of the CPU.
79356 + On i386 without hardware non-executable bit support there is a
79357 + variable but usually low performance impact, however on Intel's
79358 + P4 core based CPUs it is very high so you should not enable this
79359 + for kernels meant to be used on such CPUs.
79360 +
79361 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
79362 + with hardware non-executable bit support there is no performance
79363 + impact, on ppc the impact is negligible.
79364 +
79365 + Note that several architectures require various emulations due to
79366 + badly designed userland ABIs, this will cause a performance impact
79367 + but will disappear as soon as userland is fixed. For example, ppc
79368 + userland MUST have been built with secure-plt by a recent toolchain.
79369 +
79370 +config PAX_SEGMEXEC
79371 + bool "Segmentation based non-executable pages"
79372 + depends on PAX_NOEXEC && X86_32
79373 + help
79374 + This implementation is based on the segmentation feature of the
79375 + CPU and has a very small performance impact, however applications
79376 + will be limited to a 1.5 GB address space instead of the normal
79377 + 3 GB.
79378 +
79379 +config PAX_EMUTRAMP
79380 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
79381 + default y if PARISC
79382 + help
79383 + There are some programs and libraries that for one reason or
79384 + another attempt to execute special small code snippets from
79385 + non-executable memory pages. Most notable examples are the
79386 + signal handler return code generated by the kernel itself and
79387 + the GCC trampolines.
79388 +
79389 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
79390 + such programs will no longer work under your kernel.
79391 +
79392 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
79393 + utilities to enable trampoline emulation for the affected programs
79394 + yet still have the protection provided by the non-executable pages.
79395 +
79396 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
79397 + your system will not even boot.
79398 +
79399 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
79400 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
79401 + for the affected files.
79402 +
79403 + NOTE: enabling this feature *may* open up a loophole in the
79404 + protection provided by non-executable pages that an attacker
79405 + could abuse. Therefore the best solution is to not have any
79406 + files on your system that would require this option. This can
79407 + be achieved by not using libc5 (which relies on the kernel
79408 + signal handler return code) and not using or rewriting programs
79409 + that make use of the nested function implementation of GCC.
79410 + Skilled users can just fix GCC itself so that it implements
79411 + nested function calls in a way that does not interfere with PaX.
79412 +
79413 +config PAX_EMUSIGRT
79414 + bool "Automatically emulate sigreturn trampolines"
79415 + depends on PAX_EMUTRAMP && PARISC
79416 + default y
79417 + help
79418 + Enabling this option will have the kernel automatically detect
79419 + and emulate signal return trampolines executing on the stack
79420 + that would otherwise lead to task termination.
79421 +
79422 + This solution is intended as a temporary one for users with
79423 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
79424 + Modula-3 runtime, etc) or executables linked to such, basically
79425 + everything that does not specify its own SA_RESTORER function in
79426 + normal executable memory like glibc 2.1+ does.
79427 +
79428 + On parisc you MUST enable this option, otherwise your system will
79429 + not even boot.
79430 +
79431 + NOTE: this feature cannot be disabled on a per executable basis
79432 + and since it *does* open up a loophole in the protection provided
79433 + by non-executable pages, the best solution is to not have any
79434 + files on your system that would require this option.
79435 +
79436 +config PAX_MPROTECT
79437 + bool "Restrict mprotect()"
79438 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
79439 + help
79440 + Enabling this option will prevent programs from
79441 + - changing the executable status of memory pages that were
79442 + not originally created as executable,
79443 + - making read-only executable pages writable again,
79444 + - creating executable pages from anonymous memory,
79445 + - making read-only-after-relocations (RELRO) data pages writable again.
79446 +
79447 + You should say Y here to complete the protection provided by
79448 + the enforcement of non-executable pages.
79449 +
79450 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
79451 + this feature on a per file basis.
79452 +
79453 +config PAX_MPROTECT_COMPAT
79454 + bool "Use legacy/compat protection demoting (read help)"
79455 + depends on PAX_MPROTECT
79456 + default n
79457 + help
79458 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
79459 + by sending the proper error code to the application. For some broken
79460 + userland, this can cause problems with Python or other applications. The
79461 + current implementation however allows for applications like clamav to
79462 + detect if JIT compilation/execution is allowed and to fall back gracefully
79463 + to an interpreter-based mode if it does not. While we encourage everyone
79464 + to use the current implementation as-is and push upstream to fix broken
79465 + userland (note that the RWX logging option can assist with this), in some
79466 + environments this may not be possible. Having to disable MPROTECT
79467 + completely on certain binaries reduces the security benefit of PaX,
79468 + so this option is provided for those environments to revert to the old
79469 + behavior.
79470 +
79471 +config PAX_ELFRELOCS
79472 + bool "Allow ELF text relocations (read help)"
79473 + depends on PAX_MPROTECT
79474 + default n
79475 + help
79476 + Non-executable pages and mprotect() restrictions are effective
79477 + in preventing the introduction of new executable code into an
79478 + attacked task's address space. There remain only two venues
79479 + for this kind of attack: if the attacker can execute already
79480 + existing code in the attacked task then he can either have it
79481 + create and mmap() a file containing his code or have it mmap()
79482 + an already existing ELF library that does not have position
79483 + independent code in it and use mprotect() on it to make it
79484 + writable and copy his code there. While protecting against
79485 + the former approach is beyond PaX, the latter can be prevented
79486 + by having only PIC ELF libraries on one's system (which do not
79487 + need to relocate their code). If you are sure this is your case,
79488 + as is the case with all modern Linux distributions, then leave
79489 + this option disabled. You should say 'n' here.
79490 +
79491 +config PAX_ETEXECRELOCS
79492 + bool "Allow ELF ET_EXEC text relocations"
79493 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
79494 + select PAX_ELFRELOCS
79495 + default y
79496 + help
79497 + On some architectures there are incorrectly created applications
79498 + that require text relocations and would not work without enabling
79499 + this option. If you are an alpha, ia64 or parisc user, you should
79500 + enable this option and disable it once you have made sure that
79501 + none of your applications need it.
79502 +
79503 +config PAX_EMUPLT
79504 + bool "Automatically emulate ELF PLT"
79505 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
79506 + default y
79507 + help
79508 + Enabling this option will have the kernel automatically detect
79509 + and emulate the Procedure Linkage Table entries in ELF files.
79510 + On some architectures such entries are in writable memory, and
79511 + become non-executable leading to task termination. Therefore
79512 + it is mandatory that you enable this option on alpha, parisc,
79513 + sparc and sparc64, otherwise your system would not even boot.
79514 +
79515 + NOTE: this feature *does* open up a loophole in the protection
79516 + provided by the non-executable pages, therefore the proper
79517 + solution is to modify the toolchain to produce a PLT that does
79518 + not need to be writable.
79519 +
79520 +config PAX_DLRESOLVE
79521 + bool 'Emulate old glibc resolver stub'
79522 + depends on PAX_EMUPLT && SPARC
79523 + default n
79524 + help
79525 + This option is needed if userland has an old glibc (before 2.4)
79526 + that puts a 'save' instruction into the runtime generated resolver
79527 + stub that needs special emulation.
79528 +
79529 +config PAX_KERNEXEC
79530 + bool "Enforce non-executable kernel pages"
79531 + depends on PAX_NOEXEC && (PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN
79532 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
79533 + help
79534 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
79535 + that is, enabling this option will make it harder to inject
79536 + and execute 'foreign' code in kernel memory itself.
79537 +
79538 + Note that on x86_64 kernels there is a known regression when
79539 + this feature and KVM/VMX are both enabled in the host kernel.
79540 +
79541 +config PAX_KERNEXEC_MODULE_TEXT
79542 + int "Minimum amount of memory reserved for module code"
79543 + default "4"
79544 + depends on PAX_KERNEXEC && X86_32 && MODULES
79545 + help
79546 + Due to implementation details the kernel must reserve a fixed
79547 + amount of memory for module code at compile time that cannot be
79548 + changed at runtime. Here you can specify the minimum amount
79549 + in MB that will be reserved. Due to the same implementation
79550 + details this size will always be rounded up to the next 2/4 MB
79551 + boundary (depends on PAE) so the actually available memory for
79552 + module code will usually be more than this minimum.
79553 +
79554 + The default 4 MB should be enough for most users but if you have
79555 + an excessive number of modules (e.g., most distribution configs
79556 + compile many drivers as modules) or use huge modules such as
79557 + nvidia's kernel driver, you will need to adjust this amount.
79558 + A good rule of thumb is to look at your currently loaded kernel
79559 + modules and add up their sizes.
79560 +
79561 +endmenu
79562 +
79563 +menu "Address Space Layout Randomization"
79564 + depends on PAX
79565 +
79566 +config PAX_ASLR
79567 + bool "Address Space Layout Randomization"
79568 + depends on PAX_EI_PAX || PAX_PT_PAX_FLAGS || PAX_HAVE_ACL_FLAGS || PAX_HOOK_ACL_FLAGS
79569 + help
79570 + Many if not most exploit techniques rely on the knowledge of
79571 + certain addresses in the attacked program. The following options
79572 + will allow the kernel to apply a certain amount of randomization
79573 + to specific parts of the program thereby forcing an attacker to
79574 + guess them in most cases. Any failed guess will most likely crash
79575 + the attacked program which allows the kernel to detect such attempts
79576 + and react on them. PaX itself provides no reaction mechanisms,
79577 + instead it is strongly encouraged that you make use of Nergal's
79578 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
79579 + (http://www.grsecurity.net/) built-in crash detection features or
79580 + develop one yourself.
79581 +
79582 + By saying Y here you can choose to randomize the following areas:
79583 + - top of the task's kernel stack
79584 + - top of the task's userland stack
79585 + - base address for mmap() requests that do not specify one
79586 + (this includes all libraries)
79587 + - base address of the main executable
79588 +
79589 + It is strongly recommended to say Y here as address space layout
79590 + randomization has negligible impact on performance yet it provides
79591 + a very effective protection.
79592 +
79593 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
79594 + this feature on a per file basis.
79595 +
79596 +config PAX_RANDKSTACK
79597 + bool "Randomize kernel stack base"
79598 + depends on PAX_ASLR && X86_TSC && X86
79599 + help
79600 + By saying Y here the kernel will randomize every task's kernel
79601 + stack on every system call. This will not only force an attacker
79602 + to guess it but also prevent him from making use of possible
79603 + leaked information about it.
79604 +
79605 + Since the kernel stack is a rather scarce resource, randomization
79606 + may cause unexpected stack overflows, therefore you should very
79607 + carefully test your system. Note that once enabled in the kernel
79608 + configuration, this feature cannot be disabled on a per file basis.
79609 +
79610 +config PAX_RANDUSTACK
79611 + bool "Randomize user stack base"
79612 + depends on PAX_ASLR
79613 + help
79614 + By saying Y here the kernel will randomize every task's userland
79615 + stack. The randomization is done in two steps where the second
79616 + one may apply a big amount of shift to the top of the stack and
79617 + cause problems for programs that want to use lots of memory (more
79618 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
79619 + For this reason the second step can be controlled by 'chpax' or
79620 + 'paxctl' on a per file basis.
79621 +
79622 +config PAX_RANDMMAP
79623 + bool "Randomize mmap() base"
79624 + depends on PAX_ASLR
79625 + help
79626 + By saying Y here the kernel will use a randomized base address for
79627 + mmap() requests that do not specify one themselves. As a result
79628 + all dynamically loaded libraries will appear at random addresses
79629 + and therefore be harder to exploit by a technique where an attacker
79630 + attempts to execute library code for his purposes (e.g. spawn a
79631 + shell from an exploited program that is running at an elevated
79632 + privilege level).
79633 +
79634 + Furthermore, if a program is relinked as a dynamic ELF file, its
79635 + base address will be randomized as well, completing the full
79636 + randomization of the address space layout. Attacking such programs
79637 + becomes a guess game. You can find an example of doing this at
79638 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
79639 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
79640 +
79641 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
79642 + feature on a per file basis.
79643 +
79644 +endmenu
79645 +
79646 +menu "Miscellaneous hardening features"
79647 +
79648 +config PAX_MEMORY_SANITIZE
79649 + bool "Sanitize all freed memory"
79650 + help
79651 + By saying Y here the kernel will erase memory pages as soon as they
79652 + are freed. This in turn reduces the lifetime of data stored in the
79653 + pages, making it less likely that sensitive information such as
79654 + passwords, cryptographic secrets, etc stay in memory for too long.
79655 +
79656 + This is especially useful for programs whose runtime is short, long
79657 + lived processes and the kernel itself benefit from this as long as
79658 + they operate on whole memory pages and ensure timely freeing of pages
79659 + that may hold sensitive information.
79660 +
79661 + The tradeoff is performance impact, on a single CPU system kernel
79662 + compilation sees a 3% slowdown, other systems and workloads may vary
79663 + and you are advised to test this feature on your expected workload
79664 + before deploying it.
79665 +
79666 + Note that this feature does not protect data stored in live pages,
79667 + e.g., process memory swapped to disk may stay there for a long time.
79668 +
79669 +config PAX_MEMORY_STACKLEAK
79670 + bool "Sanitize kernel stack"
79671 + depends on X86
79672 + help
79673 + By saying Y here the kernel will erase the kernel stack before it
79674 + returns from a system call. This in turn reduces the information
79675 + that a kernel stack leak bug can reveal.
79676 +
79677 + Note that such a bug can still leak information that was put on
79678 + the stack by the current system call (the one eventually triggering
79679 + the bug) but traces of earlier system calls on the kernel stack
79680 + cannot leak anymore.
79681 +
79682 + The tradeoff is performance impact: on a single CPU system kernel
79683 + compilation sees a 1% slowdown, other systems and workloads may vary
79684 + and you are advised to test this feature on your expected workload
79685 + before deploying it.
79686 +
79687 +config PAX_MEMORY_UDEREF
79688 + bool "Prevent invalid userland pointer dereference"
79689 + depends on X86 && !UML_X86 && !XEN
79690 + select PAX_PER_CPU_PGD if X86_64
79691 + help
79692 + By saying Y here the kernel will be prevented from dereferencing
79693 + userland pointers in contexts where the kernel expects only kernel
79694 + pointers. This is both a useful runtime debugging feature and a
79695 + security measure that prevents exploiting a class of kernel bugs.
79696 +
79697 + The tradeoff is that some virtualization solutions may experience
79698 + a huge slowdown and therefore you should not enable this feature
79699 + for kernels meant to run in such environments. Whether a given VM
79700 + solution is affected or not is best determined by simply trying it
79701 + out, the performance impact will be obvious right on boot as this
79702 + mechanism engages from very early on. A good rule of thumb is that
79703 + VMs running on CPUs without hardware virtualization support (i.e.,
79704 + the majority of IA-32 CPUs) will likely experience the slowdown.
79705 +
79706 +config PAX_REFCOUNT
79707 + bool "Prevent various kernel object reference counter overflows"
79708 + depends on GRKERNSEC && (X86 || SPARC64)
79709 + help
79710 + By saying Y here the kernel will detect and prevent overflowing
79711 + various (but not all) kinds of object reference counters. Such
79712 + overflows can normally occur due to bugs only and are often, if
79713 + not always, exploitable.
79714 +
79715 + The tradeoff is that data structures protected by an overflowed
79716 + refcount will never be freed and therefore will leak memory. Note
79717 + that this leak also happens even without this protection but in
79718 + that case the overflow can eventually trigger the freeing of the
79719 + data structure while it is still being used elsewhere, resulting
79720 + in the exploitable situation that this feature prevents.
79721 +
79722 + Since this has a negligible performance impact, you should enable
79723 + this feature.
79724 +
79725 +config PAX_USERCOPY
79726 + bool "Harden heap object copies between kernel and userland"
79727 + depends on X86 || PPC || SPARC
79728 + depends on GRKERNSEC && (SLAB || SLUB)
79729 + help
79730 + By saying Y here the kernel will enforce the size of heap objects
79731 + when they are copied in either direction between the kernel and
79732 + userland, even if only a part of the heap object is copied.
79733 +
79734 + Specifically, this checking prevents information leaking from the
79735 + kernel heap during kernel to userland copies (if the kernel heap
79736 + object is otherwise fully initialized) and prevents kernel heap
79737 + overflows during userland to kernel copies.
79738 +
79739 + Note that the current implementation provides the strictest bounds
79740 + checks for the SLUB allocator.
79741 +
79742 + Enabling this option also enables per-slab cache protection against
79743 + data in a given cache being copied into/out of via userland
79744 + accessors. Though the whitelist of regions will be reduced over
79745 + time, it notably protects important data structures like task structs.
79746 +
79747 + If frame pointers are enabled on x86, this option will also restrict
79748 + copies into and out of the kernel stack to local variables within a
79749 + single frame.
79750 +
79751 + Since this has a negligible performance impact, you should enable
79752 + this feature.
79753 +
79754 +endmenu
79755 +
79756 +endmenu
79757 +
79758 config KEYS
79759 bool "Enable access key retention support"
79760 help
79761 @@ -167,7 +709,7 @@ config INTEL_TXT
79762 config LSM_MMAP_MIN_ADDR
79763 int "Low address space for LSM to protect from user allocation"
79764 depends on SECURITY && SECURITY_SELINUX
79765 - default 65536
79766 + default 32768
79767 help
79768 This is the portion of low virtual memory which should be protected
79769 from userspace allocation. Keeping a user from writing to low pages
79770 diff -urNp linux-2.6.39/security/keys/keyring.c linux-2.6.39/security/keys/keyring.c
79771 --- linux-2.6.39/security/keys/keyring.c 2011-05-19 00:06:34.000000000 -0400
79772 +++ linux-2.6.39/security/keys/keyring.c 2011-05-22 19:36:35.000000000 -0400
79773 @@ -213,15 +213,15 @@ static long keyring_read(const struct ke
79774 ret = -EFAULT;
79775
79776 for (loop = 0; loop < klist->nkeys; loop++) {
79777 + key_serial_t serial;
79778 key = klist->keys[loop];
79779 + serial = key->serial;
79780
79781 tmp = sizeof(key_serial_t);
79782 if (tmp > buflen)
79783 tmp = buflen;
79784
79785 - if (copy_to_user(buffer,
79786 - &key->serial,
79787 - tmp) != 0)
79788 + if (copy_to_user(buffer, &serial, tmp))
79789 goto error;
79790
79791 buflen -= tmp;
79792 diff -urNp linux-2.6.39/security/min_addr.c linux-2.6.39/security/min_addr.c
79793 --- linux-2.6.39/security/min_addr.c 2011-05-19 00:06:34.000000000 -0400
79794 +++ linux-2.6.39/security/min_addr.c 2011-05-22 19:41:42.000000000 -0400
79795 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG
79796 */
79797 static void update_mmap_min_addr(void)
79798 {
79799 +#ifndef SPARC
79800 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
79801 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
79802 mmap_min_addr = dac_mmap_min_addr;
79803 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
79804 #else
79805 mmap_min_addr = dac_mmap_min_addr;
79806 #endif
79807 +#endif
79808 }
79809
79810 /*
79811 diff -urNp linux-2.6.39/security/security.c linux-2.6.39/security/security.c
79812 --- linux-2.6.39/security/security.c 2011-05-19 00:06:34.000000000 -0400
79813 +++ linux-2.6.39/security/security.c 2011-05-22 19:41:42.000000000 -0400
79814 @@ -25,8 +25,8 @@ static __initdata char chosen_lsm[SECURI
79815 /* things that live in capability.c */
79816 extern void __init security_fixup_ops(struct security_operations *ops);
79817
79818 -static struct security_operations *security_ops;
79819 -static struct security_operations default_security_ops = {
79820 +static struct security_operations *security_ops __read_only;
79821 +static struct security_operations default_security_ops __read_only = {
79822 .name = "default",
79823 };
79824
79825 @@ -67,7 +67,9 @@ int __init security_init(void)
79826
79827 void reset_security_ops(void)
79828 {
79829 + pax_open_kernel();
79830 security_ops = &default_security_ops;
79831 + pax_close_kernel();
79832 }
79833
79834 /* Save user chosen LSM */
79835 diff -urNp linux-2.6.39/security/selinux/hooks.c linux-2.6.39/security/selinux/hooks.c
79836 --- linux-2.6.39/security/selinux/hooks.c 2011-05-19 00:06:34.000000000 -0400
79837 +++ linux-2.6.39/security/selinux/hooks.c 2011-05-22 19:41:42.000000000 -0400
79838 @@ -93,7 +93,6 @@
79839 #define NUM_SEL_MNT_OPTS 5
79840
79841 extern int selinux_nlmsg_lookup(u16 sclass, u16 nlmsg_type, u32 *perm);
79842 -extern struct security_operations *security_ops;
79843
79844 /* SECMARK reference count */
79845 atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
79846 @@ -5431,7 +5430,7 @@ static int selinux_key_getsecurity(struc
79847
79848 #endif
79849
79850 -static struct security_operations selinux_ops = {
79851 +static struct security_operations selinux_ops __read_only = {
79852 .name = "selinux",
79853
79854 .ptrace_access_check = selinux_ptrace_access_check,
79855 diff -urNp linux-2.6.39/security/selinux/include/xfrm.h linux-2.6.39/security/selinux/include/xfrm.h
79856 --- linux-2.6.39/security/selinux/include/xfrm.h 2011-05-19 00:06:34.000000000 -0400
79857 +++ linux-2.6.39/security/selinux/include/xfrm.h 2011-05-22 19:36:35.000000000 -0400
79858 @@ -48,7 +48,7 @@ int selinux_xfrm_decode_session(struct s
79859
79860 static inline void selinux_xfrm_notify_policyload(void)
79861 {
79862 - atomic_inc(&flow_cache_genid);
79863 + atomic_inc_unchecked(&flow_cache_genid);
79864 }
79865 #else
79866 static inline int selinux_xfrm_enabled(void)
79867 diff -urNp linux-2.6.39/security/selinux/ss/services.c linux-2.6.39/security/selinux/ss/services.c
79868 --- linux-2.6.39/security/selinux/ss/services.c 2011-05-19 00:06:34.000000000 -0400
79869 +++ linux-2.6.39/security/selinux/ss/services.c 2011-05-22 19:36:35.000000000 -0400
79870 @@ -1806,6 +1806,8 @@ int security_load_policy(void *data, siz
79871 int rc = 0;
79872 struct policy_file file = { data, len }, *fp = &file;
79873
79874 + pax_track_stack();
79875 +
79876 if (!ss_initialized) {
79877 avtab_cache_init();
79878 rc = policydb_read(&policydb, fp);
79879 diff -urNp linux-2.6.39/security/smack/smack_lsm.c linux-2.6.39/security/smack/smack_lsm.c
79880 --- linux-2.6.39/security/smack/smack_lsm.c 2011-05-19 00:06:34.000000000 -0400
79881 +++ linux-2.6.39/security/smack/smack_lsm.c 2011-05-22 19:36:35.000000000 -0400
79882 @@ -3386,7 +3386,7 @@ static int smack_inode_getsecctx(struct
79883 return 0;
79884 }
79885
79886 -struct security_operations smack_ops = {
79887 +struct security_operations smack_ops __read_only = {
79888 .name = "smack",
79889
79890 .ptrace_access_check = smack_ptrace_access_check,
79891 diff -urNp linux-2.6.39/security/tomoyo/tomoyo.c linux-2.6.39/security/tomoyo/tomoyo.c
79892 --- linux-2.6.39/security/tomoyo/tomoyo.c 2011-05-19 00:06:34.000000000 -0400
79893 +++ linux-2.6.39/security/tomoyo/tomoyo.c 2011-05-22 19:36:35.000000000 -0400
79894 @@ -240,7 +240,7 @@ static int tomoyo_sb_pivotroot(struct pa
79895 * tomoyo_security_ops is a "struct security_operations" which is used for
79896 * registering TOMOYO.
79897 */
79898 -static struct security_operations tomoyo_security_ops = {
79899 +static struct security_operations tomoyo_security_ops __read_only = {
79900 .name = "tomoyo",
79901 .cred_alloc_blank = tomoyo_cred_alloc_blank,
79902 .cred_prepare = tomoyo_cred_prepare,
79903 diff -urNp linux-2.6.39/sound/aoa/aoa.h linux-2.6.39/sound/aoa/aoa.h
79904 --- linux-2.6.39/sound/aoa/aoa.h 2011-05-19 00:06:34.000000000 -0400
79905 +++ linux-2.6.39/sound/aoa/aoa.h 2011-05-22 19:36:35.000000000 -0400
79906 @@ -122,8 +122,8 @@ extern struct snd_card *aoa_get_card(voi
79907 extern int aoa_snd_ctl_add(struct snd_kcontrol* control);
79908
79909 /* GPIO stuff */
79910 -extern struct gpio_methods *pmf_gpio_methods;
79911 -extern struct gpio_methods *ftr_gpio_methods;
79912 +extern const struct gpio_methods *pmf_gpio_methods;
79913 +extern const struct gpio_methods *ftr_gpio_methods;
79914 /* extern struct gpio_methods *map_gpio_methods; */
79915
79916 #endif /* __AOA_H */
79917 diff -urNp linux-2.6.39/sound/aoa/codecs/onyx.c linux-2.6.39/sound/aoa/codecs/onyx.c
79918 --- linux-2.6.39/sound/aoa/codecs/onyx.c 2011-05-19 00:06:34.000000000 -0400
79919 +++ linux-2.6.39/sound/aoa/codecs/onyx.c 2011-05-22 19:36:35.000000000 -0400
79920 @@ -54,7 +54,7 @@ struct onyx {
79921 spdif_locked:1,
79922 analog_locked:1,
79923 original_mute:2;
79924 - int open_count;
79925 + local_t open_count;
79926 struct codec_info *codec_info;
79927
79928 /* mutex serializes concurrent access to the device
79929 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_i
79930 struct onyx *onyx = cii->codec_data;
79931
79932 mutex_lock(&onyx->mutex);
79933 - onyx->open_count++;
79934 + local_inc(&onyx->open_count);
79935 mutex_unlock(&onyx->mutex);
79936
79937 return 0;
79938 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_
79939 struct onyx *onyx = cii->codec_data;
79940
79941 mutex_lock(&onyx->mutex);
79942 - onyx->open_count--;
79943 - if (!onyx->open_count)
79944 + if (local_dec_and_test(&onyx->open_count))
79945 onyx->spdif_locked = onyx->analog_locked = 0;
79946 mutex_unlock(&onyx->mutex);
79947
79948 diff -urNp linux-2.6.39/sound/aoa/codecs/onyx.h linux-2.6.39/sound/aoa/codecs/onyx.h
79949 --- linux-2.6.39/sound/aoa/codecs/onyx.h 2011-05-19 00:06:34.000000000 -0400
79950 +++ linux-2.6.39/sound/aoa/codecs/onyx.h 2011-05-22 19:36:35.000000000 -0400
79951 @@ -11,6 +11,7 @@
79952 #include <linux/i2c.h>
79953 #include <asm/pmac_low_i2c.h>
79954 #include <asm/prom.h>
79955 +#include <asm/local.h>
79956
79957 /* PCM3052 register definitions */
79958
79959 diff -urNp linux-2.6.39/sound/arm/aaci.c linux-2.6.39/sound/arm/aaci.c
79960 --- linux-2.6.39/sound/arm/aaci.c 2011-05-19 00:06:34.000000000 -0400
79961 +++ linux-2.6.39/sound/arm/aaci.c 2011-05-22 19:36:35.000000000 -0400
79962 @@ -635,7 +635,7 @@ static int aaci_pcm_playback_trigger(str
79963 return ret;
79964 }
79965
79966 -static struct snd_pcm_ops aaci_playback_ops = {
79967 +static const struct snd_pcm_ops aaci_playback_ops = {
79968 .open = aaci_pcm_open,
79969 .close = aaci_pcm_close,
79970 .ioctl = snd_pcm_lib_ioctl,
79971 @@ -738,7 +738,7 @@ static int aaci_pcm_capture_prepare(stru
79972 return 0;
79973 }
79974
79975 -static struct snd_pcm_ops aaci_capture_ops = {
79976 +static const struct snd_pcm_ops aaci_capture_ops = {
79977 .open = aaci_pcm_open,
79978 .close = aaci_pcm_close,
79979 .ioctl = snd_pcm_lib_ioctl,
79980 @@ -827,7 +827,7 @@ static struct ac97_pcm ac97_defs[] __dev
79981 }
79982 };
79983
79984 -static struct snd_ac97_bus_ops aaci_bus_ops = {
79985 +static const struct snd_ac97_bus_ops aaci_bus_ops = {
79986 .write = aaci_ac97_write,
79987 .read = aaci_ac97_read,
79988 };
79989 diff -urNp linux-2.6.39/sound/arm/pxa2xx-ac97.c linux-2.6.39/sound/arm/pxa2xx-ac97.c
79990 --- linux-2.6.39/sound/arm/pxa2xx-ac97.c 2011-05-19 00:06:34.000000000 -0400
79991 +++ linux-2.6.39/sound/arm/pxa2xx-ac97.c 2011-05-22 19:36:35.000000000 -0400
79992 @@ -34,7 +34,7 @@ static void pxa2xx_ac97_reset(struct snd
79993 pxa2xx_ac97_finish_reset(ac97);
79994 }
79995
79996 -static struct snd_ac97_bus_ops pxa2xx_ac97_ops = {
79997 +static const struct snd_ac97_bus_ops pxa2xx_ac97_ops = {
79998 .read = pxa2xx_ac97_read,
79999 .write = pxa2xx_ac97_write,
80000 .reset = pxa2xx_ac97_reset,
80001 diff -urNp linux-2.6.39/sound/atmel/abdac.c linux-2.6.39/sound/atmel/abdac.c
80002 --- linux-2.6.39/sound/atmel/abdac.c 2011-05-19 00:06:34.000000000 -0400
80003 +++ linux-2.6.39/sound/atmel/abdac.c 2011-05-22 19:36:35.000000000 -0400
80004 @@ -297,7 +297,7 @@ static irqreturn_t abdac_interrupt(int i
80005 return IRQ_HANDLED;
80006 }
80007
80008 -static struct snd_pcm_ops atmel_abdac_ops = {
80009 +static const struct snd_pcm_ops atmel_abdac_ops = {
80010 .open = atmel_abdac_open,
80011 .close = atmel_abdac_close,
80012 .ioctl = snd_pcm_lib_ioctl,
80013 diff -urNp linux-2.6.39/sound/atmel/ac97c.c linux-2.6.39/sound/atmel/ac97c.c
80014 --- linux-2.6.39/sound/atmel/ac97c.c 2011-05-19 00:06:34.000000000 -0400
80015 +++ linux-2.6.39/sound/atmel/ac97c.c 2011-05-22 19:36:35.000000000 -0400
80016 @@ -626,7 +626,7 @@ atmel_ac97c_capture_pointer(struct snd_p
80017 return frames;
80018 }
80019
80020 -static struct snd_pcm_ops atmel_ac97_playback_ops = {
80021 +static const struct snd_pcm_ops atmel_ac97_playback_ops = {
80022 .open = atmel_ac97c_playback_open,
80023 .close = atmel_ac97c_playback_close,
80024 .ioctl = snd_pcm_lib_ioctl,
80025 @@ -637,7 +637,7 @@ static struct snd_pcm_ops atmel_ac97_pla
80026 .pointer = atmel_ac97c_playback_pointer,
80027 };
80028
80029 -static struct snd_pcm_ops atmel_ac97_capture_ops = {
80030 +static const struct snd_pcm_ops atmel_ac97_capture_ops = {
80031 .open = atmel_ac97c_capture_open,
80032 .close = atmel_ac97c_capture_close,
80033 .ioctl = snd_pcm_lib_ioctl,
80034 @@ -909,7 +909,7 @@ static int __devinit atmel_ac97c_probe(s
80035 struct resource *regs;
80036 struct ac97c_platform_data *pdata;
80037 struct clk *pclk;
80038 - static struct snd_ac97_bus_ops ops = {
80039 + static const struct snd_ac97_bus_ops ops = {
80040 .write = atmel_ac97c_write,
80041 .read = atmel_ac97c_read,
80042 };
80043 diff -urNp linux-2.6.39/sound/core/control.c linux-2.6.39/sound/core/control.c
80044 --- linux-2.6.39/sound/core/control.c 2011-05-19 00:06:34.000000000 -0400
80045 +++ linux-2.6.39/sound/core/control.c 2011-05-22 19:36:35.000000000 -0400
80046 @@ -1520,7 +1520,7 @@ static int snd_ctl_dev_free(struct snd_d
80047 */
80048 int snd_ctl_create(struct snd_card *card)
80049 {
80050 - static struct snd_device_ops ops = {
80051 + static const struct snd_device_ops ops = {
80052 .dev_free = snd_ctl_dev_free,
80053 .dev_register = snd_ctl_dev_register,
80054 .dev_disconnect = snd_ctl_dev_disconnect,
80055 diff -urNp linux-2.6.39/sound/core/device.c linux-2.6.39/sound/core/device.c
80056 --- linux-2.6.39/sound/core/device.c 2011-05-19 00:06:34.000000000 -0400
80057 +++ linux-2.6.39/sound/core/device.c 2011-05-22 19:36:35.000000000 -0400
80058 @@ -41,7 +41,7 @@
80059 * Returns zero if successful, or a negative error code on failure.
80060 */
80061 int snd_device_new(struct snd_card *card, snd_device_type_t type,
80062 - void *device_data, struct snd_device_ops *ops)
80063 + void *device_data, const struct snd_device_ops *ops)
80064 {
80065 struct snd_device *dev;
80066
80067 diff -urNp linux-2.6.39/sound/core/hwdep.c linux-2.6.39/sound/core/hwdep.c
80068 --- linux-2.6.39/sound/core/hwdep.c 2011-05-19 00:06:34.000000000 -0400
80069 +++ linux-2.6.39/sound/core/hwdep.c 2011-05-22 19:36:35.000000000 -0400
80070 @@ -348,7 +348,7 @@ int snd_hwdep_new(struct snd_card *card,
80071 {
80072 struct snd_hwdep *hwdep;
80073 int err;
80074 - static struct snd_device_ops ops = {
80075 + static const struct snd_device_ops ops = {
80076 .dev_free = snd_hwdep_dev_free,
80077 .dev_register = snd_hwdep_dev_register,
80078 .dev_disconnect = snd_hwdep_dev_disconnect,
80079 diff -urNp linux-2.6.39/sound/core/info.c linux-2.6.39/sound/core/info.c
80080 --- linux-2.6.39/sound/core/info.c 2011-05-19 00:06:34.000000000 -0400
80081 +++ linux-2.6.39/sound/core/info.c 2011-05-22 19:36:35.000000000 -0400
80082 @@ -897,7 +897,7 @@ static int snd_info_dev_register_entry(s
80083 int snd_card_proc_new(struct snd_card *card, const char *name,
80084 struct snd_info_entry **entryp)
80085 {
80086 - static struct snd_device_ops ops = {
80087 + static const struct snd_device_ops ops = {
80088 .dev_free = snd_info_dev_free_entry,
80089 .dev_register = snd_info_dev_register_entry,
80090 /* disconnect is done via snd_info_card_disconnect() */
80091 diff -urNp linux-2.6.39/sound/core/jack.c linux-2.6.39/sound/core/jack.c
80092 --- linux-2.6.39/sound/core/jack.c 2011-05-19 00:06:34.000000000 -0400
80093 +++ linux-2.6.39/sound/core/jack.c 2011-05-22 19:36:35.000000000 -0400
80094 @@ -105,7 +105,7 @@ int snd_jack_new(struct snd_card *card,
80095 struct snd_jack *jack;
80096 int err;
80097 int i;
80098 - static struct snd_device_ops ops = {
80099 + static const struct snd_device_ops ops = {
80100 .dev_free = snd_jack_dev_free,
80101 .dev_register = snd_jack_dev_register,
80102 };
80103 diff -urNp linux-2.6.39/sound/core/pcm.c linux-2.6.39/sound/core/pcm.c
80104 --- linux-2.6.39/sound/core/pcm.c 2011-05-19 00:06:34.000000000 -0400
80105 +++ linux-2.6.39/sound/core/pcm.c 2011-05-22 19:36:35.000000000 -0400
80106 @@ -717,7 +717,7 @@ int snd_pcm_new(struct snd_card *card, c
80107 {
80108 struct snd_pcm *pcm;
80109 int err;
80110 - static struct snd_device_ops ops = {
80111 + static const struct snd_device_ops ops = {
80112 .dev_free = snd_pcm_dev_free,
80113 .dev_register = snd_pcm_dev_register,
80114 .dev_disconnect = snd_pcm_dev_disconnect,
80115 diff -urNp linux-2.6.39/sound/core/pcm_lib.c linux-2.6.39/sound/core/pcm_lib.c
80116 --- linux-2.6.39/sound/core/pcm_lib.c 2011-05-19 00:06:34.000000000 -0400
80117 +++ linux-2.6.39/sound/core/pcm_lib.c 2011-05-22 19:36:35.000000000 -0400
80118 @@ -505,7 +505,7 @@ int snd_pcm_update_hw_ptr(struct snd_pcm
80119 *
80120 * Sets the given PCM operators to the pcm instance.
80121 */
80122 -void snd_pcm_set_ops(struct snd_pcm *pcm, int direction, struct snd_pcm_ops *ops)
80123 +void snd_pcm_set_ops(struct snd_pcm *pcm, int direction, const struct snd_pcm_ops *ops)
80124 {
80125 struct snd_pcm_str *stream = &pcm->streams[direction];
80126 struct snd_pcm_substream *substream;
80127 diff -urNp linux-2.6.39/sound/core/pcm_native.c linux-2.6.39/sound/core/pcm_native.c
80128 --- linux-2.6.39/sound/core/pcm_native.c 2011-05-19 00:06:34.000000000 -0400
80129 +++ linux-2.6.39/sound/core/pcm_native.c 2011-05-22 19:36:35.000000000 -0400
80130 @@ -702,7 +702,7 @@ struct action_ops {
80131 * Note: the stream state might be changed also on failure
80132 * Note2: call with calling stream lock + link lock
80133 */
80134 -static int snd_pcm_action_group(struct action_ops *ops,
80135 +static int snd_pcm_action_group(const struct action_ops *ops,
80136 struct snd_pcm_substream *substream,
80137 int state, int do_lock)
80138 {
80139 @@ -751,7 +751,7 @@ static int snd_pcm_action_group(struct a
80140 /*
80141 * Note: call with stream lock
80142 */
80143 -static int snd_pcm_action_single(struct action_ops *ops,
80144 +static int snd_pcm_action_single(const struct action_ops *ops,
80145 struct snd_pcm_substream *substream,
80146 int state)
80147 {
80148 @@ -771,7 +771,7 @@ static int snd_pcm_action_single(struct
80149 /*
80150 * Note: call with stream lock
80151 */
80152 -static int snd_pcm_action(struct action_ops *ops,
80153 +static int snd_pcm_action(const struct action_ops *ops,
80154 struct snd_pcm_substream *substream,
80155 int state)
80156 {
80157 @@ -794,7 +794,7 @@ static int snd_pcm_action(struct action_
80158 /*
80159 * Note: don't use any locks before
80160 */
80161 -static int snd_pcm_action_lock_irq(struct action_ops *ops,
80162 +static int snd_pcm_action_lock_irq(const struct action_ops *ops,
80163 struct snd_pcm_substream *substream,
80164 int state)
80165 {
80166 @@ -818,7 +818,7 @@ static int snd_pcm_action_lock_irq(struc
80167
80168 /*
80169 */
80170 -static int snd_pcm_action_nonatomic(struct action_ops *ops,
80171 +static int snd_pcm_action_nonatomic(const struct action_ops *ops,
80172 struct snd_pcm_substream *substream,
80173 int state)
80174 {
80175 @@ -877,7 +877,7 @@ static void snd_pcm_post_start(struct sn
80176 &runtime->trigger_tstamp);
80177 }
80178
80179 -static struct action_ops snd_pcm_action_start = {
80180 +static const struct action_ops snd_pcm_action_start = {
80181 .pre_action = snd_pcm_pre_start,
80182 .do_action = snd_pcm_do_start,
80183 .undo_action = snd_pcm_undo_start,
80184 @@ -928,7 +928,7 @@ static void snd_pcm_post_stop(struct snd
80185 wake_up(&runtime->tsleep);
80186 }
80187
80188 -static struct action_ops snd_pcm_action_stop = {
80189 +static const struct action_ops snd_pcm_action_stop = {
80190 .pre_action = snd_pcm_pre_stop,
80191 .do_action = snd_pcm_do_stop,
80192 .post_action = snd_pcm_post_stop
80193 @@ -1025,7 +1025,7 @@ static void snd_pcm_post_pause(struct sn
80194 }
80195 }
80196
80197 -static struct action_ops snd_pcm_action_pause = {
80198 +static const struct action_ops snd_pcm_action_pause = {
80199 .pre_action = snd_pcm_pre_pause,
80200 .do_action = snd_pcm_do_pause,
80201 .undo_action = snd_pcm_undo_pause,
80202 @@ -1076,7 +1076,7 @@ static void snd_pcm_post_suspend(struct
80203 wake_up(&runtime->tsleep);
80204 }
80205
80206 -static struct action_ops snd_pcm_action_suspend = {
80207 +static const struct action_ops snd_pcm_action_suspend = {
80208 .pre_action = snd_pcm_pre_suspend,
80209 .do_action = snd_pcm_do_suspend,
80210 .post_action = snd_pcm_post_suspend
80211 @@ -1175,7 +1175,7 @@ static void snd_pcm_post_resume(struct s
80212 runtime->status->state = runtime->status->suspended_state;
80213 }
80214
80215 -static struct action_ops snd_pcm_action_resume = {
80216 +static const struct action_ops snd_pcm_action_resume = {
80217 .pre_action = snd_pcm_pre_resume,
80218 .do_action = snd_pcm_do_resume,
80219 .undo_action = snd_pcm_undo_resume,
80220 @@ -1278,7 +1278,7 @@ static void snd_pcm_post_reset(struct sn
80221 snd_pcm_playback_silence(substream, ULONG_MAX);
80222 }
80223
80224 -static struct action_ops snd_pcm_action_reset = {
80225 +static const struct action_ops snd_pcm_action_reset = {
80226 .pre_action = snd_pcm_pre_reset,
80227 .do_action = snd_pcm_do_reset,
80228 .post_action = snd_pcm_post_reset
80229 @@ -1322,7 +1322,7 @@ static void snd_pcm_post_prepare(struct
80230 runtime->status->state = SNDRV_PCM_STATE_PREPARED;
80231 }
80232
80233 -static struct action_ops snd_pcm_action_prepare = {
80234 +static const struct action_ops snd_pcm_action_prepare = {
80235 .pre_action = snd_pcm_pre_prepare,
80236 .do_action = snd_pcm_do_prepare,
80237 .post_action = snd_pcm_post_prepare
80238 @@ -1397,7 +1397,7 @@ static void snd_pcm_post_drain_init(stru
80239 {
80240 }
80241
80242 -static struct action_ops snd_pcm_action_drain_init = {
80243 +static const struct action_ops snd_pcm_action_drain_init = {
80244 .pre_action = snd_pcm_pre_drain_init,
80245 .do_action = snd_pcm_do_drain_init,
80246 .post_action = snd_pcm_post_drain_init
80247 diff -urNp linux-2.6.39/sound/core/rawmidi.c linux-2.6.39/sound/core/rawmidi.c
80248 --- linux-2.6.39/sound/core/rawmidi.c 2011-05-19 00:06:34.000000000 -0400
80249 +++ linux-2.6.39/sound/core/rawmidi.c 2011-05-22 19:36:35.000000000 -0400
80250 @@ -1449,7 +1449,7 @@ int snd_rawmidi_new(struct snd_card *car
80251 {
80252 struct snd_rawmidi *rmidi;
80253 int err;
80254 - static struct snd_device_ops ops = {
80255 + static const struct snd_device_ops ops = {
80256 .dev_free = snd_rawmidi_dev_free,
80257 .dev_register = snd_rawmidi_dev_register,
80258 .dev_disconnect = snd_rawmidi_dev_disconnect,
80259 @@ -1654,7 +1654,7 @@ static int snd_rawmidi_dev_disconnect(st
80260 * Sets the rawmidi operators for the given stream direction.
80261 */
80262 void snd_rawmidi_set_ops(struct snd_rawmidi *rmidi, int stream,
80263 - struct snd_rawmidi_ops *ops)
80264 + const struct snd_rawmidi_ops *ops)
80265 {
80266 struct snd_rawmidi_substream *substream;
80267
80268 diff -urNp linux-2.6.39/sound/core/seq/seq_device.c linux-2.6.39/sound/core/seq/seq_device.c
80269 --- linux-2.6.39/sound/core/seq/seq_device.c 2011-05-19 00:06:34.000000000 -0400
80270 +++ linux-2.6.39/sound/core/seq/seq_device.c 2011-05-22 19:36:35.000000000 -0400
80271 @@ -178,7 +178,7 @@ int snd_seq_device_new(struct snd_card *
80272 struct snd_seq_device *dev;
80273 struct ops_list *ops;
80274 int err;
80275 - static struct snd_device_ops dops = {
80276 + static const struct snd_device_ops dops = {
80277 .dev_free = snd_seq_device_dev_free,
80278 .dev_register = snd_seq_device_dev_register,
80279 .dev_disconnect = snd_seq_device_dev_disconnect,
80280 @@ -307,7 +307,7 @@ static int snd_seq_device_dev_disconnect
80281 * id = driver id
80282 * entry = driver operators - duplicated to each instance
80283 */
80284 -int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
80285 +int snd_seq_device_register_driver(char *id, const struct snd_seq_dev_ops *entry,
80286 int argsize)
80287 {
80288 struct ops_list *ops;
80289 diff -urNp linux-2.6.39/sound/core/seq/seq_midi.c linux-2.6.39/sound/core/seq/seq_midi.c
80290 --- linux-2.6.39/sound/core/seq/seq_midi.c 2011-05-19 00:06:34.000000000 -0400
80291 +++ linux-2.6.39/sound/core/seq/seq_midi.c 2011-05-22 19:36:35.000000000 -0400
80292 @@ -461,7 +461,7 @@ snd_seq_midisynth_unregister_port(struct
80293
80294 static int __init alsa_seq_midi_init(void)
80295 {
80296 - static struct snd_seq_dev_ops ops = {
80297 + static const struct snd_seq_dev_ops ops = {
80298 snd_seq_midisynth_register_port,
80299 snd_seq_midisynth_unregister_port,
80300 };
80301 diff -urNp linux-2.6.39/sound/core/seq/seq_virmidi.c linux-2.6.39/sound/core/seq/seq_virmidi.c
80302 --- linux-2.6.39/sound/core/seq/seq_virmidi.c 2011-05-19 00:06:34.000000000 -0400
80303 +++ linux-2.6.39/sound/core/seq/seq_virmidi.c 2011-05-22 19:36:35.000000000 -0400
80304 @@ -337,13 +337,13 @@ static int snd_virmidi_unuse(void *priva
80305 * Register functions
80306 */
80307
80308 -static struct snd_rawmidi_ops snd_virmidi_input_ops = {
80309 +static const struct snd_rawmidi_ops snd_virmidi_input_ops = {
80310 .open = snd_virmidi_input_open,
80311 .close = snd_virmidi_input_close,
80312 .trigger = snd_virmidi_input_trigger,
80313 };
80314
80315 -static struct snd_rawmidi_ops snd_virmidi_output_ops = {
80316 +static const struct snd_rawmidi_ops snd_virmidi_output_ops = {
80317 .open = snd_virmidi_output_open,
80318 .close = snd_virmidi_output_close,
80319 .trigger = snd_virmidi_output_trigger,
80320 @@ -467,7 +467,7 @@ static int snd_virmidi_dev_unregister(st
80321 /*
80322 *
80323 */
80324 -static struct snd_rawmidi_global_ops snd_virmidi_global_ops = {
80325 +static const struct snd_rawmidi_global_ops snd_virmidi_global_ops = {
80326 .dev_register = snd_virmidi_dev_register,
80327 .dev_unregister = snd_virmidi_dev_unregister,
80328 };
80329 diff -urNp linux-2.6.39/sound/core/timer.c linux-2.6.39/sound/core/timer.c
80330 --- linux-2.6.39/sound/core/timer.c 2011-05-19 00:06:34.000000000 -0400
80331 +++ linux-2.6.39/sound/core/timer.c 2011-05-22 19:36:35.000000000 -0400
80332 @@ -756,7 +756,7 @@ int snd_timer_new(struct snd_card *card,
80333 {
80334 struct snd_timer *timer;
80335 int err;
80336 - static struct snd_device_ops ops = {
80337 + static const struct snd_device_ops ops = {
80338 .dev_free = snd_timer_dev_free,
80339 .dev_register = snd_timer_dev_register,
80340 .dev_disconnect = snd_timer_dev_disconnect,
80341 diff -urNp linux-2.6.39/sound/drivers/aloop.c linux-2.6.39/sound/drivers/aloop.c
80342 --- linux-2.6.39/sound/drivers/aloop.c 2011-05-19 00:06:34.000000000 -0400
80343 +++ linux-2.6.39/sound/drivers/aloop.c 2011-05-22 19:36:35.000000000 -0400
80344 @@ -731,7 +731,7 @@ static int loopback_close(struct snd_pcm
80345 return 0;
80346 }
80347
80348 -static struct snd_pcm_ops loopback_playback_ops = {
80349 +static const struct snd_pcm_ops loopback_playback_ops = {
80350 .open = loopback_open,
80351 .close = loopback_close,
80352 .ioctl = snd_pcm_lib_ioctl,
80353 @@ -742,7 +742,7 @@ static struct snd_pcm_ops loopback_playb
80354 .pointer = loopback_pointer,
80355 };
80356
80357 -static struct snd_pcm_ops loopback_capture_ops = {
80358 +static const struct snd_pcm_ops loopback_capture_ops = {
80359 .open = loopback_open,
80360 .close = loopback_close,
80361 .ioctl = snd_pcm_lib_ioctl,
80362 diff -urNp linux-2.6.39/sound/drivers/dummy.c linux-2.6.39/sound/drivers/dummy.c
80363 --- linux-2.6.39/sound/drivers/dummy.c 2011-05-19 00:06:34.000000000 -0400
80364 +++ linux-2.6.39/sound/drivers/dummy.c 2011-05-22 19:36:35.000000000 -0400
80365 @@ -350,7 +350,7 @@ static void dummy_systimer_free(struct s
80366 kfree(substream->runtime->private_data);
80367 }
80368
80369 -static struct dummy_timer_ops dummy_systimer_ops = {
80370 +static const struct dummy_timer_ops dummy_systimer_ops = {
80371 .create = dummy_systimer_create,
80372 .free = dummy_systimer_free,
80373 .prepare = dummy_systimer_prepare,
80374 @@ -474,7 +474,7 @@ static void dummy_hrtimer_free(struct sn
80375 kfree(dpcm);
80376 }
80377
80378 -static struct dummy_timer_ops dummy_hrtimer_ops = {
80379 +static const struct dummy_timer_ops dummy_hrtimer_ops = {
80380 .create = dummy_hrtimer_create,
80381 .free = dummy_hrtimer_free,
80382 .prepare = dummy_hrtimer_prepare,
80383 @@ -660,7 +660,7 @@ static struct page *dummy_pcm_page(struc
80384 return virt_to_page(dummy_page[substream->stream]); /* the same page */
80385 }
80386
80387 -static struct snd_pcm_ops dummy_pcm_ops = {
80388 +static const struct snd_pcm_ops dummy_pcm_ops = {
80389 .open = dummy_pcm_open,
80390 .close = dummy_pcm_close,
80391 .ioctl = snd_pcm_lib_ioctl,
80392 @@ -671,7 +671,7 @@ static struct snd_pcm_ops dummy_pcm_ops
80393 .pointer = dummy_pcm_pointer,
80394 };
80395
80396 -static struct snd_pcm_ops dummy_pcm_ops_no_buf = {
80397 +static const struct snd_pcm_ops dummy_pcm_ops_no_buf = {
80398 .open = dummy_pcm_open,
80399 .close = dummy_pcm_close,
80400 .ioctl = snd_pcm_lib_ioctl,
80401 @@ -689,7 +689,7 @@ static int __devinit snd_card_dummy_pcm(
80402 int substreams)
80403 {
80404 struct snd_pcm *pcm;
80405 - struct snd_pcm_ops *ops;
80406 + const struct snd_pcm_ops *ops;
80407 int err;
80408
80409 err = snd_pcm_new(dummy->card, "Dummy PCM", device,
80410 diff -urNp linux-2.6.39/sound/drivers/ml403-ac97cr.c linux-2.6.39/sound/drivers/ml403-ac97cr.c
80411 --- linux-2.6.39/sound/drivers/ml403-ac97cr.c 2011-05-19 00:06:34.000000000 -0400
80412 +++ linux-2.6.39/sound/drivers/ml403-ac97cr.c 2011-05-22 19:36:35.000000000 -0400
80413 @@ -759,7 +759,7 @@ static int snd_ml403_ac97cr_capture_clos
80414 return 0;
80415 }
80416
80417 -static struct snd_pcm_ops snd_ml403_ac97cr_playback_ops = {
80418 +static const struct snd_pcm_ops snd_ml403_ac97cr_playback_ops = {
80419 .open = snd_ml403_ac97cr_playback_open,
80420 .close = snd_ml403_ac97cr_playback_close,
80421 .ioctl = snd_pcm_lib_ioctl,
80422 @@ -770,7 +770,7 @@ static struct snd_pcm_ops snd_ml403_ac97
80423 .pointer = snd_ml403_ac97cr_pcm_pointer,
80424 };
80425
80426 -static struct snd_pcm_ops snd_ml403_ac97cr_capture_ops = {
80427 +static const struct snd_pcm_ops snd_ml403_ac97cr_capture_ops = {
80428 .open = snd_ml403_ac97cr_capture_open,
80429 .close = snd_ml403_ac97cr_capture_close,
80430 .ioctl = snd_pcm_lib_ioctl,
80431 @@ -1114,7 +1114,7 @@ snd_ml403_ac97cr_create(struct snd_card
80432 {
80433 struct snd_ml403_ac97cr *ml403_ac97cr;
80434 int err;
80435 - static struct snd_device_ops ops = {
80436 + static const struct snd_device_ops ops = {
80437 .dev_free = snd_ml403_ac97cr_dev_free,
80438 };
80439 struct resource *resource;
80440 @@ -1210,7 +1210,7 @@ snd_ml403_ac97cr_mixer(struct snd_ml403_
80441 struct snd_ac97_bus *bus;
80442 struct snd_ac97_template ac97;
80443 int err;
80444 - static struct snd_ac97_bus_ops ops = {
80445 + static const struct snd_ac97_bus_ops ops = {
80446 .write = snd_ml403_ac97cr_codec_write,
80447 .read = snd_ml403_ac97cr_codec_read,
80448 };
80449 diff -urNp linux-2.6.39/sound/drivers/mtpav.c linux-2.6.39/sound/drivers/mtpav.c
80450 --- linux-2.6.39/sound/drivers/mtpav.c 2011-05-19 00:06:34.000000000 -0400
80451 +++ linux-2.6.39/sound/drivers/mtpav.c 2011-05-22 19:36:35.000000000 -0400
80452 @@ -601,13 +601,13 @@ static int __devinit snd_mtpav_get_ISA(s
80453 /*
80454 */
80455
80456 -static struct snd_rawmidi_ops snd_mtpav_output = {
80457 +static const struct snd_rawmidi_ops snd_mtpav_output = {
80458 .open = snd_mtpav_output_open,
80459 .close = snd_mtpav_output_close,
80460 .trigger = snd_mtpav_output_trigger,
80461 };
80462
80463 -static struct snd_rawmidi_ops snd_mtpav_input = {
80464 +static const struct snd_rawmidi_ops snd_mtpav_input = {
80465 .open = snd_mtpav_input_open,
80466 .close = snd_mtpav_input_close,
80467 .trigger = snd_mtpav_input_trigger,
80468 diff -urNp linux-2.6.39/sound/drivers/mts64.c linux-2.6.39/sound/drivers/mts64.c
80469 --- linux-2.6.39/sound/drivers/mts64.c 2011-05-19 00:06:34.000000000 -0400
80470 +++ linux-2.6.39/sound/drivers/mts64.c 2011-05-22 19:36:35.000000000 -0400
80471 @@ -28,6 +28,7 @@
80472 #include <sound/initval.h>
80473 #include <sound/rawmidi.h>
80474 #include <sound/control.h>
80475 +#include <asm/local.h>
80476
80477 #define CARD_NAME "Miditerminal 4140"
80478 #define DRIVER_NAME "MTS64"
80479 @@ -66,7 +67,7 @@ struct mts64 {
80480 struct pardevice *pardev;
80481 int pardev_claimed;
80482
80483 - int open_count;
80484 + local_t open_count;
80485 int current_midi_output_port;
80486 int current_midi_input_port;
80487 u8 mode[MTS64_NUM_INPUT_PORTS];
80488 @@ -696,7 +697,7 @@ static int snd_mts64_rawmidi_open(struct
80489 {
80490 struct mts64 *mts = substream->rmidi->private_data;
80491
80492 - if (mts->open_count == 0) {
80493 + if (local_read(&mts->open_count) == 0) {
80494 /* We don't need a spinlock here, because this is just called
80495 if the device has not been opened before.
80496 So there aren't any IRQs from the device */
80497 @@ -704,7 +705,7 @@ static int snd_mts64_rawmidi_open(struct
80498
80499 msleep(50);
80500 }
80501 - ++(mts->open_count);
80502 + local_inc(&mts->open_count);
80503
80504 return 0;
80505 }
80506 @@ -714,8 +715,7 @@ static int snd_mts64_rawmidi_close(struc
80507 struct mts64 *mts = substream->rmidi->private_data;
80508 unsigned long flags;
80509
80510 - --(mts->open_count);
80511 - if (mts->open_count == 0) {
80512 + if (local_dec_return(&mts->open_count) == 0) {
80513 /* We need the spinlock_irqsave here because we can still
80514 have IRQs at this point */
80515 spin_lock_irqsave(&mts->lock, flags);
80516 @@ -724,8 +724,8 @@ static int snd_mts64_rawmidi_close(struc
80517
80518 msleep(500);
80519
80520 - } else if (mts->open_count < 0)
80521 - mts->open_count = 0;
80522 + } else if (local_read(&mts->open_count) < 0)
80523 + local_set(&mts->open_count, 0);
80524
80525 return 0;
80526 }
80527 @@ -760,13 +760,13 @@ static void snd_mts64_rawmidi_input_trig
80528 spin_unlock_irqrestore(&mts->lock, flags);
80529 }
80530
80531 -static struct snd_rawmidi_ops snd_mts64_rawmidi_output_ops = {
80532 +static const struct snd_rawmidi_ops snd_mts64_rawmidi_output_ops = {
80533 .open = snd_mts64_rawmidi_open,
80534 .close = snd_mts64_rawmidi_close,
80535 .trigger = snd_mts64_rawmidi_output_trigger
80536 };
80537
80538 -static struct snd_rawmidi_ops snd_mts64_rawmidi_input_ops = {
80539 +static const struct snd_rawmidi_ops snd_mts64_rawmidi_input_ops = {
80540 .open = snd_mts64_rawmidi_open,
80541 .close = snd_mts64_rawmidi_close,
80542 .trigger = snd_mts64_rawmidi_input_trigger
80543 diff -urNp linux-2.6.39/sound/drivers/pcsp/pcsp.c linux-2.6.39/sound/drivers/pcsp/pcsp.c
80544 --- linux-2.6.39/sound/drivers/pcsp/pcsp.c 2011-05-19 00:06:34.000000000 -0400
80545 +++ linux-2.6.39/sound/drivers/pcsp/pcsp.c 2011-05-22 19:36:35.000000000 -0400
80546 @@ -41,7 +41,7 @@ struct snd_pcsp pcsp_chip;
80547
80548 static int __devinit snd_pcsp_create(struct snd_card *card)
80549 {
80550 - static struct snd_device_ops ops = { };
80551 + static const struct snd_device_ops ops = { };
80552 struct timespec tp;
80553 int err;
80554 int div, min_div, order;
80555 diff -urNp linux-2.6.39/sound/drivers/pcsp/pcsp_lib.c linux-2.6.39/sound/drivers/pcsp/pcsp_lib.c
80556 --- linux-2.6.39/sound/drivers/pcsp/pcsp_lib.c 2011-05-19 00:06:34.000000000 -0400
80557 +++ linux-2.6.39/sound/drivers/pcsp/pcsp_lib.c 2011-05-22 19:36:35.000000000 -0400
80558 @@ -323,7 +323,7 @@ static int snd_pcsp_playback_open(struct
80559 return 0;
80560 }
80561
80562 -static struct snd_pcm_ops snd_pcsp_playback_ops = {
80563 +static const struct snd_pcm_ops snd_pcsp_playback_ops = {
80564 .open = snd_pcsp_playback_open,
80565 .close = snd_pcsp_playback_close,
80566 .ioctl = snd_pcm_lib_ioctl,
80567 diff -urNp linux-2.6.39/sound/drivers/portman2x4.c linux-2.6.39/sound/drivers/portman2x4.c
80568 --- linux-2.6.39/sound/drivers/portman2x4.c 2011-05-19 00:06:34.000000000 -0400
80569 +++ linux-2.6.39/sound/drivers/portman2x4.c 2011-05-22 19:36:35.000000000 -0400
80570 @@ -47,6 +47,7 @@
80571 #include <sound/initval.h>
80572 #include <sound/rawmidi.h>
80573 #include <sound/control.h>
80574 +#include <asm/local.h>
80575
80576 #define CARD_NAME "Portman 2x4"
80577 #define DRIVER_NAME "portman"
80578 @@ -84,7 +85,7 @@ struct portman {
80579 struct pardevice *pardev;
80580 int pardev_claimed;
80581
80582 - int open_count;
80583 + local_t open_count;
80584 int mode[PORTMAN_NUM_INPUT_PORTS];
80585 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
80586 };
80587 @@ -547,13 +548,13 @@ static void snd_portman_midi_output_trig
80588 spin_unlock_irqrestore(&pm->reg_lock, flags);
80589 }
80590
80591 -static struct snd_rawmidi_ops snd_portman_midi_output = {
80592 +static const struct snd_rawmidi_ops snd_portman_midi_output = {
80593 .open = snd_portman_midi_open,
80594 .close = snd_portman_midi_close,
80595 .trigger = snd_portman_midi_output_trigger,
80596 };
80597
80598 -static struct snd_rawmidi_ops snd_portman_midi_input = {
80599 +static const struct snd_rawmidi_ops snd_portman_midi_input = {
80600 .open = snd_portman_midi_open,
80601 .close = snd_portman_midi_close,
80602 .trigger = snd_portman_midi_input_trigger,
80603 diff -urNp linux-2.6.39/sound/drivers/serial-u16550.c linux-2.6.39/sound/drivers/serial-u16550.c
80604 --- linux-2.6.39/sound/drivers/serial-u16550.c 2011-05-19 00:06:34.000000000 -0400
80605 +++ linux-2.6.39/sound/drivers/serial-u16550.c 2011-05-22 19:36:35.000000000 -0400
80606 @@ -754,15 +754,13 @@ static void snd_uart16550_output_trigger
80607 snd_uart16550_output_write(substream);
80608 }
80609
80610 -static struct snd_rawmidi_ops snd_uart16550_output =
80611 -{
80612 +static const struct snd_rawmidi_ops snd_uart16550_output = {
80613 .open = snd_uart16550_output_open,
80614 .close = snd_uart16550_output_close,
80615 .trigger = snd_uart16550_output_trigger,
80616 };
80617
80618 -static struct snd_rawmidi_ops snd_uart16550_input =
80619 -{
80620 +static const struct snd_rawmidi_ops snd_uart16550_input = {
80621 .open = snd_uart16550_input_open,
80622 .close = snd_uart16550_input_close,
80623 .trigger = snd_uart16550_input_trigger,
80624 @@ -792,7 +790,7 @@ static int __devinit snd_uart16550_creat
80625 int droponfull,
80626 struct snd_uart16550 **ruart)
80627 {
80628 - static struct snd_device_ops ops = {
80629 + static const struct snd_device_ops ops = {
80630 .dev_free = snd_uart16550_dev_free,
80631 };
80632 struct snd_uart16550 *uart;
80633 diff -urNp linux-2.6.39/sound/drivers/vx/vx_pcm.c linux-2.6.39/sound/drivers/vx/vx_pcm.c
80634 --- linux-2.6.39/sound/drivers/vx/vx_pcm.c 2011-05-19 00:06:34.000000000 -0400
80635 +++ linux-2.6.39/sound/drivers/vx/vx_pcm.c 2011-05-22 19:36:35.000000000 -0400
80636 @@ -895,7 +895,7 @@ static int vx_pcm_prepare(struct snd_pcm
80637 /*
80638 * operators for PCM playback
80639 */
80640 -static struct snd_pcm_ops vx_pcm_playback_ops = {
80641 +static const struct snd_pcm_ops vx_pcm_playback_ops = {
80642 .open = vx_pcm_playback_open,
80643 .close = vx_pcm_playback_close,
80644 .ioctl = snd_pcm_lib_ioctl,
80645 @@ -1116,7 +1116,7 @@ static snd_pcm_uframes_t vx_pcm_capture_
80646 /*
80647 * operators for PCM capture
80648 */
80649 -static struct snd_pcm_ops vx_pcm_capture_ops = {
80650 +static const struct snd_pcm_ops vx_pcm_capture_ops = {
80651 .open = vx_pcm_capture_open,
80652 .close = vx_pcm_capture_close,
80653 .ioctl = snd_pcm_lib_ioctl,
80654 diff -urNp linux-2.6.39/sound/firewire/amdtp.c linux-2.6.39/sound/firewire/amdtp.c
80655 --- linux-2.6.39/sound/firewire/amdtp.c 2011-05-19 00:06:34.000000000 -0400
80656 +++ linux-2.6.39/sound/firewire/amdtp.c 2011-05-22 19:36:35.000000000 -0400
80657 @@ -371,7 +371,7 @@ static void queue_out_packet(struct amdt
80658 ptr = s->pcm_buffer_pointer + data_blocks;
80659 if (ptr >= pcm->runtime->buffer_size)
80660 ptr -= pcm->runtime->buffer_size;
80661 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
80662 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
80663
80664 s->pcm_period_pointer += data_blocks;
80665 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
80666 @@ -510,7 +510,7 @@ EXPORT_SYMBOL(amdtp_out_stream_start);
80667 */
80668 void amdtp_out_stream_update(struct amdtp_out_stream *s)
80669 {
80670 - ACCESS_ONCE(s->source_node_id_field) =
80671 + ACCESS_ONCE_RW(s->source_node_id_field) =
80672 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
80673 }
80674 EXPORT_SYMBOL(amdtp_out_stream_update);
80675 diff -urNp linux-2.6.39/sound/firewire/amdtp.h linux-2.6.39/sound/firewire/amdtp.h
80676 --- linux-2.6.39/sound/firewire/amdtp.h 2011-05-19 00:06:34.000000000 -0400
80677 +++ linux-2.6.39/sound/firewire/amdtp.h 2011-05-22 19:36:35.000000000 -0400
80678 @@ -146,7 +146,7 @@ static inline void amdtp_out_stream_pcm_
80679 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
80680 struct snd_pcm_substream *pcm)
80681 {
80682 - ACCESS_ONCE(s->pcm) = pcm;
80683 + ACCESS_ONCE_RW(s->pcm) = pcm;
80684 }
80685
80686 /**
80687 diff -urNp linux-2.6.39/sound/i2c/i2c.c linux-2.6.39/sound/i2c/i2c.c
80688 --- linux-2.6.39/sound/i2c/i2c.c 2011-05-19 00:06:34.000000000 -0400
80689 +++ linux-2.6.39/sound/i2c/i2c.c 2011-05-22 19:36:35.000000000 -0400
80690 @@ -80,7 +80,7 @@ int snd_i2c_bus_create(struct snd_card *
80691 {
80692 struct snd_i2c_bus *bus;
80693 int err;
80694 - static struct snd_device_ops ops = {
80695 + static const struct snd_device_ops ops = {
80696 .dev_free = snd_i2c_bus_dev_free,
80697 };
80698
80699 diff -urNp linux-2.6.39/sound/i2c/other/ak4113.c linux-2.6.39/sound/i2c/other/ak4113.c
80700 --- linux-2.6.39/sound/i2c/other/ak4113.c 2011-05-19 00:06:34.000000000 -0400
80701 +++ linux-2.6.39/sound/i2c/other/ak4113.c 2011-05-22 19:36:35.000000000 -0400
80702 @@ -75,7 +75,7 @@ int snd_ak4113_create(struct snd_card *c
80703 struct ak4113 *chip;
80704 int err = 0;
80705 unsigned char reg;
80706 - static struct snd_device_ops ops = {
80707 + static const struct snd_device_ops ops = {
80708 .dev_free = snd_ak4113_dev_free,
80709 };
80710
80711 diff -urNp linux-2.6.39/sound/i2c/other/ak4114.c linux-2.6.39/sound/i2c/other/ak4114.c
80712 --- linux-2.6.39/sound/i2c/other/ak4114.c 2011-05-19 00:06:34.000000000 -0400
80713 +++ linux-2.6.39/sound/i2c/other/ak4114.c 2011-05-22 19:36:35.000000000 -0400
80714 @@ -86,7 +86,7 @@ int snd_ak4114_create(struct snd_card *c
80715 struct ak4114 *chip;
80716 int err = 0;
80717 unsigned char reg;
80718 - static struct snd_device_ops ops = {
80719 + static const struct snd_device_ops ops = {
80720 .dev_free = snd_ak4114_dev_free,
80721 };
80722
80723 diff -urNp linux-2.6.39/sound/i2c/other/ak4117.c linux-2.6.39/sound/i2c/other/ak4117.c
80724 --- linux-2.6.39/sound/i2c/other/ak4117.c 2011-05-19 00:06:34.000000000 -0400
80725 +++ linux-2.6.39/sound/i2c/other/ak4117.c 2011-05-22 19:36:35.000000000 -0400
80726 @@ -78,7 +78,7 @@ int snd_ak4117_create(struct snd_card *c
80727 struct ak4117 *chip;
80728 int err = 0;
80729 unsigned char reg;
80730 - static struct snd_device_ops ops = {
80731 + static const struct snd_device_ops ops = {
80732 .dev_free = snd_ak4117_dev_free,
80733 };
80734
80735 diff -urNp linux-2.6.39/sound/isa/ad1816a/ad1816a_lib.c linux-2.6.39/sound/isa/ad1816a/ad1816a_lib.c
80736 --- linux-2.6.39/sound/isa/ad1816a/ad1816a_lib.c 2011-05-19 00:06:34.000000000 -0400
80737 +++ linux-2.6.39/sound/isa/ad1816a/ad1816a_lib.c 2011-05-22 19:36:35.000000000 -0400
80738 @@ -575,7 +575,7 @@ int __devinit snd_ad1816a_create(struct
80739 unsigned long port, int irq, int dma1, int dma2,
80740 struct snd_ad1816a **rchip)
80741 {
80742 - static struct snd_device_ops ops = {
80743 + static const struct snd_device_ops ops = {
80744 .dev_free = snd_ad1816a_dev_free,
80745 };
80746 int error;
80747 diff -urNp linux-2.6.39/sound/isa/es1688/es1688_lib.c linux-2.6.39/sound/isa/es1688/es1688_lib.c
80748 --- linux-2.6.39/sound/isa/es1688/es1688_lib.c 2011-05-19 00:06:34.000000000 -0400
80749 +++ linux-2.6.39/sound/isa/es1688/es1688_lib.c 2011-05-22 19:36:35.000000000 -0400
80750 @@ -646,7 +646,7 @@ int snd_es1688_create(struct snd_card *c
80751 int dma8,
80752 unsigned short hardware)
80753 {
80754 - static struct snd_device_ops ops = {
80755 + static const struct snd_device_ops ops = {
80756 .dev_free = snd_es1688_dev_free,
80757 };
80758
80759 diff -urNp linux-2.6.39/sound/isa/es18xx.c linux-2.6.39/sound/isa/es18xx.c
80760 --- linux-2.6.39/sound/isa/es18xx.c 2011-05-19 00:06:34.000000000 -0400
80761 +++ linux-2.6.39/sound/isa/es18xx.c 2011-05-22 19:36:35.000000000 -0400
80762 @@ -1658,7 +1658,7 @@ static int __devinit snd_es18xx_probe(st
80763 return snd_es18xx_initialize(chip, mpu_port, fm_port);
80764 }
80765
80766 -static struct snd_pcm_ops snd_es18xx_playback_ops = {
80767 +static const struct snd_pcm_ops snd_es18xx_playback_ops = {
80768 .open = snd_es18xx_playback_open,
80769 .close = snd_es18xx_playback_close,
80770 .ioctl = snd_pcm_lib_ioctl,
80771 @@ -1669,7 +1669,7 @@ static struct snd_pcm_ops snd_es18xx_pla
80772 .pointer = snd_es18xx_playback_pointer,
80773 };
80774
80775 -static struct snd_pcm_ops snd_es18xx_capture_ops = {
80776 +static const struct snd_pcm_ops snd_es18xx_capture_ops = {
80777 .open = snd_es18xx_capture_open,
80778 .close = snd_es18xx_capture_close,
80779 .ioctl = snd_pcm_lib_ioctl,
80780 @@ -1784,7 +1784,7 @@ static int __devinit snd_es18xx_new_devi
80781 int irq, int dma1, int dma2)
80782 {
80783 struct snd_es18xx *chip = card->private_data;
80784 - static struct snd_device_ops ops = {
80785 + static const struct snd_device_ops ops = {
80786 .dev_free = snd_es18xx_dev_free,
80787 };
80788 int err;
80789 diff -urNp linux-2.6.39/sound/isa/gus/gus_main.c linux-2.6.39/sound/isa/gus/gus_main.c
80790 --- linux-2.6.39/sound/isa/gus/gus_main.c 2011-05-19 00:06:34.000000000 -0400
80791 +++ linux-2.6.39/sound/isa/gus/gus_main.c 2011-05-22 19:36:35.000000000 -0400
80792 @@ -139,7 +139,7 @@ int snd_gus_create(struct snd_card *card
80793 {
80794 struct snd_gus_card *gus;
80795 int err;
80796 - static struct snd_device_ops ops = {
80797 + static const struct snd_device_ops ops = {
80798 .dev_free = snd_gus_dev_free,
80799 };
80800
80801 diff -urNp linux-2.6.39/sound/isa/msnd/msnd.c linux-2.6.39/sound/isa/msnd/msnd.c
80802 --- linux-2.6.39/sound/isa/msnd/msnd.c 2011-05-19 00:06:34.000000000 -0400
80803 +++ linux-2.6.39/sound/isa/msnd/msnd.c 2011-05-22 19:36:35.000000000 -0400
80804 @@ -570,7 +570,7 @@ snd_msnd_playback_pointer(struct snd_pcm
80805 }
80806
80807
80808 -static struct snd_pcm_ops snd_msnd_playback_ops = {
80809 +static const struct snd_pcm_ops snd_msnd_playback_ops = {
80810 .open = snd_msnd_playback_open,
80811 .close = snd_msnd_playback_close,
80812 .ioctl = snd_pcm_lib_ioctl,
80813 @@ -667,7 +667,7 @@ static int snd_msnd_capture_hw_params(st
80814 }
80815
80816
80817 -static struct snd_pcm_ops snd_msnd_capture_ops = {
80818 +static const struct snd_pcm_ops snd_msnd_capture_ops = {
80819 .open = snd_msnd_capture_open,
80820 .close = snd_msnd_capture_close,
80821 .ioctl = snd_pcm_lib_ioctl,
80822 diff -urNp linux-2.6.39/sound/isa/msnd/msnd_midi.c linux-2.6.39/sound/isa/msnd/msnd_midi.c
80823 --- linux-2.6.39/sound/isa/msnd/msnd_midi.c 2011-05-19 00:06:34.000000000 -0400
80824 +++ linux-2.6.39/sound/isa/msnd/msnd_midi.c 2011-05-22 19:36:35.000000000 -0400
80825 @@ -141,7 +141,7 @@ void snd_msndmidi_input_read(void *mpuv)
80826 }
80827 EXPORT_SYMBOL(snd_msndmidi_input_read);
80828
80829 -static struct snd_rawmidi_ops snd_msndmidi_input = {
80830 +static const struct snd_rawmidi_ops snd_msndmidi_input = {
80831 .open = snd_msndmidi_input_open,
80832 .close = snd_msndmidi_input_close,
80833 .trigger = snd_msndmidi_input_trigger,
80834 diff -urNp linux-2.6.39/sound/isa/msnd/msnd_pinnacle.c linux-2.6.39/sound/isa/msnd/msnd_pinnacle.c
80835 --- linux-2.6.39/sound/isa/msnd/msnd_pinnacle.c 2011-05-19 00:06:34.000000000 -0400
80836 +++ linux-2.6.39/sound/isa/msnd/msnd_pinnacle.c 2011-05-22 19:36:35.000000000 -0400
80837 @@ -539,7 +539,7 @@ static int __devinit snd_msnd_attach(str
80838 {
80839 struct snd_msnd *chip = card->private_data;
80840 int err;
80841 - static struct snd_device_ops ops = {
80842 + static const struct snd_device_ops ops = {
80843 .dev_free = snd_msnd_dev_free,
80844 };
80845
80846 diff -urNp linux-2.6.39/sound/isa/sb/emu8000.c linux-2.6.39/sound/isa/sb/emu8000.c
80847 --- linux-2.6.39/sound/isa/sb/emu8000.c 2011-05-19 00:06:34.000000000 -0400
80848 +++ linux-2.6.39/sound/isa/sb/emu8000.c 2011-05-22 19:36:35.000000000 -0400
80849 @@ -1079,7 +1079,7 @@ snd_emu8000_new(struct snd_card *card, i
80850 struct snd_seq_device *awe;
80851 struct snd_emu8000 *hw;
80852 int err;
80853 - static struct snd_device_ops ops = {
80854 + static const struct snd_device_ops ops = {
80855 .dev_free = snd_emu8000_dev_free,
80856 };
80857
80858 diff -urNp linux-2.6.39/sound/isa/sb/emu8000_pcm.c linux-2.6.39/sound/isa/sb/emu8000_pcm.c
80859 --- linux-2.6.39/sound/isa/sb/emu8000_pcm.c 2011-05-19 00:06:34.000000000 -0400
80860 +++ linux-2.6.39/sound/isa/sb/emu8000_pcm.c 2011-05-22 19:36:35.000000000 -0400
80861 @@ -667,7 +667,7 @@ static snd_pcm_uframes_t emu8k_pcm_point
80862 }
80863
80864
80865 -static struct snd_pcm_ops emu8k_pcm_ops = {
80866 +static const struct snd_pcm_ops emu8k_pcm_ops = {
80867 .open = emu8k_pcm_open,
80868 .close = emu8k_pcm_close,
80869 .ioctl = snd_pcm_lib_ioctl,
80870 diff -urNp linux-2.6.39/sound/isa/sb/sb_common.c linux-2.6.39/sound/isa/sb/sb_common.c
80871 --- linux-2.6.39/sound/isa/sb/sb_common.c 2011-05-19 00:06:34.000000000 -0400
80872 +++ linux-2.6.39/sound/isa/sb/sb_common.c 2011-05-22 19:36:35.000000000 -0400
80873 @@ -218,7 +218,7 @@ int snd_sbdsp_create(struct snd_card *ca
80874 {
80875 struct snd_sb *chip;
80876 int err;
80877 - static struct snd_device_ops ops = {
80878 + static const struct snd_device_ops ops = {
80879 .dev_free = snd_sbdsp_dev_free,
80880 };
80881
80882 diff -urNp linux-2.6.39/sound/isa/wavefront/wavefront_midi.c linux-2.6.39/sound/isa/wavefront/wavefront_midi.c
80883 --- linux-2.6.39/sound/isa/wavefront/wavefront_midi.c 2011-05-19 00:06:34.000000000 -0400
80884 +++ linux-2.6.39/sound/isa/wavefront/wavefront_midi.c 2011-05-22 19:36:35.000000000 -0400
80885 @@ -561,14 +561,14 @@ snd_wavefront_midi_start (snd_wavefront_
80886 return 0;
80887 }
80888
80889 -struct snd_rawmidi_ops snd_wavefront_midi_output =
80890 +const struct snd_rawmidi_ops snd_wavefront_midi_output =
80891 {
80892 .open = snd_wavefront_midi_output_open,
80893 .close = snd_wavefront_midi_output_close,
80894 .trigger = snd_wavefront_midi_output_trigger,
80895 };
80896
80897 -struct snd_rawmidi_ops snd_wavefront_midi_input =
80898 +const struct snd_rawmidi_ops snd_wavefront_midi_input =
80899 {
80900 .open = snd_wavefront_midi_input_open,
80901 .close = snd_wavefront_midi_input_close,
80902 diff -urNp linux-2.6.39/sound/isa/wss/wss_lib.c linux-2.6.39/sound/isa/wss/wss_lib.c
80903 --- linux-2.6.39/sound/isa/wss/wss_lib.c 2011-05-19 00:06:34.000000000 -0400
80904 +++ linux-2.6.39/sound/isa/wss/wss_lib.c 2011-05-22 19:36:35.000000000 -0400
80905 @@ -1801,7 +1801,7 @@ int snd_wss_create(struct snd_card *card
80906 unsigned short hwshare,
80907 struct snd_wss **rchip)
80908 {
80909 - static struct snd_device_ops ops = {
80910 + static const struct snd_device_ops ops = {
80911 .dev_free = snd_wss_dev_free,
80912 };
80913 struct snd_wss *chip;
80914 diff -urNp linux-2.6.39/sound/mips/au1x00.c linux-2.6.39/sound/mips/au1x00.c
80915 --- linux-2.6.39/sound/mips/au1x00.c 2011-05-19 00:06:34.000000000 -0400
80916 +++ linux-2.6.39/sound/mips/au1x00.c 2011-05-22 19:36:35.000000000 -0400
80917 @@ -416,7 +416,7 @@ snd_au1000_pointer(struct snd_pcm_substr
80918 return bytes_to_frames(runtime,location);
80919 }
80920
80921 -static struct snd_pcm_ops snd_card_au1000_playback_ops = {
80922 +static const struct snd_pcm_ops snd_card_au1000_playback_ops = {
80923 .open = snd_au1000_playback_open,
80924 .close = snd_au1000_playback_close,
80925 .ioctl = snd_pcm_lib_ioctl,
80926 @@ -427,7 +427,7 @@ static struct snd_pcm_ops snd_card_au100
80927 .pointer = snd_au1000_pointer,
80928 };
80929
80930 -static struct snd_pcm_ops snd_card_au1000_capture_ops = {
80931 +static const struct snd_pcm_ops snd_card_au1000_capture_ops = {
80932 .open = snd_au1000_capture_open,
80933 .close = snd_au1000_capture_close,
80934 .ioctl = snd_pcm_lib_ioctl,
80935 @@ -557,7 +557,7 @@ snd_au1000_ac97_new(struct snd_au1000 *a
80936 int err;
80937 struct snd_ac97_bus *pbus;
80938 struct snd_ac97_template ac97;
80939 - static struct snd_ac97_bus_ops ops = {
80940 + static const struct snd_ac97_bus_ops ops = {
80941 .write = snd_au1000_ac97_write,
80942 .read = snd_au1000_ac97_read,
80943 };
80944 diff -urNp linux-2.6.39/sound/mips/hal2.c linux-2.6.39/sound/mips/hal2.c
80945 --- linux-2.6.39/sound/mips/hal2.c 2011-05-19 00:06:34.000000000 -0400
80946 +++ linux-2.6.39/sound/mips/hal2.c 2011-05-22 19:36:35.000000000 -0400
80947 @@ -708,7 +708,7 @@ static int hal2_capture_ack(struct snd_p
80948 return 0;
80949 }
80950
80951 -static struct snd_pcm_ops hal2_playback_ops = {
80952 +static const struct snd_pcm_ops hal2_playback_ops = {
80953 .open = hal2_playback_open,
80954 .close = hal2_playback_close,
80955 .ioctl = snd_pcm_lib_ioctl,
80956 @@ -720,7 +720,7 @@ static struct snd_pcm_ops hal2_playback_
80957 .ack = hal2_playback_ack,
80958 };
80959
80960 -static struct snd_pcm_ops hal2_capture_ops = {
80961 +static const struct snd_pcm_ops hal2_capture_ops = {
80962 .open = hal2_capture_open,
80963 .close = hal2_capture_close,
80964 .ioctl = snd_pcm_lib_ioctl,
80965 @@ -766,7 +766,7 @@ static int hal2_dev_free(struct snd_devi
80966 return 0;
80967 }
80968
80969 -static struct snd_device_ops hal2_ops = {
80970 +static const struct snd_device_ops hal2_ops = {
80971 .dev_free = hal2_dev_free,
80972 };
80973
80974 diff -urNp linux-2.6.39/sound/mips/sgio2audio.c linux-2.6.39/sound/mips/sgio2audio.c
80975 --- linux-2.6.39/sound/mips/sgio2audio.c 2011-05-19 00:06:34.000000000 -0400
80976 +++ linux-2.6.39/sound/mips/sgio2audio.c 2011-05-22 19:36:35.000000000 -0400
80977 @@ -681,7 +681,7 @@ snd_sgio2audio_pcm_pointer(struct snd_pc
80978 }
80979
80980 /* operators */
80981 -static struct snd_pcm_ops snd_sgio2audio_playback1_ops = {
80982 +static const struct snd_pcm_ops snd_sgio2audio_playback1_ops = {
80983 .open = snd_sgio2audio_playback1_open,
80984 .close = snd_sgio2audio_pcm_close,
80985 .ioctl = snd_pcm_lib_ioctl,
80986 @@ -694,7 +694,7 @@ static struct snd_pcm_ops snd_sgio2audio
80987 .mmap = snd_pcm_lib_mmap_vmalloc,
80988 };
80989
80990 -static struct snd_pcm_ops snd_sgio2audio_playback2_ops = {
80991 +static const struct snd_pcm_ops snd_sgio2audio_playback2_ops = {
80992 .open = snd_sgio2audio_playback2_open,
80993 .close = snd_sgio2audio_pcm_close,
80994 .ioctl = snd_pcm_lib_ioctl,
80995 @@ -707,7 +707,7 @@ static struct snd_pcm_ops snd_sgio2audio
80996 .mmap = snd_pcm_lib_mmap_vmalloc,
80997 };
80998
80999 -static struct snd_pcm_ops snd_sgio2audio_capture_ops = {
81000 +static const struct snd_pcm_ops snd_sgio2audio_capture_ops = {
81001 .open = snd_sgio2audio_capture_open,
81002 .close = snd_sgio2audio_pcm_close,
81003 .ioctl = snd_pcm_lib_ioctl,
81004 @@ -829,7 +829,7 @@ static int snd_sgio2audio_dev_free(struc
81005 return snd_sgio2audio_free(chip);
81006 }
81007
81008 -static struct snd_device_ops ops = {
81009 +static const struct snd_device_ops ops = {
81010 .dev_free = snd_sgio2audio_dev_free,
81011 };
81012
81013 diff -urNp linux-2.6.39/sound/oss/ac97_codec.c linux-2.6.39/sound/oss/ac97_codec.c
81014 --- linux-2.6.39/sound/oss/ac97_codec.c 2011-05-19 00:06:34.000000000 -0400
81015 +++ linux-2.6.39/sound/oss/ac97_codec.c 2011-05-22 19:36:35.000000000 -0400
81016 @@ -99,23 +99,23 @@ static int generic_digital_control(struc
81017 * operations yet
81018 */
81019
81020 -static struct ac97_ops null_ops = { NULL, NULL, NULL };
81021 -static struct ac97_ops default_ops = { NULL, eapd_control, NULL };
81022 -static struct ac97_ops default_digital_ops = { NULL, eapd_control, generic_digital_control};
81023 -static struct ac97_ops wolfson_ops03 = { wolfson_init03, NULL, NULL };
81024 -static struct ac97_ops wolfson_ops04 = { wolfson_init04, NULL, NULL };
81025 -static struct ac97_ops wolfson_ops05 = { wolfson_init05, NULL, NULL };
81026 -static struct ac97_ops wolfson_ops11 = { wolfson_init11, NULL, NULL };
81027 -static struct ac97_ops wolfson_ops13 = { wolfson_init13, NULL, NULL };
81028 -static struct ac97_ops tritech_ops = { tritech_init, NULL, NULL };
81029 -static struct ac97_ops tritech_m_ops = { tritech_maestro_init, NULL, NULL };
81030 -static struct ac97_ops sigmatel_9708_ops = { sigmatel_9708_init, NULL, NULL };
81031 -static struct ac97_ops sigmatel_9721_ops = { sigmatel_9721_init, NULL, NULL };
81032 -static struct ac97_ops sigmatel_9744_ops = { sigmatel_9744_init, NULL, NULL };
81033 -static struct ac97_ops crystal_digital_ops = { NULL, eapd_control, crystal_digital_control };
81034 -static struct ac97_ops ad1886_ops = { ad1886_init, eapd_control, NULL };
81035 -static struct ac97_ops cmedia_ops = { NULL, eapd_control, NULL};
81036 -static struct ac97_ops cmedia_digital_ops = { cmedia_init, eapd_control, cmedia_digital_control};
81037 +static const struct ac97_ops null_ops = { NULL, NULL, NULL };
81038 +static const struct ac97_ops default_ops = { NULL, eapd_control, NULL };
81039 +static const struct ac97_ops default_digital_ops = { NULL, eapd_control, generic_digital_control};
81040 +static const struct ac97_ops wolfson_ops03 = { wolfson_init03, NULL, NULL };
81041 +static const struct ac97_ops wolfson_ops04 = { wolfson_init04, NULL, NULL };
81042 +static const struct ac97_ops wolfson_ops05 = { wolfson_init05, NULL, NULL };
81043 +static const struct ac97_ops wolfson_ops11 = { wolfson_init11, NULL, NULL };
81044 +static const struct ac97_ops wolfson_ops13 = { wolfson_init13, NULL, NULL };
81045 +static const struct ac97_ops tritech_ops = { tritech_init, NULL, NULL };
81046 +static const struct ac97_ops tritech_m_ops = { tritech_maestro_init, NULL, NULL };
81047 +static const struct ac97_ops sigmatel_9708_ops = { sigmatel_9708_init, NULL, NULL };
81048 +static const struct ac97_ops sigmatel_9721_ops = { sigmatel_9721_init, NULL, NULL };
81049 +static const struct ac97_ops sigmatel_9744_ops = { sigmatel_9744_init, NULL, NULL };
81050 +static const struct ac97_ops crystal_digital_ops = { NULL, eapd_control, crystal_digital_control };
81051 +static const struct ac97_ops ad1886_ops = { ad1886_init, eapd_control, NULL };
81052 +static const struct ac97_ops cmedia_ops = { NULL, eapd_control, NULL};
81053 +static const struct ac97_ops cmedia_digital_ops = { cmedia_init, eapd_control, cmedia_digital_control};
81054
81055 /* sorted by vendor/device id */
81056 static const struct {
81057 diff -urNp linux-2.6.39/sound/oss/sb_audio.c linux-2.6.39/sound/oss/sb_audio.c
81058 --- linux-2.6.39/sound/oss/sb_audio.c 2011-05-19 00:06:34.000000000 -0400
81059 +++ linux-2.6.39/sound/oss/sb_audio.c 2011-05-22 19:36:35.000000000 -0400
81060 @@ -901,7 +901,7 @@ sb16_copy_from_user(int dev,
81061 buf16 = (signed short *)(localbuf + localoffs);
81062 while (c)
81063 {
81064 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
81065 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
81066 if (copy_from_user(lbuf8,
81067 userbuf+useroffs + p,
81068 locallen))
81069 diff -urNp linux-2.6.39/sound/oss/swarm_cs4297a.c linux-2.6.39/sound/oss/swarm_cs4297a.c
81070 --- linux-2.6.39/sound/oss/swarm_cs4297a.c 2011-05-19 00:06:34.000000000 -0400
81071 +++ linux-2.6.39/sound/oss/swarm_cs4297a.c 2011-05-22 19:36:35.000000000 -0400
81072 @@ -2606,7 +2606,6 @@ static int __init cs4297a_init(void)
81073 {
81074 struct cs4297a_state *s;
81075 u32 pwr, id;
81076 - mm_segment_t fs;
81077 int rval;
81078 #ifndef CONFIG_BCM_CS4297A_CSWARM
81079 u64 cfg;
81080 @@ -2696,22 +2695,23 @@ static int __init cs4297a_init(void)
81081 if (!rval) {
81082 char *sb1250_duart_present;
81083
81084 +#if 0
81085 + mm_segment_t fs;
81086 fs = get_fs();
81087 set_fs(KERNEL_DS);
81088 -#if 0
81089 val = SOUND_MASK_LINE;
81090 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
81091 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
81092 val = initvol[i].vol;
81093 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
81094 }
81095 + set_fs(fs);
81096 // cs4297a_write_ac97(s, 0x18, 0x0808);
81097 #else
81098 // cs4297a_write_ac97(s, 0x5e, 0x180);
81099 cs4297a_write_ac97(s, 0x02, 0x0808);
81100 cs4297a_write_ac97(s, 0x18, 0x0808);
81101 #endif
81102 - set_fs(fs);
81103
81104 list_add(&s->list, &cs4297a_devs);
81105
81106 diff -urNp linux-2.6.39/sound/parisc/harmony.c linux-2.6.39/sound/parisc/harmony.c
81107 --- linux-2.6.39/sound/parisc/harmony.c 2011-05-19 00:06:34.000000000 -0400
81108 +++ linux-2.6.39/sound/parisc/harmony.c 2011-05-22 19:36:35.000000000 -0400
81109 @@ -596,7 +596,7 @@ snd_harmony_hw_free(struct snd_pcm_subst
81110 return snd_pcm_lib_free_pages(ss);
81111 }
81112
81113 -static struct snd_pcm_ops snd_harmony_playback_ops = {
81114 +static const struct snd_pcm_ops snd_harmony_playback_ops = {
81115 .open = snd_harmony_playback_open,
81116 .close = snd_harmony_playback_close,
81117 .ioctl = snd_pcm_lib_ioctl,
81118 @@ -607,7 +607,7 @@ static struct snd_pcm_ops snd_harmony_pl
81119 .pointer = snd_harmony_playback_pointer,
81120 };
81121
81122 -static struct snd_pcm_ops snd_harmony_capture_ops = {
81123 +static const struct snd_pcm_ops snd_harmony_capture_ops = {
81124 .open = snd_harmony_capture_open,
81125 .close = snd_harmony_capture_close,
81126 .ioctl = snd_pcm_lib_ioctl,
81127 @@ -922,7 +922,7 @@ snd_harmony_create(struct snd_card *card
81128 {
81129 int err;
81130 struct snd_harmony *h;
81131 - static struct snd_device_ops ops = {
81132 + static const struct snd_device_ops ops = {
81133 .dev_free = snd_harmony_dev_free,
81134 };
81135
81136 diff -urNp linux-2.6.39/sound/pci/ac97/ac97_codec.c linux-2.6.39/sound/pci/ac97/ac97_codec.c
81137 --- linux-2.6.39/sound/pci/ac97/ac97_codec.c 2011-05-19 00:06:34.000000000 -0400
81138 +++ linux-2.6.39/sound/pci/ac97/ac97_codec.c 2011-05-22 19:36:35.000000000 -0400
81139 @@ -1910,12 +1910,12 @@ static int ac97_reset_wait(struct snd_ac
81140 *
81141 * Returns zero if successful, or a negative error code on failure.
81142 */
81143 -int snd_ac97_bus(struct snd_card *card, int num, struct snd_ac97_bus_ops *ops,
81144 +int snd_ac97_bus(struct snd_card *card, int num, const struct snd_ac97_bus_ops *ops,
81145 void *private_data, struct snd_ac97_bus **rbus)
81146 {
81147 int err;
81148 struct snd_ac97_bus *bus;
81149 - static struct snd_device_ops dev_ops = {
81150 + static const struct snd_device_ops dev_ops = {
81151 .dev_free = snd_ac97_bus_dev_free,
81152 };
81153
81154 @@ -2015,7 +2015,7 @@ int snd_ac97_mixer(struct snd_ac97_bus *
81155 unsigned long end_time;
81156 unsigned int reg;
81157 const struct ac97_codec_id *pid;
81158 - static struct snd_device_ops ops = {
81159 + static const struct snd_device_ops ops = {
81160 .dev_free = snd_ac97_dev_free,
81161 .dev_register = snd_ac97_dev_register,
81162 .dev_disconnect = snd_ac97_dev_disconnect,
81163 diff -urNp linux-2.6.39/sound/pci/ad1889.c linux-2.6.39/sound/pci/ad1889.c
81164 --- linux-2.6.39/sound/pci/ad1889.c 2011-05-19 00:06:34.000000000 -0400
81165 +++ linux-2.6.39/sound/pci/ad1889.c 2011-05-22 19:36:35.000000000 -0400
81166 @@ -574,7 +574,7 @@ snd_ad1889_capture_pointer(struct snd_pc
81167 return bytes_to_frames(ss->runtime, ptr);
81168 }
81169
81170 -static struct snd_pcm_ops snd_ad1889_playback_ops = {
81171 +static const struct snd_pcm_ops snd_ad1889_playback_ops = {
81172 .open = snd_ad1889_playback_open,
81173 .close = snd_ad1889_playback_close,
81174 .ioctl = snd_pcm_lib_ioctl,
81175 @@ -585,7 +585,7 @@ static struct snd_pcm_ops snd_ad1889_pla
81176 .pointer = snd_ad1889_playback_pointer,
81177 };
81178
81179 -static struct snd_pcm_ops snd_ad1889_capture_ops = {
81180 +static const struct snd_pcm_ops snd_ad1889_capture_ops = {
81181 .open = snd_ad1889_capture_open,
81182 .close = snd_ad1889_capture_close,
81183 .ioctl = snd_pcm_lib_ioctl,
81184 @@ -809,7 +809,7 @@ snd_ad1889_ac97_init(struct snd_ad1889 *
81185 {
81186 int err;
81187 struct snd_ac97_template ac97;
81188 - static struct snd_ac97_bus_ops ops = {
81189 + static const struct snd_ac97_bus_ops ops = {
81190 .write = snd_ad1889_ac97_write,
81191 .read = snd_ad1889_ac97_read,
81192 };
81193 @@ -899,7 +899,7 @@ snd_ad1889_create(struct snd_card *card,
81194 int err;
81195
81196 struct snd_ad1889 *chip;
81197 - static struct snd_device_ops ops = {
81198 + static const struct snd_device_ops ops = {
81199 .dev_free = snd_ad1889_dev_free,
81200 };
81201
81202 diff -urNp linux-2.6.39/sound/pci/ak4531_codec.c linux-2.6.39/sound/pci/ak4531_codec.c
81203 --- linux-2.6.39/sound/pci/ak4531_codec.c 2011-05-19 00:06:34.000000000 -0400
81204 +++ linux-2.6.39/sound/pci/ak4531_codec.c 2011-05-22 19:36:35.000000000 -0400
81205 @@ -389,7 +389,7 @@ int __devinit snd_ak4531_mixer(struct sn
81206 unsigned int idx;
81207 int err;
81208 struct snd_ak4531 *ak4531;
81209 - static struct snd_device_ops ops = {
81210 + static const struct snd_device_ops ops = {
81211 .dev_free = snd_ak4531_dev_free,
81212 };
81213
81214 diff -urNp linux-2.6.39/sound/pci/ali5451/ali5451.c linux-2.6.39/sound/pci/ali5451/ali5451.c
81215 --- linux-2.6.39/sound/pci/ali5451/ali5451.c 2011-05-19 00:06:34.000000000 -0400
81216 +++ linux-2.6.39/sound/pci/ali5451/ali5451.c 2011-05-22 19:36:35.000000000 -0400
81217 @@ -1847,7 +1847,7 @@ static int __devinit snd_ali_mixer(struc
81218 struct snd_ac97_template ac97;
81219 unsigned int idx;
81220 int i, err;
81221 - static struct snd_ac97_bus_ops ops = {
81222 + static const struct snd_ac97_bus_ops ops = {
81223 .write = snd_ali_codec_write,
81224 .read = snd_ali_codec_read,
81225 };
81226 @@ -2114,7 +2114,7 @@ static int __devinit snd_ali_create(stru
81227 struct snd_ali *codec;
81228 int i, err;
81229 unsigned short cmdw;
81230 - static struct snd_device_ops ops = {
81231 + static const struct snd_device_ops ops = {
81232 .dev_free = snd_ali_dev_free,
81233 };
81234
81235 diff -urNp linux-2.6.39/sound/pci/als300.c linux-2.6.39/sound/pci/als300.c
81236 --- linux-2.6.39/sound/pci/als300.c 2011-05-19 00:06:34.000000000 -0400
81237 +++ linux-2.6.39/sound/pci/als300.c 2011-05-22 19:36:35.000000000 -0400
81238 @@ -319,7 +319,7 @@ static int snd_als300_ac97(struct snd_al
81239 struct snd_ac97_bus *bus;
81240 struct snd_ac97_template ac97;
81241 int err;
81242 - static struct snd_ac97_bus_ops ops = {
81243 + static const struct snd_ac97_bus_ops ops = {
81244 .write = snd_als300_ac97_write,
81245 .read = snd_als300_ac97_read,
81246 };
81247 @@ -589,7 +589,7 @@ static snd_pcm_uframes_t snd_als300_poin
81248 return bytes_to_frames(substream->runtime, current_ptr);
81249 }
81250
81251 -static struct snd_pcm_ops snd_als300_playback_ops = {
81252 +static const struct snd_pcm_ops snd_als300_playback_ops = {
81253 .open = snd_als300_playback_open,
81254 .close = snd_als300_playback_close,
81255 .ioctl = snd_pcm_lib_ioctl,
81256 @@ -600,7 +600,7 @@ static struct snd_pcm_ops snd_als300_pla
81257 .pointer = snd_als300_pointer,
81258 };
81259
81260 -static struct snd_pcm_ops snd_als300_capture_ops = {
81261 +static const struct snd_pcm_ops snd_als300_capture_ops = {
81262 .open = snd_als300_capture_open,
81263 .close = snd_als300_capture_close,
81264 .ioctl = snd_pcm_lib_ioctl,
81265 @@ -680,7 +680,7 @@ static int __devinit snd_als300_create(s
81266 void *irq_handler;
81267 int err;
81268
81269 - static struct snd_device_ops ops = {
81270 + static const struct snd_device_ops ops = {
81271 .dev_free = snd_als300_dev_free,
81272 };
81273 *rchip = NULL;
81274 diff -urNp linux-2.6.39/sound/pci/als4000.c linux-2.6.39/sound/pci/als4000.c
81275 --- linux-2.6.39/sound/pci/als4000.c 2011-05-19 00:06:34.000000000 -0400
81276 +++ linux-2.6.39/sound/pci/als4000.c 2011-05-22 19:36:35.000000000 -0400
81277 @@ -672,7 +672,7 @@ static int snd_als4000_capture_close(str
81278
81279 /******************************************************************/
81280
81281 -static struct snd_pcm_ops snd_als4000_playback_ops = {
81282 +static const struct snd_pcm_ops snd_als4000_playback_ops = {
81283 .open = snd_als4000_playback_open,
81284 .close = snd_als4000_playback_close,
81285 .ioctl = snd_pcm_lib_ioctl,
81286 @@ -683,7 +683,7 @@ static struct snd_pcm_ops snd_als4000_pl
81287 .pointer = snd_als4000_playback_pointer
81288 };
81289
81290 -static struct snd_pcm_ops snd_als4000_capture_ops = {
81291 +static const struct snd_pcm_ops snd_als4000_capture_ops = {
81292 .open = snd_als4000_capture_open,
81293 .close = snd_als4000_capture_close,
81294 .ioctl = snd_pcm_lib_ioctl,
81295 diff -urNp linux-2.6.39/sound/pci/asihpi/asihpi.c linux-2.6.39/sound/pci/asihpi/asihpi.c
81296 --- linux-2.6.39/sound/pci/asihpi/asihpi.c 2011-05-19 00:06:34.000000000 -0400
81297 +++ linux-2.6.39/sound/pci/asihpi/asihpi.c 2011-05-22 19:36:35.000000000 -0400
81298 @@ -1067,7 +1067,7 @@ static int snd_card_asihpi_playback_sile
81299 return 0;
81300 }
81301
81302 -static struct snd_pcm_ops snd_card_asihpi_playback_ops = {
81303 +static const struct snd_pcm_ops snd_card_asihpi_playback_ops = {
81304 .open = snd_card_asihpi_playback_open,
81305 .close = snd_card_asihpi_playback_close,
81306 .ioctl = snd_card_asihpi_playback_ioctl,
81307 @@ -1080,7 +1080,7 @@ static struct snd_pcm_ops snd_card_asihp
81308 .silence = snd_card_asihpi_playback_silence,
81309 };
81310
81311 -static struct snd_pcm_ops snd_card_asihpi_playback_mmap_ops = {
81312 +static const struct snd_pcm_ops snd_card_asihpi_playback_mmap_ops = {
81313 .open = snd_card_asihpi_playback_open,
81314 .close = snd_card_asihpi_playback_close,
81315 .ioctl = snd_card_asihpi_playback_ioctl,
81316 @@ -1268,7 +1268,7 @@ static int snd_card_asihpi_capture_copy(
81317 return 0;
81318 }
81319
81320 -static struct snd_pcm_ops snd_card_asihpi_capture_mmap_ops = {
81321 +static const struct snd_pcm_ops snd_card_asihpi_capture_mmap_ops = {
81322 .open = snd_card_asihpi_capture_open,
81323 .close = snd_card_asihpi_capture_close,
81324 .ioctl = snd_card_asihpi_capture_ioctl,
81325 @@ -1279,7 +1279,7 @@ static struct snd_pcm_ops snd_card_asihp
81326 .pointer = snd_card_asihpi_capture_pointer,
81327 };
81328
81329 -static struct snd_pcm_ops snd_card_asihpi_capture_ops = {
81330 +static const struct snd_pcm_ops snd_card_asihpi_capture_ops = {
81331 .open = snd_card_asihpi_capture_open,
81332 .close = snd_card_asihpi_capture_close,
81333 .ioctl = snd_card_asihpi_capture_ioctl,
81334 diff -urNp linux-2.6.39/sound/pci/atiixp.c linux-2.6.39/sound/pci/atiixp.c
81335 --- linux-2.6.39/sound/pci/atiixp.c 2011-05-19 00:06:34.000000000 -0400
81336 +++ linux-2.6.39/sound/pci/atiixp.c 2011-05-22 19:36:35.000000000 -0400
81337 @@ -1148,7 +1148,7 @@ static int snd_atiixp_spdif_close(struct
81338 }
81339
81340 /* AC97 playback */
81341 -static struct snd_pcm_ops snd_atiixp_playback_ops = {
81342 +static const struct snd_pcm_ops snd_atiixp_playback_ops = {
81343 .open = snd_atiixp_playback_open,
81344 .close = snd_atiixp_playback_close,
81345 .ioctl = snd_pcm_lib_ioctl,
81346 @@ -1160,7 +1160,7 @@ static struct snd_pcm_ops snd_atiixp_pla
81347 };
81348
81349 /* AC97 capture */
81350 -static struct snd_pcm_ops snd_atiixp_capture_ops = {
81351 +static const struct snd_pcm_ops snd_atiixp_capture_ops = {
81352 .open = snd_atiixp_capture_open,
81353 .close = snd_atiixp_capture_close,
81354 .ioctl = snd_pcm_lib_ioctl,
81355 @@ -1172,7 +1172,7 @@ static struct snd_pcm_ops snd_atiixp_cap
81356 };
81357
81358 /* SPDIF playback */
81359 -static struct snd_pcm_ops snd_atiixp_spdif_ops = {
81360 +static const struct snd_pcm_ops snd_atiixp_spdif_ops = {
81361 .open = snd_atiixp_spdif_open,
81362 .close = snd_atiixp_spdif_close,
81363 .ioctl = snd_pcm_lib_ioctl,
81364 @@ -1410,7 +1410,7 @@ static int __devinit snd_atiixp_mixer_ne
81365 struct snd_ac97_template ac97;
81366 int i, err;
81367 int codec_count;
81368 - static struct snd_ac97_bus_ops ops = {
81369 + static const struct snd_ac97_bus_ops ops = {
81370 .write = snd_atiixp_ac97_write,
81371 .read = snd_atiixp_ac97_read,
81372 };
81373 @@ -1590,7 +1590,7 @@ static int __devinit snd_atiixp_create(s
81374 struct pci_dev *pci,
81375 struct atiixp **r_chip)
81376 {
81377 - static struct snd_device_ops ops = {
81378 + static const struct snd_device_ops ops = {
81379 .dev_free = snd_atiixp_dev_free,
81380 };
81381 struct atiixp *chip;
81382 diff -urNp linux-2.6.39/sound/pci/atiixp_modem.c linux-2.6.39/sound/pci/atiixp_modem.c
81383 --- linux-2.6.39/sound/pci/atiixp_modem.c 2011-05-19 00:06:34.000000000 -0400
81384 +++ linux-2.6.39/sound/pci/atiixp_modem.c 2011-05-22 19:36:35.000000000 -0400
81385 @@ -947,7 +947,7 @@ static int snd_atiixp_capture_close(stru
81386
81387
81388 /* AC97 playback */
81389 -static struct snd_pcm_ops snd_atiixp_playback_ops = {
81390 +static const struct snd_pcm_ops snd_atiixp_playback_ops = {
81391 .open = snd_atiixp_playback_open,
81392 .close = snd_atiixp_playback_close,
81393 .ioctl = snd_pcm_lib_ioctl,
81394 @@ -959,7 +959,7 @@ static struct snd_pcm_ops snd_atiixp_pla
81395 };
81396
81397 /* AC97 capture */
81398 -static struct snd_pcm_ops snd_atiixp_capture_ops = {
81399 +static const struct snd_pcm_ops snd_atiixp_capture_ops = {
81400 .open = snd_atiixp_capture_open,
81401 .close = snd_atiixp_capture_close,
81402 .ioctl = snd_pcm_lib_ioctl,
81403 @@ -1067,7 +1067,7 @@ static int __devinit snd_atiixp_mixer_ne
81404 struct snd_ac97_template ac97;
81405 int i, err;
81406 int codec_count;
81407 - static struct snd_ac97_bus_ops ops = {
81408 + static const struct snd_ac97_bus_ops ops = {
81409 .write = snd_atiixp_ac97_write,
81410 .read = snd_atiixp_ac97_read,
81411 };
81412 @@ -1226,7 +1226,7 @@ static int __devinit snd_atiixp_create(s
81413 struct pci_dev *pci,
81414 struct atiixp_modem **r_chip)
81415 {
81416 - static struct snd_device_ops ops = {
81417 + static const struct snd_device_ops ops = {
81418 .dev_free = snd_atiixp_dev_free,
81419 };
81420 struct atiixp_modem *chip;
81421 diff -urNp linux-2.6.39/sound/pci/au88x0/au88x0_pcm.c linux-2.6.39/sound/pci/au88x0/au88x0_pcm.c
81422 --- linux-2.6.39/sound/pci/au88x0/au88x0_pcm.c 2011-05-19 00:06:34.000000000 -0400
81423 +++ linux-2.6.39/sound/pci/au88x0/au88x0_pcm.c 2011-05-22 19:36:35.000000000 -0400
81424 @@ -409,7 +409,7 @@ static snd_pcm_uframes_t snd_vortex_pcm_
81425 }
81426
81427 /* operators */
81428 -static struct snd_pcm_ops snd_vortex_playback_ops = {
81429 +static const struct snd_pcm_ops snd_vortex_playback_ops = {
81430 .open = snd_vortex_pcm_open,
81431 .close = snd_vortex_pcm_close,
81432 .ioctl = snd_pcm_lib_ioctl,
81433 diff -urNp linux-2.6.39/sound/pci/aw2/aw2-alsa.c linux-2.6.39/sound/pci/aw2/aw2-alsa.c
81434 --- linux-2.6.39/sound/pci/aw2/aw2-alsa.c 2011-05-19 00:06:34.000000000 -0400
81435 +++ linux-2.6.39/sound/pci/aw2/aw2-alsa.c 2011-05-22 19:36:35.000000000 -0400
81436 @@ -178,7 +178,7 @@ static struct pci_driver driver = {
81437 };
81438
81439 /* operators for playback PCM alsa interface */
81440 -static struct snd_pcm_ops snd_aw2_playback_ops = {
81441 +static const struct snd_pcm_ops snd_aw2_playback_ops = {
81442 .open = snd_aw2_pcm_playback_open,
81443 .close = snd_aw2_pcm_playback_close,
81444 .ioctl = snd_pcm_lib_ioctl,
81445 @@ -190,7 +190,7 @@ static struct snd_pcm_ops snd_aw2_playba
81446 };
81447
81448 /* operators for capture PCM alsa interface */
81449 -static struct snd_pcm_ops snd_aw2_capture_ops = {
81450 +static const struct snd_pcm_ops snd_aw2_capture_ops = {
81451 .open = snd_aw2_pcm_capture_open,
81452 .close = snd_aw2_pcm_capture_close,
81453 .ioctl = snd_pcm_lib_ioctl,
81454 @@ -263,7 +263,7 @@ static int __devinit snd_aw2_create(stru
81455 {
81456 struct aw2 *chip;
81457 int err;
81458 - static struct snd_device_ops ops = {
81459 + static const struct snd_device_ops ops = {
81460 .dev_free = snd_aw2_dev_free,
81461 };
81462
81463 diff -urNp linux-2.6.39/sound/pci/azt3328.c linux-2.6.39/sound/pci/azt3328.c
81464 --- linux-2.6.39/sound/pci/azt3328.c 2011-05-19 00:06:34.000000000 -0400
81465 +++ linux-2.6.39/sound/pci/azt3328.c 2011-05-22 19:36:35.000000000 -0400
81466 @@ -822,7 +822,7 @@ snd_azf3328_mixer_new(struct snd_azf3328
81467 {
81468 struct snd_ac97_bus *bus;
81469 struct snd_ac97_template ac97;
81470 - static struct snd_ac97_bus_ops ops = {
81471 + static const struct snd_ac97_bus_ops ops = {
81472 .write = snd_azf3328_mixer_ac97_write,
81473 .read = snd_azf3328_mixer_ac97_read,
81474 };
81475 @@ -2179,7 +2179,7 @@ snd_azf3328_pcm_close(struct snd_pcm_sub
81476
81477 /******************************************************************/
81478
81479 -static struct snd_pcm_ops snd_azf3328_playback_ops = {
81480 +static const struct snd_pcm_ops snd_azf3328_playback_ops = {
81481 .open = snd_azf3328_pcm_playback_open,
81482 .close = snd_azf3328_pcm_close,
81483 .ioctl = snd_pcm_lib_ioctl,
81484 @@ -2190,7 +2190,7 @@ static struct snd_pcm_ops snd_azf3328_pl
81485 .pointer = snd_azf3328_pcm_pointer
81486 };
81487
81488 -static struct snd_pcm_ops snd_azf3328_capture_ops = {
81489 +static const struct snd_pcm_ops snd_azf3328_capture_ops = {
81490 .open = snd_azf3328_pcm_capture_open,
81491 .close = snd_azf3328_pcm_close,
81492 .ioctl = snd_pcm_lib_ioctl,
81493 @@ -2201,7 +2201,7 @@ static struct snd_pcm_ops snd_azf3328_ca
81494 .pointer = snd_azf3328_pcm_pointer
81495 };
81496
81497 -static struct snd_pcm_ops snd_azf3328_i2s_out_ops = {
81498 +static const struct snd_pcm_ops snd_azf3328_i2s_out_ops = {
81499 .open = snd_azf3328_pcm_i2s_out_open,
81500 .close = snd_azf3328_pcm_close,
81501 .ioctl = snd_pcm_lib_ioctl,
81502 @@ -2497,7 +2497,7 @@ snd_azf3328_create(struct snd_card *card
81503 {
81504 struct snd_azf3328 *chip;
81505 int err;
81506 - static struct snd_device_ops ops = {
81507 + static const struct snd_device_ops ops = {
81508 .dev_free = snd_azf3328_dev_free,
81509 };
81510 u8 dma_init;
81511 diff -urNp linux-2.6.39/sound/pci/bt87x.c linux-2.6.39/sound/pci/bt87x.c
81512 --- linux-2.6.39/sound/pci/bt87x.c 2011-05-19 00:06:34.000000000 -0400
81513 +++ linux-2.6.39/sound/pci/bt87x.c 2011-05-22 19:36:35.000000000 -0400
81514 @@ -542,7 +542,7 @@ static snd_pcm_uframes_t snd_bt87x_point
81515 return (snd_pcm_uframes_t)bytes_to_frames(runtime, chip->current_line * chip->line_bytes);
81516 }
81517
81518 -static struct snd_pcm_ops snd_bt87x_pcm_ops = {
81519 +static const struct snd_pcm_ops snd_bt87x_pcm_ops = {
81520 .open = snd_bt87x_pcm_open,
81521 .close = snd_bt87x_close,
81522 .ioctl = snd_pcm_lib_ioctl,
81523 @@ -720,7 +720,7 @@ static int __devinit snd_bt87x_create(st
81524 {
81525 struct snd_bt87x *chip;
81526 int err;
81527 - static struct snd_device_ops ops = {
81528 + static const struct snd_device_ops ops = {
81529 .dev_free = snd_bt87x_dev_free
81530 };
81531
81532 diff -urNp linux-2.6.39/sound/pci/ca0106/ca0106_main.c linux-2.6.39/sound/pci/ca0106/ca0106_main.c
81533 --- linux-2.6.39/sound/pci/ca0106/ca0106_main.c 2011-05-19 00:06:34.000000000 -0400
81534 +++ linux-2.6.39/sound/pci/ca0106/ca0106_main.c 2011-05-22 19:36:35.000000000 -0400
81535 @@ -1103,7 +1103,7 @@ snd_ca0106_pcm_pointer_capture(struct sn
81536 }
81537
81538 /* operators */
81539 -static struct snd_pcm_ops snd_ca0106_playback_front_ops = {
81540 +static const struct snd_pcm_ops snd_ca0106_playback_front_ops = {
81541 .open = snd_ca0106_pcm_open_playback_front,
81542 .close = snd_ca0106_pcm_close_playback,
81543 .ioctl = snd_pcm_lib_ioctl,
81544 @@ -1114,7 +1114,7 @@ static struct snd_pcm_ops snd_ca0106_pla
81545 .pointer = snd_ca0106_pcm_pointer_playback,
81546 };
81547
81548 -static struct snd_pcm_ops snd_ca0106_capture_0_ops = {
81549 +static const struct snd_pcm_ops snd_ca0106_capture_0_ops = {
81550 .open = snd_ca0106_pcm_open_0_capture,
81551 .close = snd_ca0106_pcm_close_capture,
81552 .ioctl = snd_pcm_lib_ioctl,
81553 @@ -1125,7 +1125,7 @@ static struct snd_pcm_ops snd_ca0106_cap
81554 .pointer = snd_ca0106_pcm_pointer_capture,
81555 };
81556
81557 -static struct snd_pcm_ops snd_ca0106_capture_1_ops = {
81558 +static const struct snd_pcm_ops snd_ca0106_capture_1_ops = {
81559 .open = snd_ca0106_pcm_open_1_capture,
81560 .close = snd_ca0106_pcm_close_capture,
81561 .ioctl = snd_pcm_lib_ioctl,
81562 @@ -1136,7 +1136,7 @@ static struct snd_pcm_ops snd_ca0106_cap
81563 .pointer = snd_ca0106_pcm_pointer_capture,
81564 };
81565
81566 -static struct snd_pcm_ops snd_ca0106_capture_2_ops = {
81567 +static const struct snd_pcm_ops snd_ca0106_capture_2_ops = {
81568 .open = snd_ca0106_pcm_open_2_capture,
81569 .close = snd_ca0106_pcm_close_capture,
81570 .ioctl = snd_pcm_lib_ioctl,
81571 @@ -1147,7 +1147,7 @@ static struct snd_pcm_ops snd_ca0106_cap
81572 .pointer = snd_ca0106_pcm_pointer_capture,
81573 };
81574
81575 -static struct snd_pcm_ops snd_ca0106_capture_3_ops = {
81576 +static const struct snd_pcm_ops snd_ca0106_capture_3_ops = {
81577 .open = snd_ca0106_pcm_open_3_capture,
81578 .close = snd_ca0106_pcm_close_capture,
81579 .ioctl = snd_pcm_lib_ioctl,
81580 @@ -1158,7 +1158,7 @@ static struct snd_pcm_ops snd_ca0106_cap
81581 .pointer = snd_ca0106_pcm_pointer_capture,
81582 };
81583
81584 -static struct snd_pcm_ops snd_ca0106_playback_center_lfe_ops = {
81585 +static const struct snd_pcm_ops snd_ca0106_playback_center_lfe_ops = {
81586 .open = snd_ca0106_pcm_open_playback_center_lfe,
81587 .close = snd_ca0106_pcm_close_playback,
81588 .ioctl = snd_pcm_lib_ioctl,
81589 @@ -1169,7 +1169,7 @@ static struct snd_pcm_ops snd_ca0106_pla
81590 .pointer = snd_ca0106_pcm_pointer_playback,
81591 };
81592
81593 -static struct snd_pcm_ops snd_ca0106_playback_unknown_ops = {
81594 +static const struct snd_pcm_ops snd_ca0106_playback_unknown_ops = {
81595 .open = snd_ca0106_pcm_open_playback_unknown,
81596 .close = snd_ca0106_pcm_close_playback,
81597 .ioctl = snd_pcm_lib_ioctl,
81598 @@ -1180,7 +1180,7 @@ static struct snd_pcm_ops snd_ca0106_pla
81599 .pointer = snd_ca0106_pcm_pointer_playback,
81600 };
81601
81602 -static struct snd_pcm_ops snd_ca0106_playback_rear_ops = {
81603 +static const struct snd_pcm_ops snd_ca0106_playback_rear_ops = {
81604 .open = snd_ca0106_pcm_open_playback_rear,
81605 .close = snd_ca0106_pcm_close_playback,
81606 .ioctl = snd_pcm_lib_ioctl,
81607 @@ -1223,7 +1223,7 @@ static int snd_ca0106_ac97(struct snd_ca
81608 struct snd_ac97_bus *pbus;
81609 struct snd_ac97_template ac97;
81610 int err;
81611 - static struct snd_ac97_bus_ops ops = {
81612 + static const struct snd_ac97_bus_ops ops = {
81613 .write = snd_ca0106_ac97_write,
81614 .read = snd_ca0106_ac97_read,
81615 };
81616 @@ -1629,7 +1629,7 @@ static int __devinit snd_ca0106_create(i
81617 struct snd_ca0106 *chip;
81618 struct snd_ca0106_details *c;
81619 int err;
81620 - static struct snd_device_ops ops = {
81621 + static const struct snd_device_ops ops = {
81622 .dev_free = snd_ca0106_dev_free,
81623 };
81624
81625 diff -urNp linux-2.6.39/sound/pci/ca0106/ca_midi.c linux-2.6.39/sound/pci/ca0106/ca_midi.c
81626 --- linux-2.6.39/sound/pci/ca0106/ca_midi.c 2011-05-19 00:06:34.000000000 -0400
81627 +++ linux-2.6.39/sound/pci/ca0106/ca_midi.c 2011-05-22 19:36:35.000000000 -0400
81628 @@ -255,15 +255,13 @@ static void ca_midi_output_trigger(struc
81629 }
81630 }
81631
81632 -static struct snd_rawmidi_ops ca_midi_output =
81633 -{
81634 +static const struct snd_rawmidi_ops ca_midi_output = {
81635 .open = ca_midi_output_open,
81636 .close = ca_midi_output_close,
81637 .trigger = ca_midi_output_trigger,
81638 };
81639
81640 -static struct snd_rawmidi_ops ca_midi_input =
81641 -{
81642 +static const struct snd_rawmidi_ops ca_midi_input = {
81643 .open = ca_midi_input_open,
81644 .close = ca_midi_input_close,
81645 .trigger = ca_midi_input_trigger,
81646 diff -urNp linux-2.6.39/sound/pci/cmipci.c linux-2.6.39/sound/pci/cmipci.c
81647 --- linux-2.6.39/sound/pci/cmipci.c 2011-05-19 00:06:34.000000000 -0400
81648 +++ linux-2.6.39/sound/pci/cmipci.c 2011-05-22 19:36:35.000000000 -0400
81649 @@ -1838,7 +1838,7 @@ static int snd_cmipci_capture_spdif_clos
81650 /*
81651 */
81652
81653 -static struct snd_pcm_ops snd_cmipci_playback_ops = {
81654 +static const struct snd_pcm_ops snd_cmipci_playback_ops = {
81655 .open = snd_cmipci_playback_open,
81656 .close = snd_cmipci_playback_close,
81657 .ioctl = snd_pcm_lib_ioctl,
81658 @@ -1849,7 +1849,7 @@ static struct snd_pcm_ops snd_cmipci_pla
81659 .pointer = snd_cmipci_playback_pointer,
81660 };
81661
81662 -static struct snd_pcm_ops snd_cmipci_capture_ops = {
81663 +static const struct snd_pcm_ops snd_cmipci_capture_ops = {
81664 .open = snd_cmipci_capture_open,
81665 .close = snd_cmipci_capture_close,
81666 .ioctl = snd_pcm_lib_ioctl,
81667 @@ -1860,7 +1860,7 @@ static struct snd_pcm_ops snd_cmipci_cap
81668 .pointer = snd_cmipci_capture_pointer,
81669 };
81670
81671 -static struct snd_pcm_ops snd_cmipci_playback2_ops = {
81672 +static const struct snd_pcm_ops snd_cmipci_playback2_ops = {
81673 .open = snd_cmipci_playback2_open,
81674 .close = snd_cmipci_playback2_close,
81675 .ioctl = snd_pcm_lib_ioctl,
81676 @@ -1871,7 +1871,7 @@ static struct snd_pcm_ops snd_cmipci_pla
81677 .pointer = snd_cmipci_capture_pointer, /* channel B */
81678 };
81679
81680 -static struct snd_pcm_ops snd_cmipci_playback_spdif_ops = {
81681 +static const struct snd_pcm_ops snd_cmipci_playback_spdif_ops = {
81682 .open = snd_cmipci_playback_spdif_open,
81683 .close = snd_cmipci_playback_spdif_close,
81684 .ioctl = snd_pcm_lib_ioctl,
81685 @@ -1882,7 +1882,7 @@ static struct snd_pcm_ops snd_cmipci_pla
81686 .pointer = snd_cmipci_playback_pointer,
81687 };
81688
81689 -static struct snd_pcm_ops snd_cmipci_capture_spdif_ops = {
81690 +static const struct snd_pcm_ops snd_cmipci_capture_spdif_ops = {
81691 .open = snd_cmipci_capture_spdif_open,
81692 .close = snd_cmipci_capture_spdif_close,
81693 .ioctl = snd_pcm_lib_ioctl,
81694 @@ -3011,7 +3011,7 @@ static int __devinit snd_cmipci_create(s
81695 {
81696 struct cmipci *cm;
81697 int err;
81698 - static struct snd_device_ops ops = {
81699 + static const struct snd_device_ops ops = {
81700 .dev_free = snd_cmipci_dev_free,
81701 };
81702 unsigned int val;
81703 diff -urNp linux-2.6.39/sound/pci/cs4281.c linux-2.6.39/sound/pci/cs4281.c
81704 --- linux-2.6.39/sound/pci/cs4281.c 2011-05-19 00:06:34.000000000 -0400
81705 +++ linux-2.6.39/sound/pci/cs4281.c 2011-05-22 19:36:35.000000000 -0400
81706 @@ -947,7 +947,7 @@ static int snd_cs4281_capture_close(stru
81707 return 0;
81708 }
81709
81710 -static struct snd_pcm_ops snd_cs4281_playback_ops = {
81711 +static const struct snd_pcm_ops snd_cs4281_playback_ops = {
81712 .open = snd_cs4281_playback_open,
81713 .close = snd_cs4281_playback_close,
81714 .ioctl = snd_pcm_lib_ioctl,
81715 @@ -958,7 +958,7 @@ static struct snd_pcm_ops snd_cs4281_pla
81716 .pointer = snd_cs4281_pointer,
81717 };
81718
81719 -static struct snd_pcm_ops snd_cs4281_capture_ops = {
81720 +static const struct snd_pcm_ops snd_cs4281_capture_ops = {
81721 .open = snd_cs4281_capture_open,
81722 .close = snd_cs4281_capture_close,
81723 .ioctl = snd_pcm_lib_ioctl,
81724 @@ -1098,7 +1098,7 @@ static int __devinit snd_cs4281_mixer(st
81725 struct snd_card *card = chip->card;
81726 struct snd_ac97_template ac97;
81727 int err;
81728 - static struct snd_ac97_bus_ops ops = {
81729 + static const struct snd_ac97_bus_ops ops = {
81730 .write = snd_cs4281_ac97_write,
81731 .read = snd_cs4281_ac97_read,
81732 };
81733 @@ -1343,7 +1343,7 @@ static int __devinit snd_cs4281_create(s
81734 struct cs4281 *chip;
81735 unsigned int tmp;
81736 int err;
81737 - static struct snd_device_ops ops = {
81738 + static const struct snd_device_ops ops = {
81739 .dev_free = snd_cs4281_dev_free,
81740 };
81741
81742 @@ -1765,15 +1765,13 @@ static void snd_cs4281_midi_output_trigg
81743 spin_unlock_irqrestore(&chip->reg_lock, flags);
81744 }
81745
81746 -static struct snd_rawmidi_ops snd_cs4281_midi_output =
81747 -{
81748 +static const struct snd_rawmidi_ops snd_cs4281_midi_output = {
81749 .open = snd_cs4281_midi_output_open,
81750 .close = snd_cs4281_midi_output_close,
81751 .trigger = snd_cs4281_midi_output_trigger,
81752 };
81753
81754 -static struct snd_rawmidi_ops snd_cs4281_midi_input =
81755 -{
81756 +static const struct snd_rawmidi_ops snd_cs4281_midi_input = {
81757 .open = snd_cs4281_midi_input_open,
81758 .close = snd_cs4281_midi_input_close,
81759 .trigger = snd_cs4281_midi_input_trigger,
81760 diff -urNp linux-2.6.39/sound/pci/cs46xx/cs46xx_lib.c linux-2.6.39/sound/pci/cs46xx/cs46xx_lib.c
81761 --- linux-2.6.39/sound/pci/cs46xx/cs46xx_lib.c 2011-05-19 00:06:34.000000000 -0400
81762 +++ linux-2.6.39/sound/pci/cs46xx/cs46xx_lib.c 2011-05-22 19:36:35.000000000 -0400
81763 @@ -3722,7 +3722,7 @@ int __devinit snd_cs46xx_create(struct s
81764 struct snd_cs46xx_region *region;
81765 struct cs_card_type *cp;
81766 u16 ss_card, ss_vendor;
81767 - static struct snd_device_ops ops = {
81768 + static const struct snd_device_ops ops = {
81769 .dev_free = snd_cs46xx_dev_free,
81770 };
81771
81772 diff -urNp linux-2.6.39/sound/pci/cs5530.c linux-2.6.39/sound/pci/cs5530.c
81773 --- linux-2.6.39/sound/pci/cs5530.c 2011-05-19 00:06:34.000000000 -0400
81774 +++ linux-2.6.39/sound/pci/cs5530.c 2011-05-22 19:36:35.000000000 -0400
81775 @@ -107,7 +107,7 @@ static int __devinit snd_cs5530_create(s
81776 void __iomem *mem;
81777 int err;
81778
81779 - static struct snd_device_ops ops = {
81780 + static const struct snd_device_ops ops = {
81781 .dev_free = snd_cs5530_dev_free,
81782 };
81783 *rchip = NULL;
81784 diff -urNp linux-2.6.39/sound/pci/cs5535audio/cs5535audio.c linux-2.6.39/sound/pci/cs5535audio/cs5535audio.c
81785 --- linux-2.6.39/sound/pci/cs5535audio/cs5535audio.c 2011-05-19 00:06:34.000000000 -0400
81786 +++ linux-2.6.39/sound/pci/cs5535audio/cs5535audio.c 2011-05-22 19:36:35.000000000 -0400
81787 @@ -150,7 +150,7 @@ static int __devinit snd_cs5535audio_mix
81788 struct snd_ac97_bus *pbus;
81789 struct snd_ac97_template ac97;
81790 int err;
81791 - static struct snd_ac97_bus_ops ops = {
81792 + static const struct snd_ac97_bus_ops ops = {
81793 .write = snd_cs5535audio_ac97_codec_write,
81794 .read = snd_cs5535audio_ac97_codec_read,
81795 };
81796 @@ -277,7 +277,7 @@ static int __devinit snd_cs5535audio_cre
81797 struct cs5535audio *cs5535au;
81798
81799 int err;
81800 - static struct snd_device_ops ops = {
81801 + static const struct snd_device_ops ops = {
81802 .dev_free = snd_cs5535audio_dev_free,
81803 };
81804
81805 diff -urNp linux-2.6.39/sound/pci/cs5535audio/cs5535audio_pcm.c linux-2.6.39/sound/pci/cs5535audio/cs5535audio_pcm.c
81806 --- linux-2.6.39/sound/pci/cs5535audio/cs5535audio_pcm.c 2011-05-19 00:06:34.000000000 -0400
81807 +++ linux-2.6.39/sound/pci/cs5535audio/cs5535audio_pcm.c 2011-05-22 19:36:35.000000000 -0400
81808 @@ -380,7 +380,7 @@ static int snd_cs5535audio_capture_prepa
81809 substream->runtime->rate);
81810 }
81811
81812 -static struct snd_pcm_ops snd_cs5535audio_playback_ops = {
81813 +static const struct snd_pcm_ops snd_cs5535audio_playback_ops = {
81814 .open = snd_cs5535audio_playback_open,
81815 .close = snd_cs5535audio_playback_close,
81816 .ioctl = snd_pcm_lib_ioctl,
81817 @@ -391,7 +391,7 @@ static struct snd_pcm_ops snd_cs5535audi
81818 .pointer = snd_cs5535audio_pcm_pointer,
81819 };
81820
81821 -static struct snd_pcm_ops snd_cs5535audio_capture_ops = {
81822 +static const struct snd_pcm_ops snd_cs5535audio_capture_ops = {
81823 .open = snd_cs5535audio_capture_open,
81824 .close = snd_cs5535audio_capture_close,
81825 .ioctl = snd_pcm_lib_ioctl,
81826 diff -urNp linux-2.6.39/sound/pci/ctxfi/ctpcm.c linux-2.6.39/sound/pci/ctxfi/ctpcm.c
81827 --- linux-2.6.39/sound/pci/ctxfi/ctpcm.c 2011-05-19 00:06:34.000000000 -0400
81828 +++ linux-2.6.39/sound/pci/ctxfi/ctpcm.c 2011-05-22 19:36:35.000000000 -0400
81829 @@ -370,7 +370,7 @@ ct_pcm_capture_pointer(struct snd_pcm_su
81830 }
81831
81832 /* PCM operators for playback */
81833 -static struct snd_pcm_ops ct_pcm_playback_ops = {
81834 +static const struct snd_pcm_ops ct_pcm_playback_ops = {
81835 .open = ct_pcm_playback_open,
81836 .close = ct_pcm_playback_close,
81837 .ioctl = snd_pcm_lib_ioctl,
81838 @@ -383,7 +383,7 @@ static struct snd_pcm_ops ct_pcm_playbac
81839 };
81840
81841 /* PCM operators for capture */
81842 -static struct snd_pcm_ops ct_pcm_capture_ops = {
81843 +static const struct snd_pcm_ops ct_pcm_capture_ops = {
81844 .open = ct_pcm_capture_open,
81845 .close = ct_pcm_capture_close,
81846 .ioctl = snd_pcm_lib_ioctl,
81847 diff -urNp linux-2.6.39/sound/pci/echoaudio/echoaudio.c linux-2.6.39/sound/pci/echoaudio/echoaudio.c
81848 --- linux-2.6.39/sound/pci/echoaudio/echoaudio.c 2011-05-19 00:06:34.000000000 -0400
81849 +++ linux-2.6.39/sound/pci/echoaudio/echoaudio.c 2011-05-22 19:36:35.000000000 -0400
81850 @@ -831,7 +831,7 @@ static snd_pcm_uframes_t pcm_pointer(str
81851
81852
81853 /* pcm *_ops structures */
81854 -static struct snd_pcm_ops analog_playback_ops = {
81855 +static const struct snd_pcm_ops analog_playback_ops = {
81856 .open = pcm_analog_out_open,
81857 .close = pcm_close,
81858 .ioctl = snd_pcm_lib_ioctl,
81859 @@ -842,7 +842,7 @@ static struct snd_pcm_ops analog_playbac
81860 .pointer = pcm_pointer,
81861 .page = snd_pcm_sgbuf_ops_page,
81862 };
81863 -static struct snd_pcm_ops analog_capture_ops = {
81864 +static const struct snd_pcm_ops analog_capture_ops = {
81865 .open = pcm_analog_in_open,
81866 .close = pcm_close,
81867 .ioctl = snd_pcm_lib_ioctl,
81868 @@ -855,7 +855,7 @@ static struct snd_pcm_ops analog_capture
81869 };
81870 #ifdef ECHOCARD_HAS_DIGITAL_IO
81871 #ifndef ECHOCARD_HAS_VMIXER
81872 -static struct snd_pcm_ops digital_playback_ops = {
81873 +static const struct snd_pcm_ops digital_playback_ops = {
81874 .open = pcm_digital_out_open,
81875 .close = pcm_close,
81876 .ioctl = snd_pcm_lib_ioctl,
81877 @@ -867,7 +867,7 @@ static struct snd_pcm_ops digital_playba
81878 .page = snd_pcm_sgbuf_ops_page,
81879 };
81880 #endif /* !ECHOCARD_HAS_VMIXER */
81881 -static struct snd_pcm_ops digital_capture_ops = {
81882 +static const struct snd_pcm_ops digital_capture_ops = {
81883 .open = pcm_digital_in_open,
81884 .close = pcm_close,
81885 .ioctl = snd_pcm_lib_ioctl,
81886 @@ -1945,7 +1945,7 @@ static __devinit int snd_echo_create(str
81887 struct echoaudio *chip;
81888 int err;
81889 size_t sz;
81890 - static struct snd_device_ops ops = {
81891 + static const struct snd_device_ops ops = {
81892 .dev_free = snd_echo_dev_free,
81893 };
81894
81895 diff -urNp linux-2.6.39/sound/pci/echoaudio/midi.c linux-2.6.39/sound/pci/echoaudio/midi.c
81896 --- linux-2.6.39/sound/pci/echoaudio/midi.c 2011-05-19 00:06:34.000000000 -0400
81897 +++ linux-2.6.39/sound/pci/echoaudio/midi.c 2011-05-22 19:36:35.000000000 -0400
81898 @@ -292,13 +292,13 @@ static int snd_echo_midi_output_close(st
81899
81900
81901
81902 -static struct snd_rawmidi_ops snd_echo_midi_input = {
81903 +static const struct snd_rawmidi_ops snd_echo_midi_input = {
81904 .open = snd_echo_midi_input_open,
81905 .close = snd_echo_midi_input_close,
81906 .trigger = snd_echo_midi_input_trigger,
81907 };
81908
81909 -static struct snd_rawmidi_ops snd_echo_midi_output = {
81910 +static const struct snd_rawmidi_ops snd_echo_midi_output = {
81911 .open = snd_echo_midi_output_open,
81912 .close = snd_echo_midi_output_close,
81913 .trigger = snd_echo_midi_output_trigger,
81914 diff -urNp linux-2.6.39/sound/pci/emu10k1/emu10k1_main.c linux-2.6.39/sound/pci/emu10k1/emu10k1_main.c
81915 --- linux-2.6.39/sound/pci/emu10k1/emu10k1_main.c 2011-05-19 00:06:34.000000000 -0400
81916 +++ linux-2.6.39/sound/pci/emu10k1/emu10k1_main.c 2011-05-22 19:36:35.000000000 -0400
81917 @@ -1722,7 +1722,7 @@ int __devinit snd_emu10k1_create(struct
81918 int is_audigy;
81919 unsigned int silent_page;
81920 const struct snd_emu_chip_details *c;
81921 - static struct snd_device_ops ops = {
81922 + static const struct snd_device_ops ops = {
81923 .dev_free = snd_emu10k1_dev_free,
81924 };
81925
81926 diff -urNp linux-2.6.39/sound/pci/emu10k1/emu10k1x.c linux-2.6.39/sound/pci/emu10k1/emu10k1x.c
81927 --- linux-2.6.39/sound/pci/emu10k1/emu10k1x.c 2011-05-19 00:06:34.000000000 -0400
81928 +++ linux-2.6.39/sound/pci/emu10k1/emu10k1x.c 2011-05-22 19:36:35.000000000 -0400
81929 @@ -543,7 +543,7 @@ snd_emu10k1x_pcm_pointer(struct snd_pcm_
81930 }
81931
81932 /* operators */
81933 -static struct snd_pcm_ops snd_emu10k1x_playback_ops = {
81934 +static const struct snd_pcm_ops snd_emu10k1x_playback_ops = {
81935 .open = snd_emu10k1x_playback_open,
81936 .close = snd_emu10k1x_playback_close,
81937 .ioctl = snd_pcm_lib_ioctl,
81938 @@ -689,7 +689,7 @@ snd_emu10k1x_pcm_pointer_capture(struct
81939 return ptr;
81940 }
81941
81942 -static struct snd_pcm_ops snd_emu10k1x_capture_ops = {
81943 +static const struct snd_pcm_ops snd_emu10k1x_capture_ops = {
81944 .open = snd_emu10k1x_pcm_open_capture,
81945 .close = snd_emu10k1x_pcm_close_capture,
81946 .ioctl = snd_pcm_lib_ioctl,
81947 @@ -731,7 +731,7 @@ static int snd_emu10k1x_ac97(struct emu1
81948 struct snd_ac97_bus *pbus;
81949 struct snd_ac97_template ac97;
81950 int err;
81951 - static struct snd_ac97_bus_ops ops = {
81952 + static const struct snd_ac97_bus_ops ops = {
81953 .write = snd_emu10k1x_ac97_write,
81954 .read = snd_emu10k1x_ac97_read,
81955 };
81956 @@ -888,7 +888,7 @@ static int __devinit snd_emu10k1x_create
81957 struct emu10k1x *chip;
81958 int err;
81959 int ch;
81960 - static struct snd_device_ops ops = {
81961 + static const struct snd_device_ops ops = {
81962 .dev_free = snd_emu10k1x_dev_free,
81963 };
81964
81965 @@ -1465,15 +1465,13 @@ static void snd_emu10k1x_midi_output_tri
81966
81967 */
81968
81969 -static struct snd_rawmidi_ops snd_emu10k1x_midi_output =
81970 -{
81971 +static const struct snd_rawmidi_ops snd_emu10k1x_midi_output = {
81972 .open = snd_emu10k1x_midi_output_open,
81973 .close = snd_emu10k1x_midi_output_close,
81974 .trigger = snd_emu10k1x_midi_output_trigger,
81975 };
81976
81977 -static struct snd_rawmidi_ops snd_emu10k1x_midi_input =
81978 -{
81979 +static const struct snd_rawmidi_ops snd_emu10k1x_midi_input = {
81980 .open = snd_emu10k1x_midi_input_open,
81981 .close = snd_emu10k1x_midi_input_close,
81982 .trigger = snd_emu10k1x_midi_input_trigger,
81983 diff -urNp linux-2.6.39/sound/pci/emu10k1/p16v.c linux-2.6.39/sound/pci/emu10k1/p16v.c
81984 --- linux-2.6.39/sound/pci/emu10k1/p16v.c 2011-05-19 00:06:34.000000000 -0400
81985 +++ linux-2.6.39/sound/pci/emu10k1/p16v.c 2011-05-22 19:36:35.000000000 -0400
81986 @@ -601,7 +601,7 @@ snd_p16v_pcm_pointer_capture(struct snd_
81987 }
81988
81989 /* operators */
81990 -static struct snd_pcm_ops snd_p16v_playback_front_ops = {
81991 +static const struct snd_pcm_ops snd_p16v_playback_front_ops = {
81992 .open = snd_p16v_pcm_open_playback_front,
81993 .close = snd_p16v_pcm_close_playback,
81994 .ioctl = snd_pcm_lib_ioctl,
81995 @@ -612,7 +612,7 @@ static struct snd_pcm_ops snd_p16v_playb
81996 .pointer = snd_p16v_pcm_pointer_playback,
81997 };
81998
81999 -static struct snd_pcm_ops snd_p16v_capture_ops = {
82000 +static const struct snd_pcm_ops snd_p16v_capture_ops = {
82001 .open = snd_p16v_pcm_open_capture,
82002 .close = snd_p16v_pcm_close_capture,
82003 .ioctl = snd_pcm_lib_ioctl,
82004 diff -urNp linux-2.6.39/sound/pci/ens1370.c linux-2.6.39/sound/pci/ens1370.c
82005 --- linux-2.6.39/sound/pci/ens1370.c 2011-05-19 00:06:34.000000000 -0400
82006 +++ linux-2.6.39/sound/pci/ens1370.c 2011-05-22 19:36:35.000000000 -0400
82007 @@ -1225,7 +1225,7 @@ static int snd_ensoniq_capture_close(str
82008 return 0;
82009 }
82010
82011 -static struct snd_pcm_ops snd_ensoniq_playback1_ops = {
82012 +static const struct snd_pcm_ops snd_ensoniq_playback1_ops = {
82013 .open = snd_ensoniq_playback1_open,
82014 .close = snd_ensoniq_playback1_close,
82015 .ioctl = snd_pcm_lib_ioctl,
82016 @@ -1236,7 +1236,7 @@ static struct snd_pcm_ops snd_ensoniq_pl
82017 .pointer = snd_ensoniq_playback1_pointer,
82018 };
82019
82020 -static struct snd_pcm_ops snd_ensoniq_playback2_ops = {
82021 +static const struct snd_pcm_ops snd_ensoniq_playback2_ops = {
82022 .open = snd_ensoniq_playback2_open,
82023 .close = snd_ensoniq_playback2_close,
82024 .ioctl = snd_pcm_lib_ioctl,
82025 @@ -1247,7 +1247,7 @@ static struct snd_pcm_ops snd_ensoniq_pl
82026 .pointer = snd_ensoniq_playback2_pointer,
82027 };
82028
82029 -static struct snd_pcm_ops snd_ensoniq_capture_ops = {
82030 +static const struct snd_pcm_ops snd_ensoniq_capture_ops = {
82031 .open = snd_ensoniq_capture_open,
82032 .close = snd_ensoniq_capture_close,
82033 .ioctl = snd_pcm_lib_ioctl,
82034 @@ -1633,7 +1633,7 @@ static int __devinit snd_ensoniq_1371_mi
82035 struct snd_ac97_bus *pbus;
82036 struct snd_ac97_template ac97;
82037 int err;
82038 - static struct snd_ac97_bus_ops ops = {
82039 + static const struct snd_ac97_bus_ops ops = {
82040 .write = snd_es1371_codec_write,
82041 .read = snd_es1371_codec_read,
82042 .wait = snd_es1371_codec_wait,
82043 @@ -2096,7 +2096,7 @@ static int __devinit snd_ensoniq_create(
82044 {
82045 struct ensoniq *ensoniq;
82046 int err;
82047 - static struct snd_device_ops ops = {
82048 + static const struct snd_device_ops ops = {
82049 .dev_free = snd_ensoniq_dev_free,
82050 };
82051
82052 @@ -2331,15 +2331,13 @@ static void snd_ensoniq_midi_output_trig
82053 spin_unlock_irqrestore(&ensoniq->reg_lock, flags);
82054 }
82055
82056 -static struct snd_rawmidi_ops snd_ensoniq_midi_output =
82057 -{
82058 +static const struct snd_rawmidi_ops snd_ensoniq_midi_output = {
82059 .open = snd_ensoniq_midi_output_open,
82060 .close = snd_ensoniq_midi_output_close,
82061 .trigger = snd_ensoniq_midi_output_trigger,
82062 };
82063
82064 -static struct snd_rawmidi_ops snd_ensoniq_midi_input =
82065 -{
82066 +static const struct snd_rawmidi_ops snd_ensoniq_midi_input = {
82067 .open = snd_ensoniq_midi_input_open,
82068 .close = snd_ensoniq_midi_input_close,
82069 .trigger = snd_ensoniq_midi_input_trigger,
82070 diff -urNp linux-2.6.39/sound/pci/es1938.c linux-2.6.39/sound/pci/es1938.c
82071 --- linux-2.6.39/sound/pci/es1938.c 2011-05-19 00:06:34.000000000 -0400
82072 +++ linux-2.6.39/sound/pci/es1938.c 2011-05-22 19:36:35.000000000 -0400
82073 @@ -1004,7 +1004,7 @@ static int snd_es1938_playback_close(str
82074 return 0;
82075 }
82076
82077 -static struct snd_pcm_ops snd_es1938_playback_ops = {
82078 +static const struct snd_pcm_ops snd_es1938_playback_ops = {
82079 .open = snd_es1938_playback_open,
82080 .close = snd_es1938_playback_close,
82081 .ioctl = snd_pcm_lib_ioctl,
82082 @@ -1015,7 +1015,7 @@ static struct snd_pcm_ops snd_es1938_pla
82083 .pointer = snd_es1938_playback_pointer,
82084 };
82085
82086 -static struct snd_pcm_ops snd_es1938_capture_ops = {
82087 +static const struct snd_pcm_ops snd_es1938_capture_ops = {
82088 .open = snd_es1938_capture_open,
82089 .close = snd_es1938_capture_close,
82090 .ioctl = snd_pcm_lib_ioctl,
82091 @@ -1598,7 +1598,7 @@ static int __devinit snd_es1938_create(s
82092 {
82093 struct es1938 *chip;
82094 int err;
82095 - static struct snd_device_ops ops = {
82096 + static const struct snd_device_ops ops = {
82097 .dev_free = snd_es1938_dev_free,
82098 };
82099
82100 diff -urNp linux-2.6.39/sound/pci/es1968.c linux-2.6.39/sound/pci/es1968.c
82101 --- linux-2.6.39/sound/pci/es1968.c 2011-05-19 00:06:34.000000000 -0400
82102 +++ linux-2.6.39/sound/pci/es1968.c 2011-05-22 19:36:35.000000000 -0400
82103 @@ -1682,7 +1682,7 @@ static int snd_es1968_capture_close(stru
82104 return 0;
82105 }
82106
82107 -static struct snd_pcm_ops snd_es1968_playback_ops = {
82108 +static const struct snd_pcm_ops snd_es1968_playback_ops = {
82109 .open = snd_es1968_playback_open,
82110 .close = snd_es1968_playback_close,
82111 .ioctl = snd_pcm_lib_ioctl,
82112 @@ -1693,7 +1693,7 @@ static struct snd_pcm_ops snd_es1968_pla
82113 .pointer = snd_es1968_pcm_pointer,
82114 };
82115
82116 -static struct snd_pcm_ops snd_es1968_capture_ops = {
82117 +static const struct snd_pcm_ops snd_es1968_capture_ops = {
82118 .open = snd_es1968_capture_open,
82119 .close = snd_es1968_capture_close,
82120 .ioctl = snd_pcm_lib_ioctl,
82121 @@ -2053,7 +2053,7 @@ snd_es1968_mixer(struct es1968 *chip)
82122 struct snd_ctl_elem_id elem_id;
82123 #endif
82124 int err;
82125 - static struct snd_ac97_bus_ops ops = {
82126 + static const struct snd_ac97_bus_ops ops = {
82127 .write = snd_es1968_ac97_write,
82128 .read = snd_es1968_ac97_read,
82129 };
82130 @@ -2627,7 +2627,7 @@ static int __devinit snd_es1968_create(s
82131 int do_pm,
82132 struct es1968 **chip_ret)
82133 {
82134 - static struct snd_device_ops ops = {
82135 + static const struct snd_device_ops ops = {
82136 .dev_free = snd_es1968_dev_free,
82137 };
82138 struct es1968 *chip;
82139 diff -urNp linux-2.6.39/sound/pci/fm801.c linux-2.6.39/sound/pci/fm801.c
82140 --- linux-2.6.39/sound/pci/fm801.c 2011-05-19 00:06:34.000000000 -0400
82141 +++ linux-2.6.39/sound/pci/fm801.c 2011-05-22 19:36:35.000000000 -0400
82142 @@ -662,7 +662,7 @@ static int snd_fm801_capture_close(struc
82143 return 0;
82144 }
82145
82146 -static struct snd_pcm_ops snd_fm801_playback_ops = {
82147 +static const struct snd_pcm_ops snd_fm801_playback_ops = {
82148 .open = snd_fm801_playback_open,
82149 .close = snd_fm801_playback_close,
82150 .ioctl = snd_pcm_lib_ioctl,
82151 @@ -673,7 +673,7 @@ static struct snd_pcm_ops snd_fm801_play
82152 .pointer = snd_fm801_playback_pointer,
82153 };
82154
82155 -static struct snd_pcm_ops snd_fm801_capture_ops = {
82156 +static const struct snd_pcm_ops snd_fm801_capture_ops = {
82157 .open = snd_fm801_capture_open,
82158 .close = snd_fm801_capture_close,
82159 .ioctl = snd_pcm_lib_ioctl,
82160 @@ -1236,7 +1236,7 @@ static int __devinit snd_fm801_mixer(str
82161 struct snd_ac97_template ac97;
82162 unsigned int i;
82163 int err;
82164 - static struct snd_ac97_bus_ops ops = {
82165 + static const struct snd_ac97_bus_ops ops = {
82166 .write = snd_fm801_codec_write,
82167 .read = snd_fm801_codec_read,
82168 };
82169 @@ -1396,7 +1396,7 @@ static int __devinit snd_fm801_create(st
82170 {
82171 struct fm801 *chip;
82172 int err;
82173 - static struct snd_device_ops ops = {
82174 + static const struct snd_device_ops ops = {
82175 .dev_free = snd_fm801_dev_free,
82176 };
82177
82178 diff -urNp linux-2.6.39/sound/pci/hda/hda_generic.c linux-2.6.39/sound/pci/hda/hda_generic.c
82179 --- linux-2.6.39/sound/pci/hda/hda_generic.c 2011-05-19 00:06:34.000000000 -0400
82180 +++ linux-2.6.39/sound/pci/hda/hda_generic.c 2011-05-22 19:36:35.000000000 -0400
82181 @@ -1038,7 +1038,7 @@ static int generic_check_power_status(st
82182
82183 /*
82184 */
82185 -static struct hda_codec_ops generic_patch_ops = {
82186 +static const struct hda_codec_ops generic_patch_ops = {
82187 .build_controls = build_generic_controls,
82188 .build_pcms = build_generic_pcms,
82189 .free = snd_hda_generic_free,
82190 diff -urNp linux-2.6.39/sound/pci/hda/hda_intel.c linux-2.6.39/sound/pci/hda/hda_intel.c
82191 --- linux-2.6.39/sound/pci/hda/hda_intel.c 2011-05-19 00:06:34.000000000 -0400
82192 +++ linux-2.6.39/sound/pci/hda/hda_intel.c 2011-05-22 19:36:35.000000000 -0400
82193 @@ -2452,7 +2452,7 @@ static int __devinit azx_create(struct s
82194 struct azx *chip;
82195 int i, err;
82196 unsigned short gcap;
82197 - static struct snd_device_ops ops = {
82198 + static const struct snd_device_ops ops = {
82199 .dev_free = azx_dev_free,
82200 };
82201
82202 diff -urNp linux-2.6.39/sound/pci/hda/patch_ca0110.c linux-2.6.39/sound/pci/hda/patch_ca0110.c
82203 --- linux-2.6.39/sound/pci/hda/patch_ca0110.c 2011-05-19 00:06:34.000000000 -0400
82204 +++ linux-2.6.39/sound/pci/hda/patch_ca0110.c 2011-05-22 19:36:35.000000000 -0400
82205 @@ -389,7 +389,7 @@ static void ca0110_free(struct hda_codec
82206 kfree(codec->spec);
82207 }
82208
82209 -static struct hda_codec_ops ca0110_patch_ops = {
82210 +static const struct hda_codec_ops ca0110_patch_ops = {
82211 .build_controls = ca0110_build_controls,
82212 .build_pcms = ca0110_build_pcms,
82213 .init = ca0110_init,
82214 diff -urNp linux-2.6.39/sound/pci/hda/patch_cirrus.c linux-2.6.39/sound/pci/hda/patch_cirrus.c
82215 --- linux-2.6.39/sound/pci/hda/patch_cirrus.c 2011-05-19 00:06:34.000000000 -0400
82216 +++ linux-2.6.39/sound/pci/hda/patch_cirrus.c 2011-05-22 19:36:35.000000000 -0400
82217 @@ -1126,7 +1126,7 @@ static void cs_unsol_event(struct hda_co
82218 }
82219 }
82220
82221 -static struct hda_codec_ops cs_patch_ops = {
82222 +static const struct hda_codec_ops cs_patch_ops = {
82223 .build_controls = cs_build_controls,
82224 .build_pcms = cs_build_pcms,
82225 .init = cs_init,
82226 diff -urNp linux-2.6.39/sound/pci/hda/patch_cmedia.c linux-2.6.39/sound/pci/hda/patch_cmedia.c
82227 --- linux-2.6.39/sound/pci/hda/patch_cmedia.c 2011-05-19 00:06:34.000000000 -0400
82228 +++ linux-2.6.39/sound/pci/hda/patch_cmedia.c 2011-05-22 19:36:35.000000000 -0400
82229 @@ -624,7 +624,7 @@ static struct snd_pci_quirk cmi9880_cfg_
82230 {} /* terminator */
82231 };
82232
82233 -static struct hda_codec_ops cmi9880_patch_ops = {
82234 +static const struct hda_codec_ops cmi9880_patch_ops = {
82235 .build_controls = cmi9880_build_controls,
82236 .build_pcms = cmi9880_build_pcms,
82237 .init = cmi9880_init,
82238 diff -urNp linux-2.6.39/sound/pci/hda/patch_conexant.c linux-2.6.39/sound/pci/hda/patch_conexant.c
82239 --- linux-2.6.39/sound/pci/hda/patch_conexant.c 2011-05-19 00:06:34.000000000 -0400
82240 +++ linux-2.6.39/sound/pci/hda/patch_conexant.c 2011-05-22 19:36:35.000000000 -0400
82241 @@ -546,7 +546,7 @@ static int conexant_suspend(struct hda_c
82242 }
82243 #endif
82244
82245 -static struct hda_codec_ops conexant_patch_ops = {
82246 +static const struct hda_codec_ops conexant_patch_ops = {
82247 .build_controls = conexant_build_controls,
82248 .build_pcms = conexant_build_pcms,
82249 .init = conexant_init,
82250 @@ -3791,7 +3791,7 @@ static int cx_auto_build_controls(struct
82251 return conexant_build_controls(codec);
82252 }
82253
82254 -static struct hda_codec_ops cx_auto_patch_ops = {
82255 +static const struct hda_codec_ops cx_auto_patch_ops = {
82256 .build_controls = cx_auto_build_controls,
82257 .build_pcms = conexant_build_pcms,
82258 .init = cx_auto_init,
82259 diff -urNp linux-2.6.39/sound/pci/hda/patch_hdmi.c linux-2.6.39/sound/pci/hda/patch_hdmi.c
82260 --- linux-2.6.39/sound/pci/hda/patch_hdmi.c 2011-05-19 00:06:34.000000000 -0400
82261 +++ linux-2.6.39/sound/pci/hda/patch_hdmi.c 2011-05-22 19:36:35.000000000 -0400
82262 @@ -1124,7 +1124,7 @@ static void generic_hdmi_free(struct hda
82263 kfree(spec);
82264 }
82265
82266 -static struct hda_codec_ops generic_hdmi_patch_ops = {
82267 +static const struct hda_codec_ops generic_hdmi_patch_ops = {
82268 .init = generic_hdmi_init,
82269 .free = generic_hdmi_free,
82270 .build_pcms = generic_hdmi_build_pcms,
82271 @@ -1465,14 +1465,14 @@ static struct hda_pcm_stream nvhdmi_pcm_
82272 },
82273 };
82274
82275 -static struct hda_codec_ops nvhdmi_patch_ops_8ch_7x = {
82276 +static const struct hda_codec_ops nvhdmi_patch_ops_8ch_7x = {
82277 .build_controls = generic_hdmi_build_controls,
82278 .build_pcms = generic_hdmi_build_pcms,
82279 .init = nvhdmi_7x_init,
82280 .free = generic_hdmi_free,
82281 };
82282
82283 -static struct hda_codec_ops nvhdmi_patch_ops_2ch = {
82284 +static const struct hda_codec_ops nvhdmi_patch_ops_2ch = {
82285 .build_controls = generic_hdmi_build_controls,
82286 .build_pcms = generic_hdmi_build_pcms,
82287 .init = nvhdmi_7x_init,
82288 @@ -1599,7 +1599,7 @@ static int atihdmi_init(struct hda_codec
82289 return 0;
82290 }
82291
82292 -static struct hda_codec_ops atihdmi_patch_ops = {
82293 +static const struct hda_codec_ops atihdmi_patch_ops = {
82294 .build_controls = generic_hdmi_build_controls,
82295 .build_pcms = generic_hdmi_build_pcms,
82296 .init = atihdmi_init,
82297 diff -urNp linux-2.6.39/sound/pci/hda/patch_realtek.c linux-2.6.39/sound/pci/hda/patch_realtek.c
82298 --- linux-2.6.39/sound/pci/hda/patch_realtek.c 2011-05-19 00:06:34.000000000 -0400
82299 +++ linux-2.6.39/sound/pci/hda/patch_realtek.c 2011-05-22 19:36:35.000000000 -0400
82300 @@ -4273,7 +4273,7 @@ static int alc_resume(struct hda_codec *
82301
82302 /*
82303 */
82304 -static struct hda_codec_ops alc_patch_ops = {
82305 +static const struct hda_codec_ops alc_patch_ops = {
82306 .build_controls = alc_build_controls,
82307 .build_pcms = alc_build_pcms,
82308 .init = alc_init,
82309 diff -urNp linux-2.6.39/sound/pci/hda/patch_si3054.c linux-2.6.39/sound/pci/hda/patch_si3054.c
82310 --- linux-2.6.39/sound/pci/hda/patch_si3054.c 2011-05-19 00:06:34.000000000 -0400
82311 +++ linux-2.6.39/sound/pci/hda/patch_si3054.c 2011-05-22 19:36:35.000000000 -0400
82312 @@ -263,7 +263,7 @@ static void si3054_free(struct hda_codec
82313 /*
82314 */
82315
82316 -static struct hda_codec_ops si3054_patch_ops = {
82317 +static const struct hda_codec_ops si3054_patch_ops = {
82318 .build_controls = si3054_build_controls,
82319 .build_pcms = si3054_build_pcms,
82320 .init = si3054_init,
82321 diff -urNp linux-2.6.39/sound/pci/hda/patch_sigmatel.c linux-2.6.39/sound/pci/hda/patch_sigmatel.c
82322 --- linux-2.6.39/sound/pci/hda/patch_sigmatel.c 2011-05-19 00:06:34.000000000 -0400
82323 +++ linux-2.6.39/sound/pci/hda/patch_sigmatel.c 2011-05-22 19:36:35.000000000 -0400
82324 @@ -4968,7 +4968,7 @@ static int stac92xx_suspend(struct hda_c
82325 }
82326 #endif
82327
82328 -static struct hda_codec_ops stac92xx_patch_ops = {
82329 +static const struct hda_codec_ops stac92xx_patch_ops = {
82330 .build_controls = stac92xx_build_controls,
82331 .build_pcms = stac92xx_build_pcms,
82332 .init = stac92xx_init,
82333 diff -urNp linux-2.6.39/sound/pci/hda/patch_via.c linux-2.6.39/sound/pci/hda/patch_via.c
82334 --- linux-2.6.39/sound/pci/hda/patch_via.c 2011-05-19 00:06:34.000000000 -0400
82335 +++ linux-2.6.39/sound/pci/hda/patch_via.c 2011-05-22 19:36:35.000000000 -0400
82336 @@ -2254,7 +2254,7 @@ static int via_check_power_status(struct
82337
82338 /*
82339 */
82340 -static struct hda_codec_ops via_patch_ops = {
82341 +static const struct hda_codec_ops via_patch_ops = {
82342 .build_controls = via_build_controls,
82343 .build_pcms = via_build_pcms,
82344 .init = via_init,
82345 diff -urNp linux-2.6.39/sound/pci/ice1712/ice1712.c linux-2.6.39/sound/pci/ice1712/ice1712.c
82346 --- linux-2.6.39/sound/pci/ice1712/ice1712.c 2011-05-19 00:06:34.000000000 -0400
82347 +++ linux-2.6.39/sound/pci/ice1712/ice1712.c 2011-05-22 19:36:35.000000000 -0400
82348 @@ -2541,7 +2541,7 @@ static int __devinit snd_ice1712_create(
82349 {
82350 struct snd_ice1712 *ice;
82351 int err;
82352 - static struct snd_device_ops ops = {
82353 + static const struct snd_device_ops ops = {
82354 .dev_free = snd_ice1712_dev_free,
82355 };
82356
82357 diff -urNp linux-2.6.39/sound/pci/ice1712/ice1724.c linux-2.6.39/sound/pci/ice1712/ice1724.c
82358 --- linux-2.6.39/sound/pci/ice1712/ice1724.c 2011-05-19 00:06:34.000000000 -0400
82359 +++ linux-2.6.39/sound/pci/ice1712/ice1724.c 2011-05-22 19:36:35.000000000 -0400
82360 @@ -367,7 +367,7 @@ static void vt1724_midi_output_drain(str
82361 } while (time_after(timeout, jiffies));
82362 }
82363
82364 -static struct snd_rawmidi_ops vt1724_midi_output_ops = {
82365 +static const struct snd_rawmidi_ops vt1724_midi_output_ops = {
82366 .open = vt1724_midi_output_open,
82367 .close = vt1724_midi_output_close,
82368 .trigger = vt1724_midi_output_trigger,
82369 @@ -402,7 +402,7 @@ static void vt1724_midi_input_trigger(st
82370 spin_unlock_irqrestore(&ice->reg_lock, flags);
82371 }
82372
82373 -static struct snd_rawmidi_ops vt1724_midi_input_ops = {
82374 +static const struct snd_rawmidi_ops vt1724_midi_input_ops = {
82375 .open = vt1724_midi_input_open,
82376 .close = vt1724_midi_input_close,
82377 .trigger = vt1724_midi_input_trigger,
82378 @@ -2463,7 +2463,7 @@ static int __devinit snd_vt1724_create(s
82379 {
82380 struct snd_ice1712 *ice;
82381 int err;
82382 - static struct snd_device_ops ops = {
82383 + static const struct snd_device_ops ops = {
82384 .dev_free = snd_vt1724_dev_free,
82385 };
82386
82387 diff -urNp linux-2.6.39/sound/pci/intel8x0.c linux-2.6.39/sound/pci/intel8x0.c
82388 --- linux-2.6.39/sound/pci/intel8x0.c 2011-05-19 00:06:34.000000000 -0400
82389 +++ linux-2.6.39/sound/pci/intel8x0.c 2011-05-22 19:36:35.000000000 -0400
82390 @@ -2152,12 +2152,12 @@ static int __devinit snd_intel8x0_mixer(
82391 int err;
82392 unsigned int i, codecs;
82393 unsigned int glob_sta = 0;
82394 - struct snd_ac97_bus_ops *ops;
82395 - static struct snd_ac97_bus_ops standard_bus_ops = {
82396 + const struct snd_ac97_bus_ops *ops;
82397 + static const struct snd_ac97_bus_ops standard_bus_ops = {
82398 .write = snd_intel8x0_codec_write,
82399 .read = snd_intel8x0_codec_read,
82400 };
82401 - static struct snd_ac97_bus_ops ali_bus_ops = {
82402 + static const struct snd_ac97_bus_ops ali_bus_ops = {
82403 .write = snd_intel8x0_ali_codec_write,
82404 .read = snd_intel8x0_ali_codec_read,
82405 };
82406 @@ -2921,7 +2921,7 @@ static int __devinit snd_intel8x0_create
82407 unsigned int i;
82408 unsigned int int_sta_masks;
82409 struct ichdev *ichdev;
82410 - static struct snd_device_ops ops = {
82411 + static const struct snd_device_ops ops = {
82412 .dev_free = snd_intel8x0_dev_free,
82413 };
82414
82415 diff -urNp linux-2.6.39/sound/pci/intel8x0m.c linux-2.6.39/sound/pci/intel8x0m.c
82416 --- linux-2.6.39/sound/pci/intel8x0m.c 2011-05-19 00:06:34.000000000 -0400
82417 +++ linux-2.6.39/sound/pci/intel8x0m.c 2011-05-22 19:36:35.000000000 -0400
82418 @@ -826,7 +826,7 @@ static int __devinit snd_intel8x0m_mixer
82419 struct snd_ac97 *x97;
82420 int err;
82421 unsigned int glob_sta = 0;
82422 - static struct snd_ac97_bus_ops ops = {
82423 + static const struct snd_ac97_bus_ops ops = {
82424 .write = snd_intel8x0m_codec_write,
82425 .read = snd_intel8x0m_codec_read,
82426 };
82427 @@ -1116,7 +1116,7 @@ static int __devinit snd_intel8x0m_creat
82428 unsigned int i;
82429 unsigned int int_sta_masks;
82430 struct ichdev *ichdev;
82431 - static struct snd_device_ops ops = {
82432 + static const struct snd_device_ops ops = {
82433 .dev_free = snd_intel8x0m_dev_free,
82434 };
82435 static struct ich_reg_info intel_regs[2] = {
82436 @@ -1265,7 +1265,7 @@ static struct shortname_table {
82437 { 0x5455, "ALi M5455" },
82438 { 0x746d, "AMD AMD8111" },
82439 #endif
82440 - { 0 },
82441 + { 0, },
82442 };
82443
82444 static int __devinit snd_intel8x0m_probe(struct pci_dev *pci,
82445 diff -urNp linux-2.6.39/sound/pci/korg1212/korg1212.c linux-2.6.39/sound/pci/korg1212/korg1212.c
82446 --- linux-2.6.39/sound/pci/korg1212/korg1212.c 2011-05-19 00:06:34.000000000 -0400
82447 +++ linux-2.6.39/sound/pci/korg1212/korg1212.c 2011-05-22 19:36:35.000000000 -0400
82448 @@ -1682,7 +1682,7 @@ static int snd_korg1212_capture_copy(str
82449 return snd_korg1212_copy_to(korg1212, dst, pos, count, 0, korg1212->channels * 2);
82450 }
82451
82452 -static struct snd_pcm_ops snd_korg1212_playback_ops = {
82453 +static const struct snd_pcm_ops snd_korg1212_playback_ops = {
82454 .open = snd_korg1212_playback_open,
82455 .close = snd_korg1212_playback_close,
82456 .ioctl = snd_korg1212_ioctl,
82457 @@ -1694,7 +1694,7 @@ static struct snd_pcm_ops snd_korg1212_p
82458 .silence = snd_korg1212_playback_silence,
82459 };
82460
82461 -static struct snd_pcm_ops snd_korg1212_capture_ops = {
82462 +static const struct snd_pcm_ops snd_korg1212_capture_ops = {
82463 .open = snd_korg1212_capture_open,
82464 .close = snd_korg1212_capture_close,
82465 .ioctl = snd_korg1212_ioctl,
82466 @@ -2164,7 +2164,7 @@ static int __devinit snd_korg1212_create
82467 struct snd_korg1212 * korg1212;
82468 const struct firmware *dsp_code;
82469
82470 - static struct snd_device_ops ops = {
82471 + static const struct snd_device_ops ops = {
82472 .dev_free = snd_korg1212_dev_free,
82473 };
82474
82475 diff -urNp linux-2.6.39/sound/pci/maestro3.c linux-2.6.39/sound/pci/maestro3.c
82476 --- linux-2.6.39/sound/pci/maestro3.c 2011-05-19 00:06:34.000000000 -0400
82477 +++ linux-2.6.39/sound/pci/maestro3.c 2011-05-22 19:36:35.000000000 -0400
82478 @@ -1926,7 +1926,7 @@ snd_m3_capture_close(struct snd_pcm_subs
82479 * create pcm instance
82480 */
82481
82482 -static struct snd_pcm_ops snd_m3_playback_ops = {
82483 +static const struct snd_pcm_ops snd_m3_playback_ops = {
82484 .open = snd_m3_playback_open,
82485 .close = snd_m3_playback_close,
82486 .ioctl = snd_pcm_lib_ioctl,
82487 @@ -1937,7 +1937,7 @@ static struct snd_pcm_ops snd_m3_playbac
82488 .pointer = snd_m3_pcm_pointer,
82489 };
82490
82491 -static struct snd_pcm_ops snd_m3_capture_ops = {
82492 +static const struct snd_pcm_ops snd_m3_capture_ops = {
82493 .open = snd_m3_capture_open,
82494 .close = snd_m3_capture_close,
82495 .ioctl = snd_pcm_lib_ioctl,
82496 @@ -2150,7 +2150,7 @@ static int __devinit snd_m3_mixer(struct
82497 struct snd_ctl_elem_id elem_id;
82498 #endif
82499 int err;
82500 - static struct snd_ac97_bus_ops ops = {
82501 + static const struct snd_ac97_bus_ops ops = {
82502 .write = snd_m3_ac97_write,
82503 .read = snd_m3_ac97_read,
82504 };
82505 @@ -2643,7 +2643,7 @@ snd_m3_create(struct snd_card *card, str
82506 struct snd_m3 *chip;
82507 int i, err;
82508 const struct snd_pci_quirk *quirk;
82509 - static struct snd_device_ops ops = {
82510 + static const struct snd_device_ops ops = {
82511 .dev_free = snd_m3_dev_free,
82512 };
82513
82514 diff -urNp linux-2.6.39/sound/pci/mixart/mixart.c linux-2.6.39/sound/pci/mixart/mixart.c
82515 --- linux-2.6.39/sound/pci/mixart/mixart.c 2011-05-19 00:06:34.000000000 -0400
82516 +++ linux-2.6.39/sound/pci/mixart/mixart.c 2011-05-22 19:36:35.000000000 -0400
82517 @@ -887,7 +887,7 @@ static snd_pcm_uframes_t snd_mixart_stre
82518
82519
82520
82521 -static struct snd_pcm_ops snd_mixart_playback_ops = {
82522 +static const struct snd_pcm_ops snd_mixart_playback_ops = {
82523 .open = snd_mixart_playback_open,
82524 .close = snd_mixart_close,
82525 .ioctl = snd_pcm_lib_ioctl,
82526 @@ -898,7 +898,7 @@ static struct snd_pcm_ops snd_mixart_pla
82527 .pointer = snd_mixart_stream_pointer,
82528 };
82529
82530 -static struct snd_pcm_ops snd_mixart_capture_ops = {
82531 +static const struct snd_pcm_ops snd_mixart_capture_ops = {
82532 .open = snd_mixart_capture_open,
82533 .close = snd_mixart_close,
82534 .ioctl = snd_pcm_lib_ioctl,
82535 @@ -1008,7 +1008,7 @@ static int __devinit snd_mixart_create(s
82536 {
82537 int err;
82538 struct snd_mixart *chip;
82539 - static struct snd_device_ops ops = {
82540 + static const struct snd_device_ops ops = {
82541 .dev_free = snd_mixart_chip_dev_free,
82542 };
82543
82544 diff -urNp linux-2.6.39/sound/pci/nm256/nm256.c linux-2.6.39/sound/pci/nm256/nm256.c
82545 --- linux-2.6.39/sound/pci/nm256/nm256.c 2011-05-19 00:06:34.000000000 -0400
82546 +++ linux-2.6.39/sound/pci/nm256/nm256.c 2011-05-22 19:36:35.000000000 -0400
82547 @@ -899,7 +899,7 @@ snd_nm256_capture_close(struct snd_pcm_s
82548 /*
82549 * create a pcm instance
82550 */
82551 -static struct snd_pcm_ops snd_nm256_playback_ops = {
82552 +static const struct snd_pcm_ops snd_nm256_playback_ops = {
82553 .open = snd_nm256_playback_open,
82554 .close = snd_nm256_playback_close,
82555 .ioctl = snd_pcm_lib_ioctl,
82556 @@ -914,7 +914,7 @@ static struct snd_pcm_ops snd_nm256_play
82557 .mmap = snd_pcm_lib_mmap_iomem,
82558 };
82559
82560 -static struct snd_pcm_ops snd_nm256_capture_ops = {
82561 +static const struct snd_pcm_ops snd_nm256_capture_ops = {
82562 .open = snd_nm256_capture_open,
82563 .close = snd_nm256_capture_close,
82564 .ioctl = snd_pcm_lib_ioctl,
82565 @@ -1301,7 +1301,7 @@ snd_nm256_mixer(struct nm256 *chip)
82566 struct snd_ac97_bus *pbus;
82567 struct snd_ac97_template ac97;
82568 int err;
82569 - static struct snd_ac97_bus_ops ops = {
82570 + static const struct snd_ac97_bus_ops ops = {
82571 .reset = snd_nm256_ac97_reset,
82572 .write = snd_nm256_ac97_write,
82573 .read = snd_nm256_ac97_read,
82574 @@ -1471,7 +1471,7 @@ snd_nm256_create(struct snd_card *card,
82575 {
82576 struct nm256 *chip;
82577 int err, pval;
82578 - static struct snd_device_ops ops = {
82579 + static const struct snd_device_ops ops = {
82580 .dev_free = snd_nm256_dev_free,
82581 };
82582 u32 addr;
82583 diff -urNp linux-2.6.39/sound/pci/oxygen/oxygen_pcm.c linux-2.6.39/sound/pci/oxygen/oxygen_pcm.c
82584 --- linux-2.6.39/sound/pci/oxygen/oxygen_pcm.c 2011-05-19 00:06:34.000000000 -0400
82585 +++ linux-2.6.39/sound/pci/oxygen/oxygen_pcm.c 2011-05-22 19:36:35.000000000 -0400
82586 @@ -606,7 +606,7 @@ static snd_pcm_uframes_t oxygen_pointer(
82587 return bytes_to_frames(runtime, curr_addr - (u32)runtime->dma_addr);
82588 }
82589
82590 -static struct snd_pcm_ops oxygen_rec_a_ops = {
82591 +static const struct snd_pcm_ops oxygen_rec_a_ops = {
82592 .open = oxygen_rec_a_open,
82593 .close = oxygen_close,
82594 .ioctl = snd_pcm_lib_ioctl,
82595 @@ -617,7 +617,7 @@ static struct snd_pcm_ops oxygen_rec_a_o
82596 .pointer = oxygen_pointer,
82597 };
82598
82599 -static struct snd_pcm_ops oxygen_rec_b_ops = {
82600 +static const struct snd_pcm_ops oxygen_rec_b_ops = {
82601 .open = oxygen_rec_b_open,
82602 .close = oxygen_close,
82603 .ioctl = snd_pcm_lib_ioctl,
82604 @@ -628,7 +628,7 @@ static struct snd_pcm_ops oxygen_rec_b_o
82605 .pointer = oxygen_pointer,
82606 };
82607
82608 -static struct snd_pcm_ops oxygen_rec_c_ops = {
82609 +static const struct snd_pcm_ops oxygen_rec_c_ops = {
82610 .open = oxygen_rec_c_open,
82611 .close = oxygen_close,
82612 .ioctl = snd_pcm_lib_ioctl,
82613 @@ -639,7 +639,7 @@ static struct snd_pcm_ops oxygen_rec_c_o
82614 .pointer = oxygen_pointer,
82615 };
82616
82617 -static struct snd_pcm_ops oxygen_spdif_ops = {
82618 +static const struct snd_pcm_ops oxygen_spdif_ops = {
82619 .open = oxygen_spdif_open,
82620 .close = oxygen_close,
82621 .ioctl = snd_pcm_lib_ioctl,
82622 @@ -650,7 +650,7 @@ static struct snd_pcm_ops oxygen_spdif_o
82623 .pointer = oxygen_pointer,
82624 };
82625
82626 -static struct snd_pcm_ops oxygen_multich_ops = {
82627 +static const struct snd_pcm_ops oxygen_multich_ops = {
82628 .open = oxygen_multich_open,
82629 .close = oxygen_close,
82630 .ioctl = snd_pcm_lib_ioctl,
82631 @@ -661,7 +661,7 @@ static struct snd_pcm_ops oxygen_multich
82632 .pointer = oxygen_pointer,
82633 };
82634
82635 -static struct snd_pcm_ops oxygen_ac97_ops = {
82636 +static const struct snd_pcm_ops oxygen_ac97_ops = {
82637 .open = oxygen_ac97_open,
82638 .close = oxygen_close,
82639 .ioctl = snd_pcm_lib_ioctl,
82640 diff -urNp linux-2.6.39/sound/pci/pcxhr/pcxhr.c linux-2.6.39/sound/pci/pcxhr/pcxhr.c
82641 --- linux-2.6.39/sound/pci/pcxhr/pcxhr.c 2011-05-19 00:06:34.000000000 -0400
82642 +++ linux-2.6.39/sound/pci/pcxhr/pcxhr.c 2011-05-22 19:36:35.000000000 -0400
82643 @@ -1121,7 +1121,7 @@ static snd_pcm_uframes_t pcxhr_stream_po
82644 }
82645
82646
82647 -static struct snd_pcm_ops pcxhr_ops = {
82648 +static const struct snd_pcm_ops pcxhr_ops = {
82649 .open = pcxhr_open,
82650 .close = pcxhr_close,
82651 .ioctl = snd_pcm_lib_ioctl,
82652 @@ -1184,7 +1184,7 @@ static int __devinit pcxhr_create(struct
82653 {
82654 int err;
82655 struct snd_pcxhr *chip;
82656 - static struct snd_device_ops ops = {
82657 + static const struct snd_device_ops ops = {
82658 .dev_free = pcxhr_chip_dev_free,
82659 };
82660
82661 diff -urNp linux-2.6.39/sound/pci/riptide/riptide.c linux-2.6.39/sound/pci/riptide/riptide.c
82662 --- linux-2.6.39/sound/pci/riptide/riptide.c 2011-05-19 00:06:34.000000000 -0400
82663 +++ linux-2.6.39/sound/pci/riptide/riptide.c 2011-05-22 19:36:35.000000000 -0400
82664 @@ -1675,7 +1675,7 @@ static int snd_riptide_capture_close(str
82665 return 0;
82666 }
82667
82668 -static struct snd_pcm_ops snd_riptide_playback_ops = {
82669 +static const struct snd_pcm_ops snd_riptide_playback_ops = {
82670 .open = snd_riptide_playback_open,
82671 .close = snd_riptide_playback_close,
82672 .ioctl = snd_pcm_lib_ioctl,
82673 @@ -1686,7 +1686,7 @@ static struct snd_pcm_ops snd_riptide_pl
82674 .trigger = snd_riptide_trigger,
82675 .pointer = snd_riptide_pointer,
82676 };
82677 -static struct snd_pcm_ops snd_riptide_capture_ops = {
82678 +static const struct snd_pcm_ops snd_riptide_capture_ops = {
82679 .open = snd_riptide_capture_open,
82680 .close = snd_riptide_capture_close,
82681 .ioctl = snd_pcm_lib_ioctl,
82682 @@ -1857,7 +1857,7 @@ snd_riptide_create(struct snd_card *card
82683 struct snd_riptide *chip;
82684 struct riptideport *hwport;
82685 int err;
82686 - static struct snd_device_ops ops = {
82687 + static const struct snd_device_ops ops = {
82688 .dev_free = snd_riptide_dev_free,
82689 };
82690
82691 @@ -1999,7 +1999,7 @@ static int __devinit snd_riptide_mixer(s
82692 struct snd_ac97_bus *pbus;
82693 struct snd_ac97_template ac97;
82694 int err = 0;
82695 - static struct snd_ac97_bus_ops ops = {
82696 + static const struct snd_ac97_bus_ops ops = {
82697 .write = snd_riptide_codec_write,
82698 .read = snd_riptide_codec_read,
82699 };
82700 diff -urNp linux-2.6.39/sound/pci/rme32.c linux-2.6.39/sound/pci/rme32.c
82701 --- linux-2.6.39/sound/pci/rme32.c 2011-05-19 00:06:34.000000000 -0400
82702 +++ linux-2.6.39/sound/pci/rme32.c 2011-05-22 19:36:35.000000000 -0400
82703 @@ -1197,7 +1197,7 @@ snd_rme32_capture_fd_pointer(struct snd_
82704 }
82705
82706 /* for halfduplex mode */
82707 -static struct snd_pcm_ops snd_rme32_playback_spdif_ops = {
82708 +static const struct snd_pcm_ops snd_rme32_playback_spdif_ops = {
82709 .open = snd_rme32_playback_spdif_open,
82710 .close = snd_rme32_playback_close,
82711 .ioctl = snd_pcm_lib_ioctl,
82712 @@ -1211,7 +1211,7 @@ static struct snd_pcm_ops snd_rme32_play
82713 .mmap = snd_pcm_lib_mmap_iomem,
82714 };
82715
82716 -static struct snd_pcm_ops snd_rme32_capture_spdif_ops = {
82717 +static const struct snd_pcm_ops snd_rme32_capture_spdif_ops = {
82718 .open = snd_rme32_capture_spdif_open,
82719 .close = snd_rme32_capture_close,
82720 .ioctl = snd_pcm_lib_ioctl,
82721 @@ -1224,7 +1224,7 @@ static struct snd_pcm_ops snd_rme32_capt
82722 .mmap = snd_pcm_lib_mmap_iomem,
82723 };
82724
82725 -static struct snd_pcm_ops snd_rme32_playback_adat_ops = {
82726 +static const struct snd_pcm_ops snd_rme32_playback_adat_ops = {
82727 .open = snd_rme32_playback_adat_open,
82728 .close = snd_rme32_playback_close,
82729 .ioctl = snd_pcm_lib_ioctl,
82730 @@ -1237,7 +1237,7 @@ static struct snd_pcm_ops snd_rme32_play
82731 .mmap = snd_pcm_lib_mmap_iomem,
82732 };
82733
82734 -static struct snd_pcm_ops snd_rme32_capture_adat_ops = {
82735 +static const struct snd_pcm_ops snd_rme32_capture_adat_ops = {
82736 .open = snd_rme32_capture_adat_open,
82737 .close = snd_rme32_capture_close,
82738 .ioctl = snd_pcm_lib_ioctl,
82739 @@ -1250,7 +1250,7 @@ static struct snd_pcm_ops snd_rme32_capt
82740 };
82741
82742 /* for fullduplex mode */
82743 -static struct snd_pcm_ops snd_rme32_playback_spdif_fd_ops = {
82744 +static const struct snd_pcm_ops snd_rme32_playback_spdif_fd_ops = {
82745 .open = snd_rme32_playback_spdif_open,
82746 .close = snd_rme32_playback_close,
82747 .ioctl = snd_pcm_lib_ioctl,
82748 @@ -1262,7 +1262,7 @@ static struct snd_pcm_ops snd_rme32_play
82749 .ack = snd_rme32_playback_fd_ack,
82750 };
82751
82752 -static struct snd_pcm_ops snd_rme32_capture_spdif_fd_ops = {
82753 +static const struct snd_pcm_ops snd_rme32_capture_spdif_fd_ops = {
82754 .open = snd_rme32_capture_spdif_open,
82755 .close = snd_rme32_capture_close,
82756 .ioctl = snd_pcm_lib_ioctl,
82757 @@ -1274,7 +1274,7 @@ static struct snd_pcm_ops snd_rme32_capt
82758 .ack = snd_rme32_capture_fd_ack,
82759 };
82760
82761 -static struct snd_pcm_ops snd_rme32_playback_adat_fd_ops = {
82762 +static const struct snd_pcm_ops snd_rme32_playback_adat_fd_ops = {
82763 .open = snd_rme32_playback_adat_open,
82764 .close = snd_rme32_playback_close,
82765 .ioctl = snd_pcm_lib_ioctl,
82766 @@ -1285,7 +1285,7 @@ static struct snd_pcm_ops snd_rme32_play
82767 .ack = snd_rme32_playback_fd_ack,
82768 };
82769
82770 -static struct snd_pcm_ops snd_rme32_capture_adat_fd_ops = {
82771 +static const struct snd_pcm_ops snd_rme32_capture_adat_fd_ops = {
82772 .open = snd_rme32_capture_adat_open,
82773 .close = snd_rme32_capture_close,
82774 .ioctl = snd_pcm_lib_ioctl,
82775 diff -urNp linux-2.6.39/sound/pci/rme9652/hdsp.c linux-2.6.39/sound/pci/rme9652/hdsp.c
82776 --- linux-2.6.39/sound/pci/rme9652/hdsp.c 2011-05-19 00:06:34.000000000 -0400
82777 +++ linux-2.6.39/sound/pci/rme9652/hdsp.c 2011-05-22 19:36:35.000000000 -0400
82778 @@ -1469,15 +1469,13 @@ static int snd_hdsp_midi_output_close(st
82779 return 0;
82780 }
82781
82782 -static struct snd_rawmidi_ops snd_hdsp_midi_output =
82783 -{
82784 +static const struct snd_rawmidi_ops snd_hdsp_midi_output = {
82785 .open = snd_hdsp_midi_output_open,
82786 .close = snd_hdsp_midi_output_close,
82787 .trigger = snd_hdsp_midi_output_trigger,
82788 };
82789
82790 -static struct snd_rawmidi_ops snd_hdsp_midi_input =
82791 -{
82792 +static const struct snd_rawmidi_ops snd_hdsp_midi_input = {
82793 .open = snd_hdsp_midi_input_open,
82794 .close = snd_hdsp_midi_input_close,
82795 .trigger = snd_hdsp_midi_input_trigger,
82796 @@ -5135,7 +5133,7 @@ static int snd_hdsp_hwdep_ioctl(struct s
82797 return 0;
82798 }
82799
82800 -static struct snd_pcm_ops snd_hdsp_playback_ops = {
82801 +static const struct snd_pcm_ops snd_hdsp_playback_ops = {
82802 .open = snd_hdsp_playback_open,
82803 .close = snd_hdsp_playback_release,
82804 .ioctl = snd_hdsp_ioctl,
82805 @@ -5147,7 +5145,7 @@ static struct snd_pcm_ops snd_hdsp_playb
82806 .silence = snd_hdsp_hw_silence,
82807 };
82808
82809 -static struct snd_pcm_ops snd_hdsp_capture_ops = {
82810 +static const struct snd_pcm_ops snd_hdsp_capture_ops = {
82811 .open = snd_hdsp_capture_open,
82812 .close = snd_hdsp_capture_release,
82813 .ioctl = snd_hdsp_ioctl,
82814 diff -urNp linux-2.6.39/sound/pci/rme9652/hdspm.c linux-2.6.39/sound/pci/rme9652/hdspm.c
82815 --- linux-2.6.39/sound/pci/rme9652/hdspm.c 2011-05-19 00:06:34.000000000 -0400
82816 +++ linux-2.6.39/sound/pci/rme9652/hdspm.c 2011-05-22 19:36:35.000000000 -0400
82817 @@ -1773,15 +1773,13 @@ static int snd_hdspm_midi_output_close(s
82818 return 0;
82819 }
82820
82821 -static struct snd_rawmidi_ops snd_hdspm_midi_output =
82822 -{
82823 +static const struct snd_rawmidi_ops snd_hdspm_midi_output = {
82824 .open = snd_hdspm_midi_output_open,
82825 .close = snd_hdspm_midi_output_close,
82826 .trigger = snd_hdspm_midi_output_trigger,
82827 };
82828
82829 -static struct snd_rawmidi_ops snd_hdspm_midi_input =
82830 -{
82831 +static const struct snd_rawmidi_ops snd_hdspm_midi_input = {
82832 .open = snd_hdspm_midi_input_open,
82833 .close = snd_hdspm_midi_input_close,
82834 .trigger = snd_hdspm_midi_input_trigger,
82835 @@ -6172,7 +6170,7 @@ static int snd_hdspm_hwdep_ioctl(struct
82836 return 0;
82837 }
82838
82839 -static struct snd_pcm_ops snd_hdspm_playback_ops = {
82840 +static const struct snd_pcm_ops snd_hdspm_playback_ops = {
82841 .open = snd_hdspm_playback_open,
82842 .close = snd_hdspm_playback_release,
82843 .ioctl = snd_hdspm_ioctl,
82844 @@ -6184,7 +6182,7 @@ static struct snd_pcm_ops snd_hdspm_play
82845 .page = snd_pcm_sgbuf_ops_page,
82846 };
82847
82848 -static struct snd_pcm_ops snd_hdspm_capture_ops = {
82849 +static const struct snd_pcm_ops snd_hdspm_capture_ops = {
82850 .open = snd_hdspm_capture_open,
82851 .close = snd_hdspm_capture_release,
82852 .ioctl = snd_hdspm_ioctl,
82853 diff -urNp linux-2.6.39/sound/pci/rme9652/rme9652.c linux-2.6.39/sound/pci/rme9652/rme9652.c
82854 --- linux-2.6.39/sound/pci/rme9652/rme9652.c 2011-05-19 00:06:34.000000000 -0400
82855 +++ linux-2.6.39/sound/pci/rme9652/rme9652.c 2011-05-22 19:36:35.000000000 -0400
82856 @@ -2391,7 +2391,7 @@ static int snd_rme9652_capture_release(s
82857 return 0;
82858 }
82859
82860 -static struct snd_pcm_ops snd_rme9652_playback_ops = {
82861 +static const struct snd_pcm_ops snd_rme9652_playback_ops = {
82862 .open = snd_rme9652_playback_open,
82863 .close = snd_rme9652_playback_release,
82864 .ioctl = snd_rme9652_ioctl,
82865 @@ -2403,7 +2403,7 @@ static struct snd_pcm_ops snd_rme9652_pl
82866 .silence = snd_rme9652_hw_silence,
82867 };
82868
82869 -static struct snd_pcm_ops snd_rme9652_capture_ops = {
82870 +static const struct snd_pcm_ops snd_rme9652_capture_ops = {
82871 .open = snd_rme9652_capture_open,
82872 .close = snd_rme9652_capture_release,
82873 .ioctl = snd_rme9652_ioctl,
82874 diff -urNp linux-2.6.39/sound/pci/rme96.c linux-2.6.39/sound/pci/rme96.c
82875 --- linux-2.6.39/sound/pci/rme96.c 2011-05-19 00:06:34.000000000 -0400
82876 +++ linux-2.6.39/sound/pci/rme96.c 2011-05-22 19:36:35.000000000 -0400
82877 @@ -1447,7 +1447,7 @@ snd_rme96_capture_pointer(struct snd_pcm
82878 return snd_rme96_capture_ptr(rme96);
82879 }
82880
82881 -static struct snd_pcm_ops snd_rme96_playback_spdif_ops = {
82882 +static const struct snd_pcm_ops snd_rme96_playback_spdif_ops = {
82883 .open = snd_rme96_playback_spdif_open,
82884 .close = snd_rme96_playback_close,
82885 .ioctl = snd_pcm_lib_ioctl,
82886 @@ -1460,7 +1460,7 @@ static struct snd_pcm_ops snd_rme96_play
82887 .mmap = snd_pcm_lib_mmap_iomem,
82888 };
82889
82890 -static struct snd_pcm_ops snd_rme96_capture_spdif_ops = {
82891 +static const struct snd_pcm_ops snd_rme96_capture_spdif_ops = {
82892 .open = snd_rme96_capture_spdif_open,
82893 .close = snd_rme96_capture_close,
82894 .ioctl = snd_pcm_lib_ioctl,
82895 @@ -1472,7 +1472,7 @@ static struct snd_pcm_ops snd_rme96_capt
82896 .mmap = snd_pcm_lib_mmap_iomem,
82897 };
82898
82899 -static struct snd_pcm_ops snd_rme96_playback_adat_ops = {
82900 +static const struct snd_pcm_ops snd_rme96_playback_adat_ops = {
82901 .open = snd_rme96_playback_adat_open,
82902 .close = snd_rme96_playback_close,
82903 .ioctl = snd_pcm_lib_ioctl,
82904 @@ -1485,7 +1485,7 @@ static struct snd_pcm_ops snd_rme96_play
82905 .mmap = snd_pcm_lib_mmap_iomem,
82906 };
82907
82908 -static struct snd_pcm_ops snd_rme96_capture_adat_ops = {
82909 +static const struct snd_pcm_ops snd_rme96_capture_adat_ops = {
82910 .open = snd_rme96_capture_adat_open,
82911 .close = snd_rme96_capture_close,
82912 .ioctl = snd_pcm_lib_ioctl,
82913 diff -urNp linux-2.6.39/sound/pci/sis7019.c linux-2.6.39/sound/pci/sis7019.c
82914 --- linux-2.6.39/sound/pci/sis7019.c 2011-05-19 00:06:34.000000000 -0400
82915 +++ linux-2.6.39/sound/pci/sis7019.c 2011-05-22 19:36:35.000000000 -0400
82916 @@ -1011,7 +1011,7 @@ static int __devinit sis_mixer_create(st
82917 {
82918 struct snd_ac97_bus *bus;
82919 struct snd_ac97_template ac97;
82920 - static struct snd_ac97_bus_ops ops = {
82921 + static const struct snd_ac97_bus_ops ops = {
82922 .write = sis_ac97_write,
82923 .read = sis_ac97_read,
82924 };
82925 @@ -1293,7 +1293,7 @@ static int __devinit sis_chip_create(str
82926 {
82927 struct sis7019 *sis = card->private_data;
82928 struct voice *voice;
82929 - static struct snd_device_ops ops = {
82930 + static const struct snd_device_ops ops = {
82931 .dev_free = sis_dev_free,
82932 };
82933 int rc;
82934 diff -urNp linux-2.6.39/sound/pci/sonicvibes.c linux-2.6.39/sound/pci/sonicvibes.c
82935 --- linux-2.6.39/sound/pci/sonicvibes.c 2011-05-19 00:06:34.000000000 -0400
82936 +++ linux-2.6.39/sound/pci/sonicvibes.c 2011-05-22 19:36:35.000000000 -0400
82937 @@ -855,7 +855,7 @@ static int snd_sonicvibes_capture_close(
82938 return 0;
82939 }
82940
82941 -static struct snd_pcm_ops snd_sonicvibes_playback_ops = {
82942 +static const struct snd_pcm_ops snd_sonicvibes_playback_ops = {
82943 .open = snd_sonicvibes_playback_open,
82944 .close = snd_sonicvibes_playback_close,
82945 .ioctl = snd_pcm_lib_ioctl,
82946 @@ -866,7 +866,7 @@ static struct snd_pcm_ops snd_sonicvibes
82947 .pointer = snd_sonicvibes_playback_pointer,
82948 };
82949
82950 -static struct snd_pcm_ops snd_sonicvibes_capture_ops = {
82951 +static const struct snd_pcm_ops snd_sonicvibes_capture_ops = {
82952 .open = snd_sonicvibes_capture_open,
82953 .close = snd_sonicvibes_capture_close,
82954 .ioctl = snd_pcm_lib_ioctl,
82955 @@ -1255,7 +1255,7 @@ static int __devinit snd_sonicvibes_crea
82956 struct sonicvibes *sonic;
82957 unsigned int dmaa, dmac;
82958 int err;
82959 - static struct snd_device_ops ops = {
82960 + static const struct snd_device_ops ops = {
82961 .dev_free = snd_sonicvibes_dev_free,
82962 };
82963
82964 diff -urNp linux-2.6.39/sound/pci/trident/trident_main.c linux-2.6.39/sound/pci/trident/trident_main.c
82965 --- linux-2.6.39/sound/pci/trident/trident_main.c 2011-05-19 00:06:34.000000000 -0400
82966 +++ linux-2.6.39/sound/pci/trident/trident_main.c 2011-05-22 19:36:35.000000000 -0400
82967 @@ -3549,7 +3549,7 @@ int __devinit snd_trident_create(struct
82968 int i, err;
82969 struct snd_trident_voice *voice;
82970 struct snd_trident_pcm_mixer *tmix;
82971 - static struct snd_device_ops ops = {
82972 + static const struct snd_device_ops ops = {
82973 .dev_free = snd_trident_dev_free,
82974 };
82975
82976 diff -urNp linux-2.6.39/sound/pci/via82xx.c linux-2.6.39/sound/pci/via82xx.c
82977 --- linux-2.6.39/sound/pci/via82xx.c 2011-05-19 00:06:34.000000000 -0400
82978 +++ linux-2.6.39/sound/pci/via82xx.c 2011-05-22 19:36:35.000000000 -0400
82979 @@ -1352,7 +1352,7 @@ static int snd_via8233_playback_close(st
82980
82981
82982 /* via686 playback callbacks */
82983 -static struct snd_pcm_ops snd_via686_playback_ops = {
82984 +static const struct snd_pcm_ops snd_via686_playback_ops = {
82985 .open = snd_via686_playback_open,
82986 .close = snd_via82xx_pcm_close,
82987 .ioctl = snd_pcm_lib_ioctl,
82988 @@ -1365,7 +1365,7 @@ static struct snd_pcm_ops snd_via686_pla
82989 };
82990
82991 /* via686 capture callbacks */
82992 -static struct snd_pcm_ops snd_via686_capture_ops = {
82993 +static const struct snd_pcm_ops snd_via686_capture_ops = {
82994 .open = snd_via82xx_capture_open,
82995 .close = snd_via82xx_pcm_close,
82996 .ioctl = snd_pcm_lib_ioctl,
82997 @@ -1378,7 +1378,7 @@ static struct snd_pcm_ops snd_via686_cap
82998 };
82999
83000 /* via823x DSX playback callbacks */
83001 -static struct snd_pcm_ops snd_via8233_playback_ops = {
83002 +static const struct snd_pcm_ops snd_via8233_playback_ops = {
83003 .open = snd_via8233_playback_open,
83004 .close = snd_via8233_playback_close,
83005 .ioctl = snd_pcm_lib_ioctl,
83006 @@ -1391,7 +1391,7 @@ static struct snd_pcm_ops snd_via8233_pl
83007 };
83008
83009 /* via823x multi-channel playback callbacks */
83010 -static struct snd_pcm_ops snd_via8233_multi_ops = {
83011 +static const struct snd_pcm_ops snd_via8233_multi_ops = {
83012 .open = snd_via8233_multi_open,
83013 .close = snd_via82xx_pcm_close,
83014 .ioctl = snd_pcm_lib_ioctl,
83015 @@ -1404,7 +1404,7 @@ static struct snd_pcm_ops snd_via8233_mu
83016 };
83017
83018 /* via823x capture callbacks */
83019 -static struct snd_pcm_ops snd_via8233_capture_ops = {
83020 +static const struct snd_pcm_ops snd_via8233_capture_ops = {
83021 .open = snd_via82xx_capture_open,
83022 .close = snd_via82xx_pcm_close,
83023 .ioctl = snd_pcm_lib_ioctl,
83024 @@ -1868,7 +1868,7 @@ static int __devinit snd_via82xx_mixer_n
83025 {
83026 struct snd_ac97_template ac97;
83027 int err;
83028 - static struct snd_ac97_bus_ops ops = {
83029 + static const struct snd_ac97_bus_ops ops = {
83030 .write = snd_via82xx_codec_write,
83031 .read = snd_via82xx_codec_read,
83032 .wait = snd_via82xx_codec_wait,
83033 @@ -2340,7 +2340,7 @@ static int __devinit snd_via82xx_create(
83034 {
83035 struct via82xx *chip;
83036 int err;
83037 - static struct snd_device_ops ops = {
83038 + static const struct snd_device_ops ops = {
83039 .dev_free = snd_via82xx_dev_free,
83040 };
83041
83042 diff -urNp linux-2.6.39/sound/pci/via82xx_modem.c linux-2.6.39/sound/pci/via82xx_modem.c
83043 --- linux-2.6.39/sound/pci/via82xx_modem.c 2011-05-19 00:06:34.000000000 -0400
83044 +++ linux-2.6.39/sound/pci/via82xx_modem.c 2011-05-22 19:36:35.000000000 -0400
83045 @@ -799,7 +799,7 @@ static int snd_via82xx_pcm_close(struct
83046
83047
83048 /* via686 playback callbacks */
83049 -static struct snd_pcm_ops snd_via686_playback_ops = {
83050 +static const struct snd_pcm_ops snd_via686_playback_ops = {
83051 .open = snd_via82xx_playback_open,
83052 .close = snd_via82xx_pcm_close,
83053 .ioctl = snd_pcm_lib_ioctl,
83054 @@ -812,7 +812,7 @@ static struct snd_pcm_ops snd_via686_pla
83055 };
83056
83057 /* via686 capture callbacks */
83058 -static struct snd_pcm_ops snd_via686_capture_ops = {
83059 +static const struct snd_pcm_ops snd_via686_capture_ops = {
83060 .open = snd_via82xx_capture_open,
83061 .close = snd_via82xx_pcm_close,
83062 .ioctl = snd_pcm_lib_ioctl,
83063 @@ -889,7 +889,7 @@ static int __devinit snd_via82xx_mixer_n
83064 {
83065 struct snd_ac97_template ac97;
83066 int err;
83067 - static struct snd_ac97_bus_ops ops = {
83068 + static const struct snd_ac97_bus_ops ops = {
83069 .write = snd_via82xx_codec_write,
83070 .read = snd_via82xx_codec_read,
83071 .wait = snd_via82xx_codec_wait,
83072 @@ -1105,7 +1105,7 @@ static int __devinit snd_via82xx_create(
83073 {
83074 struct via82xx_modem *chip;
83075 int err;
83076 - static struct snd_device_ops ops = {
83077 + static const struct snd_device_ops ops = {
83078 .dev_free = snd_via82xx_dev_free,
83079 };
83080
83081 diff -urNp linux-2.6.39/sound/pci/vx222/vx222.c linux-2.6.39/sound/pci/vx222/vx222.c
83082 --- linux-2.6.39/sound/pci/vx222/vx222.c 2011-05-19 00:06:34.000000000 -0400
83083 +++ linux-2.6.39/sound/pci/vx222/vx222.c 2011-05-22 19:36:35.000000000 -0400
83084 @@ -141,7 +141,7 @@ static int __devinit snd_vx222_create(st
83085 struct vx_core *chip;
83086 struct snd_vx222 *vx;
83087 int i, err;
83088 - static struct snd_device_ops ops = {
83089 + static const struct snd_device_ops ops = {
83090 .dev_free = snd_vx222_dev_free,
83091 };
83092 struct snd_vx_ops *vx_ops;
83093 diff -urNp linux-2.6.39/sound/pci/ymfpci/ymfpci_main.c linux-2.6.39/sound/pci/ymfpci/ymfpci_main.c
83094 --- linux-2.6.39/sound/pci/ymfpci/ymfpci_main.c 2011-05-19 00:06:34.000000000 -0400
83095 +++ linux-2.6.39/sound/pci/ymfpci/ymfpci_main.c 2011-05-22 19:36:35.000000000 -0400
83096 @@ -202,8 +202,8 @@ static void snd_ymfpci_hw_stop(struct sn
83097 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
83098 break;
83099 }
83100 - if (atomic_read(&chip->interrupt_sleep_count)) {
83101 - atomic_set(&chip->interrupt_sleep_count, 0);
83102 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
83103 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
83104 wake_up(&chip->interrupt_sleep);
83105 }
83106 __end:
83107 @@ -787,7 +787,7 @@ static void snd_ymfpci_irq_wait(struct s
83108 continue;
83109 init_waitqueue_entry(&wait, current);
83110 add_wait_queue(&chip->interrupt_sleep, &wait);
83111 - atomic_inc(&chip->interrupt_sleep_count);
83112 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
83113 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
83114 remove_wait_queue(&chip->interrupt_sleep, &wait);
83115 }
83116 @@ -825,8 +825,8 @@ static irqreturn_t snd_ymfpci_interrupt(
83117 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
83118 spin_unlock(&chip->reg_lock);
83119
83120 - if (atomic_read(&chip->interrupt_sleep_count)) {
83121 - atomic_set(&chip->interrupt_sleep_count, 0);
83122 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
83123 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
83124 wake_up(&chip->interrupt_sleep);
83125 }
83126 }
83127 @@ -2344,7 +2344,7 @@ int __devinit snd_ymfpci_create(struct s
83128 {
83129 struct snd_ymfpci *chip;
83130 int err;
83131 - static struct snd_device_ops ops = {
83132 + static const struct snd_device_ops ops = {
83133 .dev_free = snd_ymfpci_dev_free,
83134 };
83135
83136 @@ -2363,7 +2363,7 @@ int __devinit snd_ymfpci_create(struct s
83137 spin_lock_init(&chip->reg_lock);
83138 spin_lock_init(&chip->voice_lock);
83139 init_waitqueue_head(&chip->interrupt_sleep);
83140 - atomic_set(&chip->interrupt_sleep_count, 0);
83141 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
83142 chip->card = card;
83143 chip->pci = pci;
83144 chip->irq = -1;
83145 diff -urNp linux-2.6.39/sound/pcmcia/pdaudiocf/pdaudiocf.c linux-2.6.39/sound/pcmcia/pdaudiocf/pdaudiocf.c
83146 --- linux-2.6.39/sound/pcmcia/pdaudiocf/pdaudiocf.c 2011-05-19 00:06:34.000000000 -0400
83147 +++ linux-2.6.39/sound/pcmcia/pdaudiocf/pdaudiocf.c 2011-05-22 19:36:35.000000000 -0400
83148 @@ -94,7 +94,7 @@ static int snd_pdacf_probe(struct pcmcia
83149 int i, err;
83150 struct snd_pdacf *pdacf;
83151 struct snd_card *card;
83152 - static struct snd_device_ops ops = {
83153 + static const struct snd_device_ops ops = {
83154 .dev_free = snd_pdacf_dev_free,
83155 };
83156
83157 diff -urNp linux-2.6.39/sound/pcmcia/vx/vxpocket.c linux-2.6.39/sound/pcmcia/vx/vxpocket.c
83158 --- linux-2.6.39/sound/pcmcia/vx/vxpocket.c 2011-05-19 00:06:34.000000000 -0400
83159 +++ linux-2.6.39/sound/pcmcia/vx/vxpocket.c 2011-05-22 19:36:35.000000000 -0400
83160 @@ -137,7 +137,7 @@ static int snd_vxpocket_new(struct snd_c
83161 {
83162 struct vx_core *chip;
83163 struct snd_vxpocket *vxp;
83164 - static struct snd_device_ops ops = {
83165 + static const struct snd_device_ops ops = {
83166 .dev_free = snd_vxpocket_dev_free,
83167 };
83168 int err;
83169 diff -urNp linux-2.6.39/sound/ppc/pmac.c linux-2.6.39/sound/ppc/pmac.c
83170 --- linux-2.6.39/sound/ppc/pmac.c 2011-05-19 00:06:34.000000000 -0400
83171 +++ linux-2.6.39/sound/ppc/pmac.c 2011-05-22 19:36:35.000000000 -0400
83172 @@ -1186,7 +1186,7 @@ int __devinit snd_pmac_new(struct snd_ca
83173 int i, err;
83174 unsigned int irq;
83175 unsigned long ctrl_addr, txdma_addr, rxdma_addr;
83176 - static struct snd_device_ops ops = {
83177 + static const struct snd_device_ops ops = {
83178 .dev_free = snd_pmac_dev_free,
83179 };
83180
83181 diff -urNp linux-2.6.39/sound/ppc/snd_ps3.c linux-2.6.39/sound/ppc/snd_ps3.c
83182 --- linux-2.6.39/sound/ppc/snd_ps3.c 2011-05-19 00:06:34.000000000 -0400
83183 +++ linux-2.6.39/sound/ppc/snd_ps3.c 2011-05-22 19:36:35.000000000 -0400
83184 @@ -773,7 +773,7 @@ static struct snd_kcontrol_new spdif_ctl
83185 },
83186 };
83187
83188 -static struct snd_pcm_ops snd_ps3_pcm_spdif_ops = {
83189 +static const struct snd_pcm_ops snd_ps3_pcm_spdif_ops = {
83190 .open = snd_ps3_pcm_open,
83191 .close = snd_ps3_pcm_close,
83192 .ioctl = snd_pcm_lib_ioctl,
83193 diff -urNp linux-2.6.39/sound/sh/aica.c linux-2.6.39/sound/sh/aica.c
83194 --- linux-2.6.39/sound/sh/aica.c 2011-05-19 00:06:34.000000000 -0400
83195 +++ linux-2.6.39/sound/sh/aica.c 2011-05-22 19:36:35.000000000 -0400
83196 @@ -441,7 +441,7 @@ static unsigned long snd_aicapcm_pcm_poi
83197 return readl(AICA_CONTROL_CHANNEL_SAMPLE_NUMBER);
83198 }
83199
83200 -static struct snd_pcm_ops snd_aicapcm_playback_ops = {
83201 +static const struct snd_pcm_ops snd_aicapcm_playback_ops = {
83202 .open = snd_aicapcm_pcm_open,
83203 .close = snd_aicapcm_pcm_close,
83204 .ioctl = snd_pcm_lib_ioctl,
83205 diff -urNp linux-2.6.39/sound/sh/sh_dac_audio.c linux-2.6.39/sound/sh/sh_dac_audio.c
83206 --- linux-2.6.39/sound/sh/sh_dac_audio.c 2011-05-19 00:06:34.000000000 -0400
83207 +++ linux-2.6.39/sound/sh/sh_dac_audio.c 2011-05-22 19:36:35.000000000 -0400
83208 @@ -246,7 +246,7 @@ snd_pcm_uframes_t snd_sh_dac_pcm_pointer
83209 }
83210
83211 /* pcm ops */
83212 -static struct snd_pcm_ops snd_sh_dac_pcm_ops = {
83213 +static const struct snd_pcm_ops snd_sh_dac_pcm_ops = {
83214 .open = snd_sh_dac_pcm_open,
83215 .close = snd_sh_dac_pcm_close,
83216 .ioctl = snd_pcm_lib_ioctl,
83217 @@ -352,7 +352,7 @@ static int __devinit snd_sh_dac_create(s
83218 struct snd_sh_dac *chip;
83219 int err;
83220
83221 - static struct snd_device_ops ops = {
83222 + static const struct snd_device_ops ops = {
83223 .dev_free = snd_sh_dac_dev_free,
83224 };
83225
83226 diff -urNp linux-2.6.39/sound/soc/atmel/atmel-pcm.c linux-2.6.39/sound/soc/atmel/atmel-pcm.c
83227 --- linux-2.6.39/sound/soc/atmel/atmel-pcm.c 2011-05-19 00:06:34.000000000 -0400
83228 +++ linux-2.6.39/sound/soc/atmel/atmel-pcm.c 2011-05-22 19:36:35.000000000 -0400
83229 @@ -346,7 +346,7 @@ static int atmel_pcm_mmap(struct snd_pcm
83230 vma->vm_end - vma->vm_start, vma->vm_page_prot);
83231 }
83232
83233 -static struct snd_pcm_ops atmel_pcm_ops = {
83234 +static const struct snd_pcm_ops atmel_pcm_ops = {
83235 .open = atmel_pcm_open,
83236 .close = atmel_pcm_close,
83237 .ioctl = snd_pcm_lib_ioctl,
83238 diff -urNp linux-2.6.39/sound/soc/atmel/playpaq_wm8510.c linux-2.6.39/sound/soc/atmel/playpaq_wm8510.c
83239 --- linux-2.6.39/sound/soc/atmel/playpaq_wm8510.c 2011-05-19 00:06:34.000000000 -0400
83240 +++ linux-2.6.39/sound/soc/atmel/playpaq_wm8510.c 2011-05-22 19:36:35.000000000 -0400
83241 @@ -289,7 +289,7 @@ static int playpaq_wm8510_hw_params(stru
83242
83243
83244
83245 -static struct snd_soc_ops playpaq_wm8510_ops = {
83246 +static const struct snd_soc_ops playpaq_wm8510_ops = {
83247 .hw_params = playpaq_wm8510_hw_params,
83248 };
83249
83250 diff -urNp linux-2.6.39/sound/soc/atmel/sam9g20_wm8731.c linux-2.6.39/sound/soc/atmel/sam9g20_wm8731.c
83251 --- linux-2.6.39/sound/soc/atmel/sam9g20_wm8731.c 2011-05-19 00:06:34.000000000 -0400
83252 +++ linux-2.6.39/sound/soc/atmel/sam9g20_wm8731.c 2011-05-22 19:36:35.000000000 -0400
83253 @@ -87,7 +87,7 @@ static int at91sam9g20ek_hw_params(struc
83254 return 0;
83255 }
83256
83257 -static struct snd_soc_ops at91sam9g20ek_ops = {
83258 +static const struct snd_soc_ops at91sam9g20ek_ops = {
83259 .hw_params = at91sam9g20ek_hw_params,
83260 };
83261
83262 diff -urNp linux-2.6.39/sound/soc/atmel/snd-soc-afeb9260.c linux-2.6.39/sound/soc/atmel/snd-soc-afeb9260.c
83263 --- linux-2.6.39/sound/soc/atmel/snd-soc-afeb9260.c 2011-05-19 00:06:34.000000000 -0400
83264 +++ linux-2.6.39/sound/soc/atmel/snd-soc-afeb9260.c 2011-05-22 19:36:35.000000000 -0400
83265 @@ -81,7 +81,7 @@ static int afeb9260_hw_params(struct snd
83266 return err;
83267 }
83268
83269 -static struct snd_soc_ops afeb9260_ops = {
83270 +static const struct snd_soc_ops afeb9260_ops = {
83271 .hw_params = afeb9260_hw_params,
83272 };
83273
83274 diff -urNp linux-2.6.39/sound/soc/au1x/db1200.c linux-2.6.39/sound/soc/au1x/db1200.c
83275 --- linux-2.6.39/sound/soc/au1x/db1200.c 2011-05-19 00:06:34.000000000 -0400
83276 +++ linux-2.6.39/sound/soc/au1x/db1200.c 2011-05-22 19:36:35.000000000 -0400
83277 @@ -67,7 +67,7 @@ out:
83278 return ret;
83279 }
83280
83281 -static struct snd_soc_ops db1200_i2s_wm8731_ops = {
83282 +static const struct snd_soc_ops db1200_i2s_wm8731_ops = {
83283 .startup = db1200_i2s_startup,
83284 };
83285
83286 diff -urNp linux-2.6.39/sound/soc/au1x/dbdma2.c linux-2.6.39/sound/soc/au1x/dbdma2.c
83287 --- linux-2.6.39/sound/soc/au1x/dbdma2.c 2011-05-19 00:06:34.000000000 -0400
83288 +++ linux-2.6.39/sound/soc/au1x/dbdma2.c 2011-05-22 19:36:35.000000000 -0400
83289 @@ -303,7 +303,7 @@ static int au1xpsc_pcm_close(struct snd_
83290 return 0;
83291 }
83292
83293 -static struct snd_pcm_ops au1xpsc_pcm_ops = {
83294 +static const struct snd_pcm_ops au1xpsc_pcm_ops = {
83295 .open = au1xpsc_pcm_open,
83296 .close = au1xpsc_pcm_close,
83297 .ioctl = snd_pcm_lib_ioctl,
83298 diff -urNp linux-2.6.39/sound/soc/blackfin/bf5xx-ac97.c linux-2.6.39/sound/soc/blackfin/bf5xx-ac97.c
83299 --- linux-2.6.39/sound/soc/blackfin/bf5xx-ac97.c 2011-05-19 00:06:34.000000000 -0400
83300 +++ linux-2.6.39/sound/soc/blackfin/bf5xx-ac97.c 2011-05-22 19:36:35.000000000 -0400
83301 @@ -244,7 +244,7 @@ static void bf5xx_ac97_cold_reset(struct
83302 #endif
83303 }
83304
83305 -struct snd_ac97_bus_ops soc_ac97_ops = {
83306 +const struct snd_ac97_bus_ops soc_ac97_ops = {
83307 .read = bf5xx_ac97_read,
83308 .write = bf5xx_ac97_write,
83309 .warm_reset = bf5xx_ac97_warm_reset,
83310 diff -urNp linux-2.6.39/sound/soc/blackfin/bf5xx-ac97.h linux-2.6.39/sound/soc/blackfin/bf5xx-ac97.h
83311 --- linux-2.6.39/sound/soc/blackfin/bf5xx-ac97.h 2011-05-19 00:06:34.000000000 -0400
83312 +++ linux-2.6.39/sound/soc/blackfin/bf5xx-ac97.h 2011-05-22 19:36:35.000000000 -0400
83313 @@ -9,7 +9,7 @@
83314 #ifndef _BF5XX_AC97_H
83315 #define _BF5XX_AC97_H
83316
83317 -extern struct snd_ac97_bus_ops bf5xx_ac97_ops;
83318 +extern const struct snd_ac97_bus_ops bf5xx_ac97_ops;
83319 extern struct snd_ac97 *ac97;
83320 /* Frame format in memory, only support stereo currently */
83321 struct ac97_frame {
83322 diff -urNp linux-2.6.39/sound/soc/blackfin/bf5xx-ac97-pcm.c linux-2.6.39/sound/soc/blackfin/bf5xx-ac97-pcm.c
83323 --- linux-2.6.39/sound/soc/blackfin/bf5xx-ac97-pcm.c 2011-05-19 00:06:34.000000000 -0400
83324 +++ linux-2.6.39/sound/soc/blackfin/bf5xx-ac97-pcm.c 2011-05-22 19:36:35.000000000 -0400
83325 @@ -297,7 +297,7 @@ static int bf5xx_pcm_copy(struct snd_pcm
83326 }
83327 #endif
83328
83329 -static struct snd_pcm_ops bf5xx_pcm_ac97_ops = {
83330 +static const struct snd_pcm_ops bf5xx_pcm_ac97_ops = {
83331 .open = bf5xx_pcm_open,
83332 .ioctl = snd_pcm_lib_ioctl,
83333 .hw_params = bf5xx_pcm_hw_params,
83334 diff -urNp linux-2.6.39/sound/soc/blackfin/bf5xx-ad1836.c linux-2.6.39/sound/soc/blackfin/bf5xx-ad1836.c
83335 --- linux-2.6.39/sound/soc/blackfin/bf5xx-ad1836.c 2011-05-19 00:06:34.000000000 -0400
83336 +++ linux-2.6.39/sound/soc/blackfin/bf5xx-ad1836.c 2011-05-22 19:36:35.000000000 -0400
83337 @@ -74,7 +74,7 @@ static int bf5xx_ad1836_hw_params(struct
83338 return 0;
83339 }
83340
83341 -static struct snd_soc_ops bf5xx_ad1836_ops = {
83342 +static const struct snd_soc_ops bf5xx_ad1836_ops = {
83343 .startup = bf5xx_ad1836_startup,
83344 .hw_params = bf5xx_ad1836_hw_params,
83345 };
83346 diff -urNp linux-2.6.39/sound/soc/blackfin/bf5xx-ad193x.c linux-2.6.39/sound/soc/blackfin/bf5xx-ad193x.c
83347 --- linux-2.6.39/sound/soc/blackfin/bf5xx-ad193x.c 2011-05-19 00:06:34.000000000 -0400
83348 +++ linux-2.6.39/sound/soc/blackfin/bf5xx-ad193x.c 2011-05-22 19:36:35.000000000 -0400
83349 @@ -88,7 +88,7 @@ static int bf5xx_ad193x_hw_params(struct
83350 return 0;
83351 }
83352
83353 -static struct snd_soc_ops bf5xx_ad193x_ops = {
83354 +static const struct snd_soc_ops bf5xx_ad193x_ops = {
83355 .startup = bf5xx_ad193x_startup,
83356 .hw_params = bf5xx_ad193x_hw_params,
83357 };
83358 diff -urNp linux-2.6.39/sound/soc/blackfin/bf5xx-ad1980.c linux-2.6.39/sound/soc/blackfin/bf5xx-ad1980.c
83359 --- linux-2.6.39/sound/soc/blackfin/bf5xx-ad1980.c 2011-05-19 00:06:34.000000000 -0400
83360 +++ linux-2.6.39/sound/soc/blackfin/bf5xx-ad1980.c 2011-05-22 19:36:35.000000000 -0400
83361 @@ -63,7 +63,7 @@ static int bf5xx_board_startup(struct sn
83362 return 0;
83363 }
83364
83365 -static struct snd_soc_ops bf5xx_board_ops = {
83366 +static const struct snd_soc_ops bf5xx_board_ops = {
83367 .startup = bf5xx_board_startup,
83368 };
83369
83370 diff -urNp linux-2.6.39/sound/soc/blackfin/bf5xx-ad73311.c linux-2.6.39/sound/soc/blackfin/bf5xx-ad73311.c
83371 --- linux-2.6.39/sound/soc/blackfin/bf5xx-ad73311.c 2011-05-19 00:06:34.000000000 -0400
83372 +++ linux-2.6.39/sound/soc/blackfin/bf5xx-ad73311.c 2011-05-22 19:36:35.000000000 -0400
83373 @@ -175,7 +175,7 @@ static int bf5xx_ad73311_hw_params(struc
83374 }
83375
83376
83377 -static struct snd_soc_ops bf5xx_ad73311_ops = {
83378 +static const struct snd_soc_ops bf5xx_ad73311_ops = {
83379 .startup = bf5xx_ad73311_startup,
83380 .hw_params = bf5xx_ad73311_hw_params,
83381 };
83382 diff -urNp linux-2.6.39/sound/soc/blackfin/bf5xx-i2s-pcm.c linux-2.6.39/sound/soc/blackfin/bf5xx-i2s-pcm.c
83383 --- linux-2.6.39/sound/soc/blackfin/bf5xx-i2s-pcm.c 2011-05-19 00:06:34.000000000 -0400
83384 +++ linux-2.6.39/sound/soc/blackfin/bf5xx-i2s-pcm.c 2011-05-22 19:36:35.000000000 -0400
83385 @@ -183,7 +183,7 @@ static int bf5xx_pcm_mmap(struct snd_pcm
83386 return 0 ;
83387 }
83388
83389 -static struct snd_pcm_ops bf5xx_pcm_i2s_ops = {
83390 +static const struct snd_pcm_ops bf5xx_pcm_i2s_ops = {
83391 .open = bf5xx_pcm_open,
83392 .ioctl = snd_pcm_lib_ioctl,
83393 .hw_params = bf5xx_pcm_hw_params,
83394 diff -urNp linux-2.6.39/sound/soc/blackfin/bf5xx-ssm2602.c linux-2.6.39/sound/soc/blackfin/bf5xx-ssm2602.c
83395 --- linux-2.6.39/sound/soc/blackfin/bf5xx-ssm2602.c 2011-05-19 00:06:34.000000000 -0400
83396 +++ linux-2.6.39/sound/soc/blackfin/bf5xx-ssm2602.c 2011-05-22 19:36:35.000000000 -0400
83397 @@ -108,7 +108,7 @@ static int bf5xx_ssm2602_hw_params(struc
83398 return 0;
83399 }
83400
83401 -static struct snd_soc_ops bf5xx_ssm2602_ops = {
83402 +static const struct snd_soc_ops bf5xx_ssm2602_ops = {
83403 .startup = bf5xx_ssm2602_startup,
83404 .hw_params = bf5xx_ssm2602_hw_params,
83405 };
83406 diff -urNp linux-2.6.39/sound/soc/blackfin/bf5xx-tdm-pcm.c linux-2.6.39/sound/soc/blackfin/bf5xx-tdm-pcm.c
83407 --- linux-2.6.39/sound/soc/blackfin/bf5xx-tdm-pcm.c 2011-05-19 00:06:34.000000000 -0400
83408 +++ linux-2.6.39/sound/soc/blackfin/bf5xx-tdm-pcm.c 2011-05-22 19:36:35.000000000 -0400
83409 @@ -220,7 +220,7 @@ static int bf5xx_pcm_silence(struct snd_
83410 }
83411
83412
83413 -struct snd_pcm_ops bf5xx_pcm_tdm_ops = {
83414 +const struct snd_pcm_ops bf5xx_pcm_tdm_ops = {
83415 .open = bf5xx_pcm_open,
83416 .ioctl = snd_pcm_lib_ioctl,
83417 .hw_params = bf5xx_pcm_hw_params,
83418 diff -urNp linux-2.6.39/sound/soc/davinci/davinci-evm.c linux-2.6.39/sound/soc/davinci/davinci-evm.c
83419 --- linux-2.6.39/sound/soc/davinci/davinci-evm.c 2011-05-19 00:06:34.000000000 -0400
83420 +++ linux-2.6.39/sound/soc/davinci/davinci-evm.c 2011-05-22 19:36:35.000000000 -0400
83421 @@ -88,11 +88,11 @@ static int evm_spdif_hw_params(struct sn
83422 return snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT);
83423 }
83424
83425 -static struct snd_soc_ops evm_ops = {
83426 +static const struct snd_soc_ops evm_ops = {
83427 .hw_params = evm_hw_params,
83428 };
83429
83430 -static struct snd_soc_ops evm_spdif_ops = {
83431 +static const struct snd_soc_ops evm_spdif_ops = {
83432 .hw_params = evm_spdif_hw_params,
83433 };
83434
83435 diff -urNp linux-2.6.39/sound/soc/davinci/davinci-pcm.c linux-2.6.39/sound/soc/davinci/davinci-pcm.c
83436 --- linux-2.6.39/sound/soc/davinci/davinci-pcm.c 2011-05-19 00:06:34.000000000 -0400
83437 +++ linux-2.6.39/sound/soc/davinci/davinci-pcm.c 2011-05-22 19:36:35.000000000 -0400
83438 @@ -748,7 +748,7 @@ static int davinci_pcm_mmap(struct snd_p
83439 runtime->dma_bytes);
83440 }
83441
83442 -static struct snd_pcm_ops davinci_pcm_ops = {
83443 +static const struct snd_pcm_ops davinci_pcm_ops = {
83444 .open = davinci_pcm_open,
83445 .close = davinci_pcm_close,
83446 .ioctl = snd_pcm_lib_ioctl,
83447 diff -urNp linux-2.6.39/sound/soc/davinci/davinci-sffsdr.c linux-2.6.39/sound/soc/davinci/davinci-sffsdr.c
83448 --- linux-2.6.39/sound/soc/davinci/davinci-sffsdr.c 2011-05-19 00:06:34.000000000 -0400
83449 +++ linux-2.6.39/sound/soc/davinci/davinci-sffsdr.c 2011-05-22 19:36:35.000000000 -0400
83450 @@ -75,7 +75,7 @@ static int sffsdr_hw_params(struct snd_p
83451 #endif
83452 }
83453
83454 -static struct snd_soc_ops sffsdr_ops = {
83455 +static const struct snd_soc_ops sffsdr_ops = {
83456 .hw_params = sffsdr_hw_params,
83457 };
83458
83459 diff -urNp linux-2.6.39/sound/soc/ep93xx/edb93xx.c linux-2.6.39/sound/soc/ep93xx/edb93xx.c
83460 --- linux-2.6.39/sound/soc/ep93xx/edb93xx.c 2011-05-19 00:06:34.000000000 -0400
83461 +++ linux-2.6.39/sound/soc/ep93xx/edb93xx.c 2011-05-22 19:36:35.000000000 -0400
83462 @@ -74,7 +74,7 @@ static int edb93xx_hw_params(struct snd_
83463 SND_SOC_CLOCK_OUT);
83464 }
83465
83466 -static struct snd_soc_ops edb93xx_ops = {
83467 +static const struct snd_soc_ops edb93xx_ops = {
83468 .hw_params = edb93xx_hw_params,
83469 };
83470
83471 diff -urNp linux-2.6.39/sound/soc/ep93xx/ep93xx-ac97.c linux-2.6.39/sound/soc/ep93xx/ep93xx-ac97.c
83472 --- linux-2.6.39/sound/soc/ep93xx/ep93xx-ac97.c 2011-05-19 00:06:34.000000000 -0400
83473 +++ linux-2.6.39/sound/soc/ep93xx/ep93xx-ac97.c 2011-05-22 19:36:35.000000000 -0400
83474 @@ -239,7 +239,7 @@ static irqreturn_t ep93xx_ac97_interrupt
83475 return IRQ_HANDLED;
83476 }
83477
83478 -struct snd_ac97_bus_ops soc_ac97_ops = {
83479 +const struct snd_ac97_bus_ops soc_ac97_ops = {
83480 .read = ep93xx_ac97_read,
83481 .write = ep93xx_ac97_write,
83482 .reset = ep93xx_ac97_cold_reset,
83483 diff -urNp linux-2.6.39/sound/soc/ep93xx/ep93xx-pcm.c linux-2.6.39/sound/soc/ep93xx/ep93xx-pcm.c
83484 --- linux-2.6.39/sound/soc/ep93xx/ep93xx-pcm.c 2011-05-19 00:06:34.000000000 -0400
83485 +++ linux-2.6.39/sound/soc/ep93xx/ep93xx-pcm.c 2011-05-22 19:36:35.000000000 -0400
83486 @@ -216,7 +216,7 @@ static int ep93xx_pcm_mmap(struct snd_pc
83487 runtime->dma_bytes);
83488 }
83489
83490 -static struct snd_pcm_ops ep93xx_pcm_ops = {
83491 +static const struct snd_pcm_ops ep93xx_pcm_ops = {
83492 .open = ep93xx_pcm_open,
83493 .close = ep93xx_pcm_close,
83494 .ioctl = snd_pcm_lib_ioctl,
83495 diff -urNp linux-2.6.39/sound/soc/ep93xx/snappercl15.c linux-2.6.39/sound/soc/ep93xx/snappercl15.c
83496 --- linux-2.6.39/sound/soc/ep93xx/snappercl15.c 2011-05-19 00:06:34.000000000 -0400
83497 +++ linux-2.6.39/sound/soc/ep93xx/snappercl15.c 2011-05-22 19:36:35.000000000 -0400
83498 @@ -55,7 +55,7 @@ static int snappercl15_hw_params(struct
83499 return 0;
83500 }
83501
83502 -static struct snd_soc_ops snappercl15_ops = {
83503 +static const struct snd_soc_ops snappercl15_ops = {
83504 .hw_params = snappercl15_hw_params,
83505 };
83506
83507 diff -urNp linux-2.6.39/sound/soc/fsl/fsl_dma.c linux-2.6.39/sound/soc/fsl/fsl_dma.c
83508 --- linux-2.6.39/sound/soc/fsl/fsl_dma.c 2011-05-19 00:06:34.000000000 -0400
83509 +++ linux-2.6.39/sound/soc/fsl/fsl_dma.c 2011-05-22 19:36:35.000000000 -0400
83510 @@ -887,7 +887,7 @@ static struct device_node *find_ssi_node
83511 return NULL;
83512 }
83513
83514 -static struct snd_pcm_ops fsl_dma_ops = {
83515 +static const struct snd_pcm_ops fsl_dma_ops = {
83516 .open = fsl_dma_open,
83517 .close = fsl_dma_close,
83518 .ioctl = snd_pcm_lib_ioctl,
83519 diff -urNp linux-2.6.39/sound/soc/fsl/mpc8610_hpcd.c linux-2.6.39/sound/soc/fsl/mpc8610_hpcd.c
83520 --- linux-2.6.39/sound/soc/fsl/mpc8610_hpcd.c 2011-05-19 00:06:34.000000000 -0400
83521 +++ linux-2.6.39/sound/soc/fsl/mpc8610_hpcd.c 2011-05-22 19:36:35.000000000 -0400
83522 @@ -175,7 +175,7 @@ static int mpc8610_hpcd_machine_remove(s
83523 /**
83524 * mpc8610_hpcd_ops: ASoC machine driver operations
83525 */
83526 -static struct snd_soc_ops mpc8610_hpcd_ops = {
83527 +static const struct snd_soc_ops mpc8610_hpcd_ops = {
83528 .startup = mpc8610_hpcd_startup,
83529 };
83530
83531 diff -urNp linux-2.6.39/sound/soc/fsl/p1022_ds.c linux-2.6.39/sound/soc/fsl/p1022_ds.c
83532 --- linux-2.6.39/sound/soc/fsl/p1022_ds.c 2011-05-19 00:06:34.000000000 -0400
83533 +++ linux-2.6.39/sound/soc/fsl/p1022_ds.c 2011-05-22 19:36:35.000000000 -0400
83534 @@ -185,7 +185,7 @@ static int p1022_ds_machine_remove(struc
83535 /**
83536 * p1022_ds_ops: ASoC machine driver operations
83537 */
83538 -static struct snd_soc_ops p1022_ds_ops = {
83539 +static const struct snd_soc_ops p1022_ds_ops = {
83540 .startup = p1022_ds_startup,
83541 };
83542
83543 diff -urNp linux-2.6.39/sound/soc/imx/eukrea-tlv320.c linux-2.6.39/sound/soc/imx/eukrea-tlv320.c
83544 --- linux-2.6.39/sound/soc/imx/eukrea-tlv320.c 2011-05-19 00:06:34.000000000 -0400
83545 +++ linux-2.6.39/sound/soc/imx/eukrea-tlv320.c 2011-05-22 19:36:35.000000000 -0400
83546 @@ -71,7 +71,7 @@ static int eukrea_tlv320_hw_params(struc
83547 return 0;
83548 }
83549
83550 -static struct snd_soc_ops eukrea_tlv320_snd_ops = {
83551 +static const struct snd_soc_ops eukrea_tlv320_snd_ops = {
83552 .hw_params = eukrea_tlv320_hw_params,
83553 };
83554
83555 diff -urNp linux-2.6.39/sound/soc/imx/imx-pcm-dma-mx2.c linux-2.6.39/sound/soc/imx/imx-pcm-dma-mx2.c
83556 --- linux-2.6.39/sound/soc/imx/imx-pcm-dma-mx2.c 2011-05-19 00:06:34.000000000 -0400
83557 +++ linux-2.6.39/sound/soc/imx/imx-pcm-dma-mx2.c 2011-05-22 19:36:35.000000000 -0400
83558 @@ -283,7 +283,7 @@ static int snd_imx_close(struct snd_pcm_
83559 return 0;
83560 }
83561
83562 -static struct snd_pcm_ops imx_pcm_ops = {
83563 +static const struct snd_pcm_ops imx_pcm_ops = {
83564 .open = snd_imx_open,
83565 .close = snd_imx_close,
83566 .ioctl = snd_pcm_lib_ioctl,
83567 diff -urNp linux-2.6.39/sound/soc/imx/imx-pcm-fiq.c linux-2.6.39/sound/soc/imx/imx-pcm-fiq.c
83568 --- linux-2.6.39/sound/soc/imx/imx-pcm-fiq.c 2011-05-19 00:06:34.000000000 -0400
83569 +++ linux-2.6.39/sound/soc/imx/imx-pcm-fiq.c 2011-05-22 19:36:35.000000000 -0400
83570 @@ -225,7 +225,7 @@ static int snd_imx_close(struct snd_pcm_
83571 return 0;
83572 }
83573
83574 -static struct snd_pcm_ops imx_pcm_ops = {
83575 +static const struct snd_pcm_ops imx_pcm_ops = {
83576 .open = snd_imx_open,
83577 .close = snd_imx_close,
83578 .ioctl = snd_pcm_lib_ioctl,
83579 diff -urNp linux-2.6.39/sound/soc/imx/mx27vis-aic32x4.c linux-2.6.39/sound/soc/imx/mx27vis-aic32x4.c
83580 --- linux-2.6.39/sound/soc/imx/mx27vis-aic32x4.c 2011-05-19 00:06:34.000000000 -0400
83581 +++ linux-2.6.39/sound/soc/imx/mx27vis-aic32x4.c 2011-05-22 19:36:35.000000000 -0400
83582 @@ -70,7 +70,7 @@ static int mx27vis_aic32x4_hw_params(str
83583 return 0;
83584 }
83585
83586 -static struct snd_soc_ops mx27vis_aic32x4_snd_ops = {
83587 +static const struct snd_soc_ops mx27vis_aic32x4_snd_ops = {
83588 .hw_params = mx27vis_aic32x4_hw_params,
83589 };
83590
83591 diff -urNp linux-2.6.39/sound/soc/imx/phycore-ac97.c linux-2.6.39/sound/soc/imx/phycore-ac97.c
83592 --- linux-2.6.39/sound/soc/imx/phycore-ac97.c 2011-05-19 00:06:34.000000000 -0400
83593 +++ linux-2.6.39/sound/soc/imx/phycore-ac97.c 2011-05-22 19:36:35.000000000 -0400
83594 @@ -21,7 +21,7 @@
83595
83596 static struct snd_soc_card imx_phycore;
83597
83598 -static struct snd_soc_ops imx_phycore_hifi_ops = {
83599 +static const struct snd_soc_ops imx_phycore_hifi_ops = {
83600 };
83601
83602 static struct snd_soc_dai_link imx_phycore_dai_ac97[] = {
83603 diff -urNp linux-2.6.39/sound/soc/imx/wm1133-ev1.c linux-2.6.39/sound/soc/imx/wm1133-ev1.c
83604 --- linux-2.6.39/sound/soc/imx/wm1133-ev1.c 2011-05-19 00:06:34.000000000 -0400
83605 +++ linux-2.6.39/sound/soc/imx/wm1133-ev1.c 2011-05-22 19:36:35.000000000 -0400
83606 @@ -149,7 +149,7 @@ static int wm1133_ev1_hw_params(struct s
83607 return 0;
83608 }
83609
83610 -static struct snd_soc_ops wm1133_ev1_ops = {
83611 +static const struct snd_soc_ops wm1133_ev1_ops = {
83612 .hw_params = wm1133_ev1_hw_params,
83613 };
83614
83615 diff -urNp linux-2.6.39/sound/soc/jz4740/jz4740-pcm.c linux-2.6.39/sound/soc/jz4740/jz4740-pcm.c
83616 --- linux-2.6.39/sound/soc/jz4740/jz4740-pcm.c 2011-05-19 00:06:34.000000000 -0400
83617 +++ linux-2.6.39/sound/soc/jz4740/jz4740-pcm.c 2011-05-22 19:36:35.000000000 -0400
83618 @@ -244,7 +244,7 @@ static int jz4740_pcm_mmap(struct snd_pc
83619 vma->vm_end - vma->vm_start, vma->vm_page_prot);
83620 }
83621
83622 -static struct snd_pcm_ops jz4740_pcm_ops = {
83623 +static const struct snd_pcm_ops jz4740_pcm_ops = {
83624 .open = jz4740_pcm_open,
83625 .close = jz4740_pcm_close,
83626 .ioctl = snd_pcm_lib_ioctl,
83627 diff -urNp linux-2.6.39/sound/soc/kirkwood/kirkwood-openrd.c linux-2.6.39/sound/soc/kirkwood/kirkwood-openrd.c
83628 --- linux-2.6.39/sound/soc/kirkwood/kirkwood-openrd.c 2011-05-19 00:06:34.000000000 -0400
83629 +++ linux-2.6.39/sound/soc/kirkwood/kirkwood-openrd.c 2011-05-22 19:36:35.000000000 -0400
83630 @@ -56,7 +56,7 @@ static int openrd_client_hw_params(struc
83631
83632 }
83633
83634 -static struct snd_soc_ops openrd_client_ops = {
83635 +static const struct snd_soc_ops openrd_client_ops = {
83636 .hw_params = openrd_client_hw_params,
83637 };
83638
83639 diff -urNp linux-2.6.39/sound/soc/kirkwood/kirkwood-t5325.c linux-2.6.39/sound/soc/kirkwood/kirkwood-t5325.c
83640 --- linux-2.6.39/sound/soc/kirkwood/kirkwood-t5325.c 2011-05-19 00:06:34.000000000 -0400
83641 +++ linux-2.6.39/sound/soc/kirkwood/kirkwood-t5325.c 2011-05-22 19:36:35.000000000 -0400
83642 @@ -44,7 +44,7 @@ static int t5325_hw_params(struct snd_pc
83643
83644 }
83645
83646 -static struct snd_soc_ops t5325_ops = {
83647 +static const struct snd_soc_ops t5325_ops = {
83648 .hw_params = t5325_hw_params,
83649 };
83650
83651 diff -urNp linux-2.6.39/sound/soc/mid-x86/sst_platform.c linux-2.6.39/sound/soc/mid-x86/sst_platform.c
83652 --- linux-2.6.39/sound/soc/mid-x86/sst_platform.c 2011-05-19 00:06:34.000000000 -0400
83653 +++ linux-2.6.39/sound/soc/mid-x86/sst_platform.c 2011-05-22 19:36:35.000000000 -0400
83654 @@ -381,7 +381,7 @@ static int sst_platform_pcm_hw_free(stru
83655 return snd_pcm_lib_free_pages(substream);
83656 }
83657
83658 -static struct snd_pcm_ops sst_platform_ops = {
83659 +static const struct snd_pcm_ops sst_platform_ops = {
83660 .open = sst_platform_open,
83661 .close = sst_platform_close,
83662 .ioctl = snd_pcm_lib_ioctl,
83663 diff -urNp linux-2.6.39/sound/soc/nuc900/nuc900-pcm.c linux-2.6.39/sound/soc/nuc900/nuc900-pcm.c
83664 --- linux-2.6.39/sound/soc/nuc900/nuc900-pcm.c 2011-05-19 00:06:34.000000000 -0400
83665 +++ linux-2.6.39/sound/soc/nuc900/nuc900-pcm.c 2011-05-22 19:36:35.000000000 -0400
83666 @@ -297,7 +297,7 @@ static int nuc900_dma_mmap(struct snd_pc
83667 runtime->dma_bytes);
83668 }
83669
83670 -static struct snd_pcm_ops nuc900_dma_ops = {
83671 +static const struct snd_pcm_ops nuc900_dma_ops = {
83672 .open = nuc900_dma_open,
83673 .close = nuc900_dma_close,
83674 .ioctl = snd_pcm_lib_ioctl,
83675 diff -urNp linux-2.6.39/sound/soc/omap/am3517evm.c linux-2.6.39/sound/soc/omap/am3517evm.c
83676 --- linux-2.6.39/sound/soc/omap/am3517evm.c 2011-05-19 00:06:34.000000000 -0400
83677 +++ linux-2.6.39/sound/soc/omap/am3517evm.c 2011-05-22 19:36:35.000000000 -0400
83678 @@ -88,7 +88,7 @@ static int am3517evm_hw_params(struct sn
83679 return 0;
83680 }
83681
83682 -static struct snd_soc_ops am3517evm_ops = {
83683 +static const struct snd_soc_ops am3517evm_ops = {
83684 .hw_params = am3517evm_hw_params,
83685 };
83686
83687 diff -urNp linux-2.6.39/sound/soc/omap/ams-delta.c linux-2.6.39/sound/soc/omap/ams-delta.c
83688 --- linux-2.6.39/sound/soc/omap/ams-delta.c 2011-05-19 00:06:34.000000000 -0400
83689 +++ linux-2.6.39/sound/soc/omap/ams-delta.c 2011-05-22 19:36:35.000000000 -0400
83690 @@ -420,7 +420,7 @@ static int ams_delta_hw_params(struct sn
83691 SND_SOC_DAIFMT_CBM_CFM);
83692 }
83693
83694 -static struct snd_soc_ops ams_delta_ops = {
83695 +static const struct snd_soc_ops ams_delta_ops = {
83696 .hw_params = ams_delta_hw_params,
83697 };
83698
83699 diff -urNp linux-2.6.39/sound/soc/omap/igep0020.c linux-2.6.39/sound/soc/omap/igep0020.c
83700 --- linux-2.6.39/sound/soc/omap/igep0020.c 2011-05-19 00:06:34.000000000 -0400
83701 +++ linux-2.6.39/sound/soc/omap/igep0020.c 2011-05-22 19:36:35.000000000 -0400
83702 @@ -72,7 +72,7 @@ static int igep2_hw_params(struct snd_pc
83703 return 0;
83704 }
83705
83706 -static struct snd_soc_ops igep2_ops = {
83707 +static const struct snd_soc_ops igep2_ops = {
83708 .hw_params = igep2_hw_params,
83709 };
83710
83711 diff -urNp linux-2.6.39/sound/soc/omap/n810.c linux-2.6.39/sound/soc/omap/n810.c
83712 --- linux-2.6.39/sound/soc/omap/n810.c 2011-05-19 00:06:34.000000000 -0400
83713 +++ linux-2.6.39/sound/soc/omap/n810.c 2011-05-22 19:36:35.000000000 -0400
83714 @@ -141,7 +141,7 @@ static int n810_hw_params(struct snd_pcm
83715 return err;
83716 }
83717
83718 -static struct snd_soc_ops n810_ops = {
83719 +static const struct snd_soc_ops n810_ops = {
83720 .startup = n810_startup,
83721 .hw_params = n810_hw_params,
83722 .shutdown = n810_shutdown,
83723 diff -urNp linux-2.6.39/sound/soc/omap/omap2evm.c linux-2.6.39/sound/soc/omap/omap2evm.c
83724 --- linux-2.6.39/sound/soc/omap/omap2evm.c 2011-05-19 00:06:34.000000000 -0400
83725 +++ linux-2.6.39/sound/soc/omap/omap2evm.c 2011-05-22 19:36:35.000000000 -0400
83726 @@ -74,7 +74,7 @@ static int omap2evm_hw_params(struct snd
83727 return 0;
83728 }
83729
83730 -static struct snd_soc_ops omap2evm_ops = {
83731 +static const struct snd_soc_ops omap2evm_ops = {
83732 .hw_params = omap2evm_hw_params,
83733 };
83734
83735 diff -urNp linux-2.6.39/sound/soc/omap/omap3beagle.c linux-2.6.39/sound/soc/omap/omap3beagle.c
83736 --- linux-2.6.39/sound/soc/omap/omap3beagle.c 2011-05-19 00:06:34.000000000 -0400
83737 +++ linux-2.6.39/sound/soc/omap/omap3beagle.c 2011-05-22 19:36:35.000000000 -0400
83738 @@ -82,7 +82,7 @@ static int omap3beagle_hw_params(struct
83739 return 0;
83740 }
83741
83742 -static struct snd_soc_ops omap3beagle_ops = {
83743 +static const struct snd_soc_ops omap3beagle_ops = {
83744 .hw_params = omap3beagle_hw_params,
83745 };
83746
83747 diff -urNp linux-2.6.39/sound/soc/omap/omap3evm.c linux-2.6.39/sound/soc/omap/omap3evm.c
83748 --- linux-2.6.39/sound/soc/omap/omap3evm.c 2011-05-19 00:06:34.000000000 -0400
83749 +++ linux-2.6.39/sound/soc/omap/omap3evm.c 2011-05-22 19:36:35.000000000 -0400
83750 @@ -70,7 +70,7 @@ static int omap3evm_hw_params(struct snd
83751 return 0;
83752 }
83753
83754 -static struct snd_soc_ops omap3evm_ops = {
83755 +static const struct snd_soc_ops omap3evm_ops = {
83756 .hw_params = omap3evm_hw_params,
83757 };
83758
83759 diff -urNp linux-2.6.39/sound/soc/omap/omap3pandora.c linux-2.6.39/sound/soc/omap/omap3pandora.c
83760 --- linux-2.6.39/sound/soc/omap/omap3pandora.c 2011-05-19 00:06:34.000000000 -0400
83761 +++ linux-2.6.39/sound/soc/omap/omap3pandora.c 2011-05-22 19:36:35.000000000 -0400
83762 @@ -218,7 +218,7 @@ static int omap3pandora_in_init(struct s
83763 return snd_soc_dapm_sync(dapm);
83764 }
83765
83766 -static struct snd_soc_ops omap3pandora_ops = {
83767 +static const struct snd_soc_ops omap3pandora_ops = {
83768 .hw_params = omap3pandora_hw_params,
83769 };
83770
83771 diff -urNp linux-2.6.39/sound/soc/omap/omap-pcm.c linux-2.6.39/sound/soc/omap/omap-pcm.c
83772 --- linux-2.6.39/sound/soc/omap/omap-pcm.c 2011-05-19 00:06:34.000000000 -0400
83773 +++ linux-2.6.39/sound/soc/omap/omap-pcm.c 2011-05-22 19:36:35.000000000 -0400
83774 @@ -311,7 +311,7 @@ static int omap_pcm_mmap(struct snd_pcm_
83775 runtime->dma_bytes);
83776 }
83777
83778 -static struct snd_pcm_ops omap_pcm_ops = {
83779 +static const struct snd_pcm_ops omap_pcm_ops = {
83780 .open = omap_pcm_open,
83781 .close = omap_pcm_close,
83782 .ioctl = snd_pcm_lib_ioctl,
83783 diff -urNp linux-2.6.39/sound/soc/omap/osk5912.c linux-2.6.39/sound/soc/omap/osk5912.c
83784 --- linux-2.6.39/sound/soc/omap/osk5912.c 2011-05-19 00:06:34.000000000 -0400
83785 +++ linux-2.6.39/sound/soc/omap/osk5912.c 2011-05-22 19:36:35.000000000 -0400
83786 @@ -90,7 +90,7 @@ static int osk_hw_params(struct snd_pcm_
83787 return err;
83788 }
83789
83790 -static struct snd_soc_ops osk_ops = {
83791 +static const struct snd_soc_ops osk_ops = {
83792 .startup = osk_startup,
83793 .hw_params = osk_hw_params,
83794 .shutdown = osk_shutdown,
83795 diff -urNp linux-2.6.39/sound/soc/omap/overo.c linux-2.6.39/sound/soc/omap/overo.c
83796 --- linux-2.6.39/sound/soc/omap/overo.c 2011-05-19 00:06:34.000000000 -0400
83797 +++ linux-2.6.39/sound/soc/omap/overo.c 2011-05-22 19:36:35.000000000 -0400
83798 @@ -72,7 +72,7 @@ static int overo_hw_params(struct snd_pc
83799 return 0;
83800 }
83801
83802 -static struct snd_soc_ops overo_ops = {
83803 +static const struct snd_soc_ops overo_ops = {
83804 .hw_params = overo_hw_params,
83805 };
83806
83807 diff -urNp linux-2.6.39/sound/soc/omap/rx51.c linux-2.6.39/sound/soc/omap/rx51.c
83808 --- linux-2.6.39/sound/soc/omap/rx51.c 2011-05-19 00:06:34.000000000 -0400
83809 +++ linux-2.6.39/sound/soc/omap/rx51.c 2011-05-22 19:36:35.000000000 -0400
83810 @@ -139,7 +139,7 @@ static int rx51_hw_params(struct snd_pcm
83811 SND_SOC_CLOCK_IN);
83812 }
83813
83814 -static struct snd_soc_ops rx51_ops = {
83815 +static const struct snd_soc_ops rx51_ops = {
83816 .startup = rx51_startup,
83817 .hw_params = rx51_hw_params,
83818 };
83819 diff -urNp linux-2.6.39/sound/soc/omap/sdp3430.c linux-2.6.39/sound/soc/omap/sdp3430.c
83820 --- linux-2.6.39/sound/soc/omap/sdp3430.c 2011-05-19 00:06:34.000000000 -0400
83821 +++ linux-2.6.39/sound/soc/omap/sdp3430.c 2011-05-22 19:36:35.000000000 -0400
83822 @@ -87,7 +87,7 @@ static int sdp3430_hw_params(struct snd_
83823 return 0;
83824 }
83825
83826 -static struct snd_soc_ops sdp3430_ops = {
83827 +static const struct snd_soc_ops sdp3430_ops = {
83828 .hw_params = sdp3430_hw_params,
83829 };
83830
83831 @@ -130,7 +130,7 @@ static int sdp3430_hw_voice_params(struc
83832 return 0;
83833 }
83834
83835 -static struct snd_soc_ops sdp3430_voice_ops = {
83836 +static const struct snd_soc_ops sdp3430_voice_ops = {
83837 .hw_params = sdp3430_hw_voice_params,
83838 };
83839
83840 diff -urNp linux-2.6.39/sound/soc/omap/sdp4430.c linux-2.6.39/sound/soc/omap/sdp4430.c
83841 --- linux-2.6.39/sound/soc/omap/sdp4430.c 2011-05-19 00:06:34.000000000 -0400
83842 +++ linux-2.6.39/sound/soc/omap/sdp4430.c 2011-05-22 19:36:35.000000000 -0400
83843 @@ -62,7 +62,7 @@ static int sdp4430_hw_params(struct snd_
83844 return ret;
83845 }
83846
83847 -static struct snd_soc_ops sdp4430_ops = {
83848 +static const struct snd_soc_ops sdp4430_ops = {
83849 .hw_params = sdp4430_hw_params,
83850 };
83851
83852 diff -urNp linux-2.6.39/sound/soc/omap/zoom2.c linux-2.6.39/sound/soc/omap/zoom2.c
83853 --- linux-2.6.39/sound/soc/omap/zoom2.c 2011-05-19 00:06:34.000000000 -0400
83854 +++ linux-2.6.39/sound/soc/omap/zoom2.c 2011-05-22 19:36:35.000000000 -0400
83855 @@ -78,7 +78,7 @@ static int zoom2_hw_params(struct snd_pc
83856 return 0;
83857 }
83858
83859 -static struct snd_soc_ops zoom2_ops = {
83860 +static const struct snd_soc_ops zoom2_ops = {
83861 .hw_params = zoom2_hw_params,
83862 };
83863
83864 @@ -121,7 +121,7 @@ static int zoom2_hw_voice_params(struct
83865 return 0;
83866 }
83867
83868 -static struct snd_soc_ops zoom2_voice_ops = {
83869 +static const struct snd_soc_ops zoom2_voice_ops = {
83870 .hw_params = zoom2_hw_voice_params,
83871 };
83872
83873 diff -urNp linux-2.6.39/sound/soc/pxa/corgi.c linux-2.6.39/sound/soc/pxa/corgi.c
83874 --- linux-2.6.39/sound/soc/pxa/corgi.c 2011-05-19 00:06:34.000000000 -0400
83875 +++ linux-2.6.39/sound/soc/pxa/corgi.c 2011-05-22 19:36:35.000000000 -0400
83876 @@ -169,7 +169,7 @@ static int corgi_hw_params(struct snd_pc
83877 return 0;
83878 }
83879
83880 -static struct snd_soc_ops corgi_ops = {
83881 +static const struct snd_soc_ops corgi_ops = {
83882 .startup = corgi_startup,
83883 .hw_params = corgi_hw_params,
83884 .shutdown = corgi_shutdown,
83885 diff -urNp linux-2.6.39/sound/soc/pxa/imote2.c linux-2.6.39/sound/soc/pxa/imote2.c
83886 --- linux-2.6.39/sound/soc/pxa/imote2.c 2011-05-19 00:06:34.000000000 -0400
83887 +++ linux-2.6.39/sound/soc/pxa/imote2.c 2011-05-22 19:36:35.000000000 -0400
83888 @@ -56,7 +56,7 @@ static int imote2_asoc_hw_params(struct
83889 return ret;
83890 }
83891
83892 -static struct snd_soc_ops imote2_asoc_ops = {
83893 +static const struct snd_soc_ops imote2_asoc_ops = {
83894 .hw_params = imote2_asoc_hw_params,
83895 };
83896
83897 diff -urNp linux-2.6.39/sound/soc/pxa/magician.c linux-2.6.39/sound/soc/pxa/magician.c
83898 --- linux-2.6.39/sound/soc/pxa/magician.c 2011-05-19 00:06:34.000000000 -0400
83899 +++ linux-2.6.39/sound/soc/pxa/magician.c 2011-05-22 19:36:35.000000000 -0400
83900 @@ -258,12 +258,12 @@ static int magician_capture_hw_params(st
83901 return 0;
83902 }
83903
83904 -static struct snd_soc_ops magician_capture_ops = {
83905 +static const struct snd_soc_ops magician_capture_ops = {
83906 .startup = magician_startup,
83907 .hw_params = magician_capture_hw_params,
83908 };
83909
83910 -static struct snd_soc_ops magician_playback_ops = {
83911 +static const struct snd_soc_ops magician_playback_ops = {
83912 .startup = magician_startup,
83913 .hw_params = magician_playback_hw_params,
83914 };
83915 diff -urNp linux-2.6.39/sound/soc/pxa/mioa701_wm9713.c linux-2.6.39/sound/soc/pxa/mioa701_wm9713.c
83916 --- linux-2.6.39/sound/soc/pxa/mioa701_wm9713.c 2011-05-19 00:06:34.000000000 -0400
83917 +++ linux-2.6.39/sound/soc/pxa/mioa701_wm9713.c 2011-05-22 19:36:35.000000000 -0400
83918 @@ -156,7 +156,7 @@ static int mioa701_wm9713_init(struct sn
83919 return 0;
83920 }
83921
83922 -static struct snd_soc_ops mioa701_ops;
83923 +static const struct snd_soc_ops mioa701_ops;
83924
83925 static struct snd_soc_dai_link mioa701_dai[] = {
83926 {
83927 diff -urNp linux-2.6.39/sound/soc/pxa/poodle.c linux-2.6.39/sound/soc/pxa/poodle.c
83928 --- linux-2.6.39/sound/soc/pxa/poodle.c 2011-05-19 00:06:34.000000000 -0400
83929 +++ linux-2.6.39/sound/soc/pxa/poodle.c 2011-05-22 19:36:35.000000000 -0400
83930 @@ -148,7 +148,7 @@ static int poodle_hw_params(struct snd_p
83931 return 0;
83932 }
83933
83934 -static struct snd_soc_ops poodle_ops = {
83935 +static const struct snd_soc_ops poodle_ops = {
83936 .startup = poodle_startup,
83937 .hw_params = poodle_hw_params,
83938 .shutdown = poodle_shutdown,
83939 diff -urNp linux-2.6.39/sound/soc/pxa/pxa2xx-ac97.c linux-2.6.39/sound/soc/pxa/pxa2xx-ac97.c
83940 --- linux-2.6.39/sound/soc/pxa/pxa2xx-ac97.c 2011-05-19 00:06:34.000000000 -0400
83941 +++ linux-2.6.39/sound/soc/pxa/pxa2xx-ac97.c 2011-05-22 19:36:35.000000000 -0400
83942 @@ -40,7 +40,7 @@ static void pxa2xx_ac97_cold_reset(struc
83943 pxa2xx_ac97_finish_reset(ac97);
83944 }
83945
83946 -struct snd_ac97_bus_ops soc_ac97_ops = {
83947 +const struct snd_ac97_bus_ops soc_ac97_ops = {
83948 .read = pxa2xx_ac97_read,
83949 .write = pxa2xx_ac97_write,
83950 .warm_reset = pxa2xx_ac97_warm_reset,
83951 diff -urNp linux-2.6.39/sound/soc/pxa/pxa2xx-ac97.h linux-2.6.39/sound/soc/pxa/pxa2xx-ac97.h
83952 --- linux-2.6.39/sound/soc/pxa/pxa2xx-ac97.h 2011-05-19 00:06:34.000000000 -0400
83953 +++ linux-2.6.39/sound/soc/pxa/pxa2xx-ac97.h 2011-05-22 19:36:35.000000000 -0400
83954 @@ -15,6 +15,6 @@
83955 #define PXA2XX_DAI_AC97_MIC 2
83956
83957 /* platform data */
83958 -extern struct snd_ac97_bus_ops pxa2xx_ac97_ops;
83959 +extern const struct snd_ac97_bus_ops pxa2xx_ac97_ops;
83960
83961 #endif
83962 diff -urNp linux-2.6.39/sound/soc/pxa/raumfeld.c linux-2.6.39/sound/soc/pxa/raumfeld.c
83963 --- linux-2.6.39/sound/soc/pxa/raumfeld.c 2011-05-19 00:06:34.000000000 -0400
83964 +++ linux-2.6.39/sound/soc/pxa/raumfeld.c 2011-05-22 19:36:35.000000000 -0400
83965 @@ -145,7 +145,7 @@ static int raumfeld_cs4270_hw_params(str
83966 return 0;
83967 }
83968
83969 -static struct snd_soc_ops raumfeld_cs4270_ops = {
83970 +static const struct snd_soc_ops raumfeld_cs4270_ops = {
83971 .startup = raumfeld_cs4270_startup,
83972 .shutdown = raumfeld_cs4270_shutdown,
83973 .hw_params = raumfeld_cs4270_hw_params,
83974 @@ -221,7 +221,7 @@ static int raumfeld_ak4104_hw_params(str
83975 return 0;
83976 }
83977
83978 -static struct snd_soc_ops raumfeld_ak4104_ops = {
83979 +static const struct snd_soc_ops raumfeld_ak4104_ops = {
83980 .hw_params = raumfeld_ak4104_hw_params,
83981 };
83982
83983 diff -urNp linux-2.6.39/sound/soc/pxa/saarb.c linux-2.6.39/sound/soc/pxa/saarb.c
83984 --- linux-2.6.39/sound/soc/pxa/saarb.c 2011-05-19 00:06:34.000000000 -0400
83985 +++ linux-2.6.39/sound/soc/pxa/saarb.c 2011-05-22 19:36:35.000000000 -0400
83986 @@ -106,7 +106,7 @@ static int saarb_i2s_hw_params(struct sn
83987 return ret;
83988 }
83989
83990 -static struct snd_soc_ops saarb_i2s_ops = {
83991 +static const struct snd_soc_ops saarb_i2s_ops = {
83992 .hw_params = saarb_i2s_hw_params,
83993 };
83994
83995 diff -urNp linux-2.6.39/sound/soc/pxa/spitz.c linux-2.6.39/sound/soc/pxa/spitz.c
83996 --- linux-2.6.39/sound/soc/pxa/spitz.c 2011-05-19 00:06:34.000000000 -0400
83997 +++ linux-2.6.39/sound/soc/pxa/spitz.c 2011-05-22 19:36:35.000000000 -0400
83998 @@ -169,7 +169,7 @@ static int spitz_hw_params(struct snd_pc
83999 return 0;
84000 }
84001
84002 -static struct snd_soc_ops spitz_ops = {
84003 +static const struct snd_soc_ops spitz_ops = {
84004 .startup = spitz_startup,
84005 .hw_params = spitz_hw_params,
84006 };
84007 diff -urNp linux-2.6.39/sound/soc/pxa/tavorevb3.c linux-2.6.39/sound/soc/pxa/tavorevb3.c
84008 --- linux-2.6.39/sound/soc/pxa/tavorevb3.c 2011-05-19 00:06:34.000000000 -0400
84009 +++ linux-2.6.39/sound/soc/pxa/tavorevb3.c 2011-05-22 19:36:35.000000000 -0400
84010 @@ -106,7 +106,7 @@ static int evb3_i2s_hw_params(struct snd
84011 return ret;
84012 }
84013
84014 -static struct snd_soc_ops evb3_i2s_ops = {
84015 +static const struct snd_soc_ops evb3_i2s_ops = {
84016 .hw_params = evb3_i2s_hw_params,
84017 };
84018
84019 diff -urNp linux-2.6.39/sound/soc/pxa/tosa.c linux-2.6.39/sound/soc/pxa/tosa.c
84020 --- linux-2.6.39/sound/soc/pxa/tosa.c 2011-05-19 00:06:34.000000000 -0400
84021 +++ linux-2.6.39/sound/soc/pxa/tosa.c 2011-05-22 19:36:35.000000000 -0400
84022 @@ -92,7 +92,7 @@ static int tosa_startup(struct snd_pcm_s
84023 return 0;
84024 }
84025
84026 -static struct snd_soc_ops tosa_ops = {
84027 +static const struct snd_soc_ops tosa_ops = {
84028 .startup = tosa_startup,
84029 };
84030
84031 diff -urNp linux-2.6.39/sound/soc/pxa/z2.c linux-2.6.39/sound/soc/pxa/z2.c
84032 --- linux-2.6.39/sound/soc/pxa/z2.c 2011-05-19 00:06:34.000000000 -0400
84033 +++ linux-2.6.39/sound/soc/pxa/z2.c 2011-05-22 19:36:35.000000000 -0400
84034 @@ -187,7 +187,7 @@ err:
84035 return ret;
84036 }
84037
84038 -static struct snd_soc_ops z2_ops = {
84039 +static const struct snd_soc_ops z2_ops = {
84040 .hw_params = z2_hw_params,
84041 };
84042
84043 diff -urNp linux-2.6.39/sound/soc/pxa/zylonite.c linux-2.6.39/sound/soc/pxa/zylonite.c
84044 --- linux-2.6.39/sound/soc/pxa/zylonite.c 2011-05-19 00:06:34.000000000 -0400
84045 +++ linux-2.6.39/sound/soc/pxa/zylonite.c 2011-05-22 19:36:35.000000000 -0400
84046 @@ -156,7 +156,7 @@ static int zylonite_voice_hw_params(stru
84047 return 0;
84048 }
84049
84050 -static struct snd_soc_ops zylonite_voice_ops = {
84051 +static const struct snd_soc_ops zylonite_voice_ops = {
84052 .hw_params = zylonite_voice_hw_params,
84053 };
84054
84055 diff -urNp linux-2.6.39/sound/soc/s6000/s6000-pcm.c linux-2.6.39/sound/soc/s6000/s6000-pcm.c
84056 --- linux-2.6.39/sound/soc/s6000/s6000-pcm.c 2011-05-19 00:06:34.000000000 -0400
84057 +++ linux-2.6.39/sound/soc/s6000/s6000-pcm.c 2011-05-22 19:36:35.000000000 -0400
84058 @@ -420,7 +420,7 @@ static int s6000_pcm_hw_free(struct snd_
84059 return snd_pcm_lib_free_pages(substream);
84060 }
84061
84062 -static struct snd_pcm_ops s6000_pcm_ops = {
84063 +static const struct snd_pcm_ops s6000_pcm_ops = {
84064 .open = s6000_pcm_open,
84065 .close = s6000_pcm_close,
84066 .ioctl = snd_pcm_lib_ioctl,
84067 diff -urNp linux-2.6.39/sound/soc/s6000/s6105-ipcam.c linux-2.6.39/sound/soc/s6000/s6105-ipcam.c
84068 --- linux-2.6.39/sound/soc/s6000/s6105-ipcam.c 2011-05-19 00:06:34.000000000 -0400
84069 +++ linux-2.6.39/sound/soc/s6000/s6105-ipcam.c 2011-05-22 19:36:35.000000000 -0400
84070 @@ -55,7 +55,7 @@ static int s6105_hw_params(struct snd_pc
84071 return 0;
84072 }
84073
84074 -static struct snd_soc_ops s6105_ops = {
84075 +static const struct snd_soc_ops s6105_ops = {
84076 .hw_params = s6105_hw_params,
84077 };
84078
84079 diff -urNp linux-2.6.39/sound/soc/samsung/goni_wm8994.c linux-2.6.39/sound/soc/samsung/goni_wm8994.c
84080 --- linux-2.6.39/sound/soc/samsung/goni_wm8994.c 2011-05-19 00:06:34.000000000 -0400
84081 +++ linux-2.6.39/sound/soc/samsung/goni_wm8994.c 2011-05-22 19:36:35.000000000 -0400
84082 @@ -176,7 +176,7 @@ static int goni_hifi_hw_params(struct sn
84083 return 0;
84084 }
84085
84086 -static struct snd_soc_ops goni_hifi_ops = {
84087 +static const struct snd_soc_ops goni_hifi_ops = {
84088 .hw_params = goni_hifi_hw_params,
84089 };
84090
84091 @@ -227,7 +227,7 @@ static struct snd_soc_dai_driver voice_d
84092 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
84093 };
84094
84095 -static struct snd_soc_ops goni_voice_ops = {
84096 +static const struct snd_soc_ops goni_voice_ops = {
84097 .hw_params = goni_voice_hw_params,
84098 };
84099
84100 diff -urNp linux-2.6.39/sound/soc/samsung/h1940_uda1380.c linux-2.6.39/sound/soc/samsung/h1940_uda1380.c
84101 --- linux-2.6.39/sound/soc/samsung/h1940_uda1380.c 2011-05-19 00:06:34.000000000 -0400
84102 +++ linux-2.6.39/sound/soc/samsung/h1940_uda1380.c 2011-05-22 19:36:35.000000000 -0400
84103 @@ -136,7 +136,7 @@ static int h1940_hw_params(struct snd_pc
84104 return 0;
84105 }
84106
84107 -static struct snd_soc_ops h1940_ops = {
84108 +static const struct snd_soc_ops h1940_ops = {
84109 .startup = h1940_startup,
84110 .hw_params = h1940_hw_params,
84111 };
84112 diff -urNp linux-2.6.39/sound/soc/samsung/jive_wm8750.c linux-2.6.39/sound/soc/samsung/jive_wm8750.c
84113 --- linux-2.6.39/sound/soc/samsung/jive_wm8750.c 2011-05-19 00:06:34.000000000 -0400
84114 +++ linux-2.6.39/sound/soc/samsung/jive_wm8750.c 2011-05-22 19:36:35.000000000 -0400
84115 @@ -92,7 +92,7 @@ static int jive_hw_params(struct snd_pcm
84116 return 0;
84117 }
84118
84119 -static struct snd_soc_ops jive_ops = {
84120 +static const struct snd_soc_ops jive_ops = {
84121 .hw_params = jive_hw_params,
84122 };
84123
84124 diff -urNp linux-2.6.39/sound/soc/samsung/neo1973_wm8753.c linux-2.6.39/sound/soc/samsung/neo1973_wm8753.c
84125 --- linux-2.6.39/sound/soc/samsung/neo1973_wm8753.c 2011-05-19 00:06:34.000000000 -0400
84126 +++ linux-2.6.39/sound/soc/samsung/neo1973_wm8753.c 2011-05-22 19:36:35.000000000 -0400
84127 @@ -128,7 +128,7 @@ static int neo1973_hifi_hw_free(struct s
84128 /*
84129 * Neo1973 WM8753 HiFi DAI opserations.
84130 */
84131 -static struct snd_soc_ops neo1973_hifi_ops = {
84132 +static const struct snd_soc_ops neo1973_hifi_ops = {
84133 .hw_params = neo1973_hifi_hw_params,
84134 .hw_free = neo1973_hifi_hw_free,
84135 };
84136 @@ -187,7 +187,7 @@ static int neo1973_voice_hw_free(struct
84137 return snd_soc_dai_set_pll(codec_dai, WM8753_PLL2, 0, 0, 0);
84138 }
84139
84140 -static struct snd_soc_ops neo1973_voice_ops = {
84141 +static const struct snd_soc_ops neo1973_voice_ops = {
84142 .hw_params = neo1973_voice_hw_params,
84143 .hw_free = neo1973_voice_hw_free,
84144 };
84145 diff -urNp linux-2.6.39/sound/soc/samsung/rx1950_uda1380.c linux-2.6.39/sound/soc/samsung/rx1950_uda1380.c
84146 --- linux-2.6.39/sound/soc/samsung/rx1950_uda1380.c 2011-05-19 00:06:34.000000000 -0400
84147 +++ linux-2.6.39/sound/soc/samsung/rx1950_uda1380.c 2011-05-22 19:36:35.000000000 -0400
84148 @@ -70,7 +70,7 @@ static struct snd_soc_jack_gpio hp_jack_
84149 },
84150 };
84151
84152 -static struct snd_soc_ops rx1950_ops = {
84153 +static const struct snd_soc_ops rx1950_ops = {
84154 .startup = rx1950_startup,
84155 .hw_params = rx1950_hw_params,
84156 };
84157 diff -urNp linux-2.6.39/sound/soc/samsung/s3c24xx_simtec.c linux-2.6.39/sound/soc/samsung/s3c24xx_simtec.c
84158 --- linux-2.6.39/sound/soc/samsung/s3c24xx_simtec.c 2011-05-19 00:06:34.000000000 -0400
84159 +++ linux-2.6.39/sound/soc/samsung/s3c24xx_simtec.c 2011-05-22 19:36:35.000000000 -0400
84160 @@ -228,7 +228,7 @@ static int simtec_call_startup(struct s3
84161 return 0;
84162 }
84163
84164 -static struct snd_soc_ops simtec_snd_ops = {
84165 +static const struct snd_soc_ops simtec_snd_ops = {
84166 .hw_params = simtec_hw_params,
84167 };
84168
84169 diff -urNp linux-2.6.39/sound/soc/samsung/s3c24xx_uda134x.c linux-2.6.39/sound/soc/samsung/s3c24xx_uda134x.c
84170 --- linux-2.6.39/sound/soc/samsung/s3c24xx_uda134x.c 2011-05-19 00:06:34.000000000 -0400
84171 +++ linux-2.6.39/sound/soc/samsung/s3c24xx_uda134x.c 2011-05-22 19:36:35.000000000 -0400
84172 @@ -210,7 +210,7 @@ static int s3c24xx_uda134x_hw_params(str
84173 return 0;
84174 }
84175
84176 -static struct snd_soc_ops s3c24xx_uda134x_ops = {
84177 +static const struct snd_soc_ops s3c24xx_uda134x_ops = {
84178 .startup = s3c24xx_uda134x_startup,
84179 .shutdown = s3c24xx_uda134x_shutdown,
84180 .hw_params = s3c24xx_uda134x_hw_params,
84181 diff -urNp linux-2.6.39/sound/soc/samsung/smartq_wm8987.c linux-2.6.39/sound/soc/samsung/smartq_wm8987.c
84182 --- linux-2.6.39/sound/soc/samsung/smartq_wm8987.c 2011-05-19 00:06:34.000000000 -0400
84183 +++ linux-2.6.39/sound/soc/samsung/smartq_wm8987.c 2011-05-22 19:36:35.000000000 -0400
84184 @@ -92,7 +92,7 @@ static int smartq_hifi_hw_params(struct
84185 /*
84186 * SmartQ WM8987 HiFi DAI operations.
84187 */
84188 -static struct snd_soc_ops smartq_hifi_ops = {
84189 +static const struct snd_soc_ops smartq_hifi_ops = {
84190 .hw_params = smartq_hifi_hw_params,
84191 };
84192
84193 diff -urNp linux-2.6.39/sound/soc/samsung/smdk_spdif.c linux-2.6.39/sound/soc/samsung/smdk_spdif.c
84194 --- linux-2.6.39/sound/soc/samsung/smdk_spdif.c 2011-05-19 00:06:34.000000000 -0400
84195 +++ linux-2.6.39/sound/soc/samsung/smdk_spdif.c 2011-05-22 19:36:35.000000000 -0400
84196 @@ -143,7 +143,7 @@ static int smdk_hw_params(struct snd_pcm
84197 return ret;
84198 }
84199
84200 -static struct snd_soc_ops smdk_spdif_ops = {
84201 +static const struct snd_soc_ops smdk_spdif_ops = {
84202 .hw_params = smdk_hw_params,
84203 };
84204
84205 diff -urNp linux-2.6.39/sound/soc/samsung/smdk_wm8580.c linux-2.6.39/sound/soc/samsung/smdk_wm8580.c
84206 --- linux-2.6.39/sound/soc/samsung/smdk_wm8580.c 2011-05-19 00:06:34.000000000 -0400
84207 +++ linux-2.6.39/sound/soc/samsung/smdk_wm8580.c 2011-05-22 19:36:35.000000000 -0400
84208 @@ -114,7 +114,7 @@ static int smdk_hw_params(struct snd_pcm
84209 /*
84210 * SMDK WM8580 DAI operations.
84211 */
84212 -static struct snd_soc_ops smdk_ops = {
84213 +static const struct snd_soc_ops smdk_ops = {
84214 .hw_params = smdk_hw_params,
84215 };
84216
84217 diff -urNp linux-2.6.39/sound/soc/sh/dma-sh7760.c linux-2.6.39/sound/soc/sh/dma-sh7760.c
84218 --- linux-2.6.39/sound/soc/sh/dma-sh7760.c 2011-05-19 00:06:34.000000000 -0400
84219 +++ linux-2.6.39/sound/soc/sh/dma-sh7760.c 2011-05-22 19:36:35.000000000 -0400
84220 @@ -311,7 +311,7 @@ static snd_pcm_uframes_t camelot_pos(str
84221 return bytes_to_frames(runtime, pos);
84222 }
84223
84224 -static struct snd_pcm_ops camelot_pcm_ops = {
84225 +static const struct snd_pcm_ops camelot_pcm_ops = {
84226 .open = camelot_pcm_open,
84227 .close = camelot_pcm_close,
84228 .ioctl = snd_pcm_lib_ioctl,
84229 diff -urNp linux-2.6.39/sound/soc/sh/hac.c linux-2.6.39/sound/soc/sh/hac.c
84230 --- linux-2.6.39/sound/soc/sh/hac.c 2011-05-19 00:06:34.000000000 -0400
84231 +++ linux-2.6.39/sound/soc/sh/hac.c 2011-05-22 19:36:35.000000000 -0400
84232 @@ -227,7 +227,7 @@ static void hac_ac97_coldrst(struct snd_
84233 hac_ac97_warmrst(ac97);
84234 }
84235
84236 -struct snd_ac97_bus_ops soc_ac97_ops = {
84237 +const struct snd_ac97_bus_ops soc_ac97_ops = {
84238 .read = hac_ac97_read,
84239 .write = hac_ac97_write,
84240 .reset = hac_ac97_coldrst,
84241 diff -urNp linux-2.6.39/sound/soc/sh/migor.c linux-2.6.39/sound/soc/sh/migor.c
84242 --- linux-2.6.39/sound/soc/sh/migor.c 2011-05-19 00:06:34.000000000 -0400
84243 +++ linux-2.6.39/sound/soc/sh/migor.c 2011-05-22 19:36:35.000000000 -0400
84244 @@ -108,7 +108,7 @@ static int migor_hw_free(struct snd_pcm_
84245 return 0;
84246 }
84247
84248 -static struct snd_soc_ops migor_dai_ops = {
84249 +static const struct snd_soc_ops migor_dai_ops = {
84250 .hw_params = migor_hw_params,
84251 .hw_free = migor_hw_free,
84252 };
84253 diff -urNp linux-2.6.39/sound/soc/sh/siu_pcm.c linux-2.6.39/sound/soc/sh/siu_pcm.c
84254 --- linux-2.6.39/sound/soc/sh/siu_pcm.c 2011-05-19 00:06:34.000000000 -0400
84255 +++ linux-2.6.39/sound/soc/sh/siu_pcm.c 2011-05-22 19:36:35.000000000 -0400
84256 @@ -597,7 +597,7 @@ static void siu_pcm_free(struct snd_pcm
84257 dev_dbg(pcm->card->dev, "%s\n", __func__);
84258 }
84259
84260 -static struct snd_pcm_ops siu_pcm_ops = {
84261 +static const struct snd_pcm_ops siu_pcm_ops = {
84262 .open = siu_pcm_open,
84263 .close = siu_pcm_close,
84264 .ioctl = snd_pcm_lib_ioctl,
84265 diff -urNp linux-2.6.39/sound/soc/tegra/harmony.c linux-2.6.39/sound/soc/tegra/harmony.c
84266 --- linux-2.6.39/sound/soc/tegra/harmony.c 2011-05-19 00:06:34.000000000 -0400
84267 +++ linux-2.6.39/sound/soc/tegra/harmony.c 2011-05-22 19:36:35.000000000 -0400
84268 @@ -126,7 +126,7 @@ static int harmony_asoc_hw_params(struct
84269 return 0;
84270 }
84271
84272 -static struct snd_soc_ops harmony_asoc_ops = {
84273 +static const struct snd_soc_ops harmony_asoc_ops = {
84274 .hw_params = harmony_asoc_hw_params,
84275 };
84276
84277 diff -urNp linux-2.6.39/sound/soc/tegra/tegra_pcm.c linux-2.6.39/sound/soc/tegra/tegra_pcm.c
84278 --- linux-2.6.39/sound/soc/tegra/tegra_pcm.c 2011-05-19 00:06:34.000000000 -0400
84279 +++ linux-2.6.39/sound/soc/tegra/tegra_pcm.c 2011-05-22 19:36:36.000000000 -0400
84280 @@ -277,7 +277,7 @@ static int tegra_pcm_mmap(struct snd_pcm
84281 runtime->dma_bytes);
84282 }
84283
84284 -static struct snd_pcm_ops tegra_pcm_ops = {
84285 +static const struct snd_pcm_ops tegra_pcm_ops = {
84286 .open = tegra_pcm_open,
84287 .close = tegra_pcm_close,
84288 .ioctl = snd_pcm_lib_ioctl,
84289 diff -urNp linux-2.6.39/sound/soc/txx9/txx9aclc.c linux-2.6.39/sound/soc/txx9/txx9aclc.c
84290 --- linux-2.6.39/sound/soc/txx9/txx9aclc.c 2011-05-19 00:06:34.000000000 -0400
84291 +++ linux-2.6.39/sound/soc/txx9/txx9aclc.c 2011-05-22 19:36:36.000000000 -0400
84292 @@ -272,7 +272,7 @@ static int txx9aclc_pcm_close(struct snd
84293 return 0;
84294 }
84295
84296 -static struct snd_pcm_ops txx9aclc_pcm_ops = {
84297 +static const struct snd_pcm_ops txx9aclc_pcm_ops = {
84298 .open = txx9aclc_pcm_open,
84299 .close = txx9aclc_pcm_close,
84300 .ioctl = snd_pcm_lib_ioctl,
84301 diff -urNp linux-2.6.39/sound/sparc/amd7930.c linux-2.6.39/sound/sparc/amd7930.c
84302 --- linux-2.6.39/sound/sparc/amd7930.c 2011-05-19 00:06:34.000000000 -0400
84303 +++ linux-2.6.39/sound/sparc/amd7930.c 2011-05-22 19:36:36.000000000 -0400
84304 @@ -733,7 +733,7 @@ static int snd_amd7930_hw_free(struct sn
84305 return snd_pcm_lib_free_pages(substream);
84306 }
84307
84308 -static struct snd_pcm_ops snd_amd7930_playback_ops = {
84309 +static const struct snd_pcm_ops snd_amd7930_playback_ops = {
84310 .open = snd_amd7930_playback_open,
84311 .close = snd_amd7930_playback_close,
84312 .ioctl = snd_pcm_lib_ioctl,
84313 @@ -744,7 +744,7 @@ static struct snd_pcm_ops snd_amd7930_pl
84314 .pointer = snd_amd7930_playback_pointer,
84315 };
84316
84317 -static struct snd_pcm_ops snd_amd7930_capture_ops = {
84318 +static const struct snd_pcm_ops snd_amd7930_capture_ops = {
84319 .open = snd_amd7930_capture_open,
84320 .close = snd_amd7930_capture_close,
84321 .ioctl = snd_pcm_lib_ioctl,
84322 @@ -929,7 +929,7 @@ static int snd_amd7930_dev_free(struct s
84323 return snd_amd7930_free(amd);
84324 }
84325
84326 -static struct snd_device_ops snd_amd7930_dev_ops = {
84327 +static const struct snd_device_ops snd_amd7930_dev_ops = {
84328 .dev_free = snd_amd7930_dev_free,
84329 };
84330
84331 diff -urNp linux-2.6.39/sound/sparc/cs4231.c linux-2.6.39/sound/sparc/cs4231.c
84332 --- linux-2.6.39/sound/sparc/cs4231.c 2011-05-19 00:06:34.000000000 -0400
84333 +++ linux-2.6.39/sound/sparc/cs4231.c 2011-05-22 19:36:36.000000000 -0400
84334 @@ -1196,7 +1196,7 @@ static int snd_cs4231_capture_close(stru
84335 * XXX the audio AUXIO register...
84336 */
84337
84338 -static struct snd_pcm_ops snd_cs4231_playback_ops = {
84339 +static const struct snd_pcm_ops snd_cs4231_playback_ops = {
84340 .open = snd_cs4231_playback_open,
84341 .close = snd_cs4231_playback_close,
84342 .ioctl = snd_pcm_lib_ioctl,
84343 @@ -1207,7 +1207,7 @@ static struct snd_pcm_ops snd_cs4231_pla
84344 .pointer = snd_cs4231_playback_pointer,
84345 };
84346
84347 -static struct snd_pcm_ops snd_cs4231_capture_ops = {
84348 +static const struct snd_pcm_ops snd_cs4231_capture_ops = {
84349 .open = snd_cs4231_capture_open,
84350 .close = snd_cs4231_capture_close,
84351 .ioctl = snd_pcm_lib_ioctl,
84352 @@ -1789,7 +1789,7 @@ static int snd_cs4231_sbus_dev_free(stru
84353 return snd_cs4231_sbus_free(cp);
84354 }
84355
84356 -static struct snd_device_ops snd_cs4231_sbus_dev_ops = {
84357 +static const struct snd_device_ops snd_cs4231_sbus_dev_ops = {
84358 .dev_free = snd_cs4231_sbus_dev_free,
84359 };
84360
84361 @@ -1955,7 +1955,7 @@ static int snd_cs4231_ebus_dev_free(stru
84362 return snd_cs4231_ebus_free(cp);
84363 }
84364
84365 -static struct snd_device_ops snd_cs4231_ebus_dev_ops = {
84366 +static const struct snd_device_ops snd_cs4231_ebus_dev_ops = {
84367 .dev_free = snd_cs4231_ebus_dev_free,
84368 };
84369
84370 diff -urNp linux-2.6.39/sound/sparc/dbri.c linux-2.6.39/sound/sparc/dbri.c
84371 --- linux-2.6.39/sound/sparc/dbri.c 2011-05-19 00:06:34.000000000 -0400
84372 +++ linux-2.6.39/sound/sparc/dbri.c 2011-05-22 19:36:36.000000000 -0400
84373 @@ -2205,7 +2205,7 @@ static snd_pcm_uframes_t snd_dbri_pointe
84374 return ret;
84375 }
84376
84377 -static struct snd_pcm_ops snd_dbri_ops = {
84378 +static const struct snd_pcm_ops snd_dbri_ops = {
84379 .open = snd_dbri_open,
84380 .close = snd_dbri_close,
84381 .ioctl = snd_pcm_lib_ioctl,
84382 diff -urNp linux-2.6.39/sound/spi/at73c213.c linux-2.6.39/sound/spi/at73c213.c
84383 --- linux-2.6.39/sound/spi/at73c213.c 2011-05-19 00:06:34.000000000 -0400
84384 +++ linux-2.6.39/sound/spi/at73c213.c 2011-05-22 19:36:36.000000000 -0400
84385 @@ -319,7 +319,7 @@ snd_at73c213_pcm_pointer(struct snd_pcm_
84386 return pos;
84387 }
84388
84389 -static struct snd_pcm_ops at73c213_playback_ops = {
84390 +static const struct snd_pcm_ops at73c213_playback_ops = {
84391 .open = snd_at73c213_pcm_open,
84392 .close = snd_at73c213_pcm_close,
84393 .ioctl = snd_pcm_lib_ioctl,
84394 @@ -882,7 +882,7 @@ static int snd_at73c213_dev_free(struct
84395 static int __devinit snd_at73c213_dev_init(struct snd_card *card,
84396 struct spi_device *spi)
84397 {
84398 - static struct snd_device_ops ops = {
84399 + static const struct snd_device_ops ops = {
84400 .dev_free = snd_at73c213_dev_free,
84401 };
84402 struct snd_at73c213 *chip = get_chip(card);
84403 diff -urNp linux-2.6.39/sound/usb/6fire/midi.c linux-2.6.39/sound/usb/6fire/midi.c
84404 --- linux-2.6.39/sound/usb/6fire/midi.c 2011-05-19 00:06:34.000000000 -0400
84405 +++ linux-2.6.39/sound/usb/6fire/midi.c 2011-05-22 19:36:36.000000000 -0400
84406 @@ -134,14 +134,14 @@ static void usb6fire_midi_in_trigger(
84407 spin_unlock_irqrestore(&rt->in_lock, flags);
84408 }
84409
84410 -static struct snd_rawmidi_ops out_ops = {
84411 +static const struct snd_rawmidi_ops out_ops = {
84412 .open = usb6fire_midi_out_open,
84413 .close = usb6fire_midi_out_close,
84414 .trigger = usb6fire_midi_out_trigger,
84415 .drain = usb6fire_midi_out_drain
84416 };
84417
84418 -static struct snd_rawmidi_ops in_ops = {
84419 +static const struct snd_rawmidi_ops in_ops = {
84420 .open = usb6fire_midi_in_open,
84421 .close = usb6fire_midi_in_close,
84422 .trigger = usb6fire_midi_in_trigger
84423 diff -urNp linux-2.6.39/sound/usb/caiaq/audio.c linux-2.6.39/sound/usb/caiaq/audio.c
84424 --- linux-2.6.39/sound/usb/caiaq/audio.c 2011-05-19 00:06:34.000000000 -0400
84425 +++ linux-2.6.39/sound/usb/caiaq/audio.c 2011-05-22 19:36:36.000000000 -0400
84426 @@ -322,7 +322,7 @@ snd_usb_caiaq_pcm_pointer(struct snd_pcm
84427 }
84428
84429 /* operators for both playback and capture */
84430 -static struct snd_pcm_ops snd_usb_caiaq_ops = {
84431 +static const struct snd_pcm_ops snd_usb_caiaq_ops = {
84432 .open = snd_usb_caiaq_substream_open,
84433 .close = snd_usb_caiaq_substream_close,
84434 .ioctl = snd_pcm_lib_ioctl,
84435 diff -urNp linux-2.6.39/sound/usb/caiaq/midi.c linux-2.6.39/sound/usb/caiaq/midi.c
84436 --- linux-2.6.39/sound/usb/caiaq/midi.c 2011-05-19 00:06:34.000000000 -0400
84437 +++ linux-2.6.39/sound/usb/caiaq/midi.c 2011-05-22 19:36:36.000000000 -0400
84438 @@ -100,15 +100,13 @@ static void snd_usb_caiaq_midi_output_tr
84439 }
84440
84441
84442 -static struct snd_rawmidi_ops snd_usb_caiaq_midi_output =
84443 -{
84444 +static const struct snd_rawmidi_ops snd_usb_caiaq_midi_output = {
84445 .open = snd_usb_caiaq_midi_output_open,
84446 .close = snd_usb_caiaq_midi_output_close,
84447 .trigger = snd_usb_caiaq_midi_output_trigger,
84448 };
84449
84450 -static struct snd_rawmidi_ops snd_usb_caiaq_midi_input =
84451 -{
84452 +static const struct snd_rawmidi_ops snd_usb_caiaq_midi_input = {
84453 .open = snd_usb_caiaq_midi_input_open,
84454 .close = snd_usb_caiaq_midi_input_close,
84455 .trigger = snd_usb_caiaq_midi_input_trigger,
84456 diff -urNp linux-2.6.39/sound/usb/card.c linux-2.6.39/sound/usb/card.c
84457 --- linux-2.6.39/sound/usb/card.c 2011-05-19 00:06:34.000000000 -0400
84458 +++ linux-2.6.39/sound/usb/card.c 2011-05-22 19:36:36.000000000 -0400
84459 @@ -305,7 +305,7 @@ static int snd_usb_audio_create(struct u
84460 struct snd_usb_audio *chip;
84461 int err, len;
84462 char component[14];
84463 - static struct snd_device_ops ops = {
84464 + static const struct snd_device_ops ops = {
84465 .dev_free = snd_usb_audio_dev_free,
84466 };
84467
84468 diff -urNp linux-2.6.39/sound/usb/midi.c linux-2.6.39/sound/usb/midi.c
84469 --- linux-2.6.39/sound/usb/midi.c 2011-05-19 00:06:34.000000000 -0400
84470 +++ linux-2.6.39/sound/usb/midi.c 2011-05-22 19:36:36.000000000 -0400
84471 @@ -1146,14 +1146,14 @@ static void snd_usbmidi_input_trigger(st
84472 clear_bit(substream->number, &umidi->input_triggered);
84473 }
84474
84475 -static struct snd_rawmidi_ops snd_usbmidi_output_ops = {
84476 +static const struct snd_rawmidi_ops snd_usbmidi_output_ops = {
84477 .open = snd_usbmidi_output_open,
84478 .close = snd_usbmidi_output_close,
84479 .trigger = snd_usbmidi_output_trigger,
84480 .drain = snd_usbmidi_output_drain,
84481 };
84482
84483 -static struct snd_rawmidi_ops snd_usbmidi_input_ops = {
84484 +static const struct snd_rawmidi_ops snd_usbmidi_input_ops = {
84485 .open = snd_usbmidi_input_open,
84486 .close = snd_usbmidi_input_close,
84487 .trigger = snd_usbmidi_input_trigger
84488 diff -urNp linux-2.6.39/sound/usb/misc/ua101.c linux-2.6.39/sound/usb/misc/ua101.c
84489 --- linux-2.6.39/sound/usb/misc/ua101.c 2011-05-19 00:06:34.000000000 -0400
84490 +++ linux-2.6.39/sound/usb/misc/ua101.c 2011-05-22 19:36:36.000000000 -0400
84491 @@ -886,7 +886,7 @@ static snd_pcm_uframes_t playback_pcm_po
84492 return ua101_pcm_pointer(ua, &ua->playback);
84493 }
84494
84495 -static struct snd_pcm_ops capture_pcm_ops = {
84496 +static const struct snd_pcm_ops capture_pcm_ops = {
84497 .open = capture_pcm_open,
84498 .close = capture_pcm_close,
84499 .ioctl = snd_pcm_lib_ioctl,
84500 @@ -899,7 +899,7 @@ static struct snd_pcm_ops capture_pcm_op
84501 .mmap = snd_pcm_lib_mmap_vmalloc,
84502 };
84503
84504 -static struct snd_pcm_ops playback_pcm_ops = {
84505 +static const struct snd_pcm_ops playback_pcm_ops = {
84506 .open = playback_pcm_open,
84507 .close = playback_pcm_close,
84508 .ioctl = snd_pcm_lib_ioctl,
84509 diff -urNp linux-2.6.39/sound/usb/mixer.c linux-2.6.39/sound/usb/mixer.c
84510 --- linux-2.6.39/sound/usb/mixer.c 2011-05-19 00:06:34.000000000 -0400
84511 +++ linux-2.6.39/sound/usb/mixer.c 2011-05-22 19:36:36.000000000 -0400
84512 @@ -2201,7 +2201,7 @@ static int snd_usb_mixer_status_create(s
84513 int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif,
84514 int ignore_error)
84515 {
84516 - static struct snd_device_ops dev_ops = {
84517 + static const struct snd_device_ops dev_ops = {
84518 .dev_free = snd_usb_mixer_dev_free
84519 };
84520 struct usb_mixer_interface *mixer;
84521 diff -urNp linux-2.6.39/sound/usb/pcm.c linux-2.6.39/sound/usb/pcm.c
84522 --- linux-2.6.39/sound/usb/pcm.c 2011-05-19 00:06:34.000000000 -0400
84523 +++ linux-2.6.39/sound/usb/pcm.c 2011-05-22 19:36:36.000000000 -0400
84524 @@ -844,7 +844,7 @@ static int snd_usb_capture_close(struct
84525 return snd_usb_pcm_close(substream, SNDRV_PCM_STREAM_CAPTURE);
84526 }
84527
84528 -static struct snd_pcm_ops snd_usb_playback_ops = {
84529 +static const struct snd_pcm_ops snd_usb_playback_ops = {
84530 .open = snd_usb_playback_open,
84531 .close = snd_usb_playback_close,
84532 .ioctl = snd_pcm_lib_ioctl,
84533 @@ -857,7 +857,7 @@ static struct snd_pcm_ops snd_usb_playba
84534 .mmap = snd_pcm_lib_mmap_vmalloc,
84535 };
84536
84537 -static struct snd_pcm_ops snd_usb_capture_ops = {
84538 +static const struct snd_pcm_ops snd_usb_capture_ops = {
84539 .open = snd_usb_capture_open,
84540 .close = snd_usb_capture_close,
84541 .ioctl = snd_pcm_lib_ioctl,
84542 diff -urNp linux-2.6.39/sound/usb/usx2y/usbusx2yaudio.c linux-2.6.39/sound/usb/usx2y/usbusx2yaudio.c
84543 --- linux-2.6.39/sound/usb/usx2y/usbusx2yaudio.c 2011-05-19 00:06:34.000000000 -0400
84544 +++ linux-2.6.39/sound/usb/usx2y/usbusx2yaudio.c 2011-05-22 19:36:36.000000000 -0400
84545 @@ -919,8 +919,7 @@ static int snd_usX2Y_pcm_close(struct sn
84546 }
84547
84548
84549 -static struct snd_pcm_ops snd_usX2Y_pcm_ops =
84550 -{
84551 +static const struct snd_pcm_ops snd_usX2Y_pcm_ops = {
84552 .open = snd_usX2Y_pcm_open,
84553 .close = snd_usX2Y_pcm_close,
84554 .ioctl = snd_pcm_lib_ioctl,
84555 diff -urNp linux-2.6.39/tools/perf/builtin-lock.c linux-2.6.39/tools/perf/builtin-lock.c
84556 --- linux-2.6.39/tools/perf/builtin-lock.c 2011-05-19 00:06:34.000000000 -0400
84557 +++ linux-2.6.39/tools/perf/builtin-lock.c 2011-05-22 19:36:36.000000000 -0400
84558 @@ -635,14 +635,14 @@ end:
84559
84560 /* lock oriented handlers */
84561 /* TODO: handlers for CPU oriented, thread oriented */
84562 -static struct trace_lock_handler report_lock_ops = {
84563 +static const struct trace_lock_handler report_lock_ops = {
84564 .acquire_event = report_lock_acquire_event,
84565 .acquired_event = report_lock_acquired_event,
84566 .contended_event = report_lock_contended_event,
84567 .release_event = report_lock_release_event,
84568 };
84569
84570 -static struct trace_lock_handler *trace_handler;
84571 +static const struct trace_lock_handler *trace_handler;
84572
84573 static void
84574 process_lock_acquire_event(void *data,
84575 diff -urNp linux-2.6.39/tools/perf/builtin-sched.c linux-2.6.39/tools/perf/builtin-sched.c
84576 --- linux-2.6.39/tools/perf/builtin-sched.c 2011-05-19 00:06:34.000000000 -0400
84577 +++ linux-2.6.39/tools/perf/builtin-sched.c 2011-05-22 19:36:36.000000000 -0400
84578 @@ -845,7 +845,7 @@ replay_fork_event(struct trace_fork_even
84579 register_pid(fork_event->child_pid, fork_event->child_comm);
84580 }
84581
84582 -static struct trace_sched_handler replay_ops = {
84583 +static const struct trace_sched_handler replay_ops = {
84584 .wakeup_event = replay_wakeup_event,
84585 .switch_event = replay_switch_event,
84586 .fork_event = replay_fork_event,
84587 @@ -1183,7 +1183,7 @@ latency_migrate_task_event(struct trace_
84588 nr_unordered_timestamps++;
84589 }
84590
84591 -static struct trace_sched_handler lat_ops = {
84592 +static const struct trace_sched_handler lat_ops = {
84593 .wakeup_event = latency_wakeup_event,
84594 .switch_event = latency_switch_event,
84595 .runtime_event = latency_runtime_event,
84596 @@ -1353,7 +1353,7 @@ static void sort_lat(void)
84597 }
84598 }
84599
84600 -static struct trace_sched_handler *trace_handler;
84601 +static const struct trace_sched_handler *trace_handler;
84602
84603 static void
84604 process_sched_wakeup_event(void *data, struct perf_session *session,
84605 @@ -1719,7 +1719,7 @@ static void __cmd_lat(void)
84606
84607 }
84608
84609 -static struct trace_sched_handler map_ops = {
84610 +static const struct trace_sched_handler map_ops = {
84611 .wakeup_event = NULL,
84612 .switch_event = map_switch_event,
84613 .runtime_event = NULL,
84614 diff -urNp linux-2.6.39/usr/gen_init_cpio.c linux-2.6.39/usr/gen_init_cpio.c
84615 --- linux-2.6.39/usr/gen_init_cpio.c 2011-05-19 00:06:34.000000000 -0400
84616 +++ linux-2.6.39/usr/gen_init_cpio.c 2011-05-22 19:36:36.000000000 -0400
84617 @@ -305,7 +305,7 @@ static int cpio_mkfile(const char *name,
84618 int retval;
84619 int rc = -1;
84620 int namesize;
84621 - int i;
84622 + unsigned int i;
84623
84624 mode |= S_IFREG;
84625
84626 @@ -394,9 +394,10 @@ static char *cpio_replace_env(char *new_
84627 *env_var = *expanded = '\0';
84628 strncat(env_var, start + 2, end - start - 2);
84629 strncat(expanded, new_location, start - new_location);
84630 - strncat(expanded, getenv(env_var), PATH_MAX);
84631 - strncat(expanded, end + 1, PATH_MAX);
84632 + strncat(expanded, getenv(env_var), PATH_MAX - strlen(expanded));
84633 + strncat(expanded, end + 1, PATH_MAX - strlen(expanded));
84634 strncpy(new_location, expanded, PATH_MAX);
84635 + new_location[PATH_MAX] = 0;
84636 } else
84637 break;
84638 }
84639 diff -urNp linux-2.6.39/virt/kvm/kvm_main.c linux-2.6.39/virt/kvm/kvm_main.c
84640 --- linux-2.6.39/virt/kvm/kvm_main.c 2011-05-19 00:06:34.000000000 -0400
84641 +++ linux-2.6.39/virt/kvm/kvm_main.c 2011-05-22 19:36:36.000000000 -0400
84642 @@ -73,7 +73,7 @@ LIST_HEAD(vm_list);
84643
84644 static cpumask_var_t cpus_hardware_enabled;
84645 static int kvm_usage_count = 0;
84646 -static atomic_t hardware_enable_failed;
84647 +static atomic_unchecked_t hardware_enable_failed;
84648
84649 struct kmem_cache *kvm_vcpu_cache;
84650 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
84651 @@ -1594,7 +1594,7 @@ static int kvm_vcpu_release(struct inode
84652 return 0;
84653 }
84654
84655 -static struct file_operations kvm_vcpu_fops = {
84656 +static struct file_operations kvm_vcpu_fops = { /* cannot be const */
84657 .release = kvm_vcpu_release,
84658 .unlocked_ioctl = kvm_vcpu_ioctl,
84659 .compat_ioctl = kvm_vcpu_ioctl,
84660 @@ -2063,7 +2063,7 @@ static int kvm_vm_mmap(struct file *file
84661 return 0;
84662 }
84663
84664 -static struct file_operations kvm_vm_fops = {
84665 +static struct file_operations kvm_vm_fops = { /* cannot be const */
84666 .release = kvm_vm_release,
84667 .unlocked_ioctl = kvm_vm_ioctl,
84668 #ifdef CONFIG_COMPAT
84669 @@ -2161,7 +2161,7 @@ out:
84670 return r;
84671 }
84672
84673 -static struct file_operations kvm_chardev_ops = {
84674 +static struct file_operations kvm_chardev_ops = { /* cannot be const */
84675 .unlocked_ioctl = kvm_dev_ioctl,
84676 .compat_ioctl = kvm_dev_ioctl,
84677 .llseek = noop_llseek,
84678 @@ -2187,7 +2187,7 @@ static void hardware_enable_nolock(void
84679
84680 if (r) {
84681 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
84682 - atomic_inc(&hardware_enable_failed);
84683 + atomic_inc_unchecked(&hardware_enable_failed);
84684 printk(KERN_INFO "kvm: enabling virtualization on "
84685 "CPU%d failed\n", cpu);
84686 }
84687 @@ -2241,10 +2241,10 @@ static int hardware_enable_all(void)
84688
84689 kvm_usage_count++;
84690 if (kvm_usage_count == 1) {
84691 - atomic_set(&hardware_enable_failed, 0);
84692 + atomic_set_unchecked(&hardware_enable_failed, 0);
84693 on_each_cpu(hardware_enable_nolock, NULL, 1);
84694
84695 - if (atomic_read(&hardware_enable_failed)) {
84696 + if (atomic_read_unchecked(&hardware_enable_failed)) {
84697 hardware_disable_all_nolock();
84698 r = -EBUSY;
84699 }
84700 @@ -2509,7 +2509,7 @@ static void kvm_sched_out(struct preempt
84701 kvm_arch_vcpu_put(vcpu);
84702 }
84703
84704 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
84705 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
84706 struct module *module)
84707 {
84708 int r;
84709 @@ -2572,7 +2572,7 @@ int kvm_init(void *opaque, unsigned vcpu
84710 if (!vcpu_align)
84711 vcpu_align = __alignof__(struct kvm_vcpu);
84712 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
84713 - 0, NULL);
84714 + SLAB_USERCOPY, NULL);
84715 if (!kvm_vcpu_cache) {
84716 r = -ENOMEM;
84717 goto out_free_3;