]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.2.2-2.6.39.1-201106120643.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.2.2-2.6.39.1-201106120643.patch
CommitLineData
0bbcaee6
PK
1diff -urNp linux-2.6.39.1/arch/alpha/include/asm/dma-mapping.h linux-2.6.39.1/arch/alpha/include/asm/dma-mapping.h
2--- linux-2.6.39.1/arch/alpha/include/asm/dma-mapping.h 2011-05-19 00:06:34.000000000 -0400
3+++ linux-2.6.39.1/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 }
16diff -urNp linux-2.6.39.1/arch/alpha/include/asm/elf.h linux-2.6.39.1/arch/alpha/include/asm/elf.h
17--- linux-2.6.39.1/arch/alpha/include/asm/elf.h 2011-05-19 00:06:34.000000000 -0400
18+++ linux-2.6.39.1/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
33diff -urNp linux-2.6.39.1/arch/alpha/include/asm/pgtable.h linux-2.6.39.1/arch/alpha/include/asm/pgtable.h
34--- linux-2.6.39.1/arch/alpha/include/asm/pgtable.h 2011-05-19 00:06:34.000000000 -0400
35+++ linux-2.6.39.1/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))
54diff -urNp linux-2.6.39.1/arch/alpha/kernel/core_apecs.c linux-2.6.39.1/arch/alpha/kernel/core_apecs.c
55--- linux-2.6.39.1/arch/alpha/kernel/core_apecs.c 2011-05-19 00:06:34.000000000 -0400
56+++ linux-2.6.39.1/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,
66diff -urNp linux-2.6.39.1/arch/alpha/kernel/core_cia.c linux-2.6.39.1/arch/alpha/kernel/core_cia.c
67--- linux-2.6.39.1/arch/alpha/kernel/core_cia.c 2011-05-19 00:06:34.000000000 -0400
68+++ linux-2.6.39.1/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,
78diff -urNp linux-2.6.39.1/arch/alpha/kernel/core_irongate.c linux-2.6.39.1/arch/alpha/kernel/core_irongate.c
79--- linux-2.6.39.1/arch/alpha/kernel/core_irongate.c 2011-05-19 00:06:34.000000000 -0400
80+++ linux-2.6.39.1/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,
90diff -urNp linux-2.6.39.1/arch/alpha/kernel/core_lca.c linux-2.6.39.1/arch/alpha/kernel/core_lca.c
91--- linux-2.6.39.1/arch/alpha/kernel/core_lca.c 2011-05-19 00:06:34.000000000 -0400
92+++ linux-2.6.39.1/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,
102diff -urNp linux-2.6.39.1/arch/alpha/kernel/core_marvel.c linux-2.6.39.1/arch/alpha/kernel/core_marvel.c
103--- linux-2.6.39.1/arch/alpha/kernel/core_marvel.c 2011-05-19 00:06:34.000000000 -0400
104+++ linux-2.6.39.1/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,
114diff -urNp linux-2.6.39.1/arch/alpha/kernel/core_mcpcia.c linux-2.6.39.1/arch/alpha/kernel/core_mcpcia.c
115--- linux-2.6.39.1/arch/alpha/kernel/core_mcpcia.c 2011-05-19 00:06:34.000000000 -0400
116+++ linux-2.6.39.1/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,
126diff -urNp linux-2.6.39.1/arch/alpha/kernel/core_polaris.c linux-2.6.39.1/arch/alpha/kernel/core_polaris.c
127--- linux-2.6.39.1/arch/alpha/kernel/core_polaris.c 2011-05-19 00:06:34.000000000 -0400
128+++ linux-2.6.39.1/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,
138diff -urNp linux-2.6.39.1/arch/alpha/kernel/core_t2.c linux-2.6.39.1/arch/alpha/kernel/core_t2.c
139--- linux-2.6.39.1/arch/alpha/kernel/core_t2.c 2011-05-19 00:06:34.000000000 -0400
140+++ linux-2.6.39.1/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,
150diff -urNp linux-2.6.39.1/arch/alpha/kernel/core_titan.c linux-2.6.39.1/arch/alpha/kernel/core_titan.c
151--- linux-2.6.39.1/arch/alpha/kernel/core_titan.c 2011-05-19 00:06:34.000000000 -0400
152+++ linux-2.6.39.1/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,
162diff -urNp linux-2.6.39.1/arch/alpha/kernel/core_tsunami.c linux-2.6.39.1/arch/alpha/kernel/core_tsunami.c
163--- linux-2.6.39.1/arch/alpha/kernel/core_tsunami.c 2011-05-19 00:06:34.000000000 -0400
164+++ linux-2.6.39.1/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,
174diff -urNp linux-2.6.39.1/arch/alpha/kernel/core_wildfire.c linux-2.6.39.1/arch/alpha/kernel/core_wildfire.c
175--- linux-2.6.39.1/arch/alpha/kernel/core_wildfire.c 2011-05-19 00:06:34.000000000 -0400
176+++ linux-2.6.39.1/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,
186diff -urNp linux-2.6.39.1/arch/alpha/kernel/module.c linux-2.6.39.1/arch/alpha/kernel/module.c
187--- linux-2.6.39.1/arch/alpha/kernel/module.c 2011-05-19 00:06:34.000000000 -0400
188+++ linux-2.6.39.1/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++) {
198diff -urNp linux-2.6.39.1/arch/alpha/kernel/osf_sys.c linux-2.6.39.1/arch/alpha/kernel/osf_sys.c
199--- linux-2.6.39.1/arch/alpha/kernel/osf_sys.c 2011-05-19 00:06:34.000000000 -0400
200+++ linux-2.6.39.1/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
232diff -urNp linux-2.6.39.1/arch/alpha/kernel/pci_iommu.c linux-2.6.39.1/arch/alpha/kernel/pci_iommu.c
233--- linux-2.6.39.1/arch/alpha/kernel/pci_iommu.c 2011-05-19 00:06:34.000000000 -0400
234+++ linux-2.6.39.1/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);
251diff -urNp linux-2.6.39.1/arch/alpha/kernel/pci-noop.c linux-2.6.39.1/arch/alpha/kernel/pci-noop.c
252--- linux-2.6.39.1/arch/alpha/kernel/pci-noop.c 2011-05-19 00:06:34.000000000 -0400
253+++ linux-2.6.39.1/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)
272diff -urNp linux-2.6.39.1/arch/alpha/kernel/proto.h linux-2.6.39.1/arch/alpha/kernel/proto.h
273--- linux-2.6.39.1/arch/alpha/kernel/proto.h 2011-05-19 00:06:34.000000000 -0400
274+++ linux-2.6.39.1/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);
366diff -urNp linux-2.6.39.1/arch/alpha/mm/fault.c linux-2.6.39.1/arch/alpha/mm/fault.c
367--- linux-2.6.39.1/arch/alpha/mm/fault.c 2011-05-19 00:06:34.000000000 -0400
368+++ linux-2.6.39.1/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)))
525diff -urNp linux-2.6.39.1/arch/arm/common/it8152.c linux-2.6.39.1/arch/arm/common/it8152.c
526--- linux-2.6.39.1/arch/arm/common/it8152.c 2011-05-19 00:06:34.000000000 -0400
527+++ linux-2.6.39.1/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 };
537diff -urNp linux-2.6.39.1/arch/arm/common/via82c505.c linux-2.6.39.1/arch/arm/common/via82c505.c
538--- linux-2.6.39.1/arch/arm/common/via82c505.c 2011-05-19 00:06:34.000000000 -0400
539+++ linux-2.6.39.1/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 };
549diff -urNp linux-2.6.39.1/arch/arm/include/asm/cacheflush.h linux-2.6.39.1/arch/arm/include/asm/cacheflush.h
550--- linux-2.6.39.1/arch/arm/include/asm/cacheflush.h 2011-05-19 00:06:34.000000000 -0400
551+++ linux-2.6.39.1/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
561diff -urNp linux-2.6.39.1/arch/arm/include/asm/elf.h linux-2.6.39.1/arch/arm/include/asm/elf.h
562--- linux-2.6.39.1/arch/arm/include/asm/elf.h 2011-05-19 00:06:34.000000000 -0400
563+++ linux-2.6.39.1/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
591diff -urNp linux-2.6.39.1/arch/arm/include/asm/kmap_types.h linux-2.6.39.1/arch/arm/include/asm/kmap_types.h
592--- linux-2.6.39.1/arch/arm/include/asm/kmap_types.h 2011-05-19 00:06:34.000000000 -0400
593+++ linux-2.6.39.1/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
602diff -urNp linux-2.6.39.1/arch/arm/include/asm/outercache.h linux-2.6.39.1/arch/arm/include/asm/outercache.h
603--- linux-2.6.39.1/arch/arm/include/asm/outercache.h 2011-05-19 00:06:34.000000000 -0400
604+++ linux-2.6.39.1/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 {
614diff -urNp linux-2.6.39.1/arch/arm/include/asm/page.h linux-2.6.39.1/arch/arm/include/asm/page.h
615--- linux-2.6.39.1/arch/arm/include/asm/page.h 2011-05-19 00:06:34.000000000 -0400
616+++ linux-2.6.39.1/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
626diff -urNp linux-2.6.39.1/arch/arm/include/asm/uaccess.h linux-2.6.39.1/arch/arm/include/asm/uaccess.h
627--- linux-2.6.39.1/arch/arm/include/asm/uaccess.h 2011-05-19 00:06:34.000000000 -0400
628+++ linux-2.6.39.1/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;
649diff -urNp linux-2.6.39.1/arch/arm/kernel/kgdb.c linux-2.6.39.1/arch/arm/kernel/kgdb.c
650--- linux-2.6.39.1/arch/arm/kernel/kgdb.c 2011-05-19 00:06:34.000000000 -0400
651+++ linux-2.6.39.1/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__ */
661diff -urNp linux-2.6.39.1/arch/arm/kernel/process.c linux-2.6.39.1/arch/arm/kernel/process.c
662--- linux-2.6.39.1/arch/arm/kernel/process.c 2011-05-19 00:06:34.000000000 -0400
663+++ linux-2.6.39.1/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
685diff -urNp linux-2.6.39.1/arch/arm/mach-cns3xxx/pcie.c linux-2.6.39.1/arch/arm/mach-cns3xxx/pcie.c
686--- linux-2.6.39.1/arch/arm/mach-cns3xxx/pcie.c 2011-05-19 00:06:34.000000000 -0400
687+++ linux-2.6.39.1/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 };
697diff -urNp linux-2.6.39.1/arch/arm/mach-dove/pcie.c linux-2.6.39.1/arch/arm/mach-dove/pcie.c
698--- linux-2.6.39.1/arch/arm/mach-dove/pcie.c 2011-05-19 00:06:34.000000000 -0400
699+++ linux-2.6.39.1/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 };
709diff -urNp linux-2.6.39.1/arch/arm/mach-footbridge/dc21285.c linux-2.6.39.1/arch/arm/mach-footbridge/dc21285.c
710--- linux-2.6.39.1/arch/arm/mach-footbridge/dc21285.c 2011-05-19 00:06:34.000000000 -0400
711+++ linux-2.6.39.1/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 };
721diff -urNp linux-2.6.39.1/arch/arm/mach-integrator/pci_v3.c linux-2.6.39.1/arch/arm/mach-integrator/pci_v3.c
722--- linux-2.6.39.1/arch/arm/mach-integrator/pci_v3.c 2011-05-19 00:06:34.000000000 -0400
723+++ linux-2.6.39.1/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 };
733diff -urNp linux-2.6.39.1/arch/arm/mach-iop13xx/pci.c linux-2.6.39.1/arch/arm/mach-iop13xx/pci.c
734--- linux-2.6.39.1/arch/arm/mach-iop13xx/pci.c 2011-05-19 00:06:34.000000000 -0400
735+++ linux-2.6.39.1/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 };
754diff -urNp linux-2.6.39.1/arch/arm/mach-ixp2000/enp2611.c linux-2.6.39.1/arch/arm/mach-ixp2000/enp2611.c
755--- linux-2.6.39.1/arch/arm/mach-ixp2000/enp2611.c 2011-05-19 00:06:34.000000000 -0400
756+++ linux-2.6.39.1/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 };
766diff -urNp linux-2.6.39.1/arch/arm/mach-ixp2000/pci.c linux-2.6.39.1/arch/arm/mach-ixp2000/pci.c
767--- linux-2.6.39.1/arch/arm/mach-ixp2000/pci.c 2011-05-19 00:06:34.000000000 -0400
768+++ linux-2.6.39.1/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 };
778diff -urNp linux-2.6.39.1/arch/arm/mach-ixp23xx/pci.c linux-2.6.39.1/arch/arm/mach-ixp23xx/pci.c
779--- linux-2.6.39.1/arch/arm/mach-ixp23xx/pci.c 2011-05-19 00:06:34.000000000 -0400
780+++ linux-2.6.39.1/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 };
790diff -urNp linux-2.6.39.1/arch/arm/mach-ixp4xx/common-pci.c linux-2.6.39.1/arch/arm/mach-ixp4xx/common-pci.c
791--- linux-2.6.39.1/arch/arm/mach-ixp4xx/common-pci.c 2011-05-19 00:06:34.000000000 -0400
792+++ linux-2.6.39.1/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 };
802diff -urNp linux-2.6.39.1/arch/arm/mach-kirkwood/pcie.c linux-2.6.39.1/arch/arm/mach-kirkwood/pcie.c
803--- linux-2.6.39.1/arch/arm/mach-kirkwood/pcie.c 2011-05-19 00:06:34.000000000 -0400
804+++ linux-2.6.39.1/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 };
814diff -urNp linux-2.6.39.1/arch/arm/mach-ks8695/pci.c linux-2.6.39.1/arch/arm/mach-ks8695/pci.c
815--- linux-2.6.39.1/arch/arm/mach-ks8695/pci.c 2011-05-19 00:06:34.000000000 -0400
816+++ linux-2.6.39.1/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 };
826diff -urNp linux-2.6.39.1/arch/arm/mach-mmp/clock.c linux-2.6.39.1/arch/arm/mach-mmp/clock.c
827--- linux-2.6.39.1/arch/arm/mach-mmp/clock.c 2011-05-19 00:06:34.000000000 -0400
828+++ linux-2.6.39.1/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 };
847diff -urNp linux-2.6.39.1/arch/arm/mach-msm/iommu.c linux-2.6.39.1/arch/arm/mach-msm/iommu.c
848--- linux-2.6.39.1/arch/arm/mach-msm/iommu.c 2011-05-19 00:06:34.000000000 -0400
849+++ linux-2.6.39.1/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,
859diff -urNp linux-2.6.39.1/arch/arm/mach-msm/last_radio_log.c linux-2.6.39.1/arch/arm/mach-msm/last_radio_log.c
860--- linux-2.6.39.1/arch/arm/mach-msm/last_radio_log.c 2011-05-19 00:06:34.000000000 -0400
861+++ linux-2.6.39.1/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 };
870diff -urNp linux-2.6.39.1/arch/arm/mach-mv78xx0/pcie.c linux-2.6.39.1/arch/arm/mach-mv78xx0/pcie.c
871--- linux-2.6.39.1/arch/arm/mach-mv78xx0/pcie.c 2011-05-19 00:06:34.000000000 -0400
872+++ linux-2.6.39.1/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 };
882diff -urNp linux-2.6.39.1/arch/arm/mach-orion5x/pci.c linux-2.6.39.1/arch/arm/mach-orion5x/pci.c
883--- linux-2.6.39.1/arch/arm/mach-orion5x/pci.c 2011-05-19 00:06:34.000000000 -0400
884+++ linux-2.6.39.1/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 };
903diff -urNp linux-2.6.39.1/arch/arm/mach-sa1100/pci-nanoengine.c linux-2.6.39.1/arch/arm/mach-sa1100/pci-nanoengine.c
904--- linux-2.6.39.1/arch/arm/mach-sa1100/pci-nanoengine.c 2011-05-19 00:06:34.000000000 -0400
905+++ linux-2.6.39.1/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 };
915diff -urNp linux-2.6.39.1/arch/arm/mach-tegra/pcie.c linux-2.6.39.1/arch/arm/mach-tegra/pcie.c
916--- linux-2.6.39.1/arch/arm/mach-tegra/pcie.c 2011-05-19 00:06:34.000000000 -0400
917+++ linux-2.6.39.1/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 };
927diff -urNp linux-2.6.39.1/arch/arm/mach-ux500/mbox-db5500.c linux-2.6.39.1/arch/arm/mach-ux500/mbox-db5500.c
928--- linux-2.6.39.1/arch/arm/mach-ux500/mbox-db5500.c 2011-05-19 00:06:34.000000000 -0400
929+++ linux-2.6.39.1/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 {
939diff -urNp linux-2.6.39.1/arch/arm/mach-versatile/pci.c linux-2.6.39.1/arch/arm/mach-versatile/pci.c
940--- linux-2.6.39.1/arch/arm/mach-versatile/pci.c 2011-05-19 00:06:34.000000000 -0400
941+++ linux-2.6.39.1/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 };
951diff -urNp linux-2.6.39.1/arch/arm/mm/fault.c linux-2.6.39.1/arch/arm/mm/fault.c
952--- linux-2.6.39.1/arch/arm/mm/fault.c 2011-05-19 00:06:34.000000000 -0400
953+++ linux-2.6.39.1/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 *
1002diff -urNp linux-2.6.39.1/arch/arm/mm/mmap.c linux-2.6.39.1/arch/arm/mm/mmap.c
1003--- linux-2.6.39.1/arch/arm/mm/mmap.c 2011-05-19 00:06:34.000000000 -0400
1004+++ linux-2.6.39.1/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 */
1054diff -urNp linux-2.6.39.1/arch/arm/plat-iop/pci.c linux-2.6.39.1/arch/arm/plat-iop/pci.c
1055--- linux-2.6.39.1/arch/arm/plat-iop/pci.c 2011-05-19 00:06:34.000000000 -0400
1056+++ linux-2.6.39.1/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 };
1066diff -urNp linux-2.6.39.1/arch/avr32/include/asm/elf.h linux-2.6.39.1/arch/avr32/include/asm/elf.h
1067--- linux-2.6.39.1/arch/avr32/include/asm/elf.h 2011-05-19 00:06:34.000000000 -0400
1068+++ linux-2.6.39.1/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,
1085diff -urNp linux-2.6.39.1/arch/avr32/include/asm/kmap_types.h linux-2.6.39.1/arch/avr32/include/asm/kmap_types.h
1086--- linux-2.6.39.1/arch/avr32/include/asm/kmap_types.h 2011-05-19 00:06:34.000000000 -0400
1087+++ linux-2.6.39.1/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
1098diff -urNp linux-2.6.39.1/arch/avr32/mm/fault.c linux-2.6.39.1/arch/avr32/mm/fault.c
1099--- linux-2.6.39.1/arch/avr32/mm/fault.c 2011-05-19 00:06:34.000000000 -0400
1100+++ linux-2.6.39.1/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",
1142diff -urNp linux-2.6.39.1/arch/blackfin/kernel/kgdb.c linux-2.6.39.1/arch/blackfin/kernel/kgdb.c
1143--- linux-2.6.39.1/arch/blackfin/kernel/kgdb.c 2011-05-19 00:06:34.000000000 -0400
1144+++ linux-2.6.39.1/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,
1154diff -urNp linux-2.6.39.1/arch/blackfin/mm/maccess.c linux-2.6.39.1/arch/blackfin/mm/maccess.c
1155--- linux-2.6.39.1/arch/blackfin/mm/maccess.c 2011-05-19 00:06:34.000000000 -0400
1156+++ linux-2.6.39.1/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;
1175diff -urNp linux-2.6.39.1/arch/frv/include/asm/kmap_types.h linux-2.6.39.1/arch/frv/include/asm/kmap_types.h
1176--- linux-2.6.39.1/arch/frv/include/asm/kmap_types.h 2011-05-19 00:06:34.000000000 -0400
1177+++ linux-2.6.39.1/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
1186diff -urNp linux-2.6.39.1/arch/frv/mb93090-mb00/pci-frv.h linux-2.6.39.1/arch/frv/mb93090-mb00/pci-frv.h
1187--- linux-2.6.39.1/arch/frv/mb93090-mb00/pci-frv.h 2011-05-19 00:06:34.000000000 -0400
1188+++ linux-2.6.39.1/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;
1198diff -urNp linux-2.6.39.1/arch/frv/mb93090-mb00/pci-vdk.c linux-2.6.39.1/arch/frv/mb93090-mb00/pci-vdk.c
1199--- linux-2.6.39.1/arch/frv/mb93090-mb00/pci-vdk.c 2011-05-19 00:06:34.000000000 -0400
1200+++ linux-2.6.39.1/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;
1228diff -urNp linux-2.6.39.1/arch/frv/mm/elf-fdpic.c linux-2.6.39.1/arch/frv/mm/elf-fdpic.c
1229--- linux-2.6.39.1/arch/frv/mm/elf-fdpic.c 2011-05-19 00:06:34.000000000 -0400
1230+++ linux-2.6.39.1/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 }
1259diff -urNp linux-2.6.39.1/arch/ia64/hp/common/hwsw_iommu.c linux-2.6.39.1/arch/ia64/hp/common/hwsw_iommu.c
1260--- linux-2.6.39.1/arch/ia64/hp/common/hwsw_iommu.c 2011-05-19 00:06:34.000000000 -0400
1261+++ linux-2.6.39.1/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;
1280diff -urNp linux-2.6.39.1/arch/ia64/hp/common/sba_iommu.c linux-2.6.39.1/arch/ia64/hp/common/sba_iommu.c
1281--- linux-2.6.39.1/arch/ia64/hp/common/sba_iommu.c 2011-05-19 00:06:34.000000000 -0400
1282+++ linux-2.6.39.1/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,
1301diff -urNp linux-2.6.39.1/arch/ia64/include/asm/dma-mapping.h linux-2.6.39.1/arch/ia64/include/asm/dma-mapping.h
1302--- linux-2.6.39.1/arch/ia64/include/asm/dma-mapping.h 2011-05-19 00:06:34.000000000 -0400
1303+++ linux-2.6.39.1/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
1347diff -urNp linux-2.6.39.1/arch/ia64/include/asm/elf.h linux-2.6.39.1/arch/ia64/include/asm/elf.h
1348--- linux-2.6.39.1/arch/ia64/include/asm/elf.h 2011-05-19 00:06:34.000000000 -0400
1349+++ linux-2.6.39.1/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: */
1364diff -urNp linux-2.6.39.1/arch/ia64/include/asm/machvec.h linux-2.6.39.1/arch/ia64/include/asm/machvec.h
1365--- linux-2.6.39.1/arch/ia64/include/asm/machvec.h 2011-05-19 00:06:34.000000000 -0400
1366+++ linux-2.6.39.1/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
1385diff -urNp linux-2.6.39.1/arch/ia64/include/asm/pgtable.h linux-2.6.39.1/arch/ia64/include/asm/pgtable.h
1386--- linux-2.6.39.1/arch/ia64/include/asm/pgtable.h 2011-05-19 00:06:34.000000000 -0400
1387+++ linux-2.6.39.1/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)
1415diff -urNp linux-2.6.39.1/arch/ia64/include/asm/spinlock.h linux-2.6.39.1/arch/ia64/include/asm/spinlock.h
1416--- linux-2.6.39.1/arch/ia64/include/asm/spinlock.h 2011-05-19 00:06:34.000000000 -0400
1417+++ linux-2.6.39.1/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)
1427diff -urNp linux-2.6.39.1/arch/ia64/include/asm/uaccess.h linux-2.6.39.1/arch/ia64/include/asm/uaccess.h
1428--- linux-2.6.39.1/arch/ia64/include/asm/uaccess.h 2011-05-19 00:06:34.000000000 -0400
1429+++ linux-2.6.39.1/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 })
1448diff -urNp linux-2.6.39.1/arch/ia64/kernel/dma-mapping.c linux-2.6.39.1/arch/ia64/kernel/dma-mapping.c
1449--- linux-2.6.39.1/arch/ia64/kernel/dma-mapping.c 2011-05-19 00:06:34.000000000 -0400
1450+++ linux-2.6.39.1/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 }
1469diff -urNp linux-2.6.39.1/arch/ia64/kernel/module.c linux-2.6.39.1/arch/ia64/kernel/module.c
1470--- linux-2.6.39.1/arch/ia64/kernel/module.c 2011-05-19 00:06:34.000000000 -0400
1471+++ linux-2.6.39.1/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 }
1560diff -urNp linux-2.6.39.1/arch/ia64/kernel/pci-dma.c linux-2.6.39.1/arch/ia64/kernel/pci-dma.c
1561--- linux-2.6.39.1/arch/ia64/kernel/pci-dma.c 2011-05-19 00:06:34.000000000 -0400
1562+++ linux-2.6.39.1/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 {
1572diff -urNp linux-2.6.39.1/arch/ia64/kernel/pci-swiotlb.c linux-2.6.39.1/arch/ia64/kernel/pci-swiotlb.c
1573--- linux-2.6.39.1/arch/ia64/kernel/pci-swiotlb.c 2011-05-19 00:06:34.000000000 -0400
1574+++ linux-2.6.39.1/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,
1584diff -urNp linux-2.6.39.1/arch/ia64/kernel/sys_ia64.c linux-2.6.39.1/arch/ia64/kernel/sys_ia64.c
1585--- linux-2.6.39.1/arch/ia64/kernel/sys_ia64.c 2011-05-19 00:06:34.000000000 -0400
1586+++ linux-2.6.39.1/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;
1619diff -urNp linux-2.6.39.1/arch/ia64/kernel/vmlinux.lds.S linux-2.6.39.1/arch/ia64/kernel/vmlinux.lds.S
1620--- linux-2.6.39.1/arch/ia64/kernel/vmlinux.lds.S 2011-05-19 00:06:34.000000000 -0400
1621+++ linux-2.6.39.1/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
1631diff -urNp linux-2.6.39.1/arch/ia64/mm/fault.c linux-2.6.39.1/arch/ia64/mm/fault.c
1632--- linux-2.6.39.1/arch/ia64/mm/fault.c 2011-05-19 00:06:34.000000000 -0400
1633+++ linux-2.6.39.1/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
1683diff -urNp linux-2.6.39.1/arch/ia64/mm/hugetlbpage.c linux-2.6.39.1/arch/ia64/mm/hugetlbpage.c
1684--- linux-2.6.39.1/arch/ia64/mm/hugetlbpage.c 2011-05-19 00:06:34.000000000 -0400
1685+++ linux-2.6.39.1/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 }
1695diff -urNp linux-2.6.39.1/arch/ia64/mm/init.c linux-2.6.39.1/arch/ia64/mm/init.c
1696--- linux-2.6.39.1/arch/ia64/mm/init.c 2011-05-19 00:06:34.000000000 -0400
1697+++ linux-2.6.39.1/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)) {
1718diff -urNp linux-2.6.39.1/arch/ia64/pci/pci.c linux-2.6.39.1/arch/ia64/pci/pci.c
1719--- linux-2.6.39.1/arch/ia64/pci/pci.c 2011-05-19 00:06:34.000000000 -0400
1720+++ linux-2.6.39.1/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 };
1730diff -urNp linux-2.6.39.1/arch/ia64/sn/pci/pci_dma.c linux-2.6.39.1/arch/ia64/sn/pci/pci_dma.c
1731--- linux-2.6.39.1/arch/ia64/sn/pci/pci_dma.c 2011-05-19 00:06:34.000000000 -0400
1732+++ linux-2.6.39.1/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,
1742diff -urNp linux-2.6.39.1/arch/m32r/lib/usercopy.c linux-2.6.39.1/arch/m32r/lib/usercopy.c
1743--- linux-2.6.39.1/arch/m32r/lib/usercopy.c 2011-05-19 00:06:34.000000000 -0400
1744+++ linux-2.6.39.1/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);
1765diff -urNp linux-2.6.39.1/arch/microblaze/include/asm/device.h linux-2.6.39.1/arch/microblaze/include/asm/device.h
1766--- linux-2.6.39.1/arch/microblaze/include/asm/device.h 2011-05-19 00:06:34.000000000 -0400
1767+++ linux-2.6.39.1/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
1777diff -urNp linux-2.6.39.1/arch/microblaze/include/asm/dma-mapping.h linux-2.6.39.1/arch/microblaze/include/asm/dma-mapping.h
1778--- linux-2.6.39.1/arch/microblaze/include/asm/dma-mapping.h 2011-05-19 00:06:34.000000000 -0400
1779+++ linux-2.6.39.1/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);
1851diff -urNp linux-2.6.39.1/arch/microblaze/include/asm/pci.h linux-2.6.39.1/arch/microblaze/include/asm/pci.h
1852--- linux-2.6.39.1/arch/microblaze/include/asm/pci.h 2011-05-19 00:06:34.000000000 -0400
1853+++ linux-2.6.39.1/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
1865diff -urNp linux-2.6.39.1/arch/microblaze/kernel/dma.c linux-2.6.39.1/arch/microblaze/kernel/dma.c
1866--- linux-2.6.39.1/arch/microblaze/kernel/dma.c 2011-05-19 00:06:34.000000000 -0400
1867+++ linux-2.6.39.1/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,
1877diff -urNp linux-2.6.39.1/arch/microblaze/kernel/kgdb.c linux-2.6.39.1/arch/microblaze/kernel/kgdb.c
1878--- linux-2.6.39.1/arch/microblaze/kernel/kgdb.c 2011-05-19 00:06:34.000000000 -0400
1879+++ linux-2.6.39.1/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
1889diff -urNp linux-2.6.39.1/arch/microblaze/pci/indirect_pci.c linux-2.6.39.1/arch/microblaze/pci/indirect_pci.c
1890--- linux-2.6.39.1/arch/microblaze/pci/indirect_pci.c 2011-05-19 00:06:34.000000000 -0400
1891+++ linux-2.6.39.1/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 };
1901diff -urNp linux-2.6.39.1/arch/microblaze/pci/pci-common.c linux-2.6.39.1/arch/microblaze/pci/pci-common.c
1902--- linux-2.6.39.1/arch/microblaze/pci/pci-common.c 2011-05-19 00:06:34.000000000 -0400
1903+++ linux-2.6.39.1/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 };
1931diff -urNp linux-2.6.39.1/arch/mips/alchemy/common/pci.c linux-2.6.39.1/arch/mips/alchemy/common/pci.c
1932--- linux-2.6.39.1/arch/mips/alchemy/common/pci.c 2011-05-19 00:06:34.000000000 -0400
1933+++ linux-2.6.39.1/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,
1943diff -urNp linux-2.6.39.1/arch/mips/cavium-octeon/dma-octeon.c linux-2.6.39.1/arch/mips/cavium-octeon/dma-octeon.c
1944--- linux-2.6.39.1/arch/mips/cavium-octeon/dma-octeon.c 2011-05-19 00:06:34.000000000 -0400
1945+++ linux-2.6.39.1/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 {
1964diff -urNp linux-2.6.39.1/arch/mips/cobalt/pci.c linux-2.6.39.1/arch/mips/cobalt/pci.c
1965--- linux-2.6.39.1/arch/mips/cobalt/pci.c 2011-05-19 00:06:34.000000000 -0400
1966+++ linux-2.6.39.1/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,
1976diff -urNp linux-2.6.39.1/arch/mips/include/asm/device.h linux-2.6.39.1/arch/mips/include/asm/device.h
1977--- linux-2.6.39.1/arch/mips/include/asm/device.h 2011-05-19 00:06:34.000000000 -0400
1978+++ linux-2.6.39.1/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 {
1988diff -urNp linux-2.6.39.1/arch/mips/include/asm/dma-mapping.h linux-2.6.39.1/arch/mips/include/asm/dma-mapping.h
1989--- linux-2.6.39.1/arch/mips/include/asm/dma-mapping.h 2011-05-19 00:06:34.000000000 -0400
1990+++ linux-2.6.39.1/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
2037diff -urNp linux-2.6.39.1/arch/mips/include/asm/elf.h linux-2.6.39.1/arch/mips/include/asm/elf.h
2038--- linux-2.6.39.1/arch/mips/include/asm/elf.h 2011-05-19 00:06:34.000000000 -0400
2039+++ linux-2.6.39.1/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 */
2061diff -urNp linux-2.6.39.1/arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h linux-2.6.39.1/arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h
2062--- linux-2.6.39.1/arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h 2011-05-19 00:06:34.000000000 -0400
2063+++ linux-2.6.39.1/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 */
2073diff -urNp linux-2.6.39.1/arch/mips/include/asm/page.h linux-2.6.39.1/arch/mips/include/asm/page.h
2074--- linux-2.6.39.1/arch/mips/include/asm/page.h 2011-05-19 00:06:34.000000000 -0400
2075+++ linux-2.6.39.1/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)
2085diff -urNp linux-2.6.39.1/arch/mips/include/asm/pci/bridge.h linux-2.6.39.1/arch/mips/include/asm/pci/bridge.h
2086--- linux-2.6.39.1/arch/mips/include/asm/pci/bridge.h 2011-05-19 00:06:34.000000000 -0400
2087+++ linux-2.6.39.1/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 */
2096diff -urNp linux-2.6.39.1/arch/mips/include/asm/system.h linux-2.6.39.1/arch/mips/include/asm/system.h
2097--- linux-2.6.39.1/arch/mips/include/asm/system.h 2011-05-19 00:06:34.000000000 -0400
2098+++ linux-2.6.39.1/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 */
2107diff -urNp linux-2.6.39.1/arch/mips/kernel/binfmt_elfn32.c linux-2.6.39.1/arch/mips/kernel/binfmt_elfn32.c
2108--- linux-2.6.39.1/arch/mips/kernel/binfmt_elfn32.c 2011-05-19 00:06:34.000000000 -0400
2109+++ linux-2.6.39.1/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>
2124diff -urNp linux-2.6.39.1/arch/mips/kernel/binfmt_elfo32.c linux-2.6.39.1/arch/mips/kernel/binfmt_elfo32.c
2125--- linux-2.6.39.1/arch/mips/kernel/binfmt_elfo32.c 2011-05-19 00:06:34.000000000 -0400
2126+++ linux-2.6.39.1/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 /*
2141diff -urNp linux-2.6.39.1/arch/mips/kernel/kgdb.c linux-2.6.39.1/arch/mips/kernel/kgdb.c
2142--- linux-2.6.39.1/arch/mips/kernel/kgdb.c 2011-05-19 00:06:34.000000000 -0400
2143+++ linux-2.6.39.1/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
2153diff -urNp linux-2.6.39.1/arch/mips/kernel/process.c linux-2.6.39.1/arch/mips/kernel/process.c
2154--- linux-2.6.39.1/arch/mips/kernel/process.c 2011-05-19 00:06:34.000000000 -0400
2155+++ linux-2.6.39.1/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-}
2172diff -urNp linux-2.6.39.1/arch/mips/kernel/syscall.c linux-2.6.39.1/arch/mips/kernel/syscall.c
2173--- linux-2.6.39.1/arch/mips/kernel/syscall.c 2011-05-19 00:06:34.000000000 -0400
2174+++ linux-2.6.39.1/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)
2239diff -urNp linux-2.6.39.1/arch/mips/mm/dma-default.c linux-2.6.39.1/arch/mips/mm/dma-default.c
2240--- linux-2.6.39.1/arch/mips/mm/dma-default.c 2011-05-19 00:06:34.000000000 -0400
2241+++ linux-2.6.39.1/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)
2260diff -urNp linux-2.6.39.1/arch/mips/mm/fault.c linux-2.6.39.1/arch/mips/mm/fault.c
2261--- linux-2.6.39.1/arch/mips/mm/fault.c 2011-05-19 00:06:34.000000000 -0400
2262+++ linux-2.6.39.1/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
2287diff -urNp linux-2.6.39.1/arch/mips/mti-malta/malta-pci.c linux-2.6.39.1/arch/mips/mti-malta/malta-pci.c
2288--- linux-2.6.39.1/arch/mips/mti-malta/malta-pci.c 2011-05-19 00:06:34.000000000 -0400
2289+++ linux-2.6.39.1/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,
2303diff -urNp linux-2.6.39.1/arch/mips/nxp/pnx8550/common/pci.c linux-2.6.39.1/arch/mips/nxp/pnx8550/common/pci.c
2304--- linux-2.6.39.1/arch/mips/nxp/pnx8550/common/pci.c 2011-05-19 00:06:34.000000000 -0400
2305+++ linux-2.6.39.1/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,
2315diff -urNp linux-2.6.39.1/arch/mips/pci/ops-au1000.c linux-2.6.39.1/arch/mips/pci/ops-au1000.c
2316--- linux-2.6.39.1/arch/mips/pci/ops-au1000.c 2011-05-19 00:06:34.000000000 -0400
2317+++ linux-2.6.39.1/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 };
2327diff -urNp linux-2.6.39.1/arch/mips/pci/ops-bcm63xx.c linux-2.6.39.1/arch/mips/pci/ops-bcm63xx.c
2328--- linux-2.6.39.1/arch/mips/pci/ops-bcm63xx.c 2011-05-19 00:06:34.000000000 -0400
2329+++ linux-2.6.39.1/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 };
2348diff -urNp linux-2.6.39.1/arch/mips/pci/ops-bonito64.c linux-2.6.39.1/arch/mips/pci/ops-bonito64.c
2349--- linux-2.6.39.1/arch/mips/pci/ops-bonito64.c 2011-05-19 00:06:34.000000000 -0400
2350+++ linux-2.6.39.1/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 };
2360diff -urNp linux-2.6.39.1/arch/mips/pci/ops-bridge.c linux-2.6.39.1/arch/mips/pci/ops-bridge.c
2361--- linux-2.6.39.1/arch/mips/pci/ops-bridge.c 2011-05-19 00:06:34.000000000 -0400
2362+++ linux-2.6.39.1/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 };
2372diff -urNp linux-2.6.39.1/arch/mips/pci/ops-emma2rh.c linux-2.6.39.1/arch/mips/pci/ops-emma2rh.c
2373--- linux-2.6.39.1/arch/mips/pci/ops-emma2rh.c 2011-05-19 00:06:34.000000000 -0400
2374+++ linux-2.6.39.1/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 };
2384diff -urNp linux-2.6.39.1/arch/mips/pci/ops-gt64xxx_pci0.c linux-2.6.39.1/arch/mips/pci/ops-gt64xxx_pci0.c
2385--- linux-2.6.39.1/arch/mips/pci/ops-gt64xxx_pci0.c 2011-05-19 00:06:34.000000000 -0400
2386+++ linux-2.6.39.1/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 };
2396diff -urNp linux-2.6.39.1/arch/mips/pci/ops-loongson2.c linux-2.6.39.1/arch/mips/pci/ops-loongson2.c
2397--- linux-2.6.39.1/arch/mips/pci/ops-loongson2.c 2011-05-19 00:06:34.000000000 -0400
2398+++ linux-2.6.39.1/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 };
2408diff -urNp linux-2.6.39.1/arch/mips/pci/ops-mace.c linux-2.6.39.1/arch/mips/pci/ops-mace.c
2409--- linux-2.6.39.1/arch/mips/pci/ops-mace.c 2011-05-19 00:06:34.000000000 -0400
2410+++ linux-2.6.39.1/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 };
2420diff -urNp linux-2.6.39.1/arch/mips/pci/ops-msc.c linux-2.6.39.1/arch/mips/pci/ops-msc.c
2421--- linux-2.6.39.1/arch/mips/pci/ops-msc.c 2011-05-19 00:06:34.000000000 -0400
2422+++ linux-2.6.39.1/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 };
2432diff -urNp linux-2.6.39.1/arch/mips/pci/ops-nile4.c linux-2.6.39.1/arch/mips/pci/ops-nile4.c
2433--- linux-2.6.39.1/arch/mips/pci/ops-nile4.c 2011-05-19 00:06:34.000000000 -0400
2434+++ linux-2.6.39.1/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 };
2444diff -urNp linux-2.6.39.1/arch/mips/pci/ops-pmcmsp.c linux-2.6.39.1/arch/mips/pci/ops-pmcmsp.c
2445--- linux-2.6.39.1/arch/mips/pci/ops-pmcmsp.c 2011-05-19 00:06:34.000000000 -0400
2446+++ linux-2.6.39.1/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 };
2456diff -urNp linux-2.6.39.1/arch/mips/pci/ops-pnx8550.c linux-2.6.39.1/arch/mips/pci/ops-pnx8550.c
2457--- linux-2.6.39.1/arch/mips/pci/ops-pnx8550.c 2011-05-19 00:06:34.000000000 -0400
2458+++ linux-2.6.39.1/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 };
2468diff -urNp linux-2.6.39.1/arch/mips/pci/ops-rc32434.c linux-2.6.39.1/arch/mips/pci/ops-rc32434.c
2469--- linux-2.6.39.1/arch/mips/pci/ops-rc32434.c 2011-05-19 00:06:34.000000000 -0400
2470+++ linux-2.6.39.1/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 };
2480diff -urNp linux-2.6.39.1/arch/mips/pci/ops-sni.c linux-2.6.39.1/arch/mips/pci/ops-sni.c
2481--- linux-2.6.39.1/arch/mips/pci/ops-sni.c 2011-05-19 00:06:34.000000000 -0400
2482+++ linux-2.6.39.1/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 };
2501diff -urNp linux-2.6.39.1/arch/mips/pci/ops-titan.c linux-2.6.39.1/arch/mips/pci/ops-titan.c
2502--- linux-2.6.39.1/arch/mips/pci/ops-titan.c 2011-05-19 00:06:34.000000000 -0400
2503+++ linux-2.6.39.1/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 };
2513diff -urNp linux-2.6.39.1/arch/mips/pci/ops-titan-ht.c linux-2.6.39.1/arch/mips/pci/ops-titan-ht.c
2514--- linux-2.6.39.1/arch/mips/pci/ops-titan-ht.c 2011-05-19 00:06:34.000000000 -0400
2515+++ linux-2.6.39.1/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 };
2525diff -urNp linux-2.6.39.1/arch/mips/pci/ops-tx3927.c linux-2.6.39.1/arch/mips/pci/ops-tx3927.c
2526--- linux-2.6.39.1/arch/mips/pci/ops-tx3927.c 2011-05-19 00:06:34.000000000 -0400
2527+++ linux-2.6.39.1/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 };
2537diff -urNp linux-2.6.39.1/arch/mips/pci/ops-vr41xx.c linux-2.6.39.1/arch/mips/pci/ops-vr41xx.c
2538--- linux-2.6.39.1/arch/mips/pci/ops-vr41xx.c 2011-05-19 00:06:34.000000000 -0400
2539+++ linux-2.6.39.1/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 };
2549diff -urNp linux-2.6.39.1/arch/mips/pci/pci-bcm1480.c linux-2.6.39.1/arch/mips/pci/pci-bcm1480.c
2550--- linux-2.6.39.1/arch/mips/pci/pci-bcm1480.c 2011-05-19 00:06:34.000000000 -0400
2551+++ linux-2.6.39.1/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 };
2561diff -urNp linux-2.6.39.1/arch/mips/pci/pci-bcm1480ht.c linux-2.6.39.1/arch/mips/pci/pci-bcm1480ht.c
2562--- linux-2.6.39.1/arch/mips/pci/pci-bcm1480ht.c 2011-05-19 00:06:34.000000000 -0400
2563+++ linux-2.6.39.1/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 };
2573diff -urNp linux-2.6.39.1/arch/mips/pci/pci-bcm63xx.h linux-2.6.39.1/arch/mips/pci/pci-bcm63xx.h
2574--- linux-2.6.39.1/arch/mips/pci/pci-bcm63xx.h 2011-05-19 00:06:34.000000000 -0400
2575+++ linux-2.6.39.1/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
2587diff -urNp linux-2.6.39.1/arch/mips/pci/pci-emma2rh.c linux-2.6.39.1/arch/mips/pci/pci-emma2rh.c
2588--- linux-2.6.39.1/arch/mips/pci/pci-emma2rh.c 2011-05-19 00:06:34.000000000 -0400
2589+++ linux-2.6.39.1/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,
2599diff -urNp linux-2.6.39.1/arch/mips/pci/pcie-octeon.c linux-2.6.39.1/arch/mips/pci/pcie-octeon.c
2600--- linux-2.6.39.1/arch/mips/pci/pcie-octeon.c 2011-05-19 00:06:34.000000000 -0400
2601+++ linux-2.6.39.1/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 };
2620diff -urNp linux-2.6.39.1/arch/mips/pci/pci-ip27.c linux-2.6.39.1/arch/mips/pci/pci-ip27.c
2621--- linux-2.6.39.1/arch/mips/pci/pci-ip27.c 2011-05-19 00:06:34.000000000 -0400
2622+++ linux-2.6.39.1/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 {
2632diff -urNp linux-2.6.39.1/arch/mips/pci/pci-ip32.c linux-2.6.39.1/arch/mips/pci/pci-ip32.c
2633--- linux-2.6.39.1/arch/mips/pci/pci-ip32.c 2011-05-19 00:06:34.000000000 -0400
2634+++ linux-2.6.39.1/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",
2644diff -urNp linux-2.6.39.1/arch/mips/pci/pci-lasat.c linux-2.6.39.1/arch/mips/pci/pci-lasat.c
2645--- linux-2.6.39.1/arch/mips/pci/pci-lasat.c 2011-05-19 00:06:34.000000000 -0400
2646+++ linux-2.6.39.1/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,
2658diff -urNp linux-2.6.39.1/arch/mips/pci/pci-octeon.c linux-2.6.39.1/arch/mips/pci/pci-octeon.c
2659--- linux-2.6.39.1/arch/mips/pci/pci-octeon.c 2011-05-19 00:06:34.000000000 -0400
2660+++ linux-2.6.39.1/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 };
2670diff -urNp linux-2.6.39.1/arch/mips/pci/pci-rc32434.c linux-2.6.39.1/arch/mips/pci/pci-rc32434.c
2671--- linux-2.6.39.1/arch/mips/pci/pci-rc32434.c 2011-05-19 00:06:34.000000000 -0400
2672+++ linux-2.6.39.1/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)
2682diff -urNp linux-2.6.39.1/arch/mips/pci/pci-sb1250.c linux-2.6.39.1/arch/mips/pci/pci-sb1250.c
2683--- linux-2.6.39.1/arch/mips/pci/pci-sb1250.c 2011-05-19 00:06:34.000000000 -0400
2684+++ linux-2.6.39.1/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 };
2694diff -urNp linux-2.6.39.1/arch/mips/pci/pci-vr41xx.c linux-2.6.39.1/arch/mips/pci/pci-vr41xx.c
2695--- linux-2.6.39.1/arch/mips/pci/pci-vr41xx.c 2011-05-19 00:06:34.000000000 -0400
2696+++ linux-2.6.39.1/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
2706diff -urNp linux-2.6.39.1/arch/mips/pci/pci-yosemite.c linux-2.6.39.1/arch/mips/pci/pci-yosemite.c
2707--- linux-2.6.39.1/arch/mips/pci/pci-yosemite.c 2011-05-19 00:06:34.000000000 -0400
2708+++ linux-2.6.39.1/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,
2718diff -urNp linux-2.6.39.1/arch/mips/pmc-sierra/yosemite/ht.c linux-2.6.39.1/arch/mips/pmc-sierra/yosemite/ht.c
2719--- linux-2.6.39.1/arch/mips/pmc-sierra/yosemite/ht.c 2011-05-19 00:06:34.000000000 -0400
2720+++ linux-2.6.39.1/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,
2730diff -urNp linux-2.6.39.1/arch/mips/pnx8550/common/pci.c linux-2.6.39.1/arch/mips/pnx8550/common/pci.c
2731--- linux-2.6.39.1/arch/mips/pnx8550/common/pci.c 2011-05-19 00:06:34.000000000 -0400
2732+++ linux-2.6.39.1/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,
2742diff -urNp linux-2.6.39.1/arch/mips/sni/pcimt.c linux-2.6.39.1/arch/mips/sni/pcimt.c
2743--- linux-2.6.39.1/arch/mips/sni/pcimt.c 2011-05-19 00:06:34.000000000 -0400
2744+++ linux-2.6.39.1/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,
2754diff -urNp linux-2.6.39.1/arch/mips/sni/pcit.c linux-2.6.39.1/arch/mips/sni/pcit.c
2755--- linux-2.6.39.1/arch/mips/sni/pcit.c 2011-05-19 00:06:34.000000000 -0400
2756+++ linux-2.6.39.1/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,
2766diff -urNp linux-2.6.39.1/arch/mips/wrppmc/pci.c linux-2.6.39.1/arch/mips/wrppmc/pci.c
2767--- linux-2.6.39.1/arch/mips/wrppmc/pci.c 2011-05-19 00:06:34.000000000 -0400
2768+++ linux-2.6.39.1/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",
2778diff -urNp linux-2.6.39.1/arch/mn10300/unit-asb2305/pci-asb2305.h linux-2.6.39.1/arch/mn10300/unit-asb2305/pci-asb2305.h
2779--- linux-2.6.39.1/arch/mn10300/unit-asb2305/pci-asb2305.h 2011-05-19 00:06:34.000000000 -0400
2780+++ linux-2.6.39.1/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);
2790diff -urNp linux-2.6.39.1/arch/mn10300/unit-asb2305/pci.c linux-2.6.39.1/arch/mn10300/unit-asb2305/pci.c
2791--- linux-2.6.39.1/arch/mn10300/unit-asb2305/pci.c 2011-05-19 00:06:34.000000000 -0400
2792+++ linux-2.6.39.1/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;
2820diff -urNp linux-2.6.39.1/arch/parisc/include/asm/elf.h linux-2.6.39.1/arch/parisc/include/asm/elf.h
2821--- linux-2.6.39.1/arch/parisc/include/asm/elf.h 2011-05-19 00:06:34.000000000 -0400
2822+++ linux-2.6.39.1/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. */
2837diff -urNp linux-2.6.39.1/arch/parisc/include/asm/pgtable.h linux-2.6.39.1/arch/parisc/include/asm/pgtable.h
2838--- linux-2.6.39.1/arch/parisc/include/asm/pgtable.h 2011-05-19 00:06:34.000000000 -0400
2839+++ linux-2.6.39.1/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)
2858diff -urNp linux-2.6.39.1/arch/parisc/kernel/module.c linux-2.6.39.1/arch/parisc/kernel/module.c
2859--- linux-2.6.39.1/arch/parisc/kernel/module.c 2011-05-19 00:06:34.000000000 -0400
2860+++ linux-2.6.39.1/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);
2961diff -urNp linux-2.6.39.1/arch/parisc/kernel/sys_parisc.c linux-2.6.39.1/arch/parisc/kernel/sys_parisc.c
2962--- linux-2.6.39.1/arch/parisc/kernel/sys_parisc.c 2011-05-19 00:06:34.000000000 -0400
2963+++ linux-2.6.39.1/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);
2991diff -urNp linux-2.6.39.1/arch/parisc/kernel/traps.c linux-2.6.39.1/arch/parisc/kernel/traps.c
2992--- linux-2.6.39.1/arch/parisc/kernel/traps.c 2011-05-19 00:06:34.000000000 -0400
2993+++ linux-2.6.39.1/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
3005diff -urNp linux-2.6.39.1/arch/parisc/mm/fault.c linux-2.6.39.1/arch/parisc/mm/fault.c
3006--- linux-2.6.39.1/arch/parisc/mm/fault.c 2011-05-19 00:06:34.000000000 -0400
3007+++ linux-2.6.39.1/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
3177diff -urNp linux-2.6.39.1/arch/powerpc/include/asm/device.h linux-2.6.39.1/arch/powerpc/include/asm/device.h
3178--- linux-2.6.39.1/arch/powerpc/include/asm/device.h 2011-05-19 00:06:34.000000000 -0400
3179+++ linux-2.6.39.1/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
3189diff -urNp linux-2.6.39.1/arch/powerpc/include/asm/dma-mapping.h linux-2.6.39.1/arch/powerpc/include/asm/dma-mapping.h
3190--- linux-2.6.39.1/arch/powerpc/include/asm/dma-mapping.h 2011-05-19 00:06:34.000000000 -0400
3191+++ linux-2.6.39.1/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);
3254diff -urNp linux-2.6.39.1/arch/powerpc/include/asm/elf.h linux-2.6.39.1/arch/powerpc/include/asm/elf.h
3255--- linux-2.6.39.1/arch/powerpc/include/asm/elf.h 2011-05-19 00:06:34.000000000 -0400
3256+++ linux-2.6.39.1/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 /*
3289diff -urNp linux-2.6.39.1/arch/powerpc/include/asm/iommu.h linux-2.6.39.1/arch/powerpc/include/asm/iommu.h
3290--- linux-2.6.39.1/arch/powerpc/include/asm/iommu.h 2011-05-19 00:06:34.000000000 -0400
3291+++ linux-2.6.39.1/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);
3302diff -urNp linux-2.6.39.1/arch/powerpc/include/asm/kmap_types.h linux-2.6.39.1/arch/powerpc/include/asm/kmap_types.h
3303--- linux-2.6.39.1/arch/powerpc/include/asm/kmap_types.h 2011-05-19 00:06:34.000000000 -0400
3304+++ linux-2.6.39.1/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
3313diff -urNp linux-2.6.39.1/arch/powerpc/include/asm/page_64.h linux-2.6.39.1/arch/powerpc/include/asm/page_64.h
3314--- linux-2.6.39.1/arch/powerpc/include/asm/page_64.h 2011-05-19 00:06:34.000000000 -0400
3315+++ linux-2.6.39.1/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
3337diff -urNp linux-2.6.39.1/arch/powerpc/include/asm/page.h linux-2.6.39.1/arch/powerpc/include/asm/page.h
3338--- linux-2.6.39.1/arch/powerpc/include/asm/page.h 2011-05-19 00:06:34.000000000 -0400
3339+++ linux-2.6.39.1/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
3362diff -urNp linux-2.6.39.1/arch/powerpc/include/asm/pci.h linux-2.6.39.1/arch/powerpc/include/asm/pci.h
3363--- linux-2.6.39.1/arch/powerpc/include/asm/pci.h 2011-05-19 00:06:34.000000000 -0400
3364+++ linux-2.6.39.1/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
3376diff -urNp linux-2.6.39.1/arch/powerpc/include/asm/pgtable.h linux-2.6.39.1/arch/powerpc/include/asm/pgtable.h
3377--- linux-2.6.39.1/arch/powerpc/include/asm/pgtable.h 2011-05-19 00:06:34.000000000 -0400
3378+++ linux-2.6.39.1/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>
3387diff -urNp linux-2.6.39.1/arch/powerpc/include/asm/pte-hash32.h linux-2.6.39.1/arch/powerpc/include/asm/pte-hash32.h
3388--- linux-2.6.39.1/arch/powerpc/include/asm/pte-hash32.h 2011-05-19 00:06:34.000000000 -0400
3389+++ linux-2.6.39.1/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 */
3398diff -urNp linux-2.6.39.1/arch/powerpc/include/asm/reg.h linux-2.6.39.1/arch/powerpc/include/asm/reg.h
3399--- linux-2.6.39.1/arch/powerpc/include/asm/reg.h 2011-05-19 00:06:34.000000000 -0400
3400+++ linux-2.6.39.1/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 */
3409diff -urNp linux-2.6.39.1/arch/powerpc/include/asm/swiotlb.h linux-2.6.39.1/arch/powerpc/include/asm/swiotlb.h
3410--- linux-2.6.39.1/arch/powerpc/include/asm/swiotlb.h 2011-05-19 00:06:34.000000000 -0400
3411+++ linux-2.6.39.1/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
3421diff -urNp linux-2.6.39.1/arch/powerpc/include/asm/system.h linux-2.6.39.1/arch/powerpc/include/asm/system.h
3422--- linux-2.6.39.1/arch/powerpc/include/asm/system.h 2011-05-19 00:06:34.000000000 -0400
3423+++ linux-2.6.39.1/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);
3433diff -urNp linux-2.6.39.1/arch/powerpc/include/asm/uaccess.h linux-2.6.39.1/arch/powerpc/include/asm/uaccess.h
3434--- linux-2.6.39.1/arch/powerpc/include/asm/uaccess.h 2011-05-19 00:06:34.000000000 -0400
3435+++ linux-2.6.39.1/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)
3613diff -urNp linux-2.6.39.1/arch/powerpc/kernel/dma.c linux-2.6.39.1/arch/powerpc/kernel/dma.c
3614--- linux-2.6.39.1/arch/powerpc/kernel/dma.c 2011-05-19 00:06:34.000000000 -0400
3615+++ linux-2.6.39.1/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);
3634diff -urNp linux-2.6.39.1/arch/powerpc/kernel/dma-iommu.c linux-2.6.39.1/arch/powerpc/kernel/dma-iommu.c
3635--- linux-2.6.39.1/arch/powerpc/kernel/dma-iommu.c 2011-05-19 00:06:34.000000000 -0400
3636+++ linux-2.6.39.1/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,
3655diff -urNp linux-2.6.39.1/arch/powerpc/kernel/dma-swiotlb.c linux-2.6.39.1/arch/powerpc/kernel/dma-swiotlb.c
3656--- linux-2.6.39.1/arch/powerpc/kernel/dma-swiotlb.c 2011-05-19 00:06:34.000000000 -0400
3657+++ linux-2.6.39.1/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,
3667diff -urNp linux-2.6.39.1/arch/powerpc/kernel/exceptions-64e.S linux-2.6.39.1/arch/powerpc/kernel/exceptions-64e.S
3668--- linux-2.6.39.1/arch/powerpc/kernel/exceptions-64e.S 2011-05-19 00:06:34.000000000 -0400
3669+++ linux-2.6.39.1/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
3688diff -urNp linux-2.6.39.1/arch/powerpc/kernel/exceptions-64s.S linux-2.6.39.1/arch/powerpc/kernel/exceptions-64s.S
3689--- linux-2.6.39.1/arch/powerpc/kernel/exceptions-64s.S 2011-05-19 00:06:34.000000000 -0400
3690+++ linux-2.6.39.1/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)
3703diff -urNp linux-2.6.39.1/arch/powerpc/kernel/ibmebus.c linux-2.6.39.1/arch/powerpc/kernel/ibmebus.c
3704--- linux-2.6.39.1/arch/powerpc/kernel/ibmebus.c 2011-05-19 00:06:34.000000000 -0400
3705+++ linux-2.6.39.1/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,
3715diff -urNp linux-2.6.39.1/arch/powerpc/kernel/kgdb.c linux-2.6.39.1/arch/powerpc/kernel/kgdb.c
3716--- linux-2.6.39.1/arch/powerpc/kernel/kgdb.c 2011-05-19 00:06:34.000000000 -0400
3717+++ linux-2.6.39.1/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
3727diff -urNp linux-2.6.39.1/arch/powerpc/kernel/module_32.c linux-2.6.39.1/arch/powerpc/kernel/module_32.c
3728--- linux-2.6.39.1/arch/powerpc/kernel/module_32.c 2011-05-19 00:06:34.000000000 -0400
3729+++ linux-2.6.39.1/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]) {
3759diff -urNp linux-2.6.39.1/arch/powerpc/kernel/module.c linux-2.6.39.1/arch/powerpc/kernel/module.c
3760--- linux-2.6.39.1/arch/powerpc/kernel/module.c 2011-05-19 00:06:34.000000000 -0400
3761+++ linux-2.6.39.1/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)
3801diff -urNp linux-2.6.39.1/arch/powerpc/kernel/pci-common.c linux-2.6.39.1/arch/powerpc/kernel/pci-common.c
3802--- linux-2.6.39.1/arch/powerpc/kernel/pci-common.c 2011-05-19 00:06:34.000000000 -0400
3803+++ linux-2.6.39.1/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,
3831diff -urNp linux-2.6.39.1/arch/powerpc/kernel/process.c linux-2.6.39.1/arch/powerpc/kernel/process.c
3832--- linux-2.6.39.1/arch/powerpc/kernel/process.c 2011-05-19 00:06:34.000000000 -0400
3833+++ linux-2.6.39.1/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-}
3926diff -urNp linux-2.6.39.1/arch/powerpc/kernel/rtas_pci.c linux-2.6.39.1/arch/powerpc/kernel/rtas_pci.c
3927--- linux-2.6.39.1/arch/powerpc/kernel/rtas_pci.c 2011-05-19 00:06:34.000000000 -0400
3928+++ linux-2.6.39.1/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 };
3938diff -urNp linux-2.6.39.1/arch/powerpc/kernel/signal_32.c linux-2.6.39.1/arch/powerpc/kernel/signal_32.c
3939--- linux-2.6.39.1/arch/powerpc/kernel/signal_32.c 2011-05-19 00:06:34.000000000 -0400
3940+++ linux-2.6.39.1/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;
3950diff -urNp linux-2.6.39.1/arch/powerpc/kernel/signal_64.c linux-2.6.39.1/arch/powerpc/kernel/signal_64.c
3951--- linux-2.6.39.1/arch/powerpc/kernel/signal_64.c 2011-05-19 00:06:34.000000000 -0400
3952+++ linux-2.6.39.1/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]);
3962diff -urNp linux-2.6.39.1/arch/powerpc/kernel/vdso.c linux-2.6.39.1/arch/powerpc/kernel/vdso.c
3963--- linux-2.6.39.1/arch/powerpc/kernel/vdso.c 2011-05-19 00:06:34.000000000 -0400
3964+++ linux-2.6.39.1/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;
3991diff -urNp linux-2.6.39.1/arch/powerpc/kernel/vio.c linux-2.6.39.1/arch/powerpc/kernel/vio.c
3992--- linux-2.6.39.1/arch/powerpc/kernel/vio.c 2011-05-19 00:06:34.000000000 -0400
3993+++ linux-2.6.39.1/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,
4008diff -urNp linux-2.6.39.1/arch/powerpc/lib/usercopy_64.c linux-2.6.39.1/arch/powerpc/lib/usercopy_64.c
4009--- linux-2.6.39.1/arch/powerpc/lib/usercopy_64.c 2011-05-19 00:06:34.000000000 -0400
4010+++ linux-2.6.39.1/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
4042diff -urNp linux-2.6.39.1/arch/powerpc/mm/fault.c linux-2.6.39.1/arch/powerpc/mm/fault.c
4043--- linux-2.6.39.1/arch/powerpc/mm/fault.c 2011-05-19 00:06:34.000000000 -0400
4044+++ linux-2.6.39.1/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 }
4149diff -urNp linux-2.6.39.1/arch/powerpc/mm/mmap_64.c linux-2.6.39.1/arch/powerpc/mm/mmap_64.c
4150--- linux-2.6.39.1/arch/powerpc/mm/mmap_64.c 2011-05-19 00:06:34.000000000 -0400
4151+++ linux-2.6.39.1/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 }
4175diff -urNp linux-2.6.39.1/arch/powerpc/mm/slice.c linux-2.6.39.1/arch/powerpc/mm/slice.c
4176--- linux-2.6.39.1/arch/powerpc/mm/slice.c 2011-05-19 00:06:34.000000000 -0400
4177+++ linux-2.6.39.1/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);
4244diff -urNp linux-2.6.39.1/arch/powerpc/platforms/52xx/efika.c linux-2.6.39.1/arch/powerpc/platforms/52xx/efika.c
4245--- linux-2.6.39.1/arch/powerpc/platforms/52xx/efika.c 2011-05-19 00:06:34.000000000 -0400
4246+++ linux-2.6.39.1/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 };
4256diff -urNp linux-2.6.39.1/arch/powerpc/platforms/cell/celleb_pci.c linux-2.6.39.1/arch/powerpc/platforms/cell/celleb_pci.c
4257--- linux-2.6.39.1/arch/powerpc/platforms/cell/celleb_pci.c 2011-05-19 00:06:34.000000000 -0400
4258+++ linux-2.6.39.1/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 };
4268diff -urNp linux-2.6.39.1/arch/powerpc/platforms/cell/celleb_scc_epci.c linux-2.6.39.1/arch/powerpc/platforms/cell/celleb_scc_epci.c
4269--- linux-2.6.39.1/arch/powerpc/platforms/cell/celleb_scc_epci.c 2011-05-19 00:06:34.000000000 -0400
4270+++ linux-2.6.39.1/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 };
4280diff -urNp linux-2.6.39.1/arch/powerpc/platforms/cell/celleb_scc_pciex.c linux-2.6.39.1/arch/powerpc/platforms/cell/celleb_scc_pciex.c
4281--- linux-2.6.39.1/arch/powerpc/platforms/cell/celleb_scc_pciex.c 2011-05-19 00:06:34.000000000 -0400
4282+++ linux-2.6.39.1/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 };
4292diff -urNp linux-2.6.39.1/arch/powerpc/platforms/cell/iommu.c linux-2.6.39.1/arch/powerpc/platforms/cell/iommu.c
4293--- linux-2.6.39.1/arch/powerpc/platforms/cell/iommu.c 2011-05-19 00:06:34.000000000 -0400
4294+++ linux-2.6.39.1/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,
4304diff -urNp linux-2.6.39.1/arch/powerpc/platforms/chrp/pci.c linux-2.6.39.1/arch/powerpc/platforms/chrp/pci.c
4305--- linux-2.6.39.1/arch/powerpc/platforms/chrp/pci.c 2011-05-19 00:06:34.000000000 -0400
4306+++ linux-2.6.39.1/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,
4325diff -urNp linux-2.6.39.1/arch/powerpc/platforms/iseries/pci.c linux-2.6.39.1/arch/powerpc/platforms/iseries/pci.c
4326--- linux-2.6.39.1/arch/powerpc/platforms/iseries/pci.c 2011-05-19 00:06:34.000000000 -0400
4327+++ linux-2.6.39.1/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 };
4337diff -urNp linux-2.6.39.1/arch/powerpc/platforms/maple/pci.c linux-2.6.39.1/arch/powerpc/platforms/maple/pci.c
4338--- linux-2.6.39.1/arch/powerpc/platforms/maple/pci.c 2011-05-19 00:06:34.000000000 -0400
4339+++ linux-2.6.39.1/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,
4367diff -urNp linux-2.6.39.1/arch/powerpc/platforms/pasemi/pci.c linux-2.6.39.1/arch/powerpc/platforms/pasemi/pci.c
4368--- linux-2.6.39.1/arch/powerpc/platforms/pasemi/pci.c 2011-05-19 00:06:34.000000000 -0400
4369+++ linux-2.6.39.1/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 };
4379diff -urNp linux-2.6.39.1/arch/powerpc/platforms/powermac/pci.c linux-2.6.39.1/arch/powerpc/platforms/powermac/pci.c
4380--- linux-2.6.39.1/arch/powerpc/platforms/powermac/pci.c 2011-05-19 00:06:34.000000000 -0400
4381+++ linux-2.6.39.1/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,
4400diff -urNp linux-2.6.39.1/arch/powerpc/platforms/ps3/system-bus.c linux-2.6.39.1/arch/powerpc/platforms/ps3/system-bus.c
4401--- linux-2.6.39.1/arch/powerpc/platforms/ps3/system-bus.c 2011-05-19 00:06:34.000000000 -0400
4402+++ linux-2.6.39.1/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,
4421diff -urNp linux-2.6.39.1/arch/powerpc/sysdev/fsl_pci.c linux-2.6.39.1/arch/powerpc/sysdev/fsl_pci.c
4422--- linux-2.6.39.1/arch/powerpc/sysdev/fsl_pci.c 2011-05-19 00:06:34.000000000 -0400
4423+++ linux-2.6.39.1/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 };
4433diff -urNp linux-2.6.39.1/arch/powerpc/sysdev/indirect_pci.c linux-2.6.39.1/arch/powerpc/sysdev/indirect_pci.c
4434--- linux-2.6.39.1/arch/powerpc/sysdev/indirect_pci.c 2011-05-19 00:06:34.000000000 -0400
4435+++ linux-2.6.39.1/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,
4445diff -urNp linux-2.6.39.1/arch/powerpc/sysdev/ppc4xx_pci.c linux-2.6.39.1/arch/powerpc/sysdev/ppc4xx_pci.c
4446--- linux-2.6.39.1/arch/powerpc/sysdev/ppc4xx_pci.c 2011-05-19 00:06:34.000000000 -0400
4447+++ linux-2.6.39.1/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,
4457diff -urNp linux-2.6.39.1/arch/powerpc/sysdev/tsi108_pci.c linux-2.6.39.1/arch/powerpc/sysdev/tsi108_pci.c
4458--- linux-2.6.39.1/arch/powerpc/sysdev/tsi108_pci.c 2011-05-19 00:06:34.000000000 -0400
4459+++ linux-2.6.39.1/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 };
4469diff -urNp linux-2.6.39.1/arch/s390/include/asm/elf.h linux-2.6.39.1/arch/s390/include/asm/elf.h
4470--- linux-2.6.39.1/arch/s390/include/asm/elf.h 2011-05-19 00:06:34.000000000 -0400
4471+++ linux-2.6.39.1/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
4497diff -urNp linux-2.6.39.1/arch/s390/include/asm/system.h linux-2.6.39.1/arch/s390/include/asm/system.h
4498--- linux-2.6.39.1/arch/s390/include/asm/system.h 2011-05-19 00:06:34.000000000 -0400
4499+++ linux-2.6.39.1/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 {
4509diff -urNp linux-2.6.39.1/arch/s390/include/asm/uaccess.h linux-2.6.39.1/arch/s390/include/asm/uaccess.h
4510--- linux-2.6.39.1/arch/s390/include/asm/uaccess.h 2011-05-19 00:06:34.000000000 -0400
4511+++ linux-2.6.39.1/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;
4544diff -urNp linux-2.6.39.1/arch/s390/Kconfig linux-2.6.39.1/arch/s390/Kconfig
4545--- linux-2.6.39.1/arch/s390/Kconfig 2011-05-19 00:06:34.000000000 -0400
4546+++ linux-2.6.39.1/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
4562diff -urNp linux-2.6.39.1/arch/s390/kernel/module.c linux-2.6.39.1/arch/s390/kernel/module.c
4563--- linux-2.6.39.1/arch/s390/kernel/module.c 2011-05-19 00:06:34.000000000 -0400
4564+++ linux-2.6.39.1/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;
4636diff -urNp linux-2.6.39.1/arch/s390/kernel/process.c linux-2.6.39.1/arch/s390/kernel/process.c
4637--- linux-2.6.39.1/arch/s390/kernel/process.c 2011-05-19 00:06:34.000000000 -0400
4638+++ linux-2.6.39.1/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-}
4679diff -urNp linux-2.6.39.1/arch/s390/kernel/setup.c linux-2.6.39.1/arch/s390/kernel/setup.c
4680--- linux-2.6.39.1/arch/s390/kernel/setup.c 2011-05-19 00:06:34.000000000 -0400
4681+++ linux-2.6.39.1/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) {
4730diff -urNp linux-2.6.39.1/arch/s390/mm/maccess.c linux-2.6.39.1/arch/s390/mm/maccess.c
4731--- linux-2.6.39.1/arch/s390/mm/maccess.c 2011-05-19 00:06:34.000000000 -0400
4732+++ linux-2.6.39.1/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
4742diff -urNp linux-2.6.39.1/arch/s390/mm/mmap.c linux-2.6.39.1/arch/s390/mm/mmap.c
4743--- linux-2.6.39.1/arch/s390/mm/mmap.c 2011-05-19 00:06:34.000000000 -0400
4744+++ linux-2.6.39.1/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 }
4791diff -urNp linux-2.6.39.1/arch/score/include/asm/system.h linux-2.6.39.1/arch/score/include/asm/system.h
4792--- linux-2.6.39.1/arch/score/include/asm/system.h 2011-05-19 00:06:34.000000000 -0400
4793+++ linux-2.6.39.1/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()
4803diff -urNp linux-2.6.39.1/arch/score/kernel/process.c linux-2.6.39.1/arch/score/kernel/process.c
4804--- linux-2.6.39.1/arch/score/kernel/process.c 2011-05-19 00:06:34.000000000 -0400
4805+++ linux-2.6.39.1/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-}
4815diff -urNp linux-2.6.39.1/arch/sh/drivers/pci/ops-dreamcast.c linux-2.6.39.1/arch/sh/drivers/pci/ops-dreamcast.c
4816--- linux-2.6.39.1/arch/sh/drivers/pci/ops-dreamcast.c 2011-05-19 00:06:34.000000000 -0400
4817+++ linux-2.6.39.1/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 };
4827diff -urNp linux-2.6.39.1/arch/sh/drivers/pci/ops-sh4.c linux-2.6.39.1/arch/sh/drivers/pci/ops-sh4.c
4828--- linux-2.6.39.1/arch/sh/drivers/pci/ops-sh4.c 2011-05-19 00:06:34.000000000 -0400
4829+++ linux-2.6.39.1/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 };
4839diff -urNp linux-2.6.39.1/arch/sh/drivers/pci/ops-sh5.c linux-2.6.39.1/arch/sh/drivers/pci/ops-sh5.c
4840--- linux-2.6.39.1/arch/sh/drivers/pci/ops-sh5.c 2011-05-19 00:06:34.000000000 -0400
4841+++ linux-2.6.39.1/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 };
4851diff -urNp linux-2.6.39.1/arch/sh/drivers/pci/ops-sh7786.c linux-2.6.39.1/arch/sh/drivers/pci/ops-sh7786.c
4852--- linux-2.6.39.1/arch/sh/drivers/pci/ops-sh7786.c 2011-05-19 00:06:34.000000000 -0400
4853+++ linux-2.6.39.1/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 };
4863diff -urNp linux-2.6.39.1/arch/sh/drivers/pci/pcie-sh7786.c linux-2.6.39.1/arch/sh/drivers/pci/pcie-sh7786.c
4864--- linux-2.6.39.1/arch/sh/drivers/pci/pcie-sh7786.c 2011-05-19 00:06:34.000000000 -0400
4865+++ linux-2.6.39.1/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 { \
4875diff -urNp linux-2.6.39.1/arch/sh/drivers/pci/pci-sh4.h linux-2.6.39.1/arch/sh/drivers/pci/pci-sh4.h
4876--- linux-2.6.39.1/arch/sh/drivers/pci/pci-sh4.h 2011-05-19 00:06:34.000000000 -0400
4877+++ linux-2.6.39.1/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 {
4887diff -urNp linux-2.6.39.1/arch/sh/drivers/pci/pci-sh5.h linux-2.6.39.1/arch/sh/drivers/pci/pci-sh5.h
4888--- linux-2.6.39.1/arch/sh/drivers/pci/pci-sh5.h 2011-05-19 00:06:34.000000000 -0400
4889+++ linux-2.6.39.1/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 */
4898diff -urNp linux-2.6.39.1/arch/sh/include/asm/dma-mapping.h linux-2.6.39.1/arch/sh/include/asm/dma-mapping.h
4899--- linux-2.6.39.1/arch/sh/include/asm/dma-mapping.h 2011-05-19 00:06:34.000000000 -0400
4900+++ linux-2.6.39.1/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;
4959diff -urNp linux-2.6.39.1/arch/sh/kernel/dma-nommu.c linux-2.6.39.1/arch/sh/kernel/dma-nommu.c
4960--- linux-2.6.39.1/arch/sh/kernel/dma-nommu.c 2011-05-19 00:06:34.000000000 -0400
4961+++ linux-2.6.39.1/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,
4971diff -urNp linux-2.6.39.1/arch/sh/kernel/kgdb.c linux-2.6.39.1/arch/sh/kernel/kgdb.c
4972--- linux-2.6.39.1/arch/sh/kernel/kgdb.c 2011-05-19 00:06:34.000000000 -0400
4973+++ linux-2.6.39.1/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 },
4983diff -urNp linux-2.6.39.1/arch/sh/mm/consistent.c linux-2.6.39.1/arch/sh/mm/consistent.c
4984--- linux-2.6.39.1/arch/sh/mm/consistent.c 2011-05-19 00:06:34.000000000 -0400
4985+++ linux-2.6.39.1/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)
4995diff -urNp linux-2.6.39.1/arch/sh/mm/mmap.c linux-2.6.39.1/arch/sh/mm/mmap.c
4996--- linux-2.6.39.1/arch/sh/mm/mmap.c 2011-05-19 00:06:34.000000000 -0400
4997+++ linux-2.6.39.1/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 /*
5072diff -urNp linux-2.6.39.1/arch/sparc/include/asm/atomic_64.h linux-2.6.39.1/arch/sparc/include/asm/atomic_64.h
5073--- linux-2.6.39.1/arch/sparc/include/asm/atomic_64.h 2011-05-19 00:06:34.000000000 -0400
5074+++ linux-2.6.39.1/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)
5246diff -urNp linux-2.6.39.1/arch/sparc/include/asm/cache.h linux-2.6.39.1/arch/sparc/include/asm/cache.h
5247--- linux-2.6.39.1/arch/sparc/include/asm/cache.h 2011-05-19 00:06:34.000000000 -0400
5248+++ linux-2.6.39.1/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
5258diff -urNp linux-2.6.39.1/arch/sparc/include/asm/dma-mapping.h linux-2.6.39.1/arch/sparc/include/asm/dma-mapping.h
5259--- linux-2.6.39.1/arch/sparc/include/asm/dma-mapping.h 2011-05-19 00:06:34.000000000 -0400
5260+++ linux-2.6.39.1/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);
5292diff -urNp linux-2.6.39.1/arch/sparc/include/asm/elf_32.h linux-2.6.39.1/arch/sparc/include/asm/elf_32.h
5293--- linux-2.6.39.1/arch/sparc/include/asm/elf_32.h 2011-05-19 00:06:34.000000000 -0400
5294+++ linux-2.6.39.1/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. */
5309diff -urNp linux-2.6.39.1/arch/sparc/include/asm/elf_64.h linux-2.6.39.1/arch/sparc/include/asm/elf_64.h
5310--- linux-2.6.39.1/arch/sparc/include/asm/elf_64.h 2011-05-19 00:06:34.000000000 -0400
5311+++ linux-2.6.39.1/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. */
5325diff -urNp linux-2.6.39.1/arch/sparc/include/asm/pgtable_32.h linux-2.6.39.1/arch/sparc/include/asm/pgtable_32.h
5326--- linux-2.6.39.1/arch/sparc/include/asm/pgtable_32.h 2011-05-19 00:06:34.000000000 -0400
5327+++ linux-2.6.39.1/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
5359diff -urNp linux-2.6.39.1/arch/sparc/include/asm/pgtsrmmu.h linux-2.6.39.1/arch/sparc/include/asm/pgtsrmmu.h
5360--- linux-2.6.39.1/arch/sparc/include/asm/pgtsrmmu.h 2011-05-19 00:06:34.000000000 -0400
5361+++ linux-2.6.39.1/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
5376diff -urNp linux-2.6.39.1/arch/sparc/include/asm/spinlock_64.h linux-2.6.39.1/arch/sparc/include/asm/spinlock_64.h
5377--- linux-2.6.39.1/arch/sparc/include/asm/spinlock_64.h 2011-05-19 00:06:34.000000000 -0400
5378+++ linux-2.6.39.1/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
5476diff -urNp linux-2.6.39.1/arch/sparc/include/asm/thread_info_32.h linux-2.6.39.1/arch/sparc/include/asm/thread_info_32.h
5477--- linux-2.6.39.1/arch/sparc/include/asm/thread_info_32.h 2011-05-19 00:06:34.000000000 -0400
5478+++ linux-2.6.39.1/arch/sparc/include/asm/thread_info_32.h 2011-06-03 01:14:03.000000000 -0400
5479@@ -50,6 +50,8 @@ struct thread_info {
5480 unsigned long w_saved;
5481
5482 struct restart_block restart_block;
5483+
5484+ unsigned long lowest_stack;
5485 };
5486
5487 /*
5488diff -urNp linux-2.6.39.1/arch/sparc/include/asm/thread_info_64.h linux-2.6.39.1/arch/sparc/include/asm/thread_info_64.h
5489--- linux-2.6.39.1/arch/sparc/include/asm/thread_info_64.h 2011-05-19 00:06:34.000000000 -0400
5490+++ linux-2.6.39.1/arch/sparc/include/asm/thread_info_64.h 2011-06-03 01:14:21.000000000 -0400
5491@@ -63,6 +63,8 @@ struct thread_info {
5492 struct pt_regs *kern_una_regs;
5493 unsigned int kern_una_insn;
5494
5495+ unsigned long lowest_stack;
5496+
5497 unsigned long fpregs[0] __attribute__ ((aligned(64)));
5498 };
5499
5500diff -urNp linux-2.6.39.1/arch/sparc/include/asm/uaccess_32.h linux-2.6.39.1/arch/sparc/include/asm/uaccess_32.h
5501--- linux-2.6.39.1/arch/sparc/include/asm/uaccess_32.h 2011-05-19 00:06:34.000000000 -0400
5502+++ linux-2.6.39.1/arch/sparc/include/asm/uaccess_32.h 2011-05-22 19:36:30.000000000 -0400
5503@@ -249,27 +249,46 @@ extern unsigned long __copy_user(void __
5504
5505 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5506 {
5507- if (n && __access_ok((unsigned long) to, n))
5508+ if ((long)n < 0)
5509+ return n;
5510+
5511+ if (n && __access_ok((unsigned long) to, n)) {
5512+ if (!__builtin_constant_p(n))
5513+ check_object_size(from, n, true);
5514 return __copy_user(to, (__force void __user *) from, n);
5515- else
5516+ } else
5517 return n;
5518 }
5519
5520 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
5521 {
5522+ if ((long)n < 0)
5523+ return n;
5524+
5525+ if (!__builtin_constant_p(n))
5526+ check_object_size(from, n, true);
5527+
5528 return __copy_user(to, (__force void __user *) from, n);
5529 }
5530
5531 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5532 {
5533- if (n && __access_ok((unsigned long) from, n))
5534+ if ((long)n < 0)
5535+ return n;
5536+
5537+ if (n && __access_ok((unsigned long) from, n)) {
5538+ if (!__builtin_constant_p(n))
5539+ check_object_size(to, n, false);
5540 return __copy_user((__force void __user *) to, from, n);
5541- else
5542+ } else
5543 return n;
5544 }
5545
5546 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
5547 {
5548+ if ((long)n < 0)
5549+ return n;
5550+
5551 return __copy_user((__force void __user *) to, from, n);
5552 }
5553
5554diff -urNp linux-2.6.39.1/arch/sparc/include/asm/uaccess_64.h linux-2.6.39.1/arch/sparc/include/asm/uaccess_64.h
5555--- linux-2.6.39.1/arch/sparc/include/asm/uaccess_64.h 2011-05-19 00:06:34.000000000 -0400
5556+++ linux-2.6.39.1/arch/sparc/include/asm/uaccess_64.h 2011-05-22 19:36:30.000000000 -0400
5557@@ -10,6 +10,7 @@
5558 #include <linux/compiler.h>
5559 #include <linux/string.h>
5560 #include <linux/thread_info.h>
5561+#include <linux/kernel.h>
5562 #include <asm/asi.h>
5563 #include <asm/system.h>
5564 #include <asm/spitfire.h>
5565@@ -213,8 +214,15 @@ extern unsigned long copy_from_user_fixu
5566 static inline unsigned long __must_check
5567 copy_from_user(void *to, const void __user *from, unsigned long size)
5568 {
5569- unsigned long ret = ___copy_from_user(to, from, size);
5570+ unsigned long ret;
5571
5572+ if ((long)size < 0 || size > INT_MAX)
5573+ return size;
5574+
5575+ if (!__builtin_constant_p(size))
5576+ check_object_size(to, size, false);
5577+
5578+ ret = ___copy_from_user(to, from, size);
5579 if (unlikely(ret))
5580 ret = copy_from_user_fixup(to, from, size);
5581
5582@@ -230,8 +238,15 @@ extern unsigned long copy_to_user_fixup(
5583 static inline unsigned long __must_check
5584 copy_to_user(void __user *to, const void *from, unsigned long size)
5585 {
5586- unsigned long ret = ___copy_to_user(to, from, size);
5587+ unsigned long ret;
5588+
5589+ if ((long)size < 0 || size > INT_MAX)
5590+ return size;
5591+
5592+ if (!__builtin_constant_p(size))
5593+ check_object_size(from, size, true);
5594
5595+ ret = ___copy_to_user(to, from, size);
5596 if (unlikely(ret))
5597 ret = copy_to_user_fixup(to, from, size);
5598 return ret;
5599diff -urNp linux-2.6.39.1/arch/sparc/include/asm/uaccess.h linux-2.6.39.1/arch/sparc/include/asm/uaccess.h
5600--- linux-2.6.39.1/arch/sparc/include/asm/uaccess.h 2011-05-19 00:06:34.000000000 -0400
5601+++ linux-2.6.39.1/arch/sparc/include/asm/uaccess.h 2011-05-22 19:36:30.000000000 -0400
5602@@ -1,5 +1,13 @@
5603 #ifndef ___ASM_SPARC_UACCESS_H
5604 #define ___ASM_SPARC_UACCESS_H
5605+
5606+#ifdef __KERNEL__
5607+#ifndef __ASSEMBLY__
5608+#include <linux/types.h>
5609+extern void check_object_size(const void *ptr, unsigned long n, bool to);
5610+#endif
5611+#endif
5612+
5613 #if defined(__sparc__) && defined(__arch64__)
5614 #include <asm/uaccess_64.h>
5615 #else
5616diff -urNp linux-2.6.39.1/arch/sparc/kernel/iommu.c linux-2.6.39.1/arch/sparc/kernel/iommu.c
5617--- linux-2.6.39.1/arch/sparc/kernel/iommu.c 2011-05-19 00:06:34.000000000 -0400
5618+++ linux-2.6.39.1/arch/sparc/kernel/iommu.c 2011-05-22 19:36:30.000000000 -0400
5619@@ -824,7 +824,7 @@ static void dma_4u_sync_sg_for_cpu(struc
5620 spin_unlock_irqrestore(&iommu->lock, flags);
5621 }
5622
5623-static struct dma_map_ops sun4u_dma_ops = {
5624+static const struct dma_map_ops sun4u_dma_ops = {
5625 .alloc_coherent = dma_4u_alloc_coherent,
5626 .free_coherent = dma_4u_free_coherent,
5627 .map_page = dma_4u_map_page,
5628@@ -835,7 +835,7 @@ static struct dma_map_ops sun4u_dma_ops
5629 .sync_sg_for_cpu = dma_4u_sync_sg_for_cpu,
5630 };
5631
5632-struct dma_map_ops *dma_ops = &sun4u_dma_ops;
5633+const struct dma_map_ops *dma_ops = &sun4u_dma_ops;
5634 EXPORT_SYMBOL(dma_ops);
5635
5636 extern int pci64_dma_supported(struct pci_dev *pdev, u64 device_mask);
5637diff -urNp linux-2.6.39.1/arch/sparc/kernel/ioport.c linux-2.6.39.1/arch/sparc/kernel/ioport.c
5638--- linux-2.6.39.1/arch/sparc/kernel/ioport.c 2011-05-19 00:06:34.000000000 -0400
5639+++ linux-2.6.39.1/arch/sparc/kernel/ioport.c 2011-05-22 19:36:30.000000000 -0400
5640@@ -402,7 +402,7 @@ static void sbus_sync_sg_for_device(stru
5641 BUG();
5642 }
5643
5644-struct dma_map_ops sbus_dma_ops = {
5645+const struct dma_map_ops sbus_dma_ops = {
5646 .alloc_coherent = sbus_alloc_coherent,
5647 .free_coherent = sbus_free_coherent,
5648 .map_page = sbus_map_page,
5649@@ -653,7 +653,7 @@ static void pci32_sync_sg_for_device(str
5650 }
5651 }
5652
5653-struct dma_map_ops pci32_dma_ops = {
5654+const struct dma_map_ops pci32_dma_ops = {
5655 .alloc_coherent = pci32_alloc_coherent,
5656 .free_coherent = pci32_free_coherent,
5657 .map_page = pci32_map_page,
5658diff -urNp linux-2.6.39.1/arch/sparc/kernel/kgdb_32.c linux-2.6.39.1/arch/sparc/kernel/kgdb_32.c
5659--- linux-2.6.39.1/arch/sparc/kernel/kgdb_32.c 2011-05-19 00:06:34.000000000 -0400
5660+++ linux-2.6.39.1/arch/sparc/kernel/kgdb_32.c 2011-05-22 19:36:30.000000000 -0400
5661@@ -164,7 +164,7 @@ void kgdb_arch_set_pc(struct pt_regs *re
5662 regs->npc = regs->pc + 4;
5663 }
5664
5665-struct kgdb_arch arch_kgdb_ops = {
5666+const struct kgdb_arch arch_kgdb_ops = {
5667 /* Breakpoint instruction: ta 0x7d */
5668 .gdb_bpt_instr = { 0x91, 0xd0, 0x20, 0x7d },
5669 };
5670diff -urNp linux-2.6.39.1/arch/sparc/kernel/kgdb_64.c linux-2.6.39.1/arch/sparc/kernel/kgdb_64.c
5671--- linux-2.6.39.1/arch/sparc/kernel/kgdb_64.c 2011-05-19 00:06:34.000000000 -0400
5672+++ linux-2.6.39.1/arch/sparc/kernel/kgdb_64.c 2011-05-22 19:36:30.000000000 -0400
5673@@ -187,7 +187,7 @@ void kgdb_arch_set_pc(struct pt_regs *re
5674 regs->tnpc = regs->tpc + 4;
5675 }
5676
5677-struct kgdb_arch arch_kgdb_ops = {
5678+const struct kgdb_arch arch_kgdb_ops = {
5679 /* Breakpoint instruction: ta 0x72 */
5680 .gdb_bpt_instr = { 0x91, 0xd0, 0x20, 0x72 },
5681 };
5682diff -urNp linux-2.6.39.1/arch/sparc/kernel/Makefile linux-2.6.39.1/arch/sparc/kernel/Makefile
5683--- linux-2.6.39.1/arch/sparc/kernel/Makefile 2011-05-19 00:06:34.000000000 -0400
5684+++ linux-2.6.39.1/arch/sparc/kernel/Makefile 2011-05-22 19:36:30.000000000 -0400
5685@@ -3,7 +3,7 @@
5686 #
5687
5688 asflags-y := -ansi
5689-ccflags-y := -Werror
5690+#ccflags-y := -Werror
5691
5692 extra-y := head_$(BITS).o
5693 extra-y += init_task.o
5694diff -urNp linux-2.6.39.1/arch/sparc/kernel/pcic.c linux-2.6.39.1/arch/sparc/kernel/pcic.c
5695--- linux-2.6.39.1/arch/sparc/kernel/pcic.c 2011-05-19 00:06:34.000000000 -0400
5696+++ linux-2.6.39.1/arch/sparc/kernel/pcic.c 2011-05-22 19:36:30.000000000 -0400
5697@@ -268,7 +268,7 @@ static int pcic_write_config(struct pci_
5698 return -EINVAL;
5699 }
5700
5701-static struct pci_ops pcic_ops = {
5702+static const struct pci_ops pcic_ops = {
5703 .read = pcic_read_config,
5704 .write = pcic_write_config,
5705 };
5706diff -urNp linux-2.6.39.1/arch/sparc/kernel/pci_common.c linux-2.6.39.1/arch/sparc/kernel/pci_common.c
5707--- linux-2.6.39.1/arch/sparc/kernel/pci_common.c 2011-05-19 00:06:34.000000000 -0400
5708+++ linux-2.6.39.1/arch/sparc/kernel/pci_common.c 2011-05-22 19:36:30.000000000 -0400
5709@@ -249,7 +249,7 @@ static int sun4u_write_pci_cfg(struct pc
5710 return PCIBIOS_SUCCESSFUL;
5711 }
5712
5713-struct pci_ops sun4u_pci_ops = {
5714+const struct pci_ops sun4u_pci_ops = {
5715 .read = sun4u_read_pci_cfg,
5716 .write = sun4u_write_pci_cfg,
5717 };
5718@@ -310,7 +310,7 @@ static int sun4v_write_pci_cfg(struct pc
5719 return PCIBIOS_SUCCESSFUL;
5720 }
5721
5722-struct pci_ops sun4v_pci_ops = {
5723+const struct pci_ops sun4v_pci_ops = {
5724 .read = sun4v_read_pci_cfg,
5725 .write = sun4v_write_pci_cfg,
5726 };
5727diff -urNp linux-2.6.39.1/arch/sparc/kernel/pci_impl.h linux-2.6.39.1/arch/sparc/kernel/pci_impl.h
5728--- linux-2.6.39.1/arch/sparc/kernel/pci_impl.h 2011-05-19 00:06:34.000000000 -0400
5729+++ linux-2.6.39.1/arch/sparc/kernel/pci_impl.h 2011-05-22 19:36:30.000000000 -0400
5730@@ -175,8 +175,8 @@ extern void pci_config_write8(u8 *addr,
5731 extern void pci_config_write16(u16 *addr, u16 val);
5732 extern void pci_config_write32(u32 *addr, u32 val);
5733
5734-extern struct pci_ops sun4u_pci_ops;
5735-extern struct pci_ops sun4v_pci_ops;
5736+extern const struct pci_ops sun4u_pci_ops;
5737+extern const struct pci_ops sun4v_pci_ops;
5738
5739 extern volatile int pci_poke_in_progress;
5740 extern volatile int pci_poke_cpu;
5741diff -urNp linux-2.6.39.1/arch/sparc/kernel/pci_sun4v.c linux-2.6.39.1/arch/sparc/kernel/pci_sun4v.c
5742--- linux-2.6.39.1/arch/sparc/kernel/pci_sun4v.c 2011-05-19 00:06:34.000000000 -0400
5743+++ linux-2.6.39.1/arch/sparc/kernel/pci_sun4v.c 2011-05-22 19:36:30.000000000 -0400
5744@@ -525,7 +525,7 @@ static void dma_4v_unmap_sg(struct devic
5745 spin_unlock_irqrestore(&iommu->lock, flags);
5746 }
5747
5748-static struct dma_map_ops sun4v_dma_ops = {
5749+static const struct dma_map_ops sun4v_dma_ops = {
5750 .alloc_coherent = dma_4v_alloc_coherent,
5751 .free_coherent = dma_4v_free_coherent,
5752 .map_page = dma_4v_map_page,
5753diff -urNp linux-2.6.39.1/arch/sparc/kernel/process_32.c linux-2.6.39.1/arch/sparc/kernel/process_32.c
5754--- linux-2.6.39.1/arch/sparc/kernel/process_32.c 2011-05-19 00:06:34.000000000 -0400
5755+++ linux-2.6.39.1/arch/sparc/kernel/process_32.c 2011-05-22 19:41:32.000000000 -0400
5756@@ -196,7 +196,7 @@ void __show_backtrace(unsigned long fp)
5757 rw->ins[4], rw->ins[5],
5758 rw->ins[6],
5759 rw->ins[7]);
5760- printk("%pS\n", (void *) rw->ins[7]);
5761+ printk("%pA\n", (void *) rw->ins[7]);
5762 rw = (struct reg_window32 *) rw->ins[6];
5763 }
5764 spin_unlock_irqrestore(&sparc_backtrace_lock, flags);
5765@@ -263,14 +263,14 @@ void show_regs(struct pt_regs *r)
5766
5767 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
5768 r->psr, r->pc, r->npc, r->y, print_tainted());
5769- printk("PC: <%pS>\n", (void *) r->pc);
5770+ printk("PC: <%pA>\n", (void *) r->pc);
5771 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5772 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
5773 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
5774 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5775 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
5776 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
5777- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
5778+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
5779
5780 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5781 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
5782@@ -305,7 +305,7 @@ void show_stack(struct task_struct *tsk,
5783 rw = (struct reg_window32 *) fp;
5784 pc = rw->ins[7];
5785 printk("[%08lx : ", pc);
5786- printk("%pS ] ", (void *) pc);
5787+ printk("%pA ] ", (void *) pc);
5788 fp = rw->ins[6];
5789 } while (++count < 16);
5790 printk("\n");
5791diff -urNp linux-2.6.39.1/arch/sparc/kernel/process_64.c linux-2.6.39.1/arch/sparc/kernel/process_64.c
5792--- linux-2.6.39.1/arch/sparc/kernel/process_64.c 2011-05-19 00:06:34.000000000 -0400
5793+++ linux-2.6.39.1/arch/sparc/kernel/process_64.c 2011-05-22 19:41:32.000000000 -0400
5794@@ -180,14 +180,14 @@ static void show_regwindow(struct pt_reg
5795 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
5796 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
5797 if (regs->tstate & TSTATE_PRIV)
5798- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
5799+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
5800 }
5801
5802 void show_regs(struct pt_regs *regs)
5803 {
5804 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
5805 regs->tpc, regs->tnpc, regs->y, print_tainted());
5806- printk("TPC: <%pS>\n", (void *) regs->tpc);
5807+ printk("TPC: <%pA>\n", (void *) regs->tpc);
5808 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
5809 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
5810 regs->u_regs[3]);
5811@@ -200,7 +200,7 @@ void show_regs(struct pt_regs *regs)
5812 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
5813 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
5814 regs->u_regs[15]);
5815- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
5816+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
5817 show_regwindow(regs);
5818 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
5819 }
5820@@ -285,7 +285,7 @@ void arch_trigger_all_cpu_backtrace(void
5821 ((tp && tp->task) ? tp->task->pid : -1));
5822
5823 if (gp->tstate & TSTATE_PRIV) {
5824- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
5825+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
5826 (void *) gp->tpc,
5827 (void *) gp->o7,
5828 (void *) gp->i7,
5829diff -urNp linux-2.6.39.1/arch/sparc/kernel/sys_sparc_32.c linux-2.6.39.1/arch/sparc/kernel/sys_sparc_32.c
5830--- linux-2.6.39.1/arch/sparc/kernel/sys_sparc_32.c 2011-05-19 00:06:34.000000000 -0400
5831+++ linux-2.6.39.1/arch/sparc/kernel/sys_sparc_32.c 2011-05-22 19:36:30.000000000 -0400
5832@@ -56,7 +56,7 @@ unsigned long arch_get_unmapped_area(str
5833 if (ARCH_SUN4C && len > 0x20000000)
5834 return -ENOMEM;
5835 if (!addr)
5836- addr = TASK_UNMAPPED_BASE;
5837+ addr = current->mm->mmap_base;
5838
5839 if (flags & MAP_SHARED)
5840 addr = COLOUR_ALIGN(addr);
5841@@ -71,7 +71,7 @@ unsigned long arch_get_unmapped_area(str
5842 }
5843 if (TASK_SIZE - PAGE_SIZE - len < addr)
5844 return -ENOMEM;
5845- if (!vmm || addr + len <= vmm->vm_start)
5846+ if (check_heap_stack_gap(vmm, addr, len))
5847 return addr;
5848 addr = vmm->vm_end;
5849 if (flags & MAP_SHARED)
5850diff -urNp linux-2.6.39.1/arch/sparc/kernel/sys_sparc_64.c linux-2.6.39.1/arch/sparc/kernel/sys_sparc_64.c
5851--- linux-2.6.39.1/arch/sparc/kernel/sys_sparc_64.c 2011-05-19 00:06:34.000000000 -0400
5852+++ linux-2.6.39.1/arch/sparc/kernel/sys_sparc_64.c 2011-05-22 19:36:30.000000000 -0400
5853@@ -124,7 +124,7 @@ unsigned long arch_get_unmapped_area(str
5854 /* We do not accept a shared mapping if it would violate
5855 * cache aliasing constraints.
5856 */
5857- if ((flags & MAP_SHARED) &&
5858+ if ((filp || (flags & MAP_SHARED)) &&
5859 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5860 return -EINVAL;
5861 return addr;
5862@@ -139,6 +139,10 @@ unsigned long arch_get_unmapped_area(str
5863 if (filp || (flags & MAP_SHARED))
5864 do_color_align = 1;
5865
5866+#ifdef CONFIG_PAX_RANDMMAP
5867+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5868+#endif
5869+
5870 if (addr) {
5871 if (do_color_align)
5872 addr = COLOUR_ALIGN(addr, pgoff);
5873@@ -146,15 +150,14 @@ unsigned long arch_get_unmapped_area(str
5874 addr = PAGE_ALIGN(addr);
5875
5876 vma = find_vma(mm, addr);
5877- if (task_size - len >= addr &&
5878- (!vma || addr + len <= vma->vm_start))
5879+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5880 return addr;
5881 }
5882
5883 if (len > mm->cached_hole_size) {
5884- start_addr = addr = mm->free_area_cache;
5885+ start_addr = addr = mm->free_area_cache;
5886 } else {
5887- start_addr = addr = TASK_UNMAPPED_BASE;
5888+ start_addr = addr = mm->mmap_base;
5889 mm->cached_hole_size = 0;
5890 }
5891
5892@@ -174,14 +177,14 @@ full_search:
5893 vma = find_vma(mm, VA_EXCLUDE_END);
5894 }
5895 if (unlikely(task_size < addr)) {
5896- if (start_addr != TASK_UNMAPPED_BASE) {
5897- start_addr = addr = TASK_UNMAPPED_BASE;
5898+ if (start_addr != mm->mmap_base) {
5899+ start_addr = addr = mm->mmap_base;
5900 mm->cached_hole_size = 0;
5901 goto full_search;
5902 }
5903 return -ENOMEM;
5904 }
5905- if (likely(!vma || addr + len <= vma->vm_start)) {
5906+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5907 /*
5908 * Remember the place where we stopped the search:
5909 */
5910@@ -215,7 +218,7 @@ arch_get_unmapped_area_topdown(struct fi
5911 /* We do not accept a shared mapping if it would violate
5912 * cache aliasing constraints.
5913 */
5914- if ((flags & MAP_SHARED) &&
5915+ if ((filp || (flags & MAP_SHARED)) &&
5916 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5917 return -EINVAL;
5918 return addr;
5919@@ -236,8 +239,7 @@ arch_get_unmapped_area_topdown(struct fi
5920 addr = PAGE_ALIGN(addr);
5921
5922 vma = find_vma(mm, addr);
5923- if (task_size - len >= addr &&
5924- (!vma || addr + len <= vma->vm_start))
5925+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5926 return addr;
5927 }
5928
5929@@ -258,7 +260,7 @@ arch_get_unmapped_area_topdown(struct fi
5930 /* make sure it can fit in the remaining address space */
5931 if (likely(addr > len)) {
5932 vma = find_vma(mm, addr-len);
5933- if (!vma || addr <= vma->vm_start) {
5934+ if (check_heap_stack_gap(vma, addr - len, len)) {
5935 /* remember the address as a hint for next time */
5936 return (mm->free_area_cache = addr-len);
5937 }
5938@@ -267,18 +269,18 @@ arch_get_unmapped_area_topdown(struct fi
5939 if (unlikely(mm->mmap_base < len))
5940 goto bottomup;
5941
5942- addr = mm->mmap_base-len;
5943- if (do_color_align)
5944- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5945+ addr = mm->mmap_base - len;
5946
5947 do {
5948+ if (do_color_align)
5949+ addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5950 /*
5951 * Lookup failure means no vma is above this address,
5952 * else if new region fits below vma->vm_start,
5953 * return with success:
5954 */
5955 vma = find_vma(mm, addr);
5956- if (likely(!vma || addr+len <= vma->vm_start)) {
5957+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5958 /* remember the address as a hint for next time */
5959 return (mm->free_area_cache = addr);
5960 }
5961@@ -288,10 +290,8 @@ arch_get_unmapped_area_topdown(struct fi
5962 mm->cached_hole_size = vma->vm_start - addr;
5963
5964 /* try just below the current vma->vm_start */
5965- addr = vma->vm_start-len;
5966- if (do_color_align)
5967- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5968- } while (likely(len < vma->vm_start));
5969+ addr = skip_heap_stack_gap(vma, len);
5970+ } while (!IS_ERR_VALUE(addr));
5971
5972 bottomup:
5973 /*
5974@@ -390,6 +390,12 @@ void arch_pick_mmap_layout(struct mm_str
5975 gap == RLIM_INFINITY ||
5976 sysctl_legacy_va_layout) {
5977 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5978+
5979+#ifdef CONFIG_PAX_RANDMMAP
5980+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5981+ mm->mmap_base += mm->delta_mmap;
5982+#endif
5983+
5984 mm->get_unmapped_area = arch_get_unmapped_area;
5985 mm->unmap_area = arch_unmap_area;
5986 } else {
5987@@ -402,6 +408,12 @@ void arch_pick_mmap_layout(struct mm_str
5988 gap = (task_size / 6 * 5);
5989
5990 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
5991+
5992+#ifdef CONFIG_PAX_RANDMMAP
5993+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5994+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5995+#endif
5996+
5997 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5998 mm->unmap_area = arch_unmap_area_topdown;
5999 }
6000diff -urNp linux-2.6.39.1/arch/sparc/kernel/traps_32.c linux-2.6.39.1/arch/sparc/kernel/traps_32.c
6001--- linux-2.6.39.1/arch/sparc/kernel/traps_32.c 2011-05-19 00:06:34.000000000 -0400
6002+++ linux-2.6.39.1/arch/sparc/kernel/traps_32.c 2011-05-22 19:41:32.000000000 -0400
6003@@ -76,7 +76,7 @@ void die_if_kernel(char *str, struct pt_
6004 count++ < 30 &&
6005 (((unsigned long) rw) >= PAGE_OFFSET) &&
6006 !(((unsigned long) rw) & 0x7)) {
6007- printk("Caller[%08lx]: %pS\n", rw->ins[7],
6008+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
6009 (void *) rw->ins[7]);
6010 rw = (struct reg_window32 *)rw->ins[6];
6011 }
6012diff -urNp linux-2.6.39.1/arch/sparc/kernel/traps_64.c linux-2.6.39.1/arch/sparc/kernel/traps_64.c
6013--- linux-2.6.39.1/arch/sparc/kernel/traps_64.c 2011-05-19 00:06:34.000000000 -0400
6014+++ linux-2.6.39.1/arch/sparc/kernel/traps_64.c 2011-05-22 19:41:32.000000000 -0400
6015@@ -75,7 +75,7 @@ static void dump_tl1_traplog(struct tl1_
6016 i + 1,
6017 p->trapstack[i].tstate, p->trapstack[i].tpc,
6018 p->trapstack[i].tnpc, p->trapstack[i].tt);
6019- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
6020+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
6021 }
6022 }
6023
6024@@ -95,6 +95,12 @@ void bad_trap(struct pt_regs *regs, long
6025
6026 lvl -= 0x100;
6027 if (regs->tstate & TSTATE_PRIV) {
6028+
6029+#ifdef CONFIG_PAX_REFCOUNT
6030+ if (lvl == 6)
6031+ pax_report_refcount_overflow(regs);
6032+#endif
6033+
6034 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
6035 die_if_kernel(buffer, regs);
6036 }
6037@@ -113,11 +119,16 @@ void bad_trap(struct pt_regs *regs, long
6038 void bad_trap_tl1(struct pt_regs *regs, long lvl)
6039 {
6040 char buffer[32];
6041-
6042+
6043 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
6044 0, lvl, SIGTRAP) == NOTIFY_STOP)
6045 return;
6046
6047+#ifdef CONFIG_PAX_REFCOUNT
6048+ if (lvl == 6)
6049+ pax_report_refcount_overflow(regs);
6050+#endif
6051+
6052 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
6053
6054 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
6055@@ -1141,7 +1152,7 @@ static void cheetah_log_errors(struct pt
6056 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
6057 printk("%s" "ERROR(%d): ",
6058 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
6059- printk("TPC<%pS>\n", (void *) regs->tpc);
6060+ printk("TPC<%pA>\n", (void *) regs->tpc);
6061 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
6062 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
6063 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
6064@@ -1748,7 +1759,7 @@ void cheetah_plus_parity_error(int type,
6065 smp_processor_id(),
6066 (type & 0x1) ? 'I' : 'D',
6067 regs->tpc);
6068- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
6069+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
6070 panic("Irrecoverable Cheetah+ parity error.");
6071 }
6072
6073@@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type,
6074 smp_processor_id(),
6075 (type & 0x1) ? 'I' : 'D',
6076 regs->tpc);
6077- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
6078+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
6079 }
6080
6081 struct sun4v_error_entry {
6082@@ -1963,9 +1974,9 @@ void sun4v_itlb_error_report(struct pt_r
6083
6084 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
6085 regs->tpc, tl);
6086- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
6087+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
6088 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6089- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
6090+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
6091 (void *) regs->u_regs[UREG_I7]);
6092 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
6093 "pte[%lx] error[%lx]\n",
6094@@ -1987,9 +1998,9 @@ void sun4v_dtlb_error_report(struct pt_r
6095
6096 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
6097 regs->tpc, tl);
6098- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
6099+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
6100 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6101- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
6102+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
6103 (void *) regs->u_regs[UREG_I7]);
6104 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
6105 "pte[%lx] error[%lx]\n",
6106@@ -2195,13 +2206,13 @@ void show_stack(struct task_struct *tsk,
6107 fp = (unsigned long)sf->fp + STACK_BIAS;
6108 }
6109
6110- printk(" [%016lx] %pS\n", pc, (void *) pc);
6111+ printk(" [%016lx] %pA\n", pc, (void *) pc);
6112 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6113 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
6114 int index = tsk->curr_ret_stack;
6115 if (tsk->ret_stack && index >= graph) {
6116 pc = tsk->ret_stack[index - graph].ret;
6117- printk(" [%016lx] %pS\n", pc, (void *) pc);
6118+ printk(" [%016lx] %pA\n", pc, (void *) pc);
6119 graph++;
6120 }
6121 }
6122@@ -2254,7 +2265,7 @@ void die_if_kernel(char *str, struct pt_
6123 while (rw &&
6124 count++ < 30 &&
6125 kstack_valid(tp, (unsigned long) rw)) {
6126- printk("Caller[%016lx]: %pS\n", rw->ins[7],
6127+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
6128 (void *) rw->ins[7]);
6129
6130 rw = kernel_stack_up(rw);
6131diff -urNp linux-2.6.39.1/arch/sparc/kernel/unaligned_64.c linux-2.6.39.1/arch/sparc/kernel/unaligned_64.c
6132--- linux-2.6.39.1/arch/sparc/kernel/unaligned_64.c 2011-05-19 00:06:34.000000000 -0400
6133+++ linux-2.6.39.1/arch/sparc/kernel/unaligned_64.c 2011-05-22 19:41:32.000000000 -0400
6134@@ -278,7 +278,7 @@ static void log_unaligned(struct pt_regs
6135 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
6136
6137 if (__ratelimit(&ratelimit)) {
6138- printk("Kernel unaligned access at TPC[%lx] %pS\n",
6139+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
6140 regs->tpc, (void *) regs->tpc);
6141 }
6142 }
6143diff -urNp linux-2.6.39.1/arch/sparc/lib/atomic_64.S linux-2.6.39.1/arch/sparc/lib/atomic_64.S
6144--- linux-2.6.39.1/arch/sparc/lib/atomic_64.S 2011-05-19 00:06:34.000000000 -0400
6145+++ linux-2.6.39.1/arch/sparc/lib/atomic_64.S 2011-05-22 19:36:30.000000000 -0400
6146@@ -18,7 +18,12 @@
6147 atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
6148 BACKOFF_SETUP(%o2)
6149 1: lduw [%o1], %g1
6150- add %g1, %o0, %g7
6151+ addcc %g1, %o0, %g7
6152+
6153+#ifdef CONFIG_PAX_REFCOUNT
6154+ tvs %icc, 6
6155+#endif
6156+
6157 cas [%o1], %g1, %g7
6158 cmp %g1, %g7
6159 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6160@@ -28,12 +33,32 @@ atomic_add: /* %o0 = increment, %o1 = at
6161 2: BACKOFF_SPIN(%o2, %o3, 1b)
6162 .size atomic_add, .-atomic_add
6163
6164+ .globl atomic_add_unchecked
6165+ .type atomic_add_unchecked,#function
6166+atomic_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6167+ BACKOFF_SETUP(%o2)
6168+1: lduw [%o1], %g1
6169+ add %g1, %o0, %g7
6170+ cas [%o1], %g1, %g7
6171+ cmp %g1, %g7
6172+ bne,pn %icc, 2f
6173+ nop
6174+ retl
6175+ nop
6176+2: BACKOFF_SPIN(%o2, %o3, 1b)
6177+ .size atomic_add_unchecked, .-atomic_add_unchecked
6178+
6179 .globl atomic_sub
6180 .type atomic_sub,#function
6181 atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
6182 BACKOFF_SETUP(%o2)
6183 1: lduw [%o1], %g1
6184- sub %g1, %o0, %g7
6185+ subcc %g1, %o0, %g7
6186+
6187+#ifdef CONFIG_PAX_REFCOUNT
6188+ tvs %icc, 6
6189+#endif
6190+
6191 cas [%o1], %g1, %g7
6192 cmp %g1, %g7
6193 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6194@@ -43,12 +68,32 @@ atomic_sub: /* %o0 = decrement, %o1 = at
6195 2: BACKOFF_SPIN(%o2, %o3, 1b)
6196 .size atomic_sub, .-atomic_sub
6197
6198+ .globl atomic_sub_unchecked
6199+ .type atomic_sub_unchecked,#function
6200+atomic_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
6201+ BACKOFF_SETUP(%o2)
6202+1: lduw [%o1], %g1
6203+ sub %g1, %o0, %g7
6204+ cas [%o1], %g1, %g7
6205+ cmp %g1, %g7
6206+ bne,pn %icc, 2f
6207+ nop
6208+ retl
6209+ nop
6210+2: BACKOFF_SPIN(%o2, %o3, 1b)
6211+ .size atomic_sub_unchecked, .-atomic_sub_unchecked
6212+
6213 .globl atomic_add_ret
6214 .type atomic_add_ret,#function
6215 atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
6216 BACKOFF_SETUP(%o2)
6217 1: lduw [%o1], %g1
6218- add %g1, %o0, %g7
6219+ addcc %g1, %o0, %g7
6220+
6221+#ifdef CONFIG_PAX_REFCOUNT
6222+ tvs %icc, 6
6223+#endif
6224+
6225 cas [%o1], %g1, %g7
6226 cmp %g1, %g7
6227 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6228@@ -58,12 +103,33 @@ atomic_add_ret: /* %o0 = increment, %o1
6229 2: BACKOFF_SPIN(%o2, %o3, 1b)
6230 .size atomic_add_ret, .-atomic_add_ret
6231
6232+ .globl atomic_add_ret_unchecked
6233+ .type atomic_add_ret_unchecked,#function
6234+atomic_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6235+ BACKOFF_SETUP(%o2)
6236+1: lduw [%o1], %g1
6237+ addcc %g1, %o0, %g7
6238+ cas [%o1], %g1, %g7
6239+ cmp %g1, %g7
6240+ bne,pn %icc, 2f
6241+ add %g7, %o0, %g7
6242+ sra %g7, 0, %o0
6243+ retl
6244+ nop
6245+2: BACKOFF_SPIN(%o2, %o3, 1b)
6246+ .size atomic_add_ret_unchecked, .-atomic_add_ret_unchecked
6247+
6248 .globl atomic_sub_ret
6249 .type atomic_sub_ret,#function
6250 atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
6251 BACKOFF_SETUP(%o2)
6252 1: lduw [%o1], %g1
6253- sub %g1, %o0, %g7
6254+ subcc %g1, %o0, %g7
6255+
6256+#ifdef CONFIG_PAX_REFCOUNT
6257+ tvs %icc, 6
6258+#endif
6259+
6260 cas [%o1], %g1, %g7
6261 cmp %g1, %g7
6262 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6263@@ -78,7 +144,12 @@ atomic_sub_ret: /* %o0 = decrement, %o1
6264 atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
6265 BACKOFF_SETUP(%o2)
6266 1: ldx [%o1], %g1
6267- add %g1, %o0, %g7
6268+ addcc %g1, %o0, %g7
6269+
6270+#ifdef CONFIG_PAX_REFCOUNT
6271+ tvs %xcc, 6
6272+#endif
6273+
6274 casx [%o1], %g1, %g7
6275 cmp %g1, %g7
6276 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6277@@ -88,12 +159,32 @@ atomic64_add: /* %o0 = increment, %o1 =
6278 2: BACKOFF_SPIN(%o2, %o3, 1b)
6279 .size atomic64_add, .-atomic64_add
6280
6281+ .globl atomic64_add_unchecked
6282+ .type atomic64_add_unchecked,#function
6283+atomic64_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6284+ BACKOFF_SETUP(%o2)
6285+1: ldx [%o1], %g1
6286+ addcc %g1, %o0, %g7
6287+ casx [%o1], %g1, %g7
6288+ cmp %g1, %g7
6289+ bne,pn %xcc, 2f
6290+ nop
6291+ retl
6292+ nop
6293+2: BACKOFF_SPIN(%o2, %o3, 1b)
6294+ .size atomic64_add_unchecked, .-atomic64_add_unchecked
6295+
6296 .globl atomic64_sub
6297 .type atomic64_sub,#function
6298 atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
6299 BACKOFF_SETUP(%o2)
6300 1: ldx [%o1], %g1
6301- sub %g1, %o0, %g7
6302+ subcc %g1, %o0, %g7
6303+
6304+#ifdef CONFIG_PAX_REFCOUNT
6305+ tvs %xcc, 6
6306+#endif
6307+
6308 casx [%o1], %g1, %g7
6309 cmp %g1, %g7
6310 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6311@@ -103,12 +194,32 @@ atomic64_sub: /* %o0 = decrement, %o1 =
6312 2: BACKOFF_SPIN(%o2, %o3, 1b)
6313 .size atomic64_sub, .-atomic64_sub
6314
6315+ .globl atomic64_sub_unchecked
6316+ .type atomic64_sub_unchecked,#function
6317+atomic64_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
6318+ BACKOFF_SETUP(%o2)
6319+1: ldx [%o1], %g1
6320+ subcc %g1, %o0, %g7
6321+ casx [%o1], %g1, %g7
6322+ cmp %g1, %g7
6323+ bne,pn %xcc, 2f
6324+ nop
6325+ retl
6326+ nop
6327+2: BACKOFF_SPIN(%o2, %o3, 1b)
6328+ .size atomic64_sub_unchecked, .-atomic64_sub_unchecked
6329+
6330 .globl atomic64_add_ret
6331 .type atomic64_add_ret,#function
6332 atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
6333 BACKOFF_SETUP(%o2)
6334 1: ldx [%o1], %g1
6335- add %g1, %o0, %g7
6336+ addcc %g1, %o0, %g7
6337+
6338+#ifdef CONFIG_PAX_REFCOUNT
6339+ tvs %xcc, 6
6340+#endif
6341+
6342 casx [%o1], %g1, %g7
6343 cmp %g1, %g7
6344 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6345@@ -118,12 +229,33 @@ atomic64_add_ret: /* %o0 = increment, %o
6346 2: BACKOFF_SPIN(%o2, %o3, 1b)
6347 .size atomic64_add_ret, .-atomic64_add_ret
6348
6349+ .globl atomic64_add_ret_unchecked
6350+ .type atomic64_add_ret_unchecked,#function
6351+atomic64_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6352+ BACKOFF_SETUP(%o2)
6353+1: ldx [%o1], %g1
6354+ addcc %g1, %o0, %g7
6355+ casx [%o1], %g1, %g7
6356+ cmp %g1, %g7
6357+ bne,pn %xcc, 2f
6358+ add %g7, %o0, %g7
6359+ mov %g7, %o0
6360+ retl
6361+ nop
6362+2: BACKOFF_SPIN(%o2, %o3, 1b)
6363+ .size atomic64_add_ret_unchecked, .-atomic64_add_ret_unchecked
6364+
6365 .globl atomic64_sub_ret
6366 .type atomic64_sub_ret,#function
6367 atomic64_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
6368 BACKOFF_SETUP(%o2)
6369 1: ldx [%o1], %g1
6370- sub %g1, %o0, %g7
6371+ subcc %g1, %o0, %g7
6372+
6373+#ifdef CONFIG_PAX_REFCOUNT
6374+ tvs %xcc, 6
6375+#endif
6376+
6377 casx [%o1], %g1, %g7
6378 cmp %g1, %g7
6379 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6380diff -urNp linux-2.6.39.1/arch/sparc/lib/ksyms.c linux-2.6.39.1/arch/sparc/lib/ksyms.c
6381--- linux-2.6.39.1/arch/sparc/lib/ksyms.c 2011-05-19 00:06:34.000000000 -0400
6382+++ linux-2.6.39.1/arch/sparc/lib/ksyms.c 2011-05-22 19:36:30.000000000 -0400
6383@@ -142,12 +142,17 @@ EXPORT_SYMBOL(__downgrade_write);
6384
6385 /* Atomic counter implementation. */
6386 EXPORT_SYMBOL(atomic_add);
6387+EXPORT_SYMBOL(atomic_add_unchecked);
6388 EXPORT_SYMBOL(atomic_add_ret);
6389 EXPORT_SYMBOL(atomic_sub);
6390+EXPORT_SYMBOL(atomic_sub_unchecked);
6391 EXPORT_SYMBOL(atomic_sub_ret);
6392 EXPORT_SYMBOL(atomic64_add);
6393+EXPORT_SYMBOL(atomic64_add_unchecked);
6394 EXPORT_SYMBOL(atomic64_add_ret);
6395+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
6396 EXPORT_SYMBOL(atomic64_sub);
6397+EXPORT_SYMBOL(atomic64_sub_unchecked);
6398 EXPORT_SYMBOL(atomic64_sub_ret);
6399
6400 /* Atomic bit operations. */
6401diff -urNp linux-2.6.39.1/arch/sparc/lib/Makefile linux-2.6.39.1/arch/sparc/lib/Makefile
6402--- linux-2.6.39.1/arch/sparc/lib/Makefile 2011-05-19 00:06:34.000000000 -0400
6403+++ linux-2.6.39.1/arch/sparc/lib/Makefile 2011-05-22 19:36:30.000000000 -0400
6404@@ -2,7 +2,7 @@
6405 #
6406
6407 asflags-y := -ansi -DST_DIV0=0x02
6408-ccflags-y := -Werror
6409+#ccflags-y := -Werror
6410
6411 lib-$(CONFIG_SPARC32) += mul.o rem.o sdiv.o udiv.o umul.o urem.o ashrdi3.o
6412 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
6413diff -urNp linux-2.6.39.1/arch/sparc/Makefile linux-2.6.39.1/arch/sparc/Makefile
6414--- linux-2.6.39.1/arch/sparc/Makefile 2011-05-19 00:06:34.000000000 -0400
6415+++ linux-2.6.39.1/arch/sparc/Makefile 2011-05-22 19:41:32.000000000 -0400
6416@@ -75,7 +75,7 @@ drivers-$(CONFIG_OPROFILE) += arch/sparc
6417 # Export what is needed by arch/sparc/boot/Makefile
6418 export VMLINUX_INIT VMLINUX_MAIN
6419 VMLINUX_INIT := $(head-y) $(init-y)
6420-VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/
6421+VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
6422 VMLINUX_MAIN += $(patsubst %/, %/lib.a, $(libs-y)) $(libs-y)
6423 VMLINUX_MAIN += $(drivers-y) $(net-y)
6424
6425diff -urNp linux-2.6.39.1/arch/sparc/mm/fault_32.c linux-2.6.39.1/arch/sparc/mm/fault_32.c
6426--- linux-2.6.39.1/arch/sparc/mm/fault_32.c 2011-05-19 00:06:34.000000000 -0400
6427+++ linux-2.6.39.1/arch/sparc/mm/fault_32.c 2011-05-22 19:36:30.000000000 -0400
6428@@ -22,6 +22,9 @@
6429 #include <linux/interrupt.h>
6430 #include <linux/module.h>
6431 #include <linux/kdebug.h>
6432+#include <linux/slab.h>
6433+#include <linux/pagemap.h>
6434+#include <linux/compiler.h>
6435
6436 #include <asm/system.h>
6437 #include <asm/page.h>
6438@@ -209,6 +212,268 @@ static unsigned long compute_si_addr(str
6439 return safe_compute_effective_address(regs, insn);
6440 }
6441
6442+#ifdef CONFIG_PAX_PAGEEXEC
6443+#ifdef CONFIG_PAX_DLRESOLVE
6444+static void pax_emuplt_close(struct vm_area_struct *vma)
6445+{
6446+ vma->vm_mm->call_dl_resolve = 0UL;
6447+}
6448+
6449+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6450+{
6451+ unsigned int *kaddr;
6452+
6453+ vmf->page = alloc_page(GFP_HIGHUSER);
6454+ if (!vmf->page)
6455+ return VM_FAULT_OOM;
6456+
6457+ kaddr = kmap(vmf->page);
6458+ memset(kaddr, 0, PAGE_SIZE);
6459+ kaddr[0] = 0x9DE3BFA8U; /* save */
6460+ flush_dcache_page(vmf->page);
6461+ kunmap(vmf->page);
6462+ return VM_FAULT_MAJOR;
6463+}
6464+
6465+static const struct vm_operations_struct pax_vm_ops = {
6466+ .close = pax_emuplt_close,
6467+ .fault = pax_emuplt_fault
6468+};
6469+
6470+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6471+{
6472+ int ret;
6473+
6474+ INIT_LIST_HEAD(&vma->anon_vma_chain);
6475+ vma->vm_mm = current->mm;
6476+ vma->vm_start = addr;
6477+ vma->vm_end = addr + PAGE_SIZE;
6478+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6479+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6480+ vma->vm_ops = &pax_vm_ops;
6481+
6482+ ret = insert_vm_struct(current->mm, vma);
6483+ if (ret)
6484+ return ret;
6485+
6486+ ++current->mm->total_vm;
6487+ return 0;
6488+}
6489+#endif
6490+
6491+/*
6492+ * PaX: decide what to do with offenders (regs->pc = fault address)
6493+ *
6494+ * returns 1 when task should be killed
6495+ * 2 when patched PLT trampoline was detected
6496+ * 3 when unpatched PLT trampoline was detected
6497+ */
6498+static int pax_handle_fetch_fault(struct pt_regs *regs)
6499+{
6500+
6501+#ifdef CONFIG_PAX_EMUPLT
6502+ int err;
6503+
6504+ do { /* PaX: patched PLT emulation #1 */
6505+ unsigned int sethi1, sethi2, jmpl;
6506+
6507+ err = get_user(sethi1, (unsigned int *)regs->pc);
6508+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
6509+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
6510+
6511+ if (err)
6512+ break;
6513+
6514+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6515+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
6516+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
6517+ {
6518+ unsigned int addr;
6519+
6520+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6521+ addr = regs->u_regs[UREG_G1];
6522+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6523+ regs->pc = addr;
6524+ regs->npc = addr+4;
6525+ return 2;
6526+ }
6527+ } while (0);
6528+
6529+ { /* PaX: patched PLT emulation #2 */
6530+ unsigned int ba;
6531+
6532+ err = get_user(ba, (unsigned int *)regs->pc);
6533+
6534+ if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
6535+ unsigned int addr;
6536+
6537+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6538+ regs->pc = addr;
6539+ regs->npc = addr+4;
6540+ return 2;
6541+ }
6542+ }
6543+
6544+ do { /* PaX: patched PLT emulation #3 */
6545+ unsigned int sethi, jmpl, nop;
6546+
6547+ err = get_user(sethi, (unsigned int *)regs->pc);
6548+ err |= get_user(jmpl, (unsigned int *)(regs->pc+4));
6549+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
6550+
6551+ if (err)
6552+ break;
6553+
6554+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6555+ (jmpl & 0xFFFFE000U) == 0x81C06000U &&
6556+ nop == 0x01000000U)
6557+ {
6558+ unsigned int addr;
6559+
6560+ addr = (sethi & 0x003FFFFFU) << 10;
6561+ regs->u_regs[UREG_G1] = addr;
6562+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6563+ regs->pc = addr;
6564+ regs->npc = addr+4;
6565+ return 2;
6566+ }
6567+ } while (0);
6568+
6569+ do { /* PaX: unpatched PLT emulation step 1 */
6570+ unsigned int sethi, ba, nop;
6571+
6572+ err = get_user(sethi, (unsigned int *)regs->pc);
6573+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
6574+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
6575+
6576+ if (err)
6577+ break;
6578+
6579+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6580+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6581+ nop == 0x01000000U)
6582+ {
6583+ unsigned int addr, save, call;
6584+
6585+ if ((ba & 0xFFC00000U) == 0x30800000U)
6586+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6587+ else
6588+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6589+
6590+ err = get_user(save, (unsigned int *)addr);
6591+ err |= get_user(call, (unsigned int *)(addr+4));
6592+ err |= get_user(nop, (unsigned int *)(addr+8));
6593+ if (err)
6594+ break;
6595+
6596+#ifdef CONFIG_PAX_DLRESOLVE
6597+ if (save == 0x9DE3BFA8U &&
6598+ (call & 0xC0000000U) == 0x40000000U &&
6599+ nop == 0x01000000U)
6600+ {
6601+ struct vm_area_struct *vma;
6602+ unsigned long call_dl_resolve;
6603+
6604+ down_read(&current->mm->mmap_sem);
6605+ call_dl_resolve = current->mm->call_dl_resolve;
6606+ up_read(&current->mm->mmap_sem);
6607+ if (likely(call_dl_resolve))
6608+ goto emulate;
6609+
6610+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6611+
6612+ down_write(&current->mm->mmap_sem);
6613+ if (current->mm->call_dl_resolve) {
6614+ call_dl_resolve = current->mm->call_dl_resolve;
6615+ up_write(&current->mm->mmap_sem);
6616+ if (vma)
6617+ kmem_cache_free(vm_area_cachep, vma);
6618+ goto emulate;
6619+ }
6620+
6621+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6622+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6623+ up_write(&current->mm->mmap_sem);
6624+ if (vma)
6625+ kmem_cache_free(vm_area_cachep, vma);
6626+ return 1;
6627+ }
6628+
6629+ if (pax_insert_vma(vma, call_dl_resolve)) {
6630+ up_write(&current->mm->mmap_sem);
6631+ kmem_cache_free(vm_area_cachep, vma);
6632+ return 1;
6633+ }
6634+
6635+ current->mm->call_dl_resolve = call_dl_resolve;
6636+ up_write(&current->mm->mmap_sem);
6637+
6638+emulate:
6639+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6640+ regs->pc = call_dl_resolve;
6641+ regs->npc = addr+4;
6642+ return 3;
6643+ }
6644+#endif
6645+
6646+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6647+ if ((save & 0xFFC00000U) == 0x05000000U &&
6648+ (call & 0xFFFFE000U) == 0x85C0A000U &&
6649+ nop == 0x01000000U)
6650+ {
6651+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6652+ regs->u_regs[UREG_G2] = addr + 4;
6653+ addr = (save & 0x003FFFFFU) << 10;
6654+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6655+ regs->pc = addr;
6656+ regs->npc = addr+4;
6657+ return 3;
6658+ }
6659+ }
6660+ } while (0);
6661+
6662+ do { /* PaX: unpatched PLT emulation step 2 */
6663+ unsigned int save, call, nop;
6664+
6665+ err = get_user(save, (unsigned int *)(regs->pc-4));
6666+ err |= get_user(call, (unsigned int *)regs->pc);
6667+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
6668+ if (err)
6669+ break;
6670+
6671+ if (save == 0x9DE3BFA8U &&
6672+ (call & 0xC0000000U) == 0x40000000U &&
6673+ nop == 0x01000000U)
6674+ {
6675+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
6676+
6677+ regs->u_regs[UREG_RETPC] = regs->pc;
6678+ regs->pc = dl_resolve;
6679+ regs->npc = dl_resolve+4;
6680+ return 3;
6681+ }
6682+ } while (0);
6683+#endif
6684+
6685+ return 1;
6686+}
6687+
6688+void pax_report_insns(void *pc, void *sp)
6689+{
6690+ unsigned long i;
6691+
6692+ printk(KERN_ERR "PAX: bytes at PC: ");
6693+ for (i = 0; i < 8; i++) {
6694+ unsigned int c;
6695+ if (get_user(c, (unsigned int *)pc+i))
6696+ printk(KERN_CONT "???????? ");
6697+ else
6698+ printk(KERN_CONT "%08x ", c);
6699+ }
6700+ printk("\n");
6701+}
6702+#endif
6703+
6704 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
6705 int text_fault)
6706 {
6707@@ -281,6 +546,24 @@ good_area:
6708 if(!(vma->vm_flags & VM_WRITE))
6709 goto bad_area;
6710 } else {
6711+
6712+#ifdef CONFIG_PAX_PAGEEXEC
6713+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
6714+ up_read(&mm->mmap_sem);
6715+ switch (pax_handle_fetch_fault(regs)) {
6716+
6717+#ifdef CONFIG_PAX_EMUPLT
6718+ case 2:
6719+ case 3:
6720+ return;
6721+#endif
6722+
6723+ }
6724+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
6725+ do_group_exit(SIGKILL);
6726+ }
6727+#endif
6728+
6729 /* Allow reads even for write-only mappings */
6730 if(!(vma->vm_flags & (VM_READ | VM_EXEC)))
6731 goto bad_area;
6732diff -urNp linux-2.6.39.1/arch/sparc/mm/fault_64.c linux-2.6.39.1/arch/sparc/mm/fault_64.c
6733--- linux-2.6.39.1/arch/sparc/mm/fault_64.c 2011-05-19 00:06:34.000000000 -0400
6734+++ linux-2.6.39.1/arch/sparc/mm/fault_64.c 2011-05-22 19:41:32.000000000 -0400
6735@@ -21,6 +21,9 @@
6736 #include <linux/kprobes.h>
6737 #include <linux/kdebug.h>
6738 #include <linux/percpu.h>
6739+#include <linux/slab.h>
6740+#include <linux/pagemap.h>
6741+#include <linux/compiler.h>
6742
6743 #include <asm/page.h>
6744 #include <asm/pgtable.h>
6745@@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(stru
6746 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
6747 regs->tpc);
6748 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
6749- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
6750+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
6751 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
6752 dump_stack();
6753 unhandled_fault(regs->tpc, current, regs);
6754@@ -272,6 +275,457 @@ static void noinline __kprobes bogus_32b
6755 show_regs(regs);
6756 }
6757
6758+#ifdef CONFIG_PAX_PAGEEXEC
6759+#ifdef CONFIG_PAX_DLRESOLVE
6760+static void pax_emuplt_close(struct vm_area_struct *vma)
6761+{
6762+ vma->vm_mm->call_dl_resolve = 0UL;
6763+}
6764+
6765+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6766+{
6767+ unsigned int *kaddr;
6768+
6769+ vmf->page = alloc_page(GFP_HIGHUSER);
6770+ if (!vmf->page)
6771+ return VM_FAULT_OOM;
6772+
6773+ kaddr = kmap(vmf->page);
6774+ memset(kaddr, 0, PAGE_SIZE);
6775+ kaddr[0] = 0x9DE3BFA8U; /* save */
6776+ flush_dcache_page(vmf->page);
6777+ kunmap(vmf->page);
6778+ return VM_FAULT_MAJOR;
6779+}
6780+
6781+static const struct vm_operations_struct pax_vm_ops = {
6782+ .close = pax_emuplt_close,
6783+ .fault = pax_emuplt_fault
6784+};
6785+
6786+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6787+{
6788+ int ret;
6789+
6790+ INIT_LIST_HEAD(&vma->anon_vma_chain);
6791+ vma->vm_mm = current->mm;
6792+ vma->vm_start = addr;
6793+ vma->vm_end = addr + PAGE_SIZE;
6794+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6795+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6796+ vma->vm_ops = &pax_vm_ops;
6797+
6798+ ret = insert_vm_struct(current->mm, vma);
6799+ if (ret)
6800+ return ret;
6801+
6802+ ++current->mm->total_vm;
6803+ return 0;
6804+}
6805+#endif
6806+
6807+/*
6808+ * PaX: decide what to do with offenders (regs->tpc = fault address)
6809+ *
6810+ * returns 1 when task should be killed
6811+ * 2 when patched PLT trampoline was detected
6812+ * 3 when unpatched PLT trampoline was detected
6813+ */
6814+static int pax_handle_fetch_fault(struct pt_regs *regs)
6815+{
6816+
6817+#ifdef CONFIG_PAX_EMUPLT
6818+ int err;
6819+
6820+ do { /* PaX: patched PLT emulation #1 */
6821+ unsigned int sethi1, sethi2, jmpl;
6822+
6823+ err = get_user(sethi1, (unsigned int *)regs->tpc);
6824+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
6825+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
6826+
6827+ if (err)
6828+ break;
6829+
6830+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6831+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
6832+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
6833+ {
6834+ unsigned long addr;
6835+
6836+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6837+ addr = regs->u_regs[UREG_G1];
6838+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6839+
6840+ if (test_thread_flag(TIF_32BIT))
6841+ addr &= 0xFFFFFFFFUL;
6842+
6843+ regs->tpc = addr;
6844+ regs->tnpc = addr+4;
6845+ return 2;
6846+ }
6847+ } while (0);
6848+
6849+ { /* PaX: patched PLT emulation #2 */
6850+ unsigned int ba;
6851+
6852+ err = get_user(ba, (unsigned int *)regs->tpc);
6853+
6854+ if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
6855+ unsigned long addr;
6856+
6857+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6858+
6859+ if (test_thread_flag(TIF_32BIT))
6860+ addr &= 0xFFFFFFFFUL;
6861+
6862+ regs->tpc = addr;
6863+ regs->tnpc = addr+4;
6864+ return 2;
6865+ }
6866+ }
6867+
6868+ do { /* PaX: patched PLT emulation #3 */
6869+ unsigned int sethi, jmpl, nop;
6870+
6871+ err = get_user(sethi, (unsigned int *)regs->tpc);
6872+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+4));
6873+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6874+
6875+ if (err)
6876+ break;
6877+
6878+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6879+ (jmpl & 0xFFFFE000U) == 0x81C06000U &&
6880+ nop == 0x01000000U)
6881+ {
6882+ unsigned long addr;
6883+
6884+ addr = (sethi & 0x003FFFFFU) << 10;
6885+ regs->u_regs[UREG_G1] = addr;
6886+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6887+
6888+ if (test_thread_flag(TIF_32BIT))
6889+ addr &= 0xFFFFFFFFUL;
6890+
6891+ regs->tpc = addr;
6892+ regs->tnpc = addr+4;
6893+ return 2;
6894+ }
6895+ } while (0);
6896+
6897+ do { /* PaX: patched PLT emulation #4 */
6898+ unsigned int sethi, mov1, call, mov2;
6899+
6900+ err = get_user(sethi, (unsigned int *)regs->tpc);
6901+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
6902+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
6903+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
6904+
6905+ if (err)
6906+ break;
6907+
6908+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6909+ mov1 == 0x8210000FU &&
6910+ (call & 0xC0000000U) == 0x40000000U &&
6911+ mov2 == 0x9E100001U)
6912+ {
6913+ unsigned long addr;
6914+
6915+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
6916+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
6917+
6918+ if (test_thread_flag(TIF_32BIT))
6919+ addr &= 0xFFFFFFFFUL;
6920+
6921+ regs->tpc = addr;
6922+ regs->tnpc = addr+4;
6923+ return 2;
6924+ }
6925+ } while (0);
6926+
6927+ do { /* PaX: patched PLT emulation #5 */
6928+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
6929+
6930+ err = get_user(sethi, (unsigned int *)regs->tpc);
6931+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
6932+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
6933+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
6934+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
6935+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
6936+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
6937+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
6938+
6939+ if (err)
6940+ break;
6941+
6942+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6943+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
6944+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
6945+ (or1 & 0xFFFFE000U) == 0x82106000U &&
6946+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
6947+ sllx == 0x83287020U &&
6948+ jmpl == 0x81C04005U &&
6949+ nop == 0x01000000U)
6950+ {
6951+ unsigned long addr;
6952+
6953+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
6954+ regs->u_regs[UREG_G1] <<= 32;
6955+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
6956+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
6957+ regs->tpc = addr;
6958+ regs->tnpc = addr+4;
6959+ return 2;
6960+ }
6961+ } while (0);
6962+
6963+ do { /* PaX: patched PLT emulation #6 */
6964+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
6965+
6966+ err = get_user(sethi, (unsigned int *)regs->tpc);
6967+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
6968+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
6969+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
6970+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
6971+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
6972+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
6973+
6974+ if (err)
6975+ break;
6976+
6977+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6978+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
6979+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
6980+ sllx == 0x83287020U &&
6981+ (or & 0xFFFFE000U) == 0x8A116000U &&
6982+ jmpl == 0x81C04005U &&
6983+ nop == 0x01000000U)
6984+ {
6985+ unsigned long addr;
6986+
6987+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
6988+ regs->u_regs[UREG_G1] <<= 32;
6989+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
6990+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
6991+ regs->tpc = addr;
6992+ regs->tnpc = addr+4;
6993+ return 2;
6994+ }
6995+ } while (0);
6996+
6997+ do { /* PaX: unpatched PLT emulation step 1 */
6998+ unsigned int sethi, ba, nop;
6999+
7000+ err = get_user(sethi, (unsigned int *)regs->tpc);
7001+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7002+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7003+
7004+ if (err)
7005+ break;
7006+
7007+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7008+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
7009+ nop == 0x01000000U)
7010+ {
7011+ unsigned long addr;
7012+ unsigned int save, call;
7013+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
7014+
7015+ if ((ba & 0xFFC00000U) == 0x30800000U)
7016+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
7017+ else
7018+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7019+
7020+ if (test_thread_flag(TIF_32BIT))
7021+ addr &= 0xFFFFFFFFUL;
7022+
7023+ err = get_user(save, (unsigned int *)addr);
7024+ err |= get_user(call, (unsigned int *)(addr+4));
7025+ err |= get_user(nop, (unsigned int *)(addr+8));
7026+ if (err)
7027+ break;
7028+
7029+#ifdef CONFIG_PAX_DLRESOLVE
7030+ if (save == 0x9DE3BFA8U &&
7031+ (call & 0xC0000000U) == 0x40000000U &&
7032+ nop == 0x01000000U)
7033+ {
7034+ struct vm_area_struct *vma;
7035+ unsigned long call_dl_resolve;
7036+
7037+ down_read(&current->mm->mmap_sem);
7038+ call_dl_resolve = current->mm->call_dl_resolve;
7039+ up_read(&current->mm->mmap_sem);
7040+ if (likely(call_dl_resolve))
7041+ goto emulate;
7042+
7043+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
7044+
7045+ down_write(&current->mm->mmap_sem);
7046+ if (current->mm->call_dl_resolve) {
7047+ call_dl_resolve = current->mm->call_dl_resolve;
7048+ up_write(&current->mm->mmap_sem);
7049+ if (vma)
7050+ kmem_cache_free(vm_area_cachep, vma);
7051+ goto emulate;
7052+ }
7053+
7054+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
7055+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
7056+ up_write(&current->mm->mmap_sem);
7057+ if (vma)
7058+ kmem_cache_free(vm_area_cachep, vma);
7059+ return 1;
7060+ }
7061+
7062+ if (pax_insert_vma(vma, call_dl_resolve)) {
7063+ up_write(&current->mm->mmap_sem);
7064+ kmem_cache_free(vm_area_cachep, vma);
7065+ return 1;
7066+ }
7067+
7068+ current->mm->call_dl_resolve = call_dl_resolve;
7069+ up_write(&current->mm->mmap_sem);
7070+
7071+emulate:
7072+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7073+ regs->tpc = call_dl_resolve;
7074+ regs->tnpc = addr+4;
7075+ return 3;
7076+ }
7077+#endif
7078+
7079+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
7080+ if ((save & 0xFFC00000U) == 0x05000000U &&
7081+ (call & 0xFFFFE000U) == 0x85C0A000U &&
7082+ nop == 0x01000000U)
7083+ {
7084+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7085+ regs->u_regs[UREG_G2] = addr + 4;
7086+ addr = (save & 0x003FFFFFU) << 10;
7087+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7088+
7089+ if (test_thread_flag(TIF_32BIT))
7090+ addr &= 0xFFFFFFFFUL;
7091+
7092+ regs->tpc = addr;
7093+ regs->tnpc = addr+4;
7094+ return 3;
7095+ }
7096+
7097+ /* PaX: 64-bit PLT stub */
7098+ err = get_user(sethi1, (unsigned int *)addr);
7099+ err |= get_user(sethi2, (unsigned int *)(addr+4));
7100+ err |= get_user(or1, (unsigned int *)(addr+8));
7101+ err |= get_user(or2, (unsigned int *)(addr+12));
7102+ err |= get_user(sllx, (unsigned int *)(addr+16));
7103+ err |= get_user(add, (unsigned int *)(addr+20));
7104+ err |= get_user(jmpl, (unsigned int *)(addr+24));
7105+ err |= get_user(nop, (unsigned int *)(addr+28));
7106+ if (err)
7107+ break;
7108+
7109+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
7110+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7111+ (or1 & 0xFFFFE000U) == 0x88112000U &&
7112+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
7113+ sllx == 0x89293020U &&
7114+ add == 0x8A010005U &&
7115+ jmpl == 0x89C14000U &&
7116+ nop == 0x01000000U)
7117+ {
7118+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7119+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7120+ regs->u_regs[UREG_G4] <<= 32;
7121+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7122+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
7123+ regs->u_regs[UREG_G4] = addr + 24;
7124+ addr = regs->u_regs[UREG_G5];
7125+ regs->tpc = addr;
7126+ regs->tnpc = addr+4;
7127+ return 3;
7128+ }
7129+ }
7130+ } while (0);
7131+
7132+#ifdef CONFIG_PAX_DLRESOLVE
7133+ do { /* PaX: unpatched PLT emulation step 2 */
7134+ unsigned int save, call, nop;
7135+
7136+ err = get_user(save, (unsigned int *)(regs->tpc-4));
7137+ err |= get_user(call, (unsigned int *)regs->tpc);
7138+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
7139+ if (err)
7140+ break;
7141+
7142+ if (save == 0x9DE3BFA8U &&
7143+ (call & 0xC0000000U) == 0x40000000U &&
7144+ nop == 0x01000000U)
7145+ {
7146+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7147+
7148+ if (test_thread_flag(TIF_32BIT))
7149+ dl_resolve &= 0xFFFFFFFFUL;
7150+
7151+ regs->u_regs[UREG_RETPC] = regs->tpc;
7152+ regs->tpc = dl_resolve;
7153+ regs->tnpc = dl_resolve+4;
7154+ return 3;
7155+ }
7156+ } while (0);
7157+#endif
7158+
7159+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
7160+ unsigned int sethi, ba, nop;
7161+
7162+ err = get_user(sethi, (unsigned int *)regs->tpc);
7163+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7164+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7165+
7166+ if (err)
7167+ break;
7168+
7169+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7170+ (ba & 0xFFF00000U) == 0x30600000U &&
7171+ nop == 0x01000000U)
7172+ {
7173+ unsigned long addr;
7174+
7175+ addr = (sethi & 0x003FFFFFU) << 10;
7176+ regs->u_regs[UREG_G1] = addr;
7177+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7178+
7179+ if (test_thread_flag(TIF_32BIT))
7180+ addr &= 0xFFFFFFFFUL;
7181+
7182+ regs->tpc = addr;
7183+ regs->tnpc = addr+4;
7184+ return 2;
7185+ }
7186+ } while (0);
7187+
7188+#endif
7189+
7190+ return 1;
7191+}
7192+
7193+void pax_report_insns(void *pc, void *sp)
7194+{
7195+ unsigned long i;
7196+
7197+ printk(KERN_ERR "PAX: bytes at PC: ");
7198+ for (i = 0; i < 8; i++) {
7199+ unsigned int c;
7200+ if (get_user(c, (unsigned int *)pc+i))
7201+ printk(KERN_CONT "???????? ");
7202+ else
7203+ printk(KERN_CONT "%08x ", c);
7204+ }
7205+ printk("\n");
7206+}
7207+#endif
7208+
7209 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
7210 {
7211 struct mm_struct *mm = current->mm;
7212@@ -340,6 +794,29 @@ asmlinkage void __kprobes do_sparc64_fau
7213 if (!vma)
7214 goto bad_area;
7215
7216+#ifdef CONFIG_PAX_PAGEEXEC
7217+ /* PaX: detect ITLB misses on non-exec pages */
7218+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
7219+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
7220+ {
7221+ if (address != regs->tpc)
7222+ goto good_area;
7223+
7224+ up_read(&mm->mmap_sem);
7225+ switch (pax_handle_fetch_fault(regs)) {
7226+
7227+#ifdef CONFIG_PAX_EMUPLT
7228+ case 2:
7229+ case 3:
7230+ return;
7231+#endif
7232+
7233+ }
7234+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
7235+ do_group_exit(SIGKILL);
7236+ }
7237+#endif
7238+
7239 /* Pure DTLB misses do not tell us whether the fault causing
7240 * load/store/atomic was a write or not, it only says that there
7241 * was no match. So in such a case we (carefully) read the
7242diff -urNp linux-2.6.39.1/arch/sparc/mm/hugetlbpage.c linux-2.6.39.1/arch/sparc/mm/hugetlbpage.c
7243--- linux-2.6.39.1/arch/sparc/mm/hugetlbpage.c 2011-05-19 00:06:34.000000000 -0400
7244+++ linux-2.6.39.1/arch/sparc/mm/hugetlbpage.c 2011-05-22 19:36:30.000000000 -0400
7245@@ -68,7 +68,7 @@ full_search:
7246 }
7247 return -ENOMEM;
7248 }
7249- if (likely(!vma || addr + len <= vma->vm_start)) {
7250+ if (likely(check_heap_stack_gap(vma, addr, len))) {
7251 /*
7252 * Remember the place where we stopped the search:
7253 */
7254@@ -107,7 +107,7 @@ hugetlb_get_unmapped_area_topdown(struct
7255 /* make sure it can fit in the remaining address space */
7256 if (likely(addr > len)) {
7257 vma = find_vma(mm, addr-len);
7258- if (!vma || addr <= vma->vm_start) {
7259+ if (check_heap_stack_gap(vma, addr - len, len)) {
7260 /* remember the address as a hint for next time */
7261 return (mm->free_area_cache = addr-len);
7262 }
7263@@ -116,16 +116,17 @@ hugetlb_get_unmapped_area_topdown(struct
7264 if (unlikely(mm->mmap_base < len))
7265 goto bottomup;
7266
7267- addr = (mm->mmap_base-len) & HPAGE_MASK;
7268+ addr = mm->mmap_base - len;
7269
7270 do {
7271+ addr &= HPAGE_MASK;
7272 /*
7273 * Lookup failure means no vma is above this address,
7274 * else if new region fits below vma->vm_start,
7275 * return with success:
7276 */
7277 vma = find_vma(mm, addr);
7278- if (likely(!vma || addr+len <= vma->vm_start)) {
7279+ if (likely(check_heap_stack_gap(vma, addr, len))) {
7280 /* remember the address as a hint for next time */
7281 return (mm->free_area_cache = addr);
7282 }
7283@@ -135,8 +136,8 @@ hugetlb_get_unmapped_area_topdown(struct
7284 mm->cached_hole_size = vma->vm_start - addr;
7285
7286 /* try just below the current vma->vm_start */
7287- addr = (vma->vm_start-len) & HPAGE_MASK;
7288- } while (likely(len < vma->vm_start));
7289+ addr = skip_heap_stack_gap(vma, len);
7290+ } while (!IS_ERR_VALUE(addr));
7291
7292 bottomup:
7293 /*
7294@@ -182,8 +183,7 @@ hugetlb_get_unmapped_area(struct file *f
7295 if (addr) {
7296 addr = ALIGN(addr, HPAGE_SIZE);
7297 vma = find_vma(mm, addr);
7298- if (task_size - len >= addr &&
7299- (!vma || addr + len <= vma->vm_start))
7300+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
7301 return addr;
7302 }
7303 if (mm->get_unmapped_area == arch_get_unmapped_area)
7304diff -urNp linux-2.6.39.1/arch/sparc/mm/init_32.c linux-2.6.39.1/arch/sparc/mm/init_32.c
7305--- linux-2.6.39.1/arch/sparc/mm/init_32.c 2011-05-19 00:06:34.000000000 -0400
7306+++ linux-2.6.39.1/arch/sparc/mm/init_32.c 2011-05-22 19:36:30.000000000 -0400
7307@@ -318,6 +318,9 @@ extern void device_scan(void);
7308 pgprot_t PAGE_SHARED __read_mostly;
7309 EXPORT_SYMBOL(PAGE_SHARED);
7310
7311+pgprot_t PAGE_SHARED_NOEXEC __read_mostly;
7312+EXPORT_SYMBOL(PAGE_SHARED_NOEXEC);
7313+
7314 void __init paging_init(void)
7315 {
7316 switch(sparc_cpu_model) {
7317@@ -346,17 +349,17 @@ void __init paging_init(void)
7318
7319 /* Initialize the protection map with non-constant, MMU dependent values. */
7320 protection_map[0] = PAGE_NONE;
7321- protection_map[1] = PAGE_READONLY;
7322- protection_map[2] = PAGE_COPY;
7323- protection_map[3] = PAGE_COPY;
7324+ protection_map[1] = PAGE_READONLY_NOEXEC;
7325+ protection_map[2] = PAGE_COPY_NOEXEC;
7326+ protection_map[3] = PAGE_COPY_NOEXEC;
7327 protection_map[4] = PAGE_READONLY;
7328 protection_map[5] = PAGE_READONLY;
7329 protection_map[6] = PAGE_COPY;
7330 protection_map[7] = PAGE_COPY;
7331 protection_map[8] = PAGE_NONE;
7332- protection_map[9] = PAGE_READONLY;
7333- protection_map[10] = PAGE_SHARED;
7334- protection_map[11] = PAGE_SHARED;
7335+ protection_map[9] = PAGE_READONLY_NOEXEC;
7336+ protection_map[10] = PAGE_SHARED_NOEXEC;
7337+ protection_map[11] = PAGE_SHARED_NOEXEC;
7338 protection_map[12] = PAGE_READONLY;
7339 protection_map[13] = PAGE_READONLY;
7340 protection_map[14] = PAGE_SHARED;
7341diff -urNp linux-2.6.39.1/arch/sparc/mm/Makefile linux-2.6.39.1/arch/sparc/mm/Makefile
7342--- linux-2.6.39.1/arch/sparc/mm/Makefile 2011-05-19 00:06:34.000000000 -0400
7343+++ linux-2.6.39.1/arch/sparc/mm/Makefile 2011-05-22 19:36:30.000000000 -0400
7344@@ -2,7 +2,7 @@
7345 #
7346
7347 asflags-y := -ansi
7348-ccflags-y := -Werror
7349+#ccflags-y := -Werror
7350
7351 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o
7352 obj-y += fault_$(BITS).o
7353diff -urNp linux-2.6.39.1/arch/sparc/mm/srmmu.c linux-2.6.39.1/arch/sparc/mm/srmmu.c
7354--- linux-2.6.39.1/arch/sparc/mm/srmmu.c 2011-05-19 00:06:34.000000000 -0400
7355+++ linux-2.6.39.1/arch/sparc/mm/srmmu.c 2011-05-22 19:36:30.000000000 -0400
7356@@ -2200,6 +2200,13 @@ void __init ld_mmu_srmmu(void)
7357 PAGE_SHARED = pgprot_val(SRMMU_PAGE_SHARED);
7358 BTFIXUPSET_INT(page_copy, pgprot_val(SRMMU_PAGE_COPY));
7359 BTFIXUPSET_INT(page_readonly, pgprot_val(SRMMU_PAGE_RDONLY));
7360+
7361+#ifdef CONFIG_PAX_PAGEEXEC
7362+ PAGE_SHARED_NOEXEC = pgprot_val(SRMMU_PAGE_SHARED_NOEXEC);
7363+ BTFIXUPSET_INT(page_copy_noexec, pgprot_val(SRMMU_PAGE_COPY_NOEXEC));
7364+ BTFIXUPSET_INT(page_readonly_noexec, pgprot_val(SRMMU_PAGE_RDONLY_NOEXEC));
7365+#endif
7366+
7367 BTFIXUPSET_INT(page_kernel, pgprot_val(SRMMU_PAGE_KERNEL));
7368 page_kernel = pgprot_val(SRMMU_PAGE_KERNEL);
7369
7370diff -urNp linux-2.6.39.1/arch/tile/kernel/pci.c linux-2.6.39.1/arch/tile/kernel/pci.c
7371--- linux-2.6.39.1/arch/tile/kernel/pci.c 2011-05-19 00:06:34.000000000 -0400
7372+++ linux-2.6.39.1/arch/tile/kernel/pci.c 2011-05-22 19:36:30.000000000 -0400
7373@@ -60,7 +60,7 @@ int __write_once tile_plx_gen1;
7374 static struct pci_controller controllers[TILE_NUM_PCIE];
7375 static int num_controllers;
7376
7377-static struct pci_ops tile_cfg_ops;
7378+static const struct pci_ops tile_cfg_ops;
7379
7380
7381 /*
7382@@ -564,7 +564,7 @@ static int __devinit tile_cfg_write(stru
7383 }
7384
7385
7386-static struct pci_ops tile_cfg_ops = {
7387+static const struct pci_ops tile_cfg_ops = {
7388 .read = tile_cfg_read,
7389 .write = tile_cfg_write,
7390 };
7391diff -urNp linux-2.6.39.1/arch/um/include/asm/kmap_types.h linux-2.6.39.1/arch/um/include/asm/kmap_types.h
7392--- linux-2.6.39.1/arch/um/include/asm/kmap_types.h 2011-05-19 00:06:34.000000000 -0400
7393+++ linux-2.6.39.1/arch/um/include/asm/kmap_types.h 2011-05-22 19:36:30.000000000 -0400
7394@@ -23,6 +23,7 @@ enum km_type {
7395 KM_IRQ1,
7396 KM_SOFTIRQ0,
7397 KM_SOFTIRQ1,
7398+ KM_CLEARPAGE,
7399 KM_TYPE_NR
7400 };
7401
7402diff -urNp linux-2.6.39.1/arch/um/include/asm/page.h linux-2.6.39.1/arch/um/include/asm/page.h
7403--- linux-2.6.39.1/arch/um/include/asm/page.h 2011-05-19 00:06:34.000000000 -0400
7404+++ linux-2.6.39.1/arch/um/include/asm/page.h 2011-05-22 19:36:30.000000000 -0400
7405@@ -14,6 +14,9 @@
7406 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
7407 #define PAGE_MASK (~(PAGE_SIZE-1))
7408
7409+#define ktla_ktva(addr) (addr)
7410+#define ktva_ktla(addr) (addr)
7411+
7412 #ifndef __ASSEMBLY__
7413
7414 struct page;
7415diff -urNp linux-2.6.39.1/arch/um/kernel/process.c linux-2.6.39.1/arch/um/kernel/process.c
7416--- linux-2.6.39.1/arch/um/kernel/process.c 2011-05-19 00:06:34.000000000 -0400
7417+++ linux-2.6.39.1/arch/um/kernel/process.c 2011-05-22 19:36:30.000000000 -0400
7418@@ -404,22 +404,6 @@ int singlestepping(void * t)
7419 return 2;
7420 }
7421
7422-/*
7423- * Only x86 and x86_64 have an arch_align_stack().
7424- * All other arches have "#define arch_align_stack(x) (x)"
7425- * in their asm/system.h
7426- * As this is included in UML from asm-um/system-generic.h,
7427- * we can use it to behave as the subarch does.
7428- */
7429-#ifndef arch_align_stack
7430-unsigned long arch_align_stack(unsigned long sp)
7431-{
7432- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7433- sp -= get_random_int() % 8192;
7434- return sp & ~0xf;
7435-}
7436-#endif
7437-
7438 unsigned long get_wchan(struct task_struct *p)
7439 {
7440 unsigned long stack_page, sp, ip;
7441diff -urNp linux-2.6.39.1/arch/um/sys-i386/syscalls.c linux-2.6.39.1/arch/um/sys-i386/syscalls.c
7442--- linux-2.6.39.1/arch/um/sys-i386/syscalls.c 2011-05-19 00:06:34.000000000 -0400
7443+++ linux-2.6.39.1/arch/um/sys-i386/syscalls.c 2011-05-22 19:36:30.000000000 -0400
7444@@ -11,6 +11,21 @@
7445 #include "asm/uaccess.h"
7446 #include "asm/unistd.h"
7447
7448+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
7449+{
7450+ unsigned long pax_task_size = TASK_SIZE;
7451+
7452+#ifdef CONFIG_PAX_SEGMEXEC
7453+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
7454+ pax_task_size = SEGMEXEC_TASK_SIZE;
7455+#endif
7456+
7457+ if (len > pax_task_size || addr > pax_task_size - len)
7458+ return -EINVAL;
7459+
7460+ return 0;
7461+}
7462+
7463 /*
7464 * The prototype on i386 is:
7465 *
7466diff -urNp linux-2.6.39.1/arch/unicore32/kernel/pci.c linux-2.6.39.1/arch/unicore32/kernel/pci.c
7467--- linux-2.6.39.1/arch/unicore32/kernel/pci.c 2011-05-19 00:06:34.000000000 -0400
7468+++ linux-2.6.39.1/arch/unicore32/kernel/pci.c 2011-05-22 19:36:30.000000000 -0400
7469@@ -66,7 +66,7 @@ puv3_write_config(struct pci_bus *bus, u
7470 return PCIBIOS_SUCCESSFUL;
7471 }
7472
7473-struct pci_ops pci_puv3_ops = {
7474+const struct pci_ops pci_puv3_ops = {
7475 .read = puv3_read_config,
7476 .write = puv3_write_config,
7477 };
7478diff -urNp linux-2.6.39.1/arch/x86/boot/bitops.h linux-2.6.39.1/arch/x86/boot/bitops.h
7479--- linux-2.6.39.1/arch/x86/boot/bitops.h 2011-05-19 00:06:34.000000000 -0400
7480+++ linux-2.6.39.1/arch/x86/boot/bitops.h 2011-05-22 19:36:30.000000000 -0400
7481@@ -26,7 +26,7 @@ static inline int variable_test_bit(int
7482 u8 v;
7483 const u32 *p = (const u32 *)addr;
7484
7485- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7486+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7487 return v;
7488 }
7489
7490@@ -37,7 +37,7 @@ static inline int variable_test_bit(int
7491
7492 static inline void set_bit(int nr, void *addr)
7493 {
7494- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7495+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7496 }
7497
7498 #endif /* BOOT_BITOPS_H */
7499diff -urNp linux-2.6.39.1/arch/x86/boot/boot.h linux-2.6.39.1/arch/x86/boot/boot.h
7500--- linux-2.6.39.1/arch/x86/boot/boot.h 2011-05-19 00:06:34.000000000 -0400
7501+++ linux-2.6.39.1/arch/x86/boot/boot.h 2011-05-22 19:36:30.000000000 -0400
7502@@ -85,7 +85,7 @@ static inline void io_delay(void)
7503 static inline u16 ds(void)
7504 {
7505 u16 seg;
7506- asm("movw %%ds,%0" : "=rm" (seg));
7507+ asm volatile("movw %%ds,%0" : "=rm" (seg));
7508 return seg;
7509 }
7510
7511@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t
7512 static inline int memcmp(const void *s1, const void *s2, size_t len)
7513 {
7514 u8 diff;
7515- asm("repe; cmpsb; setnz %0"
7516+ asm volatile("repe; cmpsb; setnz %0"
7517 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
7518 return diff;
7519 }
7520diff -urNp linux-2.6.39.1/arch/x86/boot/compressed/head_32.S linux-2.6.39.1/arch/x86/boot/compressed/head_32.S
7521--- linux-2.6.39.1/arch/x86/boot/compressed/head_32.S 2011-05-19 00:06:34.000000000 -0400
7522+++ linux-2.6.39.1/arch/x86/boot/compressed/head_32.S 2011-05-22 19:36:30.000000000 -0400
7523@@ -76,7 +76,7 @@ ENTRY(startup_32)
7524 notl %eax
7525 andl %eax, %ebx
7526 #else
7527- movl $LOAD_PHYSICAL_ADDR, %ebx
7528+ movl $____LOAD_PHYSICAL_ADDR, %ebx
7529 #endif
7530
7531 /* Target address to relocate to for decompression */
7532@@ -162,7 +162,7 @@ relocated:
7533 * and where it was actually loaded.
7534 */
7535 movl %ebp, %ebx
7536- subl $LOAD_PHYSICAL_ADDR, %ebx
7537+ subl $____LOAD_PHYSICAL_ADDR, %ebx
7538 jz 2f /* Nothing to be done if loaded at compiled addr. */
7539 /*
7540 * Process relocations.
7541@@ -170,8 +170,7 @@ relocated:
7542
7543 1: subl $4, %edi
7544 movl (%edi), %ecx
7545- testl %ecx, %ecx
7546- jz 2f
7547+ jecxz 2f
7548 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
7549 jmp 1b
7550 2:
7551diff -urNp linux-2.6.39.1/arch/x86/boot/compressed/head_64.S linux-2.6.39.1/arch/x86/boot/compressed/head_64.S
7552--- linux-2.6.39.1/arch/x86/boot/compressed/head_64.S 2011-05-19 00:06:34.000000000 -0400
7553+++ linux-2.6.39.1/arch/x86/boot/compressed/head_64.S 2011-05-22 19:36:30.000000000 -0400
7554@@ -91,7 +91,7 @@ ENTRY(startup_32)
7555 notl %eax
7556 andl %eax, %ebx
7557 #else
7558- movl $LOAD_PHYSICAL_ADDR, %ebx
7559+ movl $____LOAD_PHYSICAL_ADDR, %ebx
7560 #endif
7561
7562 /* Target address to relocate to for decompression */
7563@@ -233,7 +233,7 @@ ENTRY(startup_64)
7564 notq %rax
7565 andq %rax, %rbp
7566 #else
7567- movq $LOAD_PHYSICAL_ADDR, %rbp
7568+ movq $____LOAD_PHYSICAL_ADDR, %rbp
7569 #endif
7570
7571 /* Target address to relocate to for decompression */
7572diff -urNp linux-2.6.39.1/arch/x86/boot/compressed/misc.c linux-2.6.39.1/arch/x86/boot/compressed/misc.c
7573--- linux-2.6.39.1/arch/x86/boot/compressed/misc.c 2011-05-19 00:06:34.000000000 -0400
7574+++ linux-2.6.39.1/arch/x86/boot/compressed/misc.c 2011-05-22 19:36:30.000000000 -0400
7575@@ -310,7 +310,7 @@ static void parse_elf(void *output)
7576 case PT_LOAD:
7577 #ifdef CONFIG_RELOCATABLE
7578 dest = output;
7579- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
7580+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
7581 #else
7582 dest = (void *)(phdr->p_paddr);
7583 #endif
7584@@ -363,7 +363,7 @@ asmlinkage void decompress_kernel(void *
7585 error("Destination address too large");
7586 #endif
7587 #ifndef CONFIG_RELOCATABLE
7588- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
7589+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
7590 error("Wrong destination address");
7591 #endif
7592
7593diff -urNp linux-2.6.39.1/arch/x86/boot/compressed/relocs.c linux-2.6.39.1/arch/x86/boot/compressed/relocs.c
7594--- linux-2.6.39.1/arch/x86/boot/compressed/relocs.c 2011-05-19 00:06:34.000000000 -0400
7595+++ linux-2.6.39.1/arch/x86/boot/compressed/relocs.c 2011-05-22 19:36:30.000000000 -0400
7596@@ -13,8 +13,11 @@
7597
7598 static void die(char *fmt, ...);
7599
7600+#include "../../../../include/generated/autoconf.h"
7601+
7602 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
7603 static Elf32_Ehdr ehdr;
7604+static Elf32_Phdr *phdr;
7605 static unsigned long reloc_count, reloc_idx;
7606 static unsigned long *relocs;
7607
7608@@ -270,9 +273,39 @@ static void read_ehdr(FILE *fp)
7609 }
7610 }
7611
7612+static void read_phdrs(FILE *fp)
7613+{
7614+ unsigned int i;
7615+
7616+ phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
7617+ if (!phdr) {
7618+ die("Unable to allocate %d program headers\n",
7619+ ehdr.e_phnum);
7620+ }
7621+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
7622+ die("Seek to %d failed: %s\n",
7623+ ehdr.e_phoff, strerror(errno));
7624+ }
7625+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
7626+ die("Cannot read ELF program headers: %s\n",
7627+ strerror(errno));
7628+ }
7629+ for(i = 0; i < ehdr.e_phnum; i++) {
7630+ phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
7631+ phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
7632+ phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
7633+ phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
7634+ phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
7635+ phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
7636+ phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
7637+ phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
7638+ }
7639+
7640+}
7641+
7642 static void read_shdrs(FILE *fp)
7643 {
7644- int i;
7645+ unsigned int i;
7646 Elf32_Shdr shdr;
7647
7648 secs = calloc(ehdr.e_shnum, sizeof(struct section));
7649@@ -307,7 +340,7 @@ static void read_shdrs(FILE *fp)
7650
7651 static void read_strtabs(FILE *fp)
7652 {
7653- int i;
7654+ unsigned int i;
7655 for (i = 0; i < ehdr.e_shnum; i++) {
7656 struct section *sec = &secs[i];
7657 if (sec->shdr.sh_type != SHT_STRTAB) {
7658@@ -332,7 +365,7 @@ static void read_strtabs(FILE *fp)
7659
7660 static void read_symtabs(FILE *fp)
7661 {
7662- int i,j;
7663+ unsigned int i,j;
7664 for (i = 0; i < ehdr.e_shnum; i++) {
7665 struct section *sec = &secs[i];
7666 if (sec->shdr.sh_type != SHT_SYMTAB) {
7667@@ -365,7 +398,9 @@ static void read_symtabs(FILE *fp)
7668
7669 static void read_relocs(FILE *fp)
7670 {
7671- int i,j;
7672+ unsigned int i,j;
7673+ uint32_t base;
7674+
7675 for (i = 0; i < ehdr.e_shnum; i++) {
7676 struct section *sec = &secs[i];
7677 if (sec->shdr.sh_type != SHT_REL) {
7678@@ -385,9 +420,18 @@ static void read_relocs(FILE *fp)
7679 die("Cannot read symbol table: %s\n",
7680 strerror(errno));
7681 }
7682+ base = 0;
7683+ for (j = 0; j < ehdr.e_phnum; j++) {
7684+ if (phdr[j].p_type != PT_LOAD )
7685+ continue;
7686+ 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)
7687+ continue;
7688+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
7689+ break;
7690+ }
7691 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
7692 Elf32_Rel *rel = &sec->reltab[j];
7693- rel->r_offset = elf32_to_cpu(rel->r_offset);
7694+ rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
7695 rel->r_info = elf32_to_cpu(rel->r_info);
7696 }
7697 }
7698@@ -396,14 +440,14 @@ static void read_relocs(FILE *fp)
7699
7700 static void print_absolute_symbols(void)
7701 {
7702- int i;
7703+ unsigned int i;
7704 printf("Absolute symbols\n");
7705 printf(" Num: Value Size Type Bind Visibility Name\n");
7706 for (i = 0; i < ehdr.e_shnum; i++) {
7707 struct section *sec = &secs[i];
7708 char *sym_strtab;
7709 Elf32_Sym *sh_symtab;
7710- int j;
7711+ unsigned int j;
7712
7713 if (sec->shdr.sh_type != SHT_SYMTAB) {
7714 continue;
7715@@ -431,14 +475,14 @@ static void print_absolute_symbols(void)
7716
7717 static void print_absolute_relocs(void)
7718 {
7719- int i, printed = 0;
7720+ unsigned int i, printed = 0;
7721
7722 for (i = 0; i < ehdr.e_shnum; i++) {
7723 struct section *sec = &secs[i];
7724 struct section *sec_applies, *sec_symtab;
7725 char *sym_strtab;
7726 Elf32_Sym *sh_symtab;
7727- int j;
7728+ unsigned int j;
7729 if (sec->shdr.sh_type != SHT_REL) {
7730 continue;
7731 }
7732@@ -499,13 +543,13 @@ static void print_absolute_relocs(void)
7733
7734 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym))
7735 {
7736- int i;
7737+ unsigned int i;
7738 /* Walk through the relocations */
7739 for (i = 0; i < ehdr.e_shnum; i++) {
7740 char *sym_strtab;
7741 Elf32_Sym *sh_symtab;
7742 struct section *sec_applies, *sec_symtab;
7743- int j;
7744+ unsigned int j;
7745 struct section *sec = &secs[i];
7746
7747 if (sec->shdr.sh_type != SHT_REL) {
7748@@ -530,6 +574,22 @@ static void walk_relocs(void (*visit)(El
7749 !is_rel_reloc(sym_name(sym_strtab, sym))) {
7750 continue;
7751 }
7752+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
7753+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
7754+ continue;
7755+
7756+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
7757+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
7758+ if (!strcmp(sec_name(sym->st_shndx), ".module.text") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
7759+ continue;
7760+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
7761+ continue;
7762+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
7763+ continue;
7764+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
7765+ continue;
7766+#endif
7767+
7768 switch (r_type) {
7769 case R_386_NONE:
7770 case R_386_PC32:
7771@@ -571,7 +631,7 @@ static int cmp_relocs(const void *va, co
7772
7773 static void emit_relocs(int as_text)
7774 {
7775- int i;
7776+ unsigned int i;
7777 /* Count how many relocations I have and allocate space for them. */
7778 reloc_count = 0;
7779 walk_relocs(count_reloc);
7780@@ -665,6 +725,7 @@ int main(int argc, char **argv)
7781 fname, strerror(errno));
7782 }
7783 read_ehdr(fp);
7784+ read_phdrs(fp);
7785 read_shdrs(fp);
7786 read_strtabs(fp);
7787 read_symtabs(fp);
7788diff -urNp linux-2.6.39.1/arch/x86/boot/cpucheck.c linux-2.6.39.1/arch/x86/boot/cpucheck.c
7789--- linux-2.6.39.1/arch/x86/boot/cpucheck.c 2011-05-19 00:06:34.000000000 -0400
7790+++ linux-2.6.39.1/arch/x86/boot/cpucheck.c 2011-05-22 19:36:30.000000000 -0400
7791@@ -74,7 +74,7 @@ static int has_fpu(void)
7792 u16 fcw = -1, fsw = -1;
7793 u32 cr0;
7794
7795- asm("movl %%cr0,%0" : "=r" (cr0));
7796+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
7797 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
7798 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
7799 asm volatile("movl %0,%%cr0" : : "r" (cr0));
7800@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
7801 {
7802 u32 f0, f1;
7803
7804- asm("pushfl ; "
7805+ asm volatile("pushfl ; "
7806 "pushfl ; "
7807 "popl %0 ; "
7808 "movl %0,%1 ; "
7809@@ -115,7 +115,7 @@ static void get_flags(void)
7810 set_bit(X86_FEATURE_FPU, cpu.flags);
7811
7812 if (has_eflag(X86_EFLAGS_ID)) {
7813- asm("cpuid"
7814+ asm volatile("cpuid"
7815 : "=a" (max_intel_level),
7816 "=b" (cpu_vendor[0]),
7817 "=d" (cpu_vendor[1]),
7818@@ -124,7 +124,7 @@ static void get_flags(void)
7819
7820 if (max_intel_level >= 0x00000001 &&
7821 max_intel_level <= 0x0000ffff) {
7822- asm("cpuid"
7823+ asm volatile("cpuid"
7824 : "=a" (tfms),
7825 "=c" (cpu.flags[4]),
7826 "=d" (cpu.flags[0])
7827@@ -136,7 +136,7 @@ static void get_flags(void)
7828 cpu.model += ((tfms >> 16) & 0xf) << 4;
7829 }
7830
7831- asm("cpuid"
7832+ asm volatile("cpuid"
7833 : "=a" (max_amd_level)
7834 : "a" (0x80000000)
7835 : "ebx", "ecx", "edx");
7836@@ -144,7 +144,7 @@ static void get_flags(void)
7837 if (max_amd_level >= 0x80000001 &&
7838 max_amd_level <= 0x8000ffff) {
7839 u32 eax = 0x80000001;
7840- asm("cpuid"
7841+ asm volatile("cpuid"
7842 : "+a" (eax),
7843 "=c" (cpu.flags[6]),
7844 "=d" (cpu.flags[1])
7845@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *r
7846 u32 ecx = MSR_K7_HWCR;
7847 u32 eax, edx;
7848
7849- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7850+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7851 eax &= ~(1 << 15);
7852- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7853+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7854
7855 get_flags(); /* Make sure it really did something */
7856 err = check_flags();
7857@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *r
7858 u32 ecx = MSR_VIA_FCR;
7859 u32 eax, edx;
7860
7861- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7862+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7863 eax |= (1<<1)|(1<<7);
7864- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7865+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7866
7867 set_bit(X86_FEATURE_CX8, cpu.flags);
7868 err = check_flags();
7869@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *r
7870 u32 eax, edx;
7871 u32 level = 1;
7872
7873- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7874- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7875- asm("cpuid"
7876+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7877+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7878+ asm volatile("cpuid"
7879 : "+a" (level), "=d" (cpu.flags[0])
7880 : : "ecx", "ebx");
7881- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7882+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7883
7884 err = check_flags();
7885 }
7886diff -urNp linux-2.6.39.1/arch/x86/boot/header.S linux-2.6.39.1/arch/x86/boot/header.S
7887--- linux-2.6.39.1/arch/x86/boot/header.S 2011-05-19 00:06:34.000000000 -0400
7888+++ linux-2.6.39.1/arch/x86/boot/header.S 2011-05-22 19:36:30.000000000 -0400
7889@@ -224,7 +224,7 @@ setup_data: .quad 0 # 64-bit physical
7890 # single linked list of
7891 # struct setup_data
7892
7893-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
7894+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
7895
7896 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
7897 #define VO_INIT_SIZE (VO__end - VO__text)
7898diff -urNp linux-2.6.39.1/arch/x86/boot/memory.c linux-2.6.39.1/arch/x86/boot/memory.c
7899--- linux-2.6.39.1/arch/x86/boot/memory.c 2011-05-19 00:06:34.000000000 -0400
7900+++ linux-2.6.39.1/arch/x86/boot/memory.c 2011-05-22 19:36:30.000000000 -0400
7901@@ -19,7 +19,7 @@
7902
7903 static int detect_memory_e820(void)
7904 {
7905- int count = 0;
7906+ unsigned int count = 0;
7907 struct biosregs ireg, oreg;
7908 struct e820entry *desc = boot_params.e820_map;
7909 static struct e820entry buf; /* static so it is zeroed */
7910diff -urNp linux-2.6.39.1/arch/x86/boot/video.c linux-2.6.39.1/arch/x86/boot/video.c
7911--- linux-2.6.39.1/arch/x86/boot/video.c 2011-05-19 00:06:34.000000000 -0400
7912+++ linux-2.6.39.1/arch/x86/boot/video.c 2011-05-22 19:36:30.000000000 -0400
7913@@ -96,7 +96,7 @@ static void store_mode_params(void)
7914 static unsigned int get_entry(void)
7915 {
7916 char entry_buf[4];
7917- int i, len = 0;
7918+ unsigned int i, len = 0;
7919 int key;
7920 unsigned int v;
7921
7922diff -urNp linux-2.6.39.1/arch/x86/boot/video-vesa.c linux-2.6.39.1/arch/x86/boot/video-vesa.c
7923--- linux-2.6.39.1/arch/x86/boot/video-vesa.c 2011-05-19 00:06:34.000000000 -0400
7924+++ linux-2.6.39.1/arch/x86/boot/video-vesa.c 2011-05-22 19:36:30.000000000 -0400
7925@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
7926
7927 boot_params.screen_info.vesapm_seg = oreg.es;
7928 boot_params.screen_info.vesapm_off = oreg.di;
7929+ boot_params.screen_info.vesapm_size = oreg.cx;
7930 }
7931
7932 /*
7933diff -urNp linux-2.6.39.1/arch/x86/ia32/ia32_aout.c linux-2.6.39.1/arch/x86/ia32/ia32_aout.c
7934--- linux-2.6.39.1/arch/x86/ia32/ia32_aout.c 2011-05-19 00:06:34.000000000 -0400
7935+++ linux-2.6.39.1/arch/x86/ia32/ia32_aout.c 2011-05-22 19:41:32.000000000 -0400
7936@@ -162,6 +162,8 @@ static int aout_core_dump(long signr, st
7937 unsigned long dump_start, dump_size;
7938 struct user32 dump;
7939
7940+ memset(&dump, 0, sizeof(dump));
7941+
7942 fs = get_fs();
7943 set_fs(KERNEL_DS);
7944 has_dumped = 1;
7945diff -urNp linux-2.6.39.1/arch/x86/ia32/ia32entry.S linux-2.6.39.1/arch/x86/ia32/ia32entry.S
7946--- linux-2.6.39.1/arch/x86/ia32/ia32entry.S 2011-05-19 00:06:34.000000000 -0400
7947+++ linux-2.6.39.1/arch/x86/ia32/ia32entry.S 2011-05-23 17:16:01.000000000 -0400
7948@@ -13,6 +13,7 @@
7949 #include <asm/thread_info.h>
7950 #include <asm/segment.h>
7951 #include <asm/irqflags.h>
7952+#include <asm/pgtable.h>
7953 #include <linux/linkage.h>
7954
7955 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
7956@@ -95,6 +96,32 @@ ENTRY(native_irq_enable_sysexit)
7957 ENDPROC(native_irq_enable_sysexit)
7958 #endif
7959
7960+ .macro pax_enter_kernel_user
7961+#ifdef CONFIG_PAX_MEMORY_UDEREF
7962+ call pax_enter_kernel_user
7963+#endif
7964+ .endm
7965+
7966+ .macro pax_exit_kernel_user
7967+#ifdef CONFIG_PAX_MEMORY_UDEREF
7968+ call pax_exit_kernel_user
7969+#endif
7970+#ifdef CONFIG_PAX_RANDKSTACK
7971+ pushq %rax
7972+ call pax_randomize_kstack
7973+ popq %rax
7974+#endif
7975+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
7976+ call pax_erase_kstack
7977+#endif
7978+ .endm
7979+
7980+ .macro pax_erase_kstack
7981+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
7982+ call pax_erase_kstack
7983+#endif
7984+ .endm
7985+
7986 /*
7987 * 32bit SYSENTER instruction entry.
7988 *
7989@@ -121,7 +148,7 @@ ENTRY(ia32_sysenter_target)
7990 CFI_REGISTER rsp,rbp
7991 SWAPGS_UNSAFE_STACK
7992 movq PER_CPU_VAR(kernel_stack), %rsp
7993- addq $(KERNEL_STACK_OFFSET),%rsp
7994+ pax_enter_kernel_user
7995 /*
7996 * No need to follow this irqs on/off section: the syscall
7997 * disabled irqs, here we enable it straight after entry:
7998@@ -134,7 +161,8 @@ ENTRY(ia32_sysenter_target)
7999 CFI_REL_OFFSET rsp,0
8000 pushfq_cfi
8001 /*CFI_REL_OFFSET rflags,0*/
8002- movl 8*3-THREAD_SIZE+TI_sysenter_return(%rsp), %r10d
8003+ GET_THREAD_INFO(%r10)
8004+ movl TI_sysenter_return(%r10), %r10d
8005 CFI_REGISTER rip,r10
8006 pushq_cfi $__USER32_CS
8007 /*CFI_REL_OFFSET cs,0*/
8008@@ -146,6 +174,12 @@ ENTRY(ia32_sysenter_target)
8009 SAVE_ARGS 0,0,1
8010 /* no need to do an access_ok check here because rbp has been
8011 32bit zero extended */
8012+
8013+#ifdef CONFIG_PAX_MEMORY_UDEREF
8014+ mov $PAX_USER_SHADOW_BASE,%r10
8015+ add %r10,%rbp
8016+#endif
8017+
8018 1: movl (%rbp),%ebp
8019 .section __ex_table,"a"
8020 .quad 1b,ia32_badarg
8021@@ -168,6 +202,7 @@ sysenter_dispatch:
8022 testl $_TIF_ALLWORK_MASK,TI_flags(%r10)
8023 jnz sysexit_audit
8024 sysexit_from_sys_call:
8025+ pax_exit_kernel_user
8026 andl $~TS_COMPAT,TI_status(%r10)
8027 /* clear IF, that popfq doesn't enable interrupts early */
8028 andl $~0x200,EFLAGS-R11(%rsp)
8029@@ -194,6 +229,9 @@ sysexit_from_sys_call:
8030 movl %eax,%esi /* 2nd arg: syscall number */
8031 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
8032 call audit_syscall_entry
8033+
8034+ pax_erase_kstack
8035+
8036 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
8037 cmpq $(IA32_NR_syscalls-1),%rax
8038 ja ia32_badsys
8039@@ -246,6 +284,9 @@ sysenter_tracesys:
8040 movq $-ENOSYS,RAX(%rsp)/* ptrace can change this for a bad syscall */
8041 movq %rsp,%rdi /* &pt_regs -> arg1 */
8042 call syscall_trace_enter
8043+
8044+ pax_erase_kstack
8045+
8046 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8047 RESTORE_REST
8048 cmpq $(IA32_NR_syscalls-1),%rax
8049@@ -277,19 +318,24 @@ ENDPROC(ia32_sysenter_target)
8050 ENTRY(ia32_cstar_target)
8051 CFI_STARTPROC32 simple
8052 CFI_SIGNAL_FRAME
8053- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
8054+ CFI_DEF_CFA rsp,0
8055 CFI_REGISTER rip,rcx
8056 /*CFI_REGISTER rflags,r11*/
8057 SWAPGS_UNSAFE_STACK
8058 movl %esp,%r8d
8059 CFI_REGISTER rsp,r8
8060 movq PER_CPU_VAR(kernel_stack),%rsp
8061+
8062+#ifdef CONFIG_PAX_MEMORY_UDEREF
8063+ pax_enter_kernel_user
8064+#endif
8065+
8066 /*
8067 * No need to follow this irqs on/off section: the syscall
8068 * disabled irqs and here we enable it straight after entry:
8069 */
8070 ENABLE_INTERRUPTS(CLBR_NONE)
8071- SAVE_ARGS 8,1,1
8072+ SAVE_ARGS 8*6,1,1
8073 movl %eax,%eax /* zero extension */
8074 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
8075 movq %rcx,RIP-ARGOFFSET(%rsp)
8076@@ -305,6 +351,12 @@ ENTRY(ia32_cstar_target)
8077 /* no need to do an access_ok check here because r8 has been
8078 32bit zero extended */
8079 /* hardware stack frame is complete now */
8080+
8081+#ifdef CONFIG_PAX_MEMORY_UDEREF
8082+ mov $PAX_USER_SHADOW_BASE,%r10
8083+ add %r10,%r8
8084+#endif
8085+
8086 1: movl (%r8),%r9d
8087 .section __ex_table,"a"
8088 .quad 1b,ia32_badarg
8089@@ -327,6 +379,7 @@ cstar_dispatch:
8090 testl $_TIF_ALLWORK_MASK,TI_flags(%r10)
8091 jnz sysretl_audit
8092 sysretl_from_sys_call:
8093+ pax_exit_kernel_user
8094 andl $~TS_COMPAT,TI_status(%r10)
8095 RESTORE_ARGS 1,-ARG_SKIP,1,1,1
8096 movl RIP-ARGOFFSET(%rsp),%ecx
8097@@ -364,6 +417,9 @@ cstar_tracesys:
8098 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8099 movq %rsp,%rdi /* &pt_regs -> arg1 */
8100 call syscall_trace_enter
8101+
8102+ pax_erase_kstack
8103+
8104 LOAD_ARGS32 ARGOFFSET, 1 /* reload args from stack in case ptrace changed it */
8105 RESTORE_REST
8106 xchgl %ebp,%r9d
8107@@ -409,6 +465,7 @@ ENTRY(ia32_syscall)
8108 CFI_REL_OFFSET rip,RIP-RIP
8109 PARAVIRT_ADJUST_EXCEPTION_FRAME
8110 SWAPGS
8111+ pax_enter_kernel_user
8112 /*
8113 * No need to follow this irqs on/off section: the syscall
8114 * disabled irqs and here we enable it straight after entry:
8115@@ -441,6 +498,9 @@ ia32_tracesys:
8116 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8117 movq %rsp,%rdi /* &pt_regs -> arg1 */
8118 call syscall_trace_enter
8119+
8120+ pax_erase_kstack
8121+
8122 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8123 RESTORE_REST
8124 cmpq $(IA32_NR_syscalls-1),%rax
8125diff -urNp linux-2.6.39.1/arch/x86/ia32/ia32_signal.c linux-2.6.39.1/arch/x86/ia32/ia32_signal.c
8126--- linux-2.6.39.1/arch/x86/ia32/ia32_signal.c 2011-05-19 00:06:34.000000000 -0400
8127+++ linux-2.6.39.1/arch/x86/ia32/ia32_signal.c 2011-05-22 19:36:30.000000000 -0400
8128@@ -403,7 +403,7 @@ static void __user *get_sigframe(struct
8129 sp -= frame_size;
8130 /* Align the stack pointer according to the i386 ABI,
8131 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
8132- sp = ((sp + 4) & -16ul) - 4;
8133+ sp = ((sp - 12) & -16ul) - 4;
8134 return (void __user *) sp;
8135 }
8136
8137@@ -461,7 +461,7 @@ int ia32_setup_frame(int sig, struct k_s
8138 * These are actually not used anymore, but left because some
8139 * gdb versions depend on them as a marker.
8140 */
8141- put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8142+ put_user_ex(*((const u64 *)&code), (u64 *)frame->retcode);
8143 } put_user_catch(err);
8144
8145 if (err)
8146@@ -503,7 +503,7 @@ int ia32_setup_rt_frame(int sig, struct
8147 0xb8,
8148 __NR_ia32_rt_sigreturn,
8149 0x80cd,
8150- 0,
8151+ 0
8152 };
8153
8154 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
8155@@ -533,16 +533,18 @@ int ia32_setup_rt_frame(int sig, struct
8156
8157 if (ka->sa.sa_flags & SA_RESTORER)
8158 restorer = ka->sa.sa_restorer;
8159+ else if (current->mm->context.vdso)
8160+ /* Return stub is in 32bit vsyscall page */
8161+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
8162 else
8163- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
8164- rt_sigreturn);
8165+ restorer = &frame->retcode;
8166 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
8167
8168 /*
8169 * Not actually used anymore, but left because some gdb
8170 * versions need it.
8171 */
8172- put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8173+ put_user_ex(*((const u64 *)&code), (u64 *)frame->retcode);
8174 } put_user_catch(err);
8175
8176 if (err)
8177diff -urNp linux-2.6.39.1/arch/x86/include/asm/alternative.h linux-2.6.39.1/arch/x86/include/asm/alternative.h
8178--- linux-2.6.39.1/arch/x86/include/asm/alternative.h 2011-05-19 00:06:34.000000000 -0400
8179+++ linux-2.6.39.1/arch/x86/include/asm/alternative.h 2011-05-22 19:36:30.000000000 -0400
8180@@ -94,7 +94,7 @@ static inline int alternatives_text_rese
8181 ".section .discard,\"aw\",@progbits\n" \
8182 " .byte 0xff + (664f-663f) - (662b-661b)\n" /* rlen <= slen */ \
8183 ".previous\n" \
8184- ".section .altinstr_replacement, \"ax\"\n" \
8185+ ".section .altinstr_replacement, \"a\"\n" \
8186 "663:\n\t" newinstr "\n664:\n" /* replacement */ \
8187 ".previous"
8188
8189diff -urNp linux-2.6.39.1/arch/x86/include/asm/apm.h linux-2.6.39.1/arch/x86/include/asm/apm.h
8190--- linux-2.6.39.1/arch/x86/include/asm/apm.h 2011-05-19 00:06:34.000000000 -0400
8191+++ linux-2.6.39.1/arch/x86/include/asm/apm.h 2011-05-22 19:36:30.000000000 -0400
8192@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32
8193 __asm__ __volatile__(APM_DO_ZERO_SEGS
8194 "pushl %%edi\n\t"
8195 "pushl %%ebp\n\t"
8196- "lcall *%%cs:apm_bios_entry\n\t"
8197+ "lcall *%%ss:apm_bios_entry\n\t"
8198 "setc %%al\n\t"
8199 "popl %%ebp\n\t"
8200 "popl %%edi\n\t"
8201@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_as
8202 __asm__ __volatile__(APM_DO_ZERO_SEGS
8203 "pushl %%edi\n\t"
8204 "pushl %%ebp\n\t"
8205- "lcall *%%cs:apm_bios_entry\n\t"
8206+ "lcall *%%ss:apm_bios_entry\n\t"
8207 "setc %%bl\n\t"
8208 "popl %%ebp\n\t"
8209 "popl %%edi\n\t"
8210diff -urNp linux-2.6.39.1/arch/x86/include/asm/atomic64_32.h linux-2.6.39.1/arch/x86/include/asm/atomic64_32.h
8211--- linux-2.6.39.1/arch/x86/include/asm/atomic64_32.h 2011-05-19 00:06:34.000000000 -0400
8212+++ linux-2.6.39.1/arch/x86/include/asm/atomic64_32.h 2011-05-22 19:36:30.000000000 -0400
8213@@ -12,6 +12,14 @@ typedef struct {
8214 u64 __aligned(8) counter;
8215 } atomic64_t;
8216
8217+#ifdef CONFIG_PAX_REFCOUNT
8218+typedef struct {
8219+ u64 __aligned(8) counter;
8220+} atomic64_unchecked_t;
8221+#else
8222+typedef atomic64_t atomic64_unchecked_t;
8223+#endif
8224+
8225 #define ATOMIC64_INIT(val) { (val) }
8226
8227 #ifdef CONFIG_X86_CMPXCHG64
8228@@ -38,6 +46,21 @@ static inline long long atomic64_cmpxchg
8229 }
8230
8231 /**
8232+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
8233+ * @p: pointer to type atomic64_unchecked_t
8234+ * @o: expected value
8235+ * @n: new value
8236+ *
8237+ * Atomically sets @v to @n if it was equal to @o and returns
8238+ * the old value.
8239+ */
8240+
8241+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
8242+{
8243+ return cmpxchg64(&v->counter, o, n);
8244+}
8245+
8246+/**
8247 * atomic64_xchg - xchg atomic64 variable
8248 * @v: pointer to type atomic64_t
8249 * @n: value to assign
8250@@ -77,6 +100,24 @@ static inline void atomic64_set(atomic64
8251 }
8252
8253 /**
8254+ * atomic64_set_unchecked - set atomic64 variable
8255+ * @v: pointer to type atomic64_unchecked_t
8256+ * @n: value to assign
8257+ *
8258+ * Atomically sets the value of @v to @n.
8259+ */
8260+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
8261+{
8262+ unsigned high = (unsigned)(i >> 32);
8263+ unsigned low = (unsigned)i;
8264+ asm volatile(ATOMIC64_ALTERNATIVE(set)
8265+ : "+b" (low), "+c" (high)
8266+ : "S" (v)
8267+ : "eax", "edx", "memory"
8268+ );
8269+}
8270+
8271+/**
8272 * atomic64_read - read atomic64 variable
8273 * @v: pointer to type atomic64_t
8274 *
8275@@ -93,6 +134,22 @@ static inline long long atomic64_read(at
8276 }
8277
8278 /**
8279+ * atomic64_read_unchecked - read atomic64 variable
8280+ * @v: pointer to type atomic64_unchecked_t
8281+ *
8282+ * Atomically reads the value of @v and returns it.
8283+ */
8284+static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
8285+{
8286+ long long r;
8287+ asm volatile(ATOMIC64_ALTERNATIVE(read_unchecked)
8288+ : "=A" (r), "+c" (v)
8289+ : : "memory"
8290+ );
8291+ return r;
8292+ }
8293+
8294+/**
8295 * atomic64_add_return - add and return
8296 * @i: integer value to add
8297 * @v: pointer to type atomic64_t
8298@@ -108,6 +165,22 @@ static inline long long atomic64_add_ret
8299 return i;
8300 }
8301
8302+/**
8303+ * atomic64_add_return_unchecked - add and return
8304+ * @i: integer value to add
8305+ * @v: pointer to type atomic64_unchecked_t
8306+ *
8307+ * Atomically adds @i to @v and returns @i + *@v
8308+ */
8309+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
8310+{
8311+ asm volatile(ATOMIC64_ALTERNATIVE(add_return_unchecked)
8312+ : "+A" (i), "+c" (v)
8313+ : : "memory"
8314+ );
8315+ return i;
8316+}
8317+
8318 /*
8319 * Other variants with different arithmetic operators:
8320 */
8321@@ -131,6 +204,17 @@ static inline long long atomic64_inc_ret
8322 return a;
8323 }
8324
8325+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
8326+{
8327+ long long a;
8328+ asm volatile(ATOMIC64_ALTERNATIVE(inc_return_unchecked)
8329+ : "=A" (a)
8330+ : "S" (v)
8331+ : "memory", "ecx"
8332+ );
8333+ return a;
8334+}
8335+
8336 static inline long long atomic64_dec_return(atomic64_t *v)
8337 {
8338 long long a;
8339@@ -159,6 +243,22 @@ static inline long long atomic64_add(lon
8340 }
8341
8342 /**
8343+ * atomic64_add_unchecked - add integer to atomic64 variable
8344+ * @i: integer value to add
8345+ * @v: pointer to type atomic64_unchecked_t
8346+ *
8347+ * Atomically adds @i to @v.
8348+ */
8349+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
8350+{
8351+ asm volatile(ATOMIC64_ALTERNATIVE_(add_unchecked, add_return_unchecked)
8352+ : "+A" (i), "+c" (v)
8353+ : : "memory"
8354+ );
8355+ return i;
8356+}
8357+
8358+/**
8359 * atomic64_sub - subtract the atomic64 variable
8360 * @i: integer value to subtract
8361 * @v: pointer to type atomic64_t
8362diff -urNp linux-2.6.39.1/arch/x86/include/asm/atomic64_64.h linux-2.6.39.1/arch/x86/include/asm/atomic64_64.h
8363--- linux-2.6.39.1/arch/x86/include/asm/atomic64_64.h 2011-05-19 00:06:34.000000000 -0400
8364+++ linux-2.6.39.1/arch/x86/include/asm/atomic64_64.h 2011-05-22 19:36:30.000000000 -0400
8365@@ -18,7 +18,19 @@
8366 */
8367 static inline long atomic64_read(const atomic64_t *v)
8368 {
8369- return (*(volatile long *)&(v)->counter);
8370+ return (*(volatile const long *)&(v)->counter);
8371+}
8372+
8373+/**
8374+ * atomic64_read_unchecked - read atomic64 variable
8375+ * @v: pointer of type atomic64_unchecked_t
8376+ *
8377+ * Atomically reads the value of @v.
8378+ * Doesn't imply a read memory barrier.
8379+ */
8380+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
8381+{
8382+ return (*(volatile const long *)&(v)->counter);
8383 }
8384
8385 /**
8386@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64
8387 }
8388
8389 /**
8390+ * atomic64_set_unchecked - set atomic64 variable
8391+ * @v: pointer to type atomic64_unchecked_t
8392+ * @i: required value
8393+ *
8394+ * Atomically sets the value of @v to @i.
8395+ */
8396+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
8397+{
8398+ v->counter = i;
8399+}
8400+
8401+/**
8402 * atomic64_add - add integer to atomic64 variable
8403 * @i: integer value to add
8404 * @v: pointer to type atomic64_t
8405@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64
8406 */
8407 static inline void atomic64_add(long i, atomic64_t *v)
8408 {
8409+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
8410+
8411+#ifdef CONFIG_PAX_REFCOUNT
8412+ "jno 0f\n"
8413+ LOCK_PREFIX "subq %1,%0\n"
8414+ "int $4\n0:\n"
8415+ _ASM_EXTABLE(0b, 0b)
8416+#endif
8417+
8418+ : "=m" (v->counter)
8419+ : "er" (i), "m" (v->counter));
8420+}
8421+
8422+/**
8423+ * atomic64_add_unchecked - add integer to atomic64 variable
8424+ * @i: integer value to add
8425+ * @v: pointer to type atomic64_unchecked_t
8426+ *
8427+ * Atomically adds @i to @v.
8428+ */
8429+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
8430+{
8431 asm volatile(LOCK_PREFIX "addq %1,%0"
8432 : "=m" (v->counter)
8433 : "er" (i), "m" (v->counter));
8434@@ -56,7 +102,29 @@ static inline void atomic64_add(long i,
8435 */
8436 static inline void atomic64_sub(long i, atomic64_t *v)
8437 {
8438- asm volatile(LOCK_PREFIX "subq %1,%0"
8439+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
8440+
8441+#ifdef CONFIG_PAX_REFCOUNT
8442+ "jno 0f\n"
8443+ LOCK_PREFIX "addq %1,%0\n"
8444+ "int $4\n0:\n"
8445+ _ASM_EXTABLE(0b, 0b)
8446+#endif
8447+
8448+ : "=m" (v->counter)
8449+ : "er" (i), "m" (v->counter));
8450+}
8451+
8452+/**
8453+ * atomic64_sub_unchecked - subtract the atomic64 variable
8454+ * @i: integer value to subtract
8455+ * @v: pointer to type atomic64_unchecked_t
8456+ *
8457+ * Atomically subtracts @i from @v.
8458+ */
8459+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
8460+{
8461+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
8462 : "=m" (v->counter)
8463 : "er" (i), "m" (v->counter));
8464 }
8465@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(
8466 {
8467 unsigned char c;
8468
8469- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
8470+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
8471+
8472+#ifdef CONFIG_PAX_REFCOUNT
8473+ "jno 0f\n"
8474+ LOCK_PREFIX "addq %2,%0\n"
8475+ "int $4\n0:\n"
8476+ _ASM_EXTABLE(0b, 0b)
8477+#endif
8478+
8479+ "sete %1\n"
8480 : "=m" (v->counter), "=qm" (c)
8481 : "er" (i), "m" (v->counter) : "memory");
8482 return c;
8483@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(
8484 */
8485 static inline void atomic64_inc(atomic64_t *v)
8486 {
8487+ asm volatile(LOCK_PREFIX "incq %0\n"
8488+
8489+#ifdef CONFIG_PAX_REFCOUNT
8490+ "jno 0f\n"
8491+ LOCK_PREFIX "decq %0\n"
8492+ "int $4\n0:\n"
8493+ _ASM_EXTABLE(0b, 0b)
8494+#endif
8495+
8496+ : "=m" (v->counter)
8497+ : "m" (v->counter));
8498+}
8499+
8500+/**
8501+ * atomic64_inc_unchecked - increment atomic64 variable
8502+ * @v: pointer to type atomic64_unchecked_t
8503+ *
8504+ * Atomically increments @v by 1.
8505+ */
8506+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
8507+{
8508 asm volatile(LOCK_PREFIX "incq %0"
8509 : "=m" (v->counter)
8510 : "m" (v->counter));
8511@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64
8512 */
8513 static inline void atomic64_dec(atomic64_t *v)
8514 {
8515- asm volatile(LOCK_PREFIX "decq %0"
8516+ asm volatile(LOCK_PREFIX "decq %0\n"
8517+
8518+#ifdef CONFIG_PAX_REFCOUNT
8519+ "jno 0f\n"
8520+ LOCK_PREFIX "incq %0\n"
8521+ "int $4\n0:\n"
8522+ _ASM_EXTABLE(0b, 0b)
8523+#endif
8524+
8525+ : "=m" (v->counter)
8526+ : "m" (v->counter));
8527+}
8528+
8529+/**
8530+ * atomic64_dec_unchecked - decrement atomic64 variable
8531+ * @v: pointer to type atomic64_t
8532+ *
8533+ * Atomically decrements @v by 1.
8534+ */
8535+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
8536+{
8537+ asm volatile(LOCK_PREFIX "decq %0\n"
8538 : "=m" (v->counter)
8539 : "m" (v->counter));
8540 }
8541@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(
8542 {
8543 unsigned char c;
8544
8545- asm volatile(LOCK_PREFIX "decq %0; sete %1"
8546+ asm volatile(LOCK_PREFIX "decq %0\n"
8547+
8548+#ifdef CONFIG_PAX_REFCOUNT
8549+ "jno 0f\n"
8550+ LOCK_PREFIX "incq %0\n"
8551+ "int $4\n0:\n"
8552+ _ASM_EXTABLE(0b, 0b)
8553+#endif
8554+
8555+ "sete %1\n"
8556 : "=m" (v->counter), "=qm" (c)
8557 : "m" (v->counter) : "memory");
8558 return c != 0;
8559@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(
8560 {
8561 unsigned char c;
8562
8563- asm volatile(LOCK_PREFIX "incq %0; sete %1"
8564+ asm volatile(LOCK_PREFIX "incq %0\n"
8565+
8566+#ifdef CONFIG_PAX_REFCOUNT
8567+ "jno 0f\n"
8568+ LOCK_PREFIX "decq %0\n"
8569+ "int $4\n0:\n"
8570+ _ASM_EXTABLE(0b, 0b)
8571+#endif
8572+
8573+ "sete %1\n"
8574 : "=m" (v->counter), "=qm" (c)
8575 : "m" (v->counter) : "memory");
8576 return c != 0;
8577@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(
8578 {
8579 unsigned char c;
8580
8581- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
8582+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
8583+
8584+#ifdef CONFIG_PAX_REFCOUNT
8585+ "jno 0f\n"
8586+ LOCK_PREFIX "subq %2,%0\n"
8587+ "int $4\n0:\n"
8588+ _ASM_EXTABLE(0b, 0b)
8589+#endif
8590+
8591+ "sets %1\n"
8592 : "=m" (v->counter), "=qm" (c)
8593 : "er" (i), "m" (v->counter) : "memory");
8594 return c;
8595@@ -171,7 +317,31 @@ static inline int atomic64_add_negative(
8596 static inline long atomic64_add_return(long i, atomic64_t *v)
8597 {
8598 long __i = i;
8599- asm volatile(LOCK_PREFIX "xaddq %0, %1;"
8600+ asm volatile(LOCK_PREFIX "xaddq %0, %1\n"
8601+
8602+#ifdef CONFIG_PAX_REFCOUNT
8603+ "jno 0f\n"
8604+ "movq %0, %1\n"
8605+ "int $4\n0:\n"
8606+ _ASM_EXTABLE(0b, 0b)
8607+#endif
8608+
8609+ : "+r" (i), "+m" (v->counter)
8610+ : : "memory");
8611+ return i + __i;
8612+}
8613+
8614+/**
8615+ * atomic64_add_return_unchecked - add and return
8616+ * @i: integer value to add
8617+ * @v: pointer to type atomic64_unchecked_t
8618+ *
8619+ * Atomically adds @i to @v and returns @i + @v
8620+ */
8621+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
8622+{
8623+ long __i = i;
8624+ asm volatile(LOCK_PREFIX "xaddq %0, %1"
8625 : "+r" (i), "+m" (v->counter)
8626 : : "memory");
8627 return i + __i;
8628@@ -183,6 +353,10 @@ static inline long atomic64_sub_return(l
8629 }
8630
8631 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
8632+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
8633+{
8634+ return atomic64_add_return_unchecked(1, v);
8635+}
8636 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
8637
8638 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
8639@@ -190,6 +364,11 @@ static inline long atomic64_cmpxchg(atom
8640 return cmpxchg(&v->counter, old, new);
8641 }
8642
8643+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
8644+{
8645+ return cmpxchg(&v->counter, old, new);
8646+}
8647+
8648 static inline long atomic64_xchg(atomic64_t *v, long new)
8649 {
8650 return xchg(&v->counter, new);
8651@@ -206,17 +385,30 @@ static inline long atomic64_xchg(atomic6
8652 */
8653 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
8654 {
8655- long c, old;
8656+ long c, old, new;
8657 c = atomic64_read(v);
8658 for (;;) {
8659- if (unlikely(c == (u)))
8660+ if (unlikely(c == u))
8661 break;
8662- old = atomic64_cmpxchg((v), c, c + (a));
8663+
8664+ asm volatile("add %2,%0\n"
8665+
8666+#ifdef CONFIG_PAX_REFCOUNT
8667+ "jno 0f\n"
8668+ "sub %2,%0\n"
8669+ "int $4\n0:\n"
8670+ _ASM_EXTABLE(0b, 0b)
8671+#endif
8672+
8673+ : "=r" (new)
8674+ : "0" (c), "ir" (a));
8675+
8676+ old = atomic64_cmpxchg(v, c, new);
8677 if (likely(old == c))
8678 break;
8679 c = old;
8680 }
8681- return c != (u);
8682+ return c != u;
8683 }
8684
8685 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
8686diff -urNp linux-2.6.39.1/arch/x86/include/asm/atomic.h linux-2.6.39.1/arch/x86/include/asm/atomic.h
8687--- linux-2.6.39.1/arch/x86/include/asm/atomic.h 2011-05-19 00:06:34.000000000 -0400
8688+++ linux-2.6.39.1/arch/x86/include/asm/atomic.h 2011-05-22 19:36:30.000000000 -0400
8689@@ -22,7 +22,18 @@
8690 */
8691 static inline int atomic_read(const atomic_t *v)
8692 {
8693- return (*(volatile int *)&(v)->counter);
8694+ return (*(volatile const int *)&(v)->counter);
8695+}
8696+
8697+/**
8698+ * atomic_read_unchecked - read atomic variable
8699+ * @v: pointer of type atomic_unchecked_t
8700+ *
8701+ * Atomically reads the value of @v.
8702+ */
8703+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
8704+{
8705+ return (*(volatile const int *)&(v)->counter);
8706 }
8707
8708 /**
8709@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *
8710 }
8711
8712 /**
8713+ * atomic_set_unchecked - set atomic variable
8714+ * @v: pointer of type atomic_unchecked_t
8715+ * @i: required value
8716+ *
8717+ * Atomically sets the value of @v to @i.
8718+ */
8719+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
8720+{
8721+ v->counter = i;
8722+}
8723+
8724+/**
8725 * atomic_add - add integer to atomic variable
8726 * @i: integer value to add
8727 * @v: pointer of type atomic_t
8728@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *
8729 */
8730 static inline void atomic_add(int i, atomic_t *v)
8731 {
8732- asm volatile(LOCK_PREFIX "addl %1,%0"
8733+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
8734+
8735+#ifdef CONFIG_PAX_REFCOUNT
8736+ "jno 0f\n"
8737+ LOCK_PREFIX "subl %1,%0\n"
8738+ "int $4\n0:\n"
8739+ _ASM_EXTABLE(0b, 0b)
8740+#endif
8741+
8742+ : "+m" (v->counter)
8743+ : "ir" (i));
8744+}
8745+
8746+/**
8747+ * atomic_add_unchecked - add integer to atomic variable
8748+ * @i: integer value to add
8749+ * @v: pointer of type atomic_unchecked_t
8750+ *
8751+ * Atomically adds @i to @v.
8752+ */
8753+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
8754+{
8755+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
8756 : "+m" (v->counter)
8757 : "ir" (i));
8758 }
8759@@ -60,7 +105,29 @@ static inline void atomic_add(int i, ato
8760 */
8761 static inline void atomic_sub(int i, atomic_t *v)
8762 {
8763- asm volatile(LOCK_PREFIX "subl %1,%0"
8764+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
8765+
8766+#ifdef CONFIG_PAX_REFCOUNT
8767+ "jno 0f\n"
8768+ LOCK_PREFIX "addl %1,%0\n"
8769+ "int $4\n0:\n"
8770+ _ASM_EXTABLE(0b, 0b)
8771+#endif
8772+
8773+ : "+m" (v->counter)
8774+ : "ir" (i));
8775+}
8776+
8777+/**
8778+ * atomic_sub_unchecked - subtract integer from atomic variable
8779+ * @i: integer value to subtract
8780+ * @v: pointer of type atomic_unchecked_t
8781+ *
8782+ * Atomically subtracts @i from @v.
8783+ */
8784+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
8785+{
8786+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
8787 : "+m" (v->counter)
8788 : "ir" (i));
8789 }
8790@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(in
8791 {
8792 unsigned char c;
8793
8794- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
8795+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
8796+
8797+#ifdef CONFIG_PAX_REFCOUNT
8798+ "jno 0f\n"
8799+ LOCK_PREFIX "addl %2,%0\n"
8800+ "int $4\n0:\n"
8801+ _ASM_EXTABLE(0b, 0b)
8802+#endif
8803+
8804+ "sete %1\n"
8805 : "+m" (v->counter), "=qm" (c)
8806 : "ir" (i) : "memory");
8807 return c;
8808@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(in
8809 */
8810 static inline void atomic_inc(atomic_t *v)
8811 {
8812- asm volatile(LOCK_PREFIX "incl %0"
8813+ asm volatile(LOCK_PREFIX "incl %0\n"
8814+
8815+#ifdef CONFIG_PAX_REFCOUNT
8816+ "jno 0f\n"
8817+ LOCK_PREFIX "decl %0\n"
8818+ "int $4\n0:\n"
8819+ _ASM_EXTABLE(0b, 0b)
8820+#endif
8821+
8822+ : "+m" (v->counter));
8823+}
8824+
8825+/**
8826+ * atomic_inc_unchecked - increment atomic variable
8827+ * @v: pointer of type atomic_unchecked_t
8828+ *
8829+ * Atomically increments @v by 1.
8830+ */
8831+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
8832+{
8833+ asm volatile(LOCK_PREFIX "incl %0\n"
8834 : "+m" (v->counter));
8835 }
8836
8837@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *
8838 */
8839 static inline void atomic_dec(atomic_t *v)
8840 {
8841- asm volatile(LOCK_PREFIX "decl %0"
8842+ asm volatile(LOCK_PREFIX "decl %0\n"
8843+
8844+#ifdef CONFIG_PAX_REFCOUNT
8845+ "jno 0f\n"
8846+ LOCK_PREFIX "incl %0\n"
8847+ "int $4\n0:\n"
8848+ _ASM_EXTABLE(0b, 0b)
8849+#endif
8850+
8851+ : "+m" (v->counter));
8852+}
8853+
8854+/**
8855+ * atomic_dec_unchecked - decrement atomic variable
8856+ * @v: pointer of type atomic_unchecked_t
8857+ *
8858+ * Atomically decrements @v by 1.
8859+ */
8860+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
8861+{
8862+ asm volatile(LOCK_PREFIX "decl %0\n"
8863 : "+m" (v->counter));
8864 }
8865
8866@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(at
8867 {
8868 unsigned char c;
8869
8870- asm volatile(LOCK_PREFIX "decl %0; sete %1"
8871+ asm volatile(LOCK_PREFIX "decl %0\n"
8872+
8873+#ifdef CONFIG_PAX_REFCOUNT
8874+ "jno 0f\n"
8875+ LOCK_PREFIX "incl %0\n"
8876+ "int $4\n0:\n"
8877+ _ASM_EXTABLE(0b, 0b)
8878+#endif
8879+
8880+ "sete %1\n"
8881 : "+m" (v->counter), "=qm" (c)
8882 : : "memory");
8883 return c != 0;
8884@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(at
8885 {
8886 unsigned char c;
8887
8888- asm volatile(LOCK_PREFIX "incl %0; sete %1"
8889+ asm volatile(LOCK_PREFIX "incl %0\n"
8890+
8891+#ifdef CONFIG_PAX_REFCOUNT
8892+ "jno 0f\n"
8893+ LOCK_PREFIX "decl %0\n"
8894+ "int $4\n0:\n"
8895+ _ASM_EXTABLE(0b, 0b)
8896+#endif
8897+
8898+ "sete %1\n"
8899+ : "+m" (v->counter), "=qm" (c)
8900+ : : "memory");
8901+ return c != 0;
8902+}
8903+
8904+/**
8905+ * atomic_inc_and_test_unchecked - increment and test
8906+ * @v: pointer of type atomic_unchecked_t
8907+ *
8908+ * Atomically increments @v by 1
8909+ * and returns true if the result is zero, or false for all
8910+ * other cases.
8911+ */
8912+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
8913+{
8914+ unsigned char c;
8915+
8916+ asm volatile(LOCK_PREFIX "incl %0\n"
8917+ "sete %1\n"
8918 : "+m" (v->counter), "=qm" (c)
8919 : : "memory");
8920 return c != 0;
8921@@ -157,7 +310,16 @@ static inline int atomic_add_negative(in
8922 {
8923 unsigned char c;
8924
8925- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
8926+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
8927+
8928+#ifdef CONFIG_PAX_REFCOUNT
8929+ "jno 0f\n"
8930+ LOCK_PREFIX "subl %2,%0\n"
8931+ "int $4\n0:\n"
8932+ _ASM_EXTABLE(0b, 0b)
8933+#endif
8934+
8935+ "sets %1\n"
8936 : "+m" (v->counter), "=qm" (c)
8937 : "ir" (i) : "memory");
8938 return c;
8939@@ -180,6 +342,46 @@ static inline int atomic_add_return(int
8940 #endif
8941 /* Modern 486+ processor */
8942 __i = i;
8943+ asm volatile(LOCK_PREFIX "xaddl %0, %1\n"
8944+
8945+#ifdef CONFIG_PAX_REFCOUNT
8946+ "jno 0f\n"
8947+ "movl %0, %1\n"
8948+ "int $4\n0:\n"
8949+ _ASM_EXTABLE(0b, 0b)
8950+#endif
8951+
8952+ : "+r" (i), "+m" (v->counter)
8953+ : : "memory");
8954+ return i + __i;
8955+
8956+#ifdef CONFIG_M386
8957+no_xadd: /* Legacy 386 processor */
8958+ local_irq_save(flags);
8959+ __i = atomic_read(v);
8960+ atomic_set(v, i + __i);
8961+ local_irq_restore(flags);
8962+ return i + __i;
8963+#endif
8964+}
8965+
8966+/**
8967+ * atomic_add_return_unchecked - add integer and return
8968+ * @v: pointer of type atomic_unchecked_t
8969+ * @i: integer value to add
8970+ *
8971+ * Atomically adds @i to @v and returns @i + @v
8972+ */
8973+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
8974+{
8975+ int __i;
8976+#ifdef CONFIG_M386
8977+ unsigned long flags;
8978+ if (unlikely(boot_cpu_data.x86 <= 3))
8979+ goto no_xadd;
8980+#endif
8981+ /* Modern 486+ processor */
8982+ __i = i;
8983 asm volatile(LOCK_PREFIX "xaddl %0, %1"
8984 : "+r" (i), "+m" (v->counter)
8985 : : "memory");
8986@@ -208,6 +410,10 @@ static inline int atomic_sub_return(int
8987 }
8988
8989 #define atomic_inc_return(v) (atomic_add_return(1, v))
8990+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
8991+{
8992+ return atomic_add_return_unchecked(1, v);
8993+}
8994 #define atomic_dec_return(v) (atomic_sub_return(1, v))
8995
8996 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
8997@@ -215,11 +421,21 @@ static inline int atomic_cmpxchg(atomic_
8998 return cmpxchg(&v->counter, old, new);
8999 }
9000
9001+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9002+{
9003+ return cmpxchg(&v->counter, old, new);
9004+}
9005+
9006 static inline int atomic_xchg(atomic_t *v, int new)
9007 {
9008 return xchg(&v->counter, new);
9009 }
9010
9011+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9012+{
9013+ return xchg(&v->counter, new);
9014+}
9015+
9016 /**
9017 * atomic_add_unless - add unless the number is already a given value
9018 * @v: pointer of type atomic_t
9019@@ -231,21 +447,77 @@ static inline int atomic_xchg(atomic_t *
9020 */
9021 static inline int atomic_add_unless(atomic_t *v, int a, int u)
9022 {
9023- int c, old;
9024+ int c, old, new;
9025 c = atomic_read(v);
9026 for (;;) {
9027- if (unlikely(c == (u)))
9028+ if (unlikely(c == u))
9029 break;
9030- old = atomic_cmpxchg((v), c, c + (a));
9031+
9032+ asm volatile("addl %2,%0\n"
9033+
9034+#ifdef CONFIG_PAX_REFCOUNT
9035+ "jno 0f\n"
9036+ "subl %2,%0\n"
9037+ "int $4\n0:\n"
9038+ _ASM_EXTABLE(0b, 0b)
9039+#endif
9040+
9041+ : "=r" (new)
9042+ : "0" (c), "ir" (a));
9043+
9044+ old = atomic_cmpxchg(v, c, new);
9045 if (likely(old == c))
9046 break;
9047 c = old;
9048 }
9049- return c != (u);
9050+ return c != u;
9051 }
9052
9053 #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
9054
9055+/**
9056+ * atomic_inc_not_zero_hint - increment if not null
9057+ * @v: pointer of type atomic_t
9058+ * @hint: probable value of the atomic before the increment
9059+ *
9060+ * This version of atomic_inc_not_zero() gives a hint of probable
9061+ * value of the atomic. This helps processor to not read the memory
9062+ * before doing the atomic read/modify/write cycle, lowering
9063+ * number of bus transactions on some arches.
9064+ *
9065+ * Returns: 0 if increment was not done, 1 otherwise.
9066+ */
9067+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
9068+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
9069+{
9070+ int val, c = hint, new;
9071+
9072+ /* sanity test, should be removed by compiler if hint is a constant */
9073+ if (!hint)
9074+ return atomic_inc_not_zero(v);
9075+
9076+ do {
9077+ asm volatile("incl %0\n"
9078+
9079+#ifdef CONFIG_PAX_REFCOUNT
9080+ "jno 0f\n"
9081+ "decl %0\n"
9082+ "int $4\n0:\n"
9083+ _ASM_EXTABLE(0b, 0b)
9084+#endif
9085+
9086+ : "=r" (new)
9087+ : "0" (c));
9088+
9089+ val = atomic_cmpxchg(v, c, new);
9090+ if (val == c)
9091+ return 1;
9092+ c = val;
9093+ } while (c);
9094+
9095+ return 0;
9096+}
9097+
9098 /*
9099 * atomic_dec_if_positive - decrement by 1 if old value positive
9100 * @v: pointer of type atomic_t
9101diff -urNp linux-2.6.39.1/arch/x86/include/asm/bitops.h linux-2.6.39.1/arch/x86/include/asm/bitops.h
9102--- linux-2.6.39.1/arch/x86/include/asm/bitops.h 2011-05-19 00:06:34.000000000 -0400
9103+++ linux-2.6.39.1/arch/x86/include/asm/bitops.h 2011-05-22 19:36:30.000000000 -0400
9104@@ -38,7 +38,7 @@
9105 * a mask operation on a byte.
9106 */
9107 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
9108-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
9109+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
9110 #define CONST_MASK(nr) (1 << ((nr) & 7))
9111
9112 /**
9113diff -urNp linux-2.6.39.1/arch/x86/include/asm/boot.h linux-2.6.39.1/arch/x86/include/asm/boot.h
9114--- linux-2.6.39.1/arch/x86/include/asm/boot.h 2011-05-19 00:06:34.000000000 -0400
9115+++ linux-2.6.39.1/arch/x86/include/asm/boot.h 2011-05-22 19:36:30.000000000 -0400
9116@@ -11,10 +11,15 @@
9117 #include <asm/pgtable_types.h>
9118
9119 /* Physical address where kernel should be loaded. */
9120-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
9121+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
9122 + (CONFIG_PHYSICAL_ALIGN - 1)) \
9123 & ~(CONFIG_PHYSICAL_ALIGN - 1))
9124
9125+#ifndef __ASSEMBLY__
9126+extern unsigned char __LOAD_PHYSICAL_ADDR[];
9127+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
9128+#endif
9129+
9130 /* Minimum kernel alignment, as a power of two */
9131 #ifdef CONFIG_X86_64
9132 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
9133diff -urNp linux-2.6.39.1/arch/x86/include/asm/cacheflush.h linux-2.6.39.1/arch/x86/include/asm/cacheflush.h
9134--- linux-2.6.39.1/arch/x86/include/asm/cacheflush.h 2011-05-19 00:06:34.000000000 -0400
9135+++ linux-2.6.39.1/arch/x86/include/asm/cacheflush.h 2011-05-22 19:36:30.000000000 -0400
9136@@ -26,7 +26,7 @@ static inline unsigned long get_page_mem
9137 unsigned long pg_flags = pg->flags & _PGMT_MASK;
9138
9139 if (pg_flags == _PGMT_DEFAULT)
9140- return -1;
9141+ return ~0UL;
9142 else if (pg_flags == _PGMT_WC)
9143 return _PAGE_CACHE_WC;
9144 else if (pg_flags == _PGMT_UC_MINUS)
9145diff -urNp linux-2.6.39.1/arch/x86/include/asm/cache.h linux-2.6.39.1/arch/x86/include/asm/cache.h
9146--- linux-2.6.39.1/arch/x86/include/asm/cache.h 2011-05-19 00:06:34.000000000 -0400
9147+++ linux-2.6.39.1/arch/x86/include/asm/cache.h 2011-05-22 19:36:30.000000000 -0400
9148@@ -5,12 +5,13 @@
9149
9150 /* L1 cache line size */
9151 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
9152-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9153+#define L1_CACHE_BYTES (_AC(1,U) << L1_CACHE_SHIFT)
9154
9155 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9156+#define __read_only __attribute__((__section__(".data..read_only")))
9157
9158 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
9159-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
9160+#define INTERNODE_CACHE_BYTES (_AC(1,U) << INTERNODE_CACHE_SHIFT)
9161
9162 #ifdef CONFIG_X86_VSMP
9163 #ifdef CONFIG_SMP
9164diff -urNp linux-2.6.39.1/arch/x86/include/asm/checksum_32.h linux-2.6.39.1/arch/x86/include/asm/checksum_32.h
9165--- linux-2.6.39.1/arch/x86/include/asm/checksum_32.h 2011-05-19 00:06:34.000000000 -0400
9166+++ linux-2.6.39.1/arch/x86/include/asm/checksum_32.h 2011-05-22 19:36:30.000000000 -0400
9167@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_gene
9168 int len, __wsum sum,
9169 int *src_err_ptr, int *dst_err_ptr);
9170
9171+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
9172+ int len, __wsum sum,
9173+ int *src_err_ptr, int *dst_err_ptr);
9174+
9175+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
9176+ int len, __wsum sum,
9177+ int *src_err_ptr, int *dst_err_ptr);
9178+
9179 /*
9180 * Note: when you get a NULL pointer exception here this means someone
9181 * passed in an incorrect kernel address to one of these functions.
9182@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_f
9183 int *err_ptr)
9184 {
9185 might_sleep();
9186- return csum_partial_copy_generic((__force void *)src, dst,
9187+ return csum_partial_copy_generic_from_user((__force void *)src, dst,
9188 len, sum, err_ptr, NULL);
9189 }
9190
9191@@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_us
9192 {
9193 might_sleep();
9194 if (access_ok(VERIFY_WRITE, dst, len))
9195- return csum_partial_copy_generic(src, (__force void *)dst,
9196+ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
9197 len, sum, NULL, err_ptr);
9198
9199 if (len)
9200diff -urNp linux-2.6.39.1/arch/x86/include/asm/cpufeature.h linux-2.6.39.1/arch/x86/include/asm/cpufeature.h
9201--- linux-2.6.39.1/arch/x86/include/asm/cpufeature.h 2011-06-03 00:04:13.000000000 -0400
9202+++ linux-2.6.39.1/arch/x86/include/asm/cpufeature.h 2011-06-03 00:32:04.000000000 -0400
9203@@ -351,7 +351,7 @@ static __always_inline __pure bool __sta
9204 ".section .discard,\"aw\",@progbits\n"
9205 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
9206 ".previous\n"
9207- ".section .altinstr_replacement,\"ax\"\n"
9208+ ".section .altinstr_replacement,\"a\"\n"
9209 "3: movb $1,%0\n"
9210 "4:\n"
9211 ".previous\n"
9212diff -urNp linux-2.6.39.1/arch/x86/include/asm/desc_defs.h linux-2.6.39.1/arch/x86/include/asm/desc_defs.h
9213--- linux-2.6.39.1/arch/x86/include/asm/desc_defs.h 2011-05-19 00:06:34.000000000 -0400
9214+++ linux-2.6.39.1/arch/x86/include/asm/desc_defs.h 2011-05-22 19:36:30.000000000 -0400
9215@@ -31,6 +31,12 @@ struct desc_struct {
9216 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
9217 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
9218 };
9219+ struct {
9220+ u16 offset_low;
9221+ u16 seg;
9222+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
9223+ unsigned offset_high: 16;
9224+ } gate;
9225 };
9226 } __attribute__((packed));
9227
9228diff -urNp linux-2.6.39.1/arch/x86/include/asm/desc.h linux-2.6.39.1/arch/x86/include/asm/desc.h
9229--- linux-2.6.39.1/arch/x86/include/asm/desc.h 2011-05-19 00:06:34.000000000 -0400
9230+++ linux-2.6.39.1/arch/x86/include/asm/desc.h 2011-05-22 19:36:30.000000000 -0400
9231@@ -4,6 +4,7 @@
9232 #include <asm/desc_defs.h>
9233 #include <asm/ldt.h>
9234 #include <asm/mmu.h>
9235+#include <asm/pgtable.h>
9236 #include <linux/smp.h>
9237
9238 static inline void fill_ldt(struct desc_struct *desc,
9239@@ -15,6 +16,7 @@ static inline void fill_ldt(struct desc_
9240 desc->base1 = (info->base_addr & 0x00ff0000) >> 16;
9241 desc->type = (info->read_exec_only ^ 1) << 1;
9242 desc->type |= info->contents << 2;
9243+ desc->type |= info->seg_not_present ^ 1;
9244 desc->s = 1;
9245 desc->dpl = 0x3;
9246 desc->p = info->seg_not_present ^ 1;
9247@@ -31,16 +33,12 @@ static inline void fill_ldt(struct desc_
9248 }
9249
9250 extern struct desc_ptr idt_descr;
9251-extern gate_desc idt_table[];
9252-
9253-struct gdt_page {
9254- struct desc_struct gdt[GDT_ENTRIES];
9255-} __attribute__((aligned(PAGE_SIZE)));
9256-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
9257+extern gate_desc idt_table[256];
9258
9259+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
9260 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
9261 {
9262- return per_cpu(gdt_page, cpu).gdt;
9263+ return cpu_gdt_table[cpu];
9264 }
9265
9266 #ifdef CONFIG_X86_64
9267@@ -65,9 +63,14 @@ static inline void pack_gate(gate_desc *
9268 unsigned long base, unsigned dpl, unsigned flags,
9269 unsigned short seg)
9270 {
9271- gate->a = (seg << 16) | (base & 0xffff);
9272- gate->b = (base & 0xffff0000) |
9273- (((0x80 | type | (dpl << 5)) & 0xff) << 8);
9274+ gate->gate.offset_low = base;
9275+ gate->gate.seg = seg;
9276+ gate->gate.reserved = 0;
9277+ gate->gate.type = type;
9278+ gate->gate.s = 0;
9279+ gate->gate.dpl = dpl;
9280+ gate->gate.p = 1;
9281+ gate->gate.offset_high = base >> 16;
9282 }
9283
9284 #endif
9285@@ -115,13 +118,17 @@ static inline void paravirt_free_ldt(str
9286 static inline void native_write_idt_entry(gate_desc *idt, int entry,
9287 const gate_desc *gate)
9288 {
9289+ pax_open_kernel();
9290 memcpy(&idt[entry], gate, sizeof(*gate));
9291+ pax_close_kernel();
9292 }
9293
9294 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry,
9295 const void *desc)
9296 {
9297+ pax_open_kernel();
9298 memcpy(&ldt[entry], desc, 8);
9299+ pax_close_kernel();
9300 }
9301
9302 static inline void native_write_gdt_entry(struct desc_struct *gdt, int entry,
9303@@ -139,7 +146,10 @@ static inline void native_write_gdt_entr
9304 size = sizeof(struct desc_struct);
9305 break;
9306 }
9307+
9308+ pax_open_kernel();
9309 memcpy(&gdt[entry], desc, size);
9310+ pax_close_kernel();
9311 }
9312
9313 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
9314@@ -211,7 +221,9 @@ static inline void native_set_ldt(const
9315
9316 static inline void native_load_tr_desc(void)
9317 {
9318+ pax_open_kernel();
9319 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
9320+ pax_close_kernel();
9321 }
9322
9323 static inline void native_load_gdt(const struct desc_ptr *dtr)
9324@@ -246,8 +258,10 @@ static inline void native_load_tls(struc
9325 unsigned int i;
9326 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
9327
9328+ pax_open_kernel();
9329 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
9330 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
9331+ pax_close_kernel();
9332 }
9333
9334 #define _LDT_empty(info) \
9335@@ -309,7 +323,7 @@ static inline void set_desc_limit(struct
9336 desc->limit = (limit >> 16) & 0xf;
9337 }
9338
9339-static inline void _set_gate(int gate, unsigned type, void *addr,
9340+static inline void _set_gate(int gate, unsigned type, const void *addr,
9341 unsigned dpl, unsigned ist, unsigned seg)
9342 {
9343 gate_desc s;
9344@@ -327,7 +341,7 @@ static inline void _set_gate(int gate, u
9345 * Pentium F0 0F bugfix can have resulted in the mapped
9346 * IDT being write-protected.
9347 */
9348-static inline void set_intr_gate(unsigned int n, void *addr)
9349+static inline void set_intr_gate(unsigned int n, const void *addr)
9350 {
9351 BUG_ON((unsigned)n > 0xFF);
9352 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
9353@@ -356,19 +370,19 @@ static inline void alloc_intr_gate(unsig
9354 /*
9355 * This routine sets up an interrupt gate at directory privilege level 3.
9356 */
9357-static inline void set_system_intr_gate(unsigned int n, void *addr)
9358+static inline void set_system_intr_gate(unsigned int n, const void *addr)
9359 {
9360 BUG_ON((unsigned)n > 0xFF);
9361 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
9362 }
9363
9364-static inline void set_system_trap_gate(unsigned int n, void *addr)
9365+static inline void set_system_trap_gate(unsigned int n, const void *addr)
9366 {
9367 BUG_ON((unsigned)n > 0xFF);
9368 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
9369 }
9370
9371-static inline void set_trap_gate(unsigned int n, void *addr)
9372+static inline void set_trap_gate(unsigned int n, const void *addr)
9373 {
9374 BUG_ON((unsigned)n > 0xFF);
9375 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
9376@@ -377,19 +391,31 @@ static inline void set_trap_gate(unsigne
9377 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
9378 {
9379 BUG_ON((unsigned)n > 0xFF);
9380- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
9381+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
9382 }
9383
9384-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
9385+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
9386 {
9387 BUG_ON((unsigned)n > 0xFF);
9388 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
9389 }
9390
9391-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
9392+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
9393 {
9394 BUG_ON((unsigned)n > 0xFF);
9395 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
9396 }
9397
9398+#ifdef CONFIG_X86_32
9399+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
9400+{
9401+ struct desc_struct d;
9402+
9403+ if (likely(limit))
9404+ limit = (limit - 1UL) >> PAGE_SHIFT;
9405+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
9406+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
9407+}
9408+#endif
9409+
9410 #endif /* _ASM_X86_DESC_H */
9411diff -urNp linux-2.6.39.1/arch/x86/include/asm/device.h linux-2.6.39.1/arch/x86/include/asm/device.h
9412--- linux-2.6.39.1/arch/x86/include/asm/device.h 2011-05-19 00:06:34.000000000 -0400
9413+++ linux-2.6.39.1/arch/x86/include/asm/device.h 2011-05-22 19:36:30.000000000 -0400
9414@@ -6,7 +6,7 @@ struct dev_archdata {
9415 void *acpi_handle;
9416 #endif
9417 #ifdef CONFIG_X86_64
9418-struct dma_map_ops *dma_ops;
9419+ const struct dma_map_ops *dma_ops;
9420 #endif
9421 #if defined(CONFIG_DMAR) || defined(CONFIG_AMD_IOMMU)
9422 void *iommu; /* hook for IOMMU specific extension */
9423diff -urNp linux-2.6.39.1/arch/x86/include/asm/dma-mapping.h linux-2.6.39.1/arch/x86/include/asm/dma-mapping.h
9424--- linux-2.6.39.1/arch/x86/include/asm/dma-mapping.h 2011-05-19 00:06:34.000000000 -0400
9425+++ linux-2.6.39.1/arch/x86/include/asm/dma-mapping.h 2011-05-22 19:36:30.000000000 -0400
9426@@ -26,9 +26,9 @@ extern int iommu_merge;
9427 extern struct device x86_dma_fallback_dev;
9428 extern int panic_on_overflow;
9429
9430-extern struct dma_map_ops *dma_ops;
9431+extern const struct dma_map_ops *dma_ops;
9432
9433-static inline struct dma_map_ops *get_dma_ops(struct device *dev)
9434+static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
9435 {
9436 #ifdef CONFIG_X86_32
9437 return dma_ops;
9438@@ -45,7 +45,7 @@ static inline struct dma_map_ops *get_dm
9439 /* Make sure we keep the same behaviour */
9440 static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
9441 {
9442- struct dma_map_ops *ops = get_dma_ops(dev);
9443+ const struct dma_map_ops *ops = get_dma_ops(dev);
9444 if (ops->mapping_error)
9445 return ops->mapping_error(dev, dma_addr);
9446
9447@@ -115,7 +115,7 @@ static inline void *
9448 dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
9449 gfp_t gfp)
9450 {
9451- struct dma_map_ops *ops = get_dma_ops(dev);
9452+ const struct dma_map_ops *ops = get_dma_ops(dev);
9453 void *memory;
9454
9455 gfp &= ~(__GFP_DMA | __GFP_HIGHMEM | __GFP_DMA32);
9456@@ -142,7 +142,7 @@ dma_alloc_coherent(struct device *dev, s
9457 static inline void dma_free_coherent(struct device *dev, size_t size,
9458 void *vaddr, dma_addr_t bus)
9459 {
9460- struct dma_map_ops *ops = get_dma_ops(dev);
9461+ const struct dma_map_ops *ops = get_dma_ops(dev);
9462
9463 WARN_ON(irqs_disabled()); /* for portability */
9464
9465diff -urNp linux-2.6.39.1/arch/x86/include/asm/e820.h linux-2.6.39.1/arch/x86/include/asm/e820.h
9466--- linux-2.6.39.1/arch/x86/include/asm/e820.h 2011-05-19 00:06:34.000000000 -0400
9467+++ linux-2.6.39.1/arch/x86/include/asm/e820.h 2011-05-22 19:36:30.000000000 -0400
9468@@ -69,7 +69,7 @@ struct e820map {
9469 #define ISA_START_ADDRESS 0xa0000
9470 #define ISA_END_ADDRESS 0x100000
9471
9472-#define BIOS_BEGIN 0x000a0000
9473+#define BIOS_BEGIN 0x000c0000
9474 #define BIOS_END 0x00100000
9475
9476 #define BIOS_ROM_BASE 0xffe00000
9477diff -urNp linux-2.6.39.1/arch/x86/include/asm/elf.h linux-2.6.39.1/arch/x86/include/asm/elf.h
9478--- linux-2.6.39.1/arch/x86/include/asm/elf.h 2011-05-19 00:06:34.000000000 -0400
9479+++ linux-2.6.39.1/arch/x86/include/asm/elf.h 2011-05-22 19:36:30.000000000 -0400
9480@@ -237,7 +237,25 @@ extern int force_personality32;
9481 the loader. We need to make sure that it is out of the way of the program
9482 that it will "exec", and that there is sufficient room for the brk. */
9483
9484+#ifdef CONFIG_PAX_SEGMEXEC
9485+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
9486+#else
9487 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
9488+#endif
9489+
9490+#ifdef CONFIG_PAX_ASLR
9491+#ifdef CONFIG_X86_32
9492+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
9493+
9494+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
9495+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
9496+#else
9497+#define PAX_ELF_ET_DYN_BASE 0x400000UL
9498+
9499+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
9500+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
9501+#endif
9502+#endif
9503
9504 /* This yields a mask that user programs can use to figure out what
9505 instruction set this CPU supports. This could be done in user space,
9506@@ -291,8 +309,7 @@ do { \
9507 #define ARCH_DLINFO \
9508 do { \
9509 if (vdso_enabled) \
9510- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
9511- (unsigned long)current->mm->context.vdso); \
9512+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso);\
9513 } while (0)
9514
9515 #define AT_SYSINFO 32
9516@@ -303,7 +320,7 @@ do { \
9517
9518 #endif /* !CONFIG_X86_32 */
9519
9520-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
9521+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
9522
9523 #define VDSO_ENTRY \
9524 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
9525@@ -317,7 +334,4 @@ extern int arch_setup_additional_pages(s
9526 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
9527 #define compat_arch_setup_additional_pages syscall32_setup_pages
9528
9529-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
9530-#define arch_randomize_brk arch_randomize_brk
9531-
9532 #endif /* _ASM_X86_ELF_H */
9533diff -urNp linux-2.6.39.1/arch/x86/include/asm/emergency-restart.h linux-2.6.39.1/arch/x86/include/asm/emergency-restart.h
9534--- linux-2.6.39.1/arch/x86/include/asm/emergency-restart.h 2011-05-19 00:06:34.000000000 -0400
9535+++ linux-2.6.39.1/arch/x86/include/asm/emergency-restart.h 2011-05-22 19:36:30.000000000 -0400
9536@@ -15,6 +15,6 @@ enum reboot_type {
9537
9538 extern enum reboot_type reboot_type;
9539
9540-extern void machine_emergency_restart(void);
9541+extern void machine_emergency_restart(void) __noreturn;
9542
9543 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
9544diff -urNp linux-2.6.39.1/arch/x86/include/asm/futex.h linux-2.6.39.1/arch/x86/include/asm/futex.h
9545--- linux-2.6.39.1/arch/x86/include/asm/futex.h 2011-05-19 00:06:34.000000000 -0400
9546+++ linux-2.6.39.1/arch/x86/include/asm/futex.h 2011-05-22 19:36:30.000000000 -0400
9547@@ -12,16 +12,18 @@
9548 #include <asm/system.h>
9549
9550 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
9551+ typecheck(u32 *, uaddr); \
9552 asm volatile("1:\t" insn "\n" \
9553 "2:\t.section .fixup,\"ax\"\n" \
9554 "3:\tmov\t%3, %1\n" \
9555 "\tjmp\t2b\n" \
9556 "\t.previous\n" \
9557 _ASM_EXTABLE(1b, 3b) \
9558- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
9559+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 *)____m(uaddr))\
9560 : "i" (-EFAULT), "0" (oparg), "1" (0))
9561
9562 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
9563+ typecheck(u32 *, uaddr); \
9564 asm volatile("1:\tmovl %2, %0\n" \
9565 "\tmovl\t%0, %3\n" \
9566 "\t" insn "\n" \
9567@@ -34,7 +36,7 @@
9568 _ASM_EXTABLE(1b, 4b) \
9569 _ASM_EXTABLE(2b, 4b) \
9570 : "=&a" (oldval), "=&r" (ret), \
9571- "+m" (*uaddr), "=&r" (tem) \
9572+ "+m" (*(u32 *)____m(uaddr)), "=&r" (tem) \
9573 : "r" (oparg), "i" (-EFAULT), "1" (0))
9574
9575 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
9576@@ -61,10 +63,10 @@ static inline int futex_atomic_op_inuser
9577
9578 switch (op) {
9579 case FUTEX_OP_SET:
9580- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
9581+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
9582 break;
9583 case FUTEX_OP_ADD:
9584- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
9585+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
9586 uaddr, oparg);
9587 break;
9588 case FUTEX_OP_OR:
9589@@ -123,13 +125,13 @@ static inline int futex_atomic_cmpxchg_i
9590 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
9591 return -EFAULT;
9592
9593- asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
9594+ asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
9595 "2:\t.section .fixup, \"ax\"\n"
9596 "3:\tmov %3, %0\n"
9597 "\tjmp 2b\n"
9598 "\t.previous\n"
9599 _ASM_EXTABLE(1b, 3b)
9600- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
9601+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 *)____m(uaddr))
9602 : "i" (-EFAULT), "r" (newval), "1" (oldval)
9603 : "memory"
9604 );
9605diff -urNp linux-2.6.39.1/arch/x86/include/asm/hw_irq.h linux-2.6.39.1/arch/x86/include/asm/hw_irq.h
9606--- linux-2.6.39.1/arch/x86/include/asm/hw_irq.h 2011-05-19 00:06:34.000000000 -0400
9607+++ linux-2.6.39.1/arch/x86/include/asm/hw_irq.h 2011-05-22 19:36:30.000000000 -0400
9608@@ -137,8 +137,8 @@ extern void setup_ioapic_dest(void);
9609 extern void enable_IO_APIC(void);
9610
9611 /* Statistics */
9612-extern atomic_t irq_err_count;
9613-extern atomic_t irq_mis_count;
9614+extern atomic_unchecked_t irq_err_count;
9615+extern atomic_unchecked_t irq_mis_count;
9616
9617 /* EISA */
9618 extern void eisa_set_level_irq(unsigned int irq);
9619diff -urNp linux-2.6.39.1/arch/x86/include/asm/i387.h linux-2.6.39.1/arch/x86/include/asm/i387.h
9620--- linux-2.6.39.1/arch/x86/include/asm/i387.h 2011-05-19 00:06:34.000000000 -0400
9621+++ linux-2.6.39.1/arch/x86/include/asm/i387.h 2011-05-22 19:36:30.000000000 -0400
9622@@ -92,6 +92,11 @@ static inline int fxrstor_checking(struc
9623 {
9624 int err;
9625
9626+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
9627+ if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
9628+ fx = (struct i387_fxsave_struct *)((void *)fx + PAX_USER_SHADOW_BASE);
9629+#endif
9630+
9631 /* See comment in fxsave() below. */
9632 #ifdef CONFIG_AS_FXSAVEQ
9633 asm volatile("1: fxrstorq %[fx]\n\t"
9634@@ -121,6 +126,11 @@ static inline int fxsave_user(struct i38
9635 {
9636 int err;
9637
9638+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
9639+ if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
9640+ fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
9641+#endif
9642+
9643 /*
9644 * Clear the bytes not touched by the fxsave and reserved
9645 * for the SW usage.
9646@@ -213,13 +223,8 @@ static inline void fpu_fxsave(struct fpu
9647 #endif /* CONFIG_X86_64 */
9648
9649 /* We need a safe address that is cheap to find and that is already
9650- in L1 during context switch. The best choices are unfortunately
9651- different for UP and SMP */
9652-#ifdef CONFIG_SMP
9653-#define safe_address (__per_cpu_offset[0])
9654-#else
9655-#define safe_address (kstat_cpu(0).cpustat.user)
9656-#endif
9657+ in L1 during context switch. */
9658+#define safe_address (init_tss[smp_processor_id()].x86_tss.sp0)
9659
9660 /*
9661 * These must be called with preempt disabled
9662@@ -312,7 +317,7 @@ static inline void kernel_fpu_begin(void
9663 struct thread_info *me = current_thread_info();
9664 preempt_disable();
9665 if (me->status & TS_USEDFPU)
9666- __save_init_fpu(me->task);
9667+ __save_init_fpu(current);
9668 else
9669 clts();
9670 }
9671diff -urNp linux-2.6.39.1/arch/x86/include/asm/io.h linux-2.6.39.1/arch/x86/include/asm/io.h
9672--- linux-2.6.39.1/arch/x86/include/asm/io.h 2011-05-19 00:06:34.000000000 -0400
9673+++ linux-2.6.39.1/arch/x86/include/asm/io.h 2011-05-22 19:36:30.000000000 -0400
9674@@ -216,6 +216,17 @@ extern void set_iounmap_nonlazy(void);
9675
9676 #include <linux/vmalloc.h>
9677
9678+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
9679+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
9680+{
9681+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
9682+}
9683+
9684+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
9685+{
9686+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
9687+}
9688+
9689 /*
9690 * Convert a virtual cached pointer to an uncached pointer
9691 */
9692diff -urNp linux-2.6.39.1/arch/x86/include/asm/iommu.h linux-2.6.39.1/arch/x86/include/asm/iommu.h
9693--- linux-2.6.39.1/arch/x86/include/asm/iommu.h 2011-05-19 00:06:34.000000000 -0400
9694+++ linux-2.6.39.1/arch/x86/include/asm/iommu.h 2011-05-22 19:36:30.000000000 -0400
9695@@ -1,7 +1,7 @@
9696 #ifndef _ASM_X86_IOMMU_H
9697 #define _ASM_X86_IOMMU_H
9698
9699-extern struct dma_map_ops nommu_dma_ops;
9700+extern const struct dma_map_ops nommu_dma_ops;
9701 extern int force_iommu, no_iommu;
9702 extern int iommu_detected;
9703 extern int iommu_pass_through;
9704diff -urNp linux-2.6.39.1/arch/x86/include/asm/irqflags.h linux-2.6.39.1/arch/x86/include/asm/irqflags.h
9705--- linux-2.6.39.1/arch/x86/include/asm/irqflags.h 2011-05-19 00:06:34.000000000 -0400
9706+++ linux-2.6.39.1/arch/x86/include/asm/irqflags.h 2011-05-22 19:36:30.000000000 -0400
9707@@ -140,6 +140,11 @@ static inline unsigned long arch_local_i
9708 sti; \
9709 sysexit
9710
9711+#define GET_CR0_INTO_RDI mov %cr0, %rdi
9712+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
9713+#define GET_CR3_INTO_RDI mov %cr3, %rdi
9714+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
9715+
9716 #else
9717 #define INTERRUPT_RETURN iret
9718 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
9719diff -urNp linux-2.6.39.1/arch/x86/include/asm/kprobes.h linux-2.6.39.1/arch/x86/include/asm/kprobes.h
9720--- linux-2.6.39.1/arch/x86/include/asm/kprobes.h 2011-05-19 00:06:34.000000000 -0400
9721+++ linux-2.6.39.1/arch/x86/include/asm/kprobes.h 2011-05-22 19:36:30.000000000 -0400
9722@@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
9723 #define RELATIVEJUMP_SIZE 5
9724 #define RELATIVECALL_OPCODE 0xe8
9725 #define RELATIVE_ADDR_SIZE 4
9726-#define MAX_STACK_SIZE 64
9727-#define MIN_STACK_SIZE(ADDR) \
9728- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
9729- THREAD_SIZE - (unsigned long)(ADDR))) \
9730- ? (MAX_STACK_SIZE) \
9731- : (((unsigned long)current_thread_info()) + \
9732- THREAD_SIZE - (unsigned long)(ADDR)))
9733+#define MAX_STACK_SIZE 64UL
9734+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
9735
9736 #define flush_insn_slot(p) do { } while (0)
9737
9738diff -urNp linux-2.6.39.1/arch/x86/include/asm/kvm_host.h linux-2.6.39.1/arch/x86/include/asm/kvm_host.h
9739--- linux-2.6.39.1/arch/x86/include/asm/kvm_host.h 2011-05-19 00:06:34.000000000 -0400
9740+++ linux-2.6.39.1/arch/x86/include/asm/kvm_host.h 2011-05-22 19:36:30.000000000 -0400
9741@@ -419,7 +419,7 @@ struct kvm_arch {
9742 unsigned int n_used_mmu_pages;
9743 unsigned int n_requested_mmu_pages;
9744 unsigned int n_max_mmu_pages;
9745- atomic_t invlpg_counter;
9746+ atomic_unchecked_t invlpg_counter;
9747 struct hlist_head mmu_page_hash[KVM_NUM_MMU_PAGES];
9748 /*
9749 * Hash table of struct kvm_mmu_page.
9750@@ -599,7 +599,7 @@ struct kvm_arch_async_pf {
9751 bool direct_map;
9752 };
9753
9754-extern struct kvm_x86_ops *kvm_x86_ops;
9755+extern const struct kvm_x86_ops *kvm_x86_ops;
9756
9757 int kvm_mmu_module_init(void);
9758 void kvm_mmu_module_exit(void);
9759diff -urNp linux-2.6.39.1/arch/x86/include/asm/local.h linux-2.6.39.1/arch/x86/include/asm/local.h
9760--- linux-2.6.39.1/arch/x86/include/asm/local.h 2011-05-19 00:06:34.000000000 -0400
9761+++ linux-2.6.39.1/arch/x86/include/asm/local.h 2011-05-22 19:36:30.000000000 -0400
9762@@ -18,26 +18,58 @@ typedef struct {
9763
9764 static inline void local_inc(local_t *l)
9765 {
9766- asm volatile(_ASM_INC "%0"
9767+ asm volatile(_ASM_INC "%0\n"
9768+
9769+#ifdef CONFIG_PAX_REFCOUNT
9770+ "jno 0f\n"
9771+ _ASM_DEC "%0\n"
9772+ "int $4\n0:\n"
9773+ _ASM_EXTABLE(0b, 0b)
9774+#endif
9775+
9776 : "+m" (l->a.counter));
9777 }
9778
9779 static inline void local_dec(local_t *l)
9780 {
9781- asm volatile(_ASM_DEC "%0"
9782+ asm volatile(_ASM_DEC "%0\n"
9783+
9784+#ifdef CONFIG_PAX_REFCOUNT
9785+ "jno 0f\n"
9786+ _ASM_INC "%0\n"
9787+ "int $4\n0:\n"
9788+ _ASM_EXTABLE(0b, 0b)
9789+#endif
9790+
9791 : "+m" (l->a.counter));
9792 }
9793
9794 static inline void local_add(long i, local_t *l)
9795 {
9796- asm volatile(_ASM_ADD "%1,%0"
9797+ asm volatile(_ASM_ADD "%1,%0\n"
9798+
9799+#ifdef CONFIG_PAX_REFCOUNT
9800+ "jno 0f\n"
9801+ _ASM_SUB "%1,%0\n"
9802+ "int $4\n0:\n"
9803+ _ASM_EXTABLE(0b, 0b)
9804+#endif
9805+
9806 : "+m" (l->a.counter)
9807 : "ir" (i));
9808 }
9809
9810 static inline void local_sub(long i, local_t *l)
9811 {
9812- asm volatile(_ASM_SUB "%1,%0"
9813+ asm volatile(_ASM_SUB "%1,%0\n"
9814+
9815+#ifdef CONFIG_PAX_REFCOUNT
9816+ "jno 0f\n"
9817+ _ASM_ADD "%1,%0\n"
9818+ "int $4\n0:\n"
9819+ _ASM_EXTABLE(0b, 0b)
9820+#endif
9821+
9822 : "+m" (l->a.counter)
9823 : "ir" (i));
9824 }
9825@@ -55,7 +87,16 @@ static inline int local_sub_and_test(lon
9826 {
9827 unsigned char c;
9828
9829- asm volatile(_ASM_SUB "%2,%0; sete %1"
9830+ asm volatile(_ASM_SUB "%2,%0\n"
9831+
9832+#ifdef CONFIG_PAX_REFCOUNT
9833+ "jno 0f\n"
9834+ _ASM_ADD "%2,%0\n"
9835+ "int $4\n0:\n"
9836+ _ASM_EXTABLE(0b, 0b)
9837+#endif
9838+
9839+ "sete %1\n"
9840 : "+m" (l->a.counter), "=qm" (c)
9841 : "ir" (i) : "memory");
9842 return c;
9843@@ -73,7 +114,16 @@ static inline int local_dec_and_test(loc
9844 {
9845 unsigned char c;
9846
9847- asm volatile(_ASM_DEC "%0; sete %1"
9848+ asm volatile(_ASM_DEC "%0\n"
9849+
9850+#ifdef CONFIG_PAX_REFCOUNT
9851+ "jno 0f\n"
9852+ _ASM_INC "%0\n"
9853+ "int $4\n0:\n"
9854+ _ASM_EXTABLE(0b, 0b)
9855+#endif
9856+
9857+ "sete %1\n"
9858 : "+m" (l->a.counter), "=qm" (c)
9859 : : "memory");
9860 return c != 0;
9861@@ -91,7 +141,16 @@ static inline int local_inc_and_test(loc
9862 {
9863 unsigned char c;
9864
9865- asm volatile(_ASM_INC "%0; sete %1"
9866+ asm volatile(_ASM_INC "%0\n"
9867+
9868+#ifdef CONFIG_PAX_REFCOUNT
9869+ "jno 0f\n"
9870+ _ASM_DEC "%0\n"
9871+ "int $4\n0:\n"
9872+ _ASM_EXTABLE(0b, 0b)
9873+#endif
9874+
9875+ "sete %1\n"
9876 : "+m" (l->a.counter), "=qm" (c)
9877 : : "memory");
9878 return c != 0;
9879@@ -110,7 +169,16 @@ static inline int local_add_negative(lon
9880 {
9881 unsigned char c;
9882
9883- asm volatile(_ASM_ADD "%2,%0; sets %1"
9884+ asm volatile(_ASM_ADD "%2,%0\n"
9885+
9886+#ifdef CONFIG_PAX_REFCOUNT
9887+ "jno 0f\n"
9888+ _ASM_SUB "%2,%0\n"
9889+ "int $4\n0:\n"
9890+ _ASM_EXTABLE(0b, 0b)
9891+#endif
9892+
9893+ "sets %1\n"
9894 : "+m" (l->a.counter), "=qm" (c)
9895 : "ir" (i) : "memory");
9896 return c;
9897@@ -133,7 +201,15 @@ static inline long local_add_return(long
9898 #endif
9899 /* Modern 486+ processor */
9900 __i = i;
9901- asm volatile(_ASM_XADD "%0, %1;"
9902+ asm volatile(_ASM_XADD "%0, %1\n"
9903+
9904+#ifdef CONFIG_PAX_REFCOUNT
9905+ "jno 0f\n"
9906+ _ASM_MOV "%0,%1\n"
9907+ "int $4\n0:\n"
9908+ _ASM_EXTABLE(0b, 0b)
9909+#endif
9910+
9911 : "+r" (i), "+m" (l->a.counter)
9912 : : "memory");
9913 return i + __i;
9914diff -urNp linux-2.6.39.1/arch/x86/include/asm/mce.h linux-2.6.39.1/arch/x86/include/asm/mce.h
9915--- linux-2.6.39.1/arch/x86/include/asm/mce.h 2011-05-19 00:06:34.000000000 -0400
9916+++ linux-2.6.39.1/arch/x86/include/asm/mce.h 2011-05-22 19:36:30.000000000 -0400
9917@@ -198,7 +198,7 @@ int mce_notify_irq(void);
9918 void mce_notify_process(void);
9919
9920 DECLARE_PER_CPU(struct mce, injectm);
9921-extern struct file_operations mce_chrdev_ops;
9922+extern struct file_operations mce_chrdev_ops; /* cannot be const, see arch/x86/kernel/cpu/mcheck/mce. */
9923
9924 /*
9925 * Exception handler
9926diff -urNp linux-2.6.39.1/arch/x86/include/asm/microcode.h linux-2.6.39.1/arch/x86/include/asm/microcode.h
9927--- linux-2.6.39.1/arch/x86/include/asm/microcode.h 2011-05-19 00:06:34.000000000 -0400
9928+++ linux-2.6.39.1/arch/x86/include/asm/microcode.h 2011-05-22 19:36:30.000000000 -0400
9929@@ -12,13 +12,13 @@ struct device;
9930 enum ucode_state { UCODE_ERROR, UCODE_OK, UCODE_NFOUND };
9931
9932 struct microcode_ops {
9933- enum ucode_state (*request_microcode_user) (int cpu,
9934+ enum ucode_state (* const request_microcode_user) (int cpu,
9935 const void __user *buf, size_t size);
9936
9937- enum ucode_state (*request_microcode_fw) (int cpu,
9938+ enum ucode_state (* const request_microcode_fw) (int cpu,
9939 struct device *device);
9940
9941- void (*microcode_fini_cpu) (int cpu);
9942+ void (* const microcode_fini_cpu) (int cpu);
9943
9944 /*
9945 * The generic 'microcode_core' part guarantees that
9946@@ -38,16 +38,16 @@ struct ucode_cpu_info {
9947 extern struct ucode_cpu_info ucode_cpu_info[];
9948
9949 #ifdef CONFIG_MICROCODE_INTEL
9950-extern struct microcode_ops * __init init_intel_microcode(void);
9951+extern const struct microcode_ops * __init init_intel_microcode(void);
9952 #else
9953-static inline struct microcode_ops * __init init_intel_microcode(void)
9954+static inline const struct microcode_ops * __init init_intel_microcode(void)
9955 {
9956 return NULL;
9957 }
9958 #endif /* CONFIG_MICROCODE_INTEL */
9959
9960 #ifdef CONFIG_MICROCODE_AMD
9961-extern struct microcode_ops * __init init_amd_microcode(void);
9962+extern const struct microcode_ops * __init init_amd_microcode(void);
9963
9964 static inline void get_ucode_data(void *to, const u8 *from, size_t n)
9965 {
9966@@ -55,7 +55,7 @@ static inline void get_ucode_data(void *
9967 }
9968
9969 #else
9970-static inline struct microcode_ops * __init init_amd_microcode(void)
9971+static inline const struct microcode_ops * __init init_amd_microcode(void)
9972 {
9973 return NULL;
9974 }
9975diff -urNp linux-2.6.39.1/arch/x86/include/asm/mman.h linux-2.6.39.1/arch/x86/include/asm/mman.h
9976--- linux-2.6.39.1/arch/x86/include/asm/mman.h 2011-05-19 00:06:34.000000000 -0400
9977+++ linux-2.6.39.1/arch/x86/include/asm/mman.h 2011-05-22 19:36:30.000000000 -0400
9978@@ -5,4 +5,14 @@
9979
9980 #include <asm-generic/mman.h>
9981
9982+#ifdef __KERNEL__
9983+#ifndef __ASSEMBLY__
9984+#ifdef CONFIG_X86_32
9985+#define arch_mmap_check i386_mmap_check
9986+int i386_mmap_check(unsigned long addr, unsigned long len,
9987+ unsigned long flags);
9988+#endif
9989+#endif
9990+#endif
9991+
9992 #endif /* _ASM_X86_MMAN_H */
9993diff -urNp linux-2.6.39.1/arch/x86/include/asm/mmu_context.h linux-2.6.39.1/arch/x86/include/asm/mmu_context.h
9994--- linux-2.6.39.1/arch/x86/include/asm/mmu_context.h 2011-05-19 00:06:34.000000000 -0400
9995+++ linux-2.6.39.1/arch/x86/include/asm/mmu_context.h 2011-05-22 19:36:30.000000000 -0400
9996@@ -24,6 +24,21 @@ void destroy_context(struct mm_struct *m
9997
9998 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
9999 {
10000+
10001+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10002+ unsigned int i;
10003+ pgd_t *pgd;
10004+
10005+ pax_open_kernel();
10006+ pgd = get_cpu_pgd(smp_processor_id());
10007+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
10008+ if (paravirt_enabled())
10009+ set_pgd(pgd+i, native_make_pgd(0));
10010+ else
10011+ pgd[i] = native_make_pgd(0);
10012+ pax_close_kernel();
10013+#endif
10014+
10015 #ifdef CONFIG_SMP
10016 if (percpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
10017 percpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
10018@@ -34,16 +49,30 @@ static inline void switch_mm(struct mm_s
10019 struct task_struct *tsk)
10020 {
10021 unsigned cpu = smp_processor_id();
10022+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP)
10023+ int tlbstate = TLBSTATE_OK;
10024+#endif
10025
10026 if (likely(prev != next)) {
10027 #ifdef CONFIG_SMP
10028+#ifdef CONFIG_X86_32
10029+ tlbstate = percpu_read(cpu_tlbstate.state);
10030+#endif
10031 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10032 percpu_write(cpu_tlbstate.active_mm, next);
10033 #endif
10034 cpumask_set_cpu(cpu, mm_cpumask(next));
10035
10036 /* Re-load page tables */
10037+#ifdef CONFIG_PAX_PER_CPU_PGD
10038+ pax_open_kernel();
10039+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
10040+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
10041+ pax_close_kernel();
10042+ load_cr3(get_cpu_pgd(cpu));
10043+#else
10044 load_cr3(next->pgd);
10045+#endif
10046
10047 /* stop flush ipis for the previous mm */
10048 cpumask_clear_cpu(cpu, mm_cpumask(prev));
10049@@ -53,9 +82,38 @@ static inline void switch_mm(struct mm_s
10050 */
10051 if (unlikely(prev->context.ldt != next->context.ldt))
10052 load_LDT_nolock(&next->context);
10053- }
10054+
10055+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10056+ if (!(__supported_pte_mask & _PAGE_NX)) {
10057+ smp_mb__before_clear_bit();
10058+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
10059+ smp_mb__after_clear_bit();
10060+ cpu_set(cpu, next->context.cpu_user_cs_mask);
10061+ }
10062+#endif
10063+
10064+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10065+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
10066+ prev->context.user_cs_limit != next->context.user_cs_limit))
10067+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10068 #ifdef CONFIG_SMP
10069+ else if (unlikely(tlbstate != TLBSTATE_OK))
10070+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10071+#endif
10072+#endif
10073+
10074+ }
10075 else {
10076+
10077+#ifdef CONFIG_PAX_PER_CPU_PGD
10078+ pax_open_kernel();
10079+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
10080+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
10081+ pax_close_kernel();
10082+ load_cr3(get_cpu_pgd(cpu));
10083+#endif
10084+
10085+#ifdef CONFIG_SMP
10086 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10087 BUG_ON(percpu_read(cpu_tlbstate.active_mm) != next);
10088
10089@@ -64,11 +122,28 @@ static inline void switch_mm(struct mm_s
10090 * tlb flush IPI delivery. We must reload CR3
10091 * to make sure to use no freed page tables.
10092 */
10093+
10094+#ifndef CONFIG_PAX_PER_CPU_PGD
10095 load_cr3(next->pgd);
10096+#endif
10097+
10098 load_LDT_nolock(&next->context);
10099+
10100+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
10101+ if (!(__supported_pte_mask & _PAGE_NX))
10102+ cpu_set(cpu, next->context.cpu_user_cs_mask);
10103+#endif
10104+
10105+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10106+#ifdef CONFIG_PAX_PAGEEXEC
10107+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
10108+#endif
10109+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10110+#endif
10111+
10112 }
10113- }
10114 #endif
10115+ }
10116 }
10117
10118 #define activate_mm(prev, next) \
10119diff -urNp linux-2.6.39.1/arch/x86/include/asm/mmu.h linux-2.6.39.1/arch/x86/include/asm/mmu.h
10120--- linux-2.6.39.1/arch/x86/include/asm/mmu.h 2011-05-19 00:06:34.000000000 -0400
10121+++ linux-2.6.39.1/arch/x86/include/asm/mmu.h 2011-05-22 19:36:30.000000000 -0400
10122@@ -9,10 +9,22 @@
10123 * we put the segment information here.
10124 */
10125 typedef struct {
10126- void *ldt;
10127+ struct desc_struct *ldt;
10128 int size;
10129 struct mutex lock;
10130- void *vdso;
10131+ unsigned long vdso;
10132+
10133+#ifdef CONFIG_X86_32
10134+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10135+ unsigned long user_cs_base;
10136+ unsigned long user_cs_limit;
10137+
10138+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10139+ cpumask_t cpu_user_cs_mask;
10140+#endif
10141+
10142+#endif
10143+#endif
10144
10145 #ifdef CONFIG_X86_64
10146 /* True if mm supports a task running in 32 bit compatibility mode. */
10147diff -urNp linux-2.6.39.1/arch/x86/include/asm/module.h linux-2.6.39.1/arch/x86/include/asm/module.h
10148--- linux-2.6.39.1/arch/x86/include/asm/module.h 2011-05-19 00:06:34.000000000 -0400
10149+++ linux-2.6.39.1/arch/x86/include/asm/module.h 2011-05-22 19:41:32.000000000 -0400
10150@@ -5,6 +5,7 @@
10151
10152 #ifdef CONFIG_X86_64
10153 /* X86_64 does not define MODULE_PROC_FAMILY */
10154+#define MODULE_PROC_FAMILY ""
10155 #elif defined CONFIG_M386
10156 #define MODULE_PROC_FAMILY "386 "
10157 #elif defined CONFIG_M486
10158@@ -59,8 +60,30 @@
10159 #error unknown processor family
10160 #endif
10161
10162-#ifdef CONFIG_X86_32
10163-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
10164+#ifdef CONFIG_PAX_MEMORY_UDEREF
10165+#define MODULE_PAX_UDEREF "UDEREF "
10166+#else
10167+#define MODULE_PAX_UDEREF ""
10168+#endif
10169+
10170+#ifdef CONFIG_PAX_KERNEXEC
10171+#define MODULE_PAX_KERNEXEC "KERNEXEC "
10172+#else
10173+#define MODULE_PAX_KERNEXEC ""
10174 #endif
10175
10176+#ifdef CONFIG_PAX_REFCOUNT
10177+#define MODULE_PAX_REFCOUNT "REFCOUNT "
10178+#else
10179+#define MODULE_PAX_REFCOUNT ""
10180+#endif
10181+
10182+#ifdef CONFIG_GRKERNSEC
10183+#define MODULE_GRSEC "GRSECURITY "
10184+#else
10185+#define MODULE_GRSEC ""
10186+#endif
10187+
10188+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_GRSEC MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF MODULE_PAX_REFCOUNT
10189+
10190 #endif /* _ASM_X86_MODULE_H */
10191diff -urNp linux-2.6.39.1/arch/x86/include/asm/page_64_types.h linux-2.6.39.1/arch/x86/include/asm/page_64_types.h
10192--- linux-2.6.39.1/arch/x86/include/asm/page_64_types.h 2011-05-19 00:06:34.000000000 -0400
10193+++ linux-2.6.39.1/arch/x86/include/asm/page_64_types.h 2011-05-22 19:36:30.000000000 -0400
10194@@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
10195
10196 /* duplicated to the one in bootmem.h */
10197 extern unsigned long max_pfn;
10198-extern unsigned long phys_base;
10199+extern const unsigned long phys_base;
10200
10201 extern unsigned long __phys_addr(unsigned long);
10202 #define __phys_reloc_hide(x) (x)
10203diff -urNp linux-2.6.39.1/arch/x86/include/asm/paravirt.h linux-2.6.39.1/arch/x86/include/asm/paravirt.h
10204--- linux-2.6.39.1/arch/x86/include/asm/paravirt.h 2011-05-19 00:06:34.000000000 -0400
10205+++ linux-2.6.39.1/arch/x86/include/asm/paravirt.h 2011-05-22 19:36:30.000000000 -0400
10206@@ -739,6 +739,21 @@ static inline void __set_fixmap(unsigned
10207 pv_mmu_ops.set_fixmap(idx, phys, flags);
10208 }
10209
10210+#ifdef CONFIG_PAX_KERNEXEC
10211+static inline unsigned long pax_open_kernel(void)
10212+{
10213+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
10214+}
10215+
10216+static inline unsigned long pax_close_kernel(void)
10217+{
10218+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
10219+}
10220+#else
10221+static inline unsigned long pax_open_kernel(void) { return 0; }
10222+static inline unsigned long pax_close_kernel(void) { return 0; }
10223+#endif
10224+
10225 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
10226
10227 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
10228@@ -955,7 +970,7 @@ extern void default_banner(void);
10229
10230 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
10231 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
10232-#define PARA_INDIRECT(addr) *%cs:addr
10233+#define PARA_INDIRECT(addr) *%ss:addr
10234 #endif
10235
10236 #define INTERRUPT_RETURN \
10237@@ -1032,6 +1047,21 @@ extern void default_banner(void);
10238 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
10239 CLBR_NONE, \
10240 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
10241+
10242+#define GET_CR0_INTO_RDI \
10243+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
10244+ mov %rax,%rdi
10245+
10246+#define SET_RDI_INTO_CR0 \
10247+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
10248+
10249+#define GET_CR3_INTO_RDI \
10250+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
10251+ mov %rax,%rdi
10252+
10253+#define SET_RDI_INTO_CR3 \
10254+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
10255+
10256 #endif /* CONFIG_X86_32 */
10257
10258 #endif /* __ASSEMBLY__ */
10259diff -urNp linux-2.6.39.1/arch/x86/include/asm/paravirt_types.h linux-2.6.39.1/arch/x86/include/asm/paravirt_types.h
10260--- linux-2.6.39.1/arch/x86/include/asm/paravirt_types.h 2011-05-19 00:06:34.000000000 -0400
10261+++ linux-2.6.39.1/arch/x86/include/asm/paravirt_types.h 2011-05-22 19:36:30.000000000 -0400
10262@@ -317,6 +317,12 @@ struct pv_mmu_ops {
10263 an mfn. We can tell which is which from the index. */
10264 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
10265 phys_addr_t phys, pgprot_t flags);
10266+
10267+#ifdef CONFIG_PAX_KERNEXEC
10268+ unsigned long (*pax_open_kernel)(void);
10269+ unsigned long (*pax_close_kernel)(void);
10270+#endif
10271+
10272 };
10273
10274 struct arch_spinlock;
10275diff -urNp linux-2.6.39.1/arch/x86/include/asm/pci_x86.h linux-2.6.39.1/arch/x86/include/asm/pci_x86.h
10276--- linux-2.6.39.1/arch/x86/include/asm/pci_x86.h 2011-05-19 00:06:34.000000000 -0400
10277+++ linux-2.6.39.1/arch/x86/include/asm/pci_x86.h 2011-05-22 19:36:30.000000000 -0400
10278@@ -93,16 +93,16 @@ extern int (*pcibios_enable_irq)(struct
10279 extern void (*pcibios_disable_irq)(struct pci_dev *dev);
10280
10281 struct pci_raw_ops {
10282- int (*read)(unsigned int domain, unsigned int bus, unsigned int devfn,
10283+ int (* const read)(unsigned int domain, unsigned int bus, unsigned int devfn,
10284 int reg, int len, u32 *val);
10285- int (*write)(unsigned int domain, unsigned int bus, unsigned int devfn,
10286+ int (* const write)(unsigned int domain, unsigned int bus, unsigned int devfn,
10287 int reg, int len, u32 val);
10288 };
10289
10290-extern struct pci_raw_ops *raw_pci_ops;
10291-extern struct pci_raw_ops *raw_pci_ext_ops;
10292+extern const struct pci_raw_ops *raw_pci_ops;
10293+extern const struct pci_raw_ops *raw_pci_ext_ops;
10294
10295-extern struct pci_raw_ops pci_direct_conf1;
10296+extern const struct pci_raw_ops pci_direct_conf1;
10297 extern bool port_cf9_safe;
10298
10299 /* arch_initcall level */
10300diff -urNp linux-2.6.39.1/arch/x86/include/asm/pgalloc.h linux-2.6.39.1/arch/x86/include/asm/pgalloc.h
10301--- linux-2.6.39.1/arch/x86/include/asm/pgalloc.h 2011-05-19 00:06:34.000000000 -0400
10302+++ linux-2.6.39.1/arch/x86/include/asm/pgalloc.h 2011-05-22 19:36:30.000000000 -0400
10303@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(s
10304 pmd_t *pmd, pte_t *pte)
10305 {
10306 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
10307+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
10308+}
10309+
10310+static inline void pmd_populate_user(struct mm_struct *mm,
10311+ pmd_t *pmd, pte_t *pte)
10312+{
10313+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
10314 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
10315 }
10316
10317diff -urNp linux-2.6.39.1/arch/x86/include/asm/pgtable-2level.h linux-2.6.39.1/arch/x86/include/asm/pgtable-2level.h
10318--- linux-2.6.39.1/arch/x86/include/asm/pgtable-2level.h 2011-05-19 00:06:34.000000000 -0400
10319+++ linux-2.6.39.1/arch/x86/include/asm/pgtable-2level.h 2011-05-22 19:36:30.000000000 -0400
10320@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t
10321
10322 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
10323 {
10324+ pax_open_kernel();
10325 *pmdp = pmd;
10326+ pax_close_kernel();
10327 }
10328
10329 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
10330diff -urNp linux-2.6.39.1/arch/x86/include/asm/pgtable_32.h linux-2.6.39.1/arch/x86/include/asm/pgtable_32.h
10331--- linux-2.6.39.1/arch/x86/include/asm/pgtable_32.h 2011-05-19 00:06:34.000000000 -0400
10332+++ linux-2.6.39.1/arch/x86/include/asm/pgtable_32.h 2011-05-22 19:36:30.000000000 -0400
10333@@ -25,9 +25,6 @@
10334 struct mm_struct;
10335 struct vm_area_struct;
10336
10337-extern pgd_t swapper_pg_dir[1024];
10338-extern pgd_t initial_page_table[1024];
10339-
10340 static inline void pgtable_cache_init(void) { }
10341 static inline void check_pgt_cache(void) { }
10342 void paging_init(void);
10343@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, u
10344 # include <asm/pgtable-2level.h>
10345 #endif
10346
10347+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
10348+extern pgd_t initial_page_table[PTRS_PER_PGD];
10349+#ifdef CONFIG_X86_PAE
10350+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
10351+#endif
10352+
10353 #if defined(CONFIG_HIGHPTE)
10354 #define pte_offset_map(dir, address) \
10355 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
10356@@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, u
10357 /* Clear a kernel PTE and flush it from the TLB */
10358 #define kpte_clear_flush(ptep, vaddr) \
10359 do { \
10360+ pax_open_kernel(); \
10361 pte_clear(&init_mm, (vaddr), (ptep)); \
10362+ pax_close_kernel(); \
10363 __flush_tlb_one((vaddr)); \
10364 } while (0)
10365
10366@@ -74,6 +79,9 @@ do { \
10367
10368 #endif /* !__ASSEMBLY__ */
10369
10370+#define HAVE_ARCH_UNMAPPED_AREA
10371+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
10372+
10373 /*
10374 * kern_addr_valid() is (1) for FLATMEM and (0) for
10375 * SPARSEMEM and DISCONTIGMEM
10376diff -urNp linux-2.6.39.1/arch/x86/include/asm/pgtable_32_types.h linux-2.6.39.1/arch/x86/include/asm/pgtable_32_types.h
10377--- linux-2.6.39.1/arch/x86/include/asm/pgtable_32_types.h 2011-05-19 00:06:34.000000000 -0400
10378+++ linux-2.6.39.1/arch/x86/include/asm/pgtable_32_types.h 2011-05-22 19:36:30.000000000 -0400
10379@@ -8,7 +8,7 @@
10380 */
10381 #ifdef CONFIG_X86_PAE
10382 # include <asm/pgtable-3level_types.h>
10383-# define PMD_SIZE (1UL << PMD_SHIFT)
10384+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
10385 # define PMD_MASK (~(PMD_SIZE - 1))
10386 #else
10387 # include <asm/pgtable-2level_types.h>
10388@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set
10389 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
10390 #endif
10391
10392+#ifdef CONFIG_PAX_KERNEXEC
10393+#ifndef __ASSEMBLY__
10394+extern unsigned char MODULES_EXEC_VADDR[];
10395+extern unsigned char MODULES_EXEC_END[];
10396+#endif
10397+#include <asm/boot.h>
10398+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
10399+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
10400+#else
10401+#define ktla_ktva(addr) (addr)
10402+#define ktva_ktla(addr) (addr)
10403+#endif
10404+
10405 #define MODULES_VADDR VMALLOC_START
10406 #define MODULES_END VMALLOC_END
10407 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
10408diff -urNp linux-2.6.39.1/arch/x86/include/asm/pgtable-3level.h linux-2.6.39.1/arch/x86/include/asm/pgtable-3level.h
10409--- linux-2.6.39.1/arch/x86/include/asm/pgtable-3level.h 2011-05-19 00:06:34.000000000 -0400
10410+++ linux-2.6.39.1/arch/x86/include/asm/pgtable-3level.h 2011-05-22 19:36:30.000000000 -0400
10411@@ -38,12 +38,16 @@ static inline void native_set_pte_atomic
10412
10413 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
10414 {
10415+ pax_open_kernel();
10416 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
10417+ pax_close_kernel();
10418 }
10419
10420 static inline void native_set_pud(pud_t *pudp, pud_t pud)
10421 {
10422+ pax_open_kernel();
10423 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
10424+ pax_close_kernel();
10425 }
10426
10427 /*
10428diff -urNp linux-2.6.39.1/arch/x86/include/asm/pgtable_64.h linux-2.6.39.1/arch/x86/include/asm/pgtable_64.h
10429--- linux-2.6.39.1/arch/x86/include/asm/pgtable_64.h 2011-05-19 00:06:34.000000000 -0400
10430+++ linux-2.6.39.1/arch/x86/include/asm/pgtable_64.h 2011-05-22 19:36:30.000000000 -0400
10431@@ -16,10 +16,13 @@
10432
10433 extern pud_t level3_kernel_pgt[512];
10434 extern pud_t level3_ident_pgt[512];
10435+extern pud_t level3_vmalloc_pgt[512];
10436+extern pud_t level3_vmemmap_pgt[512];
10437+extern pud_t level2_vmemmap_pgt[512];
10438 extern pmd_t level2_kernel_pgt[512];
10439 extern pmd_t level2_fixmap_pgt[512];
10440-extern pmd_t level2_ident_pgt[512];
10441-extern pgd_t init_level4_pgt[];
10442+extern pmd_t level2_ident_pgt[512*2];
10443+extern pgd_t init_level4_pgt[512];
10444
10445 #define swapper_pg_dir init_level4_pgt
10446
10447@@ -61,7 +64,9 @@ static inline void native_set_pte_atomic
10448
10449 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
10450 {
10451+ pax_open_kernel();
10452 *pmdp = pmd;
10453+ pax_close_kernel();
10454 }
10455
10456 static inline void native_pmd_clear(pmd_t *pmd)
10457@@ -107,7 +112,9 @@ static inline void native_pud_clear(pud_
10458
10459 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
10460 {
10461+ pax_open_kernel();
10462 *pgdp = pgd;
10463+ pax_close_kernel();
10464 }
10465
10466 static inline void native_pgd_clear(pgd_t *pgd)
10467diff -urNp linux-2.6.39.1/arch/x86/include/asm/pgtable_64_types.h linux-2.6.39.1/arch/x86/include/asm/pgtable_64_types.h
10468--- linux-2.6.39.1/arch/x86/include/asm/pgtable_64_types.h 2011-05-19 00:06:34.000000000 -0400
10469+++ linux-2.6.39.1/arch/x86/include/asm/pgtable_64_types.h 2011-05-22 19:36:30.000000000 -0400
10470@@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
10471 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
10472 #define MODULES_END _AC(0xffffffffff000000, UL)
10473 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
10474+#define MODULES_EXEC_VADDR MODULES_VADDR
10475+#define MODULES_EXEC_END MODULES_END
10476+
10477+#define ktla_ktva(addr) (addr)
10478+#define ktva_ktla(addr) (addr)
10479
10480 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
10481diff -urNp linux-2.6.39.1/arch/x86/include/asm/pgtable.h linux-2.6.39.1/arch/x86/include/asm/pgtable.h
10482--- linux-2.6.39.1/arch/x86/include/asm/pgtable.h 2011-05-19 00:06:34.000000000 -0400
10483+++ linux-2.6.39.1/arch/x86/include/asm/pgtable.h 2011-05-22 19:36:30.000000000 -0400
10484@@ -81,12 +81,51 @@ extern struct mm_struct *pgd_page_get_mm
10485
10486 #define arch_end_context_switch(prev) do {} while(0)
10487
10488+#define pax_open_kernel() native_pax_open_kernel()
10489+#define pax_close_kernel() native_pax_close_kernel()
10490 #endif /* CONFIG_PARAVIRT */
10491
10492+#define __HAVE_ARCH_PAX_OPEN_KERNEL
10493+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
10494+
10495+#ifdef CONFIG_PAX_KERNEXEC
10496+static inline unsigned long native_pax_open_kernel(void)
10497+{
10498+ unsigned long cr0;
10499+
10500+ preempt_disable();
10501+ barrier();
10502+ cr0 = read_cr0() ^ X86_CR0_WP;
10503+ BUG_ON(unlikely(cr0 & X86_CR0_WP));
10504+ write_cr0(cr0);
10505+ return cr0 ^ X86_CR0_WP;
10506+}
10507+
10508+static inline unsigned long native_pax_close_kernel(void)
10509+{
10510+ unsigned long cr0;
10511+
10512+ cr0 = read_cr0() ^ X86_CR0_WP;
10513+ BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
10514+ write_cr0(cr0);
10515+ barrier();
10516+ preempt_enable_no_resched();
10517+ return cr0 ^ X86_CR0_WP;
10518+}
10519+#else
10520+static inline unsigned long native_pax_open_kernel(void) { return 0; }
10521+static inline unsigned long native_pax_close_kernel(void) { return 0; }
10522+#endif
10523+
10524 /*
10525 * The following only work if pte_present() is true.
10526 * Undefined behaviour if not..
10527 */
10528+static inline int pte_user(pte_t pte)
10529+{
10530+ return pte_val(pte) & _PAGE_USER;
10531+}
10532+
10533 static inline int pte_dirty(pte_t pte)
10534 {
10535 return pte_flags(pte) & _PAGE_DIRTY;
10536@@ -196,9 +235,29 @@ static inline pte_t pte_wrprotect(pte_t
10537 return pte_clear_flags(pte, _PAGE_RW);
10538 }
10539
10540+static inline pte_t pte_mkread(pte_t pte)
10541+{
10542+ return __pte(pte_val(pte) | _PAGE_USER);
10543+}
10544+
10545 static inline pte_t pte_mkexec(pte_t pte)
10546 {
10547- return pte_clear_flags(pte, _PAGE_NX);
10548+#ifdef CONFIG_X86_PAE
10549+ if (__supported_pte_mask & _PAGE_NX)
10550+ return pte_clear_flags(pte, _PAGE_NX);
10551+ else
10552+#endif
10553+ return pte_set_flags(pte, _PAGE_USER);
10554+}
10555+
10556+static inline pte_t pte_exprotect(pte_t pte)
10557+{
10558+#ifdef CONFIG_X86_PAE
10559+ if (__supported_pte_mask & _PAGE_NX)
10560+ return pte_set_flags(pte, _PAGE_NX);
10561+ else
10562+#endif
10563+ return pte_clear_flags(pte, _PAGE_USER);
10564 }
10565
10566 static inline pte_t pte_mkdirty(pte_t pte)
10567@@ -390,6 +449,15 @@ pte_t *populate_extra_pte(unsigned long
10568 #endif
10569
10570 #ifndef __ASSEMBLY__
10571+
10572+#ifdef CONFIG_PAX_PER_CPU_PGD
10573+extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
10574+static inline pgd_t *get_cpu_pgd(unsigned int cpu)
10575+{
10576+ return cpu_pgd[cpu];
10577+}
10578+#endif
10579+
10580 #include <linux/mm_types.h>
10581
10582 static inline int pte_none(pte_t pte)
10583@@ -560,7 +628,7 @@ static inline pud_t *pud_offset(pgd_t *p
10584
10585 static inline int pgd_bad(pgd_t pgd)
10586 {
10587- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
10588+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
10589 }
10590
10591 static inline int pgd_none(pgd_t pgd)
10592@@ -583,7 +651,12 @@ static inline int pgd_none(pgd_t pgd)
10593 * pgd_offset() returns a (pgd_t *)
10594 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
10595 */
10596-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
10597+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
10598+
10599+#ifdef CONFIG_PAX_PER_CPU_PGD
10600+#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
10601+#endif
10602+
10603 /*
10604 * a shortcut which implies the use of the kernel's pgd, instead
10605 * of a process's
10606@@ -594,6 +667,20 @@ static inline int pgd_none(pgd_t pgd)
10607 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
10608 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
10609
10610+#ifdef CONFIG_X86_32
10611+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
10612+#else
10613+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
10614+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
10615+
10616+#ifdef CONFIG_PAX_MEMORY_UDEREF
10617+#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
10618+#else
10619+#define PAX_USER_SHADOW_BASE (_AC(0,UL))
10620+#endif
10621+
10622+#endif
10623+
10624 #ifndef __ASSEMBLY__
10625
10626 extern int direct_gbpages;
10627@@ -758,11 +845,23 @@ static inline void pmdp_set_wrprotect(st
10628 * dst and src can be on the same page, but the range must not overlap,
10629 * and must not cross a page boundary.
10630 */
10631-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
10632+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
10633 {
10634- memcpy(dst, src, count * sizeof(pgd_t));
10635+ pax_open_kernel();
10636+ while (count--)
10637+ *dst++ = *src++;
10638+ pax_close_kernel();
10639 }
10640
10641+#ifdef CONFIG_PAX_PER_CPU_PGD
10642+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count);
10643+#endif
10644+
10645+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10646+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count);
10647+#else
10648+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count) {}
10649+#endif
10650
10651 #include <asm-generic/pgtable.h>
10652 #endif /* __ASSEMBLY__ */
10653diff -urNp linux-2.6.39.1/arch/x86/include/asm/pgtable_types.h linux-2.6.39.1/arch/x86/include/asm/pgtable_types.h
10654--- linux-2.6.39.1/arch/x86/include/asm/pgtable_types.h 2011-05-19 00:06:34.000000000 -0400
10655+++ linux-2.6.39.1/arch/x86/include/asm/pgtable_types.h 2011-05-22 19:36:30.000000000 -0400
10656@@ -16,13 +16,12 @@
10657 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
10658 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
10659 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
10660-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
10661+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
10662 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
10663 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
10664 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
10665-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
10666-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
10667-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
10668+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
10669+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
10670 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
10671
10672 /* If _PAGE_BIT_PRESENT is clear, we use these: */
10673@@ -40,7 +39,6 @@
10674 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
10675 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
10676 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
10677-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
10678 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
10679 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
10680 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
10681@@ -57,8 +55,10 @@
10682
10683 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
10684 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
10685-#else
10686+#elif defined(CONFIG_KMEMCHECK)
10687 #define _PAGE_NX (_AT(pteval_t, 0))
10688+#else
10689+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
10690 #endif
10691
10692 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
10693@@ -96,6 +96,9 @@
10694 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
10695 _PAGE_ACCESSED)
10696
10697+#define PAGE_READONLY_NOEXEC PAGE_READONLY
10698+#define PAGE_SHARED_NOEXEC PAGE_SHARED
10699+
10700 #define __PAGE_KERNEL_EXEC \
10701 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
10702 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
10703@@ -106,8 +109,8 @@
10704 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
10705 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
10706 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
10707-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
10708-#define __PAGE_KERNEL_VSYSCALL_NOCACHE (__PAGE_KERNEL_VSYSCALL | _PAGE_PCD | _PAGE_PWT)
10709+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
10710+#define __PAGE_KERNEL_VSYSCALL_NOCACHE (__PAGE_KERNEL_RO | _PAGE_PCD | _PAGE_PWT | _PAGE_USER)
10711 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
10712 #define __PAGE_KERNEL_LARGE_NOCACHE (__PAGE_KERNEL | _PAGE_CACHE_UC | _PAGE_PSE)
10713 #define __PAGE_KERNEL_LARGE_EXEC (__PAGE_KERNEL_EXEC | _PAGE_PSE)
10714@@ -166,8 +169,8 @@
10715 * bits are combined, this will alow user to access the high address mapped
10716 * VDSO in the presence of CONFIG_COMPAT_VDSO
10717 */
10718-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
10719-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
10720+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
10721+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
10722 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
10723 #endif
10724
10725@@ -205,7 +208,17 @@ static inline pgdval_t pgd_flags(pgd_t p
10726 {
10727 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
10728 }
10729+#endif
10730
10731+#if PAGETABLE_LEVELS == 3
10732+#include <asm-generic/pgtable-nopud.h>
10733+#endif
10734+
10735+#if PAGETABLE_LEVELS == 2
10736+#include <asm-generic/pgtable-nopmd.h>
10737+#endif
10738+
10739+#ifndef __ASSEMBLY__
10740 #if PAGETABLE_LEVELS > 3
10741 typedef struct { pudval_t pud; } pud_t;
10742
10743@@ -219,8 +232,6 @@ static inline pudval_t native_pud_val(pu
10744 return pud.pud;
10745 }
10746 #else
10747-#include <asm-generic/pgtable-nopud.h>
10748-
10749 static inline pudval_t native_pud_val(pud_t pud)
10750 {
10751 return native_pgd_val(pud.pgd);
10752@@ -240,8 +251,6 @@ static inline pmdval_t native_pmd_val(pm
10753 return pmd.pmd;
10754 }
10755 #else
10756-#include <asm-generic/pgtable-nopmd.h>
10757-
10758 static inline pmdval_t native_pmd_val(pmd_t pmd)
10759 {
10760 return native_pgd_val(pmd.pud.pgd);
10761@@ -281,7 +290,6 @@ typedef struct page *pgtable_t;
10762
10763 extern pteval_t __supported_pte_mask;
10764 extern void set_nx(void);
10765-extern int nx_enabled;
10766
10767 #define pgprot_writecombine pgprot_writecombine
10768 extern pgprot_t pgprot_writecombine(pgprot_t prot);
10769diff -urNp linux-2.6.39.1/arch/x86/include/asm/processor.h linux-2.6.39.1/arch/x86/include/asm/processor.h
10770--- linux-2.6.39.1/arch/x86/include/asm/processor.h 2011-05-19 00:06:34.000000000 -0400
10771+++ linux-2.6.39.1/arch/x86/include/asm/processor.h 2011-05-22 19:36:30.000000000 -0400
10772@@ -266,7 +266,7 @@ struct tss_struct {
10773
10774 } ____cacheline_aligned;
10775
10776-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
10777+extern struct tss_struct init_tss[NR_CPUS];
10778
10779 /*
10780 * Save the original ist values for checking stack pointers during debugging
10781@@ -860,11 +860,18 @@ static inline void spin_lock_prefetch(co
10782 */
10783 #define TASK_SIZE PAGE_OFFSET
10784 #define TASK_SIZE_MAX TASK_SIZE
10785+
10786+#ifdef CONFIG_PAX_SEGMEXEC
10787+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
10788+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
10789+#else
10790 #define STACK_TOP TASK_SIZE
10791-#define STACK_TOP_MAX STACK_TOP
10792+#endif
10793+
10794+#define STACK_TOP_MAX TASK_SIZE
10795
10796 #define INIT_THREAD { \
10797- .sp0 = sizeof(init_stack) + (long)&init_stack, \
10798+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
10799 .vm86_info = NULL, \
10800 .sysenter_cs = __KERNEL_CS, \
10801 .io_bitmap_ptr = NULL, \
10802@@ -878,7 +885,7 @@ static inline void spin_lock_prefetch(co
10803 */
10804 #define INIT_TSS { \
10805 .x86_tss = { \
10806- .sp0 = sizeof(init_stack) + (long)&init_stack, \
10807+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
10808 .ss0 = __KERNEL_DS, \
10809 .ss1 = __KERNEL_CS, \
10810 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
10811@@ -889,11 +896,7 @@ static inline void spin_lock_prefetch(co
10812 extern unsigned long thread_saved_pc(struct task_struct *tsk);
10813
10814 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
10815-#define KSTK_TOP(info) \
10816-({ \
10817- unsigned long *__ptr = (unsigned long *)(info); \
10818- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
10819-})
10820+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
10821
10822 /*
10823 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
10824@@ -908,7 +911,7 @@ extern unsigned long thread_saved_pc(str
10825 #define task_pt_regs(task) \
10826 ({ \
10827 struct pt_regs *__regs__; \
10828- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
10829+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
10830 __regs__ - 1; \
10831 })
10832
10833@@ -918,13 +921,13 @@ extern unsigned long thread_saved_pc(str
10834 /*
10835 * User space process size. 47bits minus one guard page.
10836 */
10837-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
10838+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
10839
10840 /* This decides where the kernel will search for a free chunk of vm
10841 * space during mmap's.
10842 */
10843 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
10844- 0xc0000000 : 0xFFFFe000)
10845+ 0xc0000000 : 0xFFFFf000)
10846
10847 #define TASK_SIZE (test_thread_flag(TIF_IA32) ? \
10848 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
10849@@ -935,11 +938,11 @@ extern unsigned long thread_saved_pc(str
10850 #define STACK_TOP_MAX TASK_SIZE_MAX
10851
10852 #define INIT_THREAD { \
10853- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
10854+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
10855 }
10856
10857 #define INIT_TSS { \
10858- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
10859+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
10860 }
10861
10862 /*
10863@@ -961,6 +964,10 @@ extern void start_thread(struct pt_regs
10864 */
10865 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
10866
10867+#ifdef CONFIG_PAX_SEGMEXEC
10868+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
10869+#endif
10870+
10871 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
10872
10873 /* Get/set a process' ability to use the timestamp counter instruction */
10874diff -urNp linux-2.6.39.1/arch/x86/include/asm/ptrace.h linux-2.6.39.1/arch/x86/include/asm/ptrace.h
10875--- linux-2.6.39.1/arch/x86/include/asm/ptrace.h 2011-05-19 00:06:34.000000000 -0400
10876+++ linux-2.6.39.1/arch/x86/include/asm/ptrace.h 2011-05-22 19:36:30.000000000 -0400
10877@@ -152,28 +152,29 @@ static inline unsigned long regs_return_
10878 }
10879
10880 /*
10881- * user_mode_vm(regs) determines whether a register set came from user mode.
10882+ * user_mode(regs) determines whether a register set came from user mode.
10883 * This is true if V8086 mode was enabled OR if the register set was from
10884 * protected mode with RPL-3 CS value. This tricky test checks that with
10885 * one comparison. Many places in the kernel can bypass this full check
10886- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
10887+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
10888+ * be used.
10889 */
10890-static inline int user_mode(struct pt_regs *regs)
10891+static inline int user_mode_novm(struct pt_regs *regs)
10892 {
10893 #ifdef CONFIG_X86_32
10894 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
10895 #else
10896- return !!(regs->cs & 3);
10897+ return !!(regs->cs & SEGMENT_RPL_MASK);
10898 #endif
10899 }
10900
10901-static inline int user_mode_vm(struct pt_regs *regs)
10902+static inline int user_mode(struct pt_regs *regs)
10903 {
10904 #ifdef CONFIG_X86_32
10905 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
10906 USER_RPL;
10907 #else
10908- return user_mode(regs);
10909+ return user_mode_novm(regs);
10910 #endif
10911 }
10912
10913diff -urNp linux-2.6.39.1/arch/x86/include/asm/reboot.h linux-2.6.39.1/arch/x86/include/asm/reboot.h
10914--- linux-2.6.39.1/arch/x86/include/asm/reboot.h 2011-05-19 00:06:34.000000000 -0400
10915+++ linux-2.6.39.1/arch/x86/include/asm/reboot.h 2011-05-22 19:36:30.000000000 -0400
10916@@ -6,19 +6,19 @@
10917 struct pt_regs;
10918
10919 struct machine_ops {
10920- void (*restart)(char *cmd);
10921- void (*halt)(void);
10922- void (*power_off)(void);
10923+ void (* __noreturn restart)(char *cmd);
10924+ void (* __noreturn halt)(void);
10925+ void (* __noreturn power_off)(void);
10926 void (*shutdown)(void);
10927 void (*crash_shutdown)(struct pt_regs *);
10928- void (*emergency_restart)(void);
10929+ void (* __noreturn emergency_restart)(void);
10930 };
10931
10932 extern struct machine_ops machine_ops;
10933
10934 void native_machine_crash_shutdown(struct pt_regs *regs);
10935 void native_machine_shutdown(void);
10936-void machine_real_restart(unsigned int type);
10937+void machine_real_restart(unsigned int type) __noreturn;
10938 /* These must match dispatch_table in reboot_32.S */
10939 #define MRR_BIOS 0
10940 #define MRR_APM 1
10941diff -urNp linux-2.6.39.1/arch/x86/include/asm/rwsem.h linux-2.6.39.1/arch/x86/include/asm/rwsem.h
10942--- linux-2.6.39.1/arch/x86/include/asm/rwsem.h 2011-05-19 00:06:34.000000000 -0400
10943+++ linux-2.6.39.1/arch/x86/include/asm/rwsem.h 2011-05-22 19:36:30.000000000 -0400
10944@@ -64,6 +64,14 @@ static inline void __down_read(struct rw
10945 {
10946 asm volatile("# beginning down_read\n\t"
10947 LOCK_PREFIX _ASM_INC "(%1)\n\t"
10948+
10949+#ifdef CONFIG_PAX_REFCOUNT
10950+ "jno 0f\n"
10951+ LOCK_PREFIX _ASM_DEC "(%1)\n"
10952+ "int $4\n0:\n"
10953+ _ASM_EXTABLE(0b, 0b)
10954+#endif
10955+
10956 /* adds 0x00000001 */
10957 " jns 1f\n"
10958 " call call_rwsem_down_read_failed\n"
10959@@ -85,6 +93,14 @@ static inline int __down_read_trylock(st
10960 "1:\n\t"
10961 " mov %1,%2\n\t"
10962 " add %3,%2\n\t"
10963+
10964+#ifdef CONFIG_PAX_REFCOUNT
10965+ "jno 0f\n"
10966+ "sub %3,%2\n"
10967+ "int $4\n0:\n"
10968+ _ASM_EXTABLE(0b, 0b)
10969+#endif
10970+
10971 " jle 2f\n\t"
10972 LOCK_PREFIX " cmpxchg %2,%0\n\t"
10973 " jnz 1b\n\t"
10974@@ -104,6 +120,14 @@ static inline void __down_write_nested(s
10975 long tmp;
10976 asm volatile("# beginning down_write\n\t"
10977 LOCK_PREFIX " xadd %1,(%2)\n\t"
10978+
10979+#ifdef CONFIG_PAX_REFCOUNT
10980+ "jno 0f\n"
10981+ "mov %1,(%2)\n"
10982+ "int $4\n0:\n"
10983+ _ASM_EXTABLE(0b, 0b)
10984+#endif
10985+
10986 /* adds 0xffff0001, returns the old value */
10987 " test %1,%1\n\t"
10988 /* was the count 0 before? */
10989@@ -141,6 +165,14 @@ static inline void __up_read(struct rw_s
10990 long tmp;
10991 asm volatile("# beginning __up_read\n\t"
10992 LOCK_PREFIX " xadd %1,(%2)\n\t"
10993+
10994+#ifdef CONFIG_PAX_REFCOUNT
10995+ "jno 0f\n"
10996+ "mov %1,(%2)\n"
10997+ "int $4\n0:\n"
10998+ _ASM_EXTABLE(0b, 0b)
10999+#endif
11000+
11001 /* subtracts 1, returns the old value */
11002 " jns 1f\n\t"
11003 " call call_rwsem_wake\n" /* expects old value in %edx */
11004@@ -159,6 +191,14 @@ static inline void __up_write(struct rw_
11005 long tmp;
11006 asm volatile("# beginning __up_write\n\t"
11007 LOCK_PREFIX " xadd %1,(%2)\n\t"
11008+
11009+#ifdef CONFIG_PAX_REFCOUNT
11010+ "jno 0f\n"
11011+ "mov %1,(%2)\n"
11012+ "int $4\n0:\n"
11013+ _ASM_EXTABLE(0b, 0b)
11014+#endif
11015+
11016 /* subtracts 0xffff0001, returns the old value */
11017 " jns 1f\n\t"
11018 " call call_rwsem_wake\n" /* expects old value in %edx */
11019@@ -176,6 +216,14 @@ static inline void __downgrade_write(str
11020 {
11021 asm volatile("# beginning __downgrade_write\n\t"
11022 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
11023+
11024+#ifdef CONFIG_PAX_REFCOUNT
11025+ "jno 0f\n"
11026+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
11027+ "int $4\n0:\n"
11028+ _ASM_EXTABLE(0b, 0b)
11029+#endif
11030+
11031 /*
11032 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
11033 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
11034@@ -194,7 +242,15 @@ static inline void __downgrade_write(str
11035 */
11036 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
11037 {
11038- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
11039+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
11040+
11041+#ifdef CONFIG_PAX_REFCOUNT
11042+ "jno 0f\n"
11043+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
11044+ "int $4\n0:\n"
11045+ _ASM_EXTABLE(0b, 0b)
11046+#endif
11047+
11048 : "+m" (sem->count)
11049 : "er" (delta));
11050 }
11051@@ -206,7 +262,15 @@ static inline long rwsem_atomic_update(l
11052 {
11053 long tmp = delta;
11054
11055- asm volatile(LOCK_PREFIX "xadd %0,%1"
11056+ asm volatile(LOCK_PREFIX "xadd %0,%1\n"
11057+
11058+#ifdef CONFIG_PAX_REFCOUNT
11059+ "jno 0f\n"
11060+ "mov %0,%1\n"
11061+ "int $4\n0:\n"
11062+ _ASM_EXTABLE(0b, 0b)
11063+#endif
11064+
11065 : "+r" (tmp), "+m" (sem->count)
11066 : : "memory");
11067
11068diff -urNp linux-2.6.39.1/arch/x86/include/asm/segment.h linux-2.6.39.1/arch/x86/include/asm/segment.h
11069--- linux-2.6.39.1/arch/x86/include/asm/segment.h 2011-05-19 00:06:34.000000000 -0400
11070+++ linux-2.6.39.1/arch/x86/include/asm/segment.h 2011-05-22 19:36:30.000000000 -0400
11071@@ -64,8 +64,8 @@
11072 * 26 - ESPFIX small SS
11073 * 27 - per-cpu [ offset to per-cpu data area ]
11074 * 28 - stack_canary-20 [ for stack protector ]
11075- * 29 - unused
11076- * 30 - unused
11077+ * 29 - PCI BIOS CS
11078+ * 30 - PCI BIOS DS
11079 * 31 - TSS for double fault handler
11080 */
11081 #define GDT_ENTRY_TLS_MIN 6
11082@@ -79,6 +79,8 @@
11083
11084 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
11085
11086+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
11087+
11088 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
11089
11090 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
11091@@ -104,6 +106,12 @@
11092 #define __KERNEL_STACK_CANARY 0
11093 #endif
11094
11095+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
11096+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
11097+
11098+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
11099+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
11100+
11101 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
11102
11103 /*
11104@@ -141,7 +149,7 @@
11105 */
11106
11107 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
11108-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
11109+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
11110
11111
11112 #else
11113@@ -165,6 +173,8 @@
11114 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS * 8 + 3)
11115 #define __USER32_DS __USER_DS
11116
11117+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
11118+
11119 #define GDT_ENTRY_TSS 8 /* needs two entries */
11120 #define GDT_ENTRY_LDT 10 /* needs two entries */
11121 #define GDT_ENTRY_TLS_MIN 12
11122@@ -185,6 +195,7 @@
11123 #endif
11124
11125 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
11126+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
11127 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
11128 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
11129 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
11130diff -urNp linux-2.6.39.1/arch/x86/include/asm/smp.h linux-2.6.39.1/arch/x86/include/asm/smp.h
11131--- linux-2.6.39.1/arch/x86/include/asm/smp.h 2011-05-19 00:06:34.000000000 -0400
11132+++ linux-2.6.39.1/arch/x86/include/asm/smp.h 2011-05-22 19:36:30.000000000 -0400
11133@@ -36,7 +36,7 @@ DECLARE_PER_CPU(cpumask_var_t, cpu_core_
11134 /* cpus sharing the last level cache: */
11135 DECLARE_PER_CPU(cpumask_var_t, cpu_llc_shared_map);
11136 DECLARE_PER_CPU(u16, cpu_llc_id);
11137-DECLARE_PER_CPU(int, cpu_number);
11138+DECLARE_PER_CPU(unsigned int, cpu_number);
11139
11140 static inline struct cpumask *cpu_sibling_mask(int cpu)
11141 {
11142@@ -192,14 +192,8 @@ extern unsigned disabled_cpus __cpuinitd
11143 extern int safe_smp_processor_id(void);
11144
11145 #elif defined(CONFIG_X86_64_SMP)
11146-#define raw_smp_processor_id() (percpu_read(cpu_number))
11147-
11148-#define stack_smp_processor_id() \
11149-({ \
11150- struct thread_info *ti; \
11151- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
11152- ti->cpu; \
11153-})
11154+#define raw_smp_processor_id() (percpu_read(cpu_number))
11155+#define stack_smp_processor_id() raw_smp_processor_id()
11156 #define safe_smp_processor_id() smp_processor_id()
11157
11158 #endif
11159diff -urNp linux-2.6.39.1/arch/x86/include/asm/spinlock.h linux-2.6.39.1/arch/x86/include/asm/spinlock.h
11160--- linux-2.6.39.1/arch/x86/include/asm/spinlock.h 2011-05-19 00:06:34.000000000 -0400
11161+++ linux-2.6.39.1/arch/x86/include/asm/spinlock.h 2011-05-22 19:36:30.000000000 -0400
11162@@ -249,6 +249,14 @@ static inline int arch_write_can_lock(ar
11163 static inline void arch_read_lock(arch_rwlock_t *rw)
11164 {
11165 asm volatile(LOCK_PREFIX " subl $1,(%0)\n\t"
11166+
11167+#ifdef CONFIG_PAX_REFCOUNT
11168+ "jno 0f\n"
11169+ LOCK_PREFIX " addl $1,(%0)\n"
11170+ "int $4\n0:\n"
11171+ _ASM_EXTABLE(0b, 0b)
11172+#endif
11173+
11174 "jns 1f\n"
11175 "call __read_lock_failed\n\t"
11176 "1:\n"
11177@@ -258,6 +266,14 @@ static inline void arch_read_lock(arch_r
11178 static inline void arch_write_lock(arch_rwlock_t *rw)
11179 {
11180 asm volatile(LOCK_PREFIX " subl %1,(%0)\n\t"
11181+
11182+#ifdef CONFIG_PAX_REFCOUNT
11183+ "jno 0f\n"
11184+ LOCK_PREFIX " addl %1,(%0)\n"
11185+ "int $4\n0:\n"
11186+ _ASM_EXTABLE(0b, 0b)
11187+#endif
11188+
11189 "jz 1f\n"
11190 "call __write_lock_failed\n\t"
11191 "1:\n"
11192@@ -286,12 +302,29 @@ static inline int arch_write_trylock(arc
11193
11194 static inline void arch_read_unlock(arch_rwlock_t *rw)
11195 {
11196- asm volatile(LOCK_PREFIX "incl %0" :"+m" (rw->lock) : : "memory");
11197+ asm volatile(LOCK_PREFIX "incl %0\n"
11198+
11199+#ifdef CONFIG_PAX_REFCOUNT
11200+ "jno 0f\n"
11201+ LOCK_PREFIX "decl %0\n"
11202+ "int $4\n0:\n"
11203+ _ASM_EXTABLE(0b, 0b)
11204+#endif
11205+
11206+ :"+m" (rw->lock) : : "memory");
11207 }
11208
11209 static inline void arch_write_unlock(arch_rwlock_t *rw)
11210 {
11211- asm volatile(LOCK_PREFIX "addl %1, %0"
11212+ asm volatile(LOCK_PREFIX "addl %1, %0\n"
11213+
11214+#ifdef CONFIG_PAX_REFCOUNT
11215+ "jno 0f\n"
11216+ LOCK_PREFIX "subl %1, %0\n"
11217+ "int $4\n0:\n"
11218+ _ASM_EXTABLE(0b, 0b)
11219+#endif
11220+
11221 : "+m" (rw->lock) : "i" (RW_LOCK_BIAS) : "memory");
11222 }
11223
11224diff -urNp linux-2.6.39.1/arch/x86/include/asm/stackprotector.h linux-2.6.39.1/arch/x86/include/asm/stackprotector.h
11225--- linux-2.6.39.1/arch/x86/include/asm/stackprotector.h 2011-05-19 00:06:34.000000000 -0400
11226+++ linux-2.6.39.1/arch/x86/include/asm/stackprotector.h 2011-05-22 19:36:30.000000000 -0400
11227@@ -113,7 +113,7 @@ static inline void setup_stack_canary_se
11228
11229 static inline void load_stack_canary_segment(void)
11230 {
11231-#ifdef CONFIG_X86_32
11232+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
11233 asm volatile ("mov %0, %%gs" : : "r" (0));
11234 #endif
11235 }
11236diff -urNp linux-2.6.39.1/arch/x86/include/asm/stacktrace.h linux-2.6.39.1/arch/x86/include/asm/stacktrace.h
11237--- linux-2.6.39.1/arch/x86/include/asm/stacktrace.h 2011-05-19 00:06:34.000000000 -0400
11238+++ linux-2.6.39.1/arch/x86/include/asm/stacktrace.h 2011-05-22 19:36:30.000000000 -0400
11239@@ -11,28 +11,20 @@
11240
11241 extern int kstack_depth_to_print;
11242
11243-struct thread_info;
11244+struct task_struct;
11245 struct stacktrace_ops;
11246
11247-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
11248- unsigned long *stack,
11249- unsigned long bp,
11250- const struct stacktrace_ops *ops,
11251- void *data,
11252- unsigned long *end,
11253- int *graph);
11254-
11255-extern unsigned long
11256-print_context_stack(struct thread_info *tinfo,
11257- unsigned long *stack, unsigned long bp,
11258- const struct stacktrace_ops *ops, void *data,
11259- unsigned long *end, int *graph);
11260-
11261-extern unsigned long
11262-print_context_stack_bp(struct thread_info *tinfo,
11263- unsigned long *stack, unsigned long bp,
11264- const struct stacktrace_ops *ops, void *data,
11265- unsigned long *end, int *graph);
11266+typedef unsigned long walk_stack_t(struct task_struct *task,
11267+ void *stack_start,
11268+ unsigned long *stack,
11269+ unsigned long bp,
11270+ const struct stacktrace_ops *ops,
11271+ void *data,
11272+ unsigned long *end,
11273+ int *graph);
11274+
11275+extern walk_stack_t print_context_stack;
11276+extern walk_stack_t print_context_stack_bp;
11277
11278 /* Generic stack tracer with callbacks */
11279
11280@@ -43,7 +35,7 @@ struct stacktrace_ops {
11281 void (*address)(void *data, unsigned long address, int reliable);
11282 /* On negative return stop dumping */
11283 int (*stack)(void *data, char *name);
11284- walk_stack_t walk_stack;
11285+ walk_stack_t *walk_stack;
11286 };
11287
11288 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
11289diff -urNp linux-2.6.39.1/arch/x86/include/asm/system.h linux-2.6.39.1/arch/x86/include/asm/system.h
11290--- linux-2.6.39.1/arch/x86/include/asm/system.h 2011-05-19 00:06:34.000000000 -0400
11291+++ linux-2.6.39.1/arch/x86/include/asm/system.h 2011-05-22 19:36:30.000000000 -0400
11292@@ -129,7 +129,7 @@ do { \
11293 "call __switch_to\n\t" \
11294 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
11295 __switch_canary \
11296- "movq %P[thread_info](%%rsi),%%r8\n\t" \
11297+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
11298 "movq %%rax,%%rdi\n\t" \
11299 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
11300 "jnz ret_from_fork\n\t" \
11301@@ -140,7 +140,7 @@ do { \
11302 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
11303 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
11304 [_tif_fork] "i" (_TIF_FORK), \
11305- [thread_info] "i" (offsetof(struct task_struct, stack)), \
11306+ [thread_info] "m" (current_tinfo), \
11307 [current_task] "m" (current_task) \
11308 __switch_canary_iparam \
11309 : "memory", "cc" __EXTRA_CLOBBER)
11310@@ -200,7 +200,7 @@ static inline unsigned long get_limit(un
11311 {
11312 unsigned long __limit;
11313 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
11314- return __limit + 1;
11315+ return __limit;
11316 }
11317
11318 static inline void native_clts(void)
11319@@ -340,12 +340,12 @@ void enable_hlt(void);
11320
11321 void cpu_idle_wait(void);
11322
11323-extern unsigned long arch_align_stack(unsigned long sp);
11324+#define arch_align_stack(x) ((x) & ~0xfUL)
11325 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
11326
11327 void default_idle(void);
11328
11329-void stop_this_cpu(void *dummy);
11330+void stop_this_cpu(void *dummy) __noreturn;
11331
11332 /*
11333 * Force strict CPU ordering.
11334diff -urNp linux-2.6.39.1/arch/x86/include/asm/thread_info.h linux-2.6.39.1/arch/x86/include/asm/thread_info.h
11335--- linux-2.6.39.1/arch/x86/include/asm/thread_info.h 2011-05-19 00:06:34.000000000 -0400
11336+++ linux-2.6.39.1/arch/x86/include/asm/thread_info.h 2011-05-22 19:36:30.000000000 -0400
11337@@ -10,6 +10,7 @@
11338 #include <linux/compiler.h>
11339 #include <asm/page.h>
11340 #include <asm/types.h>
11341+#include <asm/percpu.h>
11342
11343 /*
11344 * low level task data that entry.S needs immediate access to
11345@@ -24,7 +25,6 @@ struct exec_domain;
11346 #include <asm/atomic.h>
11347
11348 struct thread_info {
11349- struct task_struct *task; /* main task structure */
11350 struct exec_domain *exec_domain; /* execution domain */
11351 __u32 flags; /* low level flags */
11352 __u32 status; /* thread synchronous flags */
11353@@ -34,18 +34,12 @@ struct thread_info {
11354 mm_segment_t addr_limit;
11355 struct restart_block restart_block;
11356 void __user *sysenter_return;
11357-#ifdef CONFIG_X86_32
11358- unsigned long previous_esp; /* ESP of the previous stack in
11359- case of nested (IRQ) stacks
11360- */
11361- __u8 supervisor_stack[0];
11362-#endif
11363+ unsigned long lowest_stack;
11364 int uaccess_err;
11365 };
11366
11367-#define INIT_THREAD_INFO(tsk) \
11368+#define INIT_THREAD_INFO \
11369 { \
11370- .task = &tsk, \
11371 .exec_domain = &default_exec_domain, \
11372 .flags = 0, \
11373 .cpu = 0, \
11374@@ -56,7 +50,7 @@ struct thread_info {
11375 }, \
11376 }
11377
11378-#define init_thread_info (init_thread_union.thread_info)
11379+#define init_thread_info (init_thread_union.stack)
11380 #define init_stack (init_thread_union.stack)
11381
11382 #else /* !__ASSEMBLY__ */
11383@@ -170,6 +164,23 @@ struct thread_info {
11384 ret; \
11385 })
11386
11387+#ifdef __ASSEMBLY__
11388+/* how to get the thread information struct from ASM */
11389+#define GET_THREAD_INFO(reg) \
11390+ mov PER_CPU_VAR(current_tinfo), reg
11391+
11392+/* use this one if reg already contains %esp */
11393+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
11394+#else
11395+/* how to get the thread information struct from C */
11396+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
11397+
11398+static __always_inline struct thread_info *current_thread_info(void)
11399+{
11400+ return percpu_read_stable(current_tinfo);
11401+}
11402+#endif
11403+
11404 #ifdef CONFIG_X86_32
11405
11406 #define STACK_WARN (THREAD_SIZE/8)
11407@@ -180,35 +191,13 @@ struct thread_info {
11408 */
11409 #ifndef __ASSEMBLY__
11410
11411-
11412 /* how to get the current stack pointer from C */
11413 register unsigned long current_stack_pointer asm("esp") __used;
11414
11415-/* how to get the thread information struct from C */
11416-static inline struct thread_info *current_thread_info(void)
11417-{
11418- return (struct thread_info *)
11419- (current_stack_pointer & ~(THREAD_SIZE - 1));
11420-}
11421-
11422-#else /* !__ASSEMBLY__ */
11423-
11424-/* how to get the thread information struct from ASM */
11425-#define GET_THREAD_INFO(reg) \
11426- movl $-THREAD_SIZE, reg; \
11427- andl %esp, reg
11428-
11429-/* use this one if reg already contains %esp */
11430-#define GET_THREAD_INFO_WITH_ESP(reg) \
11431- andl $-THREAD_SIZE, reg
11432-
11433 #endif
11434
11435 #else /* X86_32 */
11436
11437-#include <asm/percpu.h>
11438-#define KERNEL_STACK_OFFSET (5*8)
11439-
11440 /*
11441 * macros/functions for gaining access to the thread information structure
11442 * preempt_count needs to be 1 initially, until the scheduler is functional.
11443@@ -216,21 +205,8 @@ static inline struct thread_info *curren
11444 #ifndef __ASSEMBLY__
11445 DECLARE_PER_CPU(unsigned long, kernel_stack);
11446
11447-static inline struct thread_info *current_thread_info(void)
11448-{
11449- struct thread_info *ti;
11450- ti = (void *)(percpu_read_stable(kernel_stack) +
11451- KERNEL_STACK_OFFSET - THREAD_SIZE);
11452- return ti;
11453-}
11454-
11455-#else /* !__ASSEMBLY__ */
11456-
11457-/* how to get the thread information struct from ASM */
11458-#define GET_THREAD_INFO(reg) \
11459- movq PER_CPU_VAR(kernel_stack),reg ; \
11460- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
11461-
11462+/* how to get the current stack pointer from C */
11463+register unsigned long current_stack_pointer asm("rsp") __used;
11464 #endif
11465
11466 #endif /* !X86_32 */
11467@@ -266,5 +242,16 @@ extern void arch_task_cache_init(void);
11468 extern void free_thread_info(struct thread_info *ti);
11469 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
11470 #define arch_task_cache_init arch_task_cache_init
11471+
11472+#define __HAVE_THREAD_FUNCTIONS
11473+#define task_thread_info(task) (&(task)->tinfo)
11474+#define task_stack_page(task) ((task)->stack)
11475+#define setup_thread_stack(p, org) do {} while (0)
11476+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
11477+
11478+#define __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
11479+extern struct task_struct *alloc_task_struct_node(int node);
11480+extern void free_task_struct(struct task_struct *);
11481+
11482 #endif
11483 #endif /* _ASM_X86_THREAD_INFO_H */
11484diff -urNp linux-2.6.39.1/arch/x86/include/asm/uaccess_32.h linux-2.6.39.1/arch/x86/include/asm/uaccess_32.h
11485--- linux-2.6.39.1/arch/x86/include/asm/uaccess_32.h 2011-05-19 00:06:34.000000000 -0400
11486+++ linux-2.6.39.1/arch/x86/include/asm/uaccess_32.h 2011-05-22 19:36:30.000000000 -0400
11487@@ -44,6 +44,11 @@ unsigned long __must_check __copy_from_u
11488 static __always_inline unsigned long __must_check
11489 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
11490 {
11491+ pax_track_stack();
11492+
11493+ if ((long)n < 0)
11494+ return n;
11495+
11496 if (__builtin_constant_p(n)) {
11497 unsigned long ret;
11498
11499@@ -62,6 +67,8 @@ __copy_to_user_inatomic(void __user *to,
11500 return ret;
11501 }
11502 }
11503+ if (!__builtin_constant_p(n))
11504+ check_object_size(from, n, true);
11505 return __copy_to_user_ll(to, from, n);
11506 }
11507
11508@@ -83,12 +90,16 @@ static __always_inline unsigned long __m
11509 __copy_to_user(void __user *to, const void *from, unsigned long n)
11510 {
11511 might_fault();
11512+
11513 return __copy_to_user_inatomic(to, from, n);
11514 }
11515
11516 static __always_inline unsigned long
11517 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
11518 {
11519+ if ((long)n < 0)
11520+ return n;
11521+
11522 /* Avoid zeroing the tail if the copy fails..
11523 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
11524 * but as the zeroing behaviour is only significant when n is not
11525@@ -138,6 +149,12 @@ static __always_inline unsigned long
11526 __copy_from_user(void *to, const void __user *from, unsigned long n)
11527 {
11528 might_fault();
11529+
11530+ pax_track_stack();
11531+
11532+ if ((long)n < 0)
11533+ return n;
11534+
11535 if (__builtin_constant_p(n)) {
11536 unsigned long ret;
11537
11538@@ -153,6 +170,8 @@ __copy_from_user(void *to, const void __
11539 return ret;
11540 }
11541 }
11542+ if (!__builtin_constant_p(n))
11543+ check_object_size(to, n, false);
11544 return __copy_from_user_ll(to, from, n);
11545 }
11546
11547@@ -160,6 +179,10 @@ static __always_inline unsigned long __c
11548 const void __user *from, unsigned long n)
11549 {
11550 might_fault();
11551+
11552+ if ((long)n < 0)
11553+ return n;
11554+
11555 if (__builtin_constant_p(n)) {
11556 unsigned long ret;
11557
11558@@ -182,15 +205,19 @@ static __always_inline unsigned long
11559 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
11560 unsigned long n)
11561 {
11562- return __copy_from_user_ll_nocache_nozero(to, from, n);
11563-}
11564+ if ((long)n < 0)
11565+ return n;
11566
11567-unsigned long __must_check copy_to_user(void __user *to,
11568- const void *from, unsigned long n);
11569-unsigned long __must_check _copy_from_user(void *to,
11570- const void __user *from,
11571- unsigned long n);
11572+ return __copy_from_user_ll_nocache_nozero(to, from, n);
11573+}
11574
11575+extern void copy_to_user_overflow(void)
11576+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
11577+ __compiletime_error("copy_to_user() buffer size is not provably correct")
11578+#else
11579+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
11580+#endif
11581+;
11582
11583 extern void copy_from_user_overflow(void)
11584 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
11585@@ -200,17 +227,61 @@ extern void copy_from_user_overflow(void
11586 #endif
11587 ;
11588
11589-static inline unsigned long __must_check copy_from_user(void *to,
11590- const void __user *from,
11591- unsigned long n)
11592+/**
11593+ * copy_to_user: - Copy a block of data into user space.
11594+ * @to: Destination address, in user space.
11595+ * @from: Source address, in kernel space.
11596+ * @n: Number of bytes to copy.
11597+ *
11598+ * Context: User context only. This function may sleep.
11599+ *
11600+ * Copy data from kernel space to user space.
11601+ *
11602+ * Returns number of bytes that could not be copied.
11603+ * On success, this will be zero.
11604+ */
11605+static inline unsigned long __must_check
11606+copy_to_user(void __user *to, const void *from, unsigned long n)
11607+{
11608+ int sz = __compiletime_object_size(from);
11609+
11610+ if (unlikely(sz != -1 && sz < n))
11611+ copy_to_user_overflow();
11612+ else if (access_ok(VERIFY_WRITE, to, n))
11613+ n = __copy_to_user(to, from, n);
11614+ return n;
11615+}
11616+
11617+/**
11618+ * copy_from_user: - Copy a block of data from user space.
11619+ * @to: Destination address, in kernel space.
11620+ * @from: Source address, in user space.
11621+ * @n: Number of bytes to copy.
11622+ *
11623+ * Context: User context only. This function may sleep.
11624+ *
11625+ * Copy data from user space to kernel space.
11626+ *
11627+ * Returns number of bytes that could not be copied.
11628+ * On success, this will be zero.
11629+ *
11630+ * If some data could not be copied, this function will pad the copied
11631+ * data to the requested size using zero bytes.
11632+ */
11633+static inline unsigned long __must_check
11634+copy_from_user(void *to, const void __user *from, unsigned long n)
11635 {
11636 int sz = __compiletime_object_size(to);
11637
11638- if (likely(sz == -1 || sz >= n))
11639- n = _copy_from_user(to, from, n);
11640- else
11641+ if (unlikely(sz != -1 && sz < n))
11642 copy_from_user_overflow();
11643-
11644+ else if (access_ok(VERIFY_READ, from, n))
11645+ n = __copy_from_user(to, from, n);
11646+ else if ((long)n > 0) {
11647+ if (!__builtin_constant_p(n))
11648+ check_object_size(to, n, false);
11649+ memset(to, 0, n);
11650+ }
11651 return n;
11652 }
11653
11654diff -urNp linux-2.6.39.1/arch/x86/include/asm/uaccess_64.h linux-2.6.39.1/arch/x86/include/asm/uaccess_64.h
11655--- linux-2.6.39.1/arch/x86/include/asm/uaccess_64.h 2011-05-19 00:06:34.000000000 -0400
11656+++ linux-2.6.39.1/arch/x86/include/asm/uaccess_64.h 2011-05-22 19:36:30.000000000 -0400
11657@@ -11,6 +11,9 @@
11658 #include <asm/alternative.h>
11659 #include <asm/cpufeature.h>
11660 #include <asm/page.h>
11661+#include <asm/pgtable.h>
11662+
11663+#define set_fs(x) (current_thread_info()->addr_limit = (x))
11664
11665 /*
11666 * Copy To/From Userspace
11667@@ -37,26 +40,26 @@ copy_user_generic(void *to, const void *
11668 return ret;
11669 }
11670
11671-__must_check unsigned long
11672-_copy_to_user(void __user *to, const void *from, unsigned len);
11673-__must_check unsigned long
11674-_copy_from_user(void *to, const void __user *from, unsigned len);
11675+static __always_inline __must_check unsigned long
11676+__copy_to_user(void __user *to, const void *from, unsigned len);
11677+static __always_inline __must_check unsigned long
11678+__copy_from_user(void *to, const void __user *from, unsigned len);
11679 __must_check unsigned long
11680 copy_in_user(void __user *to, const void __user *from, unsigned len);
11681
11682 static inline unsigned long __must_check copy_from_user(void *to,
11683 const void __user *from,
11684- unsigned long n)
11685+ unsigned n)
11686 {
11687- int sz = __compiletime_object_size(to);
11688-
11689 might_fault();
11690- if (likely(sz == -1 || sz >= n))
11691- n = _copy_from_user(to, from, n);
11692-#ifdef CONFIG_DEBUG_VM
11693- else
11694- WARN(1, "Buffer overflow detected!\n");
11695-#endif
11696+
11697+ if (access_ok(VERIFY_READ, from, n))
11698+ n = __copy_from_user(to, from, n);
11699+ else if ((int)n > 0) {
11700+ if (!__builtin_constant_p(n))
11701+ check_object_size(to, n, false);
11702+ memset(to, 0, n);
11703+ }
11704 return n;
11705 }
11706
11707@@ -65,110 +68,198 @@ int copy_to_user(void __user *dst, const
11708 {
11709 might_fault();
11710
11711- return _copy_to_user(dst, src, size);
11712+ if (access_ok(VERIFY_WRITE, dst, size))
11713+ size = __copy_to_user(dst, src, size);
11714+ return size;
11715 }
11716
11717 static __always_inline __must_check
11718-int __copy_from_user(void *dst, const void __user *src, unsigned size)
11719+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned size)
11720 {
11721- int ret = 0;
11722+ int sz = __compiletime_object_size(dst);
11723+ unsigned ret = 0;
11724
11725 might_fault();
11726- if (!__builtin_constant_p(size))
11727- return copy_user_generic(dst, (__force void *)src, size);
11728+
11729+ pax_track_stack();
11730+
11731+ if ((int)size < 0)
11732+ return size;
11733+
11734+#ifdef CONFIG_PAX_MEMORY_UDEREF
11735+ if (!__access_ok(VERIFY_READ, src, size))
11736+ return size;
11737+#endif
11738+
11739+ if (unlikely(sz != -1 && sz < size)) {
11740+#ifdef CONFIG_DEBUG_VM
11741+ WARN(1, "Buffer overflow detected!\n");
11742+#endif
11743+ return size;
11744+ }
11745+
11746+ if (!__builtin_constant_p(size)) {
11747+ check_object_size(dst, size, false);
11748+
11749+#ifdef CONFIG_PAX_MEMORY_UDEREF
11750+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
11751+ src += PAX_USER_SHADOW_BASE;
11752+#endif
11753+
11754+ return copy_user_generic(dst, (__force const void *)src, size);
11755+ }
11756 switch (size) {
11757- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
11758+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
11759 ret, "b", "b", "=q", 1);
11760 return ret;
11761- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
11762+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
11763 ret, "w", "w", "=r", 2);
11764 return ret;
11765- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
11766+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
11767 ret, "l", "k", "=r", 4);
11768 return ret;
11769- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
11770+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
11771 ret, "q", "", "=r", 8);
11772 return ret;
11773 case 10:
11774- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
11775+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
11776 ret, "q", "", "=r", 10);
11777 if (unlikely(ret))
11778 return ret;
11779 __get_user_asm(*(u16 *)(8 + (char *)dst),
11780- (u16 __user *)(8 + (char __user *)src),
11781+ (const u16 __user *)(8 + (const char __user *)src),
11782 ret, "w", "w", "=r", 2);
11783 return ret;
11784 case 16:
11785- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
11786+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
11787 ret, "q", "", "=r", 16);
11788 if (unlikely(ret))
11789 return ret;
11790 __get_user_asm(*(u64 *)(8 + (char *)dst),
11791- (u64 __user *)(8 + (char __user *)src),
11792+ (const u64 __user *)(8 + (const char __user *)src),
11793 ret, "q", "", "=r", 8);
11794 return ret;
11795 default:
11796- return copy_user_generic(dst, (__force void *)src, size);
11797+
11798+#ifdef CONFIG_PAX_MEMORY_UDEREF
11799+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
11800+ src += PAX_USER_SHADOW_BASE;
11801+#endif
11802+
11803+ return copy_user_generic(dst, (__force const void *)src, size);
11804 }
11805 }
11806
11807 static __always_inline __must_check
11808-int __copy_to_user(void __user *dst, const void *src, unsigned size)
11809+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned size)
11810 {
11811- int ret = 0;
11812+ int sz = __compiletime_object_size(src);
11813+ unsigned ret = 0;
11814
11815 might_fault();
11816- if (!__builtin_constant_p(size))
11817+
11818+ pax_track_stack();
11819+
11820+ if ((int)size < 0)
11821+ return size;
11822+
11823+#ifdef CONFIG_PAX_MEMORY_UDEREF
11824+ if (!__access_ok(VERIFY_WRITE, dst, size))
11825+ return size;
11826+#endif
11827+
11828+ if (unlikely(sz != -1 && sz < size)) {
11829+#ifdef CONFIG_DEBUG_VM
11830+ WARN(1, "Buffer overflow detected!\n");
11831+#endif
11832+ return size;
11833+ }
11834+
11835+ if (!__builtin_constant_p(size)) {
11836+ check_object_size(src, size, true);
11837+
11838+#ifdef CONFIG_PAX_MEMORY_UDEREF
11839+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
11840+ dst += PAX_USER_SHADOW_BASE;
11841+#endif
11842+
11843 return copy_user_generic((__force void *)dst, src, size);
11844+ }
11845 switch (size) {
11846- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
11847+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
11848 ret, "b", "b", "iq", 1);
11849 return ret;
11850- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
11851+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
11852 ret, "w", "w", "ir", 2);
11853 return ret;
11854- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
11855+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
11856 ret, "l", "k", "ir", 4);
11857 return ret;
11858- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
11859+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
11860 ret, "q", "", "er", 8);
11861 return ret;
11862 case 10:
11863- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
11864+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
11865 ret, "q", "", "er", 10);
11866 if (unlikely(ret))
11867 return ret;
11868 asm("":::"memory");
11869- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
11870+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
11871 ret, "w", "w", "ir", 2);
11872 return ret;
11873 case 16:
11874- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
11875+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
11876 ret, "q", "", "er", 16);
11877 if (unlikely(ret))
11878 return ret;
11879 asm("":::"memory");
11880- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
11881+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
11882 ret, "q", "", "er", 8);
11883 return ret;
11884 default:
11885+
11886+#ifdef CONFIG_PAX_MEMORY_UDEREF
11887+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
11888+ dst += PAX_USER_SHADOW_BASE;
11889+#endif
11890+
11891 return copy_user_generic((__force void *)dst, src, size);
11892 }
11893 }
11894
11895 static __always_inline __must_check
11896-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
11897+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
11898 {
11899- int ret = 0;
11900+ unsigned ret = 0;
11901
11902 might_fault();
11903- if (!__builtin_constant_p(size))
11904+
11905+ if ((int)size < 0)
11906+ return size;
11907+
11908+#ifdef CONFIG_PAX_MEMORY_UDEREF
11909+ if (!__access_ok(VERIFY_READ, src, size))
11910+ return size;
11911+ if (!__access_ok(VERIFY_WRITE, dst, size))
11912+ return size;
11913+#endif
11914+
11915+ if (!__builtin_constant_p(size)) {
11916+
11917+#ifdef CONFIG_PAX_MEMORY_UDEREF
11918+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
11919+ src += PAX_USER_SHADOW_BASE;
11920+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
11921+ dst += PAX_USER_SHADOW_BASE;
11922+#endif
11923+
11924 return copy_user_generic((__force void *)dst,
11925- (__force void *)src, size);
11926+ (__force const void *)src, size);
11927+ }
11928 switch (size) {
11929 case 1: {
11930 u8 tmp;
11931- __get_user_asm(tmp, (u8 __user *)src,
11932+ __get_user_asm(tmp, (const u8 __user *)src,
11933 ret, "b", "b", "=q", 1);
11934 if (likely(!ret))
11935 __put_user_asm(tmp, (u8 __user *)dst,
11936@@ -177,7 +268,7 @@ int __copy_in_user(void __user *dst, con
11937 }
11938 case 2: {
11939 u16 tmp;
11940- __get_user_asm(tmp, (u16 __user *)src,
11941+ __get_user_asm(tmp, (const u16 __user *)src,
11942 ret, "w", "w", "=r", 2);
11943 if (likely(!ret))
11944 __put_user_asm(tmp, (u16 __user *)dst,
11945@@ -187,7 +278,7 @@ int __copy_in_user(void __user *dst, con
11946
11947 case 4: {
11948 u32 tmp;
11949- __get_user_asm(tmp, (u32 __user *)src,
11950+ __get_user_asm(tmp, (const u32 __user *)src,
11951 ret, "l", "k", "=r", 4);
11952 if (likely(!ret))
11953 __put_user_asm(tmp, (u32 __user *)dst,
11954@@ -196,7 +287,7 @@ int __copy_in_user(void __user *dst, con
11955 }
11956 case 8: {
11957 u64 tmp;
11958- __get_user_asm(tmp, (u64 __user *)src,
11959+ __get_user_asm(tmp, (const u64 __user *)src,
11960 ret, "q", "", "=r", 8);
11961 if (likely(!ret))
11962 __put_user_asm(tmp, (u64 __user *)dst,
11963@@ -204,8 +295,16 @@ int __copy_in_user(void __user *dst, con
11964 return ret;
11965 }
11966 default:
11967+
11968+#ifdef CONFIG_PAX_MEMORY_UDEREF
11969+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
11970+ src += PAX_USER_SHADOW_BASE;
11971+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
11972+ dst += PAX_USER_SHADOW_BASE;
11973+#endif
11974+
11975 return copy_user_generic((__force void *)dst,
11976- (__force void *)src, size);
11977+ (__force const void *)src, size);
11978 }
11979 }
11980
11981@@ -222,33 +321,72 @@ __must_check unsigned long __clear_user(
11982 static __must_check __always_inline int
11983 __copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
11984 {
11985+ pax_track_stack();
11986+
11987+ if ((int)size < 0)
11988+ return size;
11989+
11990+#ifdef CONFIG_PAX_MEMORY_UDEREF
11991+ if (!__access_ok(VERIFY_READ, src, size))
11992+ return size;
11993+
11994+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
11995+ src += PAX_USER_SHADOW_BASE;
11996+#endif
11997+
11998 return copy_user_generic(dst, (__force const void *)src, size);
11999 }
12000
12001-static __must_check __always_inline int
12002+static __must_check __always_inline unsigned long
12003 __copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
12004 {
12005+ if ((int)size < 0)
12006+ return size;
12007+
12008+#ifdef CONFIG_PAX_MEMORY_UDEREF
12009+ if (!__access_ok(VERIFY_WRITE, dst, size))
12010+ return size;
12011+
12012+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12013+ dst += PAX_USER_SHADOW_BASE;
12014+#endif
12015+
12016 return copy_user_generic((__force void *)dst, src, size);
12017 }
12018
12019-extern long __copy_user_nocache(void *dst, const void __user *src,
12020+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
12021 unsigned size, int zerorest);
12022
12023-static inline int
12024-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
12025+static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
12026 {
12027 might_sleep();
12028+
12029+ if ((int)size < 0)
12030+ return size;
12031+
12032+#ifdef CONFIG_PAX_MEMORY_UDEREF
12033+ if (!__access_ok(VERIFY_READ, src, size))
12034+ return size;
12035+#endif
12036+
12037 return __copy_user_nocache(dst, src, size, 1);
12038 }
12039
12040-static inline int
12041-__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
12042+static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
12043 unsigned size)
12044 {
12045+ if ((int)size < 0)
12046+ return size;
12047+
12048+#ifdef CONFIG_PAX_MEMORY_UDEREF
12049+ if (!__access_ok(VERIFY_READ, src, size))
12050+ return size;
12051+#endif
12052+
12053 return __copy_user_nocache(dst, src, size, 0);
12054 }
12055
12056-unsigned long
12057+extern unsigned long
12058 copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
12059
12060 #endif /* _ASM_X86_UACCESS_64_H */
12061diff -urNp linux-2.6.39.1/arch/x86/include/asm/uaccess.h linux-2.6.39.1/arch/x86/include/asm/uaccess.h
12062--- linux-2.6.39.1/arch/x86/include/asm/uaccess.h 2011-06-03 00:04:13.000000000 -0400
12063+++ linux-2.6.39.1/arch/x86/include/asm/uaccess.h 2011-06-03 00:32:04.000000000 -0400
12064@@ -8,12 +8,15 @@
12065 #include <linux/thread_info.h>
12066 #include <linux/prefetch.h>
12067 #include <linux/string.h>
12068+#include <linux/sched.h>
12069 #include <asm/asm.h>
12070 #include <asm/page.h>
12071
12072 #define VERIFY_READ 0
12073 #define VERIFY_WRITE 1
12074
12075+extern void check_object_size(const void *ptr, unsigned long n, bool to);
12076+
12077 /*
12078 * The fs value determines whether argument validity checking should be
12079 * performed or not. If get_fs() == USER_DS, checking is performed, with
12080@@ -29,7 +32,12 @@
12081
12082 #define get_ds() (KERNEL_DS)
12083 #define get_fs() (current_thread_info()->addr_limit)
12084+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12085+void __set_fs(mm_segment_t x);
12086+void set_fs(mm_segment_t x);
12087+#else
12088 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12089+#endif
12090
12091 #define segment_eq(a, b) ((a).seg == (b).seg)
12092
12093@@ -77,7 +85,33 @@
12094 * checks that the pointer is in the user space range - after calling
12095 * this function, memory access functions may still return -EFAULT.
12096 */
12097-#define access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12098+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12099+#define access_ok(type, addr, size) \
12100+({ \
12101+ long __size = size; \
12102+ unsigned long __addr = (unsigned long)addr; \
12103+ unsigned long __addr_ao = __addr & PAGE_MASK; \
12104+ unsigned long __end_ao = __addr + __size - 1; \
12105+ bool __ret_ao = __range_not_ok(__addr, __size) == 0; \
12106+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12107+ while(__addr_ao <= __end_ao) { \
12108+ char __c_ao; \
12109+ __addr_ao += PAGE_SIZE; \
12110+ if (__size > PAGE_SIZE) \
12111+ cond_resched(); \
12112+ if (__get_user(__c_ao, (char __user *)__addr)) \
12113+ break; \
12114+ if (type != VERIFY_WRITE) { \
12115+ __addr = __addr_ao; \
12116+ continue; \
12117+ } \
12118+ if (__put_user(__c_ao, (char __user *)__addr)) \
12119+ break; \
12120+ __addr = __addr_ao; \
12121+ } \
12122+ } \
12123+ __ret_ao; \
12124+})
12125
12126 /*
12127 * The exception table consists of pairs of addresses: the first is the
12128@@ -183,12 +217,20 @@ extern int __get_user_bad(void);
12129 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12130 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12131
12132-
12133+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12134+#define __copyuser_seg "gs;"
12135+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12136+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12137+#else
12138+#define __copyuser_seg
12139+#define __COPYUSER_SET_ES
12140+#define __COPYUSER_RESTORE_ES
12141+#endif
12142
12143 #ifdef CONFIG_X86_32
12144 #define __put_user_asm_u64(x, addr, err, errret) \
12145- asm volatile("1: movl %%eax,0(%2)\n" \
12146- "2: movl %%edx,4(%2)\n" \
12147+ asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12148+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12149 "3:\n" \
12150 ".section .fixup,\"ax\"\n" \
12151 "4: movl %3,%0\n" \
12152@@ -200,8 +242,8 @@ extern int __get_user_bad(void);
12153 : "A" (x), "r" (addr), "i" (errret), "0" (err))
12154
12155 #define __put_user_asm_ex_u64(x, addr) \
12156- asm volatile("1: movl %%eax,0(%1)\n" \
12157- "2: movl %%edx,4(%1)\n" \
12158+ asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12159+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12160 "3:\n" \
12161 _ASM_EXTABLE(1b, 2b - 1b) \
12162 _ASM_EXTABLE(2b, 3b - 2b) \
12163@@ -374,7 +416,7 @@ do { \
12164 } while (0)
12165
12166 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12167- asm volatile("1: mov"itype" %2,%"rtype"1\n" \
12168+ asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12169 "2:\n" \
12170 ".section .fixup,\"ax\"\n" \
12171 "3: mov %3,%0\n" \
12172@@ -382,7 +424,7 @@ do { \
12173 " jmp 2b\n" \
12174 ".previous\n" \
12175 _ASM_EXTABLE(1b, 3b) \
12176- : "=r" (err), ltype(x) \
12177+ : "=r" (err), ltype (x) \
12178 : "m" (__m(addr)), "i" (errret), "0" (err))
12179
12180 #define __get_user_size_ex(x, ptr, size) \
12181@@ -407,7 +449,7 @@ do { \
12182 } while (0)
12183
12184 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12185- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12186+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12187 "2:\n" \
12188 _ASM_EXTABLE(1b, 2b - 1b) \
12189 : ltype(x) : "m" (__m(addr)))
12190@@ -424,13 +466,24 @@ do { \
12191 int __gu_err; \
12192 unsigned long __gu_val; \
12193 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12194- (x) = (__force __typeof__(*(ptr)))__gu_val; \
12195+ (x) = (__typeof__(*(ptr)))__gu_val; \
12196 __gu_err; \
12197 })
12198
12199 /* FIXME: this hack is definitely wrong -AK */
12200 struct __large_struct { unsigned long buf[100]; };
12201-#define __m(x) (*(struct __large_struct __user *)(x))
12202+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12203+#define ____m(x) \
12204+({ \
12205+ unsigned long ____x = (unsigned long)(x); \
12206+ if (____x < PAX_USER_SHADOW_BASE) \
12207+ ____x += PAX_USER_SHADOW_BASE; \
12208+ (void __user *)____x; \
12209+})
12210+#else
12211+#define ____m(x) (x)
12212+#endif
12213+#define __m(x) (*(struct __large_struct __user *)____m(x))
12214
12215 /*
12216 * Tell gcc we read from memory instead of writing: this is because
12217@@ -438,7 +491,7 @@ struct __large_struct { unsigned long bu
12218 * aliasing issues.
12219 */
12220 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12221- asm volatile("1: mov"itype" %"rtype"1,%2\n" \
12222+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
12223 "2:\n" \
12224 ".section .fixup,\"ax\"\n" \
12225 "3: mov %3,%0\n" \
12226@@ -446,10 +499,10 @@ struct __large_struct { unsigned long bu
12227 ".previous\n" \
12228 _ASM_EXTABLE(1b, 3b) \
12229 : "=r"(err) \
12230- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
12231+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
12232
12233 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
12234- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
12235+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
12236 "2:\n" \
12237 _ASM_EXTABLE(1b, 2b - 1b) \
12238 : : ltype(x), "m" (__m(addr)))
12239@@ -488,8 +541,12 @@ struct __large_struct { unsigned long bu
12240 * On error, the variable @x is set to zero.
12241 */
12242
12243+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12244+#define __get_user(x, ptr) get_user((x), (ptr))
12245+#else
12246 #define __get_user(x, ptr) \
12247 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
12248+#endif
12249
12250 /**
12251 * __put_user: - Write a simple value into user space, with less checking.
12252@@ -511,8 +568,12 @@ struct __large_struct { unsigned long bu
12253 * Returns zero on success, or -EFAULT on error.
12254 */
12255
12256+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12257+#define __put_user(x, ptr) put_user((x), (ptr))
12258+#else
12259 #define __put_user(x, ptr) \
12260 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
12261+#endif
12262
12263 #define __get_user_unaligned __get_user
12264 #define __put_user_unaligned __put_user
12265@@ -530,7 +591,7 @@ struct __large_struct { unsigned long bu
12266 #define get_user_ex(x, ptr) do { \
12267 unsigned long __gue_val; \
12268 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
12269- (x) = (__force __typeof__(*(ptr)))__gue_val; \
12270+ (x) = (__typeof__(*(ptr)))__gue_val; \
12271 } while (0)
12272
12273 #ifdef CONFIG_X86_WP_WORKS_OK
12274@@ -567,6 +628,7 @@ extern struct movsl_mask {
12275
12276 #define ARCH_HAS_NOCACHE_UACCESS 1
12277
12278+#define ARCH_HAS_SORT_EXTABLE
12279 #ifdef CONFIG_X86_32
12280 # include "uaccess_32.h"
12281 #else
12282diff -urNp linux-2.6.39.1/arch/x86/include/asm/vgtod.h linux-2.6.39.1/arch/x86/include/asm/vgtod.h
12283--- linux-2.6.39.1/arch/x86/include/asm/vgtod.h 2011-05-19 00:06:34.000000000 -0400
12284+++ linux-2.6.39.1/arch/x86/include/asm/vgtod.h 2011-05-22 19:36:30.000000000 -0400
12285@@ -14,6 +14,7 @@ struct vsyscall_gtod_data {
12286 int sysctl_enabled;
12287 struct timezone sys_tz;
12288 struct { /* extract of a clocksource struct */
12289+ char name[8];
12290 cycle_t (*vread)(void);
12291 cycle_t cycle_last;
12292 cycle_t mask;
12293diff -urNp linux-2.6.39.1/arch/x86/include/asm/vsyscall.h linux-2.6.39.1/arch/x86/include/asm/vsyscall.h
12294--- linux-2.6.39.1/arch/x86/include/asm/vsyscall.h 2011-05-19 00:06:34.000000000 -0400
12295+++ linux-2.6.39.1/arch/x86/include/asm/vsyscall.h 2011-05-22 19:36:30.000000000 -0400
12296@@ -15,9 +15,10 @@ enum vsyscall_num {
12297
12298 #ifdef __KERNEL__
12299 #include <linux/seqlock.h>
12300+#include <linux/getcpu.h>
12301+#include <linux/time.h>
12302
12303 #define __section_vgetcpu_mode __attribute__ ((unused, __section__ (".vgetcpu_mode"), aligned(16)))
12304-#define __section_jiffies __attribute__ ((unused, __section__ (".jiffies"), aligned(16)))
12305
12306 /* Definitions for CONFIG_GENERIC_TIME definitions */
12307 #define __section_vsyscall_gtod_data __attribute__ \
12308@@ -31,7 +32,6 @@ enum vsyscall_num {
12309 #define VGETCPU_LSL 2
12310
12311 extern int __vgetcpu_mode;
12312-extern volatile unsigned long __jiffies;
12313
12314 /* kernel space (writeable) */
12315 extern int vgetcpu_mode;
12316@@ -39,6 +39,9 @@ extern struct timezone sys_tz;
12317
12318 extern void map_vsyscall(void);
12319
12320+extern int vgettimeofday(struct timeval * tv, struct timezone * tz);
12321+extern time_t vtime(time_t *t);
12322+extern long vgetcpu(unsigned *cpu, unsigned *node, struct getcpu_cache *tcache);
12323 #endif /* __KERNEL__ */
12324
12325 #endif /* _ASM_X86_VSYSCALL_H */
12326diff -urNp linux-2.6.39.1/arch/x86/include/asm/xen/pci.h linux-2.6.39.1/arch/x86/include/asm/xen/pci.h
12327--- linux-2.6.39.1/arch/x86/include/asm/xen/pci.h 2011-05-19 00:06:34.000000000 -0400
12328+++ linux-2.6.39.1/arch/x86/include/asm/xen/pci.h 2011-05-22 19:36:30.000000000 -0400
12329@@ -33,7 +33,7 @@ struct xen_pci_frontend_ops {
12330 void (*disable_msix)(struct pci_dev *dev);
12331 };
12332
12333-extern struct xen_pci_frontend_ops *xen_pci_frontend;
12334+extern const struct xen_pci_frontend_ops *xen_pci_frontend;
12335
12336 static inline int xen_pci_frontend_enable_msi(struct pci_dev *dev,
12337 int vectors[])
12338diff -urNp linux-2.6.39.1/arch/x86/include/asm/xsave.h linux-2.6.39.1/arch/x86/include/asm/xsave.h
12339--- linux-2.6.39.1/arch/x86/include/asm/xsave.h 2011-05-19 00:06:34.000000000 -0400
12340+++ linux-2.6.39.1/arch/x86/include/asm/xsave.h 2011-05-22 19:36:30.000000000 -0400
12341@@ -65,6 +65,11 @@ static inline int xsave_user(struct xsav
12342 {
12343 int err;
12344
12345+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12346+ if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
12347+ buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
12348+#endif
12349+
12350 /*
12351 * Clear the xsave header first, so that reserved fields are
12352 * initialized to zero.
12353@@ -100,6 +105,11 @@ static inline int xrestore_user(struct x
12354 u32 lmask = mask;
12355 u32 hmask = mask >> 32;
12356
12357+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12358+ if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
12359+ xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
12360+#endif
12361+
12362 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
12363 "2:\n"
12364 ".section .fixup,\"ax\"\n"
12365diff -urNp linux-2.6.39.1/arch/x86/Kconfig linux-2.6.39.1/arch/x86/Kconfig
12366--- linux-2.6.39.1/arch/x86/Kconfig 2011-05-19 00:06:34.000000000 -0400
12367+++ linux-2.6.39.1/arch/x86/Kconfig 2011-05-22 19:41:32.000000000 -0400
12368@@ -224,7 +224,7 @@ config X86_HT
12369
12370 config X86_32_LAZY_GS
12371 def_bool y
12372- depends on X86_32 && !CC_STACKPROTECTOR
12373+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
12374
12375 config ARCH_HWEIGHT_CFLAGS
12376 string
12377@@ -1022,7 +1022,7 @@ choice
12378
12379 config NOHIGHMEM
12380 bool "off"
12381- depends on !X86_NUMAQ
12382+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12383 ---help---
12384 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
12385 However, the address space of 32-bit x86 processors is only 4
12386@@ -1059,7 +1059,7 @@ config NOHIGHMEM
12387
12388 config HIGHMEM4G
12389 bool "4GB"
12390- depends on !X86_NUMAQ
12391+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12392 ---help---
12393 Select this if you have a 32-bit processor and between 1 and 4
12394 gigabytes of physical RAM.
12395@@ -1113,7 +1113,7 @@ config PAGE_OFFSET
12396 hex
12397 default 0xB0000000 if VMSPLIT_3G_OPT
12398 default 0x80000000 if VMSPLIT_2G
12399- default 0x78000000 if VMSPLIT_2G_OPT
12400+ default 0x70000000 if VMSPLIT_2G_OPT
12401 default 0x40000000 if VMSPLIT_1G
12402 default 0xC0000000
12403 depends on X86_32
12404@@ -1457,7 +1457,7 @@ config ARCH_USES_PG_UNCACHED
12405
12406 config EFI
12407 bool "EFI runtime service support"
12408- depends on ACPI
12409+ depends on ACPI && !PAX_KERNEXEC
12410 ---help---
12411 This enables the kernel to use EFI runtime services that are
12412 available (such as the EFI variable services).
12413@@ -1487,6 +1487,7 @@ config SECCOMP
12414
12415 config CC_STACKPROTECTOR
12416 bool "Enable -fstack-protector buffer overflow detection (EXPERIMENTAL)"
12417+ depends on X86_64 || !PAX_MEMORY_UDEREF
12418 ---help---
12419 This option turns on the -fstack-protector GCC feature. This
12420 feature puts, at the beginning of functions, a canary value on
12421@@ -1544,6 +1545,7 @@ config KEXEC_JUMP
12422 config PHYSICAL_START
12423 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
12424 default "0x1000000"
12425+ range 0x400000 0x40000000
12426 ---help---
12427 This gives the physical address where the kernel is loaded.
12428
12429@@ -1607,6 +1609,7 @@ config X86_NEED_RELOCS
12430 config PHYSICAL_ALIGN
12431 hex "Alignment value to which kernel should be aligned" if X86_32
12432 default "0x1000000"
12433+ range 0x400000 0x1000000 if PAX_KERNEXEC
12434 range 0x2000 0x1000000
12435 ---help---
12436 This value puts the alignment restrictions on physical address
12437@@ -1638,9 +1641,10 @@ config HOTPLUG_CPU
12438 Say N if you want to disable CPU hotplug.
12439
12440 config COMPAT_VDSO
12441- def_bool y
12442+ def_bool n
12443 prompt "Compat VDSO support"
12444 depends on X86_32 || IA32_EMULATION
12445+ depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
12446 ---help---
12447 Map the 32-bit VDSO to the predictable old-style address too.
12448
12449diff -urNp linux-2.6.39.1/arch/x86/Kconfig.cpu linux-2.6.39.1/arch/x86/Kconfig.cpu
12450--- linux-2.6.39.1/arch/x86/Kconfig.cpu 2011-05-19 00:06:34.000000000 -0400
12451+++ linux-2.6.39.1/arch/x86/Kconfig.cpu 2011-05-22 19:36:30.000000000 -0400
12452@@ -334,7 +334,7 @@ config X86_PPRO_FENCE
12453
12454 config X86_F00F_BUG
12455 def_bool y
12456- depends on M586MMX || M586TSC || M586 || M486 || M386
12457+ depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
12458
12459 config X86_INVD_BUG
12460 def_bool y
12461@@ -358,7 +358,7 @@ config X86_POPAD_OK
12462
12463 config X86_ALIGNMENT_16
12464 def_bool y
12465- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12466+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12467
12468 config X86_INTEL_USERCOPY
12469 def_bool y
12470@@ -404,7 +404,7 @@ config X86_CMPXCHG64
12471 # generates cmov.
12472 config X86_CMOV
12473 def_bool y
12474- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12475+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12476
12477 config X86_MINIMUM_CPU_FAMILY
12478 int
12479diff -urNp linux-2.6.39.1/arch/x86/Kconfig.debug linux-2.6.39.1/arch/x86/Kconfig.debug
12480--- linux-2.6.39.1/arch/x86/Kconfig.debug 2011-05-19 00:06:34.000000000 -0400
12481+++ linux-2.6.39.1/arch/x86/Kconfig.debug 2011-05-22 19:36:30.000000000 -0400
12482@@ -101,7 +101,7 @@ config X86_PTDUMP
12483 config DEBUG_RODATA
12484 bool "Write protect kernel read-only data structures"
12485 default y
12486- depends on DEBUG_KERNEL
12487+ depends on DEBUG_KERNEL && BROKEN
12488 ---help---
12489 Mark the kernel read-only data as write-protected in the pagetables,
12490 in order to catch accidental (and incorrect) writes to such const
12491@@ -119,7 +119,7 @@ config DEBUG_RODATA_TEST
12492
12493 config DEBUG_SET_MODULE_RONX
12494 bool "Set loadable kernel module data as NX and text as RO"
12495- depends on MODULES
12496+ depends on MODULES && BROKEN
12497 ---help---
12498 This option helps catch unintended modifications to loadable
12499 kernel module's text and read-only data. It also prevents execution
12500diff -urNp linux-2.6.39.1/arch/x86/kernel/acpi/sleep.c linux-2.6.39.1/arch/x86/kernel/acpi/sleep.c
12501--- linux-2.6.39.1/arch/x86/kernel/acpi/sleep.c 2011-05-19 00:06:34.000000000 -0400
12502+++ linux-2.6.39.1/arch/x86/kernel/acpi/sleep.c 2011-05-22 19:36:30.000000000 -0400
12503@@ -88,8 +88,12 @@ int acpi_suspend_lowlevel(void)
12504 header->trampoline_segment = trampoline_address() >> 4;
12505 #ifdef CONFIG_SMP
12506 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
12507+
12508+ pax_open_kernel();
12509 early_gdt_descr.address =
12510 (unsigned long)get_cpu_gdt_table(smp_processor_id());
12511+ pax_close_kernel();
12512+
12513 initial_gs = per_cpu_offset(smp_processor_id());
12514 #endif
12515 initial_code = (unsigned long)wakeup_long64;
12516diff -urNp linux-2.6.39.1/arch/x86/kernel/acpi/wakeup_32.S linux-2.6.39.1/arch/x86/kernel/acpi/wakeup_32.S
12517--- linux-2.6.39.1/arch/x86/kernel/acpi/wakeup_32.S 2011-05-19 00:06:34.000000000 -0400
12518+++ linux-2.6.39.1/arch/x86/kernel/acpi/wakeup_32.S 2011-05-22 19:36:30.000000000 -0400
12519@@ -30,13 +30,11 @@ wakeup_pmode_return:
12520 # and restore the stack ... but you need gdt for this to work
12521 movl saved_context_esp, %esp
12522
12523- movl %cs:saved_magic, %eax
12524- cmpl $0x12345678, %eax
12525+ cmpl $0x12345678, saved_magic
12526 jne bogus_magic
12527
12528 # jump to place where we left off
12529- movl saved_eip, %eax
12530- jmp *%eax
12531+ jmp *(saved_eip)
12532
12533 bogus_magic:
12534 jmp bogus_magic
12535diff -urNp linux-2.6.39.1/arch/x86/kernel/alternative.c linux-2.6.39.1/arch/x86/kernel/alternative.c
12536--- linux-2.6.39.1/arch/x86/kernel/alternative.c 2011-05-19 00:06:34.000000000 -0400
12537+++ linux-2.6.39.1/arch/x86/kernel/alternative.c 2011-05-22 19:36:30.000000000 -0400
12538@@ -248,7 +248,7 @@ static void alternatives_smp_lock(const
12539 if (!*poff || ptr < text || ptr >= text_end)
12540 continue;
12541 /* turn DS segment override prefix into lock prefix */
12542- if (*ptr == 0x3e)
12543+ if (*ktla_ktva(ptr) == 0x3e)
12544 text_poke(ptr, ((unsigned char []){0xf0}), 1);
12545 };
12546 mutex_unlock(&text_mutex);
12547@@ -269,7 +269,7 @@ static void alternatives_smp_unlock(cons
12548 if (!*poff || ptr < text || ptr >= text_end)
12549 continue;
12550 /* turn lock prefix into DS segment override prefix */
12551- if (*ptr == 0xf0)
12552+ if (*ktla_ktva(ptr) == 0xf0)
12553 text_poke(ptr, ((unsigned char []){0x3E}), 1);
12554 };
12555 mutex_unlock(&text_mutex);
12556@@ -438,7 +438,7 @@ void __init_or_module apply_paravirt(str
12557
12558 BUG_ON(p->len > MAX_PATCH_LEN);
12559 /* prep the buffer with the original instructions */
12560- memcpy(insnbuf, p->instr, p->len);
12561+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
12562 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
12563 (unsigned long)p->instr, p->len);
12564
12565@@ -506,7 +506,7 @@ void __init alternative_instructions(voi
12566 if (smp_alt_once)
12567 free_init_pages("SMP alternatives",
12568 (unsigned long)__smp_locks,
12569- (unsigned long)__smp_locks_end);
12570+ PAGE_ALIGN((unsigned long)__smp_locks_end));
12571
12572 restart_nmi();
12573 }
12574@@ -523,13 +523,17 @@ void __init alternative_instructions(voi
12575 * instructions. And on the local CPU you need to be protected again NMI or MCE
12576 * handlers seeing an inconsistent instruction while you patch.
12577 */
12578-void *__init_or_module text_poke_early(void *addr, const void *opcode,
12579+void *__kprobes text_poke_early(void *addr, const void *opcode,
12580 size_t len)
12581 {
12582 unsigned long flags;
12583 local_irq_save(flags);
12584- memcpy(addr, opcode, len);
12585+
12586+ pax_open_kernel();
12587+ memcpy(ktla_ktva(addr), opcode, len);
12588 sync_core();
12589+ pax_close_kernel();
12590+
12591 local_irq_restore(flags);
12592 /* Could also do a CLFLUSH here to speed up CPU recovery; but
12593 that causes hangs on some VIA CPUs. */
12594@@ -551,36 +555,22 @@ void *__init_or_module text_poke_early(v
12595 */
12596 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
12597 {
12598- unsigned long flags;
12599- char *vaddr;
12600+ unsigned char *vaddr = ktla_ktva(addr);
12601 struct page *pages[2];
12602- int i;
12603+ size_t i;
12604
12605 if (!core_kernel_text((unsigned long)addr)) {
12606- pages[0] = vmalloc_to_page(addr);
12607- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
12608+ pages[0] = vmalloc_to_page(vaddr);
12609+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
12610 } else {
12611- pages[0] = virt_to_page(addr);
12612+ pages[0] = virt_to_page(vaddr);
12613 WARN_ON(!PageReserved(pages[0]));
12614- pages[1] = virt_to_page(addr + PAGE_SIZE);
12615+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
12616 }
12617 BUG_ON(!pages[0]);
12618- local_irq_save(flags);
12619- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
12620- if (pages[1])
12621- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
12622- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
12623- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
12624- clear_fixmap(FIX_TEXT_POKE0);
12625- if (pages[1])
12626- clear_fixmap(FIX_TEXT_POKE1);
12627- local_flush_tlb();
12628- sync_core();
12629- /* Could also do a CLFLUSH here to speed up CPU recovery; but
12630- that causes hangs on some VIA CPUs. */
12631+ text_poke_early(addr, opcode, len);
12632 for (i = 0; i < len; i++)
12633- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
12634- local_irq_restore(flags);
12635+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
12636 return addr;
12637 }
12638
12639@@ -682,9 +672,9 @@ void __kprobes text_poke_smp_batch(struc
12640 #if defined(CONFIG_DYNAMIC_FTRACE) || defined(HAVE_JUMP_LABEL)
12641
12642 #ifdef CONFIG_X86_64
12643-unsigned char ideal_nop5[5] = { 0x66, 0x66, 0x66, 0x66, 0x90 };
12644+unsigned char ideal_nop5[5] __read_only = { 0x66, 0x66, 0x66, 0x66, 0x90 };
12645 #else
12646-unsigned char ideal_nop5[5] = { 0x3e, 0x8d, 0x74, 0x26, 0x00 };
12647+unsigned char ideal_nop5[5] __read_only = { 0x3e, 0x8d, 0x74, 0x26, 0x00 };
12648 #endif
12649
12650 void __init arch_init_ideal_nop5(void)
12651diff -urNp linux-2.6.39.1/arch/x86/kernel/amd_iommu.c linux-2.6.39.1/arch/x86/kernel/amd_iommu.c
12652--- linux-2.6.39.1/arch/x86/kernel/amd_iommu.c 2011-05-19 00:06:34.000000000 -0400
12653+++ linux-2.6.39.1/arch/x86/kernel/amd_iommu.c 2011-05-22 19:36:30.000000000 -0400
12654@@ -48,7 +48,7 @@ static DEFINE_SPINLOCK(iommu_pd_list_loc
12655 */
12656 static struct protection_domain *pt_domain;
12657
12658-static struct iommu_ops amd_iommu_ops;
12659+static const struct iommu_ops amd_iommu_ops;
12660
12661 /*
12662 * general struct to manage commands send to an IOMMU
12663@@ -2286,7 +2286,7 @@ static void prealloc_protection_domains(
12664 }
12665 }
12666
12667-static struct dma_map_ops amd_iommu_dma_ops = {
12668+static const struct dma_map_ops amd_iommu_dma_ops = {
12669 .alloc_coherent = alloc_coherent,
12670 .free_coherent = free_coherent,
12671 .map_page = map_page,
12672@@ -2582,7 +2582,7 @@ static int amd_iommu_domain_has_cap(stru
12673 return 0;
12674 }
12675
12676-static struct iommu_ops amd_iommu_ops = {
12677+static const struct iommu_ops amd_iommu_ops = {
12678 .domain_init = amd_iommu_domain_init,
12679 .domain_destroy = amd_iommu_domain_destroy,
12680 .attach_dev = amd_iommu_attach_device,
12681diff -urNp linux-2.6.39.1/arch/x86/kernel/apic/apic.c linux-2.6.39.1/arch/x86/kernel/apic/apic.c
12682--- linux-2.6.39.1/arch/x86/kernel/apic/apic.c 2011-05-19 00:06:34.000000000 -0400
12683+++ linux-2.6.39.1/arch/x86/kernel/apic/apic.c 2011-05-22 19:36:30.000000000 -0400
12684@@ -1821,7 +1821,7 @@ void smp_error_interrupt(struct pt_regs
12685 apic_write(APIC_ESR, 0);
12686 v1 = apic_read(APIC_ESR);
12687 ack_APIC_irq();
12688- atomic_inc(&irq_err_count);
12689+ atomic_inc_unchecked(&irq_err_count);
12690
12691 /*
12692 * Here is what the APIC error bits mean:
12693@@ -2204,6 +2204,8 @@ static int __cpuinit apic_cluster_num(vo
12694 u16 *bios_cpu_apicid;
12695 DECLARE_BITMAP(clustermap, NUM_APIC_CLUSTERS);
12696
12697+ pax_track_stack();
12698+
12699 bios_cpu_apicid = early_per_cpu_ptr(x86_bios_cpu_apicid);
12700 bitmap_zero(clustermap, NUM_APIC_CLUSTERS);
12701
12702diff -urNp linux-2.6.39.1/arch/x86/kernel/apic/io_apic.c linux-2.6.39.1/arch/x86/kernel/apic/io_apic.c
12703--- linux-2.6.39.1/arch/x86/kernel/apic/io_apic.c 2011-06-03 00:04:13.000000000 -0400
12704+++ linux-2.6.39.1/arch/x86/kernel/apic/io_apic.c 2011-06-03 00:42:37.000000000 -0400
12705@@ -623,7 +623,7 @@ struct IO_APIC_route_entry **alloc_ioapi
12706 ioapic_entries = kzalloc(sizeof(*ioapic_entries) * nr_ioapics,
12707 GFP_ATOMIC);
12708 if (!ioapic_entries)
12709- return 0;
12710+ return NULL;
12711
12712 for (apic = 0; apic < nr_ioapics; apic++) {
12713 ioapic_entries[apic] =
12714@@ -640,7 +640,7 @@ nomem:
12715 kfree(ioapic_entries[apic]);
12716 kfree(ioapic_entries);
12717
12718- return 0;
12719+ return NULL;
12720 }
12721
12722 /*
12723@@ -1040,7 +1040,7 @@ int IO_APIC_get_PCI_irq_vector(int bus,
12724 }
12725 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
12726
12727-void lock_vector_lock(void)
12728+void lock_vector_lock(void) __acquires(vector_lock)
12729 {
12730 /* Used to the online set of cpus does not change
12731 * during assign_irq_vector.
12732@@ -1048,7 +1048,7 @@ void lock_vector_lock(void)
12733 raw_spin_lock(&vector_lock);
12734 }
12735
12736-void unlock_vector_lock(void)
12737+void unlock_vector_lock(void) __releases(vector_lock)
12738 {
12739 raw_spin_unlock(&vector_lock);
12740 }
12741@@ -2379,7 +2379,7 @@ static void ack_apic_edge(struct irq_dat
12742 ack_APIC_irq();
12743 }
12744
12745-atomic_t irq_mis_count;
12746+atomic_unchecked_t irq_mis_count;
12747
12748 /*
12749 * IO-APIC versions below 0x20 don't support EOI register.
12750@@ -2487,7 +2487,7 @@ static void ack_apic_level(struct irq_da
12751 * at the cpu.
12752 */
12753 if (!(v & (1 << (i & 0x1f)))) {
12754- atomic_inc(&irq_mis_count);
12755+ atomic_inc_unchecked(&irq_mis_count);
12756
12757 eoi_ioapic_irq(irq, cfg);
12758 }
12759diff -urNp linux-2.6.39.1/arch/x86/kernel/apm_32.c linux-2.6.39.1/arch/x86/kernel/apm_32.c
12760--- linux-2.6.39.1/arch/x86/kernel/apm_32.c 2011-05-19 00:06:34.000000000 -0400
12761+++ linux-2.6.39.1/arch/x86/kernel/apm_32.c 2011-05-22 19:36:30.000000000 -0400
12762@@ -412,7 +412,7 @@ static DEFINE_MUTEX(apm_mutex);
12763 * This is for buggy BIOS's that refer to (real mode) segment 0x40
12764 * even though they are called in protected mode.
12765 */
12766-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
12767+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
12768 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
12769
12770 static const char driver_version[] = "1.16ac"; /* no spaces */
12771@@ -590,7 +590,10 @@ static long __apm_bios_call(void *_call)
12772 BUG_ON(cpu != 0);
12773 gdt = get_cpu_gdt_table(cpu);
12774 save_desc_40 = gdt[0x40 / 8];
12775+
12776+ pax_open_kernel();
12777 gdt[0x40 / 8] = bad_bios_desc;
12778+ pax_close_kernel();
12779
12780 apm_irq_save(flags);
12781 APM_DO_SAVE_SEGS;
12782@@ -599,7 +602,11 @@ static long __apm_bios_call(void *_call)
12783 &call->esi);
12784 APM_DO_RESTORE_SEGS;
12785 apm_irq_restore(flags);
12786+
12787+ pax_open_kernel();
12788 gdt[0x40 / 8] = save_desc_40;
12789+ pax_close_kernel();
12790+
12791 put_cpu();
12792
12793 return call->eax & 0xff;
12794@@ -666,7 +673,10 @@ static long __apm_bios_call_simple(void
12795 BUG_ON(cpu != 0);
12796 gdt = get_cpu_gdt_table(cpu);
12797 save_desc_40 = gdt[0x40 / 8];
12798+
12799+ pax_open_kernel();
12800 gdt[0x40 / 8] = bad_bios_desc;
12801+ pax_close_kernel();
12802
12803 apm_irq_save(flags);
12804 APM_DO_SAVE_SEGS;
12805@@ -674,7 +684,11 @@ static long __apm_bios_call_simple(void
12806 &call->eax);
12807 APM_DO_RESTORE_SEGS;
12808 apm_irq_restore(flags);
12809+
12810+ pax_open_kernel();
12811 gdt[0x40 / 8] = save_desc_40;
12812+ pax_close_kernel();
12813+
12814 put_cpu();
12815 return error;
12816 }
12817@@ -2351,12 +2365,15 @@ static int __init apm_init(void)
12818 * code to that CPU.
12819 */
12820 gdt = get_cpu_gdt_table(0);
12821+
12822+ pax_open_kernel();
12823 set_desc_base(&gdt[APM_CS >> 3],
12824 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
12825 set_desc_base(&gdt[APM_CS_16 >> 3],
12826 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
12827 set_desc_base(&gdt[APM_DS >> 3],
12828 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
12829+ pax_close_kernel();
12830
12831 proc_create("apm", 0, NULL, &apm_file_ops);
12832
12833diff -urNp linux-2.6.39.1/arch/x86/kernel/asm-offsets_64.c linux-2.6.39.1/arch/x86/kernel/asm-offsets_64.c
12834--- linux-2.6.39.1/arch/x86/kernel/asm-offsets_64.c 2011-05-19 00:06:34.000000000 -0400
12835+++ linux-2.6.39.1/arch/x86/kernel/asm-offsets_64.c 2011-05-22 19:36:30.000000000 -0400
12836@@ -69,6 +69,7 @@ int main(void)
12837 BLANK();
12838 #undef ENTRY
12839
12840+ DEFINE(TSS_size, sizeof(struct tss_struct));
12841 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
12842 BLANK();
12843
12844diff -urNp linux-2.6.39.1/arch/x86/kernel/asm-offsets.c linux-2.6.39.1/arch/x86/kernel/asm-offsets.c
12845--- linux-2.6.39.1/arch/x86/kernel/asm-offsets.c 2011-05-19 00:06:34.000000000 -0400
12846+++ linux-2.6.39.1/arch/x86/kernel/asm-offsets.c 2011-05-25 17:35:48.000000000 -0400
12847@@ -33,6 +33,8 @@ void common(void) {
12848 OFFSET(TI_status, thread_info, status);
12849 OFFSET(TI_addr_limit, thread_info, addr_limit);
12850 OFFSET(TI_preempt_count, thread_info, preempt_count);
12851+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
12852+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
12853
12854 BLANK();
12855 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
12856@@ -53,8 +55,26 @@ void common(void) {
12857 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
12858 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
12859 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
12860+
12861+#ifdef CONFIG_PAX_KERNEXEC
12862+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
12863+#endif
12864+
12865+#ifdef CONFIG_PAX_MEMORY_UDEREF
12866+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
12867+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
12868+#ifdef CONFIG_X86_64
12869+ OFFSET(PV_MMU_set_pgd, pv_mmu_ops, set_pgd);
12870+#endif
12871 #endif
12872
12873+#endif
12874+
12875+ BLANK();
12876+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
12877+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
12878+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
12879+
12880 #ifdef CONFIG_XEN
12881 BLANK();
12882 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
12883diff -urNp linux-2.6.39.1/arch/x86/kernel/cpu/amd.c linux-2.6.39.1/arch/x86/kernel/cpu/amd.c
12884--- linux-2.6.39.1/arch/x86/kernel/cpu/amd.c 2011-06-03 00:04:13.000000000 -0400
12885+++ linux-2.6.39.1/arch/x86/kernel/cpu/amd.c 2011-06-03 00:32:04.000000000 -0400
12886@@ -647,7 +647,7 @@ static unsigned int __cpuinit amd_size_c
12887 unsigned int size)
12888 {
12889 /* AMD errata T13 (order #21922) */
12890- if ((c->x86 == 6)) {
12891+ if (c->x86 == 6) {
12892 /* Duron Rev A0 */
12893 if (c->x86_model == 3 && c->x86_mask == 0)
12894 size = 64;
12895diff -urNp linux-2.6.39.1/arch/x86/kernel/cpu/common.c linux-2.6.39.1/arch/x86/kernel/cpu/common.c
12896--- linux-2.6.39.1/arch/x86/kernel/cpu/common.c 2011-06-03 00:04:13.000000000 -0400
12897+++ linux-2.6.39.1/arch/x86/kernel/cpu/common.c 2011-06-03 00:32:04.000000000 -0400
12898@@ -83,60 +83,6 @@ static const struct cpu_dev __cpuinitcon
12899
12900 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
12901
12902-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
12903-#ifdef CONFIG_X86_64
12904- /*
12905- * We need valid kernel segments for data and code in long mode too
12906- * IRET will check the segment types kkeil 2000/10/28
12907- * Also sysret mandates a special GDT layout
12908- *
12909- * TLS descriptors are currently at a different place compared to i386.
12910- * Hopefully nobody expects them at a fixed place (Wine?)
12911- */
12912- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
12913- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
12914- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
12915- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
12916- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
12917- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
12918-#else
12919- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
12920- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
12921- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
12922- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
12923- /*
12924- * Segments used for calling PnP BIOS have byte granularity.
12925- * They code segments and data segments have fixed 64k limits,
12926- * the transfer segment sizes are set at run time.
12927- */
12928- /* 32-bit code */
12929- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
12930- /* 16-bit code */
12931- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
12932- /* 16-bit data */
12933- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
12934- /* 16-bit data */
12935- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
12936- /* 16-bit data */
12937- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
12938- /*
12939- * The APM segments have byte granularity and their bases
12940- * are set at run time. All have 64k limits.
12941- */
12942- /* 32-bit code */
12943- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
12944- /* 16-bit code */
12945- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
12946- /* data */
12947- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
12948-
12949- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
12950- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
12951- GDT_STACK_CANARY_INIT
12952-#endif
12953-} };
12954-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
12955-
12956 static int __init x86_xsave_setup(char *s)
12957 {
12958 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
12959@@ -352,7 +298,7 @@ void switch_to_new_gdt(int cpu)
12960 {
12961 struct desc_ptr gdt_descr;
12962
12963- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
12964+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
12965 gdt_descr.size = GDT_SIZE - 1;
12966 load_gdt(&gdt_descr);
12967 /* Reload the per-cpu base */
12968@@ -824,6 +770,10 @@ static void __cpuinit identify_cpu(struc
12969 /* Filter out anything that depends on CPUID levels we don't have */
12970 filter_cpuid_features(c, true);
12971
12972+#if defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || (defined(CONFIG_PAX_MEMORY_UDEREF) && defined(CONFIG_X86_32))
12973+ setup_clear_cpu_cap(X86_FEATURE_SEP);
12974+#endif
12975+
12976 /* If the model name is still unset, do table lookup. */
12977 if (!c->x86_model_id[0]) {
12978 const char *p;
12979@@ -1003,6 +953,9 @@ static __init int setup_disablecpuid(cha
12980 }
12981 __setup("clearcpuid=", setup_disablecpuid);
12982
12983+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
12984+EXPORT_PER_CPU_SYMBOL(current_tinfo);
12985+
12986 #ifdef CONFIG_X86_64
12987 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
12988
12989@@ -1018,7 +971,7 @@ DEFINE_PER_CPU(struct task_struct *, cur
12990 EXPORT_PER_CPU_SYMBOL(current_task);
12991
12992 DEFINE_PER_CPU(unsigned long, kernel_stack) =
12993- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
12994+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
12995 EXPORT_PER_CPU_SYMBOL(kernel_stack);
12996
12997 DEFINE_PER_CPU(char *, irq_stack_ptr) =
12998@@ -1083,7 +1036,7 @@ struct pt_regs * __cpuinit idle_regs(str
12999 {
13000 memset(regs, 0, sizeof(struct pt_regs));
13001 regs->fs = __KERNEL_PERCPU;
13002- regs->gs = __KERNEL_STACK_CANARY;
13003+ savesegment(gs, regs->gs);
13004
13005 return regs;
13006 }
13007@@ -1138,7 +1091,7 @@ void __cpuinit cpu_init(void)
13008 int i;
13009
13010 cpu = stack_smp_processor_id();
13011- t = &per_cpu(init_tss, cpu);
13012+ t = init_tss + cpu;
13013 oist = &per_cpu(orig_ist, cpu);
13014
13015 #ifdef CONFIG_NUMA
13016@@ -1164,7 +1117,7 @@ void __cpuinit cpu_init(void)
13017 switch_to_new_gdt(cpu);
13018 loadsegment(fs, 0);
13019
13020- load_idt((const struct desc_ptr *)&idt_descr);
13021+ load_idt(&idt_descr);
13022
13023 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
13024 syscall_init();
13025@@ -1173,7 +1126,6 @@ void __cpuinit cpu_init(void)
13026 wrmsrl(MSR_KERNEL_GS_BASE, 0);
13027 barrier();
13028
13029- x86_configure_nx();
13030 if (cpu != 0)
13031 enable_x2apic();
13032
13033@@ -1227,7 +1179,7 @@ void __cpuinit cpu_init(void)
13034 {
13035 int cpu = smp_processor_id();
13036 struct task_struct *curr = current;
13037- struct tss_struct *t = &per_cpu(init_tss, cpu);
13038+ struct tss_struct *t = init_tss + cpu;
13039 struct thread_struct *thread = &curr->thread;
13040
13041 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
13042diff -urNp linux-2.6.39.1/arch/x86/kernel/cpu/intel.c linux-2.6.39.1/arch/x86/kernel/cpu/intel.c
13043--- linux-2.6.39.1/arch/x86/kernel/cpu/intel.c 2011-05-19 00:06:34.000000000 -0400
13044+++ linux-2.6.39.1/arch/x86/kernel/cpu/intel.c 2011-05-22 19:36:30.000000000 -0400
13045@@ -161,7 +161,7 @@ static void __cpuinit trap_init_f00f_bug
13046 * Update the IDT descriptor and reload the IDT so that
13047 * it uses the read-only mapped virtual address.
13048 */
13049- idt_descr.address = fix_to_virt(FIX_F00F_IDT);
13050+ idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
13051 load_idt(&idt_descr);
13052 }
13053 #endif
13054diff -urNp linux-2.6.39.1/arch/x86/kernel/cpu/Makefile linux-2.6.39.1/arch/x86/kernel/cpu/Makefile
13055--- linux-2.6.39.1/arch/x86/kernel/cpu/Makefile 2011-05-19 00:06:34.000000000 -0400
13056+++ linux-2.6.39.1/arch/x86/kernel/cpu/Makefile 2011-05-22 19:36:30.000000000 -0400
13057@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
13058 CFLAGS_REMOVE_perf_event.o = -pg
13059 endif
13060
13061-# Make sure load_percpu_segment has no stackprotector
13062-nostackp := $(call cc-option, -fno-stack-protector)
13063-CFLAGS_common.o := $(nostackp)
13064-
13065 obj-y := intel_cacheinfo.o scattered.o topology.o
13066 obj-y += proc.o capflags.o powerflags.o common.o
13067 obj-y += vmware.o hypervisor.o sched.o mshyperv.o
13068diff -urNp linux-2.6.39.1/arch/x86/kernel/cpu/mcheck/mce.c linux-2.6.39.1/arch/x86/kernel/cpu/mcheck/mce.c
13069--- linux-2.6.39.1/arch/x86/kernel/cpu/mcheck/mce.c 2011-05-19 00:06:34.000000000 -0400
13070+++ linux-2.6.39.1/arch/x86/kernel/cpu/mcheck/mce.c 2011-05-22 19:36:30.000000000 -0400
13071@@ -46,6 +46,7 @@
13072 #include <asm/ipi.h>
13073 #include <asm/mce.h>
13074 #include <asm/msr.h>
13075+#include <asm/local.h>
13076
13077 #include "mce-internal.h"
13078
13079@@ -220,7 +221,7 @@ static void print_mce(struct mce *m)
13080 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
13081 m->cs, m->ip);
13082
13083- if (m->cs == __KERNEL_CS)
13084+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
13085 print_symbol("{%s}", m->ip);
13086 pr_cont("\n");
13087 }
13088@@ -244,10 +245,10 @@ static void print_mce(struct mce *m)
13089
13090 #define PANIC_TIMEOUT 5 /* 5 seconds */
13091
13092-static atomic_t mce_paniced;
13093+static atomic_unchecked_t mce_paniced;
13094
13095 static int fake_panic;
13096-static atomic_t mce_fake_paniced;
13097+static atomic_unchecked_t mce_fake_paniced;
13098
13099 /* Panic in progress. Enable interrupts and wait for final IPI */
13100 static void wait_for_panic(void)
13101@@ -271,7 +272,7 @@ static void mce_panic(char *msg, struct
13102 /*
13103 * Make sure only one CPU runs in machine check panic
13104 */
13105- if (atomic_inc_return(&mce_paniced) > 1)
13106+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
13107 wait_for_panic();
13108 barrier();
13109
13110@@ -279,7 +280,7 @@ static void mce_panic(char *msg, struct
13111 console_verbose();
13112 } else {
13113 /* Don't log too much for fake panic */
13114- if (atomic_inc_return(&mce_fake_paniced) > 1)
13115+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
13116 return;
13117 }
13118 /* First print corrected ones that are still unlogged */
13119@@ -647,7 +648,7 @@ static int mce_timed_out(u64 *t)
13120 * might have been modified by someone else.
13121 */
13122 rmb();
13123- if (atomic_read(&mce_paniced))
13124+ if (atomic_read_unchecked(&mce_paniced))
13125 wait_for_panic();
13126 if (!monarch_timeout)
13127 goto out;
13128@@ -1461,14 +1462,14 @@ void __cpuinit mcheck_cpu_init(struct cp
13129 */
13130
13131 static DEFINE_SPINLOCK(mce_state_lock);
13132-static int open_count; /* #times opened */
13133+static local_t open_count; /* #times opened */
13134 static int open_exclu; /* already open exclusive? */
13135
13136 static int mce_open(struct inode *inode, struct file *file)
13137 {
13138 spin_lock(&mce_state_lock);
13139
13140- if (open_exclu || (open_count && (file->f_flags & O_EXCL))) {
13141+ if (open_exclu || (local_read(&open_count) && (file->f_flags & O_EXCL))) {
13142 spin_unlock(&mce_state_lock);
13143
13144 return -EBUSY;
13145@@ -1476,7 +1477,7 @@ static int mce_open(struct inode *inode,
13146
13147 if (file->f_flags & O_EXCL)
13148 open_exclu = 1;
13149- open_count++;
13150+ local_inc(&open_count);
13151
13152 spin_unlock(&mce_state_lock);
13153
13154@@ -1487,7 +1488,7 @@ static int mce_release(struct inode *ino
13155 {
13156 spin_lock(&mce_state_lock);
13157
13158- open_count--;
13159+ local_dec(&open_count);
13160 open_exclu = 0;
13161
13162 spin_unlock(&mce_state_lock);
13163@@ -2174,7 +2175,7 @@ struct dentry *mce_get_debugfs_dir(void)
13164 static void mce_reset(void)
13165 {
13166 cpu_missing = 0;
13167- atomic_set(&mce_fake_paniced, 0);
13168+ atomic_set_unchecked(&mce_fake_paniced, 0);
13169 atomic_set(&mce_executing, 0);
13170 atomic_set(&mce_callin, 0);
13171 atomic_set(&global_nwo, 0);
13172diff -urNp linux-2.6.39.1/arch/x86/kernel/cpu/mtrr/main.c linux-2.6.39.1/arch/x86/kernel/cpu/mtrr/main.c
13173--- linux-2.6.39.1/arch/x86/kernel/cpu/mtrr/main.c 2011-05-19 00:06:34.000000000 -0400
13174+++ linux-2.6.39.1/arch/x86/kernel/cpu/mtrr/main.c 2011-05-22 19:36:30.000000000 -0400
13175@@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
13176 u64 size_or_mask, size_and_mask;
13177 static bool mtrr_aps_delayed_init;
13178
13179-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
13180+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
13181
13182 const struct mtrr_ops *mtrr_if;
13183
13184diff -urNp linux-2.6.39.1/arch/x86/kernel/cpu/mtrr/mtrr.h linux-2.6.39.1/arch/x86/kernel/cpu/mtrr/mtrr.h
13185--- linux-2.6.39.1/arch/x86/kernel/cpu/mtrr/mtrr.h 2011-05-19 00:06:34.000000000 -0400
13186+++ linux-2.6.39.1/arch/x86/kernel/cpu/mtrr/mtrr.h 2011-05-22 19:36:30.000000000 -0400
13187@@ -12,19 +12,19 @@
13188 extern unsigned int mtrr_usage_table[MTRR_MAX_VAR_RANGES];
13189
13190 struct mtrr_ops {
13191- u32 vendor;
13192- u32 use_intel_if;
13193- void (*set)(unsigned int reg, unsigned long base,
13194+ const u32 vendor;
13195+ const u32 use_intel_if;
13196+ void (* const set)(unsigned int reg, unsigned long base,
13197 unsigned long size, mtrr_type type);
13198- void (*set_all)(void);
13199+ void (* const set_all)(void);
13200
13201- void (*get)(unsigned int reg, unsigned long *base,
13202+ void (* const get)(unsigned int reg, unsigned long *base,
13203 unsigned long *size, mtrr_type *type);
13204- int (*get_free_region)(unsigned long base, unsigned long size,
13205+ int (* const get_free_region)(unsigned long base, unsigned long size,
13206 int replace_reg);
13207- int (*validate_add_page)(unsigned long base, unsigned long size,
13208+ int (* const validate_add_page)(unsigned long base, unsigned long size,
13209 unsigned int type);
13210- int (*have_wrcomb)(void);
13211+ int (* const have_wrcomb)(void);
13212 };
13213
13214 extern int generic_get_free_region(unsigned long base, unsigned long size,
13215diff -urNp linux-2.6.39.1/arch/x86/kernel/cpu/perf_event.c linux-2.6.39.1/arch/x86/kernel/cpu/perf_event.c
13216--- linux-2.6.39.1/arch/x86/kernel/cpu/perf_event.c 2011-05-19 00:06:34.000000000 -0400
13217+++ linux-2.6.39.1/arch/x86/kernel/cpu/perf_event.c 2011-05-22 19:36:30.000000000 -0400
13218@@ -774,6 +774,8 @@ static int x86_schedule_events(struct cp
13219 int i, j, w, wmax, num = 0;
13220 struct hw_perf_event *hwc;
13221
13222+ pax_track_stack();
13223+
13224 bitmap_zero(used_mask, X86_PMC_IDX_MAX);
13225
13226 for (i = 0; i < n; i++) {
13227@@ -1878,7 +1880,7 @@ perf_callchain_user(struct perf_callchai
13228 break;
13229
13230 perf_callchain_store(entry, frame.return_address);
13231- fp = frame.next_frame;
13232+ fp = (__force const void __user *)frame.next_frame;
13233 }
13234 }
13235
13236diff -urNp linux-2.6.39.1/arch/x86/kernel/crash.c linux-2.6.39.1/arch/x86/kernel/crash.c
13237--- linux-2.6.39.1/arch/x86/kernel/crash.c 2011-05-19 00:06:34.000000000 -0400
13238+++ linux-2.6.39.1/arch/x86/kernel/crash.c 2011-05-22 19:36:30.000000000 -0400
13239@@ -42,7 +42,7 @@ static void kdump_nmi_callback(int cpu,
13240 regs = args->regs;
13241
13242 #ifdef CONFIG_X86_32
13243- if (!user_mode_vm(regs)) {
13244+ if (!user_mode(regs)) {
13245 crash_fixup_ss_esp(&fixed_regs, regs);
13246 regs = &fixed_regs;
13247 }
13248diff -urNp linux-2.6.39.1/arch/x86/kernel/doublefault_32.c linux-2.6.39.1/arch/x86/kernel/doublefault_32.c
13249--- linux-2.6.39.1/arch/x86/kernel/doublefault_32.c 2011-05-19 00:06:34.000000000 -0400
13250+++ linux-2.6.39.1/arch/x86/kernel/doublefault_32.c 2011-05-22 19:36:30.000000000 -0400
13251@@ -11,7 +11,7 @@
13252
13253 #define DOUBLEFAULT_STACKSIZE (1024)
13254 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
13255-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
13256+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
13257
13258 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
13259
13260@@ -21,7 +21,7 @@ static void doublefault_fn(void)
13261 unsigned long gdt, tss;
13262
13263 store_gdt(&gdt_desc);
13264- gdt = gdt_desc.address;
13265+ gdt = (unsigned long)gdt_desc.address;
13266
13267 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
13268
13269@@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cach
13270 /* 0x2 bit is always set */
13271 .flags = X86_EFLAGS_SF | 0x2,
13272 .sp = STACK_START,
13273- .es = __USER_DS,
13274+ .es = __KERNEL_DS,
13275 .cs = __KERNEL_CS,
13276 .ss = __KERNEL_DS,
13277- .ds = __USER_DS,
13278+ .ds = __KERNEL_DS,
13279 .fs = __KERNEL_PERCPU,
13280
13281 .__cr3 = __pa_nodebug(swapper_pg_dir),
13282diff -urNp linux-2.6.39.1/arch/x86/kernel/dumpstack_32.c linux-2.6.39.1/arch/x86/kernel/dumpstack_32.c
13283--- linux-2.6.39.1/arch/x86/kernel/dumpstack_32.c 2011-05-19 00:06:34.000000000 -0400
13284+++ linux-2.6.39.1/arch/x86/kernel/dumpstack_32.c 2011-05-22 19:36:30.000000000 -0400
13285@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task
13286 bp = stack_frame(task, regs);
13287
13288 for (;;) {
13289- struct thread_info *context;
13290+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
13291
13292- context = (struct thread_info *)
13293- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
13294- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
13295+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
13296
13297- stack = (unsigned long *)context->previous_esp;
13298- if (!stack)
13299+ if (stack_start == task_stack_page(task))
13300 break;
13301+ stack = *(unsigned long **)stack_start;
13302 if (ops->stack(data, "IRQ") < 0)
13303 break;
13304 touch_nmi_watchdog();
13305@@ -96,21 +94,22 @@ void show_registers(struct pt_regs *regs
13306 * When in-kernel, we also print out the stack and code at the
13307 * time of the fault..
13308 */
13309- if (!user_mode_vm(regs)) {
13310+ if (!user_mode(regs)) {
13311 unsigned int code_prologue = code_bytes * 43 / 64;
13312 unsigned int code_len = code_bytes;
13313 unsigned char c;
13314 u8 *ip;
13315+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
13316
13317 printk(KERN_EMERG "Stack:\n");
13318 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
13319
13320 printk(KERN_EMERG "Code: ");
13321
13322- ip = (u8 *)regs->ip - code_prologue;
13323+ ip = (u8 *)regs->ip - code_prologue + cs_base;
13324 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
13325 /* try starting at IP */
13326- ip = (u8 *)regs->ip;
13327+ ip = (u8 *)regs->ip + cs_base;
13328 code_len = code_len - code_prologue + 1;
13329 }
13330 for (i = 0; i < code_len; i++, ip++) {
13331@@ -119,7 +118,7 @@ void show_registers(struct pt_regs *regs
13332 printk(" Bad EIP value.");
13333 break;
13334 }
13335- if (ip == (u8 *)regs->ip)
13336+ if (ip == (u8 *)regs->ip + cs_base)
13337 printk("<%02x> ", c);
13338 else
13339 printk("%02x ", c);
13340@@ -132,6 +131,7 @@ int is_valid_bugaddr(unsigned long ip)
13341 {
13342 unsigned short ud2;
13343
13344+ ip = ktla_ktva(ip);
13345 if (ip < PAGE_OFFSET)
13346 return 0;
13347 if (probe_kernel_address((unsigned short *)ip, ud2))
13348diff -urNp linux-2.6.39.1/arch/x86/kernel/dumpstack_64.c linux-2.6.39.1/arch/x86/kernel/dumpstack_64.c
13349--- linux-2.6.39.1/arch/x86/kernel/dumpstack_64.c 2011-05-19 00:06:34.000000000 -0400
13350+++ linux-2.6.39.1/arch/x86/kernel/dumpstack_64.c 2011-05-22 19:36:30.000000000 -0400
13351@@ -147,9 +147,9 @@ void dump_trace(struct task_struct *task
13352 unsigned long *irq_stack_end =
13353 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
13354 unsigned used = 0;
13355- struct thread_info *tinfo;
13356 int graph = 0;
13357 unsigned long dummy;
13358+ void *stack_start;
13359
13360 if (!task)
13361 task = current;
13362@@ -167,10 +167,10 @@ void dump_trace(struct task_struct *task
13363 * current stack address. If the stacks consist of nested
13364 * exceptions
13365 */
13366- tinfo = task_thread_info(task);
13367 for (;;) {
13368 char *id;
13369 unsigned long *estack_end;
13370+
13371 estack_end = in_exception_stack(cpu, (unsigned long)stack,
13372 &used, &id);
13373
13374@@ -178,7 +178,7 @@ void dump_trace(struct task_struct *task
13375 if (ops->stack(data, id) < 0)
13376 break;
13377
13378- bp = ops->walk_stack(tinfo, stack, bp, ops,
13379+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
13380 data, estack_end, &graph);
13381 ops->stack(data, "<EOE>");
13382 /*
13383@@ -197,7 +197,7 @@ void dump_trace(struct task_struct *task
13384 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
13385 if (ops->stack(data, "IRQ") < 0)
13386 break;
13387- bp = ops->walk_stack(tinfo, stack, bp,
13388+ bp = ops->walk_stack(task, irq_stack, stack, bp,
13389 ops, data, irq_stack_end, &graph);
13390 /*
13391 * We link to the next stack (which would be
13392@@ -218,7 +218,8 @@ void dump_trace(struct task_struct *task
13393 /*
13394 * This handles the process stack:
13395 */
13396- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
13397+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
13398+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
13399 put_cpu();
13400 }
13401 EXPORT_SYMBOL(dump_trace);
13402diff -urNp linux-2.6.39.1/arch/x86/kernel/dumpstack.c linux-2.6.39.1/arch/x86/kernel/dumpstack.c
13403--- linux-2.6.39.1/arch/x86/kernel/dumpstack.c 2011-05-19 00:06:34.000000000 -0400
13404+++ linux-2.6.39.1/arch/x86/kernel/dumpstack.c 2011-05-22 19:41:32.000000000 -0400
13405@@ -2,6 +2,9 @@
13406 * Copyright (C) 1991, 1992 Linus Torvalds
13407 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
13408 */
13409+#ifdef CONFIG_GRKERNSEC_HIDESYM
13410+#define __INCLUDED_BY_HIDESYM 1
13411+#endif
13412 #include <linux/kallsyms.h>
13413 #include <linux/kprobes.h>
13414 #include <linux/uaccess.h>
13415@@ -35,9 +38,8 @@ void printk_address(unsigned long addres
13416 static void
13417 print_ftrace_graph_addr(unsigned long addr, void *data,
13418 const struct stacktrace_ops *ops,
13419- struct thread_info *tinfo, int *graph)
13420+ struct task_struct *task, int *graph)
13421 {
13422- struct task_struct *task = tinfo->task;
13423 unsigned long ret_addr;
13424 int index = task->curr_ret_stack;
13425
13426@@ -58,7 +60,7 @@ print_ftrace_graph_addr(unsigned long ad
13427 static inline void
13428 print_ftrace_graph_addr(unsigned long addr, void *data,
13429 const struct stacktrace_ops *ops,
13430- struct thread_info *tinfo, int *graph)
13431+ struct task_struct *task, int *graph)
13432 { }
13433 #endif
13434
13435@@ -69,10 +71,8 @@ print_ftrace_graph_addr(unsigned long ad
13436 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
13437 */
13438
13439-static inline int valid_stack_ptr(struct thread_info *tinfo,
13440- void *p, unsigned int size, void *end)
13441+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
13442 {
13443- void *t = tinfo;
13444 if (end) {
13445 if (p < end && p >= (end-THREAD_SIZE))
13446 return 1;
13447@@ -83,14 +83,14 @@ static inline int valid_stack_ptr(struct
13448 }
13449
13450 unsigned long
13451-print_context_stack(struct thread_info *tinfo,
13452+print_context_stack(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 {
13457 struct stack_frame *frame = (struct stack_frame *)bp;
13458
13459- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
13460+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
13461 unsigned long addr;
13462
13463 addr = *stack;
13464@@ -102,7 +102,7 @@ print_context_stack(struct thread_info *
13465 } else {
13466 ops->address(data, addr, 0);
13467 }
13468- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
13469+ print_ftrace_graph_addr(addr, data, ops, task, graph);
13470 }
13471 stack++;
13472 }
13473@@ -111,7 +111,7 @@ print_context_stack(struct thread_info *
13474 EXPORT_SYMBOL_GPL(print_context_stack);
13475
13476 unsigned long
13477-print_context_stack_bp(struct thread_info *tinfo,
13478+print_context_stack_bp(struct task_struct *task, void *stack_start,
13479 unsigned long *stack, unsigned long bp,
13480 const struct stacktrace_ops *ops, void *data,
13481 unsigned long *end, int *graph)
13482@@ -119,7 +119,7 @@ print_context_stack_bp(struct thread_inf
13483 struct stack_frame *frame = (struct stack_frame *)bp;
13484 unsigned long *ret_addr = &frame->return_address;
13485
13486- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
13487+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
13488 unsigned long addr = *ret_addr;
13489
13490 if (!__kernel_text_address(addr))
13491@@ -128,7 +128,7 @@ print_context_stack_bp(struct thread_inf
13492 ops->address(data, addr, 1);
13493 frame = frame->next_frame;
13494 ret_addr = &frame->return_address;
13495- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
13496+ print_ftrace_graph_addr(addr, data, ops, task, graph);
13497 }
13498
13499 return (unsigned long)frame;
13500@@ -202,7 +202,7 @@ void dump_stack(void)
13501
13502 bp = stack_frame(current, NULL);
13503 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
13504- current->pid, current->comm, print_tainted(),
13505+ task_pid_nr(current), current->comm, print_tainted(),
13506 init_utsname()->release,
13507 (int)strcspn(init_utsname()->version, " "),
13508 init_utsname()->version);
13509@@ -238,6 +238,8 @@ unsigned __kprobes long oops_begin(void)
13510 }
13511 EXPORT_SYMBOL_GPL(oops_begin);
13512
13513+extern void gr_handle_kernel_exploit(void);
13514+
13515 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
13516 {
13517 if (regs && kexec_should_crash(current))
13518@@ -259,7 +261,10 @@ void __kprobes oops_end(unsigned long fl
13519 panic("Fatal exception in interrupt");
13520 if (panic_on_oops)
13521 panic("Fatal exception");
13522- do_exit(signr);
13523+
13524+ gr_handle_kernel_exploit();
13525+
13526+ do_group_exit(signr);
13527 }
13528
13529 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
13530@@ -286,7 +291,7 @@ int __kprobes __die(const char *str, str
13531
13532 show_registers(regs);
13533 #ifdef CONFIG_X86_32
13534- if (user_mode_vm(regs)) {
13535+ if (user_mode(regs)) {
13536 sp = regs->sp;
13537 ss = regs->ss & 0xffff;
13538 } else {
13539@@ -314,7 +319,7 @@ void die(const char *str, struct pt_regs
13540 unsigned long flags = oops_begin();
13541 int sig = SIGSEGV;
13542
13543- if (!user_mode_vm(regs))
13544+ if (!user_mode(regs))
13545 report_bug(regs->ip, regs);
13546
13547 if (__die(str, regs, err))
13548diff -urNp linux-2.6.39.1/arch/x86/kernel/early_printk.c linux-2.6.39.1/arch/x86/kernel/early_printk.c
13549--- linux-2.6.39.1/arch/x86/kernel/early_printk.c 2011-05-19 00:06:34.000000000 -0400
13550+++ linux-2.6.39.1/arch/x86/kernel/early_printk.c 2011-05-22 19:36:30.000000000 -0400
13551@@ -7,6 +7,7 @@
13552 #include <linux/pci_regs.h>
13553 #include <linux/pci_ids.h>
13554 #include <linux/errno.h>
13555+#include <linux/sched.h>
13556 #include <asm/io.h>
13557 #include <asm/processor.h>
13558 #include <asm/fcntl.h>
13559@@ -179,6 +180,8 @@ asmlinkage void early_printk(const char
13560 int n;
13561 va_list ap;
13562
13563+ pax_track_stack();
13564+
13565 va_start(ap, fmt);
13566 n = vscnprintf(buf, sizeof(buf), fmt, ap);
13567 early_console->write(early_console, buf, n);
13568diff -urNp linux-2.6.39.1/arch/x86/kernel/entry_32.S linux-2.6.39.1/arch/x86/kernel/entry_32.S
13569--- linux-2.6.39.1/arch/x86/kernel/entry_32.S 2011-05-19 00:06:34.000000000 -0400
13570+++ linux-2.6.39.1/arch/x86/kernel/entry_32.S 2011-05-23 17:07:00.000000000 -0400
13571@@ -185,13 +185,146 @@
13572 /*CFI_REL_OFFSET gs, PT_GS*/
13573 .endm
13574 .macro SET_KERNEL_GS reg
13575+
13576+#ifdef CONFIG_CC_STACKPROTECTOR
13577 movl $(__KERNEL_STACK_CANARY), \reg
13578+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
13579+ movl $(__USER_DS), \reg
13580+#else
13581+ xorl \reg, \reg
13582+#endif
13583+
13584 movl \reg, %gs
13585 .endm
13586
13587 #endif /* CONFIG_X86_32_LAZY_GS */
13588
13589-.macro SAVE_ALL
13590+.macro pax_enter_kernel
13591+#ifdef CONFIG_PAX_KERNEXEC
13592+ call pax_enter_kernel
13593+#endif
13594+.endm
13595+
13596+.macro pax_exit_kernel
13597+#ifdef CONFIG_PAX_KERNEXEC
13598+ call pax_exit_kernel
13599+#endif
13600+.endm
13601+
13602+#ifdef CONFIG_PAX_KERNEXEC
13603+ENTRY(pax_enter_kernel)
13604+#ifdef CONFIG_PARAVIRT
13605+ pushl %eax
13606+ pushl %ecx
13607+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
13608+ mov %eax, %esi
13609+#else
13610+ mov %cr0, %esi
13611+#endif
13612+ bts $16, %esi
13613+ jnc 1f
13614+ mov %cs, %esi
13615+ cmp $__KERNEL_CS, %esi
13616+ jz 3f
13617+ ljmp $__KERNEL_CS, $3f
13618+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
13619+2:
13620+#ifdef CONFIG_PARAVIRT
13621+ mov %esi, %eax
13622+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
13623+#else
13624+ mov %esi, %cr0
13625+#endif
13626+3:
13627+#ifdef CONFIG_PARAVIRT
13628+ popl %ecx
13629+ popl %eax
13630+#endif
13631+ ret
13632+ENDPROC(pax_enter_kernel)
13633+
13634+ENTRY(pax_exit_kernel)
13635+#ifdef CONFIG_PARAVIRT
13636+ pushl %eax
13637+ pushl %ecx
13638+#endif
13639+ mov %cs, %esi
13640+ cmp $__KERNEXEC_KERNEL_CS, %esi
13641+ jnz 2f
13642+#ifdef CONFIG_PARAVIRT
13643+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
13644+ mov %eax, %esi
13645+#else
13646+ mov %cr0, %esi
13647+#endif
13648+ btr $16, %esi
13649+ ljmp $__KERNEL_CS, $1f
13650+1:
13651+#ifdef CONFIG_PARAVIRT
13652+ mov %esi, %eax
13653+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
13654+#else
13655+ mov %esi, %cr0
13656+#endif
13657+2:
13658+#ifdef CONFIG_PARAVIRT
13659+ popl %ecx
13660+ popl %eax
13661+#endif
13662+ ret
13663+ENDPROC(pax_exit_kernel)
13664+#endif
13665+
13666+.macro pax_erase_kstack
13667+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
13668+ call pax_erase_kstack
13669+#endif
13670+.endm
13671+
13672+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
13673+/*
13674+ * ebp: thread_info
13675+ * ecx, edx: can be clobbered
13676+ */
13677+ENTRY(pax_erase_kstack)
13678+ pushl %edi
13679+ pushl %eax
13680+
13681+ mov TI_lowest_stack(%ebp), %edi
13682+ mov $-0xBEEF, %eax
13683+ std
13684+
13685+1: mov %edi, %ecx
13686+ and $THREAD_SIZE_asm - 1, %ecx
13687+ shr $2, %ecx
13688+ repne scasl
13689+ jecxz 2f
13690+
13691+ cmp $2*16, %ecx
13692+ jc 2f
13693+
13694+ mov $2*16, %ecx
13695+ repe scasl
13696+ jecxz 2f
13697+ jne 1b
13698+
13699+2: cld
13700+ mov %esp, %ecx
13701+ sub %edi, %ecx
13702+ shr $2, %ecx
13703+ rep stosl
13704+
13705+ mov TI_task_thread_sp0(%ebp), %edi
13706+ sub $128, %edi
13707+ mov %edi, TI_lowest_stack(%ebp)
13708+
13709+ popl %eax
13710+ popl %edi
13711+ ret
13712+ENDPROC(pax_erase_kstack)
13713+#endif
13714+
13715+.macro __SAVE_ALL _DS
13716 cld
13717 PUSH_GS
13718 pushl_cfi %fs
13719@@ -214,7 +347,7 @@
13720 CFI_REL_OFFSET ecx, 0
13721 pushl_cfi %ebx
13722 CFI_REL_OFFSET ebx, 0
13723- movl $(__USER_DS), %edx
13724+ movl $\_DS, %edx
13725 movl %edx, %ds
13726 movl %edx, %es
13727 movl $(__KERNEL_PERCPU), %edx
13728@@ -222,6 +355,15 @@
13729 SET_KERNEL_GS %edx
13730 .endm
13731
13732+.macro SAVE_ALL
13733+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
13734+ __SAVE_ALL __KERNEL_DS
13735+ pax_enter_kernel
13736+#else
13737+ __SAVE_ALL __USER_DS
13738+#endif
13739+.endm
13740+
13741 .macro RESTORE_INT_REGS
13742 popl_cfi %ebx
13743 CFI_RESTORE ebx
13744@@ -332,7 +474,15 @@ check_userspace:
13745 movb PT_CS(%esp), %al
13746 andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax
13747 cmpl $USER_RPL, %eax
13748+
13749+#ifdef CONFIG_PAX_KERNEXEC
13750+ jae resume_userspace
13751+
13752+ PAX_EXIT_KERNEL
13753+ jmp resume_kernel
13754+#else
13755 jb resume_kernel # not returning to v8086 or userspace
13756+#endif
13757
13758 ENTRY(resume_userspace)
13759 LOCKDEP_SYS_EXIT
13760@@ -344,7 +494,7 @@ ENTRY(resume_userspace)
13761 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
13762 # int/exception return?
13763 jne work_pending
13764- jmp restore_all
13765+ jmp restore_all_pax
13766 END(ret_from_exception)
13767
13768 #ifdef CONFIG_PREEMPT
13769@@ -394,23 +544,34 @@ sysenter_past_esp:
13770 /*CFI_REL_OFFSET cs, 0*/
13771 /*
13772 * Push current_thread_info()->sysenter_return to the stack.
13773- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
13774- * pushed above; +8 corresponds to copy_thread's esp0 setting.
13775 */
13776- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
13777+ pushl_cfi $0
13778 CFI_REL_OFFSET eip, 0
13779
13780 pushl_cfi %eax
13781 SAVE_ALL
13782+ GET_THREAD_INFO(%ebp)
13783+ movl TI_sysenter_return(%ebp),%ebp
13784+ movl %ebp,PT_EIP(%esp)
13785 ENABLE_INTERRUPTS(CLBR_NONE)
13786
13787 /*
13788 * Load the potential sixth argument from user stack.
13789 * Careful about security.
13790 */
13791+ movl PT_OLDESP(%esp),%ebp
13792+
13793+#ifdef CONFIG_PAX_MEMORY_UDEREF
13794+ mov PT_OLDSS(%esp),%ds
13795+1: movl %ds:(%ebp),%ebp
13796+ push %ss
13797+ pop %ds
13798+#else
13799 cmpl $__PAGE_OFFSET-3,%ebp
13800 jae syscall_fault
13801 1: movl (%ebp),%ebp
13802+#endif
13803+
13804 movl %ebp,PT_EBP(%esp)
13805 .section __ex_table,"a"
13806 .align 4
13807@@ -433,12 +594,23 @@ sysenter_do_call:
13808 testl $_TIF_ALLWORK_MASK, %ecx
13809 jne sysexit_audit
13810 sysenter_exit:
13811+
13812+#ifdef CONFIG_PAX_RANDKSTACK
13813+ pushl_cfi %eax
13814+ call pax_randomize_kstack
13815+ popl_cfi %eax
13816+#endif
13817+
13818+ pax_erase_kstack
13819+
13820 /* if something modifies registers it must also disable sysexit */
13821 movl PT_EIP(%esp), %edx
13822 movl PT_OLDESP(%esp), %ecx
13823 xorl %ebp,%ebp
13824 TRACE_IRQS_ON
13825 1: mov PT_FS(%esp), %fs
13826+2: mov PT_DS(%esp), %ds
13827+3: mov PT_ES(%esp), %es
13828 PTGS_TO_GS
13829 ENABLE_INTERRUPTS_SYSEXIT
13830
13831@@ -455,6 +627,9 @@ sysenter_audit:
13832 movl %eax,%edx /* 2nd arg: syscall number */
13833 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
13834 call audit_syscall_entry
13835+
13836+ pax_erase_kstack
13837+
13838 pushl_cfi %ebx
13839 movl PT_EAX(%esp),%eax /* reload syscall number */
13840 jmp sysenter_do_call
13841@@ -481,11 +656,17 @@ sysexit_audit:
13842
13843 CFI_ENDPROC
13844 .pushsection .fixup,"ax"
13845-2: movl $0,PT_FS(%esp)
13846+4: movl $0,PT_FS(%esp)
13847+ jmp 1b
13848+5: movl $0,PT_DS(%esp)
13849+ jmp 1b
13850+6: movl $0,PT_ES(%esp)
13851 jmp 1b
13852 .section __ex_table,"a"
13853 .align 4
13854- .long 1b,2b
13855+ .long 1b,4b
13856+ .long 2b,5b
13857+ .long 3b,6b
13858 .popsection
13859 PTGS_TO_GS_EX
13860 ENDPROC(ia32_sysenter_target)
13861@@ -518,6 +699,14 @@ syscall_exit:
13862 testl $_TIF_ALLWORK_MASK, %ecx # current->work
13863 jne syscall_exit_work
13864
13865+restore_all_pax:
13866+
13867+#ifdef CONFIG_PAX_RANDKSTACK
13868+ call pax_randomize_kstack
13869+#endif
13870+
13871+ pax_erase_kstack
13872+
13873 restore_all:
13874 TRACE_IRQS_IRET
13875 restore_all_notrace:
13876@@ -577,14 +766,21 @@ ldt_ss:
13877 * compensating for the offset by changing to the ESPFIX segment with
13878 * a base address that matches for the difference.
13879 */
13880-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
13881+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
13882 mov %esp, %edx /* load kernel esp */
13883 mov PT_OLDESP(%esp), %eax /* load userspace esp */
13884 mov %dx, %ax /* eax: new kernel esp */
13885 sub %eax, %edx /* offset (low word is 0) */
13886+#ifdef CONFIG_SMP
13887+ movl PER_CPU_VAR(cpu_number), %ebx
13888+ shll $PAGE_SHIFT_asm, %ebx
13889+ addl $cpu_gdt_table, %ebx
13890+#else
13891+ movl $cpu_gdt_table, %ebx
13892+#endif
13893 shr $16, %edx
13894- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
13895- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
13896+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
13897+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
13898 pushl_cfi $__ESPFIX_SS
13899 pushl_cfi %eax /* new kernel esp */
13900 /* Disable interrupts, but do not irqtrace this section: we
13901@@ -613,29 +809,23 @@ work_resched:
13902 movl TI_flags(%ebp), %ecx
13903 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
13904 # than syscall tracing?
13905- jz restore_all
13906+ jz restore_all_pax
13907 testb $_TIF_NEED_RESCHED, %cl
13908 jnz work_resched
13909
13910 work_notifysig: # deal with pending signals and
13911 # notify-resume requests
13912+ movl %esp, %eax
13913 #ifdef CONFIG_VM86
13914 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
13915- movl %esp, %eax
13916- jne work_notifysig_v86 # returning to kernel-space or
13917+ jz 1f # returning to kernel-space or
13918 # vm86-space
13919- xorl %edx, %edx
13920- call do_notify_resume
13921- jmp resume_userspace_sig
13922
13923- ALIGN
13924-work_notifysig_v86:
13925 pushl_cfi %ecx # save ti_flags for do_notify_resume
13926 call save_v86_state # %eax contains pt_regs pointer
13927 popl_cfi %ecx
13928 movl %eax, %esp
13929-#else
13930- movl %esp, %eax
13931+1:
13932 #endif
13933 xorl %edx, %edx
13934 call do_notify_resume
13935@@ -648,6 +838,9 @@ syscall_trace_entry:
13936 movl $-ENOSYS,PT_EAX(%esp)
13937 movl %esp, %eax
13938 call syscall_trace_enter
13939+
13940+ pax_erase_kstack
13941+
13942 /* What it returned is what we'll actually use. */
13943 cmpl $(nr_syscalls), %eax
13944 jnae syscall_call
13945@@ -670,6 +863,10 @@ END(syscall_exit_work)
13946
13947 RING0_INT_FRAME # can't unwind into user space anyway
13948 syscall_fault:
13949+#ifdef CONFIG_PAX_MEMORY_UDEREF
13950+ push %ss
13951+ pop %ds
13952+#endif
13953 GET_THREAD_INFO(%ebp)
13954 movl $-EFAULT,PT_EAX(%esp)
13955 jmp resume_userspace
13956@@ -752,6 +949,36 @@ ptregs_clone:
13957 CFI_ENDPROC
13958 ENDPROC(ptregs_clone)
13959
13960+ ALIGN;
13961+ENTRY(kernel_execve)
13962+ CFI_STARTPROC
13963+ pushl_cfi %ebp
13964+ sub $PT_OLDSS+4,%esp
13965+ pushl_cfi %edi
13966+ pushl_cfi %ecx
13967+ pushl_cfi %eax
13968+ lea 3*4(%esp),%edi
13969+ mov $PT_OLDSS/4+1,%ecx
13970+ xorl %eax,%eax
13971+ rep stosl
13972+ popl_cfi %eax
13973+ popl_cfi %ecx
13974+ popl_cfi %edi
13975+ movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
13976+ pushl_cfi %esp
13977+ call sys_execve
13978+ add $4,%esp
13979+ CFI_ADJUST_CFA_OFFSET -4
13980+ GET_THREAD_INFO(%ebp)
13981+ test %eax,%eax
13982+ jz syscall_exit
13983+ add $PT_OLDSS+4,%esp
13984+ CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
13985+ popl_cfi %ebp
13986+ ret
13987+ CFI_ENDPROC
13988+ENDPROC(kernel_execve)
13989+
13990 .macro FIXUP_ESPFIX_STACK
13991 /*
13992 * Switch back for ESPFIX stack to the normal zerobased stack
13993@@ -761,8 +988,15 @@ ENDPROC(ptregs_clone)
13994 * normal stack and adjusts ESP with the matching offset.
13995 */
13996 /* fixup the stack */
13997- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
13998- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
13999+#ifdef CONFIG_SMP
14000+ movl PER_CPU_VAR(cpu_number), %ebx
14001+ shll $PAGE_SHIFT_asm, %ebx
14002+ addl $cpu_gdt_table, %ebx
14003+#else
14004+ movl $cpu_gdt_table, %ebx
14005+#endif
14006+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
14007+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
14008 shl $16, %eax
14009 addl %esp, %eax /* the adjusted stack pointer */
14010 pushl_cfi $__KERNEL_DS
14011@@ -1213,7 +1447,6 @@ return_to_handler:
14012 jmp *%ecx
14013 #endif
14014
14015-.section .rodata,"a"
14016 #include "syscall_table_32.S"
14017
14018 syscall_table_size=(.-sys_call_table)
14019@@ -1259,9 +1492,12 @@ error_code:
14020 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
14021 REG_TO_PTGS %ecx
14022 SET_KERNEL_GS %ecx
14023- movl $(__USER_DS), %ecx
14024+ movl $(__KERNEL_DS), %ecx
14025 movl %ecx, %ds
14026 movl %ecx, %es
14027+
14028+ pax_enter_kernel
14029+
14030 TRACE_IRQS_OFF
14031 movl %esp,%eax # pt_regs pointer
14032 call *%edi
14033@@ -1346,6 +1582,9 @@ nmi_stack_correct:
14034 xorl %edx,%edx # zero error code
14035 movl %esp,%eax # pt_regs pointer
14036 call do_nmi
14037+
14038+ pax_exit_kernel
14039+
14040 jmp restore_all_notrace
14041 CFI_ENDPROC
14042
14043@@ -1382,6 +1621,9 @@ nmi_espfix_stack:
14044 FIXUP_ESPFIX_STACK # %eax == %esp
14045 xorl %edx,%edx # zero error code
14046 call do_nmi
14047+
14048+ pax_exit_kernel
14049+
14050 RESTORE_REGS
14051 lss 12+4(%esp), %esp # back to espfix stack
14052 CFI_ADJUST_CFA_OFFSET -24
14053diff -urNp linux-2.6.39.1/arch/x86/kernel/entry_64.S linux-2.6.39.1/arch/x86/kernel/entry_64.S
14054--- linux-2.6.39.1/arch/x86/kernel/entry_64.S 2011-05-19 00:06:34.000000000 -0400
14055+++ linux-2.6.39.1/arch/x86/kernel/entry_64.S 2011-05-23 17:10:49.000000000 -0400
14056@@ -53,6 +53,7 @@
14057 #include <asm/paravirt.h>
14058 #include <asm/ftrace.h>
14059 #include <asm/percpu.h>
14060+#include <asm/pgtable.h>
14061
14062 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
14063 #include <linux/elf-em.h>
14064@@ -176,6 +177,259 @@ ENTRY(native_usergs_sysret64)
14065 ENDPROC(native_usergs_sysret64)
14066 #endif /* CONFIG_PARAVIRT */
14067
14068+ .macro ljmpq sel, off
14069+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
14070+ .byte 0x48; ljmp *1234f(%rip)
14071+ .pushsection .rodata
14072+ .align 16
14073+ 1234: .quad \off; .word \sel
14074+ .popsection
14075+#else
14076+ pushq $\sel
14077+ pushq $\off
14078+ lretq
14079+#endif
14080+ .endm
14081+
14082+ .macro pax_enter_kernel
14083+#ifdef CONFIG_PAX_KERNEXEC
14084+ call pax_enter_kernel
14085+#endif
14086+ .endm
14087+
14088+ .macro pax_exit_kernel
14089+#ifdef CONFIG_PAX_KERNEXEC
14090+ call pax_exit_kernel
14091+#endif
14092+ .endm
14093+
14094+#ifdef CONFIG_PAX_KERNEXEC
14095+ENTRY(pax_enter_kernel)
14096+ pushq %rdi
14097+
14098+#ifdef CONFIG_PARAVIRT
14099+ PV_SAVE_REGS(CLBR_RDI)
14100+#endif
14101+
14102+ GET_CR0_INTO_RDI
14103+ bts $16,%rdi
14104+ jnc 1f
14105+ mov %cs,%edi
14106+ cmp $__KERNEL_CS,%edi
14107+ jz 3f
14108+ ljmpq __KERNEL_CS,3f
14109+1: ljmpq __KERNEXEC_KERNEL_CS,2f
14110+2: SET_RDI_INTO_CR0
14111+3:
14112+
14113+#ifdef CONFIG_PARAVIRT
14114+ PV_RESTORE_REGS(CLBR_RDI)
14115+#endif
14116+
14117+ popq %rdi
14118+ retq
14119+ENDPROC(pax_enter_kernel)
14120+
14121+ENTRY(pax_exit_kernel)
14122+ pushq %rdi
14123+
14124+#ifdef CONFIG_PARAVIRT
14125+ PV_SAVE_REGS(CLBR_RDI)
14126+#endif
14127+
14128+ mov %cs,%rdi
14129+ cmp $__KERNEXEC_KERNEL_CS,%edi
14130+ jnz 2f
14131+ GET_CR0_INTO_RDI
14132+ btr $16,%rdi
14133+ ljmpq __KERNEL_CS,1f
14134+1: SET_RDI_INTO_CR0
14135+2:
14136+
14137+#ifdef CONFIG_PARAVIRT
14138+ PV_RESTORE_REGS(CLBR_RDI);
14139+#endif
14140+
14141+ popq %rdi
14142+ retq
14143+ENDPROC(pax_exit_kernel)
14144+#endif
14145+
14146+ .macro pax_enter_kernel_user
14147+#ifdef CONFIG_PAX_MEMORY_UDEREF
14148+ call pax_enter_kernel_user
14149+#endif
14150+ .endm
14151+
14152+ .macro pax_exit_kernel_user
14153+#ifdef CONFIG_PAX_MEMORY_UDEREF
14154+ call pax_exit_kernel_user
14155+#endif
14156+#ifdef CONFIG_PAX_RANDKSTACK
14157+ push %rax
14158+ call pax_randomize_kstack
14159+ pop %rax
14160+#endif
14161+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14162+ call pax_erase_kstack
14163+#endif
14164+ .endm
14165+
14166+#ifdef CONFIG_PAX_MEMORY_UDEREF
14167+ENTRY(pax_enter_kernel_user)
14168+ pushq %rdi
14169+ pushq %rbx
14170+
14171+#ifdef CONFIG_PARAVIRT
14172+ PV_SAVE_REGS(CLBR_RDI)
14173+#endif
14174+
14175+ GET_CR3_INTO_RDI
14176+ mov %rdi,%rbx
14177+ add $__START_KERNEL_map,%rbx
14178+ sub phys_base(%rip),%rbx
14179+
14180+#ifdef CONFIG_PARAVIRT
14181+ pushq %rdi
14182+ cmpl $0, pv_info+PARAVIRT_enabled
14183+ jz 1f
14184+ i = 0
14185+ .rept USER_PGD_PTRS
14186+ mov i*8(%rbx),%rsi
14187+ mov $0,%sil
14188+ lea i*8(%rbx),%rdi
14189+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd)
14190+ i = i + 1
14191+ .endr
14192+ jmp 2f
14193+1:
14194+#endif
14195+
14196+ i = 0
14197+ .rept USER_PGD_PTRS
14198+ movb $0,i*8(%rbx)
14199+ i = i + 1
14200+ .endr
14201+
14202+#ifdef CONFIG_PARAVIRT
14203+2: popq %rdi
14204+#endif
14205+ SET_RDI_INTO_CR3
14206+
14207+#ifdef CONFIG_PAX_KERNEXEC
14208+ GET_CR0_INTO_RDI
14209+ bts $16,%rdi
14210+ SET_RDI_INTO_CR0
14211+#endif
14212+
14213+#ifdef CONFIG_PARAVIRT
14214+ PV_RESTORE_REGS(CLBR_RDI)
14215+#endif
14216+
14217+ popq %rbx
14218+ popq %rdi
14219+ retq
14220+ENDPROC(pax_enter_kernel_user)
14221+
14222+ENTRY(pax_exit_kernel_user)
14223+ push %rdi
14224+
14225+#ifdef CONFIG_PARAVIRT
14226+ pushq %rbx
14227+ PV_SAVE_REGS(CLBR_RDI)
14228+#endif
14229+
14230+#ifdef CONFIG_PAX_KERNEXEC
14231+ GET_CR0_INTO_RDI
14232+ btr $16,%rdi
14233+ SET_RDI_INTO_CR0
14234+#endif
14235+
14236+ GET_CR3_INTO_RDI
14237+ add $__START_KERNEL_map,%rdi
14238+ sub phys_base(%rip),%rdi
14239+
14240+#ifdef CONFIG_PARAVIRT
14241+ cmpl $0, pv_info+PARAVIRT_enabled
14242+ jz 1f
14243+ mov %rdi,%rbx
14244+ i = 0
14245+ .rept USER_PGD_PTRS
14246+ mov i*8(%rbx),%rsi
14247+ mov $0x67,%sil
14248+ lea i*8(%rbx),%rdi
14249+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd)
14250+ i = i + 1
14251+ .endr
14252+ jmp 2f
14253+1:
14254+#endif
14255+
14256+ i = 0
14257+ .rept USER_PGD_PTRS
14258+ movb $0x67,i*8(%rdi)
14259+ i = i + 1
14260+ .endr
14261+
14262+#ifdef CONFIG_PARAVIRT
14263+2: PV_RESTORE_REGS(CLBR_RDI)
14264+ popq %rbx
14265+#endif
14266+
14267+ popq %rdi
14268+ retq
14269+ENDPROC(pax_exit_kernel_user)
14270+#endif
14271+
14272+ .macro pax_erase_kstack
14273+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14274+ call pax_erase_kstack
14275+#endif
14276+ .endm
14277+
14278+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14279+/*
14280+ * r10: thread_info
14281+ * rcx, rdx: can be clobbered
14282+ */
14283+ENTRY(pax_erase_kstack)
14284+ pushq %rdi
14285+ pushq %rax
14286+
14287+ GET_THREAD_INFO(%r10)
14288+ mov TI_lowest_stack(%r10), %rdi
14289+ mov $-0xBEEF, %rax
14290+ std
14291+
14292+1: mov %edi, %ecx
14293+ and $THREAD_SIZE_asm - 1, %ecx
14294+ shr $3, %ecx
14295+ repne scasq
14296+ jecxz 2f
14297+
14298+ cmp $2*8, %ecx
14299+ jc 2f
14300+
14301+ mov $2*8, %ecx
14302+ repe scasq
14303+ jecxz 2f
14304+ jne 1b
14305+
14306+2: cld
14307+ mov %esp, %ecx
14308+ sub %edi, %ecx
14309+ shr $3, %ecx
14310+ rep stosq
14311+
14312+ mov TI_task_thread_sp0(%r10), %rdi
14313+ sub $256, %rdi
14314+ mov %rdi, TI_lowest_stack(%r10)
14315+
14316+ popq %rax
14317+ popq %rdi
14318+ ret
14319+ENDPROC(pax_erase_kstack)
14320+#endif
14321
14322 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
14323 #ifdef CONFIG_TRACE_IRQFLAGS
14324@@ -318,7 +572,7 @@ ENTRY(save_args)
14325 leaq -RBP+8(%rsp),%rdi /* arg1 for handler */
14326 movq_cfi rbp, 8 /* push %rbp */
14327 leaq 8(%rsp), %rbp /* mov %rsp, %ebp */
14328- testl $3, CS(%rdi)
14329+ testb $3, CS(%rdi)
14330 je 1f
14331 SWAPGS
14332 /*
14333@@ -409,7 +663,7 @@ ENTRY(ret_from_fork)
14334
14335 RESTORE_REST
14336
14337- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
14338+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
14339 je int_ret_from_sys_call
14340
14341 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
14342@@ -455,7 +709,7 @@ END(ret_from_fork)
14343 ENTRY(system_call)
14344 CFI_STARTPROC simple
14345 CFI_SIGNAL_FRAME
14346- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
14347+ CFI_DEF_CFA rsp,0
14348 CFI_REGISTER rip,rcx
14349 /*CFI_REGISTER rflags,r11*/
14350 SWAPGS_UNSAFE_STACK
14351@@ -468,12 +722,13 @@ ENTRY(system_call_after_swapgs)
14352
14353 movq %rsp,PER_CPU_VAR(old_rsp)
14354 movq PER_CPU_VAR(kernel_stack),%rsp
14355+ pax_enter_kernel_user
14356 /*
14357 * No need to follow this irqs off/on section - it's straight
14358 * and short:
14359 */
14360 ENABLE_INTERRUPTS(CLBR_NONE)
14361- SAVE_ARGS 8,1
14362+ SAVE_ARGS 8*6,1
14363 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
14364 movq %rcx,RIP-ARGOFFSET(%rsp)
14365 CFI_REL_OFFSET rip,RIP-ARGOFFSET
14366@@ -502,6 +757,7 @@ sysret_check:
14367 andl %edi,%edx
14368 jnz sysret_careful
14369 CFI_REMEMBER_STATE
14370+ pax_exit_kernel_user
14371 /*
14372 * sysretq will re-enable interrupts:
14373 */
14374@@ -560,6 +816,9 @@ auditsys:
14375 movq %rax,%rsi /* 2nd arg: syscall number */
14376 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
14377 call audit_syscall_entry
14378+
14379+ pax_erase_kstack
14380+
14381 LOAD_ARGS 0 /* reload call-clobbered registers */
14382 jmp system_call_fastpath
14383
14384@@ -590,6 +849,9 @@ tracesys:
14385 FIXUP_TOP_OF_STACK %rdi
14386 movq %rsp,%rdi
14387 call syscall_trace_enter
14388+
14389+ pax_erase_kstack
14390+
14391 /*
14392 * Reload arg registers from stack in case ptrace changed them.
14393 * We don't reload %rax because syscall_trace_enter() returned
14394@@ -611,7 +873,7 @@ tracesys:
14395 GLOBAL(int_ret_from_sys_call)
14396 DISABLE_INTERRUPTS(CLBR_NONE)
14397 TRACE_IRQS_OFF
14398- testl $3,CS-ARGOFFSET(%rsp)
14399+ testb $3,CS-ARGOFFSET(%rsp)
14400 je retint_restore_args
14401 movl $_TIF_ALLWORK_MASK,%edi
14402 /* edi: mask to check */
14403@@ -793,6 +1055,16 @@ END(interrupt)
14404 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
14405 call save_args
14406 PARTIAL_FRAME 0
14407+#ifdef CONFIG_PAX_MEMORY_UDEREF
14408+ testb $3, CS(%rdi)
14409+ jnz 1f
14410+ pax_enter_kernel
14411+ jmp 2f
14412+1: pax_enter_kernel_user
14413+2:
14414+#else
14415+ pax_enter_kernel
14416+#endif
14417 call \func
14418 .endm
14419
14420@@ -825,7 +1097,7 @@ ret_from_intr:
14421 CFI_ADJUST_CFA_OFFSET -8
14422 exit_intr:
14423 GET_THREAD_INFO(%rcx)
14424- testl $3,CS-ARGOFFSET(%rsp)
14425+ testb $3,CS-ARGOFFSET(%rsp)
14426 je retint_kernel
14427
14428 /* Interrupt came from user space */
14429@@ -847,12 +1119,14 @@ retint_swapgs: /* return to user-space
14430 * The iretq could re-enable interrupts:
14431 */
14432 DISABLE_INTERRUPTS(CLBR_ANY)
14433+ pax_exit_kernel_user
14434 TRACE_IRQS_IRETQ
14435 SWAPGS
14436 jmp restore_args
14437
14438 retint_restore_args: /* return to kernel space */
14439 DISABLE_INTERRUPTS(CLBR_ANY)
14440+ pax_exit_kernel
14441 /*
14442 * The iretq could re-enable interrupts:
14443 */
14444@@ -1027,6 +1301,16 @@ ENTRY(\sym)
14445 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
14446 call error_entry
14447 DEFAULT_FRAME 0
14448+#ifdef CONFIG_PAX_MEMORY_UDEREF
14449+ testb $3, CS(%rsp)
14450+ jnz 1f
14451+ pax_enter_kernel
14452+ jmp 2f
14453+1: pax_enter_kernel_user
14454+2:
14455+#else
14456+ pax_enter_kernel
14457+#endif
14458 movq %rsp,%rdi /* pt_regs pointer */
14459 xorl %esi,%esi /* no error code */
14460 call \do_sym
14461@@ -1044,6 +1328,16 @@ 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 call \do_sym
14478@@ -1052,7 +1346,7 @@ ENTRY(\sym)
14479 END(\sym)
14480 .endm
14481
14482-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
14483+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
14484 .macro paranoidzeroentry_ist sym do_sym ist
14485 ENTRY(\sym)
14486 INTR_FRAME
14487@@ -1062,8 +1356,24 @@ ENTRY(\sym)
14488 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
14489 call save_paranoid
14490 TRACE_IRQS_OFF
14491+#ifdef CONFIG_PAX_MEMORY_UDEREF
14492+ testb $3, CS(%rsp)
14493+ jnz 1f
14494+ pax_enter_kernel
14495+ jmp 2f
14496+1: pax_enter_kernel_user
14497+2:
14498+#else
14499+ pax_enter_kernel
14500+#endif
14501 movq %rsp,%rdi /* pt_regs pointer */
14502 xorl %esi,%esi /* no error code */
14503+#ifdef CONFIG_SMP
14504+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
14505+ lea init_tss(%r12), %r12
14506+#else
14507+ lea init_tss(%rip), %r12
14508+#endif
14509 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
14510 call \do_sym
14511 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
14512@@ -1080,6 +1390,16 @@ ENTRY(\sym)
14513 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
14514 call error_entry
14515 DEFAULT_FRAME 0
14516+#ifdef CONFIG_PAX_MEMORY_UDEREF
14517+ testb $3, CS(%rsp)
14518+ jnz 1f
14519+ pax_enter_kernel
14520+ jmp 2f
14521+1: pax_enter_kernel_user
14522+2:
14523+#else
14524+ pax_enter_kernel
14525+#endif
14526 movq %rsp,%rdi /* pt_regs pointer */
14527 movq ORIG_RAX(%rsp),%rsi /* get error code */
14528 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
14529@@ -1099,6 +1419,16 @@ ENTRY(\sym)
14530 call save_paranoid
14531 DEFAULT_FRAME 0
14532 TRACE_IRQS_OFF
14533+#ifdef CONFIG_PAX_MEMORY_UDEREF
14534+ testb $3, CS(%rsp)
14535+ jnz 1f
14536+ pax_enter_kernel
14537+ jmp 2f
14538+1: pax_enter_kernel_user
14539+2:
14540+#else
14541+ pax_enter_kernel
14542+#endif
14543 movq %rsp,%rdi /* pt_regs pointer */
14544 movq ORIG_RAX(%rsp),%rsi /* get error code */
14545 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
14546@@ -1361,14 +1691,27 @@ ENTRY(paranoid_exit)
14547 TRACE_IRQS_OFF
14548 testl %ebx,%ebx /* swapgs needed? */
14549 jnz paranoid_restore
14550- testl $3,CS(%rsp)
14551+ testb $3,CS(%rsp)
14552 jnz paranoid_userspace
14553+#ifdef CONFIG_PAX_MEMORY_UDEREF
14554+ pax_exit_kernel
14555+ TRACE_IRQS_IRETQ 0
14556+ SWAPGS_UNSAFE_STACK
14557+ RESTORE_ALL 8
14558+ jmp irq_return
14559+#endif
14560 paranoid_swapgs:
14561+#ifdef CONFIG_PAX_MEMORY_UDEREF
14562+ pax_exit_kernel_user
14563+#else
14564+ pax_exit_kernel
14565+#endif
14566 TRACE_IRQS_IRETQ 0
14567 SWAPGS_UNSAFE_STACK
14568 RESTORE_ALL 8
14569 jmp irq_return
14570 paranoid_restore:
14571+ pax_exit_kernel
14572 TRACE_IRQS_IRETQ 0
14573 RESTORE_ALL 8
14574 jmp irq_return
14575@@ -1426,7 +1769,7 @@ ENTRY(error_entry)
14576 movq_cfi r14, R14+8
14577 movq_cfi r15, R15+8
14578 xorl %ebx,%ebx
14579- testl $3,CS+8(%rsp)
14580+ testb $3,CS+8(%rsp)
14581 je error_kernelspace
14582 error_swapgs:
14583 SWAPGS
14584@@ -1490,6 +1833,16 @@ ENTRY(nmi)
14585 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
14586 call save_paranoid
14587 DEFAULT_FRAME 0
14588+#ifdef CONFIG_PAX_MEMORY_UDEREF
14589+ testb $3, CS(%rsp)
14590+ jnz 1f
14591+ pax_enter_kernel
14592+ jmp 2f
14593+1: pax_enter_kernel_user
14594+2:
14595+#else
14596+ pax_enter_kernel
14597+#endif
14598 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
14599 movq %rsp,%rdi
14600 movq $-1,%rsi
14601@@ -1500,11 +1853,25 @@ ENTRY(nmi)
14602 DISABLE_INTERRUPTS(CLBR_NONE)
14603 testl %ebx,%ebx /* swapgs needed? */
14604 jnz nmi_restore
14605- testl $3,CS(%rsp)
14606+ testb $3,CS(%rsp)
14607 jnz nmi_userspace
14608+#ifdef CONFIG_PAX_MEMORY_UDEREF
14609+ pax_exit_kernel
14610+ SWAPGS_UNSAFE_STACK
14611+ RESTORE_ALL 8
14612+ jmp irq_return
14613+#endif
14614 nmi_swapgs:
14615+#ifdef CONFIG_PAX_MEMORY_UDEREF
14616+ pax_exit_kernel_user
14617+#else
14618+ pax_exit_kernel
14619+#endif
14620 SWAPGS_UNSAFE_STACK
14621+ RESTORE_ALL 8
14622+ jmp irq_return
14623 nmi_restore:
14624+ pax_exit_kernel
14625 RESTORE_ALL 8
14626 jmp irq_return
14627 nmi_userspace:
14628diff -urNp linux-2.6.39.1/arch/x86/kernel/ftrace.c linux-2.6.39.1/arch/x86/kernel/ftrace.c
14629--- linux-2.6.39.1/arch/x86/kernel/ftrace.c 2011-05-19 00:06:34.000000000 -0400
14630+++ linux-2.6.39.1/arch/x86/kernel/ftrace.c 2011-05-22 19:36:30.000000000 -0400
14631@@ -126,7 +126,7 @@ static void *mod_code_ip; /* holds the
14632 static void *mod_code_newcode; /* holds the text to write to the IP */
14633
14634 static unsigned nmi_wait_count;
14635-static atomic_t nmi_update_count = ATOMIC_INIT(0);
14636+static atomic_unchecked_t nmi_update_count = ATOMIC_INIT(0);
14637
14638 int ftrace_arch_read_dyn_info(char *buf, int size)
14639 {
14640@@ -134,7 +134,7 @@ int ftrace_arch_read_dyn_info(char *buf,
14641
14642 r = snprintf(buf, size, "%u %u",
14643 nmi_wait_count,
14644- atomic_read(&nmi_update_count));
14645+ atomic_read_unchecked(&nmi_update_count));
14646 return r;
14647 }
14648
14649@@ -177,8 +177,10 @@ void ftrace_nmi_enter(void)
14650
14651 if (atomic_inc_return(&nmi_running) & MOD_CODE_WRITE_FLAG) {
14652 smp_rmb();
14653+ pax_open_kernel();
14654 ftrace_mod_code();
14655- atomic_inc(&nmi_update_count);
14656+ pax_close_kernel();
14657+ atomic_inc_unchecked(&nmi_update_count);
14658 }
14659 /* Must have previous changes seen before executions */
14660 smp_mb();
14661@@ -271,6 +273,8 @@ ftrace_modify_code(unsigned long ip, uns
14662 {
14663 unsigned char replaced[MCOUNT_INSN_SIZE];
14664
14665+ ip = ktla_ktva(ip);
14666+
14667 /*
14668 * Note: Due to modules and __init, code can
14669 * disappear and change, we need to protect against faulting
14670@@ -327,7 +331,7 @@ int ftrace_update_ftrace_func(ftrace_fun
14671 unsigned char old[MCOUNT_INSN_SIZE], *new;
14672 int ret;
14673
14674- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
14675+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
14676 new = ftrace_call_replace(ip, (unsigned long)func);
14677 ret = ftrace_modify_code(ip, old, new);
14678
14679@@ -353,6 +357,8 @@ static int ftrace_mod_jmp(unsigned long
14680 {
14681 unsigned char code[MCOUNT_INSN_SIZE];
14682
14683+ ip = ktla_ktva(ip);
14684+
14685 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
14686 return -EFAULT;
14687
14688diff -urNp linux-2.6.39.1/arch/x86/kernel/head32.c linux-2.6.39.1/arch/x86/kernel/head32.c
14689--- linux-2.6.39.1/arch/x86/kernel/head32.c 2011-05-19 00:06:34.000000000 -0400
14690+++ linux-2.6.39.1/arch/x86/kernel/head32.c 2011-05-22 19:36:30.000000000 -0400
14691@@ -19,6 +19,7 @@
14692 #include <asm/io_apic.h>
14693 #include <asm/bios_ebda.h>
14694 #include <asm/tlbflush.h>
14695+#include <asm/boot.h>
14696
14697 static void __init i386_default_early_setup(void)
14698 {
14699@@ -34,7 +35,7 @@ void __init i386_start_kernel(void)
14700 {
14701 memblock_init();
14702
14703- memblock_x86_reserve_range(__pa_symbol(&_text), __pa_symbol(&__bss_stop), "TEXT DATA BSS");
14704+ memblock_x86_reserve_range(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop), "TEXT DATA BSS");
14705
14706 #ifdef CONFIG_BLK_DEV_INITRD
14707 /* Reserve INITRD */
14708diff -urNp linux-2.6.39.1/arch/x86/kernel/head_32.S linux-2.6.39.1/arch/x86/kernel/head_32.S
14709--- linux-2.6.39.1/arch/x86/kernel/head_32.S 2011-05-19 00:06:34.000000000 -0400
14710+++ linux-2.6.39.1/arch/x86/kernel/head_32.S 2011-05-22 19:36:30.000000000 -0400
14711@@ -25,6 +25,12 @@
14712 /* Physical address */
14713 #define pa(X) ((X) - __PAGE_OFFSET)
14714
14715+#ifdef CONFIG_PAX_KERNEXEC
14716+#define ta(X) (X)
14717+#else
14718+#define ta(X) ((X) - __PAGE_OFFSET)
14719+#endif
14720+
14721 /*
14722 * References to members of the new_cpu_data structure.
14723 */
14724@@ -54,11 +60,7 @@
14725 * and small than max_low_pfn, otherwise will waste some page table entries
14726 */
14727
14728-#if PTRS_PER_PMD > 1
14729-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
14730-#else
14731-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
14732-#endif
14733+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
14734
14735 /* Number of possible pages in the lowmem region */
14736 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
14737@@ -77,6 +79,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_P
14738 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
14739
14740 /*
14741+ * Real beginning of normal "text" segment
14742+ */
14743+ENTRY(stext)
14744+ENTRY(_stext)
14745+
14746+/*
14747 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
14748 * %esi points to the real-mode code as a 32-bit pointer.
14749 * CS and DS must be 4 GB flat segments, but we don't depend on
14750@@ -84,6 +92,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
14751 * can.
14752 */
14753 __HEAD
14754+
14755+#ifdef CONFIG_PAX_KERNEXEC
14756+ jmp startup_32
14757+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
14758+.fill PAGE_SIZE-5,1,0xcc
14759+#endif
14760+
14761 ENTRY(startup_32)
14762 movl pa(stack_start),%ecx
14763
14764@@ -105,6 +120,57 @@ ENTRY(startup_32)
14765 2:
14766 leal -__PAGE_OFFSET(%ecx),%esp
14767
14768+#ifdef CONFIG_SMP
14769+ movl $pa(cpu_gdt_table),%edi
14770+ movl $__per_cpu_load,%eax
14771+ movw %ax,__KERNEL_PERCPU + 2(%edi)
14772+ rorl $16,%eax
14773+ movb %al,__KERNEL_PERCPU + 4(%edi)
14774+ movb %ah,__KERNEL_PERCPU + 7(%edi)
14775+ movl $__per_cpu_end - 1,%eax
14776+ subl $__per_cpu_start,%eax
14777+ movw %ax,__KERNEL_PERCPU + 0(%edi)
14778+#endif
14779+
14780+#ifdef CONFIG_PAX_MEMORY_UDEREF
14781+ movl $NR_CPUS,%ecx
14782+ movl $pa(cpu_gdt_table),%edi
14783+1:
14784+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
14785+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
14786+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
14787+ addl $PAGE_SIZE_asm,%edi
14788+ loop 1b
14789+#endif
14790+
14791+#ifdef CONFIG_PAX_KERNEXEC
14792+ movl $pa(boot_gdt),%edi
14793+ movl $__LOAD_PHYSICAL_ADDR,%eax
14794+ movw %ax,__BOOT_CS + 2(%edi)
14795+ rorl $16,%eax
14796+ movb %al,__BOOT_CS + 4(%edi)
14797+ movb %ah,__BOOT_CS + 7(%edi)
14798+ rorl $16,%eax
14799+
14800+ ljmp $(__BOOT_CS),$1f
14801+1:
14802+
14803+ movl $NR_CPUS,%ecx
14804+ movl $pa(cpu_gdt_table),%edi
14805+ addl $__PAGE_OFFSET,%eax
14806+1:
14807+ movw %ax,__KERNEL_CS + 2(%edi)
14808+ movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
14809+ rorl $16,%eax
14810+ movb %al,__KERNEL_CS + 4(%edi)
14811+ movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
14812+ movb %ah,__KERNEL_CS + 7(%edi)
14813+ movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
14814+ rorl $16,%eax
14815+ addl $PAGE_SIZE_asm,%edi
14816+ loop 1b
14817+#endif
14818+
14819 /*
14820 * Clear BSS first so that there are no surprises...
14821 */
14822@@ -195,8 +261,11 @@ ENTRY(startup_32)
14823 movl %eax, pa(max_pfn_mapped)
14824
14825 /* Do early initialization of the fixmap area */
14826- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
14827- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
14828+#ifdef CONFIG_COMPAT_VDSO
14829+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
14830+#else
14831+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
14832+#endif
14833 #else /* Not PAE */
14834
14835 page_pde_offset = (__PAGE_OFFSET >> 20);
14836@@ -226,8 +295,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
14837 movl %eax, pa(max_pfn_mapped)
14838
14839 /* Do early initialization of the fixmap area */
14840- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
14841- movl %eax,pa(initial_page_table+0xffc)
14842+#ifdef CONFIG_COMPAT_VDSO
14843+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
14844+#else
14845+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
14846+#endif
14847 #endif
14848
14849 #ifdef CONFIG_PARAVIRT
14850@@ -241,9 +313,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
14851 cmpl $num_subarch_entries, %eax
14852 jae bad_subarch
14853
14854- movl pa(subarch_entries)(,%eax,4), %eax
14855- subl $__PAGE_OFFSET, %eax
14856- jmp *%eax
14857+ jmp *pa(subarch_entries)(,%eax,4)
14858
14859 bad_subarch:
14860 WEAK(lguest_entry)
14861@@ -255,10 +325,10 @@ WEAK(xen_entry)
14862 __INITDATA
14863
14864 subarch_entries:
14865- .long default_entry /* normal x86/PC */
14866- .long lguest_entry /* lguest hypervisor */
14867- .long xen_entry /* Xen hypervisor */
14868- .long default_entry /* Moorestown MID */
14869+ .long ta(default_entry) /* normal x86/PC */
14870+ .long ta(lguest_entry) /* lguest hypervisor */
14871+ .long ta(xen_entry) /* Xen hypervisor */
14872+ .long ta(default_entry) /* Moorestown MID */
14873 num_subarch_entries = (. - subarch_entries) / 4
14874 .previous
14875 #else
14876@@ -312,6 +382,7 @@ default_entry:
14877 orl %edx,%eax
14878 movl %eax,%cr4
14879
14880+#ifdef CONFIG_X86_PAE
14881 testb $X86_CR4_PAE, %al # check if PAE is enabled
14882 jz 6f
14883
14884@@ -340,6 +411,9 @@ default_entry:
14885 /* Make changes effective */
14886 wrmsr
14887
14888+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
14889+#endif
14890+
14891 6:
14892
14893 /*
14894@@ -443,7 +517,7 @@ is386: movl $2,%ecx # set MP
14895 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
14896 movl %eax,%ss # after changing gdt.
14897
14898- movl $(__USER_DS),%eax # DS/ES contains default USER segment
14899+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
14900 movl %eax,%ds
14901 movl %eax,%es
14902
14903@@ -457,15 +531,22 @@ is386: movl $2,%ecx # set MP
14904 */
14905 cmpb $0,ready
14906 jne 1f
14907- movl $gdt_page,%eax
14908+ movl $cpu_gdt_table,%eax
14909 movl $stack_canary,%ecx
14910+#ifdef CONFIG_SMP
14911+ addl $__per_cpu_load,%ecx
14912+#endif
14913 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
14914 shrl $16, %ecx
14915 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
14916 movb %ch, 8 * GDT_ENTRY_STACK_CANARY + 7(%eax)
14917 1:
14918-#endif
14919 movl $(__KERNEL_STACK_CANARY),%eax
14920+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
14921+ movl $(__USER_DS),%eax
14922+#else
14923+ xorl %eax,%eax
14924+#endif
14925 movl %eax,%gs
14926
14927 xorl %eax,%eax # Clear LDT
14928@@ -558,22 +639,22 @@ early_page_fault:
14929 jmp early_fault
14930
14931 early_fault:
14932- cld
14933 #ifdef CONFIG_PRINTK
14934+ cmpl $1,%ss:early_recursion_flag
14935+ je hlt_loop
14936+ incl %ss:early_recursion_flag
14937+ cld
14938 pusha
14939 movl $(__KERNEL_DS),%eax
14940 movl %eax,%ds
14941 movl %eax,%es
14942- cmpl $2,early_recursion_flag
14943- je hlt_loop
14944- incl early_recursion_flag
14945 movl %cr2,%eax
14946 pushl %eax
14947 pushl %edx /* trapno */
14948 pushl $fault_msg
14949 call printk
14950+; call dump_stack
14951 #endif
14952- call dump_stack
14953 hlt_loop:
14954 hlt
14955 jmp hlt_loop
14956@@ -581,8 +662,11 @@ hlt_loop:
14957 /* This is the default interrupt "handler" :-) */
14958 ALIGN
14959 ignore_int:
14960- cld
14961 #ifdef CONFIG_PRINTK
14962+ cmpl $2,%ss:early_recursion_flag
14963+ je hlt_loop
14964+ incl %ss:early_recursion_flag
14965+ cld
14966 pushl %eax
14967 pushl %ecx
14968 pushl %edx
14969@@ -591,9 +675,6 @@ ignore_int:
14970 movl $(__KERNEL_DS),%eax
14971 movl %eax,%ds
14972 movl %eax,%es
14973- cmpl $2,early_recursion_flag
14974- je hlt_loop
14975- incl early_recursion_flag
14976 pushl 16(%esp)
14977 pushl 24(%esp)
14978 pushl 32(%esp)
14979@@ -622,29 +703,43 @@ ENTRY(initial_code)
14980 /*
14981 * BSS section
14982 */
14983-__PAGE_ALIGNED_BSS
14984- .align PAGE_SIZE
14985 #ifdef CONFIG_X86_PAE
14986+.section .initial_pg_pmd,"a",@progbits
14987 initial_pg_pmd:
14988 .fill 1024*KPMDS,4,0
14989 #else
14990+.section .initial_page_table,"a",@progbits
14991 ENTRY(initial_page_table)
14992 .fill 1024,4,0
14993 #endif
14994+.section .initial_pg_fixmap,"a",@progbits
14995 initial_pg_fixmap:
14996 .fill 1024,4,0
14997+.section .empty_zero_page,"a",@progbits
14998 ENTRY(empty_zero_page)
14999 .fill 4096,1,0
15000+.section .swapper_pg_dir,"a",@progbits
15001 ENTRY(swapper_pg_dir)
15002+#ifdef CONFIG_X86_PAE
15003+ .fill 4,8,0
15004+#else
15005 .fill 1024,4,0
15006+#endif
15007+
15008+/*
15009+ * The IDT has to be page-aligned to simplify the Pentium
15010+ * F0 0F bug workaround.. We have a special link segment
15011+ * for this.
15012+ */
15013+.section .idt,"a",@progbits
15014+ENTRY(idt_table)
15015+ .fill 256,8,0
15016
15017 /*
15018 * This starts the data section.
15019 */
15020 #ifdef CONFIG_X86_PAE
15021-__PAGE_ALIGNED_DATA
15022- /* Page-aligned for the benefit of paravirt? */
15023- .align PAGE_SIZE
15024+.section .initial_page_table,"a",@progbits
15025 ENTRY(initial_page_table)
15026 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
15027 # if KPMDS == 3
15028@@ -663,18 +758,27 @@ ENTRY(initial_page_table)
15029 # error "Kernel PMDs should be 1, 2 or 3"
15030 # endif
15031 .align PAGE_SIZE /* needs to be page-sized too */
15032+
15033+#ifdef CONFIG_PAX_PER_CPU_PGD
15034+ENTRY(cpu_pgd)
15035+ .rept NR_CPUS
15036+ .fill 4,8,0
15037+ .endr
15038+#endif
15039+
15040 #endif
15041
15042 .data
15043 .balign 4
15044 ENTRY(stack_start)
15045- .long init_thread_union+THREAD_SIZE
15046+ .long init_thread_union+THREAD_SIZE-8
15047+
15048+ready: .byte 0
15049
15050+.section .rodata,"a",@progbits
15051 early_recursion_flag:
15052 .long 0
15053
15054-ready: .byte 0
15055-
15056 int_msg:
15057 .asciz "Unknown interrupt or fault at: %p %p %p\n"
15058
15059@@ -707,7 +811,7 @@ fault_msg:
15060 .word 0 # 32 bit align gdt_desc.address
15061 boot_gdt_descr:
15062 .word __BOOT_DS+7
15063- .long boot_gdt - __PAGE_OFFSET
15064+ .long pa(boot_gdt)
15065
15066 .word 0 # 32-bit align idt_desc.address
15067 idt_descr:
15068@@ -718,7 +822,7 @@ idt_descr:
15069 .word 0 # 32 bit align gdt_desc.address
15070 ENTRY(early_gdt_descr)
15071 .word GDT_ENTRIES*8-1
15072- .long gdt_page /* Overwritten for secondary CPUs */
15073+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
15074
15075 /*
15076 * The boot_gdt must mirror the equivalent in setup.S and is
15077@@ -727,5 +831,65 @@ ENTRY(early_gdt_descr)
15078 .align L1_CACHE_BYTES
15079 ENTRY(boot_gdt)
15080 .fill GDT_ENTRY_BOOT_CS,8,0
15081- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
15082- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
15083+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
15084+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
15085+
15086+ .align PAGE_SIZE_asm
15087+ENTRY(cpu_gdt_table)
15088+ .rept NR_CPUS
15089+ .quad 0x0000000000000000 /* NULL descriptor */
15090+ .quad 0x0000000000000000 /* 0x0b reserved */
15091+ .quad 0x0000000000000000 /* 0x13 reserved */
15092+ .quad 0x0000000000000000 /* 0x1b reserved */
15093+
15094+#ifdef CONFIG_PAX_KERNEXEC
15095+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
15096+#else
15097+ .quad 0x0000000000000000 /* 0x20 unused */
15098+#endif
15099+
15100+ .quad 0x0000000000000000 /* 0x28 unused */
15101+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
15102+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
15103+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
15104+ .quad 0x0000000000000000 /* 0x4b reserved */
15105+ .quad 0x0000000000000000 /* 0x53 reserved */
15106+ .quad 0x0000000000000000 /* 0x5b reserved */
15107+
15108+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
15109+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
15110+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
15111+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
15112+
15113+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
15114+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
15115+
15116+ /*
15117+ * Segments used for calling PnP BIOS have byte granularity.
15118+ * The code segments and data segments have fixed 64k limits,
15119+ * the transfer segment sizes are set at run time.
15120+ */
15121+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
15122+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
15123+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
15124+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
15125+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
15126+
15127+ /*
15128+ * The APM segments have byte granularity and their bases
15129+ * are set at run time. All have 64k limits.
15130+ */
15131+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
15132+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
15133+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
15134+
15135+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
15136+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
15137+ .quad 0x0040910000000018 /* 0xe0 - STACK_CANARY */
15138+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
15139+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
15140+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
15141+
15142+ /* Be sure this is zeroed to avoid false validations in Xen */
15143+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
15144+ .endr
15145diff -urNp linux-2.6.39.1/arch/x86/kernel/head_64.S linux-2.6.39.1/arch/x86/kernel/head_64.S
15146--- linux-2.6.39.1/arch/x86/kernel/head_64.S 2011-05-19 00:06:34.000000000 -0400
15147+++ linux-2.6.39.1/arch/x86/kernel/head_64.S 2011-05-22 19:36:30.000000000 -0400
15148@@ -19,6 +19,7 @@
15149 #include <asm/cache.h>
15150 #include <asm/processor-flags.h>
15151 #include <asm/percpu.h>
15152+#include <asm/cpufeature.h>
15153
15154 #ifdef CONFIG_PARAVIRT
15155 #include <asm/asm-offsets.h>
15156@@ -38,6 +39,10 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET
15157 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
15158 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
15159 L3_START_KERNEL = pud_index(__START_KERNEL_map)
15160+L4_VMALLOC_START = pgd_index(VMALLOC_START)
15161+L3_VMALLOC_START = pud_index(VMALLOC_START)
15162+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
15163+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
15164
15165 .text
15166 __HEAD
15167@@ -85,35 +90,22 @@ startup_64:
15168 */
15169 addq %rbp, init_level4_pgt + 0(%rip)
15170 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
15171+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
15172+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
15173 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
15174
15175 addq %rbp, level3_ident_pgt + 0(%rip)
15176+#ifndef CONFIG_XEN
15177+ addq %rbp, level3_ident_pgt + 8(%rip)
15178+#endif
15179
15180- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
15181- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
15182+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
15183
15184- addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
15185+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
15186+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
15187
15188- /* Add an Identity mapping if I am above 1G */
15189- leaq _text(%rip), %rdi
15190- andq $PMD_PAGE_MASK, %rdi
15191-
15192- movq %rdi, %rax
15193- shrq $PUD_SHIFT, %rax
15194- andq $(PTRS_PER_PUD - 1), %rax
15195- jz ident_complete
15196-
15197- leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
15198- leaq level3_ident_pgt(%rip), %rbx
15199- movq %rdx, 0(%rbx, %rax, 8)
15200-
15201- movq %rdi, %rax
15202- shrq $PMD_SHIFT, %rax
15203- andq $(PTRS_PER_PMD - 1), %rax
15204- leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
15205- leaq level2_spare_pgt(%rip), %rbx
15206- movq %rdx, 0(%rbx, %rax, 8)
15207-ident_complete:
15208+ addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
15209+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
15210
15211 /*
15212 * Fixup the kernel text+data virtual addresses. Note that
15213@@ -160,8 +152,8 @@ ENTRY(secondary_startup_64)
15214 * after the boot processor executes this code.
15215 */
15216
15217- /* Enable PAE mode and PGE */
15218- movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
15219+ /* Enable PAE mode and PSE/PGE */
15220+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
15221 movq %rax, %cr4
15222
15223 /* Setup early boot stage 4 level pagetables. */
15224@@ -183,9 +175,14 @@ ENTRY(secondary_startup_64)
15225 movl $MSR_EFER, %ecx
15226 rdmsr
15227 btsl $_EFER_SCE, %eax /* Enable System Call */
15228- btl $20,%edi /* No Execute supported? */
15229+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
15230 jnc 1f
15231 btsl $_EFER_NX, %eax
15232+ leaq init_level4_pgt(%rip), %rdi
15233+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
15234+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
15235+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
15236+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
15237 1: wrmsr /* Make changes effective */
15238
15239 /* Setup cr0 */
15240@@ -269,7 +266,7 @@ ENTRY(secondary_startup_64)
15241 bad_address:
15242 jmp bad_address
15243
15244- .section ".init.text","ax"
15245+ __INIT
15246 #ifdef CONFIG_EARLY_PRINTK
15247 .globl early_idt_handlers
15248 early_idt_handlers:
15249@@ -314,18 +311,23 @@ ENTRY(early_idt_handler)
15250 #endif /* EARLY_PRINTK */
15251 1: hlt
15252 jmp 1b
15253+ .previous
15254
15255 #ifdef CONFIG_EARLY_PRINTK
15256+ __INITDATA
15257 early_recursion_flag:
15258 .long 0
15259+ .previous
15260
15261+ .section .rodata,"a",@progbits
15262 early_idt_msg:
15263 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
15264 early_idt_ripmsg:
15265 .asciz "RIP %s\n"
15266-#endif /* CONFIG_EARLY_PRINTK */
15267 .previous
15268+#endif /* CONFIG_EARLY_PRINTK */
15269
15270+ .section .rodata,"a",@progbits
15271 #define NEXT_PAGE(name) \
15272 .balign PAGE_SIZE; \
15273 ENTRY(name)
15274@@ -338,7 +340,6 @@ ENTRY(name)
15275 i = i + 1 ; \
15276 .endr
15277
15278- .data
15279 /*
15280 * This default setting generates an ident mapping at address 0x100000
15281 * and a mapping for the kernel that precisely maps virtual address
15282@@ -349,13 +350,36 @@ NEXT_PAGE(init_level4_pgt)
15283 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
15284 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
15285 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
15286+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
15287+ .quad level3_vmalloc_pgt - __START_KERNEL_map + _KERNPG_TABLE
15288+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
15289+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
15290 .org init_level4_pgt + L4_START_KERNEL*8, 0
15291 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
15292 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
15293
15294+#ifdef CONFIG_PAX_PER_CPU_PGD
15295+NEXT_PAGE(cpu_pgd)
15296+ .rept NR_CPUS
15297+ .fill 512,8,0
15298+ .endr
15299+#endif
15300+
15301 NEXT_PAGE(level3_ident_pgt)
15302 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
15303+#ifdef CONFIG_XEN
15304 .fill 511,8,0
15305+#else
15306+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
15307+ .fill 510,8,0
15308+#endif
15309+
15310+NEXT_PAGE(level3_vmalloc_pgt)
15311+ .fill 512,8,0
15312+
15313+NEXT_PAGE(level3_vmemmap_pgt)
15314+ .fill L3_VMEMMAP_START,8,0
15315+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
15316
15317 NEXT_PAGE(level3_kernel_pgt)
15318 .fill L3_START_KERNEL,8,0
15319@@ -363,20 +387,23 @@ NEXT_PAGE(level3_kernel_pgt)
15320 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
15321 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
15322
15323+NEXT_PAGE(level2_vmemmap_pgt)
15324+ .fill 512,8,0
15325+
15326 NEXT_PAGE(level2_fixmap_pgt)
15327- .fill 506,8,0
15328- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
15329- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
15330- .fill 5,8,0
15331+ .fill 507,8,0
15332+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
15333+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
15334+ .fill 4,8,0
15335
15336-NEXT_PAGE(level1_fixmap_pgt)
15337+NEXT_PAGE(level1_vsyscall_pgt)
15338 .fill 512,8,0
15339
15340-NEXT_PAGE(level2_ident_pgt)
15341- /* Since I easily can, map the first 1G.
15342+ /* Since I easily can, map the first 2G.
15343 * Don't set NX because code runs from these pages.
15344 */
15345- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
15346+NEXT_PAGE(level2_ident_pgt)
15347+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
15348
15349 NEXT_PAGE(level2_kernel_pgt)
15350 /*
15351@@ -389,33 +416,55 @@ NEXT_PAGE(level2_kernel_pgt)
15352 * If you want to increase this then increase MODULES_VADDR
15353 * too.)
15354 */
15355- PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
15356- KERNEL_IMAGE_SIZE/PMD_SIZE)
15357-
15358-NEXT_PAGE(level2_spare_pgt)
15359- .fill 512, 8, 0
15360+ PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
15361
15362 #undef PMDS
15363 #undef NEXT_PAGE
15364
15365- .data
15366+ .align PAGE_SIZE
15367+ENTRY(cpu_gdt_table)
15368+ .rept NR_CPUS
15369+ .quad 0x0000000000000000 /* NULL descriptor */
15370+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
15371+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
15372+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
15373+ .quad 0x00cffb000000ffff /* __USER32_CS */
15374+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
15375+ .quad 0x00affb000000ffff /* __USER_CS */
15376+
15377+#ifdef CONFIG_PAX_KERNEXEC
15378+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
15379+#else
15380+ .quad 0x0 /* unused */
15381+#endif
15382+
15383+ .quad 0,0 /* TSS */
15384+ .quad 0,0 /* LDT */
15385+ .quad 0,0,0 /* three TLS descriptors */
15386+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
15387+ /* asm/segment.h:GDT_ENTRIES must match this */
15388+
15389+ /* zero the remaining page */
15390+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
15391+ .endr
15392+
15393 .align 16
15394 .globl early_gdt_descr
15395 early_gdt_descr:
15396 .word GDT_ENTRIES*8-1
15397 early_gdt_descr_base:
15398- .quad INIT_PER_CPU_VAR(gdt_page)
15399+ .quad cpu_gdt_table
15400
15401 ENTRY(phys_base)
15402 /* This must match the first entry in level2_kernel_pgt */
15403 .quad 0x0000000000000000
15404
15405 #include "../../x86/xen/xen-head.S"
15406-
15407- .section .bss, "aw", @nobits
15408+
15409+ .section .rodata,"a",@progbits
15410 .align L1_CACHE_BYTES
15411 ENTRY(idt_table)
15412- .skip IDT_ENTRIES * 16
15413+ .fill 512,8,0
15414
15415 __PAGE_ALIGNED_BSS
15416 .align PAGE_SIZE
15417diff -urNp linux-2.6.39.1/arch/x86/kernel/i386_ksyms_32.c linux-2.6.39.1/arch/x86/kernel/i386_ksyms_32.c
15418--- linux-2.6.39.1/arch/x86/kernel/i386_ksyms_32.c 2011-05-19 00:06:34.000000000 -0400
15419+++ linux-2.6.39.1/arch/x86/kernel/i386_ksyms_32.c 2011-05-22 19:36:30.000000000 -0400
15420@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
15421 EXPORT_SYMBOL(cmpxchg8b_emu);
15422 #endif
15423
15424+EXPORT_SYMBOL_GPL(cpu_gdt_table);
15425+
15426 /* Networking helper routines. */
15427 EXPORT_SYMBOL(csum_partial_copy_generic);
15428+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
15429+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
15430
15431 EXPORT_SYMBOL(__get_user_1);
15432 EXPORT_SYMBOL(__get_user_2);
15433@@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
15434
15435 EXPORT_SYMBOL(csum_partial);
15436 EXPORT_SYMBOL(empty_zero_page);
15437+
15438+#ifdef CONFIG_PAX_KERNEXEC
15439+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
15440+#endif
15441diff -urNp linux-2.6.39.1/arch/x86/kernel/i8259.c linux-2.6.39.1/arch/x86/kernel/i8259.c
15442--- linux-2.6.39.1/arch/x86/kernel/i8259.c 2011-05-19 00:06:34.000000000 -0400
15443+++ linux-2.6.39.1/arch/x86/kernel/i8259.c 2011-05-22 19:36:30.000000000 -0400
15444@@ -210,7 +210,7 @@ spurious_8259A_irq:
15445 "spurious 8259A interrupt: IRQ%d.\n", irq);
15446 spurious_irq_mask |= irqmask;
15447 }
15448- atomic_inc(&irq_err_count);
15449+ atomic_inc_unchecked(&irq_err_count);
15450 /*
15451 * Theoretically we do not have to handle this IRQ,
15452 * but in Linux this does not cause problems and is
15453diff -urNp linux-2.6.39.1/arch/x86/kernel/init_task.c linux-2.6.39.1/arch/x86/kernel/init_task.c
15454--- linux-2.6.39.1/arch/x86/kernel/init_task.c 2011-05-19 00:06:34.000000000 -0400
15455+++ linux-2.6.39.1/arch/x86/kernel/init_task.c 2011-05-22 19:36:30.000000000 -0400
15456@@ -20,8 +20,7 @@ static struct sighand_struct init_sighan
15457 * way process stacks are handled. This is done by having a special
15458 * "init_task" linker map entry..
15459 */
15460-union thread_union init_thread_union __init_task_data =
15461- { INIT_THREAD_INFO(init_task) };
15462+union thread_union init_thread_union __init_task_data;
15463
15464 /*
15465 * Initial task structure.
15466@@ -38,5 +37,5 @@ EXPORT_SYMBOL(init_task);
15467 * section. Since TSS's are completely CPU-local, we want them
15468 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
15469 */
15470-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
15471-
15472+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
15473+EXPORT_SYMBOL(init_tss);
15474diff -urNp linux-2.6.39.1/arch/x86/kernel/ioport.c linux-2.6.39.1/arch/x86/kernel/ioport.c
15475--- linux-2.6.39.1/arch/x86/kernel/ioport.c 2011-05-19 00:06:34.000000000 -0400
15476+++ linux-2.6.39.1/arch/x86/kernel/ioport.c 2011-05-22 19:41:32.000000000 -0400
15477@@ -6,6 +6,7 @@
15478 #include <linux/sched.h>
15479 #include <linux/kernel.h>
15480 #include <linux/capability.h>
15481+#include <linux/security.h>
15482 #include <linux/errno.h>
15483 #include <linux/types.h>
15484 #include <linux/ioport.h>
15485@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long
15486
15487 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
15488 return -EINVAL;
15489+#ifdef CONFIG_GRKERNSEC_IO
15490+ if (turn_on && grsec_disable_privio) {
15491+ gr_handle_ioperm();
15492+ return -EPERM;
15493+ }
15494+#endif
15495 if (turn_on && !capable(CAP_SYS_RAWIO))
15496 return -EPERM;
15497
15498@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long
15499 * because the ->io_bitmap_max value must match the bitmap
15500 * contents:
15501 */
15502- tss = &per_cpu(init_tss, get_cpu());
15503+ tss = init_tss + get_cpu();
15504
15505 if (turn_on)
15506 bitmap_clear(t->io_bitmap_ptr, from, num);
15507@@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct
15508 return -EINVAL;
15509 /* Trying to gain more privileges? */
15510 if (level > old) {
15511+#ifdef CONFIG_GRKERNSEC_IO
15512+ if (grsec_disable_privio) {
15513+ gr_handle_iopl();
15514+ return -EPERM;
15515+ }
15516+#endif
15517 if (!capable(CAP_SYS_RAWIO))
15518 return -EPERM;
15519 }
15520diff -urNp linux-2.6.39.1/arch/x86/kernel/irq_32.c linux-2.6.39.1/arch/x86/kernel/irq_32.c
15521--- linux-2.6.39.1/arch/x86/kernel/irq_32.c 2011-05-19 00:06:34.000000000 -0400
15522+++ linux-2.6.39.1/arch/x86/kernel/irq_32.c 2011-05-22 19:36:30.000000000 -0400
15523@@ -36,7 +36,7 @@ static int check_stack_overflow(void)
15524 __asm__ __volatile__("andl %%esp,%0" :
15525 "=r" (sp) : "0" (THREAD_SIZE - 1));
15526
15527- return sp < (sizeof(struct thread_info) + STACK_WARN);
15528+ return sp < STACK_WARN;
15529 }
15530
15531 static void print_stack_overflow(void)
15532@@ -54,8 +54,8 @@ static inline void print_stack_overflow(
15533 * per-CPU IRQ handling contexts (thread information and stack)
15534 */
15535 union irq_ctx {
15536- struct thread_info tinfo;
15537- u32 stack[THREAD_SIZE/sizeof(u32)];
15538+ unsigned long previous_esp;
15539+ u32 stack[THREAD_SIZE/sizeof(u32)];
15540 } __attribute__((aligned(THREAD_SIZE)));
15541
15542 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
15543@@ -75,10 +75,9 @@ static void call_on_stack(void *func, vo
15544 static inline int
15545 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
15546 {
15547- union irq_ctx *curctx, *irqctx;
15548+ union irq_ctx *irqctx;
15549 u32 *isp, arg1, arg2;
15550
15551- curctx = (union irq_ctx *) current_thread_info();
15552 irqctx = __this_cpu_read(hardirq_ctx);
15553
15554 /*
15555@@ -87,21 +86,17 @@ execute_on_irq_stack(int overflow, struc
15556 * handler) we can't do that and just have to keep using the
15557 * current stack (which is the irq stack already after all)
15558 */
15559- if (unlikely(curctx == irqctx))
15560+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
15561 return 0;
15562
15563 /* build the stack frame on the IRQ stack */
15564- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
15565- irqctx->tinfo.task = curctx->tinfo.task;
15566- irqctx->tinfo.previous_esp = current_stack_pointer;
15567+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
15568+ irqctx->previous_esp = current_stack_pointer;
15569+ add_preempt_count(HARDIRQ_OFFSET);
15570
15571- /*
15572- * Copy the softirq bits in preempt_count so that the
15573- * softirq checks work in the hardirq context.
15574- */
15575- irqctx->tinfo.preempt_count =
15576- (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
15577- (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
15578+#ifdef CONFIG_PAX_MEMORY_UDEREF
15579+ __set_fs(MAKE_MM_SEG(0));
15580+#endif
15581
15582 if (unlikely(overflow))
15583 call_on_stack(print_stack_overflow, isp);
15584@@ -113,6 +108,12 @@ execute_on_irq_stack(int overflow, struc
15585 : "0" (irq), "1" (desc), "2" (isp),
15586 "D" (desc->handle_irq)
15587 : "memory", "cc", "ecx");
15588+
15589+#ifdef CONFIG_PAX_MEMORY_UDEREF
15590+ __set_fs(current_thread_info()->addr_limit);
15591+#endif
15592+
15593+ sub_preempt_count(HARDIRQ_OFFSET);
15594 return 1;
15595 }
15596
15597@@ -121,29 +122,11 @@ execute_on_irq_stack(int overflow, struc
15598 */
15599 void __cpuinit irq_ctx_init(int cpu)
15600 {
15601- union irq_ctx *irqctx;
15602-
15603 if (per_cpu(hardirq_ctx, cpu))
15604 return;
15605
15606- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
15607- THREAD_FLAGS,
15608- THREAD_ORDER));
15609- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
15610- irqctx->tinfo.cpu = cpu;
15611- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
15612- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
15613-
15614- per_cpu(hardirq_ctx, cpu) = irqctx;
15615-
15616- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
15617- THREAD_FLAGS,
15618- THREAD_ORDER));
15619- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
15620- irqctx->tinfo.cpu = cpu;
15621- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
15622-
15623- per_cpu(softirq_ctx, cpu) = irqctx;
15624+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
15625+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
15626
15627 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
15628 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
15629@@ -152,7 +135,6 @@ void __cpuinit irq_ctx_init(int cpu)
15630 asmlinkage void do_softirq(void)
15631 {
15632 unsigned long flags;
15633- struct thread_info *curctx;
15634 union irq_ctx *irqctx;
15635 u32 *isp;
15636
15637@@ -162,15 +144,22 @@ asmlinkage void do_softirq(void)
15638 local_irq_save(flags);
15639
15640 if (local_softirq_pending()) {
15641- curctx = current_thread_info();
15642 irqctx = __this_cpu_read(softirq_ctx);
15643- irqctx->tinfo.task = curctx->task;
15644- irqctx->tinfo.previous_esp = current_stack_pointer;
15645+ irqctx->previous_esp = current_stack_pointer;
15646
15647 /* build the stack frame on the softirq stack */
15648- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
15649+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
15650+
15651+#ifdef CONFIG_PAX_MEMORY_UDEREF
15652+ __set_fs(MAKE_MM_SEG(0));
15653+#endif
15654
15655 call_on_stack(__do_softirq, isp);
15656+
15657+#ifdef CONFIG_PAX_MEMORY_UDEREF
15658+ __set_fs(current_thread_info()->addr_limit);
15659+#endif
15660+
15661 /*
15662 * Shouldn't happen, we returned above if in_interrupt():
15663 */
15664diff -urNp linux-2.6.39.1/arch/x86/kernel/irq.c linux-2.6.39.1/arch/x86/kernel/irq.c
15665--- linux-2.6.39.1/arch/x86/kernel/irq.c 2011-05-19 00:06:34.000000000 -0400
15666+++ linux-2.6.39.1/arch/x86/kernel/irq.c 2011-05-22 19:36:30.000000000 -0400
15667@@ -17,7 +17,7 @@
15668 #include <asm/mce.h>
15669 #include <asm/hw_irq.h>
15670
15671-atomic_t irq_err_count;
15672+atomic_unchecked_t irq_err_count;
15673
15674 /* Function pointer for generic interrupt vector handling */
15675 void (*x86_platform_ipi_callback)(void) = NULL;
15676@@ -116,9 +116,9 @@ int arch_show_interrupts(struct seq_file
15677 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
15678 seq_printf(p, " Machine check polls\n");
15679 #endif
15680- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
15681+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
15682 #if defined(CONFIG_X86_IO_APIC)
15683- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
15684+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
15685 #endif
15686 return 0;
15687 }
15688@@ -158,10 +158,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
15689
15690 u64 arch_irq_stat(void)
15691 {
15692- u64 sum = atomic_read(&irq_err_count);
15693+ u64 sum = atomic_read_unchecked(&irq_err_count);
15694
15695 #ifdef CONFIG_X86_IO_APIC
15696- sum += atomic_read(&irq_mis_count);
15697+ sum += atomic_read_unchecked(&irq_mis_count);
15698 #endif
15699 return sum;
15700 }
15701diff -urNp linux-2.6.39.1/arch/x86/kernel/kgdb.c linux-2.6.39.1/arch/x86/kernel/kgdb.c
15702--- linux-2.6.39.1/arch/x86/kernel/kgdb.c 2011-05-19 00:06:34.000000000 -0400
15703+++ linux-2.6.39.1/arch/x86/kernel/kgdb.c 2011-05-22 19:36:30.000000000 -0400
15704@@ -124,11 +124,11 @@ char *dbg_get_reg(int regno, void *mem,
15705 #ifdef CONFIG_X86_32
15706 switch (regno) {
15707 case GDB_SS:
15708- if (!user_mode_vm(regs))
15709+ if (!user_mode(regs))
15710 *(unsigned long *)mem = __KERNEL_DS;
15711 break;
15712 case GDB_SP:
15713- if (!user_mode_vm(regs))
15714+ if (!user_mode(regs))
15715 *(unsigned long *)mem = kernel_stack_pointer(regs);
15716 break;
15717 case GDB_GS:
15718@@ -473,12 +473,12 @@ int kgdb_arch_handle_exception(int e_vec
15719 case 'k':
15720 /* clear the trace bit */
15721 linux_regs->flags &= ~X86_EFLAGS_TF;
15722- atomic_set(&kgdb_cpu_doing_single_step, -1);
15723+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
15724
15725 /* set the trace bit if we're stepping */
15726 if (remcomInBuffer[0] == 's') {
15727 linux_regs->flags |= X86_EFLAGS_TF;
15728- atomic_set(&kgdb_cpu_doing_single_step,
15729+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
15730 raw_smp_processor_id());
15731 }
15732
15733@@ -534,7 +534,7 @@ static int __kgdb_notify(struct die_args
15734 return NOTIFY_DONE;
15735
15736 case DIE_DEBUG:
15737- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
15738+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
15739 if (user_mode(regs))
15740 return single_step_cont(regs, args);
15741 break;
15742@@ -710,7 +710,7 @@ void kgdb_arch_set_pc(struct pt_regs *re
15743 regs->ip = ip;
15744 }
15745
15746-struct kgdb_arch arch_kgdb_ops = {
15747+const struct kgdb_arch arch_kgdb_ops = {
15748 /* Breakpoint instruction: */
15749 .gdb_bpt_instr = { 0xcc },
15750 .flags = KGDB_HW_BREAKPOINT,
15751diff -urNp linux-2.6.39.1/arch/x86/kernel/kprobes.c linux-2.6.39.1/arch/x86/kernel/kprobes.c
15752--- linux-2.6.39.1/arch/x86/kernel/kprobes.c 2011-05-19 00:06:34.000000000 -0400
15753+++ linux-2.6.39.1/arch/x86/kernel/kprobes.c 2011-05-22 19:36:30.000000000 -0400
15754@@ -115,8 +115,11 @@ static void __kprobes __synthesize_relat
15755 } __attribute__((packed)) *insn;
15756
15757 insn = (struct __arch_relative_insn *)from;
15758+
15759+ pax_open_kernel();
15760 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
15761 insn->op = op;
15762+ pax_close_kernel();
15763 }
15764
15765 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
15766@@ -153,7 +156,7 @@ static int __kprobes can_boost(kprobe_op
15767 kprobe_opcode_t opcode;
15768 kprobe_opcode_t *orig_opcodes = opcodes;
15769
15770- if (search_exception_tables((unsigned long)opcodes))
15771+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
15772 return 0; /* Page fault may occur on this address. */
15773
15774 retry:
15775@@ -314,7 +317,9 @@ static int __kprobes __copy_instruction(
15776 }
15777 }
15778 insn_get_length(&insn);
15779+ pax_open_kernel();
15780 memcpy(dest, insn.kaddr, insn.length);
15781+ pax_close_kernel();
15782
15783 #ifdef CONFIG_X86_64
15784 if (insn_rip_relative(&insn)) {
15785@@ -338,7 +343,9 @@ static int __kprobes __copy_instruction(
15786 (u8 *) dest;
15787 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
15788 disp = (u8 *) dest + insn_offset_displacement(&insn);
15789+ pax_open_kernel();
15790 *(s32 *) disp = (s32) newdisp;
15791+ pax_close_kernel();
15792 }
15793 #endif
15794 return insn.length;
15795@@ -352,12 +359,12 @@ static void __kprobes arch_copy_kprobe(s
15796 */
15797 __copy_instruction(p->ainsn.insn, p->addr, 0);
15798
15799- if (can_boost(p->addr))
15800+ if (can_boost(ktla_ktva(p->addr)))
15801 p->ainsn.boostable = 0;
15802 else
15803 p->ainsn.boostable = -1;
15804
15805- p->opcode = *p->addr;
15806+ p->opcode = *(ktla_ktva(p->addr));
15807 }
15808
15809 int __kprobes arch_prepare_kprobe(struct kprobe *p)
15810@@ -474,7 +481,7 @@ static void __kprobes setup_singlestep(s
15811 * nor set current_kprobe, because it doesn't use single
15812 * stepping.
15813 */
15814- regs->ip = (unsigned long)p->ainsn.insn;
15815+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
15816 preempt_enable_no_resched();
15817 return;
15818 }
15819@@ -493,7 +500,7 @@ static void __kprobes setup_singlestep(s
15820 if (p->opcode == BREAKPOINT_INSTRUCTION)
15821 regs->ip = (unsigned long)p->addr;
15822 else
15823- regs->ip = (unsigned long)p->ainsn.insn;
15824+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
15825 }
15826
15827 /*
15828@@ -572,7 +579,7 @@ static int __kprobes kprobe_handler(stru
15829 setup_singlestep(p, regs, kcb, 0);
15830 return 1;
15831 }
15832- } else if (*addr != BREAKPOINT_INSTRUCTION) {
15833+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
15834 /*
15835 * The breakpoint instruction was removed right
15836 * after we hit it. Another cpu has removed
15837@@ -817,7 +824,7 @@ static void __kprobes resume_execution(s
15838 struct pt_regs *regs, struct kprobe_ctlblk *kcb)
15839 {
15840 unsigned long *tos = stack_addr(regs);
15841- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
15842+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
15843 unsigned long orig_ip = (unsigned long)p->addr;
15844 kprobe_opcode_t *insn = p->ainsn.insn;
15845
15846@@ -999,7 +1006,7 @@ int __kprobes kprobe_exceptions_notify(s
15847 struct die_args *args = data;
15848 int ret = NOTIFY_DONE;
15849
15850- if (args->regs && user_mode_vm(args->regs))
15851+ if (args->regs && user_mode(args->regs))
15852 return ret;
15853
15854 switch (val) {
15855@@ -1381,7 +1388,7 @@ int __kprobes arch_prepare_optimized_kpr
15856 * Verify if the address gap is in 2GB range, because this uses
15857 * a relative jump.
15858 */
15859- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
15860+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
15861 if (abs(rel) > 0x7fffffff)
15862 return -ERANGE;
15863
15864@@ -1402,11 +1409,11 @@ int __kprobes arch_prepare_optimized_kpr
15865 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
15866
15867 /* Set probe function call */
15868- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
15869+ synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
15870
15871 /* Set returning jmp instruction at the tail of out-of-line buffer */
15872 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
15873- (u8 *)op->kp.addr + op->optinsn.size);
15874+ (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
15875
15876 flush_icache_range((unsigned long) buf,
15877 (unsigned long) buf + TMPL_END_IDX +
15878@@ -1428,7 +1435,7 @@ static void __kprobes setup_optimize_kpr
15879 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
15880
15881 /* Backup instructions which will be replaced by jump address */
15882- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
15883+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
15884 RELATIVE_ADDR_SIZE);
15885
15886 insn_buf[0] = RELATIVEJUMP_OPCODE;
15887diff -urNp linux-2.6.39.1/arch/x86/kernel/ldt.c linux-2.6.39.1/arch/x86/kernel/ldt.c
15888--- linux-2.6.39.1/arch/x86/kernel/ldt.c 2011-05-19 00:06:34.000000000 -0400
15889+++ linux-2.6.39.1/arch/x86/kernel/ldt.c 2011-05-22 19:36:30.000000000 -0400
15890@@ -67,13 +67,13 @@ static int alloc_ldt(mm_context_t *pc, i
15891 if (reload) {
15892 #ifdef CONFIG_SMP
15893 preempt_disable();
15894- load_LDT(pc);
15895+ load_LDT_nolock(pc);
15896 if (!cpumask_equal(mm_cpumask(current->mm),
15897 cpumask_of(smp_processor_id())))
15898 smp_call_function(flush_ldt, current->mm, 1);
15899 preempt_enable();
15900 #else
15901- load_LDT(pc);
15902+ load_LDT_nolock(pc);
15903 #endif
15904 }
15905 if (oldsize) {
15906@@ -95,7 +95,7 @@ static inline int copy_ldt(mm_context_t
15907 return err;
15908
15909 for (i = 0; i < old->size; i++)
15910- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
15911+ write_ldt_entry(new->ldt, i, old->ldt + i);
15912 return 0;
15913 }
15914
15915@@ -116,6 +116,24 @@ int init_new_context(struct task_struct
15916 retval = copy_ldt(&mm->context, &old_mm->context);
15917 mutex_unlock(&old_mm->context.lock);
15918 }
15919+
15920+ if (tsk == current) {
15921+ mm->context.vdso = 0;
15922+
15923+#ifdef CONFIG_X86_32
15924+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
15925+ mm->context.user_cs_base = 0UL;
15926+ mm->context.user_cs_limit = ~0UL;
15927+
15928+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
15929+ cpus_clear(mm->context.cpu_user_cs_mask);
15930+#endif
15931+
15932+#endif
15933+#endif
15934+
15935+ }
15936+
15937 return retval;
15938 }
15939
15940@@ -230,6 +248,13 @@ static int write_ldt(void __user *ptr, u
15941 }
15942 }
15943
15944+#ifdef CONFIG_PAX_SEGMEXEC
15945+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
15946+ error = -EINVAL;
15947+ goto out_unlock;
15948+ }
15949+#endif
15950+
15951 fill_ldt(&ldt, &ldt_info);
15952 if (oldmode)
15953 ldt.avl = 0;
15954diff -urNp linux-2.6.39.1/arch/x86/kernel/machine_kexec_32.c linux-2.6.39.1/arch/x86/kernel/machine_kexec_32.c
15955--- linux-2.6.39.1/arch/x86/kernel/machine_kexec_32.c 2011-05-19 00:06:34.000000000 -0400
15956+++ linux-2.6.39.1/arch/x86/kernel/machine_kexec_32.c 2011-05-22 19:36:30.000000000 -0400
15957@@ -27,7 +27,7 @@
15958 #include <asm/cacheflush.h>
15959 #include <asm/debugreg.h>
15960
15961-static void set_idt(void *newidt, __u16 limit)
15962+static void set_idt(struct desc_struct *newidt, __u16 limit)
15963 {
15964 struct desc_ptr curidt;
15965
15966@@ -39,7 +39,7 @@ static void set_idt(void *newidt, __u16
15967 }
15968
15969
15970-static void set_gdt(void *newgdt, __u16 limit)
15971+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
15972 {
15973 struct desc_ptr curgdt;
15974
15975@@ -217,7 +217,7 @@ void machine_kexec(struct kimage *image)
15976 }
15977
15978 control_page = page_address(image->control_code_page);
15979- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
15980+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
15981
15982 relocate_kernel_ptr = control_page;
15983 page_list[PA_CONTROL_PAGE] = __pa(control_page);
15984diff -urNp linux-2.6.39.1/arch/x86/kernel/microcode_amd.c linux-2.6.39.1/arch/x86/kernel/microcode_amd.c
15985--- linux-2.6.39.1/arch/x86/kernel/microcode_amd.c 2011-05-19 00:06:34.000000000 -0400
15986+++ linux-2.6.39.1/arch/x86/kernel/microcode_amd.c 2011-05-22 19:36:30.000000000 -0400
15987@@ -339,7 +339,7 @@ static void microcode_fini_cpu_amd(int c
15988 uci->mc = NULL;
15989 }
15990
15991-static struct microcode_ops microcode_amd_ops = {
15992+static const struct microcode_ops microcode_amd_ops = {
15993 .request_microcode_user = request_microcode_user,
15994 .request_microcode_fw = request_microcode_amd,
15995 .collect_cpu_info = collect_cpu_info_amd,
15996@@ -347,7 +347,7 @@ static struct microcode_ops microcode_am
15997 .microcode_fini_cpu = microcode_fini_cpu_amd,
15998 };
15999
16000-struct microcode_ops * __init init_amd_microcode(void)
16001+const struct microcode_ops * __init init_amd_microcode(void)
16002 {
16003 return &microcode_amd_ops;
16004 }
16005diff -urNp linux-2.6.39.1/arch/x86/kernel/microcode_core.c linux-2.6.39.1/arch/x86/kernel/microcode_core.c
16006--- linux-2.6.39.1/arch/x86/kernel/microcode_core.c 2011-05-19 00:06:34.000000000 -0400
16007+++ linux-2.6.39.1/arch/x86/kernel/microcode_core.c 2011-05-22 19:36:30.000000000 -0400
16008@@ -93,7 +93,7 @@ MODULE_LICENSE("GPL");
16009
16010 #define MICROCODE_VERSION "2.00"
16011
16012-static struct microcode_ops *microcode_ops;
16013+static const struct microcode_ops *microcode_ops;
16014
16015 /*
16016 * Synchronization.
16017diff -urNp linux-2.6.39.1/arch/x86/kernel/microcode_intel.c linux-2.6.39.1/arch/x86/kernel/microcode_intel.c
16018--- linux-2.6.39.1/arch/x86/kernel/microcode_intel.c 2011-05-19 00:06:34.000000000 -0400
16019+++ linux-2.6.39.1/arch/x86/kernel/microcode_intel.c 2011-05-22 19:36:30.000000000 -0400
16020@@ -440,13 +440,13 @@ static enum ucode_state request_microcod
16021
16022 static int get_ucode_user(void *to, const void *from, size_t n)
16023 {
16024- return copy_from_user(to, from, n);
16025+ return copy_from_user(to, (__force const void __user *)from, n);
16026 }
16027
16028 static enum ucode_state
16029 request_microcode_user(int cpu, const void __user *buf, size_t size)
16030 {
16031- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
16032+ return generic_load_microcode(cpu, (__force void *)buf, size, &get_ucode_user);
16033 }
16034
16035 static void microcode_fini_cpu(int cpu)
16036@@ -457,7 +457,7 @@ static void microcode_fini_cpu(int cpu)
16037 uci->mc = NULL;
16038 }
16039
16040-static struct microcode_ops microcode_intel_ops = {
16041+static const struct microcode_ops microcode_intel_ops = {
16042 .request_microcode_user = request_microcode_user,
16043 .request_microcode_fw = request_microcode_fw,
16044 .collect_cpu_info = collect_cpu_info,
16045@@ -465,7 +465,7 @@ static struct microcode_ops microcode_in
16046 .microcode_fini_cpu = microcode_fini_cpu,
16047 };
16048
16049-struct microcode_ops * __init init_intel_microcode(void)
16050+const struct microcode_ops * __init init_intel_microcode(void)
16051 {
16052 return &microcode_intel_ops;
16053 }
16054diff -urNp linux-2.6.39.1/arch/x86/kernel/module.c linux-2.6.39.1/arch/x86/kernel/module.c
16055--- linux-2.6.39.1/arch/x86/kernel/module.c 2011-05-19 00:06:34.000000000 -0400
16056+++ linux-2.6.39.1/arch/x86/kernel/module.c 2011-05-22 19:36:30.000000000 -0400
16057@@ -35,21 +35,66 @@
16058 #define DEBUGP(fmt...)
16059 #endif
16060
16061-void *module_alloc(unsigned long size)
16062+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
16063 {
16064 if (PAGE_ALIGN(size) > MODULES_LEN)
16065 return NULL;
16066 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
16067- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
16068+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
16069 -1, __builtin_return_address(0));
16070 }
16071
16072+void *module_alloc(unsigned long size)
16073+{
16074+
16075+#ifdef CONFIG_PAX_KERNEXEC
16076+ return __module_alloc(size, PAGE_KERNEL);
16077+#else
16078+ return __module_alloc(size, PAGE_KERNEL_EXEC);
16079+#endif
16080+
16081+}
16082+
16083 /* Free memory returned from module_alloc */
16084 void module_free(struct module *mod, void *module_region)
16085 {
16086 vfree(module_region);
16087 }
16088
16089+#ifdef CONFIG_PAX_KERNEXEC
16090+#ifdef CONFIG_X86_32
16091+void *module_alloc_exec(unsigned long size)
16092+{
16093+ struct vm_struct *area;
16094+
16095+ if (size == 0)
16096+ return NULL;
16097+
16098+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
16099+ return area ? area->addr : NULL;
16100+}
16101+EXPORT_SYMBOL(module_alloc_exec);
16102+
16103+void module_free_exec(struct module *mod, void *module_region)
16104+{
16105+ vunmap(module_region);
16106+}
16107+EXPORT_SYMBOL(module_free_exec);
16108+#else
16109+void module_free_exec(struct module *mod, void *module_region)
16110+{
16111+ module_free(mod, module_region);
16112+}
16113+EXPORT_SYMBOL(module_free_exec);
16114+
16115+void *module_alloc_exec(unsigned long size)
16116+{
16117+ return __module_alloc(size, PAGE_KERNEL_RX);
16118+}
16119+EXPORT_SYMBOL(module_alloc_exec);
16120+#endif
16121+#endif
16122+
16123 /* We don't need anything special. */
16124 int module_frob_arch_sections(Elf_Ehdr *hdr,
16125 Elf_Shdr *sechdrs,
16126@@ -69,14 +114,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
16127 unsigned int i;
16128 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
16129 Elf32_Sym *sym;
16130- uint32_t *location;
16131+ uint32_t *plocation, location;
16132
16133 DEBUGP("Applying relocate section %u to %u\n", relsec,
16134 sechdrs[relsec].sh_info);
16135 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
16136 /* This is where to make the change */
16137- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
16138- + rel[i].r_offset;
16139+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
16140+ location = (uint32_t)plocation;
16141+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
16142+ plocation = ktla_ktva((void *)plocation);
16143 /* This is the symbol it is referring to. Note that all
16144 undefined symbols have been resolved. */
16145 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
16146@@ -85,11 +132,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
16147 switch (ELF32_R_TYPE(rel[i].r_info)) {
16148 case R_386_32:
16149 /* We add the value into the location given */
16150- *location += sym->st_value;
16151+ pax_open_kernel();
16152+ *plocation += sym->st_value;
16153+ pax_close_kernel();
16154 break;
16155 case R_386_PC32:
16156 /* Add the value, subtract its postition */
16157- *location += sym->st_value - (uint32_t)location;
16158+ pax_open_kernel();
16159+ *plocation += sym->st_value - location;
16160+ pax_close_kernel();
16161 break;
16162 default:
16163 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
16164@@ -145,21 +196,30 @@ int apply_relocate_add(Elf64_Shdr *sechd
16165 case R_X86_64_NONE:
16166 break;
16167 case R_X86_64_64:
16168+ pax_open_kernel();
16169 *(u64 *)loc = val;
16170+ pax_close_kernel();
16171 break;
16172 case R_X86_64_32:
16173+ pax_open_kernel();
16174 *(u32 *)loc = val;
16175+ pax_close_kernel();
16176 if (val != *(u32 *)loc)
16177 goto overflow;
16178 break;
16179 case R_X86_64_32S:
16180+ pax_open_kernel();
16181 *(s32 *)loc = val;
16182+ pax_close_kernel();
16183 if ((s64)val != *(s32 *)loc)
16184 goto overflow;
16185 break;
16186 case R_X86_64_PC32:
16187 val -= (u64)loc;
16188+ pax_open_kernel();
16189 *(u32 *)loc = val;
16190+ pax_close_kernel();
16191+
16192 #if 0
16193 if ((s64)val != *(s32 *)loc)
16194 goto overflow;
16195diff -urNp linux-2.6.39.1/arch/x86/kernel/paravirt.c linux-2.6.39.1/arch/x86/kernel/paravirt.c
16196--- linux-2.6.39.1/arch/x86/kernel/paravirt.c 2011-05-19 00:06:34.000000000 -0400
16197+++ linux-2.6.39.1/arch/x86/kernel/paravirt.c 2011-05-22 19:36:30.000000000 -0400
16198@@ -122,7 +122,7 @@ unsigned paravirt_patch_jmp(void *insnbu
16199 * corresponding structure. */
16200 static void *get_call_destination(u8 type)
16201 {
16202- struct paravirt_patch_template tmpl = {
16203+ const struct paravirt_patch_template tmpl = {
16204 .pv_init_ops = pv_init_ops,
16205 .pv_time_ops = pv_time_ops,
16206 .pv_cpu_ops = pv_cpu_ops,
16207@@ -133,6 +133,9 @@ static void *get_call_destination(u8 typ
16208 .pv_lock_ops = pv_lock_ops,
16209 #endif
16210 };
16211+
16212+ pax_track_stack();
16213+
16214 return *((void **)&tmpl + type);
16215 }
16216
16217@@ -145,14 +148,14 @@ unsigned paravirt_patch_default(u8 type,
16218 if (opfunc == NULL)
16219 /* If there's no function, patch it with a ud2a (BUG) */
16220 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
16221- else if (opfunc == _paravirt_nop)
16222+ else if (opfunc == (void *)_paravirt_nop)
16223 /* If the operation is a nop, then nop the callsite */
16224 ret = paravirt_patch_nop();
16225
16226 /* identity functions just return their single argument */
16227- else if (opfunc == _paravirt_ident_32)
16228+ else if (opfunc == (void *)_paravirt_ident_32)
16229 ret = paravirt_patch_ident_32(insnbuf, len);
16230- else if (opfunc == _paravirt_ident_64)
16231+ else if (opfunc == (void *)_paravirt_ident_64)
16232 ret = paravirt_patch_ident_64(insnbuf, len);
16233
16234 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
16235@@ -178,7 +181,7 @@ unsigned paravirt_patch_insns(void *insn
16236 if (insn_len > len || start == NULL)
16237 insn_len = len;
16238 else
16239- memcpy(insnbuf, start, insn_len);
16240+ memcpy(insnbuf, ktla_ktva(start), insn_len);
16241
16242 return insn_len;
16243 }
16244@@ -294,22 +297,22 @@ void arch_flush_lazy_mmu_mode(void)
16245 preempt_enable();
16246 }
16247
16248-struct pv_info pv_info = {
16249+struct pv_info pv_info __read_only = {
16250 .name = "bare hardware",
16251 .paravirt_enabled = 0,
16252 .kernel_rpl = 0,
16253 .shared_kernel_pmd = 1, /* Only used when CONFIG_X86_PAE is set */
16254 };
16255
16256-struct pv_init_ops pv_init_ops = {
16257+struct pv_init_ops pv_init_ops __read_only = {
16258 .patch = native_patch,
16259 };
16260
16261-struct pv_time_ops pv_time_ops = {
16262+struct pv_time_ops pv_time_ops __read_only = {
16263 .sched_clock = native_sched_clock,
16264 };
16265
16266-struct pv_irq_ops pv_irq_ops = {
16267+struct pv_irq_ops pv_irq_ops __read_only = {
16268 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
16269 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
16270 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
16271@@ -321,7 +324,7 @@ struct pv_irq_ops pv_irq_ops = {
16272 #endif
16273 };
16274
16275-struct pv_cpu_ops pv_cpu_ops = {
16276+struct pv_cpu_ops pv_cpu_ops __read_only = {
16277 .cpuid = native_cpuid,
16278 .get_debugreg = native_get_debugreg,
16279 .set_debugreg = native_set_debugreg,
16280@@ -382,7 +385,7 @@ struct pv_cpu_ops pv_cpu_ops = {
16281 .end_context_switch = paravirt_nop,
16282 };
16283
16284-struct pv_apic_ops pv_apic_ops = {
16285+struct pv_apic_ops pv_apic_ops __read_only = {
16286 #ifdef CONFIG_X86_LOCAL_APIC
16287 .startup_ipi_hook = paravirt_nop,
16288 #endif
16289@@ -396,7 +399,7 @@ struct pv_apic_ops pv_apic_ops = {
16290 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
16291 #endif
16292
16293-struct pv_mmu_ops pv_mmu_ops = {
16294+struct pv_mmu_ops pv_mmu_ops __read_only = {
16295
16296 .read_cr2 = native_read_cr2,
16297 .write_cr2 = native_write_cr2,
16298@@ -465,6 +468,12 @@ struct pv_mmu_ops pv_mmu_ops = {
16299 },
16300
16301 .set_fixmap = native_set_fixmap,
16302+
16303+#ifdef CONFIG_PAX_KERNEXEC
16304+ .pax_open_kernel = native_pax_open_kernel,
16305+ .pax_close_kernel = native_pax_close_kernel,
16306+#endif
16307+
16308 };
16309
16310 EXPORT_SYMBOL_GPL(pv_time_ops);
16311diff -urNp linux-2.6.39.1/arch/x86/kernel/paravirt-spinlocks.c linux-2.6.39.1/arch/x86/kernel/paravirt-spinlocks.c
16312--- linux-2.6.39.1/arch/x86/kernel/paravirt-spinlocks.c 2011-05-19 00:06:34.000000000 -0400
16313+++ linux-2.6.39.1/arch/x86/kernel/paravirt-spinlocks.c 2011-05-22 19:36:30.000000000 -0400
16314@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t
16315 arch_spin_lock(lock);
16316 }
16317
16318-struct pv_lock_ops pv_lock_ops = {
16319+struct pv_lock_ops pv_lock_ops __read_only = {
16320 #ifdef CONFIG_SMP
16321 .spin_is_locked = __ticket_spin_is_locked,
16322 .spin_is_contended = __ticket_spin_is_contended,
16323diff -urNp linux-2.6.39.1/arch/x86/kernel/pci-calgary_64.c linux-2.6.39.1/arch/x86/kernel/pci-calgary_64.c
16324--- linux-2.6.39.1/arch/x86/kernel/pci-calgary_64.c 2011-05-19 00:06:34.000000000 -0400
16325+++ linux-2.6.39.1/arch/x86/kernel/pci-calgary_64.c 2011-05-22 19:36:30.000000000 -0400
16326@@ -179,13 +179,13 @@ static void calioc2_dump_error_regs(stru
16327 static void calgary_init_bitmap_from_tce_table(struct iommu_table *tbl);
16328 static void get_tce_space_from_tar(void);
16329
16330-static struct cal_chipset_ops calgary_chip_ops = {
16331+static const struct cal_chipset_ops calgary_chip_ops = {
16332 .handle_quirks = calgary_handle_quirks,
16333 .tce_cache_blast = calgary_tce_cache_blast,
16334 .dump_error_regs = calgary_dump_error_regs
16335 };
16336
16337-static struct cal_chipset_ops calioc2_chip_ops = {
16338+static const struct cal_chipset_ops calioc2_chip_ops = {
16339 .handle_quirks = calioc2_handle_quirks,
16340 .tce_cache_blast = calioc2_tce_cache_blast,
16341 .dump_error_regs = calioc2_dump_error_regs
16342@@ -476,7 +476,7 @@ static void calgary_free_coherent(struct
16343 free_pages((unsigned long)vaddr, get_order(size));
16344 }
16345
16346-static struct dma_map_ops calgary_dma_ops = {
16347+static const struct dma_map_ops calgary_dma_ops = {
16348 .alloc_coherent = calgary_alloc_coherent,
16349 .free_coherent = calgary_free_coherent,
16350 .map_sg = calgary_map_sg,
16351diff -urNp linux-2.6.39.1/arch/x86/kernel/pci-dma.c linux-2.6.39.1/arch/x86/kernel/pci-dma.c
16352--- linux-2.6.39.1/arch/x86/kernel/pci-dma.c 2011-05-19 00:06:34.000000000 -0400
16353+++ linux-2.6.39.1/arch/x86/kernel/pci-dma.c 2011-05-22 19:36:30.000000000 -0400
16354@@ -16,7 +16,7 @@
16355
16356 static int forbid_dac __read_mostly;
16357
16358-struct dma_map_ops *dma_ops = &nommu_dma_ops;
16359+const struct dma_map_ops *dma_ops = &nommu_dma_ops;
16360 EXPORT_SYMBOL(dma_ops);
16361
16362 static int iommu_sac_force __read_mostly;
16363@@ -250,7 +250,7 @@ early_param("iommu", iommu_setup);
16364
16365 int dma_supported(struct device *dev, u64 mask)
16366 {
16367- struct dma_map_ops *ops = get_dma_ops(dev);
16368+ const struct dma_map_ops *ops = get_dma_ops(dev);
16369
16370 #ifdef CONFIG_PCI
16371 if (mask > 0xffffffff && forbid_dac > 0) {
16372diff -urNp linux-2.6.39.1/arch/x86/kernel/pci-gart_64.c linux-2.6.39.1/arch/x86/kernel/pci-gart_64.c
16373--- linux-2.6.39.1/arch/x86/kernel/pci-gart_64.c 2011-05-19 00:06:34.000000000 -0400
16374+++ linux-2.6.39.1/arch/x86/kernel/pci-gart_64.c 2011-05-22 19:36:30.000000000 -0400
16375@@ -695,7 +695,7 @@ static __init int init_amd_gatt(struct a
16376 return -1;
16377 }
16378
16379-static struct dma_map_ops gart_dma_ops = {
16380+static const struct dma_map_ops gart_dma_ops = {
16381 .map_sg = gart_map_sg,
16382 .unmap_sg = gart_unmap_sg,
16383 .map_page = gart_map_page,
16384diff -urNp linux-2.6.39.1/arch/x86/kernel/pci-iommu_table.c linux-2.6.39.1/arch/x86/kernel/pci-iommu_table.c
16385--- linux-2.6.39.1/arch/x86/kernel/pci-iommu_table.c 2011-05-19 00:06:34.000000000 -0400
16386+++ linux-2.6.39.1/arch/x86/kernel/pci-iommu_table.c 2011-05-22 19:36:30.000000000 -0400
16387@@ -2,7 +2,7 @@
16388 #include <asm/iommu_table.h>
16389 #include <linux/string.h>
16390 #include <linux/kallsyms.h>
16391-
16392+#include <linux/sched.h>
16393
16394 #define DEBUG 1
16395
16396@@ -53,6 +53,8 @@ void __init check_iommu_entries(struct i
16397 char sym_p[KSYM_SYMBOL_LEN];
16398 char sym_q[KSYM_SYMBOL_LEN];
16399
16400+ pax_track_stack();
16401+
16402 /* Simple cyclic dependency checker. */
16403 for (p = start; p < finish; p++) {
16404 q = find_dependents_of(start, finish, p);
16405diff -urNp linux-2.6.39.1/arch/x86/kernel/pci-nommu.c linux-2.6.39.1/arch/x86/kernel/pci-nommu.c
16406--- linux-2.6.39.1/arch/x86/kernel/pci-nommu.c 2011-05-19 00:06:34.000000000 -0400
16407+++ linux-2.6.39.1/arch/x86/kernel/pci-nommu.c 2011-05-22 19:36:30.000000000 -0400
16408@@ -95,7 +95,7 @@ static void nommu_sync_sg_for_device(str
16409 flush_write_buffers();
16410 }
16411
16412-struct dma_map_ops nommu_dma_ops = {
16413+const struct dma_map_ops nommu_dma_ops = {
16414 .alloc_coherent = dma_generic_alloc_coherent,
16415 .free_coherent = nommu_free_coherent,
16416 .map_sg = nommu_map_sg,
16417diff -urNp linux-2.6.39.1/arch/x86/kernel/pci-swiotlb.c linux-2.6.39.1/arch/x86/kernel/pci-swiotlb.c
16418--- linux-2.6.39.1/arch/x86/kernel/pci-swiotlb.c 2011-05-19 00:06:34.000000000 -0400
16419+++ linux-2.6.39.1/arch/x86/kernel/pci-swiotlb.c 2011-05-22 19:36:30.000000000 -0400
16420@@ -26,7 +26,7 @@ static void *x86_swiotlb_alloc_coherent(
16421 return swiotlb_alloc_coherent(hwdev, size, dma_handle, flags);
16422 }
16423
16424-static struct dma_map_ops swiotlb_dma_ops = {
16425+static const struct dma_map_ops swiotlb_dma_ops = {
16426 .mapping_error = swiotlb_dma_mapping_error,
16427 .alloc_coherent = x86_swiotlb_alloc_coherent,
16428 .free_coherent = swiotlb_free_coherent,
16429diff -urNp linux-2.6.39.1/arch/x86/kernel/process_32.c linux-2.6.39.1/arch/x86/kernel/process_32.c
16430--- linux-2.6.39.1/arch/x86/kernel/process_32.c 2011-05-19 00:06:34.000000000 -0400
16431+++ linux-2.6.39.1/arch/x86/kernel/process_32.c 2011-05-22 19:36:30.000000000 -0400
16432@@ -65,6 +65,7 @@ asmlinkage void ret_from_fork(void) __as
16433 unsigned long thread_saved_pc(struct task_struct *tsk)
16434 {
16435 return ((unsigned long *)tsk->thread.sp)[3];
16436+//XXX return tsk->thread.eip;
16437 }
16438
16439 #ifndef CONFIG_SMP
16440@@ -126,15 +127,14 @@ void __show_regs(struct pt_regs *regs, i
16441 unsigned long sp;
16442 unsigned short ss, gs;
16443
16444- if (user_mode_vm(regs)) {
16445+ if (user_mode(regs)) {
16446 sp = regs->sp;
16447 ss = regs->ss & 0xffff;
16448- gs = get_user_gs(regs);
16449 } else {
16450 sp = kernel_stack_pointer(regs);
16451 savesegment(ss, ss);
16452- savesegment(gs, gs);
16453 }
16454+ gs = get_user_gs(regs);
16455
16456 show_regs_common();
16457
16458@@ -196,13 +196,14 @@ int copy_thread(unsigned long clone_flag
16459 struct task_struct *tsk;
16460 int err;
16461
16462- childregs = task_pt_regs(p);
16463+ childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
16464 *childregs = *regs;
16465 childregs->ax = 0;
16466 childregs->sp = sp;
16467
16468 p->thread.sp = (unsigned long) childregs;
16469 p->thread.sp0 = (unsigned long) (childregs+1);
16470+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
16471
16472 p->thread.ip = (unsigned long) ret_from_fork;
16473
16474@@ -293,7 +294,7 @@ __switch_to(struct task_struct *prev_p,
16475 struct thread_struct *prev = &prev_p->thread,
16476 *next = &next_p->thread;
16477 int cpu = smp_processor_id();
16478- struct tss_struct *tss = &per_cpu(init_tss, cpu);
16479+ struct tss_struct *tss = init_tss + cpu;
16480 bool preload_fpu;
16481
16482 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
16483@@ -328,6 +329,10 @@ __switch_to(struct task_struct *prev_p,
16484 */
16485 lazy_save_gs(prev->gs);
16486
16487+#ifdef CONFIG_PAX_MEMORY_UDEREF
16488+ __set_fs(task_thread_info(next_p)->addr_limit);
16489+#endif
16490+
16491 /*
16492 * Load the per-thread Thread-Local Storage descriptor.
16493 */
16494@@ -363,6 +368,9 @@ __switch_to(struct task_struct *prev_p,
16495 */
16496 arch_end_context_switch(next_p);
16497
16498+ percpu_write(current_task, next_p);
16499+ percpu_write(current_tinfo, &next_p->tinfo);
16500+
16501 if (preload_fpu)
16502 __math_state_restore();
16503
16504@@ -372,8 +380,6 @@ __switch_to(struct task_struct *prev_p,
16505 if (prev->gs | next->gs)
16506 lazy_load_gs(next->gs);
16507
16508- percpu_write(current_task, next_p);
16509-
16510 return prev_p;
16511 }
16512
16513@@ -403,4 +409,3 @@ unsigned long get_wchan(struct task_stru
16514 } while (count++ < 16);
16515 return 0;
16516 }
16517-
16518diff -urNp linux-2.6.39.1/arch/x86/kernel/process_64.c linux-2.6.39.1/arch/x86/kernel/process_64.c
16519--- linux-2.6.39.1/arch/x86/kernel/process_64.c 2011-05-19 00:06:34.000000000 -0400
16520+++ linux-2.6.39.1/arch/x86/kernel/process_64.c 2011-05-22 19:36:30.000000000 -0400
16521@@ -87,7 +87,7 @@ static void __exit_idle(void)
16522 void exit_idle(void)
16523 {
16524 /* idle loop has pid 0 */
16525- if (current->pid)
16526+ if (task_pid_nr(current))
16527 return;
16528 __exit_idle();
16529 }
16530@@ -260,8 +260,7 @@ int copy_thread(unsigned long clone_flag
16531 struct pt_regs *childregs;
16532 struct task_struct *me = current;
16533
16534- childregs = ((struct pt_regs *)
16535- (THREAD_SIZE + task_stack_page(p))) - 1;
16536+ childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
16537 *childregs = *regs;
16538
16539 childregs->ax = 0;
16540@@ -273,6 +272,7 @@ int copy_thread(unsigned long clone_flag
16541 p->thread.sp = (unsigned long) childregs;
16542 p->thread.sp0 = (unsigned long) (childregs+1);
16543 p->thread.usersp = me->thread.usersp;
16544+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
16545
16546 set_tsk_thread_flag(p, TIF_FORK);
16547
16548@@ -376,7 +376,7 @@ __switch_to(struct task_struct *prev_p,
16549 struct thread_struct *prev = &prev_p->thread;
16550 struct thread_struct *next = &next_p->thread;
16551 int cpu = smp_processor_id();
16552- struct tss_struct *tss = &per_cpu(init_tss, cpu);
16553+ struct tss_struct *tss = init_tss + cpu;
16554 unsigned fsindex, gsindex;
16555 bool preload_fpu;
16556
16557@@ -472,10 +472,9 @@ __switch_to(struct task_struct *prev_p,
16558 prev->usersp = percpu_read(old_rsp);
16559 percpu_write(old_rsp, next->usersp);
16560 percpu_write(current_task, next_p);
16561+ percpu_write(current_tinfo, &next_p->tinfo);
16562
16563- percpu_write(kernel_stack,
16564- (unsigned long)task_stack_page(next_p) +
16565- THREAD_SIZE - KERNEL_STACK_OFFSET);
16566+ percpu_write(kernel_stack, next->sp0);
16567
16568 /*
16569 * Now maybe reload the debug registers and handle I/O bitmaps
16570@@ -537,12 +536,11 @@ unsigned long get_wchan(struct task_stru
16571 if (!p || p == current || p->state == TASK_RUNNING)
16572 return 0;
16573 stack = (unsigned long)task_stack_page(p);
16574- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
16575+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
16576 return 0;
16577 fp = *(u64 *)(p->thread.sp);
16578 do {
16579- if (fp < (unsigned long)stack ||
16580- fp >= (unsigned long)stack+THREAD_SIZE)
16581+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
16582 return 0;
16583 ip = *(u64 *)(fp+8);
16584 if (!in_sched_functions(ip))
16585diff -urNp linux-2.6.39.1/arch/x86/kernel/process.c linux-2.6.39.1/arch/x86/kernel/process.c
16586--- linux-2.6.39.1/arch/x86/kernel/process.c 2011-05-19 00:06:34.000000000 -0400
16587+++ linux-2.6.39.1/arch/x86/kernel/process.c 2011-05-22 19:36:30.000000000 -0400
16588@@ -48,16 +48,33 @@ void free_thread_xstate(struct task_stru
16589
16590 void free_thread_info(struct thread_info *ti)
16591 {
16592- free_thread_xstate(ti->task);
16593 free_pages((unsigned long)ti, get_order(THREAD_SIZE));
16594 }
16595
16596+static struct kmem_cache *task_struct_cachep;
16597+
16598 void arch_task_cache_init(void)
16599 {
16600- task_xstate_cachep =
16601- kmem_cache_create("task_xstate", xstate_size,
16602+ /* create a slab on which task_structs can be allocated */
16603+ task_struct_cachep =
16604+ kmem_cache_create("task_struct", sizeof(struct task_struct),
16605+ ARCH_MIN_TASKALIGN, SLAB_PANIC | SLAB_NOTRACK, NULL);
16606+
16607+ task_xstate_cachep =
16608+ kmem_cache_create("task_xstate", xstate_size,
16609 __alignof__(union thread_xstate),
16610- SLAB_PANIC | SLAB_NOTRACK, NULL);
16611+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
16612+}
16613+
16614+struct task_struct *alloc_task_struct_node(int node)
16615+{
16616+ return kmem_cache_alloc_node(task_struct_cachep, GFP_KERNEL, node);
16617+}
16618+
16619+void free_task_struct(struct task_struct *task)
16620+{
16621+ free_thread_xstate(task);
16622+ kmem_cache_free(task_struct_cachep, task);
16623 }
16624
16625 /*
16626@@ -70,7 +87,7 @@ void exit_thread(void)
16627 unsigned long *bp = t->io_bitmap_ptr;
16628
16629 if (bp) {
16630- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
16631+ struct tss_struct *tss = init_tss + get_cpu();
16632
16633 t->io_bitmap_ptr = NULL;
16634 clear_thread_flag(TIF_IO_BITMAP);
16635@@ -106,7 +123,7 @@ void show_regs_common(void)
16636
16637 printk(KERN_CONT "\n");
16638 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s",
16639- current->pid, current->comm, print_tainted(),
16640+ task_pid_nr(current), current->comm, print_tainted(),
16641 init_utsname()->release,
16642 (int)strcspn(init_utsname()->version, " "),
16643 init_utsname()->version);
16644@@ -120,6 +137,9 @@ void flush_thread(void)
16645 {
16646 struct task_struct *tsk = current;
16647
16648+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
16649+ loadsegment(gs, 0);
16650+#endif
16651 flush_ptrace_hw_breakpoint(tsk);
16652 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
16653 /*
16654@@ -282,10 +302,10 @@ int kernel_thread(int (*fn)(void *), voi
16655 regs.di = (unsigned long) arg;
16656
16657 #ifdef CONFIG_X86_32
16658- regs.ds = __USER_DS;
16659- regs.es = __USER_DS;
16660+ regs.ds = __KERNEL_DS;
16661+ regs.es = __KERNEL_DS;
16662 regs.fs = __KERNEL_PERCPU;
16663- regs.gs = __KERNEL_STACK_CANARY;
16664+ savesegment(gs, regs.gs);
16665 #else
16666 regs.ss = __KERNEL_DS;
16667 #endif
16668@@ -401,7 +421,7 @@ void default_idle(void)
16669 EXPORT_SYMBOL(default_idle);
16670 #endif
16671
16672-void stop_this_cpu(void *dummy)
16673+__noreturn void stop_this_cpu(void *dummy)
16674 {
16675 local_irq_disable();
16676 /*
16677@@ -665,16 +685,34 @@ static int __init idle_setup(char *str)
16678 }
16679 early_param("idle", idle_setup);
16680
16681-unsigned long arch_align_stack(unsigned long sp)
16682+#ifdef CONFIG_PAX_RANDKSTACK
16683+asmlinkage void pax_randomize_kstack(void)
16684 {
16685- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
16686- sp -= get_random_int() % 8192;
16687- return sp & ~0xf;
16688-}
16689+ struct thread_struct *thread = &current->thread;
16690+ unsigned long time;
16691
16692-unsigned long arch_randomize_brk(struct mm_struct *mm)
16693-{
16694- unsigned long range_end = mm->brk + 0x02000000;
16695- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
16696-}
16697+ if (!randomize_va_space)
16698+ return;
16699+
16700+ rdtscl(time);
16701+
16702+ /* P4 seems to return a 0 LSB, ignore it */
16703+#ifdef CONFIG_MPENTIUM4
16704+ time &= 0x3EUL;
16705+ time <<= 2;
16706+#elif defined(CONFIG_X86_64)
16707+ time &= 0xFUL;
16708+ time <<= 4;
16709+#else
16710+ time &= 0x1FUL;
16711+ time <<= 3;
16712+#endif
16713+
16714+ thread->sp0 ^= time;
16715+ load_sp0(init_tss + smp_processor_id(), thread);
16716
16717+#ifdef CONFIG_X86_64
16718+ percpu_write(kernel_stack, thread->sp0);
16719+#endif
16720+}
16721+#endif
16722diff -urNp linux-2.6.39.1/arch/x86/kernel/ptrace.c linux-2.6.39.1/arch/x86/kernel/ptrace.c
16723--- linux-2.6.39.1/arch/x86/kernel/ptrace.c 2011-05-19 00:06:34.000000000 -0400
16724+++ linux-2.6.39.1/arch/x86/kernel/ptrace.c 2011-05-22 19:36:30.000000000 -0400
16725@@ -821,7 +821,7 @@ long arch_ptrace(struct task_struct *chi
16726 unsigned long addr, unsigned long data)
16727 {
16728 int ret;
16729- unsigned long __user *datap = (unsigned long __user *)data;
16730+ unsigned long __user *datap = (__force unsigned long __user *)data;
16731
16732 switch (request) {
16733 /* read the word at location addr in the USER area. */
16734@@ -906,14 +906,14 @@ long arch_ptrace(struct task_struct *chi
16735 if ((int) addr < 0)
16736 return -EIO;
16737 ret = do_get_thread_area(child, addr,
16738- (struct user_desc __user *)data);
16739+ (__force struct user_desc __user *) data);
16740 break;
16741
16742 case PTRACE_SET_THREAD_AREA:
16743 if ((int) addr < 0)
16744 return -EIO;
16745 ret = do_set_thread_area(child, addr,
16746- (struct user_desc __user *)data, 0);
16747+ (__force struct user_desc __user *) data, 0);
16748 break;
16749 #endif
16750
16751@@ -1330,7 +1330,7 @@ static void fill_sigtrap_info(struct tas
16752 memset(info, 0, sizeof(*info));
16753 info->si_signo = SIGTRAP;
16754 info->si_code = si_code;
16755- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
16756+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
16757 }
16758
16759 void user_single_step_siginfo(struct task_struct *tsk,
16760@@ -1363,7 +1363,7 @@ void send_sigtrap(struct task_struct *ts
16761 * We must return the syscall number to actually look up in the table.
16762 * This can be -1L to skip running any syscall at all.
16763 */
16764-asmregparm long syscall_trace_enter(struct pt_regs *regs)
16765+long syscall_trace_enter(struct pt_regs *regs)
16766 {
16767 long ret = 0;
16768
16769@@ -1408,7 +1408,7 @@ asmregparm long syscall_trace_enter(stru
16770 return ret ?: regs->orig_ax;
16771 }
16772
16773-asmregparm void syscall_trace_leave(struct pt_regs *regs)
16774+void syscall_trace_leave(struct pt_regs *regs)
16775 {
16776 bool step;
16777
16778diff -urNp linux-2.6.39.1/arch/x86/kernel/pvclock.c linux-2.6.39.1/arch/x86/kernel/pvclock.c
16779--- linux-2.6.39.1/arch/x86/kernel/pvclock.c 2011-05-19 00:06:34.000000000 -0400
16780+++ linux-2.6.39.1/arch/x86/kernel/pvclock.c 2011-05-22 19:36:30.000000000 -0400
16781@@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvc
16782 return pv_tsc_khz;
16783 }
16784
16785-static atomic64_t last_value = ATOMIC64_INIT(0);
16786+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
16787
16788 void pvclock_resume(void)
16789 {
16790- atomic64_set(&last_value, 0);
16791+ atomic64_set_unchecked(&last_value, 0);
16792 }
16793
16794 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
16795@@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct
16796 * updating at the same time, and one of them could be slightly behind,
16797 * making the assumption that last_value always go forward fail to hold.
16798 */
16799- last = atomic64_read(&last_value);
16800+ last = atomic64_read_unchecked(&last_value);
16801 do {
16802 if (ret < last)
16803 return last;
16804- last = atomic64_cmpxchg(&last_value, last, ret);
16805+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
16806 } while (unlikely(last != ret));
16807
16808 return ret;
16809diff -urNp linux-2.6.39.1/arch/x86/kernel/reboot.c linux-2.6.39.1/arch/x86/kernel/reboot.c
16810--- linux-2.6.39.1/arch/x86/kernel/reboot.c 2011-05-19 00:06:34.000000000 -0400
16811+++ linux-2.6.39.1/arch/x86/kernel/reboot.c 2011-05-23 17:07:00.000000000 -0400
16812@@ -35,7 +35,7 @@ void (*pm_power_off)(void);
16813 EXPORT_SYMBOL(pm_power_off);
16814
16815 static const struct desc_ptr no_idt = {};
16816-static int reboot_mode;
16817+static unsigned short reboot_mode;
16818 enum reboot_type reboot_type = BOOT_KBD;
16819 int reboot_force;
16820
16821@@ -307,13 +307,17 @@ core_initcall(reboot_init);
16822 extern const unsigned char machine_real_restart_asm[];
16823 extern const u64 machine_real_restart_gdt[3];
16824
16825-void machine_real_restart(unsigned int type)
16826+__noreturn void machine_real_restart(unsigned int type)
16827 {
16828 void *restart_va;
16829 unsigned long restart_pa;
16830- void (*restart_lowmem)(unsigned int);
16831+ void (* __noreturn restart_lowmem)(unsigned int);
16832 u64 *lowmem_gdt;
16833
16834+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
16835+ struct desc_struct *gdt;
16836+#endif
16837+
16838 local_irq_disable();
16839
16840 /* Write zero to CMOS register number 0x0f, which the BIOS POST
16841@@ -339,14 +343,14 @@ void machine_real_restart(unsigned int t
16842 boot)". This seems like a fairly standard thing that gets set by
16843 REBOOT.COM programs, and the previous reset routine did this
16844 too. */
16845- *((unsigned short *)0x472) = reboot_mode;
16846+ *(unsigned short *)(__va(0x472)) = reboot_mode;
16847
16848 /* Patch the GDT in the low memory trampoline */
16849 lowmem_gdt = TRAMPOLINE_SYM(machine_real_restart_gdt);
16850
16851 restart_va = TRAMPOLINE_SYM(machine_real_restart_asm);
16852 restart_pa = virt_to_phys(restart_va);
16853- restart_lowmem = (void (*)(unsigned int))restart_pa;
16854+ restart_lowmem = (void *)restart_pa;
16855
16856 /* GDT[0]: GDT self-pointer */
16857 lowmem_gdt[0] =
16858@@ -357,7 +361,33 @@ void machine_real_restart(unsigned int t
16859 GDT_ENTRY(0x009b, restart_pa, 0xffff);
16860
16861 /* Jump to the identity-mapped low memory code */
16862+
16863+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
16864+ gdt = get_cpu_gdt_table(smp_processor_id());
16865+ pax_open_kernel();
16866+#ifdef CONFIG_PAX_MEMORY_UDEREF
16867+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
16868+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
16869+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
16870+#endif
16871+#ifdef CONFIG_PAX_KERNEXEC
16872+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
16873+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
16874+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
16875+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
16876+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
16877+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
16878+#endif
16879+ pax_close_kernel();
16880+#endif
16881+
16882+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16883+ asm volatile("push %0; push %1; lret\n" : : "i" (__KERNEL_CS), "rm" (restart_lowmem), "a" (type));
16884+ unreachable();
16885+#else
16886 restart_lowmem(type);
16887+#endif
16888+
16889 }
16890 #ifdef CONFIG_APM_MODULE
16891 EXPORT_SYMBOL(machine_real_restart);
16892@@ -478,7 +508,7 @@ void __attribute__((weak)) mach_reboot_f
16893 {
16894 }
16895
16896-static void native_machine_emergency_restart(void)
16897+__noreturn static void native_machine_emergency_restart(void)
16898 {
16899 int i;
16900
16901@@ -593,13 +623,13 @@ void native_machine_shutdown(void)
16902 #endif
16903 }
16904
16905-static void __machine_emergency_restart(int emergency)
16906+static __noreturn void __machine_emergency_restart(int emergency)
16907 {
16908 reboot_emergency = emergency;
16909 machine_ops.emergency_restart();
16910 }
16911
16912-static void native_machine_restart(char *__unused)
16913+static __noreturn void native_machine_restart(char *__unused)
16914 {
16915 printk("machine restart\n");
16916
16917@@ -608,7 +638,7 @@ static void native_machine_restart(char
16918 __machine_emergency_restart(0);
16919 }
16920
16921-static void native_machine_halt(void)
16922+static __noreturn void native_machine_halt(void)
16923 {
16924 /* stop other cpus and apics */
16925 machine_shutdown();
16926@@ -619,7 +649,7 @@ static void native_machine_halt(void)
16927 stop_this_cpu(NULL);
16928 }
16929
16930-static void native_machine_power_off(void)
16931+__noreturn static void native_machine_power_off(void)
16932 {
16933 if (pm_power_off) {
16934 if (!reboot_force)
16935@@ -628,6 +658,7 @@ static void native_machine_power_off(voi
16936 }
16937 /* a fallback in case there is no PM info available */
16938 tboot_shutdown(TB_SHUTDOWN_HALT);
16939+ unreachable();
16940 }
16941
16942 struct machine_ops machine_ops = {
16943diff -urNp linux-2.6.39.1/arch/x86/kernel/setup.c linux-2.6.39.1/arch/x86/kernel/setup.c
16944--- linux-2.6.39.1/arch/x86/kernel/setup.c 2011-06-03 00:04:13.000000000 -0400
16945+++ linux-2.6.39.1/arch/x86/kernel/setup.c 2011-06-03 00:32:04.000000000 -0400
16946@@ -650,7 +650,7 @@ static void __init trim_bios_range(void)
16947 * area (640->1Mb) as ram even though it is not.
16948 * take them out.
16949 */
16950- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
16951+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
16952 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
16953 }
16954
16955@@ -775,14 +775,14 @@ void __init setup_arch(char **cmdline_p)
16956
16957 if (!boot_params.hdr.root_flags)
16958 root_mountflags &= ~MS_RDONLY;
16959- init_mm.start_code = (unsigned long) _text;
16960- init_mm.end_code = (unsigned long) _etext;
16961+ init_mm.start_code = ktla_ktva((unsigned long) _text);
16962+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
16963 init_mm.end_data = (unsigned long) _edata;
16964 init_mm.brk = _brk_end;
16965
16966- code_resource.start = virt_to_phys(_text);
16967- code_resource.end = virt_to_phys(_etext)-1;
16968- data_resource.start = virt_to_phys(_etext);
16969+ code_resource.start = virt_to_phys(ktla_ktva(_text));
16970+ code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
16971+ data_resource.start = virt_to_phys(_sdata);
16972 data_resource.end = virt_to_phys(_edata)-1;
16973 bss_resource.start = virt_to_phys(&__bss_start);
16974 bss_resource.end = virt_to_phys(&__bss_stop)-1;
16975diff -urNp linux-2.6.39.1/arch/x86/kernel/setup_percpu.c linux-2.6.39.1/arch/x86/kernel/setup_percpu.c
16976--- linux-2.6.39.1/arch/x86/kernel/setup_percpu.c 2011-05-19 00:06:34.000000000 -0400
16977+++ linux-2.6.39.1/arch/x86/kernel/setup_percpu.c 2011-06-04 20:08:30.000000000 -0400
16978@@ -21,19 +21,17 @@
16979 #include <asm/cpu.h>
16980 #include <asm/stackprotector.h>
16981
16982-DEFINE_PER_CPU(int, cpu_number);
16983+#ifdef CONFIG_SMP
16984+DEFINE_PER_CPU(unsigned int, cpu_number);
16985 EXPORT_PER_CPU_SYMBOL(cpu_number);
16986+#endif
16987
16988-#ifdef CONFIG_X86_64
16989 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
16990-#else
16991-#define BOOT_PERCPU_OFFSET 0
16992-#endif
16993
16994 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
16995 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
16996
16997-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
16998+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
16999 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
17000 };
17001 EXPORT_SYMBOL(__per_cpu_offset);
17002@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(
17003 {
17004 #ifdef CONFIG_X86_32
17005 struct desc_struct gdt;
17006+ unsigned long base = per_cpu_offset(cpu);
17007
17008- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
17009- 0x2 | DESCTYPE_S, 0x8);
17010- gdt.s = 1;
17011+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
17012+ 0x83 | DESCTYPE_S, 0xC);
17013 write_gdt_entry(get_cpu_gdt_table(cpu),
17014 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
17015 #endif
17016@@ -207,6 +205,11 @@ void __init setup_per_cpu_areas(void)
17017 /* alrighty, percpu areas up and running */
17018 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
17019 for_each_possible_cpu(cpu) {
17020+#ifdef CONFIG_CC_STACKPROTECTOR
17021+#ifdef CONFIG_X86_32
17022+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
17023+#endif
17024+#endif
17025 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
17026 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
17027 per_cpu(cpu_number, cpu) = cpu;
17028@@ -247,6 +250,12 @@ void __init setup_per_cpu_areas(void)
17029 */
17030 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
17031 #endif
17032+#ifdef CONFIG_CC_STACKPROTECTOR
17033+#ifdef CONFIG_X86_32
17034+ if (!cpu)
17035+ per_cpu(stack_canary.canary, cpu) = canary;
17036+#endif
17037+#endif
17038 /*
17039 * Up to this point, the boot CPU has been using .init.data
17040 * area. Reload any changed state for the boot CPU.
17041diff -urNp linux-2.6.39.1/arch/x86/kernel/signal.c linux-2.6.39.1/arch/x86/kernel/signal.c
17042--- linux-2.6.39.1/arch/x86/kernel/signal.c 2011-05-19 00:06:34.000000000 -0400
17043+++ linux-2.6.39.1/arch/x86/kernel/signal.c 2011-05-23 17:07:00.000000000 -0400
17044@@ -198,7 +198,7 @@ static unsigned long align_sigframe(unsi
17045 * Align the stack pointer according to the i386 ABI,
17046 * i.e. so that on function entry ((sp + 4) & 15) == 0.
17047 */
17048- sp = ((sp + 4) & -16ul) - 4;
17049+ sp = ((sp - 12) & -16ul) - 4;
17050 #else /* !CONFIG_X86_32 */
17051 sp = round_down(sp, 16) - 8;
17052 #endif
17053@@ -249,11 +249,11 @@ get_sigframe(struct k_sigaction *ka, str
17054 * Return an always-bogus address instead so we will die with SIGSEGV.
17055 */
17056 if (onsigstack && !likely(on_sig_stack(sp)))
17057- return (void __user *)-1L;
17058+ return (__force void __user *)-1L;
17059
17060 /* save i387 state */
17061 if (used_math() && save_i387_xstate(*fpstate) < 0)
17062- return (void __user *)-1L;
17063+ return (__force void __user *)-1L;
17064
17065 return (void __user *)sp;
17066 }
17067@@ -308,9 +308,9 @@ __setup_frame(int sig, struct k_sigactio
17068 }
17069
17070 if (current->mm->context.vdso)
17071- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
17072+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
17073 else
17074- restorer = &frame->retcode;
17075+ restorer = (void __user *)&frame->retcode;
17076 if (ka->sa.sa_flags & SA_RESTORER)
17077 restorer = ka->sa.sa_restorer;
17078
17079@@ -324,7 +324,7 @@ __setup_frame(int sig, struct k_sigactio
17080 * reasons and because gdb uses it as a signature to notice
17081 * signal handler stack frames.
17082 */
17083- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
17084+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
17085
17086 if (err)
17087 return -EFAULT;
17088@@ -378,7 +378,10 @@ static int __setup_rt_frame(int sig, str
17089 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
17090
17091 /* Set up to return from userspace. */
17092- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
17093+ if (current->mm->context.vdso)
17094+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
17095+ else
17096+ restorer = (void __user *)&frame->retcode;
17097 if (ka->sa.sa_flags & SA_RESTORER)
17098 restorer = ka->sa.sa_restorer;
17099 put_user_ex(restorer, &frame->pretcode);
17100@@ -390,7 +393,7 @@ static int __setup_rt_frame(int sig, str
17101 * reasons and because gdb uses it as a signature to notice
17102 * signal handler stack frames.
17103 */
17104- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
17105+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
17106 } put_user_catch(err);
17107
17108 if (err)
17109@@ -773,6 +776,8 @@ static void do_signal(struct pt_regs *re
17110 int signr;
17111 sigset_t *oldset;
17112
17113+ pax_track_stack();
17114+
17115 /*
17116 * We want the common case to go fast, which is why we may in certain
17117 * cases get here from kernel mode. Just return without doing anything
17118@@ -780,7 +785,7 @@ static void do_signal(struct pt_regs *re
17119 * X86_32: vm86 regs switched out by assembly code before reaching
17120 * here, so testing against kernel CS suffices.
17121 */
17122- if (!user_mode(regs))
17123+ if (!user_mode_novm(regs))
17124 return;
17125
17126 if (current_thread_info()->status & TS_RESTORE_SIGMASK)
17127diff -urNp linux-2.6.39.1/arch/x86/kernel/smpboot.c linux-2.6.39.1/arch/x86/kernel/smpboot.c
17128--- linux-2.6.39.1/arch/x86/kernel/smpboot.c 2011-05-19 00:06:34.000000000 -0400
17129+++ linux-2.6.39.1/arch/x86/kernel/smpboot.c 2011-05-22 19:36:30.000000000 -0400
17130@@ -696,17 +696,20 @@ static int __cpuinit do_boot_cpu(int api
17131 set_idle_for_cpu(cpu, c_idle.idle);
17132 do_rest:
17133 per_cpu(current_task, cpu) = c_idle.idle;
17134+ per_cpu(current_tinfo, cpu) = &c_idle.idle->tinfo;
17135 #ifdef CONFIG_X86_32
17136 /* Stack for startup_32 can be just as for start_secondary onwards */
17137 irq_ctx_init(cpu);
17138 #else
17139 clear_tsk_thread_flag(c_idle.idle, TIF_FORK);
17140 initial_gs = per_cpu_offset(cpu);
17141- per_cpu(kernel_stack, cpu) =
17142- (unsigned long)task_stack_page(c_idle.idle) -
17143- KERNEL_STACK_OFFSET + THREAD_SIZE;
17144+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(c_idle.idle) - 16 + THREAD_SIZE;
17145 #endif
17146+
17147+ pax_open_kernel();
17148 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
17149+ pax_close_kernel();
17150+
17151 initial_code = (unsigned long)start_secondary;
17152 stack_start = c_idle.idle->thread.sp;
17153
17154@@ -848,6 +851,12 @@ int __cpuinit native_cpu_up(unsigned int
17155
17156 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
17157
17158+#ifdef CONFIG_PAX_PER_CPU_PGD
17159+ clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
17160+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
17161+ KERNEL_PGD_PTRS);
17162+#endif
17163+
17164 err = do_boot_cpu(apicid, cpu);
17165 if (err) {
17166 pr_debug("do_boot_cpu failed %d\n", err);
17167diff -urNp linux-2.6.39.1/arch/x86/kernel/step.c linux-2.6.39.1/arch/x86/kernel/step.c
17168--- linux-2.6.39.1/arch/x86/kernel/step.c 2011-05-19 00:06:34.000000000 -0400
17169+++ linux-2.6.39.1/arch/x86/kernel/step.c 2011-05-22 19:36:30.000000000 -0400
17170@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struc
17171 struct desc_struct *desc;
17172 unsigned long base;
17173
17174- seg &= ~7UL;
17175+ seg >>= 3;
17176
17177 mutex_lock(&child->mm->context.lock);
17178- if (unlikely((seg >> 3) >= child->mm->context.size))
17179+ if (unlikely(seg >= child->mm->context.size))
17180 addr = -1L; /* bogus selector, access would fault */
17181 else {
17182 desc = child->mm->context.ldt + seg;
17183@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struc
17184 addr += base;
17185 }
17186 mutex_unlock(&child->mm->context.lock);
17187- }
17188+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
17189+ addr = ktla_ktva(addr);
17190
17191 return addr;
17192 }
17193@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct t
17194 unsigned char opcode[15];
17195 unsigned long addr = convert_ip_to_linear(child, regs);
17196
17197+ if (addr == -EINVAL)
17198+ return 0;
17199+
17200 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
17201 for (i = 0; i < copied; i++) {
17202 switch (opcode[i]) {
17203@@ -74,7 +78,7 @@ static int is_setting_trap_flag(struct t
17204
17205 #ifdef CONFIG_X86_64
17206 case 0x40 ... 0x4f:
17207- if (regs->cs != __USER_CS)
17208+ if ((regs->cs & 0xffff) != __USER_CS)
17209 /* 32-bit mode: register increment */
17210 return 0;
17211 /* 64-bit mode: REX prefix */
17212diff -urNp linux-2.6.39.1/arch/x86/kernel/syscall_table_32.S linux-2.6.39.1/arch/x86/kernel/syscall_table_32.S
17213--- linux-2.6.39.1/arch/x86/kernel/syscall_table_32.S 2011-05-19 00:06:34.000000000 -0400
17214+++ linux-2.6.39.1/arch/x86/kernel/syscall_table_32.S 2011-05-22 19:36:30.000000000 -0400
17215@@ -1,3 +1,4 @@
17216+.section .rodata,"a",@progbits
17217 ENTRY(sys_call_table)
17218 .long sys_restart_syscall /* 0 - old "setup()" system call, used for restarting */
17219 .long sys_exit
17220diff -urNp linux-2.6.39.1/arch/x86/kernel/sys_i386_32.c linux-2.6.39.1/arch/x86/kernel/sys_i386_32.c
17221--- linux-2.6.39.1/arch/x86/kernel/sys_i386_32.c 2011-05-19 00:06:34.000000000 -0400
17222+++ linux-2.6.39.1/arch/x86/kernel/sys_i386_32.c 2011-05-22 19:36:30.000000000 -0400
17223@@ -24,17 +24,224 @@
17224
17225 #include <asm/syscalls.h>
17226
17227-/*
17228- * Do a system call from kernel instead of calling sys_execve so we
17229- * end up with proper pt_regs.
17230- */
17231-int kernel_execve(const char *filename,
17232- const char *const argv[],
17233- const char *const envp[])
17234+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
17235 {
17236- long __res;
17237- asm volatile ("int $0x80"
17238- : "=a" (__res)
17239- : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
17240- return __res;
17241+ unsigned long pax_task_size = TASK_SIZE;
17242+
17243+#ifdef CONFIG_PAX_SEGMEXEC
17244+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
17245+ pax_task_size = SEGMEXEC_TASK_SIZE;
17246+#endif
17247+
17248+ if (len > pax_task_size || addr > pax_task_size - len)
17249+ return -EINVAL;
17250+
17251+ return 0;
17252+}
17253+
17254+unsigned long
17255+arch_get_unmapped_area(struct file *filp, unsigned long addr,
17256+ unsigned long len, unsigned long pgoff, unsigned long flags)
17257+{
17258+ struct mm_struct *mm = current->mm;
17259+ struct vm_area_struct *vma;
17260+ unsigned long start_addr, pax_task_size = TASK_SIZE;
17261+
17262+#ifdef CONFIG_PAX_SEGMEXEC
17263+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
17264+ pax_task_size = SEGMEXEC_TASK_SIZE;
17265+#endif
17266+
17267+ pax_task_size -= PAGE_SIZE;
17268+
17269+ if (len > pax_task_size)
17270+ return -ENOMEM;
17271+
17272+ if (flags & MAP_FIXED)
17273+ return addr;
17274+
17275+#ifdef CONFIG_PAX_RANDMMAP
17276+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
17277+#endif
17278+
17279+ if (addr) {
17280+ addr = PAGE_ALIGN(addr);
17281+ if (pax_task_size - len >= addr) {
17282+ vma = find_vma(mm, addr);
17283+ if (check_heap_stack_gap(vma, addr, len))
17284+ return addr;
17285+ }
17286+ }
17287+ if (len > mm->cached_hole_size) {
17288+ start_addr = addr = mm->free_area_cache;
17289+ } else {
17290+ start_addr = addr = mm->mmap_base;
17291+ mm->cached_hole_size = 0;
17292+ }
17293+
17294+#ifdef CONFIG_PAX_PAGEEXEC
17295+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
17296+ start_addr = 0x00110000UL;
17297+
17298+#ifdef CONFIG_PAX_RANDMMAP
17299+ if (mm->pax_flags & MF_PAX_RANDMMAP)
17300+ start_addr += mm->delta_mmap & 0x03FFF000UL;
17301+#endif
17302+
17303+ if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
17304+ start_addr = addr = mm->mmap_base;
17305+ else
17306+ addr = start_addr;
17307+ }
17308+#endif
17309+
17310+full_search:
17311+ for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
17312+ /* At this point: (!vma || addr < vma->vm_end). */
17313+ if (pax_task_size - len < addr) {
17314+ /*
17315+ * Start a new search - just in case we missed
17316+ * some holes.
17317+ */
17318+ if (start_addr != mm->mmap_base) {
17319+ start_addr = addr = mm->mmap_base;
17320+ mm->cached_hole_size = 0;
17321+ goto full_search;
17322+ }
17323+ return -ENOMEM;
17324+ }
17325+ if (check_heap_stack_gap(vma, addr, len))
17326+ break;
17327+ if (addr + mm->cached_hole_size < vma->vm_start)
17328+ mm->cached_hole_size = vma->vm_start - addr;
17329+ addr = vma->vm_end;
17330+ if (mm->start_brk <= addr && addr < mm->mmap_base) {
17331+ start_addr = addr = mm->mmap_base;
17332+ mm->cached_hole_size = 0;
17333+ goto full_search;
17334+ }
17335+ }
17336+
17337+ /*
17338+ * Remember the place where we stopped the search:
17339+ */
17340+ mm->free_area_cache = addr + len;
17341+ return addr;
17342+}
17343+
17344+unsigned long
17345+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
17346+ const unsigned long len, const unsigned long pgoff,
17347+ const unsigned long flags)
17348+{
17349+ struct vm_area_struct *vma;
17350+ struct mm_struct *mm = current->mm;
17351+ unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
17352+
17353+#ifdef CONFIG_PAX_SEGMEXEC
17354+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
17355+ pax_task_size = SEGMEXEC_TASK_SIZE;
17356+#endif
17357+
17358+ pax_task_size -= PAGE_SIZE;
17359+
17360+ /* requested length too big for entire address space */
17361+ if (len > pax_task_size)
17362+ return -ENOMEM;
17363+
17364+ if (flags & MAP_FIXED)
17365+ return addr;
17366+
17367+#ifdef CONFIG_PAX_PAGEEXEC
17368+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
17369+ goto bottomup;
17370+#endif
17371+
17372+#ifdef CONFIG_PAX_RANDMMAP
17373+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
17374+#endif
17375+
17376+ /* requesting a specific address */
17377+ if (addr) {
17378+ addr = PAGE_ALIGN(addr);
17379+ if (pax_task_size - len >= addr) {
17380+ vma = find_vma(mm, addr);
17381+ if (check_heap_stack_gap(vma, addr, len))
17382+ return addr;
17383+ }
17384+ }
17385+
17386+ /* check if free_area_cache is useful for us */
17387+ if (len <= mm->cached_hole_size) {
17388+ mm->cached_hole_size = 0;
17389+ mm->free_area_cache = mm->mmap_base;
17390+ }
17391+
17392+ /* either no address requested or can't fit in requested address hole */
17393+ addr = mm->free_area_cache;
17394+
17395+ /* make sure it can fit in the remaining address space */
17396+ if (addr > len) {
17397+ vma = find_vma(mm, addr-len);
17398+ if (check_heap_stack_gap(vma, addr - len, len))
17399+ /* remember the address as a hint for next time */
17400+ return (mm->free_area_cache = addr-len);
17401+ }
17402+
17403+ if (mm->mmap_base < len)
17404+ goto bottomup;
17405+
17406+ addr = mm->mmap_base-len;
17407+
17408+ do {
17409+ /*
17410+ * Lookup failure means no vma is above this address,
17411+ * else if new region fits below vma->vm_start,
17412+ * return with success:
17413+ */
17414+ vma = find_vma(mm, addr);
17415+ if (check_heap_stack_gap(vma, addr, len))
17416+ /* remember the address as a hint for next time */
17417+ return (mm->free_area_cache = addr);
17418+
17419+ /* remember the largest hole we saw so far */
17420+ if (addr + mm->cached_hole_size < vma->vm_start)
17421+ mm->cached_hole_size = vma->vm_start - addr;
17422+
17423+ /* try just below the current vma->vm_start */
17424+ addr = skip_heap_stack_gap(vma, len);
17425+ } while (!IS_ERR_VALUE(addr));
17426+
17427+bottomup:
17428+ /*
17429+ * A failed mmap() very likely causes application failure,
17430+ * so fall back to the bottom-up function here. This scenario
17431+ * can happen with large stack limits and large mmap()
17432+ * allocations.
17433+ */
17434+
17435+#ifdef CONFIG_PAX_SEGMEXEC
17436+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
17437+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
17438+ else
17439+#endif
17440+
17441+ mm->mmap_base = TASK_UNMAPPED_BASE;
17442+
17443+#ifdef CONFIG_PAX_RANDMMAP
17444+ if (mm->pax_flags & MF_PAX_RANDMMAP)
17445+ mm->mmap_base += mm->delta_mmap;
17446+#endif
17447+
17448+ mm->free_area_cache = mm->mmap_base;
17449+ mm->cached_hole_size = ~0UL;
17450+ addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
17451+ /*
17452+ * Restore the topdown base:
17453+ */
17454+ mm->mmap_base = base;
17455+ mm->free_area_cache = base;
17456+ mm->cached_hole_size = ~0UL;
17457+
17458+ return addr;
17459 }
17460diff -urNp linux-2.6.39.1/arch/x86/kernel/sys_x86_64.c linux-2.6.39.1/arch/x86/kernel/sys_x86_64.c
17461--- linux-2.6.39.1/arch/x86/kernel/sys_x86_64.c 2011-05-19 00:06:34.000000000 -0400
17462+++ linux-2.6.39.1/arch/x86/kernel/sys_x86_64.c 2011-05-22 19:36:30.000000000 -0400
17463@@ -32,8 +32,8 @@ out:
17464 return error;
17465 }
17466
17467-static void find_start_end(unsigned long flags, unsigned long *begin,
17468- unsigned long *end)
17469+static void find_start_end(struct mm_struct *mm, unsigned long flags,
17470+ unsigned long *begin, unsigned long *end)
17471 {
17472 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT)) {
17473 unsigned long new_begin;
17474@@ -52,7 +52,7 @@ static void find_start_end(unsigned long
17475 *begin = new_begin;
17476 }
17477 } else {
17478- *begin = TASK_UNMAPPED_BASE;
17479+ *begin = mm->mmap_base;
17480 *end = TASK_SIZE;
17481 }
17482 }
17483@@ -69,16 +69,19 @@ arch_get_unmapped_area(struct file *filp
17484 if (flags & MAP_FIXED)
17485 return addr;
17486
17487- find_start_end(flags, &begin, &end);
17488+ find_start_end(mm, flags, &begin, &end);
17489
17490 if (len > end)
17491 return -ENOMEM;
17492
17493+#ifdef CONFIG_PAX_RANDMMAP
17494+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
17495+#endif
17496+
17497 if (addr) {
17498 addr = PAGE_ALIGN(addr);
17499 vma = find_vma(mm, addr);
17500- if (end - len >= addr &&
17501- (!vma || addr + len <= vma->vm_start))
17502+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
17503 return addr;
17504 }
17505 if (((flags & MAP_32BIT) || test_thread_flag(TIF_IA32))
17506@@ -106,7 +109,7 @@ full_search:
17507 }
17508 return -ENOMEM;
17509 }
17510- if (!vma || addr + len <= vma->vm_start) {
17511+ if (check_heap_stack_gap(vma, addr, len)) {
17512 /*
17513 * Remember the place where we stopped the search:
17514 */
17515@@ -128,7 +131,7 @@ arch_get_unmapped_area_topdown(struct fi
17516 {
17517 struct vm_area_struct *vma;
17518 struct mm_struct *mm = current->mm;
17519- unsigned long addr = addr0;
17520+ unsigned long base = mm->mmap_base, addr = addr0;
17521
17522 /* requested length too big for entire address space */
17523 if (len > TASK_SIZE)
17524@@ -141,13 +144,18 @@ arch_get_unmapped_area_topdown(struct fi
17525 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT))
17526 goto bottomup;
17527
17528+#ifdef CONFIG_PAX_RANDMMAP
17529+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
17530+#endif
17531+
17532 /* requesting a specific address */
17533 if (addr) {
17534 addr = PAGE_ALIGN(addr);
17535- vma = find_vma(mm, addr);
17536- if (TASK_SIZE - len >= addr &&
17537- (!vma || addr + len <= vma->vm_start))
17538- return addr;
17539+ if (TASK_SIZE - len >= addr) {
17540+ vma = find_vma(mm, addr);
17541+ if (check_heap_stack_gap(vma, addr, len))
17542+ return addr;
17543+ }
17544 }
17545
17546 /* check if free_area_cache is useful for us */
17547@@ -162,7 +170,7 @@ arch_get_unmapped_area_topdown(struct fi
17548 /* make sure it can fit in the remaining address space */
17549 if (addr > len) {
17550 vma = find_vma(mm, addr-len);
17551- if (!vma || addr <= vma->vm_start)
17552+ if (check_heap_stack_gap(vma, addr - len, len))
17553 /* remember the address as a hint for next time */
17554 return mm->free_area_cache = addr-len;
17555 }
17556@@ -179,7 +187,7 @@ arch_get_unmapped_area_topdown(struct fi
17557 * return with success:
17558 */
17559 vma = find_vma(mm, addr);
17560- if (!vma || addr+len <= vma->vm_start)
17561+ if (check_heap_stack_gap(vma, addr, len))
17562 /* remember the address as a hint for next time */
17563 return mm->free_area_cache = addr;
17564
17565@@ -188,8 +196,8 @@ arch_get_unmapped_area_topdown(struct fi
17566 mm->cached_hole_size = vma->vm_start - addr;
17567
17568 /* try just below the current vma->vm_start */
17569- addr = vma->vm_start-len;
17570- } while (len < vma->vm_start);
17571+ addr = skip_heap_stack_gap(vma, len);
17572+ } while (!IS_ERR_VALUE(addr));
17573
17574 bottomup:
17575 /*
17576@@ -198,13 +206,21 @@ bottomup:
17577 * can happen with large stack limits and large mmap()
17578 * allocations.
17579 */
17580+ mm->mmap_base = TASK_UNMAPPED_BASE;
17581+
17582+#ifdef CONFIG_PAX_RANDMMAP
17583+ if (mm->pax_flags & MF_PAX_RANDMMAP)
17584+ mm->mmap_base += mm->delta_mmap;
17585+#endif
17586+
17587+ mm->free_area_cache = mm->mmap_base;
17588 mm->cached_hole_size = ~0UL;
17589- mm->free_area_cache = TASK_UNMAPPED_BASE;
17590 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
17591 /*
17592 * Restore the topdown base:
17593 */
17594- mm->free_area_cache = mm->mmap_base;
17595+ mm->mmap_base = base;
17596+ mm->free_area_cache = base;
17597 mm->cached_hole_size = ~0UL;
17598
17599 return addr;
17600diff -urNp linux-2.6.39.1/arch/x86/kernel/tboot.c linux-2.6.39.1/arch/x86/kernel/tboot.c
17601--- linux-2.6.39.1/arch/x86/kernel/tboot.c 2011-05-19 00:06:34.000000000 -0400
17602+++ linux-2.6.39.1/arch/x86/kernel/tboot.c 2011-05-22 19:36:30.000000000 -0400
17603@@ -218,7 +218,7 @@ static int tboot_setup_sleep(void)
17604
17605 void tboot_shutdown(u32 shutdown_type)
17606 {
17607- void (*shutdown)(void);
17608+ void (* __noreturn shutdown)(void);
17609
17610 if (!tboot_enabled())
17611 return;
17612@@ -240,7 +240,7 @@ void tboot_shutdown(u32 shutdown_type)
17613
17614 switch_to_tboot_pt();
17615
17616- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
17617+ shutdown = (void *)tboot->shutdown_entry;
17618 shutdown();
17619
17620 /* should not reach here */
17621@@ -297,7 +297,7 @@ void tboot_sleep(u8 sleep_state, u32 pm1
17622 tboot_shutdown(acpi_shutdown_map[sleep_state]);
17623 }
17624
17625-static atomic_t ap_wfs_count;
17626+static atomic_unchecked_t ap_wfs_count;
17627
17628 static int tboot_wait_for_aps(int num_aps)
17629 {
17630@@ -321,9 +321,9 @@ static int __cpuinit tboot_cpu_callback(
17631 {
17632 switch (action) {
17633 case CPU_DYING:
17634- atomic_inc(&ap_wfs_count);
17635+ atomic_inc_unchecked(&ap_wfs_count);
17636 if (num_online_cpus() == 1)
17637- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
17638+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
17639 return NOTIFY_BAD;
17640 break;
17641 }
17642@@ -342,7 +342,7 @@ static __init int tboot_late_init(void)
17643
17644 tboot_create_trampoline();
17645
17646- atomic_set(&ap_wfs_count, 0);
17647+ atomic_set_unchecked(&ap_wfs_count, 0);
17648 register_hotcpu_notifier(&tboot_cpu_notifier);
17649 return 0;
17650 }
17651diff -urNp linux-2.6.39.1/arch/x86/kernel/time.c linux-2.6.39.1/arch/x86/kernel/time.c
17652--- linux-2.6.39.1/arch/x86/kernel/time.c 2011-05-19 00:06:34.000000000 -0400
17653+++ linux-2.6.39.1/arch/x86/kernel/time.c 2011-05-22 19:36:30.000000000 -0400
17654@@ -22,17 +22,13 @@
17655 #include <asm/hpet.h>
17656 #include <asm/time.h>
17657
17658-#ifdef CONFIG_X86_64
17659-volatile unsigned long __jiffies __section_jiffies = INITIAL_JIFFIES;
17660-#endif
17661-
17662 unsigned long profile_pc(struct pt_regs *regs)
17663 {
17664 unsigned long pc = instruction_pointer(regs);
17665
17666- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
17667+ if (!user_mode(regs) && in_lock_functions(pc)) {
17668 #ifdef CONFIG_FRAME_POINTER
17669- return *(unsigned long *)(regs->bp + sizeof(long));
17670+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
17671 #else
17672 unsigned long *sp =
17673 (unsigned long *)kernel_stack_pointer(regs);
17674@@ -41,11 +37,17 @@ unsigned long profile_pc(struct pt_regs
17675 * or above a saved flags. Eflags has bits 22-31 zero,
17676 * kernel addresses don't.
17677 */
17678+
17679+#ifdef CONFIG_PAX_KERNEXEC
17680+ return ktla_ktva(sp[0]);
17681+#else
17682 if (sp[0] >> 22)
17683 return sp[0];
17684 if (sp[1] >> 22)
17685 return sp[1];
17686 #endif
17687+
17688+#endif
17689 }
17690 return pc;
17691 }
17692diff -urNp linux-2.6.39.1/arch/x86/kernel/tls.c linux-2.6.39.1/arch/x86/kernel/tls.c
17693--- linux-2.6.39.1/arch/x86/kernel/tls.c 2011-05-19 00:06:34.000000000 -0400
17694+++ linux-2.6.39.1/arch/x86/kernel/tls.c 2011-05-22 19:36:30.000000000 -0400
17695@@ -85,6 +85,11 @@ int do_set_thread_area(struct task_struc
17696 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
17697 return -EINVAL;
17698
17699+#ifdef CONFIG_PAX_SEGMEXEC
17700+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
17701+ return -EINVAL;
17702+#endif
17703+
17704 set_tls_desc(p, idx, &info, 1);
17705
17706 return 0;
17707diff -urNp linux-2.6.39.1/arch/x86/kernel/trampoline_32.S linux-2.6.39.1/arch/x86/kernel/trampoline_32.S
17708--- linux-2.6.39.1/arch/x86/kernel/trampoline_32.S 2011-05-19 00:06:34.000000000 -0400
17709+++ linux-2.6.39.1/arch/x86/kernel/trampoline_32.S 2011-05-22 19:36:30.000000000 -0400
17710@@ -32,6 +32,12 @@
17711 #include <asm/segment.h>
17712 #include <asm/page_types.h>
17713
17714+#ifdef CONFIG_PAX_KERNEXEC
17715+#define ta(X) (X)
17716+#else
17717+#define ta(X) ((X) - __PAGE_OFFSET)
17718+#endif
17719+
17720 #ifdef CONFIG_SMP
17721
17722 .section ".x86_trampoline","a"
17723@@ -62,7 +68,7 @@ r_base = .
17724 inc %ax # protected mode (PE) bit
17725 lmsw %ax # into protected mode
17726 # flush prefetch and jump to startup_32_smp in arch/i386/kernel/head.S
17727- ljmpl $__BOOT_CS, $(startup_32_smp-__PAGE_OFFSET)
17728+ ljmpl $__BOOT_CS, $ta(startup_32_smp)
17729
17730 # These need to be in the same 64K segment as the above;
17731 # hence we don't use the boot_gdt_descr defined in head.S
17732diff -urNp linux-2.6.39.1/arch/x86/kernel/trampoline_64.S linux-2.6.39.1/arch/x86/kernel/trampoline_64.S
17733--- linux-2.6.39.1/arch/x86/kernel/trampoline_64.S 2011-05-19 00:06:34.000000000 -0400
17734+++ linux-2.6.39.1/arch/x86/kernel/trampoline_64.S 2011-05-22 19:36:30.000000000 -0400
17735@@ -90,7 +90,7 @@ startup_32:
17736 movl $__KERNEL_DS, %eax # Initialize the %ds segment register
17737 movl %eax, %ds
17738
17739- movl $X86_CR4_PAE, %eax
17740+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17741 movl %eax, %cr4 # Enable PAE mode
17742
17743 # Setup trampoline 4 level pagetables
17744@@ -138,7 +138,7 @@ tidt:
17745 # so the kernel can live anywhere
17746 .balign 4
17747 tgdt:
17748- .short tgdt_end - tgdt # gdt limit
17749+ .short tgdt_end - tgdt - 1 # gdt limit
17750 .long tgdt - r_base
17751 .short 0
17752 .quad 0x00cf9b000000ffff # __KERNEL32_CS
17753diff -urNp linux-2.6.39.1/arch/x86/kernel/traps.c linux-2.6.39.1/arch/x86/kernel/traps.c
17754--- linux-2.6.39.1/arch/x86/kernel/traps.c 2011-05-19 00:06:34.000000000 -0400
17755+++ linux-2.6.39.1/arch/x86/kernel/traps.c 2011-05-22 19:36:30.000000000 -0400
17756@@ -70,12 +70,6 @@ asmlinkage int system_call(void);
17757
17758 /* Do we ignore FPU interrupts ? */
17759 char ignore_fpu_irq;
17760-
17761-/*
17762- * The IDT has to be page-aligned to simplify the Pentium
17763- * F0 0F bug workaround.
17764- */
17765-gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
17766 #endif
17767
17768 DECLARE_BITMAP(used_vectors, NR_VECTORS);
17769@@ -117,13 +111,13 @@ static inline void preempt_conditional_c
17770 }
17771
17772 static void __kprobes
17773-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
17774+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
17775 long error_code, siginfo_t *info)
17776 {
17777 struct task_struct *tsk = current;
17778
17779 #ifdef CONFIG_X86_32
17780- if (regs->flags & X86_VM_MASK) {
17781+ if (v8086_mode(regs)) {
17782 /*
17783 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
17784 * On nmi (interrupt 2), do_trap should not be called.
17785@@ -134,7 +128,7 @@ do_trap(int trapnr, int signr, char *str
17786 }
17787 #endif
17788
17789- if (!user_mode(regs))
17790+ if (!user_mode_novm(regs))
17791 goto kernel_trap;
17792
17793 #ifdef CONFIG_X86_32
17794@@ -157,7 +151,7 @@ trap_signal:
17795 printk_ratelimit()) {
17796 printk(KERN_INFO
17797 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
17798- tsk->comm, tsk->pid, str,
17799+ tsk->comm, task_pid_nr(tsk), str,
17800 regs->ip, regs->sp, error_code);
17801 print_vma_addr(" in ", regs->ip);
17802 printk("\n");
17803@@ -174,8 +168,20 @@ kernel_trap:
17804 if (!fixup_exception(regs)) {
17805 tsk->thread.error_code = error_code;
17806 tsk->thread.trap_no = trapnr;
17807+
17808+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
17809+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
17810+ str = "PAX: suspicious stack segment fault";
17811+#endif
17812+
17813 die(str, regs, error_code);
17814 }
17815+
17816+#ifdef CONFIG_PAX_REFCOUNT
17817+ if (trapnr == 4)
17818+ pax_report_refcount_overflow(regs);
17819+#endif
17820+
17821 return;
17822
17823 #ifdef CONFIG_X86_32
17824@@ -264,14 +270,30 @@ do_general_protection(struct pt_regs *re
17825 conditional_sti(regs);
17826
17827 #ifdef CONFIG_X86_32
17828- if (regs->flags & X86_VM_MASK)
17829+ if (v8086_mode(regs))
17830 goto gp_in_vm86;
17831 #endif
17832
17833 tsk = current;
17834- if (!user_mode(regs))
17835+ if (!user_mode_novm(regs))
17836 goto gp_in_kernel;
17837
17838+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17839+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
17840+ struct mm_struct *mm = tsk->mm;
17841+ unsigned long limit;
17842+
17843+ down_write(&mm->mmap_sem);
17844+ limit = mm->context.user_cs_limit;
17845+ if (limit < TASK_SIZE) {
17846+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
17847+ up_write(&mm->mmap_sem);
17848+ return;
17849+ }
17850+ up_write(&mm->mmap_sem);
17851+ }
17852+#endif
17853+
17854 tsk->thread.error_code = error_code;
17855 tsk->thread.trap_no = 13;
17856
17857@@ -304,6 +326,13 @@ gp_in_kernel:
17858 if (notify_die(DIE_GPF, "general protection fault", regs,
17859 error_code, 13, SIGSEGV) == NOTIFY_STOP)
17860 return;
17861+
17862+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
17863+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
17864+ die("PAX: suspicious general protection fault", regs, error_code);
17865+ else
17866+#endif
17867+
17868 die("general protection fault", regs, error_code);
17869 }
17870
17871@@ -569,7 +598,7 @@ dotraplinkage void __kprobes do_debug(st
17872 /* It's safe to allow irq's after DR6 has been saved */
17873 preempt_conditional_sti(regs);
17874
17875- if (regs->flags & X86_VM_MASK) {
17876+ if (v8086_mode(regs)) {
17877 handle_vm86_trap((struct kernel_vm86_regs *) regs,
17878 error_code, 1);
17879 preempt_conditional_cli(regs);
17880@@ -583,7 +612,7 @@ dotraplinkage void __kprobes do_debug(st
17881 * We already checked v86 mode above, so we can check for kernel mode
17882 * by just checking the CPL of CS.
17883 */
17884- if ((dr6 & DR_STEP) && !user_mode(regs)) {
17885+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
17886 tsk->thread.debugreg6 &= ~DR_STEP;
17887 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
17888 regs->flags &= ~X86_EFLAGS_TF;
17889@@ -612,7 +641,7 @@ void math_error(struct pt_regs *regs, in
17890 return;
17891 conditional_sti(regs);
17892
17893- if (!user_mode_vm(regs))
17894+ if (!user_mode(regs))
17895 {
17896 if (!fixup_exception(regs)) {
17897 task->thread.error_code = error_code;
17898@@ -723,7 +752,7 @@ asmlinkage void __attribute__((weak)) sm
17899 void __math_state_restore(void)
17900 {
17901 struct thread_info *thread = current_thread_info();
17902- struct task_struct *tsk = thread->task;
17903+ struct task_struct *tsk = current;
17904
17905 /*
17906 * Paranoid restore. send a SIGSEGV if we fail to restore the state.
17907@@ -750,8 +779,7 @@ void __math_state_restore(void)
17908 */
17909 asmlinkage void math_state_restore(void)
17910 {
17911- struct thread_info *thread = current_thread_info();
17912- struct task_struct *tsk = thread->task;
17913+ struct task_struct *tsk = current;
17914
17915 if (!tsk_used_math(tsk)) {
17916 local_irq_enable();
17917diff -urNp linux-2.6.39.1/arch/x86/kernel/vm86_32.c linux-2.6.39.1/arch/x86/kernel/vm86_32.c
17918--- linux-2.6.39.1/arch/x86/kernel/vm86_32.c 2011-05-19 00:06:34.000000000 -0400
17919+++ linux-2.6.39.1/arch/x86/kernel/vm86_32.c 2011-05-22 19:41:32.000000000 -0400
17920@@ -41,6 +41,7 @@
17921 #include <linux/ptrace.h>
17922 #include <linux/audit.h>
17923 #include <linux/stddef.h>
17924+#include <linux/grsecurity.h>
17925
17926 #include <asm/uaccess.h>
17927 #include <asm/io.h>
17928@@ -148,7 +149,7 @@ struct pt_regs *save_v86_state(struct ke
17929 do_exit(SIGSEGV);
17930 }
17931
17932- tss = &per_cpu(init_tss, get_cpu());
17933+ tss = init_tss + get_cpu();
17934 current->thread.sp0 = current->thread.saved_sp0;
17935 current->thread.sysenter_cs = __KERNEL_CS;
17936 load_sp0(tss, &current->thread);
17937@@ -208,6 +209,13 @@ int sys_vm86old(struct vm86_struct __use
17938 struct task_struct *tsk;
17939 int tmp, ret = -EPERM;
17940
17941+#ifdef CONFIG_GRKERNSEC_VM86
17942+ if (!capable(CAP_SYS_RAWIO)) {
17943+ gr_handle_vm86();
17944+ goto out;
17945+ }
17946+#endif
17947+
17948 tsk = current;
17949 if (tsk->thread.saved_sp0)
17950 goto out;
17951@@ -238,6 +246,14 @@ int sys_vm86(unsigned long cmd, unsigned
17952 int tmp, ret;
17953 struct vm86plus_struct __user *v86;
17954
17955+#ifdef CONFIG_GRKERNSEC_VM86
17956+ if (!capable(CAP_SYS_RAWIO)) {
17957+ gr_handle_vm86();
17958+ ret = -EPERM;
17959+ goto out;
17960+ }
17961+#endif
17962+
17963 tsk = current;
17964 switch (cmd) {
17965 case VM86_REQUEST_IRQ:
17966@@ -324,7 +340,7 @@ static void do_sys_vm86(struct kernel_vm
17967 tsk->thread.saved_fs = info->regs32->fs;
17968 tsk->thread.saved_gs = get_user_gs(info->regs32);
17969
17970- tss = &per_cpu(init_tss, get_cpu());
17971+ tss = init_tss + get_cpu();
17972 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
17973 if (cpu_has_sep)
17974 tsk->thread.sysenter_cs = 0;
17975@@ -529,7 +545,7 @@ static void do_int(struct kernel_vm86_re
17976 goto cannot_handle;
17977 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
17978 goto cannot_handle;
17979- intr_ptr = (unsigned long __user *) (i << 2);
17980+ intr_ptr = (__force unsigned long __user *) (i << 2);
17981 if (get_user(segoffs, intr_ptr))
17982 goto cannot_handle;
17983 if ((segoffs >> 16) == BIOSSEG)
17984diff -urNp linux-2.6.39.1/arch/x86/kernel/vmlinux.lds.S linux-2.6.39.1/arch/x86/kernel/vmlinux.lds.S
17985--- linux-2.6.39.1/arch/x86/kernel/vmlinux.lds.S 2011-05-19 00:06:34.000000000 -0400
17986+++ linux-2.6.39.1/arch/x86/kernel/vmlinux.lds.S 2011-05-22 19:36:30.000000000 -0400
17987@@ -26,6 +26,13 @@
17988 #include <asm/page_types.h>
17989 #include <asm/cache.h>
17990 #include <asm/boot.h>
17991+#include <asm/segment.h>
17992+
17993+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
17994+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
17995+#else
17996+#define __KERNEL_TEXT_OFFSET 0
17997+#endif
17998
17999 #undef i386 /* in case the preprocessor is a 32bit one */
18000
18001@@ -34,11 +41,9 @@ OUTPUT_FORMAT(CONFIG_OUTPUT_FORMAT, CONF
18002 #ifdef CONFIG_X86_32
18003 OUTPUT_ARCH(i386)
18004 ENTRY(phys_startup_32)
18005-jiffies = jiffies_64;
18006 #else
18007 OUTPUT_ARCH(i386:x86-64)
18008 ENTRY(phys_startup_64)
18009-jiffies_64 = jiffies;
18010 #endif
18011
18012 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
18013@@ -69,31 +74,46 @@ jiffies_64 = jiffies;
18014
18015 PHDRS {
18016 text PT_LOAD FLAGS(5); /* R_E */
18017+#ifdef CONFIG_X86_32
18018+ module PT_LOAD FLAGS(5); /* R_E */
18019+#endif
18020+#ifdef CONFIG_XEN
18021+ rodata PT_LOAD FLAGS(5); /* R_E */
18022+#else
18023+ rodata PT_LOAD FLAGS(4); /* R__ */
18024+#endif
18025 data PT_LOAD FLAGS(6); /* RW_ */
18026 #ifdef CONFIG_X86_64
18027 user PT_LOAD FLAGS(5); /* R_E */
18028+#endif
18029+ init.begin PT_LOAD FLAGS(6); /* RW_ */
18030 #ifdef CONFIG_SMP
18031 percpu PT_LOAD FLAGS(6); /* RW_ */
18032 #endif
18033+ text.init PT_LOAD FLAGS(5); /* R_E */
18034+ text.exit PT_LOAD FLAGS(5); /* R_E */
18035 init PT_LOAD FLAGS(7); /* RWE */
18036-#endif
18037 note PT_NOTE FLAGS(0); /* ___ */
18038 }
18039
18040 SECTIONS
18041 {
18042 #ifdef CONFIG_X86_32
18043- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
18044- phys_startup_32 = startup_32 - LOAD_OFFSET;
18045+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
18046 #else
18047- . = __START_KERNEL;
18048- phys_startup_64 = startup_64 - LOAD_OFFSET;
18049+ . = __START_KERNEL;
18050 #endif
18051
18052 /* Text and read-only data */
18053- .text : AT(ADDR(.text) - LOAD_OFFSET) {
18054- _text = .;
18055+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
18056 /* bootstrapping code */
18057+#ifdef CONFIG_X86_32
18058+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
18059+#else
18060+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
18061+#endif
18062+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
18063+ _text = .;
18064 HEAD_TEXT
18065 #ifdef CONFIG_X86_32
18066 . = ALIGN(PAGE_SIZE);
18067@@ -109,13 +129,47 @@ SECTIONS
18068 IRQENTRY_TEXT
18069 *(.fixup)
18070 *(.gnu.warning)
18071- /* End of text section */
18072- _etext = .;
18073 } :text = 0x9090
18074
18075- NOTES :text :note
18076+ . += __KERNEL_TEXT_OFFSET;
18077+
18078+#ifdef CONFIG_X86_32
18079+ . = ALIGN(PAGE_SIZE);
18080+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
18081+
18082+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
18083+ MODULES_EXEC_VADDR = .;
18084+ BYTE(0)
18085+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
18086+ . = ALIGN(HPAGE_SIZE);
18087+ MODULES_EXEC_END = . - 1;
18088+#endif
18089+
18090+ } :module
18091+#endif
18092+
18093+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
18094+ /* End of text section */
18095+ _etext = . - __KERNEL_TEXT_OFFSET;
18096+ }
18097
18098- EXCEPTION_TABLE(16) :text = 0x9090
18099+#ifdef CONFIG_X86_32
18100+ . = ALIGN(PAGE_SIZE);
18101+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
18102+ *(.idt)
18103+ . = ALIGN(PAGE_SIZE);
18104+ *(.empty_zero_page)
18105+ *(.initial_pg_fixmap)
18106+ *(.initial_pg_pmd)
18107+ *(.initial_page_table)
18108+ *(.swapper_pg_dir)
18109+ } :rodata
18110+#endif
18111+
18112+ . = ALIGN(PAGE_SIZE);
18113+ NOTES :rodata :note
18114+
18115+ EXCEPTION_TABLE(16) :rodata
18116
18117 #if defined(CONFIG_DEBUG_RODATA)
18118 /* .text should occupy whole number of pages */
18119@@ -127,16 +181,20 @@ SECTIONS
18120
18121 /* Data */
18122 .data : AT(ADDR(.data) - LOAD_OFFSET) {
18123+
18124+#ifdef CONFIG_PAX_KERNEXEC
18125+ . = ALIGN(HPAGE_SIZE);
18126+#else
18127+ . = ALIGN(PAGE_SIZE);
18128+#endif
18129+
18130 /* Start of data section */
18131 _sdata = .;
18132
18133 /* init_task */
18134 INIT_TASK_DATA(THREAD_SIZE)
18135
18136-#ifdef CONFIG_X86_32
18137- /* 32 bit has nosave before _edata */
18138 NOSAVE_DATA
18139-#endif
18140
18141 PAGE_ALIGNED_DATA(PAGE_SIZE)
18142
18143@@ -145,6 +203,8 @@ SECTIONS
18144 DATA_DATA
18145 CONSTRUCTORS
18146
18147+ jiffies = jiffies_64;
18148+
18149 /* rarely changed data like cpu maps */
18150 READ_MOSTLY_DATA(INTERNODE_CACHE_BYTES)
18151
18152@@ -199,12 +259,6 @@ SECTIONS
18153 }
18154 vgetcpu_mode = VVIRT(.vgetcpu_mode);
18155
18156- . = ALIGN(L1_CACHE_BYTES);
18157- .jiffies : AT(VLOAD(.jiffies)) {
18158- *(.jiffies)
18159- }
18160- jiffies = VVIRT(.jiffies);
18161-
18162 .vsyscall_3 ADDR(.vsyscall_0) + 3072: AT(VLOAD(.vsyscall_3)) {
18163 *(.vsyscall_3)
18164 }
18165@@ -220,12 +274,19 @@ SECTIONS
18166 #endif /* CONFIG_X86_64 */
18167
18168 /* Init code and data - will be freed after init */
18169- . = ALIGN(PAGE_SIZE);
18170 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
18171+ BYTE(0)
18172+
18173+#ifdef CONFIG_PAX_KERNEXEC
18174+ . = ALIGN(HPAGE_SIZE);
18175+#else
18176+ . = ALIGN(PAGE_SIZE);
18177+#endif
18178+
18179 __init_begin = .; /* paired with __init_end */
18180- }
18181+ } :init.begin
18182
18183-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
18184+#ifdef CONFIG_SMP
18185 /*
18186 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
18187 * output PHDR, so the next output section - .init.text - should
18188@@ -234,12 +295,27 @@ SECTIONS
18189 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
18190 #endif
18191
18192- INIT_TEXT_SECTION(PAGE_SIZE)
18193-#ifdef CONFIG_X86_64
18194- :init
18195-#endif
18196+ . = ALIGN(PAGE_SIZE);
18197+ init_begin = .;
18198+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
18199+ VMLINUX_SYMBOL(_sinittext) = .;
18200+ INIT_TEXT
18201+ VMLINUX_SYMBOL(_einittext) = .;
18202+ . = ALIGN(PAGE_SIZE);
18203+ } :text.init
18204
18205- INIT_DATA_SECTION(16)
18206+ /*
18207+ * .exit.text is discard at runtime, not link time, to deal with
18208+ * references from .altinstructions and .eh_frame
18209+ */
18210+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
18211+ EXIT_TEXT
18212+ . = ALIGN(16);
18213+ } :text.exit
18214+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
18215+
18216+ . = ALIGN(PAGE_SIZE);
18217+ INIT_DATA_SECTION(16) :init
18218
18219 /*
18220 * Code and data for a variety of lowlevel trampolines, to be
18221@@ -306,19 +382,12 @@ SECTIONS
18222 }
18223
18224 . = ALIGN(8);
18225- /*
18226- * .exit.text is discard at runtime, not link time, to deal with
18227- * references from .altinstructions and .eh_frame
18228- */
18229- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
18230- EXIT_TEXT
18231- }
18232
18233 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
18234 EXIT_DATA
18235 }
18236
18237-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
18238+#ifndef CONFIG_SMP
18239 PERCPU(INTERNODE_CACHE_BYTES, PAGE_SIZE)
18240 #endif
18241
18242@@ -337,16 +406,10 @@ SECTIONS
18243 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
18244 __smp_locks = .;
18245 *(.smp_locks)
18246- . = ALIGN(PAGE_SIZE);
18247 __smp_locks_end = .;
18248+ . = ALIGN(PAGE_SIZE);
18249 }
18250
18251-#ifdef CONFIG_X86_64
18252- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
18253- NOSAVE_DATA
18254- }
18255-#endif
18256-
18257 /* BSS */
18258 . = ALIGN(PAGE_SIZE);
18259 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
18260@@ -362,6 +425,7 @@ SECTIONS
18261 __brk_base = .;
18262 . += 64 * 1024; /* 64k alignment slop space */
18263 *(.brk_reservation) /* areas brk users have reserved */
18264+ . = ALIGN(HPAGE_SIZE);
18265 __brk_limit = .;
18266 }
18267
18268@@ -388,13 +452,12 @@ SECTIONS
18269 * for the boot processor.
18270 */
18271 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
18272-INIT_PER_CPU(gdt_page);
18273 INIT_PER_CPU(irq_stack_union);
18274
18275 /*
18276 * Build-time check on the image size:
18277 */
18278-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
18279+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
18280 "kernel image bigger than KERNEL_IMAGE_SIZE");
18281
18282 #ifdef CONFIG_SMP
18283diff -urNp linux-2.6.39.1/arch/x86/kernel/vsyscall_64.c linux-2.6.39.1/arch/x86/kernel/vsyscall_64.c
18284--- linux-2.6.39.1/arch/x86/kernel/vsyscall_64.c 2011-05-19 00:06:34.000000000 -0400
18285+++ linux-2.6.39.1/arch/x86/kernel/vsyscall_64.c 2011-05-22 19:36:30.000000000 -0400
18286@@ -80,6 +80,7 @@ void update_vsyscall(struct timespec *wa
18287
18288 write_seqlock_irqsave(&vsyscall_gtod_data.lock, flags);
18289 /* copy vsyscall data */
18290+ strlcpy(vsyscall_gtod_data.clock.name, clock->name, sizeof vsyscall_gtod_data.clock.name);
18291 vsyscall_gtod_data.clock.vread = clock->vread;
18292 vsyscall_gtod_data.clock.cycle_last = clock->cycle_last;
18293 vsyscall_gtod_data.clock.mask = clock->mask;
18294@@ -208,7 +209,7 @@ vgetcpu(unsigned *cpu, unsigned *node, s
18295 We do this here because otherwise user space would do it on
18296 its own in a likely inferior way (no access to jiffies).
18297 If you don't like it pass NULL. */
18298- if (tcache && tcache->blob[0] == (j = __jiffies)) {
18299+ if (tcache && tcache->blob[0] == (j = jiffies)) {
18300 p = tcache->blob[1];
18301 } else if (__vgetcpu_mode == VGETCPU_RDTSCP) {
18302 /* Load per CPU data from RDTSCP */
18303diff -urNp linux-2.6.39.1/arch/x86/kernel/x8664_ksyms_64.c linux-2.6.39.1/arch/x86/kernel/x8664_ksyms_64.c
18304--- linux-2.6.39.1/arch/x86/kernel/x8664_ksyms_64.c 2011-05-19 00:06:34.000000000 -0400
18305+++ linux-2.6.39.1/arch/x86/kernel/x8664_ksyms_64.c 2011-05-22 19:36:30.000000000 -0400
18306@@ -29,8 +29,6 @@ EXPORT_SYMBOL(__put_user_8);
18307 EXPORT_SYMBOL(copy_user_generic_string);
18308 EXPORT_SYMBOL(copy_user_generic_unrolled);
18309 EXPORT_SYMBOL(__copy_user_nocache);
18310-EXPORT_SYMBOL(_copy_from_user);
18311-EXPORT_SYMBOL(_copy_to_user);
18312
18313 EXPORT_SYMBOL(copy_page);
18314 EXPORT_SYMBOL(clear_page);
18315diff -urNp linux-2.6.39.1/arch/x86/kernel/xsave.c linux-2.6.39.1/arch/x86/kernel/xsave.c
18316--- linux-2.6.39.1/arch/x86/kernel/xsave.c 2011-05-19 00:06:34.000000000 -0400
18317+++ linux-2.6.39.1/arch/x86/kernel/xsave.c 2011-05-22 19:36:30.000000000 -0400
18318@@ -130,7 +130,7 @@ int check_for_xstate(struct i387_fxsave_
18319 fx_sw_user->xstate_size > fx_sw_user->extended_size)
18320 return -EINVAL;
18321
18322- err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
18323+ err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
18324 fx_sw_user->extended_size -
18325 FP_XSTATE_MAGIC2_SIZE));
18326 if (err)
18327@@ -267,7 +267,7 @@ fx_only:
18328 * the other extended state.
18329 */
18330 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
18331- return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
18332+ return fxrstor_checking((struct i387_fxsave_struct __user *)buf);
18333 }
18334
18335 /*
18336@@ -299,7 +299,7 @@ int restore_i387_xstate(void __user *buf
18337 if (use_xsave())
18338 err = restore_user_xstate(buf);
18339 else
18340- err = fxrstor_checking((__force struct i387_fxsave_struct *)
18341+ err = fxrstor_checking((struct i387_fxsave_struct __user *)
18342 buf);
18343 if (unlikely(err)) {
18344 /*
18345diff -urNp linux-2.6.39.1/arch/x86/kvm/emulate.c linux-2.6.39.1/arch/x86/kvm/emulate.c
18346--- linux-2.6.39.1/arch/x86/kvm/emulate.c 2011-05-19 00:06:34.000000000 -0400
18347+++ linux-2.6.39.1/arch/x86/kvm/emulate.c 2011-05-22 19:36:30.000000000 -0400
18348@@ -89,7 +89,7 @@
18349 #define Src2ImmByte (2<<29)
18350 #define Src2One (3<<29)
18351 #define Src2Imm (4<<29)
18352-#define Src2Mask (7<<29)
18353+#define Src2Mask (7U<<29)
18354
18355 #define X2(x...) x, x
18356 #define X3(x...) X2(x), x
18357@@ -190,6 +190,7 @@ struct group_dual {
18358
18359 #define ____emulate_2op(_op, _src, _dst, _eflags, _x, _y, _suffix, _dsttype) \
18360 do { \
18361+ unsigned long _tmp; \
18362 __asm__ __volatile__ ( \
18363 _PRE_EFLAGS("0", "4", "2") \
18364 _op _suffix " %"_x"3,%1; " \
18365@@ -203,8 +204,6 @@ struct group_dual {
18366 /* Raw emulation: instruction has two explicit operands. */
18367 #define __emulate_2op_nobyte(_op,_src,_dst,_eflags,_wx,_wy,_lx,_ly,_qx,_qy) \
18368 do { \
18369- unsigned long _tmp; \
18370- \
18371 switch ((_dst).bytes) { \
18372 case 2: \
18373 ____emulate_2op(_op,_src,_dst,_eflags,_wx,_wy,"w",u16);\
18374@@ -220,7 +219,6 @@ struct group_dual {
18375
18376 #define __emulate_2op(_op,_src,_dst,_eflags,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
18377 do { \
18378- unsigned long _tmp; \
18379 switch ((_dst).bytes) { \
18380 case 1: \
18381 ____emulate_2op(_op,_src,_dst,_eflags,_bx,_by,"b",u8); \
18382diff -urNp linux-2.6.39.1/arch/x86/kvm/lapic.c linux-2.6.39.1/arch/x86/kvm/lapic.c
18383--- linux-2.6.39.1/arch/x86/kvm/lapic.c 2011-05-19 00:06:34.000000000 -0400
18384+++ linux-2.6.39.1/arch/x86/kvm/lapic.c 2011-05-22 19:36:30.000000000 -0400
18385@@ -53,7 +53,7 @@
18386 #define APIC_BUS_CYCLE_NS 1
18387
18388 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
18389-#define apic_debug(fmt, arg...)
18390+#define apic_debug(fmt, arg...) do {} while (0)
18391
18392 #define APIC_LVT_NUM 6
18393 /* 14 is the version for Xeon and Pentium 8.4.8*/
18394diff -urNp linux-2.6.39.1/arch/x86/kvm/mmu.c linux-2.6.39.1/arch/x86/kvm/mmu.c
18395--- linux-2.6.39.1/arch/x86/kvm/mmu.c 2011-05-19 00:06:34.000000000 -0400
18396+++ linux-2.6.39.1/arch/x86/kvm/mmu.c 2011-05-22 19:36:30.000000000 -0400
18397@@ -3240,7 +3240,7 @@ void kvm_mmu_pte_write(struct kvm_vcpu *
18398
18399 pgprintk("%s: gpa %llx bytes %d\n", __func__, gpa, bytes);
18400
18401- invlpg_counter = atomic_read(&vcpu->kvm->arch.invlpg_counter);
18402+ invlpg_counter = atomic_read_unchecked(&vcpu->kvm->arch.invlpg_counter);
18403
18404 /*
18405 * Assume that the pte write on a page table of the same type
18406@@ -3275,7 +3275,7 @@ void kvm_mmu_pte_write(struct kvm_vcpu *
18407 smp_rmb();
18408
18409 spin_lock(&vcpu->kvm->mmu_lock);
18410- if (atomic_read(&vcpu->kvm->arch.invlpg_counter) != invlpg_counter)
18411+ if (atomic_read_unchecked(&vcpu->kvm->arch.invlpg_counter) != invlpg_counter)
18412 gentry = 0;
18413 kvm_mmu_free_some_pages(vcpu);
18414 ++vcpu->kvm->stat.mmu_pte_write;
18415diff -urNp linux-2.6.39.1/arch/x86/kvm/paging_tmpl.h linux-2.6.39.1/arch/x86/kvm/paging_tmpl.h
18416--- linux-2.6.39.1/arch/x86/kvm/paging_tmpl.h 2011-05-19 00:06:34.000000000 -0400
18417+++ linux-2.6.39.1/arch/x86/kvm/paging_tmpl.h 2011-05-22 19:36:30.000000000 -0400
18418@@ -552,6 +552,8 @@ static int FNAME(page_fault)(struct kvm_
18419 unsigned long mmu_seq;
18420 bool map_writable;
18421
18422+ pax_track_stack();
18423+
18424 pgprintk("%s: addr %lx err %x\n", __func__, addr, error_code);
18425
18426 r = mmu_topup_memory_caches(vcpu);
18427@@ -672,7 +674,7 @@ static void FNAME(invlpg)(struct kvm_vcp
18428 if (need_flush)
18429 kvm_flush_remote_tlbs(vcpu->kvm);
18430
18431- atomic_inc(&vcpu->kvm->arch.invlpg_counter);
18432+ atomic_inc_unchecked(&vcpu->kvm->arch.invlpg_counter);
18433
18434 spin_unlock(&vcpu->kvm->mmu_lock);
18435
18436diff -urNp linux-2.6.39.1/arch/x86/kvm/svm.c linux-2.6.39.1/arch/x86/kvm/svm.c
18437--- linux-2.6.39.1/arch/x86/kvm/svm.c 2011-05-19 00:06:34.000000000 -0400
18438+++ linux-2.6.39.1/arch/x86/kvm/svm.c 2011-05-22 19:36:30.000000000 -0400
18439@@ -3278,7 +3278,11 @@ static void reload_tss(struct kvm_vcpu *
18440 int cpu = raw_smp_processor_id();
18441
18442 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
18443+
18444+ pax_open_kernel();
18445 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
18446+ pax_close_kernel();
18447+
18448 load_TR_desc();
18449 }
18450
18451@@ -3656,6 +3660,10 @@ static void svm_vcpu_run(struct kvm_vcpu
18452 #endif
18453 #endif
18454
18455+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
18456+ __set_fs(current_thread_info()->addr_limit);
18457+#endif
18458+
18459 reload_tss(vcpu);
18460
18461 local_irq_disable();
18462@@ -3871,7 +3879,7 @@ static void svm_fpu_deactivate(struct kv
18463 update_cr0_intercept(svm);
18464 }
18465
18466-static struct kvm_x86_ops svm_x86_ops = {
18467+static const struct kvm_x86_ops svm_x86_ops = {
18468 .cpu_has_kvm_support = has_svm,
18469 .disabled_by_bios = is_disabled,
18470 .hardware_setup = svm_hardware_setup,
18471diff -urNp linux-2.6.39.1/arch/x86/kvm/vmx.c linux-2.6.39.1/arch/x86/kvm/vmx.c
18472--- linux-2.6.39.1/arch/x86/kvm/vmx.c 2011-05-19 00:06:34.000000000 -0400
18473+++ linux-2.6.39.1/arch/x86/kvm/vmx.c 2011-05-22 19:36:30.000000000 -0400
18474@@ -725,7 +725,11 @@ static void reload_tss(void)
18475 struct desc_struct *descs;
18476
18477 descs = (void *)gdt->address;
18478+
18479+ pax_open_kernel();
18480 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
18481+ pax_close_kernel();
18482+
18483 load_TR_desc();
18484 }
18485
18486@@ -1648,8 +1652,11 @@ static __init int hardware_setup(void)
18487 if (!cpu_has_vmx_flexpriority())
18488 flexpriority_enabled = 0;
18489
18490- if (!cpu_has_vmx_tpr_shadow())
18491- kvm_x86_ops->update_cr8_intercept = NULL;
18492+ if (!cpu_has_vmx_tpr_shadow()) {
18493+ pax_open_kernel();
18494+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
18495+ pax_close_kernel();
18496+ }
18497
18498 if (enable_ept && !cpu_has_vmx_ept_2m_page())
18499 kvm_disable_largepages();
18500@@ -2693,7 +2700,7 @@ static int vmx_vcpu_setup(struct vcpu_vm
18501 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
18502
18503 asm("mov $.Lkvm_vmx_return, %0" : "=r"(kvm_vmx_return));
18504- vmcs_writel(HOST_RIP, kvm_vmx_return); /* 22.2.5 */
18505+ vmcs_writel(HOST_RIP, ktla_ktva(kvm_vmx_return)); /* 22.2.5 */
18506 vmcs_write32(VM_EXIT_MSR_STORE_COUNT, 0);
18507 vmcs_write32(VM_EXIT_MSR_LOAD_COUNT, 0);
18508 vmcs_write64(VM_EXIT_MSR_LOAD_ADDR, __pa(vmx->msr_autoload.host));
18509@@ -4068,6 +4075,12 @@ static void __noclone vmx_vcpu_run(struc
18510 "jmp .Lkvm_vmx_return \n\t"
18511 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
18512 ".Lkvm_vmx_return: "
18513+
18514+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18515+ "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
18516+ ".Lkvm_vmx_return2: "
18517+#endif
18518+
18519 /* Save guest registers, load host registers, keep flags */
18520 "mov %0, %c[wordsize](%%"R"sp) \n\t"
18521 "pop %0 \n\t"
18522@@ -4116,6 +4129,11 @@ static void __noclone vmx_vcpu_run(struc
18523 #endif
18524 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
18525 [wordsize]"i"(sizeof(ulong))
18526+
18527+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18528+ ,[cs]"i"(__KERNEL_CS)
18529+#endif
18530+
18531 : "cc", "memory"
18532 , R"ax", R"bx", R"di", R"si"
18533 #ifdef CONFIG_X86_64
18534@@ -4130,7 +4148,16 @@ static void __noclone vmx_vcpu_run(struc
18535
18536 vmx->idt_vectoring_info = vmcs_read32(IDT_VECTORING_INFO_FIELD);
18537
18538- asm("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
18539+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r"(__KERNEL_DS));
18540+
18541+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18542+ loadsegment(fs, __KERNEL_PERCPU);
18543+#endif
18544+
18545+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
18546+ __set_fs(current_thread_info()->addr_limit);
18547+#endif
18548+
18549 vmx->launched = 1;
18550
18551 vmx->exit_reason = vmcs_read32(VM_EXIT_REASON);
18552@@ -4368,7 +4395,7 @@ static void vmx_set_supported_cpuid(u32
18553 {
18554 }
18555
18556-static struct kvm_x86_ops vmx_x86_ops = {
18557+static const struct kvm_x86_ops vmx_x86_ops = {
18558 .cpu_has_kvm_support = cpu_has_kvm_support,
18559 .disabled_by_bios = vmx_disabled_by_bios,
18560 .hardware_setup = hardware_setup,
18561diff -urNp linux-2.6.39.1/arch/x86/kvm/x86.c linux-2.6.39.1/arch/x86/kvm/x86.c
18562--- linux-2.6.39.1/arch/x86/kvm/x86.c 2011-05-19 00:06:34.000000000 -0400
18563+++ linux-2.6.39.1/arch/x86/kvm/x86.c 2011-05-22 19:36:30.000000000 -0400
18564@@ -94,7 +94,7 @@ static void update_cr8_intercept(struct
18565 static int kvm_dev_ioctl_get_supported_cpuid(struct kvm_cpuid2 *cpuid,
18566 struct kvm_cpuid_entry2 __user *entries);
18567
18568-struct kvm_x86_ops *kvm_x86_ops;
18569+const struct kvm_x86_ops *kvm_x86_ops;
18570 EXPORT_SYMBOL_GPL(kvm_x86_ops);
18571
18572 int ignore_msrs = 0;
18573@@ -2050,6 +2050,8 @@ long kvm_arch_dev_ioctl(struct file *fil
18574 if (n < msr_list.nmsrs)
18575 goto out;
18576 r = -EFAULT;
18577+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
18578+ goto out;
18579 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
18580 num_msrs_to_save * sizeof(u32)))
18581 goto out;
18582@@ -2217,15 +2219,20 @@ static int kvm_vcpu_ioctl_set_cpuid2(str
18583 struct kvm_cpuid2 *cpuid,
18584 struct kvm_cpuid_entry2 __user *entries)
18585 {
18586- int r;
18587+ int r, i;
18588
18589 r = -E2BIG;
18590 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
18591 goto out;
18592 r = -EFAULT;
18593- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
18594- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
18595+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
18596 goto out;
18597+ for (i = 0; i < cpuid->nent; ++i) {
18598+ struct kvm_cpuid_entry2 cpuid_entry;
18599+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
18600+ goto out;
18601+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
18602+ }
18603 vcpu->arch.cpuid_nent = cpuid->nent;
18604 kvm_apic_set_version(vcpu);
18605 kvm_x86_ops->cpuid_update(vcpu);
18606@@ -2240,15 +2247,19 @@ static int kvm_vcpu_ioctl_get_cpuid2(str
18607 struct kvm_cpuid2 *cpuid,
18608 struct kvm_cpuid_entry2 __user *entries)
18609 {
18610- int r;
18611+ int r, i;
18612
18613 r = -E2BIG;
18614 if (cpuid->nent < vcpu->arch.cpuid_nent)
18615 goto out;
18616 r = -EFAULT;
18617- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
18618- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
18619+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
18620 goto out;
18621+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
18622+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
18623+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
18624+ goto out;
18625+ }
18626 return 0;
18627
18628 out:
18629@@ -2526,7 +2537,7 @@ static int kvm_vcpu_ioctl_set_lapic(stru
18630 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
18631 struct kvm_interrupt *irq)
18632 {
18633- if (irq->irq < 0 || irq->irq >= 256)
18634+ if (irq->irq >= 256)
18635 return -EINVAL;
18636 if (irqchip_in_kernel(vcpu->kvm))
18637 return -ENXIO;
18638@@ -4672,7 +4683,7 @@ static unsigned long kvm_get_guest_ip(vo
18639 return ip;
18640 }
18641
18642-static struct perf_guest_info_callbacks kvm_guest_cbs = {
18643+static const struct perf_guest_info_callbacks kvm_guest_cbs = {
18644 .is_in_guest = kvm_is_in_guest,
18645 .is_user_mode = kvm_is_user_mode,
18646 .get_guest_ip = kvm_get_guest_ip,
18647@@ -4690,10 +4701,10 @@ void kvm_after_handle_nmi(struct kvm_vcp
18648 }
18649 EXPORT_SYMBOL_GPL(kvm_after_handle_nmi);
18650
18651-int kvm_arch_init(void *opaque)
18652+int kvm_arch_init(const void *opaque)
18653 {
18654 int r;
18655- struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
18656+ const struct kvm_x86_ops *ops = (const struct kvm_x86_ops *)opaque;
18657
18658 if (kvm_x86_ops) {
18659 printk(KERN_ERR "kvm: already loaded the other module\n");
18660diff -urNp linux-2.6.39.1/arch/x86/lib/atomic64_32.c linux-2.6.39.1/arch/x86/lib/atomic64_32.c
18661--- linux-2.6.39.1/arch/x86/lib/atomic64_32.c 2011-05-19 00:06:34.000000000 -0400
18662+++ linux-2.6.39.1/arch/x86/lib/atomic64_32.c 2011-05-22 19:36:30.000000000 -0400
18663@@ -8,18 +8,30 @@
18664
18665 long long atomic64_read_cx8(long long, const atomic64_t *v);
18666 EXPORT_SYMBOL(atomic64_read_cx8);
18667+long long atomic64_read_unchecked_cx8(long long, const atomic64_unchecked_t *v);
18668+EXPORT_SYMBOL(atomic64_read_unchecked_cx8);
18669 long long atomic64_set_cx8(long long, const atomic64_t *v);
18670 EXPORT_SYMBOL(atomic64_set_cx8);
18671+long long atomic64_set_unchecked_cx8(long long, const atomic64_unchecked_t *v);
18672+EXPORT_SYMBOL(atomic64_set_unchecked_cx8);
18673 long long atomic64_xchg_cx8(long long, unsigned high);
18674 EXPORT_SYMBOL(atomic64_xchg_cx8);
18675 long long atomic64_add_return_cx8(long long a, atomic64_t *v);
18676 EXPORT_SYMBOL(atomic64_add_return_cx8);
18677+long long atomic64_add_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
18678+EXPORT_SYMBOL(atomic64_add_return_unchecked_cx8);
18679 long long atomic64_sub_return_cx8(long long a, atomic64_t *v);
18680 EXPORT_SYMBOL(atomic64_sub_return_cx8);
18681+long long atomic64_sub_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
18682+EXPORT_SYMBOL(atomic64_sub_return_unchecked_cx8);
18683 long long atomic64_inc_return_cx8(long long a, atomic64_t *v);
18684 EXPORT_SYMBOL(atomic64_inc_return_cx8);
18685+long long atomic64_inc_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
18686+EXPORT_SYMBOL(atomic64_inc_return_unchecked_cx8);
18687 long long atomic64_dec_return_cx8(long long a, atomic64_t *v);
18688 EXPORT_SYMBOL(atomic64_dec_return_cx8);
18689+long long atomic64_dec_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
18690+EXPORT_SYMBOL(atomic64_dec_return_unchecked_cx8);
18691 long long atomic64_dec_if_positive_cx8(atomic64_t *v);
18692 EXPORT_SYMBOL(atomic64_dec_if_positive_cx8);
18693 int atomic64_inc_not_zero_cx8(atomic64_t *v);
18694@@ -30,26 +42,46 @@ EXPORT_SYMBOL(atomic64_add_unless_cx8);
18695 #ifndef CONFIG_X86_CMPXCHG64
18696 long long atomic64_read_386(long long, const atomic64_t *v);
18697 EXPORT_SYMBOL(atomic64_read_386);
18698+long long atomic64_read_unchecked_386(long long, const atomic64_unchecked_t *v);
18699+EXPORT_SYMBOL(atomic64_read_unchecked_386);
18700 long long atomic64_set_386(long long, const atomic64_t *v);
18701 EXPORT_SYMBOL(atomic64_set_386);
18702+long long atomic64_set_unchecked_386(long long, const atomic64_unchecked_t *v);
18703+EXPORT_SYMBOL(atomic64_set_unchecked_386);
18704 long long atomic64_xchg_386(long long, unsigned high);
18705 EXPORT_SYMBOL(atomic64_xchg_386);
18706 long long atomic64_add_return_386(long long a, atomic64_t *v);
18707 EXPORT_SYMBOL(atomic64_add_return_386);
18708+long long atomic64_add_return_unchecked_386(long long a, atomic64_unchecked_t *v);
18709+EXPORT_SYMBOL(atomic64_add_return_unchecked_386);
18710 long long atomic64_sub_return_386(long long a, atomic64_t *v);
18711 EXPORT_SYMBOL(atomic64_sub_return_386);
18712+long long atomic64_sub_return_unchecked_386(long long a, atomic64_unchecked_t *v);
18713+EXPORT_SYMBOL(atomic64_sub_return_unchecked_386);
18714 long long atomic64_inc_return_386(long long a, atomic64_t *v);
18715 EXPORT_SYMBOL(atomic64_inc_return_386);
18716+long long atomic64_inc_return_unchecked_386(long long a, atomic64_unchecked_t *v);
18717+EXPORT_SYMBOL(atomic64_inc_return_unchecked_386);
18718 long long atomic64_dec_return_386(long long a, atomic64_t *v);
18719 EXPORT_SYMBOL(atomic64_dec_return_386);
18720+long long atomic64_dec_return_unchecked_386(long long a, atomic64_unchecked_t *v);
18721+EXPORT_SYMBOL(atomic64_dec_return_unchecked_386);
18722 long long atomic64_add_386(long long a, atomic64_t *v);
18723 EXPORT_SYMBOL(atomic64_add_386);
18724+long long atomic64_add_unchecked_386(long long a, atomic64_unchecked_t *v);
18725+EXPORT_SYMBOL(atomic64_add_unchecked_386);
18726 long long atomic64_sub_386(long long a, atomic64_t *v);
18727 EXPORT_SYMBOL(atomic64_sub_386);
18728+long long atomic64_sub_unchecked_386(long long a, atomic64_unchecked_t *v);
18729+EXPORT_SYMBOL(atomic64_sub_unchecked_386);
18730 long long atomic64_inc_386(long long a, atomic64_t *v);
18731 EXPORT_SYMBOL(atomic64_inc_386);
18732+long long atomic64_inc_unchecked_386(long long a, atomic64_unchecked_t *v);
18733+EXPORT_SYMBOL(atomic64_inc_unchecked_386);
18734 long long atomic64_dec_386(long long a, atomic64_t *v);
18735 EXPORT_SYMBOL(atomic64_dec_386);
18736+long long atomic64_dec_unchecked_386(long long a, atomic64_unchecked_t *v);
18737+EXPORT_SYMBOL(atomic64_dec_unchecked_386);
18738 long long atomic64_dec_if_positive_386(atomic64_t *v);
18739 EXPORT_SYMBOL(atomic64_dec_if_positive_386);
18740 int atomic64_inc_not_zero_386(atomic64_t *v);
18741diff -urNp linux-2.6.39.1/arch/x86/lib/atomic64_386_32.S linux-2.6.39.1/arch/x86/lib/atomic64_386_32.S
18742--- linux-2.6.39.1/arch/x86/lib/atomic64_386_32.S 2011-05-19 00:06:34.000000000 -0400
18743+++ linux-2.6.39.1/arch/x86/lib/atomic64_386_32.S 2011-05-22 19:36:30.000000000 -0400
18744@@ -48,6 +48,10 @@ BEGIN(read)
18745 movl (v), %eax
18746 movl 4(v), %edx
18747 RET_ENDP
18748+BEGIN(read_unchecked)
18749+ movl (v), %eax
18750+ movl 4(v), %edx
18751+RET_ENDP
18752 #undef v
18753
18754 #define v %esi
18755@@ -55,6 +59,10 @@ BEGIN(set)
18756 movl %ebx, (v)
18757 movl %ecx, 4(v)
18758 RET_ENDP
18759+BEGIN(set_unchecked)
18760+ movl %ebx, (v)
18761+ movl %ecx, 4(v)
18762+RET_ENDP
18763 #undef v
18764
18765 #define v %esi
18766@@ -70,6 +78,20 @@ RET_ENDP
18767 BEGIN(add)
18768 addl %eax, (v)
18769 adcl %edx, 4(v)
18770+
18771+#ifdef CONFIG_PAX_REFCOUNT
18772+ jno 0f
18773+ subl %eax, (v)
18774+ sbbl %edx, 4(v)
18775+ int $4
18776+0:
18777+ _ASM_EXTABLE(0b, 0b)
18778+#endif
18779+
18780+RET_ENDP
18781+BEGIN(add_unchecked)
18782+ addl %eax, (v)
18783+ adcl %edx, 4(v)
18784 RET_ENDP
18785 #undef v
18786
18787@@ -77,6 +99,24 @@ RET_ENDP
18788 BEGIN(add_return)
18789 addl (v), %eax
18790 adcl 4(v), %edx
18791+
18792+#ifdef CONFIG_PAX_REFCOUNT
18793+ into
18794+1234:
18795+ _ASM_EXTABLE(1234b, 2f)
18796+#endif
18797+
18798+ movl %eax, (v)
18799+ movl %edx, 4(v)
18800+
18801+#ifdef CONFIG_PAX_REFCOUNT
18802+2:
18803+#endif
18804+
18805+RET_ENDP
18806+BEGIN(add_return_unchecked)
18807+ addl (v), %eax
18808+ adcl 4(v), %edx
18809 movl %eax, (v)
18810 movl %edx, 4(v)
18811 RET_ENDP
18812@@ -86,6 +126,20 @@ RET_ENDP
18813 BEGIN(sub)
18814 subl %eax, (v)
18815 sbbl %edx, 4(v)
18816+
18817+#ifdef CONFIG_PAX_REFCOUNT
18818+ jno 0f
18819+ addl %eax, (v)
18820+ adcl %edx, 4(v)
18821+ int $4
18822+0:
18823+ _ASM_EXTABLE(0b, 0b)
18824+#endif
18825+
18826+RET_ENDP
18827+BEGIN(sub_unchecked)
18828+ subl %eax, (v)
18829+ sbbl %edx, 4(v)
18830 RET_ENDP
18831 #undef v
18832
18833@@ -96,6 +150,27 @@ BEGIN(sub_return)
18834 sbbl $0, %edx
18835 addl (v), %eax
18836 adcl 4(v), %edx
18837+
18838+#ifdef CONFIG_PAX_REFCOUNT
18839+ into
18840+1234:
18841+ _ASM_EXTABLE(1234b, 2f)
18842+#endif
18843+
18844+ movl %eax, (v)
18845+ movl %edx, 4(v)
18846+
18847+#ifdef CONFIG_PAX_REFCOUNT
18848+2:
18849+#endif
18850+
18851+RET_ENDP
18852+BEGIN(sub_return_unchecked)
18853+ negl %edx
18854+ negl %eax
18855+ sbbl $0, %edx
18856+ addl (v), %eax
18857+ adcl 4(v), %edx
18858 movl %eax, (v)
18859 movl %edx, 4(v)
18860 RET_ENDP
18861@@ -105,6 +180,20 @@ RET_ENDP
18862 BEGIN(inc)
18863 addl $1, (v)
18864 adcl $0, 4(v)
18865+
18866+#ifdef CONFIG_PAX_REFCOUNT
18867+ jno 0f
18868+ subl $1, (v)
18869+ sbbl $0, 4(v)
18870+ int $4
18871+0:
18872+ _ASM_EXTABLE(0b, 0b)
18873+#endif
18874+
18875+RET_ENDP
18876+BEGIN(inc_unchecked)
18877+ addl $1, (v)
18878+ adcl $0, 4(v)
18879 RET_ENDP
18880 #undef v
18881
18882@@ -114,6 +203,26 @@ BEGIN(inc_return)
18883 movl 4(v), %edx
18884 addl $1, %eax
18885 adcl $0, %edx
18886+
18887+#ifdef CONFIG_PAX_REFCOUNT
18888+ into
18889+1234:
18890+ _ASM_EXTABLE(1234b, 2f)
18891+#endif
18892+
18893+ movl %eax, (v)
18894+ movl %edx, 4(v)
18895+
18896+#ifdef CONFIG_PAX_REFCOUNT
18897+2:
18898+#endif
18899+
18900+RET_ENDP
18901+BEGIN(inc_return_unchecked)
18902+ movl (v), %eax
18903+ movl 4(v), %edx
18904+ addl $1, %eax
18905+ adcl $0, %edx
18906 movl %eax, (v)
18907 movl %edx, 4(v)
18908 RET_ENDP
18909@@ -123,6 +232,20 @@ RET_ENDP
18910 BEGIN(dec)
18911 subl $1, (v)
18912 sbbl $0, 4(v)
18913+
18914+#ifdef CONFIG_PAX_REFCOUNT
18915+ jno 0f
18916+ addl $1, (v)
18917+ adcl $0, 4(v)
18918+ int $4
18919+0:
18920+ _ASM_EXTABLE(0b, 0b)
18921+#endif
18922+
18923+RET_ENDP
18924+BEGIN(dec_unchecked)
18925+ subl $1, (v)
18926+ sbbl $0, 4(v)
18927 RET_ENDP
18928 #undef v
18929
18930@@ -132,6 +255,26 @@ BEGIN(dec_return)
18931 movl 4(v), %edx
18932 subl $1, %eax
18933 sbbl $0, %edx
18934+
18935+#ifdef CONFIG_PAX_REFCOUNT
18936+ into
18937+1234:
18938+ _ASM_EXTABLE(1234b, 2f)
18939+#endif
18940+
18941+ movl %eax, (v)
18942+ movl %edx, 4(v)
18943+
18944+#ifdef CONFIG_PAX_REFCOUNT
18945+2:
18946+#endif
18947+
18948+RET_ENDP
18949+BEGIN(dec_return_unchecked)
18950+ movl (v), %eax
18951+ movl 4(v), %edx
18952+ subl $1, %eax
18953+ sbbl $0, %edx
18954 movl %eax, (v)
18955 movl %edx, 4(v)
18956 RET_ENDP
18957@@ -143,6 +286,13 @@ BEGIN(add_unless)
18958 adcl %edx, %edi
18959 addl (v), %eax
18960 adcl 4(v), %edx
18961+
18962+#ifdef CONFIG_PAX_REFCOUNT
18963+ into
18964+1234:
18965+ _ASM_EXTABLE(1234b, 2f)
18966+#endif
18967+
18968 cmpl %eax, %esi
18969 je 3f
18970 1:
18971@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
18972 1:
18973 addl $1, %eax
18974 adcl $0, %edx
18975+
18976+#ifdef CONFIG_PAX_REFCOUNT
18977+ into
18978+1234:
18979+ _ASM_EXTABLE(1234b, 2f)
18980+#endif
18981+
18982 movl %eax, (v)
18983 movl %edx, 4(v)
18984 movl $1, %eax
18985@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
18986 movl 4(v), %edx
18987 subl $1, %eax
18988 sbbl $0, %edx
18989+
18990+#ifdef CONFIG_PAX_REFCOUNT
18991+ into
18992+1234:
18993+ _ASM_EXTABLE(1234b, 1f)
18994+#endif
18995+
18996 js 1f
18997 movl %eax, (v)
18998 movl %edx, 4(v)
18999diff -urNp linux-2.6.39.1/arch/x86/lib/atomic64_cx8_32.S linux-2.6.39.1/arch/x86/lib/atomic64_cx8_32.S
19000--- linux-2.6.39.1/arch/x86/lib/atomic64_cx8_32.S 2011-05-19 00:06:34.000000000 -0400
19001+++ linux-2.6.39.1/arch/x86/lib/atomic64_cx8_32.S 2011-05-22 19:36:30.000000000 -0400
19002@@ -39,6 +39,14 @@ ENTRY(atomic64_read_cx8)
19003 CFI_ENDPROC
19004 ENDPROC(atomic64_read_cx8)
19005
19006+ENTRY(atomic64_read_unchecked_cx8)
19007+ CFI_STARTPROC
19008+
19009+ read64 %ecx
19010+ ret
19011+ CFI_ENDPROC
19012+ENDPROC(atomic64_read_unchecked_cx8)
19013+
19014 ENTRY(atomic64_set_cx8)
19015 CFI_STARTPROC
19016
19017@@ -52,6 +60,19 @@ ENTRY(atomic64_set_cx8)
19018 CFI_ENDPROC
19019 ENDPROC(atomic64_set_cx8)
19020
19021+ENTRY(atomic64_set_unchecked_cx8)
19022+ CFI_STARTPROC
19023+
19024+1:
19025+/* we don't need LOCK_PREFIX since aligned 64-bit writes
19026+ * are atomic on 586 and newer */
19027+ cmpxchg8b (%esi)
19028+ jne 1b
19029+
19030+ ret
19031+ CFI_ENDPROC
19032+ENDPROC(atomic64_set_unchecked_cx8)
19033+
19034 ENTRY(atomic64_xchg_cx8)
19035 CFI_STARTPROC
19036
19037@@ -66,8 +87,8 @@ ENTRY(atomic64_xchg_cx8)
19038 CFI_ENDPROC
19039 ENDPROC(atomic64_xchg_cx8)
19040
19041-.macro addsub_return func ins insc
19042-ENTRY(atomic64_\func\()_return_cx8)
19043+.macro addsub_return func ins insc unchecked=""
19044+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
19045 CFI_STARTPROC
19046 SAVE ebp
19047 SAVE ebx
19048@@ -84,27 +105,43 @@ ENTRY(atomic64_\func\()_return_cx8)
19049 movl %edx, %ecx
19050 \ins\()l %esi, %ebx
19051 \insc\()l %edi, %ecx
19052+
19053+.ifb \unchecked
19054+#ifdef CONFIG_PAX_REFCOUNT
19055+ into
19056+2:
19057+ _ASM_EXTABLE(2b, 3f)
19058+#endif
19059+.endif
19060+
19061 LOCK_PREFIX
19062 cmpxchg8b (%ebp)
19063 jne 1b
19064-
19065-10:
19066 movl %ebx, %eax
19067 movl %ecx, %edx
19068+
19069+.ifb \unchecked
19070+#ifdef CONFIG_PAX_REFCOUNT
19071+3:
19072+#endif
19073+.endif
19074+
19075 RESTORE edi
19076 RESTORE esi
19077 RESTORE ebx
19078 RESTORE ebp
19079 ret
19080 CFI_ENDPROC
19081-ENDPROC(atomic64_\func\()_return_cx8)
19082+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
19083 .endm
19084
19085 addsub_return add add adc
19086 addsub_return sub sub sbb
19087+addsub_return add add adc _unchecked
19088+addsub_return sub sub sbb _unchecked
19089
19090-.macro incdec_return func ins insc
19091-ENTRY(atomic64_\func\()_return_cx8)
19092+.macro incdec_return func ins insc unchecked
19093+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
19094 CFI_STARTPROC
19095 SAVE ebx
19096
19097@@ -114,21 +151,38 @@ ENTRY(atomic64_\func\()_return_cx8)
19098 movl %edx, %ecx
19099 \ins\()l $1, %ebx
19100 \insc\()l $0, %ecx
19101+
19102+.ifb \unchecked
19103+#ifdef CONFIG_PAX_REFCOUNT
19104+ into
19105+2:
19106+ _ASM_EXTABLE(2b, 3f)
19107+#endif
19108+.endif
19109+
19110 LOCK_PREFIX
19111 cmpxchg8b (%esi)
19112 jne 1b
19113
19114-10:
19115 movl %ebx, %eax
19116 movl %ecx, %edx
19117+
19118+.ifb \unchecked
19119+#ifdef CONFIG_PAX_REFCOUNT
19120+3:
19121+#endif
19122+.endif
19123+
19124 RESTORE ebx
19125 ret
19126 CFI_ENDPROC
19127-ENDPROC(atomic64_\func\()_return_cx8)
19128+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
19129 .endm
19130
19131 incdec_return inc add adc
19132 incdec_return dec sub sbb
19133+incdec_return inc add adc _unchecked
19134+incdec_return dec sub sbb _unchecked
19135
19136 ENTRY(atomic64_dec_if_positive_cx8)
19137 CFI_STARTPROC
19138@@ -140,6 +194,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
19139 movl %edx, %ecx
19140 subl $1, %ebx
19141 sbb $0, %ecx
19142+
19143+#ifdef CONFIG_PAX_REFCOUNT
19144+ into
19145+1234:
19146+ _ASM_EXTABLE(1234b, 2f)
19147+#endif
19148+
19149 js 2f
19150 LOCK_PREFIX
19151 cmpxchg8b (%esi)
19152@@ -174,6 +235,13 @@ ENTRY(atomic64_add_unless_cx8)
19153 movl %edx, %ecx
19154 addl %esi, %ebx
19155 adcl %edi, %ecx
19156+
19157+#ifdef CONFIG_PAX_REFCOUNT
19158+ into
19159+1234:
19160+ _ASM_EXTABLE(1234b, 3f)
19161+#endif
19162+
19163 LOCK_PREFIX
19164 cmpxchg8b (%ebp)
19165 jne 1b
19166@@ -206,6 +274,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
19167 movl %edx, %ecx
19168 addl $1, %ebx
19169 adcl $0, %ecx
19170+
19171+#ifdef CONFIG_PAX_REFCOUNT
19172+ into
19173+1234:
19174+ _ASM_EXTABLE(1234b, 3f)
19175+#endif
19176+
19177 LOCK_PREFIX
19178 cmpxchg8b (%esi)
19179 jne 1b
19180diff -urNp linux-2.6.39.1/arch/x86/lib/checksum_32.S linux-2.6.39.1/arch/x86/lib/checksum_32.S
19181--- linux-2.6.39.1/arch/x86/lib/checksum_32.S 2011-05-19 00:06:34.000000000 -0400
19182+++ linux-2.6.39.1/arch/x86/lib/checksum_32.S 2011-05-22 19:36:30.000000000 -0400
19183@@ -28,7 +28,8 @@
19184 #include <linux/linkage.h>
19185 #include <asm/dwarf2.h>
19186 #include <asm/errno.h>
19187-
19188+#include <asm/segment.h>
19189+
19190 /*
19191 * computes a partial checksum, e.g. for TCP/UDP fragments
19192 */
19193@@ -296,9 +297,24 @@ unsigned int csum_partial_copy_generic (
19194
19195 #define ARGBASE 16
19196 #define FP 12
19197-
19198-ENTRY(csum_partial_copy_generic)
19199+
19200+ENTRY(csum_partial_copy_generic_to_user)
19201 CFI_STARTPROC
19202+
19203+#ifdef CONFIG_PAX_MEMORY_UDEREF
19204+ pushl_cfi %gs
19205+ popl_cfi %es
19206+ jmp csum_partial_copy_generic
19207+#endif
19208+
19209+ENTRY(csum_partial_copy_generic_from_user)
19210+
19211+#ifdef CONFIG_PAX_MEMORY_UDEREF
19212+ pushl_cfi %gs
19213+ popl_cfi %ds
19214+#endif
19215+
19216+ENTRY(csum_partial_copy_generic)
19217 subl $4,%esp
19218 CFI_ADJUST_CFA_OFFSET 4
19219 pushl_cfi %edi
19220@@ -320,7 +336,7 @@ ENTRY(csum_partial_copy_generic)
19221 jmp 4f
19222 SRC(1: movw (%esi), %bx )
19223 addl $2, %esi
19224-DST( movw %bx, (%edi) )
19225+DST( movw %bx, %es:(%edi) )
19226 addl $2, %edi
19227 addw %bx, %ax
19228 adcl $0, %eax
19229@@ -332,30 +348,30 @@ DST( movw %bx, (%edi) )
19230 SRC(1: movl (%esi), %ebx )
19231 SRC( movl 4(%esi), %edx )
19232 adcl %ebx, %eax
19233-DST( movl %ebx, (%edi) )
19234+DST( movl %ebx, %es:(%edi) )
19235 adcl %edx, %eax
19236-DST( movl %edx, 4(%edi) )
19237+DST( movl %edx, %es:4(%edi) )
19238
19239 SRC( movl 8(%esi), %ebx )
19240 SRC( movl 12(%esi), %edx )
19241 adcl %ebx, %eax
19242-DST( movl %ebx, 8(%edi) )
19243+DST( movl %ebx, %es:8(%edi) )
19244 adcl %edx, %eax
19245-DST( movl %edx, 12(%edi) )
19246+DST( movl %edx, %es:12(%edi) )
19247
19248 SRC( movl 16(%esi), %ebx )
19249 SRC( movl 20(%esi), %edx )
19250 adcl %ebx, %eax
19251-DST( movl %ebx, 16(%edi) )
19252+DST( movl %ebx, %es:16(%edi) )
19253 adcl %edx, %eax
19254-DST( movl %edx, 20(%edi) )
19255+DST( movl %edx, %es:20(%edi) )
19256
19257 SRC( movl 24(%esi), %ebx )
19258 SRC( movl 28(%esi), %edx )
19259 adcl %ebx, %eax
19260-DST( movl %ebx, 24(%edi) )
19261+DST( movl %ebx, %es:24(%edi) )
19262 adcl %edx, %eax
19263-DST( movl %edx, 28(%edi) )
19264+DST( movl %edx, %es:28(%edi) )
19265
19266 lea 32(%esi), %esi
19267 lea 32(%edi), %edi
19268@@ -369,7 +385,7 @@ DST( movl %edx, 28(%edi) )
19269 shrl $2, %edx # This clears CF
19270 SRC(3: movl (%esi), %ebx )
19271 adcl %ebx, %eax
19272-DST( movl %ebx, (%edi) )
19273+DST( movl %ebx, %es:(%edi) )
19274 lea 4(%esi), %esi
19275 lea 4(%edi), %edi
19276 dec %edx
19277@@ -381,12 +397,12 @@ DST( movl %ebx, (%edi) )
19278 jb 5f
19279 SRC( movw (%esi), %cx )
19280 leal 2(%esi), %esi
19281-DST( movw %cx, (%edi) )
19282+DST( movw %cx, %es:(%edi) )
19283 leal 2(%edi), %edi
19284 je 6f
19285 shll $16,%ecx
19286 SRC(5: movb (%esi), %cl )
19287-DST( movb %cl, (%edi) )
19288+DST( movb %cl, %es:(%edi) )
19289 6: addl %ecx, %eax
19290 adcl $0, %eax
19291 7:
19292@@ -397,7 +413,7 @@ DST( movb %cl, (%edi) )
19293
19294 6001:
19295 movl ARGBASE+20(%esp), %ebx # src_err_ptr
19296- movl $-EFAULT, (%ebx)
19297+ movl $-EFAULT, %ss:(%ebx)
19298
19299 # zero the complete destination - computing the rest
19300 # is too much work
19301@@ -410,11 +426,15 @@ DST( movb %cl, (%edi) )
19302
19303 6002:
19304 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
19305- movl $-EFAULT,(%ebx)
19306+ movl $-EFAULT,%ss:(%ebx)
19307 jmp 5000b
19308
19309 .previous
19310
19311+ pushl_cfi %ss
19312+ popl_cfi %ds
19313+ pushl_cfi %ss
19314+ popl_cfi %es
19315 popl_cfi %ebx
19316 CFI_RESTORE ebx
19317 popl_cfi %esi
19318@@ -424,26 +444,43 @@ DST( movb %cl, (%edi) )
19319 popl_cfi %ecx # equivalent to addl $4,%esp
19320 ret
19321 CFI_ENDPROC
19322-ENDPROC(csum_partial_copy_generic)
19323+ENDPROC(csum_partial_copy_generic_to_user)
19324
19325 #else
19326
19327 /* Version for PentiumII/PPro */
19328
19329 #define ROUND1(x) \
19330+ nop; nop; nop; \
19331 SRC(movl x(%esi), %ebx ) ; \
19332 addl %ebx, %eax ; \
19333- DST(movl %ebx, x(%edi) ) ;
19334+ DST(movl %ebx, %es:x(%edi)) ;
19335
19336 #define ROUND(x) \
19337+ nop; nop; nop; \
19338 SRC(movl x(%esi), %ebx ) ; \
19339 adcl %ebx, %eax ; \
19340- DST(movl %ebx, x(%edi) ) ;
19341+ DST(movl %ebx, %es:x(%edi)) ;
19342
19343 #define ARGBASE 12
19344-
19345-ENTRY(csum_partial_copy_generic)
19346+
19347+ENTRY(csum_partial_copy_generic_to_user)
19348 CFI_STARTPROC
19349+
19350+#ifdef CONFIG_PAX_MEMORY_UDEREF
19351+ pushl_cfi %gs
19352+ popl_cfi %es
19353+ jmp csum_partial_copy_generic
19354+#endif
19355+
19356+ENTRY(csum_partial_copy_generic_from_user)
19357+
19358+#ifdef CONFIG_PAX_MEMORY_UDEREF
19359+ pushl_cfi %gs
19360+ popl_cfi %ds
19361+#endif
19362+
19363+ENTRY(csum_partial_copy_generic)
19364 pushl_cfi %ebx
19365 CFI_REL_OFFSET ebx, 0
19366 pushl_cfi %edi
19367@@ -464,7 +501,7 @@ ENTRY(csum_partial_copy_generic)
19368 subl %ebx, %edi
19369 lea -1(%esi),%edx
19370 andl $-32,%edx
19371- lea 3f(%ebx,%ebx), %ebx
19372+ lea 3f(%ebx,%ebx,2), %ebx
19373 testl %esi, %esi
19374 jmp *%ebx
19375 1: addl $64,%esi
19376@@ -485,19 +522,19 @@ ENTRY(csum_partial_copy_generic)
19377 jb 5f
19378 SRC( movw (%esi), %dx )
19379 leal 2(%esi), %esi
19380-DST( movw %dx, (%edi) )
19381+DST( movw %dx, %es:(%edi) )
19382 leal 2(%edi), %edi
19383 je 6f
19384 shll $16,%edx
19385 5:
19386 SRC( movb (%esi), %dl )
19387-DST( movb %dl, (%edi) )
19388+DST( movb %dl, %es:(%edi) )
19389 6: addl %edx, %eax
19390 adcl $0, %eax
19391 7:
19392 .section .fixup, "ax"
19393 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
19394- movl $-EFAULT, (%ebx)
19395+ movl $-EFAULT, %ss:(%ebx)
19396 # zero the complete destination (computing the rest is too much work)
19397 movl ARGBASE+8(%esp),%edi # dst
19398 movl ARGBASE+12(%esp),%ecx # len
19399@@ -505,10 +542,17 @@ DST( movb %dl, (%edi) )
19400 rep; stosb
19401 jmp 7b
19402 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
19403- movl $-EFAULT, (%ebx)
19404+ movl $-EFAULT, %ss:(%ebx)
19405 jmp 7b
19406 .previous
19407
19408+#ifdef CONFIG_PAX_MEMORY_UDEREF
19409+ pushl_cfi %ss
19410+ popl_cfi %ds
19411+ pushl_cfi %ss
19412+ popl_cfi %es
19413+#endif
19414+
19415 popl_cfi %esi
19416 CFI_RESTORE esi
19417 popl_cfi %edi
19418@@ -517,7 +561,7 @@ DST( movb %dl, (%edi) )
19419 CFI_RESTORE ebx
19420 ret
19421 CFI_ENDPROC
19422-ENDPROC(csum_partial_copy_generic)
19423+ENDPROC(csum_partial_copy_generic_to_user)
19424
19425 #undef ROUND
19426 #undef ROUND1
19427diff -urNp linux-2.6.39.1/arch/x86/lib/clear_page_64.S linux-2.6.39.1/arch/x86/lib/clear_page_64.S
19428--- linux-2.6.39.1/arch/x86/lib/clear_page_64.S 2011-05-19 00:06:34.000000000 -0400
19429+++ linux-2.6.39.1/arch/x86/lib/clear_page_64.S 2011-05-22 19:36:30.000000000 -0400
19430@@ -43,7 +43,7 @@ ENDPROC(clear_page)
19431
19432 #include <asm/cpufeature.h>
19433
19434- .section .altinstr_replacement,"ax"
19435+ .section .altinstr_replacement,"a"
19436 1: .byte 0xeb /* jmp <disp8> */
19437 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
19438 2:
19439diff -urNp linux-2.6.39.1/arch/x86/lib/copy_page_64.S linux-2.6.39.1/arch/x86/lib/copy_page_64.S
19440--- linux-2.6.39.1/arch/x86/lib/copy_page_64.S 2011-05-19 00:06:34.000000000 -0400
19441+++ linux-2.6.39.1/arch/x86/lib/copy_page_64.S 2011-05-22 19:36:30.000000000 -0400
19442@@ -104,7 +104,7 @@ ENDPROC(copy_page)
19443
19444 #include <asm/cpufeature.h>
19445
19446- .section .altinstr_replacement,"ax"
19447+ .section .altinstr_replacement,"a"
19448 1: .byte 0xeb /* jmp <disp8> */
19449 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
19450 2:
19451diff -urNp linux-2.6.39.1/arch/x86/lib/copy_user_64.S linux-2.6.39.1/arch/x86/lib/copy_user_64.S
19452--- linux-2.6.39.1/arch/x86/lib/copy_user_64.S 2011-06-03 00:04:13.000000000 -0400
19453+++ linux-2.6.39.1/arch/x86/lib/copy_user_64.S 2011-06-03 00:32:05.000000000 -0400
19454@@ -15,13 +15,14 @@
19455 #include <asm/asm-offsets.h>
19456 #include <asm/thread_info.h>
19457 #include <asm/cpufeature.h>
19458+#include <asm/pgtable.h>
19459
19460 .macro ALTERNATIVE_JUMP feature,orig,alt
19461 0:
19462 .byte 0xe9 /* 32bit jump */
19463 .long \orig-1f /* by default jump to orig */
19464 1:
19465- .section .altinstr_replacement,"ax"
19466+ .section .altinstr_replacement,"a"
19467 2: .byte 0xe9 /* near jump with 32bit immediate */
19468 .long \alt-1b /* offset */ /* or alternatively to alt */
19469 .previous
19470@@ -64,37 +65,13 @@
19471 #endif
19472 .endm
19473
19474-/* Standard copy_to_user with segment limit checking */
19475-ENTRY(_copy_to_user)
19476- CFI_STARTPROC
19477- GET_THREAD_INFO(%rax)
19478- movq %rdi,%rcx
19479- addq %rdx,%rcx
19480- jc bad_to_user
19481- cmpq TI_addr_limit(%rax),%rcx
19482- ja bad_to_user
19483- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,copy_user_generic_unrolled,copy_user_generic_string
19484- CFI_ENDPROC
19485-ENDPROC(_copy_to_user)
19486-
19487-/* Standard copy_from_user with segment limit checking */
19488-ENTRY(_copy_from_user)
19489- CFI_STARTPROC
19490- GET_THREAD_INFO(%rax)
19491- movq %rsi,%rcx
19492- addq %rdx,%rcx
19493- jc bad_from_user
19494- cmpq TI_addr_limit(%rax),%rcx
19495- ja bad_from_user
19496- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,copy_user_generic_unrolled,copy_user_generic_string
19497- CFI_ENDPROC
19498-ENDPROC(_copy_from_user)
19499-
19500 .section .fixup,"ax"
19501 /* must zero dest */
19502 ENTRY(bad_from_user)
19503 bad_from_user:
19504 CFI_STARTPROC
19505+ testl %edx,%edx
19506+ js bad_to_user
19507 movl %edx,%ecx
19508 xorl %eax,%eax
19509 rep
19510diff -urNp linux-2.6.39.1/arch/x86/lib/copy_user_nocache_64.S linux-2.6.39.1/arch/x86/lib/copy_user_nocache_64.S
19511--- linux-2.6.39.1/arch/x86/lib/copy_user_nocache_64.S 2011-05-19 00:06:34.000000000 -0400
19512+++ linux-2.6.39.1/arch/x86/lib/copy_user_nocache_64.S 2011-05-22 19:36:30.000000000 -0400
19513@@ -14,6 +14,7 @@
19514 #include <asm/current.h>
19515 #include <asm/asm-offsets.h>
19516 #include <asm/thread_info.h>
19517+#include <asm/pgtable.h>
19518
19519 .macro ALIGN_DESTINATION
19520 #ifdef FIX_ALIGNMENT
19521@@ -50,6 +51,15 @@
19522 */
19523 ENTRY(__copy_user_nocache)
19524 CFI_STARTPROC
19525+
19526+#ifdef CONFIG_PAX_MEMORY_UDEREF
19527+ mov $PAX_USER_SHADOW_BASE,%rcx
19528+ cmp %rcx,%rsi
19529+ jae 1f
19530+ add %rcx,%rsi
19531+1:
19532+#endif
19533+
19534 cmpl $8,%edx
19535 jb 20f /* less then 8 bytes, go to byte copy loop */
19536 ALIGN_DESTINATION
19537diff -urNp linux-2.6.39.1/arch/x86/lib/csum-wrappers_64.c linux-2.6.39.1/arch/x86/lib/csum-wrappers_64.c
19538--- linux-2.6.39.1/arch/x86/lib/csum-wrappers_64.c 2011-05-19 00:06:34.000000000 -0400
19539+++ linux-2.6.39.1/arch/x86/lib/csum-wrappers_64.c 2011-05-22 19:36:30.000000000 -0400
19540@@ -52,6 +52,12 @@ csum_partial_copy_from_user(const void _
19541 len -= 2;
19542 }
19543 }
19544+
19545+#ifdef CONFIG_PAX_MEMORY_UDEREF
19546+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
19547+ src += PAX_USER_SHADOW_BASE;
19548+#endif
19549+
19550 isum = csum_partial_copy_generic((__force const void *)src,
19551 dst, len, isum, errp, NULL);
19552 if (unlikely(*errp))
19553@@ -105,6 +111,12 @@ csum_partial_copy_to_user(const void *sr
19554 }
19555
19556 *errp = 0;
19557+
19558+#ifdef CONFIG_PAX_MEMORY_UDEREF
19559+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
19560+ dst += PAX_USER_SHADOW_BASE;
19561+#endif
19562+
19563 return csum_partial_copy_generic(src, (void __force *)dst,
19564 len, isum, NULL, errp);
19565 }
19566diff -urNp linux-2.6.39.1/arch/x86/lib/getuser.S linux-2.6.39.1/arch/x86/lib/getuser.S
19567--- linux-2.6.39.1/arch/x86/lib/getuser.S 2011-05-19 00:06:34.000000000 -0400
19568+++ linux-2.6.39.1/arch/x86/lib/getuser.S 2011-05-22 19:36:30.000000000 -0400
19569@@ -33,14 +33,35 @@
19570 #include <asm/asm-offsets.h>
19571 #include <asm/thread_info.h>
19572 #include <asm/asm.h>
19573+#include <asm/segment.h>
19574+#include <asm/pgtable.h>
19575+
19576+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19577+#define __copyuser_seg gs;
19578+#else
19579+#define __copyuser_seg
19580+#endif
19581
19582 .text
19583 ENTRY(__get_user_1)
19584 CFI_STARTPROC
19585+
19586+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
19587 GET_THREAD_INFO(%_ASM_DX)
19588 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
19589 jae bad_get_user
19590-1: movzb (%_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+1: __copyuser_seg movzb (%_ASM_AX),%edx
19603 xor %eax,%eax
19604 ret
19605 CFI_ENDPROC
19606@@ -49,11 +70,24 @@ ENDPROC(__get_user_1)
19607 ENTRY(__get_user_2)
19608 CFI_STARTPROC
19609 add $1,%_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-2: movzwl -1(%_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+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
19629 xor %eax,%eax
19630 ret
19631 CFI_ENDPROC
19632@@ -62,11 +96,24 @@ ENDPROC(__get_user_2)
19633 ENTRY(__get_user_4)
19634 CFI_STARTPROC
19635 add $3,%_ASM_AX
19636+
19637+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
19638 jc bad_get_user
19639 GET_THREAD_INFO(%_ASM_DX)
19640 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
19641 jae bad_get_user
19642-3: mov -3(%_ASM_AX),%edx
19643+
19644+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19645+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
19646+ cmp %_ASM_DX,%_ASM_AX
19647+ jae 1234f
19648+ add %_ASM_DX,%_ASM_AX
19649+1234:
19650+#endif
19651+
19652+#endif
19653+
19654+3: __copyuser_seg mov -3(%_ASM_AX),%edx
19655 xor %eax,%eax
19656 ret
19657 CFI_ENDPROC
19658@@ -80,6 +127,15 @@ ENTRY(__get_user_8)
19659 GET_THREAD_INFO(%_ASM_DX)
19660 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
19661 jae bad_get_user
19662+
19663+#ifdef CONFIG_PAX_MEMORY_UDEREF
19664+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
19665+ cmp %_ASM_DX,%_ASM_AX
19666+ jae 1234f
19667+ add %_ASM_DX,%_ASM_AX
19668+1234:
19669+#endif
19670+
19671 4: movq -7(%_ASM_AX),%_ASM_DX
19672 xor %eax,%eax
19673 ret
19674diff -urNp linux-2.6.39.1/arch/x86/lib/insn.c linux-2.6.39.1/arch/x86/lib/insn.c
19675--- linux-2.6.39.1/arch/x86/lib/insn.c 2011-05-19 00:06:34.000000000 -0400
19676+++ linux-2.6.39.1/arch/x86/lib/insn.c 2011-05-22 19:36:30.000000000 -0400
19677@@ -21,6 +21,11 @@
19678 #include <linux/string.h>
19679 #include <asm/inat.h>
19680 #include <asm/insn.h>
19681+#ifdef __KERNEL__
19682+#include <asm/pgtable_types.h>
19683+#else
19684+#define ktla_ktva(addr) addr
19685+#endif
19686
19687 #define get_next(t, insn) \
19688 ({t r; r = *(t*)insn->next_byte; insn->next_byte += sizeof(t); r; })
19689@@ -40,8 +45,8 @@
19690 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
19691 {
19692 memset(insn, 0, sizeof(*insn));
19693- insn->kaddr = kaddr;
19694- insn->next_byte = kaddr;
19695+ insn->kaddr = ktla_ktva(kaddr);
19696+ insn->next_byte = ktla_ktva(kaddr);
19697 insn->x86_64 = x86_64 ? 1 : 0;
19698 insn->opnd_bytes = 4;
19699 if (x86_64)
19700diff -urNp linux-2.6.39.1/arch/x86/lib/mmx_32.c linux-2.6.39.1/arch/x86/lib/mmx_32.c
19701--- linux-2.6.39.1/arch/x86/lib/mmx_32.c 2011-05-19 00:06:34.000000000 -0400
19702+++ linux-2.6.39.1/arch/x86/lib/mmx_32.c 2011-05-22 19:36:30.000000000 -0400
19703@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *
19704 {
19705 void *p;
19706 int i;
19707+ unsigned long cr0;
19708
19709 if (unlikely(in_interrupt()))
19710 return __memcpy(to, from, len);
19711@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *
19712 kernel_fpu_begin();
19713
19714 __asm__ __volatile__ (
19715- "1: prefetch (%0)\n" /* This set is 28 bytes */
19716- " prefetch 64(%0)\n"
19717- " prefetch 128(%0)\n"
19718- " prefetch 192(%0)\n"
19719- " prefetch 256(%0)\n"
19720+ "1: prefetch (%1)\n" /* This set is 28 bytes */
19721+ " prefetch 64(%1)\n"
19722+ " prefetch 128(%1)\n"
19723+ " prefetch 192(%1)\n"
19724+ " prefetch 256(%1)\n"
19725 "2: \n"
19726 ".section .fixup, \"ax\"\n"
19727- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
19728+ "3: \n"
19729+
19730+#ifdef CONFIG_PAX_KERNEXEC
19731+ " movl %%cr0, %0\n"
19732+ " movl %0, %%eax\n"
19733+ " andl $0xFFFEFFFF, %%eax\n"
19734+ " movl %%eax, %%cr0\n"
19735+#endif
19736+
19737+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
19738+
19739+#ifdef CONFIG_PAX_KERNEXEC
19740+ " movl %0, %%cr0\n"
19741+#endif
19742+
19743 " jmp 2b\n"
19744 ".previous\n"
19745 _ASM_EXTABLE(1b, 3b)
19746- : : "r" (from));
19747+ : "=&r" (cr0) : "r" (from) : "ax");
19748
19749 for ( ; i > 5; i--) {
19750 __asm__ __volatile__ (
19751- "1: prefetch 320(%0)\n"
19752- "2: movq (%0), %%mm0\n"
19753- " movq 8(%0), %%mm1\n"
19754- " movq 16(%0), %%mm2\n"
19755- " movq 24(%0), %%mm3\n"
19756- " movq %%mm0, (%1)\n"
19757- " movq %%mm1, 8(%1)\n"
19758- " movq %%mm2, 16(%1)\n"
19759- " movq %%mm3, 24(%1)\n"
19760- " movq 32(%0), %%mm0\n"
19761- " movq 40(%0), %%mm1\n"
19762- " movq 48(%0), %%mm2\n"
19763- " movq 56(%0), %%mm3\n"
19764- " movq %%mm0, 32(%1)\n"
19765- " movq %%mm1, 40(%1)\n"
19766- " movq %%mm2, 48(%1)\n"
19767- " movq %%mm3, 56(%1)\n"
19768+ "1: prefetch 320(%1)\n"
19769+ "2: movq (%1), %%mm0\n"
19770+ " movq 8(%1), %%mm1\n"
19771+ " movq 16(%1), %%mm2\n"
19772+ " movq 24(%1), %%mm3\n"
19773+ " movq %%mm0, (%2)\n"
19774+ " movq %%mm1, 8(%2)\n"
19775+ " movq %%mm2, 16(%2)\n"
19776+ " movq %%mm3, 24(%2)\n"
19777+ " movq 32(%1), %%mm0\n"
19778+ " movq 40(%1), %%mm1\n"
19779+ " movq 48(%1), %%mm2\n"
19780+ " movq 56(%1), %%mm3\n"
19781+ " movq %%mm0, 32(%2)\n"
19782+ " movq %%mm1, 40(%2)\n"
19783+ " movq %%mm2, 48(%2)\n"
19784+ " movq %%mm3, 56(%2)\n"
19785 ".section .fixup, \"ax\"\n"
19786- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
19787+ "3:\n"
19788+
19789+#ifdef CONFIG_PAX_KERNEXEC
19790+ " movl %%cr0, %0\n"
19791+ " movl %0, %%eax\n"
19792+ " andl $0xFFFEFFFF, %%eax\n"
19793+ " movl %%eax, %%cr0\n"
19794+#endif
19795+
19796+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
19797+
19798+#ifdef CONFIG_PAX_KERNEXEC
19799+ " movl %0, %%cr0\n"
19800+#endif
19801+
19802 " jmp 2b\n"
19803 ".previous\n"
19804 _ASM_EXTABLE(1b, 3b)
19805- : : "r" (from), "r" (to) : "memory");
19806+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
19807
19808 from += 64;
19809 to += 64;
19810@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
19811 static void fast_copy_page(void *to, void *from)
19812 {
19813 int i;
19814+ unsigned long cr0;
19815
19816 kernel_fpu_begin();
19817
19818@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, voi
19819 * but that is for later. -AV
19820 */
19821 __asm__ __volatile__(
19822- "1: prefetch (%0)\n"
19823- " prefetch 64(%0)\n"
19824- " prefetch 128(%0)\n"
19825- " prefetch 192(%0)\n"
19826- " prefetch 256(%0)\n"
19827+ "1: prefetch (%1)\n"
19828+ " prefetch 64(%1)\n"
19829+ " prefetch 128(%1)\n"
19830+ " prefetch 192(%1)\n"
19831+ " prefetch 256(%1)\n"
19832 "2: \n"
19833 ".section .fixup, \"ax\"\n"
19834- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
19835+ "3: \n"
19836+
19837+#ifdef CONFIG_PAX_KERNEXEC
19838+ " movl %%cr0, %0\n"
19839+ " movl %0, %%eax\n"
19840+ " andl $0xFFFEFFFF, %%eax\n"
19841+ " movl %%eax, %%cr0\n"
19842+#endif
19843+
19844+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
19845+
19846+#ifdef CONFIG_PAX_KERNEXEC
19847+ " movl %0, %%cr0\n"
19848+#endif
19849+
19850 " jmp 2b\n"
19851 ".previous\n"
19852- _ASM_EXTABLE(1b, 3b) : : "r" (from));
19853+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
19854
19855 for (i = 0; i < (4096-320)/64; i++) {
19856 __asm__ __volatile__ (
19857- "1: prefetch 320(%0)\n"
19858- "2: movq (%0), %%mm0\n"
19859- " movntq %%mm0, (%1)\n"
19860- " movq 8(%0), %%mm1\n"
19861- " movntq %%mm1, 8(%1)\n"
19862- " movq 16(%0), %%mm2\n"
19863- " movntq %%mm2, 16(%1)\n"
19864- " movq 24(%0), %%mm3\n"
19865- " movntq %%mm3, 24(%1)\n"
19866- " movq 32(%0), %%mm4\n"
19867- " movntq %%mm4, 32(%1)\n"
19868- " movq 40(%0), %%mm5\n"
19869- " movntq %%mm5, 40(%1)\n"
19870- " movq 48(%0), %%mm6\n"
19871- " movntq %%mm6, 48(%1)\n"
19872- " movq 56(%0), %%mm7\n"
19873- " movntq %%mm7, 56(%1)\n"
19874+ "1: prefetch 320(%1)\n"
19875+ "2: movq (%1), %%mm0\n"
19876+ " movntq %%mm0, (%2)\n"
19877+ " movq 8(%1), %%mm1\n"
19878+ " movntq %%mm1, 8(%2)\n"
19879+ " movq 16(%1), %%mm2\n"
19880+ " movntq %%mm2, 16(%2)\n"
19881+ " movq 24(%1), %%mm3\n"
19882+ " movntq %%mm3, 24(%2)\n"
19883+ " movq 32(%1), %%mm4\n"
19884+ " movntq %%mm4, 32(%2)\n"
19885+ " movq 40(%1), %%mm5\n"
19886+ " movntq %%mm5, 40(%2)\n"
19887+ " movq 48(%1), %%mm6\n"
19888+ " movntq %%mm6, 48(%2)\n"
19889+ " movq 56(%1), %%mm7\n"
19890+ " movntq %%mm7, 56(%2)\n"
19891 ".section .fixup, \"ax\"\n"
19892- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
19893+ "3:\n"
19894+
19895+#ifdef CONFIG_PAX_KERNEXEC
19896+ " movl %%cr0, %0\n"
19897+ " movl %0, %%eax\n"
19898+ " andl $0xFFFEFFFF, %%eax\n"
19899+ " movl %%eax, %%cr0\n"
19900+#endif
19901+
19902+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
19903+
19904+#ifdef CONFIG_PAX_KERNEXEC
19905+ " movl %0, %%cr0\n"
19906+#endif
19907+
19908 " jmp 2b\n"
19909 ".previous\n"
19910- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
19911+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
19912
19913 from += 64;
19914 to += 64;
19915@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
19916 static void fast_copy_page(void *to, void *from)
19917 {
19918 int i;
19919+ unsigned long cr0;
19920
19921 kernel_fpu_begin();
19922
19923 __asm__ __volatile__ (
19924- "1: prefetch (%0)\n"
19925- " prefetch 64(%0)\n"
19926- " prefetch 128(%0)\n"
19927- " prefetch 192(%0)\n"
19928- " prefetch 256(%0)\n"
19929+ "1: prefetch (%1)\n"
19930+ " prefetch 64(%1)\n"
19931+ " prefetch 128(%1)\n"
19932+ " prefetch 192(%1)\n"
19933+ " prefetch 256(%1)\n"
19934 "2: \n"
19935 ".section .fixup, \"ax\"\n"
19936- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
19937+ "3: \n"
19938+
19939+#ifdef CONFIG_PAX_KERNEXEC
19940+ " movl %%cr0, %0\n"
19941+ " movl %0, %%eax\n"
19942+ " andl $0xFFFEFFFF, %%eax\n"
19943+ " movl %%eax, %%cr0\n"
19944+#endif
19945+
19946+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
19947+
19948+#ifdef CONFIG_PAX_KERNEXEC
19949+ " movl %0, %%cr0\n"
19950+#endif
19951+
19952 " jmp 2b\n"
19953 ".previous\n"
19954- _ASM_EXTABLE(1b, 3b) : : "r" (from));
19955+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
19956
19957 for (i = 0; i < 4096/64; i++) {
19958 __asm__ __volatile__ (
19959- "1: prefetch 320(%0)\n"
19960- "2: movq (%0), %%mm0\n"
19961- " movq 8(%0), %%mm1\n"
19962- " movq 16(%0), %%mm2\n"
19963- " movq 24(%0), %%mm3\n"
19964- " movq %%mm0, (%1)\n"
19965- " movq %%mm1, 8(%1)\n"
19966- " movq %%mm2, 16(%1)\n"
19967- " movq %%mm3, 24(%1)\n"
19968- " movq 32(%0), %%mm0\n"
19969- " movq 40(%0), %%mm1\n"
19970- " movq 48(%0), %%mm2\n"
19971- " movq 56(%0), %%mm3\n"
19972- " movq %%mm0, 32(%1)\n"
19973- " movq %%mm1, 40(%1)\n"
19974- " movq %%mm2, 48(%1)\n"
19975- " movq %%mm3, 56(%1)\n"
19976+ "1: prefetch 320(%1)\n"
19977+ "2: movq (%1), %%mm0\n"
19978+ " movq 8(%1), %%mm1\n"
19979+ " movq 16(%1), %%mm2\n"
19980+ " movq 24(%1), %%mm3\n"
19981+ " movq %%mm0, (%2)\n"
19982+ " movq %%mm1, 8(%2)\n"
19983+ " movq %%mm2, 16(%2)\n"
19984+ " movq %%mm3, 24(%2)\n"
19985+ " movq 32(%1), %%mm0\n"
19986+ " movq 40(%1), %%mm1\n"
19987+ " movq 48(%1), %%mm2\n"
19988+ " movq 56(%1), %%mm3\n"
19989+ " movq %%mm0, 32(%2)\n"
19990+ " movq %%mm1, 40(%2)\n"
19991+ " movq %%mm2, 48(%2)\n"
19992+ " movq %%mm3, 56(%2)\n"
19993 ".section .fixup, \"ax\"\n"
19994- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
19995+ "3:\n"
19996+
19997+#ifdef CONFIG_PAX_KERNEXEC
19998+ " movl %%cr0, %0\n"
19999+ " movl %0, %%eax\n"
20000+ " andl $0xFFFEFFFF, %%eax\n"
20001+ " movl %%eax, %%cr0\n"
20002+#endif
20003+
20004+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
20005+
20006+#ifdef CONFIG_PAX_KERNEXEC
20007+ " movl %0, %%cr0\n"
20008+#endif
20009+
20010 " jmp 2b\n"
20011 ".previous\n"
20012 _ASM_EXTABLE(1b, 3b)
20013- : : "r" (from), "r" (to) : "memory");
20014+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
20015
20016 from += 64;
20017 to += 64;
20018diff -urNp linux-2.6.39.1/arch/x86/lib/putuser.S linux-2.6.39.1/arch/x86/lib/putuser.S
20019--- linux-2.6.39.1/arch/x86/lib/putuser.S 2011-05-19 00:06:34.000000000 -0400
20020+++ linux-2.6.39.1/arch/x86/lib/putuser.S 2011-05-22 19:36:30.000000000 -0400
20021@@ -15,7 +15,8 @@
20022 #include <asm/thread_info.h>
20023 #include <asm/errno.h>
20024 #include <asm/asm.h>
20025-
20026+#include <asm/segment.h>
20027+#include <asm/pgtable.h>
20028
20029 /*
20030 * __put_user_X
20031@@ -29,52 +30,119 @@
20032 * as they get called from within inline assembly.
20033 */
20034
20035-#define ENTER CFI_STARTPROC ; \
20036- GET_THREAD_INFO(%_ASM_BX)
20037+#define ENTER CFI_STARTPROC
20038 #define EXIT ret ; \
20039 CFI_ENDPROC
20040
20041+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20042+#define _DEST %_ASM_CX,%_ASM_BX
20043+#else
20044+#define _DEST %_ASM_CX
20045+#endif
20046+
20047+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20048+#define __copyuser_seg gs;
20049+#else
20050+#define __copyuser_seg
20051+#endif
20052+
20053 .text
20054 ENTRY(__put_user_1)
20055 ENTER
20056+
20057+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
20058+ GET_THREAD_INFO(%_ASM_BX)
20059 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
20060 jae bad_put_user
20061-1: movb %al,(%_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+1: __copyuser_seg movb %al,(_DEST)
20074 xor %eax,%eax
20075 EXIT
20076 ENDPROC(__put_user_1)
20077
20078 ENTRY(__put_user_2)
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 $1,%_ASM_BX
20085 cmp %_ASM_BX,%_ASM_CX
20086 jae bad_put_user
20087-2: movw %ax,(%_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+2: __copyuser_seg movw %ax,(_DEST)
20100 xor %eax,%eax
20101 EXIT
20102 ENDPROC(__put_user_2)
20103
20104 ENTRY(__put_user_4)
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 $3,%_ASM_BX
20111 cmp %_ASM_BX,%_ASM_CX
20112 jae bad_put_user
20113-3: movl %eax,(%_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+3: __copyuser_seg movl %eax,(_DEST)
20126 xor %eax,%eax
20127 EXIT
20128 ENDPROC(__put_user_4)
20129
20130 ENTRY(__put_user_8)
20131 ENTER
20132+
20133+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
20134+ GET_THREAD_INFO(%_ASM_BX)
20135 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
20136 sub $7,%_ASM_BX
20137 cmp %_ASM_BX,%_ASM_CX
20138 jae bad_put_user
20139-4: mov %_ASM_AX,(%_ASM_CX)
20140+
20141+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20142+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
20143+ cmp %_ASM_BX,%_ASM_CX
20144+ jb 1234f
20145+ xor %ebx,%ebx
20146+1234:
20147+#endif
20148+
20149+#endif
20150+
20151+4: __copyuser_seg mov %_ASM_AX,(_DEST)
20152 #ifdef CONFIG_X86_32
20153-5: movl %edx,4(%_ASM_CX)
20154+5: __copyuser_seg movl %edx,4(_DEST)
20155 #endif
20156 xor %eax,%eax
20157 EXIT
20158diff -urNp linux-2.6.39.1/arch/x86/lib/usercopy_32.c linux-2.6.39.1/arch/x86/lib/usercopy_32.c
20159--- linux-2.6.39.1/arch/x86/lib/usercopy_32.c 2011-05-19 00:06:34.000000000 -0400
20160+++ linux-2.6.39.1/arch/x86/lib/usercopy_32.c 2011-05-22 19:36:30.000000000 -0400
20161@@ -43,7 +43,7 @@ do { \
20162 __asm__ __volatile__( \
20163 " testl %1,%1\n" \
20164 " jz 2f\n" \
20165- "0: lodsb\n" \
20166+ "0: "__copyuser_seg"lodsb\n" \
20167 " stosb\n" \
20168 " testb %%al,%%al\n" \
20169 " jz 1f\n" \
20170@@ -128,10 +128,12 @@ do { \
20171 int __d0; \
20172 might_fault(); \
20173 __asm__ __volatile__( \
20174+ __COPYUSER_SET_ES \
20175 "0: rep; stosl\n" \
20176 " movl %2,%0\n" \
20177 "1: rep; stosb\n" \
20178 "2:\n" \
20179+ __COPYUSER_RESTORE_ES \
20180 ".section .fixup,\"ax\"\n" \
20181 "3: lea 0(%2,%0,4),%0\n" \
20182 " jmp 2b\n" \
20183@@ -200,6 +202,7 @@ long strnlen_user(const char __user *s,
20184 might_fault();
20185
20186 __asm__ __volatile__(
20187+ __COPYUSER_SET_ES
20188 " testl %0, %0\n"
20189 " jz 3f\n"
20190 " andl %0,%%ecx\n"
20191@@ -208,6 +211,7 @@ long strnlen_user(const char __user *s,
20192 " subl %%ecx,%0\n"
20193 " addl %0,%%eax\n"
20194 "1:\n"
20195+ __COPYUSER_RESTORE_ES
20196 ".section .fixup,\"ax\"\n"
20197 "2: xorl %%eax,%%eax\n"
20198 " jmp 1b\n"
20199@@ -227,7 +231,7 @@ EXPORT_SYMBOL(strnlen_user);
20200
20201 #ifdef CONFIG_X86_INTEL_USERCOPY
20202 static unsigned long
20203-__copy_user_intel(void __user *to, const void *from, unsigned long size)
20204+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
20205 {
20206 int d0, d1;
20207 __asm__ __volatile__(
20208@@ -239,36 +243,36 @@ __copy_user_intel(void __user *to, const
20209 " .align 2,0x90\n"
20210 "3: movl 0(%4), %%eax\n"
20211 "4: movl 4(%4), %%edx\n"
20212- "5: movl %%eax, 0(%3)\n"
20213- "6: movl %%edx, 4(%3)\n"
20214+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
20215+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
20216 "7: movl 8(%4), %%eax\n"
20217 "8: movl 12(%4),%%edx\n"
20218- "9: movl %%eax, 8(%3)\n"
20219- "10: movl %%edx, 12(%3)\n"
20220+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
20221+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
20222 "11: movl 16(%4), %%eax\n"
20223 "12: movl 20(%4), %%edx\n"
20224- "13: movl %%eax, 16(%3)\n"
20225- "14: movl %%edx, 20(%3)\n"
20226+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
20227+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
20228 "15: movl 24(%4), %%eax\n"
20229 "16: movl 28(%4), %%edx\n"
20230- "17: movl %%eax, 24(%3)\n"
20231- "18: movl %%edx, 28(%3)\n"
20232+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
20233+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
20234 "19: movl 32(%4), %%eax\n"
20235 "20: movl 36(%4), %%edx\n"
20236- "21: movl %%eax, 32(%3)\n"
20237- "22: movl %%edx, 36(%3)\n"
20238+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
20239+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
20240 "23: movl 40(%4), %%eax\n"
20241 "24: movl 44(%4), %%edx\n"
20242- "25: movl %%eax, 40(%3)\n"
20243- "26: movl %%edx, 44(%3)\n"
20244+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
20245+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
20246 "27: movl 48(%4), %%eax\n"
20247 "28: movl 52(%4), %%edx\n"
20248- "29: movl %%eax, 48(%3)\n"
20249- "30: movl %%edx, 52(%3)\n"
20250+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
20251+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
20252 "31: movl 56(%4), %%eax\n"
20253 "32: movl 60(%4), %%edx\n"
20254- "33: movl %%eax, 56(%3)\n"
20255- "34: movl %%edx, 60(%3)\n"
20256+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
20257+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
20258 " addl $-64, %0\n"
20259 " addl $64, %4\n"
20260 " addl $64, %3\n"
20261@@ -278,10 +282,119 @@ __copy_user_intel(void __user *to, const
20262 " shrl $2, %0\n"
20263 " andl $3, %%eax\n"
20264 " cld\n"
20265+ __COPYUSER_SET_ES
20266 "99: rep; movsl\n"
20267 "36: movl %%eax, %0\n"
20268 "37: rep; movsb\n"
20269 "100:\n"
20270+ __COPYUSER_RESTORE_ES
20271+ ".section .fixup,\"ax\"\n"
20272+ "101: lea 0(%%eax,%0,4),%0\n"
20273+ " jmp 100b\n"
20274+ ".previous\n"
20275+ ".section __ex_table,\"a\"\n"
20276+ " .align 4\n"
20277+ " .long 1b,100b\n"
20278+ " .long 2b,100b\n"
20279+ " .long 3b,100b\n"
20280+ " .long 4b,100b\n"
20281+ " .long 5b,100b\n"
20282+ " .long 6b,100b\n"
20283+ " .long 7b,100b\n"
20284+ " .long 8b,100b\n"
20285+ " .long 9b,100b\n"
20286+ " .long 10b,100b\n"
20287+ " .long 11b,100b\n"
20288+ " .long 12b,100b\n"
20289+ " .long 13b,100b\n"
20290+ " .long 14b,100b\n"
20291+ " .long 15b,100b\n"
20292+ " .long 16b,100b\n"
20293+ " .long 17b,100b\n"
20294+ " .long 18b,100b\n"
20295+ " .long 19b,100b\n"
20296+ " .long 20b,100b\n"
20297+ " .long 21b,100b\n"
20298+ " .long 22b,100b\n"
20299+ " .long 23b,100b\n"
20300+ " .long 24b,100b\n"
20301+ " .long 25b,100b\n"
20302+ " .long 26b,100b\n"
20303+ " .long 27b,100b\n"
20304+ " .long 28b,100b\n"
20305+ " .long 29b,100b\n"
20306+ " .long 30b,100b\n"
20307+ " .long 31b,100b\n"
20308+ " .long 32b,100b\n"
20309+ " .long 33b,100b\n"
20310+ " .long 34b,100b\n"
20311+ " .long 35b,100b\n"
20312+ " .long 36b,100b\n"
20313+ " .long 37b,100b\n"
20314+ " .long 99b,101b\n"
20315+ ".previous"
20316+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
20317+ : "1"(to), "2"(from), "0"(size)
20318+ : "eax", "edx", "memory");
20319+ return size;
20320+}
20321+
20322+static unsigned long
20323+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
20324+{
20325+ int d0, d1;
20326+ __asm__ __volatile__(
20327+ " .align 2,0x90\n"
20328+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
20329+ " cmpl $67, %0\n"
20330+ " jbe 3f\n"
20331+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
20332+ " .align 2,0x90\n"
20333+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
20334+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
20335+ "5: movl %%eax, 0(%3)\n"
20336+ "6: movl %%edx, 4(%3)\n"
20337+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
20338+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
20339+ "9: movl %%eax, 8(%3)\n"
20340+ "10: movl %%edx, 12(%3)\n"
20341+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
20342+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
20343+ "13: movl %%eax, 16(%3)\n"
20344+ "14: movl %%edx, 20(%3)\n"
20345+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
20346+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
20347+ "17: movl %%eax, 24(%3)\n"
20348+ "18: movl %%edx, 28(%3)\n"
20349+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
20350+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
20351+ "21: movl %%eax, 32(%3)\n"
20352+ "22: movl %%edx, 36(%3)\n"
20353+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
20354+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
20355+ "25: movl %%eax, 40(%3)\n"
20356+ "26: movl %%edx, 44(%3)\n"
20357+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
20358+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
20359+ "29: movl %%eax, 48(%3)\n"
20360+ "30: movl %%edx, 52(%3)\n"
20361+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
20362+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
20363+ "33: movl %%eax, 56(%3)\n"
20364+ "34: movl %%edx, 60(%3)\n"
20365+ " addl $-64, %0\n"
20366+ " addl $64, %4\n"
20367+ " addl $64, %3\n"
20368+ " cmpl $63, %0\n"
20369+ " ja 1b\n"
20370+ "35: movl %0, %%eax\n"
20371+ " shrl $2, %0\n"
20372+ " andl $3, %%eax\n"
20373+ " cld\n"
20374+ "99: rep; "__copyuser_seg" movsl\n"
20375+ "36: movl %%eax, %0\n"
20376+ "37: rep; "__copyuser_seg" movsb\n"
20377+ "100:\n"
20378 ".section .fixup,\"ax\"\n"
20379 "101: lea 0(%%eax,%0,4),%0\n"
20380 " jmp 100b\n"
20381@@ -339,41 +452,41 @@ __copy_user_zeroing_intel(void *to, cons
20382 int d0, d1;
20383 __asm__ __volatile__(
20384 " .align 2,0x90\n"
20385- "0: movl 32(%4), %%eax\n"
20386+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
20387 " cmpl $67, %0\n"
20388 " jbe 2f\n"
20389- "1: movl 64(%4), %%eax\n"
20390+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
20391 " .align 2,0x90\n"
20392- "2: movl 0(%4), %%eax\n"
20393- "21: movl 4(%4), %%edx\n"
20394+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
20395+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
20396 " movl %%eax, 0(%3)\n"
20397 " movl %%edx, 4(%3)\n"
20398- "3: movl 8(%4), %%eax\n"
20399- "31: movl 12(%4),%%edx\n"
20400+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
20401+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
20402 " movl %%eax, 8(%3)\n"
20403 " movl %%edx, 12(%3)\n"
20404- "4: movl 16(%4), %%eax\n"
20405- "41: movl 20(%4), %%edx\n"
20406+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
20407+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
20408 " movl %%eax, 16(%3)\n"
20409 " movl %%edx, 20(%3)\n"
20410- "10: movl 24(%4), %%eax\n"
20411- "51: movl 28(%4), %%edx\n"
20412+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
20413+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
20414 " movl %%eax, 24(%3)\n"
20415 " movl %%edx, 28(%3)\n"
20416- "11: movl 32(%4), %%eax\n"
20417- "61: movl 36(%4), %%edx\n"
20418+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
20419+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
20420 " movl %%eax, 32(%3)\n"
20421 " movl %%edx, 36(%3)\n"
20422- "12: movl 40(%4), %%eax\n"
20423- "71: movl 44(%4), %%edx\n"
20424+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
20425+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
20426 " movl %%eax, 40(%3)\n"
20427 " movl %%edx, 44(%3)\n"
20428- "13: movl 48(%4), %%eax\n"
20429- "81: movl 52(%4), %%edx\n"
20430+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
20431+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
20432 " movl %%eax, 48(%3)\n"
20433 " movl %%edx, 52(%3)\n"
20434- "14: movl 56(%4), %%eax\n"
20435- "91: movl 60(%4), %%edx\n"
20436+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
20437+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
20438 " movl %%eax, 56(%3)\n"
20439 " movl %%edx, 60(%3)\n"
20440 " addl $-64, %0\n"
20441@@ -385,9 +498,9 @@ __copy_user_zeroing_intel(void *to, cons
20442 " shrl $2, %0\n"
20443 " andl $3, %%eax\n"
20444 " cld\n"
20445- "6: rep; movsl\n"
20446+ "6: rep; "__copyuser_seg" movsl\n"
20447 " movl %%eax,%0\n"
20448- "7: rep; movsb\n"
20449+ "7: rep; "__copyuser_seg" movsb\n"
20450 "8:\n"
20451 ".section .fixup,\"ax\"\n"
20452 "9: lea 0(%%eax,%0,4),%0\n"
20453@@ -440,41 +553,41 @@ static unsigned long __copy_user_zeroing
20454
20455 __asm__ __volatile__(
20456 " .align 2,0x90\n"
20457- "0: movl 32(%4), %%eax\n"
20458+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
20459 " cmpl $67, %0\n"
20460 " jbe 2f\n"
20461- "1: movl 64(%4), %%eax\n"
20462+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
20463 " .align 2,0x90\n"
20464- "2: movl 0(%4), %%eax\n"
20465- "21: movl 4(%4), %%edx\n"
20466+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
20467+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
20468 " movnti %%eax, 0(%3)\n"
20469 " movnti %%edx, 4(%3)\n"
20470- "3: movl 8(%4), %%eax\n"
20471- "31: movl 12(%4),%%edx\n"
20472+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
20473+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
20474 " movnti %%eax, 8(%3)\n"
20475 " movnti %%edx, 12(%3)\n"
20476- "4: movl 16(%4), %%eax\n"
20477- "41: movl 20(%4), %%edx\n"
20478+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
20479+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
20480 " movnti %%eax, 16(%3)\n"
20481 " movnti %%edx, 20(%3)\n"
20482- "10: movl 24(%4), %%eax\n"
20483- "51: movl 28(%4), %%edx\n"
20484+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
20485+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
20486 " movnti %%eax, 24(%3)\n"
20487 " movnti %%edx, 28(%3)\n"
20488- "11: movl 32(%4), %%eax\n"
20489- "61: movl 36(%4), %%edx\n"
20490+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
20491+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
20492 " movnti %%eax, 32(%3)\n"
20493 " movnti %%edx, 36(%3)\n"
20494- "12: movl 40(%4), %%eax\n"
20495- "71: movl 44(%4), %%edx\n"
20496+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
20497+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
20498 " movnti %%eax, 40(%3)\n"
20499 " movnti %%edx, 44(%3)\n"
20500- "13: movl 48(%4), %%eax\n"
20501- "81: movl 52(%4), %%edx\n"
20502+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
20503+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
20504 " movnti %%eax, 48(%3)\n"
20505 " movnti %%edx, 52(%3)\n"
20506- "14: movl 56(%4), %%eax\n"
20507- "91: movl 60(%4), %%edx\n"
20508+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
20509+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
20510 " movnti %%eax, 56(%3)\n"
20511 " movnti %%edx, 60(%3)\n"
20512 " addl $-64, %0\n"
20513@@ -487,9 +600,9 @@ static unsigned long __copy_user_zeroing
20514 " shrl $2, %0\n"
20515 " andl $3, %%eax\n"
20516 " cld\n"
20517- "6: rep; movsl\n"
20518+ "6: rep; "__copyuser_seg" movsl\n"
20519 " movl %%eax,%0\n"
20520- "7: rep; movsb\n"
20521+ "7: rep; "__copyuser_seg" movsb\n"
20522 "8:\n"
20523 ".section .fixup,\"ax\"\n"
20524 "9: lea 0(%%eax,%0,4),%0\n"
20525@@ -537,41 +650,41 @@ static unsigned long __copy_user_intel_n
20526
20527 __asm__ __volatile__(
20528 " .align 2,0x90\n"
20529- "0: movl 32(%4), %%eax\n"
20530+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
20531 " cmpl $67, %0\n"
20532 " jbe 2f\n"
20533- "1: movl 64(%4), %%eax\n"
20534+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
20535 " .align 2,0x90\n"
20536- "2: movl 0(%4), %%eax\n"
20537- "21: movl 4(%4), %%edx\n"
20538+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
20539+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
20540 " movnti %%eax, 0(%3)\n"
20541 " movnti %%edx, 4(%3)\n"
20542- "3: movl 8(%4), %%eax\n"
20543- "31: movl 12(%4),%%edx\n"
20544+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
20545+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
20546 " movnti %%eax, 8(%3)\n"
20547 " movnti %%edx, 12(%3)\n"
20548- "4: movl 16(%4), %%eax\n"
20549- "41: movl 20(%4), %%edx\n"
20550+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
20551+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
20552 " movnti %%eax, 16(%3)\n"
20553 " movnti %%edx, 20(%3)\n"
20554- "10: movl 24(%4), %%eax\n"
20555- "51: movl 28(%4), %%edx\n"
20556+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
20557+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
20558 " movnti %%eax, 24(%3)\n"
20559 " movnti %%edx, 28(%3)\n"
20560- "11: movl 32(%4), %%eax\n"
20561- "61: movl 36(%4), %%edx\n"
20562+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
20563+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
20564 " movnti %%eax, 32(%3)\n"
20565 " movnti %%edx, 36(%3)\n"
20566- "12: movl 40(%4), %%eax\n"
20567- "71: movl 44(%4), %%edx\n"
20568+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
20569+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
20570 " movnti %%eax, 40(%3)\n"
20571 " movnti %%edx, 44(%3)\n"
20572- "13: movl 48(%4), %%eax\n"
20573- "81: movl 52(%4), %%edx\n"
20574+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
20575+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
20576 " movnti %%eax, 48(%3)\n"
20577 " movnti %%edx, 52(%3)\n"
20578- "14: movl 56(%4), %%eax\n"
20579- "91: movl 60(%4), %%edx\n"
20580+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
20581+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
20582 " movnti %%eax, 56(%3)\n"
20583 " movnti %%edx, 60(%3)\n"
20584 " addl $-64, %0\n"
20585@@ -584,9 +697,9 @@ static unsigned long __copy_user_intel_n
20586 " shrl $2, %0\n"
20587 " andl $3, %%eax\n"
20588 " cld\n"
20589- "6: rep; movsl\n"
20590+ "6: rep; "__copyuser_seg" movsl\n"
20591 " movl %%eax,%0\n"
20592- "7: rep; movsb\n"
20593+ "7: rep; "__copyuser_seg" movsb\n"
20594 "8:\n"
20595 ".section .fixup,\"ax\"\n"
20596 "9: lea 0(%%eax,%0,4),%0\n"
20597@@ -629,32 +742,36 @@ static unsigned long __copy_user_intel_n
20598 */
20599 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
20600 unsigned long size);
20601-unsigned long __copy_user_intel(void __user *to, const void *from,
20602+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
20603+ unsigned long size);
20604+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
20605 unsigned long size);
20606 unsigned long __copy_user_zeroing_intel_nocache(void *to,
20607 const void __user *from, unsigned long size);
20608 #endif /* CONFIG_X86_INTEL_USERCOPY */
20609
20610 /* Generic arbitrary sized copy. */
20611-#define __copy_user(to, from, size) \
20612+#define __copy_user(to, from, size, prefix, set, restore) \
20613 do { \
20614 int __d0, __d1, __d2; \
20615 __asm__ __volatile__( \
20616+ set \
20617 " cmp $7,%0\n" \
20618 " jbe 1f\n" \
20619 " movl %1,%0\n" \
20620 " negl %0\n" \
20621 " andl $7,%0\n" \
20622 " subl %0,%3\n" \
20623- "4: rep; movsb\n" \
20624+ "4: rep; "prefix"movsb\n" \
20625 " movl %3,%0\n" \
20626 " shrl $2,%0\n" \
20627 " andl $3,%3\n" \
20628 " .align 2,0x90\n" \
20629- "0: rep; movsl\n" \
20630+ "0: rep; "prefix"movsl\n" \
20631 " movl %3,%0\n" \
20632- "1: rep; movsb\n" \
20633+ "1: rep; "prefix"movsb\n" \
20634 "2:\n" \
20635+ restore \
20636 ".section .fixup,\"ax\"\n" \
20637 "5: addl %3,%0\n" \
20638 " jmp 2b\n" \
20639@@ -682,14 +799,14 @@ do { \
20640 " negl %0\n" \
20641 " andl $7,%0\n" \
20642 " subl %0,%3\n" \
20643- "4: rep; movsb\n" \
20644+ "4: rep; "__copyuser_seg"movsb\n" \
20645 " movl %3,%0\n" \
20646 " shrl $2,%0\n" \
20647 " andl $3,%3\n" \
20648 " .align 2,0x90\n" \
20649- "0: rep; movsl\n" \
20650+ "0: rep; "__copyuser_seg"movsl\n" \
20651 " movl %3,%0\n" \
20652- "1: rep; movsb\n" \
20653+ "1: rep; "__copyuser_seg"movsb\n" \
20654 "2:\n" \
20655 ".section .fixup,\"ax\"\n" \
20656 "5: addl %3,%0\n" \
20657@@ -775,9 +892,9 @@ survive:
20658 }
20659 #endif
20660 if (movsl_is_ok(to, from, n))
20661- __copy_user(to, from, n);
20662+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
20663 else
20664- n = __copy_user_intel(to, from, n);
20665+ n = __generic_copy_to_user_intel(to, from, n);
20666 return n;
20667 }
20668 EXPORT_SYMBOL(__copy_to_user_ll);
20669@@ -797,10 +914,9 @@ unsigned long __copy_from_user_ll_nozero
20670 unsigned long n)
20671 {
20672 if (movsl_is_ok(to, from, n))
20673- __copy_user(to, from, n);
20674+ __copy_user(to, from, n, __copyuser_seg, "", "");
20675 else
20676- n = __copy_user_intel((void __user *)to,
20677- (const void *)from, n);
20678+ n = __generic_copy_from_user_intel(to, from, n);
20679 return n;
20680 }
20681 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
20682@@ -827,65 +943,50 @@ unsigned long __copy_from_user_ll_nocach
20683 if (n > 64 && cpu_has_xmm2)
20684 n = __copy_user_intel_nocache(to, from, n);
20685 else
20686- __copy_user(to, from, n);
20687+ __copy_user(to, from, n, __copyuser_seg, "", "");
20688 #else
20689- __copy_user(to, from, n);
20690+ __copy_user(to, from, n, __copyuser_seg, "", "");
20691 #endif
20692 return n;
20693 }
20694 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
20695
20696-/**
20697- * copy_to_user: - Copy a block of data into user space.
20698- * @to: Destination address, in user space.
20699- * @from: Source address, in kernel space.
20700- * @n: Number of bytes to copy.
20701- *
20702- * Context: User context only. This function may sleep.
20703- *
20704- * Copy data from kernel space to user space.
20705- *
20706- * Returns number of bytes that could not be copied.
20707- * On success, this will be zero.
20708- */
20709-unsigned long
20710-copy_to_user(void __user *to, const void *from, unsigned long n)
20711+void copy_from_user_overflow(void)
20712 {
20713- if (access_ok(VERIFY_WRITE, to, n))
20714- n = __copy_to_user(to, from, n);
20715- return n;
20716+ WARN(1, "Buffer overflow detected!\n");
20717 }
20718-EXPORT_SYMBOL(copy_to_user);
20719+EXPORT_SYMBOL(copy_from_user_overflow);
20720
20721-/**
20722- * copy_from_user: - Copy a block of data from user space.
20723- * @to: Destination address, in kernel space.
20724- * @from: Source address, in user space.
20725- * @n: Number of bytes to copy.
20726- *
20727- * Context: User context only. This function may sleep.
20728- *
20729- * Copy data from user space to kernel space.
20730- *
20731- * Returns number of bytes that could not be copied.
20732- * On success, this will be zero.
20733- *
20734- * If some data could not be copied, this function will pad the copied
20735- * data to the requested size using zero bytes.
20736- */
20737-unsigned long
20738-_copy_from_user(void *to, const void __user *from, unsigned long n)
20739+void copy_to_user_overflow(void)
20740 {
20741- if (access_ok(VERIFY_READ, from, n))
20742- n = __copy_from_user(to, from, n);
20743- else
20744- memset(to, 0, n);
20745- return n;
20746+ WARN(1, "Buffer overflow detected!\n");
20747 }
20748-EXPORT_SYMBOL(_copy_from_user);
20749+EXPORT_SYMBOL(copy_to_user_overflow);
20750
20751-void copy_from_user_overflow(void)
20752+#ifdef CONFIG_PAX_MEMORY_UDEREF
20753+void __set_fs(mm_segment_t x)
20754 {
20755- WARN(1, "Buffer overflow detected!\n");
20756+ switch (x.seg) {
20757+ case 0:
20758+ loadsegment(gs, 0);
20759+ break;
20760+ case TASK_SIZE_MAX:
20761+ loadsegment(gs, __USER_DS);
20762+ break;
20763+ case -1UL:
20764+ loadsegment(gs, __KERNEL_DS);
20765+ break;
20766+ default:
20767+ BUG();
20768+ }
20769+ return;
20770 }
20771-EXPORT_SYMBOL(copy_from_user_overflow);
20772+EXPORT_SYMBOL(__set_fs);
20773+
20774+void set_fs(mm_segment_t x)
20775+{
20776+ current_thread_info()->addr_limit = x;
20777+ __set_fs(x);
20778+}
20779+EXPORT_SYMBOL(set_fs);
20780+#endif
20781diff -urNp linux-2.6.39.1/arch/x86/lib/usercopy_64.c linux-2.6.39.1/arch/x86/lib/usercopy_64.c
20782--- linux-2.6.39.1/arch/x86/lib/usercopy_64.c 2011-05-19 00:06:34.000000000 -0400
20783+++ linux-2.6.39.1/arch/x86/lib/usercopy_64.c 2011-05-22 19:36:30.000000000 -0400
20784@@ -42,6 +42,12 @@ long
20785 __strncpy_from_user(char *dst, const char __user *src, long count)
20786 {
20787 long res;
20788+
20789+#ifdef CONFIG_PAX_MEMORY_UDEREF
20790+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
20791+ src += PAX_USER_SHADOW_BASE;
20792+#endif
20793+
20794 __do_strncpy_from_user(dst, src, count, res);
20795 return res;
20796 }
20797@@ -65,6 +71,12 @@ unsigned long __clear_user(void __user *
20798 {
20799 long __d0;
20800 might_fault();
20801+
20802+#ifdef CONFIG_PAX_MEMORY_UDEREF
20803+ if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
20804+ addr += PAX_USER_SHADOW_BASE;
20805+#endif
20806+
20807 /* no memory constraint because it doesn't change any memory gcc knows
20808 about */
20809 asm volatile(
20810@@ -151,10 +163,18 @@ EXPORT_SYMBOL(strlen_user);
20811
20812 unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
20813 {
20814- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
20815+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
20816+
20817+#ifdef CONFIG_PAX_MEMORY_UDEREF
20818+ if ((unsigned long)to < PAX_USER_SHADOW_BASE)
20819+ to += PAX_USER_SHADOW_BASE;
20820+ if ((unsigned long)from < PAX_USER_SHADOW_BASE)
20821+ from += PAX_USER_SHADOW_BASE;
20822+#endif
20823+
20824 return copy_user_generic((__force void *)to, (__force void *)from, len);
20825- }
20826- return len;
20827+ }
20828+ return len;
20829 }
20830 EXPORT_SYMBOL(copy_in_user);
20831
20832diff -urNp linux-2.6.39.1/arch/x86/Makefile linux-2.6.39.1/arch/x86/Makefile
20833--- linux-2.6.39.1/arch/x86/Makefile 2011-05-19 00:06:34.000000000 -0400
20834+++ linux-2.6.39.1/arch/x86/Makefile 2011-05-22 19:36:30.000000000 -0400
20835@@ -195,3 +195,12 @@ define archhelp
20836 echo ' FDARGS="..." arguments for the booted kernel'
20837 echo ' FDINITRD=file initrd for the booted kernel'
20838 endef
20839+
20840+define OLD_LD
20841+
20842+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
20843+*** Please upgrade your binutils to 2.18 or newer
20844+endef
20845+
20846+archprepare:
20847+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
20848diff -urNp linux-2.6.39.1/arch/x86/mm/extable.c linux-2.6.39.1/arch/x86/mm/extable.c
20849--- linux-2.6.39.1/arch/x86/mm/extable.c 2011-05-19 00:06:34.000000000 -0400
20850+++ linux-2.6.39.1/arch/x86/mm/extable.c 2011-05-22 19:36:30.000000000 -0400
20851@@ -1,14 +1,71 @@
20852 #include <linux/module.h>
20853 #include <linux/spinlock.h>
20854+#include <linux/sort.h>
20855 #include <asm/uaccess.h>
20856+#include <asm/pgtable.h>
20857
20858+/*
20859+ * The exception table needs to be sorted so that the binary
20860+ * search that we use to find entries in it works properly.
20861+ * This is used both for the kernel exception table and for
20862+ * the exception tables of modules that get loaded.
20863+ */
20864+static int cmp_ex(const void *a, const void *b)
20865+{
20866+ const struct exception_table_entry *x = a, *y = b;
20867+
20868+ /* avoid overflow */
20869+ if (x->insn > y->insn)
20870+ return 1;
20871+ if (x->insn < y->insn)
20872+ return -1;
20873+ return 0;
20874+}
20875+
20876+static void swap_ex(void *a, void *b, int size)
20877+{
20878+ struct exception_table_entry t, *x = a, *y = b;
20879+
20880+ t = *x;
20881+
20882+ pax_open_kernel();
20883+ *x = *y;
20884+ *y = t;
20885+ pax_close_kernel();
20886+}
20887+
20888+void sort_extable(struct exception_table_entry *start,
20889+ struct exception_table_entry *finish)
20890+{
20891+ sort(start, finish - start, sizeof(struct exception_table_entry),
20892+ cmp_ex, swap_ex);
20893+}
20894+
20895+#ifdef CONFIG_MODULES
20896+/*
20897+ * If the exception table is sorted, any referring to the module init
20898+ * will be at the beginning or the end.
20899+ */
20900+void trim_init_extable(struct module *m)
20901+{
20902+ /*trim the beginning*/
20903+ while (m->num_exentries && within_module_init(m->extable[0].insn, m)) {
20904+ m->extable++;
20905+ m->num_exentries--;
20906+ }
20907+ /*trim the end*/
20908+ while (m->num_exentries &&
20909+ within_module_init(m->extable[m->num_exentries-1].insn, m))
20910+ m->num_exentries--;
20911+}
20912+#endif /* CONFIG_MODULES */
20913
20914 int fixup_exception(struct pt_regs *regs)
20915 {
20916 const struct exception_table_entry *fixup;
20917
20918 #ifdef CONFIG_PNPBIOS
20919- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
20920+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
20921 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
20922 extern u32 pnp_bios_is_utter_crap;
20923 pnp_bios_is_utter_crap = 1;
20924diff -urNp linux-2.6.39.1/arch/x86/mm/fault.c linux-2.6.39.1/arch/x86/mm/fault.c
20925--- linux-2.6.39.1/arch/x86/mm/fault.c 2011-05-19 00:06:34.000000000 -0400
20926+++ linux-2.6.39.1/arch/x86/mm/fault.c 2011-06-06 17:34:04.000000000 -0400
20927@@ -12,10 +12,18 @@
20928 #include <linux/mmiotrace.h> /* kmmio_handler, ... */
20929 #include <linux/perf_event.h> /* perf_sw_event */
20930 #include <linux/hugetlb.h> /* hstate_index_to_shift */
20931+#include <linux/unistd.h>
20932+#include <linux/compiler.h>
20933
20934 #include <asm/traps.h> /* dotraplinkage, ... */
20935 #include <asm/pgalloc.h> /* pgd_*(), ... */
20936 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
20937+#include <asm/vsyscall.h>
20938+#include <asm/tlbflush.h>
20939+
20940+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20941+#include <asm/stacktrace.h>
20942+#endif
20943
20944 /*
20945 * Page fault error code bits:
20946@@ -53,7 +61,7 @@ static inline int __kprobes notify_page_
20947 int ret = 0;
20948
20949 /* kprobe_running() needs smp_processor_id() */
20950- if (kprobes_built_in() && !user_mode_vm(regs)) {
20951+ if (kprobes_built_in() && !user_mode(regs)) {
20952 preempt_disable();
20953 if (kprobe_running() && kprobe_fault_handler(regs, 14))
20954 ret = 1;
20955@@ -114,7 +122,10 @@ check_prefetch_opcode(struct pt_regs *re
20956 return !instr_lo || (instr_lo>>1) == 1;
20957 case 0x00:
20958 /* Prefetch instruction is 0x0F0D or 0x0F18 */
20959- if (probe_kernel_address(instr, opcode))
20960+ if (user_mode(regs)) {
20961+ if (__copy_from_user_inatomic(&opcode, (__force unsigned char __user *)(instr), 1))
20962+ return 0;
20963+ } else if (probe_kernel_address(instr, opcode))
20964 return 0;
20965
20966 *prefetch = (instr_lo == 0xF) &&
20967@@ -148,7 +159,10 @@ is_prefetch(struct pt_regs *regs, unsign
20968 while (instr < max_instr) {
20969 unsigned char opcode;
20970
20971- if (probe_kernel_address(instr, opcode))
20972+ if (user_mode(regs)) {
20973+ if (__copy_from_user_inatomic(&opcode, (__force unsigned char __user *)(instr), 1))
20974+ break;
20975+ } else if (probe_kernel_address(instr, opcode))
20976 break;
20977
20978 instr++;
20979@@ -179,6 +193,30 @@ force_sig_info_fault(int si_signo, int s
20980 force_sig_info(si_signo, &info, tsk);
20981 }
20982
20983+#ifdef CONFIG_PAX_EMUTRAMP
20984+static int pax_handle_fetch_fault(struct pt_regs *regs);
20985+#endif
20986+
20987+#ifdef CONFIG_PAX_PAGEEXEC
20988+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
20989+{
20990+ pgd_t *pgd;
20991+ pud_t *pud;
20992+ pmd_t *pmd;
20993+
20994+ pgd = pgd_offset(mm, address);
20995+ if (!pgd_present(*pgd))
20996+ return NULL;
20997+ pud = pud_offset(pgd, address);
20998+ if (!pud_present(*pud))
20999+ return NULL;
21000+ pmd = pmd_offset(pud, address);
21001+ if (!pmd_present(*pmd))
21002+ return NULL;
21003+ return pmd;
21004+}
21005+#endif
21006+
21007 DEFINE_SPINLOCK(pgd_lock);
21008 LIST_HEAD(pgd_list);
21009
21010@@ -229,10 +267,22 @@ void vmalloc_sync_all(void)
21011 for (address = VMALLOC_START & PMD_MASK;
21012 address >= TASK_SIZE && address < FIXADDR_TOP;
21013 address += PMD_SIZE) {
21014+
21015+#ifdef CONFIG_PAX_PER_CPU_PGD
21016+ unsigned long cpu;
21017+#else
21018 struct page *page;
21019+#endif
21020
21021 spin_lock(&pgd_lock);
21022+
21023+#ifdef CONFIG_PAX_PER_CPU_PGD
21024+ for (cpu = 0; cpu < NR_CPUS; ++cpu) {
21025+ pgd_t *pgd = get_cpu_pgd(cpu);
21026+ pmd_t *ret;
21027+#else
21028 list_for_each_entry(page, &pgd_list, lru) {
21029+ pgd_t *pgd = page_address(page);
21030 spinlock_t *pgt_lock;
21031 pmd_t *ret;
21032
21033@@ -240,8 +290,13 @@ void vmalloc_sync_all(void)
21034 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
21035
21036 spin_lock(pgt_lock);
21037- ret = vmalloc_sync_one(page_address(page), address);
21038+#endif
21039+
21040+ ret = vmalloc_sync_one(pgd, address);
21041+
21042+#ifndef CONFIG_PAX_PER_CPU_PGD
21043 spin_unlock(pgt_lock);
21044+#endif
21045
21046 if (!ret)
21047 break;
21048@@ -275,6 +330,11 @@ static noinline __kprobes int vmalloc_fa
21049 * an interrupt in the middle of a task switch..
21050 */
21051 pgd_paddr = read_cr3();
21052+
21053+#ifdef CONFIG_PAX_PER_CPU_PGD
21054+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
21055+#endif
21056+
21057 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
21058 if (!pmd_k)
21059 return -1;
21060@@ -370,7 +430,14 @@ static noinline __kprobes int vmalloc_fa
21061 * happen within a race in page table update. In the later
21062 * case just flush:
21063 */
21064+
21065+#ifdef CONFIG_PAX_PER_CPU_PGD
21066+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
21067+ pgd = pgd_offset_cpu(smp_processor_id(), address);
21068+#else
21069 pgd = pgd_offset(current->active_mm, address);
21070+#endif
21071+
21072 pgd_ref = pgd_offset_k(address);
21073 if (pgd_none(*pgd_ref))
21074 return -1;
21075@@ -532,7 +599,7 @@ static int is_errata93(struct pt_regs *r
21076 static int is_errata100(struct pt_regs *regs, unsigned long address)
21077 {
21078 #ifdef CONFIG_X86_64
21079- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
21080+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
21081 return 1;
21082 #endif
21083 return 0;
21084@@ -559,7 +626,7 @@ static int is_f00f_bug(struct pt_regs *r
21085 }
21086
21087 static const char nx_warning[] = KERN_CRIT
21088-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
21089+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
21090
21091 static void
21092 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
21093@@ -568,15 +635,26 @@ show_fault_oops(struct pt_regs *regs, un
21094 if (!oops_may_print())
21095 return;
21096
21097- if (error_code & PF_INSTR) {
21098+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
21099 unsigned int level;
21100
21101 pte_t *pte = lookup_address(address, &level);
21102
21103 if (pte && pte_present(*pte) && !pte_exec(*pte))
21104- printk(nx_warning, current_uid());
21105+ printk(nx_warning, current_uid(), current->comm, task_pid_nr(current));
21106 }
21107
21108+#ifdef CONFIG_PAX_KERNEXEC
21109+ if (init_mm.start_code <= address && address < init_mm.end_code) {
21110+ if (current->signal->curr_ip)
21111+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
21112+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
21113+ else
21114+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
21115+ current->comm, task_pid_nr(current), current_uid(), current_euid());
21116+ }
21117+#endif
21118+
21119 printk(KERN_ALERT "BUG: unable to handle kernel ");
21120 if (address < PAGE_SIZE)
21121 printk(KERN_CONT "NULL pointer dereference");
21122@@ -701,6 +779,68 @@ __bad_area_nosemaphore(struct pt_regs *r
21123 unsigned long address, int si_code)
21124 {
21125 struct task_struct *tsk = current;
21126+ struct mm_struct *mm = tsk->mm;
21127+
21128+#ifdef CONFIG_X86_64
21129+ if (mm && (error_code & PF_INSTR) && mm->context.vdso) {
21130+ if (regs->ip == (unsigned long)vgettimeofday) {
21131+ regs->ip = (unsigned long)VDSO64_SYMBOL(mm->context.vdso, fallback_gettimeofday);
21132+ return;
21133+ } else if (regs->ip == (unsigned long)vtime) {
21134+ regs->ip = (unsigned long)VDSO64_SYMBOL(mm->context.vdso, fallback_time);
21135+ return;
21136+ } else if (regs->ip == (unsigned long)vgetcpu) {
21137+ regs->ip = (unsigned long)VDSO64_SYMBOL(mm->context.vdso, getcpu);
21138+ return;
21139+ }
21140+ }
21141+#endif
21142+
21143+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
21144+ if (mm && (error_code & PF_USER)) {
21145+ unsigned long ip = regs->ip;
21146+
21147+ if (v8086_mode(regs))
21148+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
21149+
21150+ /*
21151+ * It's possible to have interrupts off here:
21152+ */
21153+ local_irq_enable();
21154+
21155+#ifdef CONFIG_PAX_PAGEEXEC
21156+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) &&
21157+ (((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) || (!(error_code & (PF_PROT | PF_WRITE)) && ip == address))) {
21158+
21159+#ifdef CONFIG_PAX_EMUTRAMP
21160+ switch (pax_handle_fetch_fault(regs)) {
21161+ case 2:
21162+ return;
21163+ }
21164+#endif
21165+
21166+ pax_report_fault(regs, (void *)ip, (void *)regs->sp);
21167+ do_group_exit(SIGKILL);
21168+ }
21169+#endif
21170+
21171+#ifdef CONFIG_PAX_SEGMEXEC
21172+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && !(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address)) {
21173+
21174+#ifdef CONFIG_PAX_EMUTRAMP
21175+ switch (pax_handle_fetch_fault(regs)) {
21176+ case 2:
21177+ return;
21178+ }
21179+#endif
21180+
21181+ pax_report_fault(regs, (void *)ip, (void *)regs->sp);
21182+ do_group_exit(SIGKILL);
21183+ }
21184+#endif
21185+
21186+ }
21187+#endif
21188
21189 /* User mode accesses just cause a SIGSEGV */
21190 if (error_code & PF_USER) {
21191@@ -855,6 +995,99 @@ static int spurious_fault_check(unsigned
21192 return 1;
21193 }
21194
21195+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
21196+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
21197+{
21198+ pte_t *pte;
21199+ pmd_t *pmd;
21200+ spinlock_t *ptl;
21201+ unsigned char pte_mask;
21202+
21203+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
21204+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
21205+ return 0;
21206+
21207+ /* PaX: it's our fault, let's handle it if we can */
21208+
21209+ /* PaX: take a look at read faults before acquiring any locks */
21210+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
21211+ /* instruction fetch attempt from a protected page in user mode */
21212+ up_read(&mm->mmap_sem);
21213+
21214+#ifdef CONFIG_PAX_EMUTRAMP
21215+ switch (pax_handle_fetch_fault(regs)) {
21216+ case 2:
21217+ return 1;
21218+ }
21219+#endif
21220+
21221+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
21222+ do_group_exit(SIGKILL);
21223+ }
21224+
21225+ pmd = pax_get_pmd(mm, address);
21226+ if (unlikely(!pmd))
21227+ return 0;
21228+
21229+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
21230+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
21231+ pte_unmap_unlock(pte, ptl);
21232+ return 0;
21233+ }
21234+
21235+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
21236+ /* write attempt to a protected page in user mode */
21237+ pte_unmap_unlock(pte, ptl);
21238+ return 0;
21239+ }
21240+
21241+#ifdef CONFIG_SMP
21242+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
21243+#else
21244+ if (likely(address > get_limit(regs->cs)))
21245+#endif
21246+ {
21247+ set_pte(pte, pte_mkread(*pte));
21248+ __flush_tlb_one(address);
21249+ pte_unmap_unlock(pte, ptl);
21250+ up_read(&mm->mmap_sem);
21251+ return 1;
21252+ }
21253+
21254+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
21255+
21256+ /*
21257+ * PaX: fill DTLB with user rights and retry
21258+ */
21259+ __asm__ __volatile__ (
21260+ "orb %2,(%1)\n"
21261+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
21262+/*
21263+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
21264+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
21265+ * page fault when examined during a TLB load attempt. this is true not only
21266+ * for PTEs holding a non-present entry but also present entries that will
21267+ * raise a page fault (such as those set up by PaX, or the copy-on-write
21268+ * mechanism). in effect it means that we do *not* need to flush the TLBs
21269+ * for our target pages since their PTEs are simply not in the TLBs at all.
21270+
21271+ * the best thing in omitting it is that we gain around 15-20% speed in the
21272+ * fast path of the page fault handler and can get rid of tracing since we
21273+ * can no longer flush unintended entries.
21274+ */
21275+ "invlpg (%0)\n"
21276+#endif
21277+ __copyuser_seg"testb $0,(%0)\n"
21278+ "xorb %3,(%1)\n"
21279+ :
21280+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
21281+ : "memory", "cc");
21282+ pte_unmap_unlock(pte, ptl);
21283+ up_read(&mm->mmap_sem);
21284+ return 1;
21285+}
21286+#endif
21287+
21288 /*
21289 * Handle a spurious fault caused by a stale TLB entry.
21290 *
21291@@ -927,6 +1160,9 @@ int show_unhandled_signals = 1;
21292 static inline int
21293 access_error(unsigned long error_code, struct vm_area_struct *vma)
21294 {
21295+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
21296+ return 1;
21297+
21298 if (error_code & PF_WRITE) {
21299 /* write, present and write, not present: */
21300 if (unlikely(!(vma->vm_flags & VM_WRITE)))
21301@@ -960,19 +1196,33 @@ do_page_fault(struct pt_regs *regs, unsi
21302 {
21303 struct vm_area_struct *vma;
21304 struct task_struct *tsk;
21305- unsigned long address;
21306 struct mm_struct *mm;
21307 int fault;
21308 int write = error_code & PF_WRITE;
21309 unsigned int flags = FAULT_FLAG_ALLOW_RETRY |
21310 (write ? FAULT_FLAG_WRITE : 0);
21311
21312+ /* Get the faulting address: */
21313+ unsigned long address = read_cr2();
21314+
21315+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21316+ if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
21317+ if (!search_exception_tables(regs->ip)) {
21318+ bad_area_nosemaphore(regs, error_code, address);
21319+ return;
21320+ }
21321+ if (address < PAX_USER_SHADOW_BASE) {
21322+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
21323+ printk(KERN_ERR "PAX: faulting IP: %pA\n", (void *)regs->ip);
21324+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
21325+ } else
21326+ address -= PAX_USER_SHADOW_BASE;
21327+ }
21328+#endif
21329+
21330 tsk = current;
21331 mm = tsk->mm;
21332
21333- /* Get the faulting address: */
21334- address = read_cr2();
21335-
21336 /*
21337 * Detect and handle instructions that would cause a page fault for
21338 * both a tracked kernel page and a userspace page.
21339@@ -1032,7 +1282,7 @@ do_page_fault(struct pt_regs *regs, unsi
21340 * User-mode registers count as a user access even for any
21341 * potential system fault or CPU buglet:
21342 */
21343- if (user_mode_vm(regs)) {
21344+ if (user_mode(regs)) {
21345 local_irq_enable();
21346 error_code |= PF_USER;
21347 } else {
21348@@ -1087,6 +1337,11 @@ retry:
21349 might_sleep();
21350 }
21351
21352+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
21353+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
21354+ return;
21355+#endif
21356+
21357 vma = find_vma(mm, address);
21358 if (unlikely(!vma)) {
21359 bad_area(regs, error_code, address);
21360@@ -1098,18 +1353,24 @@ retry:
21361 bad_area(regs, error_code, address);
21362 return;
21363 }
21364- if (error_code & PF_USER) {
21365- /*
21366- * Accessing the stack below %sp is always a bug.
21367- * The large cushion allows instructions like enter
21368- * and pusha to work. ("enter $65535, $31" pushes
21369- * 32 pointers and then decrements %sp by 65535.)
21370- */
21371- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
21372- bad_area(regs, error_code, address);
21373- return;
21374- }
21375+ /*
21376+ * Accessing the stack below %sp is always a bug.
21377+ * The large cushion allows instructions like enter
21378+ * and pusha to work. ("enter $65535, $31" pushes
21379+ * 32 pointers and then decrements %sp by 65535.)
21380+ */
21381+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
21382+ bad_area(regs, error_code, address);
21383+ return;
21384 }
21385+
21386+#ifdef CONFIG_PAX_SEGMEXEC
21387+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
21388+ bad_area(regs, error_code, address);
21389+ return;
21390+ }
21391+#endif
21392+
21393 if (unlikely(expand_stack(vma, address))) {
21394 bad_area(regs, error_code, address);
21395 return;
21396@@ -1164,3 +1425,199 @@ good_area:
21397
21398 up_read(&mm->mmap_sem);
21399 }
21400+
21401+#ifdef CONFIG_PAX_EMUTRAMP
21402+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
21403+{
21404+ int err;
21405+
21406+ do { /* PaX: gcc trampoline emulation #1 */
21407+ unsigned char mov1, mov2;
21408+ unsigned short jmp;
21409+ unsigned int addr1, addr2;
21410+
21411+#ifdef CONFIG_X86_64
21412+ if ((regs->ip + 11) >> 32)
21413+ break;
21414+#endif
21415+
21416+ err = get_user(mov1, (unsigned char __user *)regs->ip);
21417+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
21418+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
21419+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
21420+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
21421+
21422+ if (err)
21423+ break;
21424+
21425+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
21426+ regs->cx = addr1;
21427+ regs->ax = addr2;
21428+ regs->ip = addr2;
21429+ return 2;
21430+ }
21431+ } while (0);
21432+
21433+ do { /* PaX: gcc trampoline emulation #2 */
21434+ unsigned char mov, jmp;
21435+ unsigned int addr1, addr2;
21436+
21437+#ifdef CONFIG_X86_64
21438+ if ((regs->ip + 9) >> 32)
21439+ break;
21440+#endif
21441+
21442+ err = get_user(mov, (unsigned char __user *)regs->ip);
21443+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
21444+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
21445+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
21446+
21447+ if (err)
21448+ break;
21449+
21450+ if (mov == 0xB9 && jmp == 0xE9) {
21451+ regs->cx = addr1;
21452+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
21453+ return 2;
21454+ }
21455+ } while (0);
21456+
21457+ return 1; /* PaX in action */
21458+}
21459+
21460+#ifdef CONFIG_X86_64
21461+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
21462+{
21463+ int err;
21464+
21465+ do { /* PaX: gcc trampoline emulation #1 */
21466+ unsigned short mov1, mov2, jmp1;
21467+ unsigned char jmp2;
21468+ unsigned int addr1;
21469+ unsigned long addr2;
21470+
21471+ err = get_user(mov1, (unsigned short __user *)regs->ip);
21472+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
21473+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
21474+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
21475+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
21476+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
21477+
21478+ if (err)
21479+ break;
21480+
21481+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
21482+ regs->r11 = addr1;
21483+ regs->r10 = addr2;
21484+ regs->ip = addr1;
21485+ return 2;
21486+ }
21487+ } while (0);
21488+
21489+ do { /* PaX: gcc trampoline emulation #2 */
21490+ unsigned short mov1, mov2, jmp1;
21491+ unsigned char jmp2;
21492+ unsigned long addr1, addr2;
21493+
21494+ err = get_user(mov1, (unsigned short __user *)regs->ip);
21495+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
21496+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
21497+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
21498+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
21499+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
21500+
21501+ if (err)
21502+ break;
21503+
21504+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
21505+ regs->r11 = addr1;
21506+ regs->r10 = addr2;
21507+ regs->ip = addr1;
21508+ return 2;
21509+ }
21510+ } while (0);
21511+
21512+ return 1; /* PaX in action */
21513+}
21514+#endif
21515+
21516+/*
21517+ * PaX: decide what to do with offenders (regs->ip = fault address)
21518+ *
21519+ * returns 1 when task should be killed
21520+ * 2 when gcc trampoline was detected
21521+ */
21522+static int pax_handle_fetch_fault(struct pt_regs *regs)
21523+{
21524+ if (v8086_mode(regs))
21525+ return 1;
21526+
21527+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
21528+ return 1;
21529+
21530+#ifdef CONFIG_X86_32
21531+ return pax_handle_fetch_fault_32(regs);
21532+#else
21533+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
21534+ return pax_handle_fetch_fault_32(regs);
21535+ else
21536+ return pax_handle_fetch_fault_64(regs);
21537+#endif
21538+}
21539+#endif
21540+
21541+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
21542+void pax_report_insns(void *pc, void *sp)
21543+{
21544+ long i;
21545+
21546+ printk(KERN_ERR "PAX: bytes at PC: ");
21547+ for (i = 0; i < 20; i++) {
21548+ unsigned char c;
21549+ if (get_user(c, (__force unsigned char __user *)pc+i))
21550+ printk(KERN_CONT "?? ");
21551+ else
21552+ printk(KERN_CONT "%02x ", c);
21553+ }
21554+ printk("\n");
21555+
21556+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
21557+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
21558+ unsigned long c;
21559+ if (get_user(c, (__force unsigned long __user *)sp+i))
21560+#ifdef CONFIG_X86_32
21561+ printk(KERN_CONT "???????? ");
21562+#else
21563+ printk(KERN_CONT "???????????????? ");
21564+#endif
21565+ else
21566+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
21567+ }
21568+ printk("\n");
21569+}
21570+#endif
21571+
21572+/**
21573+ * probe_kernel_write(): safely attempt to write to a location
21574+ * @dst: address to write to
21575+ * @src: pointer to the data that shall be written
21576+ * @size: size of the data chunk
21577+ *
21578+ * Safely write to address @dst from the buffer at @src. If a kernel fault
21579+ * happens, handle that and return -EFAULT.
21580+ */
21581+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
21582+{
21583+ long ret;
21584+ mm_segment_t old_fs = get_fs();
21585+
21586+ set_fs(KERNEL_DS);
21587+ pagefault_disable();
21588+ pax_open_kernel();
21589+ ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
21590+ pax_close_kernel();
21591+ pagefault_enable();
21592+ set_fs(old_fs);
21593+
21594+ return ret ? -EFAULT : 0;
21595+}
21596diff -urNp linux-2.6.39.1/arch/x86/mm/gup.c linux-2.6.39.1/arch/x86/mm/gup.c
21597--- linux-2.6.39.1/arch/x86/mm/gup.c 2011-05-19 00:06:34.000000000 -0400
21598+++ linux-2.6.39.1/arch/x86/mm/gup.c 2011-05-22 19:36:30.000000000 -0400
21599@@ -263,7 +263,7 @@ int __get_user_pages_fast(unsigned long
21600 addr = start;
21601 len = (unsigned long) nr_pages << PAGE_SHIFT;
21602 end = start + len;
21603- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
21604+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
21605 (void __user *)start, len)))
21606 return 0;
21607
21608diff -urNp linux-2.6.39.1/arch/x86/mm/highmem_32.c linux-2.6.39.1/arch/x86/mm/highmem_32.c
21609--- linux-2.6.39.1/arch/x86/mm/highmem_32.c 2011-05-19 00:06:34.000000000 -0400
21610+++ linux-2.6.39.1/arch/x86/mm/highmem_32.c 2011-05-22 19:36:30.000000000 -0400
21611@@ -44,7 +44,10 @@ void *kmap_atomic_prot(struct page *page
21612 idx = type + KM_TYPE_NR*smp_processor_id();
21613 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
21614 BUG_ON(!pte_none(*(kmap_pte-idx)));
21615+
21616+ pax_open_kernel();
21617 set_pte(kmap_pte-idx, mk_pte(page, prot));
21618+ pax_close_kernel();
21619
21620 return (void *)vaddr;
21621 }
21622diff -urNp linux-2.6.39.1/arch/x86/mm/hugetlbpage.c linux-2.6.39.1/arch/x86/mm/hugetlbpage.c
21623--- linux-2.6.39.1/arch/x86/mm/hugetlbpage.c 2011-05-19 00:06:34.000000000 -0400
21624+++ linux-2.6.39.1/arch/x86/mm/hugetlbpage.c 2011-05-22 19:36:30.000000000 -0400
21625@@ -266,13 +266,20 @@ static unsigned long hugetlb_get_unmappe
21626 struct hstate *h = hstate_file(file);
21627 struct mm_struct *mm = current->mm;
21628 struct vm_area_struct *vma;
21629- unsigned long start_addr;
21630+ unsigned long start_addr, pax_task_size = TASK_SIZE;
21631+
21632+#ifdef CONFIG_PAX_SEGMEXEC
21633+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
21634+ pax_task_size = SEGMEXEC_TASK_SIZE;
21635+#endif
21636+
21637+ pax_task_size -= PAGE_SIZE;
21638
21639 if (len > mm->cached_hole_size) {
21640- start_addr = mm->free_area_cache;
21641+ start_addr = mm->free_area_cache;
21642 } else {
21643- start_addr = TASK_UNMAPPED_BASE;
21644- mm->cached_hole_size = 0;
21645+ start_addr = mm->mmap_base;
21646+ mm->cached_hole_size = 0;
21647 }
21648
21649 full_search:
21650@@ -280,26 +287,27 @@ full_search:
21651
21652 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
21653 /* At this point: (!vma || addr < vma->vm_end). */
21654- if (TASK_SIZE - len < addr) {
21655+ if (pax_task_size - len < addr) {
21656 /*
21657 * Start a new search - just in case we missed
21658 * some holes.
21659 */
21660- if (start_addr != TASK_UNMAPPED_BASE) {
21661- start_addr = TASK_UNMAPPED_BASE;
21662+ if (start_addr != mm->mmap_base) {
21663+ start_addr = mm->mmap_base;
21664 mm->cached_hole_size = 0;
21665 goto full_search;
21666 }
21667 return -ENOMEM;
21668 }
21669- if (!vma || addr + len <= vma->vm_start) {
21670- mm->free_area_cache = addr + len;
21671- return addr;
21672- }
21673+ if (check_heap_stack_gap(vma, addr, len))
21674+ break;
21675 if (addr + mm->cached_hole_size < vma->vm_start)
21676 mm->cached_hole_size = vma->vm_start - addr;
21677 addr = ALIGN(vma->vm_end, huge_page_size(h));
21678 }
21679+
21680+ mm->free_area_cache = addr + len;
21681+ return addr;
21682 }
21683
21684 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
21685@@ -308,10 +316,9 @@ static unsigned long hugetlb_get_unmappe
21686 {
21687 struct hstate *h = hstate_file(file);
21688 struct mm_struct *mm = current->mm;
21689- struct vm_area_struct *vma, *prev_vma;
21690- unsigned long base = mm->mmap_base, addr = addr0;
21691+ struct vm_area_struct *vma;
21692+ unsigned long base = mm->mmap_base, addr;
21693 unsigned long largest_hole = mm->cached_hole_size;
21694- int first_time = 1;
21695
21696 /* don't allow allocations above current base */
21697 if (mm->free_area_cache > base)
21698@@ -321,64 +328,63 @@ static unsigned long hugetlb_get_unmappe
21699 largest_hole = 0;
21700 mm->free_area_cache = base;
21701 }
21702-try_again:
21703+
21704 /* make sure it can fit in the remaining address space */
21705 if (mm->free_area_cache < len)
21706 goto fail;
21707
21708 /* either no address requested or can't fit in requested address hole */
21709- addr = (mm->free_area_cache - len) & huge_page_mask(h);
21710+ addr = (mm->free_area_cache - len);
21711 do {
21712+ addr &= huge_page_mask(h);
21713+ vma = find_vma(mm, addr);
21714 /*
21715 * Lookup failure means no vma is above this address,
21716 * i.e. return with success:
21717- */
21718- if (!(vma = find_vma_prev(mm, addr, &prev_vma)))
21719- return addr;
21720-
21721- /*
21722 * new region fits between prev_vma->vm_end and
21723 * vma->vm_start, use it:
21724 */
21725- if (addr + len <= vma->vm_start &&
21726- (!prev_vma || (addr >= prev_vma->vm_end))) {
21727+ if (check_heap_stack_gap(vma, addr, len)) {
21728 /* remember the address as a hint for next time */
21729- mm->cached_hole_size = largest_hole;
21730- return (mm->free_area_cache = addr);
21731- } else {
21732- /* pull free_area_cache down to the first hole */
21733- if (mm->free_area_cache == vma->vm_end) {
21734- mm->free_area_cache = vma->vm_start;
21735- mm->cached_hole_size = largest_hole;
21736- }
21737+ mm->cached_hole_size = largest_hole;
21738+ return (mm->free_area_cache = addr);
21739+ }
21740+ /* pull free_area_cache down to the first hole */
21741+ if (mm->free_area_cache == vma->vm_end) {
21742+ mm->free_area_cache = vma->vm_start;
21743+ mm->cached_hole_size = largest_hole;
21744 }
21745
21746 /* remember the largest hole we saw so far */
21747 if (addr + largest_hole < vma->vm_start)
21748- largest_hole = vma->vm_start - addr;
21749+ largest_hole = vma->vm_start - addr;
21750
21751 /* try just below the current vma->vm_start */
21752- addr = (vma->vm_start - len) & huge_page_mask(h);
21753- } while (len <= vma->vm_start);
21754+ addr = skip_heap_stack_gap(vma, len);
21755+ } while (!IS_ERR_VALUE(addr));
21756
21757 fail:
21758 /*
21759- * if hint left us with no space for the requested
21760- * mapping then try again:
21761- */
21762- if (first_time) {
21763- mm->free_area_cache = base;
21764- largest_hole = 0;
21765- first_time = 0;
21766- goto try_again;
21767- }
21768- /*
21769 * A failed mmap() very likely causes application failure,
21770 * so fall back to the bottom-up function here. This scenario
21771 * can happen with large stack limits and large mmap()
21772 * allocations.
21773 */
21774- mm->free_area_cache = TASK_UNMAPPED_BASE;
21775+
21776+#ifdef CONFIG_PAX_SEGMEXEC
21777+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
21778+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
21779+ else
21780+#endif
21781+
21782+ mm->mmap_base = TASK_UNMAPPED_BASE;
21783+
21784+#ifdef CONFIG_PAX_RANDMMAP
21785+ if (mm->pax_flags & MF_PAX_RANDMMAP)
21786+ mm->mmap_base += mm->delta_mmap;
21787+#endif
21788+
21789+ mm->free_area_cache = mm->mmap_base;
21790 mm->cached_hole_size = ~0UL;
21791 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
21792 len, pgoff, flags);
21793@@ -386,6 +392,7 @@ fail:
21794 /*
21795 * Restore the topdown base:
21796 */
21797+ mm->mmap_base = base;
21798 mm->free_area_cache = base;
21799 mm->cached_hole_size = ~0UL;
21800
21801@@ -399,10 +406,19 @@ hugetlb_get_unmapped_area(struct file *f
21802 struct hstate *h = hstate_file(file);
21803 struct mm_struct *mm = current->mm;
21804 struct vm_area_struct *vma;
21805+ unsigned long pax_task_size = TASK_SIZE;
21806
21807 if (len & ~huge_page_mask(h))
21808 return -EINVAL;
21809- if (len > TASK_SIZE)
21810+
21811+#ifdef CONFIG_PAX_SEGMEXEC
21812+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
21813+ pax_task_size = SEGMEXEC_TASK_SIZE;
21814+#endif
21815+
21816+ pax_task_size -= PAGE_SIZE;
21817+
21818+ if (len > pax_task_size)
21819 return -ENOMEM;
21820
21821 if (flags & MAP_FIXED) {
21822@@ -414,8 +430,7 @@ hugetlb_get_unmapped_area(struct file *f
21823 if (addr) {
21824 addr = ALIGN(addr, huge_page_size(h));
21825 vma = find_vma(mm, addr);
21826- if (TASK_SIZE - len >= addr &&
21827- (!vma || addr + len <= vma->vm_start))
21828+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
21829 return addr;
21830 }
21831 if (mm->get_unmapped_area == arch_get_unmapped_area)
21832diff -urNp linux-2.6.39.1/arch/x86/mm/init_32.c linux-2.6.39.1/arch/x86/mm/init_32.c
21833--- linux-2.6.39.1/arch/x86/mm/init_32.c 2011-05-19 00:06:34.000000000 -0400
21834+++ linux-2.6.39.1/arch/x86/mm/init_32.c 2011-05-22 19:36:30.000000000 -0400
21835@@ -74,36 +74,6 @@ static __init void *alloc_low_page(void)
21836 }
21837
21838 /*
21839- * Creates a middle page table and puts a pointer to it in the
21840- * given global directory entry. This only returns the gd entry
21841- * in non-PAE compilation mode, since the middle layer is folded.
21842- */
21843-static pmd_t * __init one_md_table_init(pgd_t *pgd)
21844-{
21845- pud_t *pud;
21846- pmd_t *pmd_table;
21847-
21848-#ifdef CONFIG_X86_PAE
21849- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
21850- if (after_bootmem)
21851- pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
21852- else
21853- pmd_table = (pmd_t *)alloc_low_page();
21854- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
21855- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
21856- pud = pud_offset(pgd, 0);
21857- BUG_ON(pmd_table != pmd_offset(pud, 0));
21858-
21859- return pmd_table;
21860- }
21861-#endif
21862- pud = pud_offset(pgd, 0);
21863- pmd_table = pmd_offset(pud, 0);
21864-
21865- return pmd_table;
21866-}
21867-
21868-/*
21869 * Create a page table and place a pointer to it in a middle page
21870 * directory entry:
21871 */
21872@@ -123,13 +93,28 @@ static pte_t * __init one_page_table_ini
21873 page_table = (pte_t *)alloc_low_page();
21874
21875 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
21876+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
21877+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
21878+#else
21879 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
21880+#endif
21881 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
21882 }
21883
21884 return pte_offset_kernel(pmd, 0);
21885 }
21886
21887+static pmd_t * __init one_md_table_init(pgd_t *pgd)
21888+{
21889+ pud_t *pud;
21890+ pmd_t *pmd_table;
21891+
21892+ pud = pud_offset(pgd, 0);
21893+ pmd_table = pmd_offset(pud, 0);
21894+
21895+ return pmd_table;
21896+}
21897+
21898 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
21899 {
21900 int pgd_idx = pgd_index(vaddr);
21901@@ -203,6 +188,7 @@ page_table_range_init(unsigned long star
21902 int pgd_idx, pmd_idx;
21903 unsigned long vaddr;
21904 pgd_t *pgd;
21905+ pud_t *pud;
21906 pmd_t *pmd;
21907 pte_t *pte = NULL;
21908
21909@@ -212,8 +198,13 @@ page_table_range_init(unsigned long star
21910 pgd = pgd_base + pgd_idx;
21911
21912 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
21913- pmd = one_md_table_init(pgd);
21914- pmd = pmd + pmd_index(vaddr);
21915+ pud = pud_offset(pgd, vaddr);
21916+ pmd = pmd_offset(pud, vaddr);
21917+
21918+#ifdef CONFIG_X86_PAE
21919+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
21920+#endif
21921+
21922 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
21923 pmd++, pmd_idx++) {
21924 pte = page_table_kmap_check(one_page_table_init(pmd),
21925@@ -225,11 +216,20 @@ page_table_range_init(unsigned long star
21926 }
21927 }
21928
21929-static inline int is_kernel_text(unsigned long addr)
21930+static inline int is_kernel_text(unsigned long start, unsigned long end)
21931 {
21932- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
21933- return 1;
21934- return 0;
21935+ if ((start > ktla_ktva((unsigned long)_etext) ||
21936+ end <= ktla_ktva((unsigned long)_stext)) &&
21937+ (start > ktla_ktva((unsigned long)_einittext) ||
21938+ end <= ktla_ktva((unsigned long)_sinittext)) &&
21939+
21940+#ifdef CONFIG_ACPI_SLEEP
21941+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
21942+#endif
21943+
21944+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
21945+ return 0;
21946+ return 1;
21947 }
21948
21949 /*
21950@@ -246,9 +246,10 @@ kernel_physical_mapping_init(unsigned lo
21951 unsigned long last_map_addr = end;
21952 unsigned long start_pfn, end_pfn;
21953 pgd_t *pgd_base = swapper_pg_dir;
21954- int pgd_idx, pmd_idx, pte_ofs;
21955+ unsigned int pgd_idx, pmd_idx, pte_ofs;
21956 unsigned long pfn;
21957 pgd_t *pgd;
21958+ pud_t *pud;
21959 pmd_t *pmd;
21960 pte_t *pte;
21961 unsigned pages_2m, pages_4k;
21962@@ -281,8 +282,13 @@ repeat:
21963 pfn = start_pfn;
21964 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
21965 pgd = pgd_base + pgd_idx;
21966- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
21967- pmd = one_md_table_init(pgd);
21968+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
21969+ pud = pud_offset(pgd, 0);
21970+ pmd = pmd_offset(pud, 0);
21971+
21972+#ifdef CONFIG_X86_PAE
21973+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
21974+#endif
21975
21976 if (pfn >= end_pfn)
21977 continue;
21978@@ -294,14 +300,13 @@ repeat:
21979 #endif
21980 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
21981 pmd++, pmd_idx++) {
21982- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
21983+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
21984
21985 /*
21986 * Map with big pages if possible, otherwise
21987 * create normal page tables:
21988 */
21989 if (use_pse) {
21990- unsigned int addr2;
21991 pgprot_t prot = PAGE_KERNEL_LARGE;
21992 /*
21993 * first pass will use the same initial
21994@@ -311,11 +316,7 @@ repeat:
21995 __pgprot(PTE_IDENT_ATTR |
21996 _PAGE_PSE);
21997
21998- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
21999- PAGE_OFFSET + PAGE_SIZE-1;
22000-
22001- if (is_kernel_text(addr) ||
22002- is_kernel_text(addr2))
22003+ if (is_kernel_text(address, address + PMD_SIZE))
22004 prot = PAGE_KERNEL_LARGE_EXEC;
22005
22006 pages_2m++;
22007@@ -332,7 +333,7 @@ repeat:
22008 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
22009 pte += pte_ofs;
22010 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
22011- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
22012+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
22013 pgprot_t prot = PAGE_KERNEL;
22014 /*
22015 * first pass will use the same initial
22016@@ -340,7 +341,7 @@ repeat:
22017 */
22018 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
22019
22020- if (is_kernel_text(addr))
22021+ if (is_kernel_text(address, address + PAGE_SIZE))
22022 prot = PAGE_KERNEL_EXEC;
22023
22024 pages_4k++;
22025@@ -472,7 +473,7 @@ void __init native_pagetable_setup_start
22026
22027 pud = pud_offset(pgd, va);
22028 pmd = pmd_offset(pud, va);
22029- if (!pmd_present(*pmd))
22030+ if (!pmd_present(*pmd) || pmd_huge(*pmd))
22031 break;
22032
22033 pte = pte_offset_kernel(pmd, va);
22034@@ -524,12 +525,10 @@ void __init early_ioremap_page_table_ran
22035
22036 static void __init pagetable_init(void)
22037 {
22038- pgd_t *pgd_base = swapper_pg_dir;
22039-
22040- permanent_kmaps_init(pgd_base);
22041+ permanent_kmaps_init(swapper_pg_dir);
22042 }
22043
22044-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
22045+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
22046 EXPORT_SYMBOL_GPL(__supported_pte_mask);
22047
22048 /* user-defined highmem size */
22049@@ -754,6 +753,12 @@ void __init mem_init(void)
22050
22051 pci_iommu_alloc();
22052
22053+#ifdef CONFIG_PAX_PER_CPU_PGD
22054+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
22055+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
22056+ KERNEL_PGD_PTRS);
22057+#endif
22058+
22059 #ifdef CONFIG_FLATMEM
22060 BUG_ON(!mem_map);
22061 #endif
22062@@ -771,7 +776,7 @@ void __init mem_init(void)
22063 set_highmem_pages_init();
22064
22065 codesize = (unsigned long) &_etext - (unsigned long) &_text;
22066- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
22067+ datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
22068 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
22069
22070 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
22071@@ -812,10 +817,10 @@ void __init mem_init(void)
22072 ((unsigned long)&__init_end -
22073 (unsigned long)&__init_begin) >> 10,
22074
22075- (unsigned long)&_etext, (unsigned long)&_edata,
22076- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
22077+ (unsigned long)&_sdata, (unsigned long)&_edata,
22078+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
22079
22080- (unsigned long)&_text, (unsigned long)&_etext,
22081+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
22082 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
22083
22084 /*
22085@@ -893,6 +898,7 @@ void set_kernel_text_rw(void)
22086 if (!kernel_set_to_readonly)
22087 return;
22088
22089+ start = ktla_ktva(start);
22090 pr_debug("Set kernel text: %lx - %lx for read write\n",
22091 start, start+size);
22092
22093@@ -907,6 +913,7 @@ void set_kernel_text_ro(void)
22094 if (!kernel_set_to_readonly)
22095 return;
22096
22097+ start = ktla_ktva(start);
22098 pr_debug("Set kernel text: %lx - %lx for read only\n",
22099 start, start+size);
22100
22101@@ -935,6 +942,7 @@ void mark_rodata_ro(void)
22102 unsigned long start = PFN_ALIGN(_text);
22103 unsigned long size = PFN_ALIGN(_etext) - start;
22104
22105+ start = ktla_ktva(start);
22106 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
22107 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
22108 size >> 10);
22109diff -urNp linux-2.6.39.1/arch/x86/mm/init_64.c linux-2.6.39.1/arch/x86/mm/init_64.c
22110--- linux-2.6.39.1/arch/x86/mm/init_64.c 2011-05-19 00:06:34.000000000 -0400
22111+++ linux-2.6.39.1/arch/x86/mm/init_64.c 2011-05-22 19:36:30.000000000 -0400
22112@@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpa
22113 * around without checking the pgd every time.
22114 */
22115
22116-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
22117+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
22118 EXPORT_SYMBOL_GPL(__supported_pte_mask);
22119
22120 int force_personality32;
22121@@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long star
22122
22123 for (address = start; address <= end; address += PGDIR_SIZE) {
22124 const pgd_t *pgd_ref = pgd_offset_k(address);
22125+
22126+#ifdef CONFIG_PAX_PER_CPU_PGD
22127+ unsigned long cpu;
22128+#else
22129 struct page *page;
22130+#endif
22131
22132 if (pgd_none(*pgd_ref))
22133 continue;
22134
22135 spin_lock(&pgd_lock);
22136+
22137+#ifdef CONFIG_PAX_PER_CPU_PGD
22138+ for (cpu = 0; cpu < NR_CPUS; ++cpu) {
22139+ pgd_t *pgd = pgd_offset_cpu(cpu, address);
22140+#else
22141 list_for_each_entry(page, &pgd_list, lru) {
22142 pgd_t *pgd;
22143 spinlock_t *pgt_lock;
22144@@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long star
22145 /* the pgt_lock only for Xen */
22146 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
22147 spin_lock(pgt_lock);
22148+#endif
22149
22150 if (pgd_none(*pgd))
22151 set_pgd(pgd, *pgd_ref);
22152@@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long star
22153 BUG_ON(pgd_page_vaddr(*pgd)
22154 != pgd_page_vaddr(*pgd_ref));
22155
22156+#ifndef CONFIG_PAX_PER_CPU_PGD
22157 spin_unlock(pgt_lock);
22158+#endif
22159+
22160 }
22161 spin_unlock(&pgd_lock);
22162 }
22163@@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page,
22164 pmd = fill_pmd(pud, vaddr);
22165 pte = fill_pte(pmd, vaddr);
22166
22167+ pax_open_kernel();
22168 set_pte(pte, new_pte);
22169+ pax_close_kernel();
22170
22171 /*
22172 * It's enough to flush this one mapping.
22173@@ -261,14 +277,12 @@ static void __init __init_extra_mapping(
22174 pgd = pgd_offset_k((unsigned long)__va(phys));
22175 if (pgd_none(*pgd)) {
22176 pud = (pud_t *) spp_getpage();
22177- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
22178- _PAGE_USER));
22179+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
22180 }
22181 pud = pud_offset(pgd, (unsigned long)__va(phys));
22182 if (pud_none(*pud)) {
22183 pmd = (pmd_t *) spp_getpage();
22184- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
22185- _PAGE_USER));
22186+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
22187 }
22188 pmd = pmd_offset(pud, phys);
22189 BUG_ON(!pmd_none(*pmd));
22190@@ -698,6 +712,12 @@ void __init mem_init(void)
22191
22192 pci_iommu_alloc();
22193
22194+#ifdef CONFIG_PAX_PER_CPU_PGD
22195+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
22196+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
22197+ KERNEL_PGD_PTRS);
22198+#endif
22199+
22200 /* clear_bss() already clear the empty_zero_page */
22201
22202 reservedpages = 0;
22203@@ -858,8 +878,8 @@ int kern_addr_valid(unsigned long addr)
22204 static struct vm_area_struct gate_vma = {
22205 .vm_start = VSYSCALL_START,
22206 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
22207- .vm_page_prot = PAGE_READONLY_EXEC,
22208- .vm_flags = VM_READ | VM_EXEC
22209+ .vm_page_prot = PAGE_READONLY,
22210+ .vm_flags = VM_READ
22211 };
22212
22213 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
22214@@ -893,7 +913,7 @@ int in_gate_area_no_mm(unsigned long add
22215
22216 const char *arch_vma_name(struct vm_area_struct *vma)
22217 {
22218- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
22219+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
22220 return "[vdso]";
22221 if (vma == &gate_vma)
22222 return "[vsyscall]";
22223diff -urNp linux-2.6.39.1/arch/x86/mm/init.c linux-2.6.39.1/arch/x86/mm/init.c
22224--- linux-2.6.39.1/arch/x86/mm/init.c 2011-05-19 00:06:34.000000000 -0400
22225+++ linux-2.6.39.1/arch/x86/mm/init.c 2011-06-07 19:41:11.000000000 -0400
22226@@ -33,7 +33,7 @@ int direct_gbpages
22227 static void __init find_early_table_space(unsigned long end, int use_pse,
22228 int use_gbpages)
22229 {
22230- unsigned long puds, pmds, ptes, tables, start = 0, good_end = end;
22231+ unsigned long puds, pmds, ptes, tables, start = 0x100000, good_end = end;
22232 phys_addr_t base;
22233
22234 puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
22235@@ -315,12 +315,34 @@ unsigned long __init_refok init_memory_m
22236 */
22237 int devmem_is_allowed(unsigned long pagenr)
22238 {
22239- if (pagenr <= 256)
22240+#ifdef CONFIG_GRKERNSEC_KMEM
22241+ /* allow BDA */
22242+ if (!pagenr)
22243+ return 1;
22244+ /* allow EBDA */
22245+ if ((0x9f000 >> PAGE_SHIFT) == pagenr)
22246+ return 1;
22247+#else
22248+ if (!pagenr)
22249+ return 1;
22250+#ifdef CONFIG_VM86
22251+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
22252+ return 1;
22253+#endif
22254+#endif
22255+
22256+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
22257 return 1;
22258+#ifdef CONFIG_GRKERNSEC_KMEM
22259+ /* throw out everything else below 1MB */
22260+ if (pagenr <= 256)
22261+ return 0;
22262+#endif
22263 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
22264 return 0;
22265 if (!page_is_ram(pagenr))
22266 return 1;
22267+
22268 return 0;
22269 }
22270
22271@@ -375,6 +397,86 @@ void free_init_pages(char *what, unsigne
22272
22273 void free_initmem(void)
22274 {
22275+
22276+#ifdef CONFIG_PAX_KERNEXEC
22277+#ifdef CONFIG_X86_32
22278+ /* PaX: limit KERNEL_CS to actual size */
22279+ unsigned long addr, limit;
22280+ struct desc_struct d;
22281+ int cpu;
22282+
22283+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
22284+ limit = (limit - 1UL) >> PAGE_SHIFT;
22285+
22286+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
22287+ for (cpu = 0; cpu < NR_CPUS; cpu++) {
22288+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
22289+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
22290+ }
22291+
22292+ /* PaX: make KERNEL_CS read-only */
22293+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
22294+ if (!paravirt_enabled())
22295+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
22296+/*
22297+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
22298+ pgd = pgd_offset_k(addr);
22299+ pud = pud_offset(pgd, addr);
22300+ pmd = pmd_offset(pud, addr);
22301+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
22302+ }
22303+*/
22304+#ifdef CONFIG_X86_PAE
22305+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
22306+/*
22307+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
22308+ pgd = pgd_offset_k(addr);
22309+ pud = pud_offset(pgd, addr);
22310+ pmd = pmd_offset(pud, addr);
22311+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
22312+ }
22313+*/
22314+#endif
22315+
22316+#ifdef CONFIG_MODULES
22317+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
22318+#endif
22319+
22320+#else
22321+ pgd_t *pgd;
22322+ pud_t *pud;
22323+ pmd_t *pmd;
22324+ unsigned long addr, end;
22325+
22326+ /* PaX: make kernel code/rodata read-only, rest non-executable */
22327+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
22328+ pgd = pgd_offset_k(addr);
22329+ pud = pud_offset(pgd, addr);
22330+ pmd = pmd_offset(pud, addr);
22331+ if (!pmd_present(*pmd))
22332+ continue;
22333+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
22334+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
22335+ else
22336+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
22337+ }
22338+
22339+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
22340+ end = addr + KERNEL_IMAGE_SIZE;
22341+ for (; addr < end; addr += PMD_SIZE) {
22342+ pgd = pgd_offset_k(addr);
22343+ pud = pud_offset(pgd, addr);
22344+ pmd = pmd_offset(pud, addr);
22345+ if (!pmd_present(*pmd))
22346+ continue;
22347+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
22348+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
22349+ }
22350+#endif
22351+
22352+ flush_tlb_all();
22353+#endif
22354+
22355 free_init_pages("unused kernel memory",
22356 (unsigned long)(&__init_begin),
22357 (unsigned long)(&__init_end));
22358diff -urNp linux-2.6.39.1/arch/x86/mm/iomap_32.c linux-2.6.39.1/arch/x86/mm/iomap_32.c
22359--- linux-2.6.39.1/arch/x86/mm/iomap_32.c 2011-05-19 00:06:34.000000000 -0400
22360+++ linux-2.6.39.1/arch/x86/mm/iomap_32.c 2011-05-22 19:36:30.000000000 -0400
22361@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long
22362 type = kmap_atomic_idx_push();
22363 idx = type + KM_TYPE_NR * smp_processor_id();
22364 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
22365+
22366+ pax_open_kernel();
22367 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
22368+ pax_close_kernel();
22369+
22370 arch_flush_lazy_mmu_mode();
22371
22372 return (void *)vaddr;
22373diff -urNp linux-2.6.39.1/arch/x86/mm/ioremap.c linux-2.6.39.1/arch/x86/mm/ioremap.c
22374--- linux-2.6.39.1/arch/x86/mm/ioremap.c 2011-05-19 00:06:34.000000000 -0400
22375+++ linux-2.6.39.1/arch/x86/mm/ioremap.c 2011-05-22 19:36:30.000000000 -0400
22376@@ -104,7 +104,7 @@ static void __iomem *__ioremap_caller(re
22377 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
22378 int is_ram = page_is_ram(pfn);
22379
22380- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
22381+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
22382 return NULL;
22383 WARN_ON_ONCE(is_ram);
22384 }
22385@@ -344,7 +344,7 @@ static int __init early_ioremap_debug_se
22386 early_param("early_ioremap_debug", early_ioremap_debug_setup);
22387
22388 static __initdata int after_paging_init;
22389-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
22390+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
22391
22392 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
22393 {
22394@@ -381,8 +381,7 @@ void __init early_ioremap_init(void)
22395 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
22396
22397 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
22398- memset(bm_pte, 0, sizeof(bm_pte));
22399- pmd_populate_kernel(&init_mm, pmd, bm_pte);
22400+ pmd_populate_user(&init_mm, pmd, bm_pte);
22401
22402 /*
22403 * The boot-ioremap range spans multiple pmds, for which
22404diff -urNp linux-2.6.39.1/arch/x86/mm/kmemcheck/kmemcheck.c linux-2.6.39.1/arch/x86/mm/kmemcheck/kmemcheck.c
22405--- linux-2.6.39.1/arch/x86/mm/kmemcheck/kmemcheck.c 2011-05-19 00:06:34.000000000 -0400
22406+++ linux-2.6.39.1/arch/x86/mm/kmemcheck/kmemcheck.c 2011-05-22 19:36:30.000000000 -0400
22407@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *reg
22408 * memory (e.g. tracked pages)? For now, we need this to avoid
22409 * invoking kmemcheck for PnP BIOS calls.
22410 */
22411- if (regs->flags & X86_VM_MASK)
22412+ if (v8086_mode(regs))
22413 return false;
22414- if (regs->cs != __KERNEL_CS)
22415+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
22416 return false;
22417
22418 pte = kmemcheck_pte_lookup(address);
22419diff -urNp linux-2.6.39.1/arch/x86/mm/mmap.c linux-2.6.39.1/arch/x86/mm/mmap.c
22420--- linux-2.6.39.1/arch/x86/mm/mmap.c 2011-05-19 00:06:34.000000000 -0400
22421+++ linux-2.6.39.1/arch/x86/mm/mmap.c 2011-05-22 19:36:30.000000000 -0400
22422@@ -49,7 +49,7 @@ static unsigned int stack_maxrandom_size
22423 * Leave an at least ~128 MB hole with possible stack randomization.
22424 */
22425 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
22426-#define MAX_GAP (TASK_SIZE/6*5)
22427+#define MAX_GAP (pax_task_size/6*5)
22428
22429 /*
22430 * True on X86_32 or when emulating IA32 on X86_64
22431@@ -94,27 +94,40 @@ static unsigned long mmap_rnd(void)
22432 return rnd << PAGE_SHIFT;
22433 }
22434
22435-static unsigned long mmap_base(void)
22436+static unsigned long mmap_base(struct mm_struct *mm)
22437 {
22438 unsigned long gap = rlimit(RLIMIT_STACK);
22439+ unsigned long pax_task_size = TASK_SIZE;
22440+
22441+#ifdef CONFIG_PAX_SEGMEXEC
22442+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
22443+ pax_task_size = SEGMEXEC_TASK_SIZE;
22444+#endif
22445
22446 if (gap < MIN_GAP)
22447 gap = MIN_GAP;
22448 else if (gap > MAX_GAP)
22449 gap = MAX_GAP;
22450
22451- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
22452+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
22453 }
22454
22455 /*
22456 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
22457 * does, but not when emulating X86_32
22458 */
22459-static unsigned long mmap_legacy_base(void)
22460+static unsigned long mmap_legacy_base(struct mm_struct *mm)
22461 {
22462- if (mmap_is_ia32())
22463+ if (mmap_is_ia32()) {
22464+
22465+#ifdef CONFIG_PAX_SEGMEXEC
22466+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
22467+ return SEGMEXEC_TASK_UNMAPPED_BASE;
22468+ else
22469+#endif
22470+
22471 return TASK_UNMAPPED_BASE;
22472- else
22473+ } else
22474 return TASK_UNMAPPED_BASE + mmap_rnd();
22475 }
22476
22477@@ -125,11 +138,23 @@ static unsigned long mmap_legacy_base(vo
22478 void arch_pick_mmap_layout(struct mm_struct *mm)
22479 {
22480 if (mmap_is_legacy()) {
22481- mm->mmap_base = mmap_legacy_base();
22482+ mm->mmap_base = mmap_legacy_base(mm);
22483+
22484+#ifdef CONFIG_PAX_RANDMMAP
22485+ if (mm->pax_flags & MF_PAX_RANDMMAP)
22486+ mm->mmap_base += mm->delta_mmap;
22487+#endif
22488+
22489 mm->get_unmapped_area = arch_get_unmapped_area;
22490 mm->unmap_area = arch_unmap_area;
22491 } else {
22492- mm->mmap_base = mmap_base();
22493+ mm->mmap_base = mmap_base(mm);
22494+
22495+#ifdef CONFIG_PAX_RANDMMAP
22496+ if (mm->pax_flags & MF_PAX_RANDMMAP)
22497+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
22498+#endif
22499+
22500 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
22501 mm->unmap_area = arch_unmap_area_topdown;
22502 }
22503diff -urNp linux-2.6.39.1/arch/x86/mm/mmio-mod.c linux-2.6.39.1/arch/x86/mm/mmio-mod.c
22504--- linux-2.6.39.1/arch/x86/mm/mmio-mod.c 2011-05-19 00:06:34.000000000 -0400
22505+++ linux-2.6.39.1/arch/x86/mm/mmio-mod.c 2011-05-22 19:36:30.000000000 -0400
22506@@ -235,7 +235,7 @@ static void post(struct kmmio_probe *p,
22507 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
22508 void __iomem *addr)
22509 {
22510- static atomic_t next_id;
22511+ static atomic_unchecked_t next_id;
22512 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
22513 /* These are page-unaligned. */
22514 struct mmiotrace_map map = {
22515@@ -259,7 +259,7 @@ static void ioremap_trace_core(resource_
22516 .private = trace
22517 },
22518 .phys = offset,
22519- .id = atomic_inc_return(&next_id)
22520+ .id = atomic_inc_return_unchecked(&next_id)
22521 };
22522 map.map_id = trace->id;
22523
22524diff -urNp linux-2.6.39.1/arch/x86/mm/numa_32.c linux-2.6.39.1/arch/x86/mm/numa_32.c
22525--- linux-2.6.39.1/arch/x86/mm/numa_32.c 2011-05-19 00:06:34.000000000 -0400
22526+++ linux-2.6.39.1/arch/x86/mm/numa_32.c 2011-05-22 19:36:30.000000000 -0400
22527@@ -99,7 +99,6 @@ unsigned long node_memmap_size_bytes(int
22528 }
22529 #endif
22530
22531-extern unsigned long find_max_low_pfn(void);
22532 extern unsigned long highend_pfn, highstart_pfn;
22533
22534 #define LARGE_PAGE_BYTES (PTRS_PER_PTE * PAGE_SIZE)
22535diff -urNp linux-2.6.39.1/arch/x86/mm/pageattr.c linux-2.6.39.1/arch/x86/mm/pageattr.c
22536--- linux-2.6.39.1/arch/x86/mm/pageattr.c 2011-05-19 00:06:34.000000000 -0400
22537+++ linux-2.6.39.1/arch/x86/mm/pageattr.c 2011-05-22 19:36:30.000000000 -0400
22538@@ -261,7 +261,7 @@ static inline pgprot_t static_protection
22539 */
22540 #ifdef CONFIG_PCI_BIOS
22541 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
22542- pgprot_val(forbidden) |= _PAGE_NX;
22543+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
22544 #endif
22545
22546 /*
22547@@ -269,9 +269,10 @@ static inline pgprot_t static_protection
22548 * Does not cover __inittext since that is gone later on. On
22549 * 64bit we do not enforce !NX on the low mapping
22550 */
22551- if (within(address, (unsigned long)_text, (unsigned long)_etext))
22552- pgprot_val(forbidden) |= _PAGE_NX;
22553+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
22554+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
22555
22556+#ifdef CONFIG_DEBUG_RODATA
22557 /*
22558 * The .rodata section needs to be read-only. Using the pfn
22559 * catches all aliases.
22560@@ -279,6 +280,7 @@ static inline pgprot_t static_protection
22561 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
22562 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
22563 pgprot_val(forbidden) |= _PAGE_RW;
22564+#endif
22565
22566 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
22567 /*
22568@@ -317,6 +319,13 @@ static inline pgprot_t static_protection
22569 }
22570 #endif
22571
22572+#ifdef CONFIG_PAX_KERNEXEC
22573+ if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
22574+ pgprot_val(forbidden) |= _PAGE_RW;
22575+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
22576+ }
22577+#endif
22578+
22579 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
22580
22581 return prot;
22582@@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
22583 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
22584 {
22585 /* change init_mm */
22586+ pax_open_kernel();
22587 set_pte_atomic(kpte, pte);
22588+
22589 #ifdef CONFIG_X86_32
22590 if (!SHARED_KERNEL_PMD) {
22591+
22592+#ifdef CONFIG_PAX_PER_CPU_PGD
22593+ unsigned long cpu;
22594+#else
22595 struct page *page;
22596+#endif
22597
22598+#ifdef CONFIG_PAX_PER_CPU_PGD
22599+ for (cpu = 0; cpu < NR_CPUS; ++cpu) {
22600+ pgd_t *pgd = get_cpu_pgd(cpu);
22601+#else
22602 list_for_each_entry(page, &pgd_list, lru) {
22603- pgd_t *pgd;
22604+ pgd_t *pgd = (pgd_t *)page_address(page);
22605+#endif
22606+
22607 pud_t *pud;
22608 pmd_t *pmd;
22609
22610- pgd = (pgd_t *)page_address(page) + pgd_index(address);
22611+ pgd += pgd_index(address);
22612 pud = pud_offset(pgd, address);
22613 pmd = pmd_offset(pud, address);
22614 set_pte_atomic((pte_t *)pmd, pte);
22615 }
22616 }
22617 #endif
22618+ pax_close_kernel();
22619 }
22620
22621 static int
22622diff -urNp linux-2.6.39.1/arch/x86/mm/pageattr-test.c linux-2.6.39.1/arch/x86/mm/pageattr-test.c
22623--- linux-2.6.39.1/arch/x86/mm/pageattr-test.c 2011-05-19 00:06:34.000000000 -0400
22624+++ linux-2.6.39.1/arch/x86/mm/pageattr-test.c 2011-05-22 19:36:30.000000000 -0400
22625@@ -36,7 +36,7 @@ enum {
22626
22627 static int pte_testbit(pte_t pte)
22628 {
22629- return pte_flags(pte) & _PAGE_UNUSED1;
22630+ return pte_flags(pte) & _PAGE_CPA_TEST;
22631 }
22632
22633 struct split_state {
22634diff -urNp linux-2.6.39.1/arch/x86/mm/pat.c linux-2.6.39.1/arch/x86/mm/pat.c
22635--- linux-2.6.39.1/arch/x86/mm/pat.c 2011-05-19 00:06:34.000000000 -0400
22636+++ linux-2.6.39.1/arch/x86/mm/pat.c 2011-05-22 19:36:30.000000000 -0400
22637@@ -361,7 +361,7 @@ int free_memtype(u64 start, u64 end)
22638
22639 if (!entry) {
22640 printk(KERN_INFO "%s:%d freeing invalid memtype %Lx-%Lx\n",
22641- current->comm, current->pid, start, end);
22642+ current->comm, task_pid_nr(current), start, end);
22643 return -EINVAL;
22644 }
22645
22646@@ -492,8 +492,8 @@ static inline int range_is_allowed(unsig
22647 while (cursor < to) {
22648 if (!devmem_is_allowed(pfn)) {
22649 printk(KERN_INFO
22650- "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
22651- current->comm, from, to);
22652+ "Program %s tried to access /dev/mem between %Lx->%Lx (%Lx).\n",
22653+ current->comm, from, to, cursor);
22654 return 0;
22655 }
22656 cursor += PAGE_SIZE;
22657@@ -557,7 +557,7 @@ int kernel_map_sync_memtype(u64 base, un
22658 printk(KERN_INFO
22659 "%s:%d ioremap_change_attr failed %s "
22660 "for %Lx-%Lx\n",
22661- current->comm, current->pid,
22662+ current->comm, task_pid_nr(current),
22663 cattr_name(flags),
22664 base, (unsigned long long)(base + size));
22665 return -EINVAL;
22666@@ -593,7 +593,7 @@ static int reserve_pfn_range(u64 paddr,
22667 if (want_flags != flags) {
22668 printk(KERN_WARNING
22669 "%s:%d map pfn RAM range req %s for %Lx-%Lx, got %s\n",
22670- current->comm, current->pid,
22671+ current->comm, task_pid_nr(current),
22672 cattr_name(want_flags),
22673 (unsigned long long)paddr,
22674 (unsigned long long)(paddr + size),
22675@@ -615,7 +615,7 @@ static int reserve_pfn_range(u64 paddr,
22676 free_memtype(paddr, paddr + size);
22677 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
22678 " for %Lx-%Lx, got %s\n",
22679- current->comm, current->pid,
22680+ current->comm, task_pid_nr(current),
22681 cattr_name(want_flags),
22682 (unsigned long long)paddr,
22683 (unsigned long long)(paddr + size),
22684diff -urNp linux-2.6.39.1/arch/x86/mm/pgtable_32.c linux-2.6.39.1/arch/x86/mm/pgtable_32.c
22685--- linux-2.6.39.1/arch/x86/mm/pgtable_32.c 2011-05-19 00:06:34.000000000 -0400
22686+++ linux-2.6.39.1/arch/x86/mm/pgtable_32.c 2011-05-22 19:36:30.000000000 -0400
22687@@ -48,10 +48,13 @@ void set_pte_vaddr(unsigned long vaddr,
22688 return;
22689 }
22690 pte = pte_offset_kernel(pmd, vaddr);
22691+
22692+ pax_open_kernel();
22693 if (pte_val(pteval))
22694 set_pte_at(&init_mm, vaddr, pte, pteval);
22695 else
22696 pte_clear(&init_mm, vaddr, pte);
22697+ pax_close_kernel();
22698
22699 /*
22700 * It's enough to flush this one mapping.
22701diff -urNp linux-2.6.39.1/arch/x86/mm/pgtable.c linux-2.6.39.1/arch/x86/mm/pgtable.c
22702--- linux-2.6.39.1/arch/x86/mm/pgtable.c 2011-05-19 00:06:34.000000000 -0400
22703+++ linux-2.6.39.1/arch/x86/mm/pgtable.c 2011-05-22 19:36:30.000000000 -0400
22704@@ -84,10 +84,52 @@ static inline void pgd_list_del(pgd_t *p
22705 list_del(&page->lru);
22706 }
22707
22708-#define UNSHARED_PTRS_PER_PGD \
22709- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
22710+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22711+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
22712
22713+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count)
22714+{
22715+ while (count--)
22716+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
22717+}
22718+#endif
22719+
22720+#ifdef CONFIG_PAX_PER_CPU_PGD
22721+void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count)
22722+{
22723+ while (count--)
22724+
22725+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22726+ *dst++ = __pgd(pgd_val(*src++) & clone_pgd_mask);
22727+#else
22728+ *dst++ = *src++;
22729+#endif
22730
22731+}
22732+#endif
22733+
22734+#ifdef CONFIG_X86_64
22735+#define pxd_t pud_t
22736+#define pyd_t pgd_t
22737+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
22738+#define pxd_free(mm, pud) pud_free((mm), (pud))
22739+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
22740+#define pyd_offset(mm ,address) pgd_offset((mm), (address))
22741+#define PYD_SIZE PGDIR_SIZE
22742+#else
22743+#define pxd_t pmd_t
22744+#define pyd_t pud_t
22745+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
22746+#define pxd_free(mm, pud) pmd_free((mm), (pud))
22747+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
22748+#define pyd_offset(mm ,address) pud_offset((mm), (address))
22749+#define PYD_SIZE PUD_SIZE
22750+#endif
22751+
22752+#ifdef CONFIG_PAX_PER_CPU_PGD
22753+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
22754+static inline void pgd_dtor(pgd_t *pgd) {}
22755+#else
22756 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
22757 {
22758 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
22759@@ -128,6 +170,7 @@ static void pgd_dtor(pgd_t *pgd)
22760 pgd_list_del(pgd);
22761 spin_unlock(&pgd_lock);
22762 }
22763+#endif
22764
22765 /*
22766 * List of all pgd's needed for non-PAE so it can invalidate entries
22767@@ -140,7 +183,7 @@ static void pgd_dtor(pgd_t *pgd)
22768 * -- wli
22769 */
22770
22771-#ifdef CONFIG_X86_PAE
22772+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
22773 /*
22774 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
22775 * updating the top-level pagetable entries to guarantee the
22776@@ -152,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
22777 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
22778 * and initialize the kernel pmds here.
22779 */
22780-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
22781+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
22782
22783 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
22784 {
22785@@ -170,36 +213,38 @@ void pud_populate(struct mm_struct *mm,
22786 */
22787 flush_tlb_mm(mm);
22788 }
22789+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
22790+#define PREALLOCATED_PXDS USER_PGD_PTRS
22791 #else /* !CONFIG_X86_PAE */
22792
22793 /* No need to prepopulate any pagetable entries in non-PAE modes. */
22794-#define PREALLOCATED_PMDS 0
22795+#define PREALLOCATED_PXDS 0
22796
22797 #endif /* CONFIG_X86_PAE */
22798
22799-static void free_pmds(pmd_t *pmds[])
22800+static void free_pxds(pxd_t *pxds[])
22801 {
22802 int i;
22803
22804- for(i = 0; i < PREALLOCATED_PMDS; i++)
22805- if (pmds[i])
22806- free_page((unsigned long)pmds[i]);
22807+ for(i = 0; i < PREALLOCATED_PXDS; i++)
22808+ if (pxds[i])
22809+ free_page((unsigned long)pxds[i]);
22810 }
22811
22812-static int preallocate_pmds(pmd_t *pmds[])
22813+static int preallocate_pxds(pxd_t *pxds[])
22814 {
22815 int i;
22816 bool failed = false;
22817
22818- for(i = 0; i < PREALLOCATED_PMDS; i++) {
22819- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
22820- if (pmd == NULL)
22821+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
22822+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
22823+ if (pxd == NULL)
22824 failed = true;
22825- pmds[i] = pmd;
22826+ pxds[i] = pxd;
22827 }
22828
22829 if (failed) {
22830- free_pmds(pmds);
22831+ free_pxds(pxds);
22832 return -ENOMEM;
22833 }
22834
22835@@ -212,51 +257,55 @@ static int preallocate_pmds(pmd_t *pmds[
22836 * preallocate which never got a corresponding vma will need to be
22837 * freed manually.
22838 */
22839-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
22840+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
22841 {
22842 int i;
22843
22844- for(i = 0; i < PREALLOCATED_PMDS; i++) {
22845+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
22846 pgd_t pgd = pgdp[i];
22847
22848 if (pgd_val(pgd) != 0) {
22849- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
22850+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
22851
22852- pgdp[i] = native_make_pgd(0);
22853+ set_pgd(pgdp + i, native_make_pgd(0));
22854
22855- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
22856- pmd_free(mm, pmd);
22857+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
22858+ pxd_free(mm, pxd);
22859 }
22860 }
22861 }
22862
22863-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
22864+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
22865 {
22866- pud_t *pud;
22867+ pyd_t *pyd;
22868 unsigned long addr;
22869 int i;
22870
22871- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
22872+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
22873 return;
22874
22875- pud = pud_offset(pgd, 0);
22876+#ifdef CONFIG_X86_64
22877+ pyd = pyd_offset(mm, 0L);
22878+#else
22879+ pyd = pyd_offset(pgd, 0L);
22880+#endif
22881
22882- for (addr = i = 0; i < PREALLOCATED_PMDS;
22883- i++, pud++, addr += PUD_SIZE) {
22884- pmd_t *pmd = pmds[i];
22885+ for (addr = i = 0; i < PREALLOCATED_PXDS;
22886+ i++, pyd++, addr += PYD_SIZE) {
22887+ pxd_t *pxd = pxds[i];
22888
22889 if (i >= KERNEL_PGD_BOUNDARY)
22890- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
22891- sizeof(pmd_t) * PTRS_PER_PMD);
22892+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
22893+ sizeof(pxd_t) * PTRS_PER_PMD);
22894
22895- pud_populate(mm, pud, pmd);
22896+ pyd_populate(mm, pyd, pxd);
22897 }
22898 }
22899
22900 pgd_t *pgd_alloc(struct mm_struct *mm)
22901 {
22902 pgd_t *pgd;
22903- pmd_t *pmds[PREALLOCATED_PMDS];
22904+ pxd_t *pxds[PREALLOCATED_PXDS];
22905
22906 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
22907
22908@@ -265,11 +314,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
22909
22910 mm->pgd = pgd;
22911
22912- if (preallocate_pmds(pmds) != 0)
22913+ if (preallocate_pxds(pxds) != 0)
22914 goto out_free_pgd;
22915
22916 if (paravirt_pgd_alloc(mm) != 0)
22917- goto out_free_pmds;
22918+ goto out_free_pxds;
22919
22920 /*
22921 * Make sure that pre-populating the pmds is atomic with
22922@@ -279,14 +328,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
22923 spin_lock(&pgd_lock);
22924
22925 pgd_ctor(mm, pgd);
22926- pgd_prepopulate_pmd(mm, pgd, pmds);
22927+ pgd_prepopulate_pxd(mm, pgd, pxds);
22928
22929 spin_unlock(&pgd_lock);
22930
22931 return pgd;
22932
22933-out_free_pmds:
22934- free_pmds(pmds);
22935+out_free_pxds:
22936+ free_pxds(pxds);
22937 out_free_pgd:
22938 free_page((unsigned long)pgd);
22939 out:
22940@@ -295,7 +344,7 @@ out:
22941
22942 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
22943 {
22944- pgd_mop_up_pmds(mm, pgd);
22945+ pgd_mop_up_pxds(mm, pgd);
22946 pgd_dtor(pgd);
22947 paravirt_pgd_free(mm, pgd);
22948 free_page((unsigned long)pgd);
22949diff -urNp linux-2.6.39.1/arch/x86/mm/setup_nx.c linux-2.6.39.1/arch/x86/mm/setup_nx.c
22950--- linux-2.6.39.1/arch/x86/mm/setup_nx.c 2011-05-19 00:06:34.000000000 -0400
22951+++ linux-2.6.39.1/arch/x86/mm/setup_nx.c 2011-05-22 19:36:30.000000000 -0400
22952@@ -5,8 +5,10 @@
22953 #include <asm/pgtable.h>
22954 #include <asm/proto.h>
22955
22956+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
22957 static int disable_nx __cpuinitdata;
22958
22959+#ifndef CONFIG_PAX_PAGEEXEC
22960 /*
22961 * noexec = on|off
22962 *
22963@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str
22964 return 0;
22965 }
22966 early_param("noexec", noexec_setup);
22967+#endif
22968+
22969+#endif
22970
22971 void __cpuinit x86_configure_nx(void)
22972 {
22973+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
22974 if (cpu_has_nx && !disable_nx)
22975 __supported_pte_mask |= _PAGE_NX;
22976 else
22977+#endif
22978 __supported_pte_mask &= ~_PAGE_NX;
22979 }
22980
22981diff -urNp linux-2.6.39.1/arch/x86/mm/tlb.c linux-2.6.39.1/arch/x86/mm/tlb.c
22982--- linux-2.6.39.1/arch/x86/mm/tlb.c 2011-05-19 00:06:34.000000000 -0400
22983+++ linux-2.6.39.1/arch/x86/mm/tlb.c 2011-05-22 19:36:30.000000000 -0400
22984@@ -65,7 +65,11 @@ void leave_mm(int cpu)
22985 BUG();
22986 cpumask_clear_cpu(cpu,
22987 mm_cpumask(percpu_read(cpu_tlbstate.active_mm)));
22988+
22989+#ifndef CONFIG_PAX_PER_CPU_PGD
22990 load_cr3(swapper_pg_dir);
22991+#endif
22992+
22993 }
22994 EXPORT_SYMBOL_GPL(leave_mm);
22995
22996diff -urNp linux-2.6.39.1/arch/x86/oprofile/backtrace.c linux-2.6.39.1/arch/x86/oprofile/backtrace.c
22997--- linux-2.6.39.1/arch/x86/oprofile/backtrace.c 2011-05-19 00:06:34.000000000 -0400
22998+++ linux-2.6.39.1/arch/x86/oprofile/backtrace.c 2011-05-22 19:36:30.000000000 -0400
22999@@ -57,7 +57,7 @@ dump_user_backtrace_32(struct stack_fram
23000 struct stack_frame_ia32 *fp;
23001
23002 /* Also check accessibility of one struct frame_head beyond */
23003- if (!access_ok(VERIFY_READ, head, sizeof(bufhead)))
23004+ if (!__access_ok(VERIFY_READ, head, sizeof(bufhead)))
23005 return NULL;
23006 if (__copy_from_user_inatomic(bufhead, head, sizeof(bufhead)))
23007 return NULL;
23008@@ -123,7 +123,7 @@ x86_backtrace(struct pt_regs * const reg
23009 {
23010 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
23011
23012- if (!user_mode_vm(regs)) {
23013+ if (!user_mode(regs)) {
23014 unsigned long stack = kernel_stack_pointer(regs);
23015 if (depth)
23016 dump_trace(NULL, regs, (unsigned long *)stack, 0,
23017diff -urNp linux-2.6.39.1/arch/x86/pci/ce4100.c linux-2.6.39.1/arch/x86/pci/ce4100.c
23018--- linux-2.6.39.1/arch/x86/pci/ce4100.c 2011-05-19 00:06:34.000000000 -0400
23019+++ linux-2.6.39.1/arch/x86/pci/ce4100.c 2011-05-22 19:36:30.000000000 -0400
23020@@ -302,7 +302,7 @@ static int ce4100_conf_write(unsigned in
23021 return pci_direct_conf1.write(seg, bus, devfn, reg, len, value);
23022 }
23023
23024-struct pci_raw_ops ce4100_pci_conf = {
23025+const struct pci_raw_ops ce4100_pci_conf = {
23026 .read = ce4100_conf_read,
23027 .write = ce4100_conf_write,
23028 };
23029diff -urNp linux-2.6.39.1/arch/x86/pci/common.c linux-2.6.39.1/arch/x86/pci/common.c
23030--- linux-2.6.39.1/arch/x86/pci/common.c 2011-05-19 00:06:34.000000000 -0400
23031+++ linux-2.6.39.1/arch/x86/pci/common.c 2011-05-22 19:36:30.000000000 -0400
23032@@ -33,8 +33,8 @@ int noioapicreroute = 1;
23033 int pcibios_last_bus = -1;
23034 unsigned long pirq_table_addr;
23035 struct pci_bus *pci_root_bus;
23036-struct pci_raw_ops *raw_pci_ops;
23037-struct pci_raw_ops *raw_pci_ext_ops;
23038+const struct pci_raw_ops *raw_pci_ops;
23039+const struct pci_raw_ops *raw_pci_ext_ops;
23040
23041 int raw_pci_read(unsigned int domain, unsigned int bus, unsigned int devfn,
23042 int reg, int len, u32 *val)
23043diff -urNp linux-2.6.39.1/arch/x86/pci/direct.c linux-2.6.39.1/arch/x86/pci/direct.c
23044--- linux-2.6.39.1/arch/x86/pci/direct.c 2011-05-19 00:06:34.000000000 -0400
23045+++ linux-2.6.39.1/arch/x86/pci/direct.c 2011-05-22 19:36:30.000000000 -0400
23046@@ -79,7 +79,7 @@ static int pci_conf1_write(unsigned int
23047
23048 #undef PCI_CONF1_ADDRESS
23049
23050-struct pci_raw_ops pci_direct_conf1 = {
23051+const struct pci_raw_ops pci_direct_conf1 = {
23052 .read = pci_conf1_read,
23053 .write = pci_conf1_write,
23054 };
23055@@ -173,7 +173,7 @@ static int pci_conf2_write(unsigned int
23056
23057 #undef PCI_CONF2_ADDRESS
23058
23059-struct pci_raw_ops pci_direct_conf2 = {
23060+const struct pci_raw_ops pci_direct_conf2 = {
23061 .read = pci_conf2_read,
23062 .write = pci_conf2_write,
23063 };
23064@@ -189,7 +189,7 @@ struct pci_raw_ops pci_direct_conf2 = {
23065 * This should be close to trivial, but it isn't, because there are buggy
23066 * chipsets (yes, you guessed it, by Intel and Compaq) that have no class ID.
23067 */
23068-static int __init pci_sanity_check(struct pci_raw_ops *o)
23069+static int __init pci_sanity_check(const struct pci_raw_ops *o)
23070 {
23071 u32 x = 0;
23072 int year, devfn;
23073diff -urNp linux-2.6.39.1/arch/x86/pci/fixup.c linux-2.6.39.1/arch/x86/pci/fixup.c
23074--- linux-2.6.39.1/arch/x86/pci/fixup.c 2011-05-19 00:06:34.000000000 -0400
23075+++ linux-2.6.39.1/arch/x86/pci/fixup.c 2011-05-22 19:36:30.000000000 -0400
23076@@ -435,7 +435,7 @@ static const struct dmi_system_id __devi
23077 DMI_MATCH(DMI_PRODUCT_VERSION, "PSA40U"),
23078 },
23079 },
23080- { }
23081+ {}
23082 };
23083
23084 static void __devinit pci_pre_fixup_toshiba_ohci1394(struct pci_dev *dev)
23085diff -urNp linux-2.6.39.1/arch/x86/pci/mmconfig_32.c linux-2.6.39.1/arch/x86/pci/mmconfig_32.c
23086--- linux-2.6.39.1/arch/x86/pci/mmconfig_32.c 2011-05-19 00:06:34.000000000 -0400
23087+++ linux-2.6.39.1/arch/x86/pci/mmconfig_32.c 2011-05-22 19:36:30.000000000 -0400
23088@@ -117,7 +117,7 @@ static int pci_mmcfg_write(unsigned int
23089 return 0;
23090 }
23091
23092-static struct pci_raw_ops pci_mmcfg = {
23093+static const struct pci_raw_ops pci_mmcfg = {
23094 .read = pci_mmcfg_read,
23095 .write = pci_mmcfg_write,
23096 };
23097diff -urNp linux-2.6.39.1/arch/x86/pci/mmconfig_64.c linux-2.6.39.1/arch/x86/pci/mmconfig_64.c
23098--- linux-2.6.39.1/arch/x86/pci/mmconfig_64.c 2011-05-19 00:06:34.000000000 -0400
23099+++ linux-2.6.39.1/arch/x86/pci/mmconfig_64.c 2011-05-22 19:36:30.000000000 -0400
23100@@ -81,7 +81,7 @@ static int pci_mmcfg_write(unsigned int
23101 return 0;
23102 }
23103
23104-static struct pci_raw_ops pci_mmcfg = {
23105+static const struct pci_raw_ops pci_mmcfg = {
23106 .read = pci_mmcfg_read,
23107 .write = pci_mmcfg_write,
23108 };
23109diff -urNp linux-2.6.39.1/arch/x86/pci/mrst.c linux-2.6.39.1/arch/x86/pci/mrst.c
23110--- linux-2.6.39.1/arch/x86/pci/mrst.c 2011-05-19 00:06:34.000000000 -0400
23111+++ linux-2.6.39.1/arch/x86/pci/mrst.c 2011-05-22 19:36:30.000000000 -0400
23112@@ -218,7 +218,7 @@ static int mrst_pci_irq_enable(struct pc
23113 return 0;
23114 }
23115
23116-struct pci_ops pci_mrst_ops = {
23117+const struct pci_ops pci_mrst_ops = {
23118 .read = pci_read,
23119 .write = pci_write,
23120 };
23121diff -urNp linux-2.6.39.1/arch/x86/pci/numaq_32.c linux-2.6.39.1/arch/x86/pci/numaq_32.c
23122--- linux-2.6.39.1/arch/x86/pci/numaq_32.c 2011-05-19 00:06:34.000000000 -0400
23123+++ linux-2.6.39.1/arch/x86/pci/numaq_32.c 2011-05-22 19:36:30.000000000 -0400
23124@@ -108,7 +108,7 @@ static int pci_conf1_mq_write(unsigned i
23125
23126 #undef PCI_CONF1_MQ_ADDRESS
23127
23128-static struct pci_raw_ops pci_direct_conf1_mq = {
23129+static const struct pci_raw_ops pci_direct_conf1_mq = {
23130 .read = pci_conf1_mq_read,
23131 .write = pci_conf1_mq_write
23132 };
23133diff -urNp linux-2.6.39.1/arch/x86/pci/olpc.c linux-2.6.39.1/arch/x86/pci/olpc.c
23134--- linux-2.6.39.1/arch/x86/pci/olpc.c 2011-05-19 00:06:34.000000000 -0400
23135+++ linux-2.6.39.1/arch/x86/pci/olpc.c 2011-05-22 19:36:30.000000000 -0400
23136@@ -297,7 +297,7 @@ static int pci_olpc_write(unsigned int s
23137 return 0;
23138 }
23139
23140-static struct pci_raw_ops pci_olpc_conf = {
23141+static const struct pci_raw_ops pci_olpc_conf = {
23142 .read = pci_olpc_read,
23143 .write = pci_olpc_write,
23144 };
23145diff -urNp linux-2.6.39.1/arch/x86/pci/pcbios.c linux-2.6.39.1/arch/x86/pci/pcbios.c
23146--- linux-2.6.39.1/arch/x86/pci/pcbios.c 2011-05-19 00:06:34.000000000 -0400
23147+++ linux-2.6.39.1/arch/x86/pci/pcbios.c 2011-05-22 19:36:30.000000000 -0400
23148@@ -79,50 +79,93 @@ union bios32 {
23149 static struct {
23150 unsigned long address;
23151 unsigned short segment;
23152-} bios32_indirect = { 0, __KERNEL_CS };
23153+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
23154
23155 /*
23156 * Returns the entry point for the given service, NULL on error
23157 */
23158
23159-static unsigned long bios32_service(unsigned long service)
23160+static unsigned long __devinit bios32_service(unsigned long service)
23161 {
23162 unsigned char return_code; /* %al */
23163 unsigned long address; /* %ebx */
23164 unsigned long length; /* %ecx */
23165 unsigned long entry; /* %edx */
23166 unsigned long flags;
23167+ struct desc_struct d, *gdt;
23168
23169 local_irq_save(flags);
23170- __asm__("lcall *(%%edi); cld"
23171+
23172+ gdt = get_cpu_gdt_table(smp_processor_id());
23173+
23174+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
23175+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
23176+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
23177+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
23178+
23179+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
23180 : "=a" (return_code),
23181 "=b" (address),
23182 "=c" (length),
23183 "=d" (entry)
23184 : "0" (service),
23185 "1" (0),
23186- "D" (&bios32_indirect));
23187+ "D" (&bios32_indirect),
23188+ "r"(__PCIBIOS_DS)
23189+ : "memory");
23190+
23191+ pax_open_kernel();
23192+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
23193+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
23194+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
23195+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
23196+ pax_close_kernel();
23197+
23198 local_irq_restore(flags);
23199
23200 switch (return_code) {
23201- case 0:
23202- return address + entry;
23203- case 0x80: /* Not present */
23204- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
23205- return 0;
23206- default: /* Shouldn't happen */
23207- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
23208- service, return_code);
23209+ case 0: {
23210+ int cpu;
23211+ unsigned char flags;
23212+
23213+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
23214+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
23215+ printk(KERN_WARNING "bios32_service: not valid\n");
23216 return 0;
23217+ }
23218+ address = address + PAGE_OFFSET;
23219+ length += 16UL; /* some BIOSs underreport this... */
23220+ flags = 4;
23221+ if (length >= 64*1024*1024) {
23222+ length >>= PAGE_SHIFT;
23223+ flags |= 8;
23224+ }
23225+
23226+ for (cpu = 0; cpu < NR_CPUS; cpu++) {
23227+ gdt = get_cpu_gdt_table(cpu);
23228+ pack_descriptor(&d, address, length, 0x9b, flags);
23229+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
23230+ pack_descriptor(&d, address, length, 0x93, flags);
23231+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
23232+ }
23233+ return entry;
23234+ }
23235+ case 0x80: /* Not present */
23236+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
23237+ return 0;
23238+ default: /* Shouldn't happen */
23239+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
23240+ service, return_code);
23241+ return 0;
23242 }
23243 }
23244
23245 static struct {
23246 unsigned long address;
23247 unsigned short segment;
23248-} pci_indirect = { 0, __KERNEL_CS };
23249+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
23250
23251-static int pci_bios_present;
23252+static int pci_bios_present __read_only;
23253
23254 static int __devinit check_pcibios(void)
23255 {
23256@@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
23257 unsigned long flags, pcibios_entry;
23258
23259 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
23260- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
23261+ pci_indirect.address = pcibios_entry;
23262
23263 local_irq_save(flags);
23264- __asm__(
23265- "lcall *(%%edi); cld\n\t"
23266+ __asm__("movw %w6, %%ds\n\t"
23267+ "lcall *%%ss:(%%edi); cld\n\t"
23268+ "push %%ss\n\t"
23269+ "pop %%ds\n\t"
23270 "jc 1f\n\t"
23271 "xor %%ah, %%ah\n"
23272 "1:"
23273@@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
23274 "=b" (ebx),
23275 "=c" (ecx)
23276 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
23277- "D" (&pci_indirect)
23278+ "D" (&pci_indirect),
23279+ "r" (__PCIBIOS_DS)
23280 : "memory");
23281 local_irq_restore(flags);
23282
23283@@ -188,7 +234,10 @@ static int pci_bios_read(unsigned int se
23284
23285 switch (len) {
23286 case 1:
23287- __asm__("lcall *(%%esi); cld\n\t"
23288+ __asm__("movw %w6, %%ds\n\t"
23289+ "lcall *%%ss:(%%esi); cld\n\t"
23290+ "push %%ss\n\t"
23291+ "pop %%ds\n\t"
23292 "jc 1f\n\t"
23293 "xor %%ah, %%ah\n"
23294 "1:"
23295@@ -197,7 +246,8 @@ static int pci_bios_read(unsigned int se
23296 : "1" (PCIBIOS_READ_CONFIG_BYTE),
23297 "b" (bx),
23298 "D" ((long)reg),
23299- "S" (&pci_indirect));
23300+ "S" (&pci_indirect),
23301+ "r" (__PCIBIOS_DS));
23302 /*
23303 * Zero-extend the result beyond 8 bits, do not trust the
23304 * BIOS having done it:
23305@@ -205,7 +255,10 @@ static int pci_bios_read(unsigned int se
23306 *value &= 0xff;
23307 break;
23308 case 2:
23309- __asm__("lcall *(%%esi); cld\n\t"
23310+ __asm__("movw %w6, %%ds\n\t"
23311+ "lcall *%%ss:(%%esi); cld\n\t"
23312+ "push %%ss\n\t"
23313+ "pop %%ds\n\t"
23314 "jc 1f\n\t"
23315 "xor %%ah, %%ah\n"
23316 "1:"
23317@@ -214,7 +267,8 @@ static int pci_bios_read(unsigned int se
23318 : "1" (PCIBIOS_READ_CONFIG_WORD),
23319 "b" (bx),
23320 "D" ((long)reg),
23321- "S" (&pci_indirect));
23322+ "S" (&pci_indirect),
23323+ "r" (__PCIBIOS_DS));
23324 /*
23325 * Zero-extend the result beyond 16 bits, do not trust the
23326 * BIOS having done it:
23327@@ -222,7 +276,10 @@ static int pci_bios_read(unsigned int se
23328 *value &= 0xffff;
23329 break;
23330 case 4:
23331- __asm__("lcall *(%%esi); cld\n\t"
23332+ __asm__("movw %w6, %%ds\n\t"
23333+ "lcall *%%ss:(%%esi); cld\n\t"
23334+ "push %%ss\n\t"
23335+ "pop %%ds\n\t"
23336 "jc 1f\n\t"
23337 "xor %%ah, %%ah\n"
23338 "1:"
23339@@ -231,7 +288,8 @@ static int pci_bios_read(unsigned int se
23340 : "1" (PCIBIOS_READ_CONFIG_DWORD),
23341 "b" (bx),
23342 "D" ((long)reg),
23343- "S" (&pci_indirect));
23344+ "S" (&pci_indirect),
23345+ "r" (__PCIBIOS_DS));
23346 break;
23347 }
23348
23349@@ -254,7 +312,10 @@ static int pci_bios_write(unsigned int s
23350
23351 switch (len) {
23352 case 1:
23353- __asm__("lcall *(%%esi); cld\n\t"
23354+ __asm__("movw %w6, %%ds\n\t"
23355+ "lcall *%%ss:(%%esi); cld\n\t"
23356+ "push %%ss\n\t"
23357+ "pop %%ds\n\t"
23358 "jc 1f\n\t"
23359 "xor %%ah, %%ah\n"
23360 "1:"
23361@@ -263,10 +324,14 @@ static int pci_bios_write(unsigned int s
23362 "c" (value),
23363 "b" (bx),
23364 "D" ((long)reg),
23365- "S" (&pci_indirect));
23366+ "S" (&pci_indirect),
23367+ "r" (__PCIBIOS_DS));
23368 break;
23369 case 2:
23370- __asm__("lcall *(%%esi); cld\n\t"
23371+ __asm__("movw %w6, %%ds\n\t"
23372+ "lcall *%%ss:(%%esi); cld\n\t"
23373+ "push %%ss\n\t"
23374+ "pop %%ds\n\t"
23375 "jc 1f\n\t"
23376 "xor %%ah, %%ah\n"
23377 "1:"
23378@@ -275,10 +340,14 @@ static int pci_bios_write(unsigned int s
23379 "c" (value),
23380 "b" (bx),
23381 "D" ((long)reg),
23382- "S" (&pci_indirect));
23383+ "S" (&pci_indirect),
23384+ "r" (__PCIBIOS_DS));
23385 break;
23386 case 4:
23387- __asm__("lcall *(%%esi); cld\n\t"
23388+ __asm__("movw %w6, %%ds\n\t"
23389+ "lcall *%%ss:(%%esi); cld\n\t"
23390+ "push %%ss\n\t"
23391+ "pop %%ds\n\t"
23392 "jc 1f\n\t"
23393 "xor %%ah, %%ah\n"
23394 "1:"
23395@@ -287,7 +356,8 @@ static int pci_bios_write(unsigned int s
23396 "c" (value),
23397 "b" (bx),
23398 "D" ((long)reg),
23399- "S" (&pci_indirect));
23400+ "S" (&pci_indirect),
23401+ "r" (__PCIBIOS_DS));
23402 break;
23403 }
23404
23405@@ -301,7 +371,7 @@ static int pci_bios_write(unsigned int s
23406 * Function table for BIOS32 access
23407 */
23408
23409-static struct pci_raw_ops pci_bios_access = {
23410+static const struct pci_raw_ops pci_bios_access = {
23411 .read = pci_bios_read,
23412 .write = pci_bios_write
23413 };
23414@@ -310,7 +380,7 @@ static struct pci_raw_ops pci_bios_acces
23415 * Try to find PCI BIOS.
23416 */
23417
23418-static struct pci_raw_ops * __devinit pci_find_bios(void)
23419+static const struct pci_raw_ops * __devinit pci_find_bios(void)
23420 {
23421 union bios32 *check;
23422 unsigned char sum;
23423@@ -392,10 +462,13 @@ struct irq_routing_table * pcibios_get_i
23424
23425 DBG("PCI: Fetching IRQ routing table... ");
23426 __asm__("push %%es\n\t"
23427+ "movw %w8, %%ds\n\t"
23428 "push %%ds\n\t"
23429 "pop %%es\n\t"
23430- "lcall *(%%esi); cld\n\t"
23431+ "lcall *%%ss:(%%esi); cld\n\t"
23432 "pop %%es\n\t"
23433+ "push %%ss\n\t"
23434+ "pop %%ds\n"
23435 "jc 1f\n\t"
23436 "xor %%ah, %%ah\n"
23437 "1:"
23438@@ -406,7 +479,8 @@ struct irq_routing_table * pcibios_get_i
23439 "1" (0),
23440 "D" ((long) &opt),
23441 "S" (&pci_indirect),
23442- "m" (opt)
23443+ "m" (opt),
23444+ "r" (__PCIBIOS_DS)
23445 : "memory");
23446 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
23447 if (ret & 0xff00)
23448@@ -430,7 +504,10 @@ int pcibios_set_irq_routing(struct pci_d
23449 {
23450 int ret;
23451
23452- __asm__("lcall *(%%esi); cld\n\t"
23453+ __asm__("movw %w5, %%ds\n\t"
23454+ "lcall *%%ss:(%%esi); cld\n\t"
23455+ "push %%ss\n\t"
23456+ "pop %%ds\n"
23457 "jc 1f\n\t"
23458 "xor %%ah, %%ah\n"
23459 "1:"
23460@@ -438,7 +515,8 @@ int pcibios_set_irq_routing(struct pci_d
23461 : "0" (PCIBIOS_SET_PCI_HW_INT),
23462 "b" ((dev->bus->number << 8) | dev->devfn),
23463 "c" ((irq << 8) | (pin + 10)),
23464- "S" (&pci_indirect));
23465+ "S" (&pci_indirect),
23466+ "r" (__PCIBIOS_DS));
23467 return !(ret & 0xff00);
23468 }
23469 EXPORT_SYMBOL(pcibios_set_irq_routing);
23470diff -urNp linux-2.6.39.1/arch/x86/pci/xen.c linux-2.6.39.1/arch/x86/pci/xen.c
23471--- linux-2.6.39.1/arch/x86/pci/xen.c 2011-05-19 00:06:34.000000000 -0400
23472+++ linux-2.6.39.1/arch/x86/pci/xen.c 2011-05-22 19:36:30.000000000 -0400
23473@@ -62,7 +62,7 @@ static int acpi_register_gsi_xen_hvm(str
23474 #include <linux/msi.h>
23475 #include <asm/msidef.h>
23476
23477-struct xen_pci_frontend_ops *xen_pci_frontend;
23478+const struct xen_pci_frontend_ops *xen_pci_frontend;
23479 EXPORT_SYMBOL_GPL(xen_pci_frontend);
23480
23481 #define XEN_PIRQ_MSI_DATA (MSI_DATA_TRIGGER_EDGE | \
23482diff -urNp linux-2.6.39.1/arch/x86/platform/efi/efi_32.c linux-2.6.39.1/arch/x86/platform/efi/efi_32.c
23483--- linux-2.6.39.1/arch/x86/platform/efi/efi_32.c 2011-05-19 00:06:34.000000000 -0400
23484+++ linux-2.6.39.1/arch/x86/platform/efi/efi_32.c 2011-05-22 19:36:30.000000000 -0400
23485@@ -38,70 +38,37 @@
23486 */
23487
23488 static unsigned long efi_rt_eflags;
23489-static pgd_t efi_bak_pg_dir_pointer[2];
23490+static pgd_t __initdata efi_bak_pg_dir_pointer[KERNEL_PGD_PTRS];
23491
23492-void efi_call_phys_prelog(void)
23493+void __init efi_call_phys_prelog(void)
23494 {
23495- unsigned long cr4;
23496- unsigned long temp;
23497 struct desc_ptr gdt_descr;
23498
23499 local_irq_save(efi_rt_eflags);
23500
23501- /*
23502- * If I don't have PAE, I should just duplicate two entries in page
23503- * directory. If I have PAE, I just need to duplicate one entry in
23504- * page directory.
23505- */
23506- cr4 = read_cr4_safe();
23507-
23508- if (cr4 & X86_CR4_PAE) {
23509- efi_bak_pg_dir_pointer[0].pgd =
23510- swapper_pg_dir[pgd_index(0)].pgd;
23511- swapper_pg_dir[0].pgd =
23512- swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;
23513- } else {
23514- efi_bak_pg_dir_pointer[0].pgd =
23515- swapper_pg_dir[pgd_index(0)].pgd;
23516- efi_bak_pg_dir_pointer[1].pgd =
23517- swapper_pg_dir[pgd_index(0x400000)].pgd;
23518- swapper_pg_dir[pgd_index(0)].pgd =
23519- swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;
23520- temp = PAGE_OFFSET + 0x400000;
23521- swapper_pg_dir[pgd_index(0x400000)].pgd =
23522- swapper_pg_dir[pgd_index(temp)].pgd;
23523- }
23524+ clone_pgd_range(efi_bak_pg_dir_pointer, swapper_pg_dir, KERNEL_PGD_PTRS);
23525+ clone_pgd_range(swapper_pg_dir, swapper_pg_dir + KERNEL_PGD_BOUNDARY,
23526+ min_t(unsigned long, KERNEL_PGD_PTRS, KERNEL_PGD_BOUNDARY));
23527
23528 /*
23529 * After the lock is released, the original page table is restored.
23530 */
23531 __flush_tlb_all();
23532
23533- gdt_descr.address = __pa(get_cpu_gdt_table(0));
23534+ gdt_descr.address = (struct desc_struct *)__pa(get_cpu_gdt_table(0));
23535 gdt_descr.size = GDT_SIZE - 1;
23536 load_gdt(&gdt_descr);
23537 }
23538
23539-void efi_call_phys_epilog(void)
23540+void __init efi_call_phys_epilog(void)
23541 {
23542- unsigned long cr4;
23543 struct desc_ptr gdt_descr;
23544
23545- gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
23546+ gdt_descr.address = get_cpu_gdt_table(0);
23547 gdt_descr.size = GDT_SIZE - 1;
23548 load_gdt(&gdt_descr);
23549
23550- cr4 = read_cr4_safe();
23551-
23552- if (cr4 & X86_CR4_PAE) {
23553- swapper_pg_dir[pgd_index(0)].pgd =
23554- efi_bak_pg_dir_pointer[0].pgd;
23555- } else {
23556- swapper_pg_dir[pgd_index(0)].pgd =
23557- efi_bak_pg_dir_pointer[0].pgd;
23558- swapper_pg_dir[pgd_index(0x400000)].pgd =
23559- efi_bak_pg_dir_pointer[1].pgd;
23560- }
23561+ clone_pgd_range(swapper_pg_dir, efi_bak_pg_dir_pointer, KERNEL_PGD_PTRS);
23562
23563 /*
23564 * After the lock is released, the original page table is restored.
23565diff -urNp linux-2.6.39.1/arch/x86/platform/efi/efi_stub_32.S linux-2.6.39.1/arch/x86/platform/efi/efi_stub_32.S
23566--- linux-2.6.39.1/arch/x86/platform/efi/efi_stub_32.S 2011-05-19 00:06:34.000000000 -0400
23567+++ linux-2.6.39.1/arch/x86/platform/efi/efi_stub_32.S 2011-05-22 19:36:30.000000000 -0400
23568@@ -6,6 +6,7 @@
23569 */
23570
23571 #include <linux/linkage.h>
23572+#include <linux/init.h>
23573 #include <asm/page_types.h>
23574
23575 /*
23576@@ -20,7 +21,7 @@
23577 * service functions will comply with gcc calling convention, too.
23578 */
23579
23580-.text
23581+__INIT
23582 ENTRY(efi_call_phys)
23583 /*
23584 * 0. The function can only be called in Linux kernel. So CS has been
23585@@ -36,9 +37,7 @@ ENTRY(efi_call_phys)
23586 * The mapping of lower virtual memory has been created in prelog and
23587 * epilog.
23588 */
23589- movl $1f, %edx
23590- subl $__PAGE_OFFSET, %edx
23591- jmp *%edx
23592+ jmp 1f-__PAGE_OFFSET
23593 1:
23594
23595 /*
23596@@ -47,14 +46,8 @@ ENTRY(efi_call_phys)
23597 * parameter 2, ..., param n. To make things easy, we save the return
23598 * address of efi_call_phys in a global variable.
23599 */
23600- popl %edx
23601- movl %edx, saved_return_addr
23602- /* get the function pointer into ECX*/
23603- popl %ecx
23604- movl %ecx, efi_rt_function_ptr
23605- movl $2f, %edx
23606- subl $__PAGE_OFFSET, %edx
23607- pushl %edx
23608+ popl (saved_return_addr)
23609+ popl (efi_rt_function_ptr)
23610
23611 /*
23612 * 3. Clear PG bit in %CR0.
23613@@ -73,9 +66,8 @@ ENTRY(efi_call_phys)
23614 /*
23615 * 5. Call the physical function.
23616 */
23617- jmp *%ecx
23618+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
23619
23620-2:
23621 /*
23622 * 6. After EFI runtime service returns, control will return to
23623 * following instruction. We'd better readjust stack pointer first.
23624@@ -88,35 +80,28 @@ ENTRY(efi_call_phys)
23625 movl %cr0, %edx
23626 orl $0x80000000, %edx
23627 movl %edx, %cr0
23628- jmp 1f
23629-1:
23630+
23631 /*
23632 * 8. Now restore the virtual mode from flat mode by
23633 * adding EIP with PAGE_OFFSET.
23634 */
23635- movl $1f, %edx
23636- jmp *%edx
23637+ jmp 1f+__PAGE_OFFSET
23638 1:
23639
23640 /*
23641 * 9. Balance the stack. And because EAX contain the return value,
23642 * we'd better not clobber it.
23643 */
23644- leal efi_rt_function_ptr, %edx
23645- movl (%edx), %ecx
23646- pushl %ecx
23647+ pushl (efi_rt_function_ptr)
23648
23649 /*
23650- * 10. Push the saved return address onto the stack and return.
23651+ * 10. Return to the saved return address.
23652 */
23653- leal saved_return_addr, %edx
23654- movl (%edx), %ecx
23655- pushl %ecx
23656- ret
23657+ jmpl *(saved_return_addr)
23658 ENDPROC(efi_call_phys)
23659 .previous
23660
23661-.data
23662+__INITDATA
23663 saved_return_addr:
23664 .long 0
23665 efi_rt_function_ptr:
23666diff -urNp linux-2.6.39.1/arch/x86/platform/olpc/olpc_dt.c linux-2.6.39.1/arch/x86/platform/olpc/olpc_dt.c
23667--- linux-2.6.39.1/arch/x86/platform/olpc/olpc_dt.c 2011-05-19 00:06:34.000000000 -0400
23668+++ linux-2.6.39.1/arch/x86/platform/olpc/olpc_dt.c 2011-05-22 19:36:30.000000000 -0400
23669@@ -154,7 +154,7 @@ void * __init prom_early_alloc(unsigned
23670 return res;
23671 }
23672
23673-static struct of_pdt_ops prom_olpc_ops __initdata = {
23674+static const struct of_pdt_ops prom_olpc_ops = {
23675 .nextprop = olpc_dt_nextprop,
23676 .getproplen = olpc_dt_getproplen,
23677 .getproperty = olpc_dt_getproperty,
23678diff -urNp linux-2.6.39.1/arch/x86/platform/uv/tlb_uv.c linux-2.6.39.1/arch/x86/platform/uv/tlb_uv.c
23679--- linux-2.6.39.1/arch/x86/platform/uv/tlb_uv.c 2011-05-19 00:06:34.000000000 -0400
23680+++ linux-2.6.39.1/arch/x86/platform/uv/tlb_uv.c 2011-05-22 19:36:30.000000000 -0400
23681@@ -342,6 +342,8 @@ static void uv_reset_with_ipi(struct bau
23682 cpumask_t mask;
23683 struct reset_args reset_args;
23684
23685+ pax_track_stack();
23686+
23687 reset_args.sender = sender;
23688
23689 cpus_clear(mask);
23690diff -urNp linux-2.6.39.1/arch/x86/power/cpu.c linux-2.6.39.1/arch/x86/power/cpu.c
23691--- linux-2.6.39.1/arch/x86/power/cpu.c 2011-05-19 00:06:34.000000000 -0400
23692+++ linux-2.6.39.1/arch/x86/power/cpu.c 2011-05-22 19:36:30.000000000 -0400
23693@@ -130,7 +130,7 @@ static void do_fpu_end(void)
23694 static void fix_processor_context(void)
23695 {
23696 int cpu = smp_processor_id();
23697- struct tss_struct *t = &per_cpu(init_tss, cpu);
23698+ struct tss_struct *t = init_tss + cpu;
23699
23700 set_tss_desc(cpu, t); /*
23701 * This just modifies memory; should not be
23702@@ -140,7 +140,9 @@ static void fix_processor_context(void)
23703 */
23704
23705 #ifdef CONFIG_X86_64
23706+ pax_open_kernel();
23707 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
23708+ pax_close_kernel();
23709
23710 syscall_init(); /* This sets MSR_*STAR and related */
23711 #endif
23712diff -urNp linux-2.6.39.1/arch/x86/vdso/Makefile linux-2.6.39.1/arch/x86/vdso/Makefile
23713--- linux-2.6.39.1/arch/x86/vdso/Makefile 2011-05-19 00:06:34.000000000 -0400
23714+++ linux-2.6.39.1/arch/x86/vdso/Makefile 2011-05-22 19:36:30.000000000 -0400
23715@@ -123,7 +123,7 @@ quiet_cmd_vdso = VDSO $@
23716 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
23717 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
23718
23719-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
23720+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
23721 GCOV_PROFILE := n
23722
23723 #
23724diff -urNp linux-2.6.39.1/arch/x86/vdso/vclock_gettime.c linux-2.6.39.1/arch/x86/vdso/vclock_gettime.c
23725--- linux-2.6.39.1/arch/x86/vdso/vclock_gettime.c 2011-05-19 00:06:34.000000000 -0400
23726+++ linux-2.6.39.1/arch/x86/vdso/vclock_gettime.c 2011-05-22 19:36:30.000000000 -0400
23727@@ -22,24 +22,48 @@
23728 #include <asm/hpet.h>
23729 #include <asm/unistd.h>
23730 #include <asm/io.h>
23731+#include <asm/fixmap.h>
23732 #include "vextern.h"
23733
23734 #define gtod vdso_vsyscall_gtod_data
23735
23736+notrace noinline long __vdso_fallback_time(long *t)
23737+{
23738+ long secs;
23739+ asm volatile("syscall"
23740+ : "=a" (secs)
23741+ : "0" (__NR_time),"D" (t) : "r11", "cx", "memory");
23742+ return secs;
23743+}
23744+
23745 notrace static long vdso_fallback_gettime(long clock, struct timespec *ts)
23746 {
23747 long ret;
23748 asm("syscall" : "=a" (ret) :
23749- "0" (__NR_clock_gettime),"D" (clock), "S" (ts) : "memory");
23750+ "0" (__NR_clock_gettime),"D" (clock), "S" (ts) : "r11", "cx", "memory");
23751 return ret;
23752 }
23753
23754+notrace static inline cycle_t __vdso_vread_hpet(void)
23755+{
23756+ return readl((const void __iomem *)fix_to_virt(VSYSCALL_HPET) + 0xf0);
23757+}
23758+
23759+notrace static inline cycle_t __vdso_vread_tsc(void)
23760+{
23761+ cycle_t ret = (cycle_t)vget_cycles();
23762+
23763+ return ret >= gtod->clock.cycle_last ? ret : gtod->clock.cycle_last;
23764+}
23765+
23766 notrace static inline long vgetns(void)
23767 {
23768 long v;
23769- cycles_t (*vread)(void);
23770- vread = gtod->clock.vread;
23771- v = (vread() - gtod->clock.cycle_last) & gtod->clock.mask;
23772+ if (gtod->clock.name[0] == 't' && gtod->clock.name[1] == 's' && gtod->clock.name[2] == 'c' && !gtod->clock.name[3])
23773+ v = __vdso_vread_tsc();
23774+ else
23775+ v = __vdso_vread_hpet();
23776+ v = (v - gtod->clock.cycle_last) & gtod->clock.mask;
23777 return (v * gtod->clock.mult) >> gtod->clock.shift;
23778 }
23779
23780@@ -113,7 +137,9 @@ notrace static noinline int do_monotonic
23781
23782 notrace int __vdso_clock_gettime(clockid_t clock, struct timespec *ts)
23783 {
23784- if (likely(gtod->sysctl_enabled))
23785+ if (likely(gtod->sysctl_enabled &&
23786+ ((gtod->clock.name[0] == 'h' && gtod->clock.name[1] == 'p' && gtod->clock.name[2] == 'e' && gtod->clock.name[3] == 't' && !gtod->clock.name[4]) ||
23787+ (gtod->clock.name[0] == 't' && gtod->clock.name[1] == 's' && gtod->clock.name[2] == 'c' && !gtod->clock.name[3]))))
23788 switch (clock) {
23789 case CLOCK_REALTIME:
23790 if (likely(gtod->clock.vread))
23791@@ -133,10 +159,20 @@ notrace int __vdso_clock_gettime(clockid
23792 int clock_gettime(clockid_t, struct timespec *)
23793 __attribute__((weak, alias("__vdso_clock_gettime")));
23794
23795-notrace int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz)
23796+notrace noinline int __vdso_fallback_gettimeofday(struct timeval *tv, struct timezone *tz)
23797 {
23798 long ret;
23799- if (likely(gtod->sysctl_enabled && gtod->clock.vread)) {
23800+ asm("syscall" : "=a" (ret) :
23801+ "0" (__NR_gettimeofday), "D" (tv), "S" (tz) : "r11", "cx", "memory");
23802+ return ret;
23803+}
23804+
23805+notrace int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz)
23806+{
23807+ if (likely(gtod->sysctl_enabled &&
23808+ ((gtod->clock.name[0] == 'h' && gtod->clock.name[1] == 'p' && gtod->clock.name[2] == 'e' && gtod->clock.name[3] == 't' && !gtod->clock.name[4]) ||
23809+ (gtod->clock.name[0] == 't' && gtod->clock.name[1] == 's' && gtod->clock.name[2] == 'c' && !gtod->clock.name[3]))))
23810+ {
23811 if (likely(tv != NULL)) {
23812 BUILD_BUG_ON(offsetof(struct timeval, tv_usec) !=
23813 offsetof(struct timespec, tv_nsec) ||
23814@@ -151,9 +187,7 @@ notrace int __vdso_gettimeofday(struct t
23815 }
23816 return 0;
23817 }
23818- asm("syscall" : "=a" (ret) :
23819- "0" (__NR_gettimeofday), "D" (tv), "S" (tz) : "memory");
23820- return ret;
23821+ return __vdso_fallback_gettimeofday(tv, tz);
23822 }
23823 int gettimeofday(struct timeval *, struct timezone *)
23824 __attribute__((weak, alias("__vdso_gettimeofday")));
23825diff -urNp linux-2.6.39.1/arch/x86/vdso/vdso32-setup.c linux-2.6.39.1/arch/x86/vdso/vdso32-setup.c
23826--- linux-2.6.39.1/arch/x86/vdso/vdso32-setup.c 2011-05-19 00:06:34.000000000 -0400
23827+++ linux-2.6.39.1/arch/x86/vdso/vdso32-setup.c 2011-05-22 19:36:30.000000000 -0400
23828@@ -25,6 +25,7 @@
23829 #include <asm/tlbflush.h>
23830 #include <asm/vdso.h>
23831 #include <asm/proto.h>
23832+#include <asm/mman.h>
23833
23834 enum {
23835 VDSO_DISABLED = 0,
23836@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int m
23837 void enable_sep_cpu(void)
23838 {
23839 int cpu = get_cpu();
23840- struct tss_struct *tss = &per_cpu(init_tss, cpu);
23841+ struct tss_struct *tss = init_tss + cpu;
23842
23843 if (!boot_cpu_has(X86_FEATURE_SEP)) {
23844 put_cpu();
23845@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
23846 gate_vma.vm_start = FIXADDR_USER_START;
23847 gate_vma.vm_end = FIXADDR_USER_END;
23848 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
23849- gate_vma.vm_page_prot = __P101;
23850+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
23851 /*
23852 * Make sure the vDSO gets into every core dump.
23853 * Dumping its contents makes post-mortem fully interpretable later
23854@@ -331,14 +332,14 @@ int arch_setup_additional_pages(struct l
23855 if (compat)
23856 addr = VDSO_HIGH_BASE;
23857 else {
23858- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
23859+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
23860 if (IS_ERR_VALUE(addr)) {
23861 ret = addr;
23862 goto up_fail;
23863 }
23864 }
23865
23866- current->mm->context.vdso = (void *)addr;
23867+ current->mm->context.vdso = addr;
23868
23869 if (compat_uses_vma || !compat) {
23870 /*
23871@@ -361,11 +362,11 @@ int arch_setup_additional_pages(struct l
23872 }
23873
23874 current_thread_info()->sysenter_return =
23875- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
23876+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
23877
23878 up_fail:
23879 if (ret)
23880- current->mm->context.vdso = NULL;
23881+ current->mm->context.vdso = 0;
23882
23883 up_write(&mm->mmap_sem);
23884
23885@@ -412,8 +413,14 @@ __initcall(ia32_binfmt_init);
23886
23887 const char *arch_vma_name(struct vm_area_struct *vma)
23888 {
23889- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
23890+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
23891 return "[vdso]";
23892+
23893+#ifdef CONFIG_PAX_SEGMEXEC
23894+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
23895+ return "[vdso]";
23896+#endif
23897+
23898 return NULL;
23899 }
23900
23901@@ -423,7 +430,7 @@ struct vm_area_struct *get_gate_vma(stru
23902 * Check to see if the corresponding task was created in compat vdso
23903 * mode.
23904 */
23905- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
23906+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
23907 return &gate_vma;
23908 return NULL;
23909 }
23910diff -urNp linux-2.6.39.1/arch/x86/vdso/vdso.lds.S linux-2.6.39.1/arch/x86/vdso/vdso.lds.S
23911--- linux-2.6.39.1/arch/x86/vdso/vdso.lds.S 2011-05-19 00:06:34.000000000 -0400
23912+++ linux-2.6.39.1/arch/x86/vdso/vdso.lds.S 2011-06-06 17:34:26.000000000 -0400
23913@@ -35,3 +35,9 @@ VDSO64_PRELINK = VDSO_PRELINK;
23914 #define VEXTERN(x) VDSO64_ ## x = vdso_ ## x;
23915 #include "vextern.h"
23916 #undef VEXTERN
23917+
23918+#define VEXTERN(x) VDSO64_ ## x = __vdso_ ## x;
23919+VEXTERN(fallback_gettimeofday)
23920+VEXTERN(fallback_time)
23921+VEXTERN(getcpu)
23922+#undef VEXTERN
23923diff -urNp linux-2.6.39.1/arch/x86/vdso/vextern.h linux-2.6.39.1/arch/x86/vdso/vextern.h
23924--- linux-2.6.39.1/arch/x86/vdso/vextern.h 2011-05-19 00:06:34.000000000 -0400
23925+++ linux-2.6.39.1/arch/x86/vdso/vextern.h 2011-05-22 19:36:30.000000000 -0400
23926@@ -11,6 +11,5 @@
23927 put into vextern.h and be referenced as a pointer with vdso prefix.
23928 The main kernel later fills in the values. */
23929
23930-VEXTERN(jiffies)
23931 VEXTERN(vgetcpu_mode)
23932 VEXTERN(vsyscall_gtod_data)
23933diff -urNp linux-2.6.39.1/arch/x86/vdso/vma.c linux-2.6.39.1/arch/x86/vdso/vma.c
23934--- linux-2.6.39.1/arch/x86/vdso/vma.c 2011-05-19 00:06:34.000000000 -0400
23935+++ linux-2.6.39.1/arch/x86/vdso/vma.c 2011-05-22 19:36:30.000000000 -0400
23936@@ -58,7 +58,7 @@ static int __init init_vdso_vars(void)
23937 if (!vbase)
23938 goto oom;
23939
23940- if (memcmp(vbase, "\177ELF", 4)) {
23941+ if (memcmp(vbase, ELFMAG, SELFMAG)) {
23942 printk("VDSO: I'm broken; not ELF\n");
23943 vdso_enabled = 0;
23944 }
23945@@ -118,7 +118,7 @@ int arch_setup_additional_pages(struct l
23946 goto up_fail;
23947 }
23948
23949- current->mm->context.vdso = (void *)addr;
23950+ current->mm->context.vdso = addr;
23951
23952 ret = install_special_mapping(mm, addr, vdso_size,
23953 VM_READ|VM_EXEC|
23954@@ -126,7 +126,7 @@ int arch_setup_additional_pages(struct l
23955 VM_ALWAYSDUMP,
23956 vdso_pages);
23957 if (ret) {
23958- current->mm->context.vdso = NULL;
23959+ current->mm->context.vdso = 0;
23960 goto up_fail;
23961 }
23962
23963@@ -134,10 +134,3 @@ up_fail:
23964 up_write(&mm->mmap_sem);
23965 return ret;
23966 }
23967-
23968-static __init int vdso_setup(char *s)
23969-{
23970- vdso_enabled = simple_strtoul(s, NULL, 0);
23971- return 0;
23972-}
23973-__setup("vdso=", vdso_setup);
23974diff -urNp linux-2.6.39.1/arch/x86/xen/enlighten.c linux-2.6.39.1/arch/x86/xen/enlighten.c
23975--- linux-2.6.39.1/arch/x86/xen/enlighten.c 2011-05-19 00:06:34.000000000 -0400
23976+++ linux-2.6.39.1/arch/x86/xen/enlighten.c 2011-05-22 19:36:30.000000000 -0400
23977@@ -85,8 +85,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
23978
23979 struct shared_info xen_dummy_shared_info;
23980
23981-void *xen_initial_gdt;
23982-
23983 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
23984 __read_mostly int xen_have_vector_callback;
23985 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
23986@@ -1010,7 +1008,7 @@ static const struct pv_apic_ops xen_apic
23987 #endif
23988 };
23989
23990-static void xen_reboot(int reason)
23991+static __noreturn void xen_reboot(int reason)
23992 {
23993 struct sched_shutdown r = { .reason = reason };
23994
23995@@ -1018,17 +1016,17 @@ static void xen_reboot(int reason)
23996 BUG();
23997 }
23998
23999-static void xen_restart(char *msg)
24000+static __noreturn void xen_restart(char *msg)
24001 {
24002 xen_reboot(SHUTDOWN_reboot);
24003 }
24004
24005-static void xen_emergency_restart(void)
24006+static __noreturn void xen_emergency_restart(void)
24007 {
24008 xen_reboot(SHUTDOWN_reboot);
24009 }
24010
24011-static void xen_machine_halt(void)
24012+static __noreturn void xen_machine_halt(void)
24013 {
24014 xen_reboot(SHUTDOWN_poweroff);
24015 }
24016@@ -1127,7 +1125,17 @@ asmlinkage void __init xen_start_kernel(
24017 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
24018
24019 /* Work out if we support NX */
24020- x86_configure_nx();
24021+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
24022+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
24023+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
24024+ unsigned l, h;
24025+
24026+ __supported_pte_mask |= _PAGE_NX;
24027+ rdmsr(MSR_EFER, l, h);
24028+ l |= EFER_NX;
24029+ wrmsr(MSR_EFER, l, h);
24030+ }
24031+#endif
24032
24033 xen_setup_features();
24034
24035@@ -1158,13 +1166,6 @@ asmlinkage void __init xen_start_kernel(
24036
24037 machine_ops = xen_machine_ops;
24038
24039- /*
24040- * The only reliable way to retain the initial address of the
24041- * percpu gdt_page is to remember it here, so we can go and
24042- * mark it RW later, when the initial percpu area is freed.
24043- */
24044- xen_initial_gdt = &per_cpu(gdt_page, 0);
24045-
24046 xen_smp_init();
24047
24048 #ifdef CONFIG_ACPI_NUMA
24049diff -urNp linux-2.6.39.1/arch/x86/xen/mmu.c linux-2.6.39.1/arch/x86/xen/mmu.c
24050--- linux-2.6.39.1/arch/x86/xen/mmu.c 2011-06-03 00:04:13.000000000 -0400
24051+++ linux-2.6.39.1/arch/x86/xen/mmu.c 2011-06-03 00:32:05.000000000 -0400
24052@@ -1791,6 +1791,8 @@ __init pgd_t *xen_setup_kernel_pagetable
24053 convert_pfn_mfn(init_level4_pgt);
24054 convert_pfn_mfn(level3_ident_pgt);
24055 convert_pfn_mfn(level3_kernel_pgt);
24056+ convert_pfn_mfn(level3_vmalloc_pgt);
24057+ convert_pfn_mfn(level3_vmemmap_pgt);
24058
24059 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
24060 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
24061@@ -1809,7 +1811,10 @@ __init pgd_t *xen_setup_kernel_pagetable
24062 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
24063 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
24064 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
24065+ set_page_prot(level3_vmalloc_pgt, PAGE_KERNEL_RO);
24066+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
24067 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
24068+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
24069 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
24070 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
24071
24072diff -urNp linux-2.6.39.1/arch/x86/xen/pci-swiotlb-xen.c linux-2.6.39.1/arch/x86/xen/pci-swiotlb-xen.c
24073--- linux-2.6.39.1/arch/x86/xen/pci-swiotlb-xen.c 2011-05-19 00:06:34.000000000 -0400
24074+++ linux-2.6.39.1/arch/x86/xen/pci-swiotlb-xen.c 2011-05-22 19:36:30.000000000 -0400
24075@@ -10,7 +10,7 @@
24076
24077 int xen_swiotlb __read_mostly;
24078
24079-static struct dma_map_ops xen_swiotlb_dma_ops = {
24080+static const struct dma_map_ops xen_swiotlb_dma_ops = {
24081 .mapping_error = xen_swiotlb_dma_mapping_error,
24082 .alloc_coherent = xen_swiotlb_alloc_coherent,
24083 .free_coherent = xen_swiotlb_free_coherent,
24084diff -urNp linux-2.6.39.1/arch/x86/xen/smp.c linux-2.6.39.1/arch/x86/xen/smp.c
24085--- linux-2.6.39.1/arch/x86/xen/smp.c 2011-05-19 00:06:34.000000000 -0400
24086+++ linux-2.6.39.1/arch/x86/xen/smp.c 2011-05-22 19:36:30.000000000 -0400
24087@@ -194,11 +194,6 @@ static void __init xen_smp_prepare_boot_
24088 {
24089 BUG_ON(smp_processor_id() != 0);
24090 native_smp_prepare_boot_cpu();
24091-
24092- /* We've switched to the "real" per-cpu gdt, so make sure the
24093- old memory can be recycled */
24094- make_lowmem_page_readwrite(xen_initial_gdt);
24095-
24096 xen_filter_cpu_maps();
24097 xen_setup_vcpu_info_placement();
24098 }
24099@@ -259,12 +254,12 @@ cpu_initialize_context(unsigned int cpu,
24100 gdt = get_cpu_gdt_table(cpu);
24101
24102 ctxt->flags = VGCF_IN_KERNEL;
24103- ctxt->user_regs.ds = __USER_DS;
24104- ctxt->user_regs.es = __USER_DS;
24105+ ctxt->user_regs.ds = __KERNEL_DS;
24106+ ctxt->user_regs.es = __KERNEL_DS;
24107 ctxt->user_regs.ss = __KERNEL_DS;
24108 #ifdef CONFIG_X86_32
24109 ctxt->user_regs.fs = __KERNEL_PERCPU;
24110- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
24111+ savesegment(gs, ctxt->user_regs.gs);
24112 #else
24113 ctxt->gs_base_kernel = per_cpu_offset(cpu);
24114 #endif
24115@@ -315,13 +310,12 @@ static int __cpuinit xen_cpu_up(unsigned
24116 int rc;
24117
24118 per_cpu(current_task, cpu) = idle;
24119+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
24120 #ifdef CONFIG_X86_32
24121 irq_ctx_init(cpu);
24122 #else
24123 clear_tsk_thread_flag(idle, TIF_FORK);
24124- per_cpu(kernel_stack, cpu) =
24125- (unsigned long)task_stack_page(idle) -
24126- KERNEL_STACK_OFFSET + THREAD_SIZE;
24127+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
24128 #endif
24129 xen_setup_runstate_info(cpu);
24130 xen_setup_timer(cpu);
24131diff -urNp linux-2.6.39.1/arch/x86/xen/xen-asm_32.S linux-2.6.39.1/arch/x86/xen/xen-asm_32.S
24132--- linux-2.6.39.1/arch/x86/xen/xen-asm_32.S 2011-05-19 00:06:34.000000000 -0400
24133+++ linux-2.6.39.1/arch/x86/xen/xen-asm_32.S 2011-05-22 19:36:30.000000000 -0400
24134@@ -83,14 +83,14 @@ ENTRY(xen_iret)
24135 ESP_OFFSET=4 # bytes pushed onto stack
24136
24137 /*
24138- * Store vcpu_info pointer for easy access. Do it this way to
24139- * avoid having to reload %fs
24140+ * Store vcpu_info pointer for easy access.
24141 */
24142 #ifdef CONFIG_SMP
24143- GET_THREAD_INFO(%eax)
24144- movl TI_cpu(%eax), %eax
24145- movl __per_cpu_offset(,%eax,4), %eax
24146- mov xen_vcpu(%eax), %eax
24147+ push %fs
24148+ mov $(__KERNEL_PERCPU), %eax
24149+ mov %eax, %fs
24150+ mov PER_CPU_VAR(xen_vcpu), %eax
24151+ pop %fs
24152 #else
24153 movl xen_vcpu, %eax
24154 #endif
24155diff -urNp linux-2.6.39.1/arch/x86/xen/xen-head.S linux-2.6.39.1/arch/x86/xen/xen-head.S
24156--- linux-2.6.39.1/arch/x86/xen/xen-head.S 2011-05-19 00:06:34.000000000 -0400
24157+++ linux-2.6.39.1/arch/x86/xen/xen-head.S 2011-05-22 19:36:30.000000000 -0400
24158@@ -19,6 +19,17 @@ ENTRY(startup_xen)
24159 #ifdef CONFIG_X86_32
24160 mov %esi,xen_start_info
24161 mov $init_thread_union+THREAD_SIZE,%esp
24162+#ifdef CONFIG_SMP
24163+ movl $cpu_gdt_table,%edi
24164+ movl $__per_cpu_load,%eax
24165+ movw %ax,__KERNEL_PERCPU + 2(%edi)
24166+ rorl $16,%eax
24167+ movb %al,__KERNEL_PERCPU + 4(%edi)
24168+ movb %ah,__KERNEL_PERCPU + 7(%edi)
24169+ movl $__per_cpu_end - 1,%eax
24170+ subl $__per_cpu_start,%eax
24171+ movw %ax,__KERNEL_PERCPU + 0(%edi)
24172+#endif
24173 #else
24174 mov %rsi,xen_start_info
24175 mov $init_thread_union+THREAD_SIZE,%rsp
24176diff -urNp linux-2.6.39.1/arch/x86/xen/xen-ops.h linux-2.6.39.1/arch/x86/xen/xen-ops.h
24177--- linux-2.6.39.1/arch/x86/xen/xen-ops.h 2011-05-19 00:06:34.000000000 -0400
24178+++ linux-2.6.39.1/arch/x86/xen/xen-ops.h 2011-05-22 19:36:30.000000000 -0400
24179@@ -10,8 +10,6 @@
24180 extern const char xen_hypervisor_callback[];
24181 extern const char xen_failsafe_callback[];
24182
24183-extern void *xen_initial_gdt;
24184-
24185 struct trap_info;
24186 void xen_copy_trap_info(struct trap_info *traps);
24187
24188diff -urNp linux-2.6.39.1/block/blk-iopoll.c linux-2.6.39.1/block/blk-iopoll.c
24189--- linux-2.6.39.1/block/blk-iopoll.c 2011-05-19 00:06:34.000000000 -0400
24190+++ linux-2.6.39.1/block/blk-iopoll.c 2011-05-22 19:36:30.000000000 -0400
24191@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopo
24192 }
24193 EXPORT_SYMBOL(blk_iopoll_complete);
24194
24195-static void blk_iopoll_softirq(struct softirq_action *h)
24196+static void blk_iopoll_softirq(void)
24197 {
24198 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
24199 int rearm = 0, budget = blk_iopoll_budget;
24200diff -urNp linux-2.6.39.1/block/blk-map.c linux-2.6.39.1/block/blk-map.c
24201--- linux-2.6.39.1/block/blk-map.c 2011-05-19 00:06:34.000000000 -0400
24202+++ linux-2.6.39.1/block/blk-map.c 2011-05-22 19:36:30.000000000 -0400
24203@@ -301,7 +301,7 @@ int blk_rq_map_kern(struct request_queue
24204 if (!len || !kbuf)
24205 return -EINVAL;
24206
24207- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
24208+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
24209 if (do_copy)
24210 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
24211 else
24212diff -urNp linux-2.6.39.1/block/blk-softirq.c linux-2.6.39.1/block/blk-softirq.c
24213--- linux-2.6.39.1/block/blk-softirq.c 2011-05-19 00:06:34.000000000 -0400
24214+++ linux-2.6.39.1/block/blk-softirq.c 2011-05-22 19:36:30.000000000 -0400
24215@@ -17,7 +17,7 @@ static DEFINE_PER_CPU(struct list_head,
24216 * Softirq action handler - move entries to local list and loop over them
24217 * while passing them to the queue registered handler.
24218 */
24219-static void blk_done_softirq(struct softirq_action *h)
24220+static void blk_done_softirq(void)
24221 {
24222 struct list_head *cpu_list, local_list;
24223
24224diff -urNp linux-2.6.39.1/block/bsg.c linux-2.6.39.1/block/bsg.c
24225--- linux-2.6.39.1/block/bsg.c 2011-05-19 00:06:34.000000000 -0400
24226+++ linux-2.6.39.1/block/bsg.c 2011-05-22 19:36:30.000000000 -0400
24227@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct r
24228 struct sg_io_v4 *hdr, struct bsg_device *bd,
24229 fmode_t has_write_perm)
24230 {
24231+ unsigned char tmpcmd[sizeof(rq->__cmd)];
24232+ unsigned char *cmdptr;
24233+
24234 if (hdr->request_len > BLK_MAX_CDB) {
24235 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
24236 if (!rq->cmd)
24237 return -ENOMEM;
24238- }
24239+ cmdptr = rq->cmd;
24240+ } else
24241+ cmdptr = tmpcmd;
24242
24243- if (copy_from_user(rq->cmd, (void *)(unsigned long)hdr->request,
24244+ if (copy_from_user(cmdptr, (void *)(unsigned long)hdr->request,
24245 hdr->request_len))
24246 return -EFAULT;
24247
24248+ if (cmdptr != rq->cmd)
24249+ memcpy(rq->cmd, cmdptr, hdr->request_len);
24250+
24251 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
24252 if (blk_verify_command(rq->cmd, has_write_perm))
24253 return -EPERM;
24254diff -urNp linux-2.6.39.1/block/scsi_ioctl.c linux-2.6.39.1/block/scsi_ioctl.c
24255--- linux-2.6.39.1/block/scsi_ioctl.c 2011-05-19 00:06:34.000000000 -0400
24256+++ linux-2.6.39.1/block/scsi_ioctl.c 2011-05-22 19:36:30.000000000 -0400
24257@@ -222,8 +222,20 @@ EXPORT_SYMBOL(blk_verify_command);
24258 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
24259 struct sg_io_hdr *hdr, fmode_t mode)
24260 {
24261- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
24262+ unsigned char tmpcmd[sizeof(rq->__cmd)];
24263+ unsigned char *cmdptr;
24264+
24265+ if (rq->cmd != rq->__cmd)
24266+ cmdptr = rq->cmd;
24267+ else
24268+ cmdptr = tmpcmd;
24269+
24270+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
24271 return -EFAULT;
24272+
24273+ if (cmdptr != rq->cmd)
24274+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
24275+
24276 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
24277 return -EPERM;
24278
24279@@ -432,6 +444,8 @@ int sg_scsi_ioctl(struct request_queue *
24280 int err;
24281 unsigned int in_len, out_len, bytes, opcode, cmdlen;
24282 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
24283+ unsigned char tmpcmd[sizeof(rq->__cmd)];
24284+ unsigned char *cmdptr;
24285
24286 if (!sic)
24287 return -EINVAL;
24288@@ -465,9 +479,18 @@ int sg_scsi_ioctl(struct request_queue *
24289 */
24290 err = -EFAULT;
24291 rq->cmd_len = cmdlen;
24292- if (copy_from_user(rq->cmd, sic->data, cmdlen))
24293+
24294+ if (rq->cmd != rq->__cmd)
24295+ cmdptr = rq->cmd;
24296+ else
24297+ cmdptr = tmpcmd;
24298+
24299+ if (copy_from_user(cmdptr, sic->data, cmdlen))
24300 goto error;
24301
24302+ if (rq->cmd != cmdptr)
24303+ memcpy(rq->cmd, cmdptr, cmdlen);
24304+
24305 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
24306 goto error;
24307
24308diff -urNp linux-2.6.39.1/crypto/serpent.c linux-2.6.39.1/crypto/serpent.c
24309--- linux-2.6.39.1/crypto/serpent.c 2011-05-19 00:06:34.000000000 -0400
24310+++ linux-2.6.39.1/crypto/serpent.c 2011-05-22 19:36:30.000000000 -0400
24311@@ -224,6 +224,8 @@ static int serpent_setkey(struct crypto_
24312 u32 r0,r1,r2,r3,r4;
24313 int i;
24314
24315+ pax_track_stack();
24316+
24317 /* Copy key, add padding */
24318
24319 for (i = 0; i < keylen; ++i)
24320diff -urNp linux-2.6.39.1/Documentation/dontdiff linux-2.6.39.1/Documentation/dontdiff
24321--- linux-2.6.39.1/Documentation/dontdiff 2011-05-19 00:06:34.000000000 -0400
24322+++ linux-2.6.39.1/Documentation/dontdiff 2011-05-22 19:36:30.000000000 -0400
24323@@ -1,13 +1,16 @@
24324 *.a
24325 *.aux
24326 *.bin
24327+*.cis
24328 *.cpio
24329 *.csp
24330+*.dbg
24331 *.dsp
24332 *.dvi
24333 *.elf
24334 *.eps
24335 *.fw
24336+*.gcno
24337 *.gen.S
24338 *.gif
24339 *.grep
24340@@ -38,8 +41,10 @@
24341 *.tab.h
24342 *.tex
24343 *.ver
24344+*.vim
24345 *.xml
24346 *_MODULES
24347+*_reg_safe.h
24348 *_vga16.c
24349 *~
24350 *.9
24351@@ -49,11 +54,16 @@
24352 53c700_d.h
24353 CVS
24354 ChangeSet
24355+GPATH
24356+GRTAGS
24357+GSYMS
24358+GTAGS
24359 Image
24360 Kerntypes
24361 Module.markers
24362 Module.symvers
24363 PENDING
24364+PERF*
24365 SCCS
24366 System.map*
24367 TAGS
24368@@ -80,8 +90,11 @@ btfixupprep
24369 build
24370 bvmlinux
24371 bzImage*
24372+capability_names.h
24373 capflags.c
24374 classlist.h*
24375+clut_vga16.c
24376+common-cmds.h
24377 comp*.log
24378 compile.h*
24379 conf
24380@@ -106,16 +119,19 @@ fore200e_mkfirm
24381 fore200e_pca_fw.c*
24382 gconf
24383 gen-devlist
24384+gen-kdb_cmds.c
24385 gen_crc32table
24386 gen_init_cpio
24387 generated
24388 genheaders
24389 genksyms
24390 *_gray256.c
24391+hash
24392 ihex2fw
24393 ikconfig.h*
24394 inat-tables.c
24395 initramfs_data.cpio
24396+initramfs_data.cpio.bz2
24397 initramfs_data.cpio.gz
24398 initramfs_list
24399 int16.c
24400@@ -125,7 +141,6 @@ int32.c
24401 int4.c
24402 int8.c
24403 kallsyms
24404-kconfig
24405 keywords.c
24406 ksym.c*
24407 ksym.h*
24408@@ -149,7 +164,9 @@ mkboot
24409 mkbugboot
24410 mkcpustr
24411 mkdep
24412+mkpiggy
24413 mkprep
24414+mkregtable
24415 mktables
24416 mktree
24417 modpost
24418@@ -165,6 +182,7 @@ parse.h
24419 patches*
24420 pca200e.bin
24421 pca200e_ecd.bin2
24422+perf-archive
24423 piggy.gz
24424 piggyback
24425 piggy.S
24426@@ -180,7 +198,9 @@ r600_reg_safe.h
24427 raid6altivec*.c
24428 raid6int*.c
24429 raid6tables.c
24430+regdb.c
24431 relocs
24432+rlim_names.h
24433 rn50_reg_safe.h
24434 rs600_reg_safe.h
24435 rv515_reg_safe.h
24436@@ -189,6 +209,7 @@ setup
24437 setup.bin
24438 setup.elf
24439 sImage
24440+slabinfo
24441 sm_tbl*
24442 split-include
24443 syscalltab.h
24444@@ -213,13 +234,17 @@ version.h*
24445 vmlinux
24446 vmlinux-*
24447 vmlinux.aout
24448+vmlinux.bin.all
24449+vmlinux.bin.bz2
24450 vmlinux.lds
24451+vmlinux.relocs
24452 voffset.h
24453 vsyscall.lds
24454 vsyscall_32.lds
24455 wanxlfw.inc
24456 uImage
24457 unifdef
24458+utsrelease.h
24459 wakeup.bin
24460 wakeup.elf
24461 wakeup.lds
24462diff -urNp linux-2.6.39.1/Documentation/filesystems/configfs/configfs_example_macros.c linux-2.6.39.1/Documentation/filesystems/configfs/configfs_example_macros.c
24463--- linux-2.6.39.1/Documentation/filesystems/configfs/configfs_example_macros.c 2011-05-19 00:06:34.000000000 -0400
24464+++ linux-2.6.39.1/Documentation/filesystems/configfs/configfs_example_macros.c 2011-05-22 19:36:30.000000000 -0400
24465@@ -368,7 +368,7 @@ static struct configfs_item_operations g
24466 * Note that, since no extra work is required on ->drop_item(),
24467 * no ->drop_item() is provided.
24468 */
24469-static struct configfs_group_operations group_children_group_ops = {
24470+static const struct configfs_group_operations group_children_group_ops = {
24471 .make_group = group_children_make_group,
24472 };
24473
24474diff -urNp linux-2.6.39.1/Documentation/filesystems/sysfs.txt linux-2.6.39.1/Documentation/filesystems/sysfs.txt
24475--- linux-2.6.39.1/Documentation/filesystems/sysfs.txt 2011-05-19 00:06:34.000000000 -0400
24476+++ linux-2.6.39.1/Documentation/filesystems/sysfs.txt 2011-05-22 19:36:30.000000000 -0400
24477@@ -125,8 +125,8 @@ set of sysfs operations for forwarding r
24478 show and store methods of the attribute owners.
24479
24480 struct sysfs_ops {
24481- ssize_t (*show)(struct kobject *, struct attribute *, char *);
24482- ssize_t (*store)(struct kobject *, struct attribute *, const char *, size_t);
24483+ ssize_t (* const show)(struct kobject *, struct attribute *, char *);
24484+ ssize_t (* const store)(struct kobject *, struct attribute *, const char *, size_t);
24485 };
24486
24487 [ Subsystems should have already defined a struct kobj_type as a
24488diff -urNp linux-2.6.39.1/Documentation/kernel-parameters.txt linux-2.6.39.1/Documentation/kernel-parameters.txt
24489--- linux-2.6.39.1/Documentation/kernel-parameters.txt 2011-05-19 00:06:34.000000000 -0400
24490+++ linux-2.6.39.1/Documentation/kernel-parameters.txt 2011-05-22 19:36:30.000000000 -0400
24491@@ -1879,6 +1879,13 @@ bytes respectively. Such letter suffixes
24492 the specified number of seconds. This is to be used if
24493 your oopses keep scrolling off the screen.
24494
24495+ pax_nouderef [X86] disables UDEREF. Most likely needed under certain
24496+ virtualization environments that don't cope well with the
24497+ expand down segment used by UDEREF on X86-32 or the frequent
24498+ page table updates on X86-64.
24499+
24500+ pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
24501+
24502 pcbit= [HW,ISDN]
24503
24504 pcd. [PARIDE]
24505diff -urNp linux-2.6.39.1/drivers/acpi/acpi_ipmi.c linux-2.6.39.1/drivers/acpi/acpi_ipmi.c
24506--- linux-2.6.39.1/drivers/acpi/acpi_ipmi.c 2011-05-19 00:06:34.000000000 -0400
24507+++ linux-2.6.39.1/drivers/acpi/acpi_ipmi.c 2011-05-22 19:36:30.000000000 -0400
24508@@ -70,7 +70,7 @@ struct acpi_ipmi_device {
24509 struct ipmi_driver_data {
24510 struct list_head ipmi_devices;
24511 struct ipmi_smi_watcher bmc_events;
24512- struct ipmi_user_hndl ipmi_hndlrs;
24513+ const struct ipmi_user_hndl ipmi_hndlrs;
24514 struct mutex ipmi_lock;
24515 };
24516
24517diff -urNp linux-2.6.39.1/drivers/acpi/apei/cper.c linux-2.6.39.1/drivers/acpi/apei/cper.c
24518--- linux-2.6.39.1/drivers/acpi/apei/cper.c 2011-05-19 00:06:34.000000000 -0400
24519+++ linux-2.6.39.1/drivers/acpi/apei/cper.c 2011-05-22 19:36:30.000000000 -0400
24520@@ -38,12 +38,12 @@
24521 */
24522 u64 cper_next_record_id(void)
24523 {
24524- static atomic64_t seq;
24525+ static atomic64_unchecked_t seq;
24526
24527- if (!atomic64_read(&seq))
24528- atomic64_set(&seq, ((u64)get_seconds()) << 32);
24529+ if (!atomic64_read_unchecked(&seq))
24530+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
24531
24532- return atomic64_inc_return(&seq);
24533+ return atomic64_inc_return_unchecked(&seq);
24534 }
24535 EXPORT_SYMBOL_GPL(cper_next_record_id);
24536
24537diff -urNp linux-2.6.39.1/drivers/acpi/battery.c linux-2.6.39.1/drivers/acpi/battery.c
24538--- linux-2.6.39.1/drivers/acpi/battery.c 2011-05-19 00:06:34.000000000 -0400
24539+++ linux-2.6.39.1/drivers/acpi/battery.c 2011-05-22 19:36:30.000000000 -0400
24540@@ -864,7 +864,7 @@ DECLARE_FILE_FUNCTIONS(alarm);
24541 }
24542
24543 static struct battery_file {
24544- struct file_operations ops;
24545+ const struct file_operations ops;
24546 mode_t mode;
24547 const char *name;
24548 } acpi_battery_file[] = {
24549diff -urNp linux-2.6.39.1/drivers/acpi/dock.c linux-2.6.39.1/drivers/acpi/dock.c
24550--- linux-2.6.39.1/drivers/acpi/dock.c 2011-05-19 00:06:34.000000000 -0400
24551+++ linux-2.6.39.1/drivers/acpi/dock.c 2011-05-22 19:36:30.000000000 -0400
24552@@ -77,7 +77,7 @@ struct dock_dependent_device {
24553 struct list_head list;
24554 struct list_head hotplug_list;
24555 acpi_handle handle;
24556- struct acpi_dock_ops *ops;
24557+ const struct acpi_dock_ops *ops;
24558 void *context;
24559 };
24560
24561@@ -589,7 +589,7 @@ EXPORT_SYMBOL_GPL(unregister_dock_notifi
24562 * the dock driver after _DCK is executed.
24563 */
24564 int
24565-register_hotplug_dock_device(acpi_handle handle, struct acpi_dock_ops *ops,
24566+register_hotplug_dock_device(acpi_handle handle, const struct acpi_dock_ops *ops,
24567 void *context)
24568 {
24569 struct dock_dependent_device *dd;
24570diff -urNp linux-2.6.39.1/drivers/acpi/ec_sys.c linux-2.6.39.1/drivers/acpi/ec_sys.c
24571--- linux-2.6.39.1/drivers/acpi/ec_sys.c 2011-05-19 00:06:34.000000000 -0400
24572+++ linux-2.6.39.1/drivers/acpi/ec_sys.c 2011-05-22 19:36:30.000000000 -0400
24573@@ -92,7 +92,7 @@ static ssize_t acpi_ec_write_io(struct f
24574 return count;
24575 }
24576
24577-static struct file_operations acpi_ec_io_ops = {
24578+static const struct file_operations acpi_ec_io_ops = {
24579 .owner = THIS_MODULE,
24580 .open = acpi_ec_open_io,
24581 .read = acpi_ec_read_io,
24582diff -urNp linux-2.6.39.1/drivers/acpi/fan.c linux-2.6.39.1/drivers/acpi/fan.c
24583--- linux-2.6.39.1/drivers/acpi/fan.c 2011-05-19 00:06:34.000000000 -0400
24584+++ linux-2.6.39.1/drivers/acpi/fan.c 2011-05-22 19:36:30.000000000 -0400
24585@@ -110,7 +110,7 @@ fan_set_cur_state(struct thermal_cooling
24586 return result;
24587 }
24588
24589-static struct thermal_cooling_device_ops fan_cooling_ops = {
24590+static const struct thermal_cooling_device_ops fan_cooling_ops = {
24591 .get_max_state = fan_get_max_state,
24592 .get_cur_state = fan_get_cur_state,
24593 .set_cur_state = fan_set_cur_state,
24594diff -urNp linux-2.6.39.1/drivers/acpi/power_meter.c linux-2.6.39.1/drivers/acpi/power_meter.c
24595--- linux-2.6.39.1/drivers/acpi/power_meter.c 2011-05-19 00:06:34.000000000 -0400
24596+++ linux-2.6.39.1/drivers/acpi/power_meter.c 2011-05-22 19:36:30.000000000 -0400
24597@@ -316,8 +316,6 @@ static ssize_t set_trip(struct device *d
24598 return res;
24599
24600 temp /= 1000;
24601- if (temp < 0)
24602- return -EINVAL;
24603
24604 mutex_lock(&resource->lock);
24605 resource->trip[attr->index - 7] = temp;
24606diff -urNp linux-2.6.39.1/drivers/acpi/proc.c linux-2.6.39.1/drivers/acpi/proc.c
24607--- linux-2.6.39.1/drivers/acpi/proc.c 2011-05-19 00:06:34.000000000 -0400
24608+++ linux-2.6.39.1/drivers/acpi/proc.c 2011-05-22 19:36:30.000000000 -0400
24609@@ -342,19 +342,13 @@ acpi_system_write_wakeup_device(struct f
24610 size_t count, loff_t * ppos)
24611 {
24612 struct list_head *node, *next;
24613- char strbuf[5];
24614- char str[5] = "";
24615- unsigned int len = count;
24616-
24617- if (len > 4)
24618- len = 4;
24619- if (len < 0)
24620- return -EFAULT;
24621+ char strbuf[5] = {0};
24622
24623- if (copy_from_user(strbuf, buffer, len))
24624+ if (count > 4)
24625+ count = 4;
24626+ if (copy_from_user(strbuf, buffer, count))
24627 return -EFAULT;
24628- strbuf[len] = '\0';
24629- sscanf(strbuf, "%s", str);
24630+ strbuf[count] = '\0';
24631
24632 mutex_lock(&acpi_device_lock);
24633 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
24634@@ -363,7 +357,7 @@ acpi_system_write_wakeup_device(struct f
24635 if (!dev->wakeup.flags.valid)
24636 continue;
24637
24638- if (!strncmp(dev->pnp.bus_id, str, 4)) {
24639+ if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
24640 if (device_can_wakeup(&dev->dev)) {
24641 bool enable = !device_may_wakeup(&dev->dev);
24642 device_set_wakeup_enable(&dev->dev, enable);
24643diff -urNp linux-2.6.39.1/drivers/acpi/processor_driver.c linux-2.6.39.1/drivers/acpi/processor_driver.c
24644--- linux-2.6.39.1/drivers/acpi/processor_driver.c 2011-05-19 00:06:34.000000000 -0400
24645+++ linux-2.6.39.1/drivers/acpi/processor_driver.c 2011-05-22 19:36:30.000000000 -0400
24646@@ -473,7 +473,7 @@ static int __cpuinit acpi_processor_add(
24647 return 0;
24648 #endif
24649
24650- BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
24651+ BUG_ON(pr->id >= nr_cpu_ids);
24652
24653 /*
24654 * Buggy BIOS check
24655diff -urNp linux-2.6.39.1/drivers/acpi/processor_idle.c linux-2.6.39.1/drivers/acpi/processor_idle.c
24656--- linux-2.6.39.1/drivers/acpi/processor_idle.c 2011-05-19 00:06:34.000000000 -0400
24657+++ linux-2.6.39.1/drivers/acpi/processor_idle.c 2011-05-22 19:36:30.000000000 -0400
24658@@ -121,7 +121,7 @@ static struct dmi_system_id __cpuinitdat
24659 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
24660 DMI_MATCH(DMI_PRODUCT_NAME,"L8400B series Notebook PC")},
24661 (void *)1},
24662- {},
24663+ {}
24664 };
24665
24666
24667diff -urNp linux-2.6.39.1/drivers/acpi/processor_thermal.c linux-2.6.39.1/drivers/acpi/processor_thermal.c
24668--- linux-2.6.39.1/drivers/acpi/processor_thermal.c 2011-05-19 00:06:34.000000000 -0400
24669+++ linux-2.6.39.1/drivers/acpi/processor_thermal.c 2011-05-22 19:36:30.000000000 -0400
24670@@ -244,7 +244,7 @@ processor_set_cur_state(struct thermal_c
24671 return result;
24672 }
24673
24674-struct thermal_cooling_device_ops processor_cooling_ops = {
24675+const struct thermal_cooling_device_ops processor_cooling_ops = {
24676 .get_max_state = processor_get_max_state,
24677 .get_cur_state = processor_get_cur_state,
24678 .set_cur_state = processor_set_cur_state,
24679diff -urNp linux-2.6.39.1/drivers/acpi/sysfs.c linux-2.6.39.1/drivers/acpi/sysfs.c
24680--- linux-2.6.39.1/drivers/acpi/sysfs.c 2011-05-19 00:06:34.000000000 -0400
24681+++ linux-2.6.39.1/drivers/acpi/sysfs.c 2011-05-22 19:36:30.000000000 -0400
24682@@ -149,12 +149,12 @@ static int param_get_debug_level(char *b
24683 return result;
24684 }
24685
24686-static struct kernel_param_ops param_ops_debug_layer = {
24687+static const struct kernel_param_ops param_ops_debug_layer = {
24688 .set = param_set_uint,
24689 .get = param_get_debug_layer,
24690 };
24691
24692-static struct kernel_param_ops param_ops_debug_level = {
24693+static const struct kernel_param_ops param_ops_debug_level = {
24694 .set = param_set_uint,
24695 .get = param_get_debug_level,
24696 };
24697diff -urNp linux-2.6.39.1/drivers/acpi/thermal.c linux-2.6.39.1/drivers/acpi/thermal.c
24698--- linux-2.6.39.1/drivers/acpi/thermal.c 2011-05-19 00:06:34.000000000 -0400
24699+++ linux-2.6.39.1/drivers/acpi/thermal.c 2011-05-22 19:36:30.000000000 -0400
24700@@ -812,7 +812,7 @@ acpi_thermal_unbind_cooling_device(struc
24701 thermal_zone_unbind_cooling_device);
24702 }
24703
24704-static struct thermal_zone_device_ops acpi_thermal_zone_ops = {
24705+static const struct thermal_zone_device_ops acpi_thermal_zone_ops = {
24706 .bind = acpi_thermal_bind_cooling_device,
24707 .unbind = acpi_thermal_unbind_cooling_device,
24708 .get_temp = thermal_get_temp,
24709diff -urNp linux-2.6.39.1/drivers/acpi/video.c linux-2.6.39.1/drivers/acpi/video.c
24710--- linux-2.6.39.1/drivers/acpi/video.c 2011-05-19 00:06:34.000000000 -0400
24711+++ linux-2.6.39.1/drivers/acpi/video.c 2011-05-22 19:36:30.000000000 -0400
24712@@ -308,7 +308,7 @@ video_set_cur_state(struct thermal_cooli
24713 return acpi_video_device_lcd_set_level(video, level);
24714 }
24715
24716-static struct thermal_cooling_device_ops video_cooling_ops = {
24717+static const struct thermal_cooling_device_ops video_cooling_ops = {
24718 .get_max_state = video_get_max_state,
24719 .get_cur_state = video_get_cur_state,
24720 .set_cur_state = video_set_cur_state,
24721diff -urNp linux-2.6.39.1/drivers/ata/acard-ahci.c linux-2.6.39.1/drivers/ata/acard-ahci.c
24722--- linux-2.6.39.1/drivers/ata/acard-ahci.c 2011-05-19 00:06:34.000000000 -0400
24723+++ linux-2.6.39.1/drivers/ata/acard-ahci.c 2011-05-22 19:36:30.000000000 -0400
24724@@ -87,7 +87,7 @@ static struct scsi_host_template acard_a
24725 AHCI_SHT("acard-ahci"),
24726 };
24727
24728-static struct ata_port_operations acard_ops = {
24729+static const struct ata_port_operations acard_ops = {
24730 .inherits = &ahci_ops,
24731 .qc_prep = acard_ahci_qc_prep,
24732 .qc_fill_rtf = acard_ahci_qc_fill_rtf,
24733diff -urNp linux-2.6.39.1/drivers/ata/ahci.c linux-2.6.39.1/drivers/ata/ahci.c
24734--- linux-2.6.39.1/drivers/ata/ahci.c 2011-05-19 00:06:34.000000000 -0400
24735+++ linux-2.6.39.1/drivers/ata/ahci.c 2011-05-22 19:36:30.000000000 -0400
24736@@ -94,17 +94,17 @@ static struct scsi_host_template ahci_sh
24737 AHCI_SHT("ahci"),
24738 };
24739
24740-static struct ata_port_operations ahci_vt8251_ops = {
24741+static const struct ata_port_operations ahci_vt8251_ops = {
24742 .inherits = &ahci_ops,
24743 .hardreset = ahci_vt8251_hardreset,
24744 };
24745
24746-static struct ata_port_operations ahci_p5wdh_ops = {
24747+static const struct ata_port_operations ahci_p5wdh_ops = {
24748 .inherits = &ahci_ops,
24749 .hardreset = ahci_p5wdh_hardreset,
24750 };
24751
24752-static struct ata_port_operations ahci_sb600_ops = {
24753+static const struct ata_port_operations ahci_sb600_ops = {
24754 .inherits = &ahci_ops,
24755 .softreset = ahci_sb600_softreset,
24756 .pmp_softreset = ahci_sb600_softreset,
24757diff -urNp linux-2.6.39.1/drivers/ata/ahci.h linux-2.6.39.1/drivers/ata/ahci.h
24758--- linux-2.6.39.1/drivers/ata/ahci.h 2011-05-19 00:06:34.000000000 -0400
24759+++ linux-2.6.39.1/drivers/ata/ahci.h 2011-05-22 19:36:30.000000000 -0400
24760@@ -311,7 +311,7 @@ extern struct device_attribute *ahci_sde
24761 .shost_attrs = ahci_shost_attrs, \
24762 .sdev_attrs = ahci_sdev_attrs
24763
24764-extern struct ata_port_operations ahci_ops;
24765+extern const struct ata_port_operations ahci_ops;
24766
24767 void ahci_fill_cmd_slot(struct ahci_port_priv *pp, unsigned int tag,
24768 u32 opts);
24769diff -urNp linux-2.6.39.1/drivers/ata/ata_generic.c linux-2.6.39.1/drivers/ata/ata_generic.c
24770--- linux-2.6.39.1/drivers/ata/ata_generic.c 2011-05-19 00:06:34.000000000 -0400
24771+++ linux-2.6.39.1/drivers/ata/ata_generic.c 2011-05-22 19:36:30.000000000 -0400
24772@@ -101,7 +101,7 @@ static struct scsi_host_template generic
24773 ATA_BMDMA_SHT(DRV_NAME),
24774 };
24775
24776-static struct ata_port_operations generic_port_ops = {
24777+static const struct ata_port_operations generic_port_ops = {
24778 .inherits = &ata_bmdma_port_ops,
24779 .cable_detect = ata_cable_unknown,
24780 .set_mode = generic_set_mode,
24781diff -urNp linux-2.6.39.1/drivers/ata/ata_piix.c linux-2.6.39.1/drivers/ata/ata_piix.c
24782--- linux-2.6.39.1/drivers/ata/ata_piix.c 2011-05-19 00:06:34.000000000 -0400
24783+++ linux-2.6.39.1/drivers/ata/ata_piix.c 2011-05-22 19:36:30.000000000 -0400
24784@@ -335,12 +335,12 @@ static struct scsi_host_template piix_sh
24785 ATA_BMDMA_SHT(DRV_NAME),
24786 };
24787
24788-static struct ata_port_operations piix_sata_ops = {
24789+static const struct ata_port_operations piix_sata_ops = {
24790 .inherits = &ata_bmdma32_port_ops,
24791 .sff_irq_check = piix_irq_check,
24792 };
24793
24794-static struct ata_port_operations piix_pata_ops = {
24795+static const struct ata_port_operations piix_pata_ops = {
24796 .inherits = &piix_sata_ops,
24797 .cable_detect = ata_cable_40wire,
24798 .set_piomode = piix_set_piomode,
24799@@ -348,12 +348,12 @@ static struct ata_port_operations piix_p
24800 .prereset = piix_pata_prereset,
24801 };
24802
24803-static struct ata_port_operations piix_vmw_ops = {
24804+static const struct ata_port_operations piix_vmw_ops = {
24805 .inherits = &piix_pata_ops,
24806 .bmdma_status = piix_vmw_bmdma_status,
24807 };
24808
24809-static struct ata_port_operations ich_pata_ops = {
24810+static const struct ata_port_operations ich_pata_ops = {
24811 .inherits = &piix_pata_ops,
24812 .cable_detect = ich_pata_cable_detect,
24813 .set_dmamode = ich_set_dmamode,
24814@@ -369,7 +369,7 @@ static struct scsi_host_template piix_si
24815 .shost_attrs = piix_sidpr_shost_attrs,
24816 };
24817
24818-static struct ata_port_operations piix_sidpr_sata_ops = {
24819+static const struct ata_port_operations piix_sidpr_sata_ops = {
24820 .inherits = &piix_sata_ops,
24821 .hardreset = sata_std_hardreset,
24822 .scr_read = piix_sidpr_scr_read,
24823diff -urNp linux-2.6.39.1/drivers/ata/libahci.c linux-2.6.39.1/drivers/ata/libahci.c
24824--- linux-2.6.39.1/drivers/ata/libahci.c 2011-05-19 00:06:34.000000000 -0400
24825+++ linux-2.6.39.1/drivers/ata/libahci.c 2011-05-22 19:36:30.000000000 -0400
24826@@ -141,7 +141,7 @@ struct device_attribute *ahci_sdev_attrs
24827 };
24828 EXPORT_SYMBOL_GPL(ahci_sdev_attrs);
24829
24830-struct ata_port_operations ahci_ops = {
24831+const struct ata_port_operations ahci_ops = {
24832 .inherits = &sata_pmp_port_ops,
24833
24834 .qc_defer = ahci_pmp_qc_defer,
24835diff -urNp linux-2.6.39.1/drivers/ata/libata-acpi.c linux-2.6.39.1/drivers/ata/libata-acpi.c
24836--- linux-2.6.39.1/drivers/ata/libata-acpi.c 2011-05-19 00:06:34.000000000 -0400
24837+++ linux-2.6.39.1/drivers/ata/libata-acpi.c 2011-05-22 19:36:30.000000000 -0400
24838@@ -218,12 +218,12 @@ static void ata_acpi_dev_uevent(acpi_han
24839 ata_acpi_uevent(dev->link->ap, dev, event);
24840 }
24841
24842-static struct acpi_dock_ops ata_acpi_dev_dock_ops = {
24843+static const struct acpi_dock_ops ata_acpi_dev_dock_ops = {
24844 .handler = ata_acpi_dev_notify_dock,
24845 .uevent = ata_acpi_dev_uevent,
24846 };
24847
24848-static struct acpi_dock_ops ata_acpi_ap_dock_ops = {
24849+static const struct acpi_dock_ops ata_acpi_ap_dock_ops = {
24850 .handler = ata_acpi_ap_notify_dock,
24851 .uevent = ata_acpi_ap_uevent,
24852 };
24853diff -urNp linux-2.6.39.1/drivers/ata/libata-core.c linux-2.6.39.1/drivers/ata/libata-core.c
24854--- linux-2.6.39.1/drivers/ata/libata-core.c 2011-05-19 00:06:34.000000000 -0400
24855+++ linux-2.6.39.1/drivers/ata/libata-core.c 2011-05-22 19:36:30.000000000 -0400
24856@@ -4747,7 +4747,7 @@ void ata_qc_free(struct ata_queued_cmd *
24857 struct ata_port *ap;
24858 unsigned int tag;
24859
24860- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
24861+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
24862 ap = qc->ap;
24863
24864 qc->flags = 0;
24865@@ -4763,7 +4763,7 @@ void __ata_qc_complete(struct ata_queued
24866 struct ata_port *ap;
24867 struct ata_link *link;
24868
24869- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
24870+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
24871 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
24872 ap = qc->ap;
24873 link = qc->dev->link;
24874@@ -5756,7 +5756,7 @@ static void ata_host_stop(struct device
24875 * LOCKING:
24876 * None.
24877 */
24878-static void ata_finalize_port_ops(struct ata_port_operations *ops)
24879+static void ata_finalize_port_ops(const struct ata_port_operations *ops)
24880 {
24881 static DEFINE_SPINLOCK(lock);
24882 const struct ata_port_operations *cur;
24883@@ -5768,6 +5768,7 @@ static void ata_finalize_port_ops(struct
24884 return;
24885
24886 spin_lock(&lock);
24887+ pax_open_kernel();
24888
24889 for (cur = ops->inherits; cur; cur = cur->inherits) {
24890 void **inherit = (void **)cur;
24891@@ -5781,8 +5782,9 @@ static void ata_finalize_port_ops(struct
24892 if (IS_ERR(*pp))
24893 *pp = NULL;
24894
24895- ops->inherits = NULL;
24896+ ((struct ata_port_operations *)ops)->inherits = NULL;
24897
24898+ pax_close_kernel();
24899 spin_unlock(&lock);
24900 }
24901
24902@@ -5879,7 +5881,7 @@ int ata_host_start(struct ata_host *host
24903 */
24904 /* KILLME - the only user left is ipr */
24905 void ata_host_init(struct ata_host *host, struct device *dev,
24906- unsigned long flags, struct ata_port_operations *ops)
24907+ unsigned long flags, const struct ata_port_operations *ops)
24908 {
24909 spin_lock_init(&host->lock);
24910 mutex_init(&host->eh_mutex);
24911@@ -6583,7 +6585,7 @@ static void ata_dummy_error_handler(stru
24912 /* truly dummy */
24913 }
24914
24915-struct ata_port_operations ata_dummy_port_ops = {
24916+const struct ata_port_operations ata_dummy_port_ops = {
24917 .qc_prep = ata_noop_qc_prep,
24918 .qc_issue = ata_dummy_qc_issue,
24919 .error_handler = ata_dummy_error_handler,
24920diff -urNp linux-2.6.39.1/drivers/ata/libata-eh.c linux-2.6.39.1/drivers/ata/libata-eh.c
24921--- linux-2.6.39.1/drivers/ata/libata-eh.c 2011-05-19 00:06:34.000000000 -0400
24922+++ linux-2.6.39.1/drivers/ata/libata-eh.c 2011-05-22 19:36:30.000000000 -0400
24923@@ -2518,6 +2518,8 @@ void ata_eh_report(struct ata_port *ap)
24924 {
24925 struct ata_link *link;
24926
24927+ pax_track_stack();
24928+
24929 ata_for_each_link(link, ap, HOST_FIRST)
24930 ata_eh_link_report(link);
24931 }
24932@@ -3922,7 +3924,7 @@ void ata_do_eh(struct ata_port *ap, ata_
24933 */
24934 void ata_std_error_handler(struct ata_port *ap)
24935 {
24936- struct ata_port_operations *ops = ap->ops;
24937+ const struct ata_port_operations *ops = ap->ops;
24938 ata_reset_fn_t hardreset = ops->hardreset;
24939
24940 /* ignore built-in hardreset if SCR access is not available */
24941diff -urNp linux-2.6.39.1/drivers/ata/libata-pmp.c linux-2.6.39.1/drivers/ata/libata-pmp.c
24942--- linux-2.6.39.1/drivers/ata/libata-pmp.c 2011-05-19 00:06:34.000000000 -0400
24943+++ linux-2.6.39.1/drivers/ata/libata-pmp.c 2011-05-22 19:36:30.000000000 -0400
24944@@ -912,7 +912,7 @@ static int sata_pmp_handle_link_fail(str
24945 */
24946 static int sata_pmp_eh_recover(struct ata_port *ap)
24947 {
24948- struct ata_port_operations *ops = ap->ops;
24949+ const struct ata_port_operations *ops = ap->ops;
24950 int pmp_tries, link_tries[SATA_PMP_MAX_PORTS];
24951 struct ata_link *pmp_link = &ap->link;
24952 struct ata_device *pmp_dev = pmp_link->device;
24953diff -urNp linux-2.6.39.1/drivers/ata/pata_acpi.c linux-2.6.39.1/drivers/ata/pata_acpi.c
24954--- linux-2.6.39.1/drivers/ata/pata_acpi.c 2011-05-19 00:06:34.000000000 -0400
24955+++ linux-2.6.39.1/drivers/ata/pata_acpi.c 2011-05-22 19:36:30.000000000 -0400
24956@@ -216,7 +216,7 @@ static struct scsi_host_template pacpi_s
24957 ATA_BMDMA_SHT(DRV_NAME),
24958 };
24959
24960-static struct ata_port_operations pacpi_ops = {
24961+static const struct ata_port_operations pacpi_ops = {
24962 .inherits = &ata_bmdma_port_ops,
24963 .qc_issue = pacpi_qc_issue,
24964 .cable_detect = pacpi_cable_detect,
24965diff -urNp linux-2.6.39.1/drivers/ata/pata_ali.c linux-2.6.39.1/drivers/ata/pata_ali.c
24966--- linux-2.6.39.1/drivers/ata/pata_ali.c 2011-05-19 00:06:34.000000000 -0400
24967+++ linux-2.6.39.1/drivers/ata/pata_ali.c 2011-05-22 19:36:30.000000000 -0400
24968@@ -363,7 +363,7 @@ static struct scsi_host_template ali_sht
24969 * Port operations for PIO only ALi
24970 */
24971
24972-static struct ata_port_operations ali_early_port_ops = {
24973+static const struct ata_port_operations ali_early_port_ops = {
24974 .inherits = &ata_sff_port_ops,
24975 .cable_detect = ata_cable_40wire,
24976 .set_piomode = ali_set_piomode,
24977@@ -380,7 +380,7 @@ static const struct ata_port_operations
24978 * Port operations for DMA capable ALi without cable
24979 * detect
24980 */
24981-static struct ata_port_operations ali_20_port_ops = {
24982+static const struct ata_port_operations ali_20_port_ops = {
24983 .inherits = &ali_dma_base_ops,
24984 .cable_detect = ata_cable_40wire,
24985 .mode_filter = ali_20_filter,
24986@@ -391,7 +391,7 @@ static struct ata_port_operations ali_20
24987 /*
24988 * Port operations for DMA capable ALi with cable detect
24989 */
24990-static struct ata_port_operations ali_c2_port_ops = {
24991+static const struct ata_port_operations ali_c2_port_ops = {
24992 .inherits = &ali_dma_base_ops,
24993 .check_atapi_dma = ali_check_atapi_dma,
24994 .cable_detect = ali_c2_cable_detect,
24995@@ -402,7 +402,7 @@ static struct ata_port_operations ali_c2
24996 /*
24997 * Port operations for DMA capable ALi with cable detect
24998 */
24999-static struct ata_port_operations ali_c4_port_ops = {
25000+static const struct ata_port_operations ali_c4_port_ops = {
25001 .inherits = &ali_dma_base_ops,
25002 .check_atapi_dma = ali_check_atapi_dma,
25003 .cable_detect = ali_c2_cable_detect,
25004@@ -412,7 +412,7 @@ static struct ata_port_operations ali_c4
25005 /*
25006 * Port operations for DMA capable ALi with cable detect and LBA48
25007 */
25008-static struct ata_port_operations ali_c5_port_ops = {
25009+static const struct ata_port_operations ali_c5_port_ops = {
25010 .inherits = &ali_dma_base_ops,
25011 .check_atapi_dma = ali_check_atapi_dma,
25012 .dev_config = ali_warn_atapi_dma,
25013diff -urNp linux-2.6.39.1/drivers/ata/pata_amd.c linux-2.6.39.1/drivers/ata/pata_amd.c
25014--- linux-2.6.39.1/drivers/ata/pata_amd.c 2011-05-19 00:06:34.000000000 -0400
25015+++ linux-2.6.39.1/drivers/ata/pata_amd.c 2011-05-22 19:36:31.000000000 -0400
25016@@ -397,28 +397,28 @@ static const struct ata_port_operations
25017 .prereset = amd_pre_reset,
25018 };
25019
25020-static struct ata_port_operations amd33_port_ops = {
25021+static const struct ata_port_operations amd33_port_ops = {
25022 .inherits = &amd_base_port_ops,
25023 .cable_detect = ata_cable_40wire,
25024 .set_piomode = amd33_set_piomode,
25025 .set_dmamode = amd33_set_dmamode,
25026 };
25027
25028-static struct ata_port_operations amd66_port_ops = {
25029+static const struct ata_port_operations amd66_port_ops = {
25030 .inherits = &amd_base_port_ops,
25031 .cable_detect = ata_cable_unknown,
25032 .set_piomode = amd66_set_piomode,
25033 .set_dmamode = amd66_set_dmamode,
25034 };
25035
25036-static struct ata_port_operations amd100_port_ops = {
25037+static const struct ata_port_operations amd100_port_ops = {
25038 .inherits = &amd_base_port_ops,
25039 .cable_detect = ata_cable_unknown,
25040 .set_piomode = amd100_set_piomode,
25041 .set_dmamode = amd100_set_dmamode,
25042 };
25043
25044-static struct ata_port_operations amd133_port_ops = {
25045+static const struct ata_port_operations amd133_port_ops = {
25046 .inherits = &amd_base_port_ops,
25047 .cable_detect = amd_cable_detect,
25048 .set_piomode = amd133_set_piomode,
25049@@ -433,13 +433,13 @@ static const struct ata_port_operations
25050 .host_stop = nv_host_stop,
25051 };
25052
25053-static struct ata_port_operations nv100_port_ops = {
25054+static const struct ata_port_operations nv100_port_ops = {
25055 .inherits = &nv_base_port_ops,
25056 .set_piomode = nv100_set_piomode,
25057 .set_dmamode = nv100_set_dmamode,
25058 };
25059
25060-static struct ata_port_operations nv133_port_ops = {
25061+static const struct ata_port_operations nv133_port_ops = {
25062 .inherits = &nv_base_port_ops,
25063 .set_piomode = nv133_set_piomode,
25064 .set_dmamode = nv133_set_dmamode,
25065diff -urNp linux-2.6.39.1/drivers/ata/pata_arasan_cf.c linux-2.6.39.1/drivers/ata/pata_arasan_cf.c
25066--- linux-2.6.39.1/drivers/ata/pata_arasan_cf.c 2011-05-19 00:06:34.000000000 -0400
25067+++ linux-2.6.39.1/drivers/ata/pata_arasan_cf.c 2011-05-22 19:36:31.000000000 -0400
25068@@ -862,7 +862,9 @@ static int __devinit arasan_cf_probe(str
25069 /* Handle platform specific quirks */
25070 if (pdata->quirk) {
25071 if (pdata->quirk & CF_BROKEN_PIO) {
25072- ap->ops->set_piomode = NULL;
25073+ pax_open_kernel();
25074+ *(void**)&ap->ops->set_piomode = NULL;
25075+ pax_close_kernel();
25076 ap->pio_mask = 0;
25077 }
25078 if (pdata->quirk & CF_BROKEN_MWDMA)
25079diff -urNp linux-2.6.39.1/drivers/ata/pata_artop.c linux-2.6.39.1/drivers/ata/pata_artop.c
25080--- linux-2.6.39.1/drivers/ata/pata_artop.c 2011-05-19 00:06:34.000000000 -0400
25081+++ linux-2.6.39.1/drivers/ata/pata_artop.c 2011-05-22 19:36:31.000000000 -0400
25082@@ -312,7 +312,7 @@ static struct scsi_host_template artop_s
25083 ATA_BMDMA_SHT(DRV_NAME),
25084 };
25085
25086-static struct ata_port_operations artop6210_ops = {
25087+static const struct ata_port_operations artop6210_ops = {
25088 .inherits = &ata_bmdma_port_ops,
25089 .cable_detect = ata_cable_40wire,
25090 .set_piomode = artop6210_set_piomode,
25091@@ -321,7 +321,7 @@ static struct ata_port_operations artop6
25092 .qc_defer = artop6210_qc_defer,
25093 };
25094
25095-static struct ata_port_operations artop6260_ops = {
25096+static const struct ata_port_operations artop6260_ops = {
25097 .inherits = &ata_bmdma_port_ops,
25098 .cable_detect = artop6260_cable_detect,
25099 .set_piomode = artop6260_set_piomode,
25100diff -urNp linux-2.6.39.1/drivers/ata/pata_at32.c linux-2.6.39.1/drivers/ata/pata_at32.c
25101--- linux-2.6.39.1/drivers/ata/pata_at32.c 2011-05-19 00:06:34.000000000 -0400
25102+++ linux-2.6.39.1/drivers/ata/pata_at32.c 2011-05-22 19:36:31.000000000 -0400
25103@@ -173,7 +173,7 @@ static struct scsi_host_template at32_sh
25104 ATA_PIO_SHT(DRV_NAME),
25105 };
25106
25107-static struct ata_port_operations at32_port_ops = {
25108+static const struct ata_port_operations at32_port_ops = {
25109 .inherits = &ata_sff_port_ops,
25110 .cable_detect = ata_cable_40wire,
25111 .set_piomode = pata_at32_set_piomode,
25112diff -urNp linux-2.6.39.1/drivers/ata/pata_at91.c linux-2.6.39.1/drivers/ata/pata_at91.c
25113--- linux-2.6.39.1/drivers/ata/pata_at91.c 2011-05-19 00:06:34.000000000 -0400
25114+++ linux-2.6.39.1/drivers/ata/pata_at91.c 2011-05-22 19:36:31.000000000 -0400
25115@@ -212,7 +212,7 @@ static struct scsi_host_template pata_at
25116 ATA_PIO_SHT(DRV_NAME),
25117 };
25118
25119-static struct ata_port_operations pata_at91_port_ops = {
25120+static const struct ata_port_operations pata_at91_port_ops = {
25121 .inherits = &ata_sff_port_ops,
25122
25123 .sff_data_xfer = pata_at91_data_xfer_noirq,
25124diff -urNp linux-2.6.39.1/drivers/ata/pata_atiixp.c linux-2.6.39.1/drivers/ata/pata_atiixp.c
25125--- linux-2.6.39.1/drivers/ata/pata_atiixp.c 2011-05-19 00:06:34.000000000 -0400
25126+++ linux-2.6.39.1/drivers/ata/pata_atiixp.c 2011-05-22 19:36:31.000000000 -0400
25127@@ -214,7 +214,7 @@ static struct scsi_host_template atiixp_
25128 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
25129 };
25130
25131-static struct ata_port_operations atiixp_port_ops = {
25132+static const struct ata_port_operations atiixp_port_ops = {
25133 .inherits = &ata_bmdma_port_ops,
25134
25135 .qc_prep = ata_bmdma_dumb_qc_prep,
25136diff -urNp linux-2.6.39.1/drivers/ata/pata_atp867x.c linux-2.6.39.1/drivers/ata/pata_atp867x.c
25137--- linux-2.6.39.1/drivers/ata/pata_atp867x.c 2011-05-19 00:06:34.000000000 -0400
25138+++ linux-2.6.39.1/drivers/ata/pata_atp867x.c 2011-05-22 19:36:31.000000000 -0400
25139@@ -275,7 +275,7 @@ static struct scsi_host_template atp867x
25140 ATA_BMDMA_SHT(DRV_NAME),
25141 };
25142
25143-static struct ata_port_operations atp867x_ops = {
25144+static const struct ata_port_operations atp867x_ops = {
25145 .inherits = &ata_bmdma_port_ops,
25146 .cable_detect = atp867x_cable_detect,
25147 .set_piomode = atp867x_set_piomode,
25148diff -urNp linux-2.6.39.1/drivers/ata/pata_bf54x.c linux-2.6.39.1/drivers/ata/pata_bf54x.c
25149--- linux-2.6.39.1/drivers/ata/pata_bf54x.c 2011-05-19 00:06:34.000000000 -0400
25150+++ linux-2.6.39.1/drivers/ata/pata_bf54x.c 2011-05-22 19:36:31.000000000 -0400
25151@@ -1420,7 +1420,7 @@ static struct scsi_host_template bfin_sh
25152 .dma_boundary = ATA_DMA_BOUNDARY,
25153 };
25154
25155-static struct ata_port_operations bfin_pata_ops = {
25156+static const struct ata_port_operations bfin_pata_ops = {
25157 .inherits = &ata_bmdma_port_ops,
25158
25159 .set_piomode = bfin_set_piomode,
25160diff -urNp linux-2.6.39.1/drivers/ata/pata_cmd640.c linux-2.6.39.1/drivers/ata/pata_cmd640.c
25161--- linux-2.6.39.1/drivers/ata/pata_cmd640.c 2011-05-19 00:06:34.000000000 -0400
25162+++ linux-2.6.39.1/drivers/ata/pata_cmd640.c 2011-05-22 19:36:31.000000000 -0400
25163@@ -176,7 +176,7 @@ static struct scsi_host_template cmd640_
25164 ATA_PIO_SHT(DRV_NAME),
25165 };
25166
25167-static struct ata_port_operations cmd640_port_ops = {
25168+static const struct ata_port_operations cmd640_port_ops = {
25169 .inherits = &ata_sff_port_ops,
25170 /* In theory xfer_noirq is not needed once we kill the prefetcher */
25171 .sff_data_xfer = ata_sff_data_xfer_noirq,
25172diff -urNp linux-2.6.39.1/drivers/ata/pata_cmd64x.c linux-2.6.39.1/drivers/ata/pata_cmd64x.c
25173--- linux-2.6.39.1/drivers/ata/pata_cmd64x.c 2011-06-03 00:04:13.000000000 -0400
25174+++ linux-2.6.39.1/drivers/ata/pata_cmd64x.c 2011-06-03 00:32:05.000000000 -0400
25175@@ -271,18 +271,18 @@ static const struct ata_port_operations
25176 .set_dmamode = cmd64x_set_dmamode,
25177 };
25178
25179-static struct ata_port_operations cmd64x_port_ops = {
25180+static const struct ata_port_operations cmd64x_port_ops = {
25181 .inherits = &cmd64x_base_ops,
25182 .cable_detect = ata_cable_40wire,
25183 };
25184
25185-static struct ata_port_operations cmd646r1_port_ops = {
25186+static const struct ata_port_operations cmd646r1_port_ops = {
25187 .inherits = &cmd64x_base_ops,
25188 .bmdma_stop = cmd646r1_bmdma_stop,
25189 .cable_detect = ata_cable_40wire,
25190 };
25191
25192-static struct ata_port_operations cmd648_port_ops = {
25193+static const struct ata_port_operations cmd648_port_ops = {
25194 .inherits = &cmd64x_base_ops,
25195 .bmdma_stop = cmd648_bmdma_stop,
25196 .cable_detect = cmd648_cable_detect,
25197diff -urNp linux-2.6.39.1/drivers/ata/pata_cs5520.c linux-2.6.39.1/drivers/ata/pata_cs5520.c
25198--- linux-2.6.39.1/drivers/ata/pata_cs5520.c 2011-05-19 00:06:34.000000000 -0400
25199+++ linux-2.6.39.1/drivers/ata/pata_cs5520.c 2011-05-22 19:36:31.000000000 -0400
25200@@ -108,7 +108,7 @@ static struct scsi_host_template cs5520_
25201 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
25202 };
25203
25204-static struct ata_port_operations cs5520_port_ops = {
25205+static const struct ata_port_operations cs5520_port_ops = {
25206 .inherits = &ata_bmdma_port_ops,
25207 .qc_prep = ata_bmdma_dumb_qc_prep,
25208 .cable_detect = ata_cable_40wire,
25209diff -urNp linux-2.6.39.1/drivers/ata/pata_cs5530.c linux-2.6.39.1/drivers/ata/pata_cs5530.c
25210--- linux-2.6.39.1/drivers/ata/pata_cs5530.c 2011-05-19 00:06:34.000000000 -0400
25211+++ linux-2.6.39.1/drivers/ata/pata_cs5530.c 2011-05-22 19:36:31.000000000 -0400
25212@@ -164,7 +164,7 @@ static struct scsi_host_template cs5530_
25213 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
25214 };
25215
25216-static struct ata_port_operations cs5530_port_ops = {
25217+static const struct ata_port_operations cs5530_port_ops = {
25218 .inherits = &ata_bmdma_port_ops,
25219
25220 .qc_prep = ata_bmdma_dumb_qc_prep,
25221diff -urNp linux-2.6.39.1/drivers/ata/pata_cs5535.c linux-2.6.39.1/drivers/ata/pata_cs5535.c
25222--- linux-2.6.39.1/drivers/ata/pata_cs5535.c 2011-05-19 00:06:34.000000000 -0400
25223+++ linux-2.6.39.1/drivers/ata/pata_cs5535.c 2011-05-22 19:36:31.000000000 -0400
25224@@ -160,7 +160,7 @@ static struct scsi_host_template cs5535_
25225 ATA_BMDMA_SHT(DRV_NAME),
25226 };
25227
25228-static struct ata_port_operations cs5535_port_ops = {
25229+static const struct ata_port_operations cs5535_port_ops = {
25230 .inherits = &ata_bmdma_port_ops,
25231 .cable_detect = cs5535_cable_detect,
25232 .set_piomode = cs5535_set_piomode,
25233diff -urNp linux-2.6.39.1/drivers/ata/pata_cs5536.c linux-2.6.39.1/drivers/ata/pata_cs5536.c
25234--- linux-2.6.39.1/drivers/ata/pata_cs5536.c 2011-05-19 00:06:34.000000000 -0400
25235+++ linux-2.6.39.1/drivers/ata/pata_cs5536.c 2011-05-22 19:36:31.000000000 -0400
25236@@ -233,7 +233,7 @@ static struct scsi_host_template cs5536_
25237 ATA_BMDMA_SHT(DRV_NAME),
25238 };
25239
25240-static struct ata_port_operations cs5536_port_ops = {
25241+static const struct ata_port_operations cs5536_port_ops = {
25242 .inherits = &ata_bmdma32_port_ops,
25243 .cable_detect = cs5536_cable_detect,
25244 .set_piomode = cs5536_set_piomode,
25245diff -urNp linux-2.6.39.1/drivers/ata/pata_cypress.c linux-2.6.39.1/drivers/ata/pata_cypress.c
25246--- linux-2.6.39.1/drivers/ata/pata_cypress.c 2011-05-19 00:06:34.000000000 -0400
25247+++ linux-2.6.39.1/drivers/ata/pata_cypress.c 2011-05-22 19:36:31.000000000 -0400
25248@@ -115,7 +115,7 @@ static struct scsi_host_template cy82c69
25249 ATA_BMDMA_SHT(DRV_NAME),
25250 };
25251
25252-static struct ata_port_operations cy82c693_port_ops = {
25253+static const struct ata_port_operations cy82c693_port_ops = {
25254 .inherits = &ata_bmdma_port_ops,
25255 .cable_detect = ata_cable_40wire,
25256 .set_piomode = cy82c693_set_piomode,
25257diff -urNp linux-2.6.39.1/drivers/ata/pata_efar.c linux-2.6.39.1/drivers/ata/pata_efar.c
25258--- linux-2.6.39.1/drivers/ata/pata_efar.c 2011-05-19 00:06:34.000000000 -0400
25259+++ linux-2.6.39.1/drivers/ata/pata_efar.c 2011-05-22 19:36:31.000000000 -0400
25260@@ -238,7 +238,7 @@ static struct scsi_host_template efar_sh
25261 ATA_BMDMA_SHT(DRV_NAME),
25262 };
25263
25264-static struct ata_port_operations efar_ops = {
25265+static const struct ata_port_operations efar_ops = {
25266 .inherits = &ata_bmdma_port_ops,
25267 .cable_detect = efar_cable_detect,
25268 .set_piomode = efar_set_piomode,
25269diff -urNp linux-2.6.39.1/drivers/ata/pata_hpt366.c linux-2.6.39.1/drivers/ata/pata_hpt366.c
25270--- linux-2.6.39.1/drivers/ata/pata_hpt366.c 2011-05-19 00:06:34.000000000 -0400
25271+++ linux-2.6.39.1/drivers/ata/pata_hpt366.c 2011-05-22 19:36:31.000000000 -0400
25272@@ -276,7 +276,7 @@ static struct scsi_host_template hpt36x_
25273 * Configuration for HPT366/68
25274 */
25275
25276-static struct ata_port_operations hpt366_port_ops = {
25277+static const struct ata_port_operations hpt366_port_ops = {
25278 .inherits = &ata_bmdma_port_ops,
25279 .cable_detect = hpt36x_cable_detect,
25280 .mode_filter = hpt366_filter,
25281diff -urNp linux-2.6.39.1/drivers/ata/pata_hpt37x.c linux-2.6.39.1/drivers/ata/pata_hpt37x.c
25282--- linux-2.6.39.1/drivers/ata/pata_hpt37x.c 2011-05-19 00:06:34.000000000 -0400
25283+++ linux-2.6.39.1/drivers/ata/pata_hpt37x.c 2011-05-22 19:36:31.000000000 -0400
25284@@ -589,7 +589,7 @@ static struct scsi_host_template hpt37x_
25285 * Configuration for HPT370
25286 */
25287
25288-static struct ata_port_operations hpt370_port_ops = {
25289+static const struct ata_port_operations hpt370_port_ops = {
25290 .inherits = &ata_bmdma_port_ops,
25291
25292 .bmdma_stop = hpt370_bmdma_stop,
25293@@ -605,7 +605,7 @@ static struct ata_port_operations hpt370
25294 * Configuration for HPT370A. Close to 370 but less filters
25295 */
25296
25297-static struct ata_port_operations hpt370a_port_ops = {
25298+static const struct ata_port_operations hpt370a_port_ops = {
25299 .inherits = &hpt370_port_ops,
25300 .mode_filter = hpt370a_filter,
25301 };
25302@@ -615,7 +615,7 @@ static struct ata_port_operations hpt370
25303 * mode setting functionality.
25304 */
25305
25306-static struct ata_port_operations hpt302_port_ops = {
25307+static const struct ata_port_operations hpt302_port_ops = {
25308 .inherits = &ata_bmdma_port_ops,
25309
25310 .bmdma_stop = hpt37x_bmdma_stop,
25311@@ -631,7 +631,7 @@ static struct ata_port_operations hpt302
25312 * but we have a mode filter.
25313 */
25314
25315-static struct ata_port_operations hpt372_port_ops = {
25316+static const struct ata_port_operations hpt372_port_ops = {
25317 .inherits = &hpt302_port_ops,
25318 .mode_filter = hpt372_filter,
25319 };
25320@@ -641,7 +641,7 @@ static struct ata_port_operations hpt372
25321 * but we have a different cable detection procedure for function 1.
25322 */
25323
25324-static struct ata_port_operations hpt374_fn1_port_ops = {
25325+static const struct ata_port_operations hpt374_fn1_port_ops = {
25326 .inherits = &hpt372_port_ops,
25327 .cable_detect = hpt374_fn1_cable_detect,
25328 };
25329diff -urNp linux-2.6.39.1/drivers/ata/pata_hpt3x2n.c linux-2.6.39.1/drivers/ata/pata_hpt3x2n.c
25330--- linux-2.6.39.1/drivers/ata/pata_hpt3x2n.c 2011-05-19 00:06:34.000000000 -0400
25331+++ linux-2.6.39.1/drivers/ata/pata_hpt3x2n.c 2011-05-22 19:36:31.000000000 -0400
25332@@ -350,7 +350,7 @@ static struct scsi_host_template hpt3x2n
25333 * Configuration for HPT302N/371N.
25334 */
25335
25336-static struct ata_port_operations hpt3xxn_port_ops = {
25337+static const struct ata_port_operations hpt3xxn_port_ops = {
25338 .inherits = &ata_bmdma_port_ops,
25339
25340 .bmdma_stop = hpt3x2n_bmdma_stop,
25341@@ -368,7 +368,7 @@ static struct ata_port_operations hpt3xx
25342 * Configuration for HPT372N. Same as 302N/371N but we have a mode filter.
25343 */
25344
25345-static struct ata_port_operations hpt372n_port_ops = {
25346+static const struct ata_port_operations hpt372n_port_ops = {
25347 .inherits = &hpt3xxn_port_ops,
25348 .mode_filter = &hpt372n_filter,
25349 };
25350diff -urNp linux-2.6.39.1/drivers/ata/pata_hpt3x3.c linux-2.6.39.1/drivers/ata/pata_hpt3x3.c
25351--- linux-2.6.39.1/drivers/ata/pata_hpt3x3.c 2011-05-19 00:06:34.000000000 -0400
25352+++ linux-2.6.39.1/drivers/ata/pata_hpt3x3.c 2011-05-22 19:36:31.000000000 -0400
25353@@ -141,7 +141,7 @@ static struct scsi_host_template hpt3x3_
25354 ATA_BMDMA_SHT(DRV_NAME),
25355 };
25356
25357-static struct ata_port_operations hpt3x3_port_ops = {
25358+static const struct ata_port_operations hpt3x3_port_ops = {
25359 .inherits = &ata_bmdma_port_ops,
25360 .cable_detect = ata_cable_40wire,
25361 .set_piomode = hpt3x3_set_piomode,
25362diff -urNp linux-2.6.39.1/drivers/ata/pata_icside.c linux-2.6.39.1/drivers/ata/pata_icside.c
25363--- linux-2.6.39.1/drivers/ata/pata_icside.c 2011-05-19 00:06:34.000000000 -0400
25364+++ linux-2.6.39.1/drivers/ata/pata_icside.c 2011-05-22 19:36:31.000000000 -0400
25365@@ -320,7 +320,7 @@ static void pata_icside_postreset(struct
25366 }
25367 }
25368
25369-static struct ata_port_operations pata_icside_port_ops = {
25370+static const struct ata_port_operations pata_icside_port_ops = {
25371 .inherits = &ata_bmdma_port_ops,
25372 /* no need to build any PRD tables for DMA */
25373 .qc_prep = ata_noop_qc_prep,
25374diff -urNp linux-2.6.39.1/drivers/ata/pata_isapnp.c linux-2.6.39.1/drivers/ata/pata_isapnp.c
25375--- linux-2.6.39.1/drivers/ata/pata_isapnp.c 2011-05-19 00:06:34.000000000 -0400
25376+++ linux-2.6.39.1/drivers/ata/pata_isapnp.c 2011-05-22 19:36:31.000000000 -0400
25377@@ -23,12 +23,12 @@ static struct scsi_host_template isapnp_
25378 ATA_PIO_SHT(DRV_NAME),
25379 };
25380
25381-static struct ata_port_operations isapnp_port_ops = {
25382+static const struct ata_port_operations isapnp_port_ops = {
25383 .inherits = &ata_sff_port_ops,
25384 .cable_detect = ata_cable_40wire,
25385 };
25386
25387-static struct ata_port_operations isapnp_noalt_port_ops = {
25388+static const struct ata_port_operations isapnp_noalt_port_ops = {
25389 .inherits = &ata_sff_port_ops,
25390 .cable_detect = ata_cable_40wire,
25391 /* No altstatus so we don't want to use the lost interrupt poll */
25392diff -urNp linux-2.6.39.1/drivers/ata/pata_it8213.c linux-2.6.39.1/drivers/ata/pata_it8213.c
25393--- linux-2.6.39.1/drivers/ata/pata_it8213.c 2011-05-19 00:06:34.000000000 -0400
25394+++ linux-2.6.39.1/drivers/ata/pata_it8213.c 2011-05-22 19:36:31.000000000 -0400
25395@@ -233,7 +233,7 @@ static struct scsi_host_template it8213_
25396 };
25397
25398
25399-static struct ata_port_operations it8213_ops = {
25400+static const struct ata_port_operations it8213_ops = {
25401 .inherits = &ata_bmdma_port_ops,
25402 .cable_detect = it8213_cable_detect,
25403 .set_piomode = it8213_set_piomode,
25404diff -urNp linux-2.6.39.1/drivers/ata/pata_it821x.c linux-2.6.39.1/drivers/ata/pata_it821x.c
25405--- linux-2.6.39.1/drivers/ata/pata_it821x.c 2011-05-19 00:06:34.000000000 -0400
25406+++ linux-2.6.39.1/drivers/ata/pata_it821x.c 2011-05-22 19:36:31.000000000 -0400
25407@@ -801,7 +801,7 @@ static struct scsi_host_template it821x_
25408 ATA_BMDMA_SHT(DRV_NAME),
25409 };
25410
25411-static struct ata_port_operations it821x_smart_port_ops = {
25412+static const struct ata_port_operations it821x_smart_port_ops = {
25413 .inherits = &ata_bmdma_port_ops,
25414
25415 .check_atapi_dma= it821x_check_atapi_dma,
25416@@ -815,7 +815,7 @@ static struct ata_port_operations it821x
25417 .port_start = it821x_port_start,
25418 };
25419
25420-static struct ata_port_operations it821x_passthru_port_ops = {
25421+static const struct ata_port_operations it821x_passthru_port_ops = {
25422 .inherits = &ata_bmdma_port_ops,
25423
25424 .check_atapi_dma= it821x_check_atapi_dma,
25425@@ -831,7 +831,7 @@ static struct ata_port_operations it821x
25426 .port_start = it821x_port_start,
25427 };
25428
25429-static struct ata_port_operations it821x_rdc_port_ops = {
25430+static const struct ata_port_operations it821x_rdc_port_ops = {
25431 .inherits = &ata_bmdma_port_ops,
25432
25433 .check_atapi_dma= it821x_check_atapi_dma,
25434diff -urNp linux-2.6.39.1/drivers/ata/pata_ixp4xx_cf.c linux-2.6.39.1/drivers/ata/pata_ixp4xx_cf.c
25435--- linux-2.6.39.1/drivers/ata/pata_ixp4xx_cf.c 2011-05-19 00:06:34.000000000 -0400
25436+++ linux-2.6.39.1/drivers/ata/pata_ixp4xx_cf.c 2011-05-22 19:36:31.000000000 -0400
25437@@ -89,7 +89,7 @@ static struct scsi_host_template ixp4xx_
25438 ATA_PIO_SHT(DRV_NAME),
25439 };
25440
25441-static struct ata_port_operations ixp4xx_port_ops = {
25442+static const struct ata_port_operations ixp4xx_port_ops = {
25443 .inherits = &ata_sff_port_ops,
25444 .sff_data_xfer = ixp4xx_mmio_data_xfer,
25445 .cable_detect = ata_cable_40wire,
25446diff -urNp linux-2.6.39.1/drivers/ata/pata_jmicron.c linux-2.6.39.1/drivers/ata/pata_jmicron.c
25447--- linux-2.6.39.1/drivers/ata/pata_jmicron.c 2011-05-19 00:06:34.000000000 -0400
25448+++ linux-2.6.39.1/drivers/ata/pata_jmicron.c 2011-05-22 19:36:31.000000000 -0400
25449@@ -111,7 +111,7 @@ static struct scsi_host_template jmicron
25450 ATA_BMDMA_SHT(DRV_NAME),
25451 };
25452
25453-static struct ata_port_operations jmicron_ops = {
25454+static const struct ata_port_operations jmicron_ops = {
25455 .inherits = &ata_bmdma_port_ops,
25456 .prereset = jmicron_pre_reset,
25457 };
25458diff -urNp linux-2.6.39.1/drivers/ata/pata_legacy.c linux-2.6.39.1/drivers/ata/pata_legacy.c
25459--- linux-2.6.39.1/drivers/ata/pata_legacy.c 2011-05-19 00:06:34.000000000 -0400
25460+++ linux-2.6.39.1/drivers/ata/pata_legacy.c 2011-05-22 19:36:31.000000000 -0400
25461@@ -116,7 +116,7 @@ struct legacy_probe {
25462
25463 struct legacy_controller {
25464 const char *name;
25465- struct ata_port_operations *ops;
25466+ const struct ata_port_operations *ops;
25467 unsigned int pio_mask;
25468 unsigned int flags;
25469 unsigned int pflags;
25470@@ -239,12 +239,12 @@ static const struct ata_port_operations
25471 * pio_mask as well.
25472 */
25473
25474-static struct ata_port_operations simple_port_ops = {
25475+static const struct ata_port_operations simple_port_ops = {
25476 .inherits = &legacy_base_port_ops,
25477 .sff_data_xfer = ata_sff_data_xfer_noirq,
25478 };
25479
25480-static struct ata_port_operations legacy_port_ops = {
25481+static const struct ata_port_operations legacy_port_ops = {
25482 .inherits = &legacy_base_port_ops,
25483 .sff_data_xfer = ata_sff_data_xfer_noirq,
25484 .set_mode = legacy_set_mode,
25485@@ -340,7 +340,7 @@ static unsigned int pdc_data_xfer_vlb(st
25486 return buflen;
25487 }
25488
25489-static struct ata_port_operations pdc20230_port_ops = {
25490+static const struct ata_port_operations pdc20230_port_ops = {
25491 .inherits = &legacy_base_port_ops,
25492 .set_piomode = pdc20230_set_piomode,
25493 .sff_data_xfer = pdc_data_xfer_vlb,
25494@@ -373,7 +373,7 @@ static void ht6560a_set_piomode(struct a
25495 ioread8(ap->ioaddr.status_addr);
25496 }
25497
25498-static struct ata_port_operations ht6560a_port_ops = {
25499+static const struct ata_port_operations ht6560a_port_ops = {
25500 .inherits = &legacy_base_port_ops,
25501 .set_piomode = ht6560a_set_piomode,
25502 };
25503@@ -416,7 +416,7 @@ static void ht6560b_set_piomode(struct a
25504 ioread8(ap->ioaddr.status_addr);
25505 }
25506
25507-static struct ata_port_operations ht6560b_port_ops = {
25508+static const struct ata_port_operations ht6560b_port_ops = {
25509 .inherits = &legacy_base_port_ops,
25510 .set_piomode = ht6560b_set_piomode,
25511 };
25512@@ -515,7 +515,7 @@ static void opti82c611a_set_piomode(stru
25513 }
25514
25515
25516-static struct ata_port_operations opti82c611a_port_ops = {
25517+static const struct ata_port_operations opti82c611a_port_ops = {
25518 .inherits = &legacy_base_port_ops,
25519 .set_piomode = opti82c611a_set_piomode,
25520 };
25521@@ -625,7 +625,7 @@ static unsigned int opti82c46x_qc_issue(
25522 return ata_sff_qc_issue(qc);
25523 }
25524
25525-static struct ata_port_operations opti82c46x_port_ops = {
25526+static const struct ata_port_operations opti82c46x_port_ops = {
25527 .inherits = &legacy_base_port_ops,
25528 .set_piomode = opti82c46x_set_piomode,
25529 .qc_issue = opti82c46x_qc_issue,
25530@@ -787,20 +787,20 @@ static int qdi_port(struct platform_devi
25531 return 0;
25532 }
25533
25534-static struct ata_port_operations qdi6500_port_ops = {
25535+static const struct ata_port_operations qdi6500_port_ops = {
25536 .inherits = &legacy_base_port_ops,
25537 .set_piomode = qdi6500_set_piomode,
25538 .qc_issue = qdi_qc_issue,
25539 .sff_data_xfer = vlb32_data_xfer,
25540 };
25541
25542-static struct ata_port_operations qdi6580_port_ops = {
25543+static const struct ata_port_operations qdi6580_port_ops = {
25544 .inherits = &legacy_base_port_ops,
25545 .set_piomode = qdi6580_set_piomode,
25546 .sff_data_xfer = vlb32_data_xfer,
25547 };
25548
25549-static struct ata_port_operations qdi6580dp_port_ops = {
25550+static const struct ata_port_operations qdi6580dp_port_ops = {
25551 .inherits = &legacy_base_port_ops,
25552 .set_piomode = qdi6580dp_set_piomode,
25553 .qc_issue = qdi_qc_issue,
25554@@ -872,7 +872,7 @@ static int winbond_port(struct platform_
25555 return 0;
25556 }
25557
25558-static struct ata_port_operations winbond_port_ops = {
25559+static const struct ata_port_operations winbond_port_ops = {
25560 .inherits = &legacy_base_port_ops,
25561 .set_piomode = winbond_set_piomode,
25562 .sff_data_xfer = vlb32_data_xfer,
25563@@ -995,7 +995,7 @@ static __init int legacy_init_one(struct
25564 int pio_modes = controller->pio_mask;
25565 unsigned long io = probe->port;
25566 u32 mask = (1 << probe->slot);
25567- struct ata_port_operations *ops = controller->ops;
25568+ const struct ata_port_operations *ops = controller->ops;
25569 struct legacy_data *ld = &legacy_data[probe->slot];
25570 struct ata_host *host = NULL;
25571 struct ata_port *ap;
25572diff -urNp linux-2.6.39.1/drivers/ata/pata_macio.c linux-2.6.39.1/drivers/ata/pata_macio.c
25573--- linux-2.6.39.1/drivers/ata/pata_macio.c 2011-05-19 00:06:34.000000000 -0400
25574+++ linux-2.6.39.1/drivers/ata/pata_macio.c 2011-05-22 19:36:31.000000000 -0400
25575@@ -918,9 +918,8 @@ static struct scsi_host_template pata_ma
25576 .slave_configure = pata_macio_slave_config,
25577 };
25578
25579-static struct ata_port_operations pata_macio_ops = {
25580+static const struct ata_port_operations pata_macio_ops = {
25581 .inherits = &ata_bmdma_port_ops,
25582-
25583 .freeze = pata_macio_freeze,
25584 .set_piomode = pata_macio_set_timings,
25585 .set_dmamode = pata_macio_set_timings,
25586diff -urNp linux-2.6.39.1/drivers/ata/pata_marvell.c linux-2.6.39.1/drivers/ata/pata_marvell.c
25587--- linux-2.6.39.1/drivers/ata/pata_marvell.c 2011-05-19 00:06:34.000000000 -0400
25588+++ linux-2.6.39.1/drivers/ata/pata_marvell.c 2011-05-22 19:36:31.000000000 -0400
25589@@ -100,7 +100,7 @@ static struct scsi_host_template marvell
25590 ATA_BMDMA_SHT(DRV_NAME),
25591 };
25592
25593-static struct ata_port_operations marvell_ops = {
25594+static const struct ata_port_operations marvell_ops = {
25595 .inherits = &ata_bmdma_port_ops,
25596 .cable_detect = marvell_cable_detect,
25597 .prereset = marvell_pre_reset,
25598diff -urNp linux-2.6.39.1/drivers/ata/pata_mpc52xx.c linux-2.6.39.1/drivers/ata/pata_mpc52xx.c
25599--- linux-2.6.39.1/drivers/ata/pata_mpc52xx.c 2011-05-19 00:06:34.000000000 -0400
25600+++ linux-2.6.39.1/drivers/ata/pata_mpc52xx.c 2011-05-22 19:36:31.000000000 -0400
25601@@ -609,7 +609,7 @@ static struct scsi_host_template mpc52xx
25602 ATA_PIO_SHT(DRV_NAME),
25603 };
25604
25605-static struct ata_port_operations mpc52xx_ata_port_ops = {
25606+static const struct ata_port_operations mpc52xx_ata_port_ops = {
25607 .inherits = &ata_bmdma_port_ops,
25608 .sff_dev_select = mpc52xx_ata_dev_select,
25609 .set_piomode = mpc52xx_ata_set_piomode,
25610diff -urNp linux-2.6.39.1/drivers/ata/pata_mpiix.c linux-2.6.39.1/drivers/ata/pata_mpiix.c
25611--- linux-2.6.39.1/drivers/ata/pata_mpiix.c 2011-05-19 00:06:34.000000000 -0400
25612+++ linux-2.6.39.1/drivers/ata/pata_mpiix.c 2011-05-22 19:36:31.000000000 -0400
25613@@ -140,7 +140,7 @@ static struct scsi_host_template mpiix_s
25614 ATA_PIO_SHT(DRV_NAME),
25615 };
25616
25617-static struct ata_port_operations mpiix_port_ops = {
25618+static const struct ata_port_operations mpiix_port_ops = {
25619 .inherits = &ata_sff_port_ops,
25620 .qc_issue = mpiix_qc_issue,
25621 .cable_detect = ata_cable_40wire,
25622diff -urNp linux-2.6.39.1/drivers/ata/pata_netcell.c linux-2.6.39.1/drivers/ata/pata_netcell.c
25623--- linux-2.6.39.1/drivers/ata/pata_netcell.c 2011-05-19 00:06:34.000000000 -0400
25624+++ linux-2.6.39.1/drivers/ata/pata_netcell.c 2011-05-22 19:36:31.000000000 -0400
25625@@ -34,7 +34,7 @@ static struct scsi_host_template netcell
25626 ATA_BMDMA_SHT(DRV_NAME),
25627 };
25628
25629-static struct ata_port_operations netcell_ops = {
25630+static const struct ata_port_operations netcell_ops = {
25631 .inherits = &ata_bmdma_port_ops,
25632 .cable_detect = ata_cable_80wire,
25633 .read_id = netcell_read_id,
25634diff -urNp linux-2.6.39.1/drivers/ata/pata_ninja32.c linux-2.6.39.1/drivers/ata/pata_ninja32.c
25635--- linux-2.6.39.1/drivers/ata/pata_ninja32.c 2011-05-19 00:06:34.000000000 -0400
25636+++ linux-2.6.39.1/drivers/ata/pata_ninja32.c 2011-05-22 19:36:31.000000000 -0400
25637@@ -81,7 +81,7 @@ static struct scsi_host_template ninja32
25638 ATA_BMDMA_SHT(DRV_NAME),
25639 };
25640
25641-static struct ata_port_operations ninja32_port_ops = {
25642+static const struct ata_port_operations ninja32_port_ops = {
25643 .inherits = &ata_bmdma_port_ops,
25644 .sff_dev_select = ninja32_dev_select,
25645 .cable_detect = ata_cable_40wire,
25646diff -urNp linux-2.6.39.1/drivers/ata/pata_ns87410.c linux-2.6.39.1/drivers/ata/pata_ns87410.c
25647--- linux-2.6.39.1/drivers/ata/pata_ns87410.c 2011-05-19 00:06:34.000000000 -0400
25648+++ linux-2.6.39.1/drivers/ata/pata_ns87410.c 2011-05-22 19:36:31.000000000 -0400
25649@@ -132,7 +132,7 @@ static struct scsi_host_template ns87410
25650 ATA_PIO_SHT(DRV_NAME),
25651 };
25652
25653-static struct ata_port_operations ns87410_port_ops = {
25654+static const struct ata_port_operations ns87410_port_ops = {
25655 .inherits = &ata_sff_port_ops,
25656 .qc_issue = ns87410_qc_issue,
25657 .cable_detect = ata_cable_40wire,
25658diff -urNp linux-2.6.39.1/drivers/ata/pata_ns87415.c linux-2.6.39.1/drivers/ata/pata_ns87415.c
25659--- linux-2.6.39.1/drivers/ata/pata_ns87415.c 2011-05-19 00:06:34.000000000 -0400
25660+++ linux-2.6.39.1/drivers/ata/pata_ns87415.c 2011-05-22 19:36:31.000000000 -0400
25661@@ -299,7 +299,7 @@ static u8 ns87560_bmdma_status(struct at
25662 }
25663 #endif /* 87560 SuperIO Support */
25664
25665-static struct ata_port_operations ns87415_pata_ops = {
25666+static const struct ata_port_operations ns87415_pata_ops = {
25667 .inherits = &ata_bmdma_port_ops,
25668
25669 .check_atapi_dma = ns87415_check_atapi_dma,
25670@@ -313,7 +313,7 @@ static struct ata_port_operations ns8741
25671 };
25672
25673 #if defined(CONFIG_SUPERIO)
25674-static struct ata_port_operations ns87560_pata_ops = {
25675+static const struct ata_port_operations ns87560_pata_ops = {
25676 .inherits = &ns87415_pata_ops,
25677 .sff_tf_read = ns87560_tf_read,
25678 .sff_check_status = ns87560_check_status,
25679diff -urNp linux-2.6.39.1/drivers/ata/pata_octeon_cf.c linux-2.6.39.1/drivers/ata/pata_octeon_cf.c
25680--- linux-2.6.39.1/drivers/ata/pata_octeon_cf.c 2011-05-19 00:06:34.000000000 -0400
25681+++ linux-2.6.39.1/drivers/ata/pata_octeon_cf.c 2011-05-22 19:36:31.000000000 -0400
25682@@ -780,7 +780,7 @@ static unsigned int octeon_cf_qc_issue(s
25683 return 0;
25684 }
25685
25686-static struct ata_port_operations octeon_cf_ops = {
25687+static struct ata_port_operations octeon_cf_ops = { /* cannot be const */
25688 .inherits = &ata_sff_port_ops,
25689 .check_atapi_dma = octeon_cf_check_atapi_dma,
25690 .qc_prep = ata_noop_qc_prep,
25691diff -urNp linux-2.6.39.1/drivers/ata/pata_oldpiix.c linux-2.6.39.1/drivers/ata/pata_oldpiix.c
25692--- linux-2.6.39.1/drivers/ata/pata_oldpiix.c 2011-05-19 00:06:34.000000000 -0400
25693+++ linux-2.6.39.1/drivers/ata/pata_oldpiix.c 2011-05-22 19:36:31.000000000 -0400
25694@@ -208,7 +208,7 @@ static struct scsi_host_template oldpiix
25695 ATA_BMDMA_SHT(DRV_NAME),
25696 };
25697
25698-static struct ata_port_operations oldpiix_pata_ops = {
25699+static const struct ata_port_operations oldpiix_pata_ops = {
25700 .inherits = &ata_bmdma_port_ops,
25701 .qc_issue = oldpiix_qc_issue,
25702 .cable_detect = ata_cable_40wire,
25703diff -urNp linux-2.6.39.1/drivers/ata/pata_opti.c linux-2.6.39.1/drivers/ata/pata_opti.c
25704--- linux-2.6.39.1/drivers/ata/pata_opti.c 2011-05-19 00:06:34.000000000 -0400
25705+++ linux-2.6.39.1/drivers/ata/pata_opti.c 2011-05-22 19:36:31.000000000 -0400
25706@@ -152,7 +152,7 @@ static struct scsi_host_template opti_sh
25707 ATA_PIO_SHT(DRV_NAME),
25708 };
25709
25710-static struct ata_port_operations opti_port_ops = {
25711+static const struct ata_port_operations opti_port_ops = {
25712 .inherits = &ata_sff_port_ops,
25713 .cable_detect = ata_cable_40wire,
25714 .set_piomode = opti_set_piomode,
25715diff -urNp linux-2.6.39.1/drivers/ata/pata_optidma.c linux-2.6.39.1/drivers/ata/pata_optidma.c
25716--- linux-2.6.39.1/drivers/ata/pata_optidma.c 2011-05-19 00:06:34.000000000 -0400
25717+++ linux-2.6.39.1/drivers/ata/pata_optidma.c 2011-05-22 19:36:31.000000000 -0400
25718@@ -337,7 +337,7 @@ static struct scsi_host_template optidma
25719 ATA_BMDMA_SHT(DRV_NAME),
25720 };
25721
25722-static struct ata_port_operations optidma_port_ops = {
25723+static const struct ata_port_operations optidma_port_ops = {
25724 .inherits = &ata_bmdma_port_ops,
25725 .cable_detect = ata_cable_40wire,
25726 .set_piomode = optidma_set_pio_mode,
25727@@ -346,7 +346,7 @@ static struct ata_port_operations optidm
25728 .prereset = optidma_pre_reset,
25729 };
25730
25731-static struct ata_port_operations optiplus_port_ops = {
25732+static const struct ata_port_operations optiplus_port_ops = {
25733 .inherits = &optidma_port_ops,
25734 .set_piomode = optiplus_set_pio_mode,
25735 .set_dmamode = optiplus_set_dma_mode,
25736diff -urNp linux-2.6.39.1/drivers/ata/pata_palmld.c linux-2.6.39.1/drivers/ata/pata_palmld.c
25737--- linux-2.6.39.1/drivers/ata/pata_palmld.c 2011-05-19 00:06:34.000000000 -0400
25738+++ linux-2.6.39.1/drivers/ata/pata_palmld.c 2011-05-22 19:36:31.000000000 -0400
25739@@ -42,7 +42,7 @@ static struct scsi_host_template palmld_
25740 ATA_PIO_SHT(DRV_NAME),
25741 };
25742
25743-static struct ata_port_operations palmld_port_ops = {
25744+static const struct ata_port_operations palmld_port_ops = {
25745 .inherits = &ata_sff_port_ops,
25746 .sff_data_xfer = ata_sff_data_xfer_noirq,
25747 .cable_detect = ata_cable_40wire,
25748diff -urNp linux-2.6.39.1/drivers/ata/pata_pcmcia.c linux-2.6.39.1/drivers/ata/pata_pcmcia.c
25749--- linux-2.6.39.1/drivers/ata/pata_pcmcia.c 2011-05-19 00:06:34.000000000 -0400
25750+++ linux-2.6.39.1/drivers/ata/pata_pcmcia.c 2011-05-22 19:36:31.000000000 -0400
25751@@ -151,14 +151,14 @@ static struct scsi_host_template pcmcia_
25752 ATA_PIO_SHT(DRV_NAME),
25753 };
25754
25755-static struct ata_port_operations pcmcia_port_ops = {
25756+static const struct ata_port_operations pcmcia_port_ops = {
25757 .inherits = &ata_sff_port_ops,
25758 .sff_data_xfer = ata_sff_data_xfer_noirq,
25759 .cable_detect = ata_cable_40wire,
25760 .set_mode = pcmcia_set_mode,
25761 };
25762
25763-static struct ata_port_operations pcmcia_8bit_port_ops = {
25764+static const struct ata_port_operations pcmcia_8bit_port_ops = {
25765 .inherits = &ata_sff_port_ops,
25766 .sff_data_xfer = ata_data_xfer_8bit,
25767 .cable_detect = ata_cable_40wire,
25768@@ -205,7 +205,7 @@ static int pcmcia_init_one(struct pcmcia
25769 unsigned long io_base, ctl_base;
25770 void __iomem *io_addr, *ctl_addr;
25771 int n_ports = 1;
25772- struct ata_port_operations *ops = &pcmcia_port_ops;
25773+ const struct ata_port_operations *ops = &pcmcia_port_ops;
25774
25775 /* Set up attributes in order to probe card and get resources */
25776 pdev->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO |
25777diff -urNp linux-2.6.39.1/drivers/ata/pata_pdc2027x.c linux-2.6.39.1/drivers/ata/pata_pdc2027x.c
25778--- linux-2.6.39.1/drivers/ata/pata_pdc2027x.c 2011-05-19 00:06:34.000000000 -0400
25779+++ linux-2.6.39.1/drivers/ata/pata_pdc2027x.c 2011-05-22 19:36:31.000000000 -0400
25780@@ -132,14 +132,14 @@ static struct scsi_host_template pdc2027
25781 ATA_BMDMA_SHT(DRV_NAME),
25782 };
25783
25784-static struct ata_port_operations pdc2027x_pata100_ops = {
25785+static const struct ata_port_operations pdc2027x_pata100_ops = {
25786 .inherits = &ata_bmdma_port_ops,
25787 .check_atapi_dma = pdc2027x_check_atapi_dma,
25788 .cable_detect = pdc2027x_cable_detect,
25789 .prereset = pdc2027x_prereset,
25790 };
25791
25792-static struct ata_port_operations pdc2027x_pata133_ops = {
25793+static const struct ata_port_operations pdc2027x_pata133_ops = {
25794 .inherits = &pdc2027x_pata100_ops,
25795 .mode_filter = pdc2027x_mode_filter,
25796 .set_piomode = pdc2027x_set_piomode,
25797diff -urNp linux-2.6.39.1/drivers/ata/pata_pdc202xx_old.c linux-2.6.39.1/drivers/ata/pata_pdc202xx_old.c
25798--- linux-2.6.39.1/drivers/ata/pata_pdc202xx_old.c 2011-05-19 00:06:34.000000000 -0400
25799+++ linux-2.6.39.1/drivers/ata/pata_pdc202xx_old.c 2011-05-22 19:36:31.000000000 -0400
25800@@ -295,7 +295,7 @@ static struct scsi_host_template pdc202x
25801 ATA_BMDMA_SHT(DRV_NAME),
25802 };
25803
25804-static struct ata_port_operations pdc2024x_port_ops = {
25805+static const struct ata_port_operations pdc2024x_port_ops = {
25806 .inherits = &ata_bmdma_port_ops,
25807
25808 .cable_detect = ata_cable_40wire,
25809@@ -306,7 +306,7 @@ static struct ata_port_operations pdc202
25810 .sff_irq_check = pdc202xx_irq_check,
25811 };
25812
25813-static struct ata_port_operations pdc2026x_port_ops = {
25814+static const struct ata_port_operations pdc2026x_port_ops = {
25815 .inherits = &pdc2024x_port_ops,
25816
25817 .check_atapi_dma = pdc2026x_check_atapi_dma,
25818diff -urNp linux-2.6.39.1/drivers/ata/pata_piccolo.c linux-2.6.39.1/drivers/ata/pata_piccolo.c
25819--- linux-2.6.39.1/drivers/ata/pata_piccolo.c 2011-05-19 00:06:34.000000000 -0400
25820+++ linux-2.6.39.1/drivers/ata/pata_piccolo.c 2011-05-22 19:36:31.000000000 -0400
25821@@ -67,7 +67,7 @@ static struct scsi_host_template tosh_sh
25822 ATA_BMDMA_SHT(DRV_NAME),
25823 };
25824
25825-static struct ata_port_operations tosh_port_ops = {
25826+static const struct ata_port_operations tosh_port_ops = {
25827 .inherits = &ata_bmdma_port_ops,
25828 .cable_detect = ata_cable_unknown,
25829 .set_piomode = tosh_set_piomode,
25830diff -urNp linux-2.6.39.1/drivers/ata/pata_platform.c linux-2.6.39.1/drivers/ata/pata_platform.c
25831--- linux-2.6.39.1/drivers/ata/pata_platform.c 2011-05-19 00:06:34.000000000 -0400
25832+++ linux-2.6.39.1/drivers/ata/pata_platform.c 2011-05-22 19:36:31.000000000 -0400
25833@@ -48,7 +48,7 @@ static struct scsi_host_template pata_pl
25834 ATA_PIO_SHT(DRV_NAME),
25835 };
25836
25837-static struct ata_port_operations pata_platform_port_ops = {
25838+static const struct ata_port_operations pata_platform_port_ops = {
25839 .inherits = &ata_sff_port_ops,
25840 .sff_data_xfer = ata_sff_data_xfer_noirq,
25841 .cable_detect = ata_cable_unknown,
25842diff -urNp linux-2.6.39.1/drivers/ata/pata_pxa.c linux-2.6.39.1/drivers/ata/pata_pxa.c
25843--- linux-2.6.39.1/drivers/ata/pata_pxa.c 2011-05-19 00:06:34.000000000 -0400
25844+++ linux-2.6.39.1/drivers/ata/pata_pxa.c 2011-05-22 19:36:31.000000000 -0400
25845@@ -198,7 +198,7 @@ static struct scsi_host_template pxa_ata
25846 ATA_BMDMA_SHT(DRV_NAME),
25847 };
25848
25849-static struct ata_port_operations pxa_ata_port_ops = {
25850+static const struct ata_port_operations pxa_ata_port_ops = {
25851 .inherits = &ata_bmdma_port_ops,
25852 .cable_detect = ata_cable_40wire,
25853
25854diff -urNp linux-2.6.39.1/drivers/ata/pata_qdi.c linux-2.6.39.1/drivers/ata/pata_qdi.c
25855--- linux-2.6.39.1/drivers/ata/pata_qdi.c 2011-05-19 00:06:34.000000000 -0400
25856+++ linux-2.6.39.1/drivers/ata/pata_qdi.c 2011-05-22 19:36:31.000000000 -0400
25857@@ -157,7 +157,7 @@ static struct scsi_host_template qdi_sht
25858 ATA_PIO_SHT(DRV_NAME),
25859 };
25860
25861-static struct ata_port_operations qdi6500_port_ops = {
25862+static const struct ata_port_operations qdi6500_port_ops = {
25863 .inherits = &ata_sff_port_ops,
25864 .qc_issue = qdi_qc_issue,
25865 .sff_data_xfer = qdi_data_xfer,
25866@@ -165,7 +165,7 @@ static struct ata_port_operations qdi650
25867 .set_piomode = qdi6500_set_piomode,
25868 };
25869
25870-static struct ata_port_operations qdi6580_port_ops = {
25871+static const struct ata_port_operations qdi6580_port_ops = {
25872 .inherits = &qdi6500_port_ops,
25873 .set_piomode = qdi6580_set_piomode,
25874 };
25875diff -urNp linux-2.6.39.1/drivers/ata/pata_radisys.c linux-2.6.39.1/drivers/ata/pata_radisys.c
25876--- linux-2.6.39.1/drivers/ata/pata_radisys.c 2011-05-19 00:06:34.000000000 -0400
25877+++ linux-2.6.39.1/drivers/ata/pata_radisys.c 2011-05-22 19:36:31.000000000 -0400
25878@@ -187,7 +187,7 @@ static struct scsi_host_template radisys
25879 ATA_BMDMA_SHT(DRV_NAME),
25880 };
25881
25882-static struct ata_port_operations radisys_pata_ops = {
25883+static const struct ata_port_operations radisys_pata_ops = {
25884 .inherits = &ata_bmdma_port_ops,
25885 .qc_issue = radisys_qc_issue,
25886 .cable_detect = ata_cable_unknown,
25887diff -urNp linux-2.6.39.1/drivers/ata/pata_rb532_cf.c linux-2.6.39.1/drivers/ata/pata_rb532_cf.c
25888--- linux-2.6.39.1/drivers/ata/pata_rb532_cf.c 2011-05-19 00:06:34.000000000 -0400
25889+++ linux-2.6.39.1/drivers/ata/pata_rb532_cf.c 2011-05-22 19:36:31.000000000 -0400
25890@@ -69,7 +69,7 @@ static irqreturn_t rb532_pata_irq_handle
25891 return IRQ_HANDLED;
25892 }
25893
25894-static struct ata_port_operations rb532_pata_port_ops = {
25895+static const struct ata_port_operations rb532_pata_port_ops = {
25896 .inherits = &ata_sff_port_ops,
25897 .sff_data_xfer = ata_sff_data_xfer32,
25898 };
25899diff -urNp linux-2.6.39.1/drivers/ata/pata_rdc.c linux-2.6.39.1/drivers/ata/pata_rdc.c
25900--- linux-2.6.39.1/drivers/ata/pata_rdc.c 2011-05-19 00:06:34.000000000 -0400
25901+++ linux-2.6.39.1/drivers/ata/pata_rdc.c 2011-05-22 19:36:31.000000000 -0400
25902@@ -273,7 +273,7 @@ static void rdc_set_dmamode(struct ata_p
25903 pci_write_config_byte(dev, 0x48, udma_enable);
25904 }
25905
25906-static struct ata_port_operations rdc_pata_ops = {
25907+static const struct ata_port_operations rdc_pata_ops = {
25908 .inherits = &ata_bmdma32_port_ops,
25909 .cable_detect = rdc_pata_cable_detect,
25910 .set_piomode = rdc_set_piomode,
25911diff -urNp linux-2.6.39.1/drivers/ata/pata_rz1000.c linux-2.6.39.1/drivers/ata/pata_rz1000.c
25912--- linux-2.6.39.1/drivers/ata/pata_rz1000.c 2011-05-19 00:06:34.000000000 -0400
25913+++ linux-2.6.39.1/drivers/ata/pata_rz1000.c 2011-05-22 19:36:31.000000000 -0400
25914@@ -54,7 +54,7 @@ static struct scsi_host_template rz1000_
25915 ATA_PIO_SHT(DRV_NAME),
25916 };
25917
25918-static struct ata_port_operations rz1000_port_ops = {
25919+static const struct ata_port_operations rz1000_port_ops = {
25920 .inherits = &ata_sff_port_ops,
25921 .cable_detect = ata_cable_40wire,
25922 .set_mode = rz1000_set_mode,
25923diff -urNp linux-2.6.39.1/drivers/ata/pata_samsung_cf.c linux-2.6.39.1/drivers/ata/pata_samsung_cf.c
25924--- linux-2.6.39.1/drivers/ata/pata_samsung_cf.c 2011-05-19 00:06:34.000000000 -0400
25925+++ linux-2.6.39.1/drivers/ata/pata_samsung_cf.c 2011-05-22 19:36:31.000000000 -0400
25926@@ -399,7 +399,7 @@ static struct scsi_host_template pata_s3
25927 ATA_PIO_SHT(DRV_NAME),
25928 };
25929
25930-static struct ata_port_operations pata_s3c_port_ops = {
25931+static const struct ata_port_operations pata_s3c_port_ops = {
25932 .inherits = &ata_sff_port_ops,
25933 .sff_check_status = pata_s3c_check_status,
25934 .sff_check_altstatus = pata_s3c_check_altstatus,
25935@@ -413,7 +413,7 @@ static struct ata_port_operations pata_s
25936 .set_piomode = pata_s3c_set_piomode,
25937 };
25938
25939-static struct ata_port_operations pata_s5p_port_ops = {
25940+static const struct ata_port_operations pata_s5p_port_ops = {
25941 .inherits = &ata_sff_port_ops,
25942 .set_piomode = pata_s3c_set_piomode,
25943 };
25944diff -urNp linux-2.6.39.1/drivers/ata/pata_sc1200.c linux-2.6.39.1/drivers/ata/pata_sc1200.c
25945--- linux-2.6.39.1/drivers/ata/pata_sc1200.c 2011-05-19 00:06:34.000000000 -0400
25946+++ linux-2.6.39.1/drivers/ata/pata_sc1200.c 2011-05-22 19:36:31.000000000 -0400
25947@@ -207,7 +207,7 @@ static struct scsi_host_template sc1200_
25948 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
25949 };
25950
25951-static struct ata_port_operations sc1200_port_ops = {
25952+static const struct ata_port_operations sc1200_port_ops = {
25953 .inherits = &ata_bmdma_port_ops,
25954 .qc_prep = ata_bmdma_dumb_qc_prep,
25955 .qc_issue = sc1200_qc_issue,
25956diff -urNp linux-2.6.39.1/drivers/ata/pata_scc.c linux-2.6.39.1/drivers/ata/pata_scc.c
25957--- linux-2.6.39.1/drivers/ata/pata_scc.c 2011-05-19 00:06:34.000000000 -0400
25958+++ linux-2.6.39.1/drivers/ata/pata_scc.c 2011-05-22 19:36:31.000000000 -0400
25959@@ -926,7 +926,7 @@ static struct scsi_host_template scc_sht
25960 ATA_BMDMA_SHT(DRV_NAME),
25961 };
25962
25963-static struct ata_port_operations scc_pata_ops = {
25964+static const struct ata_port_operations scc_pata_ops = {
25965 .inherits = &ata_bmdma_port_ops,
25966
25967 .set_piomode = scc_set_piomode,
25968diff -urNp linux-2.6.39.1/drivers/ata/pata_sch.c linux-2.6.39.1/drivers/ata/pata_sch.c
25969--- linux-2.6.39.1/drivers/ata/pata_sch.c 2011-05-19 00:06:34.000000000 -0400
25970+++ linux-2.6.39.1/drivers/ata/pata_sch.c 2011-05-22 19:36:31.000000000 -0400
25971@@ -75,7 +75,7 @@ static struct scsi_host_template sch_sht
25972 ATA_BMDMA_SHT(DRV_NAME),
25973 };
25974
25975-static struct ata_port_operations sch_pata_ops = {
25976+static const struct ata_port_operations sch_pata_ops = {
25977 .inherits = &ata_bmdma_port_ops,
25978 .cable_detect = ata_cable_unknown,
25979 .set_piomode = sch_set_piomode,
25980diff -urNp linux-2.6.39.1/drivers/ata/pata_serverworks.c linux-2.6.39.1/drivers/ata/pata_serverworks.c
25981--- linux-2.6.39.1/drivers/ata/pata_serverworks.c 2011-05-19 00:06:34.000000000 -0400
25982+++ linux-2.6.39.1/drivers/ata/pata_serverworks.c 2011-05-22 19:36:31.000000000 -0400
25983@@ -300,7 +300,7 @@ static struct scsi_host_template serverw
25984 ATA_BMDMA_SHT(DRV_NAME),
25985 };
25986
25987-static struct ata_port_operations serverworks_osb4_port_ops = {
25988+static const struct ata_port_operations serverworks_osb4_port_ops = {
25989 .inherits = &ata_bmdma_port_ops,
25990 .cable_detect = serverworks_cable_detect,
25991 .mode_filter = serverworks_osb4_filter,
25992@@ -308,7 +308,7 @@ static struct ata_port_operations server
25993 .set_dmamode = serverworks_set_dmamode,
25994 };
25995
25996-static struct ata_port_operations serverworks_csb_port_ops = {
25997+static const struct ata_port_operations serverworks_csb_port_ops = {
25998 .inherits = &serverworks_osb4_port_ops,
25999 .mode_filter = serverworks_csb_filter,
26000 };
26001diff -urNp linux-2.6.39.1/drivers/ata/pata_sil680.c linux-2.6.39.1/drivers/ata/pata_sil680.c
26002--- linux-2.6.39.1/drivers/ata/pata_sil680.c 2011-05-19 00:06:34.000000000 -0400
26003+++ linux-2.6.39.1/drivers/ata/pata_sil680.c 2011-05-22 19:36:31.000000000 -0400
26004@@ -225,8 +225,7 @@ static struct scsi_host_template sil680_
26005 ATA_BMDMA_SHT(DRV_NAME),
26006 };
26007
26008-
26009-static struct ata_port_operations sil680_port_ops = {
26010+static const struct ata_port_operations sil680_port_ops = {
26011 .inherits = &ata_bmdma32_port_ops,
26012 .sff_exec_command = sil680_sff_exec_command,
26013 .sff_irq_check = sil680_sff_irq_check,
26014diff -urNp linux-2.6.39.1/drivers/ata/pata_sis.c linux-2.6.39.1/drivers/ata/pata_sis.c
26015--- linux-2.6.39.1/drivers/ata/pata_sis.c 2011-05-19 00:06:34.000000000 -0400
26016+++ linux-2.6.39.1/drivers/ata/pata_sis.c 2011-05-22 19:36:31.000000000 -0400
26017@@ -503,47 +503,47 @@ static struct scsi_host_template sis_sht
26018 ATA_BMDMA_SHT(DRV_NAME),
26019 };
26020
26021-static struct ata_port_operations sis_133_for_sata_ops = {
26022+static const struct ata_port_operations sis_133_for_sata_ops = {
26023 .inherits = &ata_bmdma_port_ops,
26024 .set_piomode = sis_133_set_piomode,
26025 .set_dmamode = sis_133_set_dmamode,
26026 .cable_detect = sis_133_cable_detect,
26027 };
26028
26029-static struct ata_port_operations sis_base_ops = {
26030+static const struct ata_port_operations sis_base_ops = {
26031 .inherits = &ata_bmdma_port_ops,
26032 .prereset = sis_pre_reset,
26033 };
26034
26035-static struct ata_port_operations sis_133_ops = {
26036+static const struct ata_port_operations sis_133_ops = {
26037 .inherits = &sis_base_ops,
26038 .set_piomode = sis_133_set_piomode,
26039 .set_dmamode = sis_133_set_dmamode,
26040 .cable_detect = sis_133_cable_detect,
26041 };
26042
26043-static struct ata_port_operations sis_133_early_ops = {
26044+static const struct ata_port_operations sis_133_early_ops = {
26045 .inherits = &sis_base_ops,
26046 .set_piomode = sis_100_set_piomode,
26047 .set_dmamode = sis_133_early_set_dmamode,
26048 .cable_detect = sis_66_cable_detect,
26049 };
26050
26051-static struct ata_port_operations sis_100_ops = {
26052+static const struct ata_port_operations sis_100_ops = {
26053 .inherits = &sis_base_ops,
26054 .set_piomode = sis_100_set_piomode,
26055 .set_dmamode = sis_100_set_dmamode,
26056 .cable_detect = sis_66_cable_detect,
26057 };
26058
26059-static struct ata_port_operations sis_66_ops = {
26060+static const struct ata_port_operations sis_66_ops = {
26061 .inherits = &sis_base_ops,
26062 .set_piomode = sis_old_set_piomode,
26063 .set_dmamode = sis_66_set_dmamode,
26064 .cable_detect = sis_66_cable_detect,
26065 };
26066
26067-static struct ata_port_operations sis_old_ops = {
26068+static const struct ata_port_operations sis_old_ops = {
26069 .inherits = &sis_base_ops,
26070 .set_piomode = sis_old_set_piomode,
26071 .set_dmamode = sis_old_set_dmamode,
26072diff -urNp linux-2.6.39.1/drivers/ata/pata_sl82c105.c linux-2.6.39.1/drivers/ata/pata_sl82c105.c
26073--- linux-2.6.39.1/drivers/ata/pata_sl82c105.c 2011-05-19 00:06:34.000000000 -0400
26074+++ linux-2.6.39.1/drivers/ata/pata_sl82c105.c 2011-05-22 19:36:31.000000000 -0400
26075@@ -241,7 +241,7 @@ static struct scsi_host_template sl82c10
26076 ATA_BMDMA_SHT(DRV_NAME),
26077 };
26078
26079-static struct ata_port_operations sl82c105_port_ops = {
26080+static const struct ata_port_operations sl82c105_port_ops = {
26081 .inherits = &ata_bmdma_port_ops,
26082 .qc_defer = sl82c105_qc_defer,
26083 .bmdma_start = sl82c105_bmdma_start,
26084diff -urNp linux-2.6.39.1/drivers/ata/pata_triflex.c linux-2.6.39.1/drivers/ata/pata_triflex.c
26085--- linux-2.6.39.1/drivers/ata/pata_triflex.c 2011-05-19 00:06:34.000000000 -0400
26086+++ linux-2.6.39.1/drivers/ata/pata_triflex.c 2011-05-22 19:36:31.000000000 -0400
26087@@ -178,7 +178,7 @@ static struct scsi_host_template triflex
26088 ATA_BMDMA_SHT(DRV_NAME),
26089 };
26090
26091-static struct ata_port_operations triflex_port_ops = {
26092+static const struct ata_port_operations triflex_port_ops = {
26093 .inherits = &ata_bmdma_port_ops,
26094 .bmdma_start = triflex_bmdma_start,
26095 .bmdma_stop = triflex_bmdma_stop,
26096diff -urNp linux-2.6.39.1/drivers/ata/pata_via.c linux-2.6.39.1/drivers/ata/pata_via.c
26097--- linux-2.6.39.1/drivers/ata/pata_via.c 2011-05-19 00:06:34.000000000 -0400
26098+++ linux-2.6.39.1/drivers/ata/pata_via.c 2011-05-22 19:36:31.000000000 -0400
26099@@ -441,7 +441,7 @@ static struct scsi_host_template via_sht
26100 ATA_BMDMA_SHT(DRV_NAME),
26101 };
26102
26103-static struct ata_port_operations via_port_ops = {
26104+static const struct ata_port_operations via_port_ops = {
26105 .inherits = &ata_bmdma_port_ops,
26106 .cable_detect = via_cable_detect,
26107 .set_piomode = via_set_piomode,
26108@@ -452,7 +452,7 @@ static struct ata_port_operations via_po
26109 .mode_filter = via_mode_filter,
26110 };
26111
26112-static struct ata_port_operations via_port_ops_noirq = {
26113+static const struct ata_port_operations via_port_ops_noirq = {
26114 .inherits = &via_port_ops,
26115 .sff_data_xfer = ata_sff_data_xfer_noirq,
26116 };
26117diff -urNp linux-2.6.39.1/drivers/ata/pdc_adma.c linux-2.6.39.1/drivers/ata/pdc_adma.c
26118--- linux-2.6.39.1/drivers/ata/pdc_adma.c 2011-05-19 00:06:34.000000000 -0400
26119+++ linux-2.6.39.1/drivers/ata/pdc_adma.c 2011-05-22 19:36:31.000000000 -0400
26120@@ -146,7 +146,7 @@ static struct scsi_host_template adma_at
26121 .dma_boundary = ADMA_DMA_BOUNDARY,
26122 };
26123
26124-static struct ata_port_operations adma_ata_ops = {
26125+static const struct ata_port_operations adma_ata_ops = {
26126 .inherits = &ata_sff_port_ops,
26127
26128 .lost_interrupt = ATA_OP_NULL,
26129diff -urNp linux-2.6.39.1/drivers/ata/sata_dwc_460ex.c linux-2.6.39.1/drivers/ata/sata_dwc_460ex.c
26130--- linux-2.6.39.1/drivers/ata/sata_dwc_460ex.c 2011-05-19 00:06:34.000000000 -0400
26131+++ linux-2.6.39.1/drivers/ata/sata_dwc_460ex.c 2011-05-22 19:36:31.000000000 -0400
26132@@ -1598,7 +1598,7 @@ static struct scsi_host_template sata_dw
26133 .dma_boundary = ATA_DMA_BOUNDARY,
26134 };
26135
26136-static struct ata_port_operations sata_dwc_ops = {
26137+static const struct ata_port_operations sata_dwc_ops = {
26138 .inherits = &ata_sff_port_ops,
26139
26140 .error_handler = sata_dwc_error_handler,
26141diff -urNp linux-2.6.39.1/drivers/ata/sata_fsl.c linux-2.6.39.1/drivers/ata/sata_fsl.c
26142--- linux-2.6.39.1/drivers/ata/sata_fsl.c 2011-05-19 00:06:34.000000000 -0400
26143+++ linux-2.6.39.1/drivers/ata/sata_fsl.c 2011-05-22 19:36:31.000000000 -0400
26144@@ -1268,7 +1268,7 @@ static struct scsi_host_template sata_fs
26145 .dma_boundary = ATA_DMA_BOUNDARY,
26146 };
26147
26148-static struct ata_port_operations sata_fsl_ops = {
26149+static const struct ata_port_operations sata_fsl_ops = {
26150 .inherits = &sata_pmp_port_ops,
26151
26152 .qc_defer = ata_std_qc_defer,
26153diff -urNp linux-2.6.39.1/drivers/ata/sata_inic162x.c linux-2.6.39.1/drivers/ata/sata_inic162x.c
26154--- linux-2.6.39.1/drivers/ata/sata_inic162x.c 2011-05-19 00:06:34.000000000 -0400
26155+++ linux-2.6.39.1/drivers/ata/sata_inic162x.c 2011-05-22 19:36:31.000000000 -0400
26156@@ -705,7 +705,7 @@ static int inic_port_start(struct ata_po
26157 return 0;
26158 }
26159
26160-static struct ata_port_operations inic_port_ops = {
26161+static const struct ata_port_operations inic_port_ops = {
26162 .inherits = &sata_port_ops,
26163
26164 .check_atapi_dma = inic_check_atapi_dma,
26165diff -urNp linux-2.6.39.1/drivers/ata/sata_mv.c linux-2.6.39.1/drivers/ata/sata_mv.c
26166--- linux-2.6.39.1/drivers/ata/sata_mv.c 2011-05-19 00:06:34.000000000 -0400
26167+++ linux-2.6.39.1/drivers/ata/sata_mv.c 2011-05-22 19:36:31.000000000 -0400
26168@@ -662,7 +662,7 @@ static struct scsi_host_template mv6_sht
26169 .dma_boundary = MV_DMA_BOUNDARY,
26170 };
26171
26172-static struct ata_port_operations mv5_ops = {
26173+static const struct ata_port_operations mv5_ops = {
26174 .inherits = &ata_sff_port_ops,
26175
26176 .lost_interrupt = ATA_OP_NULL,
26177@@ -682,7 +682,7 @@ static struct ata_port_operations mv5_op
26178 .port_stop = mv_port_stop,
26179 };
26180
26181-static struct ata_port_operations mv6_ops = {
26182+static const struct ata_port_operations mv6_ops = {
26183 .inherits = &ata_bmdma_port_ops,
26184
26185 .lost_interrupt = ATA_OP_NULL,
26186@@ -716,7 +716,7 @@ static struct ata_port_operations mv6_op
26187 .port_stop = mv_port_stop,
26188 };
26189
26190-static struct ata_port_operations mv_iie_ops = {
26191+static const struct ata_port_operations mv_iie_ops = {
26192 .inherits = &mv6_ops,
26193 .dev_config = ATA_OP_NULL,
26194 .qc_prep = mv_qc_prep_iie,
26195diff -urNp linux-2.6.39.1/drivers/ata/sata_nv.c linux-2.6.39.1/drivers/ata/sata_nv.c
26196--- linux-2.6.39.1/drivers/ata/sata_nv.c 2011-05-19 00:06:34.000000000 -0400
26197+++ linux-2.6.39.1/drivers/ata/sata_nv.c 2011-05-22 19:36:31.000000000 -0400
26198@@ -465,7 +465,7 @@ static struct scsi_host_template nv_swnc
26199 * cases. Define nv_hardreset() which only kicks in for post-boot
26200 * probing and use it for all variants.
26201 */
26202-static struct ata_port_operations nv_generic_ops = {
26203+static const struct ata_port_operations nv_generic_ops = {
26204 .inherits = &ata_bmdma_port_ops,
26205 .lost_interrupt = ATA_OP_NULL,
26206 .scr_read = nv_scr_read,
26207@@ -473,20 +473,20 @@ static struct ata_port_operations nv_gen
26208 .hardreset = nv_hardreset,
26209 };
26210
26211-static struct ata_port_operations nv_nf2_ops = {
26212+static const struct ata_port_operations nv_nf2_ops = {
26213 .inherits = &nv_generic_ops,
26214 .freeze = nv_nf2_freeze,
26215 .thaw = nv_nf2_thaw,
26216 };
26217
26218-static struct ata_port_operations nv_ck804_ops = {
26219+static const struct ata_port_operations nv_ck804_ops = {
26220 .inherits = &nv_generic_ops,
26221 .freeze = nv_ck804_freeze,
26222 .thaw = nv_ck804_thaw,
26223 .host_stop = nv_ck804_host_stop,
26224 };
26225
26226-static struct ata_port_operations nv_adma_ops = {
26227+static const struct ata_port_operations nv_adma_ops = {
26228 .inherits = &nv_ck804_ops,
26229
26230 .check_atapi_dma = nv_adma_check_atapi_dma,
26231@@ -510,7 +510,7 @@ static struct ata_port_operations nv_adm
26232 .host_stop = nv_adma_host_stop,
26233 };
26234
26235-static struct ata_port_operations nv_swncq_ops = {
26236+static const struct ata_port_operations nv_swncq_ops = {
26237 .inherits = &nv_generic_ops,
26238
26239 .qc_defer = ata_std_qc_defer,
26240diff -urNp linux-2.6.39.1/drivers/ata/sata_promise.c linux-2.6.39.1/drivers/ata/sata_promise.c
26241--- linux-2.6.39.1/drivers/ata/sata_promise.c 2011-05-19 00:06:34.000000000 -0400
26242+++ linux-2.6.39.1/drivers/ata/sata_promise.c 2011-05-22 19:36:31.000000000 -0400
26243@@ -194,7 +194,7 @@ static const struct ata_port_operations
26244 .error_handler = pdc_error_handler,
26245 };
26246
26247-static struct ata_port_operations pdc_sata_ops = {
26248+static const struct ata_port_operations pdc_sata_ops = {
26249 .inherits = &pdc_common_ops,
26250 .cable_detect = pdc_sata_cable_detect,
26251 .freeze = pdc_sata_freeze,
26252@@ -207,14 +207,14 @@ static struct ata_port_operations pdc_sa
26253
26254 /* First-generation chips need a more restrictive ->check_atapi_dma op,
26255 and ->freeze/thaw that ignore the hotplug controls. */
26256-static struct ata_port_operations pdc_old_sata_ops = {
26257+static const struct ata_port_operations pdc_old_sata_ops = {
26258 .inherits = &pdc_sata_ops,
26259 .freeze = pdc_freeze,
26260 .thaw = pdc_thaw,
26261 .check_atapi_dma = pdc_old_sata_check_atapi_dma,
26262 };
26263
26264-static struct ata_port_operations pdc_pata_ops = {
26265+static const struct ata_port_operations pdc_pata_ops = {
26266 .inherits = &pdc_common_ops,
26267 .cable_detect = pdc_pata_cable_detect,
26268 .freeze = pdc_freeze,
26269diff -urNp linux-2.6.39.1/drivers/ata/sata_qstor.c linux-2.6.39.1/drivers/ata/sata_qstor.c
26270--- linux-2.6.39.1/drivers/ata/sata_qstor.c 2011-05-19 00:06:34.000000000 -0400
26271+++ linux-2.6.39.1/drivers/ata/sata_qstor.c 2011-05-22 19:36:31.000000000 -0400
26272@@ -131,7 +131,7 @@ static struct scsi_host_template qs_ata_
26273 .dma_boundary = QS_DMA_BOUNDARY,
26274 };
26275
26276-static struct ata_port_operations qs_ata_ops = {
26277+static const struct ata_port_operations qs_ata_ops = {
26278 .inherits = &ata_sff_port_ops,
26279
26280 .check_atapi_dma = qs_check_atapi_dma,
26281diff -urNp linux-2.6.39.1/drivers/ata/sata_sil24.c linux-2.6.39.1/drivers/ata/sata_sil24.c
26282--- linux-2.6.39.1/drivers/ata/sata_sil24.c 2011-05-19 00:06:34.000000000 -0400
26283+++ linux-2.6.39.1/drivers/ata/sata_sil24.c 2011-05-22 19:36:31.000000000 -0400
26284@@ -388,7 +388,7 @@ static struct scsi_host_template sil24_s
26285 .dma_boundary = ATA_DMA_BOUNDARY,
26286 };
26287
26288-static struct ata_port_operations sil24_ops = {
26289+static const struct ata_port_operations sil24_ops = {
26290 .inherits = &sata_pmp_port_ops,
26291
26292 .qc_defer = sil24_qc_defer,
26293diff -urNp linux-2.6.39.1/drivers/ata/sata_sil.c linux-2.6.39.1/drivers/ata/sata_sil.c
26294--- linux-2.6.39.1/drivers/ata/sata_sil.c 2011-05-19 00:06:34.000000000 -0400
26295+++ linux-2.6.39.1/drivers/ata/sata_sil.c 2011-05-22 19:36:31.000000000 -0400
26296@@ -181,7 +181,7 @@ static struct scsi_host_template sil_sht
26297 .sg_tablesize = ATA_MAX_PRD
26298 };
26299
26300-static struct ata_port_operations sil_ops = {
26301+static const struct ata_port_operations sil_ops = {
26302 .inherits = &ata_bmdma32_port_ops,
26303 .dev_config = sil_dev_config,
26304 .set_mode = sil_set_mode,
26305diff -urNp linux-2.6.39.1/drivers/ata/sata_sis.c linux-2.6.39.1/drivers/ata/sata_sis.c
26306--- linux-2.6.39.1/drivers/ata/sata_sis.c 2011-05-19 00:06:34.000000000 -0400
26307+++ linux-2.6.39.1/drivers/ata/sata_sis.c 2011-05-22 19:36:31.000000000 -0400
26308@@ -89,7 +89,7 @@ static struct scsi_host_template sis_sht
26309 ATA_BMDMA_SHT(DRV_NAME),
26310 };
26311
26312-static struct ata_port_operations sis_ops = {
26313+static const struct ata_port_operations sis_ops = {
26314 .inherits = &ata_bmdma_port_ops,
26315 .scr_read = sis_scr_read,
26316 .scr_write = sis_scr_write,
26317diff -urNp linux-2.6.39.1/drivers/ata/sata_svw.c linux-2.6.39.1/drivers/ata/sata_svw.c
26318--- linux-2.6.39.1/drivers/ata/sata_svw.c 2011-05-19 00:06:34.000000000 -0400
26319+++ linux-2.6.39.1/drivers/ata/sata_svw.c 2011-05-22 19:36:31.000000000 -0400
26320@@ -344,7 +344,7 @@ static struct scsi_host_template k2_sata
26321 };
26322
26323
26324-static struct ata_port_operations k2_sata_ops = {
26325+static const struct ata_port_operations k2_sata_ops = {
26326 .inherits = &ata_bmdma_port_ops,
26327 .sff_tf_load = k2_sata_tf_load,
26328 .sff_tf_read = k2_sata_tf_read,
26329diff -urNp linux-2.6.39.1/drivers/ata/sata_sx4.c linux-2.6.39.1/drivers/ata/sata_sx4.c
26330--- linux-2.6.39.1/drivers/ata/sata_sx4.c 2011-05-19 00:06:34.000000000 -0400
26331+++ linux-2.6.39.1/drivers/ata/sata_sx4.c 2011-05-22 19:36:31.000000000 -0400
26332@@ -249,7 +249,7 @@ static struct scsi_host_template pdc_sat
26333 };
26334
26335 /* TODO: inherit from base port_ops after converting to new EH */
26336-static struct ata_port_operations pdc_20621_ops = {
26337+static const struct ata_port_operations pdc_20621_ops = {
26338 .inherits = &ata_sff_port_ops,
26339
26340 .check_atapi_dma = pdc_check_atapi_dma,
26341diff -urNp linux-2.6.39.1/drivers/ata/sata_uli.c linux-2.6.39.1/drivers/ata/sata_uli.c
26342--- linux-2.6.39.1/drivers/ata/sata_uli.c 2011-05-19 00:06:34.000000000 -0400
26343+++ linux-2.6.39.1/drivers/ata/sata_uli.c 2011-05-22 19:36:31.000000000 -0400
26344@@ -80,7 +80,7 @@ static struct scsi_host_template uli_sht
26345 ATA_BMDMA_SHT(DRV_NAME),
26346 };
26347
26348-static struct ata_port_operations uli_ops = {
26349+static const struct ata_port_operations uli_ops = {
26350 .inherits = &ata_bmdma_port_ops,
26351 .scr_read = uli_scr_read,
26352 .scr_write = uli_scr_write,
26353diff -urNp linux-2.6.39.1/drivers/ata/sata_via.c linux-2.6.39.1/drivers/ata/sata_via.c
26354--- linux-2.6.39.1/drivers/ata/sata_via.c 2011-05-19 00:06:34.000000000 -0400
26355+++ linux-2.6.39.1/drivers/ata/sata_via.c 2011-05-22 19:36:31.000000000 -0400
26356@@ -115,32 +115,32 @@ static struct scsi_host_template svia_sh
26357 ATA_BMDMA_SHT(DRV_NAME),
26358 };
26359
26360-static struct ata_port_operations svia_base_ops = {
26361+static const struct ata_port_operations svia_base_ops = {
26362 .inherits = &ata_bmdma_port_ops,
26363 .sff_tf_load = svia_tf_load,
26364 };
26365
26366-static struct ata_port_operations vt6420_sata_ops = {
26367+static const struct ata_port_operations vt6420_sata_ops = {
26368 .inherits = &svia_base_ops,
26369 .freeze = svia_noop_freeze,
26370 .prereset = vt6420_prereset,
26371 .bmdma_start = vt6420_bmdma_start,
26372 };
26373
26374-static struct ata_port_operations vt6421_pata_ops = {
26375+static const struct ata_port_operations vt6421_pata_ops = {
26376 .inherits = &svia_base_ops,
26377 .cable_detect = vt6421_pata_cable_detect,
26378 .set_piomode = vt6421_set_pio_mode,
26379 .set_dmamode = vt6421_set_dma_mode,
26380 };
26381
26382-static struct ata_port_operations vt6421_sata_ops = {
26383+static const struct ata_port_operations vt6421_sata_ops = {
26384 .inherits = &svia_base_ops,
26385 .scr_read = svia_scr_read,
26386 .scr_write = svia_scr_write,
26387 };
26388
26389-static struct ata_port_operations vt8251_ops = {
26390+static const struct ata_port_operations vt8251_ops = {
26391 .inherits = &svia_base_ops,
26392 .hardreset = sata_std_hardreset,
26393 .scr_read = vt8251_scr_read,
26394diff -urNp linux-2.6.39.1/drivers/ata/sata_vsc.c linux-2.6.39.1/drivers/ata/sata_vsc.c
26395--- linux-2.6.39.1/drivers/ata/sata_vsc.c 2011-05-19 00:06:34.000000000 -0400
26396+++ linux-2.6.39.1/drivers/ata/sata_vsc.c 2011-05-22 19:36:31.000000000 -0400
26397@@ -300,7 +300,7 @@ static struct scsi_host_template vsc_sat
26398 };
26399
26400
26401-static struct ata_port_operations vsc_sata_ops = {
26402+static const struct ata_port_operations vsc_sata_ops = {
26403 .inherits = &ata_bmdma_port_ops,
26404 /* The IRQ handling is not quite standard SFF behaviour so we
26405 cannot use the default lost interrupt handler */
26406diff -urNp linux-2.6.39.1/drivers/atm/adummy.c linux-2.6.39.1/drivers/atm/adummy.c
26407--- linux-2.6.39.1/drivers/atm/adummy.c 2011-05-19 00:06:34.000000000 -0400
26408+++ linux-2.6.39.1/drivers/atm/adummy.c 2011-05-22 19:36:31.000000000 -0400
26409@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct
26410 vcc->pop(vcc, skb);
26411 else
26412 dev_kfree_skb_any(skb);
26413- atomic_inc(&vcc->stats->tx);
26414+ atomic_inc_unchecked(&vcc->stats->tx);
26415
26416 return 0;
26417 }
26418diff -urNp linux-2.6.39.1/drivers/atm/ambassador.c linux-2.6.39.1/drivers/atm/ambassador.c
26419--- linux-2.6.39.1/drivers/atm/ambassador.c 2011-05-19 00:06:34.000000000 -0400
26420+++ linux-2.6.39.1/drivers/atm/ambassador.c 2011-05-22 19:36:31.000000000 -0400
26421@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev,
26422 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
26423
26424 // VC layer stats
26425- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
26426+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
26427
26428 // free the descriptor
26429 kfree (tx_descr);
26430@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev,
26431 dump_skb ("<<<", vc, skb);
26432
26433 // VC layer stats
26434- atomic_inc(&atm_vcc->stats->rx);
26435+ atomic_inc_unchecked(&atm_vcc->stats->rx);
26436 __net_timestamp(skb);
26437 // end of our responsibility
26438 atm_vcc->push (atm_vcc, skb);
26439@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev,
26440 } else {
26441 PRINTK (KERN_INFO, "dropped over-size frame");
26442 // should we count this?
26443- atomic_inc(&atm_vcc->stats->rx_drop);
26444+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
26445 }
26446
26447 } else {
26448@@ -1342,7 +1342,7 @@ static int amb_send (struct atm_vcc * at
26449 }
26450
26451 if (check_area (skb->data, skb->len)) {
26452- atomic_inc(&atm_vcc->stats->tx_err);
26453+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
26454 return -ENOMEM; // ?
26455 }
26456
26457diff -urNp linux-2.6.39.1/drivers/atm/atmtcp.c linux-2.6.39.1/drivers/atm/atmtcp.c
26458--- linux-2.6.39.1/drivers/atm/atmtcp.c 2011-05-19 00:06:34.000000000 -0400
26459+++ linux-2.6.39.1/drivers/atm/atmtcp.c 2011-05-22 19:36:31.000000000 -0400
26460@@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc
26461 if (vcc->pop) vcc->pop(vcc,skb);
26462 else dev_kfree_skb(skb);
26463 if (dev_data) return 0;
26464- atomic_inc(&vcc->stats->tx_err);
26465+ atomic_inc_unchecked(&vcc->stats->tx_err);
26466 return -ENOLINK;
26467 }
26468 size = skb->len+sizeof(struct atmtcp_hdr);
26469@@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc
26470 if (!new_skb) {
26471 if (vcc->pop) vcc->pop(vcc,skb);
26472 else dev_kfree_skb(skb);
26473- atomic_inc(&vcc->stats->tx_err);
26474+ atomic_inc_unchecked(&vcc->stats->tx_err);
26475 return -ENOBUFS;
26476 }
26477 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
26478@@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc
26479 if (vcc->pop) vcc->pop(vcc,skb);
26480 else dev_kfree_skb(skb);
26481 out_vcc->push(out_vcc,new_skb);
26482- atomic_inc(&vcc->stats->tx);
26483- atomic_inc(&out_vcc->stats->rx);
26484+ atomic_inc_unchecked(&vcc->stats->tx);
26485+ atomic_inc_unchecked(&out_vcc->stats->rx);
26486 return 0;
26487 }
26488
26489@@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc
26490 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
26491 read_unlock(&vcc_sklist_lock);
26492 if (!out_vcc) {
26493- atomic_inc(&vcc->stats->tx_err);
26494+ atomic_inc_unchecked(&vcc->stats->tx_err);
26495 goto done;
26496 }
26497 skb_pull(skb,sizeof(struct atmtcp_hdr));
26498@@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc
26499 __net_timestamp(new_skb);
26500 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
26501 out_vcc->push(out_vcc,new_skb);
26502- atomic_inc(&vcc->stats->tx);
26503- atomic_inc(&out_vcc->stats->rx);
26504+ atomic_inc_unchecked(&vcc->stats->tx);
26505+ atomic_inc_unchecked(&out_vcc->stats->rx);
26506 done:
26507 if (vcc->pop) vcc->pop(vcc,skb);
26508 else dev_kfree_skb(skb);
26509diff -urNp linux-2.6.39.1/drivers/atm/eni.c linux-2.6.39.1/drivers/atm/eni.c
26510--- linux-2.6.39.1/drivers/atm/eni.c 2011-05-19 00:06:34.000000000 -0400
26511+++ linux-2.6.39.1/drivers/atm/eni.c 2011-05-22 19:36:31.000000000 -0400
26512@@ -526,7 +526,7 @@ static int rx_aal0(struct atm_vcc *vcc)
26513 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
26514 vcc->dev->number);
26515 length = 0;
26516- atomic_inc(&vcc->stats->rx_err);
26517+ atomic_inc_unchecked(&vcc->stats->rx_err);
26518 }
26519 else {
26520 length = ATM_CELL_SIZE-1; /* no HEC */
26521@@ -581,7 +581,7 @@ static int rx_aal5(struct atm_vcc *vcc)
26522 size);
26523 }
26524 eff = length = 0;
26525- atomic_inc(&vcc->stats->rx_err);
26526+ atomic_inc_unchecked(&vcc->stats->rx_err);
26527 }
26528 else {
26529 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
26530@@ -598,7 +598,7 @@ static int rx_aal5(struct atm_vcc *vcc)
26531 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
26532 vcc->dev->number,vcc->vci,length,size << 2,descr);
26533 length = eff = 0;
26534- atomic_inc(&vcc->stats->rx_err);
26535+ atomic_inc_unchecked(&vcc->stats->rx_err);
26536 }
26537 }
26538 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
26539@@ -771,7 +771,7 @@ rx_dequeued++;
26540 vcc->push(vcc,skb);
26541 pushed++;
26542 }
26543- atomic_inc(&vcc->stats->rx);
26544+ atomic_inc_unchecked(&vcc->stats->rx);
26545 }
26546 wake_up(&eni_dev->rx_wait);
26547 }
26548@@ -1228,7 +1228,7 @@ static void dequeue_tx(struct atm_dev *d
26549 PCI_DMA_TODEVICE);
26550 if (vcc->pop) vcc->pop(vcc,skb);
26551 else dev_kfree_skb_irq(skb);
26552- atomic_inc(&vcc->stats->tx);
26553+ atomic_inc_unchecked(&vcc->stats->tx);
26554 wake_up(&eni_dev->tx_wait);
26555 dma_complete++;
26556 }
26557diff -urNp linux-2.6.39.1/drivers/atm/firestream.c linux-2.6.39.1/drivers/atm/firestream.c
26558--- linux-2.6.39.1/drivers/atm/firestream.c 2011-05-19 00:06:34.000000000 -0400
26559+++ linux-2.6.39.1/drivers/atm/firestream.c 2011-05-22 19:36:31.000000000 -0400
26560@@ -749,7 +749,7 @@ static void process_txdone_queue (struct
26561 }
26562 }
26563
26564- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
26565+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
26566
26567 fs_dprintk (FS_DEBUG_TXMEM, "i");
26568 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
26569@@ -816,7 +816,7 @@ static void process_incoming (struct fs_
26570 #endif
26571 skb_put (skb, qe->p1 & 0xffff);
26572 ATM_SKB(skb)->vcc = atm_vcc;
26573- atomic_inc(&atm_vcc->stats->rx);
26574+ atomic_inc_unchecked(&atm_vcc->stats->rx);
26575 __net_timestamp(skb);
26576 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
26577 atm_vcc->push (atm_vcc, skb);
26578@@ -837,12 +837,12 @@ static void process_incoming (struct fs_
26579 kfree (pe);
26580 }
26581 if (atm_vcc)
26582- atomic_inc(&atm_vcc->stats->rx_drop);
26583+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
26584 break;
26585 case 0x1f: /* Reassembly abort: no buffers. */
26586 /* Silently increment error counter. */
26587 if (atm_vcc)
26588- atomic_inc(&atm_vcc->stats->rx_drop);
26589+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
26590 break;
26591 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
26592 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
26593diff -urNp linux-2.6.39.1/drivers/atm/fore200e.c linux-2.6.39.1/drivers/atm/fore200e.c
26594--- linux-2.6.39.1/drivers/atm/fore200e.c 2011-05-19 00:06:34.000000000 -0400
26595+++ linux-2.6.39.1/drivers/atm/fore200e.c 2011-05-22 19:36:31.000000000 -0400
26596@@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200
26597 #endif
26598 /* check error condition */
26599 if (*entry->status & STATUS_ERROR)
26600- atomic_inc(&vcc->stats->tx_err);
26601+ atomic_inc_unchecked(&vcc->stats->tx_err);
26602 else
26603- atomic_inc(&vcc->stats->tx);
26604+ atomic_inc_unchecked(&vcc->stats->tx);
26605 }
26606 }
26607
26608@@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore2
26609 if (skb == NULL) {
26610 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
26611
26612- atomic_inc(&vcc->stats->rx_drop);
26613+ atomic_inc_unchecked(&vcc->stats->rx_drop);
26614 return -ENOMEM;
26615 }
26616
26617@@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore2
26618
26619 dev_kfree_skb_any(skb);
26620
26621- atomic_inc(&vcc->stats->rx_drop);
26622+ atomic_inc_unchecked(&vcc->stats->rx_drop);
26623 return -ENOMEM;
26624 }
26625
26626 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
26627
26628 vcc->push(vcc, skb);
26629- atomic_inc(&vcc->stats->rx);
26630+ atomic_inc_unchecked(&vcc->stats->rx);
26631
26632 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
26633
26634@@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200
26635 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
26636 fore200e->atm_dev->number,
26637 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
26638- atomic_inc(&vcc->stats->rx_err);
26639+ atomic_inc_unchecked(&vcc->stats->rx_err);
26640 }
26641 }
26642
26643@@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struc
26644 goto retry_here;
26645 }
26646
26647- atomic_inc(&vcc->stats->tx_err);
26648+ atomic_inc_unchecked(&vcc->stats->tx_err);
26649
26650 fore200e->tx_sat++;
26651 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
26652diff -urNp linux-2.6.39.1/drivers/atm/he.c linux-2.6.39.1/drivers/atm/he.c
26653--- linux-2.6.39.1/drivers/atm/he.c 2011-05-19 00:06:34.000000000 -0400
26654+++ linux-2.6.39.1/drivers/atm/he.c 2011-05-22 19:36:31.000000000 -0400
26655@@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, i
26656
26657 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
26658 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
26659- atomic_inc(&vcc->stats->rx_drop);
26660+ atomic_inc_unchecked(&vcc->stats->rx_drop);
26661 goto return_host_buffers;
26662 }
26663
26664@@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, i
26665 RBRQ_LEN_ERR(he_dev->rbrq_head)
26666 ? "LEN_ERR" : "",
26667 vcc->vpi, vcc->vci);
26668- atomic_inc(&vcc->stats->rx_err);
26669+ atomic_inc_unchecked(&vcc->stats->rx_err);
26670 goto return_host_buffers;
26671 }
26672
26673@@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, i
26674 vcc->push(vcc, skb);
26675 spin_lock(&he_dev->global_lock);
26676
26677- atomic_inc(&vcc->stats->rx);
26678+ atomic_inc_unchecked(&vcc->stats->rx);
26679
26680 return_host_buffers:
26681 ++pdus_assembled;
26682@@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, str
26683 tpd->vcc->pop(tpd->vcc, tpd->skb);
26684 else
26685 dev_kfree_skb_any(tpd->skb);
26686- atomic_inc(&tpd->vcc->stats->tx_err);
26687+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
26688 }
26689 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
26690 return;
26691@@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
26692 vcc->pop(vcc, skb);
26693 else
26694 dev_kfree_skb_any(skb);
26695- atomic_inc(&vcc->stats->tx_err);
26696+ atomic_inc_unchecked(&vcc->stats->tx_err);
26697 return -EINVAL;
26698 }
26699
26700@@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
26701 vcc->pop(vcc, skb);
26702 else
26703 dev_kfree_skb_any(skb);
26704- atomic_inc(&vcc->stats->tx_err);
26705+ atomic_inc_unchecked(&vcc->stats->tx_err);
26706 return -EINVAL;
26707 }
26708 #endif
26709@@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
26710 vcc->pop(vcc, skb);
26711 else
26712 dev_kfree_skb_any(skb);
26713- atomic_inc(&vcc->stats->tx_err);
26714+ atomic_inc_unchecked(&vcc->stats->tx_err);
26715 spin_unlock_irqrestore(&he_dev->global_lock, flags);
26716 return -ENOMEM;
26717 }
26718@@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
26719 vcc->pop(vcc, skb);
26720 else
26721 dev_kfree_skb_any(skb);
26722- atomic_inc(&vcc->stats->tx_err);
26723+ atomic_inc_unchecked(&vcc->stats->tx_err);
26724 spin_unlock_irqrestore(&he_dev->global_lock, flags);
26725 return -ENOMEM;
26726 }
26727@@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
26728 __enqueue_tpd(he_dev, tpd, cid);
26729 spin_unlock_irqrestore(&he_dev->global_lock, flags);
26730
26731- atomic_inc(&vcc->stats->tx);
26732+ atomic_inc_unchecked(&vcc->stats->tx);
26733
26734 return 0;
26735 }
26736diff -urNp linux-2.6.39.1/drivers/atm/horizon.c linux-2.6.39.1/drivers/atm/horizon.c
26737--- linux-2.6.39.1/drivers/atm/horizon.c 2011-05-19 00:06:34.000000000 -0400
26738+++ linux-2.6.39.1/drivers/atm/horizon.c 2011-05-22 19:36:31.000000000 -0400
26739@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev,
26740 {
26741 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
26742 // VC layer stats
26743- atomic_inc(&vcc->stats->rx);
26744+ atomic_inc_unchecked(&vcc->stats->rx);
26745 __net_timestamp(skb);
26746 // end of our responsibility
26747 vcc->push (vcc, skb);
26748@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const
26749 dev->tx_iovec = NULL;
26750
26751 // VC layer stats
26752- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
26753+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
26754
26755 // free the skb
26756 hrz_kfree_skb (skb);
26757diff -urNp linux-2.6.39.1/drivers/atm/idt77252.c linux-2.6.39.1/drivers/atm/idt77252.c
26758--- linux-2.6.39.1/drivers/atm/idt77252.c 2011-05-19 00:06:34.000000000 -0400
26759+++ linux-2.6.39.1/drivers/atm/idt77252.c 2011-05-22 19:36:31.000000000 -0400
26760@@ -811,7 +811,7 @@ drain_scq(struct idt77252_dev *card, str
26761 else
26762 dev_kfree_skb(skb);
26763
26764- atomic_inc(&vcc->stats->tx);
26765+ atomic_inc_unchecked(&vcc->stats->tx);
26766 }
26767
26768 atomic_dec(&scq->used);
26769@@ -1074,13 +1074,13 @@ dequeue_rx(struct idt77252_dev *card, st
26770 if ((sb = dev_alloc_skb(64)) == NULL) {
26771 printk("%s: Can't allocate buffers for aal0.\n",
26772 card->name);
26773- atomic_add(i, &vcc->stats->rx_drop);
26774+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
26775 break;
26776 }
26777 if (!atm_charge(vcc, sb->truesize)) {
26778 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
26779 card->name);
26780- atomic_add(i - 1, &vcc->stats->rx_drop);
26781+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
26782 dev_kfree_skb(sb);
26783 break;
26784 }
26785@@ -1097,7 +1097,7 @@ dequeue_rx(struct idt77252_dev *card, st
26786 ATM_SKB(sb)->vcc = vcc;
26787 __net_timestamp(sb);
26788 vcc->push(vcc, sb);
26789- atomic_inc(&vcc->stats->rx);
26790+ atomic_inc_unchecked(&vcc->stats->rx);
26791
26792 cell += ATM_CELL_PAYLOAD;
26793 }
26794@@ -1134,13 +1134,13 @@ dequeue_rx(struct idt77252_dev *card, st
26795 "(CDC: %08x)\n",
26796 card->name, len, rpp->len, readl(SAR_REG_CDC));
26797 recycle_rx_pool_skb(card, rpp);
26798- atomic_inc(&vcc->stats->rx_err);
26799+ atomic_inc_unchecked(&vcc->stats->rx_err);
26800 return;
26801 }
26802 if (stat & SAR_RSQE_CRC) {
26803 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
26804 recycle_rx_pool_skb(card, rpp);
26805- atomic_inc(&vcc->stats->rx_err);
26806+ atomic_inc_unchecked(&vcc->stats->rx_err);
26807 return;
26808 }
26809 if (skb_queue_len(&rpp->queue) > 1) {
26810@@ -1151,7 +1151,7 @@ dequeue_rx(struct idt77252_dev *card, st
26811 RXPRINTK("%s: Can't alloc RX skb.\n",
26812 card->name);
26813 recycle_rx_pool_skb(card, rpp);
26814- atomic_inc(&vcc->stats->rx_err);
26815+ atomic_inc_unchecked(&vcc->stats->rx_err);
26816 return;
26817 }
26818 if (!atm_charge(vcc, skb->truesize)) {
26819@@ -1170,7 +1170,7 @@ dequeue_rx(struct idt77252_dev *card, st
26820 __net_timestamp(skb);
26821
26822 vcc->push(vcc, skb);
26823- atomic_inc(&vcc->stats->rx);
26824+ atomic_inc_unchecked(&vcc->stats->rx);
26825
26826 return;
26827 }
26828@@ -1192,7 +1192,7 @@ dequeue_rx(struct idt77252_dev *card, st
26829 __net_timestamp(skb);
26830
26831 vcc->push(vcc, skb);
26832- atomic_inc(&vcc->stats->rx);
26833+ atomic_inc_unchecked(&vcc->stats->rx);
26834
26835 if (skb->truesize > SAR_FB_SIZE_3)
26836 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
26837@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *car
26838 if (vcc->qos.aal != ATM_AAL0) {
26839 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
26840 card->name, vpi, vci);
26841- atomic_inc(&vcc->stats->rx_drop);
26842+ atomic_inc_unchecked(&vcc->stats->rx_drop);
26843 goto drop;
26844 }
26845
26846 if ((sb = dev_alloc_skb(64)) == NULL) {
26847 printk("%s: Can't allocate buffers for AAL0.\n",
26848 card->name);
26849- atomic_inc(&vcc->stats->rx_err);
26850+ atomic_inc_unchecked(&vcc->stats->rx_err);
26851 goto drop;
26852 }
26853
26854@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *car
26855 ATM_SKB(sb)->vcc = vcc;
26856 __net_timestamp(sb);
26857 vcc->push(vcc, sb);
26858- atomic_inc(&vcc->stats->rx);
26859+ atomic_inc_unchecked(&vcc->stats->rx);
26860
26861 drop:
26862 skb_pull(queue, 64);
26863@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, s
26864
26865 if (vc == NULL) {
26866 printk("%s: NULL connection in send().\n", card->name);
26867- atomic_inc(&vcc->stats->tx_err);
26868+ atomic_inc_unchecked(&vcc->stats->tx_err);
26869 dev_kfree_skb(skb);
26870 return -EINVAL;
26871 }
26872 if (!test_bit(VCF_TX, &vc->flags)) {
26873 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
26874- atomic_inc(&vcc->stats->tx_err);
26875+ atomic_inc_unchecked(&vcc->stats->tx_err);
26876 dev_kfree_skb(skb);
26877 return -EINVAL;
26878 }
26879@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, s
26880 break;
26881 default:
26882 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
26883- atomic_inc(&vcc->stats->tx_err);
26884+ atomic_inc_unchecked(&vcc->stats->tx_err);
26885 dev_kfree_skb(skb);
26886 return -EINVAL;
26887 }
26888
26889 if (skb_shinfo(skb)->nr_frags != 0) {
26890 printk("%s: No scatter-gather yet.\n", card->name);
26891- atomic_inc(&vcc->stats->tx_err);
26892+ atomic_inc_unchecked(&vcc->stats->tx_err);
26893 dev_kfree_skb(skb);
26894 return -EINVAL;
26895 }
26896@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, s
26897
26898 err = queue_skb(card, vc, skb, oam);
26899 if (err) {
26900- atomic_inc(&vcc->stats->tx_err);
26901+ atomic_inc_unchecked(&vcc->stats->tx_err);
26902 dev_kfree_skb(skb);
26903 return err;
26904 }
26905@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, v
26906 skb = dev_alloc_skb(64);
26907 if (!skb) {
26908 printk("%s: Out of memory in send_oam().\n", card->name);
26909- atomic_inc(&vcc->stats->tx_err);
26910+ atomic_inc_unchecked(&vcc->stats->tx_err);
26911 return -ENOMEM;
26912 }
26913 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
26914diff -urNp linux-2.6.39.1/drivers/atm/iphase.c linux-2.6.39.1/drivers/atm/iphase.c
26915--- linux-2.6.39.1/drivers/atm/iphase.c 2011-05-19 00:06:34.000000000 -0400
26916+++ linux-2.6.39.1/drivers/atm/iphase.c 2011-05-22 19:36:31.000000000 -0400
26917@@ -1124,7 +1124,7 @@ static int rx_pkt(struct atm_dev *dev)
26918 status = (u_short) (buf_desc_ptr->desc_mode);
26919 if (status & (RX_CER | RX_PTE | RX_OFL))
26920 {
26921- atomic_inc(&vcc->stats->rx_err);
26922+ atomic_inc_unchecked(&vcc->stats->rx_err);
26923 IF_ERR(printk("IA: bad packet, dropping it");)
26924 if (status & RX_CER) {
26925 IF_ERR(printk(" cause: packet CRC error\n");)
26926@@ -1147,7 +1147,7 @@ static int rx_pkt(struct atm_dev *dev)
26927 len = dma_addr - buf_addr;
26928 if (len > iadev->rx_buf_sz) {
26929 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
26930- atomic_inc(&vcc->stats->rx_err);
26931+ atomic_inc_unchecked(&vcc->stats->rx_err);
26932 goto out_free_desc;
26933 }
26934
26935@@ -1297,7 +1297,7 @@ static void rx_dle_intr(struct atm_dev *
26936 ia_vcc = INPH_IA_VCC(vcc);
26937 if (ia_vcc == NULL)
26938 {
26939- atomic_inc(&vcc->stats->rx_err);
26940+ atomic_inc_unchecked(&vcc->stats->rx_err);
26941 dev_kfree_skb_any(skb);
26942 atm_return(vcc, atm_guess_pdu2truesize(len));
26943 goto INCR_DLE;
26944@@ -1309,7 +1309,7 @@ static void rx_dle_intr(struct atm_dev *
26945 if ((length > iadev->rx_buf_sz) || (length >
26946 (skb->len - sizeof(struct cpcs_trailer))))
26947 {
26948- atomic_inc(&vcc->stats->rx_err);
26949+ atomic_inc_unchecked(&vcc->stats->rx_err);
26950 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
26951 length, skb->len);)
26952 dev_kfree_skb_any(skb);
26953@@ -1325,7 +1325,7 @@ static void rx_dle_intr(struct atm_dev *
26954
26955 IF_RX(printk("rx_dle_intr: skb push");)
26956 vcc->push(vcc,skb);
26957- atomic_inc(&vcc->stats->rx);
26958+ atomic_inc_unchecked(&vcc->stats->rx);
26959 iadev->rx_pkt_cnt++;
26960 }
26961 INCR_DLE:
26962@@ -2807,15 +2807,15 @@ static int ia_ioctl(struct atm_dev *dev,
26963 {
26964 struct k_sonet_stats *stats;
26965 stats = &PRIV(_ia_dev[board])->sonet_stats;
26966- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
26967- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
26968- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
26969- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
26970- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
26971- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
26972- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
26973- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
26974- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
26975+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
26976+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
26977+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
26978+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
26979+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
26980+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
26981+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
26982+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
26983+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
26984 }
26985 ia_cmds.status = 0;
26986 break;
26987@@ -2920,7 +2920,7 @@ static int ia_pkt_tx (struct atm_vcc *vc
26988 if ((desc == 0) || (desc > iadev->num_tx_desc))
26989 {
26990 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
26991- atomic_inc(&vcc->stats->tx);
26992+ atomic_inc_unchecked(&vcc->stats->tx);
26993 if (vcc->pop)
26994 vcc->pop(vcc, skb);
26995 else
26996@@ -3025,14 +3025,14 @@ static int ia_pkt_tx (struct atm_vcc *vc
26997 ATM_DESC(skb) = vcc->vci;
26998 skb_queue_tail(&iadev->tx_dma_q, skb);
26999
27000- atomic_inc(&vcc->stats->tx);
27001+ atomic_inc_unchecked(&vcc->stats->tx);
27002 iadev->tx_pkt_cnt++;
27003 /* Increment transaction counter */
27004 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
27005
27006 #if 0
27007 /* add flow control logic */
27008- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
27009+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
27010 if (iavcc->vc_desc_cnt > 10) {
27011 vcc->tx_quota = vcc->tx_quota * 3 / 4;
27012 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
27013diff -urNp linux-2.6.39.1/drivers/atm/lanai.c linux-2.6.39.1/drivers/atm/lanai.c
27014--- linux-2.6.39.1/drivers/atm/lanai.c 2011-05-19 00:06:34.000000000 -0400
27015+++ linux-2.6.39.1/drivers/atm/lanai.c 2011-05-22 19:36:31.000000000 -0400
27016@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct l
27017 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
27018 lanai_endtx(lanai, lvcc);
27019 lanai_free_skb(lvcc->tx.atmvcc, skb);
27020- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
27021+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
27022 }
27023
27024 /* Try to fill the buffer - don't call unless there is backlog */
27025@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc
27026 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
27027 __net_timestamp(skb);
27028 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
27029- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
27030+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
27031 out:
27032 lvcc->rx.buf.ptr = end;
27033 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
27034@@ -1668,7 +1668,7 @@ static int handle_service(struct lanai_d
27035 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
27036 "vcc %d\n", lanai->number, (unsigned int) s, vci);
27037 lanai->stats.service_rxnotaal5++;
27038- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
27039+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
27040 return 0;
27041 }
27042 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
27043@@ -1680,7 +1680,7 @@ static int handle_service(struct lanai_d
27044 int bytes;
27045 read_unlock(&vcc_sklist_lock);
27046 DPRINTK("got trashed rx pdu on vci %d\n", vci);
27047- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
27048+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
27049 lvcc->stats.x.aal5.service_trash++;
27050 bytes = (SERVICE_GET_END(s) * 16) -
27051 (((unsigned long) lvcc->rx.buf.ptr) -
27052@@ -1692,7 +1692,7 @@ static int handle_service(struct lanai_d
27053 }
27054 if (s & SERVICE_STREAM) {
27055 read_unlock(&vcc_sklist_lock);
27056- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
27057+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
27058 lvcc->stats.x.aal5.service_stream++;
27059 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
27060 "PDU on VCI %d!\n", lanai->number, vci);
27061@@ -1700,7 +1700,7 @@ static int handle_service(struct lanai_d
27062 return 0;
27063 }
27064 DPRINTK("got rx crc error on vci %d\n", vci);
27065- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
27066+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
27067 lvcc->stats.x.aal5.service_rxcrc++;
27068 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
27069 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
27070diff -urNp linux-2.6.39.1/drivers/atm/nicstar.c linux-2.6.39.1/drivers/atm/nicstar.c
27071--- linux-2.6.39.1/drivers/atm/nicstar.c 2011-05-19 00:06:34.000000000 -0400
27072+++ linux-2.6.39.1/drivers/atm/nicstar.c 2011-05-22 19:36:31.000000000 -0400
27073@@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc,
27074 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
27075 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
27076 card->index);
27077- atomic_inc(&vcc->stats->tx_err);
27078+ atomic_inc_unchecked(&vcc->stats->tx_err);
27079 dev_kfree_skb_any(skb);
27080 return -EINVAL;
27081 }
27082@@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc,
27083 if (!vc->tx) {
27084 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
27085 card->index);
27086- atomic_inc(&vcc->stats->tx_err);
27087+ atomic_inc_unchecked(&vcc->stats->tx_err);
27088 dev_kfree_skb_any(skb);
27089 return -EINVAL;
27090 }
27091@@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc,
27092 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
27093 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
27094 card->index);
27095- atomic_inc(&vcc->stats->tx_err);
27096+ atomic_inc_unchecked(&vcc->stats->tx_err);
27097 dev_kfree_skb_any(skb);
27098 return -EINVAL;
27099 }
27100
27101 if (skb_shinfo(skb)->nr_frags != 0) {
27102 printk("nicstar%d: No scatter-gather yet.\n", card->index);
27103- atomic_inc(&vcc->stats->tx_err);
27104+ atomic_inc_unchecked(&vcc->stats->tx_err);
27105 dev_kfree_skb_any(skb);
27106 return -EINVAL;
27107 }
27108@@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc,
27109 }
27110
27111 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
27112- atomic_inc(&vcc->stats->tx_err);
27113+ atomic_inc_unchecked(&vcc->stats->tx_err);
27114 dev_kfree_skb_any(skb);
27115 return -EIO;
27116 }
27117- atomic_inc(&vcc->stats->tx);
27118+ atomic_inc_unchecked(&vcc->stats->tx);
27119
27120 return 0;
27121 }
27122@@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns
27123 printk
27124 ("nicstar%d: Can't allocate buffers for aal0.\n",
27125 card->index);
27126- atomic_add(i, &vcc->stats->rx_drop);
27127+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
27128 break;
27129 }
27130 if (!atm_charge(vcc, sb->truesize)) {
27131 RXPRINTK
27132 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
27133 card->index);
27134- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
27135+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
27136 dev_kfree_skb_any(sb);
27137 break;
27138 }
27139@@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns
27140 ATM_SKB(sb)->vcc = vcc;
27141 __net_timestamp(sb);
27142 vcc->push(vcc, sb);
27143- atomic_inc(&vcc->stats->rx);
27144+ atomic_inc_unchecked(&vcc->stats->rx);
27145 cell += ATM_CELL_PAYLOAD;
27146 }
27147
27148@@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns
27149 if (iovb == NULL) {
27150 printk("nicstar%d: Out of iovec buffers.\n",
27151 card->index);
27152- atomic_inc(&vcc->stats->rx_drop);
27153+ atomic_inc_unchecked(&vcc->stats->rx_drop);
27154 recycle_rx_buf(card, skb);
27155 return;
27156 }
27157@@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns
27158 small or large buffer itself. */
27159 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
27160 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
27161- atomic_inc(&vcc->stats->rx_err);
27162+ atomic_inc_unchecked(&vcc->stats->rx_err);
27163 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
27164 NS_MAX_IOVECS);
27165 NS_PRV_IOVCNT(iovb) = 0;
27166@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns
27167 ("nicstar%d: Expected a small buffer, and this is not one.\n",
27168 card->index);
27169 which_list(card, skb);
27170- atomic_inc(&vcc->stats->rx_err);
27171+ atomic_inc_unchecked(&vcc->stats->rx_err);
27172 recycle_rx_buf(card, skb);
27173 vc->rx_iov = NULL;
27174 recycle_iov_buf(card, iovb);
27175@@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns
27176 ("nicstar%d: Expected a large buffer, and this is not one.\n",
27177 card->index);
27178 which_list(card, skb);
27179- atomic_inc(&vcc->stats->rx_err);
27180+ atomic_inc_unchecked(&vcc->stats->rx_err);
27181 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
27182 NS_PRV_IOVCNT(iovb));
27183 vc->rx_iov = NULL;
27184@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns
27185 printk(" - PDU size mismatch.\n");
27186 else
27187 printk(".\n");
27188- atomic_inc(&vcc->stats->rx_err);
27189+ atomic_inc_unchecked(&vcc->stats->rx_err);
27190 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
27191 NS_PRV_IOVCNT(iovb));
27192 vc->rx_iov = NULL;
27193@@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns
27194 /* skb points to a small buffer */
27195 if (!atm_charge(vcc, skb->truesize)) {
27196 push_rxbufs(card, skb);
27197- atomic_inc(&vcc->stats->rx_drop);
27198+ atomic_inc_unchecked(&vcc->stats->rx_drop);
27199 } else {
27200 skb_put(skb, len);
27201 dequeue_sm_buf(card, skb);
27202@@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns
27203 ATM_SKB(skb)->vcc = vcc;
27204 __net_timestamp(skb);
27205 vcc->push(vcc, skb);
27206- atomic_inc(&vcc->stats->rx);
27207+ atomic_inc_unchecked(&vcc->stats->rx);
27208 }
27209 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
27210 struct sk_buff *sb;
27211@@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns
27212 if (len <= NS_SMBUFSIZE) {
27213 if (!atm_charge(vcc, sb->truesize)) {
27214 push_rxbufs(card, sb);
27215- atomic_inc(&vcc->stats->rx_drop);
27216+ atomic_inc_unchecked(&vcc->stats->rx_drop);
27217 } else {
27218 skb_put(sb, len);
27219 dequeue_sm_buf(card, sb);
27220@@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns
27221 ATM_SKB(sb)->vcc = vcc;
27222 __net_timestamp(sb);
27223 vcc->push(vcc, sb);
27224- atomic_inc(&vcc->stats->rx);
27225+ atomic_inc_unchecked(&vcc->stats->rx);
27226 }
27227
27228 push_rxbufs(card, skb);
27229@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns
27230
27231 if (!atm_charge(vcc, skb->truesize)) {
27232 push_rxbufs(card, skb);
27233- atomic_inc(&vcc->stats->rx_drop);
27234+ atomic_inc_unchecked(&vcc->stats->rx_drop);
27235 } else {
27236 dequeue_lg_buf(card, skb);
27237 #ifdef NS_USE_DESTRUCTORS
27238@@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns
27239 ATM_SKB(skb)->vcc = vcc;
27240 __net_timestamp(skb);
27241 vcc->push(vcc, skb);
27242- atomic_inc(&vcc->stats->rx);
27243+ atomic_inc_unchecked(&vcc->stats->rx);
27244 }
27245
27246 push_rxbufs(card, sb);
27247@@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns
27248 printk
27249 ("nicstar%d: Out of huge buffers.\n",
27250 card->index);
27251- atomic_inc(&vcc->stats->rx_drop);
27252+ atomic_inc_unchecked(&vcc->stats->rx_drop);
27253 recycle_iovec_rx_bufs(card,
27254 (struct iovec *)
27255 iovb->data,
27256@@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns
27257 card->hbpool.count++;
27258 } else
27259 dev_kfree_skb_any(hb);
27260- atomic_inc(&vcc->stats->rx_drop);
27261+ atomic_inc_unchecked(&vcc->stats->rx_drop);
27262 } else {
27263 /* Copy the small buffer to the huge buffer */
27264 sb = (struct sk_buff *)iov->iov_base;
27265@@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns
27266 #endif /* NS_USE_DESTRUCTORS */
27267 __net_timestamp(hb);
27268 vcc->push(vcc, hb);
27269- atomic_inc(&vcc->stats->rx);
27270+ atomic_inc_unchecked(&vcc->stats->rx);
27271 }
27272 }
27273
27274diff -urNp linux-2.6.39.1/drivers/atm/solos-pci.c linux-2.6.39.1/drivers/atm/solos-pci.c
27275--- linux-2.6.39.1/drivers/atm/solos-pci.c 2011-05-19 00:06:34.000000000 -0400
27276+++ linux-2.6.39.1/drivers/atm/solos-pci.c 2011-05-22 19:36:31.000000000 -0400
27277@@ -715,7 +715,7 @@ void solos_bh(unsigned long card_arg)
27278 }
27279 atm_charge(vcc, skb->truesize);
27280 vcc->push(vcc, skb);
27281- atomic_inc(&vcc->stats->rx);
27282+ atomic_inc_unchecked(&vcc->stats->rx);
27283 break;
27284
27285 case PKT_STATUS:
27286@@ -900,6 +900,8 @@ static int print_buffer(struct sk_buff *
27287 char msg[500];
27288 char item[10];
27289
27290+ pax_track_stack();
27291+
27292 len = buf->len;
27293 for (i = 0; i < len; i++){
27294 if(i % 8 == 0)
27295@@ -1009,7 +1011,7 @@ static uint32_t fpga_tx(struct solos_car
27296 vcc = SKB_CB(oldskb)->vcc;
27297
27298 if (vcc) {
27299- atomic_inc(&vcc->stats->tx);
27300+ atomic_inc_unchecked(&vcc->stats->tx);
27301 solos_pop(vcc, oldskb);
27302 } else
27303 dev_kfree_skb_irq(oldskb);
27304diff -urNp linux-2.6.39.1/drivers/atm/suni.c linux-2.6.39.1/drivers/atm/suni.c
27305--- linux-2.6.39.1/drivers/atm/suni.c 2011-05-19 00:06:34.000000000 -0400
27306+++ linux-2.6.39.1/drivers/atm/suni.c 2011-05-22 19:36:31.000000000 -0400
27307@@ -50,8 +50,8 @@ static DEFINE_SPINLOCK(sunis_lock);
27308
27309
27310 #define ADD_LIMITED(s,v) \
27311- atomic_add((v),&stats->s); \
27312- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
27313+ atomic_add_unchecked((v),&stats->s); \
27314+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
27315
27316
27317 static void suni_hz(unsigned long from_timer)
27318diff -urNp linux-2.6.39.1/drivers/atm/uPD98402.c linux-2.6.39.1/drivers/atm/uPD98402.c
27319--- linux-2.6.39.1/drivers/atm/uPD98402.c 2011-05-19 00:06:34.000000000 -0400
27320+++ linux-2.6.39.1/drivers/atm/uPD98402.c 2011-05-22 19:36:31.000000000 -0400
27321@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *d
27322 struct sonet_stats tmp;
27323 int error = 0;
27324
27325- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
27326+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
27327 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
27328 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
27329 if (zero && !error) {
27330@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev
27331
27332
27333 #define ADD_LIMITED(s,v) \
27334- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
27335- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
27336- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
27337+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
27338+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
27339+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
27340
27341
27342 static void stat_event(struct atm_dev *dev)
27343@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev
27344 if (reason & uPD98402_INT_PFM) stat_event(dev);
27345 if (reason & uPD98402_INT_PCO) {
27346 (void) GET(PCOCR); /* clear interrupt cause */
27347- atomic_add(GET(HECCT),
27348+ atomic_add_unchecked(GET(HECCT),
27349 &PRIV(dev)->sonet_stats.uncorr_hcs);
27350 }
27351 if ((reason & uPD98402_INT_RFO) &&
27352@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev
27353 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
27354 uPD98402_INT_LOS),PIMR); /* enable them */
27355 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
27356- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
27357- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
27358- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
27359+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
27360+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
27361+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
27362 return 0;
27363 }
27364
27365diff -urNp linux-2.6.39.1/drivers/atm/zatm.c linux-2.6.39.1/drivers/atm/zatm.c
27366--- linux-2.6.39.1/drivers/atm/zatm.c 2011-05-19 00:06:34.000000000 -0400
27367+++ linux-2.6.39.1/drivers/atm/zatm.c 2011-05-22 19:36:31.000000000 -0400
27368@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy
27369 }
27370 if (!size) {
27371 dev_kfree_skb_irq(skb);
27372- if (vcc) atomic_inc(&vcc->stats->rx_err);
27373+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
27374 continue;
27375 }
27376 if (!atm_charge(vcc,skb->truesize)) {
27377@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy
27378 skb->len = size;
27379 ATM_SKB(skb)->vcc = vcc;
27380 vcc->push(vcc,skb);
27381- atomic_inc(&vcc->stats->rx);
27382+ atomic_inc_unchecked(&vcc->stats->rx);
27383 }
27384 zout(pos & 0xffff,MTA(mbx));
27385 #if 0 /* probably a stupid idea */
27386@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD
27387 skb_queue_head(&zatm_vcc->backlog,skb);
27388 break;
27389 }
27390- atomic_inc(&vcc->stats->tx);
27391+ atomic_inc_unchecked(&vcc->stats->tx);
27392 wake_up(&zatm_vcc->tx_wait);
27393 }
27394
27395diff -urNp linux-2.6.39.1/drivers/base/iommu.c linux-2.6.39.1/drivers/base/iommu.c
27396--- linux-2.6.39.1/drivers/base/iommu.c 2011-05-19 00:06:34.000000000 -0400
27397+++ linux-2.6.39.1/drivers/base/iommu.c 2011-05-22 19:36:31.000000000 -0400
27398@@ -23,9 +23,8 @@
27399 #include <linux/errno.h>
27400 #include <linux/iommu.h>
27401
27402-static struct iommu_ops *iommu_ops;
27403-
27404-void register_iommu(struct iommu_ops *ops)
27405+static const struct iommu_ops *iommu_ops;
27406+void register_iommu(const struct iommu_ops *ops)
27407 {
27408 if (iommu_ops)
27409 BUG();
27410diff -urNp linux-2.6.39.1/drivers/base/power/generic_ops.c linux-2.6.39.1/drivers/base/power/generic_ops.c
27411--- linux-2.6.39.1/drivers/base/power/generic_ops.c 2011-05-19 00:06:34.000000000 -0400
27412+++ linux-2.6.39.1/drivers/base/power/generic_ops.c 2011-05-22 19:36:31.000000000 -0400
27413@@ -215,7 +215,7 @@ int pm_generic_restore(struct device *de
27414 EXPORT_SYMBOL_GPL(pm_generic_restore);
27415 #endif /* CONFIG_PM_SLEEP */
27416
27417-struct dev_pm_ops generic_subsys_pm_ops = {
27418+const struct dev_pm_ops generic_subsys_pm_ops = {
27419 #ifdef CONFIG_PM_SLEEP
27420 .suspend = pm_generic_suspend,
27421 .resume = pm_generic_resume,
27422diff -urNp linux-2.6.39.1/drivers/base/power/wakeup.c linux-2.6.39.1/drivers/base/power/wakeup.c
27423--- linux-2.6.39.1/drivers/base/power/wakeup.c 2011-05-19 00:06:34.000000000 -0400
27424+++ linux-2.6.39.1/drivers/base/power/wakeup.c 2011-05-22 19:36:31.000000000 -0400
27425@@ -29,14 +29,14 @@ bool events_check_enabled;
27426 * They need to be modified together atomically, so it's better to use one
27427 * atomic variable to hold them both.
27428 */
27429-static atomic_t combined_event_count = ATOMIC_INIT(0);
27430+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
27431
27432 #define IN_PROGRESS_BITS (sizeof(int) * 4)
27433 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
27434
27435 static void split_counters(unsigned int *cnt, unsigned int *inpr)
27436 {
27437- unsigned int comb = atomic_read(&combined_event_count);
27438+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
27439
27440 *cnt = (comb >> IN_PROGRESS_BITS);
27441 *inpr = comb & MAX_IN_PROGRESS;
27442@@ -351,7 +351,7 @@ static void wakeup_source_activate(struc
27443 ws->last_time = ktime_get();
27444
27445 /* Increment the counter of events in progress. */
27446- atomic_inc(&combined_event_count);
27447+ atomic_inc_unchecked(&combined_event_count);
27448 }
27449
27450 /**
27451@@ -441,7 +441,7 @@ static void wakeup_source_deactivate(str
27452 * Increment the counter of registered wakeup events and decrement the
27453 * couter of wakeup events in progress simultaneously.
27454 */
27455- atomic_add(MAX_IN_PROGRESS, &combined_event_count);
27456+ atomic_add_unchecked(MAX_IN_PROGRESS, &combined_event_count);
27457 }
27458
27459 /**
27460diff -urNp linux-2.6.39.1/drivers/block/cciss.c linux-2.6.39.1/drivers/block/cciss.c
27461--- linux-2.6.39.1/drivers/block/cciss.c 2011-05-19 00:06:34.000000000 -0400
27462+++ linux-2.6.39.1/drivers/block/cciss.c 2011-05-22 19:41:32.000000000 -0400
27463@@ -103,7 +103,7 @@ MODULE_DEVICE_TABLE(pci, cciss_pci_devic
27464 * product = Marketing Name for the board
27465 * access = Address of the struct of function pointers
27466 */
27467-static struct board_type products[] = {
27468+static const struct board_type products[] = {
27469 {0x40700E11, "Smart Array 5300", &SA5_access},
27470 {0x40800E11, "Smart Array 5i", &SA5B_access},
27471 {0x40820E11, "Smart Array 532", &SA5B_access},
27472@@ -1151,6 +1151,8 @@ static int cciss_ioctl32_passthru(struct
27473 int err;
27474 u32 cp;
27475
27476+ memset(&arg64, 0, sizeof(arg64));
27477+
27478 err = 0;
27479 err |=
27480 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
27481diff -urNp linux-2.6.39.1/drivers/block/cciss.h linux-2.6.39.1/drivers/block/cciss.h
27482--- linux-2.6.39.1/drivers/block/cciss.h 2011-05-19 00:06:34.000000000 -0400
27483+++ linux-2.6.39.1/drivers/block/cciss.h 2011-05-22 19:36:31.000000000 -0400
27484@@ -393,7 +393,7 @@ static bool SA5_performant_intr_pending(
27485 return register_value & SA5_OUTDB_STATUS_PERF_BIT;
27486 }
27487
27488-static struct access_method SA5_access = {
27489+static const struct access_method SA5_access = {
27490 SA5_submit_command,
27491 SA5_intr_mask,
27492 SA5_fifo_full,
27493@@ -401,7 +401,7 @@ static struct access_method SA5_access =
27494 SA5_completed,
27495 };
27496
27497-static struct access_method SA5B_access = {
27498+static const struct access_method SA5B_access = {
27499 SA5_submit_command,
27500 SA5B_intr_mask,
27501 SA5_fifo_full,
27502@@ -409,7 +409,7 @@ static struct access_method SA5B_access
27503 SA5_completed,
27504 };
27505
27506-static struct access_method SA5_performant_access = {
27507+static const struct access_method SA5_performant_access = {
27508 SA5_submit_command,
27509 SA5_performant_intr_mask,
27510 SA5_fifo_full,
27511@@ -420,7 +420,7 @@ static struct access_method SA5_performa
27512 struct board_type {
27513 __u32 board_id;
27514 char *product_name;
27515- struct access_method *access;
27516+ const struct access_method *access;
27517 int nr_cmds; /* Max cmds this kind of ctlr can handle. */
27518 };
27519
27520diff -urNp linux-2.6.39.1/drivers/block/cpqarray.c linux-2.6.39.1/drivers/block/cpqarray.c
27521--- linux-2.6.39.1/drivers/block/cpqarray.c 2011-05-19 00:06:34.000000000 -0400
27522+++ linux-2.6.39.1/drivers/block/cpqarray.c 2011-05-22 19:36:31.000000000 -0400
27523@@ -80,7 +80,7 @@ static int eisa[8];
27524 * product = Marketing Name for the board
27525 * access = Address of the struct of function pointers
27526 */
27527-static struct board_type products[] = {
27528+static const struct board_type products[] = {
27529 { 0x0040110E, "IDA", &smart1_access },
27530 { 0x0140110E, "IDA-2", &smart1_access },
27531 { 0x1040110E, "IAES", &smart1_access },
27532@@ -911,6 +911,8 @@ static void do_ida_request(struct reques
27533 struct scatterlist tmp_sg[SG_MAX];
27534 int i, dir, seg;
27535
27536+ pax_track_stack();
27537+
27538 queue_next:
27539 creq = blk_peek_request(q);
27540 if (!creq)
27541diff -urNp linux-2.6.39.1/drivers/block/cpqarray.h linux-2.6.39.1/drivers/block/cpqarray.h
27542--- linux-2.6.39.1/drivers/block/cpqarray.h 2011-05-19 00:06:34.000000000 -0400
27543+++ linux-2.6.39.1/drivers/block/cpqarray.h 2011-05-22 19:36:31.000000000 -0400
27544@@ -69,7 +69,7 @@ struct access_method {
27545 struct board_type {
27546 __u32 board_id;
27547 char *product_name;
27548- struct access_method *access;
27549+ const struct access_method *access;
27550 };
27551
27552 struct ctlr_info {
27553diff -urNp linux-2.6.39.1/drivers/block/DAC960.c linux-2.6.39.1/drivers/block/DAC960.c
27554--- linux-2.6.39.1/drivers/block/DAC960.c 2011-05-19 00:06:34.000000000 -0400
27555+++ linux-2.6.39.1/drivers/block/DAC960.c 2011-05-22 19:36:31.000000000 -0400
27556@@ -1980,6 +1980,8 @@ static bool DAC960_V1_ReadDeviceConfigur
27557 unsigned long flags;
27558 int Channel, TargetID;
27559
27560+ pax_track_stack();
27561+
27562 if (!init_dma_loaf(Controller->PCIDevice, &local_dma,
27563 DAC960_V1_MaxChannels*(sizeof(DAC960_V1_DCDB_T) +
27564 sizeof(DAC960_SCSI_Inquiry_T) +
27565diff -urNp linux-2.6.39.1/drivers/block/drbd/drbd_int.h linux-2.6.39.1/drivers/block/drbd/drbd_int.h
27566--- linux-2.6.39.1/drivers/block/drbd/drbd_int.h 2011-05-19 00:06:34.000000000 -0400
27567+++ linux-2.6.39.1/drivers/block/drbd/drbd_int.h 2011-05-22 19:36:31.000000000 -0400
27568@@ -736,7 +736,7 @@ struct drbd_request;
27569 struct drbd_epoch {
27570 struct list_head list;
27571 unsigned int barrier_nr;
27572- atomic_t epoch_size; /* increased on every request added. */
27573+ atomic_unchecked_t epoch_size; /* increased on every request added. */
27574 atomic_t active; /* increased on every req. added, and dec on every finished. */
27575 unsigned long flags;
27576 };
27577@@ -1108,7 +1108,7 @@ struct drbd_conf {
27578 void *int_dig_in;
27579 void *int_dig_vv;
27580 wait_queue_head_t seq_wait;
27581- atomic_t packet_seq;
27582+ atomic_unchecked_t packet_seq;
27583 unsigned int peer_seq;
27584 spinlock_t peer_seq_lock;
27585 unsigned int minor;
27586diff -urNp linux-2.6.39.1/drivers/block/drbd/drbd_main.c linux-2.6.39.1/drivers/block/drbd/drbd_main.c
27587--- linux-2.6.39.1/drivers/block/drbd/drbd_main.c 2011-05-19 00:06:34.000000000 -0400
27588+++ linux-2.6.39.1/drivers/block/drbd/drbd_main.c 2011-05-22 19:36:31.000000000 -0400
27589@@ -2387,7 +2387,7 @@ static int _drbd_send_ack(struct drbd_co
27590 p.sector = sector;
27591 p.block_id = block_id;
27592 p.blksize = blksize;
27593- p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
27594+ p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
27595
27596 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
27597 return false;
27598@@ -2686,7 +2686,7 @@ int drbd_send_dblock(struct drbd_conf *m
27599 p.sector = cpu_to_be64(req->sector);
27600 p.block_id = (unsigned long)req;
27601 p.seq_num = cpu_to_be32(req->seq_num =
27602- atomic_add_return(1, &mdev->packet_seq));
27603+ atomic_add_return_unchecked(1, &mdev->packet_seq));
27604
27605 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
27606
27607@@ -2971,7 +2971,7 @@ void drbd_init_set_defaults(struct drbd_
27608 atomic_set(&mdev->unacked_cnt, 0);
27609 atomic_set(&mdev->local_cnt, 0);
27610 atomic_set(&mdev->net_cnt, 0);
27611- atomic_set(&mdev->packet_seq, 0);
27612+ atomic_set_unchecked(&mdev->packet_seq, 0);
27613 atomic_set(&mdev->pp_in_use, 0);
27614 atomic_set(&mdev->pp_in_use_by_net, 0);
27615 atomic_set(&mdev->rs_sect_in, 0);
27616@@ -3051,8 +3051,8 @@ void drbd_mdev_cleanup(struct drbd_conf
27617 mdev->receiver.t_state);
27618
27619 /* no need to lock it, I'm the only thread alive */
27620- if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
27621- dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
27622+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
27623+ dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
27624 mdev->al_writ_cnt =
27625 mdev->bm_writ_cnt =
27626 mdev->read_cnt =
27627diff -urNp linux-2.6.39.1/drivers/block/drbd/drbd_nl.c linux-2.6.39.1/drivers/block/drbd/drbd_nl.c
27628--- linux-2.6.39.1/drivers/block/drbd/drbd_nl.c 2011-05-19 00:06:34.000000000 -0400
27629+++ linux-2.6.39.1/drivers/block/drbd/drbd_nl.c 2011-05-22 19:36:31.000000000 -0400
27630@@ -2298,7 +2298,7 @@ static void drbd_connector_callback(stru
27631 module_put(THIS_MODULE);
27632 }
27633
27634-static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
27635+static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
27636
27637 static unsigned short *
27638 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
27639@@ -2369,7 +2369,7 @@ void drbd_bcast_state(struct drbd_conf *
27640 cn_reply->id.idx = CN_IDX_DRBD;
27641 cn_reply->id.val = CN_VAL_DRBD;
27642
27643- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
27644+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
27645 cn_reply->ack = 0; /* not used here. */
27646 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
27647 (int)((char *)tl - (char *)reply->tag_list);
27648@@ -2401,7 +2401,7 @@ void drbd_bcast_ev_helper(struct drbd_co
27649 cn_reply->id.idx = CN_IDX_DRBD;
27650 cn_reply->id.val = CN_VAL_DRBD;
27651
27652- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
27653+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
27654 cn_reply->ack = 0; /* not used here. */
27655 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
27656 (int)((char *)tl - (char *)reply->tag_list);
27657@@ -2479,7 +2479,7 @@ void drbd_bcast_ee(struct drbd_conf *mde
27658 cn_reply->id.idx = CN_IDX_DRBD;
27659 cn_reply->id.val = CN_VAL_DRBD;
27660
27661- cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
27662+ cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
27663 cn_reply->ack = 0; // not used here.
27664 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
27665 (int)((char*)tl - (char*)reply->tag_list);
27666@@ -2518,7 +2518,7 @@ void drbd_bcast_sync_progress(struct drb
27667 cn_reply->id.idx = CN_IDX_DRBD;
27668 cn_reply->id.val = CN_VAL_DRBD;
27669
27670- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
27671+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
27672 cn_reply->ack = 0; /* not used here. */
27673 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
27674 (int)((char *)tl - (char *)reply->tag_list);
27675diff -urNp linux-2.6.39.1/drivers/block/drbd/drbd_receiver.c linux-2.6.39.1/drivers/block/drbd/drbd_receiver.c
27676--- linux-2.6.39.1/drivers/block/drbd/drbd_receiver.c 2011-05-19 00:06:34.000000000 -0400
27677+++ linux-2.6.39.1/drivers/block/drbd/drbd_receiver.c 2011-05-22 19:36:31.000000000 -0400
27678@@ -894,7 +894,7 @@ retry:
27679 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
27680 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
27681
27682- atomic_set(&mdev->packet_seq, 0);
27683+ atomic_set_unchecked(&mdev->packet_seq, 0);
27684 mdev->peer_seq = 0;
27685
27686 drbd_thread_start(&mdev->asender);
27687@@ -990,7 +990,7 @@ static enum finish_epoch drbd_may_finish
27688 do {
27689 next_epoch = NULL;
27690
27691- epoch_size = atomic_read(&epoch->epoch_size);
27692+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
27693
27694 switch (ev & ~EV_CLEANUP) {
27695 case EV_PUT:
27696@@ -1025,7 +1025,7 @@ static enum finish_epoch drbd_may_finish
27697 rv = FE_DESTROYED;
27698 } else {
27699 epoch->flags = 0;
27700- atomic_set(&epoch->epoch_size, 0);
27701+ atomic_set_unchecked(&epoch->epoch_size, 0);
27702 /* atomic_set(&epoch->active, 0); is already zero */
27703 if (rv == FE_STILL_LIVE)
27704 rv = FE_RECYCLED;
27705@@ -1196,14 +1196,14 @@ static int receive_Barrier(struct drbd_c
27706 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
27707 drbd_flush(mdev);
27708
27709- if (atomic_read(&mdev->current_epoch->epoch_size)) {
27710+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
27711 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
27712 if (epoch)
27713 break;
27714 }
27715
27716 epoch = mdev->current_epoch;
27717- wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
27718+ wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
27719
27720 D_ASSERT(atomic_read(&epoch->active) == 0);
27721 D_ASSERT(epoch->flags == 0);
27722@@ -1215,11 +1215,11 @@ static int receive_Barrier(struct drbd_c
27723 }
27724
27725 epoch->flags = 0;
27726- atomic_set(&epoch->epoch_size, 0);
27727+ atomic_set_unchecked(&epoch->epoch_size, 0);
27728 atomic_set(&epoch->active, 0);
27729
27730 spin_lock(&mdev->epoch_lock);
27731- if (atomic_read(&mdev->current_epoch->epoch_size)) {
27732+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
27733 list_add(&epoch->list, &mdev->current_epoch->list);
27734 mdev->current_epoch = epoch;
27735 mdev->epochs++;
27736@@ -1668,7 +1668,7 @@ static int receive_Data(struct drbd_conf
27737 spin_unlock(&mdev->peer_seq_lock);
27738
27739 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
27740- atomic_inc(&mdev->current_epoch->epoch_size);
27741+ atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
27742 return drbd_drain_block(mdev, data_size);
27743 }
27744
27745@@ -1694,7 +1694,7 @@ static int receive_Data(struct drbd_conf
27746
27747 spin_lock(&mdev->epoch_lock);
27748 e->epoch = mdev->current_epoch;
27749- atomic_inc(&e->epoch->epoch_size);
27750+ atomic_inc_unchecked(&e->epoch->epoch_size);
27751 atomic_inc(&e->epoch->active);
27752 spin_unlock(&mdev->epoch_lock);
27753
27754@@ -3905,7 +3905,7 @@ static void drbd_disconnect(struct drbd_
27755 D_ASSERT(list_empty(&mdev->done_ee));
27756
27757 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
27758- atomic_set(&mdev->current_epoch->epoch_size, 0);
27759+ atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
27760 D_ASSERT(list_empty(&mdev->current_epoch->list));
27761 }
27762
27763diff -urNp linux-2.6.39.1/drivers/block/nbd.c linux-2.6.39.1/drivers/block/nbd.c
27764--- linux-2.6.39.1/drivers/block/nbd.c 2011-05-19 00:06:34.000000000 -0400
27765+++ linux-2.6.39.1/drivers/block/nbd.c 2011-05-22 19:36:31.000000000 -0400
27766@@ -157,6 +157,8 @@ static int sock_xmit(struct nbd_device *
27767 struct kvec iov;
27768 sigset_t blocked, oldset;
27769
27770+ pax_track_stack();
27771+
27772 if (unlikely(!sock)) {
27773 printk(KERN_ERR "%s: Attempted %s on closed socket in sock_xmit\n",
27774 lo->disk->disk_name, (send ? "send" : "recv"));
27775@@ -571,6 +573,8 @@ static void do_nbd_request(struct reques
27776 static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *lo,
27777 unsigned int cmd, unsigned long arg)
27778 {
27779+ pax_track_stack();
27780+
27781 switch (cmd) {
27782 case NBD_DISCONNECT: {
27783 struct request sreq;
27784diff -urNp linux-2.6.39.1/drivers/block/smart1,2.h linux-2.6.39.1/drivers/block/smart1,2.h
27785--- linux-2.6.39.1/drivers/block/smart1,2.h 2011-05-19 00:06:34.000000000 -0400
27786+++ linux-2.6.39.1/drivers/block/smart1,2.h 2011-05-22 19:36:31.000000000 -0400
27787@@ -107,7 +107,7 @@ static unsigned long smart4_intr_pending
27788 return 0 ;
27789 }
27790
27791-static struct access_method smart4_access = {
27792+static const struct access_method smart4_access = {
27793 smart4_submit_command,
27794 smart4_intr_mask,
27795 smart4_fifo_full,
27796@@ -143,7 +143,7 @@ static unsigned long smart2_intr_pending
27797 return readl(h->vaddr + INTR_PENDING);
27798 }
27799
27800-static struct access_method smart2_access = {
27801+static const struct access_method smart2_access = {
27802 smart2_submit_command,
27803 smart2_intr_mask,
27804 smart2_fifo_full,
27805@@ -179,7 +179,7 @@ static unsigned long smart2e_intr_pendin
27806 return inl(h->io_mem_addr + INTR_PENDING);
27807 }
27808
27809-static struct access_method smart2e_access = {
27810+static const struct access_method smart2e_access = {
27811 smart2e_submit_command,
27812 smart2e_intr_mask,
27813 smart2e_fifo_full,
27814@@ -269,7 +269,7 @@ static unsigned long smart1_intr_pending
27815 return chan;
27816 }
27817
27818-static struct access_method smart1_access = {
27819+static const struct access_method smart1_access = {
27820 smart1_submit_command,
27821 smart1_intr_mask,
27822 smart1_fifo_full,
27823diff -urNp linux-2.6.39.1/drivers/block/xsysace.c linux-2.6.39.1/drivers/block/xsysace.c
27824--- linux-2.6.39.1/drivers/block/xsysace.c 2011-05-19 00:06:34.000000000 -0400
27825+++ linux-2.6.39.1/drivers/block/xsysace.c 2011-05-22 19:36:31.000000000 -0400
27826@@ -262,7 +262,7 @@ static void ace_dataout_8(struct ace_dev
27827 ace->data_ptr = src;
27828 }
27829
27830-static struct ace_reg_ops ace_reg_8_ops = {
27831+static const struct ace_reg_ops ace_reg_8_ops = {
27832 .in = ace_in_8,
27833 .out = ace_out_8,
27834 .datain = ace_datain_8,
27835@@ -327,14 +327,14 @@ static void ace_dataout_le16(struct ace_
27836 ace->data_ptr = src;
27837 }
27838
27839-static struct ace_reg_ops ace_reg_be16_ops = {
27840+static const struct ace_reg_ops ace_reg_be16_ops = {
27841 .in = ace_in_be16,
27842 .out = ace_out_be16,
27843 .datain = ace_datain_be16,
27844 .dataout = ace_dataout_be16,
27845 };
27846
27847-static struct ace_reg_ops ace_reg_le16_ops = {
27848+static const struct ace_reg_ops ace_reg_le16_ops = {
27849 .in = ace_in_le16,
27850 .out = ace_out_le16,
27851 .datain = ace_datain_le16,
27852diff -urNp linux-2.6.39.1/drivers/char/agp/frontend.c linux-2.6.39.1/drivers/char/agp/frontend.c
27853--- linux-2.6.39.1/drivers/char/agp/frontend.c 2011-05-19 00:06:34.000000000 -0400
27854+++ linux-2.6.39.1/drivers/char/agp/frontend.c 2011-05-22 19:36:31.000000000 -0400
27855@@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct ag
27856 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
27857 return -EFAULT;
27858
27859- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
27860+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
27861 return -EFAULT;
27862
27863 client = agp_find_client_by_pid(reserve.pid);
27864diff -urNp linux-2.6.39.1/drivers/char/briq_panel.c linux-2.6.39.1/drivers/char/briq_panel.c
27865--- linux-2.6.39.1/drivers/char/briq_panel.c 2011-05-19 00:06:34.000000000 -0400
27866+++ linux-2.6.39.1/drivers/char/briq_panel.c 2011-05-22 19:41:32.000000000 -0400
27867@@ -9,6 +9,7 @@
27868 #include <linux/types.h>
27869 #include <linux/errno.h>
27870 #include <linux/tty.h>
27871+#include <linux/mutex.h>
27872 #include <linux/timer.h>
27873 #include <linux/kernel.h>
27874 #include <linux/wait.h>
27875@@ -34,6 +35,7 @@ static int vfd_is_open;
27876 static unsigned char vfd[40];
27877 static int vfd_cursor;
27878 static unsigned char ledpb, led;
27879+static DEFINE_MUTEX(vfd_mutex);
27880
27881 static void update_vfd(void)
27882 {
27883@@ -140,12 +142,15 @@ static ssize_t briq_panel_write(struct f
27884 if (!vfd_is_open)
27885 return -EBUSY;
27886
27887+ mutex_lock(&vfd_mutex);
27888 for (;;) {
27889 char c;
27890 if (!indx)
27891 break;
27892- if (get_user(c, buf))
27893+ if (get_user(c, buf)) {
27894+ mutex_unlock(&vfd_mutex);
27895 return -EFAULT;
27896+ }
27897 if (esc) {
27898 set_led(c);
27899 esc = 0;
27900@@ -175,6 +180,7 @@ static ssize_t briq_panel_write(struct f
27901 buf++;
27902 }
27903 update_vfd();
27904+ mutex_unlock(&vfd_mutex);
27905
27906 return len;
27907 }
27908diff -urNp linux-2.6.39.1/drivers/char/genrtc.c linux-2.6.39.1/drivers/char/genrtc.c
27909--- linux-2.6.39.1/drivers/char/genrtc.c 2011-05-19 00:06:34.000000000 -0400
27910+++ linux-2.6.39.1/drivers/char/genrtc.c 2011-05-22 19:41:32.000000000 -0400
27911@@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *fi
27912 switch (cmd) {
27913
27914 case RTC_PLL_GET:
27915+ memset(&pll, 0, sizeof(pll));
27916 if (get_rtc_pll(&pll))
27917 return -EINVAL;
27918 else
27919diff -urNp linux-2.6.39.1/drivers/char/hpet.c linux-2.6.39.1/drivers/char/hpet.c
27920--- linux-2.6.39.1/drivers/char/hpet.c 2011-05-19 00:06:34.000000000 -0400
27921+++ linux-2.6.39.1/drivers/char/hpet.c 2011-05-22 19:36:31.000000000 -0400
27922@@ -553,7 +553,7 @@ static inline unsigned long hpet_time_di
27923 }
27924
27925 static int
27926-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
27927+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
27928 struct hpet_info *info)
27929 {
27930 struct hpet_timer __iomem *timer;
27931diff -urNp linux-2.6.39.1/drivers/char/ipmi/ipmi_devintf.c linux-2.6.39.1/drivers/char/ipmi/ipmi_devintf.c
27932--- linux-2.6.39.1/drivers/char/ipmi/ipmi_devintf.c 2011-05-19 00:06:34.000000000 -0400
27933+++ linux-2.6.39.1/drivers/char/ipmi/ipmi_devintf.c 2011-05-22 19:36:31.000000000 -0400
27934@@ -109,8 +109,7 @@ static int ipmi_fasync(int fd, struct fi
27935 return (result);
27936 }
27937
27938-static struct ipmi_user_hndl ipmi_hndlrs =
27939-{
27940+static const struct ipmi_user_hndl ipmi_hndlrs = {
27941 .ipmi_recv_hndl = file_receive_handler,
27942 };
27943
27944diff -urNp linux-2.6.39.1/drivers/char/ipmi/ipmi_msghandler.c linux-2.6.39.1/drivers/char/ipmi/ipmi_msghandler.c
27945--- linux-2.6.39.1/drivers/char/ipmi/ipmi_msghandler.c 2011-05-19 00:06:34.000000000 -0400
27946+++ linux-2.6.39.1/drivers/char/ipmi/ipmi_msghandler.c 2011-05-22 19:36:31.000000000 -0400
27947@@ -82,7 +82,7 @@ struct ipmi_user {
27948 struct kref refcount;
27949
27950 /* The upper layer that handles receive messages. */
27951- struct ipmi_user_hndl *handler;
27952+ const struct ipmi_user_hndl *handler;
27953 void *handler_data;
27954
27955 /* The interface this user is bound to. */
27956@@ -414,7 +414,7 @@ struct ipmi_smi {
27957 struct proc_dir_entry *proc_dir;
27958 char proc_dir_name[10];
27959
27960- atomic_t stats[IPMI_NUM_STATS];
27961+ atomic_unchecked_t stats[IPMI_NUM_STATS];
27962
27963 /*
27964 * run_to_completion duplicate of smb_info, smi_info
27965@@ -447,9 +447,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
27966
27967
27968 #define ipmi_inc_stat(intf, stat) \
27969- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
27970+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
27971 #define ipmi_get_stat(intf, stat) \
27972- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
27973+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
27974
27975 static int is_lan_addr(struct ipmi_addr *addr)
27976 {
27977@@ -875,7 +875,7 @@ static int intf_err_seq(ipmi_smi_t int
27978
27979
27980 int ipmi_create_user(unsigned int if_num,
27981- struct ipmi_user_hndl *handler,
27982+ const struct ipmi_user_hndl *handler,
27983 void *handler_data,
27984 ipmi_user_t *user)
27985 {
27986@@ -2844,7 +2844,7 @@ int ipmi_register_smi(struct ipmi_smi_ha
27987 INIT_LIST_HEAD(&intf->cmd_rcvrs);
27988 init_waitqueue_head(&intf->waitq);
27989 for (i = 0; i < IPMI_NUM_STATS; i++)
27990- atomic_set(&intf->stats[i], 0);
27991+ atomic_set_unchecked(&intf->stats[i], 0);
27992
27993 intf->proc_dir = NULL;
27994
27995@@ -4196,6 +4196,8 @@ static void send_panic_events(char *str)
27996 struct ipmi_smi_msg smi_msg;
27997 struct ipmi_recv_msg recv_msg;
27998
27999+ pax_track_stack();
28000+
28001 si = (struct ipmi_system_interface_addr *) &addr;
28002 si->addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
28003 si->channel = IPMI_BMC_CHANNEL;
28004diff -urNp linux-2.6.39.1/drivers/char/ipmi/ipmi_poweroff.c linux-2.6.39.1/drivers/char/ipmi/ipmi_poweroff.c
28005--- linux-2.6.39.1/drivers/char/ipmi/ipmi_poweroff.c 2011-05-19 00:06:34.000000000 -0400
28006+++ linux-2.6.39.1/drivers/char/ipmi/ipmi_poweroff.c 2011-05-22 19:36:31.000000000 -0400
28007@@ -133,7 +133,7 @@ static void receive_handler(struct ipmi_
28008 complete(comp);
28009 }
28010
28011-static struct ipmi_user_hndl ipmi_poweroff_handler = {
28012+static const struct ipmi_user_hndl ipmi_poweroff_handler = {
28013 .ipmi_recv_hndl = receive_handler
28014 };
28015
28016diff -urNp linux-2.6.39.1/drivers/char/ipmi/ipmi_si_intf.c linux-2.6.39.1/drivers/char/ipmi/ipmi_si_intf.c
28017--- linux-2.6.39.1/drivers/char/ipmi/ipmi_si_intf.c 2011-05-19 00:06:34.000000000 -0400
28018+++ linux-2.6.39.1/drivers/char/ipmi/ipmi_si_intf.c 2011-05-22 19:36:31.000000000 -0400
28019@@ -276,7 +276,7 @@ struct smi_info {
28020 unsigned char slave_addr;
28021
28022 /* Counters and things for the proc filesystem. */
28023- atomic_t stats[SI_NUM_STATS];
28024+ atomic_unchecked_t stats[SI_NUM_STATS];
28025
28026 struct task_struct *thread;
28027
28028@@ -285,9 +285,9 @@ struct smi_info {
28029 };
28030
28031 #define smi_inc_stat(smi, stat) \
28032- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
28033+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
28034 #define smi_get_stat(smi, stat) \
28035- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
28036+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
28037
28038 #define SI_MAX_PARMS 4
28039
28040@@ -3198,7 +3198,7 @@ static int try_smi_init(struct smi_info
28041 atomic_set(&new_smi->req_events, 0);
28042 new_smi->run_to_completion = 0;
28043 for (i = 0; i < SI_NUM_STATS; i++)
28044- atomic_set(&new_smi->stats[i], 0);
28045+ atomic_set_unchecked(&new_smi->stats[i], 0);
28046
28047 new_smi->interrupt_disabled = 1;
28048 atomic_set(&new_smi->stop_operation, 0);
28049diff -urNp linux-2.6.39.1/drivers/char/ipmi/ipmi_watchdog.c linux-2.6.39.1/drivers/char/ipmi/ipmi_watchdog.c
28050--- linux-2.6.39.1/drivers/char/ipmi/ipmi_watchdog.c 2011-05-19 00:06:34.000000000 -0400
28051+++ linux-2.6.39.1/drivers/char/ipmi/ipmi_watchdog.c 2011-05-22 19:36:31.000000000 -0400
28052@@ -216,7 +216,7 @@ static int set_param_timeout(const char
28053 return rv;
28054 }
28055
28056-static struct kernel_param_ops param_ops_timeout = {
28057+static const struct kernel_param_ops param_ops_timeout = {
28058 .set = set_param_timeout,
28059 .get = param_get_int,
28060 };
28061@@ -278,14 +278,14 @@ static int set_param_wdog_ifnum(const ch
28062 return 0;
28063 }
28064
28065-static struct kernel_param_ops param_ops_wdog_ifnum = {
28066+static const struct kernel_param_ops param_ops_wdog_ifnum = {
28067 .set = set_param_wdog_ifnum,
28068 .get = param_get_int,
28069 };
28070
28071 #define param_check_wdog_ifnum param_check_int
28072
28073-static struct kernel_param_ops param_ops_str = {
28074+static const struct kernel_param_ops param_ops_str = {
28075 .set = set_param_str,
28076 .get = get_param_str,
28077 };
28078@@ -953,7 +953,7 @@ static void ipmi_wdog_pretimeout_handler
28079 pretimeout_since_last_heartbeat = 1;
28080 }
28081
28082-static struct ipmi_user_hndl ipmi_hndlrs = {
28083+static const struct ipmi_user_hndl ipmi_hndlrs = {
28084 .ipmi_recv_hndl = ipmi_wdog_msg_handler,
28085 .ipmi_watchdog_pretimeout = ipmi_wdog_pretimeout_handler
28086 };
28087diff -urNp linux-2.6.39.1/drivers/char/Kconfig linux-2.6.39.1/drivers/char/Kconfig
28088--- linux-2.6.39.1/drivers/char/Kconfig 2011-05-19 00:06:34.000000000 -0400
28089+++ linux-2.6.39.1/drivers/char/Kconfig 2011-05-22 19:41:37.000000000 -0400
28090@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
28091
28092 config DEVKMEM
28093 bool "/dev/kmem virtual device support"
28094- default y
28095+ default n
28096+ depends on !GRKERNSEC_KMEM
28097 help
28098 Say Y here if you want to support the /dev/kmem device. The
28099 /dev/kmem device is rarely used, but can be used for certain
28100@@ -596,6 +597,7 @@ config DEVPORT
28101 bool
28102 depends on !M68K
28103 depends on ISA || PCI
28104+ depends on !GRKERNSEC_KMEM
28105 default y
28106
28107 source "drivers/s390/char/Kconfig"
28108diff -urNp linux-2.6.39.1/drivers/char/mem.c linux-2.6.39.1/drivers/char/mem.c
28109--- linux-2.6.39.1/drivers/char/mem.c 2011-05-19 00:06:34.000000000 -0400
28110+++ linux-2.6.39.1/drivers/char/mem.c 2011-05-22 19:41:37.000000000 -0400
28111@@ -18,6 +18,7 @@
28112 #include <linux/raw.h>
28113 #include <linux/tty.h>
28114 #include <linux/capability.h>
28115+#include <linux/security.h>
28116 #include <linux/ptrace.h>
28117 #include <linux/device.h>
28118 #include <linux/highmem.h>
28119@@ -34,6 +35,10 @@
28120 # include <linux/efi.h>
28121 #endif
28122
28123+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
28124+extern struct file_operations grsec_fops;
28125+#endif
28126+
28127 static inline unsigned long size_inside_page(unsigned long start,
28128 unsigned long size)
28129 {
28130@@ -65,9 +70,13 @@ static inline int range_is_allowed(unsig
28131
28132 while (cursor < to) {
28133 if (!devmem_is_allowed(pfn)) {
28134+#ifdef CONFIG_GRKERNSEC_KMEM
28135+ gr_handle_mem_readwrite(from, to);
28136+#else
28137 printk(KERN_INFO
28138 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
28139 current->comm, from, to);
28140+#endif
28141 return 0;
28142 }
28143 cursor += PAGE_SIZE;
28144@@ -75,6 +84,11 @@ static inline int range_is_allowed(unsig
28145 }
28146 return 1;
28147 }
28148+#elif defined(CONFIG_GRKERNSEC_KMEM)
28149+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
28150+{
28151+ return 0;
28152+}
28153 #else
28154 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
28155 {
28156@@ -117,6 +131,7 @@ static ssize_t read_mem(struct file *fil
28157
28158 while (count > 0) {
28159 unsigned long remaining;
28160+ char *temp;
28161
28162 sz = size_inside_page(p, count);
28163
28164@@ -132,7 +147,23 @@ static ssize_t read_mem(struct file *fil
28165 if (!ptr)
28166 return -EFAULT;
28167
28168- remaining = copy_to_user(buf, ptr, sz);
28169+#ifdef CONFIG_PAX_USERCOPY
28170+ temp = kmalloc(sz, GFP_KERNEL);
28171+ if (!temp) {
28172+ unxlate_dev_mem_ptr(p, ptr);
28173+ return -ENOMEM;
28174+ }
28175+ memcpy(temp, ptr, sz);
28176+#else
28177+ temp = ptr;
28178+#endif
28179+
28180+ remaining = copy_to_user(buf, temp, sz);
28181+
28182+#ifdef CONFIG_PAX_USERCOPY
28183+ kfree(temp);
28184+#endif
28185+
28186 unxlate_dev_mem_ptr(p, ptr);
28187 if (remaining)
28188 return -EFAULT;
28189@@ -395,9 +426,8 @@ static ssize_t read_kmem(struct file *fi
28190 size_t count, loff_t *ppos)
28191 {
28192 unsigned long p = *ppos;
28193- ssize_t low_count, read, sz;
28194+ ssize_t low_count, read, sz, err = 0;
28195 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
28196- int err = 0;
28197
28198 read = 0;
28199 if (p < (unsigned long) high_memory) {
28200@@ -419,6 +449,8 @@ static ssize_t read_kmem(struct file *fi
28201 }
28202 #endif
28203 while (low_count > 0) {
28204+ char *temp;
28205+
28206 sz = size_inside_page(p, low_count);
28207
28208 /*
28209@@ -428,7 +460,22 @@ static ssize_t read_kmem(struct file *fi
28210 */
28211 kbuf = xlate_dev_kmem_ptr((char *)p);
28212
28213- if (copy_to_user(buf, kbuf, sz))
28214+#ifdef CONFIG_PAX_USERCOPY
28215+ temp = kmalloc(sz, GFP_KERNEL);
28216+ if (!temp)
28217+ return -ENOMEM;
28218+ memcpy(temp, kbuf, sz);
28219+#else
28220+ temp = kbuf;
28221+#endif
28222+
28223+ err = copy_to_user(buf, temp, sz);
28224+
28225+#ifdef CONFIG_PAX_USERCOPY
28226+ kfree(temp);
28227+#endif
28228+
28229+ if (err)
28230 return -EFAULT;
28231 buf += sz;
28232 p += sz;
28233@@ -854,6 +901,9 @@ static const struct memdev {
28234 #ifdef CONFIG_CRASH_DUMP
28235 [12] = { "oldmem", 0, &oldmem_fops, NULL },
28236 #endif
28237+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
28238+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
28239+#endif
28240 };
28241
28242 static int memory_open(struct inode *inode, struct file *filp)
28243diff -urNp linux-2.6.39.1/drivers/char/mmtimer.c linux-2.6.39.1/drivers/char/mmtimer.c
28244--- linux-2.6.39.1/drivers/char/mmtimer.c 2011-05-19 00:06:34.000000000 -0400
28245+++ linux-2.6.39.1/drivers/char/mmtimer.c 2011-05-22 19:36:31.000000000 -0400
28246@@ -53,7 +53,7 @@ MODULE_LICENSE("GPL");
28247
28248 #define RTC_BITS 55 /* 55 bits for this implementation */
28249
28250-static struct k_clock sgi_clock;
28251+static const struct k_clock sgi_clock;
28252
28253 extern unsigned long sn_rtc_cycles_per_second;
28254
28255@@ -772,7 +772,7 @@ static int sgi_clock_getres(const clocki
28256 return 0;
28257 }
28258
28259-static struct k_clock sgi_clock = {
28260+static const struct k_clock sgi_clock = {
28261 .clock_set = sgi_clock_set,
28262 .clock_get = sgi_clock_get,
28263 .clock_getres = sgi_clock_getres,
28264diff -urNp linux-2.6.39.1/drivers/char/nvram.c linux-2.6.39.1/drivers/char/nvram.c
28265--- linux-2.6.39.1/drivers/char/nvram.c 2011-05-19 00:06:34.000000000 -0400
28266+++ linux-2.6.39.1/drivers/char/nvram.c 2011-05-22 19:36:31.000000000 -0400
28267@@ -246,7 +246,7 @@ static ssize_t nvram_read(struct file *f
28268
28269 spin_unlock_irq(&rtc_lock);
28270
28271- if (copy_to_user(buf, contents, tmp - contents))
28272+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
28273 return -EFAULT;
28274
28275 *ppos = i;
28276diff -urNp linux-2.6.39.1/drivers/char/random.c linux-2.6.39.1/drivers/char/random.c
28277--- linux-2.6.39.1/drivers/char/random.c 2011-05-19 00:06:34.000000000 -0400
28278+++ linux-2.6.39.1/drivers/char/random.c 2011-05-22 19:41:37.000000000 -0400
28279@@ -261,8 +261,13 @@
28280 /*
28281 * Configuration information
28282 */
28283+#ifdef CONFIG_GRKERNSEC_RANDNET
28284+#define INPUT_POOL_WORDS 512
28285+#define OUTPUT_POOL_WORDS 128
28286+#else
28287 #define INPUT_POOL_WORDS 128
28288 #define OUTPUT_POOL_WORDS 32
28289+#endif
28290 #define SEC_XFER_SIZE 512
28291 #define EXTRACT_SIZE 10
28292
28293@@ -300,10 +305,17 @@ static struct poolinfo {
28294 int poolwords;
28295 int tap1, tap2, tap3, tap4, tap5;
28296 } poolinfo_table[] = {
28297+#ifdef CONFIG_GRKERNSEC_RANDNET
28298+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
28299+ { 512, 411, 308, 208, 104, 1 },
28300+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
28301+ { 128, 103, 76, 51, 25, 1 },
28302+#else
28303 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
28304 { 128, 103, 76, 51, 25, 1 },
28305 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
28306 { 32, 26, 20, 14, 7, 1 },
28307+#endif
28308 #if 0
28309 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
28310 { 2048, 1638, 1231, 819, 411, 1 },
28311@@ -909,7 +921,7 @@ static ssize_t extract_entropy_user(stru
28312
28313 extract_buf(r, tmp);
28314 i = min_t(int, nbytes, EXTRACT_SIZE);
28315- if (copy_to_user(buf, tmp, i)) {
28316+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
28317 ret = -EFAULT;
28318 break;
28319 }
28320@@ -1214,7 +1226,7 @@ EXPORT_SYMBOL(generate_random_uuid);
28321 #include <linux/sysctl.h>
28322
28323 static int min_read_thresh = 8, min_write_thresh;
28324-static int max_read_thresh = INPUT_POOL_WORDS * 32;
28325+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
28326 static int max_write_thresh = INPUT_POOL_WORDS * 32;
28327 static char sysctl_bootid[16];
28328
28329diff -urNp linux-2.6.39.1/drivers/char/sonypi.c linux-2.6.39.1/drivers/char/sonypi.c
28330--- linux-2.6.39.1/drivers/char/sonypi.c 2011-05-19 00:06:34.000000000 -0400
28331+++ linux-2.6.39.1/drivers/char/sonypi.c 2011-05-22 19:36:31.000000000 -0400
28332@@ -55,6 +55,7 @@
28333 #include <asm/uaccess.h>
28334 #include <asm/io.h>
28335 #include <asm/system.h>
28336+#include <asm/local.h>
28337
28338 #include <linux/sonypi.h>
28339
28340@@ -491,7 +492,7 @@ static struct sonypi_device {
28341 spinlock_t fifo_lock;
28342 wait_queue_head_t fifo_proc_list;
28343 struct fasync_struct *fifo_async;
28344- int open_count;
28345+ local_t open_count;
28346 int model;
28347 struct input_dev *input_jog_dev;
28348 struct input_dev *input_key_dev;
28349@@ -898,7 +899,7 @@ static int sonypi_misc_fasync(int fd, st
28350 static int sonypi_misc_release(struct inode *inode, struct file *file)
28351 {
28352 mutex_lock(&sonypi_device.lock);
28353- sonypi_device.open_count--;
28354+ local_dec(&sonypi_device.open_count);
28355 mutex_unlock(&sonypi_device.lock);
28356 return 0;
28357 }
28358@@ -907,9 +908,9 @@ static int sonypi_misc_open(struct inode
28359 {
28360 mutex_lock(&sonypi_device.lock);
28361 /* Flush input queue on first open */
28362- if (!sonypi_device.open_count)
28363+ if (!local_read(&sonypi_device.open_count))
28364 kfifo_reset(&sonypi_device.fifo);
28365- sonypi_device.open_count++;
28366+ local_inc(&sonypi_device.open_count);
28367 mutex_unlock(&sonypi_device.lock);
28368
28369 return 0;
28370diff -urNp linux-2.6.39.1/drivers/char/tpm/tpm_bios.c linux-2.6.39.1/drivers/char/tpm/tpm_bios.c
28371--- linux-2.6.39.1/drivers/char/tpm/tpm_bios.c 2011-05-19 00:06:34.000000000 -0400
28372+++ linux-2.6.39.1/drivers/char/tpm/tpm_bios.c 2011-05-22 19:36:31.000000000 -0400
28373@@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start
28374 event = addr;
28375
28376 if ((event->event_type == 0 && event->event_size == 0) ||
28377- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
28378+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
28379 return NULL;
28380
28381 return addr;
28382@@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(
28383 return NULL;
28384
28385 if ((event->event_type == 0 && event->event_size == 0) ||
28386- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
28387+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
28388 return NULL;
28389
28390 (*pos)++;
28391@@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_
28392 int i;
28393
28394 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
28395- seq_putc(m, data[i]);
28396+ if (!seq_putc(m, data[i]))
28397+ return -EFAULT;
28398
28399 return 0;
28400 }
28401@@ -410,6 +411,11 @@ static int read_log(struct tpm_bios_log
28402 log->bios_event_log_end = log->bios_event_log + len;
28403
28404 virt = acpi_os_map_memory(start, len);
28405+ if (!virt) {
28406+ kfree(log->bios_event_log);
28407+ log->bios_event_log = NULL;
28408+ return -EFAULT;
28409+ }
28410
28411 memcpy(log->bios_event_log, virt, len);
28412
28413diff -urNp linux-2.6.39.1/drivers/char/tpm/tpm.c linux-2.6.39.1/drivers/char/tpm/tpm.c
28414--- linux-2.6.39.1/drivers/char/tpm/tpm.c 2011-05-19 00:06:34.000000000 -0400
28415+++ linux-2.6.39.1/drivers/char/tpm/tpm.c 2011-05-22 19:36:31.000000000 -0400
28416@@ -411,7 +411,7 @@ static ssize_t tpm_transmit(struct tpm_c
28417 chip->vendor.req_complete_val)
28418 goto out_recv;
28419
28420- if ((status == chip->vendor.req_canceled)) {
28421+ if (status == chip->vendor.req_canceled) {
28422 dev_err(chip->dev, "Operation Canceled\n");
28423 rc = -ECANCELED;
28424 goto out;
28425@@ -844,6 +844,8 @@ ssize_t tpm_show_pubek(struct device *de
28426
28427 struct tpm_chip *chip = dev_get_drvdata(dev);
28428
28429+ pax_track_stack();
28430+
28431 tpm_cmd.header.in = tpm_readpubek_header;
28432 err = transmit_cmd(chip, &tpm_cmd, READ_PUBEK_RESULT_SIZE,
28433 "attempting to read the PUBEK");
28434diff -urNp linux-2.6.39.1/drivers/char/ttyprintk.c linux-2.6.39.1/drivers/char/ttyprintk.c
28435--- linux-2.6.39.1/drivers/char/ttyprintk.c 2011-05-19 00:06:34.000000000 -0400
28436+++ linux-2.6.39.1/drivers/char/ttyprintk.c 2011-05-22 19:36:31.000000000 -0400
28437@@ -170,7 +170,7 @@ static const struct tty_operations ttypr
28438 .ioctl = tpk_ioctl,
28439 };
28440
28441-struct tty_port_operations null_ops = { };
28442+const struct tty_port_operations null_ops = { };
28443
28444 static struct tty_driver *ttyprintk_driver;
28445
28446diff -urNp linux-2.6.39.1/drivers/char/xilinx_hwicap/xilinx_hwicap.c linux-2.6.39.1/drivers/char/xilinx_hwicap/xilinx_hwicap.c
28447--- linux-2.6.39.1/drivers/char/xilinx_hwicap/xilinx_hwicap.c 2011-05-19 00:06:34.000000000 -0400
28448+++ linux-2.6.39.1/drivers/char/xilinx_hwicap/xilinx_hwicap.c 2011-05-22 19:36:31.000000000 -0400
28449@@ -678,14 +678,14 @@ static int __devinit hwicap_setup(struct
28450 return retval;
28451 }
28452
28453-static struct hwicap_driver_config buffer_icap_config = {
28454+static const struct hwicap_driver_config buffer_icap_config = {
28455 .get_configuration = buffer_icap_get_configuration,
28456 .set_configuration = buffer_icap_set_configuration,
28457 .get_status = buffer_icap_get_status,
28458 .reset = buffer_icap_reset,
28459 };
28460
28461-static struct hwicap_driver_config fifo_icap_config = {
28462+static const struct hwicap_driver_config fifo_icap_config = {
28463 .get_configuration = fifo_icap_get_configuration,
28464 .set_configuration = fifo_icap_set_configuration,
28465 .get_status = fifo_icap_get_status,
28466diff -urNp linux-2.6.39.1/drivers/crypto/hifn_795x.c linux-2.6.39.1/drivers/crypto/hifn_795x.c
28467--- linux-2.6.39.1/drivers/crypto/hifn_795x.c 2011-05-19 00:06:34.000000000 -0400
28468+++ linux-2.6.39.1/drivers/crypto/hifn_795x.c 2011-05-22 19:36:31.000000000 -0400
28469@@ -1655,6 +1655,8 @@ static int hifn_test(struct hifn_device
28470 0xCA, 0x34, 0x2B, 0x2E};
28471 struct scatterlist sg;
28472
28473+ pax_track_stack();
28474+
28475 memset(src, 0, sizeof(src));
28476 memset(ctx.key, 0, sizeof(ctx.key));
28477
28478diff -urNp linux-2.6.39.1/drivers/crypto/padlock-aes.c linux-2.6.39.1/drivers/crypto/padlock-aes.c
28479--- linux-2.6.39.1/drivers/crypto/padlock-aes.c 2011-05-19 00:06:34.000000000 -0400
28480+++ linux-2.6.39.1/drivers/crypto/padlock-aes.c 2011-05-22 19:36:31.000000000 -0400
28481@@ -109,6 +109,8 @@ static int aes_set_key(struct crypto_tfm
28482 struct crypto_aes_ctx gen_aes;
28483 int cpu;
28484
28485+ pax_track_stack();
28486+
28487 if (key_len % 8) {
28488 *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
28489 return -EINVAL;
28490diff -urNp linux-2.6.39.1/drivers/dca/dca-core.c linux-2.6.39.1/drivers/dca/dca-core.c
28491--- linux-2.6.39.1/drivers/dca/dca-core.c 2011-05-19 00:06:34.000000000 -0400
28492+++ linux-2.6.39.1/drivers/dca/dca-core.c 2011-05-22 19:36:31.000000000 -0400
28493@@ -325,7 +325,7 @@ EXPORT_SYMBOL_GPL(dca_get_tag);
28494 * @ops - pointer to struct of dca operation function pointers
28495 * @priv_size - size of extra mem to be added for provider's needs
28496 */
28497-struct dca_provider *alloc_dca_provider(struct dca_ops *ops, int priv_size)
28498+struct dca_provider *alloc_dca_provider(const struct dca_ops *ops, int priv_size)
28499 {
28500 struct dca_provider *dca;
28501 int alloc_size;
28502diff -urNp linux-2.6.39.1/drivers/dma/ioat/dca.c linux-2.6.39.1/drivers/dma/ioat/dca.c
28503--- linux-2.6.39.1/drivers/dma/ioat/dca.c 2011-05-19 00:06:34.000000000 -0400
28504+++ linux-2.6.39.1/drivers/dma/ioat/dca.c 2011-05-22 19:36:31.000000000 -0400
28505@@ -234,7 +234,7 @@ static int ioat_dca_dev_managed(struct d
28506 return 0;
28507 }
28508
28509-static struct dca_ops ioat_dca_ops = {
28510+static const struct dca_ops ioat_dca_ops = {
28511 .add_requester = ioat_dca_add_requester,
28512 .remove_requester = ioat_dca_remove_requester,
28513 .get_tag = ioat_dca_get_tag,
28514@@ -384,7 +384,7 @@ static u8 ioat2_dca_get_tag(struct dca_p
28515 return tag;
28516 }
28517
28518-static struct dca_ops ioat2_dca_ops = {
28519+static const struct dca_ops ioat2_dca_ops = {
28520 .add_requester = ioat2_dca_add_requester,
28521 .remove_requester = ioat2_dca_remove_requester,
28522 .get_tag = ioat2_dca_get_tag,
28523@@ -579,7 +579,7 @@ static u8 ioat3_dca_get_tag(struct dca_p
28524 return tag;
28525 }
28526
28527-static struct dca_ops ioat3_dca_ops = {
28528+static const struct dca_ops ioat3_dca_ops = {
28529 .add_requester = ioat3_dca_add_requester,
28530 .remove_requester = ioat3_dca_remove_requester,
28531 .get_tag = ioat3_dca_get_tag,
28532diff -urNp linux-2.6.39.1/drivers/edac/amd64_edac.h linux-2.6.39.1/drivers/edac/amd64_edac.h
28533--- linux-2.6.39.1/drivers/edac/amd64_edac.h 2011-05-19 00:06:34.000000000 -0400
28534+++ linux-2.6.39.1/drivers/edac/amd64_edac.h 2011-05-22 19:36:31.000000000 -0400
28535@@ -333,7 +333,7 @@ struct chip_select {
28536 };
28537
28538 struct amd64_pvt {
28539- struct low_ops *ops;
28540+ const struct low_ops *ops;
28541
28542 /* pci_device handles which we utilize */
28543 struct pci_dev *F1, *F2, *F3;
28544@@ -443,7 +443,7 @@ struct low_ops {
28545 struct amd64_family_type {
28546 const char *ctl_name;
28547 u16 f1_id, f3_id;
28548- struct low_ops ops;
28549+ const struct low_ops ops;
28550 };
28551
28552 int __amd64_write_pci_cfg_dword(struct pci_dev *pdev, int offset,
28553diff -urNp linux-2.6.39.1/drivers/edac/edac_mc_sysfs.c linux-2.6.39.1/drivers/edac/edac_mc_sysfs.c
28554--- linux-2.6.39.1/drivers/edac/edac_mc_sysfs.c 2011-05-19 00:06:34.000000000 -0400
28555+++ linux-2.6.39.1/drivers/edac/edac_mc_sysfs.c 2011-05-22 19:36:31.000000000 -0400
28556@@ -760,7 +760,7 @@ static void edac_inst_grp_release(struct
28557 }
28558
28559 /* Intermediate show/store table */
28560-static struct sysfs_ops inst_grp_ops = {
28561+static const struct sysfs_ops inst_grp_ops = {
28562 .show = inst_grp_show,
28563 .store = inst_grp_store
28564 };
28565diff -urNp linux-2.6.39.1/drivers/edac/edac_pci_sysfs.c linux-2.6.39.1/drivers/edac/edac_pci_sysfs.c
28566--- linux-2.6.39.1/drivers/edac/edac_pci_sysfs.c 2011-05-19 00:06:34.000000000 -0400
28567+++ linux-2.6.39.1/drivers/edac/edac_pci_sysfs.c 2011-05-22 19:36:31.000000000 -0400
28568@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log
28569 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
28570 static int edac_pci_poll_msec = 1000; /* one second workq period */
28571
28572-static atomic_t pci_parity_count = ATOMIC_INIT(0);
28573-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
28574+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
28575+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
28576
28577 static struct kobject *edac_pci_top_main_kobj;
28578 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
28579@@ -582,7 +582,7 @@ static void edac_pci_dev_parity_test(str
28580 edac_printk(KERN_CRIT, EDAC_PCI,
28581 "Signaled System Error on %s\n",
28582 pci_name(dev));
28583- atomic_inc(&pci_nonparity_count);
28584+ atomic_inc_unchecked(&pci_nonparity_count);
28585 }
28586
28587 if (status & (PCI_STATUS_PARITY)) {
28588@@ -590,7 +590,7 @@ static void edac_pci_dev_parity_test(str
28589 "Master Data Parity Error on %s\n",
28590 pci_name(dev));
28591
28592- atomic_inc(&pci_parity_count);
28593+ atomic_inc_unchecked(&pci_parity_count);
28594 }
28595
28596 if (status & (PCI_STATUS_DETECTED_PARITY)) {
28597@@ -598,7 +598,7 @@ static void edac_pci_dev_parity_test(str
28598 "Detected Parity Error on %s\n",
28599 pci_name(dev));
28600
28601- atomic_inc(&pci_parity_count);
28602+ atomic_inc_unchecked(&pci_parity_count);
28603 }
28604 }
28605
28606@@ -619,7 +619,7 @@ static void edac_pci_dev_parity_test(str
28607 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
28608 "Signaled System Error on %s\n",
28609 pci_name(dev));
28610- atomic_inc(&pci_nonparity_count);
28611+ atomic_inc_unchecked(&pci_nonparity_count);
28612 }
28613
28614 if (status & (PCI_STATUS_PARITY)) {
28615@@ -627,7 +627,7 @@ static void edac_pci_dev_parity_test(str
28616 "Master Data Parity Error on "
28617 "%s\n", pci_name(dev));
28618
28619- atomic_inc(&pci_parity_count);
28620+ atomic_inc_unchecked(&pci_parity_count);
28621 }
28622
28623 if (status & (PCI_STATUS_DETECTED_PARITY)) {
28624@@ -635,7 +635,7 @@ static void edac_pci_dev_parity_test(str
28625 "Detected Parity Error on %s\n",
28626 pci_name(dev));
28627
28628- atomic_inc(&pci_parity_count);
28629+ atomic_inc_unchecked(&pci_parity_count);
28630 }
28631 }
28632 }
28633@@ -677,7 +677,7 @@ void edac_pci_do_parity_check(void)
28634 if (!check_pci_errors)
28635 return;
28636
28637- before_count = atomic_read(&pci_parity_count);
28638+ before_count = atomic_read_unchecked(&pci_parity_count);
28639
28640 /* scan all PCI devices looking for a Parity Error on devices and
28641 * bridges.
28642@@ -689,7 +689,7 @@ void edac_pci_do_parity_check(void)
28643 /* Only if operator has selected panic on PCI Error */
28644 if (edac_pci_get_panic_on_pe()) {
28645 /* If the count is different 'after' from 'before' */
28646- if (before_count != atomic_read(&pci_parity_count))
28647+ if (before_count != atomic_read_unchecked(&pci_parity_count))
28648 panic("EDAC: PCI Parity Error");
28649 }
28650 }
28651diff -urNp linux-2.6.39.1/drivers/firewire/core-cdev.c linux-2.6.39.1/drivers/firewire/core-cdev.c
28652--- linux-2.6.39.1/drivers/firewire/core-cdev.c 2011-05-19 00:06:34.000000000 -0400
28653+++ linux-2.6.39.1/drivers/firewire/core-cdev.c 2011-05-22 19:36:31.000000000 -0400
28654@@ -1312,8 +1312,7 @@ static int init_iso_resource(struct clie
28655 int ret;
28656
28657 if ((request->channels == 0 && request->bandwidth == 0) ||
28658- request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
28659- request->bandwidth < 0)
28660+ request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
28661 return -EINVAL;
28662
28663 r = kmalloc(sizeof(*r), GFP_KERNEL);
28664diff -urNp linux-2.6.39.1/drivers/firewire/core-transaction.c linux-2.6.39.1/drivers/firewire/core-transaction.c
28665--- linux-2.6.39.1/drivers/firewire/core-transaction.c 2011-05-19 00:06:34.000000000 -0400
28666+++ linux-2.6.39.1/drivers/firewire/core-transaction.c 2011-05-22 19:36:31.000000000 -0400
28667@@ -36,6 +36,7 @@
28668 #include <linux/string.h>
28669 #include <linux/timer.h>
28670 #include <linux/types.h>
28671+#include <linux/sched.h>
28672
28673 #include <asm/byteorder.h>
28674
28675@@ -420,6 +421,8 @@ int fw_run_transaction(struct fw_card *c
28676 struct transaction_callback_data d;
28677 struct fw_transaction t;
28678
28679+ pax_track_stack();
28680+
28681 init_timer_on_stack(&t.split_timeout_timer);
28682 init_completion(&d.done);
28683 d.payload = payload;
28684diff -urNp linux-2.6.39.1/drivers/firmware/dmi_scan.c linux-2.6.39.1/drivers/firmware/dmi_scan.c
28685--- linux-2.6.39.1/drivers/firmware/dmi_scan.c 2011-05-19 00:06:34.000000000 -0400
28686+++ linux-2.6.39.1/drivers/firmware/dmi_scan.c 2011-05-22 19:36:31.000000000 -0400
28687@@ -449,11 +449,6 @@ void __init dmi_scan_machine(void)
28688 }
28689 }
28690 else {
28691- /*
28692- * no iounmap() for that ioremap(); it would be a no-op, but
28693- * it's so early in setup that sucker gets confused into doing
28694- * what it shouldn't if we actually call it.
28695- */
28696 p = dmi_ioremap(0xF0000, 0x10000);
28697 if (p == NULL)
28698 goto error;
28699diff -urNp linux-2.6.39.1/drivers/gpio/vr41xx_giu.c linux-2.6.39.1/drivers/gpio/vr41xx_giu.c
28700--- linux-2.6.39.1/drivers/gpio/vr41xx_giu.c 2011-05-19 00:06:34.000000000 -0400
28701+++ linux-2.6.39.1/drivers/gpio/vr41xx_giu.c 2011-05-22 19:36:31.000000000 -0400
28702@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
28703 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
28704 maskl, pendl, maskh, pendh);
28705
28706- atomic_inc(&irq_err_count);
28707+ atomic_inc_unchecked(&irq_err_count);
28708
28709 return -EINVAL;
28710 }
28711diff -urNp linux-2.6.39.1/drivers/gpu/drm/drm_crtc_helper.c linux-2.6.39.1/drivers/gpu/drm/drm_crtc_helper.c
28712--- linux-2.6.39.1/drivers/gpu/drm/drm_crtc_helper.c 2011-05-19 00:06:34.000000000 -0400
28713+++ linux-2.6.39.1/drivers/gpu/drm/drm_crtc_helper.c 2011-05-22 19:36:31.000000000 -0400
28714@@ -276,7 +276,7 @@ static bool drm_encoder_crtc_ok(struct d
28715 struct drm_crtc *tmp;
28716 int crtc_mask = 1;
28717
28718- WARN(!crtc, "checking null crtc?\n");
28719+ BUG_ON(!crtc);
28720
28721 dev = crtc->dev;
28722
28723@@ -343,6 +343,8 @@ bool drm_crtc_helper_set_mode(struct drm
28724 struct drm_encoder *encoder;
28725 bool ret = true;
28726
28727+ pax_track_stack();
28728+
28729 crtc->enabled = drm_helper_crtc_in_use(crtc);
28730 if (!crtc->enabled)
28731 return true;
28732diff -urNp linux-2.6.39.1/drivers/gpu/drm/drm_drv.c linux-2.6.39.1/drivers/gpu/drm/drm_drv.c
28733--- linux-2.6.39.1/drivers/gpu/drm/drm_drv.c 2011-05-19 00:06:34.000000000 -0400
28734+++ linux-2.6.39.1/drivers/gpu/drm/drm_drv.c 2011-05-22 19:36:31.000000000 -0400
28735@@ -386,7 +386,7 @@ long drm_ioctl(struct file *filp,
28736
28737 dev = file_priv->minor->dev;
28738 atomic_inc(&dev->ioctl_count);
28739- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
28740+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
28741 ++file_priv->ioctl_count;
28742
28743 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
28744diff -urNp linux-2.6.39.1/drivers/gpu/drm/drm_fops.c linux-2.6.39.1/drivers/gpu/drm/drm_fops.c
28745--- linux-2.6.39.1/drivers/gpu/drm/drm_fops.c 2011-05-19 00:06:34.000000000 -0400
28746+++ linux-2.6.39.1/drivers/gpu/drm/drm_fops.c 2011-05-22 19:36:31.000000000 -0400
28747@@ -70,7 +70,7 @@ static int drm_setup(struct drm_device *
28748 }
28749
28750 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
28751- atomic_set(&dev->counts[i], 0);
28752+ atomic_set_unchecked(&dev->counts[i], 0);
28753
28754 dev->sigdata.lock = NULL;
28755
28756@@ -134,8 +134,8 @@ int drm_open(struct inode *inode, struct
28757
28758 retcode = drm_open_helper(inode, filp, dev);
28759 if (!retcode) {
28760- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
28761- if (!dev->open_count++)
28762+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
28763+ if (local_inc_return(&dev->open_count) == 1)
28764 retcode = drm_setup(dev);
28765 }
28766 if (!retcode) {
28767@@ -472,7 +472,7 @@ int drm_release(struct inode *inode, str
28768
28769 mutex_lock(&drm_global_mutex);
28770
28771- DRM_DEBUG("open_count = %d\n", dev->open_count);
28772+ DRM_DEBUG("open_count = %d\n", local_read(&dev->open_count));
28773
28774 if (dev->driver->preclose)
28775 dev->driver->preclose(dev, file_priv);
28776@@ -484,7 +484,7 @@ int drm_release(struct inode *inode, str
28777 DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
28778 task_pid_nr(current),
28779 (long)old_encode_dev(file_priv->minor->device),
28780- dev->open_count);
28781+ local_read(&dev->open_count));
28782
28783 /* if the master has gone away we can't do anything with the lock */
28784 if (file_priv->minor->master)
28785@@ -565,8 +565,8 @@ int drm_release(struct inode *inode, str
28786 * End inline drm_release
28787 */
28788
28789- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
28790- if (!--dev->open_count) {
28791+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
28792+ if (local_dec_and_test(&dev->open_count)) {
28793 if (atomic_read(&dev->ioctl_count)) {
28794 DRM_ERROR("Device busy: %d\n",
28795 atomic_read(&dev->ioctl_count));
28796diff -urNp linux-2.6.39.1/drivers/gpu/drm/drm_global.c linux-2.6.39.1/drivers/gpu/drm/drm_global.c
28797--- linux-2.6.39.1/drivers/gpu/drm/drm_global.c 2011-05-19 00:06:34.000000000 -0400
28798+++ linux-2.6.39.1/drivers/gpu/drm/drm_global.c 2011-05-22 19:36:31.000000000 -0400
28799@@ -36,7 +36,7 @@
28800 struct drm_global_item {
28801 struct mutex mutex;
28802 void *object;
28803- int refcount;
28804+ atomic_t refcount;
28805 };
28806
28807 static struct drm_global_item glob[DRM_GLOBAL_NUM];
28808@@ -49,7 +49,7 @@ void drm_global_init(void)
28809 struct drm_global_item *item = &glob[i];
28810 mutex_init(&item->mutex);
28811 item->object = NULL;
28812- item->refcount = 0;
28813+ atomic_set(&item->refcount, 0);
28814 }
28815 }
28816
28817@@ -59,7 +59,7 @@ void drm_global_release(void)
28818 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
28819 struct drm_global_item *item = &glob[i];
28820 BUG_ON(item->object != NULL);
28821- BUG_ON(item->refcount != 0);
28822+ BUG_ON(atomic_read(&item->refcount) != 0);
28823 }
28824 }
28825
28826@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_globa
28827 void *object;
28828
28829 mutex_lock(&item->mutex);
28830- if (item->refcount == 0) {
28831+ if (atomic_read(&item->refcount) == 0) {
28832 item->object = kzalloc(ref->size, GFP_KERNEL);
28833 if (unlikely(item->object == NULL)) {
28834 ret = -ENOMEM;
28835@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_globa
28836 goto out_err;
28837
28838 }
28839- ++item->refcount;
28840+ atomic_inc(&item->refcount);
28841 ref->object = item->object;
28842 object = item->object;
28843 mutex_unlock(&item->mutex);
28844@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_gl
28845 struct drm_global_item *item = &glob[ref->global_type];
28846
28847 mutex_lock(&item->mutex);
28848- BUG_ON(item->refcount == 0);
28849+ BUG_ON(atomic_read(&item->refcount) == 0);
28850 BUG_ON(ref->object != item->object);
28851- if (--item->refcount == 0) {
28852+ if (atomic_dec_and_test(&item->refcount)) {
28853 ref->release(ref);
28854 item->object = NULL;
28855 }
28856diff -urNp linux-2.6.39.1/drivers/gpu/drm/drm_info.c linux-2.6.39.1/drivers/gpu/drm/drm_info.c
28857--- linux-2.6.39.1/drivers/gpu/drm/drm_info.c 2011-05-19 00:06:34.000000000 -0400
28858+++ linux-2.6.39.1/drivers/gpu/drm/drm_info.c 2011-05-22 19:41:37.000000000 -0400
28859@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void
28860 struct drm_local_map *map;
28861 struct drm_map_list *r_list;
28862
28863- /* Hardcoded from _DRM_FRAME_BUFFER,
28864- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
28865- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
28866- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
28867+ static const char * const types[] = {
28868+ [_DRM_FRAME_BUFFER] = "FB",
28869+ [_DRM_REGISTERS] = "REG",
28870+ [_DRM_SHM] = "SHM",
28871+ [_DRM_AGP] = "AGP",
28872+ [_DRM_SCATTER_GATHER] = "SG",
28873+ [_DRM_CONSISTENT] = "PCI",
28874+ [_DRM_GEM] = "GEM" };
28875 const char *type;
28876 int i;
28877
28878@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void
28879 map = r_list->map;
28880 if (!map)
28881 continue;
28882- if (map->type < 0 || map->type > 5)
28883+ if (map->type >= ARRAY_SIZE(types))
28884 type = "??";
28885 else
28886 type = types[map->type];
28887@@ -290,7 +294,11 @@ int drm_vma_info(struct seq_file *m, voi
28888 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
28889 vma->vm_flags & VM_LOCKED ? 'l' : '-',
28890 vma->vm_flags & VM_IO ? 'i' : '-',
28891+#ifdef CONFIG_GRKERNSEC_HIDESYM
28892+ 0);
28893+#else
28894 vma->vm_pgoff);
28895+#endif
28896
28897 #if defined(__i386__)
28898 pgprot = pgprot_val(vma->vm_page_prot);
28899diff -urNp linux-2.6.39.1/drivers/gpu/drm/drm_ioctl.c linux-2.6.39.1/drivers/gpu/drm/drm_ioctl.c
28900--- linux-2.6.39.1/drivers/gpu/drm/drm_ioctl.c 2011-05-19 00:06:34.000000000 -0400
28901+++ linux-2.6.39.1/drivers/gpu/drm/drm_ioctl.c 2011-05-22 19:36:31.000000000 -0400
28902@@ -256,7 +256,7 @@ int drm_getstats(struct drm_device *dev,
28903 stats->data[i].value =
28904 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
28905 else
28906- stats->data[i].value = atomic_read(&dev->counts[i]);
28907+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
28908 stats->data[i].type = dev->types[i];
28909 }
28910
28911diff -urNp linux-2.6.39.1/drivers/gpu/drm/drm_lock.c linux-2.6.39.1/drivers/gpu/drm/drm_lock.c
28912--- linux-2.6.39.1/drivers/gpu/drm/drm_lock.c 2011-05-19 00:06:34.000000000 -0400
28913+++ linux-2.6.39.1/drivers/gpu/drm/drm_lock.c 2011-05-22 19:36:31.000000000 -0400
28914@@ -89,7 +89,7 @@ int drm_lock(struct drm_device *dev, voi
28915 if (drm_lock_take(&master->lock, lock->context)) {
28916 master->lock.file_priv = file_priv;
28917 master->lock.lock_time = jiffies;
28918- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
28919+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
28920 break; /* Got lock */
28921 }
28922
28923@@ -160,7 +160,7 @@ int drm_unlock(struct drm_device *dev, v
28924 return -EINVAL;
28925 }
28926
28927- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
28928+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
28929
28930 if (drm_lock_free(&master->lock, lock->context)) {
28931 /* FIXME: Should really bail out here. */
28932diff -urNp linux-2.6.39.1/drivers/gpu/drm/i810/i810_dma.c linux-2.6.39.1/drivers/gpu/drm/i810/i810_dma.c
28933--- linux-2.6.39.1/drivers/gpu/drm/i810/i810_dma.c 2011-05-19 00:06:34.000000000 -0400
28934+++ linux-2.6.39.1/drivers/gpu/drm/i810/i810_dma.c 2011-05-22 19:36:31.000000000 -0400
28935@@ -950,8 +950,8 @@ static int i810_dma_vertex(struct drm_de
28936 dma->buflist[vertex->idx],
28937 vertex->discard, vertex->used);
28938
28939- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
28940- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
28941+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
28942+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
28943 sarea_priv->last_enqueue = dev_priv->counter - 1;
28944 sarea_priv->last_dispatch = (int)hw_status[5];
28945
28946@@ -1111,8 +1111,8 @@ static int i810_dma_mc(struct drm_device
28947 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
28948 mc->last_render);
28949
28950- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
28951- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
28952+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
28953+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
28954 sarea_priv->last_enqueue = dev_priv->counter - 1;
28955 sarea_priv->last_dispatch = (int)hw_status[5];
28956
28957diff -urNp linux-2.6.39.1/drivers/gpu/drm/i810/i810_drv.h linux-2.6.39.1/drivers/gpu/drm/i810/i810_drv.h
28958--- linux-2.6.39.1/drivers/gpu/drm/i810/i810_drv.h 2011-05-19 00:06:34.000000000 -0400
28959+++ linux-2.6.39.1/drivers/gpu/drm/i810/i810_drv.h 2011-05-22 19:36:31.000000000 -0400
28960@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
28961 int page_flipping;
28962
28963 wait_queue_head_t irq_queue;
28964- atomic_t irq_received;
28965- atomic_t irq_emitted;
28966+ atomic_unchecked_t irq_received;
28967+ atomic_unchecked_t irq_emitted;
28968
28969 int front_offset;
28970 } drm_i810_private_t;
28971diff -urNp linux-2.6.39.1/drivers/gpu/drm/i915/dvo_ch7017.c linux-2.6.39.1/drivers/gpu/drm/i915/dvo_ch7017.c
28972--- linux-2.6.39.1/drivers/gpu/drm/i915/dvo_ch7017.c 2011-05-19 00:06:34.000000000 -0400
28973+++ linux-2.6.39.1/drivers/gpu/drm/i915/dvo_ch7017.c 2011-05-22 19:36:31.000000000 -0400
28974@@ -390,7 +390,7 @@ static void ch7017_destroy(struct intel_
28975 }
28976 }
28977
28978-struct intel_dvo_dev_ops ch7017_ops = {
28979+const struct intel_dvo_dev_ops ch7017_ops = {
28980 .init = ch7017_init,
28981 .detect = ch7017_detect,
28982 .mode_valid = ch7017_mode_valid,
28983diff -urNp linux-2.6.39.1/drivers/gpu/drm/i915/dvo_ch7xxx.c linux-2.6.39.1/drivers/gpu/drm/i915/dvo_ch7xxx.c
28984--- linux-2.6.39.1/drivers/gpu/drm/i915/dvo_ch7xxx.c 2011-05-19 00:06:34.000000000 -0400
28985+++ linux-2.6.39.1/drivers/gpu/drm/i915/dvo_ch7xxx.c 2011-05-22 19:36:31.000000000 -0400
28986@@ -320,7 +320,7 @@ static void ch7xxx_destroy(struct intel_
28987 }
28988 }
28989
28990-struct intel_dvo_dev_ops ch7xxx_ops = {
28991+const struct intel_dvo_dev_ops ch7xxx_ops = {
28992 .init = ch7xxx_init,
28993 .detect = ch7xxx_detect,
28994 .mode_valid = ch7xxx_mode_valid,
28995diff -urNp linux-2.6.39.1/drivers/gpu/drm/i915/dvo.h linux-2.6.39.1/drivers/gpu/drm/i915/dvo.h
28996--- linux-2.6.39.1/drivers/gpu/drm/i915/dvo.h 2011-05-19 00:06:34.000000000 -0400
28997+++ linux-2.6.39.1/drivers/gpu/drm/i915/dvo.h 2011-05-22 19:36:31.000000000 -0400
28998@@ -122,23 +122,23 @@ struct intel_dvo_dev_ops {
28999 *
29000 * \return singly-linked list of modes or NULL if no modes found.
29001 */
29002- struct drm_display_mode *(*get_modes)(struct intel_dvo_device *dvo);
29003+ struct drm_display_mode *(* const get_modes)(struct intel_dvo_device *dvo);
29004
29005 /**
29006 * Clean up driver-specific bits of the output
29007 */
29008- void (*destroy) (struct intel_dvo_device *dvo);
29009+ void (* const destroy) (struct intel_dvo_device *dvo);
29010
29011 /**
29012 * Debugging hook to dump device registers to log file
29013 */
29014- void (*dump_regs)(struct intel_dvo_device *dvo);
29015+ void (* const dump_regs)(struct intel_dvo_device *dvo);
29016 };
29017
29018-extern struct intel_dvo_dev_ops sil164_ops;
29019-extern struct intel_dvo_dev_ops ch7xxx_ops;
29020-extern struct intel_dvo_dev_ops ivch_ops;
29021-extern struct intel_dvo_dev_ops tfp410_ops;
29022-extern struct intel_dvo_dev_ops ch7017_ops;
29023+extern const struct intel_dvo_dev_ops sil164_ops;
29024+extern const struct intel_dvo_dev_ops ch7xxx_ops;
29025+extern const struct intel_dvo_dev_ops ivch_ops;
29026+extern const struct intel_dvo_dev_ops tfp410_ops;
29027+extern const struct intel_dvo_dev_ops ch7017_ops;
29028
29029 #endif /* _INTEL_DVO_H */
29030diff -urNp linux-2.6.39.1/drivers/gpu/drm/i915/dvo_ivch.c linux-2.6.39.1/drivers/gpu/drm/i915/dvo_ivch.c
29031--- linux-2.6.39.1/drivers/gpu/drm/i915/dvo_ivch.c 2011-05-19 00:06:34.000000000 -0400
29032+++ linux-2.6.39.1/drivers/gpu/drm/i915/dvo_ivch.c 2011-05-22 19:36:31.000000000 -0400
29033@@ -410,7 +410,7 @@ static void ivch_destroy(struct intel_dv
29034 }
29035 }
29036
29037-struct intel_dvo_dev_ops ivch_ops= {
29038+const struct intel_dvo_dev_ops ivch_ops= {
29039 .init = ivch_init,
29040 .dpms = ivch_dpms,
29041 .mode_valid = ivch_mode_valid,
29042diff -urNp linux-2.6.39.1/drivers/gpu/drm/i915/dvo_sil164.c linux-2.6.39.1/drivers/gpu/drm/i915/dvo_sil164.c
29043--- linux-2.6.39.1/drivers/gpu/drm/i915/dvo_sil164.c 2011-05-19 00:06:34.000000000 -0400
29044+++ linux-2.6.39.1/drivers/gpu/drm/i915/dvo_sil164.c 2011-05-22 19:36:31.000000000 -0400
29045@@ -252,7 +252,7 @@ static void sil164_destroy(struct intel_
29046 }
29047 }
29048
29049-struct intel_dvo_dev_ops sil164_ops = {
29050+const struct intel_dvo_dev_ops sil164_ops = {
29051 .init = sil164_init,
29052 .detect = sil164_detect,
29053 .mode_valid = sil164_mode_valid,
29054diff -urNp linux-2.6.39.1/drivers/gpu/drm/i915/dvo_tfp410.c linux-2.6.39.1/drivers/gpu/drm/i915/dvo_tfp410.c
29055--- linux-2.6.39.1/drivers/gpu/drm/i915/dvo_tfp410.c 2011-05-19 00:06:34.000000000 -0400
29056+++ linux-2.6.39.1/drivers/gpu/drm/i915/dvo_tfp410.c 2011-05-22 19:36:31.000000000 -0400
29057@@ -293,7 +293,7 @@ static void tfp410_destroy(struct intel_
29058 }
29059 }
29060
29061-struct intel_dvo_dev_ops tfp410_ops = {
29062+const struct intel_dvo_dev_ops tfp410_ops = {
29063 .init = tfp410_init,
29064 .detect = tfp410_detect,
29065 .mode_valid = tfp410_mode_valid,
29066diff -urNp linux-2.6.39.1/drivers/gpu/drm/i915/i915_debugfs.c linux-2.6.39.1/drivers/gpu/drm/i915/i915_debugfs.c
29067--- linux-2.6.39.1/drivers/gpu/drm/i915/i915_debugfs.c 2011-05-19 00:06:34.000000000 -0400
29068+++ linux-2.6.39.1/drivers/gpu/drm/i915/i915_debugfs.c 2011-05-22 19:36:31.000000000 -0400
29069@@ -496,7 +496,7 @@ static int i915_interrupt_info(struct se
29070 I915_READ(GTIMR));
29071 }
29072 seq_printf(m, "Interrupts received: %d\n",
29073- atomic_read(&dev_priv->irq_received));
29074+ atomic_read_unchecked(&dev_priv->irq_received));
29075 for (i = 0; i < I915_NUM_RINGS; i++) {
29076 if (IS_GEN6(dev)) {
29077 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
29078diff -urNp linux-2.6.39.1/drivers/gpu/drm/i915/i915_dma.c linux-2.6.39.1/drivers/gpu/drm/i915/i915_dma.c
29079--- linux-2.6.39.1/drivers/gpu/drm/i915/i915_dma.c 2011-05-19 00:06:34.000000000 -0400
29080+++ linux-2.6.39.1/drivers/gpu/drm/i915/i915_dma.c 2011-05-22 19:36:31.000000000 -0400
29081@@ -1171,7 +1171,7 @@ static bool i915_switcheroo_can_switch(s
29082 bool can_switch;
29083
29084 spin_lock(&dev->count_lock);
29085- can_switch = (dev->open_count == 0);
29086+ can_switch = (local_read(&dev->open_count) == 0);
29087 spin_unlock(&dev->count_lock);
29088 return can_switch;
29089 }
29090diff -urNp linux-2.6.39.1/drivers/gpu/drm/i915/i915_drv.c linux-2.6.39.1/drivers/gpu/drm/i915/i915_drv.c
29091--- linux-2.6.39.1/drivers/gpu/drm/i915/i915_drv.c 2011-05-19 00:06:34.000000000 -0400
29092+++ linux-2.6.39.1/drivers/gpu/drm/i915/i915_drv.c 2011-05-22 19:36:31.000000000 -0400
29093@@ -679,7 +679,7 @@ static const struct dev_pm_ops i915_pm_o
29094 .restore = i915_pm_resume,
29095 };
29096
29097-static struct vm_operations_struct i915_gem_vm_ops = {
29098+static const struct vm_operations_struct i915_gem_vm_ops = {
29099 .fault = i915_gem_fault,
29100 .open = drm_gem_vm_open,
29101 .close = drm_gem_vm_close,
29102diff -urNp linux-2.6.39.1/drivers/gpu/drm/i915/i915_drv.h linux-2.6.39.1/drivers/gpu/drm/i915/i915_drv.h
29103--- linux-2.6.39.1/drivers/gpu/drm/i915/i915_drv.h 2011-05-19 00:06:34.000000000 -0400
29104+++ linux-2.6.39.1/drivers/gpu/drm/i915/i915_drv.h 2011-05-22 19:36:31.000000000 -0400
29105@@ -287,7 +287,7 @@ typedef struct drm_i915_private {
29106 int current_page;
29107 int page_flipping;
29108
29109- atomic_t irq_received;
29110+ atomic_unchecked_t irq_received;
29111
29112 /* protects the irq masks */
29113 spinlock_t irq_lock;
29114@@ -848,7 +848,7 @@ struct drm_i915_gem_object {
29115 * will be page flipped away on the next vblank. When it
29116 * reaches 0, dev_priv->pending_flip_queue will be woken up.
29117 */
29118- atomic_t pending_flip;
29119+ atomic_unchecked_t pending_flip;
29120 };
29121
29122 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
29123@@ -1232,7 +1232,7 @@ extern int intel_setup_gmbus(struct drm_
29124 extern void intel_teardown_gmbus(struct drm_device *dev);
29125 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
29126 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
29127-extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
29128+static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
29129 {
29130 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
29131 }
29132diff -urNp linux-2.6.39.1/drivers/gpu/drm/i915/i915_gem_execbuffer.c linux-2.6.39.1/drivers/gpu/drm/i915/i915_gem_execbuffer.c
29133--- linux-2.6.39.1/drivers/gpu/drm/i915/i915_gem_execbuffer.c 2011-05-19 00:06:34.000000000 -0400
29134+++ linux-2.6.39.1/drivers/gpu/drm/i915/i915_gem_execbuffer.c 2011-05-22 19:36:31.000000000 -0400
29135@@ -192,7 +192,7 @@ i915_gem_object_set_to_gpu_domain(struct
29136 i915_gem_release_mmap(obj);
29137
29138 if (obj->base.pending_write_domain)
29139- cd->flips |= atomic_read(&obj->pending_flip);
29140+ cd->flips |= atomic_read_unchecked(&obj->pending_flip);
29141
29142 /* The actual obj->write_domain will be updated with
29143 * pending_write_domain after we emit the accumulated flush for all
29144diff -urNp linux-2.6.39.1/drivers/gpu/drm/i915/i915_irq.c linux-2.6.39.1/drivers/gpu/drm/i915/i915_irq.c
29145--- linux-2.6.39.1/drivers/gpu/drm/i915/i915_irq.c 2011-05-19 00:06:34.000000000 -0400
29146+++ linux-2.6.39.1/drivers/gpu/drm/i915/i915_irq.c 2011-05-22 19:36:31.000000000 -0400
29147@@ -1101,7 +1101,7 @@ irqreturn_t i915_driver_irq_handler(DRM_
29148 int ret = IRQ_NONE, pipe;
29149 bool blc_event = false;
29150
29151- atomic_inc(&dev_priv->irq_received);
29152+ atomic_inc_unchecked(&dev_priv->irq_received);
29153
29154 if (HAS_PCH_SPLIT(dev))
29155 return ironlake_irq_handler(dev);
29156@@ -1655,7 +1655,7 @@ void i915_driver_irq_preinstall(struct d
29157 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
29158 int pipe;
29159
29160- atomic_set(&dev_priv->irq_received, 0);
29161+ atomic_set_unchecked(&dev_priv->irq_received, 0);
29162
29163 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
29164 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
29165diff -urNp linux-2.6.39.1/drivers/gpu/drm/i915/intel_display.c linux-2.6.39.1/drivers/gpu/drm/i915/intel_display.c
29166--- linux-2.6.39.1/drivers/gpu/drm/i915/intel_display.c 2011-05-19 00:06:34.000000000 -0400
29167+++ linux-2.6.39.1/drivers/gpu/drm/i915/intel_display.c 2011-05-22 19:36:31.000000000 -0400
29168@@ -2244,7 +2244,7 @@ intel_pipe_set_base(struct drm_crtc *crt
29169
29170 wait_event(dev_priv->pending_flip_queue,
29171 atomic_read(&dev_priv->mm.wedged) ||
29172- atomic_read(&obj->pending_flip) == 0);
29173+ atomic_read_unchecked(&obj->pending_flip) == 0);
29174
29175 /* Big Hammer, we also need to ensure that any pending
29176 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
29177@@ -2712,7 +2712,7 @@ static void intel_crtc_wait_for_pending_
29178 obj = to_intel_framebuffer(crtc->fb)->obj;
29179 dev_priv = crtc->dev->dev_private;
29180 wait_event(dev_priv->pending_flip_queue,
29181- atomic_read(&obj->pending_flip) == 0);
29182+ atomic_read_unchecked(&obj->pending_flip) == 0);
29183 }
29184
29185 static bool intel_crtc_driving_pch(struct drm_crtc *crtc)
29186@@ -6016,7 +6016,7 @@ static void do_intel_finish_page_flip(st
29187
29188 atomic_clear_mask(1 << intel_crtc->plane,
29189 &obj->pending_flip.counter);
29190- if (atomic_read(&obj->pending_flip) == 0)
29191+ if (atomic_read_unchecked(&obj->pending_flip) == 0)
29192 wake_up(&dev_priv->pending_flip_queue);
29193
29194 schedule_work(&work->work);
29195@@ -6145,7 +6145,7 @@ static int intel_crtc_page_flip(struct d
29196 /* Block clients from rendering to the new back buffer until
29197 * the flip occurs and the object is no longer visible.
29198 */
29199- atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
29200+ atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
29201
29202 switch (INTEL_INFO(dev)->gen) {
29203 case 2:
29204diff -urNp linux-2.6.39.1/drivers/gpu/drm/mga/mga_drv.h linux-2.6.39.1/drivers/gpu/drm/mga/mga_drv.h
29205--- linux-2.6.39.1/drivers/gpu/drm/mga/mga_drv.h 2011-05-19 00:06:34.000000000 -0400
29206+++ linux-2.6.39.1/drivers/gpu/drm/mga/mga_drv.h 2011-05-22 19:36:31.000000000 -0400
29207@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
29208 u32 clear_cmd;
29209 u32 maccess;
29210
29211- atomic_t vbl_received; /**< Number of vblanks received. */
29212+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
29213 wait_queue_head_t fence_queue;
29214- atomic_t last_fence_retired;
29215+ atomic_unchecked_t last_fence_retired;
29216 u32 next_fence_to_post;
29217
29218 unsigned int fb_cpp;
29219diff -urNp linux-2.6.39.1/drivers/gpu/drm/mga/mga_irq.c linux-2.6.39.1/drivers/gpu/drm/mga/mga_irq.c
29220--- linux-2.6.39.1/drivers/gpu/drm/mga/mga_irq.c 2011-05-19 00:06:34.000000000 -0400
29221+++ linux-2.6.39.1/drivers/gpu/drm/mga/mga_irq.c 2011-05-22 19:36:31.000000000 -0400
29222@@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_de
29223 if (crtc != 0)
29224 return 0;
29225
29226- return atomic_read(&dev_priv->vbl_received);
29227+ return atomic_read_unchecked(&dev_priv->vbl_received);
29228 }
29229
29230
29231@@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_I
29232 /* VBLANK interrupt */
29233 if (status & MGA_VLINEPEN) {
29234 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
29235- atomic_inc(&dev_priv->vbl_received);
29236+ atomic_inc_unchecked(&dev_priv->vbl_received);
29237 drm_handle_vblank(dev, 0);
29238 handled = 1;
29239 }
29240@@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_I
29241 if ((prim_start & ~0x03) != (prim_end & ~0x03))
29242 MGA_WRITE(MGA_PRIMEND, prim_end);
29243
29244- atomic_inc(&dev_priv->last_fence_retired);
29245+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
29246 DRM_WAKEUP(&dev_priv->fence_queue);
29247 handled = 1;
29248 }
29249@@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_dev
29250 * using fences.
29251 */
29252 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
29253- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
29254+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
29255 - *sequence) <= (1 << 23)));
29256
29257 *sequence = cur_fence;
29258diff -urNp linux-2.6.39.1/drivers/gpu/drm/nouveau/nouveau_acpi.c linux-2.6.39.1/drivers/gpu/drm/nouveau/nouveau_acpi.c
29259--- linux-2.6.39.1/drivers/gpu/drm/nouveau/nouveau_acpi.c 2011-05-19 00:06:34.000000000 -0400
29260+++ linux-2.6.39.1/drivers/gpu/drm/nouveau/nouveau_acpi.c 2011-05-22 19:36:31.000000000 -0400
29261@@ -141,7 +141,7 @@ static int nouveau_dsm_get_client_id(str
29262 return VGA_SWITCHEROO_DIS;
29263 }
29264
29265-static struct vga_switcheroo_handler nouveau_dsm_handler = {
29266+static const struct vga_switcheroo_handler nouveau_dsm_handler = {
29267 .switchto = nouveau_dsm_switchto,
29268 .power_state = nouveau_dsm_power_state,
29269 .init = nouveau_dsm_init,
29270diff -urNp linux-2.6.39.1/drivers/gpu/drm/nouveau/nouveau_drv.h linux-2.6.39.1/drivers/gpu/drm/nouveau/nouveau_drv.h
29271--- linux-2.6.39.1/drivers/gpu/drm/nouveau/nouveau_drv.h 2011-05-19 00:06:34.000000000 -0400
29272+++ linux-2.6.39.1/drivers/gpu/drm/nouveau/nouveau_drv.h 2011-06-07 18:07:24.000000000 -0400
29273@@ -228,7 +228,7 @@ struct nouveau_channel {
29274 struct list_head pending;
29275 uint32_t sequence;
29276 uint32_t sequence_ack;
29277- atomic_t last_sequence_irq;
29278+ atomic_unchecked_t last_sequence_irq;
29279 } fence;
29280
29281 /* DMA push buffer */
29282@@ -662,7 +662,7 @@ struct drm_nouveau_private {
29283 struct drm_global_reference mem_global_ref;
29284 struct ttm_bo_global_ref bo_global_ref;
29285 struct ttm_bo_device bdev;
29286- atomic_t validate_sequence;
29287+ atomic_unchecked_t validate_sequence;
29288 } ttm;
29289
29290 struct {
29291diff -urNp linux-2.6.39.1/drivers/gpu/drm/nouveau/nouveau_fence.c linux-2.6.39.1/drivers/gpu/drm/nouveau/nouveau_fence.c
29292--- linux-2.6.39.1/drivers/gpu/drm/nouveau/nouveau_fence.c 2011-05-19 00:06:34.000000000 -0400
29293+++ linux-2.6.39.1/drivers/gpu/drm/nouveau/nouveau_fence.c 2011-05-22 19:36:31.000000000 -0400
29294@@ -85,7 +85,7 @@ nouveau_fence_update(struct nouveau_chan
29295 if (USE_REFCNT(dev))
29296 sequence = nvchan_rd32(chan, 0x48);
29297 else
29298- sequence = atomic_read(&chan->fence.last_sequence_irq);
29299+ sequence = atomic_read_unchecked(&chan->fence.last_sequence_irq);
29300
29301 if (chan->fence.sequence_ack == sequence)
29302 goto out;
29303@@ -553,7 +553,7 @@ nouveau_fence_channel_init(struct nouvea
29304 out_initialised:
29305 INIT_LIST_HEAD(&chan->fence.pending);
29306 spin_lock_init(&chan->fence.lock);
29307- atomic_set(&chan->fence.last_sequence_irq, 0);
29308+ atomic_set_unchecked(&chan->fence.last_sequence_irq, 0);
29309 return 0;
29310 }
29311
29312diff -urNp linux-2.6.39.1/drivers/gpu/drm/nouveau/nouveau_gem.c linux-2.6.39.1/drivers/gpu/drm/nouveau/nouveau_gem.c
29313--- linux-2.6.39.1/drivers/gpu/drm/nouveau/nouveau_gem.c 2011-05-19 00:06:34.000000000 -0400
29314+++ linux-2.6.39.1/drivers/gpu/drm/nouveau/nouveau_gem.c 2011-05-22 19:36:31.000000000 -0400
29315@@ -249,7 +249,7 @@ validate_init(struct nouveau_channel *ch
29316 int trycnt = 0;
29317 int ret, i;
29318
29319- sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
29320+ sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
29321 retry:
29322 if (++trycnt > 100000) {
29323 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
29324diff -urNp linux-2.6.39.1/drivers/gpu/drm/nouveau/nouveau_state.c linux-2.6.39.1/drivers/gpu/drm/nouveau/nouveau_state.c
29325--- linux-2.6.39.1/drivers/gpu/drm/nouveau/nouveau_state.c 2011-05-19 00:06:34.000000000 -0400
29326+++ linux-2.6.39.1/drivers/gpu/drm/nouveau/nouveau_state.c 2011-05-22 19:36:31.000000000 -0400
29327@@ -583,7 +583,7 @@ static bool nouveau_switcheroo_can_switc
29328 bool can_switch;
29329
29330 spin_lock(&dev->count_lock);
29331- can_switch = (dev->open_count == 0);
29332+ can_switch = (local_read(&dev->open_count) == 0);
29333 spin_unlock(&dev->count_lock);
29334 return can_switch;
29335 }
29336diff -urNp linux-2.6.39.1/drivers/gpu/drm/nouveau/nv04_graph.c linux-2.6.39.1/drivers/gpu/drm/nouveau/nv04_graph.c
29337--- linux-2.6.39.1/drivers/gpu/drm/nouveau/nv04_graph.c 2011-05-19 00:06:34.000000000 -0400
29338+++ linux-2.6.39.1/drivers/gpu/drm/nouveau/nv04_graph.c 2011-05-22 19:36:31.000000000 -0400
29339@@ -552,7 +552,7 @@ static int
29340 nv04_graph_mthd_set_ref(struct nouveau_channel *chan,
29341 u32 class, u32 mthd, u32 data)
29342 {
29343- atomic_set(&chan->fence.last_sequence_irq, data);
29344+ atomic_set_unchecked(&chan->fence.last_sequence_irq, data);
29345 return 0;
29346 }
29347
29348diff -urNp linux-2.6.39.1/drivers/gpu/drm/r128/r128_cce.c linux-2.6.39.1/drivers/gpu/drm/r128/r128_cce.c
29349--- linux-2.6.39.1/drivers/gpu/drm/r128/r128_cce.c 2011-05-19 00:06:34.000000000 -0400
29350+++ linux-2.6.39.1/drivers/gpu/drm/r128/r128_cce.c 2011-05-22 19:36:31.000000000 -0400
29351@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_d
29352
29353 /* GH: Simple idle check.
29354 */
29355- atomic_set(&dev_priv->idle_count, 0);
29356+ atomic_set_unchecked(&dev_priv->idle_count, 0);
29357
29358 /* We don't support anything other than bus-mastering ring mode,
29359 * but the ring can be in either AGP or PCI space for the ring
29360diff -urNp linux-2.6.39.1/drivers/gpu/drm/r128/r128_drv.h linux-2.6.39.1/drivers/gpu/drm/r128/r128_drv.h
29361--- linux-2.6.39.1/drivers/gpu/drm/r128/r128_drv.h 2011-05-19 00:06:34.000000000 -0400
29362+++ linux-2.6.39.1/drivers/gpu/drm/r128/r128_drv.h 2011-05-22 19:36:31.000000000 -0400
29363@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
29364 int is_pci;
29365 unsigned long cce_buffers_offset;
29366
29367- atomic_t idle_count;
29368+ atomic_unchecked_t idle_count;
29369
29370 int page_flipping;
29371 int current_page;
29372 u32 crtc_offset;
29373 u32 crtc_offset_cntl;
29374
29375- atomic_t vbl_received;
29376+ atomic_unchecked_t vbl_received;
29377
29378 u32 color_fmt;
29379 unsigned int front_offset;
29380diff -urNp linux-2.6.39.1/drivers/gpu/drm/r128/r128_irq.c linux-2.6.39.1/drivers/gpu/drm/r128/r128_irq.c
29381--- linux-2.6.39.1/drivers/gpu/drm/r128/r128_irq.c 2011-05-19 00:06:34.000000000 -0400
29382+++ linux-2.6.39.1/drivers/gpu/drm/r128/r128_irq.c 2011-05-22 19:36:31.000000000 -0400
29383@@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_d
29384 if (crtc != 0)
29385 return 0;
29386
29387- return atomic_read(&dev_priv->vbl_received);
29388+ return atomic_read_unchecked(&dev_priv->vbl_received);
29389 }
29390
29391 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
29392@@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_
29393 /* VBLANK interrupt */
29394 if (status & R128_CRTC_VBLANK_INT) {
29395 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
29396- atomic_inc(&dev_priv->vbl_received);
29397+ atomic_inc_unchecked(&dev_priv->vbl_received);
29398 drm_handle_vblank(dev, 0);
29399 return IRQ_HANDLED;
29400 }
29401diff -urNp linux-2.6.39.1/drivers/gpu/drm/r128/r128_state.c linux-2.6.39.1/drivers/gpu/drm/r128/r128_state.c
29402--- linux-2.6.39.1/drivers/gpu/drm/r128/r128_state.c 2011-05-19 00:06:34.000000000 -0400
29403+++ linux-2.6.39.1/drivers/gpu/drm/r128/r128_state.c 2011-05-22 19:36:31.000000000 -0400
29404@@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_priv
29405
29406 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
29407 {
29408- if (atomic_read(&dev_priv->idle_count) == 0)
29409+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
29410 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
29411 else
29412- atomic_set(&dev_priv->idle_count, 0);
29413+ atomic_set_unchecked(&dev_priv->idle_count, 0);
29414 }
29415
29416 #endif
29417diff -urNp linux-2.6.39.1/drivers/gpu/drm/radeon/atom.c linux-2.6.39.1/drivers/gpu/drm/radeon/atom.c
29418--- linux-2.6.39.1/drivers/gpu/drm/radeon/atom.c 2011-05-19 00:06:34.000000000 -0400
29419+++ linux-2.6.39.1/drivers/gpu/drm/radeon/atom.c 2011-05-22 19:36:31.000000000 -0400
29420@@ -1245,6 +1245,8 @@ struct atom_context *atom_parse(struct c
29421 char name[512];
29422 int i;
29423
29424+ pax_track_stack();
29425+
29426 ctx->card = card;
29427 ctx->bios = bios;
29428
29429diff -urNp linux-2.6.39.1/drivers/gpu/drm/radeon/mkregtable.c linux-2.6.39.1/drivers/gpu/drm/radeon/mkregtable.c
29430--- linux-2.6.39.1/drivers/gpu/drm/radeon/mkregtable.c 2011-05-19 00:06:34.000000000 -0400
29431+++ linux-2.6.39.1/drivers/gpu/drm/radeon/mkregtable.c 2011-05-22 19:36:31.000000000 -0400
29432@@ -637,14 +637,14 @@ static int parser_auth(struct table *t,
29433 regex_t mask_rex;
29434 regmatch_t match[4];
29435 char buf[1024];
29436- size_t end;
29437+ long end;
29438 int len;
29439 int done = 0;
29440 int r;
29441 unsigned o;
29442 struct offset *offset;
29443 char last_reg_s[10];
29444- int last_reg;
29445+ unsigned long last_reg;
29446
29447 if (regcomp
29448 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
29449diff -urNp linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_atombios.c linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_atombios.c
29450--- linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_atombios.c 2011-05-19 00:06:34.000000000 -0400
29451+++ linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_atombios.c 2011-05-22 19:36:31.000000000 -0400
29452@@ -545,6 +545,8 @@ bool radeon_get_atom_connector_info_from
29453 struct radeon_gpio_rec gpio;
29454 struct radeon_hpd hpd;
29455
29456+ pax_track_stack();
29457+
29458 if (!atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset))
29459 return false;
29460
29461diff -urNp linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_atpx_handler.c linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_atpx_handler.c
29462--- linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_atpx_handler.c 2011-05-19 00:06:34.000000000 -0400
29463+++ linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_atpx_handler.c 2011-05-22 19:36:31.000000000 -0400
29464@@ -234,7 +234,7 @@ static int radeon_atpx_get_client_id(str
29465 return VGA_SWITCHEROO_DIS;
29466 }
29467
29468-static struct vga_switcheroo_handler radeon_atpx_handler = {
29469+static const struct vga_switcheroo_handler radeon_atpx_handler = {
29470 .switchto = radeon_atpx_switchto,
29471 .power_state = radeon_atpx_power_state,
29472 .init = radeon_atpx_init,
29473diff -urNp linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_device.c linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_device.c
29474--- linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_device.c 2011-05-19 00:06:34.000000000 -0400
29475+++ linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_device.c 2011-05-22 19:36:31.000000000 -0400
29476@@ -674,7 +674,7 @@ static bool radeon_switcheroo_can_switch
29477 bool can_switch;
29478
29479 spin_lock(&dev->count_lock);
29480- can_switch = (dev->open_count == 0);
29481+ can_switch = (local_read(&dev->open_count) == 0);
29482 spin_unlock(&dev->count_lock);
29483 return can_switch;
29484 }
29485diff -urNp linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_display.c linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_display.c
29486--- linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_display.c 2011-05-19 00:06:34.000000000 -0400
29487+++ linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_display.c 2011-05-22 19:36:31.000000000 -0400
29488@@ -934,6 +934,8 @@ void radeon_compute_pll_legacy(struct ra
29489 uint32_t post_div;
29490 u32 pll_out_min, pll_out_max;
29491
29492+ pax_track_stack();
29493+
29494 DRM_DEBUG_KMS("PLL freq %llu %u %u\n", freq, pll->min_ref_div, pll->max_ref_div);
29495 freq = freq * 1000;
29496
29497diff -urNp linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_drv.h linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_drv.h
29498--- linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_drv.h 2011-05-19 00:06:34.000000000 -0400
29499+++ linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_drv.h 2011-05-22 19:36:31.000000000 -0400
29500@@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
29501
29502 /* SW interrupt */
29503 wait_queue_head_t swi_queue;
29504- atomic_t swi_emitted;
29505+ atomic_unchecked_t swi_emitted;
29506 int vblank_crtc;
29507 uint32_t irq_enable_reg;
29508 uint32_t r500_disp_irq_reg;
29509diff -urNp linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_fence.c linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_fence.c
29510--- linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_fence.c 2011-05-19 00:06:34.000000000 -0400
29511+++ linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_fence.c 2011-05-22 19:36:31.000000000 -0400
29512@@ -49,7 +49,7 @@ int radeon_fence_emit(struct radeon_devi
29513 write_unlock_irqrestore(&rdev->fence_drv.lock, irq_flags);
29514 return 0;
29515 }
29516- fence->seq = atomic_add_return(1, &rdev->fence_drv.seq);
29517+ fence->seq = atomic_add_return_unchecked(1, &rdev->fence_drv.seq);
29518 if (!rdev->cp.ready) {
29519 /* FIXME: cp is not running assume everythings is done right
29520 * away
29521@@ -352,7 +352,7 @@ int radeon_fence_driver_init(struct rade
29522 return r;
29523 }
29524 WREG32(rdev->fence_drv.scratch_reg, 0);
29525- atomic_set(&rdev->fence_drv.seq, 0);
29526+ atomic_set_unchecked(&rdev->fence_drv.seq, 0);
29527 INIT_LIST_HEAD(&rdev->fence_drv.created);
29528 INIT_LIST_HEAD(&rdev->fence_drv.emited);
29529 INIT_LIST_HEAD(&rdev->fence_drv.signaled);
29530diff -urNp linux-2.6.39.1/drivers/gpu/drm/radeon/radeon.h linux-2.6.39.1/drivers/gpu/drm/radeon/radeon.h
29531--- linux-2.6.39.1/drivers/gpu/drm/radeon/radeon.h 2011-05-19 00:06:34.000000000 -0400
29532+++ linux-2.6.39.1/drivers/gpu/drm/radeon/radeon.h 2011-05-22 19:36:31.000000000 -0400
29533@@ -189,7 +189,7 @@ extern int sumo_get_temp(struct radeon_d
29534 */
29535 struct radeon_fence_driver {
29536 uint32_t scratch_reg;
29537- atomic_t seq;
29538+ atomic_unchecked_t seq;
29539 uint32_t last_seq;
29540 unsigned long last_jiffies;
29541 unsigned long last_timeout;
29542diff -urNp linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_ioc32.c linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_ioc32.c
29543--- linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_ioc32.c 2011-05-19 00:06:34.000000000 -0400
29544+++ linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_ioc32.c 2011-05-22 19:36:31.000000000 -0400
29545@@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(str
29546 request = compat_alloc_user_space(sizeof(*request));
29547 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
29548 || __put_user(req32.param, &request->param)
29549- || __put_user((void __user *)(unsigned long)req32.value,
29550+ || __put_user((unsigned long)req32.value,
29551 &request->value))
29552 return -EFAULT;
29553
29554diff -urNp linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_irq.c linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_irq.c
29555--- linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_irq.c 2011-05-19 00:06:34.000000000 -0400
29556+++ linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_irq.c 2011-05-22 19:36:31.000000000 -0400
29557@@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_de
29558 unsigned int ret;
29559 RING_LOCALS;
29560
29561- atomic_inc(&dev_priv->swi_emitted);
29562- ret = atomic_read(&dev_priv->swi_emitted);
29563+ atomic_inc_unchecked(&dev_priv->swi_emitted);
29564+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
29565
29566 BEGIN_RING(4);
29567 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
29568@@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct
29569 drm_radeon_private_t *dev_priv =
29570 (drm_radeon_private_t *) dev->dev_private;
29571
29572- atomic_set(&dev_priv->swi_emitted, 0);
29573+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
29574 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
29575
29576 dev->max_vblank_count = 0x001fffff;
29577diff -urNp linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_state.c linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_state.c
29578--- linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_state.c 2011-05-19 00:06:34.000000000 -0400
29579+++ linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_state.c 2011-05-22 19:36:31.000000000 -0400
29580@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_de
29581 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
29582 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
29583
29584- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
29585+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
29586 sarea_priv->nbox * sizeof(depth_boxes[0])))
29587 return -EFAULT;
29588
29589@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm
29590 {
29591 drm_radeon_private_t *dev_priv = dev->dev_private;
29592 drm_radeon_getparam_t *param = data;
29593- int value;
29594+ int value = 0;
29595
29596 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
29597
29598diff -urNp linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_ttm.c linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_ttm.c
29599--- linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_ttm.c 2011-05-19 00:06:34.000000000 -0400
29600+++ linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_ttm.c 2011-05-22 19:36:31.000000000 -0400
29601@@ -603,8 +603,9 @@ void radeon_ttm_set_active_vram_size(str
29602 man->size = size >> PAGE_SHIFT;
29603 }
29604
29605-static struct vm_operations_struct radeon_ttm_vm_ops;
29606-static const struct vm_operations_struct *ttm_vm_ops = NULL;
29607+extern int ttm_bo_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf);
29608+extern void ttm_bo_vm_open(struct vm_area_struct *vma);
29609+extern void ttm_bo_vm_close(struct vm_area_struct *vma);
29610
29611 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
29612 {
29613@@ -612,17 +613,22 @@ static int radeon_ttm_fault(struct vm_ar
29614 struct radeon_device *rdev;
29615 int r;
29616
29617- bo = (struct ttm_buffer_object *)vma->vm_private_data;
29618- if (bo == NULL) {
29619+ bo = (struct ttm_buffer_object *)vma->vm_private_data;
29620+ if (!bo)
29621 return VM_FAULT_NOPAGE;
29622- }
29623 rdev = radeon_get_rdev(bo->bdev);
29624 mutex_lock(&rdev->vram_mutex);
29625- r = ttm_vm_ops->fault(vma, vmf);
29626+ r = ttm_bo_vm_fault(vma, vmf);
29627 mutex_unlock(&rdev->vram_mutex);
29628 return r;
29629 }
29630
29631+static const struct vm_operations_struct radeon_ttm_vm_ops = {
29632+ .fault = radeon_ttm_fault,
29633+ .open = ttm_bo_vm_open,
29634+ .close = ttm_bo_vm_close
29635+};
29636+
29637 int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
29638 {
29639 struct drm_file *file_priv;
29640@@ -635,18 +641,11 @@ int radeon_mmap(struct file *filp, struc
29641
29642 file_priv = filp->private_data;
29643 rdev = file_priv->minor->dev->dev_private;
29644- if (rdev == NULL) {
29645+ if (!rdev)
29646 return -EINVAL;
29647- }
29648 r = ttm_bo_mmap(filp, vma, &rdev->mman.bdev);
29649- if (unlikely(r != 0)) {
29650+ if (r)
29651 return r;
29652- }
29653- if (unlikely(ttm_vm_ops == NULL)) {
29654- ttm_vm_ops = vma->vm_ops;
29655- radeon_ttm_vm_ops = *ttm_vm_ops;
29656- radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
29657- }
29658 vma->vm_ops = &radeon_ttm_vm_ops;
29659 return 0;
29660 }
29661diff -urNp linux-2.6.39.1/drivers/gpu/drm/radeon/rs690.c linux-2.6.39.1/drivers/gpu/drm/radeon/rs690.c
29662--- linux-2.6.39.1/drivers/gpu/drm/radeon/rs690.c 2011-05-19 00:06:34.000000000 -0400
29663+++ linux-2.6.39.1/drivers/gpu/drm/radeon/rs690.c 2011-05-22 19:36:31.000000000 -0400
29664@@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct
29665 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
29666 rdev->pm.sideport_bandwidth.full)
29667 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
29668- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
29669+ read_delay_latency.full = dfixed_const(800 * 1000);
29670 read_delay_latency.full = dfixed_div(read_delay_latency,
29671 rdev->pm.igp_sideport_mclk);
29672+ a.full = dfixed_const(370);
29673+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
29674 } else {
29675 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
29676 rdev->pm.k8_bandwidth.full)
29677diff -urNp linux-2.6.39.1/drivers/gpu/drm/ttm/ttm_bo_vm.c linux-2.6.39.1/drivers/gpu/drm/ttm/ttm_bo_vm.c
29678--- linux-2.6.39.1/drivers/gpu/drm/ttm/ttm_bo_vm.c 2011-05-19 00:06:34.000000000 -0400
29679+++ linux-2.6.39.1/drivers/gpu/drm/ttm/ttm_bo_vm.c 2011-05-22 19:36:31.000000000 -0400
29680@@ -69,11 +69,11 @@ static struct ttm_buffer_object *ttm_bo_
29681 return best_bo;
29682 }
29683
29684-static int ttm_bo_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
29685+int ttm_bo_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
29686 {
29687 struct ttm_buffer_object *bo = (struct ttm_buffer_object *)
29688 vma->vm_private_data;
29689- struct ttm_bo_device *bdev = bo->bdev;
29690+ struct ttm_bo_device *bdev;
29691 unsigned long page_offset;
29692 unsigned long page_last;
29693 unsigned long pfn;
29694@@ -83,8 +83,12 @@ static int ttm_bo_vm_fault(struct vm_are
29695 int i;
29696 unsigned long address = (unsigned long)vmf->virtual_address;
29697 int retval = VM_FAULT_NOPAGE;
29698- struct ttm_mem_type_manager *man =
29699- &bdev->man[bo->mem.mem_type];
29700+ struct ttm_mem_type_manager *man;
29701+
29702+ if (!bo)
29703+ return VM_FAULT_NOPAGE;
29704+ bdev = bo->bdev;
29705+ man = &bdev->man[bo->mem.mem_type];
29706
29707 /*
29708 * Work around locking order reversal in fault / nopfn
29709@@ -219,22 +223,25 @@ out_unlock:
29710 ttm_bo_unreserve(bo);
29711 return retval;
29712 }
29713+EXPORT_SYMBOL(ttm_bo_vm_fault);
29714
29715-static void ttm_bo_vm_open(struct vm_area_struct *vma)
29716+void ttm_bo_vm_open(struct vm_area_struct *vma)
29717 {
29718 struct ttm_buffer_object *bo =
29719 (struct ttm_buffer_object *)vma->vm_private_data;
29720
29721 (void)ttm_bo_reference(bo);
29722 }
29723+EXPORT_SYMBOL(ttm_bo_vm_open);
29724
29725-static void ttm_bo_vm_close(struct vm_area_struct *vma)
29726+void ttm_bo_vm_close(struct vm_area_struct *vma)
29727 {
29728 struct ttm_buffer_object *bo = (struct ttm_buffer_object *)vma->vm_private_data;
29729
29730 ttm_bo_unref(&bo);
29731 vma->vm_private_data = NULL;
29732 }
29733+EXPORT_SYMBOL(ttm_bo_vm_close);
29734
29735 static const struct vm_operations_struct ttm_bo_vm_ops = {
29736 .fault = ttm_bo_vm_fault,
29737diff -urNp linux-2.6.39.1/drivers/gpu/drm/ttm/ttm_page_alloc.c linux-2.6.39.1/drivers/gpu/drm/ttm/ttm_page_alloc.c
29738--- linux-2.6.39.1/drivers/gpu/drm/ttm/ttm_page_alloc.c 2011-05-19 00:06:34.000000000 -0400
29739+++ linux-2.6.39.1/drivers/gpu/drm/ttm/ttm_page_alloc.c 2011-05-22 19:36:31.000000000 -0400
29740@@ -397,9 +397,9 @@ static int ttm_pool_get_num_unused_pages
29741 */
29742 static int ttm_pool_mm_shrink(struct shrinker *shrink, int shrink_pages, gfp_t gfp_mask)
29743 {
29744- static atomic_t start_pool = ATOMIC_INIT(0);
29745+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
29746 unsigned i;
29747- unsigned pool_offset = atomic_add_return(1, &start_pool);
29748+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
29749 struct ttm_page_pool *pool;
29750
29751 pool_offset = pool_offset % NUM_POOLS;
29752diff -urNp linux-2.6.39.1/drivers/gpu/drm/via/via_drv.h linux-2.6.39.1/drivers/gpu/drm/via/via_drv.h
29753--- linux-2.6.39.1/drivers/gpu/drm/via/via_drv.h 2011-05-19 00:06:34.000000000 -0400
29754+++ linux-2.6.39.1/drivers/gpu/drm/via/via_drv.h 2011-05-22 19:36:31.000000000 -0400
29755@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
29756 typedef uint32_t maskarray_t[5];
29757
29758 typedef struct drm_via_irq {
29759- atomic_t irq_received;
29760+ atomic_unchecked_t irq_received;
29761 uint32_t pending_mask;
29762 uint32_t enable_mask;
29763 wait_queue_head_t irq_queue;
29764@@ -75,7 +75,7 @@ typedef struct drm_via_private {
29765 struct timeval last_vblank;
29766 int last_vblank_valid;
29767 unsigned usec_per_vblank;
29768- atomic_t vbl_received;
29769+ atomic_unchecked_t vbl_received;
29770 drm_via_state_t hc_state;
29771 char pci_buf[VIA_PCI_BUF_SIZE];
29772 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
29773diff -urNp linux-2.6.39.1/drivers/gpu/drm/via/via_irq.c linux-2.6.39.1/drivers/gpu/drm/via/via_irq.c
29774--- linux-2.6.39.1/drivers/gpu/drm/via/via_irq.c 2011-05-19 00:06:34.000000000 -0400
29775+++ linux-2.6.39.1/drivers/gpu/drm/via/via_irq.c 2011-05-22 19:36:31.000000000 -0400
29776@@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_de
29777 if (crtc != 0)
29778 return 0;
29779
29780- return atomic_read(&dev_priv->vbl_received);
29781+ return atomic_read_unchecked(&dev_priv->vbl_received);
29782 }
29783
29784 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
29785@@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_I
29786
29787 status = VIA_READ(VIA_REG_INTERRUPT);
29788 if (status & VIA_IRQ_VBLANK_PENDING) {
29789- atomic_inc(&dev_priv->vbl_received);
29790- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
29791+ atomic_inc_unchecked(&dev_priv->vbl_received);
29792+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
29793 do_gettimeofday(&cur_vblank);
29794 if (dev_priv->last_vblank_valid) {
29795 dev_priv->usec_per_vblank =
29796@@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_I
29797 dev_priv->last_vblank = cur_vblank;
29798 dev_priv->last_vblank_valid = 1;
29799 }
29800- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
29801+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
29802 DRM_DEBUG("US per vblank is: %u\n",
29803 dev_priv->usec_per_vblank);
29804 }
29805@@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_I
29806
29807 for (i = 0; i < dev_priv->num_irqs; ++i) {
29808 if (status & cur_irq->pending_mask) {
29809- atomic_inc(&cur_irq->irq_received);
29810+ atomic_inc_unchecked(&cur_irq->irq_received);
29811 DRM_WAKEUP(&cur_irq->irq_queue);
29812 handled = 1;
29813 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
29814@@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *d
29815 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
29816 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
29817 masks[irq][4]));
29818- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
29819+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
29820 } else {
29821 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
29822 (((cur_irq_sequence =
29823- atomic_read(&cur_irq->irq_received)) -
29824+ atomic_read_unchecked(&cur_irq->irq_received)) -
29825 *sequence) <= (1 << 23)));
29826 }
29827 *sequence = cur_irq_sequence;
29828@@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct dr
29829 }
29830
29831 for (i = 0; i < dev_priv->num_irqs; ++i) {
29832- atomic_set(&cur_irq->irq_received, 0);
29833+ atomic_set_unchecked(&cur_irq->irq_received, 0);
29834 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
29835 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
29836 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
29837@@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev,
29838 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
29839 case VIA_IRQ_RELATIVE:
29840 irqwait->request.sequence +=
29841- atomic_read(&cur_irq->irq_received);
29842+ atomic_read_unchecked(&cur_irq->irq_received);
29843 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
29844 case VIA_IRQ_ABSOLUTE:
29845 break;
29846diff -urNp linux-2.6.39.1/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h linux-2.6.39.1/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
29847--- linux-2.6.39.1/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h 2011-05-19 00:06:34.000000000 -0400
29848+++ linux-2.6.39.1/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h 2011-05-22 19:36:31.000000000 -0400
29849@@ -240,7 +240,7 @@ struct vmw_private {
29850 * Fencing and IRQs.
29851 */
29852
29853- atomic_t fence_seq;
29854+ atomic_unchecked_t fence_seq;
29855 wait_queue_head_t fence_queue;
29856 wait_queue_head_t fifo_queue;
29857 atomic_t fence_queue_waiters;
29858diff -urNp linux-2.6.39.1/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c linux-2.6.39.1/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c
29859--- linux-2.6.39.1/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c 2011-05-19 00:06:34.000000000 -0400
29860+++ linux-2.6.39.1/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c 2011-05-22 19:36:31.000000000 -0400
29861@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev
29862 while (!vmw_lag_lt(queue, us)) {
29863 spin_lock(&queue->lock);
29864 if (list_empty(&queue->head))
29865- sequence = atomic_read(&dev_priv->fence_seq);
29866+ sequence = atomic_read_unchecked(&dev_priv->fence_seq);
29867 else {
29868 fence = list_first_entry(&queue->head,
29869 struct vmw_fence, head);
29870diff -urNp linux-2.6.39.1/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c linux-2.6.39.1/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
29871--- linux-2.6.39.1/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c 2011-05-19 00:06:34.000000000 -0400
29872+++ linux-2.6.39.1/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c 2011-05-22 19:36:31.000000000 -0400
29873@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *de
29874 (unsigned int) min,
29875 (unsigned int) fifo->capabilities);
29876
29877- atomic_set(&dev_priv->fence_seq, dev_priv->last_read_sequence);
29878+ atomic_set_unchecked(&dev_priv->fence_seq, dev_priv->last_read_sequence);
29879 iowrite32(dev_priv->last_read_sequence, fifo_mem + SVGA_FIFO_FENCE);
29880 vmw_fence_queue_init(&fifo->fence_queue);
29881 return vmw_fifo_send_fence(dev_priv, &dummy);
29882@@ -476,7 +476,7 @@ int vmw_fifo_send_fence(struct vmw_priva
29883
29884 fm = vmw_fifo_reserve(dev_priv, bytes);
29885 if (unlikely(fm == NULL)) {
29886- *sequence = atomic_read(&dev_priv->fence_seq);
29887+ *sequence = atomic_read_unchecked(&dev_priv->fence_seq);
29888 ret = -ENOMEM;
29889 (void)vmw_fallback_wait(dev_priv, false, true, *sequence,
29890 false, 3*HZ);
29891@@ -484,7 +484,7 @@ int vmw_fifo_send_fence(struct vmw_priva
29892 }
29893
29894 do {
29895- *sequence = atomic_add_return(1, &dev_priv->fence_seq);
29896+ *sequence = atomic_add_return_unchecked(1, &dev_priv->fence_seq);
29897 } while (*sequence == 0);
29898
29899 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
29900@@ -534,7 +534,7 @@ static int vmw_fifo_vm_fault(struct vm_a
29901 return VM_FAULT_SIGBUS;
29902 }
29903
29904-static struct vm_operations_struct vmw_fifo_vm_ops = {
29905+static const struct vm_operations_struct vmw_fifo_vm_ops = {
29906 .fault = vmw_fifo_vm_fault,
29907 .open = NULL,
29908 .close = NULL
29909diff -urNp linux-2.6.39.1/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c linux-2.6.39.1/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
29910--- linux-2.6.39.1/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c 2011-05-19 00:06:34.000000000 -0400
29911+++ linux-2.6.39.1/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c 2011-05-22 19:36:31.000000000 -0400
29912@@ -100,7 +100,7 @@ bool vmw_fence_signaled(struct vmw_priva
29913 * emitted. Then the fence is stale and signaled.
29914 */
29915
29916- ret = ((atomic_read(&dev_priv->fence_seq) - sequence)
29917+ ret = ((atomic_read_unchecked(&dev_priv->fence_seq) - sequence)
29918 > VMW_FENCE_WRAP);
29919
29920 return ret;
29921@@ -131,7 +131,7 @@ int vmw_fallback_wait(struct vmw_private
29922
29923 if (fifo_idle)
29924 down_read(&fifo_state->rwsem);
29925- signal_seq = atomic_read(&dev_priv->fence_seq);
29926+ signal_seq = atomic_read_unchecked(&dev_priv->fence_seq);
29927 ret = 0;
29928
29929 for (;;) {
29930diff -urNp linux-2.6.39.1/drivers/gpu/vga/vga_switcheroo.c linux-2.6.39.1/drivers/gpu/vga/vga_switcheroo.c
29931--- linux-2.6.39.1/drivers/gpu/vga/vga_switcheroo.c 2011-05-19 00:06:34.000000000 -0400
29932+++ linux-2.6.39.1/drivers/gpu/vga/vga_switcheroo.c 2011-05-22 19:36:31.000000000 -0400
29933@@ -53,7 +53,7 @@ struct vgasr_priv {
29934 int registered_clients;
29935 struct vga_switcheroo_client clients[VGA_SWITCHEROO_MAX_CLIENTS];
29936
29937- struct vga_switcheroo_handler *handler;
29938+ const struct vga_switcheroo_handler *handler;
29939 };
29940
29941 static int vga_switcheroo_debugfs_init(struct vgasr_priv *priv);
29942@@ -62,7 +62,7 @@ static void vga_switcheroo_debugfs_fini(
29943 /* only one switcheroo per system */
29944 static struct vgasr_priv vgasr_priv;
29945
29946-int vga_switcheroo_register_handler(struct vga_switcheroo_handler *handler)
29947+int vga_switcheroo_register_handler(const struct vga_switcheroo_handler *handler)
29948 {
29949 mutex_lock(&vgasr_mutex);
29950 if (vgasr_priv.handler) {
29951diff -urNp linux-2.6.39.1/drivers/hid/hid-core.c linux-2.6.39.1/drivers/hid/hid-core.c
29952--- linux-2.6.39.1/drivers/hid/hid-core.c 2011-05-19 00:06:34.000000000 -0400
29953+++ linux-2.6.39.1/drivers/hid/hid-core.c 2011-05-22 19:36:31.000000000 -0400
29954@@ -1888,7 +1888,7 @@ static bool hid_ignore(struct hid_device
29955
29956 int hid_add_device(struct hid_device *hdev)
29957 {
29958- static atomic_t id = ATOMIC_INIT(0);
29959+ static atomic_unchecked_t id = ATOMIC_INIT(0);
29960 int ret;
29961
29962 if (WARN_ON(hdev->status & HID_STAT_ADDED))
29963@@ -1903,7 +1903,7 @@ int hid_add_device(struct hid_device *hd
29964 /* XXX hack, any other cleaner solution after the driver core
29965 * is converted to allow more than 20 bytes as the device name? */
29966 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
29967- hdev->vendor, hdev->product, atomic_inc_return(&id));
29968+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
29969
29970 hid_debug_register(hdev, dev_name(&hdev->dev));
29971 ret = device_add(&hdev->dev);
29972diff -urNp linux-2.6.39.1/drivers/hid/hid-picolcd.c linux-2.6.39.1/drivers/hid/hid-picolcd.c
29973--- linux-2.6.39.1/drivers/hid/hid-picolcd.c 2011-05-19 00:06:34.000000000 -0400
29974+++ linux-2.6.39.1/drivers/hid/hid-picolcd.c 2011-05-22 19:36:31.000000000 -0400
29975@@ -1037,7 +1037,7 @@ static int picolcd_check_lcd_fb(struct l
29976 return fb && fb == picolcd_fbinfo((struct picolcd_data *)lcd_get_data(ldev));
29977 }
29978
29979-static struct lcd_ops picolcd_lcdops = {
29980+static const struct lcd_ops picolcd_lcdops = {
29981 .get_contrast = picolcd_get_contrast,
29982 .set_contrast = picolcd_set_contrast,
29983 .check_fb = picolcd_check_lcd_fb,
29984diff -urNp linux-2.6.39.1/drivers/hid/usbhid/hiddev.c linux-2.6.39.1/drivers/hid/usbhid/hiddev.c
29985--- linux-2.6.39.1/drivers/hid/usbhid/hiddev.c 2011-05-19 00:06:34.000000000 -0400
29986+++ linux-2.6.39.1/drivers/hid/usbhid/hiddev.c 2011-05-22 19:36:31.000000000 -0400
29987@@ -613,7 +613,7 @@ static long hiddev_ioctl(struct file *fi
29988 break;
29989
29990 case HIDIOCAPPLICATION:
29991- if (arg < 0 || arg >= hid->maxapplication)
29992+ if (arg >= hid->maxapplication)
29993 break;
29994
29995 for (i = 0; i < hid->maxcollection; i++)
29996diff -urNp linux-2.6.39.1/drivers/hwmon/ibmaem.c linux-2.6.39.1/drivers/hwmon/ibmaem.c
29997--- linux-2.6.39.1/drivers/hwmon/ibmaem.c 2011-05-19 00:06:34.000000000 -0400
29998+++ linux-2.6.39.1/drivers/hwmon/ibmaem.c 2011-05-22 19:36:31.000000000 -0400
29999@@ -238,7 +238,7 @@ struct aem_read_sensor_resp {
30000 struct aem_driver_data {
30001 struct list_head aem_devices;
30002 struct ipmi_smi_watcher bmc_events;
30003- struct ipmi_user_hndl ipmi_hndlrs;
30004+ const struct ipmi_user_hndl ipmi_hndlrs;
30005 };
30006
30007 static void aem_register_bmc(int iface, struct device *dev);
30008diff -urNp linux-2.6.39.1/drivers/hwmon/ibmpex.c linux-2.6.39.1/drivers/hwmon/ibmpex.c
30009--- linux-2.6.39.1/drivers/hwmon/ibmpex.c 2011-05-19 00:06:34.000000000 -0400
30010+++ linux-2.6.39.1/drivers/hwmon/ibmpex.c 2011-05-22 19:36:31.000000000 -0400
30011@@ -110,7 +110,7 @@ struct ibmpex_bmc_data {
30012 struct ibmpex_driver_data {
30013 struct list_head bmc_data;
30014 struct ipmi_smi_watcher bmc_events;
30015- struct ipmi_user_hndl ipmi_hndlrs;
30016+ const struct ipmi_user_hndl ipmi_hndlrs;
30017 };
30018
30019 static struct ibmpex_driver_data driver_data = {
30020diff -urNp linux-2.6.39.1/drivers/hwmon/sht15.c linux-2.6.39.1/drivers/hwmon/sht15.c
30021--- linux-2.6.39.1/drivers/hwmon/sht15.c 2011-05-19 00:06:34.000000000 -0400
30022+++ linux-2.6.39.1/drivers/hwmon/sht15.c 2011-05-22 19:36:31.000000000 -0400
30023@@ -113,7 +113,7 @@ struct sht15_data {
30024 int supply_uV;
30025 int supply_uV_valid;
30026 struct work_struct update_supply_work;
30027- atomic_t interrupt_handled;
30028+ atomic_unchecked_t interrupt_handled;
30029 };
30030
30031 /**
30032@@ -246,13 +246,13 @@ static inline int sht15_update_single_va
30033 return ret;
30034
30035 gpio_direction_input(data->pdata->gpio_data);
30036- atomic_set(&data->interrupt_handled, 0);
30037+ atomic_set_unchecked(&data->interrupt_handled, 0);
30038
30039 enable_irq(gpio_to_irq(data->pdata->gpio_data));
30040 if (gpio_get_value(data->pdata->gpio_data) == 0) {
30041 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
30042 /* Only relevant if the interrupt hasn't occurred. */
30043- if (!atomic_read(&data->interrupt_handled))
30044+ if (!atomic_read_unchecked(&data->interrupt_handled))
30045 schedule_work(&data->read_work);
30046 }
30047 ret = wait_event_timeout(data->wait_queue,
30048@@ -399,7 +399,7 @@ static irqreturn_t sht15_interrupt_fired
30049 struct sht15_data *data = d;
30050 /* First disable the interrupt */
30051 disable_irq_nosync(irq);
30052- atomic_inc(&data->interrupt_handled);
30053+ atomic_inc_unchecked(&data->interrupt_handled);
30054 /* Then schedule a reading work struct */
30055 if (data->flag != SHT15_READING_NOTHING)
30056 schedule_work(&data->read_work);
30057@@ -450,11 +450,11 @@ static void sht15_bh_read_data(struct wo
30058 here as could have gone low in meantime so verify
30059 it hasn't!
30060 */
30061- atomic_set(&data->interrupt_handled, 0);
30062+ atomic_set_unchecked(&data->interrupt_handled, 0);
30063 enable_irq(gpio_to_irq(data->pdata->gpio_data));
30064 /* If still not occurred or another handler has been scheduled */
30065 if (gpio_get_value(data->pdata->gpio_data)
30066- || atomic_read(&data->interrupt_handled))
30067+ || atomic_read_unchecked(&data->interrupt_handled))
30068 return;
30069 }
30070 /* Read the data back from the device */
30071diff -urNp linux-2.6.39.1/drivers/hwmon/w83791d.c linux-2.6.39.1/drivers/hwmon/w83791d.c
30072--- linux-2.6.39.1/drivers/hwmon/w83791d.c 2011-05-19 00:06:34.000000000 -0400
30073+++ linux-2.6.39.1/drivers/hwmon/w83791d.c 2011-05-22 19:36:31.000000000 -0400
30074@@ -329,8 +329,8 @@ static int w83791d_detect(struct i2c_cli
30075 struct i2c_board_info *info);
30076 static int w83791d_remove(struct i2c_client *client);
30077
30078-static int w83791d_read(struct i2c_client *client, u8 register);
30079-static int w83791d_write(struct i2c_client *client, u8 register, u8 value);
30080+static int w83791d_read(struct i2c_client *client, u8 reg);
30081+static int w83791d_write(struct i2c_client *client, u8 reg, u8 value);
30082 static struct w83791d_data *w83791d_update_device(struct device *dev);
30083
30084 #ifdef DEBUG
30085diff -urNp linux-2.6.39.1/drivers/i2c/busses/i2c-at91.c linux-2.6.39.1/drivers/i2c/busses/i2c-at91.c
30086--- linux-2.6.39.1/drivers/i2c/busses/i2c-at91.c 2011-05-19 00:06:34.000000000 -0400
30087+++ linux-2.6.39.1/drivers/i2c/busses/i2c-at91.c 2011-05-22 19:36:31.000000000 -0400
30088@@ -181,7 +181,7 @@ static u32 at91_func(struct i2c_adapter
30089 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
30090 }
30091
30092-static struct i2c_algorithm at91_algorithm = {
30093+static const struct i2c_algorithm at91_algorithm = {
30094 .master_xfer = at91_xfer,
30095 .functionality = at91_func,
30096 };
30097diff -urNp linux-2.6.39.1/drivers/i2c/busses/i2c-bfin-twi.c linux-2.6.39.1/drivers/i2c/busses/i2c-bfin-twi.c
30098--- linux-2.6.39.1/drivers/i2c/busses/i2c-bfin-twi.c 2011-05-19 00:06:34.000000000 -0400
30099+++ linux-2.6.39.1/drivers/i2c/busses/i2c-bfin-twi.c 2011-05-22 19:36:31.000000000 -0400
30100@@ -599,7 +599,7 @@ static u32 bfin_twi_functionality(struct
30101 I2C_FUNC_I2C | I2C_FUNC_SMBUS_I2C_BLOCK;
30102 }
30103
30104-static struct i2c_algorithm bfin_twi_algorithm = {
30105+static const struct i2c_algorithm bfin_twi_algorithm = {
30106 .master_xfer = bfin_twi_master_xfer,
30107 .smbus_xfer = bfin_twi_smbus_xfer,
30108 .functionality = bfin_twi_functionality,
30109diff -urNp linux-2.6.39.1/drivers/i2c/busses/i2c-davinci.c linux-2.6.39.1/drivers/i2c/busses/i2c-davinci.c
30110--- linux-2.6.39.1/drivers/i2c/busses/i2c-davinci.c 2011-05-19 00:06:34.000000000 -0400
30111+++ linux-2.6.39.1/drivers/i2c/busses/i2c-davinci.c 2011-05-22 19:36:31.000000000 -0400
30112@@ -630,7 +630,7 @@ static inline void i2c_davinci_cpufreq_d
30113 }
30114 #endif
30115
30116-static struct i2c_algorithm i2c_davinci_algo = {
30117+static const struct i2c_algorithm i2c_davinci_algo = {
30118 .master_xfer = i2c_davinci_xfer,
30119 .functionality = i2c_davinci_func,
30120 };
30121diff -urNp linux-2.6.39.1/drivers/i2c/busses/i2c-designware.c linux-2.6.39.1/drivers/i2c/busses/i2c-designware.c
30122--- linux-2.6.39.1/drivers/i2c/busses/i2c-designware.c 2011-05-19 00:06:34.000000000 -0400
30123+++ linux-2.6.39.1/drivers/i2c/busses/i2c-designware.c 2011-05-22 19:36:31.000000000 -0400
30124@@ -689,7 +689,7 @@ tx_aborted:
30125 return IRQ_HANDLED;
30126 }
30127
30128-static struct i2c_algorithm i2c_dw_algo = {
30129+static const struct i2c_algorithm i2c_dw_algo = {
30130 .master_xfer = i2c_dw_xfer,
30131 .functionality = i2c_dw_func,
30132 };
30133diff -urNp linux-2.6.39.1/drivers/i2c/busses/i2c-eg20t.c linux-2.6.39.1/drivers/i2c/busses/i2c-eg20t.c
30134--- linux-2.6.39.1/drivers/i2c/busses/i2c-eg20t.c 2011-05-19 00:06:34.000000000 -0400
30135+++ linux-2.6.39.1/drivers/i2c/busses/i2c-eg20t.c 2011-05-22 19:36:31.000000000 -0400
30136@@ -708,7 +708,7 @@ static u32 pch_i2c_func(struct i2c_adapt
30137 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR;
30138 }
30139
30140-static struct i2c_algorithm pch_algorithm = {
30141+static const struct i2c_algorithm pch_algorithm = {
30142 .master_xfer = pch_i2c_xfer,
30143 .functionality = pch_i2c_func
30144 };
30145diff -urNp linux-2.6.39.1/drivers/i2c/busses/i2c-imx.c linux-2.6.39.1/drivers/i2c/busses/i2c-imx.c
30146--- linux-2.6.39.1/drivers/i2c/busses/i2c-imx.c 2011-05-19 00:06:34.000000000 -0400
30147+++ linux-2.6.39.1/drivers/i2c/busses/i2c-imx.c 2011-05-22 19:36:31.000000000 -0400
30148@@ -457,7 +457,7 @@ static u32 i2c_imx_func(struct i2c_adapt
30149 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
30150 }
30151
30152-static struct i2c_algorithm i2c_imx_algo = {
30153+static const struct i2c_algorithm i2c_imx_algo = {
30154 .master_xfer = i2c_imx_xfer,
30155 .functionality = i2c_imx_func,
30156 };
30157diff -urNp linux-2.6.39.1/drivers/i2c/busses/i2c-intel-mid.c linux-2.6.39.1/drivers/i2c/busses/i2c-intel-mid.c
30158--- linux-2.6.39.1/drivers/i2c/busses/i2c-intel-mid.c 2011-05-19 00:06:34.000000000 -0400
30159+++ linux-2.6.39.1/drivers/i2c/busses/i2c-intel-mid.c 2011-05-22 19:36:31.000000000 -0400
30160@@ -917,7 +917,7 @@ err:
30161 return IRQ_HANDLED;
30162 }
30163
30164-static struct i2c_algorithm intel_mid_i2c_algorithm = {
30165+static const struct i2c_algorithm intel_mid_i2c_algorithm = {
30166 .master_xfer = intel_mid_i2c_xfer,
30167 .functionality = intel_mid_i2c_func,
30168 };
30169diff -urNp linux-2.6.39.1/drivers/i2c/busses/i2c-nforce2.c linux-2.6.39.1/drivers/i2c/busses/i2c-nforce2.c
30170--- linux-2.6.39.1/drivers/i2c/busses/i2c-nforce2.c 2011-05-19 00:06:34.000000000 -0400
30171+++ linux-2.6.39.1/drivers/i2c/busses/i2c-nforce2.c 2011-05-22 19:36:31.000000000 -0400
30172@@ -303,7 +303,7 @@ static u32 nforce2_func(struct i2c_adapt
30173 I2C_FUNC_SMBUS_BLOCK_DATA : 0);
30174 }
30175
30176-static struct i2c_algorithm smbus_algorithm = {
30177+static const struct i2c_algorithm smbus_algorithm = {
30178 .smbus_xfer = nforce2_access,
30179 .functionality = nforce2_func,
30180 };
30181diff -urNp linux-2.6.39.1/drivers/i2c/busses/i2c-pmcmsp.c linux-2.6.39.1/drivers/i2c/busses/i2c-pmcmsp.c
30182--- linux-2.6.39.1/drivers/i2c/busses/i2c-pmcmsp.c 2011-05-19 00:06:34.000000000 -0400
30183+++ linux-2.6.39.1/drivers/i2c/busses/i2c-pmcmsp.c 2011-05-22 19:36:31.000000000 -0400
30184@@ -615,7 +615,7 @@ static u32 pmcmsptwi_i2c_func(struct i2c
30185
30186 /* -- Initialization -- */
30187
30188-static struct i2c_algorithm pmcmsptwi_algo = {
30189+static const struct i2c_algorithm pmcmsptwi_algo = {
30190 .master_xfer = pmcmsptwi_master_xfer,
30191 .functionality = pmcmsptwi_i2c_func,
30192 };
30193diff -urNp linux-2.6.39.1/drivers/i2c/busses/i2c-pnx.c linux-2.6.39.1/drivers/i2c/busses/i2c-pnx.c
30194--- linux-2.6.39.1/drivers/i2c/busses/i2c-pnx.c 2011-05-19 00:06:34.000000000 -0400
30195+++ linux-2.6.39.1/drivers/i2c/busses/i2c-pnx.c 2011-05-22 19:36:31.000000000 -0400
30196@@ -535,7 +535,7 @@ static u32 i2c_pnx_func(struct i2c_adapt
30197 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
30198 }
30199
30200-static struct i2c_algorithm pnx_algorithm = {
30201+static const struct i2c_algorithm pnx_algorithm = {
30202 .master_xfer = i2c_pnx_xfer,
30203 .functionality = i2c_pnx_func,
30204 };
30205diff -urNp linux-2.6.39.1/drivers/i2c/busses/i2c-puv3.c linux-2.6.39.1/drivers/i2c/busses/i2c-puv3.c
30206--- linux-2.6.39.1/drivers/i2c/busses/i2c-puv3.c 2011-05-19 00:06:34.000000000 -0400
30207+++ linux-2.6.39.1/drivers/i2c/busses/i2c-puv3.c 2011-05-22 19:36:31.000000000 -0400
30208@@ -176,7 +176,7 @@ static u32 puv3_i2c_func(struct i2c_adap
30209 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
30210 }
30211
30212-static struct i2c_algorithm puv3_i2c_algorithm = {
30213+static const struct i2c_algorithm puv3_i2c_algorithm = {
30214 .master_xfer = puv3_i2c_xfer,
30215 .functionality = puv3_i2c_func,
30216 };
30217diff -urNp linux-2.6.39.1/drivers/i2c/busses/i2c-s6000.c linux-2.6.39.1/drivers/i2c/busses/i2c-s6000.c
30218--- linux-2.6.39.1/drivers/i2c/busses/i2c-s6000.c 2011-05-19 00:06:34.000000000 -0400
30219+++ linux-2.6.39.1/drivers/i2c/busses/i2c-s6000.c 2011-05-22 19:36:31.000000000 -0400
30220@@ -243,7 +243,7 @@ static u32 s6i2c_functionality(struct i2
30221 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
30222 }
30223
30224-static struct i2c_algorithm s6i2c_algorithm = {
30225+static const struct i2c_algorithm s6i2c_algorithm = {
30226 .master_xfer = s6i2c_master_xfer,
30227 .functionality = s6i2c_functionality,
30228 };
30229diff -urNp linux-2.6.39.1/drivers/i2c/busses/i2c-sh_mobile.c linux-2.6.39.1/drivers/i2c/busses/i2c-sh_mobile.c
30230--- linux-2.6.39.1/drivers/i2c/busses/i2c-sh_mobile.c 2011-05-19 00:06:34.000000000 -0400
30231+++ linux-2.6.39.1/drivers/i2c/busses/i2c-sh_mobile.c 2011-05-22 19:36:31.000000000 -0400
30232@@ -529,7 +529,7 @@ static u32 sh_mobile_i2c_func(struct i2c
30233 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
30234 }
30235
30236-static struct i2c_algorithm sh_mobile_i2c_algorithm = {
30237+static const struct i2c_algorithm sh_mobile_i2c_algorithm = {
30238 .functionality = sh_mobile_i2c_func,
30239 .master_xfer = sh_mobile_i2c_xfer,
30240 };
30241diff -urNp linux-2.6.39.1/drivers/ide/ide-cd.c linux-2.6.39.1/drivers/ide/ide-cd.c
30242--- linux-2.6.39.1/drivers/ide/ide-cd.c 2011-06-03 00:04:14.000000000 -0400
30243+++ linux-2.6.39.1/drivers/ide/ide-cd.c 2011-06-03 00:32:05.000000000 -0400
30244@@ -769,7 +769,7 @@ static void cdrom_do_block_pc(ide_drive_
30245 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
30246 if ((unsigned long)buf & alignment
30247 || blk_rq_bytes(rq) & q->dma_pad_mask
30248- || object_is_on_stack(buf))
30249+ || object_starts_on_stack(buf))
30250 drive->dma = 0;
30251 }
30252 }
30253diff -urNp linux-2.6.39.1/drivers/ide/ide-floppy.c linux-2.6.39.1/drivers/ide/ide-floppy.c
30254--- linux-2.6.39.1/drivers/ide/ide-floppy.c 2011-05-19 00:06:34.000000000 -0400
30255+++ linux-2.6.39.1/drivers/ide/ide-floppy.c 2011-05-22 19:36:31.000000000 -0400
30256@@ -379,6 +379,8 @@ static int ide_floppy_get_capacity(ide_d
30257 u8 pc_buf[256], header_len, desc_cnt;
30258 int i, rc = 1, blocks, length;
30259
30260+ pax_track_stack();
30261+
30262 ide_debug_log(IDE_DBG_FUNC, "enter");
30263
30264 drive->bios_cyl = 0;
30265diff -urNp linux-2.6.39.1/drivers/ide/it821x.c linux-2.6.39.1/drivers/ide/it821x.c
30266--- linux-2.6.39.1/drivers/ide/it821x.c 2011-05-19 00:06:34.000000000 -0400
30267+++ linux-2.6.39.1/drivers/ide/it821x.c 2011-05-22 19:36:31.000000000 -0400
30268@@ -508,7 +508,7 @@ static void it821x_quirkproc(ide_drive_t
30269
30270 }
30271
30272-static struct ide_dma_ops it821x_pass_through_dma_ops = {
30273+static const struct ide_dma_ops it821x_pass_through_dma_ops = {
30274 .dma_host_set = ide_dma_host_set,
30275 .dma_setup = ide_dma_setup,
30276 .dma_start = it821x_dma_start,
30277diff -urNp linux-2.6.39.1/drivers/ide/setup-pci.c linux-2.6.39.1/drivers/ide/setup-pci.c
30278--- linux-2.6.39.1/drivers/ide/setup-pci.c 2011-05-19 00:06:34.000000000 -0400
30279+++ linux-2.6.39.1/drivers/ide/setup-pci.c 2011-05-22 19:36:31.000000000 -0400
30280@@ -542,6 +542,8 @@ int ide_pci_init_two(struct pci_dev *dev
30281 int ret, i, n_ports = dev2 ? 4 : 2;
30282 struct ide_hw hw[4], *hws[] = { NULL, NULL, NULL, NULL };
30283
30284+ pax_track_stack();
30285+
30286 for (i = 0; i < n_ports / 2; i++) {
30287 ret = ide_setup_pci_controller(pdev[i], d, !i);
30288 if (ret < 0)
30289diff -urNp linux-2.6.39.1/drivers/ide/trm290.c linux-2.6.39.1/drivers/ide/trm290.c
30290--- linux-2.6.39.1/drivers/ide/trm290.c 2011-05-19 00:06:34.000000000 -0400
30291+++ linux-2.6.39.1/drivers/ide/trm290.c 2011-05-22 19:36:31.000000000 -0400
30292@@ -314,7 +314,7 @@ static const struct ide_tp_ops trm290_tp
30293 .output_data = ide_output_data,
30294 };
30295
30296-static struct ide_dma_ops trm290_dma_ops = {
30297+static const struct ide_dma_ops trm290_dma_ops = {
30298 .dma_host_set = trm290_dma_host_set,
30299 .dma_setup = trm290_dma_setup,
30300 .dma_start = trm290_dma_start,
30301diff -urNp linux-2.6.39.1/drivers/infiniband/core/cm.c linux-2.6.39.1/drivers/infiniband/core/cm.c
30302--- linux-2.6.39.1/drivers/infiniband/core/cm.c 2011-05-19 00:06:34.000000000 -0400
30303+++ linux-2.6.39.1/drivers/infiniband/core/cm.c 2011-05-22 19:36:31.000000000 -0400
30304@@ -113,7 +113,7 @@ static char const counter_group_names[CM
30305
30306 struct cm_counter_group {
30307 struct kobject obj;
30308- atomic_long_t counter[CM_ATTR_COUNT];
30309+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
30310 };
30311
30312 struct cm_counter_attribute {
30313@@ -1387,7 +1387,7 @@ static void cm_dup_req_handler(struct cm
30314 struct ib_mad_send_buf *msg = NULL;
30315 int ret;
30316
30317- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30318+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30319 counter[CM_REQ_COUNTER]);
30320
30321 /* Quick state check to discard duplicate REQs. */
30322@@ -1765,7 +1765,7 @@ static void cm_dup_rep_handler(struct cm
30323 if (!cm_id_priv)
30324 return;
30325
30326- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30327+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30328 counter[CM_REP_COUNTER]);
30329 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
30330 if (ret)
30331@@ -1932,7 +1932,7 @@ static int cm_rtu_handler(struct cm_work
30332 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
30333 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
30334 spin_unlock_irq(&cm_id_priv->lock);
30335- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30336+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30337 counter[CM_RTU_COUNTER]);
30338 goto out;
30339 }
30340@@ -2115,7 +2115,7 @@ static int cm_dreq_handler(struct cm_wor
30341 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
30342 dreq_msg->local_comm_id);
30343 if (!cm_id_priv) {
30344- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30345+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30346 counter[CM_DREQ_COUNTER]);
30347 cm_issue_drep(work->port, work->mad_recv_wc);
30348 return -EINVAL;
30349@@ -2140,7 +2140,7 @@ static int cm_dreq_handler(struct cm_wor
30350 case IB_CM_MRA_REP_RCVD:
30351 break;
30352 case IB_CM_TIMEWAIT:
30353- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30354+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30355 counter[CM_DREQ_COUNTER]);
30356 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
30357 goto unlock;
30358@@ -2154,7 +2154,7 @@ static int cm_dreq_handler(struct cm_wor
30359 cm_free_msg(msg);
30360 goto deref;
30361 case IB_CM_DREQ_RCVD:
30362- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30363+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30364 counter[CM_DREQ_COUNTER]);
30365 goto unlock;
30366 default:
30367@@ -2521,7 +2521,7 @@ static int cm_mra_handler(struct cm_work
30368 ib_modify_mad(cm_id_priv->av.port->mad_agent,
30369 cm_id_priv->msg, timeout)) {
30370 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
30371- atomic_long_inc(&work->port->
30372+ atomic_long_inc_unchecked(&work->port->
30373 counter_group[CM_RECV_DUPLICATES].
30374 counter[CM_MRA_COUNTER]);
30375 goto out;
30376@@ -2530,7 +2530,7 @@ static int cm_mra_handler(struct cm_work
30377 break;
30378 case IB_CM_MRA_REQ_RCVD:
30379 case IB_CM_MRA_REP_RCVD:
30380- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30381+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30382 counter[CM_MRA_COUNTER]);
30383 /* fall through */
30384 default:
30385@@ -2692,7 +2692,7 @@ static int cm_lap_handler(struct cm_work
30386 case IB_CM_LAP_IDLE:
30387 break;
30388 case IB_CM_MRA_LAP_SENT:
30389- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30390+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30391 counter[CM_LAP_COUNTER]);
30392 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
30393 goto unlock;
30394@@ -2708,7 +2708,7 @@ static int cm_lap_handler(struct cm_work
30395 cm_free_msg(msg);
30396 goto deref;
30397 case IB_CM_LAP_RCVD:
30398- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30399+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30400 counter[CM_LAP_COUNTER]);
30401 goto unlock;
30402 default:
30403@@ -2992,7 +2992,7 @@ static int cm_sidr_req_handler(struct cm
30404 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
30405 if (cur_cm_id_priv) {
30406 spin_unlock_irq(&cm.lock);
30407- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30408+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30409 counter[CM_SIDR_REQ_COUNTER]);
30410 goto out; /* Duplicate message. */
30411 }
30412@@ -3204,10 +3204,10 @@ static void cm_send_handler(struct ib_ma
30413 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
30414 msg->retries = 1;
30415
30416- atomic_long_add(1 + msg->retries,
30417+ atomic_long_add_unchecked(1 + msg->retries,
30418 &port->counter_group[CM_XMIT].counter[attr_index]);
30419 if (msg->retries)
30420- atomic_long_add(msg->retries,
30421+ atomic_long_add_unchecked(msg->retries,
30422 &port->counter_group[CM_XMIT_RETRIES].
30423 counter[attr_index]);
30424
30425@@ -3417,7 +3417,7 @@ static void cm_recv_handler(struct ib_ma
30426 }
30427
30428 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
30429- atomic_long_inc(&port->counter_group[CM_RECV].
30430+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
30431 counter[attr_id - CM_ATTR_ID_OFFSET]);
30432
30433 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
30434@@ -3615,7 +3615,7 @@ static ssize_t cm_show_counter(struct ko
30435 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
30436
30437 return sprintf(buf, "%ld\n",
30438- atomic_long_read(&group->counter[cm_attr->index]));
30439+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
30440 }
30441
30442 static const struct sysfs_ops cm_counter_ops = {
30443diff -urNp linux-2.6.39.1/drivers/infiniband/core/fmr_pool.c linux-2.6.39.1/drivers/infiniband/core/fmr_pool.c
30444--- linux-2.6.39.1/drivers/infiniband/core/fmr_pool.c 2011-05-19 00:06:34.000000000 -0400
30445+++ linux-2.6.39.1/drivers/infiniband/core/fmr_pool.c 2011-05-22 19:36:31.000000000 -0400
30446@@ -97,8 +97,8 @@ struct ib_fmr_pool {
30447
30448 struct task_struct *thread;
30449
30450- atomic_t req_ser;
30451- atomic_t flush_ser;
30452+ atomic_unchecked_t req_ser;
30453+ atomic_unchecked_t flush_ser;
30454
30455 wait_queue_head_t force_wait;
30456 };
30457@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *p
30458 struct ib_fmr_pool *pool = pool_ptr;
30459
30460 do {
30461- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
30462+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
30463 ib_fmr_batch_release(pool);
30464
30465- atomic_inc(&pool->flush_ser);
30466+ atomic_inc_unchecked(&pool->flush_ser);
30467 wake_up_interruptible(&pool->force_wait);
30468
30469 if (pool->flush_function)
30470@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *p
30471 }
30472
30473 set_current_state(TASK_INTERRUPTIBLE);
30474- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
30475+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
30476 !kthread_should_stop())
30477 schedule();
30478 __set_current_state(TASK_RUNNING);
30479@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(s
30480 pool->dirty_watermark = params->dirty_watermark;
30481 pool->dirty_len = 0;
30482 spin_lock_init(&pool->pool_lock);
30483- atomic_set(&pool->req_ser, 0);
30484- atomic_set(&pool->flush_ser, 0);
30485+ atomic_set_unchecked(&pool->req_ser, 0);
30486+ atomic_set_unchecked(&pool->flush_ser, 0);
30487 init_waitqueue_head(&pool->force_wait);
30488
30489 pool->thread = kthread_run(ib_fmr_cleanup_thread,
30490@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool
30491 }
30492 spin_unlock_irq(&pool->pool_lock);
30493
30494- serial = atomic_inc_return(&pool->req_ser);
30495+ serial = atomic_inc_return_unchecked(&pool->req_ser);
30496 wake_up_process(pool->thread);
30497
30498 if (wait_event_interruptible(pool->force_wait,
30499- atomic_read(&pool->flush_ser) - serial >= 0))
30500+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
30501 return -EINTR;
30502
30503 return 0;
30504@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr
30505 } else {
30506 list_add_tail(&fmr->list, &pool->dirty_list);
30507 if (++pool->dirty_len >= pool->dirty_watermark) {
30508- atomic_inc(&pool->req_ser);
30509+ atomic_inc_unchecked(&pool->req_ser);
30510 wake_up_process(pool->thread);
30511 }
30512 }
30513diff -urNp linux-2.6.39.1/drivers/infiniband/hw/cxgb4/mem.c linux-2.6.39.1/drivers/infiniband/hw/cxgb4/mem.c
30514--- linux-2.6.39.1/drivers/infiniband/hw/cxgb4/mem.c 2011-05-19 00:06:34.000000000 -0400
30515+++ linux-2.6.39.1/drivers/infiniband/hw/cxgb4/mem.c 2011-05-22 19:36:31.000000000 -0400
30516@@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_r
30517 int err;
30518 struct fw_ri_tpte tpt;
30519 u32 stag_idx;
30520- static atomic_t key;
30521+ static atomic_unchecked_t key;
30522
30523 if (c4iw_fatal_error(rdev))
30524 return -EIO;
30525@@ -135,7 +135,7 @@ static int write_tpt_entry(struct c4iw_r
30526 &rdev->resource.tpt_fifo_lock);
30527 if (!stag_idx)
30528 return -ENOMEM;
30529- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
30530+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
30531 }
30532 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
30533 __func__, stag_state, type, pdid, stag_idx);
30534diff -urNp linux-2.6.39.1/drivers/infiniband/hw/ipath/ipath_dma.c linux-2.6.39.1/drivers/infiniband/hw/ipath/ipath_dma.c
30535--- linux-2.6.39.1/drivers/infiniband/hw/ipath/ipath_dma.c 2011-05-19 00:06:34.000000000 -0400
30536+++ linux-2.6.39.1/drivers/infiniband/hw/ipath/ipath_dma.c 2011-05-22 19:36:31.000000000 -0400
30537@@ -175,7 +175,7 @@ static void ipath_dma_free_coherent(stru
30538 free_pages((unsigned long) cpu_addr, get_order(size));
30539 }
30540
30541-struct ib_dma_mapping_ops ipath_dma_mapping_ops = {
30542+const struct ib_dma_mapping_ops ipath_dma_mapping_ops = {
30543 ipath_mapping_error,
30544 ipath_dma_map_single,
30545 ipath_dma_unmap_single,
30546diff -urNp linux-2.6.39.1/drivers/infiniband/hw/ipath/ipath_fs.c linux-2.6.39.1/drivers/infiniband/hw/ipath/ipath_fs.c
30547--- linux-2.6.39.1/drivers/infiniband/hw/ipath/ipath_fs.c 2011-05-19 00:06:34.000000000 -0400
30548+++ linux-2.6.39.1/drivers/infiniband/hw/ipath/ipath_fs.c 2011-05-22 19:36:31.000000000 -0400
30549@@ -113,6 +113,8 @@ static ssize_t atomic_counters_read(stru
30550 struct infinipath_counters counters;
30551 struct ipath_devdata *dd;
30552
30553+ pax_track_stack();
30554+
30555 dd = file->f_path.dentry->d_inode->i_private;
30556 dd->ipath_f_read_counters(dd, &counters);
30557
30558diff -urNp linux-2.6.39.1/drivers/infiniband/hw/ipath/ipath_rc.c linux-2.6.39.1/drivers/infiniband/hw/ipath/ipath_rc.c
30559--- linux-2.6.39.1/drivers/infiniband/hw/ipath/ipath_rc.c 2011-05-19 00:06:34.000000000 -0400
30560+++ linux-2.6.39.1/drivers/infiniband/hw/ipath/ipath_rc.c 2011-05-22 19:36:31.000000000 -0400
30561@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *de
30562 struct ib_atomic_eth *ateth;
30563 struct ipath_ack_entry *e;
30564 u64 vaddr;
30565- atomic64_t *maddr;
30566+ atomic64_unchecked_t *maddr;
30567 u64 sdata;
30568 u32 rkey;
30569 u8 next;
30570@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *de
30571 IB_ACCESS_REMOTE_ATOMIC)))
30572 goto nack_acc_unlck;
30573 /* Perform atomic OP and save result. */
30574- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
30575+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
30576 sdata = be64_to_cpu(ateth->swap_data);
30577 e = &qp->s_ack_queue[qp->r_head_ack_queue];
30578 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
30579- (u64) atomic64_add_return(sdata, maddr) - sdata :
30580+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
30581 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
30582 be64_to_cpu(ateth->compare_data),
30583 sdata);
30584diff -urNp linux-2.6.39.1/drivers/infiniband/hw/ipath/ipath_ruc.c linux-2.6.39.1/drivers/infiniband/hw/ipath/ipath_ruc.c
30585--- linux-2.6.39.1/drivers/infiniband/hw/ipath/ipath_ruc.c 2011-05-19 00:06:34.000000000 -0400
30586+++ linux-2.6.39.1/drivers/infiniband/hw/ipath/ipath_ruc.c 2011-05-22 19:36:31.000000000 -0400
30587@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ip
30588 unsigned long flags;
30589 struct ib_wc wc;
30590 u64 sdata;
30591- atomic64_t *maddr;
30592+ atomic64_unchecked_t *maddr;
30593 enum ib_wc_status send_status;
30594
30595 /*
30596@@ -382,11 +382,11 @@ again:
30597 IB_ACCESS_REMOTE_ATOMIC)))
30598 goto acc_err;
30599 /* Perform atomic OP and save result. */
30600- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
30601+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
30602 sdata = wqe->wr.wr.atomic.compare_add;
30603 *(u64 *) sqp->s_sge.sge.vaddr =
30604 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
30605- (u64) atomic64_add_return(sdata, maddr) - sdata :
30606+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
30607 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
30608 sdata, wqe->wr.wr.atomic.swap);
30609 goto send_comp;
30610diff -urNp linux-2.6.39.1/drivers/infiniband/hw/ipath/ipath_verbs.h linux-2.6.39.1/drivers/infiniband/hw/ipath/ipath_verbs.h
30611--- linux-2.6.39.1/drivers/infiniband/hw/ipath/ipath_verbs.h 2011-05-19 00:06:34.000000000 -0400
30612+++ linux-2.6.39.1/drivers/infiniband/hw/ipath/ipath_verbs.h 2011-05-22 19:36:31.000000000 -0400
30613@@ -931,6 +931,6 @@ extern unsigned int ib_ipath_max_srq_wrs
30614
30615 extern const u32 ib_ipath_rnr_table[];
30616
30617-extern struct ib_dma_mapping_ops ipath_dma_mapping_ops;
30618+extern const struct ib_dma_mapping_ops ipath_dma_mapping_ops;
30619
30620 #endif /* IPATH_VERBS_H */
30621diff -urNp linux-2.6.39.1/drivers/infiniband/hw/nes/nes.c linux-2.6.39.1/drivers/infiniband/hw/nes/nes.c
30622--- linux-2.6.39.1/drivers/infiniband/hw/nes/nes.c 2011-05-19 00:06:34.000000000 -0400
30623+++ linux-2.6.39.1/drivers/infiniband/hw/nes/nes.c 2011-05-22 19:36:31.000000000 -0400
30624@@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limi
30625 LIST_HEAD(nes_adapter_list);
30626 static LIST_HEAD(nes_dev_list);
30627
30628-atomic_t qps_destroyed;
30629+atomic_unchecked_t qps_destroyed;
30630
30631 static unsigned int ee_flsh_adapter;
30632 static unsigned int sysfs_nonidx_addr;
30633@@ -275,7 +275,7 @@ static void nes_cqp_rem_ref_callback(str
30634 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
30635 struct nes_adapter *nesadapter = nesdev->nesadapter;
30636
30637- atomic_inc(&qps_destroyed);
30638+ atomic_inc_unchecked(&qps_destroyed);
30639
30640 /* Free the control structures */
30641
30642diff -urNp linux-2.6.39.1/drivers/infiniband/hw/nes/nes_cm.c linux-2.6.39.1/drivers/infiniband/hw/nes/nes_cm.c
30643--- linux-2.6.39.1/drivers/infiniband/hw/nes/nes_cm.c 2011-05-19 00:06:34.000000000 -0400
30644+++ linux-2.6.39.1/drivers/infiniband/hw/nes/nes_cm.c 2011-05-22 19:36:31.000000000 -0400
30645@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
30646 u32 cm_packets_retrans;
30647 u32 cm_packets_created;
30648 u32 cm_packets_received;
30649-atomic_t cm_listens_created;
30650-atomic_t cm_listens_destroyed;
30651+atomic_unchecked_t cm_listens_created;
30652+atomic_unchecked_t cm_listens_destroyed;
30653 u32 cm_backlog_drops;
30654-atomic_t cm_loopbacks;
30655-atomic_t cm_nodes_created;
30656-atomic_t cm_nodes_destroyed;
30657-atomic_t cm_accel_dropped_pkts;
30658-atomic_t cm_resets_recvd;
30659+atomic_unchecked_t cm_loopbacks;
30660+atomic_unchecked_t cm_nodes_created;
30661+atomic_unchecked_t cm_nodes_destroyed;
30662+atomic_unchecked_t cm_accel_dropped_pkts;
30663+atomic_unchecked_t cm_resets_recvd;
30664
30665 static inline int mini_cm_accelerated(struct nes_cm_core *,
30666 struct nes_cm_node *);
30667@@ -151,13 +151,13 @@ static struct nes_cm_ops nes_cm_api = {
30668
30669 static struct nes_cm_core *g_cm_core;
30670
30671-atomic_t cm_connects;
30672-atomic_t cm_accepts;
30673-atomic_t cm_disconnects;
30674-atomic_t cm_closes;
30675-atomic_t cm_connecteds;
30676-atomic_t cm_connect_reqs;
30677-atomic_t cm_rejects;
30678+atomic_unchecked_t cm_connects;
30679+atomic_unchecked_t cm_accepts;
30680+atomic_unchecked_t cm_disconnects;
30681+atomic_unchecked_t cm_closes;
30682+atomic_unchecked_t cm_connecteds;
30683+atomic_unchecked_t cm_connect_reqs;
30684+atomic_unchecked_t cm_rejects;
30685
30686
30687 /**
30688@@ -1045,7 +1045,7 @@ static int mini_cm_dec_refcnt_listen(str
30689 kfree(listener);
30690 listener = NULL;
30691 ret = 0;
30692- atomic_inc(&cm_listens_destroyed);
30693+ atomic_inc_unchecked(&cm_listens_destroyed);
30694 } else {
30695 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
30696 }
30697@@ -1240,7 +1240,7 @@ static struct nes_cm_node *make_cm_node(
30698 cm_node->rem_mac);
30699
30700 add_hte_node(cm_core, cm_node);
30701- atomic_inc(&cm_nodes_created);
30702+ atomic_inc_unchecked(&cm_nodes_created);
30703
30704 return cm_node;
30705 }
30706@@ -1298,7 +1298,7 @@ static int rem_ref_cm_node(struct nes_cm
30707 }
30708
30709 atomic_dec(&cm_core->node_cnt);
30710- atomic_inc(&cm_nodes_destroyed);
30711+ atomic_inc_unchecked(&cm_nodes_destroyed);
30712 nesqp = cm_node->nesqp;
30713 if (nesqp) {
30714 nesqp->cm_node = NULL;
30715@@ -1365,7 +1365,7 @@ static int process_options(struct nes_cm
30716
30717 static void drop_packet(struct sk_buff *skb)
30718 {
30719- atomic_inc(&cm_accel_dropped_pkts);
30720+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
30721 dev_kfree_skb_any(skb);
30722 }
30723
30724@@ -1428,7 +1428,7 @@ static void handle_rst_pkt(struct nes_cm
30725 {
30726
30727 int reset = 0; /* whether to send reset in case of err.. */
30728- atomic_inc(&cm_resets_recvd);
30729+ atomic_inc_unchecked(&cm_resets_recvd);
30730 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
30731 " refcnt=%d\n", cm_node, cm_node->state,
30732 atomic_read(&cm_node->ref_count));
30733@@ -2057,7 +2057,7 @@ static struct nes_cm_node *mini_cm_conne
30734 rem_ref_cm_node(cm_node->cm_core, cm_node);
30735 return NULL;
30736 }
30737- atomic_inc(&cm_loopbacks);
30738+ atomic_inc_unchecked(&cm_loopbacks);
30739 loopbackremotenode->loopbackpartner = cm_node;
30740 loopbackremotenode->tcp_cntxt.rcv_wscale =
30741 NES_CM_DEFAULT_RCV_WND_SCALE;
30742@@ -2332,7 +2332,7 @@ static int mini_cm_recv_pkt(struct nes_c
30743 add_ref_cm_node(cm_node);
30744 } else if (cm_node->state == NES_CM_STATE_TSA) {
30745 rem_ref_cm_node(cm_core, cm_node);
30746- atomic_inc(&cm_accel_dropped_pkts);
30747+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
30748 dev_kfree_skb_any(skb);
30749 break;
30750 }
30751@@ -2638,7 +2638,7 @@ static int nes_cm_disconn_true(struct ne
30752
30753 if ((cm_id) && (cm_id->event_handler)) {
30754 if (issue_disconn) {
30755- atomic_inc(&cm_disconnects);
30756+ atomic_inc_unchecked(&cm_disconnects);
30757 cm_event.event = IW_CM_EVENT_DISCONNECT;
30758 cm_event.status = disconn_status;
30759 cm_event.local_addr = cm_id->local_addr;
30760@@ -2660,7 +2660,7 @@ static int nes_cm_disconn_true(struct ne
30761 }
30762
30763 if (issue_close) {
30764- atomic_inc(&cm_closes);
30765+ atomic_inc_unchecked(&cm_closes);
30766 nes_disconnect(nesqp, 1);
30767
30768 cm_id->provider_data = nesqp;
30769@@ -2791,7 +2791,7 @@ int nes_accept(struct iw_cm_id *cm_id, s
30770
30771 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
30772 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
30773- atomic_inc(&cm_accepts);
30774+ atomic_inc_unchecked(&cm_accepts);
30775
30776 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
30777 netdev_refcnt_read(nesvnic->netdev));
30778@@ -3001,7 +3001,7 @@ int nes_reject(struct iw_cm_id *cm_id, c
30779
30780 struct nes_cm_core *cm_core;
30781
30782- atomic_inc(&cm_rejects);
30783+ atomic_inc_unchecked(&cm_rejects);
30784 cm_node = (struct nes_cm_node *) cm_id->provider_data;
30785 loopback = cm_node->loopbackpartner;
30786 cm_core = cm_node->cm_core;
30787@@ -3067,7 +3067,7 @@ int nes_connect(struct iw_cm_id *cm_id,
30788 ntohl(cm_id->local_addr.sin_addr.s_addr),
30789 ntohs(cm_id->local_addr.sin_port));
30790
30791- atomic_inc(&cm_connects);
30792+ atomic_inc_unchecked(&cm_connects);
30793 nesqp->active_conn = 1;
30794
30795 /* cache the cm_id in the qp */
30796@@ -3173,7 +3173,7 @@ int nes_create_listen(struct iw_cm_id *c
30797 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
30798 return err;
30799 }
30800- atomic_inc(&cm_listens_created);
30801+ atomic_inc_unchecked(&cm_listens_created);
30802 }
30803
30804 cm_id->add_ref(cm_id);
30805@@ -3278,7 +3278,7 @@ static void cm_event_connected(struct ne
30806 if (nesqp->destroyed) {
30807 return;
30808 }
30809- atomic_inc(&cm_connecteds);
30810+ atomic_inc_unchecked(&cm_connecteds);
30811 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
30812 " local port 0x%04X. jiffies = %lu.\n",
30813 nesqp->hwqp.qp_id,
30814@@ -3493,7 +3493,7 @@ static void cm_event_reset(struct nes_cm
30815
30816 cm_id->add_ref(cm_id);
30817 ret = cm_id->event_handler(cm_id, &cm_event);
30818- atomic_inc(&cm_closes);
30819+ atomic_inc_unchecked(&cm_closes);
30820 cm_event.event = IW_CM_EVENT_CLOSE;
30821 cm_event.status = IW_CM_EVENT_STATUS_OK;
30822 cm_event.provider_data = cm_id->provider_data;
30823@@ -3529,7 +3529,7 @@ static void cm_event_mpa_req(struct nes_
30824 return;
30825 cm_id = cm_node->cm_id;
30826
30827- atomic_inc(&cm_connect_reqs);
30828+ atomic_inc_unchecked(&cm_connect_reqs);
30829 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
30830 cm_node, cm_id, jiffies);
30831
30832@@ -3567,7 +3567,7 @@ static void cm_event_mpa_reject(struct n
30833 return;
30834 cm_id = cm_node->cm_id;
30835
30836- atomic_inc(&cm_connect_reqs);
30837+ atomic_inc_unchecked(&cm_connect_reqs);
30838 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
30839 cm_node, cm_id, jiffies);
30840
30841diff -urNp linux-2.6.39.1/drivers/infiniband/hw/nes/nes.h linux-2.6.39.1/drivers/infiniband/hw/nes/nes.h
30842--- linux-2.6.39.1/drivers/infiniband/hw/nes/nes.h 2011-05-19 00:06:34.000000000 -0400
30843+++ linux-2.6.39.1/drivers/infiniband/hw/nes/nes.h 2011-05-22 19:36:31.000000000 -0400
30844@@ -175,17 +175,17 @@ extern unsigned int nes_debug_level;
30845 extern unsigned int wqm_quanta;
30846 extern struct list_head nes_adapter_list;
30847
30848-extern atomic_t cm_connects;
30849-extern atomic_t cm_accepts;
30850-extern atomic_t cm_disconnects;
30851-extern atomic_t cm_closes;
30852-extern atomic_t cm_connecteds;
30853-extern atomic_t cm_connect_reqs;
30854-extern atomic_t cm_rejects;
30855-extern atomic_t mod_qp_timouts;
30856-extern atomic_t qps_created;
30857-extern atomic_t qps_destroyed;
30858-extern atomic_t sw_qps_destroyed;
30859+extern atomic_unchecked_t cm_connects;
30860+extern atomic_unchecked_t cm_accepts;
30861+extern atomic_unchecked_t cm_disconnects;
30862+extern atomic_unchecked_t cm_closes;
30863+extern atomic_unchecked_t cm_connecteds;
30864+extern atomic_unchecked_t cm_connect_reqs;
30865+extern atomic_unchecked_t cm_rejects;
30866+extern atomic_unchecked_t mod_qp_timouts;
30867+extern atomic_unchecked_t qps_created;
30868+extern atomic_unchecked_t qps_destroyed;
30869+extern atomic_unchecked_t sw_qps_destroyed;
30870 extern u32 mh_detected;
30871 extern u32 mh_pauses_sent;
30872 extern u32 cm_packets_sent;
30873@@ -194,14 +194,14 @@ extern u32 cm_packets_created;
30874 extern u32 cm_packets_received;
30875 extern u32 cm_packets_dropped;
30876 extern u32 cm_packets_retrans;
30877-extern atomic_t cm_listens_created;
30878-extern atomic_t cm_listens_destroyed;
30879+extern atomic_unchecked_t cm_listens_created;
30880+extern atomic_unchecked_t cm_listens_destroyed;
30881 extern u32 cm_backlog_drops;
30882-extern atomic_t cm_loopbacks;
30883-extern atomic_t cm_nodes_created;
30884-extern atomic_t cm_nodes_destroyed;
30885-extern atomic_t cm_accel_dropped_pkts;
30886-extern atomic_t cm_resets_recvd;
30887+extern atomic_unchecked_t cm_loopbacks;
30888+extern atomic_unchecked_t cm_nodes_created;
30889+extern atomic_unchecked_t cm_nodes_destroyed;
30890+extern atomic_unchecked_t cm_accel_dropped_pkts;
30891+extern atomic_unchecked_t cm_resets_recvd;
30892
30893 extern u32 int_mod_timer_init;
30894 extern u32 int_mod_cq_depth_256;
30895diff -urNp linux-2.6.39.1/drivers/infiniband/hw/nes/nes_nic.c linux-2.6.39.1/drivers/infiniband/hw/nes/nes_nic.c
30896--- linux-2.6.39.1/drivers/infiniband/hw/nes/nes_nic.c 2011-05-19 00:06:34.000000000 -0400
30897+++ linux-2.6.39.1/drivers/infiniband/hw/nes/nes_nic.c 2011-05-22 19:36:31.000000000 -0400
30898@@ -1302,31 +1302,31 @@ static void nes_netdev_get_ethtool_stats
30899 target_stat_values[++index] = mh_detected;
30900 target_stat_values[++index] = mh_pauses_sent;
30901 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
30902- target_stat_values[++index] = atomic_read(&cm_connects);
30903- target_stat_values[++index] = atomic_read(&cm_accepts);
30904- target_stat_values[++index] = atomic_read(&cm_disconnects);
30905- target_stat_values[++index] = atomic_read(&cm_connecteds);
30906- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
30907- target_stat_values[++index] = atomic_read(&cm_rejects);
30908- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
30909- target_stat_values[++index] = atomic_read(&qps_created);
30910- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
30911- target_stat_values[++index] = atomic_read(&qps_destroyed);
30912- target_stat_values[++index] = atomic_read(&cm_closes);
30913+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
30914+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
30915+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
30916+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
30917+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
30918+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
30919+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
30920+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
30921+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
30922+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
30923+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
30924 target_stat_values[++index] = cm_packets_sent;
30925 target_stat_values[++index] = cm_packets_bounced;
30926 target_stat_values[++index] = cm_packets_created;
30927 target_stat_values[++index] = cm_packets_received;
30928 target_stat_values[++index] = cm_packets_dropped;
30929 target_stat_values[++index] = cm_packets_retrans;
30930- target_stat_values[++index] = atomic_read(&cm_listens_created);
30931- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
30932+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
30933+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
30934 target_stat_values[++index] = cm_backlog_drops;
30935- target_stat_values[++index] = atomic_read(&cm_loopbacks);
30936- target_stat_values[++index] = atomic_read(&cm_nodes_created);
30937- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
30938- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
30939- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
30940+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
30941+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
30942+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
30943+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
30944+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
30945 target_stat_values[++index] = nesadapter->free_4kpbl;
30946 target_stat_values[++index] = nesadapter->free_256pbl;
30947 target_stat_values[++index] = int_mod_timer_init;
30948diff -urNp linux-2.6.39.1/drivers/infiniband/hw/nes/nes_verbs.c linux-2.6.39.1/drivers/infiniband/hw/nes/nes_verbs.c
30949--- linux-2.6.39.1/drivers/infiniband/hw/nes/nes_verbs.c 2011-05-19 00:06:34.000000000 -0400
30950+++ linux-2.6.39.1/drivers/infiniband/hw/nes/nes_verbs.c 2011-05-22 19:36:31.000000000 -0400
30951@@ -46,9 +46,9 @@
30952
30953 #include <rdma/ib_umem.h>
30954
30955-atomic_t mod_qp_timouts;
30956-atomic_t qps_created;
30957-atomic_t sw_qps_destroyed;
30958+atomic_unchecked_t mod_qp_timouts;
30959+atomic_unchecked_t qps_created;
30960+atomic_unchecked_t sw_qps_destroyed;
30961
30962 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
30963
30964@@ -1141,7 +1141,7 @@ static struct ib_qp *nes_create_qp(struc
30965 if (init_attr->create_flags)
30966 return ERR_PTR(-EINVAL);
30967
30968- atomic_inc(&qps_created);
30969+ atomic_inc_unchecked(&qps_created);
30970 switch (init_attr->qp_type) {
30971 case IB_QPT_RC:
30972 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
30973@@ -1470,7 +1470,7 @@ static int nes_destroy_qp(struct ib_qp *
30974 struct iw_cm_event cm_event;
30975 int ret;
30976
30977- atomic_inc(&sw_qps_destroyed);
30978+ atomic_inc_unchecked(&sw_qps_destroyed);
30979 nesqp->destroyed = 1;
30980
30981 /* Blow away the connection if it exists. */
30982diff -urNp linux-2.6.39.1/drivers/infiniband/hw/qib/qib.h linux-2.6.39.1/drivers/infiniband/hw/qib/qib.h
30983--- linux-2.6.39.1/drivers/infiniband/hw/qib/qib.h 2011-05-19 00:06:34.000000000 -0400
30984+++ linux-2.6.39.1/drivers/infiniband/hw/qib/qib.h 2011-05-22 19:36:31.000000000 -0400
30985@@ -51,6 +51,7 @@
30986 #include <linux/completion.h>
30987 #include <linux/kref.h>
30988 #include <linux/sched.h>
30989+#include <linux/slab.h>
30990
30991 #include "qib_common.h"
30992 #include "qib_verbs.h"
30993@@ -87,7 +88,7 @@ struct qlogic_ib_stats {
30994 };
30995
30996 extern struct qlogic_ib_stats qib_stats;
30997-extern struct pci_error_handlers qib_pci_err_handler;
30998+extern const struct pci_error_handlers qib_pci_err_handler;
30999 extern struct pci_driver qib_driver;
31000
31001 #define QIB_CHIP_SWVERSION QIB_CHIP_VERS_MAJ
31002diff -urNp linux-2.6.39.1/drivers/infiniband/hw/qib/qib_mmap.c linux-2.6.39.1/drivers/infiniband/hw/qib/qib_mmap.c
31003--- linux-2.6.39.1/drivers/infiniband/hw/qib/qib_mmap.c 2011-05-19 00:06:34.000000000 -0400
31004+++ linux-2.6.39.1/drivers/infiniband/hw/qib/qib_mmap.c 2011-05-22 19:36:31.000000000 -0400
31005@@ -75,7 +75,7 @@ static void qib_vma_close(struct vm_area
31006 kref_put(&ip->ref, qib_release_mmap_info);
31007 }
31008
31009-static struct vm_operations_struct qib_vm_ops = {
31010+static const struct vm_operations_struct qib_vm_ops = {
31011 .open = qib_vma_open,
31012 .close = qib_vma_close,
31013 };
31014diff -urNp linux-2.6.39.1/drivers/infiniband/hw/qib/qib_pcie.c linux-2.6.39.1/drivers/infiniband/hw/qib/qib_pcie.c
31015--- linux-2.6.39.1/drivers/infiniband/hw/qib/qib_pcie.c 2011-05-19 00:06:34.000000000 -0400
31016+++ linux-2.6.39.1/drivers/infiniband/hw/qib/qib_pcie.c 2011-05-22 19:36:31.000000000 -0400
31017@@ -735,7 +735,7 @@ qib_pci_resume(struct pci_dev *pdev)
31018 qib_init(dd, 1); /* same as re-init after reset */
31019 }
31020
31021-struct pci_error_handlers qib_pci_err_handler = {
31022+const struct pci_error_handlers qib_pci_err_handler = {
31023 .error_detected = qib_pci_error_detected,
31024 .mmio_enabled = qib_pci_mmio_enabled,
31025 .link_reset = qib_pci_link_reset,
31026diff -urNp linux-2.6.39.1/drivers/input/gameport/gameport.c linux-2.6.39.1/drivers/input/gameport/gameport.c
31027--- linux-2.6.39.1/drivers/input/gameport/gameport.c 2011-05-19 00:06:34.000000000 -0400
31028+++ linux-2.6.39.1/drivers/input/gameport/gameport.c 2011-05-22 19:36:31.000000000 -0400
31029@@ -488,14 +488,14 @@ EXPORT_SYMBOL(gameport_set_phys);
31030 */
31031 static void gameport_init_port(struct gameport *gameport)
31032 {
31033- static atomic_t gameport_no = ATOMIC_INIT(0);
31034+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
31035
31036 __module_get(THIS_MODULE);
31037
31038 mutex_init(&gameport->drv_mutex);
31039 device_initialize(&gameport->dev);
31040 dev_set_name(&gameport->dev, "gameport%lu",
31041- (unsigned long)atomic_inc_return(&gameport_no) - 1);
31042+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
31043 gameport->dev.bus = &gameport_bus;
31044 gameport->dev.release = gameport_release_port;
31045 if (gameport->parent)
31046diff -urNp linux-2.6.39.1/drivers/input/input.c linux-2.6.39.1/drivers/input/input.c
31047--- linux-2.6.39.1/drivers/input/input.c 2011-05-19 00:06:34.000000000 -0400
31048+++ linux-2.6.39.1/drivers/input/input.c 2011-05-22 19:36:31.000000000 -0400
31049@@ -1815,7 +1815,7 @@ static void input_cleanse_bitmasks(struc
31050 */
31051 int input_register_device(struct input_dev *dev)
31052 {
31053- static atomic_t input_no = ATOMIC_INIT(0);
31054+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
31055 struct input_handler *handler;
31056 const char *path;
31057 int error;
31058@@ -1852,7 +1852,7 @@ int input_register_device(struct input_d
31059 dev->setkeycode = input_default_setkeycode;
31060
31061 dev_set_name(&dev->dev, "input%ld",
31062- (unsigned long) atomic_inc_return(&input_no) - 1);
31063+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
31064
31065 error = device_add(&dev->dev);
31066 if (error)
31067diff -urNp linux-2.6.39.1/drivers/input/joystick/sidewinder.c linux-2.6.39.1/drivers/input/joystick/sidewinder.c
31068--- linux-2.6.39.1/drivers/input/joystick/sidewinder.c 2011-05-19 00:06:34.000000000 -0400
31069+++ linux-2.6.39.1/drivers/input/joystick/sidewinder.c 2011-05-22 19:36:31.000000000 -0400
31070@@ -30,6 +30,7 @@
31071 #include <linux/kernel.h>
31072 #include <linux/module.h>
31073 #include <linux/slab.h>
31074+#include <linux/sched.h>
31075 #include <linux/init.h>
31076 #include <linux/input.h>
31077 #include <linux/gameport.h>
31078@@ -428,6 +429,8 @@ static int sw_read(struct sw *sw)
31079 unsigned char buf[SW_LENGTH];
31080 int i;
31081
31082+ pax_track_stack();
31083+
31084 i = sw_read_packet(sw->gameport, buf, sw->length, 0);
31085
31086 if (sw->type == SW_ID_3DP && sw->length == 66 && i != 66) { /* Broken packet, try to fix */
31087diff -urNp linux-2.6.39.1/drivers/input/joystick/xpad.c linux-2.6.39.1/drivers/input/joystick/xpad.c
31088--- linux-2.6.39.1/drivers/input/joystick/xpad.c 2011-05-19 00:06:34.000000000 -0400
31089+++ linux-2.6.39.1/drivers/input/joystick/xpad.c 2011-05-22 19:36:31.000000000 -0400
31090@@ -689,7 +689,7 @@ static void xpad_led_set(struct led_clas
31091
31092 static int xpad_led_probe(struct usb_xpad *xpad)
31093 {
31094- static atomic_t led_seq = ATOMIC_INIT(0);
31095+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
31096 long led_no;
31097 struct xpad_led *led;
31098 struct led_classdev *led_cdev;
31099@@ -702,7 +702,7 @@ static int xpad_led_probe(struct usb_xpa
31100 if (!led)
31101 return -ENOMEM;
31102
31103- led_no = (long)atomic_inc_return(&led_seq) - 1;
31104+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
31105
31106 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
31107 led->xpad = xpad;
31108diff -urNp linux-2.6.39.1/drivers/input/mousedev.c linux-2.6.39.1/drivers/input/mousedev.c
31109--- linux-2.6.39.1/drivers/input/mousedev.c 2011-05-19 00:06:34.000000000 -0400
31110+++ linux-2.6.39.1/drivers/input/mousedev.c 2011-05-22 19:36:31.000000000 -0400
31111@@ -764,7 +764,7 @@ static ssize_t mousedev_read(struct file
31112
31113 spin_unlock_irq(&client->packet_lock);
31114
31115- if (copy_to_user(buffer, data, count))
31116+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
31117 return -EFAULT;
31118
31119 return count;
31120diff -urNp linux-2.6.39.1/drivers/input/serio/serio.c linux-2.6.39.1/drivers/input/serio/serio.c
31121--- linux-2.6.39.1/drivers/input/serio/serio.c 2011-05-19 00:06:34.000000000 -0400
31122+++ linux-2.6.39.1/drivers/input/serio/serio.c 2011-05-22 19:36:31.000000000 -0400
31123@@ -497,7 +497,7 @@ static void serio_release_port(struct de
31124 */
31125 static void serio_init_port(struct serio *serio)
31126 {
31127- static atomic_t serio_no = ATOMIC_INIT(0);
31128+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
31129
31130 __module_get(THIS_MODULE);
31131
31132@@ -508,7 +508,7 @@ static void serio_init_port(struct serio
31133 mutex_init(&serio->drv_mutex);
31134 device_initialize(&serio->dev);
31135 dev_set_name(&serio->dev, "serio%ld",
31136- (long)atomic_inc_return(&serio_no) - 1);
31137+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
31138 serio->dev.bus = &serio_bus;
31139 serio->dev.release = serio_release_port;
31140 serio->dev.groups = serio_device_attr_groups;
31141diff -urNp linux-2.6.39.1/drivers/isdn/capi/capi.c linux-2.6.39.1/drivers/isdn/capi/capi.c
31142--- linux-2.6.39.1/drivers/isdn/capi/capi.c 2011-05-19 00:06:34.000000000 -0400
31143+++ linux-2.6.39.1/drivers/isdn/capi/capi.c 2011-05-22 19:36:31.000000000 -0400
31144@@ -89,8 +89,8 @@ struct capiminor {
31145
31146 struct capi20_appl *ap;
31147 u32 ncci;
31148- atomic_t datahandle;
31149- atomic_t msgid;
31150+ atomic_unchecked_t datahandle;
31151+ atomic_unchecked_t msgid;
31152
31153 struct tty_port port;
31154 int ttyinstop;
31155@@ -414,7 +414,7 @@ gen_data_b3_resp_for(struct capiminor *m
31156 capimsg_setu16(s, 2, mp->ap->applid);
31157 capimsg_setu8 (s, 4, CAPI_DATA_B3);
31158 capimsg_setu8 (s, 5, CAPI_RESP);
31159- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
31160+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
31161 capimsg_setu32(s, 8, mp->ncci);
31162 capimsg_setu16(s, 12, datahandle);
31163 }
31164@@ -547,14 +547,14 @@ static void handle_minor_send(struct cap
31165 mp->outbytes -= len;
31166 spin_unlock_bh(&mp->outlock);
31167
31168- datahandle = atomic_inc_return(&mp->datahandle);
31169+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
31170 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
31171 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
31172 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
31173 capimsg_setu16(skb->data, 2, mp->ap->applid);
31174 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
31175 capimsg_setu8 (skb->data, 5, CAPI_REQ);
31176- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
31177+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
31178 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
31179 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
31180 capimsg_setu16(skb->data, 16, len); /* Data length */
31181diff -urNp linux-2.6.39.1/drivers/isdn/gigaset/common.c linux-2.6.39.1/drivers/isdn/gigaset/common.c
31182--- linux-2.6.39.1/drivers/isdn/gigaset/common.c 2011-05-19 00:06:34.000000000 -0400
31183+++ linux-2.6.39.1/drivers/isdn/gigaset/common.c 2011-05-22 19:36:31.000000000 -0400
31184@@ -723,7 +723,7 @@ struct cardstate *gigaset_initcs(struct
31185 cs->commands_pending = 0;
31186 cs->cur_at_seq = 0;
31187 cs->gotfwver = -1;
31188- cs->open_count = 0;
31189+ local_set(&cs->open_count, 0);
31190 cs->dev = NULL;
31191 cs->tty = NULL;
31192 cs->tty_dev = NULL;
31193diff -urNp linux-2.6.39.1/drivers/isdn/gigaset/gigaset.h linux-2.6.39.1/drivers/isdn/gigaset/gigaset.h
31194--- linux-2.6.39.1/drivers/isdn/gigaset/gigaset.h 2011-05-19 00:06:34.000000000 -0400
31195+++ linux-2.6.39.1/drivers/isdn/gigaset/gigaset.h 2011-05-22 19:36:31.000000000 -0400
31196@@ -35,6 +35,7 @@
31197 #include <linux/tty_driver.h>
31198 #include <linux/list.h>
31199 #include <asm/atomic.h>
31200+#include <asm/local.h>
31201
31202 #define GIG_VERSION {0, 5, 0, 0}
31203 #define GIG_COMPAT {0, 4, 0, 0}
31204@@ -433,7 +434,7 @@ struct cardstate {
31205 spinlock_t cmdlock;
31206 unsigned curlen, cmdbytes;
31207
31208- unsigned open_count;
31209+ local_t open_count;
31210 struct tty_struct *tty;
31211 struct tasklet_struct if_wake_tasklet;
31212 unsigned control_state;
31213diff -urNp linux-2.6.39.1/drivers/isdn/gigaset/interface.c linux-2.6.39.1/drivers/isdn/gigaset/interface.c
31214--- linux-2.6.39.1/drivers/isdn/gigaset/interface.c 2011-05-19 00:06:34.000000000 -0400
31215+++ linux-2.6.39.1/drivers/isdn/gigaset/interface.c 2011-05-22 19:36:31.000000000 -0400
31216@@ -160,9 +160,7 @@ static int if_open(struct tty_struct *tt
31217 return -ERESTARTSYS;
31218 tty->driver_data = cs;
31219
31220- ++cs->open_count;
31221-
31222- if (cs->open_count == 1) {
31223+ if (local_inc_return(&cs->open_count) == 1) {
31224 spin_lock_irqsave(&cs->lock, flags);
31225 cs->tty = tty;
31226 spin_unlock_irqrestore(&cs->lock, flags);
31227@@ -190,10 +188,10 @@ static void if_close(struct tty_struct *
31228
31229 if (!cs->connected)
31230 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
31231- else if (!cs->open_count)
31232+ else if (!local_read(&cs->open_count))
31233 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31234 else {
31235- if (!--cs->open_count) {
31236+ if (!local_dec_return(&cs->open_count)) {
31237 spin_lock_irqsave(&cs->lock, flags);
31238 cs->tty = NULL;
31239 spin_unlock_irqrestore(&cs->lock, flags);
31240@@ -228,7 +226,7 @@ static int if_ioctl(struct tty_struct *t
31241 if (!cs->connected) {
31242 gig_dbg(DEBUG_IF, "not connected");
31243 retval = -ENODEV;
31244- } else if (!cs->open_count)
31245+ } else if (!local_read(&cs->open_count))
31246 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31247 else {
31248 retval = 0;
31249@@ -358,7 +356,7 @@ static int if_write(struct tty_struct *t
31250 retval = -ENODEV;
31251 goto done;
31252 }
31253- if (!cs->open_count) {
31254+ if (!local_read(&cs->open_count)) {
31255 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31256 retval = -ENODEV;
31257 goto done;
31258@@ -411,7 +409,7 @@ static int if_write_room(struct tty_stru
31259 if (!cs->connected) {
31260 gig_dbg(DEBUG_IF, "not connected");
31261 retval = -ENODEV;
31262- } else if (!cs->open_count)
31263+ } else if (!local_read(&cs->open_count))
31264 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31265 else if (cs->mstate != MS_LOCKED) {
31266 dev_warn(cs->dev, "can't write to unlocked device\n");
31267@@ -441,7 +439,7 @@ static int if_chars_in_buffer(struct tty
31268
31269 if (!cs->connected)
31270 gig_dbg(DEBUG_IF, "not connected");
31271- else if (!cs->open_count)
31272+ else if (!local_read(&cs->open_count))
31273 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31274 else if (cs->mstate != MS_LOCKED)
31275 dev_warn(cs->dev, "can't write to unlocked device\n");
31276@@ -469,7 +467,7 @@ static void if_throttle(struct tty_struc
31277
31278 if (!cs->connected)
31279 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
31280- else if (!cs->open_count)
31281+ else if (!local_read(&cs->open_count))
31282 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31283 else
31284 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
31285@@ -493,7 +491,7 @@ static void if_unthrottle(struct tty_str
31286
31287 if (!cs->connected)
31288 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
31289- else if (!cs->open_count)
31290+ else if (!local_read(&cs->open_count))
31291 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31292 else
31293 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
31294@@ -524,7 +522,7 @@ static void if_set_termios(struct tty_st
31295 goto out;
31296 }
31297
31298- if (!cs->open_count) {
31299+ if (!local_read(&cs->open_count)) {
31300 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31301 goto out;
31302 }
31303diff -urNp linux-2.6.39.1/drivers/isdn/hardware/avm/b1.c linux-2.6.39.1/drivers/isdn/hardware/avm/b1.c
31304--- linux-2.6.39.1/drivers/isdn/hardware/avm/b1.c 2011-05-19 00:06:34.000000000 -0400
31305+++ linux-2.6.39.1/drivers/isdn/hardware/avm/b1.c 2011-05-22 19:36:31.000000000 -0400
31306@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capilo
31307 }
31308 if (left) {
31309 if (t4file->user) {
31310- if (copy_from_user(buf, dp, left))
31311+ if (left > sizeof buf || copy_from_user(buf, dp, left))
31312 return -EFAULT;
31313 } else {
31314 memcpy(buf, dp, left);
31315@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capilo
31316 }
31317 if (left) {
31318 if (config->user) {
31319- if (copy_from_user(buf, dp, left))
31320+ if (left > sizeof buf || copy_from_user(buf, dp, left))
31321 return -EFAULT;
31322 } else {
31323 memcpy(buf, dp, left);
31324diff -urNp linux-2.6.39.1/drivers/isdn/hardware/eicon/capidtmf.c linux-2.6.39.1/drivers/isdn/hardware/eicon/capidtmf.c
31325--- linux-2.6.39.1/drivers/isdn/hardware/eicon/capidtmf.c 2011-05-19 00:06:34.000000000 -0400
31326+++ linux-2.6.39.1/drivers/isdn/hardware/eicon/capidtmf.c 2011-05-22 19:36:31.000000000 -0400
31327@@ -498,6 +498,7 @@ void capidtmf_recv_block (t_capidtmf_sta
31328 byte goertzel_result_buffer[CAPIDTMF_RECV_TOTAL_FREQUENCY_COUNT];
31329 short windowed_sample_buffer[CAPIDTMF_RECV_WINDOWED_SAMPLES];
31330
31331+ pax_track_stack();
31332
31333 if (p_state->recv.state & CAPIDTMF_RECV_STATE_DTMF_ACTIVE)
31334 {
31335diff -urNp linux-2.6.39.1/drivers/isdn/hardware/eicon/capifunc.c linux-2.6.39.1/drivers/isdn/hardware/eicon/capifunc.c
31336--- linux-2.6.39.1/drivers/isdn/hardware/eicon/capifunc.c 2011-05-19 00:06:34.000000000 -0400
31337+++ linux-2.6.39.1/drivers/isdn/hardware/eicon/capifunc.c 2011-05-22 19:36:31.000000000 -0400
31338@@ -1055,6 +1055,8 @@ static int divacapi_connect_didd(void)
31339 IDI_SYNC_REQ req;
31340 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
31341
31342+ pax_track_stack();
31343+
31344 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
31345
31346 for (x = 0; x < MAX_DESCRIPTORS; x++) {
31347diff -urNp linux-2.6.39.1/drivers/isdn/hardware/eicon/diddfunc.c linux-2.6.39.1/drivers/isdn/hardware/eicon/diddfunc.c
31348--- linux-2.6.39.1/drivers/isdn/hardware/eicon/diddfunc.c 2011-05-19 00:06:34.000000000 -0400
31349+++ linux-2.6.39.1/drivers/isdn/hardware/eicon/diddfunc.c 2011-05-22 19:36:31.000000000 -0400
31350@@ -54,6 +54,8 @@ static int DIVA_INIT_FUNCTION connect_di
31351 IDI_SYNC_REQ req;
31352 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
31353
31354+ pax_track_stack();
31355+
31356 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
31357
31358 for (x = 0; x < MAX_DESCRIPTORS; x++) {
31359diff -urNp linux-2.6.39.1/drivers/isdn/hardware/eicon/divasfunc.c linux-2.6.39.1/drivers/isdn/hardware/eicon/divasfunc.c
31360--- linux-2.6.39.1/drivers/isdn/hardware/eicon/divasfunc.c 2011-05-19 00:06:34.000000000 -0400
31361+++ linux-2.6.39.1/drivers/isdn/hardware/eicon/divasfunc.c 2011-05-22 19:36:31.000000000 -0400
31362@@ -161,6 +161,8 @@ static int DIVA_INIT_FUNCTION connect_di
31363 IDI_SYNC_REQ req;
31364 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
31365
31366+ pax_track_stack();
31367+
31368 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
31369
31370 for (x = 0; x < MAX_DESCRIPTORS; x++) {
31371diff -urNp linux-2.6.39.1/drivers/isdn/hardware/eicon/idifunc.c linux-2.6.39.1/drivers/isdn/hardware/eicon/idifunc.c
31372--- linux-2.6.39.1/drivers/isdn/hardware/eicon/idifunc.c 2011-05-19 00:06:34.000000000 -0400
31373+++ linux-2.6.39.1/drivers/isdn/hardware/eicon/idifunc.c 2011-05-22 19:36:31.000000000 -0400
31374@@ -188,6 +188,8 @@ static int DIVA_INIT_FUNCTION connect_di
31375 IDI_SYNC_REQ req;
31376 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
31377
31378+ pax_track_stack();
31379+
31380 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
31381
31382 for (x = 0; x < MAX_DESCRIPTORS; x++) {
31383diff -urNp linux-2.6.39.1/drivers/isdn/hardware/eicon/message.c linux-2.6.39.1/drivers/isdn/hardware/eicon/message.c
31384--- linux-2.6.39.1/drivers/isdn/hardware/eicon/message.c 2011-05-19 00:06:34.000000000 -0400
31385+++ linux-2.6.39.1/drivers/isdn/hardware/eicon/message.c 2011-05-22 19:36:31.000000000 -0400
31386@@ -4889,6 +4889,8 @@ static void sig_ind(PLCI *plci)
31387 dword d;
31388 word w;
31389
31390+ pax_track_stack();
31391+
31392 a = plci->adapter;
31393 Id = ((word)plci->Id<<8)|a->Id;
31394 PUT_WORD(&SS_Ind[4],0x0000);
31395@@ -7484,6 +7486,8 @@ static word add_b1(PLCI *plci, API_PARSE
31396 word j, n, w;
31397 dword d;
31398
31399+ pax_track_stack();
31400+
31401
31402 for(i=0;i<8;i++) bp_parms[i].length = 0;
31403 for(i=0;i<2;i++) global_config[i].length = 0;
31404@@ -7958,6 +7962,8 @@ static word add_b23(PLCI *plci, API_PARS
31405 const byte llc3[] = {4,3,2,2,6,6,0};
31406 const byte header[] = {0,2,3,3,0,0,0};
31407
31408+ pax_track_stack();
31409+
31410 for(i=0;i<8;i++) bp_parms[i].length = 0;
31411 for(i=0;i<6;i++) b2_config_parms[i].length = 0;
31412 for(i=0;i<5;i++) b3_config_parms[i].length = 0;
31413@@ -14760,6 +14766,8 @@ static void group_optimization(DIVA_CAPI
31414 word appl_number_group_type[MAX_APPL];
31415 PLCI *auxplci;
31416
31417+ pax_track_stack();
31418+
31419 set_group_ind_mask (plci); /* all APPLs within this inc. call are allowed to dial in */
31420
31421 if(!a->group_optimization_enabled)
31422diff -urNp linux-2.6.39.1/drivers/isdn/hardware/eicon/mntfunc.c linux-2.6.39.1/drivers/isdn/hardware/eicon/mntfunc.c
31423--- linux-2.6.39.1/drivers/isdn/hardware/eicon/mntfunc.c 2011-05-19 00:06:34.000000000 -0400
31424+++ linux-2.6.39.1/drivers/isdn/hardware/eicon/mntfunc.c 2011-05-22 19:36:31.000000000 -0400
31425@@ -79,6 +79,8 @@ static int DIVA_INIT_FUNCTION connect_di
31426 IDI_SYNC_REQ req;
31427 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
31428
31429+ pax_track_stack();
31430+
31431 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
31432
31433 for (x = 0; x < MAX_DESCRIPTORS; x++) {
31434diff -urNp linux-2.6.39.1/drivers/isdn/i4l/isdn_common.c linux-2.6.39.1/drivers/isdn/i4l/isdn_common.c
31435--- linux-2.6.39.1/drivers/isdn/i4l/isdn_common.c 2011-05-19 00:06:34.000000000 -0400
31436+++ linux-2.6.39.1/drivers/isdn/i4l/isdn_common.c 2011-05-22 19:36:31.000000000 -0400
31437@@ -1292,6 +1292,8 @@ isdn_ioctl(struct file *file, uint cmd,
31438 } iocpar;
31439 void __user *argp = (void __user *)arg;
31440
31441+ pax_track_stack();
31442+
31443 #define name iocpar.name
31444 #define bname iocpar.bname
31445 #define iocts iocpar.iocts
31446diff -urNp linux-2.6.39.1/drivers/isdn/i4l/isdn_net.c linux-2.6.39.1/drivers/isdn/i4l/isdn_net.c
31447--- linux-2.6.39.1/drivers/isdn/i4l/isdn_net.c 2011-05-19 00:06:34.000000000 -0400
31448+++ linux-2.6.39.1/drivers/isdn/i4l/isdn_net.c 2011-05-22 19:36:31.000000000 -0400
31449@@ -400,7 +400,7 @@ isdn_net_stat_callback(int idx, isdn_ctr
31450 isdn_net_local *lp = p->local;
31451 #ifdef CONFIG_ISDN_X25
31452 struct concap_proto *cprot = lp->netdev->cprot;
31453- struct concap_proto_ops *pops = cprot ? cprot->pops : NULL;
31454+ const struct concap_proto_ops *pops = cprot ? cprot->pops : NULL;
31455 #endif
31456 switch (cmd) {
31457 case ISDN_STAT_BSENT:
31458@@ -831,7 +831,7 @@ isdn_net_hangup(struct net_device *d)
31459 isdn_ctrl cmd;
31460 #ifdef CONFIG_ISDN_X25
31461 struct concap_proto *cprot = lp->netdev->cprot;
31462- struct concap_proto_ops *pops = cprot ? cprot->pops : NULL;
31463+ const struct concap_proto_ops *pops = cprot ? cprot->pops : NULL;
31464 #endif
31465
31466 if (lp->flags & ISDN_NET_CONNECTED) {
31467diff -urNp linux-2.6.39.1/drivers/isdn/i4l/isdn_x25iface.c linux-2.6.39.1/drivers/isdn/i4l/isdn_x25iface.c
31468--- linux-2.6.39.1/drivers/isdn/i4l/isdn_x25iface.c 2011-05-19 00:06:34.000000000 -0400
31469+++ linux-2.6.39.1/drivers/isdn/i4l/isdn_x25iface.c 2011-05-22 19:36:31.000000000 -0400
31470@@ -52,7 +52,7 @@ static int isdn_x25iface_connect_ind( st
31471 static int isdn_x25iface_disconn_ind( struct concap_proto * );
31472
31473
31474-static struct concap_proto_ops ix25_pops = {
31475+static const struct concap_proto_ops ix25_pops = {
31476 &isdn_x25iface_proto_new,
31477 &isdn_x25iface_proto_del,
31478 &isdn_x25iface_proto_restart,
31479diff -urNp linux-2.6.39.1/drivers/isdn/i4l/isdn_x25iface.h linux-2.6.39.1/drivers/isdn/i4l/isdn_x25iface.h
31480--- linux-2.6.39.1/drivers/isdn/i4l/isdn_x25iface.h 2011-05-19 00:06:34.000000000 -0400
31481+++ linux-2.6.39.1/drivers/isdn/i4l/isdn_x25iface.h 2011-05-22 19:36:31.000000000 -0400
31482@@ -23,7 +23,7 @@
31483 #include <linux/isdn.h>
31484 #include <linux/concap.h>
31485
31486-extern struct concap_proto_ops * isdn_x25iface_concap_proto_ops_pt;
31487+extern const struct concap_proto_ops *isdn_x25iface_concap_proto_ops_pt;
31488 extern struct concap_proto * isdn_x25iface_proto_new(void);
31489
31490
31491diff -urNp linux-2.6.39.1/drivers/isdn/icn/icn.c linux-2.6.39.1/drivers/isdn/icn/icn.c
31492--- linux-2.6.39.1/drivers/isdn/icn/icn.c 2011-05-19 00:06:34.000000000 -0400
31493+++ linux-2.6.39.1/drivers/isdn/icn/icn.c 2011-05-22 19:36:31.000000000 -0400
31494@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char * buf, int len
31495 if (count > len)
31496 count = len;
31497 if (user) {
31498- if (copy_from_user(msg, buf, count))
31499+ if (count > sizeof msg || copy_from_user(msg, buf, count))
31500 return -EFAULT;
31501 } else
31502 memcpy(msg, buf, count);
31503diff -urNp linux-2.6.39.1/drivers/lguest/core.c linux-2.6.39.1/drivers/lguest/core.c
31504--- linux-2.6.39.1/drivers/lguest/core.c 2011-05-19 00:06:34.000000000 -0400
31505+++ linux-2.6.39.1/drivers/lguest/core.c 2011-05-22 19:36:31.000000000 -0400
31506@@ -92,9 +92,17 @@ static __init int map_switcher(void)
31507 * it's worked so far. The end address needs +1 because __get_vm_area
31508 * allocates an extra guard page, so we need space for that.
31509 */
31510+
31511+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31512+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
31513+ VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
31514+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
31515+#else
31516 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
31517 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
31518 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
31519+#endif
31520+
31521 if (!switcher_vma) {
31522 err = -ENOMEM;
31523 printk("lguest: could not map switcher pages high\n");
31524@@ -119,7 +127,7 @@ static __init int map_switcher(void)
31525 * Now the Switcher is mapped at the right address, we can't fail!
31526 * Copy in the compiled-in Switcher code (from <arch>_switcher.S).
31527 */
31528- memcpy(switcher_vma->addr, start_switcher_text,
31529+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
31530 end_switcher_text - start_switcher_text);
31531
31532 printk(KERN_INFO "lguest: mapped switcher at %p\n",
31533diff -urNp linux-2.6.39.1/drivers/lguest/lguest_device.c linux-2.6.39.1/drivers/lguest/lguest_device.c
31534--- linux-2.6.39.1/drivers/lguest/lguest_device.c 2011-05-19 00:06:34.000000000 -0400
31535+++ linux-2.6.39.1/drivers/lguest/lguest_device.c 2011-05-22 19:36:31.000000000 -0400
31536@@ -374,7 +374,7 @@ error:
31537 }
31538
31539 /* The ops structure which hooks everything together. */
31540-static struct virtio_config_ops lguest_config_ops = {
31541+static const struct virtio_config_ops lguest_config_ops = {
31542 .get_features = lg_get_features,
31543 .finalize_features = lg_finalize_features,
31544 .get = lg_get,
31545diff -urNp linux-2.6.39.1/drivers/lguest/x86/core.c linux-2.6.39.1/drivers/lguest/x86/core.c
31546--- linux-2.6.39.1/drivers/lguest/x86/core.c 2011-05-19 00:06:34.000000000 -0400
31547+++ linux-2.6.39.1/drivers/lguest/x86/core.c 2011-05-22 19:36:31.000000000 -0400
31548@@ -59,7 +59,7 @@ static struct {
31549 /* Offset from where switcher.S was compiled to where we've copied it */
31550 static unsigned long switcher_offset(void)
31551 {
31552- return SWITCHER_ADDR - (unsigned long)start_switcher_text;
31553+ return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
31554 }
31555
31556 /* This cpu's struct lguest_pages. */
31557@@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg
31558 * These copies are pretty cheap, so we do them unconditionally: */
31559 /* Save the current Host top-level page directory.
31560 */
31561+
31562+#ifdef CONFIG_PAX_PER_CPU_PGD
31563+ pages->state.host_cr3 = read_cr3();
31564+#else
31565 pages->state.host_cr3 = __pa(current->mm->pgd);
31566+#endif
31567+
31568 /*
31569 * Set up the Guest's page tables to see this CPU's pages (and no
31570 * other CPU's pages).
31571@@ -547,7 +553,7 @@ void __init lguest_arch_host_init(void)
31572 * compiled-in switcher code and the high-mapped copy we just made.
31573 */
31574 for (i = 0; i < IDT_ENTRIES; i++)
31575- default_idt_entries[i] += switcher_offset();
31576+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
31577
31578 /*
31579 * Set up the Switcher's per-cpu areas.
31580@@ -630,7 +636,7 @@ void __init lguest_arch_host_init(void)
31581 * it will be undisturbed when we switch. To change %cs and jump we
31582 * need this structure to feed to Intel's "lcall" instruction.
31583 */
31584- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
31585+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
31586 lguest_entry.segment = LGUEST_CS;
31587
31588 /*
31589diff -urNp linux-2.6.39.1/drivers/lguest/x86/switcher_32.S linux-2.6.39.1/drivers/lguest/x86/switcher_32.S
31590--- linux-2.6.39.1/drivers/lguest/x86/switcher_32.S 2011-05-19 00:06:34.000000000 -0400
31591+++ linux-2.6.39.1/drivers/lguest/x86/switcher_32.S 2011-05-22 19:36:31.000000000 -0400
31592@@ -87,6 +87,7 @@
31593 #include <asm/page.h>
31594 #include <asm/segment.h>
31595 #include <asm/lguest.h>
31596+#include <asm/processor-flags.h>
31597
31598 // We mark the start of the code to copy
31599 // It's placed in .text tho it's never run here
31600@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
31601 // Changes type when we load it: damn Intel!
31602 // For after we switch over our page tables
31603 // That entry will be read-only: we'd crash.
31604+
31605+#ifdef CONFIG_PAX_KERNEXEC
31606+ mov %cr0, %edx
31607+ xor $X86_CR0_WP, %edx
31608+ mov %edx, %cr0
31609+#endif
31610+
31611 movl $(GDT_ENTRY_TSS*8), %edx
31612 ltr %dx
31613
31614@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
31615 // Let's clear it again for our return.
31616 // The GDT descriptor of the Host
31617 // Points to the table after two "size" bytes
31618- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
31619+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
31620 // Clear "used" from type field (byte 5, bit 2)
31621- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
31622+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
31623+
31624+#ifdef CONFIG_PAX_KERNEXEC
31625+ mov %cr0, %eax
31626+ xor $X86_CR0_WP, %eax
31627+ mov %eax, %cr0
31628+#endif
31629
31630 // Once our page table's switched, the Guest is live!
31631 // The Host fades as we run this final step.
31632@@ -295,13 +309,12 @@ deliver_to_host:
31633 // I consulted gcc, and it gave
31634 // These instructions, which I gladly credit:
31635 leal (%edx,%ebx,8), %eax
31636- movzwl (%eax),%edx
31637- movl 4(%eax), %eax
31638- xorw %ax, %ax
31639- orl %eax, %edx
31640+ movl 4(%eax), %edx
31641+ movw (%eax), %dx
31642 // Now the address of the handler's in %edx
31643 // We call it now: its "iret" drops us home.
31644- jmp *%edx
31645+ ljmp $__KERNEL_CS, $1f
31646+1: jmp *%edx
31647
31648 // Every interrupt can come to us here
31649 // But we must truly tell each apart.
31650diff -urNp linux-2.6.39.1/drivers/md/dm.c linux-2.6.39.1/drivers/md/dm.c
31651--- linux-2.6.39.1/drivers/md/dm.c 2011-05-19 00:06:34.000000000 -0400
31652+++ linux-2.6.39.1/drivers/md/dm.c 2011-05-22 19:36:31.000000000 -0400
31653@@ -162,9 +162,9 @@ struct mapped_device {
31654 /*
31655 * Event handling.
31656 */
31657- atomic_t event_nr;
31658+ atomic_unchecked_t event_nr;
31659 wait_queue_head_t eventq;
31660- atomic_t uevent_seq;
31661+ atomic_unchecked_t uevent_seq;
31662 struct list_head uevent_list;
31663 spinlock_t uevent_lock; /* Protect access to uevent_list */
31664
31665@@ -1836,8 +1836,8 @@ static struct mapped_device *alloc_dev(i
31666 rwlock_init(&md->map_lock);
31667 atomic_set(&md->holders, 1);
31668 atomic_set(&md->open_count, 0);
31669- atomic_set(&md->event_nr, 0);
31670- atomic_set(&md->uevent_seq, 0);
31671+ atomic_set_unchecked(&md->event_nr, 0);
31672+ atomic_set_unchecked(&md->uevent_seq, 0);
31673 INIT_LIST_HEAD(&md->uevent_list);
31674 spin_lock_init(&md->uevent_lock);
31675
31676@@ -1971,7 +1971,7 @@ static void event_callback(void *context
31677
31678 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
31679
31680- atomic_inc(&md->event_nr);
31681+ atomic_inc_unchecked(&md->event_nr);
31682 wake_up(&md->eventq);
31683 }
31684
31685@@ -2547,18 +2547,18 @@ int dm_kobject_uevent(struct mapped_devi
31686
31687 uint32_t dm_next_uevent_seq(struct mapped_device *md)
31688 {
31689- return atomic_add_return(1, &md->uevent_seq);
31690+ return atomic_add_return_unchecked(1, &md->uevent_seq);
31691 }
31692
31693 uint32_t dm_get_event_nr(struct mapped_device *md)
31694 {
31695- return atomic_read(&md->event_nr);
31696+ return atomic_read_unchecked(&md->event_nr);
31697 }
31698
31699 int dm_wait_event(struct mapped_device *md, int event_nr)
31700 {
31701 return wait_event_interruptible(md->eventq,
31702- (event_nr != atomic_read(&md->event_nr)));
31703+ (event_nr != atomic_read_unchecked(&md->event_nr)));
31704 }
31705
31706 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
31707diff -urNp linux-2.6.39.1/drivers/md/dm-crypt.c linux-2.6.39.1/drivers/md/dm-crypt.c
31708--- linux-2.6.39.1/drivers/md/dm-crypt.c 2011-05-19 00:06:34.000000000 -0400
31709+++ linux-2.6.39.1/drivers/md/dm-crypt.c 2011-05-22 19:36:31.000000000 -0400
31710@@ -138,7 +138,7 @@ struct crypt_config {
31711 char *cipher;
31712 char *cipher_string;
31713
31714- struct crypt_iv_operations *iv_gen_ops;
31715+ const struct crypt_iv_operations *iv_gen_ops;
31716 union {
31717 struct iv_essiv_private essiv;
31718 struct iv_benbi_private benbi;
31719@@ -620,15 +620,15 @@ static int crypt_iv_lmk_post(struct cryp
31720 return r;
31721 }
31722
31723-static struct crypt_iv_operations crypt_iv_plain_ops = {
31724+static const struct crypt_iv_operations crypt_iv_plain_ops = {
31725 .generator = crypt_iv_plain_gen
31726 };
31727
31728-static struct crypt_iv_operations crypt_iv_plain64_ops = {
31729+static const struct crypt_iv_operations crypt_iv_plain64_ops = {
31730 .generator = crypt_iv_plain64_gen
31731 };
31732
31733-static struct crypt_iv_operations crypt_iv_essiv_ops = {
31734+static const struct crypt_iv_operations crypt_iv_essiv_ops = {
31735 .ctr = crypt_iv_essiv_ctr,
31736 .dtr = crypt_iv_essiv_dtr,
31737 .init = crypt_iv_essiv_init,
31738@@ -636,17 +636,17 @@ static struct crypt_iv_operations crypt_
31739 .generator = crypt_iv_essiv_gen
31740 };
31741
31742-static struct crypt_iv_operations crypt_iv_benbi_ops = {
31743+static const struct crypt_iv_operations crypt_iv_benbi_ops = {
31744 .ctr = crypt_iv_benbi_ctr,
31745 .dtr = crypt_iv_benbi_dtr,
31746 .generator = crypt_iv_benbi_gen
31747 };
31748
31749-static struct crypt_iv_operations crypt_iv_null_ops = {
31750+static const struct crypt_iv_operations crypt_iv_null_ops = {
31751 .generator = crypt_iv_null_gen
31752 };
31753
31754-static struct crypt_iv_operations crypt_iv_lmk_ops = {
31755+static const struct crypt_iv_operations crypt_iv_lmk_ops = {
31756 .ctr = crypt_iv_lmk_ctr,
31757 .dtr = crypt_iv_lmk_dtr,
31758 .init = crypt_iv_lmk_init,
31759diff -urNp linux-2.6.39.1/drivers/md/dm-ioctl.c linux-2.6.39.1/drivers/md/dm-ioctl.c
31760--- linux-2.6.39.1/drivers/md/dm-ioctl.c 2011-05-19 00:06:34.000000000 -0400
31761+++ linux-2.6.39.1/drivers/md/dm-ioctl.c 2011-05-22 19:36:31.000000000 -0400
31762@@ -1551,7 +1551,7 @@ static int validate_params(uint cmd, str
31763 cmd == DM_LIST_VERSIONS_CMD)
31764 return 0;
31765
31766- if ((cmd == DM_DEV_CREATE_CMD)) {
31767+ if (cmd == DM_DEV_CREATE_CMD) {
31768 if (!*param->name) {
31769 DMWARN("name not supplied when creating device");
31770 return -EINVAL;
31771diff -urNp linux-2.6.39.1/drivers/md/dm-raid1.c linux-2.6.39.1/drivers/md/dm-raid1.c
31772--- linux-2.6.39.1/drivers/md/dm-raid1.c 2011-05-19 00:06:34.000000000 -0400
31773+++ linux-2.6.39.1/drivers/md/dm-raid1.c 2011-05-22 19:36:31.000000000 -0400
31774@@ -42,7 +42,7 @@ enum dm_raid1_error {
31775
31776 struct mirror {
31777 struct mirror_set *ms;
31778- atomic_t error_count;
31779+ atomic_unchecked_t error_count;
31780 unsigned long error_type;
31781 struct dm_dev *dev;
31782 sector_t offset;
31783@@ -187,7 +187,7 @@ static struct mirror *get_valid_mirror(s
31784 struct mirror *m;
31785
31786 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
31787- if (!atomic_read(&m->error_count))
31788+ if (!atomic_read_unchecked(&m->error_count))
31789 return m;
31790
31791 return NULL;
31792@@ -219,7 +219,7 @@ static void fail_mirror(struct mirror *m
31793 * simple way to tell if a device has encountered
31794 * errors.
31795 */
31796- atomic_inc(&m->error_count);
31797+ atomic_inc_unchecked(&m->error_count);
31798
31799 if (test_and_set_bit(error_type, &m->error_type))
31800 return;
31801@@ -410,7 +410,7 @@ static struct mirror *choose_mirror(stru
31802 struct mirror *m = get_default_mirror(ms);
31803
31804 do {
31805- if (likely(!atomic_read(&m->error_count)))
31806+ if (likely(!atomic_read_unchecked(&m->error_count)))
31807 return m;
31808
31809 if (m-- == ms->mirror)
31810@@ -424,7 +424,7 @@ static int default_ok(struct mirror *m)
31811 {
31812 struct mirror *default_mirror = get_default_mirror(m->ms);
31813
31814- return !atomic_read(&default_mirror->error_count);
31815+ return !atomic_read_unchecked(&default_mirror->error_count);
31816 }
31817
31818 static int mirror_available(struct mirror_set *ms, struct bio *bio)
31819@@ -561,7 +561,7 @@ static void do_reads(struct mirror_set *
31820 */
31821 if (likely(region_in_sync(ms, region, 1)))
31822 m = choose_mirror(ms, bio->bi_sector);
31823- else if (m && atomic_read(&m->error_count))
31824+ else if (m && atomic_read_unchecked(&m->error_count))
31825 m = NULL;
31826
31827 if (likely(m))
31828@@ -939,7 +939,7 @@ static int get_mirror(struct mirror_set
31829 }
31830
31831 ms->mirror[mirror].ms = ms;
31832- atomic_set(&(ms->mirror[mirror].error_count), 0);
31833+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
31834 ms->mirror[mirror].error_type = 0;
31835 ms->mirror[mirror].offset = offset;
31836
31837@@ -1347,7 +1347,7 @@ static void mirror_resume(struct dm_targ
31838 */
31839 static char device_status_char(struct mirror *m)
31840 {
31841- if (!atomic_read(&(m->error_count)))
31842+ if (!atomic_read_unchecked(&(m->error_count)))
31843 return 'A';
31844
31845 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
31846diff -urNp linux-2.6.39.1/drivers/md/dm-stripe.c linux-2.6.39.1/drivers/md/dm-stripe.c
31847--- linux-2.6.39.1/drivers/md/dm-stripe.c 2011-05-19 00:06:34.000000000 -0400
31848+++ linux-2.6.39.1/drivers/md/dm-stripe.c 2011-05-22 19:36:31.000000000 -0400
31849@@ -20,7 +20,7 @@ struct stripe {
31850 struct dm_dev *dev;
31851 sector_t physical_start;
31852
31853- atomic_t error_count;
31854+ atomic_unchecked_t error_count;
31855 };
31856
31857 struct stripe_c {
31858@@ -192,7 +192,7 @@ static int stripe_ctr(struct dm_target *
31859 kfree(sc);
31860 return r;
31861 }
31862- atomic_set(&(sc->stripe[i].error_count), 0);
31863+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
31864 }
31865
31866 ti->private = sc;
31867@@ -314,7 +314,7 @@ static int stripe_status(struct dm_targe
31868 DMEMIT("%d ", sc->stripes);
31869 for (i = 0; i < sc->stripes; i++) {
31870 DMEMIT("%s ", sc->stripe[i].dev->name);
31871- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
31872+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
31873 'D' : 'A';
31874 }
31875 buffer[i] = '\0';
31876@@ -361,8 +361,8 @@ static int stripe_end_io(struct dm_targe
31877 */
31878 for (i = 0; i < sc->stripes; i++)
31879 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
31880- atomic_inc(&(sc->stripe[i].error_count));
31881- if (atomic_read(&(sc->stripe[i].error_count)) <
31882+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
31883+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
31884 DM_IO_ERROR_THRESHOLD)
31885 schedule_work(&sc->trigger_event);
31886 }
31887diff -urNp linux-2.6.39.1/drivers/md/dm-table.c linux-2.6.39.1/drivers/md/dm-table.c
31888--- linux-2.6.39.1/drivers/md/dm-table.c 2011-06-03 00:04:14.000000000 -0400
31889+++ linux-2.6.39.1/drivers/md/dm-table.c 2011-06-03 00:32:05.000000000 -0400
31890@@ -390,7 +390,7 @@ static int device_area_is_invalid(struct
31891 if (!dev_size)
31892 return 0;
31893
31894- if ((start >= dev_size) || (start + len > dev_size)) {
31895+ if ((start >= dev_size) || (len > dev_size - start)) {
31896 DMWARN("%s: %s too small for target: "
31897 "start=%llu, len=%llu, dev_size=%llu",
31898 dm_device_name(ti->table->md), bdevname(bdev, b),
31899diff -urNp linux-2.6.39.1/drivers/md/md.c linux-2.6.39.1/drivers/md/md.c
31900--- linux-2.6.39.1/drivers/md/md.c 2011-06-03 00:04:14.000000000 -0400
31901+++ linux-2.6.39.1/drivers/md/md.c 2011-06-03 00:32:05.000000000 -0400
31902@@ -226,10 +226,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
31903 * start build, activate spare
31904 */
31905 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
31906-static atomic_t md_event_count;
31907+static atomic_unchecked_t md_event_count;
31908 void md_new_event(mddev_t *mddev)
31909 {
31910- atomic_inc(&md_event_count);
31911+ atomic_inc_unchecked(&md_event_count);
31912 wake_up(&md_event_waiters);
31913 }
31914 EXPORT_SYMBOL_GPL(md_new_event);
31915@@ -239,7 +239,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
31916 */
31917 static void md_new_event_inintr(mddev_t *mddev)
31918 {
31919- atomic_inc(&md_event_count);
31920+ atomic_inc_unchecked(&md_event_count);
31921 wake_up(&md_event_waiters);
31922 }
31923
31924@@ -1454,7 +1454,7 @@ static int super_1_load(mdk_rdev_t *rdev
31925
31926 rdev->preferred_minor = 0xffff;
31927 rdev->data_offset = le64_to_cpu(sb->data_offset);
31928- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
31929+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
31930
31931 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
31932 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
31933@@ -1632,7 +1632,7 @@ static void super_1_sync(mddev_t *mddev,
31934 else
31935 sb->resync_offset = cpu_to_le64(0);
31936
31937- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
31938+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
31939
31940 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
31941 sb->size = cpu_to_le64(mddev->dev_sectors);
31942@@ -2414,7 +2414,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_sho
31943 static ssize_t
31944 errors_show(mdk_rdev_t *rdev, char *page)
31945 {
31946- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
31947+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
31948 }
31949
31950 static ssize_t
31951@@ -2423,7 +2423,7 @@ errors_store(mdk_rdev_t *rdev, const cha
31952 char *e;
31953 unsigned long n = simple_strtoul(buf, &e, 10);
31954 if (*buf && (*e == 0 || *e == '\n')) {
31955- atomic_set(&rdev->corrected_errors, n);
31956+ atomic_set_unchecked(&rdev->corrected_errors, n);
31957 return len;
31958 }
31959 return -EINVAL;
31960@@ -2779,8 +2779,8 @@ void md_rdev_init(mdk_rdev_t *rdev)
31961 rdev->last_read_error.tv_sec = 0;
31962 rdev->last_read_error.tv_nsec = 0;
31963 atomic_set(&rdev->nr_pending, 0);
31964- atomic_set(&rdev->read_errors, 0);
31965- atomic_set(&rdev->corrected_errors, 0);
31966+ atomic_set_unchecked(&rdev->read_errors, 0);
31967+ atomic_set_unchecked(&rdev->corrected_errors, 0);
31968
31969 INIT_LIST_HEAD(&rdev->same_set);
31970 init_waitqueue_head(&rdev->blocked_wait);
31971@@ -6388,7 +6388,7 @@ static int md_seq_show(struct seq_file *
31972
31973 spin_unlock(&pers_lock);
31974 seq_printf(seq, "\n");
31975- mi->event = atomic_read(&md_event_count);
31976+ mi->event = atomic_read_unchecked(&md_event_count);
31977 return 0;
31978 }
31979 if (v == (void*)2) {
31980@@ -6477,7 +6477,7 @@ static int md_seq_show(struct seq_file *
31981 chunk_kb ? "KB" : "B");
31982 if (bitmap->file) {
31983 seq_printf(seq, ", file: ");
31984- seq_path(seq, &bitmap->file->f_path, " \t\n");
31985+ seq_path(seq, &bitmap->file->f_path, " \t\n\\");
31986 }
31987
31988 seq_printf(seq, "\n");
31989@@ -6511,7 +6511,7 @@ static int md_seq_open(struct inode *ino
31990 else {
31991 struct seq_file *p = file->private_data;
31992 p->private = mi;
31993- mi->event = atomic_read(&md_event_count);
31994+ mi->event = atomic_read_unchecked(&md_event_count);
31995 }
31996 return error;
31997 }
31998@@ -6527,7 +6527,7 @@ static unsigned int mdstat_poll(struct f
31999 /* always allow read */
32000 mask = POLLIN | POLLRDNORM;
32001
32002- if (mi->event != atomic_read(&md_event_count))
32003+ if (mi->event != atomic_read_unchecked(&md_event_count))
32004 mask |= POLLERR | POLLPRI;
32005 return mask;
32006 }
32007@@ -6571,7 +6571,7 @@ static int is_mddev_idle(mddev_t *mddev,
32008 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
32009 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
32010 (int)part_stat_read(&disk->part0, sectors[1]) -
32011- atomic_read(&disk->sync_io);
32012+ atomic_read_unchecked(&disk->sync_io);
32013 /* sync IO will cause sync_io to increase before the disk_stats
32014 * as sync_io is counted when a request starts, and
32015 * disk_stats is counted when it completes.
32016diff -urNp linux-2.6.39.1/drivers/md/md.h linux-2.6.39.1/drivers/md/md.h
32017--- linux-2.6.39.1/drivers/md/md.h 2011-05-19 00:06:34.000000000 -0400
32018+++ linux-2.6.39.1/drivers/md/md.h 2011-05-22 19:36:31.000000000 -0400
32019@@ -97,13 +97,13 @@ struct mdk_rdev_s
32020 * only maintained for arrays that
32021 * support hot removal
32022 */
32023- atomic_t read_errors; /* number of consecutive read errors that
32024+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
32025 * we have tried to ignore.
32026 */
32027 struct timespec last_read_error; /* monotonic time since our
32028 * last read error
32029 */
32030- atomic_t corrected_errors; /* number of corrected read errors,
32031+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
32032 * for reporting to userspace and storing
32033 * in superblock.
32034 */
32035@@ -342,7 +342,7 @@ static inline void rdev_dec_pending(mdk_
32036
32037 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
32038 {
32039- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
32040+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
32041 }
32042
32043 struct mdk_personality
32044diff -urNp linux-2.6.39.1/drivers/md/raid10.c linux-2.6.39.1/drivers/md/raid10.c
32045--- linux-2.6.39.1/drivers/md/raid10.c 2011-05-19 00:06:34.000000000 -0400
32046+++ linux-2.6.39.1/drivers/md/raid10.c 2011-05-22 19:36:31.000000000 -0400
32047@@ -1209,7 +1209,7 @@ static void end_sync_read(struct bio *bi
32048 if (test_bit(BIO_UPTODATE, &bio->bi_flags))
32049 set_bit(R10BIO_Uptodate, &r10_bio->state);
32050 else {
32051- atomic_add(r10_bio->sectors,
32052+ atomic_add_unchecked(r10_bio->sectors,
32053 &conf->mirrors[d].rdev->corrected_errors);
32054 if (!test_bit(MD_RECOVERY_SYNC, &conf->mddev->recovery))
32055 md_error(r10_bio->mddev,
32056@@ -1417,7 +1417,7 @@ static void check_decay_read_errors(mdde
32057 {
32058 struct timespec cur_time_mon;
32059 unsigned long hours_since_last;
32060- unsigned int read_errors = atomic_read(&rdev->read_errors);
32061+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
32062
32063 ktime_get_ts(&cur_time_mon);
32064
32065@@ -1439,9 +1439,9 @@ static void check_decay_read_errors(mdde
32066 * overflowing the shift of read_errors by hours_since_last.
32067 */
32068 if (hours_since_last >= 8 * sizeof(read_errors))
32069- atomic_set(&rdev->read_errors, 0);
32070+ atomic_set_unchecked(&rdev->read_errors, 0);
32071 else
32072- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
32073+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
32074 }
32075
32076 /*
32077@@ -1476,8 +1476,8 @@ static void fix_read_error(conf_t *conf,
32078 }
32079
32080 check_decay_read_errors(mddev, rdev);
32081- atomic_inc(&rdev->read_errors);
32082- cur_read_error_count = atomic_read(&rdev->read_errors);
32083+ atomic_inc_unchecked(&rdev->read_errors);
32084+ cur_read_error_count = atomic_read_unchecked(&rdev->read_errors);
32085 if (cur_read_error_count > max_read_errors) {
32086 rcu_read_unlock();
32087 printk(KERN_NOTICE
32088@@ -1550,7 +1550,7 @@ static void fix_read_error(conf_t *conf,
32089 test_bit(In_sync, &rdev->flags)) {
32090 atomic_inc(&rdev->nr_pending);
32091 rcu_read_unlock();
32092- atomic_add(s, &rdev->corrected_errors);
32093+ atomic_add_unchecked(s, &rdev->corrected_errors);
32094 if (sync_page_io(rdev,
32095 r10_bio->devs[sl].addr +
32096 sect,
32097diff -urNp linux-2.6.39.1/drivers/md/raid1.c linux-2.6.39.1/drivers/md/raid1.c
32098--- linux-2.6.39.1/drivers/md/raid1.c 2011-05-19 00:06:34.000000000 -0400
32099+++ linux-2.6.39.1/drivers/md/raid1.c 2011-05-22 19:36:31.000000000 -0400
32100@@ -1342,7 +1342,7 @@ static void sync_request_write(mddev_t *
32101 if (r1_bio->bios[d]->bi_end_io != end_sync_read)
32102 continue;
32103 rdev = conf->mirrors[d].rdev;
32104- atomic_add(s, &rdev->corrected_errors);
32105+ atomic_add_unchecked(s, &rdev->corrected_errors);
32106 if (sync_page_io(rdev,
32107 sect,
32108 s<<9,
32109@@ -1488,7 +1488,7 @@ static void fix_read_error(conf_t *conf,
32110 /* Well, this device is dead */
32111 md_error(mddev, rdev);
32112 else {
32113- atomic_add(s, &rdev->corrected_errors);
32114+ atomic_add_unchecked(s, &rdev->corrected_errors);
32115 printk(KERN_INFO
32116 "md/raid1:%s: read error corrected "
32117 "(%d sectors at %llu on %s)\n",
32118diff -urNp linux-2.6.39.1/drivers/md/raid5.c linux-2.6.39.1/drivers/md/raid5.c
32119--- linux-2.6.39.1/drivers/md/raid5.c 2011-05-19 00:06:34.000000000 -0400
32120+++ linux-2.6.39.1/drivers/md/raid5.c 2011-05-22 19:36:31.000000000 -0400
32121@@ -550,7 +550,7 @@ static void ops_run_io(struct stripe_hea
32122 bi->bi_next = NULL;
32123 if (rw == WRITE &&
32124 test_bit(R5_ReWrite, &sh->dev[i].flags))
32125- atomic_add(STRIPE_SECTORS,
32126+ atomic_add_unchecked(STRIPE_SECTORS,
32127 &rdev->corrected_errors);
32128 generic_make_request(bi);
32129 } else {
32130@@ -1596,15 +1596,15 @@ static void raid5_end_read_request(struc
32131 clear_bit(R5_ReadError, &sh->dev[i].flags);
32132 clear_bit(R5_ReWrite, &sh->dev[i].flags);
32133 }
32134- if (atomic_read(&conf->disks[i].rdev->read_errors))
32135- atomic_set(&conf->disks[i].rdev->read_errors, 0);
32136+ if (atomic_read_unchecked(&conf->disks[i].rdev->read_errors))
32137+ atomic_set_unchecked(&conf->disks[i].rdev->read_errors, 0);
32138 } else {
32139 const char *bdn = bdevname(conf->disks[i].rdev->bdev, b);
32140 int retry = 0;
32141 rdev = conf->disks[i].rdev;
32142
32143 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
32144- atomic_inc(&rdev->read_errors);
32145+ atomic_inc_unchecked(&rdev->read_errors);
32146 if (conf->mddev->degraded >= conf->max_degraded)
32147 printk_rl(KERN_WARNING
32148 "md/raid:%s: read error not correctable "
32149@@ -1622,7 +1622,7 @@ static void raid5_end_read_request(struc
32150 (unsigned long long)(sh->sector
32151 + rdev->data_offset),
32152 bdn);
32153- else if (atomic_read(&rdev->read_errors)
32154+ else if (atomic_read_unchecked(&rdev->read_errors)
32155 > conf->max_nr_stripes)
32156 printk(KERN_WARNING
32157 "md/raid:%s: Too many read errors, failing device %s.\n",
32158@@ -1947,6 +1947,7 @@ static sector_t compute_blocknr(struct s
32159 sector_t r_sector;
32160 struct stripe_head sh2;
32161
32162+ pax_track_stack();
32163
32164 chunk_offset = sector_div(new_sector, sectors_per_chunk);
32165 stripe = new_sector;
32166diff -urNp linux-2.6.39.1/drivers/media/common/saa7146_hlp.c linux-2.6.39.1/drivers/media/common/saa7146_hlp.c
32167--- linux-2.6.39.1/drivers/media/common/saa7146_hlp.c 2011-05-19 00:06:34.000000000 -0400
32168+++ linux-2.6.39.1/drivers/media/common/saa7146_hlp.c 2011-05-22 19:36:31.000000000 -0400
32169@@ -353,6 +353,8 @@ static void calculate_clipping_registers
32170
32171 int x[32], y[32], w[32], h[32];
32172
32173+ pax_track_stack();
32174+
32175 /* clear out memory */
32176 memset(&line_list[0], 0x00, sizeof(u32)*32);
32177 memset(&pixel_list[0], 0x00, sizeof(u32)*32);
32178diff -urNp linux-2.6.39.1/drivers/media/common/saa7146_vbi.c linux-2.6.39.1/drivers/media/common/saa7146_vbi.c
32179--- linux-2.6.39.1/drivers/media/common/saa7146_vbi.c 2011-05-19 00:06:34.000000000 -0400
32180+++ linux-2.6.39.1/drivers/media/common/saa7146_vbi.c 2011-05-22 19:36:31.000000000 -0400
32181@@ -501,7 +501,7 @@ static ssize_t vbi_read(struct file *fil
32182 return ret;
32183 }
32184
32185-struct saa7146_use_ops saa7146_vbi_uops = {
32186+const struct saa7146_use_ops saa7146_vbi_uops = {
32187 .init = vbi_init,
32188 .open = vbi_open,
32189 .release = vbi_close,
32190diff -urNp linux-2.6.39.1/drivers/media/common/saa7146_video.c linux-2.6.39.1/drivers/media/common/saa7146_video.c
32191--- linux-2.6.39.1/drivers/media/common/saa7146_video.c 2011-05-19 00:06:34.000000000 -0400
32192+++ linux-2.6.39.1/drivers/media/common/saa7146_video.c 2011-05-22 19:36:31.000000000 -0400
32193@@ -1420,7 +1420,7 @@ out:
32194 return ret;
32195 }
32196
32197-struct saa7146_use_ops saa7146_video_uops = {
32198+const struct saa7146_use_ops saa7146_video_uops = {
32199 .init = video_init,
32200 .open = video_open,
32201 .release = video_close,
32202diff -urNp linux-2.6.39.1/drivers/media/dvb/dm1105/dm1105.c linux-2.6.39.1/drivers/media/dvb/dm1105/dm1105.c
32203--- linux-2.6.39.1/drivers/media/dvb/dm1105/dm1105.c 2011-05-19 00:06:34.000000000 -0400
32204+++ linux-2.6.39.1/drivers/media/dvb/dm1105/dm1105.c 2011-05-22 19:36:31.000000000 -0400
32205@@ -418,7 +418,7 @@ static u32 functionality(struct i2c_adap
32206 return I2C_FUNC_I2C;
32207 }
32208
32209-static struct i2c_algorithm dm1105_algo = {
32210+static const struct i2c_algorithm dm1105_algo = {
32211 .master_xfer = dm1105_i2c_xfer,
32212 .functionality = functionality,
32213 };
32214diff -urNp linux-2.6.39.1/drivers/media/dvb/dvb-core/dvb_ca_en50221.c linux-2.6.39.1/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
32215--- linux-2.6.39.1/drivers/media/dvb/dvb-core/dvb_ca_en50221.c 2011-05-19 00:06:34.000000000 -0400
32216+++ linux-2.6.39.1/drivers/media/dvb/dvb-core/dvb_ca_en50221.c 2011-05-22 19:36:31.000000000 -0400
32217@@ -590,6 +590,8 @@ static int dvb_ca_en50221_read_data(stru
32218 u8 buf[HOST_LINK_BUF_SIZE];
32219 int i;
32220
32221+ pax_track_stack();
32222+
32223 dprintk("%s\n", __func__);
32224
32225 /* check if we have space for a link buf in the rx_buffer */
32226@@ -1285,6 +1287,8 @@ static ssize_t dvb_ca_en50221_io_write(s
32227 unsigned long timeout;
32228 int written;
32229
32230+ pax_track_stack();
32231+
32232 dprintk("%s\n", __func__);
32233
32234 /* Incoming packet has a 2 byte header. hdr[0] = slot_id, hdr[1] = connection_id */
32235diff -urNp linux-2.6.39.1/drivers/media/dvb/dvb-core/dvbdev.c linux-2.6.39.1/drivers/media/dvb/dvb-core/dvbdev.c
32236--- linux-2.6.39.1/drivers/media/dvb/dvb-core/dvbdev.c 2011-05-19 00:06:34.000000000 -0400
32237+++ linux-2.6.39.1/drivers/media/dvb/dvb-core/dvbdev.c 2011-05-22 19:36:31.000000000 -0400
32238@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapt
32239 const struct dvb_device *template, void *priv, int type)
32240 {
32241 struct dvb_device *dvbdev;
32242- struct file_operations *dvbdevfops;
32243+ struct file_operations *dvbdevfops; /* cannot be const, see this function */
32244 struct device *clsdev;
32245 int minor;
32246 int id;
32247diff -urNp linux-2.6.39.1/drivers/media/dvb/dvb-usb/dib0700_core.c linux-2.6.39.1/drivers/media/dvb/dvb-usb/dib0700_core.c
32248--- linux-2.6.39.1/drivers/media/dvb/dvb-usb/dib0700_core.c 2011-05-19 00:06:34.000000000 -0400
32249+++ linux-2.6.39.1/drivers/media/dvb/dvb-usb/dib0700_core.c 2011-05-22 19:36:31.000000000 -0400
32250@@ -391,6 +391,8 @@ int dib0700_download_firmware(struct usb
32251
32252 u8 buf[260];
32253
32254+ pax_track_stack();
32255+
32256 while ((ret = dvb_usb_get_hexline(fw, &hx, &pos)) > 0) {
32257 deb_fwdata("writing to address 0x%08x (buffer: 0x%02x %02x)\n",
32258 hx.addr, hx.len, hx.chk);
32259diff -urNp linux-2.6.39.1/drivers/media/dvb/dvb-usb/lmedm04.c linux-2.6.39.1/drivers/media/dvb/dvb-usb/lmedm04.c
32260--- linux-2.6.39.1/drivers/media/dvb/dvb-usb/lmedm04.c 2011-05-19 00:06:34.000000000 -0400
32261+++ linux-2.6.39.1/drivers/media/dvb/dvb-usb/lmedm04.c 2011-05-22 19:36:31.000000000 -0400
32262@@ -663,6 +663,7 @@ static int lme2510_download_firmware(str
32263 packet_size = 0x31;
32264 len_in = 1;
32265
32266+ pax_track_stack();
32267
32268 info("FRM Starting Firmware Download");
32269
32270@@ -715,6 +716,8 @@ static void lme_coldreset(struct usb_dev
32271 int ret = 0, len_in;
32272 u8 data[512] = {0};
32273
32274+ pax_track_stack();
32275+
32276 data[0] = 0x0a;
32277 len_in = 1;
32278 info("FRM Firmware Cold Reset");
32279diff -urNp linux-2.6.39.1/drivers/media/dvb/frontends/dib7000p.c linux-2.6.39.1/drivers/media/dvb/frontends/dib7000p.c
32280--- linux-2.6.39.1/drivers/media/dvb/frontends/dib7000p.c 2011-06-03 00:04:14.000000000 -0400
32281+++ linux-2.6.39.1/drivers/media/dvb/frontends/dib7000p.c 2011-06-03 00:32:05.000000000 -0400
32282@@ -1945,7 +1945,7 @@ static u32 dib7000p_i2c_func(struct i2c_
32283 return I2C_FUNC_I2C;
32284 }
32285
32286-static struct i2c_algorithm dib7090_tuner_xfer_algo = {
32287+static const struct i2c_algorithm dib7090_tuner_xfer_algo = {
32288 .master_xfer = dib7090_tuner_xfer,
32289 .functionality = dib7000p_i2c_func,
32290 };
32291diff -urNp linux-2.6.39.1/drivers/media/dvb/frontends/dib9000.c linux-2.6.39.1/drivers/media/dvb/frontends/dib9000.c
32292--- linux-2.6.39.1/drivers/media/dvb/frontends/dib9000.c 2011-06-03 00:04:14.000000000 -0400
32293+++ linux-2.6.39.1/drivers/media/dvb/frontends/dib9000.c 2011-06-03 00:32:05.000000000 -0400
32294@@ -1676,12 +1676,12 @@ static u32 dib9000_i2c_func(struct i2c_a
32295 return I2C_FUNC_I2C;
32296 }
32297
32298-static struct i2c_algorithm dib9000_tuner_algo = {
32299+static const struct i2c_algorithm dib9000_tuner_algo = {
32300 .master_xfer = dib9000_tuner_xfer,
32301 .functionality = dib9000_i2c_func,
32302 };
32303
32304-static struct i2c_algorithm dib9000_component_bus_algo = {
32305+static const struct i2c_algorithm dib9000_component_bus_algo = {
32306 .master_xfer = dib9000_fw_component_bus_xfer,
32307 .functionality = dib9000_i2c_func,
32308 };
32309diff -urNp linux-2.6.39.1/drivers/media/dvb/frontends/dibx000_common.c linux-2.6.39.1/drivers/media/dvb/frontends/dibx000_common.c
32310--- linux-2.6.39.1/drivers/media/dvb/frontends/dibx000_common.c 2011-06-03 00:04:14.000000000 -0400
32311+++ linux-2.6.39.1/drivers/media/dvb/frontends/dibx000_common.c 2011-06-03 00:37:36.000000000 -0400
32312@@ -221,12 +221,12 @@ static int dibx000_i2c_master_xfer_gpio3
32313 return num;
32314 }
32315
32316-static struct i2c_algorithm dibx000_i2c_master_gpio12_xfer_algo = {
32317+static const struct i2c_algorithm dibx000_i2c_master_gpio12_xfer_algo = {
32318 .master_xfer = dibx000_i2c_master_xfer_gpio12,
32319 .functionality = dibx000_i2c_func,
32320 };
32321
32322-static struct i2c_algorithm dibx000_i2c_master_gpio34_xfer_algo = {
32323+static const struct i2c_algorithm dibx000_i2c_master_gpio34_xfer_algo = {
32324 .master_xfer = dibx000_i2c_master_xfer_gpio34,
32325 .functionality = dibx000_i2c_func,
32326 };
32327@@ -285,7 +285,7 @@ static int dibx000_i2c_gated_gpio67_xfer
32328 return i2c_transfer(mst->i2c_adap, mst->msg, 2 + num) == 2 + num ? num : -EIO;
32329 }
32330
32331-static struct i2c_algorithm dibx000_i2c_gated_gpio67_algo = {
32332+static const struct i2c_algorithm dibx000_i2c_gated_gpio67_algo = {
32333 .master_xfer = dibx000_i2c_gated_gpio67_xfer,
32334 .functionality = dibx000_i2c_func,
32335 };
32336@@ -322,7 +322,7 @@ static int dibx000_i2c_gated_tuner_xfer(
32337 return i2c_transfer(mst->i2c_adap, mst->msg, 2 + num) == 2 + num ? num : -EIO;
32338 }
32339
32340-static struct i2c_algorithm dibx000_i2c_gated_tuner_algo = {
32341+static const struct i2c_algorithm dibx000_i2c_gated_tuner_algo = {
32342 .master_xfer = dibx000_i2c_gated_tuner_xfer,
32343 .functionality = dibx000_i2c_func,
32344 };
32345@@ -375,7 +375,7 @@ void dibx000_reset_i2c_master(struct dib
32346 EXPORT_SYMBOL(dibx000_reset_i2c_master);
32347
32348 static int i2c_adapter_init(struct i2c_adapter *i2c_adap,
32349- struct i2c_algorithm *algo, const char *name,
32350+ const struct i2c_algorithm *algo, const char *name,
32351 struct dibx000_i2c_master *mst)
32352 {
32353 strncpy(i2c_adap->name, name, sizeof(i2c_adap->name));
32354diff -urNp linux-2.6.39.1/drivers/media/dvb/frontends/mb86a16.c linux-2.6.39.1/drivers/media/dvb/frontends/mb86a16.c
32355--- linux-2.6.39.1/drivers/media/dvb/frontends/mb86a16.c 2011-05-19 00:06:34.000000000 -0400
32356+++ linux-2.6.39.1/drivers/media/dvb/frontends/mb86a16.c 2011-05-22 19:36:31.000000000 -0400
32357@@ -1060,6 +1060,8 @@ static int mb86a16_set_fe(struct mb86a16
32358 int ret = -1;
32359 int sync;
32360
32361+ pax_track_stack();
32362+
32363 dprintk(verbose, MB86A16_INFO, 1, "freq=%d Mhz, symbrt=%d Ksps", state->frequency, state->srate);
32364
32365 fcp = 3000;
32366diff -urNp linux-2.6.39.1/drivers/media/dvb/frontends/or51211.c linux-2.6.39.1/drivers/media/dvb/frontends/or51211.c
32367--- linux-2.6.39.1/drivers/media/dvb/frontends/or51211.c 2011-05-19 00:06:34.000000000 -0400
32368+++ linux-2.6.39.1/drivers/media/dvb/frontends/or51211.c 2011-05-22 19:36:31.000000000 -0400
32369@@ -113,6 +113,8 @@ static int or51211_load_firmware (struct
32370 u8 tudata[585];
32371 int i;
32372
32373+ pax_track_stack();
32374+
32375 dprintk("Firmware is %zd bytes\n",fw->size);
32376
32377 /* Get eprom data */
32378diff -urNp linux-2.6.39.1/drivers/media/dvb/frontends/s5h1420.c linux-2.6.39.1/drivers/media/dvb/frontends/s5h1420.c
32379--- linux-2.6.39.1/drivers/media/dvb/frontends/s5h1420.c 2011-05-19 00:06:34.000000000 -0400
32380+++ linux-2.6.39.1/drivers/media/dvb/frontends/s5h1420.c 2011-05-22 19:36:31.000000000 -0400
32381@@ -870,7 +870,7 @@ static int s5h1420_tuner_i2c_tuner_xfer(
32382 return i2c_transfer(state->i2c, m, 1+num) == 1 + num ? num : -EIO;
32383 }
32384
32385-static struct i2c_algorithm s5h1420_tuner_i2c_algo = {
32386+static const struct i2c_algorithm s5h1420_tuner_i2c_algo = {
32387 .master_xfer = s5h1420_tuner_i2c_tuner_xfer,
32388 .functionality = s5h1420_tuner_i2c_func,
32389 };
32390diff -urNp linux-2.6.39.1/drivers/media/dvb/mantis/mantis_i2c.c linux-2.6.39.1/drivers/media/dvb/mantis/mantis_i2c.c
32391--- linux-2.6.39.1/drivers/media/dvb/mantis/mantis_i2c.c 2011-05-19 00:06:34.000000000 -0400
32392+++ linux-2.6.39.1/drivers/media/dvb/mantis/mantis_i2c.c 2011-05-22 19:36:31.000000000 -0400
32393@@ -212,7 +212,7 @@ static u32 mantis_i2c_func(struct i2c_ad
32394 return I2C_FUNC_SMBUS_EMUL;
32395 }
32396
32397-static struct i2c_algorithm mantis_algo = {
32398+static const struct i2c_algorithm mantis_algo = {
32399 .master_xfer = mantis_i2c_xfer,
32400 .functionality = mantis_i2c_func,
32401 };
32402diff -urNp linux-2.6.39.1/drivers/media/dvb/ttusb-dec/ttusb_dec.c linux-2.6.39.1/drivers/media/dvb/ttusb-dec/ttusb_dec.c
32403--- linux-2.6.39.1/drivers/media/dvb/ttusb-dec/ttusb_dec.c 2011-05-19 00:06:34.000000000 -0400
32404+++ linux-2.6.39.1/drivers/media/dvb/ttusb-dec/ttusb_dec.c 2011-05-22 19:36:31.000000000 -0400
32405@@ -1614,7 +1614,7 @@ static int fe_send_command(struct dvb_fr
32406 return ttusb_dec_send_command(dec, command, param_length, params, result_length, cmd_result);
32407 }
32408
32409-static struct ttusbdecfe_config fe_config = {
32410+static const struct ttusbdecfe_config fe_config = {
32411 .send_command = fe_send_command
32412 };
32413
32414diff -urNp linux-2.6.39.1/drivers/media/radio/radio-cadet.c linux-2.6.39.1/drivers/media/radio/radio-cadet.c
32415--- linux-2.6.39.1/drivers/media/radio/radio-cadet.c 2011-05-19 00:06:34.000000000 -0400
32416+++ linux-2.6.39.1/drivers/media/radio/radio-cadet.c 2011-05-22 19:36:31.000000000 -0400
32417@@ -349,7 +349,7 @@ static ssize_t cadet_read(struct file *f
32418 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
32419 mutex_unlock(&dev->lock);
32420
32421- if (copy_to_user(data, readbuf, i))
32422+ if (i > sizeof readbuf || copy_to_user(data, readbuf, i))
32423 return -EFAULT;
32424 return i;
32425 }
32426diff -urNp linux-2.6.39.1/drivers/media/radio/radio-si4713.c linux-2.6.39.1/drivers/media/radio/radio-si4713.c
32427--- linux-2.6.39.1/drivers/media/radio/radio-si4713.c 2011-05-19 00:06:34.000000000 -0400
32428+++ linux-2.6.39.1/drivers/media/radio/radio-si4713.c 2011-05-22 19:36:31.000000000 -0400
32429@@ -231,7 +231,7 @@ static long radio_si4713_default(struct
32430 ioctl, cmd, arg);
32431 }
32432
32433-static struct v4l2_ioctl_ops radio_si4713_ioctl_ops = {
32434+static const struct v4l2_ioctl_ops radio_si4713_ioctl_ops = {
32435 .vidioc_enumaudout = radio_si4713_enumaudout,
32436 .vidioc_g_audout = radio_si4713_g_audout,
32437 .vidioc_s_audout = radio_si4713_s_audout,
32438diff -urNp linux-2.6.39.1/drivers/media/rc/ir-lirc-codec.c linux-2.6.39.1/drivers/media/rc/ir-lirc-codec.c
32439--- linux-2.6.39.1/drivers/media/rc/ir-lirc-codec.c 2011-05-19 00:06:34.000000000 -0400
32440+++ linux-2.6.39.1/drivers/media/rc/ir-lirc-codec.c 2011-05-22 19:36:31.000000000 -0400
32441@@ -277,7 +277,7 @@ static void ir_lirc_close(void *data)
32442 return;
32443 }
32444
32445-static struct file_operations lirc_fops = {
32446+static const struct file_operations lirc_fops = {
32447 .owner = THIS_MODULE,
32448 .write = ir_lirc_transmit_ir,
32449 .unlocked_ioctl = ir_lirc_ioctl,
32450diff -urNp linux-2.6.39.1/drivers/media/rc/lirc_dev.c linux-2.6.39.1/drivers/media/rc/lirc_dev.c
32451--- linux-2.6.39.1/drivers/media/rc/lirc_dev.c 2011-05-19 00:06:34.000000000 -0400
32452+++ linux-2.6.39.1/drivers/media/rc/lirc_dev.c 2011-05-22 19:36:31.000000000 -0400
32453@@ -151,7 +151,7 @@ static int lirc_thread(void *irctl)
32454 }
32455
32456
32457-static struct file_operations lirc_dev_fops = {
32458+static const struct file_operations lirc_dev_fops = {
32459 .owner = THIS_MODULE,
32460 .read = lirc_dev_fop_read,
32461 .write = lirc_dev_fop_write,
32462diff -urNp linux-2.6.39.1/drivers/media/rc/rc-main.c linux-2.6.39.1/drivers/media/rc/rc-main.c
32463--- linux-2.6.39.1/drivers/media/rc/rc-main.c 2011-05-19 00:06:34.000000000 -0400
32464+++ linux-2.6.39.1/drivers/media/rc/rc-main.c 2011-05-22 19:36:31.000000000 -0400
32465@@ -996,7 +996,7 @@ EXPORT_SYMBOL_GPL(rc_free_device);
32466
32467 int rc_register_device(struct rc_dev *dev)
32468 {
32469- static atomic_t devno = ATOMIC_INIT(0);
32470+ static atomic_unchecked_t devno = ATOMIC_INIT(0);
32471 struct rc_map *rc_map;
32472 const char *path;
32473 int rc;
32474@@ -1019,7 +1019,7 @@ int rc_register_device(struct rc_dev *de
32475 if (dev->close)
32476 dev->input_dev->close = ir_close;
32477
32478- dev->devno = (unsigned long)(atomic_inc_return(&devno) - 1);
32479+ dev->devno = (unsigned long)(atomic_inc_return_unchecked(&devno) - 1);
32480 dev_set_name(&dev->dev, "rc%ld", dev->devno);
32481 dev_set_drvdata(&dev->dev, dev);
32482 rc = device_add(&dev->dev);
32483diff -urNp linux-2.6.39.1/drivers/media/video/cafe_ccic.c linux-2.6.39.1/drivers/media/video/cafe_ccic.c
32484--- linux-2.6.39.1/drivers/media/video/cafe_ccic.c 2011-05-19 00:06:34.000000000 -0400
32485+++ linux-2.6.39.1/drivers/media/video/cafe_ccic.c 2011-05-22 19:36:31.000000000 -0400
32486@@ -520,7 +520,7 @@ static u32 cafe_smbus_func(struct i2c_ad
32487 I2C_FUNC_SMBUS_WRITE_BYTE_DATA;
32488 }
32489
32490-static struct i2c_algorithm cafe_smbus_algo = {
32491+static const struct i2c_algorithm cafe_smbus_algo = {
32492 .smbus_xfer = cafe_smbus_xfer,
32493 .functionality = cafe_smbus_func
32494 };
32495diff -urNp linux-2.6.39.1/drivers/media/video/cx18/cx18-alsa-pcm.c linux-2.6.39.1/drivers/media/video/cx18/cx18-alsa-pcm.c
32496--- linux-2.6.39.1/drivers/media/video/cx18/cx18-alsa-pcm.c 2011-05-19 00:06:34.000000000 -0400
32497+++ linux-2.6.39.1/drivers/media/video/cx18/cx18-alsa-pcm.c 2011-05-22 19:36:31.000000000 -0400
32498@@ -314,7 +314,7 @@ static struct page *snd_pcm_get_vmalloc_
32499 return vmalloc_to_page(pageptr);
32500 }
32501
32502-static struct snd_pcm_ops snd_cx18_pcm_capture_ops = {
32503+static const struct snd_pcm_ops snd_cx18_pcm_capture_ops = {
32504 .open = snd_cx18_pcm_capture_open,
32505 .close = snd_cx18_pcm_capture_close,
32506 .ioctl = snd_cx18_pcm_ioctl,
32507diff -urNp linux-2.6.39.1/drivers/media/video/cx18/cx18-driver.c linux-2.6.39.1/drivers/media/video/cx18/cx18-driver.c
32508--- linux-2.6.39.1/drivers/media/video/cx18/cx18-driver.c 2011-05-19 00:06:34.000000000 -0400
32509+++ linux-2.6.39.1/drivers/media/video/cx18/cx18-driver.c 2011-05-22 19:36:31.000000000 -0400
32510@@ -61,7 +61,7 @@ static struct pci_device_id cx18_pci_tbl
32511
32512 MODULE_DEVICE_TABLE(pci, cx18_pci_tbl);
32513
32514-static atomic_t cx18_instance = ATOMIC_INIT(0);
32515+static atomic_unchecked_t cx18_instance = ATOMIC_INIT(0);
32516
32517 /* Parameter declarations */
32518 static int cardtype[CX18_MAX_CARDS];
32519@@ -327,6 +327,8 @@ void cx18_read_eeprom(struct cx18 *cx, s
32520 struct i2c_client c;
32521 u8 eedata[256];
32522
32523+ pax_track_stack();
32524+
32525 memset(&c, 0, sizeof(c));
32526 strlcpy(c.name, "cx18 tveeprom tmp", sizeof(c.name));
32527 c.adapter = &cx->i2c_adap[0];
32528@@ -892,7 +894,7 @@ static int __devinit cx18_probe(struct p
32529 struct cx18 *cx;
32530
32531 /* FIXME - module parameter arrays constrain max instances */
32532- i = atomic_inc_return(&cx18_instance) - 1;
32533+ i = atomic_inc_return_unchecked(&cx18_instance) - 1;
32534 if (i >= CX18_MAX_CARDS) {
32535 printk(KERN_ERR "cx18: cannot manage card %d, driver has a "
32536 "limit of 0 - %d\n", i, CX18_MAX_CARDS - 1);
32537diff -urNp linux-2.6.39.1/drivers/media/video/cx231xx/cx231xx-audio.c linux-2.6.39.1/drivers/media/video/cx231xx/cx231xx-audio.c
32538--- linux-2.6.39.1/drivers/media/video/cx231xx/cx231xx-audio.c 2011-05-19 00:06:34.000000000 -0400
32539+++ linux-2.6.39.1/drivers/media/video/cx231xx/cx231xx-audio.c 2011-05-22 19:36:31.000000000 -0400
32540@@ -613,7 +613,7 @@ static struct page *snd_pcm_get_vmalloc_
32541 return vmalloc_to_page(pageptr);
32542 }
32543
32544-static struct snd_pcm_ops snd_cx231xx_pcm_capture = {
32545+static const struct snd_pcm_ops snd_cx231xx_pcm_capture = {
32546 .open = snd_cx231xx_capture_open,
32547 .close = snd_cx231xx_pcm_close,
32548 .ioctl = snd_pcm_lib_ioctl,
32549diff -urNp linux-2.6.39.1/drivers/media/video/cx231xx/cx231xx-i2c.c linux-2.6.39.1/drivers/media/video/cx231xx/cx231xx-i2c.c
32550--- linux-2.6.39.1/drivers/media/video/cx231xx/cx231xx-i2c.c 2011-05-19 00:06:34.000000000 -0400
32551+++ linux-2.6.39.1/drivers/media/video/cx231xx/cx231xx-i2c.c 2011-05-22 19:36:31.000000000 -0400
32552@@ -435,7 +435,7 @@ static u32 functionality(struct i2c_adap
32553 return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_I2C;
32554 }
32555
32556-static struct i2c_algorithm cx231xx_algo = {
32557+static const struct i2c_algorithm cx231xx_algo = {
32558 .master_xfer = cx231xx_i2c_xfer,
32559 .functionality = functionality,
32560 };
32561diff -urNp linux-2.6.39.1/drivers/media/video/cx23885/cx23885-input.c linux-2.6.39.1/drivers/media/video/cx23885/cx23885-input.c
32562--- linux-2.6.39.1/drivers/media/video/cx23885/cx23885-input.c 2011-05-19 00:06:34.000000000 -0400
32563+++ linux-2.6.39.1/drivers/media/video/cx23885/cx23885-input.c 2011-05-22 19:36:31.000000000 -0400
32564@@ -53,6 +53,8 @@ static void cx23885_input_process_measur
32565 bool handle = false;
32566 struct ir_raw_event ir_core_event[64];
32567
32568+ pax_track_stack();
32569+
32570 do {
32571 num = 0;
32572 v4l2_subdev_call(dev->sd_ir, ir, rx_read, (u8 *) ir_core_event,
32573diff -urNp linux-2.6.39.1/drivers/media/video/cx88/cx88-alsa.c linux-2.6.39.1/drivers/media/video/cx88/cx88-alsa.c
32574--- linux-2.6.39.1/drivers/media/video/cx88/cx88-alsa.c 2011-05-19 00:06:34.000000000 -0400
32575+++ linux-2.6.39.1/drivers/media/video/cx88/cx88-alsa.c 2011-05-22 19:36:31.000000000 -0400
32576@@ -519,7 +519,7 @@ static struct page *snd_cx88_page(struct
32577 /*
32578 * operators
32579 */
32580-static struct snd_pcm_ops snd_cx88_pcm_ops = {
32581+static const struct snd_pcm_ops snd_cx88_pcm_ops = {
32582 .open = snd_cx88_pcm_open,
32583 .close = snd_cx88_close,
32584 .ioctl = snd_pcm_lib_ioctl,
32585diff -urNp linux-2.6.39.1/drivers/media/video/davinci/ccdc_hw_device.h linux-2.6.39.1/drivers/media/video/davinci/ccdc_hw_device.h
32586--- linux-2.6.39.1/drivers/media/video/davinci/ccdc_hw_device.h 2011-05-19 00:06:34.000000000 -0400
32587+++ linux-2.6.39.1/drivers/media/video/davinci/ccdc_hw_device.h 2011-05-22 19:36:31.000000000 -0400
32588@@ -99,7 +99,7 @@ struct ccdc_hw_device {
32589 /* module owner */
32590 struct module *owner;
32591 /* hw ops */
32592- struct ccdc_hw_ops hw_ops;
32593+ const struct ccdc_hw_ops hw_ops;
32594 };
32595
32596 /* Used by CCDC module to register & unregister with vpfe capture driver */
32597diff -urNp linux-2.6.39.1/drivers/media/video/davinci/vpss.c linux-2.6.39.1/drivers/media/video/davinci/vpss.c
32598--- linux-2.6.39.1/drivers/media/video/davinci/vpss.c 2011-05-19 00:06:34.000000000 -0400
32599+++ linux-2.6.39.1/drivers/media/video/davinci/vpss.c 2011-05-22 19:36:31.000000000 -0400
32600@@ -103,7 +103,7 @@ struct vpss_oper_config {
32601 __iomem void *vpss_regs_base1;
32602 enum vpss_platform_type platform;
32603 spinlock_t vpss_lock;
32604- struct vpss_hw_ops hw_ops;
32605+ const struct vpss_hw_ops hw_ops;
32606 };
32607
32608 static struct vpss_oper_config oper_cfg;
32609diff -urNp linux-2.6.39.1/drivers/media/video/em28xx/em28xx-audio.c linux-2.6.39.1/drivers/media/video/em28xx/em28xx-audio.c
32610--- linux-2.6.39.1/drivers/media/video/em28xx/em28xx-audio.c 2011-05-19 00:06:34.000000000 -0400
32611+++ linux-2.6.39.1/drivers/media/video/em28xx/em28xx-audio.c 2011-05-22 19:36:31.000000000 -0400
32612@@ -432,7 +432,7 @@ static struct page *snd_pcm_get_vmalloc_
32613 return vmalloc_to_page(pageptr);
32614 }
32615
32616-static struct snd_pcm_ops snd_em28xx_pcm_capture = {
32617+static const struct snd_pcm_ops snd_em28xx_pcm_capture = {
32618 .open = snd_em28xx_capture_open,
32619 .close = snd_em28xx_pcm_close,
32620 .ioctl = snd_pcm_lib_ioctl,
32621diff -urNp linux-2.6.39.1/drivers/media/video/em28xx/em28xx-i2c.c linux-2.6.39.1/drivers/media/video/em28xx/em28xx-i2c.c
32622--- linux-2.6.39.1/drivers/media/video/em28xx/em28xx-i2c.c 2011-05-19 00:06:34.000000000 -0400
32623+++ linux-2.6.39.1/drivers/media/video/em28xx/em28xx-i2c.c 2011-05-22 19:36:31.000000000 -0400
32624@@ -451,7 +451,7 @@ static u32 functionality(struct i2c_adap
32625 return I2C_FUNC_SMBUS_EMUL;
32626 }
32627
32628-static struct i2c_algorithm em28xx_algo = {
32629+static const struct i2c_algorithm em28xx_algo = {
32630 .master_xfer = em28xx_i2c_xfer,
32631 .functionality = functionality,
32632 };
32633diff -urNp linux-2.6.39.1/drivers/media/video/hdpvr/hdpvr-i2c.c linux-2.6.39.1/drivers/media/video/hdpvr/hdpvr-i2c.c
32634--- linux-2.6.39.1/drivers/media/video/hdpvr/hdpvr-i2c.c 2011-05-19 00:06:34.000000000 -0400
32635+++ linux-2.6.39.1/drivers/media/video/hdpvr/hdpvr-i2c.c 2011-05-22 19:36:31.000000000 -0400
32636@@ -179,7 +179,7 @@ static u32 hdpvr_functionality(struct i2
32637 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
32638 }
32639
32640-static struct i2c_algorithm hdpvr_algo = {
32641+static const struct i2c_algorithm hdpvr_algo = {
32642 .master_xfer = hdpvr_transfer,
32643 .functionality = hdpvr_functionality,
32644 };
32645diff -urNp linux-2.6.39.1/drivers/media/video/imx074.c linux-2.6.39.1/drivers/media/video/imx074.c
32646--- linux-2.6.39.1/drivers/media/video/imx074.c 2011-05-19 00:06:34.000000000 -0400
32647+++ linux-2.6.39.1/drivers/media/video/imx074.c 2011-05-22 19:36:31.000000000 -0400
32648@@ -267,7 +267,7 @@ static int imx074_g_chip_ident(struct v4
32649 return 0;
32650 }
32651
32652-static struct v4l2_subdev_video_ops imx074_subdev_video_ops = {
32653+static const struct v4l2_subdev_video_ops imx074_subdev_video_ops = {
32654 .s_stream = imx074_s_stream,
32655 .s_mbus_fmt = imx074_s_fmt,
32656 .g_mbus_fmt = imx074_g_fmt,
32657@@ -277,7 +277,7 @@ static struct v4l2_subdev_video_ops imx0
32658 .cropcap = imx074_cropcap,
32659 };
32660
32661-static struct v4l2_subdev_core_ops imx074_subdev_core_ops = {
32662+static const struct v4l2_subdev_core_ops imx074_subdev_core_ops = {
32663 .g_chip_ident = imx074_g_chip_ident,
32664 };
32665
32666diff -urNp linux-2.6.39.1/drivers/media/video/ivtv/ivtv-driver.c linux-2.6.39.1/drivers/media/video/ivtv/ivtv-driver.c
32667--- linux-2.6.39.1/drivers/media/video/ivtv/ivtv-driver.c 2011-05-19 00:06:34.000000000 -0400
32668+++ linux-2.6.39.1/drivers/media/video/ivtv/ivtv-driver.c 2011-05-22 19:36:31.000000000 -0400
32669@@ -80,7 +80,7 @@ static struct pci_device_id ivtv_pci_tbl
32670 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
32671
32672 /* ivtv instance counter */
32673-static atomic_t ivtv_instance = ATOMIC_INIT(0);
32674+static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
32675
32676 /* Parameter declarations */
32677 static int cardtype[IVTV_MAX_CARDS];
32678diff -urNp linux-2.6.39.1/drivers/media/video/mt9m001.c linux-2.6.39.1/drivers/media/video/mt9m001.c
32679--- linux-2.6.39.1/drivers/media/video/mt9m001.c 2011-05-19 00:06:34.000000000 -0400
32680+++ linux-2.6.39.1/drivers/media/video/mt9m001.c 2011-05-22 19:36:31.000000000 -0400
32681@@ -691,7 +691,7 @@ static int mt9m001_g_skip_top_lines(stru
32682 return 0;
32683 }
32684
32685-static struct v4l2_subdev_core_ops mt9m001_subdev_core_ops = {
32686+static const struct v4l2_subdev_core_ops mt9m001_subdev_core_ops = {
32687 .g_ctrl = mt9m001_g_ctrl,
32688 .s_ctrl = mt9m001_s_ctrl,
32689 .g_chip_ident = mt9m001_g_chip_ident,
32690@@ -714,7 +714,7 @@ static int mt9m001_enum_fmt(struct v4l2_
32691 return 0;
32692 }
32693
32694-static struct v4l2_subdev_video_ops mt9m001_subdev_video_ops = {
32695+static const struct v4l2_subdev_video_ops mt9m001_subdev_video_ops = {
32696 .s_stream = mt9m001_s_stream,
32697 .s_mbus_fmt = mt9m001_s_fmt,
32698 .g_mbus_fmt = mt9m001_g_fmt,
32699@@ -725,7 +725,7 @@ static struct v4l2_subdev_video_ops mt9m
32700 .enum_mbus_fmt = mt9m001_enum_fmt,
32701 };
32702
32703-static struct v4l2_subdev_sensor_ops mt9m001_subdev_sensor_ops = {
32704+static const struct v4l2_subdev_sensor_ops mt9m001_subdev_sensor_ops = {
32705 .g_skip_top_lines = mt9m001_g_skip_top_lines,
32706 };
32707
32708diff -urNp linux-2.6.39.1/drivers/media/video/mt9t031.c linux-2.6.39.1/drivers/media/video/mt9t031.c
32709--- linux-2.6.39.1/drivers/media/video/mt9t031.c 2011-05-19 00:06:34.000000000 -0400
32710+++ linux-2.6.39.1/drivers/media/video/mt9t031.c 2011-05-22 19:36:31.000000000 -0400
32711@@ -725,7 +725,7 @@ static int mt9t031_runtime_resume(struct
32712 return 0;
32713 }
32714
32715-static struct dev_pm_ops mt9t031_dev_pm_ops = {
32716+static const struct dev_pm_ops mt9t031_dev_pm_ops = {
32717 .runtime_suspend = mt9t031_runtime_suspend,
32718 .runtime_resume = mt9t031_runtime_resume,
32719 };
32720@@ -788,7 +788,7 @@ static int mt9t031_g_skip_top_lines(stru
32721 return 0;
32722 }
32723
32724-static struct v4l2_subdev_core_ops mt9t031_subdev_core_ops = {
32725+static const struct v4l2_subdev_core_ops mt9t031_subdev_core_ops = {
32726 .g_ctrl = mt9t031_g_ctrl,
32727 .s_ctrl = mt9t031_s_ctrl,
32728 .g_chip_ident = mt9t031_g_chip_ident,
32729@@ -808,7 +808,7 @@ static int mt9t031_enum_fmt(struct v4l2_
32730 return 0;
32731 }
32732
32733-static struct v4l2_subdev_video_ops mt9t031_subdev_video_ops = {
32734+static const struct v4l2_subdev_video_ops mt9t031_subdev_video_ops = {
32735 .s_stream = mt9t031_s_stream,
32736 .s_mbus_fmt = mt9t031_s_fmt,
32737 .g_mbus_fmt = mt9t031_g_fmt,
32738@@ -819,7 +819,7 @@ static struct v4l2_subdev_video_ops mt9t
32739 .enum_mbus_fmt = mt9t031_enum_fmt,
32740 };
32741
32742-static struct v4l2_subdev_sensor_ops mt9t031_subdev_sensor_ops = {
32743+static const struct v4l2_subdev_sensor_ops mt9t031_subdev_sensor_ops = {
32744 .g_skip_top_lines = mt9t031_g_skip_top_lines,
32745 };
32746
32747diff -urNp linux-2.6.39.1/drivers/media/video/mt9v022.c linux-2.6.39.1/drivers/media/video/mt9v022.c
32748--- linux-2.6.39.1/drivers/media/video/mt9v022.c 2011-05-19 00:06:34.000000000 -0400
32749+++ linux-2.6.39.1/drivers/media/video/mt9v022.c 2011-05-22 19:36:31.000000000 -0400
32750@@ -825,7 +825,7 @@ static int mt9v022_g_skip_top_lines(stru
32751 return 0;
32752 }
32753
32754-static struct v4l2_subdev_core_ops mt9v022_subdev_core_ops = {
32755+static const struct v4l2_subdev_core_ops mt9v022_subdev_core_ops = {
32756 .g_ctrl = mt9v022_g_ctrl,
32757 .s_ctrl = mt9v022_s_ctrl,
32758 .g_chip_ident = mt9v022_g_chip_ident,
32759@@ -848,7 +848,7 @@ static int mt9v022_enum_fmt(struct v4l2_
32760 return 0;
32761 }
32762
32763-static struct v4l2_subdev_video_ops mt9v022_subdev_video_ops = {
32764+static const struct v4l2_subdev_video_ops mt9v022_subdev_video_ops = {
32765 .s_stream = mt9v022_s_stream,
32766 .s_mbus_fmt = mt9v022_s_fmt,
32767 .g_mbus_fmt = mt9v022_g_fmt,
32768@@ -859,7 +859,7 @@ static struct v4l2_subdev_video_ops mt9v
32769 .enum_mbus_fmt = mt9v022_enum_fmt,
32770 };
32771
32772-static struct v4l2_subdev_sensor_ops mt9v022_subdev_sensor_ops = {
32773+static const struct v4l2_subdev_sensor_ops mt9v022_subdev_sensor_ops = {
32774 .g_skip_top_lines = mt9v022_g_skip_top_lines,
32775 };
32776
32777diff -urNp linux-2.6.39.1/drivers/media/video/mx2_camera.c linux-2.6.39.1/drivers/media/video/mx2_camera.c
32778--- linux-2.6.39.1/drivers/media/video/mx2_camera.c 2011-05-19 00:06:34.000000000 -0400
32779+++ linux-2.6.39.1/drivers/media/video/mx2_camera.c 2011-05-22 19:36:31.000000000 -0400
32780@@ -668,7 +668,7 @@ static void mx2_videobuf_release(struct
32781 free_buffer(vq, buf);
32782 }
32783
32784-static struct videobuf_queue_ops mx2_videobuf_ops = {
32785+static const struct videobuf_queue_ops mx2_videobuf_ops = {
32786 .buf_setup = mx2_videobuf_setup,
32787 .buf_prepare = mx2_videobuf_prepare,
32788 .buf_queue = mx2_videobuf_queue,
32789diff -urNp linux-2.6.39.1/drivers/media/video/omap24xxcam.c linux-2.6.39.1/drivers/media/video/omap24xxcam.c
32790--- linux-2.6.39.1/drivers/media/video/omap24xxcam.c 2011-05-19 00:06:34.000000000 -0400
32791+++ linux-2.6.39.1/drivers/media/video/omap24xxcam.c 2011-05-22 19:36:31.000000000 -0400
32792@@ -403,7 +403,7 @@ static void omap24xxcam_vbq_complete(str
32793 spin_unlock_irqrestore(&cam->core_enable_disable_lock, flags);
32794
32795 do_gettimeofday(&vb->ts);
32796- vb->field_count = atomic_add_return(2, &fh->field_count);
32797+ vb->field_count = atomic_add_return_unchecked(2, &fh->field_count);
32798 if (csr & csr_error) {
32799 vb->state = VIDEOBUF_ERROR;
32800 if (!atomic_read(&fh->cam->in_reset)) {
32801diff -urNp linux-2.6.39.1/drivers/media/video/omap24xxcam.h linux-2.6.39.1/drivers/media/video/omap24xxcam.h
32802--- linux-2.6.39.1/drivers/media/video/omap24xxcam.h 2011-05-19 00:06:34.000000000 -0400
32803+++ linux-2.6.39.1/drivers/media/video/omap24xxcam.h 2011-05-22 19:36:31.000000000 -0400
32804@@ -533,7 +533,7 @@ struct omap24xxcam_fh {
32805 spinlock_t vbq_lock; /* spinlock for the videobuf queue */
32806 struct videobuf_queue vbq;
32807 struct v4l2_pix_format pix; /* serialise pix by vbq->lock */
32808- atomic_t field_count; /* field counter for videobuf_buffer */
32809+ atomic_unchecked_t field_count; /* field counter for videobuf_buffer */
32810 /* accessing cam here doesn't need serialisation: it's constant */
32811 struct omap24xxcam_device *cam;
32812 };
32813diff -urNp linux-2.6.39.1/drivers/media/video/omap3isp/isp.h linux-2.6.39.1/drivers/media/video/omap3isp/isp.h
32814--- linux-2.6.39.1/drivers/media/video/omap3isp/isp.h 2011-05-19 00:06:34.000000000 -0400
32815+++ linux-2.6.39.1/drivers/media/video/omap3isp/isp.h 2011-05-22 19:36:31.000000000 -0400
32816@@ -290,7 +290,7 @@ struct isp_device {
32817
32818 struct iommu *iommu;
32819
32820- struct isp_platform_callback platform_cb;
32821+ const struct isp_platform_callback platform_cb;
32822 };
32823
32824 #define v4l2_dev_to_isp_device(dev) \
32825diff -urNp linux-2.6.39.1/drivers/media/video/ov2640.c linux-2.6.39.1/drivers/media/video/ov2640.c
32826--- linux-2.6.39.1/drivers/media/video/ov2640.c 2011-05-19 00:06:34.000000000 -0400
32827+++ linux-2.6.39.1/drivers/media/video/ov2640.c 2011-05-22 19:36:31.000000000 -0400
32828@@ -1080,7 +1080,7 @@ static struct soc_camera_ops ov2640_ops
32829 .num_controls = ARRAY_SIZE(ov2640_controls),
32830 };
32831
32832-static struct v4l2_subdev_core_ops ov2640_subdev_core_ops = {
32833+static const struct v4l2_subdev_core_ops ov2640_subdev_core_ops = {
32834 .g_ctrl = ov2640_g_ctrl,
32835 .s_ctrl = ov2640_s_ctrl,
32836 .g_chip_ident = ov2640_g_chip_ident,
32837@@ -1090,7 +1090,7 @@ static struct v4l2_subdev_core_ops ov264
32838 #endif
32839 };
32840
32841-static struct v4l2_subdev_video_ops ov2640_subdev_video_ops = {
32842+static const struct v4l2_subdev_video_ops ov2640_subdev_video_ops = {
32843 .s_stream = ov2640_s_stream,
32844 .g_mbus_fmt = ov2640_g_fmt,
32845 .s_mbus_fmt = ov2640_s_fmt,
32846diff -urNp linux-2.6.39.1/drivers/media/video/ov772x.c linux-2.6.39.1/drivers/media/video/ov772x.c
32847--- linux-2.6.39.1/drivers/media/video/ov772x.c 2011-05-19 00:06:34.000000000 -0400
32848+++ linux-2.6.39.1/drivers/media/video/ov772x.c 2011-05-22 19:36:31.000000000 -0400
32849@@ -1079,7 +1079,7 @@ static struct soc_camera_ops ov772x_ops
32850 .num_controls = ARRAY_SIZE(ov772x_controls),
32851 };
32852
32853-static struct v4l2_subdev_core_ops ov772x_subdev_core_ops = {
32854+static const struct v4l2_subdev_core_ops ov772x_subdev_core_ops = {
32855 .g_ctrl = ov772x_g_ctrl,
32856 .s_ctrl = ov772x_s_ctrl,
32857 .g_chip_ident = ov772x_g_chip_ident,
32858@@ -1099,7 +1099,7 @@ static int ov772x_enum_fmt(struct v4l2_s
32859 return 0;
32860 }
32861
32862-static struct v4l2_subdev_video_ops ov772x_subdev_video_ops = {
32863+static const struct v4l2_subdev_video_ops ov772x_subdev_video_ops = {
32864 .s_stream = ov772x_s_stream,
32865 .g_mbus_fmt = ov772x_g_fmt,
32866 .s_mbus_fmt = ov772x_s_fmt,
32867diff -urNp linux-2.6.39.1/drivers/media/video/pvrusb2/pvrusb2-eeprom.c linux-2.6.39.1/drivers/media/video/pvrusb2/pvrusb2-eeprom.c
32868--- linux-2.6.39.1/drivers/media/video/pvrusb2/pvrusb2-eeprom.c 2011-05-19 00:06:34.000000000 -0400
32869+++ linux-2.6.39.1/drivers/media/video/pvrusb2/pvrusb2-eeprom.c 2011-05-22 19:36:31.000000000 -0400
32870@@ -120,6 +120,8 @@ int pvr2_eeprom_analyze(struct pvr2_hdw
32871 u8 *eeprom;
32872 struct tveeprom tvdata;
32873
32874+ pax_track_stack();
32875+
32876 memset(&tvdata,0,sizeof(tvdata));
32877
32878 eeprom = pvr2_eeprom_fetch(hdw);
32879diff -urNp linux-2.6.39.1/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c linux-2.6.39.1/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c
32880--- linux-2.6.39.1/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c 2011-05-19 00:06:34.000000000 -0400
32881+++ linux-2.6.39.1/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c 2011-05-22 19:36:31.000000000 -0400
32882@@ -527,7 +527,7 @@ static u32 pvr2_i2c_functionality(struct
32883 return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_I2C;
32884 }
32885
32886-static struct i2c_algorithm pvr2_i2c_algo_template = {
32887+static const struct i2c_algorithm pvr2_i2c_algo_template = {
32888 .master_xfer = pvr2_i2c_xfer,
32889 .functionality = pvr2_i2c_functionality,
32890 };
32891diff -urNp linux-2.6.39.1/drivers/media/video/rj54n1cb0c.c linux-2.6.39.1/drivers/media/video/rj54n1cb0c.c
32892--- linux-2.6.39.1/drivers/media/video/rj54n1cb0c.c 2011-05-19 00:06:34.000000000 -0400
32893+++ linux-2.6.39.1/drivers/media/video/rj54n1cb0c.c 2011-05-22 19:36:31.000000000 -0400
32894@@ -1327,7 +1327,7 @@ static int rj54n1_s_ctrl(struct v4l2_sub
32895 return 0;
32896 }
32897
32898-static struct v4l2_subdev_core_ops rj54n1_subdev_core_ops = {
32899+static const struct v4l2_subdev_core_ops rj54n1_subdev_core_ops = {
32900 .g_ctrl = rj54n1_g_ctrl,
32901 .s_ctrl = rj54n1_s_ctrl,
32902 .g_chip_ident = rj54n1_g_chip_ident,
32903@@ -1337,7 +1337,7 @@ static struct v4l2_subdev_core_ops rj54n
32904 #endif
32905 };
32906
32907-static struct v4l2_subdev_video_ops rj54n1_subdev_video_ops = {
32908+static const struct v4l2_subdev_video_ops rj54n1_subdev_video_ops = {
32909 .s_stream = rj54n1_s_stream,
32910 .s_mbus_fmt = rj54n1_s_fmt,
32911 .g_mbus_fmt = rj54n1_g_fmt,
32912diff -urNp linux-2.6.39.1/drivers/media/video/s5p-fimc/fimc-capture.c linux-2.6.39.1/drivers/media/video/s5p-fimc/fimc-capture.c
32913--- linux-2.6.39.1/drivers/media/video/s5p-fimc/fimc-capture.c 2011-05-19 00:06:34.000000000 -0400
32914+++ linux-2.6.39.1/drivers/media/video/s5p-fimc/fimc-capture.c 2011-05-22 19:36:31.000000000 -0400
32915@@ -376,7 +376,7 @@ static void fimc_unlock(struct vb2_queue
32916 mutex_unlock(&ctx->fimc_dev->lock);
32917 }
32918
32919-static struct vb2_ops fimc_capture_qops = {
32920+static const struct vb2_ops fimc_capture_qops = {
32921 .queue_setup = queue_setup,
32922 .buf_prepare = buffer_prepare,
32923 .buf_queue = buffer_queue,
32924diff -urNp linux-2.6.39.1/drivers/media/video/s5p-fimc/fimc-core.c linux-2.6.39.1/drivers/media/video/s5p-fimc/fimc-core.c
32925--- linux-2.6.39.1/drivers/media/video/s5p-fimc/fimc-core.c 2011-05-19 00:06:34.000000000 -0400
32926+++ linux-2.6.39.1/drivers/media/video/s5p-fimc/fimc-core.c 2011-05-22 19:36:31.000000000 -0400
32927@@ -768,7 +768,7 @@ static void fimc_unlock(struct vb2_queue
32928 mutex_unlock(&ctx->fimc_dev->lock);
32929 }
32930
32931-static struct vb2_ops fimc_qops = {
32932+static const struct vb2_ops fimc_qops = {
32933 .queue_setup = fimc_queue_setup,
32934 .buf_prepare = fimc_buf_prepare,
32935 .buf_queue = fimc_buf_queue,
32936diff -urNp linux-2.6.39.1/drivers/media/video/saa7134/saa6752hs.c linux-2.6.39.1/drivers/media/video/saa7134/saa6752hs.c
32937--- linux-2.6.39.1/drivers/media/video/saa7134/saa6752hs.c 2011-05-19 00:06:34.000000000 -0400
32938+++ linux-2.6.39.1/drivers/media/video/saa7134/saa6752hs.c 2011-05-22 19:36:31.000000000 -0400
32939@@ -682,6 +682,8 @@ static int saa6752hs_init(struct v4l2_su
32940 unsigned char localPAT[256];
32941 unsigned char localPMT[256];
32942
32943+ pax_track_stack();
32944+
32945 /* Set video format - must be done first as it resets other settings */
32946 set_reg8(client, 0x41, h->video_format);
32947
32948diff -urNp linux-2.6.39.1/drivers/media/video/saa7134/saa7134-alsa.c linux-2.6.39.1/drivers/media/video/saa7134/saa7134-alsa.c
32949--- linux-2.6.39.1/drivers/media/video/saa7134/saa7134-alsa.c 2011-05-19 00:06:34.000000000 -0400
32950+++ linux-2.6.39.1/drivers/media/video/saa7134/saa7134-alsa.c 2011-05-22 19:36:31.000000000 -0400
32951@@ -808,7 +808,7 @@ static struct page *snd_card_saa7134_pag
32952 * ALSA capture callbacks definition
32953 */
32954
32955-static struct snd_pcm_ops snd_card_saa7134_capture_ops = {
32956+static const struct snd_pcm_ops snd_card_saa7134_capture_ops = {
32957 .open = snd_card_saa7134_capture_open,
32958 .close = snd_card_saa7134_capture_close,
32959 .ioctl = snd_pcm_lib_ioctl,
32960diff -urNp linux-2.6.39.1/drivers/media/video/saa7164/saa7164-cmd.c linux-2.6.39.1/drivers/media/video/saa7164/saa7164-cmd.c
32961--- linux-2.6.39.1/drivers/media/video/saa7164/saa7164-cmd.c 2011-05-19 00:06:34.000000000 -0400
32962+++ linux-2.6.39.1/drivers/media/video/saa7164/saa7164-cmd.c 2011-05-22 19:36:31.000000000 -0400
32963@@ -88,6 +88,8 @@ int saa7164_irq_dequeue(struct saa7164_d
32964 u8 tmp[512];
32965 dprintk(DBGLVL_CMD, "%s()\n", __func__);
32966
32967+ pax_track_stack();
32968+
32969 /* While any outstand message on the bus exists... */
32970 do {
32971
32972@@ -141,6 +143,8 @@ int saa7164_cmd_dequeue(struct saa7164_d
32973 u8 tmp[512];
32974 dprintk(DBGLVL_CMD, "%s()\n", __func__);
32975
32976+ pax_track_stack();
32977+
32978 while (loop) {
32979
32980 struct tmComResInfo tRsp = { 0, 0, 0, 0, 0, 0 };
32981diff -urNp linux-2.6.39.1/drivers/media/video/sh_mobile_csi2.c linux-2.6.39.1/drivers/media/video/sh_mobile_csi2.c
32982--- linux-2.6.39.1/drivers/media/video/sh_mobile_csi2.c 2011-05-19 00:06:34.000000000 -0400
32983+++ linux-2.6.39.1/drivers/media/video/sh_mobile_csi2.c 2011-05-22 19:36:31.000000000 -0400
32984@@ -127,12 +127,12 @@ static int sh_csi2_s_fmt(struct v4l2_sub
32985 return 0;
32986 }
32987
32988-static struct v4l2_subdev_video_ops sh_csi2_subdev_video_ops = {
32989+static const struct v4l2_subdev_video_ops sh_csi2_subdev_video_ops = {
32990 .s_mbus_fmt = sh_csi2_s_fmt,
32991 .try_mbus_fmt = sh_csi2_try_fmt,
32992 };
32993
32994-static struct v4l2_subdev_core_ops sh_csi2_subdev_core_ops;
32995+static const struct v4l2_subdev_core_ops sh_csi2_subdev_core_ops;
32996
32997 static struct v4l2_subdev_ops sh_csi2_subdev_ops = {
32998 .core = &sh_csi2_subdev_core_ops,
32999diff -urNp linux-2.6.39.1/drivers/media/video/soc_camera_platform.c linux-2.6.39.1/drivers/media/video/soc_camera_platform.c
33000--- linux-2.6.39.1/drivers/media/video/soc_camera_platform.c 2011-05-19 00:06:34.000000000 -0400
33001+++ linux-2.6.39.1/drivers/media/video/soc_camera_platform.c 2011-05-22 19:36:31.000000000 -0400
33002@@ -70,7 +70,7 @@ static int soc_camera_platform_fill_fmt(
33003 return 0;
33004 }
33005
33006-static struct v4l2_subdev_core_ops platform_subdev_core_ops;
33007+static const struct v4l2_subdev_core_ops platform_subdev_core_ops;
33008
33009 static int soc_camera_platform_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
33010 enum v4l2_mbus_pixelcode *code)
33011@@ -115,7 +115,7 @@ static int soc_camera_platform_cropcap(s
33012 return 0;
33013 }
33014
33015-static struct v4l2_subdev_video_ops platform_subdev_video_ops = {
33016+static const struct v4l2_subdev_video_ops platform_subdev_video_ops = {
33017 .s_stream = soc_camera_platform_s_stream,
33018 .enum_mbus_fmt = soc_camera_platform_enum_fmt,
33019 .cropcap = soc_camera_platform_cropcap,
33020diff -urNp linux-2.6.39.1/drivers/media/video/tlg2300/pd-alsa.c linux-2.6.39.1/drivers/media/video/tlg2300/pd-alsa.c
33021--- linux-2.6.39.1/drivers/media/video/tlg2300/pd-alsa.c 2011-05-19 00:06:34.000000000 -0400
33022+++ linux-2.6.39.1/drivers/media/video/tlg2300/pd-alsa.c 2011-05-22 19:36:31.000000000 -0400
33023@@ -265,7 +265,7 @@ static struct page *snd_pcm_pd_get_page(
33024 return vmalloc_to_page(pageptr);
33025 }
33026
33027-static struct snd_pcm_ops pcm_capture_ops = {
33028+static const struct snd_pcm_ops pcm_capture_ops = {
33029 .open = snd_pd_capture_open,
33030 .close = snd_pd_pcm_close,
33031 .ioctl = snd_pcm_lib_ioctl,
33032diff -urNp linux-2.6.39.1/drivers/media/video/tw9910.c linux-2.6.39.1/drivers/media/video/tw9910.c
33033--- linux-2.6.39.1/drivers/media/video/tw9910.c 2011-05-19 00:06:34.000000000 -0400
33034+++ linux-2.6.39.1/drivers/media/video/tw9910.c 2011-05-22 19:36:31.000000000 -0400
33035@@ -894,7 +894,7 @@ static struct soc_camera_ops tw9910_ops
33036 .enum_input = tw9910_enum_input,
33037 };
33038
33039-static struct v4l2_subdev_core_ops tw9910_subdev_core_ops = {
33040+static const struct v4l2_subdev_core_ops tw9910_subdev_core_ops = {
33041 .g_chip_ident = tw9910_g_chip_ident,
33042 .s_std = tw9910_s_std,
33043 #ifdef CONFIG_VIDEO_ADV_DEBUG
33044@@ -913,7 +913,7 @@ static int tw9910_enum_fmt(struct v4l2_s
33045 return 0;
33046 }
33047
33048-static struct v4l2_subdev_video_ops tw9910_subdev_video_ops = {
33049+static const struct v4l2_subdev_video_ops tw9910_subdev_video_ops = {
33050 .s_stream = tw9910_s_stream,
33051 .g_mbus_fmt = tw9910_g_fmt,
33052 .s_mbus_fmt = tw9910_s_fmt,
33053diff -urNp linux-2.6.39.1/drivers/media/video/usbvision/usbvision-core.c linux-2.6.39.1/drivers/media/video/usbvision/usbvision-core.c
33054--- linux-2.6.39.1/drivers/media/video/usbvision/usbvision-core.c 2011-05-19 00:06:34.000000000 -0400
33055+++ linux-2.6.39.1/drivers/media/video/usbvision/usbvision-core.c 2011-05-22 19:36:31.000000000 -0400
33056@@ -799,6 +799,8 @@ static enum parse_state usbvision_parse_
33057 unsigned char rv, gv, bv;
33058 static unsigned char *Y, *U, *V;
33059
33060+ pax_track_stack();
33061+
33062 frame = usbvision->cur_frame;
33063 image_size = frame->frmwidth * frame->frmheight;
33064 if ((frame->v4l2_format.format == V4L2_PIX_FMT_YUV422P) ||
33065diff -urNp linux-2.6.39.1/drivers/media/video/usbvision/usbvision-i2c.c linux-2.6.39.1/drivers/media/video/usbvision/usbvision-i2c.c
33066--- linux-2.6.39.1/drivers/media/video/usbvision/usbvision-i2c.c 2011-05-19 00:06:34.000000000 -0400
33067+++ linux-2.6.39.1/drivers/media/video/usbvision/usbvision-i2c.c 2011-05-22 19:36:31.000000000 -0400
33068@@ -189,7 +189,7 @@ static u32 functionality(struct i2c_adap
33069
33070 /* -----exported algorithm data: ------------------------------------- */
33071
33072-static struct i2c_algorithm usbvision_algo = {
33073+static const struct i2c_algorithm usbvision_algo = {
33074 .master_xfer = usbvision_i2c_xfer,
33075 .smbus_xfer = NULL,
33076 .functionality = functionality,
33077diff -urNp linux-2.6.39.1/drivers/media/video/v4l2-device.c linux-2.6.39.1/drivers/media/video/v4l2-device.c
33078--- linux-2.6.39.1/drivers/media/video/v4l2-device.c 2011-05-19 00:06:34.000000000 -0400
33079+++ linux-2.6.39.1/drivers/media/video/v4l2-device.c 2011-05-22 19:36:31.000000000 -0400
33080@@ -71,9 +71,9 @@ int v4l2_device_put(struct v4l2_device *
33081 EXPORT_SYMBOL_GPL(v4l2_device_put);
33082
33083 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
33084- atomic_t *instance)
33085+ atomic_unchecked_t *instance)
33086 {
33087- int num = atomic_inc_return(instance) - 1;
33088+ int num = atomic_inc_return_unchecked(instance) - 1;
33089 int len = strlen(basename);
33090
33091 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
33092diff -urNp linux-2.6.39.1/drivers/media/video/videobuf-dma-sg.c linux-2.6.39.1/drivers/media/video/videobuf-dma-sg.c
33093--- linux-2.6.39.1/drivers/media/video/videobuf-dma-sg.c 2011-05-19 00:06:34.000000000 -0400
33094+++ linux-2.6.39.1/drivers/media/video/videobuf-dma-sg.c 2011-05-22 19:36:31.000000000 -0400
33095@@ -606,6 +606,8 @@ void *videobuf_sg_alloc(size_t size)
33096 {
33097 struct videobuf_queue q;
33098
33099+ pax_track_stack();
33100+
33101 /* Required to make generic handler to call __videobuf_alloc */
33102 q.int_ops = &sg_ops;
33103
33104diff -urNp linux-2.6.39.1/drivers/message/fusion/mptbase.c linux-2.6.39.1/drivers/message/fusion/mptbase.c
33105--- linux-2.6.39.1/drivers/message/fusion/mptbase.c 2011-05-19 00:06:34.000000000 -0400
33106+++ linux-2.6.39.1/drivers/message/fusion/mptbase.c 2011-05-22 19:41:37.000000000 -0400
33107@@ -143,7 +143,7 @@ static int MptDriverClass[MPT_MAX_PRO
33108 static MPT_EVHANDLER MptEvHandlers[MPT_MAX_PROTOCOL_DRIVERS];
33109 /* Reset handler lookup table */
33110 static MPT_RESETHANDLER MptResetHandlers[MPT_MAX_PROTOCOL_DRIVERS];
33111-static struct mpt_pci_driver *MptDeviceDriverHandlers[MPT_MAX_PROTOCOL_DRIVERS];
33112+static const struct mpt_pci_driver *MptDeviceDriverHandlers[MPT_MAX_PROTOCOL_DRIVERS];
33113
33114 #ifdef CONFIG_PROC_FS
33115 static struct proc_dir_entry *mpt_proc_root_dir;
33116@@ -772,7 +772,7 @@ mpt_reset_deregister(u8 cb_idx)
33117 * @cb_idx: MPT protocol driver index
33118 */
33119 int
33120-mpt_device_driver_register(struct mpt_pci_driver * dd_cbfunc, u8 cb_idx)
33121+mpt_device_driver_register(const struct mpt_pci_driver * dd_cbfunc, u8 cb_idx)
33122 {
33123 MPT_ADAPTER *ioc;
33124 const struct pci_device_id *id;
33125@@ -801,7 +801,7 @@ mpt_device_driver_register(struct mpt_pc
33126 void
33127 mpt_device_driver_deregister(u8 cb_idx)
33128 {
33129- struct mpt_pci_driver *dd_cbfunc;
33130+ const struct mpt_pci_driver *dd_cbfunc;
33131 MPT_ADAPTER *ioc;
33132
33133 if (!cb_idx || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
33134@@ -6683,8 +6683,13 @@ static int mpt_iocinfo_proc_show(struct
33135 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
33136 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
33137
33138+#ifdef CONFIG_GRKERNSEC_HIDESYM
33139+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
33140+#else
33141 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
33142 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
33143+#endif
33144+
33145 /*
33146 * Rounding UP to nearest 4-kB boundary here...
33147 */
33148diff -urNp linux-2.6.39.1/drivers/message/fusion/mptbase.h linux-2.6.39.1/drivers/message/fusion/mptbase.h
33149--- linux-2.6.39.1/drivers/message/fusion/mptbase.h 2011-05-19 00:06:34.000000000 -0400
33150+++ linux-2.6.39.1/drivers/message/fusion/mptbase.h 2011-05-22 19:36:31.000000000 -0400
33151@@ -908,7 +908,7 @@ extern int mpt_event_register(u8 cb_idx
33152 extern void mpt_event_deregister(u8 cb_idx);
33153 extern int mpt_reset_register(u8 cb_idx, MPT_RESETHANDLER reset_func);
33154 extern void mpt_reset_deregister(u8 cb_idx);
33155-extern int mpt_device_driver_register(struct mpt_pci_driver * dd_cbfunc, u8 cb_idx);
33156+extern int mpt_device_driver_register(const struct mpt_pci_driver * dd_cbfunc, u8 cb_idx);
33157 extern void mpt_device_driver_deregister(u8 cb_idx);
33158 extern MPT_FRAME_HDR *mpt_get_msg_frame(u8 cb_idx, MPT_ADAPTER *ioc);
33159 extern void mpt_free_msg_frame(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf);
33160diff -urNp linux-2.6.39.1/drivers/message/fusion/mptctl.c linux-2.6.39.1/drivers/message/fusion/mptctl.c
33161--- linux-2.6.39.1/drivers/message/fusion/mptctl.c 2011-05-19 00:06:34.000000000 -0400
33162+++ linux-2.6.39.1/drivers/message/fusion/mptctl.c 2011-05-22 19:36:31.000000000 -0400
33163@@ -3000,7 +3000,7 @@ mptctl_remove(struct pci_dev *pdev)
33164 {
33165 }
33166
33167-static struct mpt_pci_driver mptctl_driver = {
33168+static const struct mpt_pci_driver mptctl_driver = {
33169 .probe = mptctl_probe,
33170 .remove = mptctl_remove,
33171 };
33172diff -urNp linux-2.6.39.1/drivers/message/fusion/mptsas.c linux-2.6.39.1/drivers/message/fusion/mptsas.c
33173--- linux-2.6.39.1/drivers/message/fusion/mptsas.c 2011-05-19 00:06:34.000000000 -0400
33174+++ linux-2.6.39.1/drivers/message/fusion/mptsas.c 2011-05-22 19:36:31.000000000 -0400
33175@@ -439,6 +439,23 @@ mptsas_is_end_device(struct mptsas_devin
33176 return 0;
33177 }
33178
33179+static inline void
33180+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33181+{
33182+ if (phy_info->port_details) {
33183+ phy_info->port_details->rphy = rphy;
33184+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33185+ ioc->name, rphy));
33186+ }
33187+
33188+ if (rphy) {
33189+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33190+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33191+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33192+ ioc->name, rphy, rphy->dev.release));
33193+ }
33194+}
33195+
33196 /* no mutex */
33197 static void
33198 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
33199@@ -477,23 +494,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *p
33200 return NULL;
33201 }
33202
33203-static inline void
33204-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33205-{
33206- if (phy_info->port_details) {
33207- phy_info->port_details->rphy = rphy;
33208- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33209- ioc->name, rphy));
33210- }
33211-
33212- if (rphy) {
33213- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33214- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33215- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33216- ioc->name, rphy, rphy->dev.release));
33217- }
33218-}
33219-
33220 static inline struct sas_port *
33221 mptsas_get_port(struct mptsas_phyinfo *phy_info)
33222 {
33223diff -urNp linux-2.6.39.1/drivers/message/fusion/mptscsih.c linux-2.6.39.1/drivers/message/fusion/mptscsih.c
33224--- linux-2.6.39.1/drivers/message/fusion/mptscsih.c 2011-05-19 00:06:34.000000000 -0400
33225+++ linux-2.6.39.1/drivers/message/fusion/mptscsih.c 2011-05-22 19:36:31.000000000 -0400
33226@@ -1268,15 +1268,16 @@ mptscsih_info(struct Scsi_Host *SChost)
33227
33228 h = shost_priv(SChost);
33229
33230- if (h) {
33231- if (h->info_kbuf == NULL)
33232- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
33233- return h->info_kbuf;
33234- h->info_kbuf[0] = '\0';
33235+ if (!h)
33236+ return NULL;
33237
33238- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
33239- h->info_kbuf[size-1] = '\0';
33240- }
33241+ if (h->info_kbuf == NULL)
33242+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
33243+ return h->info_kbuf;
33244+ h->info_kbuf[0] = '\0';
33245+
33246+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
33247+ h->info_kbuf[size-1] = '\0';
33248
33249 return h->info_kbuf;
33250 }
33251diff -urNp linux-2.6.39.1/drivers/message/i2o/i2o_config.c linux-2.6.39.1/drivers/message/i2o/i2o_config.c
33252--- linux-2.6.39.1/drivers/message/i2o/i2o_config.c 2011-05-19 00:06:34.000000000 -0400
33253+++ linux-2.6.39.1/drivers/message/i2o/i2o_config.c 2011-05-22 19:36:31.000000000 -0400
33254@@ -781,6 +781,8 @@ static int i2o_cfg_passthru(unsigned lon
33255 struct i2o_message *msg;
33256 unsigned int iop;
33257
33258+ pax_track_stack();
33259+
33260 if (get_user(iop, &cmd->iop) || get_user(user_msg, &cmd->msg))
33261 return -EFAULT;
33262
33263diff -urNp linux-2.6.39.1/drivers/message/i2o/i2o_proc.c linux-2.6.39.1/drivers/message/i2o/i2o_proc.c
33264--- linux-2.6.39.1/drivers/message/i2o/i2o_proc.c 2011-05-19 00:06:34.000000000 -0400
33265+++ linux-2.6.39.1/drivers/message/i2o/i2o_proc.c 2011-05-22 19:36:31.000000000 -0400
33266@@ -255,13 +255,6 @@ static char *scsi_devices[] = {
33267 "Array Controller Device"
33268 };
33269
33270-static char *chtostr(u8 * chars, int n)
33271-{
33272- char tmp[256];
33273- tmp[0] = 0;
33274- return strncat(tmp, (char *)chars, n);
33275-}
33276-
33277 static int i2o_report_query_status(struct seq_file *seq, int block_status,
33278 char *group)
33279 {
33280@@ -838,8 +831,7 @@ static int i2o_seq_show_ddm_table(struct
33281
33282 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
33283 seq_printf(seq, "%-#8x", ddm_table.module_id);
33284- seq_printf(seq, "%-29s",
33285- chtostr(ddm_table.module_name_version, 28));
33286+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
33287 seq_printf(seq, "%9d ", ddm_table.data_size);
33288 seq_printf(seq, "%8d", ddm_table.code_size);
33289
33290@@ -940,8 +932,8 @@ static int i2o_seq_show_drivers_stored(s
33291
33292 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
33293 seq_printf(seq, "%-#8x", dst->module_id);
33294- seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
33295- seq_printf(seq, "%-9s", chtostr(dst->date, 8));
33296+ seq_printf(seq, "%-.28s", dst->module_name_version);
33297+ seq_printf(seq, "%-.8s", dst->date);
33298 seq_printf(seq, "%8d ", dst->module_size);
33299 seq_printf(seq, "%8d ", dst->mpb_size);
33300 seq_printf(seq, "0x%04x", dst->module_flags);
33301@@ -1272,14 +1264,10 @@ static int i2o_seq_show_dev_identity(str
33302 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
33303 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
33304 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
33305- seq_printf(seq, "Vendor info : %s\n",
33306- chtostr((u8 *) (work32 + 2), 16));
33307- seq_printf(seq, "Product info : %s\n",
33308- chtostr((u8 *) (work32 + 6), 16));
33309- seq_printf(seq, "Description : %s\n",
33310- chtostr((u8 *) (work32 + 10), 16));
33311- seq_printf(seq, "Product rev. : %s\n",
33312- chtostr((u8 *) (work32 + 14), 8));
33313+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
33314+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
33315+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
33316+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
33317
33318 seq_printf(seq, "Serial number : ");
33319 print_serial_number(seq, (u8 *) (work32 + 16),
33320@@ -1324,10 +1312,8 @@ static int i2o_seq_show_ddm_identity(str
33321 }
33322
33323 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
33324- seq_printf(seq, "Module name : %s\n",
33325- chtostr(result.module_name, 24));
33326- seq_printf(seq, "Module revision : %s\n",
33327- chtostr(result.module_rev, 8));
33328+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
33329+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
33330
33331 seq_printf(seq, "Serial number : ");
33332 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
33333@@ -1358,14 +1344,10 @@ static int i2o_seq_show_uinfo(struct seq
33334 return 0;
33335 }
33336
33337- seq_printf(seq, "Device name : %s\n",
33338- chtostr(result.device_name, 64));
33339- seq_printf(seq, "Service name : %s\n",
33340- chtostr(result.service_name, 64));
33341- seq_printf(seq, "Physical name : %s\n",
33342- chtostr(result.physical_location, 64));
33343- seq_printf(seq, "Instance number : %s\n",
33344- chtostr(result.instance_number, 4));
33345+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
33346+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
33347+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
33348+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
33349
33350 return 0;
33351 }
33352diff -urNp linux-2.6.39.1/drivers/message/i2o/iop.c linux-2.6.39.1/drivers/message/i2o/iop.c
33353--- linux-2.6.39.1/drivers/message/i2o/iop.c 2011-05-19 00:06:34.000000000 -0400
33354+++ linux-2.6.39.1/drivers/message/i2o/iop.c 2011-05-22 19:36:31.000000000 -0400
33355@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_contro
33356
33357 spin_lock_irqsave(&c->context_list_lock, flags);
33358
33359- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
33360- atomic_inc(&c->context_list_counter);
33361+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
33362+ atomic_inc_unchecked(&c->context_list_counter);
33363
33364- entry->context = atomic_read(&c->context_list_counter);
33365+ entry->context = atomic_read_unchecked(&c->context_list_counter);
33366
33367 list_add(&entry->list, &c->context_list);
33368
33369@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(voi
33370
33371 #if BITS_PER_LONG == 64
33372 spin_lock_init(&c->context_list_lock);
33373- atomic_set(&c->context_list_counter, 0);
33374+ atomic_set_unchecked(&c->context_list_counter, 0);
33375 INIT_LIST_HEAD(&c->context_list);
33376 #endif
33377
33378diff -urNp linux-2.6.39.1/drivers/mfd/ab3100-core.c linux-2.6.39.1/drivers/mfd/ab3100-core.c
33379--- linux-2.6.39.1/drivers/mfd/ab3100-core.c 2011-05-19 00:06:34.000000000 -0400
33380+++ linux-2.6.39.1/drivers/mfd/ab3100-core.c 2011-05-22 19:36:31.000000000 -0400
33381@@ -385,7 +385,7 @@ static int ab3100_event_registers_startu
33382 return 0;
33383 }
33384
33385-static struct abx500_ops ab3100_ops = {
33386+static const struct abx500_ops ab3100_ops = {
33387 .get_chip_id = ab3100_get_chip_id,
33388 .set_register = set_register_interruptible,
33389 .get_register = get_register_interruptible,
33390diff -urNp linux-2.6.39.1/drivers/mfd/ab3550-core.c linux-2.6.39.1/drivers/mfd/ab3550-core.c
33391--- linux-2.6.39.1/drivers/mfd/ab3550-core.c 2011-05-19 00:06:34.000000000 -0400
33392+++ linux-2.6.39.1/drivers/mfd/ab3550-core.c 2011-05-22 19:36:31.000000000 -0400
33393@@ -676,7 +676,7 @@ static int ab3550_startup_irq_enabled(st
33394 return val;
33395 }
33396
33397-static struct abx500_ops ab3550_ops = {
33398+static const struct abx500_ops ab3550_ops = {
33399 .get_chip_id = ab3550_get_chip_id,
33400 .get_register = ab3550_get_register_interruptible,
33401 .set_register = ab3550_set_register_interruptible,
33402diff -urNp linux-2.6.39.1/drivers/mfd/ab8500-core.c linux-2.6.39.1/drivers/mfd/ab8500-core.c
33403--- linux-2.6.39.1/drivers/mfd/ab8500-core.c 2011-05-19 00:06:34.000000000 -0400
33404+++ linux-2.6.39.1/drivers/mfd/ab8500-core.c 2011-05-22 19:36:31.000000000 -0400
33405@@ -223,7 +223,7 @@ static int ab8500_mask_and_set_register(
33406
33407 }
33408
33409-static struct abx500_ops ab8500_ops = {
33410+static const struct abx500_ops ab8500_ops = {
33411 .get_chip_id = ab8500_get_chip_id,
33412 .get_register = ab8500_get_register,
33413 .set_register = ab8500_set_register,
33414diff -urNp linux-2.6.39.1/drivers/mfd/abx500-core.c linux-2.6.39.1/drivers/mfd/abx500-core.c
33415--- linux-2.6.39.1/drivers/mfd/abx500-core.c 2011-05-19 00:06:34.000000000 -0400
33416+++ linux-2.6.39.1/drivers/mfd/abx500-core.c 2011-05-22 19:36:31.000000000 -0400
33417@@ -18,7 +18,7 @@ struct abx500_device_entry {
33418 struct device *dev;
33419 };
33420
33421-static void lookup_ops(struct device *dev, struct abx500_ops **ops)
33422+static void lookup_ops(struct device *dev, const struct abx500_ops **ops)
33423 {
33424 struct abx500_device_entry *dev_entry;
33425
33426@@ -31,7 +31,7 @@ static void lookup_ops(struct device *de
33427 }
33428 }
33429
33430-int abx500_register_ops(struct device *dev, struct abx500_ops *ops)
33431+int abx500_register_ops(struct device *dev, const struct abx500_ops *ops)
33432 {
33433 struct abx500_device_entry *dev_entry;
33434
33435@@ -65,7 +65,7 @@ EXPORT_SYMBOL(abx500_remove_ops);
33436 int abx500_set_register_interruptible(struct device *dev, u8 bank, u8 reg,
33437 u8 value)
33438 {
33439- struct abx500_ops *ops;
33440+ const struct abx500_ops *ops;
33441
33442 lookup_ops(dev->parent, &ops);
33443 if ((ops != NULL) && (ops->set_register != NULL))
33444@@ -78,7 +78,7 @@ EXPORT_SYMBOL(abx500_set_register_interr
33445 int abx500_get_register_interruptible(struct device *dev, u8 bank, u8 reg,
33446 u8 *value)
33447 {
33448- struct abx500_ops *ops;
33449+ const struct abx500_ops *ops;
33450
33451 lookup_ops(dev->parent, &ops);
33452 if ((ops != NULL) && (ops->get_register != NULL))
33453@@ -91,7 +91,7 @@ EXPORT_SYMBOL(abx500_get_register_interr
33454 int abx500_get_register_page_interruptible(struct device *dev, u8 bank,
33455 u8 first_reg, u8 *regvals, u8 numregs)
33456 {
33457- struct abx500_ops *ops;
33458+ const struct abx500_ops *ops;
33459
33460 lookup_ops(dev->parent, &ops);
33461 if ((ops != NULL) && (ops->get_register_page != NULL))
33462@@ -105,7 +105,7 @@ EXPORT_SYMBOL(abx500_get_register_page_i
33463 int abx500_mask_and_set_register_interruptible(struct device *dev, u8 bank,
33464 u8 reg, u8 bitmask, u8 bitvalues)
33465 {
33466- struct abx500_ops *ops;
33467+ const struct abx500_ops *ops;
33468
33469 lookup_ops(dev->parent, &ops);
33470 if ((ops != NULL) && (ops->mask_and_set_register != NULL))
33471@@ -118,7 +118,7 @@ EXPORT_SYMBOL(abx500_mask_and_set_regist
33472
33473 int abx500_get_chip_id(struct device *dev)
33474 {
33475- struct abx500_ops *ops;
33476+ const struct abx500_ops *ops;
33477
33478 lookup_ops(dev->parent, &ops);
33479 if ((ops != NULL) && (ops->get_chip_id != NULL))
33480@@ -130,7 +130,7 @@ EXPORT_SYMBOL(abx500_get_chip_id);
33481
33482 int abx500_event_registers_startup_state_get(struct device *dev, u8 *event)
33483 {
33484- struct abx500_ops *ops;
33485+ const struct abx500_ops *ops;
33486
33487 lookup_ops(dev->parent, &ops);
33488 if ((ops != NULL) && (ops->event_registers_startup_state_get != NULL))
33489@@ -142,7 +142,7 @@ EXPORT_SYMBOL(abx500_event_registers_sta
33490
33491 int abx500_startup_irq_enabled(struct device *dev, unsigned int irq)
33492 {
33493- struct abx500_ops *ops;
33494+ const struct abx500_ops *ops;
33495
33496 lookup_ops(dev->parent, &ops);
33497 if ((ops != NULL) && (ops->startup_irq_enabled != NULL))
33498diff -urNp linux-2.6.39.1/drivers/mfd/janz-cmodio.c linux-2.6.39.1/drivers/mfd/janz-cmodio.c
33499--- linux-2.6.39.1/drivers/mfd/janz-cmodio.c 2011-05-19 00:06:34.000000000 -0400
33500+++ linux-2.6.39.1/drivers/mfd/janz-cmodio.c 2011-05-22 19:36:31.000000000 -0400
33501@@ -13,6 +13,7 @@
33502
33503 #include <linux/kernel.h>
33504 #include <linux/module.h>
33505+#include <linux/slab.h>
33506 #include <linux/init.h>
33507 #include <linux/pci.h>
33508 #include <linux/interrupt.h>
33509diff -urNp linux-2.6.39.1/drivers/mfd/mcp-sa11x0.c linux-2.6.39.1/drivers/mfd/mcp-sa11x0.c
33510--- linux-2.6.39.1/drivers/mfd/mcp-sa11x0.c 2011-05-19 00:06:34.000000000 -0400
33511+++ linux-2.6.39.1/drivers/mfd/mcp-sa11x0.c 2011-05-22 19:36:31.000000000 -0400
33512@@ -128,7 +128,7 @@ static void mcp_sa11x0_disable(struct mc
33513 /*
33514 * Our methods.
33515 */
33516-static struct mcp_ops mcp_sa11x0 = {
33517+static const struct mcp_ops mcp_sa11x0 = {
33518 .set_telecom_divisor = mcp_sa11x0_set_telecom_divisor,
33519 .set_audio_divisor = mcp_sa11x0_set_audio_divisor,
33520 .reg_write = mcp_sa11x0_write,
33521diff -urNp linux-2.6.39.1/drivers/mfd/wm8350-i2c.c linux-2.6.39.1/drivers/mfd/wm8350-i2c.c
33522--- linux-2.6.39.1/drivers/mfd/wm8350-i2c.c 2011-05-19 00:06:34.000000000 -0400
33523+++ linux-2.6.39.1/drivers/mfd/wm8350-i2c.c 2011-05-22 19:36:31.000000000 -0400
33524@@ -44,6 +44,8 @@ static int wm8350_i2c_write_device(struc
33525 u8 msg[(WM8350_MAX_REGISTER << 1) + 1];
33526 int ret;
33527
33528+ pax_track_stack();
33529+
33530 if (bytes > ((WM8350_MAX_REGISTER << 1) + 1))
33531 return -EINVAL;
33532
33533diff -urNp linux-2.6.39.1/drivers/misc/enclosure.c linux-2.6.39.1/drivers/misc/enclosure.c
33534--- linux-2.6.39.1/drivers/misc/enclosure.c 2011-05-19 00:06:34.000000000 -0400
33535+++ linux-2.6.39.1/drivers/misc/enclosure.c 2011-05-22 19:36:31.000000000 -0400
33536@@ -161,7 +161,7 @@ enclosure_register(struct device *dev, c
33537 }
33538 EXPORT_SYMBOL_GPL(enclosure_register);
33539
33540-static struct enclosure_component_callbacks enclosure_null_callbacks;
33541+static const struct enclosure_component_callbacks enclosure_null_callbacks;
33542
33543 /**
33544 * enclosure_unregister - remove an enclosure
33545diff -urNp linux-2.6.39.1/drivers/misc/kgdbts.c linux-2.6.39.1/drivers/misc/kgdbts.c
33546--- linux-2.6.39.1/drivers/misc/kgdbts.c 2011-05-19 00:06:34.000000000 -0400
33547+++ linux-2.6.39.1/drivers/misc/kgdbts.c 2011-05-22 19:36:31.000000000 -0400
33548@@ -118,7 +118,7 @@
33549 } while (0)
33550 #define MAX_CONFIG_LEN 40
33551
33552-static struct kgdb_io kgdbts_io_ops;
33553+static const struct kgdb_io kgdbts_io_ops;
33554 static char get_buf[BUFMAX];
33555 static int get_buf_cnt;
33556 static char put_buf[BUFMAX];
33557@@ -1103,7 +1103,7 @@ static void kgdbts_post_exp_handler(void
33558 module_put(THIS_MODULE);
33559 }
33560
33561-static struct kgdb_io kgdbts_io_ops = {
33562+static const struct kgdb_io kgdbts_io_ops = {
33563 .name = "kgdbts",
33564 .read_char = kgdbts_get_char,
33565 .write_char = kgdbts_put_char,
33566diff -urNp linux-2.6.39.1/drivers/misc/lis3lv02d/lis3lv02d.c linux-2.6.39.1/drivers/misc/lis3lv02d/lis3lv02d.c
33567--- linux-2.6.39.1/drivers/misc/lis3lv02d/lis3lv02d.c 2011-05-19 00:06:34.000000000 -0400
33568+++ linux-2.6.39.1/drivers/misc/lis3lv02d/lis3lv02d.c 2011-05-22 19:36:31.000000000 -0400
33569@@ -435,7 +435,7 @@ static irqreturn_t lis302dl_interrupt(in
33570 * the lid is closed. This leads to interrupts as soon as a little move
33571 * is done.
33572 */
33573- atomic_inc(&lis3_dev.count);
33574+ atomic_inc_unchecked(&lis3_dev.count);
33575
33576 wake_up_interruptible(&lis3_dev.misc_wait);
33577 kill_fasync(&lis3_dev.async_queue, SIGIO, POLL_IN);
33578@@ -518,7 +518,7 @@ static int lis3lv02d_misc_open(struct in
33579 if (lis3_dev.pm_dev)
33580 pm_runtime_get_sync(lis3_dev.pm_dev);
33581
33582- atomic_set(&lis3_dev.count, 0);
33583+ atomic_set_unchecked(&lis3_dev.count, 0);
33584 return 0;
33585 }
33586
33587@@ -545,7 +545,7 @@ static ssize_t lis3lv02d_misc_read(struc
33588 add_wait_queue(&lis3_dev.misc_wait, &wait);
33589 while (true) {
33590 set_current_state(TASK_INTERRUPTIBLE);
33591- data = atomic_xchg(&lis3_dev.count, 0);
33592+ data = atomic_xchg_unchecked(&lis3_dev.count, 0);
33593 if (data)
33594 break;
33595
33596@@ -583,7 +583,7 @@ out:
33597 static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
33598 {
33599 poll_wait(file, &lis3_dev.misc_wait, wait);
33600- if (atomic_read(&lis3_dev.count))
33601+ if (atomic_read_unchecked(&lis3_dev.count))
33602 return POLLIN | POLLRDNORM;
33603 return 0;
33604 }
33605diff -urNp linux-2.6.39.1/drivers/misc/lis3lv02d/lis3lv02d.h linux-2.6.39.1/drivers/misc/lis3lv02d/lis3lv02d.h
33606--- linux-2.6.39.1/drivers/misc/lis3lv02d/lis3lv02d.h 2011-05-19 00:06:34.000000000 -0400
33607+++ linux-2.6.39.1/drivers/misc/lis3lv02d/lis3lv02d.h 2011-05-22 19:36:31.000000000 -0400
33608@@ -265,7 +265,7 @@ struct lis3lv02d {
33609 struct input_polled_dev *idev; /* input device */
33610 struct platform_device *pdev; /* platform device */
33611 struct regulator_bulk_data regulators[2];
33612- atomic_t count; /* interrupt count after last read */
33613+ atomic_unchecked_t count; /* interrupt count after last read */
33614 union axis_conversion ac; /* hw -> logical axis */
33615 int mapped_btns[3];
33616
33617diff -urNp linux-2.6.39.1/drivers/misc/sgi-gru/gruhandles.c linux-2.6.39.1/drivers/misc/sgi-gru/gruhandles.c
33618--- linux-2.6.39.1/drivers/misc/sgi-gru/gruhandles.c 2011-05-19 00:06:34.000000000 -0400
33619+++ linux-2.6.39.1/drivers/misc/sgi-gru/gruhandles.c 2011-05-22 19:36:31.000000000 -0400
33620@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op
33621 unsigned long nsec;
33622
33623 nsec = CLKS2NSEC(clks);
33624- atomic_long_inc(&mcs_op_statistics[op].count);
33625- atomic_long_add(nsec, &mcs_op_statistics[op].total);
33626+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
33627+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
33628 if (mcs_op_statistics[op].max < nsec)
33629 mcs_op_statistics[op].max = nsec;
33630 }
33631diff -urNp linux-2.6.39.1/drivers/misc/sgi-gru/gruprocfs.c linux-2.6.39.1/drivers/misc/sgi-gru/gruprocfs.c
33632--- linux-2.6.39.1/drivers/misc/sgi-gru/gruprocfs.c 2011-05-19 00:06:34.000000000 -0400
33633+++ linux-2.6.39.1/drivers/misc/sgi-gru/gruprocfs.c 2011-05-22 19:36:31.000000000 -0400
33634@@ -32,9 +32,9 @@
33635
33636 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
33637
33638-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
33639+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
33640 {
33641- unsigned long val = atomic_long_read(v);
33642+ unsigned long val = atomic_long_read_unchecked(v);
33643
33644 seq_printf(s, "%16lu %s\n", val, id);
33645 }
33646@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct se
33647
33648 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
33649 for (op = 0; op < mcsop_last; op++) {
33650- count = atomic_long_read(&mcs_op_statistics[op].count);
33651- total = atomic_long_read(&mcs_op_statistics[op].total);
33652+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
33653+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
33654 max = mcs_op_statistics[op].max;
33655 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
33656 count ? total / count : 0, max);
33657diff -urNp linux-2.6.39.1/drivers/misc/sgi-gru/grutables.h linux-2.6.39.1/drivers/misc/sgi-gru/grutables.h
33658--- linux-2.6.39.1/drivers/misc/sgi-gru/grutables.h 2011-05-19 00:06:34.000000000 -0400
33659+++ linux-2.6.39.1/drivers/misc/sgi-gru/grutables.h 2011-05-22 19:36:31.000000000 -0400
33660@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
33661 * GRU statistics.
33662 */
33663 struct gru_stats_s {
33664- atomic_long_t vdata_alloc;
33665- atomic_long_t vdata_free;
33666- atomic_long_t gts_alloc;
33667- atomic_long_t gts_free;
33668- atomic_long_t gms_alloc;
33669- atomic_long_t gms_free;
33670- atomic_long_t gts_double_allocate;
33671- atomic_long_t assign_context;
33672- atomic_long_t assign_context_failed;
33673- atomic_long_t free_context;
33674- atomic_long_t load_user_context;
33675- atomic_long_t load_kernel_context;
33676- atomic_long_t lock_kernel_context;
33677- atomic_long_t unlock_kernel_context;
33678- atomic_long_t steal_user_context;
33679- atomic_long_t steal_kernel_context;
33680- atomic_long_t steal_context_failed;
33681- atomic_long_t nopfn;
33682- atomic_long_t asid_new;
33683- atomic_long_t asid_next;
33684- atomic_long_t asid_wrap;
33685- atomic_long_t asid_reuse;
33686- atomic_long_t intr;
33687- atomic_long_t intr_cbr;
33688- atomic_long_t intr_tfh;
33689- atomic_long_t intr_spurious;
33690- atomic_long_t intr_mm_lock_failed;
33691- atomic_long_t call_os;
33692- atomic_long_t call_os_wait_queue;
33693- atomic_long_t user_flush_tlb;
33694- atomic_long_t user_unload_context;
33695- atomic_long_t user_exception;
33696- atomic_long_t set_context_option;
33697- atomic_long_t check_context_retarget_intr;
33698- atomic_long_t check_context_unload;
33699- atomic_long_t tlb_dropin;
33700- atomic_long_t tlb_preload_page;
33701- atomic_long_t tlb_dropin_fail_no_asid;
33702- atomic_long_t tlb_dropin_fail_upm;
33703- atomic_long_t tlb_dropin_fail_invalid;
33704- atomic_long_t tlb_dropin_fail_range_active;
33705- atomic_long_t tlb_dropin_fail_idle;
33706- atomic_long_t tlb_dropin_fail_fmm;
33707- atomic_long_t tlb_dropin_fail_no_exception;
33708- atomic_long_t tfh_stale_on_fault;
33709- atomic_long_t mmu_invalidate_range;
33710- atomic_long_t mmu_invalidate_page;
33711- atomic_long_t flush_tlb;
33712- atomic_long_t flush_tlb_gru;
33713- atomic_long_t flush_tlb_gru_tgh;
33714- atomic_long_t flush_tlb_gru_zero_asid;
33715-
33716- atomic_long_t copy_gpa;
33717- atomic_long_t read_gpa;
33718-
33719- atomic_long_t mesq_receive;
33720- atomic_long_t mesq_receive_none;
33721- atomic_long_t mesq_send;
33722- atomic_long_t mesq_send_failed;
33723- atomic_long_t mesq_noop;
33724- atomic_long_t mesq_send_unexpected_error;
33725- atomic_long_t mesq_send_lb_overflow;
33726- atomic_long_t mesq_send_qlimit_reached;
33727- atomic_long_t mesq_send_amo_nacked;
33728- atomic_long_t mesq_send_put_nacked;
33729- atomic_long_t mesq_page_overflow;
33730- atomic_long_t mesq_qf_locked;
33731- atomic_long_t mesq_qf_noop_not_full;
33732- atomic_long_t mesq_qf_switch_head_failed;
33733- atomic_long_t mesq_qf_unexpected_error;
33734- atomic_long_t mesq_noop_unexpected_error;
33735- atomic_long_t mesq_noop_lb_overflow;
33736- atomic_long_t mesq_noop_qlimit_reached;
33737- atomic_long_t mesq_noop_amo_nacked;
33738- atomic_long_t mesq_noop_put_nacked;
33739- atomic_long_t mesq_noop_page_overflow;
33740+ atomic_long_unchecked_t vdata_alloc;
33741+ atomic_long_unchecked_t vdata_free;
33742+ atomic_long_unchecked_t gts_alloc;
33743+ atomic_long_unchecked_t gts_free;
33744+ atomic_long_unchecked_t gms_alloc;
33745+ atomic_long_unchecked_t gms_free;
33746+ atomic_long_unchecked_t gts_double_allocate;
33747+ atomic_long_unchecked_t assign_context;
33748+ atomic_long_unchecked_t assign_context_failed;
33749+ atomic_long_unchecked_t free_context;
33750+ atomic_long_unchecked_t load_user_context;
33751+ atomic_long_unchecked_t load_kernel_context;
33752+ atomic_long_unchecked_t lock_kernel_context;
33753+ atomic_long_unchecked_t unlock_kernel_context;
33754+ atomic_long_unchecked_t steal_user_context;
33755+ atomic_long_unchecked_t steal_kernel_context;
33756+ atomic_long_unchecked_t steal_context_failed;
33757+ atomic_long_unchecked_t nopfn;
33758+ atomic_long_unchecked_t asid_new;
33759+ atomic_long_unchecked_t asid_next;
33760+ atomic_long_unchecked_t asid_wrap;
33761+ atomic_long_unchecked_t asid_reuse;
33762+ atomic_long_unchecked_t intr;
33763+ atomic_long_unchecked_t intr_cbr;
33764+ atomic_long_unchecked_t intr_tfh;
33765+ atomic_long_unchecked_t intr_spurious;
33766+ atomic_long_unchecked_t intr_mm_lock_failed;
33767+ atomic_long_unchecked_t call_os;
33768+ atomic_long_unchecked_t call_os_wait_queue;
33769+ atomic_long_unchecked_t user_flush_tlb;
33770+ atomic_long_unchecked_t user_unload_context;
33771+ atomic_long_unchecked_t user_exception;
33772+ atomic_long_unchecked_t set_context_option;
33773+ atomic_long_unchecked_t check_context_retarget_intr;
33774+ atomic_long_unchecked_t check_context_unload;
33775+ atomic_long_unchecked_t tlb_dropin;
33776+ atomic_long_unchecked_t tlb_preload_page;
33777+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
33778+ atomic_long_unchecked_t tlb_dropin_fail_upm;
33779+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
33780+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
33781+ atomic_long_unchecked_t tlb_dropin_fail_idle;
33782+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
33783+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
33784+ atomic_long_unchecked_t tfh_stale_on_fault;
33785+ atomic_long_unchecked_t mmu_invalidate_range;
33786+ atomic_long_unchecked_t mmu_invalidate_page;
33787+ atomic_long_unchecked_t flush_tlb;
33788+ atomic_long_unchecked_t flush_tlb_gru;
33789+ atomic_long_unchecked_t flush_tlb_gru_tgh;
33790+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
33791+
33792+ atomic_long_unchecked_t copy_gpa;
33793+ atomic_long_unchecked_t read_gpa;
33794+
33795+ atomic_long_unchecked_t mesq_receive;
33796+ atomic_long_unchecked_t mesq_receive_none;
33797+ atomic_long_unchecked_t mesq_send;
33798+ atomic_long_unchecked_t mesq_send_failed;
33799+ atomic_long_unchecked_t mesq_noop;
33800+ atomic_long_unchecked_t mesq_send_unexpected_error;
33801+ atomic_long_unchecked_t mesq_send_lb_overflow;
33802+ atomic_long_unchecked_t mesq_send_qlimit_reached;
33803+ atomic_long_unchecked_t mesq_send_amo_nacked;
33804+ atomic_long_unchecked_t mesq_send_put_nacked;
33805+ atomic_long_unchecked_t mesq_page_overflow;
33806+ atomic_long_unchecked_t mesq_qf_locked;
33807+ atomic_long_unchecked_t mesq_qf_noop_not_full;
33808+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
33809+ atomic_long_unchecked_t mesq_qf_unexpected_error;
33810+ atomic_long_unchecked_t mesq_noop_unexpected_error;
33811+ atomic_long_unchecked_t mesq_noop_lb_overflow;
33812+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
33813+ atomic_long_unchecked_t mesq_noop_amo_nacked;
33814+ atomic_long_unchecked_t mesq_noop_put_nacked;
33815+ atomic_long_unchecked_t mesq_noop_page_overflow;
33816
33817 };
33818
33819@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start
33820 tghop_invalidate, mcsop_last};
33821
33822 struct mcs_op_statistic {
33823- atomic_long_t count;
33824- atomic_long_t total;
33825+ atomic_long_unchecked_t count;
33826+ atomic_long_unchecked_t total;
33827 unsigned long max;
33828 };
33829
33830@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_st
33831
33832 #define STAT(id) do { \
33833 if (gru_options & OPT_STATS) \
33834- atomic_long_inc(&gru_stats.id); \
33835+ atomic_long_inc_unchecked(&gru_stats.id); \
33836 } while (0)
33837
33838 #ifdef CONFIG_SGI_GRU_DEBUG
33839diff -urNp linux-2.6.39.1/drivers/misc/sgi-xp/xpc_sn2.c linux-2.6.39.1/drivers/misc/sgi-xp/xpc_sn2.c
33840--- linux-2.6.39.1/drivers/misc/sgi-xp/xpc_sn2.c 2011-05-19 00:06:34.000000000 -0400
33841+++ linux-2.6.39.1/drivers/misc/sgi-xp/xpc_sn2.c 2011-05-22 19:36:31.000000000 -0400
33842@@ -2351,7 +2351,7 @@ xpc_received_payload_sn2(struct xpc_chan
33843 xpc_acknowledge_msgs_sn2(ch, get, msg->flags);
33844 }
33845
33846-static struct xpc_arch_operations xpc_arch_ops_sn2 = {
33847+static const struct xpc_arch_operations xpc_arch_ops_sn2 = {
33848 .setup_partitions = xpc_setup_partitions_sn2,
33849 .teardown_partitions = xpc_teardown_partitions_sn2,
33850 .process_activate_IRQ_rcvd = xpc_process_activate_IRQ_rcvd_sn2,
33851diff -urNp linux-2.6.39.1/drivers/misc/sgi-xp/xpc_uv.c linux-2.6.39.1/drivers/misc/sgi-xp/xpc_uv.c
33852--- linux-2.6.39.1/drivers/misc/sgi-xp/xpc_uv.c 2011-05-19 00:06:34.000000000 -0400
33853+++ linux-2.6.39.1/drivers/misc/sgi-xp/xpc_uv.c 2011-05-22 19:36:31.000000000 -0400
33854@@ -1674,7 +1674,7 @@ xpc_received_payload_uv(struct xpc_chann
33855 XPC_DEACTIVATE_PARTITION(&xpc_partitions[ch->partid], ret);
33856 }
33857
33858-static struct xpc_arch_operations xpc_arch_ops_uv = {
33859+static const struct xpc_arch_operations xpc_arch_ops_uv = {
33860 .setup_partitions = xpc_setup_partitions_uv,
33861 .teardown_partitions = xpc_teardown_partitions_uv,
33862 .process_activate_IRQ_rcvd = xpc_process_activate_IRQ_rcvd_uv,
33863diff -urNp linux-2.6.39.1/drivers/misc/spear13xx_pcie_gadget.c linux-2.6.39.1/drivers/misc/spear13xx_pcie_gadget.c
33864--- linux-2.6.39.1/drivers/misc/spear13xx_pcie_gadget.c 2011-05-19 00:06:34.000000000 -0400
33865+++ linux-2.6.39.1/drivers/misc/spear13xx_pcie_gadget.c 2011-05-22 19:36:31.000000000 -0400
33866@@ -644,7 +644,7 @@ static ssize_t pcie_gadget_target_attr_s
33867 return ret;
33868 }
33869
33870-static struct configfs_item_operations pcie_gadget_target_item_ops = {
33871+static const struct configfs_item_operations pcie_gadget_target_item_ops = {
33872 .show_attribute = pcie_gadget_target_attr_show,
33873 .store_attribute = pcie_gadget_target_attr_store,
33874 };
33875diff -urNp linux-2.6.39.1/drivers/mmc/host/davinci_mmc.c linux-2.6.39.1/drivers/mmc/host/davinci_mmc.c
33876--- linux-2.6.39.1/drivers/mmc/host/davinci_mmc.c 2011-05-19 00:06:34.000000000 -0400
33877+++ linux-2.6.39.1/drivers/mmc/host/davinci_mmc.c 2011-05-22 19:36:31.000000000 -0400
33878@@ -1133,7 +1133,7 @@ static void mmc_davinci_enable_sdio_irq(
33879 }
33880 }
33881
33882-static struct mmc_host_ops mmc_davinci_ops = {
33883+static const struct mmc_host_ops mmc_davinci_ops = {
33884 .request = mmc_davinci_request,
33885 .set_ios = mmc_davinci_set_ios,
33886 .get_cd = mmc_davinci_get_cd,
33887diff -urNp linux-2.6.39.1/drivers/mmc/host/dw_mmc.c linux-2.6.39.1/drivers/mmc/host/dw_mmc.c
33888--- linux-2.6.39.1/drivers/mmc/host/dw_mmc.c 2011-05-19 00:06:34.000000000 -0400
33889+++ linux-2.6.39.1/drivers/mmc/host/dw_mmc.c 2011-05-22 19:36:31.000000000 -0400
33890@@ -417,7 +417,7 @@ static int dw_mci_idmac_init(struct dw_m
33891 return 0;
33892 }
33893
33894-static struct dw_mci_dma_ops dw_mci_idmac_ops = {
33895+static const struct dw_mci_dma_ops dw_mci_idmac_ops = {
33896 .init = dw_mci_idmac_init,
33897 .start = dw_mci_idmac_start_dma,
33898 .stop = dw_mci_idmac_stop_dma,
33899diff -urNp linux-2.6.39.1/drivers/mmc/host/s3cmci.c linux-2.6.39.1/drivers/mmc/host/s3cmci.c
33900--- linux-2.6.39.1/drivers/mmc/host/s3cmci.c 2011-05-19 00:06:34.000000000 -0400
33901+++ linux-2.6.39.1/drivers/mmc/host/s3cmci.c 2011-05-22 19:36:31.000000000 -0400
33902@@ -1349,7 +1349,7 @@ static void s3cmci_enable_sdio_irq(struc
33903 s3cmci_check_sdio_irq(host);
33904 }
33905
33906-static struct mmc_host_ops s3cmci_ops = {
33907+static const struct mmc_host_ops s3cmci_ops = {
33908 .request = s3cmci_request,
33909 .set_ios = s3cmci_set_ios,
33910 .get_ro = s3cmci_get_ro,
33911diff -urNp linux-2.6.39.1/drivers/mmc/host/sdhci-cns3xxx.c linux-2.6.39.1/drivers/mmc/host/sdhci-cns3xxx.c
33912--- linux-2.6.39.1/drivers/mmc/host/sdhci-cns3xxx.c 2011-05-19 00:06:34.000000000 -0400
33913+++ linux-2.6.39.1/drivers/mmc/host/sdhci-cns3xxx.c 2011-05-22 19:36:31.000000000 -0400
33914@@ -81,7 +81,7 @@ out:
33915 host->clock = clock;
33916 }
33917
33918-static struct sdhci_ops sdhci_cns3xxx_ops = {
33919+static const struct sdhci_ops sdhci_cns3xxx_ops = {
33920 .get_max_clock = sdhci_cns3xxx_get_max_clk,
33921 .set_clock = sdhci_cns3xxx_set_clock,
33922 };
33923diff -urNp linux-2.6.39.1/drivers/mmc/host/sdhci-dove.c linux-2.6.39.1/drivers/mmc/host/sdhci-dove.c
33924--- linux-2.6.39.1/drivers/mmc/host/sdhci-dove.c 2011-05-19 00:06:34.000000000 -0400
33925+++ linux-2.6.39.1/drivers/mmc/host/sdhci-dove.c 2011-05-22 19:36:31.000000000 -0400
33926@@ -56,7 +56,7 @@ static u32 sdhci_dove_readl(struct sdhci
33927 return ret;
33928 }
33929
33930-static struct sdhci_ops sdhci_dove_ops = {
33931+static const struct sdhci_ops sdhci_dove_ops = {
33932 .read_w = sdhci_dove_readw,
33933 .read_l = sdhci_dove_readl,
33934 };
33935diff -urNp linux-2.6.39.1/drivers/mmc/host/sdhci-esdhc-imx.c linux-2.6.39.1/drivers/mmc/host/sdhci-esdhc-imx.c
33936--- linux-2.6.39.1/drivers/mmc/host/sdhci-esdhc-imx.c 2011-05-19 00:06:34.000000000 -0400
33937+++ linux-2.6.39.1/drivers/mmc/host/sdhci-esdhc-imx.c 2011-05-22 19:36:31.000000000 -0400
33938@@ -201,7 +201,7 @@ static unsigned int esdhc_pltfm_get_ro(s
33939 return -ENOSYS;
33940 }
33941
33942-static struct sdhci_ops sdhci_esdhc_ops = {
33943+static const struct sdhci_ops sdhci_esdhc_ops = {
33944 .read_l = esdhc_readl_le,
33945 .read_w = esdhc_readw_le,
33946 .write_l = esdhc_writel_le,
33947diff -urNp linux-2.6.39.1/drivers/mmc/host/sdhci-of.h linux-2.6.39.1/drivers/mmc/host/sdhci-of.h
33948--- linux-2.6.39.1/drivers/mmc/host/sdhci-of.h 2011-05-19 00:06:34.000000000 -0400
33949+++ linux-2.6.39.1/drivers/mmc/host/sdhci-of.h 2011-05-22 19:36:31.000000000 -0400
33950@@ -21,7 +21,7 @@
33951
33952 struct sdhci_of_data {
33953 unsigned int quirks;
33954- struct sdhci_ops ops;
33955+ const struct sdhci_ops ops;
33956 };
33957
33958 struct sdhci_of_host {
33959diff -urNp linux-2.6.39.1/drivers/mmc/host/sdhci-pci.c linux-2.6.39.1/drivers/mmc/host/sdhci-pci.c
33960--- linux-2.6.39.1/drivers/mmc/host/sdhci-pci.c 2011-05-19 00:06:34.000000000 -0400
33961+++ linux-2.6.39.1/drivers/mmc/host/sdhci-pci.c 2011-05-22 19:36:31.000000000 -0400
33962@@ -786,7 +786,7 @@ static int sdhci_pci_enable_dma(struct s
33963 return 0;
33964 }
33965
33966-static struct sdhci_ops sdhci_pci_ops = {
33967+static const struct sdhci_ops sdhci_pci_ops = {
33968 .enable_dma = sdhci_pci_enable_dma,
33969 };
33970
33971diff -urNp linux-2.6.39.1/drivers/mmc/host/sdhci-pltfm.c linux-2.6.39.1/drivers/mmc/host/sdhci-pltfm.c
33972--- linux-2.6.39.1/drivers/mmc/host/sdhci-pltfm.c 2011-05-19 00:06:34.000000000 -0400
33973+++ linux-2.6.39.1/drivers/mmc/host/sdhci-pltfm.c 2011-05-22 19:36:31.000000000 -0400
33974@@ -41,7 +41,7 @@
33975 * *
33976 \*****************************************************************************/
33977
33978-static struct sdhci_ops sdhci_pltfm_ops = {
33979+static const struct sdhci_ops sdhci_pltfm_ops = {
33980 };
33981
33982 /*****************************************************************************\
33983diff -urNp linux-2.6.39.1/drivers/mmc/host/sdhci-pxa.c linux-2.6.39.1/drivers/mmc/host/sdhci-pxa.c
33984--- linux-2.6.39.1/drivers/mmc/host/sdhci-pxa.c 2011-05-19 00:06:34.000000000 -0400
33985+++ linux-2.6.39.1/drivers/mmc/host/sdhci-pxa.c 2011-05-22 19:36:31.000000000 -0400
33986@@ -69,7 +69,7 @@ static void set_clock(struct sdhci_host
33987 }
33988 }
33989
33990-static struct sdhci_ops sdhci_pxa_ops = {
33991+static const struct sdhci_ops sdhci_pxa_ops = {
33992 .set_clock = set_clock,
33993 };
33994
33995diff -urNp linux-2.6.39.1/drivers/mmc/host/sdhci-s3c.c linux-2.6.39.1/drivers/mmc/host/sdhci-s3c.c
33996--- linux-2.6.39.1/drivers/mmc/host/sdhci-s3c.c 2011-05-19 00:06:34.000000000 -0400
33997+++ linux-2.6.39.1/drivers/mmc/host/sdhci-s3c.c 2011-05-22 19:36:31.000000000 -0400
33998@@ -309,7 +309,7 @@ static int sdhci_s3c_platform_8bit_width
33999 return 0;
34000 }
34001
34002-static struct sdhci_ops sdhci_s3c_ops = {
34003+static const struct sdhci_ops sdhci_s3c_ops = {
34004 .get_max_clock = sdhci_s3c_get_max_clk,
34005 .set_clock = sdhci_s3c_set_clock,
34006 .get_min_clock = sdhci_s3c_get_min_clock,
34007diff -urNp linux-2.6.39.1/drivers/mmc/host/sdhci-spear.c linux-2.6.39.1/drivers/mmc/host/sdhci-spear.c
34008--- linux-2.6.39.1/drivers/mmc/host/sdhci-spear.c 2011-05-19 00:06:34.000000000 -0400
34009+++ linux-2.6.39.1/drivers/mmc/host/sdhci-spear.c 2011-05-22 19:36:31.000000000 -0400
34010@@ -32,7 +32,7 @@ struct spear_sdhci {
34011 };
34012
34013 /* sdhci ops */
34014-static struct sdhci_ops sdhci_pltfm_ops = {
34015+static const struct sdhci_ops sdhci_pltfm_ops = {
34016 /* Nothing to do for now. */
34017 };
34018
34019diff -urNp linux-2.6.39.1/drivers/mmc/host/sdhci-tegra.c linux-2.6.39.1/drivers/mmc/host/sdhci-tegra.c
34020--- linux-2.6.39.1/drivers/mmc/host/sdhci-tegra.c 2011-05-19 00:06:34.000000000 -0400
34021+++ linux-2.6.39.1/drivers/mmc/host/sdhci-tegra.c 2011-05-22 19:36:31.000000000 -0400
34022@@ -242,7 +242,7 @@ static void tegra_sdhci_pltfm_exit(struc
34023 clk_put(pltfm_host->clk);
34024 }
34025
34026-static struct sdhci_ops tegra_sdhci_ops = {
34027+static const struct sdhci_ops tegra_sdhci_ops = {
34028 .get_ro = tegra_sdhci_get_ro,
34029 .read_l = tegra_sdhci_readl,
34030 .read_w = tegra_sdhci_readw,
34031diff -urNp linux-2.6.39.1/drivers/mmc/host/sdricoh_cs.c linux-2.6.39.1/drivers/mmc/host/sdricoh_cs.c
34032--- linux-2.6.39.1/drivers/mmc/host/sdricoh_cs.c 2011-05-19 00:06:34.000000000 -0400
34033+++ linux-2.6.39.1/drivers/mmc/host/sdricoh_cs.c 2011-05-22 19:36:31.000000000 -0400
34034@@ -387,7 +387,7 @@ static int sdricoh_get_ro(struct mmc_hos
34035 return (status & STATUS_CARD_LOCKED);
34036 }
34037
34038-static struct mmc_host_ops sdricoh_ops = {
34039+static const struct mmc_host_ops sdricoh_ops = {
34040 .request = sdricoh_request,
34041 .set_ios = sdricoh_set_ios,
34042 .get_ro = sdricoh_get_ro,
34043diff -urNp linux-2.6.39.1/drivers/mmc/host/sh_mmcif.c linux-2.6.39.1/drivers/mmc/host/sh_mmcif.c
34044--- linux-2.6.39.1/drivers/mmc/host/sh_mmcif.c 2011-05-19 00:06:34.000000000 -0400
34045+++ linux-2.6.39.1/drivers/mmc/host/sh_mmcif.c 2011-05-22 19:36:31.000000000 -0400
34046@@ -872,7 +872,7 @@ static int sh_mmcif_get_cd(struct mmc_ho
34047 return p->get_cd(host->pd);
34048 }
34049
34050-static struct mmc_host_ops sh_mmcif_ops = {
34051+static const struct mmc_host_ops sh_mmcif_ops = {
34052 .request = sh_mmcif_request,
34053 .set_ios = sh_mmcif_set_ios,
34054 .get_cd = sh_mmcif_get_cd,
34055diff -urNp linux-2.6.39.1/drivers/mtd/chips/cfi_cmdset_0001.c linux-2.6.39.1/drivers/mtd/chips/cfi_cmdset_0001.c
34056--- linux-2.6.39.1/drivers/mtd/chips/cfi_cmdset_0001.c 2011-05-19 00:06:34.000000000 -0400
34057+++ linux-2.6.39.1/drivers/mtd/chips/cfi_cmdset_0001.c 2011-05-22 19:36:31.000000000 -0400
34058@@ -757,6 +757,8 @@ static int chip_ready (struct map_info *
34059 struct cfi_pri_intelext *cfip = cfi->cmdset_priv;
34060 unsigned long timeo = jiffies + HZ;
34061
34062+ pax_track_stack();
34063+
34064 /* Prevent setting state FL_SYNCING for chip in suspended state. */
34065 if (mode == FL_SYNCING && chip->oldstate != FL_READY)
34066 goto sleep;
34067@@ -1657,6 +1659,8 @@ static int __xipram do_write_buffer(stru
34068 unsigned long initial_adr;
34069 int initial_len = len;
34070
34071+ pax_track_stack();
34072+
34073 wbufsize = cfi_interleave(cfi) << cfi->cfiq->MaxBufWriteSize;
34074 adr += chip->start;
34075 initial_adr = adr;
34076@@ -1875,6 +1879,8 @@ static int __xipram do_erase_oneblock(st
34077 int retries = 3;
34078 int ret;
34079
34080+ pax_track_stack();
34081+
34082 adr += chip->start;
34083
34084 retry:
34085diff -urNp linux-2.6.39.1/drivers/mtd/chips/cfi_cmdset_0020.c linux-2.6.39.1/drivers/mtd/chips/cfi_cmdset_0020.c
34086--- linux-2.6.39.1/drivers/mtd/chips/cfi_cmdset_0020.c 2011-05-19 00:06:34.000000000 -0400
34087+++ linux-2.6.39.1/drivers/mtd/chips/cfi_cmdset_0020.c 2011-05-22 19:36:31.000000000 -0400
34088@@ -255,6 +255,8 @@ static inline int do_read_onechip(struct
34089 unsigned long cmd_addr;
34090 struct cfi_private *cfi = map->fldrv_priv;
34091
34092+ pax_track_stack();
34093+
34094 adr += chip->start;
34095
34096 /* Ensure cmd read/writes are aligned. */
34097@@ -428,6 +430,8 @@ static inline int do_write_buffer(struct
34098 DECLARE_WAITQUEUE(wait, current);
34099 int wbufsize, z;
34100
34101+ pax_track_stack();
34102+
34103 /* M58LW064A requires bus alignment for buffer wriets -- saw */
34104 if (adr & (map_bankwidth(map)-1))
34105 return -EINVAL;
34106@@ -742,6 +746,8 @@ static inline int do_erase_oneblock(stru
34107 DECLARE_WAITQUEUE(wait, current);
34108 int ret = 0;
34109
34110+ pax_track_stack();
34111+
34112 adr += chip->start;
34113
34114 /* Let's determine this according to the interleave only once */
34115@@ -1047,6 +1053,8 @@ static inline int do_lock_oneblock(struc
34116 unsigned long timeo = jiffies + HZ;
34117 DECLARE_WAITQUEUE(wait, current);
34118
34119+ pax_track_stack();
34120+
34121 adr += chip->start;
34122
34123 /* Let's determine this according to the interleave only once */
34124@@ -1196,6 +1204,8 @@ static inline int do_unlock_oneblock(str
34125 unsigned long timeo = jiffies + HZ;
34126 DECLARE_WAITQUEUE(wait, current);
34127
34128+ pax_track_stack();
34129+
34130 adr += chip->start;
34131
34132 /* Let's determine this according to the interleave only once */
34133diff -urNp linux-2.6.39.1/drivers/mtd/devices/doc2000.c linux-2.6.39.1/drivers/mtd/devices/doc2000.c
34134--- linux-2.6.39.1/drivers/mtd/devices/doc2000.c 2011-05-19 00:06:34.000000000 -0400
34135+++ linux-2.6.39.1/drivers/mtd/devices/doc2000.c 2011-05-22 19:36:31.000000000 -0400
34136@@ -776,7 +776,7 @@ static int doc_write(struct mtd_info *mt
34137
34138 /* The ECC will not be calculated correctly if less than 512 is written */
34139 /* DBB-
34140- if (len != 0x200 && eccbuf)
34141+ if (len != 0x200)
34142 printk(KERN_WARNING
34143 "ECC needs a full sector write (adr: %lx size %lx)\n",
34144 (long) to, (long) len);
34145diff -urNp linux-2.6.39.1/drivers/mtd/devices/doc2001.c linux-2.6.39.1/drivers/mtd/devices/doc2001.c
34146--- linux-2.6.39.1/drivers/mtd/devices/doc2001.c 2011-05-19 00:06:34.000000000 -0400
34147+++ linux-2.6.39.1/drivers/mtd/devices/doc2001.c 2011-05-22 19:36:31.000000000 -0400
34148@@ -393,7 +393,7 @@ static int doc_read (struct mtd_info *mt
34149 struct Nand *mychip = &this->chips[from >> (this->chipshift)];
34150
34151 /* Don't allow read past end of device */
34152- if (from >= this->totlen)
34153+ if (from >= this->totlen || !len)
34154 return -EINVAL;
34155
34156 /* Don't allow a single read to cross a 512-byte block boundary */
34157diff -urNp linux-2.6.39.1/drivers/mtd/ftl.c linux-2.6.39.1/drivers/mtd/ftl.c
34158--- linux-2.6.39.1/drivers/mtd/ftl.c 2011-05-19 00:06:34.000000000 -0400
34159+++ linux-2.6.39.1/drivers/mtd/ftl.c 2011-05-22 19:36:31.000000000 -0400
34160@@ -474,6 +474,8 @@ static int copy_erase_unit(partition_t *
34161 loff_t offset;
34162 uint16_t srcunitswap = cpu_to_le16(srcunit);
34163
34164+ pax_track_stack();
34165+
34166 eun = &part->EUNInfo[srcunit];
34167 xfer = &part->XferInfo[xferunit];
34168 DEBUG(2, "ftl_cs: copying block 0x%x to 0x%x\n",
34169diff -urNp linux-2.6.39.1/drivers/mtd/inftlcore.c linux-2.6.39.1/drivers/mtd/inftlcore.c
34170--- linux-2.6.39.1/drivers/mtd/inftlcore.c 2011-05-19 00:06:34.000000000 -0400
34171+++ linux-2.6.39.1/drivers/mtd/inftlcore.c 2011-05-22 19:36:31.000000000 -0400
34172@@ -259,6 +259,8 @@ static u16 INFTL_foldchain(struct INFTLr
34173 struct inftl_oob oob;
34174 size_t retlen;
34175
34176+ pax_track_stack();
34177+
34178 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: INFTL_foldchain(inftl=%p,thisVUC=%d,"
34179 "pending=%d)\n", inftl, thisVUC, pendingblock);
34180
34181diff -urNp linux-2.6.39.1/drivers/mtd/inftlmount.c linux-2.6.39.1/drivers/mtd/inftlmount.c
34182--- linux-2.6.39.1/drivers/mtd/inftlmount.c 2011-05-19 00:06:34.000000000 -0400
34183+++ linux-2.6.39.1/drivers/mtd/inftlmount.c 2011-05-22 19:36:31.000000000 -0400
34184@@ -53,6 +53,8 @@ static int find_boot_record(struct INFTL
34185 struct INFTLPartition *ip;
34186 size_t retlen;
34187
34188+ pax_track_stack();
34189+
34190 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: find_boot_record(inftl=%p)\n", inftl);
34191
34192 /*
34193diff -urNp linux-2.6.39.1/drivers/mtd/lpddr/qinfo_probe.c linux-2.6.39.1/drivers/mtd/lpddr/qinfo_probe.c
34194--- linux-2.6.39.1/drivers/mtd/lpddr/qinfo_probe.c 2011-05-19 00:06:34.000000000 -0400
34195+++ linux-2.6.39.1/drivers/mtd/lpddr/qinfo_probe.c 2011-05-22 19:36:31.000000000 -0400
34196@@ -106,6 +106,8 @@ static int lpddr_pfow_present(struct map
34197 {
34198 map_word pfow_val[4];
34199
34200+ pax_track_stack();
34201+
34202 /* Check identification string */
34203 pfow_val[0] = map_read(map, map->pfow_base + PFOW_QUERY_STRING_P);
34204 pfow_val[1] = map_read(map, map->pfow_base + PFOW_QUERY_STRING_F);
34205diff -urNp linux-2.6.39.1/drivers/mtd/mtdchar.c linux-2.6.39.1/drivers/mtd/mtdchar.c
34206--- linux-2.6.39.1/drivers/mtd/mtdchar.c 2011-05-19 00:06:34.000000000 -0400
34207+++ linux-2.6.39.1/drivers/mtd/mtdchar.c 2011-05-22 19:36:31.000000000 -0400
34208@@ -560,6 +560,8 @@ static int mtd_ioctl(struct file *file,
34209 u_long size;
34210 struct mtd_info_user info;
34211
34212+ pax_track_stack();
34213+
34214 DEBUG(MTD_DEBUG_LEVEL0, "MTD_ioctl\n");
34215
34216 size = (cmd & IOCSIZE_MASK) >> IOCSIZE_SHIFT;
34217diff -urNp linux-2.6.39.1/drivers/mtd/nand/denali.c linux-2.6.39.1/drivers/mtd/nand/denali.c
34218--- linux-2.6.39.1/drivers/mtd/nand/denali.c 2011-05-19 00:06:34.000000000 -0400
34219+++ linux-2.6.39.1/drivers/mtd/nand/denali.c 2011-05-22 19:36:31.000000000 -0400
34220@@ -25,6 +25,7 @@
34221 #include <linux/pci.h>
34222 #include <linux/mtd/mtd.h>
34223 #include <linux/module.h>
34224+#include <linux/slab.h>
34225
34226 #include "denali.h"
34227
34228diff -urNp linux-2.6.39.1/drivers/mtd/nftlcore.c linux-2.6.39.1/drivers/mtd/nftlcore.c
34229--- linux-2.6.39.1/drivers/mtd/nftlcore.c 2011-05-19 00:06:34.000000000 -0400
34230+++ linux-2.6.39.1/drivers/mtd/nftlcore.c 2011-05-22 19:36:31.000000000 -0400
34231@@ -264,6 +264,8 @@ static u16 NFTL_foldchain (struct NFTLre
34232 int inplace = 1;
34233 size_t retlen;
34234
34235+ pax_track_stack();
34236+
34237 memset(BlockMap, 0xff, sizeof(BlockMap));
34238 memset(BlockFreeFound, 0, sizeof(BlockFreeFound));
34239
34240diff -urNp linux-2.6.39.1/drivers/mtd/nftlmount.c linux-2.6.39.1/drivers/mtd/nftlmount.c
34241--- linux-2.6.39.1/drivers/mtd/nftlmount.c 2011-05-19 00:06:34.000000000 -0400
34242+++ linux-2.6.39.1/drivers/mtd/nftlmount.c 2011-05-22 19:36:31.000000000 -0400
34243@@ -24,6 +24,7 @@
34244 #include <asm/errno.h>
34245 #include <linux/delay.h>
34246 #include <linux/slab.h>
34247+#include <linux/sched.h>
34248 #include <linux/mtd/mtd.h>
34249 #include <linux/mtd/nand.h>
34250 #include <linux/mtd/nftl.h>
34251@@ -45,6 +46,8 @@ static int find_boot_record(struct NFTLr
34252 struct mtd_info *mtd = nftl->mbd.mtd;
34253 unsigned int i;
34254
34255+ pax_track_stack();
34256+
34257 /* Assume logical EraseSize == physical erasesize for starting the scan.
34258 We'll sort it out later if we find a MediaHeader which says otherwise */
34259 /* Actually, we won't. The new DiskOnChip driver has already scanned
34260diff -urNp linux-2.6.39.1/drivers/mtd/ubi/build.c linux-2.6.39.1/drivers/mtd/ubi/build.c
34261--- linux-2.6.39.1/drivers/mtd/ubi/build.c 2011-05-19 00:06:34.000000000 -0400
34262+++ linux-2.6.39.1/drivers/mtd/ubi/build.c 2011-05-22 19:36:31.000000000 -0400
34263@@ -1287,7 +1287,7 @@ module_exit(ubi_exit);
34264 static int __init bytes_str_to_int(const char *str)
34265 {
34266 char *endp;
34267- unsigned long result;
34268+ unsigned long result, scale = 1;
34269
34270 result = simple_strtoul(str, &endp, 0);
34271 if (str == endp || result >= INT_MAX) {
34272@@ -1298,11 +1298,11 @@ static int __init bytes_str_to_int(const
34273
34274 switch (*endp) {
34275 case 'G':
34276- result *= 1024;
34277+ scale *= 1024;
34278 case 'M':
34279- result *= 1024;
34280+ scale *= 1024;
34281 case 'K':
34282- result *= 1024;
34283+ scale *= 1024;
34284 if (endp[1] == 'i' && endp[2] == 'B')
34285 endp += 2;
34286 case '\0':
34287@@ -1313,7 +1313,13 @@ static int __init bytes_str_to_int(const
34288 return -EINVAL;
34289 }
34290
34291- return result;
34292+ if ((intoverflow_t)result*scale >= INT_MAX) {
34293+ printk(KERN_ERR "UBI error: incorrect bytes count: \"%s\"\n",
34294+ str);
34295+ return -EINVAL;
34296+ }
34297+
34298+ return result*scale;
34299 }
34300
34301 /**
34302diff -urNp linux-2.6.39.1/drivers/net/bcm63xx_enet.c linux-2.6.39.1/drivers/net/bcm63xx_enet.c
34303--- linux-2.6.39.1/drivers/net/bcm63xx_enet.c 2011-05-19 00:06:34.000000000 -0400
34304+++ linux-2.6.39.1/drivers/net/bcm63xx_enet.c 2011-05-22 19:36:31.000000000 -0400
34305@@ -1469,7 +1469,7 @@ static int bcm_enet_set_pauseparam(struc
34306 return 0;
34307 }
34308
34309-static struct ethtool_ops bcm_enet_ethtool_ops = {
34310+static const struct ethtool_ops bcm_enet_ethtool_ops = {
34311 .get_strings = bcm_enet_get_strings,
34312 .get_sset_count = bcm_enet_get_sset_count,
34313 .get_ethtool_stats = bcm_enet_get_ethtool_stats,
34314diff -urNp linux-2.6.39.1/drivers/net/bna/bnad_ethtool.c linux-2.6.39.1/drivers/net/bna/bnad_ethtool.c
34315--- linux-2.6.39.1/drivers/net/bna/bnad_ethtool.c 2011-05-19 00:06:34.000000000 -0400
34316+++ linux-2.6.39.1/drivers/net/bna/bnad_ethtool.c 2011-05-22 19:36:31.000000000 -0400
34317@@ -1242,7 +1242,7 @@ bnad_get_sset_count(struct net_device *n
34318 }
34319 }
34320
34321-static struct ethtool_ops bnad_ethtool_ops = {
34322+static const struct ethtool_ops bnad_ethtool_ops = {
34323 .get_settings = bnad_get_settings,
34324 .set_settings = bnad_set_settings,
34325 .get_drvinfo = bnad_get_drvinfo,
34326diff -urNp linux-2.6.39.1/drivers/net/bnx2.c linux-2.6.39.1/drivers/net/bnx2.c
34327--- linux-2.6.39.1/drivers/net/bnx2.c 2011-05-19 00:06:34.000000000 -0400
34328+++ linux-2.6.39.1/drivers/net/bnx2.c 2011-05-22 19:36:31.000000000 -0400
34329@@ -5828,6 +5828,8 @@ bnx2_test_nvram(struct bnx2 *bp)
34330 int rc = 0;
34331 u32 magic, csum;
34332
34333+ pax_track_stack();
34334+
34335 if ((rc = bnx2_nvram_read(bp, 0, data, 4)) != 0)
34336 goto test_nvram_done;
34337
34338diff -urNp linux-2.6.39.1/drivers/net/bnx2x/bnx2x_ethtool.c linux-2.6.39.1/drivers/net/bnx2x/bnx2x_ethtool.c
34339--- linux-2.6.39.1/drivers/net/bnx2x/bnx2x_ethtool.c 2011-05-19 00:06:34.000000000 -0400
34340+++ linux-2.6.39.1/drivers/net/bnx2x/bnx2x_ethtool.c 2011-05-22 19:36:31.000000000 -0400
34341@@ -1788,6 +1788,8 @@ static int bnx2x_test_nvram(struct bnx2x
34342 int i, rc;
34343 u32 magic, crc;
34344
34345+ pax_track_stack();
34346+
34347 if (BP_NOMCP(bp))
34348 return 0;
34349
34350diff -urNp linux-2.6.39.1/drivers/net/chelsio/pm3393.c linux-2.6.39.1/drivers/net/chelsio/pm3393.c
34351--- linux-2.6.39.1/drivers/net/chelsio/pm3393.c 2011-05-19 00:06:34.000000000 -0400
34352+++ linux-2.6.39.1/drivers/net/chelsio/pm3393.c 2011-05-22 19:36:31.000000000 -0400
34353@@ -571,7 +571,7 @@ static void pm3393_destroy(struct cmac *
34354 kfree(cmac);
34355 }
34356
34357-static struct cmac_ops pm3393_ops = {
34358+static const struct cmac_ops pm3393_ops = {
34359 .destroy = pm3393_destroy,
34360 .reset = pm3393_reset,
34361 .interrupt_enable = pm3393_interrupt_enable,
34362diff -urNp linux-2.6.39.1/drivers/net/chelsio/vsc7326.c linux-2.6.39.1/drivers/net/chelsio/vsc7326.c
34363--- linux-2.6.39.1/drivers/net/chelsio/vsc7326.c 2011-05-19 00:06:34.000000000 -0400
34364+++ linux-2.6.39.1/drivers/net/chelsio/vsc7326.c 2011-05-22 19:36:31.000000000 -0400
34365@@ -666,7 +666,7 @@ static void mac_destroy(struct cmac *mac
34366 kfree(mac);
34367 }
34368
34369-static struct cmac_ops vsc7326_ops = {
34370+static const struct cmac_ops vsc7326_ops = {
34371 .destroy = mac_destroy,
34372 .reset = mac_reset,
34373 .interrupt_handler = mac_intr_handler,
34374diff -urNp linux-2.6.39.1/drivers/net/cxgb4/cxgb4_main.c linux-2.6.39.1/drivers/net/cxgb4/cxgb4_main.c
34375--- linux-2.6.39.1/drivers/net/cxgb4/cxgb4_main.c 2011-05-19 00:06:34.000000000 -0400
34376+++ linux-2.6.39.1/drivers/net/cxgb4/cxgb4_main.c 2011-05-22 19:36:31.000000000 -0400
34377@@ -3428,6 +3428,8 @@ static int __devinit enable_msix(struct
34378 unsigned int nchan = adap->params.nports;
34379 struct msix_entry entries[MAX_INGQ + 1];
34380
34381+ pax_track_stack();
34382+
34383 for (i = 0; i < ARRAY_SIZE(entries); ++i)
34384 entries[i].entry = i;
34385
34386diff -urNp linux-2.6.39.1/drivers/net/cxgb4/t4_hw.c linux-2.6.39.1/drivers/net/cxgb4/t4_hw.c
34387--- linux-2.6.39.1/drivers/net/cxgb4/t4_hw.c 2011-05-19 00:06:34.000000000 -0400
34388+++ linux-2.6.39.1/drivers/net/cxgb4/t4_hw.c 2011-05-22 19:36:31.000000000 -0400
34389@@ -362,6 +362,8 @@ static int get_vpd_params(struct adapter
34390 u8 vpd[VPD_LEN], csum;
34391 unsigned int vpdr_len, kw_offset, id_len;
34392
34393+ pax_track_stack();
34394+
34395 ret = pci_read_vpd(adapter->pdev, VPD_BASE, sizeof(vpd), vpd);
34396 if (ret < 0)
34397 return ret;
34398diff -urNp linux-2.6.39.1/drivers/net/cxgb4vf/cxgb4vf_main.c linux-2.6.39.1/drivers/net/cxgb4vf/cxgb4vf_main.c
34399--- linux-2.6.39.1/drivers/net/cxgb4vf/cxgb4vf_main.c 2011-05-19 00:06:34.000000000 -0400
34400+++ linux-2.6.39.1/drivers/net/cxgb4vf/cxgb4vf_main.c 2011-05-22 19:36:31.000000000 -0400
34401@@ -1572,7 +1572,7 @@ static int cxgb4vf_set_tso(struct net_de
34402 return 0;
34403 }
34404
34405-static struct ethtool_ops cxgb4vf_ethtool_ops = {
34406+static const struct ethtool_ops cxgb4vf_ethtool_ops = {
34407 .get_settings = cxgb4vf_get_settings,
34408 .get_drvinfo = cxgb4vf_get_drvinfo,
34409 .get_msglevel = cxgb4vf_get_msglevel,
34410diff -urNp linux-2.6.39.1/drivers/net/e1000e/82571.c linux-2.6.39.1/drivers/net/e1000e/82571.c
34411--- linux-2.6.39.1/drivers/net/e1000e/82571.c 2011-05-19 00:06:34.000000000 -0400
34412+++ linux-2.6.39.1/drivers/net/e1000e/82571.c 2011-05-22 19:36:31.000000000 -0400
34413@@ -239,7 +239,7 @@ static s32 e1000_init_mac_params_82571(s
34414 {
34415 struct e1000_hw *hw = &adapter->hw;
34416 struct e1000_mac_info *mac = &hw->mac;
34417- struct e1000_mac_operations *func = &mac->ops;
34418+ struct e1000_mac_operations *func = &mac->ops; /* cannot be const */
34419 u32 swsm = 0;
34420 u32 swsm2 = 0;
34421 bool force_clear_smbi = false;
34422@@ -1930,7 +1930,7 @@ static void e1000_clear_hw_cntrs_82571(s
34423 er32(ICRXDMTC);
34424 }
34425
34426-static struct e1000_mac_operations e82571_mac_ops = {
34427+static const struct e1000_mac_operations e82571_mac_ops = {
34428 /* .check_mng_mode: mac type dependent */
34429 /* .check_for_link: media type dependent */
34430 .id_led_init = e1000e_id_led_init,
34431@@ -1952,7 +1952,7 @@ static struct e1000_mac_operations e8257
34432 .read_mac_addr = e1000_read_mac_addr_82571,
34433 };
34434
34435-static struct e1000_phy_operations e82_phy_ops_igp = {
34436+static const struct e1000_phy_operations e82_phy_ops_igp = {
34437 .acquire = e1000_get_hw_semaphore_82571,
34438 .check_polarity = e1000_check_polarity_igp,
34439 .check_reset_block = e1000e_check_reset_block_generic,
34440@@ -1970,7 +1970,7 @@ static struct e1000_phy_operations e82_p
34441 .cfg_on_link_up = NULL,
34442 };
34443
34444-static struct e1000_phy_operations e82_phy_ops_m88 = {
34445+static const struct e1000_phy_operations e82_phy_ops_m88 = {
34446 .acquire = e1000_get_hw_semaphore_82571,
34447 .check_polarity = e1000_check_polarity_m88,
34448 .check_reset_block = e1000e_check_reset_block_generic,
34449@@ -1988,7 +1988,7 @@ static struct e1000_phy_operations e82_p
34450 .cfg_on_link_up = NULL,
34451 };
34452
34453-static struct e1000_phy_operations e82_phy_ops_bm = {
34454+static const struct e1000_phy_operations e82_phy_ops_bm = {
34455 .acquire = e1000_get_hw_semaphore_82571,
34456 .check_polarity = e1000_check_polarity_m88,
34457 .check_reset_block = e1000e_check_reset_block_generic,
34458@@ -2006,7 +2006,7 @@ static struct e1000_phy_operations e82_p
34459 .cfg_on_link_up = NULL,
34460 };
34461
34462-static struct e1000_nvm_operations e82571_nvm_ops = {
34463+static const struct e1000_nvm_operations e82571_nvm_ops = {
34464 .acquire = e1000_acquire_nvm_82571,
34465 .read = e1000e_read_nvm_eerd,
34466 .release = e1000_release_nvm_82571,
34467diff -urNp linux-2.6.39.1/drivers/net/e1000e/e1000.h linux-2.6.39.1/drivers/net/e1000e/e1000.h
34468--- linux-2.6.39.1/drivers/net/e1000e/e1000.h 2011-05-19 00:06:34.000000000 -0400
34469+++ linux-2.6.39.1/drivers/net/e1000e/e1000.h 2011-05-22 19:36:31.000000000 -0400
34470@@ -409,9 +409,9 @@ struct e1000_info {
34471 u32 pba;
34472 u32 max_hw_frame_size;
34473 s32 (*get_variants)(struct e1000_adapter *);
34474- struct e1000_mac_operations *mac_ops;
34475- struct e1000_phy_operations *phy_ops;
34476- struct e1000_nvm_operations *nvm_ops;
34477+ const struct e1000_mac_operations *mac_ops;
34478+ const struct e1000_phy_operations *phy_ops;
34479+ const struct e1000_nvm_operations *nvm_ops;
34480 };
34481
34482 /* hardware capability, feature, and workaround flags */
34483diff -urNp linux-2.6.39.1/drivers/net/e1000e/es2lan.c linux-2.6.39.1/drivers/net/e1000e/es2lan.c
34484--- linux-2.6.39.1/drivers/net/e1000e/es2lan.c 2011-05-19 00:06:34.000000000 -0400
34485+++ linux-2.6.39.1/drivers/net/e1000e/es2lan.c 2011-05-22 19:36:31.000000000 -0400
34486@@ -205,7 +205,7 @@ static s32 e1000_init_mac_params_80003es
34487 {
34488 struct e1000_hw *hw = &adapter->hw;
34489 struct e1000_mac_info *mac = &hw->mac;
34490- struct e1000_mac_operations *func = &mac->ops;
34491+ struct e1000_mac_operations *func = &mac->ops; /* cannot be const */
34492
34493 /* Set media type */
34494 switch (adapter->pdev->device) {
34495@@ -1431,7 +1431,7 @@ static void e1000_clear_hw_cntrs_80003es
34496 er32(ICRXDMTC);
34497 }
34498
34499-static struct e1000_mac_operations es2_mac_ops = {
34500+static const struct e1000_mac_operations es2_mac_ops = {
34501 .read_mac_addr = e1000_read_mac_addr_80003es2lan,
34502 .id_led_init = e1000e_id_led_init,
34503 .check_mng_mode = e1000e_check_mng_mode_generic,
34504@@ -1453,7 +1453,7 @@ static struct e1000_mac_operations es2_m
34505 .setup_led = e1000e_setup_led_generic,
34506 };
34507
34508-static struct e1000_phy_operations es2_phy_ops = {
34509+static const struct e1000_phy_operations es2_phy_ops = {
34510 .acquire = e1000_acquire_phy_80003es2lan,
34511 .check_polarity = e1000_check_polarity_m88,
34512 .check_reset_block = e1000e_check_reset_block_generic,
34513@@ -1471,7 +1471,7 @@ static struct e1000_phy_operations es2_p
34514 .cfg_on_link_up = e1000_cfg_on_link_up_80003es2lan,
34515 };
34516
34517-static struct e1000_nvm_operations es2_nvm_ops = {
34518+static const struct e1000_nvm_operations es2_nvm_ops = {
34519 .acquire = e1000_acquire_nvm_80003es2lan,
34520 .read = e1000e_read_nvm_eerd,
34521 .release = e1000_release_nvm_80003es2lan,
34522diff -urNp linux-2.6.39.1/drivers/net/e1000e/hw.h linux-2.6.39.1/drivers/net/e1000e/hw.h
34523--- linux-2.6.39.1/drivers/net/e1000e/hw.h 2011-05-19 00:06:34.000000000 -0400
34524+++ linux-2.6.39.1/drivers/net/e1000e/hw.h 2011-05-22 19:36:31.000000000 -0400
34525@@ -811,6 +811,7 @@ struct e1000_nvm_operations {
34526 };
34527
34528 struct e1000_mac_info {
34529+ /* cannot be const see e1000_init_mac_params_ich8lan */
34530 struct e1000_mac_operations ops;
34531 u8 addr[ETH_ALEN];
34532 u8 perm_addr[ETH_ALEN];
34533@@ -852,6 +853,7 @@ struct e1000_mac_info {
34534 };
34535
34536 struct e1000_phy_info {
34537+ /* Cannot be const see e1000_init_phy_params_82571() */
34538 struct e1000_phy_operations ops;
34539
34540 enum e1000_phy_type type;
34541@@ -886,6 +888,7 @@ struct e1000_phy_info {
34542 };
34543
34544 struct e1000_nvm_info {
34545+ /* cannot be const */
34546 struct e1000_nvm_operations ops;
34547
34548 enum e1000_nvm_type type;
34549diff -urNp linux-2.6.39.1/drivers/net/e1000e/ich8lan.c linux-2.6.39.1/drivers/net/e1000e/ich8lan.c
34550--- linux-2.6.39.1/drivers/net/e1000e/ich8lan.c 2011-05-19 00:06:34.000000000 -0400
34551+++ linux-2.6.39.1/drivers/net/e1000e/ich8lan.c 2011-05-22 19:36:31.000000000 -0400
34552@@ -3866,7 +3866,7 @@ static void e1000_clear_hw_cntrs_ich8lan
34553 }
34554 }
34555
34556-static struct e1000_mac_operations ich8_mac_ops = {
34557+static const struct e1000_mac_operations ich8_mac_ops = {
34558 .id_led_init = e1000e_id_led_init,
34559 /* check_mng_mode dependent on mac type */
34560 .check_for_link = e1000_check_for_copper_link_ich8lan,
34561@@ -3885,7 +3885,7 @@ static struct e1000_mac_operations ich8_
34562 /* id_led_init dependent on mac type */
34563 };
34564
34565-static struct e1000_phy_operations ich8_phy_ops = {
34566+static const struct e1000_phy_operations ich8_phy_ops = {
34567 .acquire = e1000_acquire_swflag_ich8lan,
34568 .check_reset_block = e1000_check_reset_block_ich8lan,
34569 .commit = NULL,
34570@@ -3899,7 +3899,7 @@ static struct e1000_phy_operations ich8_
34571 .write_reg = e1000e_write_phy_reg_igp,
34572 };
34573
34574-static struct e1000_nvm_operations ich8_nvm_ops = {
34575+static const struct e1000_nvm_operations ich8_nvm_ops = {
34576 .acquire = e1000_acquire_nvm_ich8lan,
34577 .read = e1000_read_nvm_ich8lan,
34578 .release = e1000_release_nvm_ich8lan,
34579diff -urNp linux-2.6.39.1/drivers/net/greth.c linux-2.6.39.1/drivers/net/greth.c
34580--- linux-2.6.39.1/drivers/net/greth.c 2011-05-19 00:06:34.000000000 -0400
34581+++ linux-2.6.39.1/drivers/net/greth.c 2011-05-22 19:36:31.000000000 -0400
34582@@ -1192,7 +1192,7 @@ static const struct ethtool_ops greth_et
34583 .get_link = ethtool_op_get_link,
34584 };
34585
34586-static struct net_device_ops greth_netdev_ops = {
34587+static const struct net_device_ops greth_netdev_ops = {
34588 .ndo_open = greth_open,
34589 .ndo_stop = greth_close,
34590 .ndo_start_xmit = greth_start_xmit,
34591diff -urNp linux-2.6.39.1/drivers/net/hamradio/6pack.c linux-2.6.39.1/drivers/net/hamradio/6pack.c
34592--- linux-2.6.39.1/drivers/net/hamradio/6pack.c 2011-05-19 00:06:34.000000000 -0400
34593+++ linux-2.6.39.1/drivers/net/hamradio/6pack.c 2011-05-22 19:36:31.000000000 -0400
34594@@ -463,6 +463,8 @@ static void sixpack_receive_buf(struct t
34595 unsigned char buf[512];
34596 int count1;
34597
34598+ pax_track_stack();
34599+
34600 if (!count)
34601 return;
34602
34603diff -urNp linux-2.6.39.1/drivers/net/ibm_newemac/phy.c linux-2.6.39.1/drivers/net/ibm_newemac/phy.c
34604--- linux-2.6.39.1/drivers/net/ibm_newemac/phy.c 2011-05-19 00:06:34.000000000 -0400
34605+++ linux-2.6.39.1/drivers/net/ibm_newemac/phy.c 2011-05-22 19:36:31.000000000 -0400
34606@@ -273,7 +273,7 @@ static int genmii_read_link(struct mii_p
34607 }
34608
34609 /* Generic implementation for most 10/100/1000 PHYs */
34610-static struct mii_phy_ops generic_phy_ops = {
34611+static const struct mii_phy_ops generic_phy_ops = {
34612 .setup_aneg = genmii_setup_aneg,
34613 .setup_forced = genmii_setup_forced,
34614 .poll_link = genmii_poll_link,
34615@@ -337,7 +337,7 @@ static int cis8201_init(struct mii_phy *
34616 return 0;
34617 }
34618
34619-static struct mii_phy_ops cis8201_phy_ops = {
34620+static const struct mii_phy_ops cis8201_phy_ops = {
34621 .init = cis8201_init,
34622 .setup_aneg = genmii_setup_aneg,
34623 .setup_forced = genmii_setup_forced,
34624@@ -417,7 +417,7 @@ static int et1011c_init(struct mii_phy *
34625 return 0;
34626 }
34627
34628-static struct mii_phy_ops et1011c_phy_ops = {
34629+static const struct mii_phy_ops et1011c_phy_ops = {
34630 .init = et1011c_init,
34631 .setup_aneg = genmii_setup_aneg,
34632 .setup_forced = genmii_setup_forced,
34633@@ -436,7 +436,7 @@ static struct mii_phy_def et1011c_phy_de
34634
34635
34636
34637-static struct mii_phy_ops m88e1111_phy_ops = {
34638+static const struct mii_phy_ops m88e1111_phy_ops = {
34639 .init = m88e1111_init,
34640 .setup_aneg = genmii_setup_aneg,
34641 .setup_forced = genmii_setup_forced,
34642@@ -452,7 +452,7 @@ static struct mii_phy_def m88e1111_phy_d
34643 .ops = &m88e1111_phy_ops,
34644 };
34645
34646-static struct mii_phy_ops m88e1112_phy_ops = {
34647+static const struct mii_phy_ops m88e1112_phy_ops = {
34648 .init = m88e1112_init,
34649 .setup_aneg = genmii_setup_aneg,
34650 .setup_forced = genmii_setup_forced,
34651diff -urNp linux-2.6.39.1/drivers/net/ibmveth.c linux-2.6.39.1/drivers/net/ibmveth.c
34652--- linux-2.6.39.1/drivers/net/ibmveth.c 2011-05-19 00:06:34.000000000 -0400
34653+++ linux-2.6.39.1/drivers/net/ibmveth.c 2011-05-22 19:36:31.000000000 -0400
34654@@ -1625,7 +1625,7 @@ static struct vio_device_id ibmveth_devi
34655 };
34656 MODULE_DEVICE_TABLE(vio, ibmveth_device_table);
34657
34658-static struct dev_pm_ops ibmveth_pm_ops = {
34659+static const struct dev_pm_ops ibmveth_pm_ops = {
34660 .resume = ibmveth_resume
34661 };
34662
34663diff -urNp linux-2.6.39.1/drivers/net/igb/e1000_82575.c linux-2.6.39.1/drivers/net/igb/e1000_82575.c
34664--- linux-2.6.39.1/drivers/net/igb/e1000_82575.c 2011-05-19 00:06:34.000000000 -0400
34665+++ linux-2.6.39.1/drivers/net/igb/e1000_82575.c 2011-05-22 19:36:31.000000000 -0400
34666@@ -2029,7 +2029,7 @@ out:
34667 return ret_val;
34668 }
34669
34670-static struct e1000_mac_operations e1000_mac_ops_82575 = {
34671+static const struct e1000_mac_operations e1000_mac_ops_82575 = {
34672 .init_hw = igb_init_hw_82575,
34673 .check_for_link = igb_check_for_link_82575,
34674 .rar_set = igb_rar_set,
34675@@ -2037,13 +2037,13 @@ static struct e1000_mac_operations e1000
34676 .get_speed_and_duplex = igb_get_speed_and_duplex_copper,
34677 };
34678
34679-static struct e1000_phy_operations e1000_phy_ops_82575 = {
34680+static const struct e1000_phy_operations e1000_phy_ops_82575 = {
34681 .acquire = igb_acquire_phy_82575,
34682 .get_cfg_done = igb_get_cfg_done_82575,
34683 .release = igb_release_phy_82575,
34684 };
34685
34686-static struct e1000_nvm_operations e1000_nvm_ops_82575 = {
34687+static const struct e1000_nvm_operations e1000_nvm_ops_82575 = {
34688 .acquire = igb_acquire_nvm_82575,
34689 .read = igb_read_nvm_eerd,
34690 .release = igb_release_nvm_82575,
34691diff -urNp linux-2.6.39.1/drivers/net/igb/e1000_hw.h linux-2.6.39.1/drivers/net/igb/e1000_hw.h
34692--- linux-2.6.39.1/drivers/net/igb/e1000_hw.h 2011-05-19 00:06:34.000000000 -0400
34693+++ linux-2.6.39.1/drivers/net/igb/e1000_hw.h 2011-05-22 19:36:31.000000000 -0400
34694@@ -342,14 +342,15 @@ struct e1000_nvm_operations {
34695
34696 struct e1000_info {
34697 s32 (*get_invariants)(struct e1000_hw *);
34698- struct e1000_mac_operations *mac_ops;
34699- struct e1000_phy_operations *phy_ops;
34700- struct e1000_nvm_operations *nvm_ops;
34701+ const struct e1000_mac_operations *mac_ops;
34702+ const struct e1000_phy_operations *phy_ops;
34703+ const struct e1000_nvm_operations *nvm_ops;
34704 };
34705
34706 extern const struct e1000_info e1000_82575_info;
34707
34708 struct e1000_mac_info {
34709+ /* cannot be const see igb_get_invariants_82575() */
34710 struct e1000_mac_operations ops;
34711
34712 u8 addr[6];
34713@@ -388,6 +389,7 @@ struct e1000_mac_info {
34714 };
34715
34716 struct e1000_phy_info {
34717+ /* cannot be const see igb_get_invariants_82575() */
34718 struct e1000_phy_operations ops;
34719
34720 enum e1000_phy_type type;
34721@@ -423,6 +425,7 @@ struct e1000_phy_info {
34722 };
34723
34724 struct e1000_nvm_info {
34725+ /* cannot be const */
34726 struct e1000_nvm_operations ops;
34727 enum e1000_nvm_type type;
34728 enum e1000_nvm_override override;
34729diff -urNp linux-2.6.39.1/drivers/net/igbvf/vf.h linux-2.6.39.1/drivers/net/igbvf/vf.h
34730--- linux-2.6.39.1/drivers/net/igbvf/vf.h 2011-05-19 00:06:34.000000000 -0400
34731+++ linux-2.6.39.1/drivers/net/igbvf/vf.h 2011-05-22 19:36:31.000000000 -0400
34732@@ -191,6 +191,7 @@ struct e1000_mac_operations {
34733 };
34734
34735 struct e1000_mac_info {
34736+ /* cannot be const see e1000_init_mac_params_vf() */
34737 struct e1000_mac_operations ops;
34738 u8 addr[6];
34739 u8 perm_addr[6];
34740diff -urNp linux-2.6.39.1/drivers/net/irda/sh_irda.c linux-2.6.39.1/drivers/net/irda/sh_irda.c
34741--- linux-2.6.39.1/drivers/net/irda/sh_irda.c 2011-05-19 00:06:34.000000000 -0400
34742+++ linux-2.6.39.1/drivers/net/irda/sh_irda.c 2011-05-22 19:36:31.000000000 -0400
34743@@ -307,7 +307,7 @@ static int xir_fte(struct sh_irda_self *
34744 return 0;
34745 }
34746
34747-static struct sh_irda_xir_func xir_func = {
34748+static const struct sh_irda_xir_func xir_func = {
34749 .xir_fre = xir_fre,
34750 .xir_trov = xir_trov,
34751 .xir_9 = xir_9,
34752@@ -321,7 +321,7 @@ static struct sh_irda_xir_func xir_func
34753 *
34754 * MIR/FIR are not supported now
34755 *=====================================*/
34756-static struct sh_irda_xir_func mfir_func = {
34757+static const struct sh_irda_xir_func mfir_func = {
34758 .xir_fre = xir_fre,
34759 .xir_trov = xir_trov,
34760 .xir_9 = xir_9,
34761@@ -400,7 +400,7 @@ static int sir_fte(struct sh_irda_self *
34762 return 0;
34763 }
34764
34765-static struct sh_irda_xir_func sir_func = {
34766+static const struct sh_irda_xir_func sir_func = {
34767 .xir_fre = sir_fre,
34768 .xir_trov = sir_trov,
34769 .xir_9 = sir_tot,
34770@@ -411,7 +411,7 @@ static struct sh_irda_xir_func sir_func
34771 static void sh_irda_set_mode(struct sh_irda_self *self, enum sh_irda_mode mode)
34772 {
34773 struct device *dev = &self->ndev->dev;
34774- struct sh_irda_xir_func *func;
34775+ const struct sh_irda_xir_func *func;
34776 const char *name;
34777 u16 data;
34778
34779diff -urNp linux-2.6.39.1/drivers/net/ixgb/ixgb_main.c linux-2.6.39.1/drivers/net/ixgb/ixgb_main.c
34780--- linux-2.6.39.1/drivers/net/ixgb/ixgb_main.c 2011-05-19 00:06:34.000000000 -0400
34781+++ linux-2.6.39.1/drivers/net/ixgb/ixgb_main.c 2011-05-22 19:36:31.000000000 -0400
34782@@ -1069,6 +1069,8 @@ ixgb_set_multi(struct net_device *netdev
34783 u32 rctl;
34784 int i;
34785
34786+ pax_track_stack();
34787+
34788 /* Check for Promiscuous and All Multicast modes */
34789
34790 rctl = IXGB_READ_REG(hw, RCTL);
34791diff -urNp linux-2.6.39.1/drivers/net/ixgb/ixgb_param.c linux-2.6.39.1/drivers/net/ixgb/ixgb_param.c
34792--- linux-2.6.39.1/drivers/net/ixgb/ixgb_param.c 2011-05-19 00:06:34.000000000 -0400
34793+++ linux-2.6.39.1/drivers/net/ixgb/ixgb_param.c 2011-05-22 19:36:31.000000000 -0400
34794@@ -261,6 +261,9 @@ void __devinit
34795 ixgb_check_options(struct ixgb_adapter *adapter)
34796 {
34797 int bd = adapter->bd_number;
34798+
34799+ pax_track_stack();
34800+
34801 if (bd >= IXGB_MAX_NIC) {
34802 pr_notice("Warning: no configuration for board #%i\n", bd);
34803 pr_notice("Using defaults for all values\n");
34804diff -urNp linux-2.6.39.1/drivers/net/ixgbe/ixgbe_82599.c linux-2.6.39.1/drivers/net/ixgbe/ixgbe_82599.c
34805--- linux-2.6.39.1/drivers/net/ixgbe/ixgbe_82599.c 2011-05-19 00:06:34.000000000 -0400
34806+++ linux-2.6.39.1/drivers/net/ixgbe/ixgbe_82599.c 2011-05-22 19:36:31.000000000 -0400
34807@@ -2099,7 +2099,7 @@ static struct ixgbe_phy_operations phy_o
34808 .check_overtemp = &ixgbe_tn_check_overtemp,
34809 };
34810
34811-struct ixgbe_info ixgbe_82599_info = {
34812+const struct ixgbe_info ixgbe_82599_info = {
34813 .mac = ixgbe_mac_82599EB,
34814 .get_invariants = &ixgbe_get_invariants_82599,
34815 .mac_ops = &mac_ops_82599,
34816diff -urNp linux-2.6.39.1/drivers/net/ixgbe/ixgbe.h linux-2.6.39.1/drivers/net/ixgbe/ixgbe.h
34817--- linux-2.6.39.1/drivers/net/ixgbe/ixgbe.h 2011-05-19 00:06:34.000000000 -0400
34818+++ linux-2.6.39.1/drivers/net/ixgbe/ixgbe.h 2011-05-22 19:36:31.000000000 -0400
34819@@ -493,8 +493,8 @@ enum ixgbe_boards {
34820 };
34821
34822 extern struct ixgbe_info ixgbe_82598_info;
34823-extern struct ixgbe_info ixgbe_82599_info;
34824-extern struct ixgbe_info ixgbe_X540_info;
34825+extern const struct ixgbe_info ixgbe_82599_info;
34826+extern const struct ixgbe_info ixgbe_X540_info;
34827 #ifdef CONFIG_IXGBE_DCB
34828 extern const struct dcbnl_rtnl_ops dcbnl_ops;
34829 extern int ixgbe_copy_dcb_cfg(struct ixgbe_dcb_config *src_dcb_cfg,
34830diff -urNp linux-2.6.39.1/drivers/net/ixgbe/ixgbe_x540.c linux-2.6.39.1/drivers/net/ixgbe/ixgbe_x540.c
34831--- linux-2.6.39.1/drivers/net/ixgbe/ixgbe_x540.c 2011-05-19 00:06:34.000000000 -0400
34832+++ linux-2.6.39.1/drivers/net/ixgbe/ixgbe_x540.c 2011-05-22 19:36:31.000000000 -0400
34833@@ -727,7 +727,7 @@ static struct ixgbe_phy_operations phy_o
34834 .check_overtemp = &ixgbe_tn_check_overtemp,
34835 };
34836
34837-struct ixgbe_info ixgbe_X540_info = {
34838+const struct ixgbe_info ixgbe_X540_info = {
34839 .mac = ixgbe_mac_X540,
34840 .get_invariants = &ixgbe_get_invariants_X540,
34841 .mac_ops = &mac_ops_X540,
34842diff -urNp linux-2.6.39.1/drivers/net/ixgbevf/ethtool.c linux-2.6.39.1/drivers/net/ixgbevf/ethtool.c
34843--- linux-2.6.39.1/drivers/net/ixgbevf/ethtool.c 2011-05-19 00:06:34.000000000 -0400
34844+++ linux-2.6.39.1/drivers/net/ixgbevf/ethtool.c 2011-05-22 19:36:31.000000000 -0400
34845@@ -709,7 +709,7 @@ static int ixgbevf_nway_reset(struct net
34846 return 0;
34847 }
34848
34849-static struct ethtool_ops ixgbevf_ethtool_ops = {
34850+static const struct ethtool_ops ixgbevf_ethtool_ops = {
34851 .get_settings = ixgbevf_get_settings,
34852 .get_drvinfo = ixgbevf_get_drvinfo,
34853 .get_regs_len = ixgbevf_get_regs_len,
34854diff -urNp linux-2.6.39.1/drivers/net/ixgbevf/ixgbevf.h linux-2.6.39.1/drivers/net/ixgbevf/ixgbevf.h
34855--- linux-2.6.39.1/drivers/net/ixgbevf/ixgbevf.h 2011-05-19 00:06:34.000000000 -0400
34856+++ linux-2.6.39.1/drivers/net/ixgbevf/ixgbevf.h 2011-05-22 19:36:31.000000000 -0400
34857@@ -279,7 +279,7 @@ enum ixgbevf_boards {
34858
34859 extern struct ixgbevf_info ixgbevf_82599_vf_info;
34860 extern struct ixgbevf_info ixgbevf_X540_vf_info;
34861-extern struct ixgbe_mac_operations ixgbevf_mbx_ops;
34862+extern const struct ixgbe_mac_operations ixgbevf_mbx_ops;
34863
34864 /* needed by ethtool.c */
34865 extern char ixgbevf_driver_name[];
34866diff -urNp linux-2.6.39.1/drivers/net/ixgbevf/vf.c linux-2.6.39.1/drivers/net/ixgbevf/vf.c
34867--- linux-2.6.39.1/drivers/net/ixgbevf/vf.c 2011-05-19 00:06:34.000000000 -0400
34868+++ linux-2.6.39.1/drivers/net/ixgbevf/vf.c 2011-05-22 19:36:31.000000000 -0400
34869@@ -368,7 +368,7 @@ static s32 ixgbevf_check_mac_link_vf(str
34870 return 0;
34871 }
34872
34873-static struct ixgbe_mac_operations ixgbevf_mac_ops = {
34874+static const struct ixgbe_mac_operations ixgbevf_mac_ops = {
34875 .init_hw = ixgbevf_init_hw_vf,
34876 .reset_hw = ixgbevf_reset_hw_vf,
34877 .start_hw = ixgbevf_start_hw_vf,
34878@@ -381,12 +381,12 @@ static struct ixgbe_mac_operations ixgbe
34879 .set_vfta = ixgbevf_set_vfta_vf,
34880 };
34881
34882-struct ixgbevf_info ixgbevf_82599_vf_info = {
34883+const struct ixgbevf_info ixgbevf_82599_vf_info = {
34884 .mac = ixgbe_mac_82599_vf,
34885 .mac_ops = &ixgbevf_mac_ops,
34886 };
34887
34888-struct ixgbevf_info ixgbevf_X540_vf_info = {
34889+const struct ixgbevf_info ixgbevf_X540_vf_info = {
34890 .mac = ixgbe_mac_X540_vf,
34891 .mac_ops = &ixgbevf_mac_ops,
34892 };
34893diff -urNp linux-2.6.39.1/drivers/net/ixgbevf/vf.h linux-2.6.39.1/drivers/net/ixgbevf/vf.h
34894--- linux-2.6.39.1/drivers/net/ixgbevf/vf.h 2011-05-19 00:06:34.000000000 -0400
34895+++ linux-2.6.39.1/drivers/net/ixgbevf/vf.h 2011-05-22 19:36:31.000000000 -0400
34896@@ -166,7 +166,7 @@ struct ixgbevf_hw_stats {
34897
34898 struct ixgbevf_info {
34899 enum ixgbe_mac_type mac;
34900- struct ixgbe_mac_operations *mac_ops;
34901+ const struct ixgbe_mac_operations *mac_ops;
34902 };
34903
34904 #endif /* __IXGBE_VF_H__ */
34905diff -urNp linux-2.6.39.1/drivers/net/ksz884x.c linux-2.6.39.1/drivers/net/ksz884x.c
34906--- linux-2.6.39.1/drivers/net/ksz884x.c 2011-05-19 00:06:34.000000000 -0400
34907+++ linux-2.6.39.1/drivers/net/ksz884x.c 2011-05-22 19:36:31.000000000 -0400
34908@@ -6536,6 +6536,8 @@ static void netdev_get_ethtool_stats(str
34909 int rc;
34910 u64 counter[TOTAL_PORT_COUNTER_NUM];
34911
34912+ pax_track_stack();
34913+
34914 mutex_lock(&hw_priv->lock);
34915 n = SWITCH_PORT_NUM;
34916 for (i = 0, p = port->first_port; i < port->mib_port_cnt; i++, p++) {
34917@@ -6637,7 +6639,7 @@ static int netdev_set_rx_csum(struct net
34918 return 0;
34919 }
34920
34921-static struct ethtool_ops netdev_ethtool_ops = {
34922+static const struct ethtool_ops netdev_ethtool_ops = {
34923 .get_settings = netdev_get_settings,
34924 .set_settings = netdev_set_settings,
34925 .nway_reset = netdev_nway_reset,
34926diff -urNp linux-2.6.39.1/drivers/net/mlx4/main.c linux-2.6.39.1/drivers/net/mlx4/main.c
34927--- linux-2.6.39.1/drivers/net/mlx4/main.c 2011-05-19 00:06:34.000000000 -0400
34928+++ linux-2.6.39.1/drivers/net/mlx4/main.c 2011-05-22 19:36:31.000000000 -0400
34929@@ -40,6 +40,7 @@
34930 #include <linux/dma-mapping.h>
34931 #include <linux/slab.h>
34932 #include <linux/io-mapping.h>
34933+#include <linux/sched.h>
34934
34935 #include <linux/mlx4/device.h>
34936 #include <linux/mlx4/doorbell.h>
34937@@ -764,6 +765,8 @@ static int mlx4_init_hca(struct mlx4_dev
34938 u64 icm_size;
34939 int err;
34940
34941+ pax_track_stack();
34942+
34943 err = mlx4_QUERY_FW(dev);
34944 if (err) {
34945 if (err == -EACCES)
34946diff -urNp linux-2.6.39.1/drivers/net/netconsole.c linux-2.6.39.1/drivers/net/netconsole.c
34947--- linux-2.6.39.1/drivers/net/netconsole.c 2011-05-19 00:06:34.000000000 -0400
34948+++ linux-2.6.39.1/drivers/net/netconsole.c 2011-05-22 19:36:31.000000000 -0400
34949@@ -634,7 +634,7 @@ static void drop_netconsole_target(struc
34950 config_item_put(&nt->item);
34951 }
34952
34953-static struct configfs_group_operations netconsole_subsys_group_ops = {
34954+static const struct configfs_group_operations netconsole_subsys_group_ops = {
34955 .make_item = make_netconsole_target,
34956 .drop_item = drop_netconsole_target,
34957 };
34958diff -urNp linux-2.6.39.1/drivers/net/niu.c linux-2.6.39.1/drivers/net/niu.c
34959--- linux-2.6.39.1/drivers/net/niu.c 2011-05-19 00:06:34.000000000 -0400
34960+++ linux-2.6.39.1/drivers/net/niu.c 2011-05-22 19:36:31.000000000 -0400
34961@@ -9067,6 +9067,8 @@ static void __devinit niu_try_msix(struc
34962 int i, num_irqs, err;
34963 u8 first_ldg;
34964
34965+ pax_track_stack();
34966+
34967 first_ldg = (NIU_NUM_LDG / parent->num_ports) * np->port;
34968 for (i = 0; i < (NIU_NUM_LDG / parent->num_ports); i++)
34969 ldg_num_map[i] = first_ldg + i;
34970diff -urNp linux-2.6.39.1/drivers/net/pcnet32.c linux-2.6.39.1/drivers/net/pcnet32.c
34971--- linux-2.6.39.1/drivers/net/pcnet32.c 2011-05-19 00:06:34.000000000 -0400
34972+++ linux-2.6.39.1/drivers/net/pcnet32.c 2011-05-22 19:36:31.000000000 -0400
34973@@ -82,7 +82,7 @@ static int cards_found;
34974 /*
34975 * VLB I/O addresses
34976 */
34977-static unsigned int pcnet32_portlist[] __initdata =
34978+static unsigned int pcnet32_portlist[] __devinitdata =
34979 { 0x300, 0x320, 0x340, 0x360, 0 };
34980
34981 static int pcnet32_debug;
34982@@ -379,7 +379,7 @@ static int pcnet32_wio_check(unsigned lo
34983 return inw(addr + PCNET32_WIO_RAP) == 88;
34984 }
34985
34986-static struct pcnet32_access pcnet32_wio = {
34987+static const struct pcnet32_access pcnet32_wio = {
34988 .read_csr = pcnet32_wio_read_csr,
34989 .write_csr = pcnet32_wio_write_csr,
34990 .read_bcr = pcnet32_wio_read_bcr,
34991@@ -434,7 +434,7 @@ static int pcnet32_dwio_check(unsigned l
34992 return (inl(addr + PCNET32_DWIO_RAP) & 0xffff) == 88;
34993 }
34994
34995-static struct pcnet32_access pcnet32_dwio = {
34996+static const struct pcnet32_access pcnet32_dwio = {
34997 .read_csr = pcnet32_dwio_read_csr,
34998 .write_csr = pcnet32_dwio_write_csr,
34999 .read_bcr = pcnet32_dwio_read_bcr,
35000@@ -1546,7 +1546,7 @@ pcnet32_probe1(unsigned long ioaddr, int
35001 int chip_version;
35002 char *chipname;
35003 struct net_device *dev;
35004- struct pcnet32_access *a = NULL;
35005+ const struct pcnet32_access *a = NULL;
35006 u8 promaddr[6];
35007 int ret = -ENODEV;
35008
35009diff -urNp linux-2.6.39.1/drivers/net/ppp_generic.c linux-2.6.39.1/drivers/net/ppp_generic.c
35010--- linux-2.6.39.1/drivers/net/ppp_generic.c 2011-05-19 00:06:34.000000000 -0400
35011+++ linux-2.6.39.1/drivers/net/ppp_generic.c 2011-05-22 19:36:31.000000000 -0400
35012@@ -987,7 +987,6 @@ ppp_net_ioctl(struct net_device *dev, st
35013 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
35014 struct ppp_stats stats;
35015 struct ppp_comp_stats cstats;
35016- char *vers;
35017
35018 switch (cmd) {
35019 case SIOCGPPPSTATS:
35020@@ -1009,8 +1008,7 @@ ppp_net_ioctl(struct net_device *dev, st
35021 break;
35022
35023 case SIOCGPPPVER:
35024- vers = PPP_VERSION;
35025- if (copy_to_user(addr, vers, strlen(vers) + 1))
35026+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
35027 break;
35028 err = 0;
35029 break;
35030diff -urNp linux-2.6.39.1/drivers/net/qlcnic/qlcnic.h linux-2.6.39.1/drivers/net/qlcnic/qlcnic.h
35031--- linux-2.6.39.1/drivers/net/qlcnic/qlcnic.h 2011-05-19 00:06:34.000000000 -0400
35032+++ linux-2.6.39.1/drivers/net/qlcnic/qlcnic.h 2011-05-22 19:36:31.000000000 -0400
35033@@ -1037,7 +1037,7 @@ struct qlcnic_adapter {
35034 struct vlan_group *vlgrp;
35035 struct qlcnic_npar_info *npars;
35036 struct qlcnic_eswitch *eswitch;
35037- struct qlcnic_nic_template *nic_ops;
35038+ const struct qlcnic_nic_template *nic_ops;
35039
35040 struct qlcnic_adapter_stats stats;
35041
35042diff -urNp linux-2.6.39.1/drivers/net/qlcnic/qlcnic_main.c linux-2.6.39.1/drivers/net/qlcnic/qlcnic_main.c
35043--- linux-2.6.39.1/drivers/net/qlcnic/qlcnic_main.c 2011-05-19 00:06:34.000000000 -0400
35044+++ linux-2.6.39.1/drivers/net/qlcnic/qlcnic_main.c 2011-05-22 19:36:31.000000000 -0400
35045@@ -340,13 +340,13 @@ static const struct net_device_ops qlcni
35046 #endif
35047 };
35048
35049-static struct qlcnic_nic_template qlcnic_ops = {
35050+static const struct qlcnic_nic_template qlcnic_ops = {
35051 .config_bridged_mode = qlcnic_config_bridged_mode,
35052 .config_led = qlcnic_config_led,
35053 .start_firmware = qlcnic_start_firmware
35054 };
35055
35056-static struct qlcnic_nic_template qlcnic_vf_ops = {
35057+static const struct qlcnic_nic_template qlcnic_vf_ops = {
35058 .config_bridged_mode = qlcnicvf_config_bridged_mode,
35059 .config_led = qlcnicvf_config_led,
35060 .start_firmware = qlcnicvf_start_firmware
35061diff -urNp linux-2.6.39.1/drivers/net/qlge/qlge.h linux-2.6.39.1/drivers/net/qlge/qlge.h
35062--- linux-2.6.39.1/drivers/net/qlge/qlge.h 2011-05-19 00:06:34.000000000 -0400
35063+++ linux-2.6.39.1/drivers/net/qlge/qlge.h 2011-05-22 19:36:31.000000000 -0400
35064@@ -2134,7 +2134,7 @@ struct ql_adapter {
35065 struct delayed_work mpi_idc_work;
35066 struct delayed_work mpi_core_to_log;
35067 struct completion ide_completion;
35068- struct nic_operations *nic_ops;
35069+ const struct nic_operations *nic_ops;
35070 u16 device_id;
35071 struct timer_list timer;
35072 atomic_t lb_count;
35073diff -urNp linux-2.6.39.1/drivers/net/qlge/qlge_main.c linux-2.6.39.1/drivers/net/qlge/qlge_main.c
35074--- linux-2.6.39.1/drivers/net/qlge/qlge_main.c 2011-05-19 00:06:34.000000000 -0400
35075+++ linux-2.6.39.1/drivers/net/qlge/qlge_main.c 2011-05-22 19:36:31.000000000 -0400
35076@@ -4412,12 +4412,12 @@ error:
35077 rtnl_unlock();
35078 }
35079
35080-static struct nic_operations qla8012_nic_ops = {
35081+static const struct nic_operations qla8012_nic_ops = {
35082 .get_flash = ql_get_8012_flash_params,
35083 .port_initialize = ql_8012_port_initialize,
35084 };
35085
35086-static struct nic_operations qla8000_nic_ops = {
35087+static const struct nic_operations qla8000_nic_ops = {
35088 .get_flash = ql_get_8000_flash_params,
35089 .port_initialize = ql_8000_port_initialize,
35090 };
35091diff -urNp linux-2.6.39.1/drivers/net/sfc/falcon.c linux-2.6.39.1/drivers/net/sfc/falcon.c
35092--- linux-2.6.39.1/drivers/net/sfc/falcon.c 2011-05-19 00:06:34.000000000 -0400
35093+++ linux-2.6.39.1/drivers/net/sfc/falcon.c 2011-05-22 19:36:31.000000000 -0400
35094@@ -1703,7 +1703,7 @@ static int falcon_set_wol(struct efx_nic
35095 **************************************************************************
35096 */
35097
35098-struct efx_nic_type falcon_a1_nic_type = {
35099+const struct efx_nic_type falcon_a1_nic_type = {
35100 .probe = falcon_probe_nic,
35101 .remove = falcon_remove_nic,
35102 .init = falcon_init_nic,
35103@@ -1744,7 +1744,7 @@ struct efx_nic_type falcon_a1_nic_type =
35104 .reset_world_flags = ETH_RESET_IRQ,
35105 };
35106
35107-struct efx_nic_type falcon_b0_nic_type = {
35108+const struct efx_nic_type falcon_b0_nic_type = {
35109 .probe = falcon_probe_nic,
35110 .remove = falcon_remove_nic,
35111 .init = falcon_init_nic,
35112diff -urNp linux-2.6.39.1/drivers/net/sfc/mtd.c linux-2.6.39.1/drivers/net/sfc/mtd.c
35113--- linux-2.6.39.1/drivers/net/sfc/mtd.c 2011-05-19 00:06:34.000000000 -0400
35114+++ linux-2.6.39.1/drivers/net/sfc/mtd.c 2011-05-22 19:36:31.000000000 -0400
35115@@ -382,7 +382,7 @@ static int falcon_mtd_sync(struct mtd_in
35116 return rc;
35117 }
35118
35119-static struct efx_mtd_ops falcon_mtd_ops = {
35120+static const struct efx_mtd_ops falcon_mtd_ops = {
35121 .read = falcon_mtd_read,
35122 .erase = falcon_mtd_erase,
35123 .write = falcon_mtd_write,
35124@@ -560,7 +560,7 @@ static int siena_mtd_sync(struct mtd_inf
35125 return rc;
35126 }
35127
35128-static struct efx_mtd_ops siena_mtd_ops = {
35129+static const struct efx_mtd_ops siena_mtd_ops = {
35130 .read = siena_mtd_read,
35131 .erase = siena_mtd_erase,
35132 .write = siena_mtd_write,
35133diff -urNp linux-2.6.39.1/drivers/net/sfc/nic.h linux-2.6.39.1/drivers/net/sfc/nic.h
35134--- linux-2.6.39.1/drivers/net/sfc/nic.h 2011-05-19 00:06:34.000000000 -0400
35135+++ linux-2.6.39.1/drivers/net/sfc/nic.h 2011-05-22 19:36:31.000000000 -0400
35136@@ -152,9 +152,9 @@ struct siena_nic_data {
35137 int wol_filter_id;
35138 };
35139
35140-extern struct efx_nic_type falcon_a1_nic_type;
35141-extern struct efx_nic_type falcon_b0_nic_type;
35142-extern struct efx_nic_type siena_a0_nic_type;
35143+extern const struct efx_nic_type falcon_a1_nic_type;
35144+extern const struct efx_nic_type falcon_b0_nic_type;
35145+extern const struct efx_nic_type siena_a0_nic_type;
35146
35147 /**************************************************************************
35148 *
35149diff -urNp linux-2.6.39.1/drivers/net/sfc/siena.c linux-2.6.39.1/drivers/net/sfc/siena.c
35150--- linux-2.6.39.1/drivers/net/sfc/siena.c 2011-05-19 00:06:34.000000000 -0400
35151+++ linux-2.6.39.1/drivers/net/sfc/siena.c 2011-05-22 19:36:31.000000000 -0400
35152@@ -599,7 +599,7 @@ static void siena_init_wol(struct efx_ni
35153 **************************************************************************
35154 */
35155
35156-struct efx_nic_type siena_a0_nic_type = {
35157+const struct efx_nic_type siena_a0_nic_type = {
35158 .probe = siena_probe_nic,
35159 .remove = siena_remove_nic,
35160 .init = siena_init_nic,
35161diff -urNp linux-2.6.39.1/drivers/net/sh_eth.c linux-2.6.39.1/drivers/net/sh_eth.c
35162--- linux-2.6.39.1/drivers/net/sh_eth.c 2011-05-19 00:06:34.000000000 -0400
35163+++ linux-2.6.39.1/drivers/net/sh_eth.c 2011-05-22 19:36:31.000000000 -0400
35164@@ -1360,7 +1360,7 @@ static void sh_eth_get_strings(struct ne
35165 }
35166 }
35167
35168-static struct ethtool_ops sh_eth_ethtool_ops = {
35169+static const struct ethtool_ops sh_eth_ethtool_ops = {
35170 .get_settings = sh_eth_get_settings,
35171 .set_settings = sh_eth_set_settings,
35172 .nway_reset = sh_eth_nway_reset,
35173diff -urNp linux-2.6.39.1/drivers/net/stmmac/stmmac_ethtool.c linux-2.6.39.1/drivers/net/stmmac/stmmac_ethtool.c
35174--- linux-2.6.39.1/drivers/net/stmmac/stmmac_ethtool.c 2011-05-19 00:06:34.000000000 -0400
35175+++ linux-2.6.39.1/drivers/net/stmmac/stmmac_ethtool.c 2011-05-22 19:36:31.000000000 -0400
35176@@ -348,7 +348,7 @@ static int stmmac_set_wol(struct net_dev
35177 return 0;
35178 }
35179
35180-static struct ethtool_ops stmmac_ethtool_ops = {
35181+static const struct ethtool_ops stmmac_ethtool_ops = {
35182 .begin = stmmac_check_if_running,
35183 .get_drvinfo = stmmac_ethtool_getdrvinfo,
35184 .get_settings = stmmac_ethtool_getsettings,
35185diff -urNp linux-2.6.39.1/drivers/net/sungem_phy.c linux-2.6.39.1/drivers/net/sungem_phy.c
35186--- linux-2.6.39.1/drivers/net/sungem_phy.c 2011-05-19 00:06:34.000000000 -0400
35187+++ linux-2.6.39.1/drivers/net/sungem_phy.c 2011-05-22 19:36:31.000000000 -0400
35188@@ -886,7 +886,7 @@ static int marvell_read_link(struct mii_
35189 SUPPORTED_1000baseT_Half | SUPPORTED_1000baseT_Full)
35190
35191 /* Broadcom BCM 5201 */
35192-static struct mii_phy_ops bcm5201_phy_ops = {
35193+static const struct mii_phy_ops bcm5201_phy_ops = {
35194 .init = bcm5201_init,
35195 .suspend = bcm5201_suspend,
35196 .setup_aneg = genmii_setup_aneg,
35197@@ -905,7 +905,7 @@ static struct mii_phy_def bcm5201_phy_de
35198 };
35199
35200 /* Broadcom BCM 5221 */
35201-static struct mii_phy_ops bcm5221_phy_ops = {
35202+static const struct mii_phy_ops bcm5221_phy_ops = {
35203 .suspend = bcm5221_suspend,
35204 .init = bcm5221_init,
35205 .setup_aneg = genmii_setup_aneg,
35206@@ -924,7 +924,7 @@ static struct mii_phy_def bcm5221_phy_de
35207 };
35208
35209 /* Broadcom BCM 5241 */
35210-static struct mii_phy_ops bcm5241_phy_ops = {
35211+static const struct mii_phy_ops bcm5241_phy_ops = {
35212 .suspend = bcm5241_suspend,
35213 .init = bcm5241_init,
35214 .setup_aneg = genmii_setup_aneg,
35215@@ -942,7 +942,7 @@ static struct mii_phy_def bcm5241_phy_de
35216 };
35217
35218 /* Broadcom BCM 5400 */
35219-static struct mii_phy_ops bcm5400_phy_ops = {
35220+static const struct mii_phy_ops bcm5400_phy_ops = {
35221 .init = bcm5400_init,
35222 .suspend = bcm5400_suspend,
35223 .setup_aneg = bcm54xx_setup_aneg,
35224@@ -961,7 +961,7 @@ static struct mii_phy_def bcm5400_phy_de
35225 };
35226
35227 /* Broadcom BCM 5401 */
35228-static struct mii_phy_ops bcm5401_phy_ops = {
35229+static const struct mii_phy_ops bcm5401_phy_ops = {
35230 .init = bcm5401_init,
35231 .suspend = bcm5401_suspend,
35232 .setup_aneg = bcm54xx_setup_aneg,
35233@@ -980,7 +980,7 @@ static struct mii_phy_def bcm5401_phy_de
35234 };
35235
35236 /* Broadcom BCM 5411 */
35237-static struct mii_phy_ops bcm5411_phy_ops = {
35238+static const struct mii_phy_ops bcm5411_phy_ops = {
35239 .init = bcm5411_init,
35240 .suspend = generic_suspend,
35241 .setup_aneg = bcm54xx_setup_aneg,
35242@@ -999,7 +999,7 @@ static struct mii_phy_def bcm5411_phy_de
35243 };
35244
35245 /* Broadcom BCM 5421 */
35246-static struct mii_phy_ops bcm5421_phy_ops = {
35247+static const struct mii_phy_ops bcm5421_phy_ops = {
35248 .init = bcm5421_init,
35249 .suspend = generic_suspend,
35250 .setup_aneg = bcm54xx_setup_aneg,
35251@@ -1019,7 +1019,7 @@ static struct mii_phy_def bcm5421_phy_de
35252 };
35253
35254 /* Broadcom BCM 5421 built-in K2 */
35255-static struct mii_phy_ops bcm5421k2_phy_ops = {
35256+static const struct mii_phy_ops bcm5421k2_phy_ops = {
35257 .init = bcm5421_init,
35258 .suspend = generic_suspend,
35259 .setup_aneg = bcm54xx_setup_aneg,
35260@@ -1037,7 +1037,7 @@ static struct mii_phy_def bcm5421k2_phy_
35261 .ops = &bcm5421k2_phy_ops
35262 };
35263
35264-static struct mii_phy_ops bcm5461_phy_ops = {
35265+static const struct mii_phy_ops bcm5461_phy_ops = {
35266 .init = bcm5421_init,
35267 .suspend = generic_suspend,
35268 .setup_aneg = bcm54xx_setup_aneg,
35269@@ -1057,7 +1057,7 @@ static struct mii_phy_def bcm5461_phy_de
35270 };
35271
35272 /* Broadcom BCM 5462 built-in Vesta */
35273-static struct mii_phy_ops bcm5462V_phy_ops = {
35274+static const struct mii_phy_ops bcm5462V_phy_ops = {
35275 .init = bcm5421_init,
35276 .suspend = generic_suspend,
35277 .setup_aneg = bcm54xx_setup_aneg,
35278@@ -1076,7 +1076,7 @@ static struct mii_phy_def bcm5462V_phy_d
35279 };
35280
35281 /* Marvell 88E1101 amd 88E1111 */
35282-static struct mii_phy_ops marvell88e1101_phy_ops = {
35283+static const struct mii_phy_ops marvell88e1101_phy_ops = {
35284 .suspend = generic_suspend,
35285 .setup_aneg = marvell_setup_aneg,
35286 .setup_forced = marvell_setup_forced,
35287@@ -1084,7 +1084,7 @@ static struct mii_phy_ops marvell88e1101
35288 .read_link = marvell_read_link
35289 };
35290
35291-static struct mii_phy_ops marvell88e1111_phy_ops = {
35292+static const struct mii_phy_ops marvell88e1111_phy_ops = {
35293 .init = marvell88e1111_init,
35294 .suspend = generic_suspend,
35295 .setup_aneg = marvell_setup_aneg,
35296@@ -1122,7 +1122,7 @@ static struct mii_phy_def marvell88e1111
35297 };
35298
35299 /* Generic implementation for most 10/100 PHYs */
35300-static struct mii_phy_ops generic_phy_ops = {
35301+static const struct mii_phy_ops generic_phy_ops = {
35302 .setup_aneg = genmii_setup_aneg,
35303 .setup_forced = genmii_setup_forced,
35304 .poll_link = genmii_poll_link,
35305diff -urNp linux-2.6.39.1/drivers/net/tg3.h linux-2.6.39.1/drivers/net/tg3.h
35306--- linux-2.6.39.1/drivers/net/tg3.h 2011-05-19 00:06:34.000000000 -0400
35307+++ linux-2.6.39.1/drivers/net/tg3.h 2011-05-22 19:36:31.000000000 -0400
35308@@ -131,6 +131,7 @@
35309 #define CHIPREV_ID_5750_A0 0x4000
35310 #define CHIPREV_ID_5750_A1 0x4001
35311 #define CHIPREV_ID_5750_A3 0x4003
35312+#define CHIPREV_ID_5750_C1 0x4201
35313 #define CHIPREV_ID_5750_C2 0x4202
35314 #define CHIPREV_ID_5752_A0_HW 0x5000
35315 #define CHIPREV_ID_5752_A0 0x6000
35316diff -urNp linux-2.6.39.1/drivers/net/tile/tilepro.c linux-2.6.39.1/drivers/net/tile/tilepro.c
35317--- linux-2.6.39.1/drivers/net/tile/tilepro.c 2011-05-19 00:06:34.000000000 -0400
35318+++ linux-2.6.39.1/drivers/net/tile/tilepro.c 2011-05-22 19:36:31.000000000 -0400
35319@@ -2263,7 +2263,7 @@ static int tile_net_get_mac(struct net_d
35320 }
35321
35322
35323-static struct net_device_ops tile_net_ops = {
35324+static const struct net_device_ops tile_net_ops = {
35325 .ndo_open = tile_net_open,
35326 .ndo_stop = tile_net_stop,
35327 .ndo_start_xmit = tile_net_tx,
35328diff -urNp linux-2.6.39.1/drivers/net/tulip/de2104x.c linux-2.6.39.1/drivers/net/tulip/de2104x.c
35329--- linux-2.6.39.1/drivers/net/tulip/de2104x.c 2011-05-19 00:06:34.000000000 -0400
35330+++ linux-2.6.39.1/drivers/net/tulip/de2104x.c 2011-05-22 19:36:31.000000000 -0400
35331@@ -1817,6 +1817,8 @@ static void __devinit de21041_get_srom_i
35332 struct de_srom_info_leaf *il;
35333 void *bufp;
35334
35335+ pax_track_stack();
35336+
35337 /* download entire eeprom */
35338 for (i = 0; i < DE_EEPROM_WORDS; i++)
35339 ((__le16 *)ee_data)[i] =
35340diff -urNp linux-2.6.39.1/drivers/net/tulip/de4x5.c linux-2.6.39.1/drivers/net/tulip/de4x5.c
35341--- linux-2.6.39.1/drivers/net/tulip/de4x5.c 2011-05-19 00:06:34.000000000 -0400
35342+++ linux-2.6.39.1/drivers/net/tulip/de4x5.c 2011-05-22 19:36:31.000000000 -0400
35343@@ -5401,7 +5401,7 @@ de4x5_ioctl(struct net_device *dev, stru
35344 for (i=0; i<ETH_ALEN; i++) {
35345 tmp.addr[i] = dev->dev_addr[i];
35346 }
35347- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
35348+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
35349 break;
35350
35351 case DE4X5_SET_HWADDR: /* Set the hardware address */
35352@@ -5441,7 +5441,7 @@ de4x5_ioctl(struct net_device *dev, stru
35353 spin_lock_irqsave(&lp->lock, flags);
35354 memcpy(&statbuf, &lp->pktStats, ioc->len);
35355 spin_unlock_irqrestore(&lp->lock, flags);
35356- if (copy_to_user(ioc->data, &statbuf, ioc->len))
35357+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
35358 return -EFAULT;
35359 break;
35360 }
35361diff -urNp linux-2.6.39.1/drivers/net/usb/asix.c linux-2.6.39.1/drivers/net/usb/asix.c
35362--- linux-2.6.39.1/drivers/net/usb/asix.c 2011-05-19 00:06:34.000000000 -0400
35363+++ linux-2.6.39.1/drivers/net/usb/asix.c 2011-05-22 19:36:31.000000000 -0400
35364@@ -1098,7 +1098,7 @@ out:
35365 return ret;
35366 }
35367
35368-static struct ethtool_ops ax88178_ethtool_ops = {
35369+static const struct ethtool_ops ax88178_ethtool_ops = {
35370 .get_drvinfo = asix_get_drvinfo,
35371 .get_link = asix_get_link,
35372 .get_msglevel = usbnet_get_msglevel,
35373diff -urNp linux-2.6.39.1/drivers/net/usb/cdc_ncm.c linux-2.6.39.1/drivers/net/usb/cdc_ncm.c
35374--- linux-2.6.39.1/drivers/net/usb/cdc_ncm.c 2011-05-19 00:06:34.000000000 -0400
35375+++ linux-2.6.39.1/drivers/net/usb/cdc_ncm.c 2011-05-22 19:36:31.000000000 -0400
35376@@ -141,7 +141,7 @@ struct cdc_ncm_ctx {
35377 static void cdc_ncm_tx_timeout(unsigned long arg);
35378 static const struct driver_info cdc_ncm_info;
35379 static struct usb_driver cdc_ncm_driver;
35380-static struct ethtool_ops cdc_ncm_ethtool_ops;
35381+static const struct ethtool_ops cdc_ncm_ethtool_ops;
35382
35383 static const struct usb_device_id cdc_devs[] = {
35384 { USB_INTERFACE_INFO(USB_CLASS_COMM,
35385@@ -1257,7 +1257,7 @@ static struct usb_driver cdc_ncm_driver
35386 .supports_autosuspend = 1,
35387 };
35388
35389-static struct ethtool_ops cdc_ncm_ethtool_ops = {
35390+static const struct ethtool_ops cdc_ncm_ethtool_ops = {
35391 .get_drvinfo = cdc_ncm_get_drvinfo,
35392 .get_link = usbnet_get_link,
35393 .get_msglevel = usbnet_get_msglevel,
35394diff -urNp linux-2.6.39.1/drivers/net/usb/hso.c linux-2.6.39.1/drivers/net/usb/hso.c
35395--- linux-2.6.39.1/drivers/net/usb/hso.c 2011-05-19 00:06:34.000000000 -0400
35396+++ linux-2.6.39.1/drivers/net/usb/hso.c 2011-05-22 19:36:31.000000000 -0400
35397@@ -71,7 +71,7 @@
35398 #include <asm/byteorder.h>
35399 #include <linux/serial_core.h>
35400 #include <linux/serial.h>
35401-
35402+#include <asm/local.h>
35403
35404 #define MOD_AUTHOR "Option Wireless"
35405 #define MOD_DESCRIPTION "USB High Speed Option driver"
35406@@ -257,7 +257,7 @@ struct hso_serial {
35407
35408 /* from usb_serial_port */
35409 struct tty_struct *tty;
35410- int open_count;
35411+ local_t open_count;
35412 spinlock_t serial_lock;
35413
35414 int (*write_data) (struct hso_serial *serial);
35415@@ -1190,7 +1190,7 @@ static void put_rxbuf_data_and_resubmit_
35416 struct urb *urb;
35417
35418 urb = serial->rx_urb[0];
35419- if (serial->open_count > 0) {
35420+ if (local_read(&serial->open_count) > 0) {
35421 count = put_rxbuf_data(urb, serial);
35422 if (count == -1)
35423 return;
35424@@ -1226,7 +1226,7 @@ static void hso_std_serial_read_bulk_cal
35425 DUMP1(urb->transfer_buffer, urb->actual_length);
35426
35427 /* Anyone listening? */
35428- if (serial->open_count == 0)
35429+ if (local_read(&serial->open_count) == 0)
35430 return;
35431
35432 if (status == 0) {
35433@@ -1311,8 +1311,7 @@ static int hso_serial_open(struct tty_st
35434 spin_unlock_irq(&serial->serial_lock);
35435
35436 /* check for port already opened, if not set the termios */
35437- serial->open_count++;
35438- if (serial->open_count == 1) {
35439+ if (local_inc_return(&serial->open_count) == 1) {
35440 serial->rx_state = RX_IDLE;
35441 /* Force default termio settings */
35442 _hso_serial_set_termios(tty, NULL);
35443@@ -1324,7 +1323,7 @@ static int hso_serial_open(struct tty_st
35444 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35445 if (result) {
35446 hso_stop_serial_device(serial->parent);
35447- serial->open_count--;
35448+ local_dec(&serial->open_count);
35449 kref_put(&serial->parent->ref, hso_serial_ref_free);
35450 }
35451 } else {
35452@@ -1361,10 +1360,10 @@ static void hso_serial_close(struct tty_
35453
35454 /* reset the rts and dtr */
35455 /* do the actual close */
35456- serial->open_count--;
35457+ local_dec(&serial->open_count);
35458
35459- if (serial->open_count <= 0) {
35460- serial->open_count = 0;
35461+ if (local_read(&serial->open_count) <= 0) {
35462+ local_set(&serial->open_count, 0);
35463 spin_lock_irq(&serial->serial_lock);
35464 if (serial->tty == tty) {
35465 serial->tty->driver_data = NULL;
35466@@ -1446,7 +1445,7 @@ static void hso_serial_set_termios(struc
35467
35468 /* the actual setup */
35469 spin_lock_irqsave(&serial->serial_lock, flags);
35470- if (serial->open_count)
35471+ if (local_read(&serial->open_count))
35472 _hso_serial_set_termios(tty, old);
35473 else
35474 tty->termios = old;
35475@@ -1905,7 +1904,7 @@ static void intr_callback(struct urb *ur
35476 D1("Pending read interrupt on port %d\n", i);
35477 spin_lock(&serial->serial_lock);
35478 if (serial->rx_state == RX_IDLE &&
35479- serial->open_count > 0) {
35480+ local_read(&serial->open_count) > 0) {
35481 /* Setup and send a ctrl req read on
35482 * port i */
35483 if (!serial->rx_urb_filled[0]) {
35484@@ -3097,7 +3096,7 @@ static int hso_resume(struct usb_interfa
35485 /* Start all serial ports */
35486 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35487 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35488- if (dev2ser(serial_table[i])->open_count) {
35489+ if (local_read(&dev2ser(serial_table[i])->open_count)) {
35490 result =
35491 hso_start_serial_device(serial_table[i], GFP_NOIO);
35492 hso_kick_transmit(dev2ser(serial_table[i]));
35493diff -urNp linux-2.6.39.1/drivers/net/usb/ipheth.c linux-2.6.39.1/drivers/net/usb/ipheth.c
35494--- linux-2.6.39.1/drivers/net/usb/ipheth.c 2011-05-19 00:06:34.000000000 -0400
35495+++ linux-2.6.39.1/drivers/net/usb/ipheth.c 2011-05-22 19:36:31.000000000 -0400
35496@@ -421,7 +421,7 @@ static u32 ipheth_ethtool_op_get_link(st
35497 return netif_carrier_ok(dev->net);
35498 }
35499
35500-static struct ethtool_ops ops = {
35501+static const struct ethtool_ops ops = {
35502 .get_link = ipheth_ethtool_op_get_link
35503 };
35504
35505diff -urNp linux-2.6.39.1/drivers/net/usb/sierra_net.c linux-2.6.39.1/drivers/net/usb/sierra_net.c
35506--- linux-2.6.39.1/drivers/net/usb/sierra_net.c 2011-05-19 00:06:34.000000000 -0400
35507+++ linux-2.6.39.1/drivers/net/usb/sierra_net.c 2011-05-22 19:36:31.000000000 -0400
35508@@ -618,7 +618,7 @@ static u32 sierra_net_get_link(struct ne
35509 return sierra_net_get_private(dev)->link_up && netif_running(net);
35510 }
35511
35512-static struct ethtool_ops sierra_net_ethtool_ops = {
35513+static const struct ethtool_ops sierra_net_ethtool_ops = {
35514 .get_drvinfo = sierra_net_get_drvinfo,
35515 .get_link = sierra_net_get_link,
35516 .get_msglevel = usbnet_get_msglevel,
35517diff -urNp linux-2.6.39.1/drivers/net/vmxnet3/vmxnet3_ethtool.c linux-2.6.39.1/drivers/net/vmxnet3/vmxnet3_ethtool.c
35518--- linux-2.6.39.1/drivers/net/vmxnet3/vmxnet3_ethtool.c 2011-05-19 00:06:34.000000000 -0400
35519+++ linux-2.6.39.1/drivers/net/vmxnet3/vmxnet3_ethtool.c 2011-05-22 19:36:31.000000000 -0400
35520@@ -631,8 +631,7 @@ vmxnet3_set_rss_indir(struct net_device
35521 * Return with error code if any of the queue indices
35522 * is out of range
35523 */
35524- if (p->ring_index[i] < 0 ||
35525- p->ring_index[i] >= adapter->num_rx_queues)
35526+ if (p->ring_index[i] >= adapter->num_rx_queues)
35527 return -EINVAL;
35528 }
35529
35530diff -urNp linux-2.6.39.1/drivers/net/vxge/vxge-main.c linux-2.6.39.1/drivers/net/vxge/vxge-main.c
35531--- linux-2.6.39.1/drivers/net/vxge/vxge-main.c 2011-05-19 00:06:34.000000000 -0400
35532+++ linux-2.6.39.1/drivers/net/vxge/vxge-main.c 2011-05-22 19:36:31.000000000 -0400
35533@@ -97,6 +97,8 @@ static inline void VXGE_COMPLETE_VPATH_T
35534 struct sk_buff *completed[NR_SKB_COMPLETED];
35535 int more;
35536
35537+ pax_track_stack();
35538+
35539 do {
35540 more = 0;
35541 skb_ptr = completed;
35542@@ -1927,6 +1929,8 @@ static enum vxge_hw_status vxge_rth_conf
35543 u8 mtable[256] = {0}; /* CPU to vpath mapping */
35544 int index;
35545
35546+ pax_track_stack();
35547+
35548 /*
35549 * Filling
35550 * - itable with bucket numbers
35551diff -urNp linux-2.6.39.1/drivers/net/wan/cycx_x25.c linux-2.6.39.1/drivers/net/wan/cycx_x25.c
35552--- linux-2.6.39.1/drivers/net/wan/cycx_x25.c 2011-05-19 00:06:34.000000000 -0400
35553+++ linux-2.6.39.1/drivers/net/wan/cycx_x25.c 2011-05-22 19:36:31.000000000 -0400
35554@@ -1018,6 +1018,8 @@ static void hex_dump(char *msg, unsigned
35555 unsigned char hex[1024],
35556 * phex = hex;
35557
35558+ pax_track_stack();
35559+
35560 if (len >= (sizeof(hex) / 2))
35561 len = (sizeof(hex) / 2) - 1;
35562
35563diff -urNp linux-2.6.39.1/drivers/net/wan/lapbether.c linux-2.6.39.1/drivers/net/wan/lapbether.c
35564--- linux-2.6.39.1/drivers/net/wan/lapbether.c 2011-05-19 00:06:34.000000000 -0400
35565+++ linux-2.6.39.1/drivers/net/wan/lapbether.c 2011-05-22 19:36:31.000000000 -0400
35566@@ -259,7 +259,7 @@ static int lapbeth_set_mac_address(struc
35567 }
35568
35569
35570-static struct lapb_register_struct lapbeth_callbacks = {
35571+static const struct lapb_register_struct lapbeth_callbacks = {
35572 .connect_confirmation = lapbeth_connected,
35573 .connect_indication = lapbeth_connected,
35574 .disconnect_confirmation = lapbeth_disconnected,
35575diff -urNp linux-2.6.39.1/drivers/net/wan/x25_asy.c linux-2.6.39.1/drivers/net/wan/x25_asy.c
35576--- linux-2.6.39.1/drivers/net/wan/x25_asy.c 2011-05-19 00:06:34.000000000 -0400
35577+++ linux-2.6.39.1/drivers/net/wan/x25_asy.c 2011-05-22 19:36:31.000000000 -0400
35578@@ -434,7 +434,7 @@ static void x25_asy_disconnected(struct
35579 netif_rx(skb);
35580 }
35581
35582-static struct lapb_register_struct x25_asy_callbacks = {
35583+static const struct lapb_register_struct x25_asy_callbacks = {
35584 .connect_confirmation = x25_asy_connected,
35585 .connect_indication = x25_asy_connected,
35586 .disconnect_confirmation = x25_asy_disconnected,
35587diff -urNp linux-2.6.39.1/drivers/net/wimax/i2400m/usb-fw.c linux-2.6.39.1/drivers/net/wimax/i2400m/usb-fw.c
35588--- linux-2.6.39.1/drivers/net/wimax/i2400m/usb-fw.c 2011-05-19 00:06:34.000000000 -0400
35589+++ linux-2.6.39.1/drivers/net/wimax/i2400m/usb-fw.c 2011-05-22 19:36:31.000000000 -0400
35590@@ -287,6 +287,8 @@ ssize_t i2400mu_bus_bm_wait_for_ack(stru
35591 int do_autopm = 1;
35592 DECLARE_COMPLETION_ONSTACK(notif_completion);
35593
35594+ pax_track_stack();
35595+
35596 d_fnstart(8, dev, "(i2400m %p ack %p size %zu)\n",
35597 i2400m, ack, ack_size);
35598 BUG_ON(_ack == i2400m->bm_ack_buf);
35599diff -urNp linux-2.6.39.1/drivers/net/wireless/airo.c linux-2.6.39.1/drivers/net/wireless/airo.c
35600--- linux-2.6.39.1/drivers/net/wireless/airo.c 2011-05-19 00:06:34.000000000 -0400
35601+++ linux-2.6.39.1/drivers/net/wireless/airo.c 2011-05-22 19:36:31.000000000 -0400
35602@@ -3001,6 +3001,8 @@ static void airo_process_scan_results (s
35603 BSSListElement * loop_net;
35604 BSSListElement * tmp_net;
35605
35606+ pax_track_stack();
35607+
35608 /* Blow away current list of scan results */
35609 list_for_each_entry_safe (loop_net, tmp_net, &ai->network_list, list) {
35610 list_move_tail (&loop_net->list, &ai->network_free_list);
35611@@ -3792,6 +3794,8 @@ static u16 setup_card(struct airo_info *
35612 WepKeyRid wkr;
35613 int rc;
35614
35615+ pax_track_stack();
35616+
35617 memset( &mySsid, 0, sizeof( mySsid ) );
35618 kfree (ai->flash);
35619 ai->flash = NULL;
35620@@ -4760,6 +4764,8 @@ static int proc_stats_rid_open( struct i
35621 __le32 *vals = stats.vals;
35622 int len;
35623
35624+ pax_track_stack();
35625+
35626 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
35627 return -ENOMEM;
35628 data = file->private_data;
35629@@ -5483,6 +5489,8 @@ static int proc_BSSList_open( struct ino
35630 /* If doLoseSync is not 1, we won't do a Lose Sync */
35631 int doLoseSync = -1;
35632
35633+ pax_track_stack();
35634+
35635 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
35636 return -ENOMEM;
35637 data = file->private_data;
35638@@ -7190,6 +7198,8 @@ static int airo_get_aplist(struct net_de
35639 int i;
35640 int loseSync = capable(CAP_NET_ADMIN) ? 1: -1;
35641
35642+ pax_track_stack();
35643+
35644 qual = kmalloc(IW_MAX_AP * sizeof(*qual), GFP_KERNEL);
35645 if (!qual)
35646 return -ENOMEM;
35647@@ -7750,6 +7760,8 @@ static void airo_read_wireless_stats(str
35648 CapabilityRid cap_rid;
35649 __le32 *vals = stats_rid.vals;
35650
35651+ pax_track_stack();
35652+
35653 /* Get stats out of the card */
35654 clear_bit(JOB_WSTATS, &local->jobs);
35655 if (local->power.event) {
35656diff -urNp linux-2.6.39.1/drivers/net/wireless/ath/ath5k/debug.c linux-2.6.39.1/drivers/net/wireless/ath/ath5k/debug.c
35657--- linux-2.6.39.1/drivers/net/wireless/ath/ath5k/debug.c 2011-05-19 00:06:34.000000000 -0400
35658+++ linux-2.6.39.1/drivers/net/wireless/ath/ath5k/debug.c 2011-05-22 19:36:31.000000000 -0400
35659@@ -204,6 +204,8 @@ static ssize_t read_file_beacon(struct f
35660 unsigned int v;
35661 u64 tsf;
35662
35663+ pax_track_stack();
35664+
35665 v = ath5k_hw_reg_read(sc->ah, AR5K_BEACON);
35666 len += snprintf(buf+len, sizeof(buf)-len,
35667 "%-24s0x%08x\tintval: %d\tTIM: 0x%x\n",
35668@@ -323,6 +325,8 @@ static ssize_t read_file_debug(struct fi
35669 unsigned int len = 0;
35670 unsigned int i;
35671
35672+ pax_track_stack();
35673+
35674 len += snprintf(buf+len, sizeof(buf)-len,
35675 "DEBUG LEVEL: 0x%08x\n\n", sc->debug.level);
35676
35677@@ -384,6 +388,8 @@ static ssize_t read_file_antenna(struct
35678 unsigned int i;
35679 unsigned int v;
35680
35681+ pax_track_stack();
35682+
35683 len += snprintf(buf+len, sizeof(buf)-len, "antenna mode\t%d\n",
35684 sc->ah->ah_ant_mode);
35685 len += snprintf(buf+len, sizeof(buf)-len, "default antenna\t%d\n",
35686@@ -494,6 +500,8 @@ static ssize_t read_file_misc(struct fil
35687 unsigned int len = 0;
35688 u32 filt = ath5k_hw_get_rx_filter(sc->ah);
35689
35690+ pax_track_stack();
35691+
35692 len += snprintf(buf+len, sizeof(buf)-len, "bssid-mask: %pM\n",
35693 sc->bssidmask);
35694 len += snprintf(buf+len, sizeof(buf)-len, "filter-flags: 0x%x ",
35695@@ -550,6 +558,8 @@ static ssize_t read_file_frameerrors(str
35696 unsigned int len = 0;
35697 int i;
35698
35699+ pax_track_stack();
35700+
35701 len += snprintf(buf+len, sizeof(buf)-len,
35702 "RX\n---------------------\n");
35703 len += snprintf(buf+len, sizeof(buf)-len, "CRC\t%u\t(%u%%)\n",
35704@@ -667,6 +677,8 @@ static ssize_t read_file_ani(struct file
35705 char buf[700];
35706 unsigned int len = 0;
35707
35708+ pax_track_stack();
35709+
35710 len += snprintf(buf+len, sizeof(buf)-len,
35711 "HW has PHY error counters:\t%s\n",
35712 sc->ah->ah_capabilities.cap_has_phyerr_counters ?
35713@@ -827,6 +839,8 @@ static ssize_t read_file_queue(struct fi
35714 struct ath5k_buf *bf, *bf0;
35715 int i, n;
35716
35717+ pax_track_stack();
35718+
35719 len += snprintf(buf+len, sizeof(buf)-len,
35720 "available txbuffers: %d\n", sc->txbuf_len);
35721
35722diff -urNp linux-2.6.39.1/drivers/net/wireless/ath/ath9k/ar9003_calib.c linux-2.6.39.1/drivers/net/wireless/ath/ath9k/ar9003_calib.c
35723--- linux-2.6.39.1/drivers/net/wireless/ath/ath9k/ar9003_calib.c 2011-05-19 00:06:34.000000000 -0400
35724+++ linux-2.6.39.1/drivers/net/wireless/ath/ath9k/ar9003_calib.c 2011-05-22 19:36:31.000000000 -0400
35725@@ -734,6 +734,8 @@ static void ar9003_hw_tx_iq_cal(struct a
35726 s32 i, j, ip, im, nmeasurement;
35727 u8 nchains = get_streams(common->tx_chainmask);
35728
35729+ pax_track_stack();
35730+
35731 for (ip = 0; ip < MPASS; ip++) {
35732 REG_RMW_FIELD(ah, AR_PHY_TX_IQCAL_CONTROL_1,
35733 AR_PHY_TX_IQCAQL_CONTROL_1_IQCORR_I_Q_COFF_DELPT,
35734@@ -856,6 +858,8 @@ static void ar9003_hw_tx_iq_cal_post_pro
35735 int i, ip, im, j;
35736 int nmeasurement;
35737
35738+ pax_track_stack();
35739+
35740 for (i = 0; i < AR9300_MAX_CHAINS; i++) {
35741 if (ah->txchainmask & (1 << i))
35742 num_chains++;
35743diff -urNp linux-2.6.39.1/drivers/net/wireless/ath/ath9k/ar9003_paprd.c linux-2.6.39.1/drivers/net/wireless/ath/ath9k/ar9003_paprd.c
35744--- linux-2.6.39.1/drivers/net/wireless/ath/ath9k/ar9003_paprd.c 2011-05-19 00:06:34.000000000 -0400
35745+++ linux-2.6.39.1/drivers/net/wireless/ath/ath9k/ar9003_paprd.c 2011-05-22 19:36:31.000000000 -0400
35746@@ -356,6 +356,8 @@ static bool create_pa_curve(u32 *data_L,
35747 int theta_low_bin = 0;
35748 int i;
35749
35750+ pax_track_stack();
35751+
35752 /* disregard any bin that contains <= 16 samples */
35753 thresh_accum_cnt = 16;
35754 scale_factor = 5;
35755diff -urNp linux-2.6.39.1/drivers/net/wireless/ath/ath9k/debug.c linux-2.6.39.1/drivers/net/wireless/ath/ath9k/debug.c
35756--- linux-2.6.39.1/drivers/net/wireless/ath/ath9k/debug.c 2011-05-19 00:06:34.000000000 -0400
35757+++ linux-2.6.39.1/drivers/net/wireless/ath/ath9k/debug.c 2011-05-22 19:36:31.000000000 -0400
35758@@ -335,6 +335,8 @@ static ssize_t read_file_interrupt(struc
35759 char buf[512];
35760 unsigned int len = 0;
35761
35762+ pax_track_stack();
35763+
35764 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
35765 len += snprintf(buf + len, sizeof(buf) - len,
35766 "%8s: %10u\n", "RXLP", sc->debug.stats.istats.rxlp);
35767@@ -422,6 +424,8 @@ static ssize_t read_file_wiphy(struct fi
35768 u8 addr[ETH_ALEN];
35769 u32 tmp;
35770
35771+ pax_track_stack();
35772+
35773 len += snprintf(buf + len, sizeof(buf) - len,
35774 "%s (chan=%d center-freq: %d MHz channel-type: %d (%s))\n",
35775 wiphy_name(sc->hw->wiphy),
35776diff -urNp linux-2.6.39.1/drivers/net/wireless/ath/ath9k/htc_drv_main.c linux-2.6.39.1/drivers/net/wireless/ath/ath9k/htc_drv_main.c
35777--- linux-2.6.39.1/drivers/net/wireless/ath/ath9k/htc_drv_main.c 2011-05-19 00:06:34.000000000 -0400
35778+++ linux-2.6.39.1/drivers/net/wireless/ath/ath9k/htc_drv_main.c 2011-05-22 19:36:31.000000000 -0400
35779@@ -737,6 +737,8 @@ static ssize_t read_file_tgt_stats(struc
35780 unsigned int len = 0;
35781 int ret = 0;
35782
35783+ pax_track_stack();
35784+
35785 memset(&cmd_rsp, 0, sizeof(cmd_rsp));
35786
35787 WMI_CMD(WMI_TGT_STATS_CMDID);
35788@@ -782,6 +784,8 @@ static ssize_t read_file_xmit(struct fil
35789 char buf[512];
35790 unsigned int len = 0;
35791
35792+ pax_track_stack();
35793+
35794 len += snprintf(buf + len, sizeof(buf) - len,
35795 "%20s : %10u\n", "Buffers queued",
35796 priv->debug.tx_stats.buf_queued);
35797@@ -831,6 +835,8 @@ static ssize_t read_file_recv(struct fil
35798 char buf[512];
35799 unsigned int len = 0;
35800
35801+ pax_track_stack();
35802+
35803 len += snprintf(buf + len, sizeof(buf) - len,
35804 "%20s : %10u\n", "SKBs allocated",
35805 priv->debug.rx_stats.skb_allocated);
35806@@ -1816,7 +1822,7 @@ static void ath9k_htc_set_coverage_class
35807 mutex_unlock(&priv->mutex);
35808 }
35809
35810-struct ieee80211_ops ath9k_htc_ops = {
35811+const struct ieee80211_ops ath9k_htc_ops = {
35812 .tx = ath9k_htc_tx,
35813 .start = ath9k_htc_start,
35814 .stop = ath9k_htc_stop,
35815diff -urNp linux-2.6.39.1/drivers/net/wireless/ath/ath9k/htc.h linux-2.6.39.1/drivers/net/wireless/ath/ath9k/htc.h
35816--- linux-2.6.39.1/drivers/net/wireless/ath/ath9k/htc.h 2011-05-19 00:06:34.000000000 -0400
35817+++ linux-2.6.39.1/drivers/net/wireless/ath/ath9k/htc.h 2011-05-22 19:36:31.000000000 -0400
35818@@ -42,7 +42,7 @@
35819 #define TSF_TO_TU(_h, _l) \
35820 ((((u32)(_h)) << 22) | (((u32)(_l)) >> 10))
35821
35822-extern struct ieee80211_ops ath9k_htc_ops;
35823+extern const struct ieee80211_ops ath9k_htc_ops;
35824 extern int htc_modparam_nohwcrypt;
35825
35826 enum htc_phymode {
35827diff -urNp linux-2.6.39.1/drivers/net/wireless/b43/debugfs.c linux-2.6.39.1/drivers/net/wireless/b43/debugfs.c
35828--- linux-2.6.39.1/drivers/net/wireless/b43/debugfs.c 2011-05-19 00:06:34.000000000 -0400
35829+++ linux-2.6.39.1/drivers/net/wireless/b43/debugfs.c 2011-05-22 19:36:31.000000000 -0400
35830@@ -43,7 +43,7 @@ static struct dentry *rootdir;
35831 struct b43_debugfs_fops {
35832 ssize_t (*read)(struct b43_wldev *dev, char *buf, size_t bufsize);
35833 int (*write)(struct b43_wldev *dev, const char *buf, size_t count);
35834- struct file_operations fops;
35835+ const struct file_operations fops;
35836 /* Offset of struct b43_dfs_file in struct b43_dfsentry */
35837 size_t file_struct_offset;
35838 };
35839diff -urNp linux-2.6.39.1/drivers/net/wireless/b43legacy/debugfs.c linux-2.6.39.1/drivers/net/wireless/b43legacy/debugfs.c
35840--- linux-2.6.39.1/drivers/net/wireless/b43legacy/debugfs.c 2011-05-19 00:06:34.000000000 -0400
35841+++ linux-2.6.39.1/drivers/net/wireless/b43legacy/debugfs.c 2011-05-22 19:36:31.000000000 -0400
35842@@ -44,7 +44,7 @@ static struct dentry *rootdir;
35843 struct b43legacy_debugfs_fops {
35844 ssize_t (*read)(struct b43legacy_wldev *dev, char *buf, size_t bufsize);
35845 int (*write)(struct b43legacy_wldev *dev, const char *buf, size_t count);
35846- struct file_operations fops;
35847+ const struct file_operations fops;
35848 /* Offset of struct b43legacy_dfs_file in struct b43legacy_dfsentry */
35849 size_t file_struct_offset;
35850 /* Take wl->irq_lock before calling read/write? */
35851diff -urNp linux-2.6.39.1/drivers/net/wireless/ipw2x00/ipw2100.c linux-2.6.39.1/drivers/net/wireless/ipw2x00/ipw2100.c
35852--- linux-2.6.39.1/drivers/net/wireless/ipw2x00/ipw2100.c 2011-05-19 00:06:34.000000000 -0400
35853+++ linux-2.6.39.1/drivers/net/wireless/ipw2x00/ipw2100.c 2011-05-22 19:36:31.000000000 -0400
35854@@ -2100,6 +2100,8 @@ static int ipw2100_set_essid(struct ipw2
35855 int err;
35856 DECLARE_SSID_BUF(ssid);
35857
35858+ pax_track_stack();
35859+
35860 IPW_DEBUG_HC("SSID: '%s'\n", print_ssid(ssid, essid, ssid_len));
35861
35862 if (ssid_len)
35863@@ -5449,6 +5451,8 @@ static int ipw2100_set_key(struct ipw210
35864 struct ipw2100_wep_key *wep_key = (void *)cmd.host_command_parameters;
35865 int err;
35866
35867+ pax_track_stack();
35868+
35869 IPW_DEBUG_HC("WEP_KEY_INFO: index = %d, len = %d/%d\n",
35870 idx, keylen, len);
35871
35872diff -urNp linux-2.6.39.1/drivers/net/wireless/ipw2x00/libipw_rx.c linux-2.6.39.1/drivers/net/wireless/ipw2x00/libipw_rx.c
35873--- linux-2.6.39.1/drivers/net/wireless/ipw2x00/libipw_rx.c 2011-05-19 00:06:34.000000000 -0400
35874+++ linux-2.6.39.1/drivers/net/wireless/ipw2x00/libipw_rx.c 2011-05-22 19:36:31.000000000 -0400
35875@@ -1565,6 +1565,8 @@ static void libipw_process_probe_respons
35876 unsigned long flags;
35877 DECLARE_SSID_BUF(ssid);
35878
35879+ pax_track_stack();
35880+
35881 LIBIPW_DEBUG_SCAN("'%s' (%pM"
35882 "): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
35883 print_ssid(ssid, info_element->data, info_element->len),
35884diff -urNp linux-2.6.39.1/drivers/net/wireless/iwlegacy/iwl-3945.c linux-2.6.39.1/drivers/net/wireless/iwlegacy/iwl-3945.c
35885--- linux-2.6.39.1/drivers/net/wireless/iwlegacy/iwl-3945.c 2011-05-19 00:06:34.000000000 -0400
35886+++ linux-2.6.39.1/drivers/net/wireless/iwlegacy/iwl-3945.c 2011-05-22 19:36:31.000000000 -0400
35887@@ -2630,7 +2630,7 @@ static int iwl3945_load_bsm(struct iwl_p
35888 return 0;
35889 }
35890
35891-static struct iwl_hcmd_ops iwl3945_hcmd = {
35892+static const struct iwl_hcmd_ops iwl3945_hcmd = {
35893 .rxon_assoc = iwl3945_send_rxon_assoc,
35894 .commit_rxon = iwl3945_commit_rxon,
35895 };
35896@@ -2675,7 +2675,7 @@ static const struct iwl_legacy_ops iwl39
35897 .manage_ibss_station = iwl3945_manage_ibss_station,
35898 };
35899
35900-static struct iwl_hcmd_utils_ops iwl3945_hcmd_utils = {
35901+static const struct iwl_hcmd_utils_ops iwl3945_hcmd_utils = {
35902 .get_hcmd_size = iwl3945_get_hcmd_size,
35903 .build_addsta_hcmd = iwl3945_build_addsta_hcmd,
35904 .request_scan = iwl3945_request_scan,
35905diff -urNp linux-2.6.39.1/drivers/net/wireless/iwlegacy/iwl-4965.c linux-2.6.39.1/drivers/net/wireless/iwlegacy/iwl-4965.c
35906--- linux-2.6.39.1/drivers/net/wireless/iwlegacy/iwl-4965.c 2011-05-19 00:06:34.000000000 -0400
35907+++ linux-2.6.39.1/drivers/net/wireless/iwlegacy/iwl-4965.c 2011-05-22 19:36:32.000000000 -0400
35908@@ -1904,7 +1904,7 @@ static void iwl4965_rx_handler_setup(str
35909 priv->rx_handlers[BEACON_NOTIFICATION] = iwl4965_rx_beacon_notif;
35910 }
35911
35912-static struct iwl_hcmd_ops iwl4965_hcmd = {
35913+static const struct iwl_hcmd_ops iwl4965_hcmd = {
35914 .rxon_assoc = iwl4965_send_rxon_assoc,
35915 .commit_rxon = iwl4965_commit_rxon,
35916 .set_rxon_chain = iwl4965_set_rxon_chain,
35917@@ -2056,7 +2056,7 @@ static void iwl4965_config_ap(struct iwl
35918 iwl4965_send_beacon_cmd(priv);
35919 }
35920
35921-static struct iwl_hcmd_utils_ops iwl4965_hcmd_utils = {
35922+static const struct iwl_hcmd_utils_ops iwl4965_hcmd_utils = {
35923 .get_hcmd_size = iwl4965_get_hcmd_size,
35924 .build_addsta_hcmd = iwl4965_build_addsta_hcmd,
35925 .request_scan = iwl4965_request_scan,
35926@@ -2114,7 +2114,7 @@ static const struct iwl_legacy_ops iwl49
35927 .update_bcast_stations = iwl4965_update_bcast_stations,
35928 };
35929
35930-struct ieee80211_ops iwl4965_hw_ops = {
35931+const struct ieee80211_ops iwl4965_hw_ops = {
35932 .tx = iwl4965_mac_tx,
35933 .start = iwl4965_mac_start,
35934 .stop = iwl4965_mac_stop,
35935diff -urNp linux-2.6.39.1/drivers/net/wireless/iwlegacy/iwl-4965.h linux-2.6.39.1/drivers/net/wireless/iwlegacy/iwl-4965.h
35936--- linux-2.6.39.1/drivers/net/wireless/iwlegacy/iwl-4965.h 2011-05-19 00:06:34.000000000 -0400
35937+++ linux-2.6.39.1/drivers/net/wireless/iwlegacy/iwl-4965.h 2011-05-22 19:36:32.000000000 -0400
35938@@ -70,7 +70,7 @@ extern struct iwl_cfg iwl4965_cfg;
35939
35940 extern struct iwl_mod_params iwl4965_mod_params;
35941
35942-extern struct ieee80211_ops iwl4965_hw_ops;
35943+extern const struct ieee80211_ops iwl4965_hw_ops;
35944
35945 /* tx queue */
35946 void iwl4965_free_tfds_in_queue(struct iwl_priv *priv,
35947diff -urNp linux-2.6.39.1/drivers/net/wireless/iwlegacy/iwl-core.h linux-2.6.39.1/drivers/net/wireless/iwlegacy/iwl-core.h
35948--- linux-2.6.39.1/drivers/net/wireless/iwlegacy/iwl-core.h 2011-05-19 00:06:34.000000000 -0400
35949+++ linux-2.6.39.1/drivers/net/wireless/iwlegacy/iwl-core.h 2011-05-22 19:36:32.000000000 -0400
35950@@ -150,7 +150,7 @@ struct iwl_lib_ops {
35951 int (*set_channel_switch)(struct iwl_priv *priv,
35952 struct ieee80211_channel_switch *ch_switch);
35953 /* power management */
35954- struct iwl_apm_ops apm_ops;
35955+ const struct iwl_apm_ops apm_ops;
35956
35957 /* power */
35958 int (*send_tx_power) (struct iwl_priv *priv);
35959@@ -160,12 +160,12 @@ struct iwl_lib_ops {
35960 struct iwl_eeprom_ops eeprom_ops;
35961
35962 /* temperature */
35963- struct iwl_temp_ops temp_ops;
35964+ const struct iwl_temp_ops temp_ops;
35965 /* check for plcp health */
35966 bool (*check_plcp_health)(struct iwl_priv *priv,
35967 struct iwl_rx_packet *pkt);
35968
35969- struct iwl_debugfs_ops debugfs_ops;
35970+ const struct iwl_debugfs_ops debugfs_ops;
35971
35972 };
35973
35974diff -urNp linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-6000.c linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-6000.c
35975--- linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-6000.c 2011-05-19 00:06:34.000000000 -0400
35976+++ linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-6000.c 2011-05-22 19:36:32.000000000 -0400
35977@@ -422,11 +422,11 @@ static struct iwl_lib_ops iwl6030_lib =
35978 }
35979 };
35980
35981-static struct iwl_nic_ops iwl6050_nic_ops = {
35982+static const struct iwl_nic_ops iwl6050_nic_ops = {
35983 .additional_nic_config = &iwl6050_additional_nic_config,
35984 };
35985
35986-static struct iwl_nic_ops iwl6150_nic_ops = {
35987+static const struct iwl_nic_ops iwl6150_nic_ops = {
35988 .additional_nic_config = &iwl6150_additional_nic_config,
35989 };
35990
35991diff -urNp linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-agn.h linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-agn.h
35992--- linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-agn.h 2011-05-19 00:06:34.000000000 -0400
35993+++ linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-agn.h 2011-05-22 19:36:32.000000000 -0400
35994@@ -109,9 +109,9 @@ extern struct iwl_cfg iwl230_bg_cfg;
35995 extern struct iwl_cfg iwl230_bgn_cfg;
35996
35997 extern struct iwl_mod_params iwlagn_mod_params;
35998-extern struct iwl_hcmd_ops iwlagn_hcmd;
35999-extern struct iwl_hcmd_ops iwlagn_bt_hcmd;
36000-extern struct iwl_hcmd_utils_ops iwlagn_hcmd_utils;
36001+extern const struct iwl_hcmd_ops iwlagn_hcmd;
36002+extern const struct iwl_hcmd_ops iwlagn_bt_hcmd;
36003+extern const struct iwl_hcmd_utils_ops iwlagn_hcmd_utils;
36004
36005 extern struct ieee80211_ops iwlagn_hw_ops;
36006 extern struct ieee80211_ops iwl4965_hw_ops;
36007diff -urNp linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-agn-hcmd.c linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-agn-hcmd.c
36008--- linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-agn-hcmd.c 2011-05-19 00:06:34.000000000 -0400
36009+++ linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-agn-hcmd.c 2011-05-22 19:36:32.000000000 -0400
36010@@ -363,7 +363,7 @@ static int iwlagn_set_pan_params(struct
36011 return ret;
36012 }
36013
36014-struct iwl_hcmd_ops iwlagn_hcmd = {
36015+const struct iwl_hcmd_ops iwlagn_hcmd = {
36016 .rxon_assoc = iwlagn_send_rxon_assoc,
36017 .commit_rxon = iwlagn_commit_rxon,
36018 .set_rxon_chain = iwlagn_set_rxon_chain,
36019@@ -372,7 +372,7 @@ struct iwl_hcmd_ops iwlagn_hcmd = {
36020 .set_pan_params = iwlagn_set_pan_params,
36021 };
36022
36023-struct iwl_hcmd_ops iwlagn_bt_hcmd = {
36024+const struct iwl_hcmd_ops iwlagn_bt_hcmd = {
36025 .rxon_assoc = iwlagn_send_rxon_assoc,
36026 .commit_rxon = iwlagn_commit_rxon,
36027 .set_rxon_chain = iwlagn_set_rxon_chain,
36028@@ -381,7 +381,7 @@ struct iwl_hcmd_ops iwlagn_bt_hcmd = {
36029 .set_pan_params = iwlagn_set_pan_params,
36030 };
36031
36032-struct iwl_hcmd_utils_ops iwlagn_hcmd_utils = {
36033+const struct iwl_hcmd_utils_ops iwlagn_hcmd_utils = {
36034 .get_hcmd_size = iwlagn_get_hcmd_size,
36035 .build_addsta_hcmd = iwlagn_build_addsta_hcmd,
36036 .gain_computation = iwlagn_gain_computation,
36037diff -urNp linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-agn-rs.c linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
36038--- linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-agn-rs.c 2011-05-19 00:06:34.000000000 -0400
36039+++ linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-agn-rs.c 2011-05-22 19:36:32.000000000 -0400
36040@@ -883,6 +883,8 @@ static void rs_tx_status(void *priv_r, s
36041 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
36042 struct iwl_rxon_context *ctx = sta_priv->common.ctx;
36043
36044+ pax_track_stack();
36045+
36046 IWL_DEBUG_RATE_LIMIT(priv, "get frame ack response, update rate scale window\n");
36047
36048 /* Treat uninitialized rate scaling data same as non-existing. */
36049@@ -2894,6 +2896,8 @@ static void rs_fill_link_cmd(struct iwl_
36050 container_of(lq_sta, struct iwl_station_priv, lq_sta);
36051 struct iwl_link_quality_cmd *lq_cmd = &lq_sta->lq;
36052
36053+ pax_track_stack();
36054+
36055 /* Override starting rate (index 0) if needed for debug purposes */
36056 rs_dbgfs_set_mcs(lq_sta, &new_rate, index);
36057
36058diff -urNp linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-core.h linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-core.h
36059--- linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-core.h 2011-05-19 00:06:34.000000000 -0400
36060+++ linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-core.h 2011-05-22 19:36:32.000000000 -0400
36061@@ -198,28 +198,25 @@ struct iwl_lib_ops {
36062 int (*set_channel_switch)(struct iwl_priv *priv,
36063 struct ieee80211_channel_switch *ch_switch);
36064 /* power management */
36065- struct iwl_apm_ops apm_ops;
36066+ const struct iwl_apm_ops apm_ops;
36067
36068 /* power */
36069 int (*send_tx_power) (struct iwl_priv *priv);
36070 void (*update_chain_flags)(struct iwl_priv *priv);
36071
36072 /* isr */
36073- struct iwl_isr_ops isr_ops;
36074+ const struct iwl_isr_ops isr_ops;
36075
36076 /* eeprom operations (as defined in iwl-eeprom.h) */
36077 struct iwl_eeprom_ops eeprom_ops;
36078
36079 /* temperature */
36080- struct iwl_temp_ops temp_ops;
36081+ const struct iwl_temp_ops temp_ops;
36082
36083 int (*txfifo_flush)(struct iwl_priv *priv, u16 flush_control);
36084 void (*dev_txfifo_flush)(struct iwl_priv *priv, u16 flush_control);
36085
36086- struct iwl_debugfs_ops debugfs_ops;
36087-
36088- /* thermal throttling */
36089- struct iwl_tt_ops tt_ops;
36090+ const struct iwl_debugfs_ops debugfs_ops;const struct iwl_tt_ops tt_ops;
36091 };
36092
36093 struct iwl_led_ops {
36094diff -urNp linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-debugfs.c linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-debugfs.c
36095--- linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-debugfs.c 2011-05-19 00:06:34.000000000 -0400
36096+++ linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-debugfs.c 2011-05-22 19:36:32.000000000 -0400
36097@@ -549,6 +549,8 @@ static ssize_t iwl_dbgfs_status_read(str
36098 int pos = 0;
36099 const size_t bufsz = sizeof(buf);
36100
36101+ pax_track_stack();
36102+
36103 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_ACTIVE:\t %d\n",
36104 test_bit(STATUS_HCMD_ACTIVE, &priv->status));
36105 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INT_ENABLED:\t %d\n",
36106@@ -681,6 +683,8 @@ static ssize_t iwl_dbgfs_qos_read(struct
36107 char buf[256 * NUM_IWL_RXON_CTX];
36108 const size_t bufsz = sizeof(buf);
36109
36110+ pax_track_stack();
36111+
36112 for_each_context(priv, ctx) {
36113 pos += scnprintf(buf + pos, bufsz - pos, "context %d:\n",
36114 ctx->ctxid);
36115diff -urNp linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-debug.h linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-debug.h
36116--- linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-debug.h 2011-05-19 00:06:34.000000000 -0400
36117+++ linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-debug.h 2011-05-22 19:36:32.000000000 -0400
36118@@ -68,8 +68,8 @@ do {
36119 } while (0)
36120
36121 #else
36122-#define IWL_DEBUG(__priv, level, fmt, args...)
36123-#define IWL_DEBUG_LIMIT(__priv, level, fmt, args...)
36124+#define IWL_DEBUG(__priv, level, fmt, args...) do {} while (0)
36125+#define IWL_DEBUG_LIMIT(__priv, level, fmt, args...) do {} while (0)
36126 static inline void iwl_print_hex_dump(struct iwl_priv *priv, int level,
36127 const void *p, u32 len)
36128 {}
36129diff -urNp linux-2.6.39.1/drivers/net/wireless/iwmc3200wifi/cfg80211.c linux-2.6.39.1/drivers/net/wireless/iwmc3200wifi/cfg80211.c
36130--- linux-2.6.39.1/drivers/net/wireless/iwmc3200wifi/cfg80211.c 2011-05-19 00:06:34.000000000 -0400
36131+++ linux-2.6.39.1/drivers/net/wireless/iwmc3200wifi/cfg80211.c 2011-05-22 19:36:32.000000000 -0400
36132@@ -763,7 +763,7 @@ static int iwm_cfg80211_flush_pmksa(stru
36133 }
36134
36135
36136-static struct cfg80211_ops iwm_cfg80211_ops = {
36137+static const struct cfg80211_ops iwm_cfg80211_ops = {
36138 .change_virtual_intf = iwm_cfg80211_change_iface,
36139 .add_key = iwm_cfg80211_add_key,
36140 .get_key = iwm_cfg80211_get_key,
36141diff -urNp linux-2.6.39.1/drivers/net/wireless/iwmc3200wifi/debugfs.c linux-2.6.39.1/drivers/net/wireless/iwmc3200wifi/debugfs.c
36142--- linux-2.6.39.1/drivers/net/wireless/iwmc3200wifi/debugfs.c 2011-05-19 00:06:34.000000000 -0400
36143+++ linux-2.6.39.1/drivers/net/wireless/iwmc3200wifi/debugfs.c 2011-05-22 19:36:32.000000000 -0400
36144@@ -327,6 +327,8 @@ static ssize_t iwm_debugfs_fw_err_read(s
36145 int buf_len = 512;
36146 size_t len = 0;
36147
36148+ pax_track_stack();
36149+
36150 if (*ppos != 0)
36151 return 0;
36152 if (count < sizeof(buf))
36153diff -urNp linux-2.6.39.1/drivers/net/wireless/libertas/cfg.c linux-2.6.39.1/drivers/net/wireless/libertas/cfg.c
36154--- linux-2.6.39.1/drivers/net/wireless/libertas/cfg.c 2011-05-19 00:06:34.000000000 -0400
36155+++ linux-2.6.39.1/drivers/net/wireless/libertas/cfg.c 2011-05-22 19:36:32.000000000 -0400
36156@@ -2003,7 +2003,7 @@ static int lbs_leave_ibss(struct wiphy *
36157 * Initialization
36158 */
36159
36160-static struct cfg80211_ops lbs_cfg80211_ops = {
36161+static const struct cfg80211_ops lbs_cfg80211_ops = {
36162 .set_channel = lbs_cfg_set_channel,
36163 .scan = lbs_cfg_scan,
36164 .connect = lbs_cfg_connect,
36165diff -urNp linux-2.6.39.1/drivers/net/wireless/libertas/debugfs.c linux-2.6.39.1/drivers/net/wireless/libertas/debugfs.c
36166--- linux-2.6.39.1/drivers/net/wireless/libertas/debugfs.c 2011-05-19 00:06:34.000000000 -0400
36167+++ linux-2.6.39.1/drivers/net/wireless/libertas/debugfs.c 2011-05-22 19:36:32.000000000 -0400
36168@@ -702,7 +702,7 @@ out_unlock:
36169 struct lbs_debugfs_files {
36170 const char *name;
36171 int perm;
36172- struct file_operations fops;
36173+ const struct file_operations fops;
36174 };
36175
36176 static const struct lbs_debugfs_files debugfs_files[] = {
36177diff -urNp linux-2.6.39.1/drivers/net/wireless/rndis_wlan.c linux-2.6.39.1/drivers/net/wireless/rndis_wlan.c
36178--- linux-2.6.39.1/drivers/net/wireless/rndis_wlan.c 2011-05-19 00:06:34.000000000 -0400
36179+++ linux-2.6.39.1/drivers/net/wireless/rndis_wlan.c 2011-05-22 19:36:32.000000000 -0400
36180@@ -1277,7 +1277,7 @@ static int set_rts_threshold(struct usbn
36181
36182 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
36183
36184- if (rts_threshold < 0 || rts_threshold > 2347)
36185+ if (rts_threshold > 2347)
36186 rts_threshold = 2347;
36187
36188 tmp = cpu_to_le32(rts_threshold);
36189diff -urNp linux-2.6.39.1/drivers/net/wireless/rtlwifi/pci.c linux-2.6.39.1/drivers/net/wireless/rtlwifi/pci.c
36190--- linux-2.6.39.1/drivers/net/wireless/rtlwifi/pci.c 2011-05-19 00:06:34.000000000 -0400
36191+++ linux-2.6.39.1/drivers/net/wireless/rtlwifi/pci.c 2011-05-22 19:36:32.000000000 -0400
36192@@ -1869,7 +1869,7 @@ int rtl_pci_resume(struct pci_dev *pdev)
36193 }
36194 EXPORT_SYMBOL(rtl_pci_resume);
36195
36196-struct rtl_intf_ops rtl_pci_ops = {
36197+const struct rtl_intf_ops rtl_pci_ops = {
36198 .adapter_start = rtl_pci_start,
36199 .adapter_stop = rtl_pci_stop,
36200 .adapter_tx = rtl_pci_tx,
36201diff -urNp linux-2.6.39.1/drivers/net/wireless/rtlwifi/pci.h linux-2.6.39.1/drivers/net/wireless/rtlwifi/pci.h
36202--- linux-2.6.39.1/drivers/net/wireless/rtlwifi/pci.h 2011-05-19 00:06:34.000000000 -0400
36203+++ linux-2.6.39.1/drivers/net/wireless/rtlwifi/pci.h 2011-05-22 19:36:32.000000000 -0400
36204@@ -234,7 +234,7 @@ struct rtl_pci_priv {
36205
36206 int rtl_pci_reset_trx_ring(struct ieee80211_hw *hw);
36207
36208-extern struct rtl_intf_ops rtl_pci_ops;
36209+extern const struct rtl_intf_ops rtl_pci_ops;
36210
36211 int __devinit rtl_pci_probe(struct pci_dev *pdev,
36212 const struct pci_device_id *id);
36213diff -urNp linux-2.6.39.1/drivers/net/wireless/rtlwifi/rtl8192c/phy_common.c linux-2.6.39.1/drivers/net/wireless/rtlwifi/rtl8192c/phy_common.c
36214--- linux-2.6.39.1/drivers/net/wireless/rtlwifi/rtl8192c/phy_common.c 2011-05-19 00:06:34.000000000 -0400
36215+++ linux-2.6.39.1/drivers/net/wireless/rtlwifi/rtl8192c/phy_common.c 2011-05-22 19:36:32.000000000 -0400
36216@@ -827,6 +827,8 @@ static bool _rtl92c_phy_sw_chnl_step_by_
36217 u8 rfpath;
36218 u8 num_total_rfpath = rtlphy->num_total_rfpath;
36219
36220+ pax_track_stack();
36221+
36222 precommoncmdcnt = 0;
36223 _rtl92c_phy_set_sw_chnl_cmdarray(precommoncmd, precommoncmdcnt++,
36224 MAX_PRECMD_CNT,
36225diff -urNp linux-2.6.39.1/drivers/net/wireless/rtlwifi/rtl8192ce/sw.c linux-2.6.39.1/drivers/net/wireless/rtlwifi/rtl8192ce/sw.c
36226--- linux-2.6.39.1/drivers/net/wireless/rtlwifi/rtl8192ce/sw.c 2011-05-19 00:06:34.000000000 -0400
36227+++ linux-2.6.39.1/drivers/net/wireless/rtlwifi/rtl8192ce/sw.c 2011-05-22 19:36:32.000000000 -0400
36228@@ -96,7 +96,7 @@ void rtl92c_deinit_sw_vars(struct ieee80
36229 }
36230 }
36231
36232-static struct rtl_hal_ops rtl8192ce_hal_ops = {
36233+static const struct rtl_hal_ops rtl8192ce_hal_ops = {
36234 .init_sw_vars = rtl92c_init_sw_vars,
36235 .deinit_sw_vars = rtl92c_deinit_sw_vars,
36236 .read_eeprom_info = rtl92ce_read_eeprom_info,
36237@@ -151,7 +151,7 @@ static struct rtl_mod_params rtl92ce_mod
36238 .sw_crypto = 0,
36239 };
36240
36241-static struct rtl_hal_cfg rtl92ce_hal_cfg = {
36242+static const struct rtl_hal_cfg rtl92ce_hal_cfg = {
36243 .name = "rtl92c_pci",
36244 .fw_name = "rtlwifi/rtl8192cfw.bin",
36245 .ops = &rtl8192ce_hal_ops,
36246diff -urNp linux-2.6.39.1/drivers/net/wireless/rtlwifi/rtl8192cu/sw.c linux-2.6.39.1/drivers/net/wireless/rtlwifi/rtl8192cu/sw.c
36247--- linux-2.6.39.1/drivers/net/wireless/rtlwifi/rtl8192cu/sw.c 2011-05-19 00:06:34.000000000 -0400
36248+++ linux-2.6.39.1/drivers/net/wireless/rtlwifi/rtl8192cu/sw.c 2011-05-22 19:36:32.000000000 -0400
36249@@ -77,7 +77,7 @@ static void rtl92cu_deinit_sw_vars(struc
36250 }
36251 }
36252
36253-static struct rtl_hal_ops rtl8192cu_hal_ops = {
36254+static const struct rtl_hal_ops rtl8192cu_hal_ops = {
36255 .init_sw_vars = rtl92cu_init_sw_vars,
36256 .deinit_sw_vars = rtl92cu_deinit_sw_vars,
36257 .read_chip_version = rtl92c_read_chip_version,
36258@@ -147,7 +147,7 @@ static struct rtl_hal_usbint_cfg rtl92cu
36259 .usb_mq_to_hwq = rtl8192cu_mq_to_hwq,
36260 };
36261
36262-static struct rtl_hal_cfg rtl92cu_hal_cfg = {
36263+static const struct rtl_hal_cfg rtl92cu_hal_cfg = {
36264 .name = "rtl92c_usb",
36265 .fw_name = "rtlwifi/rtl8192cufw.bin",
36266 .ops = &rtl8192cu_hal_ops,
36267diff -urNp linux-2.6.39.1/drivers/net/wireless/rtlwifi/usb.c linux-2.6.39.1/drivers/net/wireless/rtlwifi/usb.c
36268--- linux-2.6.39.1/drivers/net/wireless/rtlwifi/usb.c 2011-05-19 00:06:34.000000000 -0400
36269+++ linux-2.6.39.1/drivers/net/wireless/rtlwifi/usb.c 2011-05-22 19:36:32.000000000 -0400
36270@@ -913,7 +913,7 @@ static bool rtl_usb_tx_chk_waitq_insert(
36271 return false;
36272 }
36273
36274-static struct rtl_intf_ops rtl_usb_ops = {
36275+static const struct rtl_intf_ops rtl_usb_ops = {
36276 .adapter_start = rtl_usb_start,
36277 .adapter_stop = rtl_usb_stop,
36278 .adapter_tx = rtl_usb_tx,
36279diff -urNp linux-2.6.39.1/drivers/net/wireless/rtlwifi/wifi.h linux-2.6.39.1/drivers/net/wireless/rtlwifi/wifi.h
36280--- linux-2.6.39.1/drivers/net/wireless/rtlwifi/wifi.h 2011-05-19 00:06:34.000000000 -0400
36281+++ linux-2.6.39.1/drivers/net/wireless/rtlwifi/wifi.h 2011-05-22 19:36:32.000000000 -0400
36282@@ -1447,7 +1447,7 @@ struct rtl_hal_cfg {
36283 u8 bar_id;
36284 char *name;
36285 char *fw_name;
36286- struct rtl_hal_ops *ops;
36287+ const struct rtl_hal_ops *ops;
36288 struct rtl_mod_params *mod_params;
36289 struct rtl_hal_usbint_cfg *usb_interface_cfg;
36290
36291@@ -1533,7 +1533,7 @@ struct rtl_priv {
36292 *intf_ops : for diff interrface usb/pcie
36293 */
36294 struct rtl_hal_cfg *cfg;
36295- struct rtl_intf_ops *intf_ops;
36296+ const struct rtl_intf_ops *intf_ops;
36297
36298 /*this var will be set by set_bit,
36299 and was used to indicate status of
36300diff -urNp linux-2.6.39.1/drivers/net/wireless/wl12xx/spi.c linux-2.6.39.1/drivers/net/wireless/wl12xx/spi.c
36301--- linux-2.6.39.1/drivers/net/wireless/wl12xx/spi.c 2011-05-19 00:06:34.000000000 -0400
36302+++ linux-2.6.39.1/drivers/net/wireless/wl12xx/spi.c 2011-05-22 19:36:32.000000000 -0400
36303@@ -280,6 +280,8 @@ static void wl1271_spi_raw_write(struct
36304 u32 chunk_len;
36305 int i;
36306
36307+ pax_track_stack();
36308+
36309 WARN_ON(len > WL1271_AGGR_BUFFER_SIZE);
36310
36311 spi_message_init(&m);
36312diff -urNp linux-2.6.39.1/drivers/net/xen-netback/interface.c linux-2.6.39.1/drivers/net/xen-netback/interface.c
36313--- linux-2.6.39.1/drivers/net/xen-netback/interface.c 2011-05-19 00:06:34.000000000 -0400
36314+++ linux-2.6.39.1/drivers/net/xen-netback/interface.c 2011-05-22 19:36:32.000000000 -0400
36315@@ -273,7 +273,7 @@ static void xenvif_get_strings(struct ne
36316 }
36317 }
36318
36319-static struct ethtool_ops xenvif_ethtool_ops = {
36320+static const struct ethtool_ops xenvif_ethtool_ops = {
36321 .get_tx_csum = ethtool_op_get_tx_csum,
36322 .set_tx_csum = xenvif_set_tx_csum,
36323 .get_sg = ethtool_op_get_sg,
36324diff -urNp linux-2.6.39.1/drivers/net/xilinx_emaclite.c linux-2.6.39.1/drivers/net/xilinx_emaclite.c
36325--- linux-2.6.39.1/drivers/net/xilinx_emaclite.c 2011-05-19 00:06:34.000000000 -0400
36326+++ linux-2.6.39.1/drivers/net/xilinx_emaclite.c 2011-05-22 19:36:32.000000000 -0400
36327@@ -1085,7 +1085,7 @@ static bool get_bool(struct platform_dev
36328 }
36329 }
36330
36331-static struct net_device_ops xemaclite_netdev_ops;
36332+static const struct net_device_ops xemaclite_netdev_ops;
36333
36334 /**
36335 * xemaclite_of_probe - Probe method for the Emaclite device.
36336@@ -1264,7 +1264,7 @@ xemaclite_poll_controller(struct net_dev
36337 }
36338 #endif
36339
36340-static struct net_device_ops xemaclite_netdev_ops = {
36341+static const struct net_device_ops xemaclite_netdev_ops = {
36342 .ndo_open = xemaclite_open,
36343 .ndo_stop = xemaclite_close,
36344 .ndo_start_xmit = xemaclite_send,
36345diff -urNp linux-2.6.39.1/drivers/nfc/pn544.c linux-2.6.39.1/drivers/nfc/pn544.c
36346--- linux-2.6.39.1/drivers/nfc/pn544.c 2011-05-19 00:06:34.000000000 -0400
36347+++ linux-2.6.39.1/drivers/nfc/pn544.c 2011-05-22 19:36:32.000000000 -0400
36348@@ -89,7 +89,7 @@ static ssize_t pn544_test(struct device
36349
36350 static int pn544_enable(struct pn544_info *info, int mode)
36351 {
36352- struct pn544_nfc_platform_data *pdata;
36353+ const struct pn544_nfc_platform_data *pdata;
36354 struct i2c_client *client = info->i2c_dev;
36355
36356 int r;
36357@@ -118,7 +118,7 @@ static int pn544_enable(struct pn544_inf
36358
36359 static void pn544_disable(struct pn544_info *info)
36360 {
36361- struct pn544_nfc_platform_data *pdata;
36362+ const struct pn544_nfc_platform_data *pdata;
36363 struct i2c_client *client = info->i2c_dev;
36364
36365 pdata = client->dev.platform_data;
36366@@ -509,7 +509,7 @@ static long pn544_ioctl(struct file *fil
36367 struct pn544_info *info = container_of(file->private_data,
36368 struct pn544_info, miscdev);
36369 struct i2c_client *client = info->i2c_dev;
36370- struct pn544_nfc_platform_data *pdata;
36371+ const struct pn544_nfc_platform_data *pdata;
36372 unsigned int val;
36373 int r = 0;
36374
36375@@ -715,7 +715,7 @@ static int __devinit pn544_probe(struct
36376 const struct i2c_device_id *id)
36377 {
36378 struct pn544_info *info;
36379- struct pn544_nfc_platform_data *pdata;
36380+ const struct pn544_nfc_platform_data *pdata;
36381 int r = 0;
36382
36383 dev_dbg(&client->dev, "%s\n", __func__);
36384diff -urNp linux-2.6.39.1/drivers/of/pdt.c linux-2.6.39.1/drivers/of/pdt.c
36385--- linux-2.6.39.1/drivers/of/pdt.c 2011-05-19 00:06:34.000000000 -0400
36386+++ linux-2.6.39.1/drivers/of/pdt.c 2011-05-22 19:36:32.000000000 -0400
36387@@ -24,7 +24,7 @@
36388 #include <linux/of_pdt.h>
36389 #include <asm/prom.h>
36390
36391-static struct of_pdt_ops *of_pdt_prom_ops __initdata;
36392+static const struct of_pdt_ops *of_pdt_prom_ops;
36393
36394 void __initdata (*of_pdt_build_more)(struct device_node *dp,
36395 struct device_node ***nextp);
36396diff -urNp linux-2.6.39.1/drivers/oprofile/buffer_sync.c linux-2.6.39.1/drivers/oprofile/buffer_sync.c
36397--- linux-2.6.39.1/drivers/oprofile/buffer_sync.c 2011-05-19 00:06:34.000000000 -0400
36398+++ linux-2.6.39.1/drivers/oprofile/buffer_sync.c 2011-05-22 19:36:32.000000000 -0400
36399@@ -342,7 +342,7 @@ static void add_data(struct op_entry *en
36400 if (cookie == NO_COOKIE)
36401 offset = pc;
36402 if (cookie == INVALID_COOKIE) {
36403- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36404+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36405 offset = pc;
36406 }
36407 if (cookie != last_cookie) {
36408@@ -386,14 +386,14 @@ add_sample(struct mm_struct *mm, struct
36409 /* add userspace sample */
36410
36411 if (!mm) {
36412- atomic_inc(&oprofile_stats.sample_lost_no_mm);
36413+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
36414 return 0;
36415 }
36416
36417 cookie = lookup_dcookie(mm, s->eip, &offset);
36418
36419 if (cookie == INVALID_COOKIE) {
36420- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36421+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36422 return 0;
36423 }
36424
36425@@ -562,7 +562,7 @@ void sync_buffer(int cpu)
36426 /* ignore backtraces if failed to add a sample */
36427 if (state == sb_bt_start) {
36428 state = sb_bt_ignore;
36429- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
36430+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
36431 }
36432 }
36433 release_mm(mm);
36434diff -urNp linux-2.6.39.1/drivers/oprofile/event_buffer.c linux-2.6.39.1/drivers/oprofile/event_buffer.c
36435--- linux-2.6.39.1/drivers/oprofile/event_buffer.c 2011-05-19 00:06:34.000000000 -0400
36436+++ linux-2.6.39.1/drivers/oprofile/event_buffer.c 2011-05-22 19:36:32.000000000 -0400
36437@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value
36438 }
36439
36440 if (buffer_pos == buffer_size) {
36441- atomic_inc(&oprofile_stats.event_lost_overflow);
36442+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
36443 return;
36444 }
36445
36446diff -urNp linux-2.6.39.1/drivers/oprofile/oprof.c linux-2.6.39.1/drivers/oprofile/oprof.c
36447--- linux-2.6.39.1/drivers/oprofile/oprof.c 2011-05-19 00:06:34.000000000 -0400
36448+++ linux-2.6.39.1/drivers/oprofile/oprof.c 2011-05-22 19:36:32.000000000 -0400
36449@@ -110,7 +110,7 @@ static void switch_worker(struct work_st
36450 if (oprofile_ops.switch_events())
36451 return;
36452
36453- atomic_inc(&oprofile_stats.multiplex_counter);
36454+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
36455 start_switch_worker();
36456 }
36457
36458diff -urNp linux-2.6.39.1/drivers/oprofile/oprofilefs.c linux-2.6.39.1/drivers/oprofile/oprofilefs.c
36459--- linux-2.6.39.1/drivers/oprofile/oprofilefs.c 2011-05-19 00:06:34.000000000 -0400
36460+++ linux-2.6.39.1/drivers/oprofile/oprofilefs.c 2011-05-22 19:36:32.000000000 -0400
36461@@ -186,7 +186,7 @@ static const struct file_operations atom
36462
36463
36464 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
36465- char const *name, atomic_t *val)
36466+ char const *name, atomic_unchecked_t *val)
36467 {
36468 return __oprofilefs_create_file(sb, root, name,
36469 &atomic_ro_fops, 0444, val);
36470diff -urNp linux-2.6.39.1/drivers/oprofile/oprofile_stats.c linux-2.6.39.1/drivers/oprofile/oprofile_stats.c
36471--- linux-2.6.39.1/drivers/oprofile/oprofile_stats.c 2011-05-19 00:06:34.000000000 -0400
36472+++ linux-2.6.39.1/drivers/oprofile/oprofile_stats.c 2011-05-22 19:36:32.000000000 -0400
36473@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
36474 cpu_buf->sample_invalid_eip = 0;
36475 }
36476
36477- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
36478- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
36479- atomic_set(&oprofile_stats.event_lost_overflow, 0);
36480- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
36481- atomic_set(&oprofile_stats.multiplex_counter, 0);
36482+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
36483+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
36484+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
36485+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
36486+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
36487 }
36488
36489
36490diff -urNp linux-2.6.39.1/drivers/oprofile/oprofile_stats.h linux-2.6.39.1/drivers/oprofile/oprofile_stats.h
36491--- linux-2.6.39.1/drivers/oprofile/oprofile_stats.h 2011-05-19 00:06:34.000000000 -0400
36492+++ linux-2.6.39.1/drivers/oprofile/oprofile_stats.h 2011-05-22 19:36:32.000000000 -0400
36493@@ -13,11 +13,11 @@
36494 #include <asm/atomic.h>
36495
36496 struct oprofile_stat_struct {
36497- atomic_t sample_lost_no_mm;
36498- atomic_t sample_lost_no_mapping;
36499- atomic_t bt_lost_no_mapping;
36500- atomic_t event_lost_overflow;
36501- atomic_t multiplex_counter;
36502+ atomic_unchecked_t sample_lost_no_mm;
36503+ atomic_unchecked_t sample_lost_no_mapping;
36504+ atomic_unchecked_t bt_lost_no_mapping;
36505+ atomic_unchecked_t event_lost_overflow;
36506+ atomic_unchecked_t multiplex_counter;
36507 };
36508
36509 extern struct oprofile_stat_struct oprofile_stats;
36510diff -urNp linux-2.6.39.1/drivers/parisc/dino.c linux-2.6.39.1/drivers/parisc/dino.c
36511--- linux-2.6.39.1/drivers/parisc/dino.c 2011-05-19 00:06:34.000000000 -0400
36512+++ linux-2.6.39.1/drivers/parisc/dino.c 2011-05-22 19:36:32.000000000 -0400
36513@@ -238,7 +238,7 @@ static int dino_cfg_write(struct pci_bus
36514 return 0;
36515 }
36516
36517-static struct pci_ops dino_cfg_ops = {
36518+static const struct pci_ops dino_cfg_ops = {
36519 .read = dino_cfg_read,
36520 .write = dino_cfg_write,
36521 };
36522diff -urNp linux-2.6.39.1/drivers/parisc/lba_pci.c linux-2.6.39.1/drivers/parisc/lba_pci.c
36523--- linux-2.6.39.1/drivers/parisc/lba_pci.c 2011-05-19 00:06:34.000000000 -0400
36524+++ linux-2.6.39.1/drivers/parisc/lba_pci.c 2011-05-22 19:36:32.000000000 -0400
36525@@ -468,7 +468,7 @@ static int elroy_cfg_write(struct pci_bu
36526 }
36527
36528
36529-static struct pci_ops elroy_cfg_ops = {
36530+static const struct pci_ops elroy_cfg_ops = {
36531 .read = elroy_cfg_read,
36532 .write = elroy_cfg_write,
36533 };
36534@@ -541,7 +541,7 @@ static int mercury_cfg_write(struct pci_
36535 return 0;
36536 }
36537
36538-static struct pci_ops mercury_cfg_ops = {
36539+static const struct pci_ops mercury_cfg_ops = {
36540 .read = mercury_cfg_read,
36541 .write = mercury_cfg_write,
36542 };
36543@@ -1405,7 +1405,7 @@ lba_driver_probe(struct parisc_device *d
36544 {
36545 struct lba_device *lba_dev;
36546 struct pci_bus *lba_bus;
36547- struct pci_ops *cfg_ops;
36548+ const struct pci_ops *cfg_ops;
36549 u32 func_class;
36550 void *tmp_obj;
36551 char *version;
36552diff -urNp linux-2.6.39.1/drivers/parport/procfs.c linux-2.6.39.1/drivers/parport/procfs.c
36553--- linux-2.6.39.1/drivers/parport/procfs.c 2011-05-19 00:06:34.000000000 -0400
36554+++ linux-2.6.39.1/drivers/parport/procfs.c 2011-05-22 19:36:32.000000000 -0400
36555@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *t
36556
36557 *ppos += len;
36558
36559- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
36560+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
36561 }
36562
36563 #ifdef CONFIG_PARPORT_1284
36564@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table
36565
36566 *ppos += len;
36567
36568- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
36569+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
36570 }
36571 #endif /* IEEE1284.3 support. */
36572
36573diff -urNp linux-2.6.39.1/drivers/pci/access.c linux-2.6.39.1/drivers/pci/access.c
36574--- linux-2.6.39.1/drivers/pci/access.c 2011-05-19 00:06:34.000000000 -0400
36575+++ linux-2.6.39.1/drivers/pci/access.c 2011-05-22 19:36:32.000000000 -0400
36576@@ -74,9 +74,9 @@ EXPORT_SYMBOL(pci_bus_write_config_dword
36577 *
36578 * Return previous raw operations
36579 */
36580-struct pci_ops *pci_bus_set_ops(struct pci_bus *bus, struct pci_ops *ops)
36581+const struct pci_ops *pci_bus_set_ops(struct pci_bus *bus, const struct pci_ops *ops)
36582 {
36583- struct pci_ops *old_ops;
36584+ const struct pci_ops *old_ops;
36585 unsigned long flags;
36586
36587 raw_spin_lock_irqsave(&pci_lock, flags);
36588diff -urNp linux-2.6.39.1/drivers/pci/hotplug/acpiphp_glue.c linux-2.6.39.1/drivers/pci/hotplug/acpiphp_glue.c
36589--- linux-2.6.39.1/drivers/pci/hotplug/acpiphp_glue.c 2011-05-19 00:06:34.000000000 -0400
36590+++ linux-2.6.39.1/drivers/pci/hotplug/acpiphp_glue.c 2011-05-22 19:36:32.000000000 -0400
36591@@ -110,7 +110,7 @@ static int post_dock_fixups(struct notif
36592 }
36593
36594
36595-static struct acpi_dock_ops acpiphp_dock_ops = {
36596+static const struct acpi_dock_ops acpiphp_dock_ops = {
36597 .handler = handle_hotplug_event_func,
36598 };
36599
36600diff -urNp linux-2.6.39.1/drivers/pci/hotplug/cpqphp_nvram.c linux-2.6.39.1/drivers/pci/hotplug/cpqphp_nvram.c
36601--- linux-2.6.39.1/drivers/pci/hotplug/cpqphp_nvram.c 2011-05-19 00:06:34.000000000 -0400
36602+++ linux-2.6.39.1/drivers/pci/hotplug/cpqphp_nvram.c 2011-05-22 19:36:32.000000000 -0400
36603@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_
36604
36605 void compaq_nvram_init (void __iomem *rom_start)
36606 {
36607+
36608+#ifndef CONFIG_PAX_KERNEXEC
36609 if (rom_start) {
36610 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
36611 }
36612+#endif
36613+
36614 dbg("int15 entry = %p\n", compaq_int15_entry_point);
36615
36616 /* initialize our int15 lock */
36617diff -urNp linux-2.6.39.1/drivers/pci/hotplug/shpchp.h linux-2.6.39.1/drivers/pci/hotplug/shpchp.h
36618--- linux-2.6.39.1/drivers/pci/hotplug/shpchp.h 2011-05-19 00:06:34.000000000 -0400
36619+++ linux-2.6.39.1/drivers/pci/hotplug/shpchp.h 2011-05-22 19:36:32.000000000 -0400
36620@@ -86,7 +86,7 @@ struct slot {
36621 u8 presence_save;
36622 u8 pwr_save;
36623 struct controller *ctrl;
36624- struct hpc_ops *hpc_ops;
36625+ const struct hpc_ops *hpc_ops;
36626 struct hotplug_slot *hotplug_slot;
36627 struct list_head slot_list;
36628 struct delayed_work work; /* work for button event */
36629@@ -107,7 +107,7 @@ struct controller {
36630 int slot_num_inc; /* 1 or -1 */
36631 struct pci_dev *pci_dev;
36632 struct list_head slot_list;
36633- struct hpc_ops *hpc_ops;
36634+ const struct hpc_ops *hpc_ops;
36635 wait_queue_head_t queue; /* sleep & wake process */
36636 u8 slot_device_offset;
36637 u32 pcix_misc2_reg; /* for amd pogo errata */
36638diff -urNp linux-2.6.39.1/drivers/pci/hotplug/shpchp_hpc.c linux-2.6.39.1/drivers/pci/hotplug/shpchp_hpc.c
36639--- linux-2.6.39.1/drivers/pci/hotplug/shpchp_hpc.c 2011-05-19 00:06:34.000000000 -0400
36640+++ linux-2.6.39.1/drivers/pci/hotplug/shpchp_hpc.c 2011-05-22 19:36:32.000000000 -0400
36641@@ -910,7 +910,7 @@ static int shpc_get_max_bus_speed(struct
36642 return retval;
36643 }
36644
36645-static struct hpc_ops shpchp_hpc_ops = {
36646+static const struct hpc_ops shpchp_hpc_ops = {
36647 .power_on_slot = hpc_power_on_slot,
36648 .slot_enable = hpc_slot_enable,
36649 .slot_disable = hpc_slot_disable,
36650diff -urNp linux-2.6.39.1/drivers/pci/intel-iommu.c linux-2.6.39.1/drivers/pci/intel-iommu.c
36651--- linux-2.6.39.1/drivers/pci/intel-iommu.c 2011-05-19 00:06:34.000000000 -0400
36652+++ linux-2.6.39.1/drivers/pci/intel-iommu.c 2011-05-22 19:36:32.000000000 -0400
36653@@ -391,7 +391,7 @@ static int intel_iommu_strict;
36654 static DEFINE_SPINLOCK(device_domain_lock);
36655 static LIST_HEAD(device_domain_list);
36656
36657-static struct iommu_ops intel_iommu_ops;
36658+static const struct iommu_ops intel_iommu_ops;
36659
36660 static int __init intel_iommu_setup(char *str)
36661 {
36662@@ -2945,7 +2945,7 @@ static int intel_mapping_error(struct de
36663 return !dma_addr;
36664 }
36665
36666-struct dma_map_ops intel_dma_ops = {
36667+const struct dma_map_ops intel_dma_ops = {
36668 .alloc_coherent = intel_alloc_coherent,
36669 .free_coherent = intel_free_coherent,
36670 .map_sg = intel_map_sg,
36671@@ -3739,7 +3739,7 @@ static int intel_iommu_domain_has_cap(st
36672 return 0;
36673 }
36674
36675-static struct iommu_ops intel_iommu_ops = {
36676+static const struct iommu_ops intel_iommu_ops = {
36677 .domain_init = intel_iommu_domain_init,
36678 .domain_destroy = intel_iommu_domain_destroy,
36679 .attach_dev = intel_iommu_attach_device,
36680diff -urNp linux-2.6.39.1/drivers/pci/pci-acpi.c linux-2.6.39.1/drivers/pci/pci-acpi.c
36681--- linux-2.6.39.1/drivers/pci/pci-acpi.c 2011-05-19 00:06:34.000000000 -0400
36682+++ linux-2.6.39.1/drivers/pci/pci-acpi.c 2011-05-22 19:36:32.000000000 -0400
36683@@ -332,7 +332,7 @@ static int acpi_pci_run_wake(struct pci_
36684 return 0;
36685 }
36686
36687-static struct pci_platform_pm_ops acpi_pci_platform_pm = {
36688+static const struct pci_platform_pm_ops acpi_pci_platform_pm = {
36689 .is_manageable = acpi_pci_power_manageable,
36690 .set_state = acpi_pci_set_power_state,
36691 .choose_state = acpi_pci_choose_state,
36692diff -urNp linux-2.6.39.1/drivers/pci/pci.c linux-2.6.39.1/drivers/pci/pci.c
36693--- linux-2.6.39.1/drivers/pci/pci.c 2011-05-19 00:06:34.000000000 -0400
36694+++ linux-2.6.39.1/drivers/pci/pci.c 2011-05-22 19:36:32.000000000 -0400
36695@@ -480,9 +480,9 @@ pci_restore_bars(struct pci_dev *dev)
36696 pci_update_resource(dev, i);
36697 }
36698
36699-static struct pci_platform_pm_ops *pci_platform_pm;
36700+static const struct pci_platform_pm_ops *pci_platform_pm;
36701
36702-int pci_set_platform_pm(struct pci_platform_pm_ops *ops)
36703+int pci_set_platform_pm(const struct pci_platform_pm_ops *ops)
36704 {
36705 if (!ops->is_manageable || !ops->set_state || !ops->choose_state
36706 || !ops->sleep_wake || !ops->can_wakeup)
36707diff -urNp linux-2.6.39.1/drivers/pci/pcie/aer/aerdrv_core.c linux-2.6.39.1/drivers/pci/pcie/aer/aerdrv_core.c
36708--- linux-2.6.39.1/drivers/pci/pcie/aer/aerdrv_core.c 2011-05-19 00:06:34.000000000 -0400
36709+++ linux-2.6.39.1/drivers/pci/pcie/aer/aerdrv_core.c 2011-05-22 19:36:32.000000000 -0400
36710@@ -239,7 +239,7 @@ static bool find_source_device(struct pc
36711 static int report_error_detected(struct pci_dev *dev, void *data)
36712 {
36713 pci_ers_result_t vote;
36714- struct pci_error_handlers *err_handler;
36715+ const struct pci_error_handlers *err_handler;
36716 struct aer_broadcast_data *result_data;
36717 result_data = (struct aer_broadcast_data *) data;
36718
36719@@ -273,7 +273,7 @@ static int report_error_detected(struct
36720 static int report_mmio_enabled(struct pci_dev *dev, void *data)
36721 {
36722 pci_ers_result_t vote;
36723- struct pci_error_handlers *err_handler;
36724+ const struct pci_error_handlers *err_handler;
36725 struct aer_broadcast_data *result_data;
36726 result_data = (struct aer_broadcast_data *) data;
36727
36728@@ -291,7 +291,7 @@ static int report_mmio_enabled(struct pc
36729 static int report_slot_reset(struct pci_dev *dev, void *data)
36730 {
36731 pci_ers_result_t vote;
36732- struct pci_error_handlers *err_handler;
36733+ const struct pci_error_handlers *err_handler;
36734 struct aer_broadcast_data *result_data;
36735 result_data = (struct aer_broadcast_data *) data;
36736
36737@@ -308,7 +308,7 @@ static int report_slot_reset(struct pci_
36738
36739 static int report_resume(struct pci_dev *dev, void *data)
36740 {
36741- struct pci_error_handlers *err_handler;
36742+ const struct pci_error_handlers *err_handler;
36743
36744 dev->error_state = pci_channel_io_normal;
36745
36746diff -urNp linux-2.6.39.1/drivers/pci/pcie/aer/aer_inject.c linux-2.6.39.1/drivers/pci/pcie/aer/aer_inject.c
36747--- linux-2.6.39.1/drivers/pci/pcie/aer/aer_inject.c 2011-05-19 00:06:34.000000000 -0400
36748+++ linux-2.6.39.1/drivers/pci/pcie/aer/aer_inject.c 2011-05-22 19:36:32.000000000 -0400
36749@@ -64,7 +64,7 @@ struct aer_error {
36750 struct pci_bus_ops {
36751 struct list_head list;
36752 struct pci_bus *bus;
36753- struct pci_ops *ops;
36754+ const struct pci_ops *ops;
36755 };
36756
36757 static LIST_HEAD(einjected);
36758@@ -110,7 +110,7 @@ static struct aer_error *__find_aer_erro
36759 }
36760
36761 /* inject_lock must be held before calling */
36762-static struct pci_ops *__find_pci_bus_ops(struct pci_bus *bus)
36763+static const struct pci_ops *__find_pci_bus_ops(struct pci_bus *bus)
36764 {
36765 struct pci_bus_ops *bus_ops;
36766
36767@@ -187,7 +187,7 @@ static int pci_read_aer(struct pci_bus *
36768 u32 *sim;
36769 struct aer_error *err;
36770 unsigned long flags;
36771- struct pci_ops *ops;
36772+ const struct pci_ops *ops;
36773 int domain;
36774
36775 spin_lock_irqsave(&inject_lock, flags);
36776@@ -219,7 +219,7 @@ int pci_write_aer(struct pci_bus *bus, u
36777 struct aer_error *err;
36778 unsigned long flags;
36779 int rw1cs;
36780- struct pci_ops *ops;
36781+ const struct pci_ops *ops;
36782 int domain;
36783
36784 spin_lock_irqsave(&inject_lock, flags);
36785@@ -254,7 +254,7 @@ static struct pci_ops pci_ops_aer = {
36786
36787 static void pci_bus_ops_init(struct pci_bus_ops *bus_ops,
36788 struct pci_bus *bus,
36789- struct pci_ops *ops)
36790+ const struct pci_ops *ops)
36791 {
36792 INIT_LIST_HEAD(&bus_ops->list);
36793 bus_ops->bus = bus;
36794@@ -263,7 +263,7 @@ static void pci_bus_ops_init(struct pci_
36795
36796 static int pci_bus_set_aer_ops(struct pci_bus *bus)
36797 {
36798- struct pci_ops *ops;
36799+ const struct pci_ops *ops;
36800 struct pci_bus_ops *bus_ops;
36801 unsigned long flags;
36802
36803diff -urNp linux-2.6.39.1/drivers/pci/pcie/aspm.c linux-2.6.39.1/drivers/pci/pcie/aspm.c
36804--- linux-2.6.39.1/drivers/pci/pcie/aspm.c 2011-05-19 00:06:34.000000000 -0400
36805+++ linux-2.6.39.1/drivers/pci/pcie/aspm.c 2011-05-22 19:36:32.000000000 -0400
36806@@ -27,9 +27,9 @@
36807 #define MODULE_PARAM_PREFIX "pcie_aspm."
36808
36809 /* Note: those are not register definitions */
36810-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
36811-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
36812-#define ASPM_STATE_L1 (4) /* L1 state */
36813+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
36814+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
36815+#define ASPM_STATE_L1 (4U) /* L1 state */
36816 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
36817 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
36818
36819diff -urNp linux-2.6.39.1/drivers/pci/pci.h linux-2.6.39.1/drivers/pci/pci.h
36820--- linux-2.6.39.1/drivers/pci/pci.h 2011-05-19 00:06:34.000000000 -0400
36821+++ linux-2.6.39.1/drivers/pci/pci.h 2011-05-22 19:36:32.000000000 -0400
36822@@ -65,7 +65,7 @@ struct pci_platform_pm_ops {
36823 int (*run_wake)(struct pci_dev *dev, bool enable);
36824 };
36825
36826-extern int pci_set_platform_pm(struct pci_platform_pm_ops *ops);
36827+extern int pci_set_platform_pm(const struct pci_platform_pm_ops *ops);
36828 extern void pci_update_current_state(struct pci_dev *dev, pci_power_t state);
36829 extern void pci_disable_enabled_device(struct pci_dev *dev);
36830 extern int pci_finish_runtime_suspend(struct pci_dev *dev);
36831diff -urNp linux-2.6.39.1/drivers/pci/probe.c linux-2.6.39.1/drivers/pci/probe.c
36832--- linux-2.6.39.1/drivers/pci/probe.c 2011-05-19 00:06:34.000000000 -0400
36833+++ linux-2.6.39.1/drivers/pci/probe.c 2011-05-22 19:36:32.000000000 -0400
36834@@ -62,14 +62,14 @@ static ssize_t pci_bus_show_cpuaffinity(
36835 return ret;
36836 }
36837
36838-static ssize_t inline pci_bus_show_cpumaskaffinity(struct device *dev,
36839+static inline ssize_t pci_bus_show_cpumaskaffinity(struct device *dev,
36840 struct device_attribute *attr,
36841 char *buf)
36842 {
36843 return pci_bus_show_cpuaffinity(dev, 0, attr, buf);
36844 }
36845
36846-static ssize_t inline pci_bus_show_cpulistaffinity(struct device *dev,
36847+static inline ssize_t pci_bus_show_cpulistaffinity(struct device *dev,
36848 struct device_attribute *attr,
36849 char *buf)
36850 {
36851@@ -165,7 +165,7 @@ int __pci_read_base(struct pci_dev *dev,
36852 u32 l, sz, mask;
36853 u16 orig_cmd;
36854
36855- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
36856+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
36857
36858 if (!dev->mmio_always_on) {
36859 pci_read_config_word(dev, PCI_COMMAND, &orig_cmd);
36860@@ -1407,7 +1407,7 @@ unsigned int __devinit pci_scan_child_bu
36861 }
36862
36863 struct pci_bus * pci_create_bus(struct device *parent,
36864- int bus, struct pci_ops *ops, void *sysdata)
36865+ int bus, const struct pci_ops *ops, void *sysdata)
36866 {
36867 int error;
36868 struct pci_bus *b, *b2;
36869@@ -1483,7 +1483,7 @@ err_out:
36870 }
36871
36872 struct pci_bus * __devinit pci_scan_bus_parented(struct device *parent,
36873- int bus, struct pci_ops *ops, void *sysdata)
36874+ int bus, const struct pci_ops *ops, void *sysdata)
36875 {
36876 struct pci_bus *b;
36877
36878diff -urNp linux-2.6.39.1/drivers/pci/proc.c linux-2.6.39.1/drivers/pci/proc.c
36879--- linux-2.6.39.1/drivers/pci/proc.c 2011-05-19 00:06:34.000000000 -0400
36880+++ linux-2.6.39.1/drivers/pci/proc.c 2011-05-22 19:41:37.000000000 -0400
36881@@ -476,7 +476,16 @@ static const struct file_operations proc
36882 static int __init pci_proc_init(void)
36883 {
36884 struct pci_dev *dev = NULL;
36885+
36886+#ifdef CONFIG_GRKERNSEC_PROC_ADD
36887+#ifdef CONFIG_GRKERNSEC_PROC_USER
36888+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
36889+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
36890+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
36891+#endif
36892+#else
36893 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
36894+#endif
36895 proc_create("devices", 0, proc_bus_pci_dir,
36896 &proc_bus_pci_dev_operations);
36897 proc_initialized = 1;
36898diff -urNp linux-2.6.39.1/drivers/pci/xen-pcifront.c linux-2.6.39.1/drivers/pci/xen-pcifront.c
36899--- linux-2.6.39.1/drivers/pci/xen-pcifront.c 2011-05-19 00:06:34.000000000 -0400
36900+++ linux-2.6.39.1/drivers/pci/xen-pcifront.c 2011-05-22 19:36:32.000000000 -0400
36901@@ -187,6 +187,8 @@ static int pcifront_bus_read(struct pci_
36902 struct pcifront_sd *sd = bus->sysdata;
36903 struct pcifront_device *pdev = pcifront_get_pdev(sd);
36904
36905+ pax_track_stack();
36906+
36907 if (verbose_request)
36908 dev_info(&pdev->xdev->dev,
36909 "read dev=%04x:%02x:%02x.%01x - offset %x size %d\n",
36910@@ -226,6 +228,8 @@ static int pcifront_bus_write(struct pci
36911 struct pcifront_sd *sd = bus->sysdata;
36912 struct pcifront_device *pdev = pcifront_get_pdev(sd);
36913
36914+ pax_track_stack();
36915+
36916 if (verbose_request)
36917 dev_info(&pdev->xdev->dev,
36918 "write dev=%04x:%02x:%02x.%01x - "
36919@@ -236,7 +240,7 @@ static int pcifront_bus_write(struct pci
36920 return errno_to_pcibios_err(do_pci_op(pdev, &op));
36921 }
36922
36923-struct pci_ops pcifront_bus_ops = {
36924+const struct pci_ops pcifront_bus_ops = {
36925 .read = pcifront_bus_read,
36926 .write = pcifront_bus_write,
36927 };
36928@@ -258,6 +262,8 @@ static int pci_frontend_enable_msix(stru
36929 struct pcifront_device *pdev = pcifront_get_pdev(sd);
36930 struct msi_desc *entry;
36931
36932+ pax_track_stack();
36933+
36934 if (nvec > SH_INFO_MAX_VEC) {
36935 dev_err(&dev->dev, "too much vector for pci frontend: %x."
36936 " Increase SH_INFO_MAX_VEC.\n", nvec);
36937@@ -309,6 +315,8 @@ static void pci_frontend_disable_msix(st
36938 struct pcifront_sd *sd = dev->bus->sysdata;
36939 struct pcifront_device *pdev = pcifront_get_pdev(sd);
36940
36941+ pax_track_stack();
36942+
36943 err = do_pci_op(pdev, &op);
36944
36945 /* What should do for error ? */
36946@@ -328,6 +336,8 @@ static int pci_frontend_enable_msi(struc
36947 struct pcifront_sd *sd = dev->bus->sysdata;
36948 struct pcifront_device *pdev = pcifront_get_pdev(sd);
36949
36950+ pax_track_stack();
36951+
36952 err = do_pci_op(pdev, &op);
36953 if (likely(!err)) {
36954 vector[0] = op.value;
36955@@ -368,7 +378,7 @@ static void pci_frontend_disable_msi(str
36956 printk(KERN_DEBUG "get fake response frombackend\n");
36957 }
36958
36959-static struct xen_pci_frontend_ops pci_frontend_ops = {
36960+static const struct xen_pci_frontend_ops pci_frontend_ops = {
36961 .enable_msi = pci_frontend_enable_msi,
36962 .disable_msi = pci_frontend_disable_msi,
36963 .enable_msix = pci_frontend_enable_msix,
36964diff -urNp linux-2.6.39.1/drivers/pcmcia/at91_cf.c linux-2.6.39.1/drivers/pcmcia/at91_cf.c
36965--- linux-2.6.39.1/drivers/pcmcia/at91_cf.c 2011-05-19 00:06:34.000000000 -0400
36966+++ linux-2.6.39.1/drivers/pcmcia/at91_cf.c 2011-05-22 19:36:32.000000000 -0400
36967@@ -203,7 +203,7 @@ at91_cf_set_mem_map(struct pcmcia_socket
36968 return 0;
36969 }
36970
36971-static struct pccard_operations at91_cf_ops = {
36972+static const struct pccard_operations at91_cf_ops = {
36973 .init = at91_cf_ss_init,
36974 .suspend = at91_cf_ss_suspend,
36975 .get_status = at91_cf_get_status,
36976diff -urNp linux-2.6.39.1/drivers/pcmcia/bfin_cf_pcmcia.c linux-2.6.39.1/drivers/pcmcia/bfin_cf_pcmcia.c
36977--- linux-2.6.39.1/drivers/pcmcia/bfin_cf_pcmcia.c 2011-05-19 00:06:34.000000000 -0400
36978+++ linux-2.6.39.1/drivers/pcmcia/bfin_cf_pcmcia.c 2011-05-22 19:36:32.000000000 -0400
36979@@ -184,7 +184,7 @@ bfin_cf_set_mem_map(struct pcmcia_socket
36980 return 0;
36981 }
36982
36983-static struct pccard_operations bfin_cf_ops = {
36984+static const struct pccard_operations bfin_cf_ops = {
36985 .init = bfin_cf_ss_init,
36986 .suspend = bfin_cf_ss_suspend,
36987 .get_status = bfin_cf_get_status,
36988diff -urNp linux-2.6.39.1/drivers/pcmcia/db1xxx_ss.c linux-2.6.39.1/drivers/pcmcia/db1xxx_ss.c
36989--- linux-2.6.39.1/drivers/pcmcia/db1xxx_ss.c 2011-05-19 00:06:34.000000000 -0400
36990+++ linux-2.6.39.1/drivers/pcmcia/db1xxx_ss.c 2011-05-22 19:36:32.000000000 -0400
36991@@ -384,7 +384,7 @@ static int au1x00_pcmcia_set_mem_map(str
36992 return 0;
36993 }
36994
36995-static struct pccard_operations db1x_pcmcia_operations = {
36996+static const struct pccard_operations db1x_pcmcia_operations = {
36997 .init = db1x_pcmcia_sock_init,
36998 .suspend = db1x_pcmcia_sock_suspend,
36999 .get_status = db1x_pcmcia_get_status,
37000diff -urNp linux-2.6.39.1/drivers/pcmcia/electra_cf.c linux-2.6.39.1/drivers/pcmcia/electra_cf.c
37001--- linux-2.6.39.1/drivers/pcmcia/electra_cf.c 2011-05-19 00:06:34.000000000 -0400
37002+++ linux-2.6.39.1/drivers/pcmcia/electra_cf.c 2011-05-22 19:36:32.000000000 -0400
37003@@ -173,7 +173,7 @@ static int electra_cf_set_mem_map(struct
37004 return 0;
37005 }
37006
37007-static struct pccard_operations electra_cf_ops = {
37008+static const struct pccard_operations electra_cf_ops = {
37009 .init = electra_cf_ss_init,
37010 .get_status = electra_cf_get_status,
37011 .set_socket = electra_cf_set_socket,
37012diff -urNp linux-2.6.39.1/drivers/pcmcia/m32r_cfc.c linux-2.6.39.1/drivers/pcmcia/m32r_cfc.c
37013--- linux-2.6.39.1/drivers/pcmcia/m32r_cfc.c 2011-05-19 00:06:34.000000000 -0400
37014+++ linux-2.6.39.1/drivers/pcmcia/m32r_cfc.c 2011-05-22 19:36:32.000000000 -0400
37015@@ -674,7 +674,7 @@ static int pcc_init(struct pcmcia_socket
37016 return 0;
37017 }
37018
37019-static struct pccard_operations pcc_operations = {
37020+static const struct pccard_operations pcc_operations = {
37021 .init = pcc_init,
37022 .get_status = pcc_get_status,
37023 .set_socket = pcc_set_socket,
37024diff -urNp linux-2.6.39.1/drivers/pcmcia/m32r_pcc.c linux-2.6.39.1/drivers/pcmcia/m32r_pcc.c
37025--- linux-2.6.39.1/drivers/pcmcia/m32r_pcc.c 2011-05-19 00:06:34.000000000 -0400
37026+++ linux-2.6.39.1/drivers/pcmcia/m32r_pcc.c 2011-05-22 19:36:32.000000000 -0400
37027@@ -652,7 +652,7 @@ static int pcc_init(struct pcmcia_socket
37028 return 0;
37029 }
37030
37031-static struct pccard_operations pcc_operations = {
37032+static const struct pccard_operations pcc_operations = {
37033 .init = pcc_init,
37034 .get_status = pcc_get_status,
37035 .set_socket = pcc_set_socket,
37036diff -urNp linux-2.6.39.1/drivers/pcmcia/m8xx_pcmcia.c linux-2.6.39.1/drivers/pcmcia/m8xx_pcmcia.c
37037--- linux-2.6.39.1/drivers/pcmcia/m8xx_pcmcia.c 2011-05-19 00:06:34.000000000 -0400
37038+++ linux-2.6.39.1/drivers/pcmcia/m8xx_pcmcia.c 2011-05-22 19:36:32.000000000 -0400
37039@@ -1139,7 +1139,7 @@ static int m8xx_sock_suspend(struct pcmc
37040 return m8xx_set_socket(sock, &dead_socket);
37041 }
37042
37043-static struct pccard_operations m8xx_services = {
37044+static const struct pccard_operations m8xx_services = {
37045 .init = m8xx_sock_init,
37046 .suspend = m8xx_sock_suspend,
37047 .get_status = m8xx_get_status,
37048diff -urNp linux-2.6.39.1/drivers/pcmcia/omap_cf.c linux-2.6.39.1/drivers/pcmcia/omap_cf.c
37049--- linux-2.6.39.1/drivers/pcmcia/omap_cf.c 2011-05-19 00:06:34.000000000 -0400
37050+++ linux-2.6.39.1/drivers/pcmcia/omap_cf.c 2011-05-22 19:36:32.000000000 -0400
37051@@ -185,7 +185,7 @@ omap_cf_set_mem_map(struct pcmcia_socket
37052 return 0;
37053 }
37054
37055-static struct pccard_operations omap_cf_ops = {
37056+static const struct pccard_operations omap_cf_ops = {
37057 .init = omap_cf_ss_init,
37058 .suspend = omap_cf_ss_suspend,
37059 .get_status = omap_cf_get_status,
37060diff -urNp linux-2.6.39.1/drivers/pcmcia/rsrc_iodyn.c linux-2.6.39.1/drivers/pcmcia/rsrc_iodyn.c
37061--- linux-2.6.39.1/drivers/pcmcia/rsrc_iodyn.c 2011-05-19 00:06:34.000000000 -0400
37062+++ linux-2.6.39.1/drivers/pcmcia/rsrc_iodyn.c 2011-05-22 19:36:32.000000000 -0400
37063@@ -161,7 +161,7 @@ static int iodyn_find_io(struct pcmcia_s
37064 }
37065
37066
37067-struct pccard_resource_ops pccard_iodyn_ops = {
37068+const struct pccard_resource_ops pccard_iodyn_ops = {
37069 .validate_mem = NULL,
37070 .find_io = iodyn_find_io,
37071 .find_mem = NULL,
37072diff -urNp linux-2.6.39.1/drivers/pcmcia/rsrc_mgr.c linux-2.6.39.1/drivers/pcmcia/rsrc_mgr.c
37073--- linux-2.6.39.1/drivers/pcmcia/rsrc_mgr.c 2011-05-19 00:06:34.000000000 -0400
37074+++ linux-2.6.39.1/drivers/pcmcia/rsrc_mgr.c 2011-05-22 19:36:32.000000000 -0400
37075@@ -57,7 +57,7 @@ static int static_find_io(struct pcmcia_
37076 }
37077
37078
37079-struct pccard_resource_ops pccard_static_ops = {
37080+const struct pccard_resource_ops pccard_static_ops = {
37081 .validate_mem = NULL,
37082 .find_io = static_find_io,
37083 .find_mem = NULL,
37084diff -urNp linux-2.6.39.1/drivers/pcmcia/vrc4171_card.c linux-2.6.39.1/drivers/pcmcia/vrc4171_card.c
37085--- linux-2.6.39.1/drivers/pcmcia/vrc4171_card.c 2011-05-19 00:06:34.000000000 -0400
37086+++ linux-2.6.39.1/drivers/pcmcia/vrc4171_card.c 2011-05-22 19:36:32.000000000 -0400
37087@@ -479,7 +479,7 @@ static int pccard_set_mem_map(struct pcm
37088 return 0;
37089 }
37090
37091-static struct pccard_operations vrc4171_pccard_operations = {
37092+static const struct pccard_operations vrc4171_pccard_operations = {
37093 .init = pccard_init,
37094 .get_status = pccard_get_status,
37095 .set_socket = pccard_set_socket,
37096diff -urNp linux-2.6.39.1/drivers/pcmcia/vrc4173_cardu.c linux-2.6.39.1/drivers/pcmcia/vrc4173_cardu.c
37097--- linux-2.6.39.1/drivers/pcmcia/vrc4173_cardu.c 2011-05-19 00:06:34.000000000 -0400
37098+++ linux-2.6.39.1/drivers/pcmcia/vrc4173_cardu.c 2011-05-22 19:36:32.000000000 -0400
37099@@ -384,7 +384,7 @@ static void cardu_proc_setup(unsigned in
37100 {
37101 }
37102
37103-static struct pccard_operations cardu_operations = {
37104+static const struct pccard_operations cardu_operations = {
37105 .init = cardu_init,
37106 .register_callback = cardu_register_callback,
37107 .inquire_socket = cardu_inquire_socket,
37108diff -urNp linux-2.6.39.1/drivers/pcmcia/xxs1500_ss.c linux-2.6.39.1/drivers/pcmcia/xxs1500_ss.c
37109--- linux-2.6.39.1/drivers/pcmcia/xxs1500_ss.c 2011-05-19 00:06:34.000000000 -0400
37110+++ linux-2.6.39.1/drivers/pcmcia/xxs1500_ss.c 2011-05-22 19:36:32.000000000 -0400
37111@@ -196,7 +196,7 @@ static int au1x00_pcmcia_set_mem_map(str
37112 return 0;
37113 }
37114
37115-static struct pccard_operations xxs1500_pcmcia_operations = {
37116+static const struct pccard_operations xxs1500_pcmcia_operations = {
37117 .init = xxs1500_pcmcia_sock_init,
37118 .suspend = xxs1500_pcmcia_sock_suspend,
37119 .get_status = xxs1500_pcmcia_get_status,
37120diff -urNp linux-2.6.39.1/drivers/platform/x86/acerhdf.c linux-2.6.39.1/drivers/platform/x86/acerhdf.c
37121--- linux-2.6.39.1/drivers/platform/x86/acerhdf.c 2011-05-19 00:06:34.000000000 -0400
37122+++ linux-2.6.39.1/drivers/platform/x86/acerhdf.c 2011-05-22 19:36:32.000000000 -0400
37123@@ -406,7 +406,7 @@ static int acerhdf_get_crit_temp(struct
37124 }
37125
37126 /* bind callback functions to thermalzone */
37127-static struct thermal_zone_device_ops acerhdf_dev_ops = {
37128+static const struct thermal_zone_device_ops acerhdf_dev_ops = {
37129 .bind = acerhdf_bind,
37130 .unbind = acerhdf_unbind,
37131 .get_temp = acerhdf_get_ec_temp,
37132@@ -481,7 +481,7 @@ err_out:
37133 }
37134
37135 /* bind fan callbacks to fan device */
37136-static struct thermal_cooling_device_ops acerhdf_cooling_ops = {
37137+static const struct thermal_cooling_device_ops acerhdf_cooling_ops = {
37138 .get_max_state = acerhdf_get_max_state,
37139 .get_cur_state = acerhdf_get_cur_state,
37140 .set_cur_state = acerhdf_set_cur_state,
37141diff -urNp linux-2.6.39.1/drivers/platform/x86/ideapad-laptop.c linux-2.6.39.1/drivers/platform/x86/ideapad-laptop.c
37142--- linux-2.6.39.1/drivers/platform/x86/ideapad-laptop.c 2011-05-19 00:06:34.000000000 -0400
37143+++ linux-2.6.39.1/drivers/platform/x86/ideapad-laptop.c 2011-05-22 19:36:32.000000000 -0400
37144@@ -207,7 +207,7 @@ static int ideapad_rfk_set(void *data, b
37145 return write_ec_cmd(ideapad_handle, opcode, !blocked);
37146 }
37147
37148-static struct rfkill_ops ideapad_rfk_ops = {
37149+static const struct rfkill_ops ideapad_rfk_ops = {
37150 .set_block = ideapad_rfk_set,
37151 };
37152
37153diff -urNp linux-2.6.39.1/drivers/platform/x86/intel_menlow.c linux-2.6.39.1/drivers/platform/x86/intel_menlow.c
37154--- linux-2.6.39.1/drivers/platform/x86/intel_menlow.c 2011-05-19 00:06:34.000000000 -0400
37155+++ linux-2.6.39.1/drivers/platform/x86/intel_menlow.c 2011-05-22 19:36:32.000000000 -0400
37156@@ -143,7 +143,7 @@ static int memory_set_cur_bandwidth(stru
37157 return 0;
37158 }
37159
37160-static struct thermal_cooling_device_ops memory_cooling_ops = {
37161+static const struct thermal_cooling_device_ops memory_cooling_ops = {
37162 .get_max_state = memory_get_max_bandwidth,
37163 .get_cur_state = memory_get_cur_bandwidth,
37164 .set_cur_state = memory_set_cur_bandwidth,
37165diff -urNp linux-2.6.39.1/drivers/platform/x86/intel_mid_thermal.c linux-2.6.39.1/drivers/platform/x86/intel_mid_thermal.c
37166--- linux-2.6.39.1/drivers/platform/x86/intel_mid_thermal.c 2011-05-19 00:06:34.000000000 -0400
37167+++ linux-2.6.39.1/drivers/platform/x86/intel_mid_thermal.c 2011-05-22 19:36:32.000000000 -0400
37168@@ -458,7 +458,7 @@ static int read_curr_temp(struct thermal
37169 }
37170
37171 /* Can't be const */
37172-static struct thermal_zone_device_ops tzd_ops = {
37173+static const struct thermal_zone_device_ops tzd_ops = {
37174 .get_temp = read_curr_temp,
37175 };
37176
37177diff -urNp linux-2.6.39.1/drivers/platform/x86/samsung-laptop.c linux-2.6.39.1/drivers/platform/x86/samsung-laptop.c
37178--- linux-2.6.39.1/drivers/platform/x86/samsung-laptop.c 2011-05-19 00:06:34.000000000 -0400
37179+++ linux-2.6.39.1/drivers/platform/x86/samsung-laptop.c 2011-05-22 19:36:32.000000000 -0400
37180@@ -419,7 +419,7 @@ static int rfkill_set(void *data, bool b
37181 return 0;
37182 }
37183
37184-static struct rfkill_ops rfkill_ops = {
37185+static const struct rfkill_ops rfkill_ops = {
37186 .set_block = rfkill_set,
37187 };
37188
37189diff -urNp linux-2.6.39.1/drivers/pnp/pnpbios/bioscalls.c linux-2.6.39.1/drivers/pnp/pnpbios/bioscalls.c
37190--- linux-2.6.39.1/drivers/pnp/pnpbios/bioscalls.c 2011-05-19 00:06:34.000000000 -0400
37191+++ linux-2.6.39.1/drivers/pnp/pnpbios/bioscalls.c 2011-05-22 19:36:32.000000000 -0400
37192@@ -59,7 +59,7 @@ do { \
37193 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
37194 } while(0)
37195
37196-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
37197+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
37198 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
37199
37200 /*
37201@@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func
37202
37203 cpu = get_cpu();
37204 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
37205+
37206+ pax_open_kernel();
37207 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
37208+ pax_close_kernel();
37209
37210 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
37211 spin_lock_irqsave(&pnp_bios_lock, flags);
37212@@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func
37213 :"memory");
37214 spin_unlock_irqrestore(&pnp_bios_lock, flags);
37215
37216+ pax_open_kernel();
37217 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
37218+ pax_close_kernel();
37219+
37220 put_cpu();
37221
37222 /* If we get here and this is set then the PnP BIOS faulted on us. */
37223@@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 n
37224 return status;
37225 }
37226
37227-void pnpbios_calls_init(union pnp_bios_install_struct *header)
37228+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
37229 {
37230 int i;
37231
37232@@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_i
37233 pnp_bios_callpoint.offset = header->fields.pm16offset;
37234 pnp_bios_callpoint.segment = PNP_CS16;
37235
37236+ pax_open_kernel();
37237+
37238 for_each_possible_cpu(i) {
37239 struct desc_struct *gdt = get_cpu_gdt_table(i);
37240 if (!gdt)
37241@@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_i
37242 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
37243 (unsigned long)__va(header->fields.pm16dseg));
37244 }
37245+
37246+ pax_close_kernel();
37247 }
37248diff -urNp linux-2.6.39.1/drivers/pnp/resource.c linux-2.6.39.1/drivers/pnp/resource.c
37249--- linux-2.6.39.1/drivers/pnp/resource.c 2011-05-19 00:06:34.000000000 -0400
37250+++ linux-2.6.39.1/drivers/pnp/resource.c 2011-05-22 19:36:32.000000000 -0400
37251@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, s
37252 return 1;
37253
37254 /* check if the resource is valid */
37255- if (*irq < 0 || *irq > 15)
37256+ if (*irq > 15)
37257 return 0;
37258
37259 /* check if the resource is reserved */
37260@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, s
37261 return 1;
37262
37263 /* check if the resource is valid */
37264- if (*dma < 0 || *dma == 4 || *dma > 7)
37265+ if (*dma == 4 || *dma > 7)
37266 return 0;
37267
37268 /* check if the resource is reserved */
37269diff -urNp linux-2.6.39.1/drivers/power/max8925_power.c linux-2.6.39.1/drivers/power/max8925_power.c
37270--- linux-2.6.39.1/drivers/power/max8925_power.c 2011-05-19 00:06:34.000000000 -0400
37271+++ linux-2.6.39.1/drivers/power/max8925_power.c 2011-05-22 19:36:32.000000000 -0400
37272@@ -426,7 +426,7 @@ static __devinit int max8925_power_probe
37273 {
37274 struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent);
37275 struct max8925_platform_data *max8925_pdata;
37276- struct max8925_power_pdata *pdata = NULL;
37277+ const struct max8925_power_pdata *pdata = NULL;
37278 struct max8925_power_info *info;
37279 int ret;
37280
37281diff -urNp linux-2.6.39.1/drivers/regulator/core.c linux-2.6.39.1/drivers/regulator/core.c
37282--- linux-2.6.39.1/drivers/regulator/core.c 2011-05-19 00:06:34.000000000 -0400
37283+++ linux-2.6.39.1/drivers/regulator/core.c 2011-05-22 19:36:32.000000000 -0400
37284@@ -2883,7 +2883,7 @@ core_initcall(regulator_init);
37285 static int __init regulator_init_complete(void)
37286 {
37287 struct regulator_dev *rdev;
37288- struct regulator_ops *ops;
37289+ const struct regulator_ops *ops;
37290 struct regulation_constraints *c;
37291 int enabled, ret;
37292
37293diff -urNp linux-2.6.39.1/drivers/rtc/rtc-at32ap700x.c linux-2.6.39.1/drivers/rtc/rtc-at32ap700x.c
37294--- linux-2.6.39.1/drivers/rtc/rtc-at32ap700x.c 2011-05-19 00:06:34.000000000 -0400
37295+++ linux-2.6.39.1/drivers/rtc/rtc-at32ap700x.c 2011-05-22 19:36:32.000000000 -0400
37296@@ -187,7 +187,7 @@ static irqreturn_t at32_rtc_interrupt(in
37297 return ret;
37298 }
37299
37300-static struct rtc_class_ops at32_rtc_ops = {
37301+static const struct rtc_class_ops at32_rtc_ops = {
37302 .read_time = at32_rtc_readtime,
37303 .set_time = at32_rtc_settime,
37304 .read_alarm = at32_rtc_readalarm,
37305diff -urNp linux-2.6.39.1/drivers/rtc/rtc-au1xxx.c linux-2.6.39.1/drivers/rtc/rtc-au1xxx.c
37306--- linux-2.6.39.1/drivers/rtc/rtc-au1xxx.c 2011-05-19 00:06:34.000000000 -0400
37307+++ linux-2.6.39.1/drivers/rtc/rtc-au1xxx.c 2011-05-22 19:36:32.000000000 -0400
37308@@ -57,7 +57,7 @@ static int au1xtoy_rtc_set_time(struct d
37309 return 0;
37310 }
37311
37312-static struct rtc_class_ops au1xtoy_rtc_ops = {
37313+static const struct rtc_class_ops au1xtoy_rtc_ops = {
37314 .read_time = au1xtoy_rtc_read_time,
37315 .set_time = au1xtoy_rtc_set_time,
37316 };
37317diff -urNp linux-2.6.39.1/drivers/rtc/rtc-bfin.c linux-2.6.39.1/drivers/rtc/rtc-bfin.c
37318--- linux-2.6.39.1/drivers/rtc/rtc-bfin.c 2011-05-19 00:06:34.000000000 -0400
37319+++ linux-2.6.39.1/drivers/rtc/rtc-bfin.c 2011-05-22 19:36:32.000000000 -0400
37320@@ -333,7 +333,7 @@ static int bfin_rtc_proc(struct device *
37321 #undef yesno
37322 }
37323
37324-static struct rtc_class_ops bfin_rtc_ops = {
37325+static const struct rtc_class_ops bfin_rtc_ops = {
37326 .read_time = bfin_rtc_read_time,
37327 .set_time = bfin_rtc_set_time,
37328 .read_alarm = bfin_rtc_read_alarm,
37329diff -urNp linux-2.6.39.1/drivers/rtc/rtc-coh901331.c linux-2.6.39.1/drivers/rtc/rtc-coh901331.c
37330--- linux-2.6.39.1/drivers/rtc/rtc-coh901331.c 2011-05-19 00:06:34.000000000 -0400
37331+++ linux-2.6.39.1/drivers/rtc/rtc-coh901331.c 2011-05-22 19:36:32.000000000 -0400
37332@@ -142,7 +142,7 @@ static int coh901331_alarm_irq_enable(st
37333 return 0;
37334 }
37335
37336-static struct rtc_class_ops coh901331_ops = {
37337+static const struct rtc_class_ops coh901331_ops = {
37338 .read_time = coh901331_read_time,
37339 .set_mmss = coh901331_set_mmss,
37340 .read_alarm = coh901331_read_alarm,
37341diff -urNp linux-2.6.39.1/drivers/rtc/rtc-davinci.c linux-2.6.39.1/drivers/rtc/rtc-davinci.c
37342--- linux-2.6.39.1/drivers/rtc/rtc-davinci.c 2011-05-19 00:06:34.000000000 -0400
37343+++ linux-2.6.39.1/drivers/rtc/rtc-davinci.c 2011-05-22 19:36:32.000000000 -0400
37344@@ -469,7 +469,7 @@ static int davinci_rtc_set_alarm(struct
37345 return 0;
37346 }
37347
37348-static struct rtc_class_ops davinci_rtc_ops = {
37349+static const struct rtc_class_ops davinci_rtc_ops = {
37350 .ioctl = davinci_rtc_ioctl,
37351 .read_time = davinci_rtc_read_time,
37352 .set_time = davinci_rtc_set_time,
37353diff -urNp linux-2.6.39.1/drivers/rtc/rtc-dev.c linux-2.6.39.1/drivers/rtc/rtc-dev.c
37354--- linux-2.6.39.1/drivers/rtc/rtc-dev.c 2011-05-19 00:06:34.000000000 -0400
37355+++ linux-2.6.39.1/drivers/rtc/rtc-dev.c 2011-05-22 19:41:37.000000000 -0400
37356@@ -14,6 +14,7 @@
37357 #include <linux/module.h>
37358 #include <linux/rtc.h>
37359 #include <linux/sched.h>
37360+#include <linux/grsecurity.h>
37361 #include "rtc-core.h"
37362
37363 static dev_t rtc_devt;
37364@@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *f
37365 if (copy_from_user(&tm, uarg, sizeof(tm)))
37366 return -EFAULT;
37367
37368+ gr_log_timechange();
37369+
37370 return rtc_set_time(rtc, &tm);
37371
37372 case RTC_PIE_ON:
37373diff -urNp linux-2.6.39.1/drivers/rtc/rtc-dm355evm.c linux-2.6.39.1/drivers/rtc/rtc-dm355evm.c
37374--- linux-2.6.39.1/drivers/rtc/rtc-dm355evm.c 2011-05-19 00:06:34.000000000 -0400
37375+++ linux-2.6.39.1/drivers/rtc/rtc-dm355evm.c 2011-05-22 19:36:32.000000000 -0400
37376@@ -115,7 +115,7 @@ static int dm355evm_rtc_set_time(struct
37377 return 0;
37378 }
37379
37380-static struct rtc_class_ops dm355evm_rtc_ops = {
37381+static const struct rtc_class_ops dm355evm_rtc_ops = {
37382 .read_time = dm355evm_rtc_read_time,
37383 .set_time = dm355evm_rtc_set_time,
37384 };
37385diff -urNp linux-2.6.39.1/drivers/rtc/rtc-ds1302.c linux-2.6.39.1/drivers/rtc/rtc-ds1302.c
37386--- linux-2.6.39.1/drivers/rtc/rtc-ds1302.c 2011-05-19 00:06:34.000000000 -0400
37387+++ linux-2.6.39.1/drivers/rtc/rtc-ds1302.c 2011-05-22 19:36:32.000000000 -0400
37388@@ -199,7 +199,7 @@ static int ds1302_rtc_ioctl(struct devic
37389 return -ENOIOCTLCMD;
37390 }
37391
37392-static struct rtc_class_ops ds1302_rtc_ops = {
37393+static const struct rtc_class_ops ds1302_rtc_ops = {
37394 .read_time = ds1302_rtc_read_time,
37395 .set_time = ds1302_rtc_set_time,
37396 .ioctl = ds1302_rtc_ioctl,
37397diff -urNp linux-2.6.39.1/drivers/rtc/rtc-imxdi.c linux-2.6.39.1/drivers/rtc/rtc-imxdi.c
37398--- linux-2.6.39.1/drivers/rtc/rtc-imxdi.c 2011-05-19 00:06:34.000000000 -0400
37399+++ linux-2.6.39.1/drivers/rtc/rtc-imxdi.c 2011-05-22 19:36:32.000000000 -0400
37400@@ -290,7 +290,7 @@ static int dryice_rtc_set_alarm(struct d
37401 return 0;
37402 }
37403
37404-static struct rtc_class_ops dryice_rtc_ops = {
37405+static const struct rtc_class_ops dryice_rtc_ops = {
37406 .read_time = dryice_rtc_read_time,
37407 .set_mmss = dryice_rtc_set_mmss,
37408 .alarm_irq_enable = dryice_rtc_alarm_irq_enable,
37409diff -urNp linux-2.6.39.1/drivers/rtc/rtc-jz4740.c linux-2.6.39.1/drivers/rtc/rtc-jz4740.c
37410--- linux-2.6.39.1/drivers/rtc/rtc-jz4740.c 2011-05-19 00:06:34.000000000 -0400
37411+++ linux-2.6.39.1/drivers/rtc/rtc-jz4740.c 2011-05-22 19:36:32.000000000 -0400
37412@@ -174,7 +174,7 @@ static int jz4740_rtc_alarm_irq_enable(s
37413 return jz4740_rtc_ctrl_set_bits(rtc, JZ_RTC_CTRL_AF_IRQ, enable);
37414 }
37415
37416-static struct rtc_class_ops jz4740_rtc_ops = {
37417+static const struct rtc_class_ops jz4740_rtc_ops = {
37418 .read_time = jz4740_rtc_read_time,
37419 .set_mmss = jz4740_rtc_set_mmss,
37420 .read_alarm = jz4740_rtc_read_alarm,
37421diff -urNp linux-2.6.39.1/drivers/rtc/rtc-m41t80.c linux-2.6.39.1/drivers/rtc/rtc-m41t80.c
37422--- linux-2.6.39.1/drivers/rtc/rtc-m41t80.c 2011-05-19 00:06:34.000000000 -0400
37423+++ linux-2.6.39.1/drivers/rtc/rtc-m41t80.c 2011-05-22 19:36:32.000000000 -0400
37424@@ -354,7 +354,7 @@ static int m41t80_rtc_read_alarm(struct
37425 return 0;
37426 }
37427
37428-static struct rtc_class_ops m41t80_rtc_ops = {
37429+static const struct rtc_class_ops m41t80_rtc_ops = {
37430 .read_time = m41t80_rtc_read_time,
37431 .set_time = m41t80_rtc_set_time,
37432 .read_alarm = m41t80_rtc_read_alarm,
37433diff -urNp linux-2.6.39.1/drivers/rtc/rtc-mxc.c linux-2.6.39.1/drivers/rtc/rtc-mxc.c
37434--- linux-2.6.39.1/drivers/rtc/rtc-mxc.c 2011-05-19 00:06:34.000000000 -0400
37435+++ linux-2.6.39.1/drivers/rtc/rtc-mxc.c 2011-05-22 19:36:32.000000000 -0400
37436@@ -355,7 +355,7 @@ static int mxc_rtc_set_alarm(struct devi
37437 }
37438
37439 /* RTC layer */
37440-static struct rtc_class_ops mxc_rtc_ops = {
37441+static const struct rtc_class_ops mxc_rtc_ops = {
37442 .release = mxc_rtc_release,
37443 .read_time = mxc_rtc_read_time,
37444 .set_mmss = mxc_rtc_set_mmss,
37445diff -urNp linux-2.6.39.1/drivers/rtc/rtc-nuc900.c linux-2.6.39.1/drivers/rtc/rtc-nuc900.c
37446--- linux-2.6.39.1/drivers/rtc/rtc-nuc900.c 2011-05-19 00:06:34.000000000 -0400
37447+++ linux-2.6.39.1/drivers/rtc/rtc-nuc900.c 2011-05-22 19:36:32.000000000 -0400
37448@@ -214,7 +214,7 @@ static int nuc900_rtc_set_alarm(struct d
37449 return 0;
37450 }
37451
37452-static struct rtc_class_ops nuc900_rtc_ops = {
37453+static const struct rtc_class_ops nuc900_rtc_ops = {
37454 .read_time = nuc900_rtc_read_time,
37455 .set_time = nuc900_rtc_set_time,
37456 .read_alarm = nuc900_rtc_read_alarm,
37457diff -urNp linux-2.6.39.1/drivers/rtc/rtc-omap.c linux-2.6.39.1/drivers/rtc/rtc-omap.c
37458--- linux-2.6.39.1/drivers/rtc/rtc-omap.c 2011-05-19 00:06:34.000000000 -0400
37459+++ linux-2.6.39.1/drivers/rtc/rtc-omap.c 2011-05-22 19:36:32.000000000 -0400
37460@@ -274,7 +274,7 @@ static int omap_rtc_set_alarm(struct dev
37461 return 0;
37462 }
37463
37464-static struct rtc_class_ops omap_rtc_ops = {
37465+static const struct rtc_class_ops omap_rtc_ops = {
37466 .read_time = omap_rtc_read_time,
37467 .set_time = omap_rtc_set_time,
37468 .read_alarm = omap_rtc_read_alarm,
37469diff -urNp linux-2.6.39.1/drivers/rtc/rtc-pcf50633.c linux-2.6.39.1/drivers/rtc/rtc-pcf50633.c
37470--- linux-2.6.39.1/drivers/rtc/rtc-pcf50633.c 2011-05-19 00:06:34.000000000 -0400
37471+++ linux-2.6.39.1/drivers/rtc/rtc-pcf50633.c 2011-05-22 19:36:32.000000000 -0400
37472@@ -238,7 +238,7 @@ static int pcf50633_rtc_set_alarm(struct
37473 return ret;
37474 }
37475
37476-static struct rtc_class_ops pcf50633_rtc_ops = {
37477+static const struct rtc_class_ops pcf50633_rtc_ops = {
37478 .read_time = pcf50633_rtc_read_time,
37479 .set_time = pcf50633_rtc_set_time,
37480 .read_alarm = pcf50633_rtc_read_alarm,
37481diff -urNp linux-2.6.39.1/drivers/rtc/rtc-pl031.c linux-2.6.39.1/drivers/rtc/rtc-pl031.c
37482--- linux-2.6.39.1/drivers/rtc/rtc-pl031.c 2011-05-19 00:06:34.000000000 -0400
37483+++ linux-2.6.39.1/drivers/rtc/rtc-pl031.c 2011-05-22 19:36:32.000000000 -0400
37484@@ -374,7 +374,7 @@ err_req:
37485 }
37486
37487 /* Operations for the original ARM version */
37488-static struct rtc_class_ops arm_pl031_ops = {
37489+static const struct rtc_class_ops arm_pl031_ops = {
37490 .read_time = pl031_read_time,
37491 .set_time = pl031_set_time,
37492 .read_alarm = pl031_read_alarm,
37493@@ -383,7 +383,7 @@ static struct rtc_class_ops arm_pl031_op
37494 };
37495
37496 /* The First ST derivative */
37497-static struct rtc_class_ops stv1_pl031_ops = {
37498+static const struct rtc_class_ops stv1_pl031_ops = {
37499 .read_time = pl031_read_time,
37500 .set_time = pl031_set_time,
37501 .read_alarm = pl031_read_alarm,
37502@@ -392,7 +392,7 @@ static struct rtc_class_ops stv1_pl031_o
37503 };
37504
37505 /* And the second ST derivative */
37506-static struct rtc_class_ops stv2_pl031_ops = {
37507+static const struct rtc_class_ops stv2_pl031_ops = {
37508 .read_time = pl031_stv2_read_time,
37509 .set_time = pl031_stv2_set_time,
37510 .read_alarm = pl031_stv2_read_alarm,
37511diff -urNp linux-2.6.39.1/drivers/rtc/rtc-rx8025.c linux-2.6.39.1/drivers/rtc/rtc-rx8025.c
37512--- linux-2.6.39.1/drivers/rtc/rtc-rx8025.c 2011-05-19 00:06:34.000000000 -0400
37513+++ linux-2.6.39.1/drivers/rtc/rtc-rx8025.c 2011-05-22 19:36:32.000000000 -0400
37514@@ -424,7 +424,7 @@ static int rx8025_alarm_irq_enable(struc
37515 return 0;
37516 }
37517
37518-static struct rtc_class_ops rx8025_rtc_ops = {
37519+static const struct rtc_class_ops rx8025_rtc_ops = {
37520 .read_time = rx8025_get_time,
37521 .set_time = rx8025_set_time,
37522 .read_alarm = rx8025_read_alarm,
37523diff -urNp linux-2.6.39.1/drivers/rtc/rtc-sh.c linux-2.6.39.1/drivers/rtc/rtc-sh.c
37524--- linux-2.6.39.1/drivers/rtc/rtc-sh.c 2011-05-19 00:06:34.000000000 -0400
37525+++ linux-2.6.39.1/drivers/rtc/rtc-sh.c 2011-05-22 19:36:32.000000000 -0400
37526@@ -576,7 +576,7 @@ static int sh_rtc_set_alarm(struct devic
37527 return 0;
37528 }
37529
37530-static struct rtc_class_ops sh_rtc_ops = {
37531+static const struct rtc_class_ops sh_rtc_ops = {
37532 .read_time = sh_rtc_read_time,
37533 .set_time = sh_rtc_set_time,
37534 .read_alarm = sh_rtc_read_alarm,
37535diff -urNp linux-2.6.39.1/drivers/rtc/rtc-stmp3xxx.c linux-2.6.39.1/drivers/rtc/rtc-stmp3xxx.c
37536--- linux-2.6.39.1/drivers/rtc/rtc-stmp3xxx.c 2011-05-19 00:06:34.000000000 -0400
37537+++ linux-2.6.39.1/drivers/rtc/rtc-stmp3xxx.c 2011-05-22 19:36:32.000000000 -0400
37538@@ -133,7 +133,7 @@ static int stmp3xxx_rtc_set_alarm(struct
37539 return 0;
37540 }
37541
37542-static struct rtc_class_ops stmp3xxx_rtc_ops = {
37543+static const struct rtc_class_ops stmp3xxx_rtc_ops = {
37544 .alarm_irq_enable =
37545 stmp3xxx_alarm_irq_enable,
37546 .read_time = stmp3xxx_rtc_gettime,
37547diff -urNp linux-2.6.39.1/drivers/rtc/rtc-tegra.c linux-2.6.39.1/drivers/rtc/rtc-tegra.c
37548--- linux-2.6.39.1/drivers/rtc/rtc-tegra.c 2011-05-19 00:06:34.000000000 -0400
37549+++ linux-2.6.39.1/drivers/rtc/rtc-tegra.c 2011-05-22 19:36:32.000000000 -0400
37550@@ -294,7 +294,7 @@ static irqreturn_t tegra_rtc_irq_handler
37551 return IRQ_HANDLED;
37552 }
37553
37554-static struct rtc_class_ops tegra_rtc_ops = {
37555+static const struct rtc_class_ops tegra_rtc_ops = {
37556 .read_time = tegra_rtc_read_time,
37557 .set_time = tegra_rtc_set_time,
37558 .read_alarm = tegra_rtc_read_alarm,
37559diff -urNp linux-2.6.39.1/drivers/rtc/rtc-twl.c linux-2.6.39.1/drivers/rtc/rtc-twl.c
37560--- linux-2.6.39.1/drivers/rtc/rtc-twl.c 2011-05-19 00:06:34.000000000 -0400
37561+++ linux-2.6.39.1/drivers/rtc/rtc-twl.c 2011-05-22 19:36:32.000000000 -0400
37562@@ -415,7 +415,7 @@ out:
37563 return ret;
37564 }
37565
37566-static struct rtc_class_ops twl_rtc_ops = {
37567+static const struct rtc_class_ops twl_rtc_ops = {
37568 .read_time = twl_rtc_read_time,
37569 .set_time = twl_rtc_set_time,
37570 .read_alarm = twl_rtc_read_alarm,
37571diff -urNp linux-2.6.39.1/drivers/rtc/rtc-v3020.c linux-2.6.39.1/drivers/rtc/rtc-v3020.c
37572--- linux-2.6.39.1/drivers/rtc/rtc-v3020.c 2011-05-19 00:06:34.000000000 -0400
37573+++ linux-2.6.39.1/drivers/rtc/rtc-v3020.c 2011-05-22 19:36:32.000000000 -0400
37574@@ -62,7 +62,7 @@ struct v3020 {
37575 /* GPIO access */
37576 struct v3020_gpio *gpio;
37577
37578- struct v3020_chip_ops *ops;
37579+ const struct v3020_chip_ops *ops;
37580
37581 struct rtc_device *rtc;
37582 };
37583@@ -100,7 +100,7 @@ static unsigned char v3020_mmio_read_bit
37584 return !!(readl(chip->ioaddress) & (1 << chip->leftshift));
37585 }
37586
37587-static struct v3020_chip_ops v3020_mmio_ops = {
37588+static const struct v3020_chip_ops v3020_mmio_ops = {
37589 .map_io = v3020_mmio_map,
37590 .unmap_io = v3020_mmio_unmap,
37591 .read_bit = v3020_mmio_read_bit,
37592@@ -177,7 +177,7 @@ static unsigned char v3020_gpio_read_bit
37593 return bit;
37594 }
37595
37596-static struct v3020_chip_ops v3020_gpio_ops = {
37597+static const struct v3020_chip_ops v3020_gpio_ops = {
37598 .map_io = v3020_gpio_map,
37599 .unmap_io = v3020_gpio_unmap,
37600 .read_bit = v3020_gpio_read_bit,
37601diff -urNp linux-2.6.39.1/drivers/s390/char/con3270.c linux-2.6.39.1/drivers/s390/char/con3270.c
37602--- linux-2.6.39.1/drivers/s390/char/con3270.c 2011-05-19 00:06:34.000000000 -0400
37603+++ linux-2.6.39.1/drivers/s390/char/con3270.c 2011-05-22 19:36:32.000000000 -0400
37604@@ -28,7 +28,7 @@
37605 #define CON3270_OUTPUT_BUFFER_SIZE 1024
37606 #define CON3270_STRING_PAGES 4
37607
37608-static struct raw3270_fn con3270_fn;
37609+static const struct raw3270_fn con3270_fn;
37610
37611 /*
37612 * Main 3270 console view data structure.
37613@@ -413,7 +413,7 @@ con3270_irq(struct con3270 *cp, struct r
37614 }
37615
37616 /* Console view to a 3270 device. */
37617-static struct raw3270_fn con3270_fn = {
37618+static const struct raw3270_fn con3270_fn = {
37619 .activate = con3270_activate,
37620 .deactivate = con3270_deactivate,
37621 .intv = (void *) con3270_irq
37622diff -urNp linux-2.6.39.1/drivers/s390/char/fs3270.c linux-2.6.39.1/drivers/s390/char/fs3270.c
37623--- linux-2.6.39.1/drivers/s390/char/fs3270.c 2011-05-19 00:06:34.000000000 -0400
37624+++ linux-2.6.39.1/drivers/s390/char/fs3270.c 2011-05-22 19:36:32.000000000 -0400
37625@@ -24,7 +24,7 @@
37626 #include "raw3270.h"
37627 #include "ctrlchar.h"
37628
37629-static struct raw3270_fn fs3270_fn;
37630+static const struct raw3270_fn fs3270_fn;
37631
37632 struct fs3270 {
37633 struct raw3270_view view;
37634@@ -413,7 +413,7 @@ fs3270_release(struct raw3270_view *view
37635 }
37636
37637 /* View to a 3270 device. Can be console, tty or fullscreen. */
37638-static struct raw3270_fn fs3270_fn = {
37639+static const struct raw3270_fn fs3270_fn = {
37640 .activate = fs3270_activate,
37641 .deactivate = fs3270_deactivate,
37642 .intv = (void *) fs3270_irq,
37643diff -urNp linux-2.6.39.1/drivers/s390/char/raw3270.c linux-2.6.39.1/drivers/s390/char/raw3270.c
37644--- linux-2.6.39.1/drivers/s390/char/raw3270.c 2011-05-19 00:06:34.000000000 -0400
37645+++ linux-2.6.39.1/drivers/s390/char/raw3270.c 2011-05-22 19:36:32.000000000 -0400
37646@@ -488,7 +488,7 @@ raw3270_init_irq(struct raw3270_view *vi
37647 return RAW3270_IO_DONE;
37648 }
37649
37650-static struct raw3270_fn raw3270_init_fn = {
37651+static const struct raw3270_fn raw3270_init_fn = {
37652 .intv = raw3270_init_irq
37653 };
37654
37655diff -urNp linux-2.6.39.1/drivers/s390/char/tty3270.c linux-2.6.39.1/drivers/s390/char/tty3270.c
37656--- linux-2.6.39.1/drivers/s390/char/tty3270.c 2011-05-19 00:06:34.000000000 -0400
37657+++ linux-2.6.39.1/drivers/s390/char/tty3270.c 2011-05-22 19:36:32.000000000 -0400
37658@@ -37,7 +37,7 @@
37659 struct tty_driver *tty3270_driver;
37660 static int tty3270_max_index;
37661
37662-static struct raw3270_fn tty3270_fn;
37663+static const struct raw3270_fn tty3270_fn;
37664
37665 struct tty3270_cell {
37666 unsigned char character;
37667@@ -834,7 +834,7 @@ tty3270_del_views(void)
37668 }
37669 }
37670
37671-static struct raw3270_fn tty3270_fn = {
37672+static const struct raw3270_fn tty3270_fn = {
37673 .activate = tty3270_activate,
37674 .deactivate = tty3270_deactivate,
37675 .intv = (void *) tty3270_irq,
37676diff -urNp linux-2.6.39.1/drivers/s390/cio/qdio_debug.c linux-2.6.39.1/drivers/s390/cio/qdio_debug.c
37677--- linux-2.6.39.1/drivers/s390/cio/qdio_debug.c 2011-05-19 00:06:34.000000000 -0400
37678+++ linux-2.6.39.1/drivers/s390/cio/qdio_debug.c 2011-05-22 19:36:32.000000000 -0400
37679@@ -225,7 +225,7 @@ static int qperf_seq_open(struct inode *
37680 filp->f_path.dentry->d_inode->i_private);
37681 }
37682
37683-static struct file_operations debugfs_perf_fops = {
37684+static const struct file_operations debugfs_perf_fops = {
37685 .owner = THIS_MODULE,
37686 .open = qperf_seq_open,
37687 .read = seq_read,
37688diff -urNp linux-2.6.39.1/drivers/s390/crypto/zcrypt_cex2a.c linux-2.6.39.1/drivers/s390/crypto/zcrypt_cex2a.c
37689--- linux-2.6.39.1/drivers/s390/crypto/zcrypt_cex2a.c 2011-05-19 00:06:34.000000000 -0400
37690+++ linux-2.6.39.1/drivers/s390/crypto/zcrypt_cex2a.c 2011-05-22 19:36:32.000000000 -0400
37691@@ -415,7 +415,7 @@ out_free:
37692 /**
37693 * The crypto operations for a CEX2A card.
37694 */
37695-static struct zcrypt_ops zcrypt_cex2a_ops = {
37696+static const struct zcrypt_ops zcrypt_cex2a_ops = {
37697 .rsa_modexpo = zcrypt_cex2a_modexpo,
37698 .rsa_modexpo_crt = zcrypt_cex2a_modexpo_crt,
37699 };
37700diff -urNp linux-2.6.39.1/drivers/s390/crypto/zcrypt_pcica.c linux-2.6.39.1/drivers/s390/crypto/zcrypt_pcica.c
37701--- linux-2.6.39.1/drivers/s390/crypto/zcrypt_pcica.c 2011-05-19 00:06:34.000000000 -0400
37702+++ linux-2.6.39.1/drivers/s390/crypto/zcrypt_pcica.c 2011-05-22 19:36:32.000000000 -0400
37703@@ -347,7 +347,7 @@ out_free:
37704 /**
37705 * The crypto operations for a PCICA card.
37706 */
37707-static struct zcrypt_ops zcrypt_pcica_ops = {
37708+static const struct zcrypt_ops zcrypt_pcica_ops = {
37709 .rsa_modexpo = zcrypt_pcica_modexpo,
37710 .rsa_modexpo_crt = zcrypt_pcica_modexpo_crt,
37711 };
37712diff -urNp linux-2.6.39.1/drivers/s390/crypto/zcrypt_pcicc.c linux-2.6.39.1/drivers/s390/crypto/zcrypt_pcicc.c
37713--- linux-2.6.39.1/drivers/s390/crypto/zcrypt_pcicc.c 2011-05-19 00:06:34.000000000 -0400
37714+++ linux-2.6.39.1/drivers/s390/crypto/zcrypt_pcicc.c 2011-05-22 19:36:32.000000000 -0400
37715@@ -553,7 +553,7 @@ out_free:
37716 /**
37717 * The crypto operations for a PCICC card.
37718 */
37719-static struct zcrypt_ops zcrypt_pcicc_ops = {
37720+static const struct zcrypt_ops zcrypt_pcicc_ops = {
37721 .rsa_modexpo = zcrypt_pcicc_modexpo,
37722 .rsa_modexpo_crt = zcrypt_pcicc_modexpo_crt,
37723 };
37724diff -urNp linux-2.6.39.1/drivers/s390/crypto/zcrypt_pcixcc.c linux-2.6.39.1/drivers/s390/crypto/zcrypt_pcixcc.c
37725--- linux-2.6.39.1/drivers/s390/crypto/zcrypt_pcixcc.c 2011-05-19 00:06:34.000000000 -0400
37726+++ linux-2.6.39.1/drivers/s390/crypto/zcrypt_pcixcc.c 2011-05-22 19:36:32.000000000 -0400
37727@@ -851,13 +851,13 @@ static long zcrypt_pcixcc_rng(struct zcr
37728 /**
37729 * The crypto operations for a PCIXCC/CEX2C card.
37730 */
37731-static struct zcrypt_ops zcrypt_pcixcc_ops = {
37732+static const struct zcrypt_ops zcrypt_pcixcc_ops = {
37733 .rsa_modexpo = zcrypt_pcixcc_modexpo,
37734 .rsa_modexpo_crt = zcrypt_pcixcc_modexpo_crt,
37735 .send_cprb = zcrypt_pcixcc_send_cprb,
37736 };
37737
37738-static struct zcrypt_ops zcrypt_pcixcc_with_rng_ops = {
37739+static const struct zcrypt_ops zcrypt_pcixcc_with_rng_ops = {
37740 .rsa_modexpo = zcrypt_pcixcc_modexpo,
37741 .rsa_modexpo_crt = zcrypt_pcixcc_modexpo_crt,
37742 .send_cprb = zcrypt_pcixcc_send_cprb,
37743diff -urNp linux-2.6.39.1/drivers/s390/kvm/kvm_virtio.c linux-2.6.39.1/drivers/s390/kvm/kvm_virtio.c
37744--- linux-2.6.39.1/drivers/s390/kvm/kvm_virtio.c 2011-05-19 00:06:34.000000000 -0400
37745+++ linux-2.6.39.1/drivers/s390/kvm/kvm_virtio.c 2011-05-22 19:36:32.000000000 -0400
37746@@ -266,7 +266,7 @@ error:
37747 /*
37748 * The config ops structure as defined by virtio config
37749 */
37750-static struct virtio_config_ops kvm_vq_configspace_ops = {
37751+static const struct virtio_config_ops kvm_vq_configspace_ops = {
37752 .get_features = kvm_get_features,
37753 .finalize_features = kvm_finalize_features,
37754 .get = kvm_get,
37755diff -urNp linux-2.6.39.1/drivers/s390/net/qeth_core.h linux-2.6.39.1/drivers/s390/net/qeth_core.h
37756--- linux-2.6.39.1/drivers/s390/net/qeth_core.h 2011-05-19 00:06:34.000000000 -0400
37757+++ linux-2.6.39.1/drivers/s390/net/qeth_core.h 2011-05-22 19:36:32.000000000 -0400
37758@@ -743,7 +743,7 @@ struct qeth_card {
37759 struct qeth_qdio_info qdio;
37760 struct qeth_perf_stats perf_stats;
37761 int read_or_write_problem;
37762- struct qeth_osn_info osn_info;
37763+ const struct qeth_osn_info osn_info;
37764 struct qeth_discipline discipline;
37765 atomic_t force_alloc_skb;
37766 struct service_level qeth_service_level;
37767diff -urNp linux-2.6.39.1/drivers/scsi/53c700.c linux-2.6.39.1/drivers/scsi/53c700.c
37768--- linux-2.6.39.1/drivers/scsi/53c700.c 2011-05-19 00:06:34.000000000 -0400
37769+++ linux-2.6.39.1/drivers/scsi/53c700.c 2011-05-22 19:36:32.000000000 -0400
37770@@ -2153,7 +2153,7 @@ EXPORT_SYMBOL(NCR_700_detect);
37771 EXPORT_SYMBOL(NCR_700_release);
37772 EXPORT_SYMBOL(NCR_700_intr);
37773
37774-static struct spi_function_template NCR_700_transport_functions = {
37775+static struct spi_function_template NCR_700_transport_functions = {
37776 .set_period = NCR_700_set_period,
37777 .show_period = 1,
37778 .set_offset = NCR_700_set_offset,
37779diff -urNp linux-2.6.39.1/drivers/scsi/aacraid/commctrl.c linux-2.6.39.1/drivers/scsi/aacraid/commctrl.c
37780--- linux-2.6.39.1/drivers/scsi/aacraid/commctrl.c 2011-05-19 00:06:34.000000000 -0400
37781+++ linux-2.6.39.1/drivers/scsi/aacraid/commctrl.c 2011-05-22 19:36:32.000000000 -0400
37782@@ -482,6 +482,7 @@ static int aac_send_raw_srb(struct aac_d
37783 u32 actual_fibsize64, actual_fibsize = 0;
37784 int i;
37785
37786+ pax_track_stack();
37787
37788 if (dev->in_reset) {
37789 dprintk((KERN_DEBUG"aacraid: send raw srb -EBUSY\n"));
37790diff -urNp linux-2.6.39.1/drivers/scsi/aic94xx/aic94xx_init.c linux-2.6.39.1/drivers/scsi/aic94xx/aic94xx_init.c
37791--- linux-2.6.39.1/drivers/scsi/aic94xx/aic94xx_init.c 2011-05-19 00:06:34.000000000 -0400
37792+++ linux-2.6.39.1/drivers/scsi/aic94xx/aic94xx_init.c 2011-05-22 19:41:37.000000000 -0400
37793@@ -486,7 +486,7 @@ static ssize_t asd_show_update_bios(stru
37794 flash_error_table[i].reason);
37795 }
37796
37797-static DEVICE_ATTR(update_bios, S_IRUGO|S_IWUGO,
37798+static DEVICE_ATTR(update_bios, S_IRUGO|S_IWUSR,
37799 asd_show_update_bios, asd_store_update_bios);
37800
37801 static int asd_create_dev_attrs(struct asd_ha_struct *asd_ha)
37802diff -urNp linux-2.6.39.1/drivers/scsi/bfa/bfa_core.c linux-2.6.39.1/drivers/scsi/bfa/bfa_core.c
37803--- linux-2.6.39.1/drivers/scsi/bfa/bfa_core.c 2011-05-19 00:06:34.000000000 -0400
37804+++ linux-2.6.39.1/drivers/scsi/bfa/bfa_core.c 2011-05-22 19:36:32.000000000 -0400
37805@@ -24,7 +24,7 @@ BFA_TRC_FILE(HAL, CORE);
37806 /*
37807 * BFA module list terminated by NULL
37808 */
37809-static struct bfa_module_s *hal_mods[] = {
37810+static const struct bfa_module_s *hal_mods[] = {
37811 &hal_mod_sgpg,
37812 &hal_mod_fcport,
37813 &hal_mod_fcxp,
37814diff -urNp linux-2.6.39.1/drivers/scsi/bfa/bfad.c linux-2.6.39.1/drivers/scsi/bfa/bfad.c
37815--- linux-2.6.39.1/drivers/scsi/bfa/bfad.c 2011-05-19 00:06:34.000000000 -0400
37816+++ linux-2.6.39.1/drivers/scsi/bfa/bfad.c 2011-05-22 19:36:32.000000000 -0400
37817@@ -1027,6 +1027,8 @@ bfad_start_ops(struct bfad_s *bfad) {
37818 struct bfad_vport_s *vport, *vport_new;
37819 struct bfa_fcs_driver_info_s driver_info;
37820
37821+ pax_track_stack();
37822+
37823 /* Fill the driver_info info to fcs*/
37824 memset(&driver_info, 0, sizeof(driver_info));
37825 strncpy(driver_info.version, BFAD_DRIVER_VERSION,
37826diff -urNp linux-2.6.39.1/drivers/scsi/bfa/bfa_fcs.c linux-2.6.39.1/drivers/scsi/bfa/bfa_fcs.c
37827--- linux-2.6.39.1/drivers/scsi/bfa/bfa_fcs.c 2011-05-19 00:06:34.000000000 -0400
37828+++ linux-2.6.39.1/drivers/scsi/bfa/bfa_fcs.c 2011-05-22 19:36:32.000000000 -0400
37829@@ -70,7 +70,7 @@ bfa_fcs_attach(struct bfa_fcs_s *fcs, st
37830 bfa_boolean_t min_cfg)
37831 {
37832 int i;
37833- struct bfa_fcs_mod_s *mod;
37834+ const struct bfa_fcs_mod_s *mod;
37835
37836 fcs->bfa = bfa;
37837 fcs->bfad = bfad;
37838@@ -93,7 +93,7 @@ void
37839 bfa_fcs_init(struct bfa_fcs_s *fcs)
37840 {
37841 int i, npbc_vports;
37842- struct bfa_fcs_mod_s *mod;
37843+ const struct bfa_fcs_mod_s *mod;
37844 struct bfi_pbc_vport_s pbc_vports[BFI_PBC_MAX_VPORTS];
37845
37846 for (i = 0; i < sizeof(fcs_modules) / sizeof(fcs_modules[0]); i++) {
37847@@ -140,7 +140,7 @@ bfa_fcs_driver_info_init(struct bfa_fcs_
37848 void
37849 bfa_fcs_exit(struct bfa_fcs_s *fcs)
37850 {
37851- struct bfa_fcs_mod_s *mod;
37852+ const struct bfa_fcs_mod_s *mod;
37853 int nmods, i;
37854
37855 bfa_wc_init(&fcs->wc, bfa_fcs_exit_comp, fcs);
37856diff -urNp linux-2.6.39.1/drivers/scsi/bfa/bfa_fcs_lport.c linux-2.6.39.1/drivers/scsi/bfa/bfa_fcs_lport.c
37857--- linux-2.6.39.1/drivers/scsi/bfa/bfa_fcs_lport.c 2011-05-19 00:06:34.000000000 -0400
37858+++ linux-2.6.39.1/drivers/scsi/bfa/bfa_fcs_lport.c 2011-05-22 19:36:32.000000000 -0400
37859@@ -1559,6 +1559,8 @@ bfa_fcs_lport_fdmi_build_rhba_pyld(struc
37860 u16 len, count;
37861 u16 templen;
37862
37863+ pax_track_stack();
37864+
37865 /*
37866 * get hba attributes
37867 */
37868@@ -1836,6 +1838,8 @@ bfa_fcs_lport_fdmi_build_portattr_block(
37869 u8 count = 0;
37870 u16 templen;
37871
37872+ pax_track_stack();
37873+
37874 /*
37875 * get port attributes
37876 */
37877diff -urNp linux-2.6.39.1/drivers/scsi/bfa/bfa_fcs_rport.c linux-2.6.39.1/drivers/scsi/bfa/bfa_fcs_rport.c
37878--- linux-2.6.39.1/drivers/scsi/bfa/bfa_fcs_rport.c 2011-05-19 00:06:34.000000000 -0400
37879+++ linux-2.6.39.1/drivers/scsi/bfa/bfa_fcs_rport.c 2011-05-22 19:36:32.000000000 -0400
37880@@ -1844,6 +1844,8 @@ bfa_fcs_rport_process_rpsc(struct bfa_fc
37881 struct fc_rpsc_speed_info_s speeds;
37882 struct bfa_port_attr_s pport_attr;
37883
37884+ pax_track_stack();
37885+
37886 bfa_trc(port->fcs, rx_fchs->s_id);
37887 bfa_trc(port->fcs, rx_fchs->d_id);
37888
37889diff -urNp linux-2.6.39.1/drivers/scsi/bfa/bfa_modules.h linux-2.6.39.1/drivers/scsi/bfa/bfa_modules.h
37890--- linux-2.6.39.1/drivers/scsi/bfa/bfa_modules.h 2011-05-19 00:06:34.000000000 -0400
37891+++ linux-2.6.39.1/drivers/scsi/bfa/bfa_modules.h 2011-05-22 19:36:32.000000000 -0400
37892@@ -68,8 +68,8 @@ enum {
37893 static void bfa_ ## __mod ## _stop(struct bfa_s *bfa); \
37894 static void bfa_ ## __mod ## _iocdisable(struct bfa_s *bfa); \
37895 \
37896- extern struct bfa_module_s hal_mod_ ## __mod; \
37897- struct bfa_module_s hal_mod_ ## __mod = { \
37898+ extern const struct bfa_module_s hal_mod_ ## __mod; \
37899+ const struct bfa_module_s hal_mod_ ## __mod = { \
37900 bfa_ ## __mod ## _meminfo, \
37901 bfa_ ## __mod ## _attach, \
37902 bfa_ ## __mod ## _detach, \
37903@@ -116,12 +116,12 @@ struct bfa_s {
37904 };
37905
37906 extern bfa_boolean_t bfa_auto_recover;
37907-extern struct bfa_module_s hal_mod_sgpg;
37908-extern struct bfa_module_s hal_mod_fcport;
37909-extern struct bfa_module_s hal_mod_fcxp;
37910-extern struct bfa_module_s hal_mod_lps;
37911-extern struct bfa_module_s hal_mod_uf;
37912-extern struct bfa_module_s hal_mod_rport;
37913-extern struct bfa_module_s hal_mod_fcpim;
37914+extern const struct bfa_module_s hal_mod_sgpg;
37915+extern const struct bfa_module_s hal_mod_fcport;
37916+extern const struct bfa_module_s hal_mod_fcxp;
37917+extern const struct bfa_module_s hal_mod_lps;
37918+extern const struct bfa_module_s hal_mod_uf;
37919+extern const struct bfa_module_s hal_mod_rport;
37920+extern const struct bfa_module_s hal_mod_fcpim;
37921
37922 #endif /* __BFA_MODULES_H__ */
37923diff -urNp linux-2.6.39.1/drivers/scsi/BusLogic.c linux-2.6.39.1/drivers/scsi/BusLogic.c
37924--- linux-2.6.39.1/drivers/scsi/BusLogic.c 2011-05-19 00:06:34.000000000 -0400
37925+++ linux-2.6.39.1/drivers/scsi/BusLogic.c 2011-05-22 19:36:32.000000000 -0400
37926@@ -962,6 +962,8 @@ static int __init BusLogic_InitializeFla
37927 static void __init BusLogic_InitializeProbeInfoList(struct BusLogic_HostAdapter
37928 *PrototypeHostAdapter)
37929 {
37930+ pax_track_stack();
37931+
37932 /*
37933 If a PCI BIOS is present, interrogate it for MultiMaster and FlashPoint
37934 Host Adapters; otherwise, default to the standard ISA MultiMaster probe.
37935diff -urNp linux-2.6.39.1/drivers/scsi/dpt_i2o.c linux-2.6.39.1/drivers/scsi/dpt_i2o.c
37936--- linux-2.6.39.1/drivers/scsi/dpt_i2o.c 2011-05-19 00:06:34.000000000 -0400
37937+++ linux-2.6.39.1/drivers/scsi/dpt_i2o.c 2011-05-22 19:36:32.000000000 -0400
37938@@ -1811,6 +1811,8 @@ static int adpt_i2o_passthru(adpt_hba* p
37939 dma_addr_t addr;
37940 ulong flags = 0;
37941
37942+ pax_track_stack();
37943+
37944 memset(&msg, 0, MAX_MESSAGE_SIZE*4);
37945 // get user msg size in u32s
37946 if(get_user(size, &user_msg[0])){
37947@@ -2317,6 +2319,8 @@ static s32 adpt_scsi_to_i2o(adpt_hba* pH
37948 s32 rcode;
37949 dma_addr_t addr;
37950
37951+ pax_track_stack();
37952+
37953 memset(msg, 0 , sizeof(msg));
37954 len = scsi_bufflen(cmd);
37955 direction = 0x00000000;
37956diff -urNp linux-2.6.39.1/drivers/scsi/eata.c linux-2.6.39.1/drivers/scsi/eata.c
37957--- linux-2.6.39.1/drivers/scsi/eata.c 2011-05-19 00:06:34.000000000 -0400
37958+++ linux-2.6.39.1/drivers/scsi/eata.c 2011-05-22 19:36:32.000000000 -0400
37959@@ -1087,6 +1087,8 @@ static int port_detect(unsigned long por
37960 struct hostdata *ha;
37961 char name[16];
37962
37963+ pax_track_stack();
37964+
37965 sprintf(name, "%s%d", driver_name, j);
37966
37967 if (!request_region(port_base, REGION_SIZE, driver_name)) {
37968diff -urNp linux-2.6.39.1/drivers/scsi/esp_scsi.c linux-2.6.39.1/drivers/scsi/esp_scsi.c
37969--- linux-2.6.39.1/drivers/scsi/esp_scsi.c 2011-05-19 00:06:34.000000000 -0400
37970+++ linux-2.6.39.1/drivers/scsi/esp_scsi.c 2011-05-22 19:36:32.000000000 -0400
37971@@ -2680,7 +2680,7 @@ static void esp_set_width(struct scsi_ta
37972 tp->flags |= ESP_TGT_CHECK_NEGO;
37973 }
37974
37975-static struct spi_function_template esp_transport_ops = {
37976+static const struct spi_function_template esp_transport_ops = {
37977 .set_offset = esp_set_offset,
37978 .show_offset = 1,
37979 .set_period = esp_set_period,
37980diff -urNp linux-2.6.39.1/drivers/scsi/fcoe/fcoe.c linux-2.6.39.1/drivers/scsi/fcoe/fcoe.c
37981--- linux-2.6.39.1/drivers/scsi/fcoe/fcoe.c 2011-05-19 00:06:34.000000000 -0400
37982+++ linux-2.6.39.1/drivers/scsi/fcoe/fcoe.c 2011-05-22 19:36:32.000000000 -0400
37983@@ -138,7 +138,7 @@ static int fcoe_vport_disable(struct fc_
37984 static void fcoe_set_vport_symbolic_name(struct fc_vport *);
37985 static void fcoe_set_port_id(struct fc_lport *, u32, struct fc_frame *);
37986
37987-static struct libfc_function_template fcoe_libfc_fcn_templ = {
37988+static const struct libfc_function_template fcoe_libfc_fcn_templ = {
37989 .frame_send = fcoe_xmit,
37990 .ddp_setup = fcoe_ddp_setup,
37991 .ddp_done = fcoe_ddp_done,
37992diff -urNp linux-2.6.39.1/drivers/scsi/fcoe/fcoe_ctlr.c linux-2.6.39.1/drivers/scsi/fcoe/fcoe_ctlr.c
37993--- linux-2.6.39.1/drivers/scsi/fcoe/fcoe_ctlr.c 2011-05-19 00:06:34.000000000 -0400
37994+++ linux-2.6.39.1/drivers/scsi/fcoe/fcoe_ctlr.c 2011-05-22 19:36:32.000000000 -0400
37995@@ -1912,7 +1912,7 @@ static void fcoe_ctlr_vn_rport_callback(
37996 mutex_unlock(&fip->ctlr_mutex);
37997 }
37998
37999-static struct fc_rport_operations fcoe_ctlr_vn_rport_ops = {
38000+static const struct fc_rport_operations fcoe_ctlr_vn_rport_ops = {
38001 .event_callback = fcoe_ctlr_vn_rport_callback,
38002 };
38003
38004@@ -2458,6 +2458,8 @@ static int fcoe_ctlr_vn_recv(struct fcoe
38005 } buf;
38006 int rc;
38007
38008+ pax_track_stack();
38009+
38010 fiph = (struct fip_header *)skb->data;
38011 sub = fiph->fip_subcode;
38012
38013diff -urNp linux-2.6.39.1/drivers/scsi/fnic/fnic_main.c linux-2.6.39.1/drivers/scsi/fnic/fnic_main.c
38014--- linux-2.6.39.1/drivers/scsi/fnic/fnic_main.c 2011-05-19 00:06:34.000000000 -0400
38015+++ linux-2.6.39.1/drivers/scsi/fnic/fnic_main.c 2011-05-22 19:36:32.000000000 -0400
38016@@ -69,7 +69,7 @@ module_param(fnic_log_level, int, S_IRUG
38017 MODULE_PARM_DESC(fnic_log_level, "bit mask of fnic logging levels");
38018
38019
38020-static struct libfc_function_template fnic_transport_template = {
38021+static const struct libfc_function_template fnic_transport_template = {
38022 .frame_send = fnic_send,
38023 .lport_set_port_id = fnic_set_port_id,
38024 .fcp_abort_io = fnic_empty_scsi_cleanup,
38025diff -urNp linux-2.6.39.1/drivers/scsi/gdth.c linux-2.6.39.1/drivers/scsi/gdth.c
38026--- linux-2.6.39.1/drivers/scsi/gdth.c 2011-05-19 00:06:34.000000000 -0400
38027+++ linux-2.6.39.1/drivers/scsi/gdth.c 2011-05-22 19:36:32.000000000 -0400
38028@@ -4107,6 +4107,8 @@ static int ioc_lockdrv(void __user *arg)
38029 unsigned long flags;
38030 gdth_ha_str *ha;
38031
38032+ pax_track_stack();
38033+
38034 if (copy_from_user(&ldrv, arg, sizeof(gdth_ioctl_lockdrv)))
38035 return -EFAULT;
38036 ha = gdth_find_ha(ldrv.ionode);
38037@@ -4139,6 +4141,8 @@ static int ioc_resetdrv(void __user *arg
38038 gdth_ha_str *ha;
38039 int rval;
38040
38041+ pax_track_stack();
38042+
38043 if (copy_from_user(&res, arg, sizeof(gdth_ioctl_reset)) ||
38044 res.number >= MAX_HDRIVES)
38045 return -EFAULT;
38046@@ -4174,6 +4178,8 @@ static int ioc_general(void __user *arg,
38047 gdth_ha_str *ha;
38048 int rval;
38049
38050+ pax_track_stack();
38051+
38052 if (copy_from_user(&gen, arg, sizeof(gdth_ioctl_general)))
38053 return -EFAULT;
38054 ha = gdth_find_ha(gen.ionode);
38055@@ -4642,6 +4648,9 @@ static void gdth_flush(gdth_ha_str *ha)
38056 int i;
38057 gdth_cmd_str gdtcmd;
38058 char cmnd[MAX_COMMAND_SIZE];
38059+
38060+ pax_track_stack();
38061+
38062 memset(cmnd, 0xff, MAX_COMMAND_SIZE);
38063
38064 TRACE2(("gdth_flush() hanum %d\n", ha->hanum));
38065diff -urNp linux-2.6.39.1/drivers/scsi/gdth_proc.c linux-2.6.39.1/drivers/scsi/gdth_proc.c
38066--- linux-2.6.39.1/drivers/scsi/gdth_proc.c 2011-05-19 00:06:34.000000000 -0400
38067+++ linux-2.6.39.1/drivers/scsi/gdth_proc.c 2011-05-22 19:36:32.000000000 -0400
38068@@ -47,6 +47,9 @@ static int gdth_set_asc_info(struct Scsi
38069 u64 paddr;
38070
38071 char cmnd[MAX_COMMAND_SIZE];
38072+
38073+ pax_track_stack();
38074+
38075 memset(cmnd, 0xff, 12);
38076 memset(&gdtcmd, 0, sizeof(gdth_cmd_str));
38077
38078@@ -175,6 +178,8 @@ static int gdth_get_info(char *buffer,ch
38079 gdth_hget_str *phg;
38080 char cmnd[MAX_COMMAND_SIZE];
38081
38082+ pax_track_stack();
38083+
38084 gdtcmd = kmalloc(sizeof(*gdtcmd), GFP_KERNEL);
38085 estr = kmalloc(sizeof(*estr), GFP_KERNEL);
38086 if (!gdtcmd || !estr)
38087diff -urNp linux-2.6.39.1/drivers/scsi/hosts.c linux-2.6.39.1/drivers/scsi/hosts.c
38088--- linux-2.6.39.1/drivers/scsi/hosts.c 2011-05-19 00:06:34.000000000 -0400
38089+++ linux-2.6.39.1/drivers/scsi/hosts.c 2011-05-22 19:36:32.000000000 -0400
38090@@ -42,7 +42,7 @@
38091 #include "scsi_logging.h"
38092
38093
38094-static atomic_t scsi_host_next_hn; /* host_no for next new host */
38095+static atomic_unchecked_t scsi_host_next_hn; /* host_no for next new host */
38096
38097
38098 static void scsi_host_cls_release(struct device *dev)
38099@@ -354,7 +354,7 @@ struct Scsi_Host *scsi_host_alloc(struct
38100 * subtract one because we increment first then return, but we need to
38101 * know what the next host number was before increment
38102 */
38103- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
38104+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
38105 shost->dma_channel = 0xff;
38106
38107 /* These three are default values which can be overridden */
38108diff -urNp linux-2.6.39.1/drivers/scsi/hpsa.h linux-2.6.39.1/drivers/scsi/hpsa.h
38109--- linux-2.6.39.1/drivers/scsi/hpsa.h 2011-05-19 00:06:34.000000000 -0400
38110+++ linux-2.6.39.1/drivers/scsi/hpsa.h 2011-05-22 19:36:32.000000000 -0400
38111@@ -347,7 +347,7 @@ static struct access_method SA5_access =
38112 SA5_completed,
38113 };
38114
38115-static struct access_method SA5_performant_access = {
38116+static const struct access_method SA5_performant_access = {
38117 SA5_submit_command,
38118 SA5_performant_intr_mask,
38119 SA5_fifo_full,
38120diff -urNp linux-2.6.39.1/drivers/scsi/hptiop.c linux-2.6.39.1/drivers/scsi/hptiop.c
38121--- linux-2.6.39.1/drivers/scsi/hptiop.c 2011-05-19 00:06:34.000000000 -0400
38122+++ linux-2.6.39.1/drivers/scsi/hptiop.c 2011-05-22 19:36:32.000000000 -0400
38123@@ -1226,7 +1226,7 @@ static void hptiop_remove(struct pci_dev
38124 scsi_host_put(host);
38125 }
38126
38127-static struct hptiop_adapter_ops hptiop_itl_ops = {
38128+static const struct hptiop_adapter_ops hptiop_itl_ops = {
38129 .iop_wait_ready = iop_wait_ready_itl,
38130 .internal_memalloc = NULL,
38131 .internal_memfree = NULL,
38132@@ -1241,7 +1241,7 @@ static struct hptiop_adapter_ops hptiop_
38133 .post_req = hptiop_post_req_itl,
38134 };
38135
38136-static struct hptiop_adapter_ops hptiop_mv_ops = {
38137+static const struct hptiop_adapter_ops hptiop_mv_ops = {
38138 .iop_wait_ready = iop_wait_ready_mv,
38139 .internal_memalloc = hptiop_internal_memalloc_mv,
38140 .internal_memfree = hptiop_internal_memfree_mv,
38141diff -urNp linux-2.6.39.1/drivers/scsi/ibmvscsi/ibmvfc.c linux-2.6.39.1/drivers/scsi/ibmvscsi/ibmvfc.c
38142--- linux-2.6.39.1/drivers/scsi/ibmvscsi/ibmvfc.c 2011-05-19 00:06:34.000000000 -0400
38143+++ linux-2.6.39.1/drivers/scsi/ibmvscsi/ibmvfc.c 2011-05-22 19:36:32.000000000 -0400
38144@@ -4881,7 +4881,7 @@ static struct vio_device_id ibmvfc_devic
38145 };
38146 MODULE_DEVICE_TABLE(vio, ibmvfc_device_table);
38147
38148-static struct dev_pm_ops ibmvfc_pm_ops = {
38149+static const struct dev_pm_ops ibmvfc_pm_ops = {
38150 .resume = ibmvfc_resume
38151 };
38152
38153diff -urNp linux-2.6.39.1/drivers/scsi/ibmvscsi/ibmvscsi.c linux-2.6.39.1/drivers/scsi/ibmvscsi/ibmvscsi.c
38154--- linux-2.6.39.1/drivers/scsi/ibmvscsi/ibmvscsi.c 2011-05-19 00:06:34.000000000 -0400
38155+++ linux-2.6.39.1/drivers/scsi/ibmvscsi/ibmvscsi.c 2011-05-22 19:36:32.000000000 -0400
38156@@ -104,7 +104,7 @@ static struct scsi_transport_template *i
38157
38158 #define IBMVSCSI_VERSION "1.5.9"
38159
38160-static struct ibmvscsi_ops *ibmvscsi_ops;
38161+static const struct ibmvscsi_ops *ibmvscsi_ops;
38162
38163 MODULE_DESCRIPTION("IBM Virtual SCSI");
38164 MODULE_AUTHOR("Dave Boutcher");
38165@@ -2059,7 +2059,7 @@ static struct vio_device_id ibmvscsi_dev
38166 };
38167 MODULE_DEVICE_TABLE(vio, ibmvscsi_device_table);
38168
38169-static struct dev_pm_ops ibmvscsi_pm_ops = {
38170+static const struct dev_pm_ops ibmvscsi_pm_ops = {
38171 .resume = ibmvscsi_resume
38172 };
38173
38174@@ -2075,7 +2075,7 @@ static struct vio_driver ibmvscsi_driver
38175 }
38176 };
38177
38178-static struct srp_function_template ibmvscsi_transport_functions = {
38179+static const struct srp_function_template ibmvscsi_transport_functions = {
38180 };
38181
38182 int __init ibmvscsi_module_init(void)
38183diff -urNp linux-2.6.39.1/drivers/scsi/ibmvscsi/ibmvscsi.h linux-2.6.39.1/drivers/scsi/ibmvscsi/ibmvscsi.h
38184--- linux-2.6.39.1/drivers/scsi/ibmvscsi/ibmvscsi.h 2011-05-19 00:06:34.000000000 -0400
38185+++ linux-2.6.39.1/drivers/scsi/ibmvscsi/ibmvscsi.h 2011-05-22 19:36:32.000000000 -0400
38186@@ -127,7 +127,7 @@ struct ibmvscsi_ops {
38187 int (*resume) (struct ibmvscsi_host_data *hostdata);
38188 };
38189
38190-extern struct ibmvscsi_ops iseriesvscsi_ops;
38191-extern struct ibmvscsi_ops rpavscsi_ops;
38192+extern const struct ibmvscsi_ops iseriesvscsi_ops;
38193+extern const struct ibmvscsi_ops rpavscsi_ops;
38194
38195 #endif /* IBMVSCSI_H */
38196diff -urNp linux-2.6.39.1/drivers/scsi/ibmvscsi/ibmvstgt.c linux-2.6.39.1/drivers/scsi/ibmvscsi/ibmvstgt.c
38197--- linux-2.6.39.1/drivers/scsi/ibmvscsi/ibmvstgt.c 2011-05-19 00:06:34.000000000 -0400
38198+++ linux-2.6.39.1/drivers/scsi/ibmvscsi/ibmvstgt.c 2011-05-22 19:36:32.000000000 -0400
38199@@ -951,7 +951,7 @@ static int get_system_info(void)
38200 return 0;
38201 }
38202
38203-static struct srp_function_template ibmvstgt_transport_functions = {
38204+static const struct srp_function_template ibmvstgt_transport_functions = {
38205 .tsk_mgmt_response = ibmvstgt_tsk_mgmt_response,
38206 .it_nexus_response = ibmvstgt_it_nexus_response,
38207 };
38208diff -urNp linux-2.6.39.1/drivers/scsi/ibmvscsi/iseries_vscsi.c linux-2.6.39.1/drivers/scsi/ibmvscsi/iseries_vscsi.c
38209--- linux-2.6.39.1/drivers/scsi/ibmvscsi/iseries_vscsi.c 2011-05-19 00:06:34.000000000 -0400
38210+++ linux-2.6.39.1/drivers/scsi/ibmvscsi/iseries_vscsi.c 2011-05-22 19:36:32.000000000 -0400
38211@@ -163,7 +163,7 @@ static int iseriesvscsi_resume(struct ib
38212 return 0;
38213 }
38214
38215-struct ibmvscsi_ops iseriesvscsi_ops = {
38216+const struct ibmvscsi_ops iseriesvscsi_ops = {
38217 .init_crq_queue = iseriesvscsi_init_crq_queue,
38218 .release_crq_queue = iseriesvscsi_release_crq_queue,
38219 .reset_crq_queue = iseriesvscsi_reset_crq_queue,
38220diff -urNp linux-2.6.39.1/drivers/scsi/ibmvscsi/rpa_vscsi.c linux-2.6.39.1/drivers/scsi/ibmvscsi/rpa_vscsi.c
38221--- linux-2.6.39.1/drivers/scsi/ibmvscsi/rpa_vscsi.c 2011-05-19 00:06:34.000000000 -0400
38222+++ linux-2.6.39.1/drivers/scsi/ibmvscsi/rpa_vscsi.c 2011-05-22 19:36:32.000000000 -0400
38223@@ -358,7 +358,7 @@ static int rpavscsi_resume(struct ibmvsc
38224 return 0;
38225 }
38226
38227-struct ibmvscsi_ops rpavscsi_ops = {
38228+const struct ibmvscsi_ops rpavscsi_ops = {
38229 .init_crq_queue = rpavscsi_init_crq_queue,
38230 .release_crq_queue = rpavscsi_release_crq_queue,
38231 .reset_crq_queue = rpavscsi_reset_crq_queue,
38232diff -urNp linux-2.6.39.1/drivers/scsi/ipr.c linux-2.6.39.1/drivers/scsi/ipr.c
38233--- linux-2.6.39.1/drivers/scsi/ipr.c 2011-05-19 00:06:34.000000000 -0400
38234+++ linux-2.6.39.1/drivers/scsi/ipr.c 2011-05-22 19:36:32.000000000 -0400
38235@@ -6210,7 +6210,7 @@ static bool ipr_qc_fill_rtf(struct ata_q
38236 return true;
38237 }
38238
38239-static struct ata_port_operations ipr_sata_ops = {
38240+static const struct ata_port_operations ipr_sata_ops = {
38241 .phy_reset = ipr_ata_phy_reset,
38242 .hardreset = ipr_sata_reset,
38243 .post_internal_cmd = ipr_ata_post_internal,
38244diff -urNp linux-2.6.39.1/drivers/scsi/libfc/fc_exch.c linux-2.6.39.1/drivers/scsi/libfc/fc_exch.c
38245--- linux-2.6.39.1/drivers/scsi/libfc/fc_exch.c 2011-05-19 00:06:34.000000000 -0400
38246+++ linux-2.6.39.1/drivers/scsi/libfc/fc_exch.c 2011-05-22 19:36:32.000000000 -0400
38247@@ -105,12 +105,12 @@ struct fc_exch_mgr {
38248 * all together if not used XXX
38249 */
38250 struct {
38251- atomic_t no_free_exch;
38252- atomic_t no_free_exch_xid;
38253- atomic_t xid_not_found;
38254- atomic_t xid_busy;
38255- atomic_t seq_not_found;
38256- atomic_t non_bls_resp;
38257+ atomic_unchecked_t no_free_exch;
38258+ atomic_unchecked_t no_free_exch_xid;
38259+ atomic_unchecked_t xid_not_found;
38260+ atomic_unchecked_t xid_busy;
38261+ atomic_unchecked_t seq_not_found;
38262+ atomic_unchecked_t non_bls_resp;
38263 } stats;
38264 };
38265
38266@@ -700,7 +700,7 @@ static struct fc_exch *fc_exch_em_alloc(
38267 /* allocate memory for exchange */
38268 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
38269 if (!ep) {
38270- atomic_inc(&mp->stats.no_free_exch);
38271+ atomic_inc_unchecked(&mp->stats.no_free_exch);
38272 goto out;
38273 }
38274 memset(ep, 0, sizeof(*ep));
38275@@ -761,7 +761,7 @@ out:
38276 return ep;
38277 err:
38278 spin_unlock_bh(&pool->lock);
38279- atomic_inc(&mp->stats.no_free_exch_xid);
38280+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
38281 mempool_free(ep, mp->ep_pool);
38282 return NULL;
38283 }
38284@@ -906,7 +906,7 @@ static enum fc_pf_rjt_reason fc_seq_look
38285 xid = ntohs(fh->fh_ox_id); /* we originated exch */
38286 ep = fc_exch_find(mp, xid);
38287 if (!ep) {
38288- atomic_inc(&mp->stats.xid_not_found);
38289+ atomic_inc_unchecked(&mp->stats.xid_not_found);
38290 reject = FC_RJT_OX_ID;
38291 goto out;
38292 }
38293@@ -936,7 +936,7 @@ static enum fc_pf_rjt_reason fc_seq_look
38294 ep = fc_exch_find(mp, xid);
38295 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
38296 if (ep) {
38297- atomic_inc(&mp->stats.xid_busy);
38298+ atomic_inc_unchecked(&mp->stats.xid_busy);
38299 reject = FC_RJT_RX_ID;
38300 goto rel;
38301 }
38302@@ -947,7 +947,7 @@ static enum fc_pf_rjt_reason fc_seq_look
38303 }
38304 xid = ep->xid; /* get our XID */
38305 } else if (!ep) {
38306- atomic_inc(&mp->stats.xid_not_found);
38307+ atomic_inc_unchecked(&mp->stats.xid_not_found);
38308 reject = FC_RJT_RX_ID; /* XID not found */
38309 goto out;
38310 }
38311@@ -964,7 +964,7 @@ static enum fc_pf_rjt_reason fc_seq_look
38312 } else {
38313 sp = &ep->seq;
38314 if (sp->id != fh->fh_seq_id) {
38315- atomic_inc(&mp->stats.seq_not_found);
38316+ atomic_inc_unchecked(&mp->stats.seq_not_found);
38317 reject = FC_RJT_SEQ_ID; /* sequence/exch should exist */
38318 goto rel;
38319 }
38320@@ -1392,22 +1392,22 @@ static void fc_exch_recv_seq_resp(struct
38321
38322 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
38323 if (!ep) {
38324- atomic_inc(&mp->stats.xid_not_found);
38325+ atomic_inc_unchecked(&mp->stats.xid_not_found);
38326 goto out;
38327 }
38328 if (ep->esb_stat & ESB_ST_COMPLETE) {
38329- atomic_inc(&mp->stats.xid_not_found);
38330+ atomic_inc_unchecked(&mp->stats.xid_not_found);
38331 goto rel;
38332 }
38333 if (ep->rxid == FC_XID_UNKNOWN)
38334 ep->rxid = ntohs(fh->fh_rx_id);
38335 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
38336- atomic_inc(&mp->stats.xid_not_found);
38337+ atomic_inc_unchecked(&mp->stats.xid_not_found);
38338 goto rel;
38339 }
38340 if (ep->did != ntoh24(fh->fh_s_id) &&
38341 ep->did != FC_FID_FLOGI) {
38342- atomic_inc(&mp->stats.xid_not_found);
38343+ atomic_inc_unchecked(&mp->stats.xid_not_found);
38344 goto rel;
38345 }
38346 sof = fr_sof(fp);
38347@@ -1416,7 +1416,7 @@ static void fc_exch_recv_seq_resp(struct
38348 sp->ssb_stat |= SSB_ST_RESP;
38349 sp->id = fh->fh_seq_id;
38350 } else if (sp->id != fh->fh_seq_id) {
38351- atomic_inc(&mp->stats.seq_not_found);
38352+ atomic_inc_unchecked(&mp->stats.seq_not_found);
38353 goto rel;
38354 }
38355
38356@@ -1479,9 +1479,9 @@ static void fc_exch_recv_resp(struct fc_
38357 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
38358
38359 if (!sp)
38360- atomic_inc(&mp->stats.xid_not_found);
38361+ atomic_inc_unchecked(&mp->stats.xid_not_found);
38362 else
38363- atomic_inc(&mp->stats.non_bls_resp);
38364+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
38365
38366 fc_frame_free(fp);
38367 }
38368diff -urNp linux-2.6.39.1/drivers/scsi/libfc/fc_lport.c linux-2.6.39.1/drivers/scsi/libfc/fc_lport.c
38369--- linux-2.6.39.1/drivers/scsi/libfc/fc_lport.c 2011-05-19 00:06:34.000000000 -0400
38370+++ linux-2.6.39.1/drivers/scsi/libfc/fc_lport.c 2011-05-22 19:36:32.000000000 -0400
38371@@ -1299,7 +1299,7 @@ static void fc_lport_enter_ns(struct fc_
38372 fc_lport_error(lport, fp);
38373 }
38374
38375-static struct fc_rport_operations fc_lport_rport_ops = {
38376+static const struct fc_rport_operations fc_lport_rport_ops = {
38377 .event_callback = fc_lport_rport_callback,
38378 };
38379
38380diff -urNp linux-2.6.39.1/drivers/scsi/libfc/fc_rport.c linux-2.6.39.1/drivers/scsi/libfc/fc_rport.c
38381--- linux-2.6.39.1/drivers/scsi/libfc/fc_rport.c 2011-05-19 00:06:34.000000000 -0400
38382+++ linux-2.6.39.1/drivers/scsi/libfc/fc_rport.c 2011-05-22 19:36:32.000000000 -0400
38383@@ -256,7 +256,7 @@ static void fc_rport_work(struct work_st
38384 struct fc_rport_libfc_priv *rpriv;
38385 enum fc_rport_event event;
38386 struct fc_lport *lport = rdata->local_port;
38387- struct fc_rport_operations *rport_ops;
38388+ const struct fc_rport_operations *rport_ops;
38389 struct fc_rport_identifiers ids;
38390 struct fc_rport *rport;
38391 struct fc4_prov *prov;
38392diff -urNp linux-2.6.39.1/drivers/scsi/libsas/sas_ata.c linux-2.6.39.1/drivers/scsi/libsas/sas_ata.c
38393--- linux-2.6.39.1/drivers/scsi/libsas/sas_ata.c 2011-05-19 00:06:34.000000000 -0400
38394+++ linux-2.6.39.1/drivers/scsi/libsas/sas_ata.c 2011-05-22 19:36:32.000000000 -0400
38395@@ -307,14 +307,14 @@ static void sas_ata_post_internal(struct
38396 }
38397 }
38398
38399-static struct ata_port_operations sas_sata_ops = {
38400+static const struct ata_port_operations sas_sata_ops = {
38401 .prereset = ata_std_prereset,
38402 .softreset = NULL,
38403 .hardreset = sas_ata_hard_reset,
38404 .postreset = ata_std_postreset,
38405 .error_handler = ata_std_error_handler,
38406 .post_internal_cmd = sas_ata_post_internal,
38407- .qc_defer = ata_std_qc_defer,
38408+ .qc_defer = ata_std_qc_defer,
38409 .qc_prep = ata_noop_qc_prep,
38410 .qc_issue = sas_ata_qc_issue,
38411 .qc_fill_rtf = sas_ata_qc_fill_rtf,
38412diff -urNp linux-2.6.39.1/drivers/scsi/lpfc/lpfc_debugfs.c linux-2.6.39.1/drivers/scsi/lpfc/lpfc_debugfs.c
38413--- linux-2.6.39.1/drivers/scsi/lpfc/lpfc_debugfs.c 2011-05-19 00:06:34.000000000 -0400
38414+++ linux-2.6.39.1/drivers/scsi/lpfc/lpfc_debugfs.c 2011-05-22 19:36:32.000000000 -0400
38415@@ -104,7 +104,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_
38416
38417 #include <linux/debugfs.h>
38418
38419-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
38420+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
38421 static unsigned long lpfc_debugfs_start_time = 0L;
38422
38423 /* iDiag */
38424@@ -141,7 +141,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_v
38425 lpfc_debugfs_enable = 0;
38426
38427 len = 0;
38428- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
38429+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
38430 (lpfc_debugfs_max_disc_trc - 1);
38431 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
38432 dtp = vport->disc_trc + i;
38433@@ -202,7 +202,7 @@ lpfc_debugfs_slow_ring_trc_data(struct l
38434 lpfc_debugfs_enable = 0;
38435
38436 len = 0;
38437- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
38438+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
38439 (lpfc_debugfs_max_slow_ring_trc - 1);
38440 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
38441 dtp = phba->slow_ring_trc + i;
38442@@ -380,6 +380,8 @@ lpfc_debugfs_dumpHBASlim_data(struct lpf
38443 uint32_t *ptr;
38444 char buffer[1024];
38445
38446+ pax_track_stack();
38447+
38448 off = 0;
38449 spin_lock_irq(&phba->hbalock);
38450
38451@@ -617,14 +619,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport
38452 !vport || !vport->disc_trc)
38453 return;
38454
38455- index = atomic_inc_return(&vport->disc_trc_cnt) &
38456+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
38457 (lpfc_debugfs_max_disc_trc - 1);
38458 dtp = vport->disc_trc + index;
38459 dtp->fmt = fmt;
38460 dtp->data1 = data1;
38461 dtp->data2 = data2;
38462 dtp->data3 = data3;
38463- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
38464+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
38465 dtp->jif = jiffies;
38466 #endif
38467 return;
38468@@ -655,14 +657,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_h
38469 !phba || !phba->slow_ring_trc)
38470 return;
38471
38472- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
38473+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
38474 (lpfc_debugfs_max_slow_ring_trc - 1);
38475 dtp = phba->slow_ring_trc + index;
38476 dtp->fmt = fmt;
38477 dtp->data1 = data1;
38478 dtp->data2 = data2;
38479 dtp->data3 = data3;
38480- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
38481+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
38482 dtp->jif = jiffies;
38483 #endif
38484 return;
38485@@ -2145,7 +2147,7 @@ lpfc_debugfs_initialize(struct lpfc_vpor
38486 "slow_ring buffer\n");
38487 goto debug_failed;
38488 }
38489- atomic_set(&phba->slow_ring_trc_cnt, 0);
38490+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
38491 memset(phba->slow_ring_trc, 0,
38492 (sizeof(struct lpfc_debugfs_trc) *
38493 lpfc_debugfs_max_slow_ring_trc));
38494@@ -2191,7 +2193,7 @@ lpfc_debugfs_initialize(struct lpfc_vpor
38495 "buffer\n");
38496 goto debug_failed;
38497 }
38498- atomic_set(&vport->disc_trc_cnt, 0);
38499+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
38500
38501 snprintf(name, sizeof(name), "discovery_trace");
38502 vport->debug_disc_trc =
38503diff -urNp linux-2.6.39.1/drivers/scsi/lpfc/lpfc.h linux-2.6.39.1/drivers/scsi/lpfc/lpfc.h
38504--- linux-2.6.39.1/drivers/scsi/lpfc/lpfc.h 2011-05-19 00:06:34.000000000 -0400
38505+++ linux-2.6.39.1/drivers/scsi/lpfc/lpfc.h 2011-05-22 19:36:32.000000000 -0400
38506@@ -419,7 +419,7 @@ struct lpfc_vport {
38507 struct dentry *debug_nodelist;
38508 struct dentry *vport_debugfs_root;
38509 struct lpfc_debugfs_trc *disc_trc;
38510- atomic_t disc_trc_cnt;
38511+ atomic_unchecked_t disc_trc_cnt;
38512 #endif
38513 uint8_t stat_data_enabled;
38514 uint8_t stat_data_blocked;
38515@@ -785,8 +785,8 @@ struct lpfc_hba {
38516 struct timer_list fabric_block_timer;
38517 unsigned long bit_flags;
38518 #define FABRIC_COMANDS_BLOCKED 0
38519- atomic_t num_rsrc_err;
38520- atomic_t num_cmd_success;
38521+ atomic_unchecked_t num_rsrc_err;
38522+ atomic_unchecked_t num_cmd_success;
38523 unsigned long last_rsrc_error_time;
38524 unsigned long last_ramp_down_time;
38525 unsigned long last_ramp_up_time;
38526@@ -800,7 +800,7 @@ struct lpfc_hba {
38527 struct dentry *debug_dumpDif; /* BlockGuard BPL*/
38528 struct dentry *debug_slow_ring_trc;
38529 struct lpfc_debugfs_trc *slow_ring_trc;
38530- atomic_t slow_ring_trc_cnt;
38531+ atomic_unchecked_t slow_ring_trc_cnt;
38532 /* iDiag debugfs sub-directory */
38533 struct dentry *idiag_root;
38534 struct dentry *idiag_pci_cfg;
38535diff -urNp linux-2.6.39.1/drivers/scsi/lpfc/lpfc_scsi.c linux-2.6.39.1/drivers/scsi/lpfc/lpfc_scsi.c
38536--- linux-2.6.39.1/drivers/scsi/lpfc/lpfc_scsi.c 2011-05-19 00:06:34.000000000 -0400
38537+++ linux-2.6.39.1/drivers/scsi/lpfc/lpfc_scsi.c 2011-05-22 19:36:32.000000000 -0400
38538@@ -297,7 +297,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hb
38539 uint32_t evt_posted;
38540
38541 spin_lock_irqsave(&phba->hbalock, flags);
38542- atomic_inc(&phba->num_rsrc_err);
38543+ atomic_inc_unchecked(&phba->num_rsrc_err);
38544 phba->last_rsrc_error_time = jiffies;
38545
38546 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
38547@@ -338,7 +338,7 @@ lpfc_rampup_queue_depth(struct lpfc_vpor
38548 unsigned long flags;
38549 struct lpfc_hba *phba = vport->phba;
38550 uint32_t evt_posted;
38551- atomic_inc(&phba->num_cmd_success);
38552+ atomic_inc_unchecked(&phba->num_cmd_success);
38553
38554 if (vport->cfg_lun_queue_depth <= queue_depth)
38555 return;
38556@@ -382,8 +382,8 @@ lpfc_ramp_down_queue_handler(struct lpfc
38557 unsigned long num_rsrc_err, num_cmd_success;
38558 int i;
38559
38560- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
38561- num_cmd_success = atomic_read(&phba->num_cmd_success);
38562+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
38563+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
38564
38565 vports = lpfc_create_vport_work_array(phba);
38566 if (vports != NULL)
38567@@ -403,8 +403,8 @@ lpfc_ramp_down_queue_handler(struct lpfc
38568 }
38569 }
38570 lpfc_destroy_vport_work_array(phba, vports);
38571- atomic_set(&phba->num_rsrc_err, 0);
38572- atomic_set(&phba->num_cmd_success, 0);
38573+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
38574+ atomic_set_unchecked(&phba->num_cmd_success, 0);
38575 }
38576
38577 /**
38578@@ -438,8 +438,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_h
38579 }
38580 }
38581 lpfc_destroy_vport_work_array(phba, vports);
38582- atomic_set(&phba->num_rsrc_err, 0);
38583- atomic_set(&phba->num_cmd_success, 0);
38584+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
38585+ atomic_set_unchecked(&phba->num_cmd_success, 0);
38586 }
38587
38588 /**
38589diff -urNp linux-2.6.39.1/drivers/scsi/mac_esp.c linux-2.6.39.1/drivers/scsi/mac_esp.c
38590--- linux-2.6.39.1/drivers/scsi/mac_esp.c 2011-05-19 00:06:34.000000000 -0400
38591+++ linux-2.6.39.1/drivers/scsi/mac_esp.c 2011-05-22 19:36:32.000000000 -0400
38592@@ -473,7 +473,7 @@ static irqreturn_t mac_scsi_esp_intr(int
38593 return IRQ_HANDLED;
38594 }
38595
38596-static struct esp_driver_ops mac_esp_ops = {
38597+static const struct esp_driver_ops mac_esp_ops = {
38598 .esp_write8 = mac_esp_write8,
38599 .esp_read8 = mac_esp_read8,
38600 .map_single = mac_esp_map_single,
38601diff -urNp linux-2.6.39.1/drivers/scsi/megaraid/megaraid_mbox.c linux-2.6.39.1/drivers/scsi/megaraid/megaraid_mbox.c
38602--- linux-2.6.39.1/drivers/scsi/megaraid/megaraid_mbox.c 2011-05-19 00:06:34.000000000 -0400
38603+++ linux-2.6.39.1/drivers/scsi/megaraid/megaraid_mbox.c 2011-05-22 19:36:32.000000000 -0400
38604@@ -3510,6 +3510,8 @@ megaraid_cmm_register(adapter_t *adapter
38605 int rval;
38606 int i;
38607
38608+ pax_track_stack();
38609+
38610 // Allocate memory for the base list of scb for management module.
38611 adapter->uscb_list = kcalloc(MBOX_MAX_USER_CMDS, sizeof(scb_t), GFP_KERNEL);
38612
38613diff -urNp linux-2.6.39.1/drivers/scsi/megaraid/megaraid_sas_base.c linux-2.6.39.1/drivers/scsi/megaraid/megaraid_sas_base.c
38614--- linux-2.6.39.1/drivers/scsi/megaraid/megaraid_sas_base.c 2011-05-19 00:06:34.000000000 -0400
38615+++ linux-2.6.39.1/drivers/scsi/megaraid/megaraid_sas_base.c 2011-05-22 19:36:32.000000000 -0400
38616@@ -366,7 +366,7 @@ megasas_check_reset_xscale(struct megasa
38617 return 0;
38618 }
38619
38620-static struct megasas_instance_template megasas_instance_template_xscale = {
38621+static const struct megasas_instance_template megasas_instance_template_xscale = {
38622
38623 .fire_cmd = megasas_fire_cmd_xscale,
38624 .enable_intr = megasas_enable_intr_xscale,
38625@@ -497,7 +497,7 @@ megasas_check_reset_ppc(struct megasas_i
38626 {
38627 return 0;
38628 }
38629-static struct megasas_instance_template megasas_instance_template_ppc = {
38630+static const struct megasas_instance_template megasas_instance_template_ppc = {
38631
38632 .fire_cmd = megasas_fire_cmd_ppc,
38633 .enable_intr = megasas_enable_intr_ppc,
38634@@ -623,7 +623,7 @@ megasas_check_reset_skinny(struct megasa
38635 return 0;
38636 }
38637
38638-static struct megasas_instance_template megasas_instance_template_skinny = {
38639+static const struct megasas_instance_template megasas_instance_template_skinny = {
38640
38641 .fire_cmd = megasas_fire_cmd_skinny,
38642 .enable_intr = megasas_enable_intr_skinny,
38643@@ -810,7 +810,7 @@ megasas_check_reset_gen2(struct megasas_
38644 return 0;
38645 }
38646
38647-static struct megasas_instance_template megasas_instance_template_gen2 = {
38648+static const struct megasas_instance_template megasas_instance_template_gen2 = {
38649
38650 .fire_cmd = megasas_fire_cmd_gen2,
38651 .enable_intr = megasas_enable_intr_gen2,
38652@@ -834,7 +834,7 @@ static struct megasas_instance_template
38653 /*
38654 * Template added for TB (Fusion)
38655 */
38656-extern struct megasas_instance_template megasas_instance_template_fusion;
38657+extern const struct megasas_instance_template megasas_instance_template_fusion;
38658
38659 /**
38660 * megasas_issue_polled - Issues a polling command
38661diff -urNp linux-2.6.39.1/drivers/scsi/megaraid/megaraid_sas_fusion.c linux-2.6.39.1/drivers/scsi/megaraid/megaraid_sas_fusion.c
38662--- linux-2.6.39.1/drivers/scsi/megaraid/megaraid_sas_fusion.c 2011-05-19 00:06:34.000000000 -0400
38663+++ linux-2.6.39.1/drivers/scsi/megaraid/megaraid_sas_fusion.c 2011-05-22 19:36:32.000000000 -0400
38664@@ -2236,7 +2236,7 @@ void megasas_fusion_ocr_wq(struct work_s
38665 megasas_reset_fusion(instance->host);
38666 }
38667
38668-struct megasas_instance_template megasas_instance_template_fusion = {
38669+const struct megasas_instance_template megasas_instance_template_fusion = {
38670 .fire_cmd = megasas_fire_cmd_fusion,
38671 .enable_intr = megasas_enable_intr_fusion,
38672 .disable_intr = megasas_disable_intr_fusion,
38673diff -urNp linux-2.6.39.1/drivers/scsi/megaraid/megaraid_sas.h linux-2.6.39.1/drivers/scsi/megaraid/megaraid_sas.h
38674--- linux-2.6.39.1/drivers/scsi/megaraid/megaraid_sas.h 2011-05-19 00:06:34.000000000 -0400
38675+++ linux-2.6.39.1/drivers/scsi/megaraid/megaraid_sas.h 2011-05-22 19:36:32.000000000 -0400
38676@@ -1330,7 +1330,7 @@ struct megasas_instance {
38677 atomic_t fw_outstanding;
38678 atomic_t fw_reset_no_pci_access;
38679
38680- struct megasas_instance_template *instancet;
38681+ const struct megasas_instance_template *instancet;
38682 struct tasklet_struct isr_tasklet;
38683 struct work_struct work_init;
38684
38685diff -urNp linux-2.6.39.1/drivers/scsi/ncr53c8xx.c linux-2.6.39.1/drivers/scsi/ncr53c8xx.c
38686--- linux-2.6.39.1/drivers/scsi/ncr53c8xx.c 2011-05-19 00:06:34.000000000 -0400
38687+++ linux-2.6.39.1/drivers/scsi/ncr53c8xx.c 2011-05-22 19:36:32.000000000 -0400
38688@@ -8606,7 +8606,7 @@ static void ncr53c8xx_get_signalling(str
38689 spi_signalling(shost) = type;
38690 }
38691
38692-static struct spi_function_template ncr53c8xx_transport_functions = {
38693+static struct spi_function_template ncr53c8xx_transport_functions = {
38694 .set_period = ncr53c8xx_set_period,
38695 .show_period = 1,
38696 .set_offset = ncr53c8xx_set_offset,
38697diff -urNp linux-2.6.39.1/drivers/scsi/osd/osd_initiator.c linux-2.6.39.1/drivers/scsi/osd/osd_initiator.c
38698--- linux-2.6.39.1/drivers/scsi/osd/osd_initiator.c 2011-05-19 00:06:34.000000000 -0400
38699+++ linux-2.6.39.1/drivers/scsi/osd/osd_initiator.c 2011-05-22 19:36:32.000000000 -0400
38700@@ -97,6 +97,8 @@ static int _osd_get_print_system_info(st
38701 int nelem = ARRAY_SIZE(get_attrs), a = 0;
38702 int ret;
38703
38704+ pax_track_stack();
38705+
38706 or = osd_start_request(od, GFP_KERNEL);
38707 if (!or)
38708 return -ENOMEM;
38709diff -urNp linux-2.6.39.1/drivers/scsi/pmcraid.c linux-2.6.39.1/drivers/scsi/pmcraid.c
38710--- linux-2.6.39.1/drivers/scsi/pmcraid.c 2011-05-19 00:06:34.000000000 -0400
38711+++ linux-2.6.39.1/drivers/scsi/pmcraid.c 2011-05-22 19:36:32.000000000 -0400
38712@@ -201,8 +201,8 @@ static int pmcraid_slave_alloc(struct sc
38713 res->scsi_dev = scsi_dev;
38714 scsi_dev->hostdata = res;
38715 res->change_detected = 0;
38716- atomic_set(&res->read_failures, 0);
38717- atomic_set(&res->write_failures, 0);
38718+ atomic_set_unchecked(&res->read_failures, 0);
38719+ atomic_set_unchecked(&res->write_failures, 0);
38720 rc = 0;
38721 }
38722 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
38723@@ -2677,9 +2677,9 @@ static int pmcraid_error_handler(struct
38724
38725 /* If this was a SCSI read/write command keep count of errors */
38726 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
38727- atomic_inc(&res->read_failures);
38728+ atomic_inc_unchecked(&res->read_failures);
38729 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
38730- atomic_inc(&res->write_failures);
38731+ atomic_inc_unchecked(&res->write_failures);
38732
38733 if (!RES_IS_GSCSI(res->cfg_entry) &&
38734 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
38735@@ -3535,7 +3535,7 @@ static int pmcraid_queuecommand_lck(
38736 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
38737 * hrrq_id assigned here in queuecommand
38738 */
38739- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
38740+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
38741 pinstance->num_hrrq;
38742 cmd->cmd_done = pmcraid_io_done;
38743
38744@@ -3860,7 +3860,7 @@ static long pmcraid_ioctl_passthrough(
38745 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
38746 * hrrq_id assigned here in queuecommand
38747 */
38748- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
38749+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
38750 pinstance->num_hrrq;
38751
38752 if (request_size) {
38753@@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(stru
38754
38755 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
38756 /* add resources only after host is added into system */
38757- if (!atomic_read(&pinstance->expose_resources))
38758+ if (!atomic_read_unchecked(&pinstance->expose_resources))
38759 return;
38760
38761 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
38762@@ -5329,8 +5329,8 @@ static int __devinit pmcraid_init_instan
38763 init_waitqueue_head(&pinstance->reset_wait_q);
38764
38765 atomic_set(&pinstance->outstanding_cmds, 0);
38766- atomic_set(&pinstance->last_message_id, 0);
38767- atomic_set(&pinstance->expose_resources, 0);
38768+ atomic_set_unchecked(&pinstance->last_message_id, 0);
38769+ atomic_set_unchecked(&pinstance->expose_resources, 0);
38770
38771 INIT_LIST_HEAD(&pinstance->free_res_q);
38772 INIT_LIST_HEAD(&pinstance->used_res_q);
38773@@ -6045,7 +6045,7 @@ static int __devinit pmcraid_probe(
38774 /* Schedule worker thread to handle CCN and take care of adding and
38775 * removing devices to OS
38776 */
38777- atomic_set(&pinstance->expose_resources, 1);
38778+ atomic_set_unchecked(&pinstance->expose_resources, 1);
38779 schedule_work(&pinstance->worker_q);
38780 return rc;
38781
38782diff -urNp linux-2.6.39.1/drivers/scsi/pmcraid.h linux-2.6.39.1/drivers/scsi/pmcraid.h
38783--- linux-2.6.39.1/drivers/scsi/pmcraid.h 2011-05-19 00:06:34.000000000 -0400
38784+++ linux-2.6.39.1/drivers/scsi/pmcraid.h 2011-05-22 19:36:32.000000000 -0400
38785@@ -750,7 +750,7 @@ struct pmcraid_instance {
38786 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
38787
38788 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
38789- atomic_t last_message_id;
38790+ atomic_unchecked_t last_message_id;
38791
38792 /* configuration table */
38793 struct pmcraid_config_table *cfg_table;
38794@@ -779,7 +779,7 @@ struct pmcraid_instance {
38795 atomic_t outstanding_cmds;
38796
38797 /* should add/delete resources to mid-layer now ?*/
38798- atomic_t expose_resources;
38799+ atomic_unchecked_t expose_resources;
38800
38801
38802
38803@@ -815,8 +815,8 @@ struct pmcraid_resource_entry {
38804 struct pmcraid_config_table_entry_ext cfg_entry_ext;
38805 };
38806 struct scsi_device *scsi_dev; /* Link scsi_device structure */
38807- atomic_t read_failures; /* count of failed READ commands */
38808- atomic_t write_failures; /* count of failed WRITE commands */
38809+ atomic_unchecked_t read_failures; /* count of failed READ commands */
38810+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
38811
38812 /* To indicate add/delete/modify during CCN */
38813 u8 change_detected;
38814diff -urNp linux-2.6.39.1/drivers/scsi/qla2xxx/qla_os.c linux-2.6.39.1/drivers/scsi/qla2xxx/qla_os.c
38815--- linux-2.6.39.1/drivers/scsi/qla2xxx/qla_os.c 2011-06-03 00:04:14.000000000 -0400
38816+++ linux-2.6.39.1/drivers/scsi/qla2xxx/qla_os.c 2011-06-03 00:32:06.000000000 -0400
38817@@ -4103,7 +4103,7 @@ static struct pci_driver qla2xxx_pci_dri
38818 .err_handler = &qla2xxx_err_handler,
38819 };
38820
38821-static struct file_operations apidev_fops = {
38822+static const struct file_operations apidev_fops = {
38823 .owner = THIS_MODULE,
38824 .llseek = noop_llseek,
38825 };
38826diff -urNp linux-2.6.39.1/drivers/scsi/qla4xxx/ql4_def.h linux-2.6.39.1/drivers/scsi/qla4xxx/ql4_def.h
38827--- linux-2.6.39.1/drivers/scsi/qla4xxx/ql4_def.h 2011-05-19 00:06:34.000000000 -0400
38828+++ linux-2.6.39.1/drivers/scsi/qla4xxx/ql4_def.h 2011-05-22 19:36:32.000000000 -0400
38829@@ -256,7 +256,7 @@ struct ddb_entry {
38830 atomic_t retry_relogin_timer; /* Min Time between relogins
38831 * (4000 only) */
38832 atomic_t relogin_timer; /* Max Time to wait for relogin to complete */
38833- atomic_t relogin_retry_count; /* Num of times relogin has been
38834+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
38835 * retried */
38836
38837 uint16_t port;
38838diff -urNp linux-2.6.39.1/drivers/scsi/qla4xxx/ql4_init.c linux-2.6.39.1/drivers/scsi/qla4xxx/ql4_init.c
38839--- linux-2.6.39.1/drivers/scsi/qla4xxx/ql4_init.c 2011-05-19 00:06:34.000000000 -0400
38840+++ linux-2.6.39.1/drivers/scsi/qla4xxx/ql4_init.c 2011-05-22 19:36:32.000000000 -0400
38841@@ -680,7 +680,7 @@ static struct ddb_entry * qla4xxx_alloc_
38842 ddb_entry->fw_ddb_index = fw_ddb_index;
38843 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
38844 atomic_set(&ddb_entry->relogin_timer, 0);
38845- atomic_set(&ddb_entry->relogin_retry_count, 0);
38846+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
38847 atomic_set(&ddb_entry->state, DDB_STATE_ONLINE);
38848 list_add_tail(&ddb_entry->list, &ha->ddb_list);
38849 ha->fw_ddb_index_map[fw_ddb_index] = ddb_entry;
38850@@ -1433,7 +1433,7 @@ int qla4xxx_process_ddb_changed(struct s
38851 if ((ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) &&
38852 (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE)) {
38853 atomic_set(&ddb_entry->state, DDB_STATE_ONLINE);
38854- atomic_set(&ddb_entry->relogin_retry_count, 0);
38855+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
38856 atomic_set(&ddb_entry->relogin_timer, 0);
38857 clear_bit(DF_RELOGIN, &ddb_entry->flags);
38858 iscsi_unblock_session(ddb_entry->sess);
38859diff -urNp linux-2.6.39.1/drivers/scsi/qla4xxx/ql4_os.c linux-2.6.39.1/drivers/scsi/qla4xxx/ql4_os.c
38860--- linux-2.6.39.1/drivers/scsi/qla4xxx/ql4_os.c 2011-05-19 00:06:34.000000000 -0400
38861+++ linux-2.6.39.1/drivers/scsi/qla4xxx/ql4_os.c 2011-05-22 19:36:32.000000000 -0400
38862@@ -802,13 +802,13 @@ static void qla4xxx_timer(struct scsi_ql
38863 ddb_entry->fw_ddb_device_state ==
38864 DDB_DS_SESSION_FAILED) {
38865 /* Reset retry relogin timer */
38866- atomic_inc(&ddb_entry->relogin_retry_count);
38867+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
38868 DEBUG2(printk("scsi%ld: ddb [%d] relogin"
38869 " timed out-retrying"
38870 " relogin (%d)\n",
38871 ha->host_no,
38872 ddb_entry->fw_ddb_index,
38873- atomic_read(&ddb_entry->
38874+ atomic_read_unchecked(&ddb_entry->
38875 relogin_retry_count))
38876 );
38877 start_dpc++;
38878diff -urNp linux-2.6.39.1/drivers/scsi/scsi.c linux-2.6.39.1/drivers/scsi/scsi.c
38879--- linux-2.6.39.1/drivers/scsi/scsi.c 2011-05-19 00:06:34.000000000 -0400
38880+++ linux-2.6.39.1/drivers/scsi/scsi.c 2011-05-22 19:36:32.000000000 -0400
38881@@ -655,7 +655,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *
38882 unsigned long timeout;
38883 int rtn = 0;
38884
38885- atomic_inc(&cmd->device->iorequest_cnt);
38886+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
38887
38888 /* check if the device is still usable */
38889 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
38890diff -urNp linux-2.6.39.1/drivers/scsi/scsi_debug.c linux-2.6.39.1/drivers/scsi/scsi_debug.c
38891--- linux-2.6.39.1/drivers/scsi/scsi_debug.c 2011-05-19 00:06:34.000000000 -0400
38892+++ linux-2.6.39.1/drivers/scsi/scsi_debug.c 2011-05-22 19:36:32.000000000 -0400
38893@@ -1493,6 +1493,8 @@ static int resp_mode_select(struct scsi_
38894 unsigned char arr[SDEBUG_MAX_MSELECT_SZ];
38895 unsigned char *cmd = (unsigned char *)scp->cmnd;
38896
38897+ pax_track_stack();
38898+
38899 if ((errsts = check_readiness(scp, 1, devip)))
38900 return errsts;
38901 memset(arr, 0, sizeof(arr));
38902@@ -1590,6 +1592,8 @@ static int resp_log_sense(struct scsi_cm
38903 unsigned char arr[SDEBUG_MAX_LSENSE_SZ];
38904 unsigned char *cmd = (unsigned char *)scp->cmnd;
38905
38906+ pax_track_stack();
38907+
38908 if ((errsts = check_readiness(scp, 1, devip)))
38909 return errsts;
38910 memset(arr, 0, sizeof(arr));
38911diff -urNp linux-2.6.39.1/drivers/scsi/scsi_lib.c linux-2.6.39.1/drivers/scsi/scsi_lib.c
38912--- linux-2.6.39.1/drivers/scsi/scsi_lib.c 2011-05-19 00:06:34.000000000 -0400
38913+++ linux-2.6.39.1/drivers/scsi/scsi_lib.c 2011-05-22 19:36:32.000000000 -0400
38914@@ -1410,7 +1410,7 @@ static void scsi_kill_request(struct req
38915 shost = sdev->host;
38916 scsi_init_cmd_errh(cmd);
38917 cmd->result = DID_NO_CONNECT << 16;
38918- atomic_inc(&cmd->device->iorequest_cnt);
38919+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
38920
38921 /*
38922 * SCSI request completion path will do scsi_device_unbusy(),
38923@@ -1436,9 +1436,9 @@ static void scsi_softirq_done(struct req
38924
38925 INIT_LIST_HEAD(&cmd->eh_entry);
38926
38927- atomic_inc(&cmd->device->iodone_cnt);
38928+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
38929 if (cmd->result)
38930- atomic_inc(&cmd->device->ioerr_cnt);
38931+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
38932
38933 disposition = scsi_decide_disposition(cmd);
38934 if (disposition != SUCCESS &&
38935diff -urNp linux-2.6.39.1/drivers/scsi/scsi_sysfs.c linux-2.6.39.1/drivers/scsi/scsi_sysfs.c
38936--- linux-2.6.39.1/drivers/scsi/scsi_sysfs.c 2011-05-19 00:06:34.000000000 -0400
38937+++ linux-2.6.39.1/drivers/scsi/scsi_sysfs.c 2011-05-22 19:36:32.000000000 -0400
38938@@ -621,7 +621,7 @@ show_iostat_##field(struct device *dev,
38939 char *buf) \
38940 { \
38941 struct scsi_device *sdev = to_scsi_device(dev); \
38942- unsigned long long count = atomic_read(&sdev->field); \
38943+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
38944 return snprintf(buf, 20, "0x%llx\n", count); \
38945 } \
38946 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
38947diff -urNp linux-2.6.39.1/drivers/scsi/scsi_transport_fc.c linux-2.6.39.1/drivers/scsi/scsi_transport_fc.c
38948--- linux-2.6.39.1/drivers/scsi/scsi_transport_fc.c 2011-05-19 00:06:34.000000000 -0400
38949+++ linux-2.6.39.1/drivers/scsi/scsi_transport_fc.c 2011-05-22 19:36:32.000000000 -0400
38950@@ -485,7 +485,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_
38951 * Netlink Infrastructure
38952 */
38953
38954-static atomic_t fc_event_seq;
38955+static atomic_unchecked_t fc_event_seq;
38956
38957 /**
38958 * fc_get_event_number - Obtain the next sequential FC event number
38959@@ -498,7 +498,7 @@ static atomic_t fc_event_seq;
38960 u32
38961 fc_get_event_number(void)
38962 {
38963- return atomic_add_return(1, &fc_event_seq);
38964+ return atomic_add_return_unchecked(1, &fc_event_seq);
38965 }
38966 EXPORT_SYMBOL(fc_get_event_number);
38967
38968@@ -646,7 +646,7 @@ static __init int fc_transport_init(void
38969 {
38970 int error;
38971
38972- atomic_set(&fc_event_seq, 0);
38973+ atomic_set_unchecked(&fc_event_seq, 0);
38974
38975 error = transport_class_register(&fc_host_class);
38976 if (error)
38977@@ -836,7 +836,7 @@ static int fc_str_to_dev_loss(const char
38978 char *cp;
38979
38980 *val = simple_strtoul(buf, &cp, 0);
38981- if ((*cp && (*cp != '\n')) || (*val < 0))
38982+ if (*cp && (*cp != '\n'))
38983 return -EINVAL;
38984 /*
38985 * Check for overflow; dev_loss_tmo is u32
38986diff -urNp linux-2.6.39.1/drivers/scsi/scsi_transport_iscsi.c linux-2.6.39.1/drivers/scsi/scsi_transport_iscsi.c
38987--- linux-2.6.39.1/drivers/scsi/scsi_transport_iscsi.c 2011-05-19 00:06:34.000000000 -0400
38988+++ linux-2.6.39.1/drivers/scsi/scsi_transport_iscsi.c 2011-05-22 19:36:32.000000000 -0400
38989@@ -83,7 +83,7 @@ struct iscsi_internal {
38990 struct device_attribute *session_attrs[ISCSI_SESSION_ATTRS + 1];
38991 };
38992
38993-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
38994+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
38995 static struct workqueue_struct *iscsi_eh_timer_workq;
38996
38997 /*
38998@@ -761,7 +761,7 @@ int iscsi_add_session(struct iscsi_cls_s
38999 int err;
39000
39001 ihost = shost->shost_data;
39002- session->sid = atomic_add_return(1, &iscsi_session_nr);
39003+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
39004
39005 if (id == ISCSI_MAX_TARGET) {
39006 for (id = 0; id < ISCSI_MAX_TARGET; id++) {
39007@@ -2200,7 +2200,7 @@ static __init int iscsi_transport_init(v
39008 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
39009 ISCSI_TRANSPORT_VERSION);
39010
39011- atomic_set(&iscsi_session_nr, 0);
39012+ atomic_set_unchecked(&iscsi_session_nr, 0);
39013
39014 err = class_register(&iscsi_transport_class);
39015 if (err)
39016diff -urNp linux-2.6.39.1/drivers/scsi/scsi_transport_srp.c linux-2.6.39.1/drivers/scsi/scsi_transport_srp.c
39017--- linux-2.6.39.1/drivers/scsi/scsi_transport_srp.c 2011-05-19 00:06:34.000000000 -0400
39018+++ linux-2.6.39.1/drivers/scsi/scsi_transport_srp.c 2011-05-22 19:36:32.000000000 -0400
39019@@ -33,7 +33,7 @@
39020 #include "scsi_transport_srp_internal.h"
39021
39022 struct srp_host_attrs {
39023- atomic_t next_port_id;
39024+ atomic_unchecked_t next_port_id;
39025 };
39026 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
39027
39028@@ -62,7 +62,7 @@ static int srp_host_setup(struct transpo
39029 struct Scsi_Host *shost = dev_to_shost(dev);
39030 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
39031
39032- atomic_set(&srp_host->next_port_id, 0);
39033+ atomic_set_unchecked(&srp_host->next_port_id, 0);
39034 return 0;
39035 }
39036
39037@@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct S
39038 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
39039 rport->roles = ids->roles;
39040
39041- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
39042+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
39043 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
39044
39045 transport_setup_device(&rport->dev);
39046diff -urNp linux-2.6.39.1/drivers/scsi/sg.c linux-2.6.39.1/drivers/scsi/sg.c
39047--- linux-2.6.39.1/drivers/scsi/sg.c 2011-05-19 00:06:34.000000000 -0400
39048+++ linux-2.6.39.1/drivers/scsi/sg.c 2011-05-22 19:36:32.000000000 -0400
39049@@ -2310,7 +2310,7 @@ struct sg_proc_leaf {
39050 const struct file_operations * fops;
39051 };
39052
39053-static struct sg_proc_leaf sg_proc_leaf_arr[] = {
39054+static const struct sg_proc_leaf sg_proc_leaf_arr[] = {
39055 {"allow_dio", &adio_fops},
39056 {"debug", &debug_fops},
39057 {"def_reserved_size", &dressz_fops},
39058@@ -2325,7 +2325,7 @@ sg_proc_init(void)
39059 {
39060 int k, mask;
39061 int num_leaves = ARRAY_SIZE(sg_proc_leaf_arr);
39062- struct sg_proc_leaf * leaf;
39063+ const struct sg_proc_leaf * leaf;
39064
39065 sg_proc_sgp = proc_mkdir(sg_proc_sg_dirname, NULL);
39066 if (!sg_proc_sgp)
39067diff -urNp linux-2.6.39.1/drivers/scsi/sym53c8xx_2/sym_glue.c linux-2.6.39.1/drivers/scsi/sym53c8xx_2/sym_glue.c
39068--- linux-2.6.39.1/drivers/scsi/sym53c8xx_2/sym_glue.c 2011-05-19 00:06:34.000000000 -0400
39069+++ linux-2.6.39.1/drivers/scsi/sym53c8xx_2/sym_glue.c 2011-05-22 19:36:32.000000000 -0400
39070@@ -1756,6 +1756,8 @@ static int __devinit sym2_probe(struct p
39071 int do_iounmap = 0;
39072 int do_disable_device = 1;
39073
39074+ pax_track_stack();
39075+
39076 memset(&sym_dev, 0, sizeof(sym_dev));
39077 memset(&nvram, 0, sizeof(nvram));
39078 sym_dev.pdev = pdev;
39079diff -urNp linux-2.6.39.1/drivers/scsi/vmw_pvscsi.c linux-2.6.39.1/drivers/scsi/vmw_pvscsi.c
39080--- linux-2.6.39.1/drivers/scsi/vmw_pvscsi.c 2011-05-19 00:06:34.000000000 -0400
39081+++ linux-2.6.39.1/drivers/scsi/vmw_pvscsi.c 2011-05-22 19:36:32.000000000 -0400
39082@@ -447,6 +447,8 @@ static void pvscsi_setup_all_rings(const
39083 dma_addr_t base;
39084 unsigned i;
39085
39086+ pax_track_stack();
39087+
39088 cmd.ringsStatePPN = adapter->ringStatePA >> PAGE_SHIFT;
39089 cmd.reqRingNumPages = adapter->req_pages;
39090 cmd.cmpRingNumPages = adapter->cmp_pages;
39091diff -urNp linux-2.6.39.1/drivers/sh/clk/cpg.c linux-2.6.39.1/drivers/sh/clk/cpg.c
39092--- linux-2.6.39.1/drivers/sh/clk/cpg.c 2011-06-03 00:04:14.000000000 -0400
39093+++ linux-2.6.39.1/drivers/sh/clk/cpg.c 2011-06-03 00:32:06.000000000 -0400
39094@@ -26,7 +26,7 @@ static void sh_clk_mstp32_disable(struct
39095 clk->enable_reg);
39096 }
39097
39098-static struct clk_ops sh_clk_mstp32_clk_ops = {
39099+static const struct clk_ops sh_clk_mstp32_clk_ops = {
39100 .enable = sh_clk_mstp32_enable,
39101 .disable = sh_clk_mstp32_disable,
39102 .recalc = followparent_recalc,
39103@@ -150,7 +150,7 @@ static void sh_clk_div6_disable(struct c
39104 __raw_writel(value, clk->enable_reg);
39105 }
39106
39107-static struct clk_ops sh_clk_div6_clk_ops = {
39108+static const struct clk_ops sh_clk_div6_clk_ops = {
39109 .recalc = sh_clk_div6_recalc,
39110 .round_rate = sh_clk_div_round_rate,
39111 .set_rate = sh_clk_div6_set_rate,
39112@@ -158,7 +158,7 @@ static struct clk_ops sh_clk_div6_clk_op
39113 .disable = sh_clk_div6_disable,
39114 };
39115
39116-static struct clk_ops sh_clk_div6_reparent_clk_ops = {
39117+static const struct clk_ops sh_clk_div6_reparent_clk_ops = {
39118 .recalc = sh_clk_div6_recalc,
39119 .round_rate = sh_clk_div_round_rate,
39120 .set_rate = sh_clk_div6_set_rate,
39121@@ -282,13 +282,13 @@ static void sh_clk_div4_disable(struct c
39122 __raw_writel(__raw_readl(clk->enable_reg) | (1 << 8), clk->enable_reg);
39123 }
39124
39125-static struct clk_ops sh_clk_div4_clk_ops = {
39126+static const struct clk_ops sh_clk_div4_clk_ops = {
39127 .recalc = sh_clk_div4_recalc,
39128 .set_rate = sh_clk_div4_set_rate,
39129 .round_rate = sh_clk_div_round_rate,
39130 };
39131
39132-static struct clk_ops sh_clk_div4_enable_clk_ops = {
39133+static const struct clk_ops sh_clk_div4_enable_clk_ops = {
39134 .recalc = sh_clk_div4_recalc,
39135 .set_rate = sh_clk_div4_set_rate,
39136 .round_rate = sh_clk_div_round_rate,
39137@@ -296,7 +296,7 @@ static struct clk_ops sh_clk_div4_enable
39138 .disable = sh_clk_div4_disable,
39139 };
39140
39141-static struct clk_ops sh_clk_div4_reparent_clk_ops = {
39142+static const struct clk_ops sh_clk_div4_reparent_clk_ops = {
39143 .recalc = sh_clk_div4_recalc,
39144 .set_rate = sh_clk_div4_set_rate,
39145 .round_rate = sh_clk_div_round_rate,
39146diff -urNp linux-2.6.39.1/drivers/spi/dw_spi.h linux-2.6.39.1/drivers/spi/dw_spi.h
39147--- linux-2.6.39.1/drivers/spi/dw_spi.h 2011-05-19 00:06:34.000000000 -0400
39148+++ linux-2.6.39.1/drivers/spi/dw_spi.h 2011-05-22 19:36:32.000000000 -0400
39149@@ -151,7 +151,7 @@ struct dw_spi {
39150 int dma_chan_done;
39151 struct device *dma_dev;
39152 dma_addr_t dma_addr; /* phy address of the Data register */
39153- struct dw_spi_dma_ops *dma_ops;
39154+ const struct dw_spi_dma_ops *dma_ops;
39155 void *dma_priv; /* platform relate info */
39156 struct pci_dev *dmac;
39157
39158diff -urNp linux-2.6.39.1/drivers/spi/dw_spi_mid.c linux-2.6.39.1/drivers/spi/dw_spi_mid.c
39159--- linux-2.6.39.1/drivers/spi/dw_spi_mid.c 2011-05-19 00:06:34.000000000 -0400
39160+++ linux-2.6.39.1/drivers/spi/dw_spi_mid.c 2011-05-22 19:36:32.000000000 -0400
39161@@ -180,7 +180,7 @@ static int mid_spi_dma_transfer(struct d
39162 return 0;
39163 }
39164
39165-static struct dw_spi_dma_ops mid_dma_ops = {
39166+static const struct dw_spi_dma_ops mid_dma_ops = {
39167 .dma_init = mid_spi_dma_init,
39168 .dma_exit = mid_spi_dma_exit,
39169 .dma_transfer = mid_spi_dma_transfer,
39170diff -urNp linux-2.6.39.1/drivers/spi/spi.c linux-2.6.39.1/drivers/spi/spi.c
39171--- linux-2.6.39.1/drivers/spi/spi.c 2011-05-19 00:06:34.000000000 -0400
39172+++ linux-2.6.39.1/drivers/spi/spi.c 2011-05-22 19:36:32.000000000 -0400
39173@@ -1023,7 +1023,7 @@ int spi_bus_unlock(struct spi_master *ma
39174 EXPORT_SYMBOL_GPL(spi_bus_unlock);
39175
39176 /* portable code must never pass more than 32 bytes */
39177-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
39178+#define SPI_BUFSIZ max(32U,SMP_CACHE_BYTES)
39179
39180 static u8 *buf;
39181
39182diff -urNp linux-2.6.39.1/drivers/ssb/driver_pcicore.c linux-2.6.39.1/drivers/ssb/driver_pcicore.c
39183--- linux-2.6.39.1/drivers/ssb/driver_pcicore.c 2011-05-19 00:06:34.000000000 -0400
39184+++ linux-2.6.39.1/drivers/ssb/driver_pcicore.c 2011-05-22 19:36:32.000000000 -0400
39185@@ -223,7 +223,7 @@ static int ssb_pcicore_write_config(stru
39186 return err ? PCIBIOS_DEVICE_NOT_FOUND : PCIBIOS_SUCCESSFUL;
39187 }
39188
39189-static struct pci_ops ssb_pcicore_pciops = {
39190+static const struct pci_ops ssb_pcicore_pciops = {
39191 .read = ssb_pcicore_read_config,
39192 .write = ssb_pcicore_write_config,
39193 };
39194diff -urNp linux-2.6.39.1/drivers/staging/ath6kl/os/linux/cfg80211.c linux-2.6.39.1/drivers/staging/ath6kl/os/linux/cfg80211.c
39195--- linux-2.6.39.1/drivers/staging/ath6kl/os/linux/cfg80211.c 2011-05-19 00:06:34.000000000 -0400
39196+++ linux-2.6.39.1/drivers/staging/ath6kl/os/linux/cfg80211.c 2011-05-22 19:36:32.000000000 -0400
39197@@ -1391,8 +1391,7 @@ u32 cipher_suites[] = {
39198 WLAN_CIPHER_SUITE_CCMP,
39199 };
39200
39201-static struct
39202-cfg80211_ops ar6k_cfg80211_ops = {
39203+static const struct cfg80211_ops ar6k_cfg80211_ops = {
39204 .change_virtual_intf = ar6k_cfg80211_change_iface,
39205 .add_virtual_intf = ar6k_cfg80211_add_virtual_intf,
39206 .del_virtual_intf = ar6k_cfg80211_del_virtual_intf,
39207diff -urNp linux-2.6.39.1/drivers/staging/brcm80211/brcmfmac/dhd_linux.c linux-2.6.39.1/drivers/staging/brcm80211/brcmfmac/dhd_linux.c
39208--- linux-2.6.39.1/drivers/staging/brcm80211/brcmfmac/dhd_linux.c 2011-05-19 00:06:34.000000000 -0400
39209+++ linux-2.6.39.1/drivers/staging/brcm80211/brcmfmac/dhd_linux.c 2011-05-22 19:36:32.000000000 -0400
39210@@ -857,14 +857,14 @@ static void dhd_op_if(dhd_if_t *ifp)
39211 free_netdev(ifp->net);
39212 }
39213 /* Allocate etherdev, including space for private structure */
39214- ifp->net = alloc_etherdev(sizeof(dhd));
39215+ ifp->net = alloc_etherdev(sizeof(*dhd));
39216 if (!ifp->net) {
39217 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
39218 ret = -ENOMEM;
39219 }
39220 if (ret == 0) {
39221 strcpy(ifp->net->name, ifp->name);
39222- memcpy(netdev_priv(ifp->net), &dhd, sizeof(dhd));
39223+ memcpy(netdev_priv(ifp->net), dhd, sizeof(*dhd));
39224 err = dhd_net_attach(&dhd->pub, ifp->idx);
39225 if (err != 0) {
39226 DHD_ERROR(("%s: dhd_net_attach failed, "
39227@@ -1500,7 +1500,7 @@ static void dhd_ethtool_get_drvinfo(stru
39228 sprintf(info->bus_info, "%s", dev_name(&wl_cfg80211_get_sdio_func()->dev));
39229 }
39230
39231-struct ethtool_ops dhd_ethtool_ops = {
39232+const struct ethtool_ops dhd_ethtool_ops = {
39233 .get_drvinfo = dhd_ethtool_get_drvinfo
39234 };
39235
39236@@ -1923,7 +1923,7 @@ dhd_pub_t *dhd_attach(struct dhd_bus *bu
39237 strcpy(nv_path, nvram_path);
39238
39239 /* Allocate etherdev, including space for private structure */
39240- net = alloc_etherdev(sizeof(dhd));
39241+ net = alloc_etherdev(sizeof(*dhd));
39242 if (!net) {
39243 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
39244 goto fail;
39245@@ -1939,7 +1939,7 @@ dhd_pub_t *dhd_attach(struct dhd_bus *bu
39246 /*
39247 * Save the dhd_info into the priv
39248 */
39249- memcpy(netdev_priv(net), &dhd, sizeof(dhd));
39250+ memcpy(netdev_priv(net), dhd, sizeof(*dhd));
39251
39252 /* Set network interface name if it was provided as module parameter */
39253 if (iface_name[0]) {
39254@@ -2056,7 +2056,7 @@ dhd_pub_t *dhd_attach(struct dhd_bus *bu
39255 /*
39256 * Save the dhd_info into the priv
39257 */
39258- memcpy(netdev_priv(net), &dhd, sizeof(dhd));
39259+ memcpy(netdev_priv(net), dhd, sizeof(*dhd));
39260
39261 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
39262 g_bus = bus;
39263@@ -2206,7 +2206,7 @@ dhd_iovar(dhd_pub_t *pub, int ifidx, cha
39264 return ret;
39265 }
39266
39267-static struct net_device_ops dhd_ops_pri = {
39268+static const struct net_device_ops dhd_ops_pri = {
39269 .ndo_open = dhd_open,
39270 .ndo_stop = dhd_stop,
39271 .ndo_get_stats = dhd_get_stats,
39272diff -urNp linux-2.6.39.1/drivers/staging/brcm80211/brcmfmac/wl_cfg80211.c linux-2.6.39.1/drivers/staging/brcm80211/brcmfmac/wl_cfg80211.c
39273--- linux-2.6.39.1/drivers/staging/brcm80211/brcmfmac/wl_cfg80211.c 2011-05-19 00:06:34.000000000 -0400
39274+++ linux-2.6.39.1/drivers/staging/brcm80211/brcmfmac/wl_cfg80211.c 2011-05-22 19:36:32.000000000 -0400
39275@@ -2109,7 +2109,7 @@ wl_cfg80211_flush_pmksa(struct wiphy *wi
39276
39277 }
39278
39279-static struct cfg80211_ops wl_cfg80211_ops = {
39280+static const struct cfg80211_ops wl_cfg80211_ops = {
39281 .change_virtual_intf = wl_cfg80211_change_iface,
39282 .scan = wl_cfg80211_scan,
39283 .set_wiphy_params = wl_cfg80211_set_wiphy_params,
39284diff -urNp linux-2.6.39.1/drivers/staging/brcm80211/brcmfmac/wl_iw.c linux-2.6.39.1/drivers/staging/brcm80211/brcmfmac/wl_iw.c
39285--- linux-2.6.39.1/drivers/staging/brcm80211/brcmfmac/wl_iw.c 2011-05-19 00:06:34.000000000 -0400
39286+++ linux-2.6.39.1/drivers/staging/brcm80211/brcmfmac/wl_iw.c 2011-05-22 19:36:32.000000000 -0400
39287@@ -495,7 +495,7 @@ wl_iw_get_range(struct net_device *dev,
39288 list = (wl_u32_list_t *) channels;
39289
39290 dwrq->length = sizeof(struct iw_range);
39291- memset(range, 0, sizeof(range));
39292+ memset(range, 0, sizeof(*range));
39293
39294 range->min_nwid = range->max_nwid = 0;
39295
39296diff -urNp linux-2.6.39.1/drivers/staging/comedi/comedi_fops.c linux-2.6.39.1/drivers/staging/comedi/comedi_fops.c
39297--- linux-2.6.39.1/drivers/staging/comedi/comedi_fops.c 2011-05-19 00:06:34.000000000 -0400
39298+++ linux-2.6.39.1/drivers/staging/comedi/comedi_fops.c 2011-05-22 19:36:32.000000000 -0400
39299@@ -1445,7 +1445,7 @@ static void comedi_unmap(struct vm_area_
39300 mutex_unlock(&dev->mutex);
39301 }
39302
39303-static struct vm_operations_struct comedi_vm_ops = {
39304+static const struct vm_operations_struct comedi_vm_ops = {
39305 .close = comedi_unmap,
39306 };
39307
39308diff -urNp linux-2.6.39.1/drivers/staging/cx25821/cx25821-alsa.c linux-2.6.39.1/drivers/staging/cx25821/cx25821-alsa.c
39309--- linux-2.6.39.1/drivers/staging/cx25821/cx25821-alsa.c 2011-05-19 00:06:34.000000000 -0400
39310+++ linux-2.6.39.1/drivers/staging/cx25821/cx25821-alsa.c 2011-05-22 19:36:32.000000000 -0400
39311@@ -586,7 +586,7 @@ static struct page *snd_cx25821_page(str
39312 /*
39313 * operators
39314 */
39315-static struct snd_pcm_ops snd_cx25821_pcm_ops = {
39316+static const struct snd_pcm_ops snd_cx25821_pcm_ops = {
39317 .open = snd_cx25821_pcm_open,
39318 .close = snd_cx25821_close,
39319 .ioctl = snd_pcm_lib_ioctl,
39320diff -urNp linux-2.6.39.1/drivers/staging/cx25821/cx25821-i2c.c linux-2.6.39.1/drivers/staging/cx25821/cx25821-i2c.c
39321--- linux-2.6.39.1/drivers/staging/cx25821/cx25821-i2c.c 2011-05-19 00:06:34.000000000 -0400
39322+++ linux-2.6.39.1/drivers/staging/cx25821/cx25821-i2c.c 2011-05-22 19:36:32.000000000 -0400
39323@@ -282,7 +282,7 @@ static u32 cx25821_functionality(struct
39324 I2C_FUNC_SMBUS_READ_WORD_DATA | I2C_FUNC_SMBUS_WRITE_WORD_DATA;
39325 }
39326
39327-static struct i2c_algorithm cx25821_i2c_algo_template = {
39328+static const struct i2c_algorithm cx25821_i2c_algo_template = {
39329 .master_xfer = i2c_xfer,
39330 .functionality = cx25821_functionality,
39331 #ifdef NEED_ALGO_CONTROL
39332diff -urNp linux-2.6.39.1/drivers/staging/et131x/et1310_tx.c linux-2.6.39.1/drivers/staging/et131x/et1310_tx.c
39333--- linux-2.6.39.1/drivers/staging/et131x/et1310_tx.c 2011-05-19 00:06:34.000000000 -0400
39334+++ linux-2.6.39.1/drivers/staging/et131x/et1310_tx.c 2011-05-22 19:36:32.000000000 -0400
39335@@ -635,11 +635,11 @@ inline void et131x_free_send_packet(stru
39336 struct net_device_stats *stats = &etdev->net_stats;
39337
39338 if (tcb->flags & fMP_DEST_BROAD)
39339- atomic_inc(&etdev->Stats.brdcstxmt);
39340+ atomic_inc_unchecked(&etdev->Stats.brdcstxmt);
39341 else if (tcb->flags & fMP_DEST_MULTI)
39342- atomic_inc(&etdev->Stats.multixmt);
39343+ atomic_inc_unchecked(&etdev->Stats.multixmt);
39344 else
39345- atomic_inc(&etdev->Stats.unixmt);
39346+ atomic_inc_unchecked(&etdev->Stats.unixmt);
39347
39348 if (tcb->skb) {
39349 stats->tx_bytes += tcb->skb->len;
39350diff -urNp linux-2.6.39.1/drivers/staging/et131x/et131x_adapter.h linux-2.6.39.1/drivers/staging/et131x/et131x_adapter.h
39351--- linux-2.6.39.1/drivers/staging/et131x/et131x_adapter.h 2011-05-19 00:06:34.000000000 -0400
39352+++ linux-2.6.39.1/drivers/staging/et131x/et131x_adapter.h 2011-05-22 19:36:32.000000000 -0400
39353@@ -110,11 +110,11 @@ typedef struct _ce_stats_t {
39354 * operations
39355 */
39356 u32 unircv; /* # multicast packets received */
39357- atomic_t unixmt; /* # multicast packets for Tx */
39358+ atomic_unchecked_t unixmt; /* # multicast packets for Tx */
39359 u32 multircv; /* # multicast packets received */
39360- atomic_t multixmt; /* # multicast packets for Tx */
39361+ atomic_unchecked_t multixmt; /* # multicast packets for Tx */
39362 u32 brdcstrcv; /* # broadcast packets received */
39363- atomic_t brdcstxmt; /* # broadcast packets for Tx */
39364+ atomic_unchecked_t brdcstxmt; /* # broadcast packets for Tx */
39365 u32 norcvbuf; /* # Rx packets discarded */
39366 u32 noxmtbuf; /* # Tx packets discarded */
39367
39368diff -urNp linux-2.6.39.1/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c linux-2.6.39.1/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c
39369--- linux-2.6.39.1/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c 2011-05-19 00:06:34.000000000 -0400
39370+++ linux-2.6.39.1/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c 2011-05-22 19:36:32.000000000 -0400
39371@@ -55,7 +55,7 @@ int numofmsgbuf = 0;
39372 //
39373 // Table of entry-point routines for char device
39374 //
39375-static struct file_operations ft1000fops =
39376+static const struct file_operations ft1000fops =
39377 {
39378 .unlocked_ioctl = ft1000_ioctl,
39379 .poll = ft1000_poll_dev,
39380diff -urNp linux-2.6.39.1/drivers/staging/generic_serial/rio/rio_linux.c linux-2.6.39.1/drivers/staging/generic_serial/rio/rio_linux.c
39381--- linux-2.6.39.1/drivers/staging/generic_serial/rio/rio_linux.c 2011-05-19 00:06:34.000000000 -0400
39382+++ linux-2.6.39.1/drivers/staging/generic_serial/rio/rio_linux.c 2011-05-22 19:36:32.000000000 -0400
39383@@ -221,7 +221,7 @@ module_param(rio_poll, int, 0);
39384 module_param(rio_debug, int, 0644);
39385 module_param(rio_irqmask, long, 0);
39386
39387-static struct real_driver rio_real_driver = {
39388+static const struct real_driver rio_real_driver = {
39389 rio_disable_tx_interrupts,
39390 rio_enable_tx_interrupts,
39391 rio_disable_rx_interrupts,
39392diff -urNp linux-2.6.39.1/drivers/staging/generic_serial/ser_a2232.c linux-2.6.39.1/drivers/staging/generic_serial/ser_a2232.c
39393--- linux-2.6.39.1/drivers/staging/generic_serial/ser_a2232.c 2011-05-19 00:06:34.000000000 -0400
39394+++ linux-2.6.39.1/drivers/staging/generic_serial/ser_a2232.c 2011-05-22 19:36:32.000000000 -0400
39395@@ -144,7 +144,7 @@ static int a2232_open(struct tty_struct
39396 /*---------------------------------------------------------------------------
39397 * Interface from generic_serial.c back here
39398 *--------------------------------------------------------------------------*/
39399-static struct real_driver a2232_real_driver = {
39400+static const struct real_driver a2232_real_driver = {
39401 a2232_disable_tx_interrupts,
39402 a2232_enable_tx_interrupts,
39403 a2232_disable_rx_interrupts,
39404diff -urNp linux-2.6.39.1/drivers/staging/generic_serial/sx.c linux-2.6.39.1/drivers/staging/generic_serial/sx.c
39405--- linux-2.6.39.1/drivers/staging/generic_serial/sx.c 2011-05-19 00:06:34.000000000 -0400
39406+++ linux-2.6.39.1/drivers/staging/generic_serial/sx.c 2011-05-22 19:36:32.000000000 -0400
39407@@ -355,7 +355,7 @@ module_param(sx_irqmask, int, 0);
39408
39409 MODULE_LICENSE("GPL");
39410
39411-static struct real_driver sx_real_driver = {
39412+static const struct real_driver sx_real_driver = {
39413 sx_disable_tx_interrupts,
39414 sx_enable_tx_interrupts,
39415 sx_disable_rx_interrupts,
39416diff -urNp linux-2.6.39.1/drivers/staging/generic_serial/vme_scc.c linux-2.6.39.1/drivers/staging/generic_serial/vme_scc.c
39417--- linux-2.6.39.1/drivers/staging/generic_serial/vme_scc.c 2011-05-19 00:06:34.000000000 -0400
39418+++ linux-2.6.39.1/drivers/staging/generic_serial/vme_scc.c 2011-05-22 19:36:32.000000000 -0400
39419@@ -94,7 +94,7 @@ static struct scc_port scc_ports[2];
39420 * Interface from generic_serial.c back here
39421 *--------------------------------------------------------------------------*/
39422
39423-static struct real_driver scc_real_driver = {
39424+static const struct real_driver scc_real_driver = {
39425 scc_disable_tx_interrupts,
39426 scc_enable_tx_interrupts,
39427 scc_disable_rx_interrupts,
39428diff -urNp linux-2.6.39.1/drivers/staging/gma500/psb_fb.c linux-2.6.39.1/drivers/staging/gma500/psb_fb.c
39429--- linux-2.6.39.1/drivers/staging/gma500/psb_fb.c 2011-05-19 00:06:34.000000000 -0400
39430+++ linux-2.6.39.1/drivers/staging/gma500/psb_fb.c 2011-05-22 19:36:32.000000000 -0400
39431@@ -230,7 +230,7 @@ static void psbfb_vm_close(struct vm_are
39432 DRM_DEBUG("vm_close\n");
39433 }
39434
39435-static struct vm_operations_struct psbfb_vm_ops = {
39436+static const struct vm_operations_struct psbfb_vm_ops = {
39437 .fault = psbfb_vm_fault,
39438 .open = psbfb_vm_open,
39439 .close = psbfb_vm_close
39440diff -urNp linux-2.6.39.1/drivers/staging/go7007/go7007-i2c.c linux-2.6.39.1/drivers/staging/go7007/go7007-i2c.c
39441--- linux-2.6.39.1/drivers/staging/go7007/go7007-i2c.c 2011-05-19 00:06:34.000000000 -0400
39442+++ linux-2.6.39.1/drivers/staging/go7007/go7007-i2c.c 2011-05-22 19:36:32.000000000 -0400
39443@@ -198,7 +198,7 @@ static u32 go7007_functionality(struct i
39444 return I2C_FUNC_SMBUS_BYTE_DATA;
39445 }
39446
39447-static struct i2c_algorithm go7007_algo = {
39448+static const struct i2c_algorithm go7007_algo = {
39449 .smbus_xfer = go7007_smbus_xfer,
39450 .master_xfer = go7007_i2c_master_xfer,
39451 .functionality = go7007_functionality,
39452diff -urNp linux-2.6.39.1/drivers/staging/go7007/go7007-usb.c linux-2.6.39.1/drivers/staging/go7007/go7007-usb.c
39453--- linux-2.6.39.1/drivers/staging/go7007/go7007-usb.c 2011-05-19 00:06:34.000000000 -0400
39454+++ linux-2.6.39.1/drivers/staging/go7007/go7007-usb.c 2011-05-22 19:36:32.000000000 -0400
39455@@ -849,7 +849,7 @@ static int go7007_usb_send_firmware(stru
39456 &transferred, timeout);
39457 }
39458
39459-static struct go7007_hpi_ops go7007_usb_ezusb_hpi_ops = {
39460+static const struct go7007_hpi_ops go7007_usb_ezusb_hpi_ops = {
39461 .interface_reset = go7007_usb_interface_reset,
39462 .write_interrupt = go7007_usb_ezusb_write_interrupt,
39463 .read_interrupt = go7007_usb_read_interrupt,
39464@@ -858,7 +858,7 @@ static struct go7007_hpi_ops go7007_usb_
39465 .send_firmware = go7007_usb_send_firmware,
39466 };
39467
39468-static struct go7007_hpi_ops go7007_usb_onboard_hpi_ops = {
39469+static const struct go7007_hpi_ops go7007_usb_onboard_hpi_ops = {
39470 .interface_reset = go7007_usb_interface_reset,
39471 .write_interrupt = go7007_usb_onboard_write_interrupt,
39472 .read_interrupt = go7007_usb_read_interrupt,
39473@@ -950,7 +950,7 @@ static u32 go7007_usb_functionality(stru
39474 return (I2C_FUNC_SMBUS_EMUL) & ~I2C_FUNC_SMBUS_QUICK;
39475 }
39476
39477-static struct i2c_algorithm go7007_usb_algo = {
39478+static const struct i2c_algorithm go7007_usb_algo = {
39479 .master_xfer = go7007_usb_i2c_master_xfer,
39480 .functionality = go7007_usb_functionality,
39481 };
39482diff -urNp linux-2.6.39.1/drivers/staging/go7007/go7007-v4l2.c linux-2.6.39.1/drivers/staging/go7007/go7007-v4l2.c
39483--- linux-2.6.39.1/drivers/staging/go7007/go7007-v4l2.c 2011-05-19 00:06:34.000000000 -0400
39484+++ linux-2.6.39.1/drivers/staging/go7007/go7007-v4l2.c 2011-05-22 19:36:32.000000000 -0400
39485@@ -1672,7 +1672,7 @@ static int go7007_vm_fault(struct vm_are
39486 return 0;
39487 }
39488
39489-static struct vm_operations_struct go7007_vm_ops = {
39490+static const struct vm_operations_struct go7007_vm_ops = {
39491 .open = go7007_vm_open,
39492 .close = go7007_vm_close,
39493 .fault = go7007_vm_fault,
39494diff -urNp linux-2.6.39.1/drivers/staging/go7007/saa7134-go7007.c linux-2.6.39.1/drivers/staging/go7007/saa7134-go7007.c
39495--- linux-2.6.39.1/drivers/staging/go7007/saa7134-go7007.c 2011-05-19 00:06:34.000000000 -0400
39496+++ linux-2.6.39.1/drivers/staging/go7007/saa7134-go7007.c 2011-05-22 19:36:32.000000000 -0400
39497@@ -421,7 +421,7 @@ static int saa7134_go7007_send_command(s
39498
39499 }
39500
39501-static struct go7007_hpi_ops saa7134_go7007_hpi_ops = {
39502+static const struct go7007_hpi_ops saa7134_go7007_hpi_ops = {
39503 .interface_reset = saa7134_go7007_interface_reset,
39504 .write_interrupt = saa7134_go7007_write_interrupt,
39505 .read_interrupt = saa7134_go7007_read_interrupt,
39506diff -urNp linux-2.6.39.1/drivers/staging/go7007/snd-go7007.c linux-2.6.39.1/drivers/staging/go7007/snd-go7007.c
39507--- linux-2.6.39.1/drivers/staging/go7007/snd-go7007.c 2011-05-19 00:06:34.000000000 -0400
39508+++ linux-2.6.39.1/drivers/staging/go7007/snd-go7007.c 2011-05-22 19:36:32.000000000 -0400
39509@@ -204,7 +204,7 @@ static struct page *go7007_snd_pcm_page(
39510 return vmalloc_to_page(substream->runtime->dma_area + offset);
39511 }
39512
39513-static struct snd_pcm_ops go7007_snd_capture_ops = {
39514+static const struct snd_pcm_ops go7007_snd_capture_ops = {
39515 .open = go7007_snd_capture_open,
39516 .close = go7007_snd_capture_close,
39517 .ioctl = snd_pcm_lib_ioctl,
39518@@ -227,7 +227,7 @@ static int go7007_snd_free(struct snd_de
39519 return 0;
39520 }
39521
39522-static struct snd_device_ops go7007_snd_device_ops = {
39523+static const struct snd_device_ops go7007_snd_device_ops = {
39524 .dev_free = go7007_snd_free,
39525 };
39526
39527diff -urNp linux-2.6.39.1/drivers/staging/hv/channel.c linux-2.6.39.1/drivers/staging/hv/channel.c
39528--- linux-2.6.39.1/drivers/staging/hv/channel.c 2011-05-19 00:06:34.000000000 -0400
39529+++ linux-2.6.39.1/drivers/staging/hv/channel.c 2011-05-22 19:36:32.000000000 -0400
39530@@ -509,8 +509,8 @@ int vmbus_establish_gpadl(struct vmbus_c
39531 unsigned long flags;
39532 int ret = 0;
39533
39534- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
39535- atomic_inc(&vmbus_connection.next_gpadl_handle);
39536+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
39537+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
39538
39539 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
39540 if (ret)
39541diff -urNp linux-2.6.39.1/drivers/staging/hv/hv.c linux-2.6.39.1/drivers/staging/hv/hv.c
39542--- linux-2.6.39.1/drivers/staging/hv/hv.c 2011-05-19 00:06:34.000000000 -0400
39543+++ linux-2.6.39.1/drivers/staging/hv/hv.c 2011-05-22 19:36:32.000000000 -0400
39544@@ -163,7 +163,7 @@ static u64 do_hypercall(u64 control, voi
39545 u64 output_address = (output) ? virt_to_phys(output) : 0;
39546 u32 output_address_hi = output_address >> 32;
39547 u32 output_address_lo = output_address & 0xFFFFFFFF;
39548- volatile void *hypercall_page = hv_context.hypercall_page;
39549+ volatile void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
39550
39551 DPRINT_DBG(VMBUS, "Hypercall <control %llx input %p output %p>",
39552 control, input, output);
39553diff -urNp linux-2.6.39.1/drivers/staging/hv/rndis_filter.c linux-2.6.39.1/drivers/staging/hv/rndis_filter.c
39554--- linux-2.6.39.1/drivers/staging/hv/rndis_filter.c 2011-05-19 00:06:34.000000000 -0400
39555+++ linux-2.6.39.1/drivers/staging/hv/rndis_filter.c 2011-05-22 19:36:32.000000000 -0400
39556@@ -49,7 +49,7 @@ struct rndis_device {
39557
39558 enum rndis_device_state state;
39559 u32 link_stat;
39560- atomic_t new_req_id;
39561+ atomic_unchecked_t new_req_id;
39562
39563 spinlock_t request_lock;
39564 struct list_head req_list;
39565@@ -144,7 +144,7 @@ static struct rndis_request *get_rndis_r
39566 * template
39567 */
39568 set = &rndis_msg->msg.set_req;
39569- set->req_id = atomic_inc_return(&dev->new_req_id);
39570+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
39571
39572 /* Add to the request list */
39573 spin_lock_irqsave(&dev->request_lock, flags);
39574@@ -709,7 +709,7 @@ static void rndis_filter_halt_device(str
39575
39576 /* Setup the rndis set */
39577 halt = &request->request_msg.msg.halt_req;
39578- halt->req_id = atomic_inc_return(&dev->new_req_id);
39579+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
39580
39581 /* Ignore return since this msg is optional. */
39582 rndis_filter_send_request(dev, request);
39583diff -urNp linux-2.6.39.1/drivers/staging/hv/vmbus_drv.c linux-2.6.39.1/drivers/staging/hv/vmbus_drv.c
39584--- linux-2.6.39.1/drivers/staging/hv/vmbus_drv.c 2011-05-19 00:06:34.000000000 -0400
39585+++ linux-2.6.39.1/drivers/staging/hv/vmbus_drv.c 2011-05-22 19:36:32.000000000 -0400
39586@@ -661,14 +661,14 @@ int vmbus_child_device_register(struct h
39587 {
39588 int ret = 0;
39589
39590- static atomic_t device_num = ATOMIC_INIT(0);
39591+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
39592
39593 DPRINT_DBG(VMBUS_DRV, "child device (%p) registering",
39594 child_device_obj);
39595
39596 /* Set the device name. Otherwise, device_register() will fail. */
39597 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
39598- atomic_inc_return(&device_num));
39599+ atomic_inc_return_unchecked(&device_num));
39600
39601 /* The new device belongs to this bus */
39602 child_device_obj->device.bus = &vmbus_drv.bus; /* device->dev.bus; */
39603diff -urNp linux-2.6.39.1/drivers/staging/hv/vmbus_private.h linux-2.6.39.1/drivers/staging/hv/vmbus_private.h
39604--- linux-2.6.39.1/drivers/staging/hv/vmbus_private.h 2011-05-19 00:06:34.000000000 -0400
39605+++ linux-2.6.39.1/drivers/staging/hv/vmbus_private.h 2011-05-22 19:36:32.000000000 -0400
39606@@ -58,7 +58,7 @@ enum vmbus_connect_state {
39607 struct vmbus_connection {
39608 enum vmbus_connect_state conn_state;
39609
39610- atomic_t next_gpadl_handle;
39611+ atomic_unchecked_t next_gpadl_handle;
39612
39613 /*
39614 * Represents channel interrupts. Each bit position represents a
39615diff -urNp linux-2.6.39.1/drivers/staging/iio/ring_generic.h linux-2.6.39.1/drivers/staging/iio/ring_generic.h
39616--- linux-2.6.39.1/drivers/staging/iio/ring_generic.h 2011-05-19 00:06:34.000000000 -0400
39617+++ linux-2.6.39.1/drivers/staging/iio/ring_generic.h 2011-05-25 16:55:27.000000000 -0400
39618@@ -134,7 +134,7 @@ struct iio_ring_buffer {
39619 struct iio_handler access_handler;
39620 struct iio_event_interface ev_int;
39621 struct iio_shared_ev_pointer shared_ev_pointer;
39622- struct iio_ring_access_funcs access;
39623+ struct iio_ring_access_funcs access;
39624 int (*preenable)(struct iio_dev *);
39625 int (*postenable)(struct iio_dev *);
39626 int (*predisable)(struct iio_dev *);
39627diff -urNp linux-2.6.39.1/drivers/staging/intel_sst/intelmid_ctrl.c linux-2.6.39.1/drivers/staging/intel_sst/intelmid_ctrl.c
39628--- linux-2.6.39.1/drivers/staging/intel_sst/intelmid_ctrl.c 2011-05-19 00:06:34.000000000 -0400
39629+++ linux-2.6.39.1/drivers/staging/intel_sst/intelmid_ctrl.c 2011-05-22 19:36:32.000000000 -0400
39630@@ -494,7 +494,7 @@ static int snd_intelmad_device_set(struc
39631 struct snd_intelmad *intelmaddata;
39632 struct snd_pmic_ops *scard_ops;
39633 int ret_val = 0, vendor, status;
39634- struct intel_sst_pcm_control *pcm_control;
39635+ const struct intel_sst_pcm_control *pcm_control;
39636
39637 pr_debug("snd_intelmad_device_set called\n");
39638
39639diff -urNp linux-2.6.39.1/drivers/staging/intel_sst/intel_sst_drv_interface.c linux-2.6.39.1/drivers/staging/intel_sst/intel_sst_drv_interface.c
39640--- linux-2.6.39.1/drivers/staging/intel_sst/intel_sst_drv_interface.c 2011-05-19 00:06:34.000000000 -0400
39641+++ linux-2.6.39.1/drivers/staging/intel_sst/intel_sst_drv_interface.c 2011-05-22 19:36:32.000000000 -0400
39642@@ -470,7 +470,7 @@ int sst_device_control(int cmd, void *ar
39643 }
39644
39645
39646-struct intel_sst_pcm_control pcm_ops = {
39647+const struct intel_sst_pcm_control pcm_ops = {
39648 .open = sst_open_pcm_stream,
39649 .device_control = sst_device_control,
39650 .close = sst_close_pcm_stream,
39651diff -urNp linux-2.6.39.1/drivers/staging/line6/capture.c linux-2.6.39.1/drivers/staging/line6/capture.c
39652--- linux-2.6.39.1/drivers/staging/line6/capture.c 2011-05-19 00:06:34.000000000 -0400
39653+++ linux-2.6.39.1/drivers/staging/line6/capture.c 2011-05-22 19:36:32.000000000 -0400
39654@@ -378,7 +378,7 @@ snd_line6_capture_pointer(struct snd_pcm
39655 }
39656
39657 /* capture operators */
39658-struct snd_pcm_ops snd_line6_capture_ops = {
39659+const struct snd_pcm_ops snd_line6_capture_ops = {
39660 .open = snd_line6_capture_open,
39661 .close = snd_line6_capture_close,
39662 .ioctl = snd_pcm_lib_ioctl,
39663diff -urNp linux-2.6.39.1/drivers/staging/line6/capture.h linux-2.6.39.1/drivers/staging/line6/capture.h
39664--- linux-2.6.39.1/drivers/staging/line6/capture.h 2011-05-19 00:06:34.000000000 -0400
39665+++ linux-2.6.39.1/drivers/staging/line6/capture.h 2011-05-22 19:36:32.000000000 -0400
39666@@ -17,7 +17,7 @@
39667 #include "driver.h"
39668 #include "pcm.h"
39669
39670-extern struct snd_pcm_ops snd_line6_capture_ops;
39671+extern const struct snd_pcm_ops snd_line6_capture_ops;
39672
39673 extern void line6_capture_copy(struct snd_line6_pcm *line6pcm, char *fbuf,
39674 int fsize);
39675diff -urNp linux-2.6.39.1/drivers/staging/line6/midi.c linux-2.6.39.1/drivers/staging/line6/midi.c
39676--- linux-2.6.39.1/drivers/staging/line6/midi.c 2011-05-19 00:06:34.000000000 -0400
39677+++ linux-2.6.39.1/drivers/staging/line6/midi.c 2011-05-22 19:36:32.000000000 -0400
39678@@ -239,14 +239,14 @@ static void line6_midi_input_trigger(str
39679 line6->line6midi->substream_receive = 0;
39680 }
39681
39682-static struct snd_rawmidi_ops line6_midi_output_ops = {
39683+static const struct snd_rawmidi_ops line6_midi_output_ops = {
39684 .open = line6_midi_output_open,
39685 .close = line6_midi_output_close,
39686 .trigger = line6_midi_output_trigger,
39687 .drain = line6_midi_output_drain,
39688 };
39689
39690-static struct snd_rawmidi_ops line6_midi_input_ops = {
39691+static const struct snd_rawmidi_ops line6_midi_input_ops = {
39692 .open = line6_midi_input_open,
39693 .close = line6_midi_input_close,
39694 .trigger = line6_midi_input_trigger,
39695@@ -373,7 +373,7 @@ static int snd_line6_midi_free(struct sn
39696 */
39697 int line6_init_midi(struct usb_line6 *line6)
39698 {
39699- static struct snd_device_ops midi_ops = {
39700+ static const struct snd_device_ops midi_ops = {
39701 .dev_free = snd_line6_midi_free,
39702 };
39703
39704diff -urNp linux-2.6.39.1/drivers/staging/line6/pcm.c linux-2.6.39.1/drivers/staging/line6/pcm.c
39705--- linux-2.6.39.1/drivers/staging/line6/pcm.c 2011-05-19 00:06:34.000000000 -0400
39706+++ linux-2.6.39.1/drivers/staging/line6/pcm.c 2011-05-22 19:36:32.000000000 -0400
39707@@ -384,7 +384,7 @@ void line6_pcm_disconnect(struct snd_lin
39708 int line6_init_pcm(struct usb_line6 *line6,
39709 struct line6_pcm_properties *properties)
39710 {
39711- static struct snd_device_ops pcm_ops = {
39712+ static const struct snd_device_ops pcm_ops = {
39713 .dev_free = snd_line6_pcm_free,
39714 };
39715
39716diff -urNp linux-2.6.39.1/drivers/staging/line6/playback.c linux-2.6.39.1/drivers/staging/line6/playback.c
39717--- linux-2.6.39.1/drivers/staging/line6/playback.c 2011-05-19 00:06:34.000000000 -0400
39718+++ linux-2.6.39.1/drivers/staging/line6/playback.c 2011-05-22 19:36:32.000000000 -0400
39719@@ -536,7 +536,7 @@ snd_line6_playback_pointer(struct snd_pc
39720 }
39721
39722 /* playback operators */
39723-struct snd_pcm_ops snd_line6_playback_ops = {
39724+const struct snd_pcm_ops snd_line6_playback_ops = {
39725 .open = snd_line6_playback_open,
39726 .close = snd_line6_playback_close,
39727 .ioctl = snd_pcm_lib_ioctl,
39728diff -urNp linux-2.6.39.1/drivers/staging/line6/playback.h linux-2.6.39.1/drivers/staging/line6/playback.h
39729--- linux-2.6.39.1/drivers/staging/line6/playback.h 2011-05-19 00:06:34.000000000 -0400
39730+++ linux-2.6.39.1/drivers/staging/line6/playback.h 2011-05-22 19:36:32.000000000 -0400
39731@@ -27,7 +27,7 @@
39732 */
39733 #define USE_CLEAR_BUFFER_WORKAROUND 1
39734
39735-extern struct snd_pcm_ops snd_line6_playback_ops;
39736+extern const struct snd_pcm_ops snd_line6_playback_ops;
39737
39738 extern int line6_create_audio_out_urbs(struct snd_line6_pcm *line6pcm);
39739 extern int line6_submit_audio_out_all_urbs(struct snd_line6_pcm *line6pcm);
39740diff -urNp linux-2.6.39.1/drivers/staging/msm/staging-devices.c linux-2.6.39.1/drivers/staging/msm/staging-devices.c
39741--- linux-2.6.39.1/drivers/staging/msm/staging-devices.c 2011-05-19 00:06:34.000000000 -0400
39742+++ linux-2.6.39.1/drivers/staging/msm/staging-devices.c 2011-05-22 19:36:32.000000000 -0400
39743@@ -211,7 +211,7 @@ static int msm_fb_lcdc_gpio_config(int o
39744 }
39745
39746
39747-static struct lcdc_platform_data lcdc_pdata = {
39748+static const struct lcdc_platform_data lcdc_pdata = {
39749 .lcdc_gpio_config = msm_fb_lcdc_gpio_config,
39750 };
39751
39752diff -urNp linux-2.6.39.1/drivers/staging/octeon/ethernet.c linux-2.6.39.1/drivers/staging/octeon/ethernet.c
39753--- linux-2.6.39.1/drivers/staging/octeon/ethernet.c 2011-05-19 00:06:34.000000000 -0400
39754+++ linux-2.6.39.1/drivers/staging/octeon/ethernet.c 2011-05-22 19:36:32.000000000 -0400
39755@@ -258,11 +258,11 @@ static struct net_device_stats *cvm_oct_
39756 * since the RX tasklet also increments it.
39757 */
39758 #ifdef CONFIG_64BIT
39759- atomic64_add(rx_status.dropped_packets,
39760- (atomic64_t *)&priv->stats.rx_dropped);
39761+ atomic64_add_unchecked(rx_status.dropped_packets,
39762+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
39763 #else
39764- atomic_add(rx_status.dropped_packets,
39765- (atomic_t *)&priv->stats.rx_dropped);
39766+ atomic_add_unchecked(rx_status.dropped_packets,
39767+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
39768 #endif
39769 }
39770
39771diff -urNp linux-2.6.39.1/drivers/staging/octeon/ethernet-rx.c linux-2.6.39.1/drivers/staging/octeon/ethernet-rx.c
39772--- linux-2.6.39.1/drivers/staging/octeon/ethernet-rx.c 2011-05-19 00:06:34.000000000 -0400
39773+++ linux-2.6.39.1/drivers/staging/octeon/ethernet-rx.c 2011-05-22 19:36:32.000000000 -0400
39774@@ -417,11 +417,11 @@ static int cvm_oct_napi_poll(struct napi
39775 /* Increment RX stats for virtual ports */
39776 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
39777 #ifdef CONFIG_64BIT
39778- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
39779- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
39780+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
39781+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
39782 #else
39783- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
39784- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
39785+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
39786+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
39787 #endif
39788 }
39789 netif_receive_skb(skb);
39790@@ -433,9 +433,9 @@ static int cvm_oct_napi_poll(struct napi
39791 dev->name);
39792 */
39793 #ifdef CONFIG_64BIT
39794- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
39795+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
39796 #else
39797- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
39798+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
39799 #endif
39800 dev_kfree_skb_irq(skb);
39801 }
39802diff -urNp linux-2.6.39.1/drivers/staging/olpc_dcon/olpc_dcon.c linux-2.6.39.1/drivers/staging/olpc_dcon/olpc_dcon.c
39803--- linux-2.6.39.1/drivers/staging/olpc_dcon/olpc_dcon.c 2011-05-19 00:06:34.000000000 -0400
39804+++ linux-2.6.39.1/drivers/staging/olpc_dcon/olpc_dcon.c 2011-05-22 19:36:32.000000000 -0400
39805@@ -43,7 +43,7 @@ module_param(noinit, int, 0444);
39806 static int useaa = 1;
39807 module_param(useaa, int, 0444);
39808
39809-static struct dcon_platform_data *pdata;
39810+static const struct dcon_platform_data *pdata;
39811
39812 /* I2C structures */
39813
39814diff -urNp linux-2.6.39.1/drivers/staging/olpc_dcon/olpc_dcon.h linux-2.6.39.1/drivers/staging/olpc_dcon/olpc_dcon.h
39815--- linux-2.6.39.1/drivers/staging/olpc_dcon/olpc_dcon.h 2011-05-19 00:06:34.000000000 -0400
39816+++ linux-2.6.39.1/drivers/staging/olpc_dcon/olpc_dcon.h 2011-05-22 19:36:32.000000000 -0400
39817@@ -92,11 +92,11 @@ struct dcon_platform_data {
39818 extern irqreturn_t dcon_interrupt(int irq, void *id);
39819
39820 #ifdef CONFIG_FB_OLPC_DCON_1
39821-extern struct dcon_platform_data dcon_pdata_xo_1;
39822+extern const struct dcon_platform_data dcon_pdata_xo_1;
39823 #endif
39824
39825 #ifdef CONFIG_FB_OLPC_DCON_1_5
39826-extern struct dcon_platform_data dcon_pdata_xo_1_5;
39827+extern const struct dcon_platform_data dcon_pdata_xo_1_5;
39828 #endif
39829
39830 #endif
39831diff -urNp linux-2.6.39.1/drivers/staging/olpc_dcon/olpc_dcon_xo_1_5.c linux-2.6.39.1/drivers/staging/olpc_dcon/olpc_dcon_xo_1_5.c
39832--- linux-2.6.39.1/drivers/staging/olpc_dcon/olpc_dcon_xo_1_5.c 2011-05-19 00:06:34.000000000 -0400
39833+++ linux-2.6.39.1/drivers/staging/olpc_dcon/olpc_dcon_xo_1_5.c 2011-05-22 19:36:32.000000000 -0400
39834@@ -185,7 +185,7 @@ static u8 dcon_read_status_xo_1_5(void)
39835 return status;
39836 }
39837
39838-struct dcon_platform_data dcon_pdata_xo_1_5 = {
39839+const struct dcon_platform_data dcon_pdata_xo_1_5 = {
39840 .init = dcon_init_xo_1_5,
39841 .bus_stabilize_wiggle = dcon_wiggle_xo_1_5,
39842 .set_dconload = dcon_set_dconload_xo_1_5,
39843diff -urNp linux-2.6.39.1/drivers/staging/olpc_dcon/olpc_dcon_xo_1.c linux-2.6.39.1/drivers/staging/olpc_dcon/olpc_dcon_xo_1.c
39844--- linux-2.6.39.1/drivers/staging/olpc_dcon/olpc_dcon_xo_1.c 2011-05-19 00:06:34.000000000 -0400
39845+++ linux-2.6.39.1/drivers/staging/olpc_dcon/olpc_dcon_xo_1.c 2011-05-22 19:36:32.000000000 -0400
39846@@ -196,7 +196,7 @@ static u8 dcon_read_status_xo_1(void)
39847 return status;
39848 }
39849
39850-struct dcon_platform_data dcon_pdata_xo_1 = {
39851+const struct dcon_platform_data dcon_pdata_xo_1 = {
39852 .init = dcon_init_xo_1,
39853 .bus_stabilize_wiggle = dcon_wiggle_xo_1,
39854 .set_dconload = dcon_set_dconload_1,
39855diff -urNp linux-2.6.39.1/drivers/staging/phison/phison.c linux-2.6.39.1/drivers/staging/phison/phison.c
39856--- linux-2.6.39.1/drivers/staging/phison/phison.c 2011-05-19 00:06:34.000000000 -0400
39857+++ linux-2.6.39.1/drivers/staging/phison/phison.c 2011-05-22 19:36:32.000000000 -0400
39858@@ -43,7 +43,7 @@ static struct scsi_host_template phison_
39859 ATA_BMDMA_SHT(DRV_NAME),
39860 };
39861
39862-static struct ata_port_operations phison_ops = {
39863+static const struct ata_port_operations phison_ops = {
39864 .inherits = &ata_bmdma_port_ops,
39865 .prereset = phison_pre_reset,
39866 };
39867diff -urNp linux-2.6.39.1/drivers/staging/pohmelfs/inode.c linux-2.6.39.1/drivers/staging/pohmelfs/inode.c
39868--- linux-2.6.39.1/drivers/staging/pohmelfs/inode.c 2011-05-19 00:06:34.000000000 -0400
39869+++ linux-2.6.39.1/drivers/staging/pohmelfs/inode.c 2011-05-22 19:36:32.000000000 -0400
39870@@ -1855,7 +1855,7 @@ static int pohmelfs_fill_super(struct su
39871 mutex_init(&psb->mcache_lock);
39872 psb->mcache_root = RB_ROOT;
39873 psb->mcache_timeout = msecs_to_jiffies(5000);
39874- atomic_long_set(&psb->mcache_gen, 0);
39875+ atomic_long_set_unchecked(&psb->mcache_gen, 0);
39876
39877 psb->trans_max_pages = 100;
39878
39879@@ -1870,7 +1870,7 @@ static int pohmelfs_fill_super(struct su
39880 INIT_LIST_HEAD(&psb->crypto_ready_list);
39881 INIT_LIST_HEAD(&psb->crypto_active_list);
39882
39883- atomic_set(&psb->trans_gen, 1);
39884+ atomic_set_unchecked(&psb->trans_gen, 1);
39885 atomic_long_set(&psb->total_inodes, 0);
39886
39887 mutex_init(&psb->state_lock);
39888diff -urNp linux-2.6.39.1/drivers/staging/pohmelfs/mcache.c linux-2.6.39.1/drivers/staging/pohmelfs/mcache.c
39889--- linux-2.6.39.1/drivers/staging/pohmelfs/mcache.c 2011-05-19 00:06:34.000000000 -0400
39890+++ linux-2.6.39.1/drivers/staging/pohmelfs/mcache.c 2011-05-22 19:36:32.000000000 -0400
39891@@ -121,7 +121,7 @@ struct pohmelfs_mcache *pohmelfs_mcache_
39892 m->data = data;
39893 m->start = start;
39894 m->size = size;
39895- m->gen = atomic_long_inc_return(&psb->mcache_gen);
39896+ m->gen = atomic_long_inc_return_unchecked(&psb->mcache_gen);
39897
39898 mutex_lock(&psb->mcache_lock);
39899 err = pohmelfs_mcache_insert(psb, m);
39900diff -urNp linux-2.6.39.1/drivers/staging/pohmelfs/netfs.h linux-2.6.39.1/drivers/staging/pohmelfs/netfs.h
39901--- linux-2.6.39.1/drivers/staging/pohmelfs/netfs.h 2011-05-19 00:06:34.000000000 -0400
39902+++ linux-2.6.39.1/drivers/staging/pohmelfs/netfs.h 2011-05-22 19:36:32.000000000 -0400
39903@@ -571,14 +571,14 @@ struct pohmelfs_config;
39904 struct pohmelfs_sb {
39905 struct rb_root mcache_root;
39906 struct mutex mcache_lock;
39907- atomic_long_t mcache_gen;
39908+ atomic_long_unchecked_t mcache_gen;
39909 unsigned long mcache_timeout;
39910
39911 unsigned int idx;
39912
39913 unsigned int trans_retries;
39914
39915- atomic_t trans_gen;
39916+ atomic_unchecked_t trans_gen;
39917
39918 unsigned int crypto_attached_size;
39919 unsigned int crypto_align_size;
39920diff -urNp linux-2.6.39.1/drivers/staging/pohmelfs/trans.c linux-2.6.39.1/drivers/staging/pohmelfs/trans.c
39921--- linux-2.6.39.1/drivers/staging/pohmelfs/trans.c 2011-05-19 00:06:34.000000000 -0400
39922+++ linux-2.6.39.1/drivers/staging/pohmelfs/trans.c 2011-05-22 19:36:32.000000000 -0400
39923@@ -492,7 +492,7 @@ int netfs_trans_finish(struct netfs_tran
39924 int err;
39925 struct netfs_cmd *cmd = t->iovec.iov_base;
39926
39927- t->gen = atomic_inc_return(&psb->trans_gen);
39928+ t->gen = atomic_inc_return_unchecked(&psb->trans_gen);
39929
39930 cmd->size = t->iovec.iov_len - sizeof(struct netfs_cmd) +
39931 t->attached_size + t->attached_pages * sizeof(struct netfs_cmd);
39932diff -urNp linux-2.6.39.1/drivers/staging/rtl8192u/ieee80211/proc.c linux-2.6.39.1/drivers/staging/rtl8192u/ieee80211/proc.c
39933--- linux-2.6.39.1/drivers/staging/rtl8192u/ieee80211/proc.c 2011-05-19 00:06:34.000000000 -0400
39934+++ linux-2.6.39.1/drivers/staging/rtl8192u/ieee80211/proc.c 2011-05-22 19:36:32.000000000 -0400
39935@@ -87,7 +87,7 @@ static int c_show(struct seq_file *m, vo
39936 return 0;
39937 }
39938
39939-static struct seq_operations crypto_seq_ops = {
39940+static const struct seq_operations crypto_seq_ops = {
39941 .start = c_start,
39942 .next = c_next,
39943 .stop = c_stop,
39944@@ -99,7 +99,7 @@ static int crypto_info_open(struct inode
39945 return seq_open(file, &crypto_seq_ops);
39946 }
39947
39948-static struct file_operations proc_crypto_ops = {
39949+static const struct file_operations proc_crypto_ops = {
39950 .open = crypto_info_open,
39951 .read = seq_read,
39952 .llseek = seq_lseek,
39953diff -urNp linux-2.6.39.1/drivers/staging/rtl8712/rtl871x_io.h linux-2.6.39.1/drivers/staging/rtl8712/rtl871x_io.h
39954--- linux-2.6.39.1/drivers/staging/rtl8712/rtl871x_io.h 2011-05-19 00:06:34.000000000 -0400
39955+++ linux-2.6.39.1/drivers/staging/rtl8712/rtl871x_io.h 2011-05-22 19:36:32.000000000 -0400
39956@@ -107,7 +107,7 @@ struct intf_hdl {
39957 void (*intf_hdl_unload)(u8 *priv);
39958 void (*intf_hdl_open)(u8 *priv);
39959 void (*intf_hdl_close)(u8 *priv);
39960- struct _io_ops io_ops;
39961+ const struct _io_ops io_ops;
39962 };
39963
39964 struct reg_protocol_rd {
39965diff -urNp linux-2.6.39.1/drivers/staging/solo6x10/g723.c linux-2.6.39.1/drivers/staging/solo6x10/g723.c
39966--- linux-2.6.39.1/drivers/staging/solo6x10/g723.c 2011-05-19 00:06:34.000000000 -0400
39967+++ linux-2.6.39.1/drivers/staging/solo6x10/g723.c 2011-05-22 19:36:32.000000000 -0400
39968@@ -237,7 +237,7 @@ static int snd_solo_pcm_copy(struct snd_
39969 return 0;
39970 }
39971
39972-static struct snd_pcm_ops snd_solo_pcm_ops = {
39973+static const struct snd_pcm_ops snd_solo_pcm_ops = {
39974 .open = snd_solo_pcm_open,
39975 .close = snd_solo_pcm_close,
39976 .ioctl = snd_pcm_lib_ioctl,
39977@@ -334,7 +334,7 @@ static int solo_snd_pcm_init(struct solo
39978
39979 int solo_g723_init(struct solo_dev *solo_dev)
39980 {
39981- static struct snd_device_ops ops = { NULL };
39982+ static const struct snd_device_ops ops = { NULL };
39983 struct snd_card *card;
39984 struct snd_kcontrol_new kctl;
39985 char name[32];
39986diff -urNp linux-2.6.39.1/drivers/staging/spectra/ffsport.c linux-2.6.39.1/drivers/staging/spectra/ffsport.c
39987--- linux-2.6.39.1/drivers/staging/spectra/ffsport.c 2011-05-19 00:06:34.000000000 -0400
39988+++ linux-2.6.39.1/drivers/staging/spectra/ffsport.c 2011-05-22 19:36:32.000000000 -0400
39989@@ -604,7 +604,7 @@ int GLOB_SBD_unlocked_ioctl(struct block
39990 return ret;
39991 }
39992
39993-static struct block_device_operations GLOB_SBD_ops = {
39994+static const struct block_device_operations GLOB_SBD_ops = {
39995 .owner = THIS_MODULE,
39996 .open = GLOB_SBD_open,
39997 .release = GLOB_SBD_release,
39998diff -urNp linux-2.6.39.1/drivers/staging/tm6000/tm6000-alsa.c linux-2.6.39.1/drivers/staging/tm6000/tm6000-alsa.c
39999--- linux-2.6.39.1/drivers/staging/tm6000/tm6000-alsa.c 2011-05-19 00:06:34.000000000 -0400
40000+++ linux-2.6.39.1/drivers/staging/tm6000/tm6000-alsa.c 2011-05-22 19:36:32.000000000 -0400
40001@@ -380,7 +380,7 @@ static snd_pcm_uframes_t snd_tm6000_poin
40002 /*
40003 * operators
40004 */
40005-static struct snd_pcm_ops snd_tm6000_pcm_ops = {
40006+static const struct snd_pcm_ops snd_tm6000_pcm_ops = {
40007 .open = snd_tm6000_pcm_open,
40008 .close = snd_tm6000_close,
40009 .ioctl = snd_pcm_lib_ioctl,
40010diff -urNp linux-2.6.39.1/drivers/staging/tty/istallion.c linux-2.6.39.1/drivers/staging/tty/istallion.c
40011--- linux-2.6.39.1/drivers/staging/tty/istallion.c 2011-05-19 00:06:34.000000000 -0400
40012+++ linux-2.6.39.1/drivers/staging/tty/istallion.c 2011-05-22 20:49:07.000000000 -0400
40013@@ -186,7 +186,6 @@ static struct ktermios stli_deftermios
40014 * re-used for each stats call.
40015 */
40016 static comstats_t stli_comstats;
40017-static combrd_t stli_brdstats;
40018 static struct asystats stli_cdkstats;
40019
40020 /*****************************************************************************/
40021@@ -4003,6 +4002,7 @@ out:
40022
40023 static int stli_getbrdstats(combrd_t __user *bp)
40024 {
40025+ combrd_t stli_brdstats;
40026 struct stlibrd *brdp;
40027 unsigned int i;
40028
40029@@ -4226,6 +4226,8 @@ static int stli_getportstruct(struct stl
40030 struct stliport stli_dummyport;
40031 struct stliport *portp;
40032
40033+ pax_track_stack();
40034+
40035 if (copy_from_user(&stli_dummyport, arg, sizeof(struct stliport)))
40036 return -EFAULT;
40037 portp = stli_getport(stli_dummyport.brdnr, stli_dummyport.panelnr,
40038@@ -4248,6 +4250,8 @@ static int stli_getbrdstruct(struct stli
40039 struct stlibrd stli_dummybrd;
40040 struct stlibrd *brdp;
40041
40042+ pax_track_stack();
40043+
40044 if (copy_from_user(&stli_dummybrd, arg, sizeof(struct stlibrd)))
40045 return -EFAULT;
40046 if (stli_dummybrd.brdnr >= STL_MAXBRDS)
40047diff -urNp linux-2.6.39.1/drivers/staging/tty/stallion.c linux-2.6.39.1/drivers/staging/tty/stallion.c
40048--- linux-2.6.39.1/drivers/staging/tty/stallion.c 2011-05-19 00:06:34.000000000 -0400
40049+++ linux-2.6.39.1/drivers/staging/tty/stallion.c 2011-05-22 19:36:32.000000000 -0400
40050@@ -2406,6 +2406,8 @@ static int stl_getportstruct(struct stlp
40051 struct stlport stl_dummyport;
40052 struct stlport *portp;
40053
40054+ pax_track_stack();
40055+
40056 if (copy_from_user(&stl_dummyport, arg, sizeof(struct stlport)))
40057 return -EFAULT;
40058 portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr,
40059diff -urNp linux-2.6.39.1/drivers/staging/usbip/vhci.h linux-2.6.39.1/drivers/staging/usbip/vhci.h
40060--- linux-2.6.39.1/drivers/staging/usbip/vhci.h 2011-05-19 00:06:34.000000000 -0400
40061+++ linux-2.6.39.1/drivers/staging/usbip/vhci.h 2011-05-22 19:36:32.000000000 -0400
40062@@ -92,7 +92,7 @@ struct vhci_hcd {
40063 unsigned resuming:1;
40064 unsigned long re_timeout;
40065
40066- atomic_t seqnum;
40067+ atomic_unchecked_t seqnum;
40068
40069 /*
40070 * NOTE:
40071diff -urNp linux-2.6.39.1/drivers/staging/usbip/vhci_hcd.c linux-2.6.39.1/drivers/staging/usbip/vhci_hcd.c
40072--- linux-2.6.39.1/drivers/staging/usbip/vhci_hcd.c 2011-05-19 00:06:34.000000000 -0400
40073+++ linux-2.6.39.1/drivers/staging/usbip/vhci_hcd.c 2011-05-22 19:36:32.000000000 -0400
40074@@ -536,7 +536,7 @@ static void vhci_tx_urb(struct urb *urb)
40075 return;
40076 }
40077
40078- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
40079+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
40080 if (priv->seqnum == 0xffff)
40081 usbip_uinfo("seqnum max\n");
40082
40083@@ -795,7 +795,7 @@ static int vhci_urb_dequeue(struct usb_h
40084 return -ENOMEM;
40085 }
40086
40087- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
40088+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
40089 if (unlink->seqnum == 0xffff)
40090 usbip_uinfo("seqnum max\n");
40091
40092@@ -992,7 +992,7 @@ static int vhci_start(struct usb_hcd *hc
40093 vdev->rhport = rhport;
40094 }
40095
40096- atomic_set(&vhci->seqnum, 0);
40097+ atomic_set_unchecked(&vhci->seqnum, 0);
40098 spin_lock_init(&vhci->lock);
40099
40100
40101diff -urNp linux-2.6.39.1/drivers/staging/usbip/vhci_rx.c linux-2.6.39.1/drivers/staging/usbip/vhci_rx.c
40102--- linux-2.6.39.1/drivers/staging/usbip/vhci_rx.c 2011-05-19 00:06:34.000000000 -0400
40103+++ linux-2.6.39.1/drivers/staging/usbip/vhci_rx.c 2011-05-22 19:36:32.000000000 -0400
40104@@ -81,7 +81,7 @@ static void vhci_recv_ret_submit(struct
40105 usbip_uerr("cannot find a urb of seqnum %u\n",
40106 pdu->base.seqnum);
40107 usbip_uinfo("max seqnum %d\n",
40108- atomic_read(&the_controller->seqnum));
40109+ atomic_read_unchecked(&the_controller->seqnum));
40110 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
40111 return;
40112 }
40113diff -urNp linux-2.6.39.1/drivers/staging/vme/devices/vme_user.c linux-2.6.39.1/drivers/staging/vme/devices/vme_user.c
40114--- linux-2.6.39.1/drivers/staging/vme/devices/vme_user.c 2011-05-19 00:06:34.000000000 -0400
40115+++ linux-2.6.39.1/drivers/staging/vme/devices/vme_user.c 2011-05-22 19:36:32.000000000 -0400
40116@@ -138,7 +138,7 @@ static long vme_user_unlocked_ioctl(stru
40117 static int __devinit vme_user_probe(struct device *, int, int);
40118 static int __devexit vme_user_remove(struct device *, int, int);
40119
40120-static struct file_operations vme_user_fops = {
40121+static const struct file_operations vme_user_fops = {
40122 .open = vme_user_open,
40123 .release = vme_user_release,
40124 .read = vme_user_read,
40125diff -urNp linux-2.6.39.1/drivers/staging/westbridge/astoria/block/cyasblkdev_block.c linux-2.6.39.1/drivers/staging/westbridge/astoria/block/cyasblkdev_block.c
40126--- linux-2.6.39.1/drivers/staging/westbridge/astoria/block/cyasblkdev_block.c 2011-05-19 00:06:34.000000000 -0400
40127+++ linux-2.6.39.1/drivers/staging/westbridge/astoria/block/cyasblkdev_block.c 2011-05-22 19:36:32.000000000 -0400
40128@@ -426,7 +426,7 @@ int cyasblkdev_revalidate_disk(struct ge
40129
40130
40131 /*standard block device driver interface */
40132-static struct block_device_operations cyasblkdev_bdops = {
40133+static const struct block_device_operations cyasblkdev_bdops = {
40134 .open = cyasblkdev_blk_open,
40135 .release = cyasblkdev_blk_release,
40136 .ioctl = cyasblkdev_blk_ioctl,
40137diff -urNp linux-2.6.39.1/drivers/staging/wlags49_h2/wl_netdev.c linux-2.6.39.1/drivers/staging/wlags49_h2/wl_netdev.c
40138--- linux-2.6.39.1/drivers/staging/wlags49_h2/wl_netdev.c 2011-05-19 00:06:34.000000000 -0400
40139+++ linux-2.6.39.1/drivers/staging/wlags49_h2/wl_netdev.c 2011-05-22 19:36:32.000000000 -0400
40140@@ -474,7 +474,7 @@ static void wl_get_drvinfo(struct net_de
40141 }
40142 } // wl_get_drvinfo
40143
40144-static struct ethtool_ops wl_ethtool_ops = {
40145+static const struct ethtool_ops wl_ethtool_ops = {
40146 .get_drvinfo = wl_get_drvinfo,
40147 .get_link = ethtool_op_get_link,
40148 };
40149diff -urNp linux-2.6.39.1/drivers/staging/wlan-ng/hfa384x_usb.c linux-2.6.39.1/drivers/staging/wlan-ng/hfa384x_usb.c
40150--- linux-2.6.39.1/drivers/staging/wlan-ng/hfa384x_usb.c 2011-05-19 00:06:34.000000000 -0400
40151+++ linux-2.6.39.1/drivers/staging/wlan-ng/hfa384x_usb.c 2011-05-22 19:36:32.000000000 -0400
40152@@ -671,7 +671,7 @@ struct usbctlx_cmd_completor {
40153 hfa384x_cmdresult_t *result;
40154 };
40155
40156-static inline int usbctlx_cmd_completor_fn(struct usbctlx_completor *head)
40157+static inline int usbctlx_cmd_completor_fn(const struct usbctlx_completor *head)
40158 {
40159 struct usbctlx_cmd_completor *complete;
40160
40161@@ -705,7 +705,7 @@ struct usbctlx_rrid_completor {
40162 unsigned int riddatalen;
40163 };
40164
40165-static int usbctlx_rrid_completor_fn(struct usbctlx_completor *head)
40166+static int usbctlx_rrid_completor_fn(const struct usbctlx_completor *head)
40167 {
40168 struct usbctlx_rrid_completor *complete;
40169 hfa384x_rridresult_t rridresult;
40170@@ -768,7 +768,7 @@ struct usbctlx_rmem_completor {
40171 };
40172 typedef struct usbctlx_rmem_completor usbctlx_rmem_completor_t;
40173
40174-static int usbctlx_rmem_completor_fn(struct usbctlx_completor *head)
40175+static int usbctlx_rmem_completor_fn(const struct usbctlx_completor *head)
40176 {
40177 usbctlx_rmem_completor_t *complete = (usbctlx_rmem_completor_t *) head;
40178
40179diff -urNp linux-2.6.39.1/drivers/staging/zcache/tmem.c linux-2.6.39.1/drivers/staging/zcache/tmem.c
40180--- linux-2.6.39.1/drivers/staging/zcache/tmem.c 2011-05-19 00:06:34.000000000 -0400
40181+++ linux-2.6.39.1/drivers/staging/zcache/tmem.c 2011-05-22 19:36:32.000000000 -0400
40182@@ -39,7 +39,7 @@
40183 * A tmem host implementation must use this function to register callbacks
40184 * for memory allocation.
40185 */
40186-static struct tmem_hostops tmem_hostops;
40187+static const struct tmem_hostops tmem_hostops;
40188
40189 static void tmem_objnode_tree_init(void);
40190
40191@@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_h
40192 * A tmem host implementation must use this function to register
40193 * callbacks for a page-accessible memory (PAM) implementation
40194 */
40195-static struct tmem_pamops tmem_pamops;
40196+static const struct tmem_pamops tmem_pamops;
40197
40198 void tmem_register_pamops(struct tmem_pamops *m)
40199 {
40200diff -urNp linux-2.6.39.1/drivers/staging/zcache/zcache.c linux-2.6.39.1/drivers/staging/zcache/zcache.c
40201--- linux-2.6.39.1/drivers/staging/zcache/zcache.c 2011-05-19 00:06:34.000000000 -0400
40202+++ linux-2.6.39.1/drivers/staging/zcache/zcache.c 2011-05-22 19:36:32.000000000 -0400
40203@@ -882,7 +882,7 @@ static void zcache_obj_free(struct tmem_
40204 kmem_cache_free(zcache_obj_cache, obj);
40205 }
40206
40207-static struct tmem_hostops zcache_hostops = {
40208+static const struct tmem_hostops zcache_hostops = {
40209 .obj_alloc = zcache_obj_alloc,
40210 .obj_free = zcache_obj_free,
40211 .objnode_alloc = zcache_objnode_alloc,
40212@@ -987,7 +987,7 @@ static void zcache_pampd_free(void *pamp
40213 }
40214 }
40215
40216-static struct tmem_pamops zcache_pamops = {
40217+static const struct tmem_pamops zcache_pamops = {
40218 .create = zcache_pampd_create,
40219 .get_data = zcache_pampd_get_data,
40220 .free = zcache_pampd_free,
40221diff -urNp linux-2.6.39.1/drivers/target/target_core_alua.c linux-2.6.39.1/drivers/target/target_core_alua.c
40222--- linux-2.6.39.1/drivers/target/target_core_alua.c 2011-05-19 00:06:34.000000000 -0400
40223+++ linux-2.6.39.1/drivers/target/target_core_alua.c 2011-05-22 19:36:32.000000000 -0400
40224@@ -675,6 +675,8 @@ static int core_alua_update_tpg_primary_
40225 char path[ALUA_METADATA_PATH_LEN];
40226 int len;
40227
40228+ pax_track_stack();
40229+
40230 memset(path, 0, ALUA_METADATA_PATH_LEN);
40231
40232 len = snprintf(md_buf, tg_pt_gp->tg_pt_gp_md_buf_len,
40233@@ -938,6 +940,8 @@ static int core_alua_update_tpg_secondar
40234 char path[ALUA_METADATA_PATH_LEN], wwn[ALUA_SECONDARY_METADATA_WWN_LEN];
40235 int len;
40236
40237+ pax_track_stack();
40238+
40239 memset(path, 0, ALUA_METADATA_PATH_LEN);
40240 memset(wwn, 0, ALUA_SECONDARY_METADATA_WWN_LEN);
40241
40242diff -urNp linux-2.6.39.1/drivers/target/target_core_cdb.c linux-2.6.39.1/drivers/target/target_core_cdb.c
40243--- linux-2.6.39.1/drivers/target/target_core_cdb.c 2011-05-19 00:06:34.000000000 -0400
40244+++ linux-2.6.39.1/drivers/target/target_core_cdb.c 2011-05-22 19:36:32.000000000 -0400
40245@@ -838,6 +838,8 @@ target_emulate_modesense(struct se_cmd *
40246 int length = 0;
40247 unsigned char buf[SE_MODE_PAGE_BUF];
40248
40249+ pax_track_stack();
40250+
40251 memset(buf, 0, SE_MODE_PAGE_BUF);
40252
40253 switch (cdb[2] & 0x3f) {
40254diff -urNp linux-2.6.39.1/drivers/target/target_core_configfs.c linux-2.6.39.1/drivers/target/target_core_configfs.c
40255--- linux-2.6.39.1/drivers/target/target_core_configfs.c 2011-05-19 00:06:34.000000000 -0400
40256+++ linux-2.6.39.1/drivers/target/target_core_configfs.c 2011-05-22 19:36:32.000000000 -0400
40257@@ -1280,6 +1280,8 @@ static ssize_t target_core_dev_pr_show_a
40258 ssize_t len = 0;
40259 int reg_count = 0, prf_isid;
40260
40261+ pax_track_stack();
40262+
40263 if (!(su_dev->se_dev_ptr))
40264 return -ENODEV;
40265
40266@@ -2682,7 +2684,7 @@ static void target_core_alua_drop_tg_pt_
40267 config_item_put(item);
40268 }
40269
40270-static struct configfs_group_operations target_core_alua_tg_pt_gps_group_ops = {
40271+static const struct configfs_group_operations target_core_alua_tg_pt_gps_group_ops = {
40272 .make_group = &target_core_alua_create_tg_pt_gp,
40273 .drop_item = &target_core_alua_drop_tg_pt_gp,
40274 };
40275@@ -2726,7 +2728,7 @@ static void target_core_stat_rmdir(
40276 return;
40277 }
40278
40279-static struct configfs_group_operations target_core_stat_group_ops = {
40280+static const struct configfs_group_operations target_core_stat_group_ops = {
40281 .make_group = &target_core_stat_mkdir,
40282 .drop_item = &target_core_stat_rmdir,
40283 };
40284@@ -2939,7 +2941,7 @@ static void target_core_drop_subdev(
40285 mutex_unlock(&hba->hba_access_mutex);
40286 }
40287
40288-static struct configfs_group_operations target_core_hba_group_ops = {
40289+static const struct configfs_group_operations target_core_hba_group_ops = {
40290 .make_group = target_core_make_subdev,
40291 .drop_item = target_core_drop_subdev,
40292 };
40293@@ -3117,7 +3119,7 @@ static void target_core_call_delhbafromt
40294 config_item_put(item);
40295 }
40296
40297-static struct configfs_group_operations target_core_group_ops = {
40298+static const struct configfs_group_operations target_core_group_ops = {
40299 .make_group = target_core_call_addhbatotarget,
40300 .drop_item = target_core_call_delhbafromtarget,
40301 };
40302diff -urNp linux-2.6.39.1/drivers/target/target_core_fabric_configfs.c linux-2.6.39.1/drivers/target/target_core_fabric_configfs.c
40303--- linux-2.6.39.1/drivers/target/target_core_fabric_configfs.c 2011-05-19 00:06:34.000000000 -0400
40304+++ linux-2.6.39.1/drivers/target/target_core_fabric_configfs.c 2011-05-22 19:36:32.000000000 -0400
40305@@ -1174,7 +1174,7 @@ static void target_fabric_drop_wwn(
40306 config_item_put(item);
40307 }
40308
40309-static struct configfs_group_operations target_fabric_wwn_group_ops = {
40310+static const struct configfs_group_operations target_fabric_wwn_group_ops = {
40311 .make_group = target_fabric_make_wwn,
40312 .drop_item = target_fabric_drop_wwn,
40313 };
40314diff -urNp linux-2.6.39.1/drivers/target/target_core_pr.c linux-2.6.39.1/drivers/target/target_core_pr.c
40315--- linux-2.6.39.1/drivers/target/target_core_pr.c 2011-05-19 00:06:34.000000000 -0400
40316+++ linux-2.6.39.1/drivers/target/target_core_pr.c 2011-05-22 19:36:32.000000000 -0400
40317@@ -918,6 +918,8 @@ static int __core_scsi3_check_aptpl_regi
40318 unsigned char t_port[PR_APTPL_MAX_TPORT_LEN];
40319 u16 tpgt;
40320
40321+ pax_track_stack();
40322+
40323 memset(i_port, 0, PR_APTPL_MAX_IPORT_LEN);
40324 memset(t_port, 0, PR_APTPL_MAX_TPORT_LEN);
40325 /*
40326@@ -1861,6 +1863,8 @@ static int __core_scsi3_update_aptpl_buf
40327 ssize_t len = 0;
40328 int reg_count = 0;
40329
40330+ pax_track_stack();
40331+
40332 memset(buf, 0, pr_aptpl_buf_len);
40333 /*
40334 * Called to clear metadata once APTPL has been deactivated.
40335@@ -1983,6 +1987,8 @@ static int __core_scsi3_write_aptpl_to_f
40336 char path[512];
40337 int ret;
40338
40339+ pax_track_stack();
40340+
40341 memset(iov, 0, sizeof(struct iovec));
40342 memset(path, 0, 512);
40343
40344diff -urNp linux-2.6.39.1/drivers/target/target_core_tmr.c linux-2.6.39.1/drivers/target/target_core_tmr.c
40345--- linux-2.6.39.1/drivers/target/target_core_tmr.c 2011-06-03 00:04:14.000000000 -0400
40346+++ linux-2.6.39.1/drivers/target/target_core_tmr.c 2011-06-03 00:32:07.000000000 -0400
40347@@ -263,7 +263,7 @@ int core_tmr_lun_reset(
40348 CMD_TFO(cmd)->get_task_tag(cmd), cmd->pr_res_key,
40349 T_TASK(cmd)->t_task_cdbs,
40350 atomic_read(&T_TASK(cmd)->t_task_cdbs_left),
40351- atomic_read(&T_TASK(cmd)->t_task_cdbs_sent),
40352+ atomic_read_unchecked(&T_TASK(cmd)->t_task_cdbs_sent),
40353 atomic_read(&T_TASK(cmd)->t_transport_active),
40354 atomic_read(&T_TASK(cmd)->t_transport_stop),
40355 atomic_read(&T_TASK(cmd)->t_transport_sent));
40356@@ -305,7 +305,7 @@ int core_tmr_lun_reset(
40357 DEBUG_LR("LUN_RESET: got t_transport_active = 1 for"
40358 " task: %p, t_fe_count: %d dev: %p\n", task,
40359 fe_count, dev);
40360- atomic_set(&T_TASK(cmd)->t_transport_aborted, 1);
40361+ atomic_set_unchecked(&T_TASK(cmd)->t_transport_aborted, 1);
40362 spin_unlock_irqrestore(&T_TASK(cmd)->t_state_lock,
40363 flags);
40364 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
40365@@ -315,7 +315,7 @@ int core_tmr_lun_reset(
40366 }
40367 DEBUG_LR("LUN_RESET: Got t_transport_active = 0 for task: %p,"
40368 " t_fe_count: %d dev: %p\n", task, fe_count, dev);
40369- atomic_set(&T_TASK(cmd)->t_transport_aborted, 1);
40370+ atomic_set_unchecked(&T_TASK(cmd)->t_transport_aborted, 1);
40371 spin_unlock_irqrestore(&T_TASK(cmd)->t_state_lock, flags);
40372 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
40373
40374diff -urNp linux-2.6.39.1/drivers/target/target_core_transport.c linux-2.6.39.1/drivers/target/target_core_transport.c
40375--- linux-2.6.39.1/drivers/target/target_core_transport.c 2011-06-03 00:04:14.000000000 -0400
40376+++ linux-2.6.39.1/drivers/target/target_core_transport.c 2011-06-03 00:32:07.000000000 -0400
40377@@ -1681,7 +1681,7 @@ struct se_device *transport_add_device_t
40378
40379 dev->queue_depth = dev_limits->queue_depth;
40380 atomic_set(&dev->depth_left, dev->queue_depth);
40381- atomic_set(&dev->dev_ordered_id, 0);
40382+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
40383
40384 se_dev_set_default_attribs(dev, dev_limits);
40385
40386@@ -1882,7 +1882,7 @@ static int transport_check_alloc_task_at
40387 * Used to determine when ORDERED commands should go from
40388 * Dormant to Active status.
40389 */
40390- cmd->se_ordered_id = atomic_inc_return(&SE_DEV(cmd)->dev_ordered_id);
40391+ cmd->se_ordered_id = atomic_inc_return_unchecked(&SE_DEV(cmd)->dev_ordered_id);
40392 smp_mb__after_atomic_inc();
40393 DEBUG_STA("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
40394 cmd->se_ordered_id, cmd->sam_task_attr,
40395@@ -2169,7 +2169,7 @@ static void transport_generic_request_fa
40396 " t_transport_active: %d t_transport_stop: %d"
40397 " t_transport_sent: %d\n", T_TASK(cmd)->t_task_cdbs,
40398 atomic_read(&T_TASK(cmd)->t_task_cdbs_left),
40399- atomic_read(&T_TASK(cmd)->t_task_cdbs_sent),
40400+ atomic_read_unchecked(&T_TASK(cmd)->t_task_cdbs_sent),
40401 atomic_read(&T_TASK(cmd)->t_task_cdbs_ex_left),
40402 atomic_read(&T_TASK(cmd)->t_transport_active),
40403 atomic_read(&T_TASK(cmd)->t_transport_stop),
40404@@ -2673,9 +2673,9 @@ check_depth:
40405 spin_lock_irqsave(&T_TASK(cmd)->t_state_lock, flags);
40406 atomic_set(&task->task_active, 1);
40407 atomic_set(&task->task_sent, 1);
40408- atomic_inc(&T_TASK(cmd)->t_task_cdbs_sent);
40409+ atomic_inc_unchecked(&T_TASK(cmd)->t_task_cdbs_sent);
40410
40411- if (atomic_read(&T_TASK(cmd)->t_task_cdbs_sent) ==
40412+ if (atomic_read_unchecked(&T_TASK(cmd)->t_task_cdbs_sent) ==
40413 T_TASK(cmd)->t_task_cdbs)
40414 atomic_set(&cmd->transport_sent, 1);
40415
40416@@ -5568,7 +5568,7 @@ static void transport_generic_wait_for_t
40417 atomic_set(&T_TASK(cmd)->transport_lun_stop, 0);
40418 }
40419 if (!atomic_read(&T_TASK(cmd)->t_transport_active) ||
40420- atomic_read(&T_TASK(cmd)->t_transport_aborted))
40421+ atomic_read_unchecked(&T_TASK(cmd)->t_transport_aborted))
40422 goto remove;
40423
40424 atomic_set(&T_TASK(cmd)->t_transport_stop, 1);
40425@@ -5797,7 +5797,7 @@ int transport_check_aborted_status(struc
40426 {
40427 int ret = 0;
40428
40429- if (atomic_read(&T_TASK(cmd)->t_transport_aborted) != 0) {
40430+ if (atomic_read_unchecked(&T_TASK(cmd)->t_transport_aborted) != 0) {
40431 if (!(send_status) ||
40432 (cmd->se_cmd_flags & SCF_SENT_DELAYED_TAS))
40433 return 1;
40434@@ -5825,7 +5825,7 @@ void transport_send_task_abort(struct se
40435 */
40436 if (cmd->data_direction == DMA_TO_DEVICE) {
40437 if (CMD_TFO(cmd)->write_pending_status(cmd) != 0) {
40438- atomic_inc(&T_TASK(cmd)->t_transport_aborted);
40439+ atomic_inc_unchecked(&T_TASK(cmd)->t_transport_aborted);
40440 smp_mb__after_atomic_inc();
40441 cmd->scsi_status = SAM_STAT_TASK_ABORTED;
40442 transport_new_cmd_failure(cmd);
40443@@ -5949,7 +5949,7 @@ static void transport_processing_shutdow
40444 CMD_TFO(cmd)->get_task_tag(cmd),
40445 T_TASK(cmd)->t_task_cdbs,
40446 atomic_read(&T_TASK(cmd)->t_task_cdbs_left),
40447- atomic_read(&T_TASK(cmd)->t_task_cdbs_sent),
40448+ atomic_read_unchecked(&T_TASK(cmd)->t_task_cdbs_sent),
40449 atomic_read(&T_TASK(cmd)->t_transport_active),
40450 atomic_read(&T_TASK(cmd)->t_transport_stop),
40451 atomic_read(&T_TASK(cmd)->t_transport_sent));
40452diff -urNp linux-2.6.39.1/drivers/telephony/ixj.c linux-2.6.39.1/drivers/telephony/ixj.c
40453--- linux-2.6.39.1/drivers/telephony/ixj.c 2011-05-19 00:06:34.000000000 -0400
40454+++ linux-2.6.39.1/drivers/telephony/ixj.c 2011-05-22 19:36:32.000000000 -0400
40455@@ -4976,6 +4976,8 @@ static int ixj_daa_cid_read(IXJ *j)
40456 bool mContinue;
40457 char *pIn, *pOut;
40458
40459+ pax_track_stack();
40460+
40461 if (!SCI_Prepare(j))
40462 return 0;
40463
40464diff -urNp linux-2.6.39.1/drivers/tty/hvc/hvc_console.h linux-2.6.39.1/drivers/tty/hvc/hvc_console.h
40465--- linux-2.6.39.1/drivers/tty/hvc/hvc_console.h 2011-05-19 00:06:34.000000000 -0400
40466+++ linux-2.6.39.1/drivers/tty/hvc/hvc_console.h 2011-05-22 19:36:32.000000000 -0400
40467@@ -82,6 +82,7 @@ extern int hvc_instantiate(uint32_t vter
40468 /* register a vterm for hvc tty operation (module_init or hotplug add) */
40469 extern struct hvc_struct * hvc_alloc(uint32_t vtermno, int data,
40470 const struct hv_ops *ops, int outbuf_size);
40471+
40472 /* remove a vterm from hvc tty operation (module_exit or hotplug remove) */
40473 extern int hvc_remove(struct hvc_struct *hp);
40474
40475diff -urNp linux-2.6.39.1/drivers/tty/hvc/hvc_iucv.c linux-2.6.39.1/drivers/tty/hvc/hvc_iucv.c
40476--- linux-2.6.39.1/drivers/tty/hvc/hvc_iucv.c 2011-05-19 00:06:34.000000000 -0400
40477+++ linux-2.6.39.1/drivers/tty/hvc/hvc_iucv.c 2011-05-22 19:36:32.000000000 -0400
40478@@ -1203,7 +1203,7 @@ static int param_get_vmidfilter(char *bu
40479
40480 #define param_check_vmidfilter(name, p) __param_check(name, p, void)
40481
40482-static struct kernel_param_ops param_ops_vmidfilter = {
40483+static const struct kernel_param_ops param_ops_vmidfilter = {
40484 .set = param_set_vmidfilter,
40485 .get = param_get_vmidfilter,
40486 };
40487diff -urNp linux-2.6.39.1/drivers/tty/hvc/hvcs.c linux-2.6.39.1/drivers/tty/hvc/hvcs.c
40488--- linux-2.6.39.1/drivers/tty/hvc/hvcs.c 2011-05-19 00:06:34.000000000 -0400
40489+++ linux-2.6.39.1/drivers/tty/hvc/hvcs.c 2011-05-22 19:36:32.000000000 -0400
40490@@ -83,6 +83,7 @@
40491 #include <asm/hvcserver.h>
40492 #include <asm/uaccess.h>
40493 #include <asm/vio.h>
40494+#include <asm/local.h>
40495
40496 /*
40497 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
40498@@ -270,7 +271,7 @@ struct hvcs_struct {
40499 unsigned int index;
40500
40501 struct tty_struct *tty;
40502- int open_count;
40503+ local_t open_count;
40504
40505 /*
40506 * Used to tell the driver kernel_thread what operations need to take
40507@@ -422,7 +423,7 @@ static ssize_t hvcs_vterm_state_store(st
40508
40509 spin_lock_irqsave(&hvcsd->lock, flags);
40510
40511- if (hvcsd->open_count > 0) {
40512+ if (local_read(&hvcsd->open_count) > 0) {
40513 spin_unlock_irqrestore(&hvcsd->lock, flags);
40514 printk(KERN_INFO "HVCS: vterm state unchanged. "
40515 "The hvcs device node is still in use.\n");
40516@@ -1145,7 +1146,7 @@ static int hvcs_open(struct tty_struct *
40517 if ((retval = hvcs_partner_connect(hvcsd)))
40518 goto error_release;
40519
40520- hvcsd->open_count = 1;
40521+ local_set(&hvcsd->open_count, 1);
40522 hvcsd->tty = tty;
40523 tty->driver_data = hvcsd;
40524
40525@@ -1179,7 +1180,7 @@ fast_open:
40526
40527 spin_lock_irqsave(&hvcsd->lock, flags);
40528 kref_get(&hvcsd->kref);
40529- hvcsd->open_count++;
40530+ local_inc(&hvcsd->open_count);
40531 hvcsd->todo_mask |= HVCS_SCHED_READ;
40532 spin_unlock_irqrestore(&hvcsd->lock, flags);
40533
40534@@ -1223,7 +1224,7 @@ static void hvcs_close(struct tty_struct
40535 hvcsd = tty->driver_data;
40536
40537 spin_lock_irqsave(&hvcsd->lock, flags);
40538- if (--hvcsd->open_count == 0) {
40539+ if (local_dec_and_test(&hvcsd->open_count)) {
40540
40541 vio_disable_interrupts(hvcsd->vdev);
40542
40543@@ -1249,10 +1250,10 @@ static void hvcs_close(struct tty_struct
40544 free_irq(irq, hvcsd);
40545 kref_put(&hvcsd->kref, destroy_hvcs_struct);
40546 return;
40547- } else if (hvcsd->open_count < 0) {
40548+ } else if (local_read(&hvcsd->open_count) < 0) {
40549 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
40550 " is missmanaged.\n",
40551- hvcsd->vdev->unit_address, hvcsd->open_count);
40552+ hvcsd->vdev->unit_address, local_read(&hvcsd->open_count));
40553 }
40554
40555 spin_unlock_irqrestore(&hvcsd->lock, flags);
40556@@ -1268,7 +1269,7 @@ static void hvcs_hangup(struct tty_struc
40557
40558 spin_lock_irqsave(&hvcsd->lock, flags);
40559 /* Preserve this so that we know how many kref refs to put */
40560- temp_open_count = hvcsd->open_count;
40561+ temp_open_count = local_read(&hvcsd->open_count);
40562
40563 /*
40564 * Don't kref put inside the spinlock because the destruction
40565@@ -1283,7 +1284,7 @@ static void hvcs_hangup(struct tty_struc
40566 hvcsd->tty->driver_data = NULL;
40567 hvcsd->tty = NULL;
40568
40569- hvcsd->open_count = 0;
40570+ local_set(&hvcsd->open_count, 0);
40571
40572 /* This will drop any buffered data on the floor which is OK in a hangup
40573 * scenario. */
40574@@ -1354,7 +1355,7 @@ static int hvcs_write(struct tty_struct
40575 * the middle of a write operation? This is a crummy place to do this
40576 * but we want to keep it all in the spinlock.
40577 */
40578- if (hvcsd->open_count <= 0) {
40579+ if (local_read(&hvcsd->open_count) <= 0) {
40580 spin_unlock_irqrestore(&hvcsd->lock, flags);
40581 return -ENODEV;
40582 }
40583@@ -1428,7 +1429,7 @@ static int hvcs_write_room(struct tty_st
40584 {
40585 struct hvcs_struct *hvcsd = tty->driver_data;
40586
40587- if (!hvcsd || hvcsd->open_count <= 0)
40588+ if (!hvcsd || local_read(&hvcsd->open_count) <= 0)
40589 return 0;
40590
40591 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
40592diff -urNp linux-2.6.39.1/drivers/tty/hvc/hvc_xen.c linux-2.6.39.1/drivers/tty/hvc/hvc_xen.c
40593--- linux-2.6.39.1/drivers/tty/hvc/hvc_xen.c 2011-05-19 00:06:34.000000000 -0400
40594+++ linux-2.6.39.1/drivers/tty/hvc/hvc_xen.c 2011-05-22 19:36:32.000000000 -0400
40595@@ -123,7 +123,7 @@ static int domU_read_console(uint32_t vt
40596 return recv;
40597 }
40598
40599-static struct hv_ops domU_hvc_ops = {
40600+static const struct hv_ops domU_hvc_ops = {
40601 .get_chars = domU_read_console,
40602 .put_chars = domU_write_console,
40603 .notifier_add = notifier_add_irq,
40604@@ -149,7 +149,7 @@ static int dom0_write_console(uint32_t v
40605 return len;
40606 }
40607
40608-static struct hv_ops dom0_hvc_ops = {
40609+static const struct hv_ops dom0_hvc_ops = {
40610 .get_chars = dom0_read_console,
40611 .put_chars = dom0_write_console,
40612 .notifier_add = notifier_add_irq,
40613@@ -160,7 +160,7 @@ static struct hv_ops dom0_hvc_ops = {
40614 static int __init xen_hvc_init(void)
40615 {
40616 struct hvc_struct *hp;
40617- struct hv_ops *ops;
40618+ const struct hv_ops *ops;
40619
40620 if (!xen_pv_domain())
40621 return -ENODEV;
40622@@ -205,7 +205,7 @@ static void __exit xen_hvc_fini(void)
40623
40624 static int xen_cons_init(void)
40625 {
40626- struct hv_ops *ops;
40627+ const struct hv_ops *ops;
40628
40629 if (!xen_pv_domain())
40630 return 0;
40631diff -urNp linux-2.6.39.1/drivers/tty/ipwireless/tty.c linux-2.6.39.1/drivers/tty/ipwireless/tty.c
40632--- linux-2.6.39.1/drivers/tty/ipwireless/tty.c 2011-05-19 00:06:34.000000000 -0400
40633+++ linux-2.6.39.1/drivers/tty/ipwireless/tty.c 2011-05-22 19:36:32.000000000 -0400
40634@@ -29,6 +29,7 @@
40635 #include <linux/tty_driver.h>
40636 #include <linux/tty_flip.h>
40637 #include <linux/uaccess.h>
40638+#include <asm/local.h>
40639
40640 #include "tty.h"
40641 #include "network.h"
40642@@ -51,7 +52,7 @@ struct ipw_tty {
40643 int tty_type;
40644 struct ipw_network *network;
40645 struct tty_struct *linux_tty;
40646- int open_count;
40647+ local_t open_count;
40648 unsigned int control_lines;
40649 struct mutex ipw_tty_mutex;
40650 int tx_bytes_queued;
40651@@ -127,10 +128,10 @@ static int ipw_open(struct tty_struct *l
40652 mutex_unlock(&tty->ipw_tty_mutex);
40653 return -ENODEV;
40654 }
40655- if (tty->open_count == 0)
40656+ if (local_read(&tty->open_count) == 0)
40657 tty->tx_bytes_queued = 0;
40658
40659- tty->open_count++;
40660+ local_inc(&tty->open_count);
40661
40662 tty->linux_tty = linux_tty;
40663 linux_tty->driver_data = tty;
40664@@ -146,9 +147,7 @@ static int ipw_open(struct tty_struct *l
40665
40666 static void do_ipw_close(struct ipw_tty *tty)
40667 {
40668- tty->open_count--;
40669-
40670- if (tty->open_count == 0) {
40671+ if (local_dec_return(&tty->open_count) == 0) {
40672 struct tty_struct *linux_tty = tty->linux_tty;
40673
40674 if (linux_tty != NULL) {
40675@@ -169,7 +168,7 @@ static void ipw_hangup(struct tty_struct
40676 return;
40677
40678 mutex_lock(&tty->ipw_tty_mutex);
40679- if (tty->open_count == 0) {
40680+ if (local_read(&tty->open_count) == 0) {
40681 mutex_unlock(&tty->ipw_tty_mutex);
40682 return;
40683 }
40684@@ -198,7 +197,7 @@ void ipwireless_tty_received(struct ipw_
40685 return;
40686 }
40687
40688- if (!tty->open_count) {
40689+ if (!local_read(&tty->open_count)) {
40690 mutex_unlock(&tty->ipw_tty_mutex);
40691 return;
40692 }
40693@@ -240,7 +239,7 @@ static int ipw_write(struct tty_struct *
40694 return -ENODEV;
40695
40696 mutex_lock(&tty->ipw_tty_mutex);
40697- if (!tty->open_count) {
40698+ if (!local_read(&tty->open_count)) {
40699 mutex_unlock(&tty->ipw_tty_mutex);
40700 return -EINVAL;
40701 }
40702@@ -280,7 +279,7 @@ static int ipw_write_room(struct tty_str
40703 if (!tty)
40704 return -ENODEV;
40705
40706- if (!tty->open_count)
40707+ if (!local_read(&tty->open_count))
40708 return -EINVAL;
40709
40710 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
40711@@ -322,7 +321,7 @@ static int ipw_chars_in_buffer(struct tt
40712 if (!tty)
40713 return 0;
40714
40715- if (!tty->open_count)
40716+ if (!local_read(&tty->open_count))
40717 return 0;
40718
40719 return tty->tx_bytes_queued;
40720@@ -403,7 +402,7 @@ static int ipw_tiocmget(struct tty_struc
40721 if (!tty)
40722 return -ENODEV;
40723
40724- if (!tty->open_count)
40725+ if (!local_read(&tty->open_count))
40726 return -EINVAL;
40727
40728 return get_control_lines(tty);
40729@@ -419,7 +418,7 @@ ipw_tiocmset(struct tty_struct *linux_tt
40730 if (!tty)
40731 return -ENODEV;
40732
40733- if (!tty->open_count)
40734+ if (!local_read(&tty->open_count))
40735 return -EINVAL;
40736
40737 return set_control_lines(tty, set, clear);
40738@@ -433,7 +432,7 @@ static int ipw_ioctl(struct tty_struct *
40739 if (!tty)
40740 return -ENODEV;
40741
40742- if (!tty->open_count)
40743+ if (!local_read(&tty->open_count))
40744 return -EINVAL;
40745
40746 /* FIXME: Exactly how is the tty object locked here .. */
40747@@ -582,7 +581,7 @@ void ipwireless_tty_free(struct ipw_tty
40748 against a parallel ioctl etc */
40749 mutex_lock(&ttyj->ipw_tty_mutex);
40750 }
40751- while (ttyj->open_count)
40752+ while (local_read(&ttyj->open_count))
40753 do_ipw_close(ttyj);
40754 ipwireless_disassociate_network_ttys(network,
40755 ttyj->channel_idx);
40756diff -urNp linux-2.6.39.1/drivers/tty/mxser.c linux-2.6.39.1/drivers/tty/mxser.c
40757--- linux-2.6.39.1/drivers/tty/mxser.c 2011-05-19 00:06:34.000000000 -0400
40758+++ linux-2.6.39.1/drivers/tty/mxser.c 2011-05-22 19:36:32.000000000 -0400
40759@@ -2340,7 +2340,7 @@ static const struct tty_operations mxser
40760 .get_icount = mxser_get_icount,
40761 };
40762
40763-struct tty_port_operations mxser_port_ops = {
40764+const struct tty_port_operations mxser_port_ops = {
40765 .carrier_raised = mxser_carrier_raised,
40766 .dtr_rts = mxser_dtr_rts,
40767 .activate = mxser_activate,
40768diff -urNp linux-2.6.39.1/drivers/tty/n_gsm.c linux-2.6.39.1/drivers/tty/n_gsm.c
40769--- linux-2.6.39.1/drivers/tty/n_gsm.c 2011-05-19 00:06:34.000000000 -0400
40770+++ linux-2.6.39.1/drivers/tty/n_gsm.c 2011-05-22 19:36:32.000000000 -0400
40771@@ -1588,7 +1588,7 @@ static struct gsm_dlci *gsm_dlci_alloc(s
40772 return NULL;
40773 spin_lock_init(&dlci->lock);
40774 dlci->fifo = &dlci->_fifo;
40775- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
40776+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
40777 kfree(dlci);
40778 return NULL;
40779 }
40780diff -urNp linux-2.6.39.1/drivers/tty/n_tty.c linux-2.6.39.1/drivers/tty/n_tty.c
40781--- linux-2.6.39.1/drivers/tty/n_tty.c 2011-05-19 00:06:34.000000000 -0400
40782+++ linux-2.6.39.1/drivers/tty/n_tty.c 2011-05-22 19:36:32.000000000 -0400
40783@@ -2122,6 +2122,7 @@ void n_tty_inherit_ops(struct tty_ldisc_
40784 {
40785 *ops = tty_ldisc_N_TTY;
40786 ops->owner = NULL;
40787- ops->refcount = ops->flags = 0;
40788+ atomic_set(&ops->refcount, 0);
40789+ ops->flags = 0;
40790 }
40791 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
40792diff -urNp linux-2.6.39.1/drivers/tty/pty.c linux-2.6.39.1/drivers/tty/pty.c
40793--- linux-2.6.39.1/drivers/tty/pty.c 2011-05-19 00:06:34.000000000 -0400
40794+++ linux-2.6.39.1/drivers/tty/pty.c 2011-05-22 19:36:32.000000000 -0400
40795@@ -699,7 +699,18 @@ out:
40796 return retval;
40797 }
40798
40799-static struct file_operations ptmx_fops;
40800+static const struct file_operations ptmx_fops = {
40801+ .llseek = no_llseek,
40802+ .read = tty_read,
40803+ .write = tty_write,
40804+ .poll = tty_poll,
40805+ .unlocked_ioctl = tty_ioctl,
40806+ .compat_ioctl = tty_compat_ioctl,
40807+ .open = ptmx_open,
40808+ .release = tty_release,
40809+ .fasync = tty_fasync,
40810+};
40811+
40812
40813 static void __init unix98_pty_init(void)
40814 {
40815@@ -752,10 +763,6 @@ static void __init unix98_pty_init(void)
40816
40817 register_sysctl_table(pty_root_table);
40818
40819- /* Now create the /dev/ptmx special device */
40820- tty_default_fops(&ptmx_fops);
40821- ptmx_fops.open = ptmx_open;
40822-
40823 cdev_init(&ptmx_cdev, &ptmx_fops);
40824 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
40825 register_chrdev_region(MKDEV(TTYAUX_MAJOR, 2), 1, "/dev/ptmx") < 0)
40826diff -urNp linux-2.6.39.1/drivers/tty/rocket.c linux-2.6.39.1/drivers/tty/rocket.c
40827--- linux-2.6.39.1/drivers/tty/rocket.c 2011-05-19 00:06:34.000000000 -0400
40828+++ linux-2.6.39.1/drivers/tty/rocket.c 2011-05-22 19:36:32.000000000 -0400
40829@@ -1277,6 +1277,8 @@ static int get_ports(struct r_port *info
40830 struct rocket_ports tmp;
40831 int board;
40832
40833+ pax_track_stack();
40834+
40835 if (!retports)
40836 return -EFAULT;
40837 memset(&tmp, 0, sizeof (tmp));
40838diff -urNp linux-2.6.39.1/drivers/tty/serial/21285.c linux-2.6.39.1/drivers/tty/serial/21285.c
40839--- linux-2.6.39.1/drivers/tty/serial/21285.c 2011-05-19 00:06:34.000000000 -0400
40840+++ linux-2.6.39.1/drivers/tty/serial/21285.c 2011-05-22 19:36:32.000000000 -0400
40841@@ -340,7 +340,7 @@ static int serial21285_verify_port(struc
40842 return ret;
40843 }
40844
40845-static struct uart_ops serial21285_ops = {
40846+static const struct uart_ops serial21285_ops = {
40847 .tx_empty = serial21285_tx_empty,
40848 .get_mctrl = serial21285_get_mctrl,
40849 .set_mctrl = serial21285_set_mctrl,
40850diff -urNp linux-2.6.39.1/drivers/tty/serial/8250.c linux-2.6.39.1/drivers/tty/serial/8250.c
40851--- linux-2.6.39.1/drivers/tty/serial/8250.c 2011-05-19 00:06:34.000000000 -0400
40852+++ linux-2.6.39.1/drivers/tty/serial/8250.c 2011-05-22 19:36:32.000000000 -0400
40853@@ -2708,7 +2708,7 @@ serial8250_type(struct uart_port *port)
40854 return uart_config[type].name;
40855 }
40856
40857-static struct uart_ops serial8250_pops = {
40858+static const struct uart_ops serial8250_pops = {
40859 .tx_empty = serial8250_tx_empty,
40860 .set_mctrl = serial8250_set_mctrl,
40861 .get_mctrl = serial8250_get_mctrl,
40862diff -urNp linux-2.6.39.1/drivers/tty/serial/altera_jtaguart.c linux-2.6.39.1/drivers/tty/serial/altera_jtaguart.c
40863--- linux-2.6.39.1/drivers/tty/serial/altera_jtaguart.c 2011-05-19 00:06:34.000000000 -0400
40864+++ linux-2.6.39.1/drivers/tty/serial/altera_jtaguart.c 2011-05-22 19:36:32.000000000 -0400
40865@@ -281,7 +281,7 @@ static int altera_jtaguart_verify_port(s
40866 /*
40867 * Define the basic serial functions we support.
40868 */
40869-static struct uart_ops altera_jtaguart_ops = {
40870+static const struct uart_ops altera_jtaguart_ops = {
40871 .tx_empty = altera_jtaguart_tx_empty,
40872 .get_mctrl = altera_jtaguart_get_mctrl,
40873 .set_mctrl = altera_jtaguart_set_mctrl,
40874diff -urNp linux-2.6.39.1/drivers/tty/serial/altera_uart.c linux-2.6.39.1/drivers/tty/serial/altera_uart.c
40875--- linux-2.6.39.1/drivers/tty/serial/altera_uart.c 2011-05-19 00:06:34.000000000 -0400
40876+++ linux-2.6.39.1/drivers/tty/serial/altera_uart.c 2011-05-22 19:36:32.000000000 -0400
40877@@ -380,7 +380,7 @@ static int altera_uart_verify_port(struc
40878 /*
40879 * Define the basic serial functions we support.
40880 */
40881-static struct uart_ops altera_uart_ops = {
40882+static const struct uart_ops altera_uart_ops = {
40883 .tx_empty = altera_uart_tx_empty,
40884 .get_mctrl = altera_uart_get_mctrl,
40885 .set_mctrl = altera_uart_set_mctrl,
40886diff -urNp linux-2.6.39.1/drivers/tty/serial/amba-pl010.c linux-2.6.39.1/drivers/tty/serial/amba-pl010.c
40887--- linux-2.6.39.1/drivers/tty/serial/amba-pl010.c 2011-05-19 00:06:34.000000000 -0400
40888+++ linux-2.6.39.1/drivers/tty/serial/amba-pl010.c 2011-05-22 19:36:32.000000000 -0400
40889@@ -529,7 +529,7 @@ static int pl010_verify_port(struct uart
40890 return ret;
40891 }
40892
40893-static struct uart_ops amba_pl010_pops = {
40894+static const struct uart_ops amba_pl010_pops = {
40895 .tx_empty = pl010_tx_empty,
40896 .set_mctrl = pl010_set_mctrl,
40897 .get_mctrl = pl010_get_mctrl,
40898diff -urNp linux-2.6.39.1/drivers/tty/serial/amba-pl011.c linux-2.6.39.1/drivers/tty/serial/amba-pl011.c
40899--- linux-2.6.39.1/drivers/tty/serial/amba-pl011.c 2011-05-19 00:06:34.000000000 -0400
40900+++ linux-2.6.39.1/drivers/tty/serial/amba-pl011.c 2011-05-22 19:36:32.000000000 -0400
40901@@ -1581,7 +1581,7 @@ static int pl010_verify_port(struct uart
40902 return ret;
40903 }
40904
40905-static struct uart_ops amba_pl011_pops = {
40906+static const struct uart_ops amba_pl011_pops = {
40907 .tx_empty = pl01x_tx_empty,
40908 .set_mctrl = pl011_set_mctrl,
40909 .get_mctrl = pl01x_get_mctrl,
40910diff -urNp linux-2.6.39.1/drivers/tty/serial/apbuart.c linux-2.6.39.1/drivers/tty/serial/apbuart.c
40911--- linux-2.6.39.1/drivers/tty/serial/apbuart.c 2011-05-19 00:06:34.000000000 -0400
40912+++ linux-2.6.39.1/drivers/tty/serial/apbuart.c 2011-05-22 19:36:32.000000000 -0400
40913@@ -328,7 +328,7 @@ static int apbuart_verify_port(struct ua
40914 return ret;
40915 }
40916
40917-static struct uart_ops grlib_apbuart_ops = {
40918+static const struct uart_ops grlib_apbuart_ops = {
40919 .tx_empty = apbuart_tx_empty,
40920 .set_mctrl = apbuart_set_mctrl,
40921 .get_mctrl = apbuart_get_mctrl,
40922diff -urNp linux-2.6.39.1/drivers/tty/serial/atmel_serial.c linux-2.6.39.1/drivers/tty/serial/atmel_serial.c
40923--- linux-2.6.39.1/drivers/tty/serial/atmel_serial.c 2011-05-19 00:06:34.000000000 -0400
40924+++ linux-2.6.39.1/drivers/tty/serial/atmel_serial.c 2011-05-22 19:36:32.000000000 -0400
40925@@ -1382,7 +1382,7 @@ atmel_ioctl(struct uart_port *port, unsi
40926
40927
40928
40929-static struct uart_ops atmel_pops = {
40930+static const struct uart_ops atmel_pops = {
40931 .tx_empty = atmel_tx_empty,
40932 .set_mctrl = atmel_set_mctrl,
40933 .get_mctrl = atmel_get_mctrl,
40934diff -urNp linux-2.6.39.1/drivers/tty/serial/bcm63xx_uart.c linux-2.6.39.1/drivers/tty/serial/bcm63xx_uart.c
40935--- linux-2.6.39.1/drivers/tty/serial/bcm63xx_uart.c 2011-05-19 00:06:34.000000000 -0400
40936+++ linux-2.6.39.1/drivers/tty/serial/bcm63xx_uart.c 2011-05-22 19:36:32.000000000 -0400
40937@@ -636,7 +636,7 @@ static int bcm_uart_verify_port(struct u
40938 }
40939
40940 /* serial core callbacks */
40941-static struct uart_ops bcm_uart_ops = {
40942+static const struct uart_ops bcm_uart_ops = {
40943 .tx_empty = bcm_uart_tx_empty,
40944 .get_mctrl = bcm_uart_get_mctrl,
40945 .set_mctrl = bcm_uart_set_mctrl,
40946diff -urNp linux-2.6.39.1/drivers/tty/serial/bfin_5xx.c linux-2.6.39.1/drivers/tty/serial/bfin_5xx.c
40947--- linux-2.6.39.1/drivers/tty/serial/bfin_5xx.c 2011-05-19 00:06:34.000000000 -0400
40948+++ linux-2.6.39.1/drivers/tty/serial/bfin_5xx.c 2011-05-22 19:36:32.000000000 -0400
40949@@ -1036,7 +1036,7 @@ static int bfin_kgdboc_port_startup(stru
40950 }
40951 #endif
40952
40953-static struct uart_ops bfin_serial_pops = {
40954+static const struct uart_ops bfin_serial_pops = {
40955 .tx_empty = bfin_serial_tx_empty,
40956 .set_mctrl = bfin_serial_set_mctrl,
40957 .get_mctrl = bfin_serial_get_mctrl,
40958diff -urNp linux-2.6.39.1/drivers/tty/serial/bfin_sport_uart.c linux-2.6.39.1/drivers/tty/serial/bfin_sport_uart.c
40959--- linux-2.6.39.1/drivers/tty/serial/bfin_sport_uart.c 2011-05-19 00:06:34.000000000 -0400
40960+++ linux-2.6.39.1/drivers/tty/serial/bfin_sport_uart.c 2011-05-22 19:36:32.000000000 -0400
40961@@ -571,7 +571,7 @@ static void sport_set_termios(struct uar
40962 spin_unlock_irqrestore(&up->port.lock, flags);
40963 }
40964
40965-struct uart_ops sport_uart_ops = {
40966+const struct uart_ops sport_uart_ops = {
40967 .tx_empty = sport_tx_empty,
40968 .set_mctrl = sport_set_mctrl,
40969 .get_mctrl = sport_get_mctrl,
40970diff -urNp linux-2.6.39.1/drivers/tty/serial/clps711x.c linux-2.6.39.1/drivers/tty/serial/clps711x.c
40971--- linux-2.6.39.1/drivers/tty/serial/clps711x.c 2011-05-19 00:06:34.000000000 -0400
40972+++ linux-2.6.39.1/drivers/tty/serial/clps711x.c 2011-05-22 19:36:32.000000000 -0400
40973@@ -380,7 +380,7 @@ static int clps711xuart_request_port(str
40974 return 0;
40975 }
40976
40977-static struct uart_ops clps711x_pops = {
40978+static const struct uart_ops clps711x_pops = {
40979 .tx_empty = clps711xuart_tx_empty,
40980 .set_mctrl = clps711xuart_set_mctrl_null,
40981 .get_mctrl = clps711xuart_get_mctrl,
40982diff -urNp linux-2.6.39.1/drivers/tty/serial/cpm_uart/cpm_uart_core.c linux-2.6.39.1/drivers/tty/serial/cpm_uart/cpm_uart_core.c
40983--- linux-2.6.39.1/drivers/tty/serial/cpm_uart/cpm_uart_core.c 2011-05-19 00:06:34.000000000 -0400
40984+++ linux-2.6.39.1/drivers/tty/serial/cpm_uart/cpm_uart_core.c 2011-05-22 19:36:32.000000000 -0400
40985@@ -1099,7 +1099,7 @@ static void cpm_put_poll_char(struct uar
40986 }
40987 #endif /* CONFIG_CONSOLE_POLL */
40988
40989-static struct uart_ops cpm_uart_pops = {
40990+static const struct uart_ops cpm_uart_pops = {
40991 .tx_empty = cpm_uart_tx_empty,
40992 .set_mctrl = cpm_uart_set_mctrl,
40993 .get_mctrl = cpm_uart_get_mctrl,
40994diff -urNp linux-2.6.39.1/drivers/tty/serial/dz.c linux-2.6.39.1/drivers/tty/serial/dz.c
40995--- linux-2.6.39.1/drivers/tty/serial/dz.c 2011-05-19 00:06:34.000000000 -0400
40996+++ linux-2.6.39.1/drivers/tty/serial/dz.c 2011-05-22 19:36:32.000000000 -0400
40997@@ -746,7 +746,7 @@ static int dz_verify_port(struct uart_po
40998 return ret;
40999 }
41000
41001-static struct uart_ops dz_ops = {
41002+static const struct uart_ops dz_ops = {
41003 .tx_empty = dz_tx_empty,
41004 .get_mctrl = dz_get_mctrl,
41005 .set_mctrl = dz_set_mctrl,
41006diff -urNp linux-2.6.39.1/drivers/tty/serial/imx.c linux-2.6.39.1/drivers/tty/serial/imx.c
41007--- linux-2.6.39.1/drivers/tty/serial/imx.c 2011-05-19 00:06:34.000000000 -0400
41008+++ linux-2.6.39.1/drivers/tty/serial/imx.c 2011-05-22 19:36:32.000000000 -0400
41009@@ -1018,7 +1018,7 @@ imx_verify_port(struct uart_port *port,
41010 return ret;
41011 }
41012
41013-static struct uart_ops imx_pops = {
41014+static const struct uart_ops imx_pops = {
41015 .tx_empty = imx_tx_empty,
41016 .set_mctrl = imx_set_mctrl,
41017 .get_mctrl = imx_get_mctrl,
41018diff -urNp linux-2.6.39.1/drivers/tty/serial/ioc3_serial.c linux-2.6.39.1/drivers/tty/serial/ioc3_serial.c
41019--- linux-2.6.39.1/drivers/tty/serial/ioc3_serial.c 2011-05-19 00:06:34.000000000 -0400
41020+++ linux-2.6.39.1/drivers/tty/serial/ioc3_serial.c 2011-05-22 19:36:32.000000000 -0400
41021@@ -1874,7 +1874,7 @@ static int ic3_request_port(struct uart_
41022 }
41023
41024 /* Associate the uart functions above - given to serial core */
41025-static struct uart_ops ioc3_ops = {
41026+static const struct uart_ops ioc3_ops = {
41027 .tx_empty = ic3_tx_empty,
41028 .set_mctrl = ic3_set_mctrl,
41029 .get_mctrl = ic3_get_mctrl,
41030diff -urNp linux-2.6.39.1/drivers/tty/serial/ioc4_serial.c linux-2.6.39.1/drivers/tty/serial/ioc4_serial.c
41031--- linux-2.6.39.1/drivers/tty/serial/ioc4_serial.c 2011-05-19 00:06:34.000000000 -0400
41032+++ linux-2.6.39.1/drivers/tty/serial/ioc4_serial.c 2011-05-22 19:36:32.000000000 -0400
41033@@ -2593,7 +2593,7 @@ static int ic4_request_port(struct uart_
41034
41035 /* Associate the uart functions above - given to serial core */
41036
41037-static struct uart_ops ioc4_ops = {
41038+static const struct uart_ops ioc4_ops = {
41039 .tx_empty = ic4_tx_empty,
41040 .set_mctrl = ic4_set_mctrl,
41041 .get_mctrl = ic4_get_mctrl,
41042diff -urNp linux-2.6.39.1/drivers/tty/serial/ip22zilog.c linux-2.6.39.1/drivers/tty/serial/ip22zilog.c
41043--- linux-2.6.39.1/drivers/tty/serial/ip22zilog.c 2011-05-19 00:06:34.000000000 -0400
41044+++ linux-2.6.39.1/drivers/tty/serial/ip22zilog.c 2011-05-22 19:36:32.000000000 -0400
41045@@ -928,7 +928,7 @@ static int ip22zilog_verify_port(struct
41046 return -EINVAL;
41047 }
41048
41049-static struct uart_ops ip22zilog_pops = {
41050+static const struct uart_ops ip22zilog_pops = {
41051 .tx_empty = ip22zilog_tx_empty,
41052 .set_mctrl = ip22zilog_set_mctrl,
41053 .get_mctrl = ip22zilog_get_mctrl,
41054diff -urNp linux-2.6.39.1/drivers/tty/serial/kgdboc.c linux-2.6.39.1/drivers/tty/serial/kgdboc.c
41055--- linux-2.6.39.1/drivers/tty/serial/kgdboc.c 2011-05-19 00:06:34.000000000 -0400
41056+++ linux-2.6.39.1/drivers/tty/serial/kgdboc.c 2011-05-22 19:36:32.000000000 -0400
41057@@ -22,7 +22,7 @@
41058
41059 #define MAX_CONFIG_LEN 40
41060
41061-static struct kgdb_io kgdboc_io_ops;
41062+static struct kgdb_io kgdboc_io_ops; /* cannot be const, see configure_kgdboc() */
41063
41064 /* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
41065 static int configured = -1;
41066@@ -293,7 +293,7 @@ static void kgdboc_post_exp_handler(void
41067 kgdboc_restore_input();
41068 }
41069
41070-static struct kgdb_io kgdboc_io_ops = {
41071+static struct kgdb_io kgdboc_io_ops = { /* cannot be const, see configure_kgdboc() */
41072 .name = "kgdboc",
41073 .read_char = kgdboc_get_char,
41074 .write_char = kgdboc_put_char,
41075diff -urNp linux-2.6.39.1/drivers/tty/serial/m32r_sio.c linux-2.6.39.1/drivers/tty/serial/m32r_sio.c
41076--- linux-2.6.39.1/drivers/tty/serial/m32r_sio.c 2011-05-19 00:06:34.000000000 -0400
41077+++ linux-2.6.39.1/drivers/tty/serial/m32r_sio.c 2011-05-22 19:36:32.000000000 -0400
41078@@ -939,7 +939,7 @@ m32r_sio_type(struct uart_port *port)
41079 return uart_config[type].name;
41080 }
41081
41082-static struct uart_ops m32r_sio_pops = {
41083+static const struct uart_ops m32r_sio_pops = {
41084 .tx_empty = m32r_sio_tx_empty,
41085 .set_mctrl = m32r_sio_set_mctrl,
41086 .get_mctrl = m32r_sio_get_mctrl,
41087diff -urNp linux-2.6.39.1/drivers/tty/serial/max3100.c linux-2.6.39.1/drivers/tty/serial/max3100.c
41088--- linux-2.6.39.1/drivers/tty/serial/max3100.c 2011-05-19 00:06:34.000000000 -0400
41089+++ linux-2.6.39.1/drivers/tty/serial/max3100.c 2011-05-22 19:36:32.000000000 -0400
41090@@ -710,7 +710,7 @@ static void max3100_break_ctl(struct uar
41091 dev_dbg(&s->spi->dev, "%s\n", __func__);
41092 }
41093
41094-static struct uart_ops max3100_ops = {
41095+static const struct uart_ops max3100_ops = {
41096 .tx_empty = max3100_tx_empty,
41097 .set_mctrl = max3100_set_mctrl,
41098 .get_mctrl = max3100_get_mctrl,
41099diff -urNp linux-2.6.39.1/drivers/tty/serial/max3107.c linux-2.6.39.1/drivers/tty/serial/max3107.c
41100--- linux-2.6.39.1/drivers/tty/serial/max3107.c 2011-05-19 00:06:34.000000000 -0400
41101+++ linux-2.6.39.1/drivers/tty/serial/max3107.c 2011-05-22 19:36:32.000000000 -0400
41102@@ -910,7 +910,7 @@ static void max3107_break_ctl(struct uar
41103
41104
41105 /* Port functions */
41106-static struct uart_ops max3107_ops = {
41107+static const struct uart_ops max3107_ops = {
41108 .tx_empty = max3107_tx_empty,
41109 .set_mctrl = max3107_set_mctrl,
41110 .get_mctrl = max3107_get_mctrl,
41111diff -urNp linux-2.6.39.1/drivers/tty/serial/mfd.c linux-2.6.39.1/drivers/tty/serial/mfd.c
41112--- linux-2.6.39.1/drivers/tty/serial/mfd.c 2011-05-19 00:06:34.000000000 -0400
41113+++ linux-2.6.39.1/drivers/tty/serial/mfd.c 2011-05-22 19:36:32.000000000 -0400
41114@@ -1178,7 +1178,7 @@ static struct console serial_hsu_console
41115 };
41116 #endif
41117
41118-struct uart_ops serial_hsu_pops = {
41119+const struct uart_ops serial_hsu_pops = {
41120 .tx_empty = serial_hsu_tx_empty,
41121 .set_mctrl = serial_hsu_set_mctrl,
41122 .get_mctrl = serial_hsu_get_mctrl,
41123diff -urNp linux-2.6.39.1/drivers/tty/serial/mpc52xx_uart.c linux-2.6.39.1/drivers/tty/serial/mpc52xx_uart.c
41124--- linux-2.6.39.1/drivers/tty/serial/mpc52xx_uart.c 2011-05-19 00:06:34.000000000 -0400
41125+++ linux-2.6.39.1/drivers/tty/serial/mpc52xx_uart.c 2011-05-22 19:36:32.000000000 -0400
41126@@ -283,7 +283,7 @@ static irqreturn_t mpc52xx_psc_handle_ir
41127 return mpc5xxx_uart_process_int(port);
41128 }
41129
41130-static struct psc_ops mpc52xx_psc_ops = {
41131+static const struct psc_ops mpc52xx_psc_ops = {
41132 .fifo_init = mpc52xx_psc_fifo_init,
41133 .raw_rx_rdy = mpc52xx_psc_raw_rx_rdy,
41134 .raw_tx_rdy = mpc52xx_psc_raw_tx_rdy,
41135@@ -304,7 +304,7 @@ static struct psc_ops mpc52xx_psc_ops =
41136 .handle_irq = mpc52xx_psc_handle_irq,
41137 };
41138
41139-static struct psc_ops mpc5200b_psc_ops = {
41140+static const struct psc_ops mpc5200b_psc_ops = {
41141 .fifo_init = mpc52xx_psc_fifo_init,
41142 .raw_rx_rdy = mpc52xx_psc_raw_rx_rdy,
41143 .raw_tx_rdy = mpc52xx_psc_raw_tx_rdy,
41144@@ -571,7 +571,7 @@ static void mpc512x_psc_get_irq(struct u
41145 port->irq = psc_fifoc_irq;
41146 }
41147
41148-static struct psc_ops mpc512x_psc_ops = {
41149+static const struct psc_ops mpc512x_psc_ops = {
41150 .fifo_init = mpc512x_psc_fifo_init,
41151 .raw_rx_rdy = mpc512x_psc_raw_rx_rdy,
41152 .raw_tx_rdy = mpc512x_psc_raw_tx_rdy,
41153@@ -596,7 +596,7 @@ static struct psc_ops mpc512x_psc_ops =
41154 };
41155 #endif
41156
41157-static struct psc_ops *psc_ops;
41158+static const struct psc_ops *psc_ops;
41159
41160 /* ======================================================================== */
41161 /* UART operations */
41162@@ -905,7 +905,7 @@ mpc52xx_uart_verify_port(struct uart_por
41163 }
41164
41165
41166-static struct uart_ops mpc52xx_uart_ops = {
41167+static const struct uart_ops mpc52xx_uart_ops = {
41168 .tx_empty = mpc52xx_uart_tx_empty,
41169 .set_mctrl = mpc52xx_uart_set_mctrl,
41170 .get_mctrl = mpc52xx_uart_get_mctrl,
41171diff -urNp linux-2.6.39.1/drivers/tty/serial/mpsc.c linux-2.6.39.1/drivers/tty/serial/mpsc.c
41172--- linux-2.6.39.1/drivers/tty/serial/mpsc.c 2011-05-19 00:06:34.000000000 -0400
41173+++ linux-2.6.39.1/drivers/tty/serial/mpsc.c 2011-05-22 19:36:32.000000000 -0400
41174@@ -1663,7 +1663,7 @@ static void mpsc_put_poll_char(struct ua
41175 }
41176 #endif
41177
41178-static struct uart_ops mpsc_pops = {
41179+static const struct uart_ops mpsc_pops = {
41180 .tx_empty = mpsc_tx_empty,
41181 .set_mctrl = mpsc_set_mctrl,
41182 .get_mctrl = mpsc_get_mctrl,
41183diff -urNp linux-2.6.39.1/drivers/tty/serial/mrst_max3110.c linux-2.6.39.1/drivers/tty/serial/mrst_max3110.c
41184--- linux-2.6.39.1/drivers/tty/serial/mrst_max3110.c 2011-05-19 00:06:34.000000000 -0400
41185+++ linux-2.6.39.1/drivers/tty/serial/mrst_max3110.c 2011-05-22 19:36:32.000000000 -0400
41186@@ -393,6 +393,8 @@ static void max3110_con_receive(struct u
41187 int loop = 1, num, total = 0;
41188 u8 recv_buf[512], *pbuf;
41189
41190+ pax_track_stack();
41191+
41192 pbuf = recv_buf;
41193 do {
41194 num = max3110_read_multi(max, pbuf);
41195@@ -726,7 +728,7 @@ static void serial_m3110_enable_ms(struc
41196 {
41197 }
41198
41199-struct uart_ops serial_m3110_ops = {
41200+const struct uart_ops serial_m3110_ops = {
41201 .tx_empty = serial_m3110_tx_empty,
41202 .set_mctrl = serial_m3110_set_mctrl,
41203 .get_mctrl = serial_m3110_get_mctrl,
41204diff -urNp linux-2.6.39.1/drivers/tty/serial/msm_serial.c linux-2.6.39.1/drivers/tty/serial/msm_serial.c
41205--- linux-2.6.39.1/drivers/tty/serial/msm_serial.c 2011-05-19 00:06:34.000000000 -0400
41206+++ linux-2.6.39.1/drivers/tty/serial/msm_serial.c 2011-05-22 19:36:32.000000000 -0400
41207@@ -702,7 +702,7 @@ static void msm_power(struct uart_port *
41208 }
41209 }
41210
41211-static struct uart_ops msm_uart_pops = {
41212+static const struct uart_ops msm_uart_pops = {
41213 .tx_empty = msm_tx_empty,
41214 .set_mctrl = msm_set_mctrl,
41215 .get_mctrl = msm_get_mctrl,
41216diff -urNp linux-2.6.39.1/drivers/tty/serial/msm_serial_hs.c linux-2.6.39.1/drivers/tty/serial/msm_serial_hs.c
41217--- linux-2.6.39.1/drivers/tty/serial/msm_serial_hs.c 2011-05-19 00:06:34.000000000 -0400
41218+++ linux-2.6.39.1/drivers/tty/serial/msm_serial_hs.c 2011-05-22 19:36:32.000000000 -0400
41219@@ -360,7 +360,7 @@ struct msm_hs_port {
41220 static struct msm_hs_port q_uart_port[UARTDM_NR];
41221 static struct platform_driver msm_serial_hs_platform_driver;
41222 static struct uart_driver msm_hs_driver;
41223-static struct uart_ops msm_hs_ops;
41224+static const struct uart_ops msm_hs_ops;
41225 static struct workqueue_struct *msm_hs_workqueue;
41226
41227 #define UARTDM_TO_MSM(uart_port) \
41228@@ -1856,7 +1856,7 @@ static struct uart_driver msm_hs_driver
41229 .cons = 0,
41230 };
41231
41232-static struct uart_ops msm_hs_ops = {
41233+static const struct uart_ops msm_hs_ops = {
41234 .tx_empty = msm_hs_tx_empty,
41235 .set_mctrl = msm_hs_set_mctrl_locked,
41236 .get_mctrl = msm_hs_get_mctrl_locked,
41237diff -urNp linux-2.6.39.1/drivers/tty/serial/mux.c linux-2.6.39.1/drivers/tty/serial/mux.c
41238--- linux-2.6.39.1/drivers/tty/serial/mux.c 2011-05-19 00:06:34.000000000 -0400
41239+++ linux-2.6.39.1/drivers/tty/serial/mux.c 2011-05-22 19:36:32.000000000 -0400
41240@@ -442,7 +442,7 @@ static struct console mux_console = {
41241 #define MUX_CONSOLE NULL
41242 #endif
41243
41244-static struct uart_ops mux_pops = {
41245+static const struct uart_ops mux_pops = {
41246 .tx_empty = mux_tx_empty,
41247 .set_mctrl = mux_set_mctrl,
41248 .get_mctrl = mux_get_mctrl,
41249diff -urNp linux-2.6.39.1/drivers/tty/serial/mxs-auart.c linux-2.6.39.1/drivers/tty/serial/mxs-auart.c
41250--- linux-2.6.39.1/drivers/tty/serial/mxs-auart.c 2011-05-19 00:06:34.000000000 -0400
41251+++ linux-2.6.39.1/drivers/tty/serial/mxs-auart.c 2011-05-22 19:36:32.000000000 -0400
41252@@ -499,7 +499,7 @@ static void mxs_auart_enable_ms(struct u
41253 /* just empty */
41254 }
41255
41256-static struct uart_ops mxs_auart_ops = {
41257+static const struct uart_ops mxs_auart_ops = {
41258 .tx_empty = mxs_auart_tx_empty,
41259 .start_tx = mxs_auart_start_tx,
41260 .stop_tx = mxs_auart_stop_tx,
41261diff -urNp linux-2.6.39.1/drivers/tty/serial/netx-serial.c linux-2.6.39.1/drivers/tty/serial/netx-serial.c
41262--- linux-2.6.39.1/drivers/tty/serial/netx-serial.c 2011-05-19 00:06:34.000000000 -0400
41263+++ linux-2.6.39.1/drivers/tty/serial/netx-serial.c 2011-05-22 19:36:32.000000000 -0400
41264@@ -464,7 +464,7 @@ netx_verify_port(struct uart_port *port,
41265 return ret;
41266 }
41267
41268-static struct uart_ops netx_pops = {
41269+static const struct uart_ops netx_pops = {
41270 .tx_empty = netx_tx_empty,
41271 .set_mctrl = netx_set_mctrl,
41272 .get_mctrl = netx_get_mctrl,
41273diff -urNp linux-2.6.39.1/drivers/tty/serial/nwpserial.c linux-2.6.39.1/drivers/tty/serial/nwpserial.c
41274--- linux-2.6.39.1/drivers/tty/serial/nwpserial.c 2011-05-19 00:06:34.000000000 -0400
41275+++ linux-2.6.39.1/drivers/tty/serial/nwpserial.c 2011-05-22 19:36:32.000000000 -0400
41276@@ -303,7 +303,7 @@ static unsigned int nwpserial_tx_empty(s
41277 return ret & UART_LSR_TEMT ? TIOCSER_TEMT : 0;
41278 }
41279
41280-static struct uart_ops nwpserial_pops = {
41281+static const struct uart_ops nwpserial_pops = {
41282 .tx_empty = nwpserial_tx_empty,
41283 .set_mctrl = nwpserial_set_mctrl,
41284 .get_mctrl = nwpserial_get_mctrl,
41285diff -urNp linux-2.6.39.1/drivers/tty/serial/omap-serial.c linux-2.6.39.1/drivers/tty/serial/omap-serial.c
41286--- linux-2.6.39.1/drivers/tty/serial/omap-serial.c 2011-05-19 00:06:34.000000000 -0400
41287+++ linux-2.6.39.1/drivers/tty/serial/omap-serial.c 2011-05-22 19:36:32.000000000 -0400
41288@@ -1029,7 +1029,7 @@ static inline void serial_omap_add_conso
41289
41290 #endif
41291
41292-static struct uart_ops serial_omap_pops = {
41293+static const struct uart_ops serial_omap_pops = {
41294 .tx_empty = serial_omap_tx_empty,
41295 .set_mctrl = serial_omap_set_mctrl,
41296 .get_mctrl = serial_omap_get_mctrl,
41297diff -urNp linux-2.6.39.1/drivers/tty/serial/pch_uart.c linux-2.6.39.1/drivers/tty/serial/pch_uart.c
41298--- linux-2.6.39.1/drivers/tty/serial/pch_uart.c 2011-05-19 00:06:34.000000000 -0400
41299+++ linux-2.6.39.1/drivers/tty/serial/pch_uart.c 2011-05-22 19:36:32.000000000 -0400
41300@@ -1351,7 +1351,7 @@ static int pch_uart_verify_port(struct u
41301 return 0;
41302 }
41303
41304-static struct uart_ops pch_uart_ops = {
41305+static const struct uart_ops pch_uart_ops = {
41306 .tx_empty = pch_uart_tx_empty,
41307 .set_mctrl = pch_uart_set_mctrl,
41308 .get_mctrl = pch_uart_get_mctrl,
41309diff -urNp linux-2.6.39.1/drivers/tty/serial/pmac_zilog.c linux-2.6.39.1/drivers/tty/serial/pmac_zilog.c
41310--- linux-2.6.39.1/drivers/tty/serial/pmac_zilog.c 2011-05-19 00:06:34.000000000 -0400
41311+++ linux-2.6.39.1/drivers/tty/serial/pmac_zilog.c 2011-05-22 19:36:32.000000000 -0400
41312@@ -1427,7 +1427,7 @@ static void pmz_poll_put_char(struct uar
41313
41314 #endif /* CONFIG_CONSOLE_POLL */
41315
41316-static struct uart_ops pmz_pops = {
41317+static const struct uart_ops pmz_pops = {
41318 .tx_empty = pmz_tx_empty,
41319 .set_mctrl = pmz_set_mctrl,
41320 .get_mctrl = pmz_get_mctrl,
41321diff -urNp linux-2.6.39.1/drivers/tty/serial/pnx8xxx_uart.c linux-2.6.39.1/drivers/tty/serial/pnx8xxx_uart.c
41322--- linux-2.6.39.1/drivers/tty/serial/pnx8xxx_uart.c 2011-05-19 00:06:34.000000000 -0400
41323+++ linux-2.6.39.1/drivers/tty/serial/pnx8xxx_uart.c 2011-05-22 19:36:32.000000000 -0400
41324@@ -614,7 +614,7 @@ pnx8xxx_verify_port(struct uart_port *po
41325 return ret;
41326 }
41327
41328-static struct uart_ops pnx8xxx_pops = {
41329+static const struct uart_ops pnx8xxx_pops = {
41330 .tx_empty = pnx8xxx_tx_empty,
41331 .set_mctrl = pnx8xxx_set_mctrl,
41332 .get_mctrl = pnx8xxx_get_mctrl,
41333diff -urNp linux-2.6.39.1/drivers/tty/serial/pxa.c linux-2.6.39.1/drivers/tty/serial/pxa.c
41334--- linux-2.6.39.1/drivers/tty/serial/pxa.c 2011-05-19 00:06:34.000000000 -0400
41335+++ linux-2.6.39.1/drivers/tty/serial/pxa.c 2011-05-22 19:36:32.000000000 -0400
41336@@ -706,7 +706,7 @@ static struct console serial_pxa_console
41337 #define PXA_CONSOLE NULL
41338 #endif
41339
41340-struct uart_ops serial_pxa_pops = {
41341+const struct uart_ops serial_pxa_pops = {
41342 .tx_empty = serial_pxa_tx_empty,
41343 .set_mctrl = serial_pxa_set_mctrl,
41344 .get_mctrl = serial_pxa_get_mctrl,
41345diff -urNp linux-2.6.39.1/drivers/tty/serial/sa1100.c linux-2.6.39.1/drivers/tty/serial/sa1100.c
41346--- linux-2.6.39.1/drivers/tty/serial/sa1100.c 2011-05-19 00:06:34.000000000 -0400
41347+++ linux-2.6.39.1/drivers/tty/serial/sa1100.c 2011-05-22 19:36:32.000000000 -0400
41348@@ -577,7 +577,7 @@ sa1100_verify_port(struct uart_port *por
41349 return ret;
41350 }
41351
41352-static struct uart_ops sa1100_pops = {
41353+static const struct uart_ops sa1100_pops = {
41354 .tx_empty = sa1100_tx_empty,
41355 .set_mctrl = sa1100_set_mctrl,
41356 .get_mctrl = sa1100_get_mctrl,
41357diff -urNp linux-2.6.39.1/drivers/tty/serial/samsung.c linux-2.6.39.1/drivers/tty/serial/samsung.c
41358--- linux-2.6.39.1/drivers/tty/serial/samsung.c 2011-05-19 00:06:34.000000000 -0400
41359+++ linux-2.6.39.1/drivers/tty/serial/samsung.c 2011-05-22 19:36:32.000000000 -0400
41360@@ -860,7 +860,7 @@ static struct console s3c24xx_serial_con
41361 #define S3C24XX_SERIAL_CONSOLE NULL
41362 #endif
41363
41364-static struct uart_ops s3c24xx_serial_ops = {
41365+static const struct uart_ops s3c24xx_serial_ops = {
41366 .pm = s3c24xx_serial_pm,
41367 .tx_empty = s3c24xx_serial_tx_empty,
41368 .get_mctrl = s3c24xx_serial_get_mctrl,
41369diff -urNp linux-2.6.39.1/drivers/tty/serial/sc26xx.c linux-2.6.39.1/drivers/tty/serial/sc26xx.c
41370--- linux-2.6.39.1/drivers/tty/serial/sc26xx.c 2011-05-19 00:06:34.000000000 -0400
41371+++ linux-2.6.39.1/drivers/tty/serial/sc26xx.c 2011-05-22 19:36:32.000000000 -0400
41372@@ -515,7 +515,7 @@ static int sc26xx_verify_port(struct uar
41373 return -EINVAL;
41374 }
41375
41376-static struct uart_ops sc26xx_ops = {
41377+static const struct uart_ops sc26xx_ops = {
41378 .tx_empty = sc26xx_tx_empty,
41379 .set_mctrl = sc26xx_set_mctrl,
41380 .get_mctrl = sc26xx_get_mctrl,
41381diff -urNp linux-2.6.39.1/drivers/tty/serial/serial_ks8695.c linux-2.6.39.1/drivers/tty/serial/serial_ks8695.c
41382--- linux-2.6.39.1/drivers/tty/serial/serial_ks8695.c 2011-05-19 00:06:34.000000000 -0400
41383+++ linux-2.6.39.1/drivers/tty/serial/serial_ks8695.c 2011-05-22 19:36:32.000000000 -0400
41384@@ -528,7 +528,7 @@ static int ks8695uart_verify_port(struct
41385 return ret;
41386 }
41387
41388-static struct uart_ops ks8695uart_pops = {
41389+static const struct uart_ops ks8695uart_pops = {
41390 .tx_empty = ks8695uart_tx_empty,
41391 .set_mctrl = ks8695uart_set_mctrl,
41392 .get_mctrl = ks8695uart_get_mctrl,
41393diff -urNp linux-2.6.39.1/drivers/tty/serial/serial_txx9.c linux-2.6.39.1/drivers/tty/serial/serial_txx9.c
41394--- linux-2.6.39.1/drivers/tty/serial/serial_txx9.c 2011-05-19 00:06:34.000000000 -0400
41395+++ linux-2.6.39.1/drivers/tty/serial/serial_txx9.c 2011-05-22 19:36:32.000000000 -0400
41396@@ -857,7 +857,7 @@ serial_txx9_type(struct uart_port *port)
41397 return "txx9";
41398 }
41399
41400-static struct uart_ops serial_txx9_pops = {
41401+static const struct uart_ops serial_txx9_pops = {
41402 .tx_empty = serial_txx9_tx_empty,
41403 .set_mctrl = serial_txx9_set_mctrl,
41404 .get_mctrl = serial_txx9_get_mctrl,
41405diff -urNp linux-2.6.39.1/drivers/tty/serial/sn_console.c linux-2.6.39.1/drivers/tty/serial/sn_console.c
41406--- linux-2.6.39.1/drivers/tty/serial/sn_console.c 2011-05-19 00:06:34.000000000 -0400
41407+++ linux-2.6.39.1/drivers/tty/serial/sn_console.c 2011-05-22 19:36:32.000000000 -0400
41408@@ -388,7 +388,7 @@ static void snp_config_port(struct uart_
41409
41410 /* Associate the uart functions above - given to serial core */
41411
41412-static struct uart_ops sn_console_ops = {
41413+static const struct uart_ops sn_console_ops = {
41414 .tx_empty = snp_tx_empty,
41415 .set_mctrl = snp_set_mctrl,
41416 .get_mctrl = snp_get_mctrl,
41417diff -urNp linux-2.6.39.1/drivers/tty/serial/sunhv.c linux-2.6.39.1/drivers/tty/serial/sunhv.c
41418--- linux-2.6.39.1/drivers/tty/serial/sunhv.c 2011-05-19 00:06:34.000000000 -0400
41419+++ linux-2.6.39.1/drivers/tty/serial/sunhv.c 2011-05-22 19:36:32.000000000 -0400
41420@@ -168,12 +168,12 @@ struct sunhv_ops {
41421 int (*receive_chars)(struct uart_port *port, struct tty_struct *tty);
41422 };
41423
41424-static struct sunhv_ops bychar_ops = {
41425+static const struct sunhv_ops bychar_ops = {
41426 .transmit_chars = transmit_chars_putchar,
41427 .receive_chars = receive_chars_getchar,
41428 };
41429
41430-static struct sunhv_ops bywrite_ops = {
41431+static const struct sunhv_ops bywrite_ops = {
41432 .transmit_chars = transmit_chars_write,
41433 .receive_chars = receive_chars_read,
41434 };
41435@@ -370,7 +370,7 @@ static int sunhv_verify_port(struct uart
41436 return -EINVAL;
41437 }
41438
41439-static struct uart_ops sunhv_pops = {
41440+static const struct uart_ops sunhv_pops = {
41441 .tx_empty = sunhv_tx_empty,
41442 .set_mctrl = sunhv_set_mctrl,
41443 .get_mctrl = sunhv_get_mctrl,
41444diff -urNp linux-2.6.39.1/drivers/tty/serial/sunsab.c linux-2.6.39.1/drivers/tty/serial/sunsab.c
41445--- linux-2.6.39.1/drivers/tty/serial/sunsab.c 2011-05-19 00:06:34.000000000 -0400
41446+++ linux-2.6.39.1/drivers/tty/serial/sunsab.c 2011-05-22 19:36:32.000000000 -0400
41447@@ -804,7 +804,7 @@ static int sunsab_verify_port(struct uar
41448 return -EINVAL;
41449 }
41450
41451-static struct uart_ops sunsab_pops = {
41452+static const struct uart_ops sunsab_pops = {
41453 .tx_empty = sunsab_tx_empty,
41454 .set_mctrl = sunsab_set_mctrl,
41455 .get_mctrl = sunsab_get_mctrl,
41456diff -urNp linux-2.6.39.1/drivers/tty/serial/sunsu.c linux-2.6.39.1/drivers/tty/serial/sunsu.c
41457--- linux-2.6.39.1/drivers/tty/serial/sunsu.c 2011-05-19 00:06:34.000000000 -0400
41458+++ linux-2.6.39.1/drivers/tty/serial/sunsu.c 2011-05-22 19:36:32.000000000 -0400
41459@@ -946,7 +946,7 @@ sunsu_type(struct uart_port *port)
41460 return uart_config[type].name;
41461 }
41462
41463-static struct uart_ops sunsu_pops = {
41464+static const struct uart_ops sunsu_pops = {
41465 .tx_empty = sunsu_tx_empty,
41466 .set_mctrl = sunsu_set_mctrl,
41467 .get_mctrl = sunsu_get_mctrl,
41468diff -urNp linux-2.6.39.1/drivers/tty/serial/sunzilog.c linux-2.6.39.1/drivers/tty/serial/sunzilog.c
41469--- linux-2.6.39.1/drivers/tty/serial/sunzilog.c 2011-05-19 00:06:34.000000000 -0400
41470+++ linux-2.6.39.1/drivers/tty/serial/sunzilog.c 2011-05-22 19:36:32.000000000 -0400
41471@@ -1042,7 +1042,7 @@ static void sunzilog_put_poll_char(struc
41472 }
41473 #endif /* CONFIG_CONSOLE_POLL */
41474
41475-static struct uart_ops sunzilog_pops = {
41476+static const struct uart_ops sunzilog_pops = {
41477 .tx_empty = sunzilog_tx_empty,
41478 .set_mctrl = sunzilog_set_mctrl,
41479 .get_mctrl = sunzilog_get_mctrl,
41480diff -urNp linux-2.6.39.1/drivers/tty/serial/timbuart.c linux-2.6.39.1/drivers/tty/serial/timbuart.c
41481--- linux-2.6.39.1/drivers/tty/serial/timbuart.c 2011-05-19 00:06:34.000000000 -0400
41482+++ linux-2.6.39.1/drivers/tty/serial/timbuart.c 2011-05-22 19:36:32.000000000 -0400
41483@@ -394,7 +394,7 @@ static int timbuart_verify_port(struct u
41484 return -EINVAL;
41485 }
41486
41487-static struct uart_ops timbuart_ops = {
41488+static const struct uart_ops timbuart_ops = {
41489 .tx_empty = timbuart_tx_empty,
41490 .set_mctrl = timbuart_set_mctrl,
41491 .get_mctrl = timbuart_get_mctrl,
41492diff -urNp linux-2.6.39.1/drivers/tty/serial/uartlite.c linux-2.6.39.1/drivers/tty/serial/uartlite.c
41493--- linux-2.6.39.1/drivers/tty/serial/uartlite.c 2011-05-19 00:06:34.000000000 -0400
41494+++ linux-2.6.39.1/drivers/tty/serial/uartlite.c 2011-05-22 19:36:32.000000000 -0400
41495@@ -331,7 +331,7 @@ static void ulite_put_poll_char(struct u
41496 }
41497 #endif
41498
41499-static struct uart_ops ulite_ops = {
41500+static const struct uart_ops ulite_ops = {
41501 .tx_empty = ulite_tx_empty,
41502 .set_mctrl = ulite_set_mctrl,
41503 .get_mctrl = ulite_get_mctrl,
41504diff -urNp linux-2.6.39.1/drivers/tty/serial/ucc_uart.c linux-2.6.39.1/drivers/tty/serial/ucc_uart.c
41505--- linux-2.6.39.1/drivers/tty/serial/ucc_uart.c 2011-05-19 00:06:34.000000000 -0400
41506+++ linux-2.6.39.1/drivers/tty/serial/ucc_uart.c 2011-05-22 19:36:32.000000000 -0400
41507@@ -1088,7 +1088,7 @@ static int qe_uart_verify_port(struct ua
41508 *
41509 * Details on these functions can be found in Documentation/serial/driver
41510 */
41511-static struct uart_ops qe_uart_pops = {
41512+static const struct uart_ops qe_uart_pops = {
41513 .tx_empty = qe_uart_tx_empty,
41514 .set_mctrl = qe_uart_set_mctrl,
41515 .get_mctrl = qe_uart_get_mctrl,
41516diff -urNp linux-2.6.39.1/drivers/tty/serial/vr41xx_siu.c linux-2.6.39.1/drivers/tty/serial/vr41xx_siu.c
41517--- linux-2.6.39.1/drivers/tty/serial/vr41xx_siu.c 2011-05-19 00:06:34.000000000 -0400
41518+++ linux-2.6.39.1/drivers/tty/serial/vr41xx_siu.c 2011-05-22 19:36:32.000000000 -0400
41519@@ -683,7 +683,7 @@ static int siu_verify_port(struct uart_p
41520 return 0;
41521 }
41522
41523-static struct uart_ops siu_uart_ops = {
41524+static const struct uart_ops siu_uart_ops = {
41525 .tx_empty = siu_tx_empty,
41526 .set_mctrl = siu_set_mctrl,
41527 .get_mctrl = siu_get_mctrl,
41528diff -urNp linux-2.6.39.1/drivers/tty/serial/vt8500_serial.c linux-2.6.39.1/drivers/tty/serial/vt8500_serial.c
41529--- linux-2.6.39.1/drivers/tty/serial/vt8500_serial.c 2011-05-19 00:06:34.000000000 -0400
41530+++ linux-2.6.39.1/drivers/tty/serial/vt8500_serial.c 2011-05-22 19:36:32.000000000 -0400
41531@@ -519,7 +519,7 @@ static struct console vt8500_console = {
41532 #define VT8500_CONSOLE NULL
41533 #endif
41534
41535-static struct uart_ops vt8500_uart_pops = {
41536+static const struct uart_ops vt8500_uart_pops = {
41537 .tx_empty = vt8500_tx_empty,
41538 .set_mctrl = vt8500_set_mctrl,
41539 .get_mctrl = vt8500_get_mctrl,
41540diff -urNp linux-2.6.39.1/drivers/tty/serial/zs.c linux-2.6.39.1/drivers/tty/serial/zs.c
41541--- linux-2.6.39.1/drivers/tty/serial/zs.c 2011-05-19 00:06:34.000000000 -0400
41542+++ linux-2.6.39.1/drivers/tty/serial/zs.c 2011-05-22 19:36:32.000000000 -0400
41543@@ -1044,7 +1044,7 @@ static int zs_verify_port(struct uart_po
41544 }
41545
41546
41547-static struct uart_ops zs_ops = {
41548+static const struct uart_ops zs_ops = {
41549 .tx_empty = zs_tx_empty,
41550 .set_mctrl = zs_set_mctrl,
41551 .get_mctrl = zs_get_mctrl,
41552diff -urNp linux-2.6.39.1/drivers/tty/tty_io.c linux-2.6.39.1/drivers/tty/tty_io.c
41553--- linux-2.6.39.1/drivers/tty/tty_io.c 2011-05-19 00:06:34.000000000 -0400
41554+++ linux-2.6.39.1/drivers/tty/tty_io.c 2011-05-22 19:36:32.000000000 -0400
41555@@ -139,21 +139,11 @@ EXPORT_SYMBOL(tty_mutex);
41556 /* Spinlock to protect the tty->tty_files list */
41557 DEFINE_SPINLOCK(tty_files_lock);
41558
41559-static ssize_t tty_read(struct file *, char __user *, size_t, loff_t *);
41560-static ssize_t tty_write(struct file *, const char __user *, size_t, loff_t *);
41561 ssize_t redirected_tty_write(struct file *, const char __user *,
41562 size_t, loff_t *);
41563-static unsigned int tty_poll(struct file *, poll_table *);
41564 static int tty_open(struct inode *, struct file *);
41565 long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
41566-#ifdef CONFIG_COMPAT
41567-static long tty_compat_ioctl(struct file *file, unsigned int cmd,
41568- unsigned long arg);
41569-#else
41570-#define tty_compat_ioctl NULL
41571-#endif
41572 static int __tty_fasync(int fd, struct file *filp, int on);
41573-static int tty_fasync(int fd, struct file *filp, int on);
41574 static void release_tty(struct tty_struct *tty, int idx);
41575 static void __proc_set_tty(struct task_struct *tsk, struct tty_struct *tty);
41576 static void proc_set_tty(struct task_struct *tsk, struct tty_struct *tty);
41577@@ -937,7 +927,7 @@ EXPORT_SYMBOL(start_tty);
41578 * read calls may be outstanding in parallel.
41579 */
41580
41581-static ssize_t tty_read(struct file *file, char __user *buf, size_t count,
41582+ssize_t tty_read(struct file *file, char __user *buf, size_t count,
41583 loff_t *ppos)
41584 {
41585 int i;
41586@@ -963,6 +953,8 @@ static ssize_t tty_read(struct file *fil
41587 return i;
41588 }
41589
41590+EXPORT_SYMBOL(tty_read);
41591+
41592 void tty_write_unlock(struct tty_struct *tty)
41593 {
41594 mutex_unlock(&tty->atomic_write_lock);
41595@@ -1112,7 +1104,7 @@ void tty_write_message(struct tty_struct
41596 * write method will not be invoked in parallel for each device.
41597 */
41598
41599-static ssize_t tty_write(struct file *file, const char __user *buf,
41600+ssize_t tty_write(struct file *file, const char __user *buf,
41601 size_t count, loff_t *ppos)
41602 {
41603 struct inode *inode = file->f_path.dentry->d_inode;
41604@@ -1138,6 +1130,8 @@ static ssize_t tty_write(struct file *fi
41605 return ret;
41606 }
41607
41608+EXPORT_SYMBOL(tty_write);
41609+
41610 ssize_t redirected_tty_write(struct file *file, const char __user *buf,
41611 size_t count, loff_t *ppos)
41612 {
41613@@ -1777,6 +1771,8 @@ int tty_release(struct inode *inode, str
41614 return 0;
41615 }
41616
41617+EXPORT_SYMBOL(tty_release);
41618+
41619 /**
41620 * tty_open - open a tty device
41621 * @inode: inode of device file
41622@@ -1968,7 +1964,7 @@ got_driver:
41623 * may be re-entered freely by other callers.
41624 */
41625
41626-static unsigned int tty_poll(struct file *filp, poll_table *wait)
41627+unsigned int tty_poll(struct file *filp, poll_table *wait)
41628 {
41629 struct tty_struct *tty = file_tty(filp);
41630 struct tty_ldisc *ld;
41631@@ -1984,6 +1980,8 @@ static unsigned int tty_poll(struct file
41632 return ret;
41633 }
41634
41635+EXPORT_SYMBOL(tty_poll);
41636+
41637 static int __tty_fasync(int fd, struct file *filp, int on)
41638 {
41639 struct tty_struct *tty = file_tty(filp);
41640@@ -2025,7 +2023,7 @@ out:
41641 return retval;
41642 }
41643
41644-static int tty_fasync(int fd, struct file *filp, int on)
41645+int tty_fasync(int fd, struct file *filp, int on)
41646 {
41647 int retval;
41648 tty_lock();
41649@@ -2034,6 +2032,8 @@ static int tty_fasync(int fd, struct fil
41650 return retval;
41651 }
41652
41653+EXPORT_SYMBOL(tty_fasync);
41654+
41655 /**
41656 * tiocsti - fake input character
41657 * @tty: tty to fake input into
41658@@ -2695,8 +2695,10 @@ long tty_ioctl(struct file *file, unsign
41659 return retval;
41660 }
41661
41662+EXPORT_SYMBOL(tty_ioctl);
41663+
41664 #ifdef CONFIG_COMPAT
41665-static long tty_compat_ioctl(struct file *file, unsigned int cmd,
41666+long tty_compat_ioctl(struct file *file, unsigned int cmd,
41667 unsigned long arg)
41668 {
41669 struct inode *inode = file->f_dentry->d_inode;
41670@@ -2720,6 +2722,9 @@ static long tty_compat_ioctl(struct file
41671
41672 return retval;
41673 }
41674+
41675+EXPORT_SYMBOL(tty_compat_ioctl);
41676+
41677 #endif
41678
41679 /*
41680@@ -3198,11 +3203,6 @@ struct tty_struct *get_current_tty(void)
41681 }
41682 EXPORT_SYMBOL_GPL(get_current_tty);
41683
41684-void tty_default_fops(struct file_operations *fops)
41685-{
41686- *fops = tty_fops;
41687-}
41688-
41689 /*
41690 * Initialize the console device. This is called *early*, so
41691 * we can't necessarily depend on lots of kernel help here.
41692diff -urNp linux-2.6.39.1/drivers/tty/tty_ldisc.c linux-2.6.39.1/drivers/tty/tty_ldisc.c
41693--- linux-2.6.39.1/drivers/tty/tty_ldisc.c 2011-05-19 00:06:34.000000000 -0400
41694+++ linux-2.6.39.1/drivers/tty/tty_ldisc.c 2011-05-22 19:36:32.000000000 -0400
41695@@ -74,7 +74,7 @@ static void put_ldisc(struct tty_ldisc *
41696 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
41697 struct tty_ldisc_ops *ldo = ld->ops;
41698
41699- ldo->refcount--;
41700+ atomic_dec(&ldo->refcount);
41701 module_put(ldo->owner);
41702 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
41703
41704@@ -109,7 +109,7 @@ int tty_register_ldisc(int disc, struct
41705 spin_lock_irqsave(&tty_ldisc_lock, flags);
41706 tty_ldiscs[disc] = new_ldisc;
41707 new_ldisc->num = disc;
41708- new_ldisc->refcount = 0;
41709+ atomic_set(&new_ldisc->refcount, 0);
41710 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
41711
41712 return ret;
41713@@ -137,7 +137,7 @@ int tty_unregister_ldisc(int disc)
41714 return -EINVAL;
41715
41716 spin_lock_irqsave(&tty_ldisc_lock, flags);
41717- if (tty_ldiscs[disc]->refcount)
41718+ if (atomic_read(&tty_ldiscs[disc]->refcount))
41719 ret = -EBUSY;
41720 else
41721 tty_ldiscs[disc] = NULL;
41722@@ -158,7 +158,7 @@ static struct tty_ldisc_ops *get_ldops(i
41723 if (ldops) {
41724 ret = ERR_PTR(-EAGAIN);
41725 if (try_module_get(ldops->owner)) {
41726- ldops->refcount++;
41727+ atomic_inc(&ldops->refcount);
41728 ret = ldops;
41729 }
41730 }
41731@@ -171,7 +171,7 @@ static void put_ldops(struct tty_ldisc_o
41732 unsigned long flags;
41733
41734 spin_lock_irqsave(&tty_ldisc_lock, flags);
41735- ldops->refcount--;
41736+ atomic_dec(&ldops->refcount);
41737 module_put(ldops->owner);
41738 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
41739 }
41740diff -urNp linux-2.6.39.1/drivers/tty/vt/keyboard.c linux-2.6.39.1/drivers/tty/vt/keyboard.c
41741--- linux-2.6.39.1/drivers/tty/vt/keyboard.c 2011-05-19 00:06:34.000000000 -0400
41742+++ linux-2.6.39.1/drivers/tty/vt/keyboard.c 2011-05-22 20:32:43.000000000 -0400
41743@@ -658,6 +658,16 @@ static void k_spec(struct vc_data *vc, u
41744 kbd->kbdmode == VC_OFF) &&
41745 value != KVAL(K_SAK))
41746 return; /* SAK is allowed even in raw mode */
41747+
41748+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
41749+ {
41750+ void *func = fn_handler[value];
41751+ if (func == fn_show_state || func == fn_show_ptregs ||
41752+ func == fn_show_mem)
41753+ return;
41754+ }
41755+#endif
41756+
41757 fn_handler[value](vc);
41758 }
41759
41760diff -urNp linux-2.6.39.1/drivers/tty/vt/vt.c linux-2.6.39.1/drivers/tty/vt/vt.c
41761--- linux-2.6.39.1/drivers/tty/vt/vt.c 2011-05-19 00:06:34.000000000 -0400
41762+++ linux-2.6.39.1/drivers/tty/vt/vt.c 2011-05-22 19:36:32.000000000 -0400
41763@@ -261,7 +261,7 @@ EXPORT_SYMBOL_GPL(unregister_vt_notifier
41764
41765 static void notify_write(struct vc_data *vc, unsigned int unicode)
41766 {
41767- struct vt_notifier_param param = { .vc = vc, unicode = unicode };
41768+ struct vt_notifier_param param = { .vc = vc, .c = unicode };
41769 atomic_notifier_call_chain(&vt_notifier_list, VT_WRITE, &param);
41770 }
41771
41772diff -urNp linux-2.6.39.1/drivers/tty/vt/vt_ioctl.c linux-2.6.39.1/drivers/tty/vt/vt_ioctl.c
41773--- linux-2.6.39.1/drivers/tty/vt/vt_ioctl.c 2011-05-19 00:06:34.000000000 -0400
41774+++ linux-2.6.39.1/drivers/tty/vt/vt_ioctl.c 2011-05-22 19:41:37.000000000 -0400
41775@@ -209,9 +209,6 @@ do_kdsk_ioctl(int cmd, struct kbentry __
41776 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
41777 return -EFAULT;
41778
41779- if (!capable(CAP_SYS_TTY_CONFIG))
41780- perm = 0;
41781-
41782 switch (cmd) {
41783 case KDGKBENT:
41784 key_map = key_maps[s];
41785@@ -223,6 +220,9 @@ do_kdsk_ioctl(int cmd, struct kbentry __
41786 val = (i ? K_HOLE : K_NOSUCHMAP);
41787 return put_user(val, &user_kbe->kb_value);
41788 case KDSKBENT:
41789+ if (!capable(CAP_SYS_TTY_CONFIG))
41790+ perm = 0;
41791+
41792 if (!perm)
41793 return -EPERM;
41794 if (!i && v == K_NOSUCHMAP) {
41795@@ -324,9 +324,6 @@ do_kdgkb_ioctl(int cmd, struct kbsentry
41796 int i, j, k;
41797 int ret;
41798
41799- if (!capable(CAP_SYS_TTY_CONFIG))
41800- perm = 0;
41801-
41802 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
41803 if (!kbs) {
41804 ret = -ENOMEM;
41805@@ -360,6 +357,9 @@ do_kdgkb_ioctl(int cmd, struct kbsentry
41806 kfree(kbs);
41807 return ((p && *p) ? -EOVERFLOW : 0);
41808 case KDSKBSENT:
41809+ if (!capable(CAP_SYS_TTY_CONFIG))
41810+ perm = 0;
41811+
41812 if (!perm) {
41813 ret = -EPERM;
41814 goto reterr;
41815diff -urNp linux-2.6.39.1/drivers/uio/uio.c linux-2.6.39.1/drivers/uio/uio.c
41816--- linux-2.6.39.1/drivers/uio/uio.c 2011-05-19 00:06:34.000000000 -0400
41817+++ linux-2.6.39.1/drivers/uio/uio.c 2011-05-22 19:36:32.000000000 -0400
41818@@ -25,6 +25,7 @@
41819 #include <linux/kobject.h>
41820 #include <linux/cdev.h>
41821 #include <linux/uio_driver.h>
41822+#include <asm/local.h>
41823
41824 #define UIO_MAX_DEVICES (1U << MINORBITS)
41825
41826@@ -32,10 +33,10 @@ struct uio_device {
41827 struct module *owner;
41828 struct device *dev;
41829 int minor;
41830- atomic_t event;
41831+ atomic_unchecked_t event;
41832 struct fasync_struct *async_queue;
41833 wait_queue_head_t wait;
41834- int vma_count;
41835+ local_t vma_count;
41836 struct uio_info *info;
41837 struct kobject *map_dir;
41838 struct kobject *portio_dir;
41839@@ -242,7 +243,7 @@ static ssize_t show_event(struct device
41840 struct device_attribute *attr, char *buf)
41841 {
41842 struct uio_device *idev = dev_get_drvdata(dev);
41843- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
41844+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
41845 }
41846
41847 static struct device_attribute uio_class_attributes[] = {
41848@@ -402,7 +403,7 @@ void uio_event_notify(struct uio_info *i
41849 {
41850 struct uio_device *idev = info->uio_dev;
41851
41852- atomic_inc(&idev->event);
41853+ atomic_inc_unchecked(&idev->event);
41854 wake_up_interruptible(&idev->wait);
41855 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
41856 }
41857@@ -455,7 +456,7 @@ static int uio_open(struct inode *inode,
41858 }
41859
41860 listener->dev = idev;
41861- listener->event_count = atomic_read(&idev->event);
41862+ listener->event_count = atomic_read_unchecked(&idev->event);
41863 filep->private_data = listener;
41864
41865 if (idev->info->open) {
41866@@ -506,7 +507,7 @@ static unsigned int uio_poll(struct file
41867 return -EIO;
41868
41869 poll_wait(filep, &idev->wait, wait);
41870- if (listener->event_count != atomic_read(&idev->event))
41871+ if (listener->event_count != atomic_read_unchecked(&idev->event))
41872 return POLLIN | POLLRDNORM;
41873 return 0;
41874 }
41875@@ -531,7 +532,7 @@ static ssize_t uio_read(struct file *fil
41876 do {
41877 set_current_state(TASK_INTERRUPTIBLE);
41878
41879- event_count = atomic_read(&idev->event);
41880+ event_count = atomic_read_unchecked(&idev->event);
41881 if (event_count != listener->event_count) {
41882 if (copy_to_user(buf, &event_count, count))
41883 retval = -EFAULT;
41884@@ -602,13 +603,13 @@ static int uio_find_mem_index(struct vm_
41885 static void uio_vma_open(struct vm_area_struct *vma)
41886 {
41887 struct uio_device *idev = vma->vm_private_data;
41888- idev->vma_count++;
41889+ local_inc(&idev->vma_count);
41890 }
41891
41892 static void uio_vma_close(struct vm_area_struct *vma)
41893 {
41894 struct uio_device *idev = vma->vm_private_data;
41895- idev->vma_count--;
41896+ local_dec(&idev->vma_count);
41897 }
41898
41899 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41900@@ -819,7 +820,7 @@ int __uio_register_device(struct module
41901 idev->owner = owner;
41902 idev->info = info;
41903 init_waitqueue_head(&idev->wait);
41904- atomic_set(&idev->event, 0);
41905+ atomic_set_unchecked(&idev->event, 0);
41906
41907 ret = uio_get_minor(idev);
41908 if (ret)
41909diff -urNp linux-2.6.39.1/drivers/usb/atm/cxacru.c linux-2.6.39.1/drivers/usb/atm/cxacru.c
41910--- linux-2.6.39.1/drivers/usb/atm/cxacru.c 2011-05-19 00:06:34.000000000 -0400
41911+++ linux-2.6.39.1/drivers/usb/atm/cxacru.c 2011-05-22 19:36:32.000000000 -0400
41912@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_c
41913 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
41914 if (ret < 2)
41915 return -EINVAL;
41916- if (index < 0 || index > 0x7f)
41917+ if (index > 0x7f)
41918 return -EINVAL;
41919 pos += tmp;
41920
41921diff -urNp linux-2.6.39.1/drivers/usb/atm/usbatm.c linux-2.6.39.1/drivers/usb/atm/usbatm.c
41922--- linux-2.6.39.1/drivers/usb/atm/usbatm.c 2011-05-19 00:06:34.000000000 -0400
41923+++ linux-2.6.39.1/drivers/usb/atm/usbatm.c 2011-05-22 19:36:32.000000000 -0400
41924@@ -332,7 +332,7 @@ static void usbatm_extract_one_cell(stru
41925 if (printk_ratelimit())
41926 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
41927 __func__, vpi, vci);
41928- atomic_inc(&vcc->stats->rx_err);
41929+ atomic_inc_unchecked(&vcc->stats->rx_err);
41930 return;
41931 }
41932
41933@@ -360,7 +360,7 @@ static void usbatm_extract_one_cell(stru
41934 if (length > ATM_MAX_AAL5_PDU) {
41935 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
41936 __func__, length, vcc);
41937- atomic_inc(&vcc->stats->rx_err);
41938+ atomic_inc_unchecked(&vcc->stats->rx_err);
41939 goto out;
41940 }
41941
41942@@ -369,14 +369,14 @@ static void usbatm_extract_one_cell(stru
41943 if (sarb->len < pdu_length) {
41944 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
41945 __func__, pdu_length, sarb->len, vcc);
41946- atomic_inc(&vcc->stats->rx_err);
41947+ atomic_inc_unchecked(&vcc->stats->rx_err);
41948 goto out;
41949 }
41950
41951 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
41952 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
41953 __func__, vcc);
41954- atomic_inc(&vcc->stats->rx_err);
41955+ atomic_inc_unchecked(&vcc->stats->rx_err);
41956 goto out;
41957 }
41958
41959@@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(stru
41960 if (printk_ratelimit())
41961 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
41962 __func__, length);
41963- atomic_inc(&vcc->stats->rx_drop);
41964+ atomic_inc_unchecked(&vcc->stats->rx_drop);
41965 goto out;
41966 }
41967
41968@@ -411,7 +411,7 @@ static void usbatm_extract_one_cell(stru
41969
41970 vcc->push(vcc, skb);
41971
41972- atomic_inc(&vcc->stats->rx);
41973+ atomic_inc_unchecked(&vcc->stats->rx);
41974 out:
41975 skb_trim(sarb, 0);
41976 }
41977@@ -614,7 +614,7 @@ static void usbatm_tx_process(unsigned l
41978 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
41979
41980 usbatm_pop(vcc, skb);
41981- atomic_inc(&vcc->stats->tx);
41982+ atomic_inc_unchecked(&vcc->stats->tx);
41983
41984 skb = skb_dequeue(&instance->sndqueue);
41985 }
41986@@ -773,11 +773,11 @@ static int usbatm_atm_proc_read(struct a
41987 if (!left--)
41988 return sprintf(page,
41989 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
41990- atomic_read(&atm_dev->stats.aal5.tx),
41991- atomic_read(&atm_dev->stats.aal5.tx_err),
41992- atomic_read(&atm_dev->stats.aal5.rx),
41993- atomic_read(&atm_dev->stats.aal5.rx_err),
41994- atomic_read(&atm_dev->stats.aal5.rx_drop));
41995+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
41996+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
41997+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
41998+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
41999+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
42000
42001 if (!left--) {
42002 if (instance->disconnected)
42003diff -urNp linux-2.6.39.1/drivers/usb/core/devices.c linux-2.6.39.1/drivers/usb/core/devices.c
42004--- linux-2.6.39.1/drivers/usb/core/devices.c 2011-05-19 00:06:34.000000000 -0400
42005+++ linux-2.6.39.1/drivers/usb/core/devices.c 2011-05-22 19:36:32.000000000 -0400
42006@@ -126,7 +126,7 @@ static const char *format_endpt =
42007 * time it gets called.
42008 */
42009 static struct device_connect_event {
42010- atomic_t count;
42011+ atomic_unchecked_t count;
42012 wait_queue_head_t wait;
42013 } device_event = {
42014 .count = ATOMIC_INIT(1),
42015@@ -164,7 +164,7 @@ static const struct class_info clas_info
42016
42017 void usbfs_conn_disc_event(void)
42018 {
42019- atomic_add(2, &device_event.count);
42020+ atomic_add_unchecked(2, &device_event.count);
42021 wake_up(&device_event.wait);
42022 }
42023
42024@@ -648,7 +648,7 @@ static unsigned int usb_device_poll(stru
42025
42026 poll_wait(file, &device_event.wait, wait);
42027
42028- event_count = atomic_read(&device_event.count);
42029+ event_count = atomic_read_unchecked(&device_event.count);
42030 if (file->f_version != event_count) {
42031 file->f_version = event_count;
42032 return POLLIN | POLLRDNORM;
42033diff -urNp linux-2.6.39.1/drivers/usb/core/hcd.c linux-2.6.39.1/drivers/usb/core/hcd.c
42034--- linux-2.6.39.1/drivers/usb/core/hcd.c 2011-06-03 00:04:14.000000000 -0400
42035+++ linux-2.6.39.1/drivers/usb/core/hcd.c 2011-06-03 00:32:07.000000000 -0400
42036@@ -2574,7 +2574,7 @@ EXPORT_SYMBOL_GPL(usb_hcd_platform_shutd
42037
42038 #if defined(CONFIG_USB_MON) || defined(CONFIG_USB_MON_MODULE)
42039
42040-struct usb_mon_operations *mon_ops;
42041+const struct usb_mon_operations *mon_ops;
42042
42043 /*
42044 * The registration is unlocked.
42045@@ -2584,7 +2584,7 @@ struct usb_mon_operations *mon_ops;
42046 * symbols from usbcore, usbcore gets referenced and cannot be unloaded first.
42047 */
42048
42049-int usb_mon_register (struct usb_mon_operations *ops)
42050+int usb_mon_register (const struct usb_mon_operations *ops)
42051 {
42052
42053 if (mon_ops)
42054diff -urNp linux-2.6.39.1/drivers/usb/core/message.c linux-2.6.39.1/drivers/usb/core/message.c
42055--- linux-2.6.39.1/drivers/usb/core/message.c 2011-05-19 00:06:34.000000000 -0400
42056+++ linux-2.6.39.1/drivers/usb/core/message.c 2011-05-22 19:36:32.000000000 -0400
42057@@ -869,8 +869,8 @@ char *usb_cache_string(struct usb_device
42058 buf = kmalloc(MAX_USB_STRING_SIZE, GFP_NOIO);
42059 if (buf) {
42060 len = usb_string(udev, index, buf, MAX_USB_STRING_SIZE);
42061- if (len > 0) {
42062- smallbuf = kmalloc(++len, GFP_NOIO);
42063+ if (len++ > 0) {
42064+ smallbuf = kmalloc(len, GFP_NOIO);
42065 if (!smallbuf)
42066 return buf;
42067 memcpy(smallbuf, buf, len);
42068diff -urNp linux-2.6.39.1/drivers/usb/early/ehci-dbgp.c linux-2.6.39.1/drivers/usb/early/ehci-dbgp.c
42069--- linux-2.6.39.1/drivers/usb/early/ehci-dbgp.c 2011-05-19 00:06:34.000000000 -0400
42070+++ linux-2.6.39.1/drivers/usb/early/ehci-dbgp.c 2011-05-22 19:36:32.000000000 -0400
42071@@ -96,7 +96,7 @@ static inline u32 dbgp_len_update(u32 x,
42072 }
42073
42074 #ifdef CONFIG_KGDB
42075-static struct kgdb_io kgdbdbgp_io_ops;
42076+static struct kgdb_io kgdbdbgp_io_ops; /* cannot be const, see kgdbdbgp_parse_config */
42077 #define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
42078 #else
42079 #define dbgp_kgdb_mode (0)
42080@@ -1026,7 +1026,7 @@ static void kgdbdbgp_write_char(u8 chr)
42081 early_dbgp_write(NULL, &chr, 1);
42082 }
42083
42084-static struct kgdb_io kgdbdbgp_io_ops = {
42085+static struct kgdb_io kgdbdbgp_io_ops = { /* cannot be const, see kgdbdbgp_parse_config() */
42086 .name = "kgdbdbgp",
42087 .read_char = kgdbdbgp_read_char,
42088 .write_char = kgdbdbgp_write_char,
42089diff -urNp linux-2.6.39.1/drivers/usb/gadget/fsl_qe_udc.c linux-2.6.39.1/drivers/usb/gadget/fsl_qe_udc.c
42090--- linux-2.6.39.1/drivers/usb/gadget/fsl_qe_udc.c 2011-05-19 00:06:34.000000000 -0400
42091+++ linux-2.6.39.1/drivers/usb/gadget/fsl_qe_udc.c 2011-05-22 19:36:32.000000000 -0400
42092@@ -1859,7 +1859,7 @@ out:
42093 return status;
42094 }
42095
42096-static struct usb_ep_ops qe_ep_ops = {
42097+static const struct usb_ep_ops qe_ep_ops = {
42098 .enable = qe_ep_enable,
42099 .disable = qe_ep_disable,
42100
42101@@ -1928,7 +1928,7 @@ static int qe_pullup(struct usb_gadget *
42102 }
42103
42104 /* defined in usb_gadget.h */
42105-static struct usb_gadget_ops qe_gadget_ops = {
42106+static const struct usb_gadget_ops qe_gadget_ops = {
42107 .get_frame = qe_get_frame,
42108 .wakeup = qe_wakeup,
42109 /* .set_selfpowered = qe_set_selfpowered,*/ /* always selfpowered */
42110diff -urNp linux-2.6.39.1/drivers/usb/gadget/fsl_udc_core.c linux-2.6.39.1/drivers/usb/gadget/fsl_udc_core.c
42111--- linux-2.6.39.1/drivers/usb/gadget/fsl_udc_core.c 2011-05-19 00:06:34.000000000 -0400
42112+++ linux-2.6.39.1/drivers/usb/gadget/fsl_udc_core.c 2011-05-22 19:36:32.000000000 -0400
42113@@ -1003,7 +1003,7 @@ static void fsl_ep_fifo_flush(struct usb
42114 } while (fsl_readl(&dr_regs->endptstatus) & bits);
42115 }
42116
42117-static struct usb_ep_ops fsl_ep_ops = {
42118+static const struct usb_ep_ops fsl_ep_ops = {
42119 .enable = fsl_ep_enable,
42120 .disable = fsl_ep_disable,
42121
42122@@ -1114,7 +1114,7 @@ static int fsl_pullup(struct usb_gadget
42123 }
42124
42125 /* defined in gadget.h */
42126-static struct usb_gadget_ops fsl_gadget_ops = {
42127+static const struct usb_gadget_ops fsl_gadget_ops = {
42128 .get_frame = fsl_get_frame,
42129 .wakeup = fsl_wakeup,
42130 /* .set_selfpowered = fsl_set_selfpowered, */ /* Always selfpowered */
42131diff -urNp linux-2.6.39.1/drivers/usb/gadget/fusb300_udc.c linux-2.6.39.1/drivers/usb/gadget/fusb300_udc.c
42132--- linux-2.6.39.1/drivers/usb/gadget/fusb300_udc.c 2011-05-19 00:06:34.000000000 -0400
42133+++ linux-2.6.39.1/drivers/usb/gadget/fusb300_udc.c 2011-05-22 19:36:32.000000000 -0400
42134@@ -527,7 +527,7 @@ static void fusb300_fifo_flush(struct us
42135 {
42136 }
42137
42138-static struct usb_ep_ops fusb300_ep_ops = {
42139+static const struct usb_ep_ops fusb300_ep_ops = {
42140 .enable = fusb300_enable,
42141 .disable = fusb300_disable,
42142
42143@@ -1570,7 +1570,7 @@ static int fusb300_udc_pullup(struct usb
42144 return 0;
42145 }
42146
42147-static struct usb_gadget_ops fusb300_gadget_ops = {
42148+static const struct usb_gadget_ops fusb300_gadget_ops = {
42149 .pullup = fusb300_udc_pullup,
42150 };
42151
42152diff -urNp linux-2.6.39.1/drivers/usb/gadget/goku_udc.c linux-2.6.39.1/drivers/usb/gadget/goku_udc.c
42153--- linux-2.6.39.1/drivers/usb/gadget/goku_udc.c 2011-05-19 00:06:34.000000000 -0400
42154+++ linux-2.6.39.1/drivers/usb/gadget/goku_udc.c 2011-05-22 19:36:32.000000000 -0400
42155@@ -973,7 +973,7 @@ static void goku_fifo_flush(struct usb_e
42156 command(regs, COMMAND_FIFO_CLEAR, ep->num);
42157 }
42158
42159-static struct usb_ep_ops goku_ep_ops = {
42160+static const struct usb_ep_ops goku_ep_ops = {
42161 .enable = goku_ep_enable,
42162 .disable = goku_ep_disable,
42163
42164diff -urNp linux-2.6.39.1/drivers/usb/gadget/imx_udc.c linux-2.6.39.1/drivers/usb/gadget/imx_udc.c
42165--- linux-2.6.39.1/drivers/usb/gadget/imx_udc.c 2011-05-19 00:06:34.000000000 -0400
42166+++ linux-2.6.39.1/drivers/usb/gadget/imx_udc.c 2011-05-22 19:36:32.000000000 -0400
42167@@ -937,7 +937,7 @@ static void imx_ep_fifo_flush(struct usb
42168 local_irq_restore(flags);
42169 }
42170
42171-static struct usb_ep_ops imx_ep_ops = {
42172+static const struct usb_ep_ops imx_ep_ops = {
42173 .enable = imx_ep_enable,
42174 .disable = imx_ep_disable,
42175
42176diff -urNp linux-2.6.39.1/drivers/usb/gadget/m66592-udc.c linux-2.6.39.1/drivers/usb/gadget/m66592-udc.c
42177--- linux-2.6.39.1/drivers/usb/gadget/m66592-udc.c 2011-05-19 00:06:34.000000000 -0400
42178+++ linux-2.6.39.1/drivers/usb/gadget/m66592-udc.c 2011-05-22 19:36:32.000000000 -0400
42179@@ -1437,7 +1437,7 @@ static void m66592_fifo_flush(struct usb
42180 spin_unlock_irqrestore(&ep->m66592->lock, flags);
42181 }
42182
42183-static struct usb_ep_ops m66592_ep_ops = {
42184+static const struct usb_ep_ops m66592_ep_ops = {
42185 .enable = m66592_enable,
42186 .disable = m66592_disable,
42187
42188@@ -1542,7 +1542,7 @@ static int m66592_get_frame(struct usb_g
42189 return m66592_read(m66592, M66592_FRMNUM) & 0x03FF;
42190 }
42191
42192-static struct usb_gadget_ops m66592_gadget_ops = {
42193+static const struct usb_gadget_ops m66592_gadget_ops = {
42194 .get_frame = m66592_get_frame,
42195 };
42196
42197diff -urNp linux-2.6.39.1/drivers/usb/gadget/mv_udc_core.c linux-2.6.39.1/drivers/usb/gadget/mv_udc_core.c
42198--- linux-2.6.39.1/drivers/usb/gadget/mv_udc_core.c 2011-05-19 00:06:34.000000000 -0400
42199+++ linux-2.6.39.1/drivers/usb/gadget/mv_udc_core.c 2011-05-22 19:36:32.000000000 -0400
42200@@ -972,7 +972,7 @@ static int mv_ep_set_wedge(struct usb_ep
42201 return mv_ep_set_halt_wedge(_ep, 1, 1);
42202 }
42203
42204-static struct usb_ep_ops mv_ep_ops = {
42205+static const struct usb_ep_ops mv_ep_ops = {
42206 .enable = mv_ep_enable,
42207 .disable = mv_ep_disable,
42208
42209diff -urNp linux-2.6.39.1/drivers/usb/gadget/omap_udc.c linux-2.6.39.1/drivers/usb/gadget/omap_udc.c
42210--- linux-2.6.39.1/drivers/usb/gadget/omap_udc.c 2011-05-19 00:06:34.000000000 -0400
42211+++ linux-2.6.39.1/drivers/usb/gadget/omap_udc.c 2011-05-22 19:36:32.000000000 -0400
42212@@ -1177,7 +1177,7 @@ done:
42213 return status;
42214 }
42215
42216-static struct usb_ep_ops omap_ep_ops = {
42217+static const struct usb_ep_ops omap_ep_ops = {
42218 .enable = omap_ep_enable,
42219 .disable = omap_ep_disable,
42220
42221@@ -1374,7 +1374,7 @@ static int omap_pullup(struct usb_gadget
42222 return 0;
42223 }
42224
42225-static struct usb_gadget_ops omap_gadget_ops = {
42226+static const struct usb_gadget_ops omap_gadget_ops = {
42227 .get_frame = omap_get_frame,
42228 .wakeup = omap_wakeup,
42229 .set_selfpowered = omap_set_selfpowered,
42230diff -urNp linux-2.6.39.1/drivers/usb/gadget/pxa25x_udc.c linux-2.6.39.1/drivers/usb/gadget/pxa25x_udc.c
42231--- linux-2.6.39.1/drivers/usb/gadget/pxa25x_udc.c 2011-05-19 00:06:34.000000000 -0400
42232+++ linux-2.6.39.1/drivers/usb/gadget/pxa25x_udc.c 2011-05-22 19:36:32.000000000 -0400
42233@@ -896,7 +896,7 @@ static void pxa25x_ep_fifo_flush(struct
42234 }
42235
42236
42237-static struct usb_ep_ops pxa25x_ep_ops = {
42238+static const struct usb_ep_ops pxa25x_ep_ops = {
42239 .enable = pxa25x_ep_enable,
42240 .disable = pxa25x_ep_disable,
42241
42242diff -urNp linux-2.6.39.1/drivers/usb/gadget/pxa27x_udc.c linux-2.6.39.1/drivers/usb/gadget/pxa27x_udc.c
42243--- linux-2.6.39.1/drivers/usb/gadget/pxa27x_udc.c 2011-05-19 00:06:34.000000000 -0400
42244+++ linux-2.6.39.1/drivers/usb/gadget/pxa27x_udc.c 2011-05-22 19:36:32.000000000 -0400
42245@@ -1491,7 +1491,7 @@ static int pxa_ep_disable(struct usb_ep
42246 return 0;
42247 }
42248
42249-static struct usb_ep_ops pxa_ep_ops = {
42250+static const struct usb_ep_ops pxa_ep_ops = {
42251 .enable = pxa_ep_enable,
42252 .disable = pxa_ep_disable,
42253
42254diff -urNp linux-2.6.39.1/drivers/usb/gadget/r8a66597-udc.c linux-2.6.39.1/drivers/usb/gadget/r8a66597-udc.c
42255--- linux-2.6.39.1/drivers/usb/gadget/r8a66597-udc.c 2011-05-19 00:06:34.000000000 -0400
42256+++ linux-2.6.39.1/drivers/usb/gadget/r8a66597-udc.c 2011-05-22 19:36:32.000000000 -0400
42257@@ -1392,7 +1392,7 @@ static void r8a66597_fifo_flush(struct u
42258 spin_unlock_irqrestore(&ep->r8a66597->lock, flags);
42259 }
42260
42261-static struct usb_ep_ops r8a66597_ep_ops = {
42262+static const struct usb_ep_ops r8a66597_ep_ops = {
42263 .enable = r8a66597_enable,
42264 .disable = r8a66597_disable,
42265
42266@@ -1497,7 +1497,7 @@ static int r8a66597_get_frame(struct usb
42267 return r8a66597_read(r8a66597, FRMNUM) & 0x03FF;
42268 }
42269
42270-static struct usb_gadget_ops r8a66597_gadget_ops = {
42271+static const struct usb_gadget_ops r8a66597_gadget_ops = {
42272 .get_frame = r8a66597_get_frame,
42273 };
42274
42275diff -urNp linux-2.6.39.1/drivers/usb/gadget/s3c-hsotg.c linux-2.6.39.1/drivers/usb/gadget/s3c-hsotg.c
42276--- linux-2.6.39.1/drivers/usb/gadget/s3c-hsotg.c 2011-05-19 00:06:34.000000000 -0400
42277+++ linux-2.6.39.1/drivers/usb/gadget/s3c-hsotg.c 2011-05-22 19:36:32.000000000 -0400
42278@@ -2461,7 +2461,7 @@ static int s3c_hsotg_ep_sethalt(struct u
42279 return 0;
42280 }
42281
42282-static struct usb_ep_ops s3c_hsotg_ep_ops = {
42283+static const struct usb_ep_ops s3c_hsotg_ep_ops = {
42284 .enable = s3c_hsotg_ep_enable,
42285 .disable = s3c_hsotg_ep_disable,
42286 .alloc_request = s3c_hsotg_ep_alloc_request,
42287@@ -2725,7 +2725,7 @@ static int s3c_hsotg_gadget_getframe(str
42288 return s3c_hsotg_read_frameno(to_hsotg(gadget));
42289 }
42290
42291-static struct usb_gadget_ops s3c_hsotg_gadget_ops = {
42292+static const struct usb_gadget_ops s3c_hsotg_gadget_ops = {
42293 .get_frame = s3c_hsotg_gadget_getframe,
42294 };
42295
42296diff -urNp linux-2.6.39.1/drivers/usb/gadget/uvc_queue.c linux-2.6.39.1/drivers/usb/gadget/uvc_queue.c
42297--- linux-2.6.39.1/drivers/usb/gadget/uvc_queue.c 2011-05-19 00:06:34.000000000 -0400
42298+++ linux-2.6.39.1/drivers/usb/gadget/uvc_queue.c 2011-05-22 19:36:32.000000000 -0400
42299@@ -400,7 +400,7 @@ static void uvc_vm_close(struct vm_area_
42300 buffer->vma_use_count--;
42301 }
42302
42303-static struct vm_operations_struct uvc_vm_ops = {
42304+static const struct vm_operations_struct uvc_vm_ops = {
42305 .open = uvc_vm_open,
42306 .close = uvc_vm_close,
42307 };
42308diff -urNp linux-2.6.39.1/drivers/usb/host/ehci-fsl.c linux-2.6.39.1/drivers/usb/host/ehci-fsl.c
42309--- linux-2.6.39.1/drivers/usb/host/ehci-fsl.c 2011-05-19 00:06:34.000000000 -0400
42310+++ linux-2.6.39.1/drivers/usb/host/ehci-fsl.c 2011-05-22 19:36:32.000000000 -0400
42311@@ -380,7 +380,7 @@ static int ehci_fsl_drv_restore(struct d
42312 return 0;
42313 }
42314
42315-static struct dev_pm_ops ehci_fsl_pm_ops = {
42316+static const struct dev_pm_ops ehci_fsl_pm_ops = {
42317 .suspend = ehci_fsl_drv_suspend,
42318 .resume = ehci_fsl_drv_resume,
42319 .restore = ehci_fsl_drv_restore,
42320diff -urNp linux-2.6.39.1/drivers/usb/host/xhci-mem.c linux-2.6.39.1/drivers/usb/host/xhci-mem.c
42321--- linux-2.6.39.1/drivers/usb/host/xhci-mem.c 2011-06-03 00:04:14.000000000 -0400
42322+++ linux-2.6.39.1/drivers/usb/host/xhci-mem.c 2011-06-03 00:32:07.000000000 -0400
42323@@ -1670,6 +1670,8 @@ static int xhci_check_trb_in_td_math(str
42324 unsigned int num_tests;
42325 int i, ret;
42326
42327+ pax_track_stack();
42328+
42329 num_tests = ARRAY_SIZE(simple_test_vector);
42330 for (i = 0; i < num_tests; i++) {
42331 ret = xhci_test_trb_in_td(xhci,
42332diff -urNp linux-2.6.39.1/drivers/usb/mon/mon_main.c linux-2.6.39.1/drivers/usb/mon/mon_main.c
42333--- linux-2.6.39.1/drivers/usb/mon/mon_main.c 2011-05-19 00:06:34.000000000 -0400
42334+++ linux-2.6.39.1/drivers/usb/mon/mon_main.c 2011-05-22 19:36:32.000000000 -0400
42335@@ -238,7 +238,7 @@ static struct notifier_block mon_nb = {
42336 /*
42337 * Ops
42338 */
42339-static struct usb_mon_operations mon_ops_0 = {
42340+static const struct usb_mon_operations mon_ops_0 = {
42341 .urb_submit = mon_submit,
42342 .urb_submit_error = mon_submit_error,
42343 .urb_complete = mon_complete,
42344diff -urNp linux-2.6.39.1/drivers/usb/musb/cppi_dma.h linux-2.6.39.1/drivers/usb/musb/cppi_dma.h
42345--- linux-2.6.39.1/drivers/usb/musb/cppi_dma.h 2011-05-19 00:06:34.000000000 -0400
42346+++ linux-2.6.39.1/drivers/usb/musb/cppi_dma.h 2011-05-22 19:36:32.000000000 -0400
42347@@ -113,7 +113,7 @@ struct cppi_channel {
42348
42349 /* CPPI DMA controller object */
42350 struct cppi {
42351- struct dma_controller controller;
42352+ const struct dma_controller controller;
42353 struct musb *musb;
42354 void __iomem *mregs; /* Mentor regs */
42355 void __iomem *tibase; /* TI/CPPI regs */
42356diff -urNp linux-2.6.39.1/drivers/usb/otg/msm_otg.c linux-2.6.39.1/drivers/usb/otg/msm_otg.c
42357--- linux-2.6.39.1/drivers/usb/otg/msm_otg.c 2011-05-19 00:06:34.000000000 -0400
42358+++ linux-2.6.39.1/drivers/usb/otg/msm_otg.c 2011-05-22 19:36:32.000000000 -0400
42359@@ -95,7 +95,7 @@ static int ulpi_write(struct otg_transce
42360 return 0;
42361 }
42362
42363-static struct otg_io_access_ops msm_otg_io_ops = {
42364+static const struct otg_io_access_ops msm_otg_io_ops = {
42365 .read = ulpi_read,
42366 .write = ulpi_write,
42367 };
42368diff -urNp linux-2.6.39.1/drivers/usb/otg/ulpi_viewport.c linux-2.6.39.1/drivers/usb/otg/ulpi_viewport.c
42369--- linux-2.6.39.1/drivers/usb/otg/ulpi_viewport.c 2011-05-19 00:06:34.000000000 -0400
42370+++ linux-2.6.39.1/drivers/usb/otg/ulpi_viewport.c 2011-05-22 19:36:32.000000000 -0400
42371@@ -74,7 +74,7 @@ static int ulpi_viewport_write(struct ot
42372 return ulpi_viewport_wait(view, ULPI_VIEW_RUN);
42373 }
42374
42375-struct otg_io_access_ops ulpi_viewport_access_ops = {
42376+const struct otg_io_access_ops ulpi_viewport_access_ops = {
42377 .read = ulpi_viewport_read,
42378 .write = ulpi_viewport_write,
42379 };
42380diff -urNp linux-2.6.39.1/drivers/usb/serial/ftdi_sio.c linux-2.6.39.1/drivers/usb/serial/ftdi_sio.c
42381--- linux-2.6.39.1/drivers/usb/serial/ftdi_sio.c 2011-06-03 00:04:14.000000000 -0400
42382+++ linux-2.6.39.1/drivers/usb/serial/ftdi_sio.c 2011-06-03 00:32:07.000000000 -0400
42383@@ -104,27 +104,27 @@ static int ftdi_stmclite_probe(struct
42384 static void ftdi_USB_UIRT_setup(struct ftdi_private *priv);
42385 static void ftdi_HE_TIRA1_setup(struct ftdi_private *priv);
42386
42387-static struct ftdi_sio_quirk ftdi_jtag_quirk = {
42388+static const struct ftdi_sio_quirk ftdi_jtag_quirk = {
42389 .probe = ftdi_jtag_probe,
42390 };
42391
42392-static struct ftdi_sio_quirk ftdi_mtxorb_hack_quirk = {
42393+static const struct ftdi_sio_quirk ftdi_mtxorb_hack_quirk = {
42394 .probe = ftdi_mtxorb_hack_setup,
42395 };
42396
42397-static struct ftdi_sio_quirk ftdi_NDI_device_quirk = {
42398+static const struct ftdi_sio_quirk ftdi_NDI_device_quirk = {
42399 .probe = ftdi_NDI_device_setup,
42400 };
42401
42402-static struct ftdi_sio_quirk ftdi_USB_UIRT_quirk = {
42403+static const struct ftdi_sio_quirk ftdi_USB_UIRT_quirk = {
42404 .port_probe = ftdi_USB_UIRT_setup,
42405 };
42406
42407-static struct ftdi_sio_quirk ftdi_HE_TIRA1_quirk = {
42408+static const struct ftdi_sio_quirk ftdi_HE_TIRA1_quirk = {
42409 .port_probe = ftdi_HE_TIRA1_setup,
42410 };
42411
42412-static struct ftdi_sio_quirk ftdi_stmclite_quirk = {
42413+static const struct ftdi_sio_quirk ftdi_stmclite_quirk = {
42414 .probe = ftdi_stmclite_probe,
42415 };
42416
42417diff -urNp linux-2.6.39.1/drivers/usb/wusbcore/wa-hc.h linux-2.6.39.1/drivers/usb/wusbcore/wa-hc.h
42418--- linux-2.6.39.1/drivers/usb/wusbcore/wa-hc.h 2011-05-19 00:06:34.000000000 -0400
42419+++ linux-2.6.39.1/drivers/usb/wusbcore/wa-hc.h 2011-05-22 19:36:32.000000000 -0400
42420@@ -192,7 +192,7 @@ struct wahc {
42421 struct list_head xfer_delayed_list;
42422 spinlock_t xfer_list_lock;
42423 struct work_struct xfer_work;
42424- atomic_t xfer_id_count;
42425+ atomic_unchecked_t xfer_id_count;
42426 };
42427
42428
42429@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *
42430 INIT_LIST_HEAD(&wa->xfer_delayed_list);
42431 spin_lock_init(&wa->xfer_list_lock);
42432 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
42433- atomic_set(&wa->xfer_id_count, 1);
42434+ atomic_set_unchecked(&wa->xfer_id_count, 1);
42435 }
42436
42437 /**
42438diff -urNp linux-2.6.39.1/drivers/usb/wusbcore/wa-xfer.c linux-2.6.39.1/drivers/usb/wusbcore/wa-xfer.c
42439--- linux-2.6.39.1/drivers/usb/wusbcore/wa-xfer.c 2011-05-19 00:06:34.000000000 -0400
42440+++ linux-2.6.39.1/drivers/usb/wusbcore/wa-xfer.c 2011-05-22 19:36:32.000000000 -0400
42441@@ -294,7 +294,7 @@ out:
42442 */
42443 static void wa_xfer_id_init(struct wa_xfer *xfer)
42444 {
42445- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
42446+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
42447 }
42448
42449 /*
42450diff -urNp linux-2.6.39.1/drivers/vhost/vhost.c linux-2.6.39.1/drivers/vhost/vhost.c
42451--- linux-2.6.39.1/drivers/vhost/vhost.c 2011-05-19 00:06:34.000000000 -0400
42452+++ linux-2.6.39.1/drivers/vhost/vhost.c 2011-05-22 19:36:32.000000000 -0400
42453@@ -580,7 +580,7 @@ static int init_used(struct vhost_virtqu
42454 return get_user(vq->last_used_idx, &used->idx);
42455 }
42456
42457-static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
42458+static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
42459 {
42460 struct file *eventfp, *filep = NULL,
42461 *pollstart = NULL, *pollstop = NULL;
42462diff -urNp linux-2.6.39.1/drivers/video/backlight/corgi_lcd.c linux-2.6.39.1/drivers/video/backlight/corgi_lcd.c
42463--- linux-2.6.39.1/drivers/video/backlight/corgi_lcd.c 2011-05-19 00:06:34.000000000 -0400
42464+++ linux-2.6.39.1/drivers/video/backlight/corgi_lcd.c 2011-05-22 19:36:32.000000000 -0400
42465@@ -383,7 +383,7 @@ static int corgi_lcd_get_power(struct lc
42466 return lcd->power;
42467 }
42468
42469-static struct lcd_ops corgi_lcd_ops = {
42470+static const struct lcd_ops corgi_lcd_ops = {
42471 .get_power = corgi_lcd_get_power,
42472 .set_power = corgi_lcd_set_power,
42473 .set_mode = corgi_lcd_set_mode,
42474diff -urNp linux-2.6.39.1/drivers/video/backlight/cr_bllcd.c linux-2.6.39.1/drivers/video/backlight/cr_bllcd.c
42475--- linux-2.6.39.1/drivers/video/backlight/cr_bllcd.c 2011-05-19 00:06:34.000000000 -0400
42476+++ linux-2.6.39.1/drivers/video/backlight/cr_bllcd.c 2011-05-22 19:36:32.000000000 -0400
42477@@ -165,7 +165,7 @@ static int cr_lcd_set_power(struct lcd_d
42478 return 0;
42479 }
42480
42481-static struct lcd_ops cr_lcd_ops = {
42482+static const struct lcd_ops cr_lcd_ops = {
42483 .set_power = cr_lcd_set_power,
42484 };
42485
42486diff -urNp linux-2.6.39.1/drivers/video/backlight/ili9320.c linux-2.6.39.1/drivers/video/backlight/ili9320.c
42487--- linux-2.6.39.1/drivers/video/backlight/ili9320.c 2011-05-19 00:06:34.000000000 -0400
42488+++ linux-2.6.39.1/drivers/video/backlight/ili9320.c 2011-05-22 19:36:32.000000000 -0400
42489@@ -166,7 +166,7 @@ static int ili9320_get_power(struct lcd_
42490 return lcd->power;
42491 }
42492
42493-static struct lcd_ops ili9320_ops = {
42494+static const struct lcd_ops ili9320_ops = {
42495 .get_power = ili9320_get_power,
42496 .set_power = ili9320_set_power,
42497 };
42498diff -urNp linux-2.6.39.1/drivers/video/backlight/jornada720_lcd.c linux-2.6.39.1/drivers/video/backlight/jornada720_lcd.c
42499--- linux-2.6.39.1/drivers/video/backlight/jornada720_lcd.c 2011-05-19 00:06:34.000000000 -0400
42500+++ linux-2.6.39.1/drivers/video/backlight/jornada720_lcd.c 2011-05-22 19:36:32.000000000 -0400
42501@@ -87,7 +87,7 @@ static int jornada_lcd_set_power(struct
42502 return 0;
42503 }
42504
42505-static struct lcd_ops jornada_lcd_props = {
42506+static const struct lcd_ops jornada_lcd_props = {
42507 .get_contrast = jornada_lcd_get_contrast,
42508 .set_contrast = jornada_lcd_set_contrast,
42509 .get_power = jornada_lcd_get_power,
42510diff -urNp linux-2.6.39.1/drivers/video/backlight/l4f00242t03.c linux-2.6.39.1/drivers/video/backlight/l4f00242t03.c
42511--- linux-2.6.39.1/drivers/video/backlight/l4f00242t03.c 2011-05-19 00:06:34.000000000 -0400
42512+++ linux-2.6.39.1/drivers/video/backlight/l4f00242t03.c 2011-05-22 19:36:32.000000000 -0400
42513@@ -149,7 +149,7 @@ static int l4f00242t03_lcd_power_set(str
42514 return 0;
42515 }
42516
42517-static struct lcd_ops l4f_ops = {
42518+static const struct lcd_ops l4f_ops = {
42519 .set_power = l4f00242t03_lcd_power_set,
42520 .get_power = l4f00242t03_lcd_power_get,
42521 };
42522diff -urNp linux-2.6.39.1/drivers/video/backlight/lcd.c linux-2.6.39.1/drivers/video/backlight/lcd.c
42523--- linux-2.6.39.1/drivers/video/backlight/lcd.c 2011-05-19 00:06:34.000000000 -0400
42524+++ linux-2.6.39.1/drivers/video/backlight/lcd.c 2011-05-22 19:36:32.000000000 -0400
42525@@ -192,7 +192,7 @@ static struct device_attribute lcd_devic
42526 * or a pointer to the newly allocated device.
42527 */
42528 struct lcd_device *lcd_device_register(const char *name, struct device *parent,
42529- void *devdata, struct lcd_ops *ops)
42530+ void *devdata, const struct lcd_ops *ops)
42531 {
42532 struct lcd_device *new_ld;
42533 int rc;
42534diff -urNp linux-2.6.39.1/drivers/video/backlight/ld9040.c linux-2.6.39.1/drivers/video/backlight/ld9040.c
42535--- linux-2.6.39.1/drivers/video/backlight/ld9040.c 2011-05-19 00:06:34.000000000 -0400
42536+++ linux-2.6.39.1/drivers/video/backlight/ld9040.c 2011-05-22 19:36:32.000000000 -0400
42537@@ -651,7 +651,7 @@ static int ld9040_set_brightness(struct
42538 return ret;
42539 }
42540
42541-static struct lcd_ops ld9040_lcd_ops = {
42542+static const struct lcd_ops ld9040_lcd_ops = {
42543 .set_power = ld9040_set_power,
42544 .get_power = ld9040_get_power,
42545 };
42546diff -urNp linux-2.6.39.1/drivers/video/backlight/lms283gf05.c linux-2.6.39.1/drivers/video/backlight/lms283gf05.c
42547--- linux-2.6.39.1/drivers/video/backlight/lms283gf05.c 2011-05-19 00:06:34.000000000 -0400
42548+++ linux-2.6.39.1/drivers/video/backlight/lms283gf05.c 2011-05-22 19:36:32.000000000 -0400
42549@@ -144,7 +144,7 @@ static int lms283gf05_power_set(struct l
42550 return 0;
42551 }
42552
42553-static struct lcd_ops lms_ops = {
42554+static const struct lcd_ops lms_ops = {
42555 .set_power = lms283gf05_power_set,
42556 .get_power = NULL,
42557 };
42558diff -urNp linux-2.6.39.1/drivers/video/backlight/ltv350qv.c linux-2.6.39.1/drivers/video/backlight/ltv350qv.c
42559--- linux-2.6.39.1/drivers/video/backlight/ltv350qv.c 2011-05-19 00:06:34.000000000 -0400
42560+++ linux-2.6.39.1/drivers/video/backlight/ltv350qv.c 2011-05-22 19:36:32.000000000 -0400
42561@@ -221,7 +221,7 @@ static int ltv350qv_get_power(struct lcd
42562 return lcd->power;
42563 }
42564
42565-static struct lcd_ops ltv_ops = {
42566+static const struct lcd_ops ltv_ops = {
42567 .get_power = ltv350qv_get_power,
42568 .set_power = ltv350qv_set_power,
42569 };
42570diff -urNp linux-2.6.39.1/drivers/video/backlight/platform_lcd.c linux-2.6.39.1/drivers/video/backlight/platform_lcd.c
42571--- linux-2.6.39.1/drivers/video/backlight/platform_lcd.c 2011-05-19 00:06:34.000000000 -0400
42572+++ linux-2.6.39.1/drivers/video/backlight/platform_lcd.c 2011-05-22 19:36:32.000000000 -0400
42573@@ -66,7 +66,7 @@ static int platform_lcd_match(struct lcd
42574 return plcd->us->parent == info->device;
42575 }
42576
42577-static struct lcd_ops platform_lcd_ops = {
42578+static const struct lcd_ops platform_lcd_ops = {
42579 .get_power = platform_lcd_get_power,
42580 .set_power = platform_lcd_set_power,
42581 .check_fb = platform_lcd_match,
42582diff -urNp linux-2.6.39.1/drivers/video/backlight/s6e63m0.c linux-2.6.39.1/drivers/video/backlight/s6e63m0.c
42583--- linux-2.6.39.1/drivers/video/backlight/s6e63m0.c 2011-05-19 00:06:34.000000000 -0400
42584+++ linux-2.6.39.1/drivers/video/backlight/s6e63m0.c 2011-05-22 19:36:32.000000000 -0400
42585@@ -644,7 +644,7 @@ static int s6e63m0_set_brightness(struct
42586 return ret;
42587 }
42588
42589-static struct lcd_ops s6e63m0_lcd_ops = {
42590+static const struct lcd_ops s6e63m0_lcd_ops = {
42591 .set_power = s6e63m0_set_power,
42592 .get_power = s6e63m0_get_power,
42593 };
42594diff -urNp linux-2.6.39.1/drivers/video/backlight/tdo24m.c linux-2.6.39.1/drivers/video/backlight/tdo24m.c
42595--- linux-2.6.39.1/drivers/video/backlight/tdo24m.c 2011-05-19 00:06:34.000000000 -0400
42596+++ linux-2.6.39.1/drivers/video/backlight/tdo24m.c 2011-05-22 19:36:32.000000000 -0400
42597@@ -322,7 +322,7 @@ static int tdo24m_set_mode(struct lcd_de
42598 return lcd->adj_mode(lcd, mode);
42599 }
42600
42601-static struct lcd_ops tdo24m_ops = {
42602+static const struct lcd_ops tdo24m_ops = {
42603 .get_power = tdo24m_get_power,
42604 .set_power = tdo24m_set_power,
42605 .set_mode = tdo24m_set_mode,
42606diff -urNp linux-2.6.39.1/drivers/video/backlight/tosa_lcd.c linux-2.6.39.1/drivers/video/backlight/tosa_lcd.c
42607--- linux-2.6.39.1/drivers/video/backlight/tosa_lcd.c 2011-05-19 00:06:34.000000000 -0400
42608+++ linux-2.6.39.1/drivers/video/backlight/tosa_lcd.c 2011-05-22 19:36:32.000000000 -0400
42609@@ -163,7 +163,7 @@ static int tosa_lcd_set_mode(struct lcd_
42610 return 0;
42611 }
42612
42613-static struct lcd_ops tosa_lcd_ops = {
42614+static const struct lcd_ops tosa_lcd_ops = {
42615 .set_power = tosa_lcd_set_power,
42616 .get_power = tosa_lcd_get_power,
42617 .set_mode = tosa_lcd_set_mode,
42618diff -urNp linux-2.6.39.1/drivers/video/bf537-lq035.c linux-2.6.39.1/drivers/video/bf537-lq035.c
42619--- linux-2.6.39.1/drivers/video/bf537-lq035.c 2011-05-19 00:06:34.000000000 -0400
42620+++ linux-2.6.39.1/drivers/video/bf537-lq035.c 2011-05-22 19:36:32.000000000 -0400
42621@@ -682,7 +682,7 @@ static int bfin_lcd_check_fb(struct lcd_
42622 return 0;
42623 }
42624
42625-static struct lcd_ops bfin_lcd_ops = {
42626+static const struct lcd_ops bfin_lcd_ops = {
42627 .get_power = bfin_lcd_get_power,
42628 .set_power = bfin_lcd_set_power,
42629 .get_contrast = bfin_lcd_get_contrast,
42630diff -urNp linux-2.6.39.1/drivers/video/bf54x-lq043fb.c linux-2.6.39.1/drivers/video/bf54x-lq043fb.c
42631--- linux-2.6.39.1/drivers/video/bf54x-lq043fb.c 2011-05-19 00:06:34.000000000 -0400
42632+++ linux-2.6.39.1/drivers/video/bf54x-lq043fb.c 2011-05-22 19:36:32.000000000 -0400
42633@@ -467,7 +467,7 @@ static int bfin_lcd_check_fb(struct lcd_
42634 return 0;
42635 }
42636
42637-static struct lcd_ops bfin_lcd_ops = {
42638+static const struct lcd_ops bfin_lcd_ops = {
42639 .get_power = bfin_lcd_get_power,
42640 .set_power = bfin_lcd_set_power,
42641 .get_contrast = bfin_lcd_get_contrast,
42642diff -urNp linux-2.6.39.1/drivers/video/bfin-t350mcqb-fb.c linux-2.6.39.1/drivers/video/bfin-t350mcqb-fb.c
42643--- linux-2.6.39.1/drivers/video/bfin-t350mcqb-fb.c 2011-05-19 00:06:34.000000000 -0400
42644+++ linux-2.6.39.1/drivers/video/bfin-t350mcqb-fb.c 2011-05-22 19:36:32.000000000 -0400
42645@@ -387,7 +387,7 @@ static int bfin_lcd_check_fb(struct lcd_
42646 return 0;
42647 }
42648
42649-static struct lcd_ops bfin_lcd_ops = {
42650+static const struct lcd_ops bfin_lcd_ops = {
42651 .get_power = bfin_lcd_get_power,
42652 .set_power = bfin_lcd_set_power,
42653 .get_contrast = bfin_lcd_get_contrast,
42654diff -urNp linux-2.6.39.1/drivers/video/fbcmap.c linux-2.6.39.1/drivers/video/fbcmap.c
42655--- linux-2.6.39.1/drivers/video/fbcmap.c 2011-05-19 00:06:34.000000000 -0400
42656+++ linux-2.6.39.1/drivers/video/fbcmap.c 2011-05-22 19:36:32.000000000 -0400
42657@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user
42658 rc = -ENODEV;
42659 goto out;
42660 }
42661- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
42662- !info->fbops->fb_setcmap)) {
42663+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
42664 rc = -EINVAL;
42665 goto out1;
42666 }
42667diff -urNp linux-2.6.39.1/drivers/video/fbmem.c linux-2.6.39.1/drivers/video/fbmem.c
42668--- linux-2.6.39.1/drivers/video/fbmem.c 2011-05-19 00:06:34.000000000 -0400
42669+++ linux-2.6.39.1/drivers/video/fbmem.c 2011-05-22 19:36:32.000000000 -0400
42670@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_in
42671 image->dx += image->width + 8;
42672 }
42673 } else if (rotate == FB_ROTATE_UD) {
42674- for (x = 0; x < num && image->dx >= 0; x++) {
42675+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
42676 info->fbops->fb_imageblit(info, image);
42677 image->dx -= image->width + 8;
42678 }
42679@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_in
42680 image->dy += image->height + 8;
42681 }
42682 } else if (rotate == FB_ROTATE_CCW) {
42683- for (x = 0; x < num && image->dy >= 0; x++) {
42684+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
42685 info->fbops->fb_imageblit(info, image);
42686 image->dy -= image->height + 8;
42687 }
42688@@ -939,6 +939,8 @@ fb_set_var(struct fb_info *info, struct
42689 int flags = info->flags;
42690 int ret = 0;
42691
42692+ pax_track_stack();
42693+
42694 if (var->activate & FB_ACTIVATE_INV_MODE) {
42695 struct fb_videomode mode1, mode2;
42696
42697@@ -1064,6 +1066,8 @@ static long do_fb_ioctl(struct fb_info *
42698 void __user *argp = (void __user *)arg;
42699 long ret = 0;
42700
42701+ pax_track_stack();
42702+
42703 switch (cmd) {
42704 case FBIOGET_VSCREENINFO:
42705 if (!lock_fb_info(info))
42706@@ -1143,7 +1147,7 @@ static long do_fb_ioctl(struct fb_info *
42707 return -EFAULT;
42708 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
42709 return -EINVAL;
42710- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
42711+ if (con2fb.framebuffer >= FB_MAX)
42712 return -EINVAL;
42713 if (!registered_fb[con2fb.framebuffer])
42714 request_module("fb%d", con2fb.framebuffer);
42715diff -urNp linux-2.6.39.1/drivers/video/geode/display_gx1.c linux-2.6.39.1/drivers/video/geode/display_gx1.c
42716--- linux-2.6.39.1/drivers/video/geode/display_gx1.c 2011-05-19 00:06:34.000000000 -0400
42717+++ linux-2.6.39.1/drivers/video/geode/display_gx1.c 2011-05-22 19:36:32.000000000 -0400
42718@@ -208,7 +208,7 @@ static void gx1_set_hw_palette_reg(struc
42719 writel(val, par->dc_regs + DC_PAL_DATA);
42720 }
42721
42722-struct geode_dc_ops gx1_dc_ops = {
42723+const struct geode_dc_ops gx1_dc_ops = {
42724 .set_mode = gx1_set_mode,
42725 .set_palette_reg = gx1_set_hw_palette_reg,
42726 };
42727diff -urNp linux-2.6.39.1/drivers/video/geode/display_gx1.h linux-2.6.39.1/drivers/video/geode/display_gx1.h
42728--- linux-2.6.39.1/drivers/video/geode/display_gx1.h 2011-05-19 00:06:34.000000000 -0400
42729+++ linux-2.6.39.1/drivers/video/geode/display_gx1.h 2011-05-22 19:36:32.000000000 -0400
42730@@ -18,7 +18,7 @@
42731 unsigned gx1_gx_base(void);
42732 int gx1_frame_buffer_size(void);
42733
42734-extern struct geode_dc_ops gx1_dc_ops;
42735+extern const struct geode_dc_ops gx1_dc_ops;
42736
42737 /* GX1 configuration I/O registers */
42738
42739diff -urNp linux-2.6.39.1/drivers/video/geode/geodefb.h linux-2.6.39.1/drivers/video/geode/geodefb.h
42740--- linux-2.6.39.1/drivers/video/geode/geodefb.h 2011-05-19 00:06:34.000000000 -0400
42741+++ linux-2.6.39.1/drivers/video/geode/geodefb.h 2011-05-22 19:36:32.000000000 -0400
42742@@ -31,8 +31,8 @@ struct geodefb_par {
42743 int panel_y;
42744 void __iomem *dc_regs;
42745 void __iomem *vid_regs;
42746- struct geode_dc_ops *dc_ops;
42747- struct geode_vid_ops *vid_ops;
42748+ const struct geode_dc_ops *dc_ops;
42749+ const struct geode_vid_ops *vid_ops;
42750 };
42751
42752 #endif /* !__GEODEFB_H__ */
42753diff -urNp linux-2.6.39.1/drivers/video/geode/video_cs5530.c linux-2.6.39.1/drivers/video/geode/video_cs5530.c
42754--- linux-2.6.39.1/drivers/video/geode/video_cs5530.c 2011-05-19 00:06:34.000000000 -0400
42755+++ linux-2.6.39.1/drivers/video/geode/video_cs5530.c 2011-05-22 19:36:32.000000000 -0400
42756@@ -186,7 +186,7 @@ static int cs5530_blank_display(struct f
42757 return 0;
42758 }
42759
42760-struct geode_vid_ops cs5530_vid_ops = {
42761+const struct geode_vid_ops cs5530_vid_ops = {
42762 .set_dclk = cs5530_set_dclk_frequency,
42763 .configure_display = cs5530_configure_display,
42764 .blank_display = cs5530_blank_display,
42765diff -urNp linux-2.6.39.1/drivers/video/geode/video_cs5530.h linux-2.6.39.1/drivers/video/geode/video_cs5530.h
42766--- linux-2.6.39.1/drivers/video/geode/video_cs5530.h 2011-05-19 00:06:34.000000000 -0400
42767+++ linux-2.6.39.1/drivers/video/geode/video_cs5530.h 2011-05-22 19:36:32.000000000 -0400
42768@@ -15,7 +15,7 @@
42769 #ifndef __VIDEO_CS5530_H__
42770 #define __VIDEO_CS5530_H__
42771
42772-extern struct geode_vid_ops cs5530_vid_ops;
42773+extern const struct geode_vid_ops cs5530_vid_ops;
42774
42775 /* CS5530 Video device registers */
42776
42777diff -urNp linux-2.6.39.1/drivers/video/i810/i810_accel.c linux-2.6.39.1/drivers/video/i810/i810_accel.c
42778--- linux-2.6.39.1/drivers/video/i810/i810_accel.c 2011-05-19 00:06:34.000000000 -0400
42779+++ linux-2.6.39.1/drivers/video/i810/i810_accel.c 2011-05-22 19:36:32.000000000 -0400
42780@@ -73,6 +73,7 @@ static inline int wait_for_space(struct
42781 }
42782 }
42783 printk("ringbuffer lockup!!!\n");
42784+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
42785 i810_report_error(mmio);
42786 par->dev_flags |= LOCKUP;
42787 info->pixmap.scan_align = 1;
42788diff -urNp linux-2.6.39.1/drivers/video/matrox/matroxfb_base.c linux-2.6.39.1/drivers/video/matrox/matroxfb_base.c
42789--- linux-2.6.39.1/drivers/video/matrox/matroxfb_base.c 2011-05-19 00:06:34.000000000 -0400
42790+++ linux-2.6.39.1/drivers/video/matrox/matroxfb_base.c 2011-05-22 19:36:32.000000000 -0400
42791@@ -1232,7 +1232,7 @@ static struct fb_ops matroxfb_ops = {
42792 #define RSText 0x7
42793 #define RSText8 0x8
42794 /* 9-F */
42795-static struct { struct fb_bitfield red, green, blue, transp; int bits_per_pixel; } colors[] = {
42796+static const struct { struct fb_bitfield red, green, blue, transp; int bits_per_pixel; } colors[] = {
42797 { { 0, 8, 0}, { 0, 8, 0}, { 0, 8, 0}, { 0, 0, 0}, 8 },
42798 { { 10, 5, 0}, { 5, 5, 0}, { 0, 5, 0}, { 15, 1, 0}, 16 },
42799 { { 11, 5, 0}, { 5, 6, 0}, { 0, 5, 0}, { 0, 0, 0}, 16 },
42800diff -urNp linux-2.6.39.1/drivers/video/omap/lcd_ams_delta.c linux-2.6.39.1/drivers/video/omap/lcd_ams_delta.c
42801--- linux-2.6.39.1/drivers/video/omap/lcd_ams_delta.c 2011-05-19 00:06:34.000000000 -0400
42802+++ linux-2.6.39.1/drivers/video/omap/lcd_ams_delta.c 2011-05-22 19:36:32.000000000 -0400
42803@@ -87,7 +87,7 @@ static int ams_delta_lcd_get_contrast(st
42804 return ams_delta_lcd & AMS_DELTA_MAX_CONTRAST;
42805 }
42806
42807-static struct lcd_ops ams_delta_lcd_ops = {
42808+static const struct lcd_ops ams_delta_lcd_ops = {
42809 .get_power = ams_delta_lcd_get_power,
42810 .set_power = ams_delta_lcd_set_power,
42811 .get_contrast = ams_delta_lcd_get_contrast,
42812diff -urNp linux-2.6.39.1/drivers/video/pxa3xx-gcu.c linux-2.6.39.1/drivers/video/pxa3xx-gcu.c
42813--- linux-2.6.39.1/drivers/video/pxa3xx-gcu.c 2011-05-19 00:06:34.000000000 -0400
42814+++ linux-2.6.39.1/drivers/video/pxa3xx-gcu.c 2011-05-22 19:36:32.000000000 -0400
42815@@ -103,7 +103,7 @@ struct pxa3xx_gcu_priv {
42816 dma_addr_t shared_phys;
42817 struct resource *resource_mem;
42818 struct miscdevice misc_dev;
42819- struct file_operations misc_fops;
42820+ const struct file_operations misc_fops;
42821 wait_queue_head_t wait_idle;
42822 wait_queue_head_t wait_free;
42823 spinlock_t spinlock;
42824diff -urNp linux-2.6.39.1/drivers/video/sh_mobile_lcdcfb.c linux-2.6.39.1/drivers/video/sh_mobile_lcdcfb.c
42825--- linux-2.6.39.1/drivers/video/sh_mobile_lcdcfb.c 2011-05-19 00:06:34.000000000 -0400
42826+++ linux-2.6.39.1/drivers/video/sh_mobile_lcdcfb.c 2011-05-22 19:36:32.000000000 -0400
42827@@ -245,7 +245,7 @@ static unsigned long lcdc_sys_read_data(
42828 return lcdc_read(ch->lcdc, _LDDRDR) & 0x3ffff;
42829 }
42830
42831-struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
42832+const struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
42833 lcdc_sys_write_index,
42834 lcdc_sys_write_data,
42835 lcdc_sys_read_data,
42836diff -urNp linux-2.6.39.1/drivers/video/udlfb.c linux-2.6.39.1/drivers/video/udlfb.c
42837--- linux-2.6.39.1/drivers/video/udlfb.c 2011-05-19 00:06:34.000000000 -0400
42838+++ linux-2.6.39.1/drivers/video/udlfb.c 2011-05-22 19:36:32.000000000 -0400
42839@@ -584,11 +584,11 @@ int dlfb_handle_damage(struct dlfb_data
42840 dlfb_urb_completion(urb);
42841
42842 error:
42843- atomic_add(bytes_sent, &dev->bytes_sent);
42844- atomic_add(bytes_identical, &dev->bytes_identical);
42845- atomic_add(width*height*2, &dev->bytes_rendered);
42846+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42847+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
42848+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
42849 end_cycles = get_cycles();
42850- atomic_add(((unsigned int) ((end_cycles - start_cycles)
42851+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
42852 >> 10)), /* Kcycles */
42853 &dev->cpu_kcycles_used);
42854
42855@@ -709,11 +709,11 @@ static void dlfb_dpy_deferred_io(struct
42856 dlfb_urb_completion(urb);
42857
42858 error:
42859- atomic_add(bytes_sent, &dev->bytes_sent);
42860- atomic_add(bytes_identical, &dev->bytes_identical);
42861- atomic_add(bytes_rendered, &dev->bytes_rendered);
42862+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42863+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
42864+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
42865 end_cycles = get_cycles();
42866- atomic_add(((unsigned int) ((end_cycles - start_cycles)
42867+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
42868 >> 10)), /* Kcycles */
42869 &dev->cpu_kcycles_used);
42870 }
42871@@ -1301,7 +1301,7 @@ static ssize_t metrics_bytes_rendered_sh
42872 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42873 struct dlfb_data *dev = fb_info->par;
42874 return snprintf(buf, PAGE_SIZE, "%u\n",
42875- atomic_read(&dev->bytes_rendered));
42876+ atomic_read_unchecked(&dev->bytes_rendered));
42877 }
42878
42879 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
42880@@ -1309,7 +1309,7 @@ static ssize_t metrics_bytes_identical_s
42881 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42882 struct dlfb_data *dev = fb_info->par;
42883 return snprintf(buf, PAGE_SIZE, "%u\n",
42884- atomic_read(&dev->bytes_identical));
42885+ atomic_read_unchecked(&dev->bytes_identical));
42886 }
42887
42888 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
42889@@ -1317,7 +1317,7 @@ static ssize_t metrics_bytes_sent_show(s
42890 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42891 struct dlfb_data *dev = fb_info->par;
42892 return snprintf(buf, PAGE_SIZE, "%u\n",
42893- atomic_read(&dev->bytes_sent));
42894+ atomic_read_unchecked(&dev->bytes_sent));
42895 }
42896
42897 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
42898@@ -1325,7 +1325,7 @@ static ssize_t metrics_cpu_kcycles_used_
42899 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42900 struct dlfb_data *dev = fb_info->par;
42901 return snprintf(buf, PAGE_SIZE, "%u\n",
42902- atomic_read(&dev->cpu_kcycles_used));
42903+ atomic_read_unchecked(&dev->cpu_kcycles_used));
42904 }
42905
42906 static ssize_t edid_show(
42907@@ -1382,10 +1382,10 @@ static ssize_t metrics_reset_store(struc
42908 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42909 struct dlfb_data *dev = fb_info->par;
42910
42911- atomic_set(&dev->bytes_rendered, 0);
42912- atomic_set(&dev->bytes_identical, 0);
42913- atomic_set(&dev->bytes_sent, 0);
42914- atomic_set(&dev->cpu_kcycles_used, 0);
42915+ atomic_set_unchecked(&dev->bytes_rendered, 0);
42916+ atomic_set_unchecked(&dev->bytes_identical, 0);
42917+ atomic_set_unchecked(&dev->bytes_sent, 0);
42918+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
42919
42920 return count;
42921 }
42922diff -urNp linux-2.6.39.1/drivers/video/uvesafb.c linux-2.6.39.1/drivers/video/uvesafb.c
42923--- linux-2.6.39.1/drivers/video/uvesafb.c 2011-05-19 00:06:34.000000000 -0400
42924+++ linux-2.6.39.1/drivers/video/uvesafb.c 2011-05-22 19:36:32.000000000 -0400
42925@@ -19,6 +19,7 @@
42926 #include <linux/io.h>
42927 #include <linux/mutex.h>
42928 #include <linux/slab.h>
42929+#include <linux/moduleloader.h>
42930 #include <video/edid.h>
42931 #include <video/uvesafb.h>
42932 #ifdef CONFIG_X86
42933@@ -121,7 +122,7 @@ static int uvesafb_helper_start(void)
42934 NULL,
42935 };
42936
42937- return call_usermodehelper(v86d_path, argv, envp, 1);
42938+ return call_usermodehelper(v86d_path, argv, envp, UMH_WAIT_PROC);
42939 }
42940
42941 /*
42942@@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(
42943 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
42944 par->pmi_setpal = par->ypan = 0;
42945 } else {
42946+
42947+#ifdef CONFIG_PAX_KERNEXEC
42948+#ifdef CONFIG_MODULES
42949+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
42950+#endif
42951+ if (!par->pmi_code) {
42952+ par->pmi_setpal = par->ypan = 0;
42953+ return 0;
42954+ }
42955+#endif
42956+
42957 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
42958 + task->t.regs.edi);
42959+
42960+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42961+ pax_open_kernel();
42962+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
42963+ pax_close_kernel();
42964+
42965+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
42966+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
42967+#else
42968 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
42969 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
42970+#endif
42971+
42972 printk(KERN_INFO "uvesafb: protected mode interface info at "
42973 "%04x:%04x\n",
42974 (u16)task->t.regs.es, (u16)task->t.regs.edi);
42975@@ -1821,6 +1844,11 @@ out:
42976 if (par->vbe_modes)
42977 kfree(par->vbe_modes);
42978
42979+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42980+ if (par->pmi_code)
42981+ module_free_exec(NULL, par->pmi_code);
42982+#endif
42983+
42984 framebuffer_release(info);
42985 return err;
42986 }
42987@@ -1847,6 +1875,12 @@ static int uvesafb_remove(struct platfor
42988 kfree(par->vbe_state_orig);
42989 if (par->vbe_state_saved)
42990 kfree(par->vbe_state_saved);
42991+
42992+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42993+ if (par->pmi_code)
42994+ module_free_exec(NULL, par->pmi_code);
42995+#endif
42996+
42997 }
42998
42999 framebuffer_release(info);
43000@@ -2013,7 +2047,7 @@ static int param_set_scroll(const char *
43001
43002 return 0;
43003 }
43004-static struct kernel_param_ops param_ops_scroll = {
43005+static const struct kernel_param_ops param_ops_scroll = {
43006 .set = param_set_scroll,
43007 };
43008 #define param_check_scroll(name, p) __param_check(name, p, void)
43009diff -urNp linux-2.6.39.1/drivers/video/vesafb.c linux-2.6.39.1/drivers/video/vesafb.c
43010--- linux-2.6.39.1/drivers/video/vesafb.c 2011-05-19 00:06:34.000000000 -0400
43011+++ linux-2.6.39.1/drivers/video/vesafb.c 2011-05-22 19:36:32.000000000 -0400
43012@@ -9,6 +9,7 @@
43013 */
43014
43015 #include <linux/module.h>
43016+#include <linux/moduleloader.h>
43017 #include <linux/kernel.h>
43018 #include <linux/errno.h>
43019 #include <linux/string.h>
43020@@ -52,8 +53,8 @@ static int vram_remap __initdata; /*
43021 static int vram_total __initdata; /* Set total amount of memory */
43022 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
43023 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
43024-static void (*pmi_start)(void) __read_mostly;
43025-static void (*pmi_pal) (void) __read_mostly;
43026+static void (*pmi_start)(void) __read_only;
43027+static void (*pmi_pal) (void) __read_only;
43028 static int depth __read_mostly;
43029 static int vga_compat __read_mostly;
43030 /* --------------------------------------------------------------------- */
43031@@ -232,6 +233,7 @@ static int __init vesafb_probe(struct pl
43032 unsigned int size_vmode;
43033 unsigned int size_remap;
43034 unsigned int size_total;
43035+ void *pmi_code = NULL;
43036
43037 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
43038 return -ENODEV;
43039@@ -274,10 +276,6 @@ static int __init vesafb_probe(struct pl
43040 size_remap = size_total;
43041 vesafb_fix.smem_len = size_remap;
43042
43043-#ifndef __i386__
43044- screen_info.vesapm_seg = 0;
43045-#endif
43046-
43047 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
43048 printk(KERN_WARNING
43049 "vesafb: cannot reserve video memory at 0x%lx\n",
43050@@ -306,9 +304,21 @@ static int __init vesafb_probe(struct pl
43051 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
43052 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
43053
43054+#ifdef __i386__
43055+
43056+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43057+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
43058+ if (!pmi_code)
43059+#elif !defined(CONFIG_PAX_KERNEXEC)
43060+ if (0)
43061+#endif
43062+
43063+#endif
43064+ screen_info.vesapm_seg = 0;
43065+
43066 if (screen_info.vesapm_seg) {
43067- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
43068- screen_info.vesapm_seg,screen_info.vesapm_off);
43069+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
43070+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
43071 }
43072
43073 if (screen_info.vesapm_seg < 0xc000)
43074@@ -316,9 +326,25 @@ static int __init vesafb_probe(struct pl
43075
43076 if (ypan || pmi_setpal) {
43077 unsigned short *pmi_base;
43078- pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
43079- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
43080- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
43081+
43082+ pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
43083+
43084+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43085+ pax_open_kernel();
43086+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
43087+#else
43088+ pmi_code = pmi_base;
43089+#endif
43090+
43091+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
43092+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
43093+
43094+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43095+ pmi_start = ktva_ktla(pmi_start);
43096+ pmi_pal = ktva_ktla(pmi_pal);
43097+ pax_close_kernel();
43098+#endif
43099+
43100 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
43101 if (pmi_base[3]) {
43102 printk(KERN_INFO "vesafb: pmi: ports = ");
43103@@ -487,6 +513,11 @@ static int __init vesafb_probe(struct pl
43104 info->node, info->fix.id);
43105 return 0;
43106 err:
43107+
43108+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43109+ module_free_exec(NULL, pmi_code);
43110+#endif
43111+
43112 if (info->screen_base)
43113 iounmap(info->screen_base);
43114 framebuffer_release(info);
43115diff -urNp linux-2.6.39.1/drivers/virtio/virtio_balloon.c linux-2.6.39.1/drivers/virtio/virtio_balloon.c
43116--- linux-2.6.39.1/drivers/virtio/virtio_balloon.c 2011-05-19 00:06:34.000000000 -0400
43117+++ linux-2.6.39.1/drivers/virtio/virtio_balloon.c 2011-05-22 19:36:32.000000000 -0400
43118@@ -176,6 +176,8 @@ static void update_balloon_stats(struct
43119 struct sysinfo i;
43120 int idx = 0;
43121
43122+ pax_track_stack();
43123+
43124 all_vm_events(events);
43125 si_meminfo(&i);
43126
43127diff -urNp linux-2.6.39.1/drivers/xen/gntalloc.c linux-2.6.39.1/drivers/xen/gntalloc.c
43128--- linux-2.6.39.1/drivers/xen/gntalloc.c 2011-05-19 00:06:34.000000000 -0400
43129+++ linux-2.6.39.1/drivers/xen/gntalloc.c 2011-05-22 19:36:32.000000000 -0400
43130@@ -440,7 +440,7 @@ static void gntalloc_vma_close(struct vm
43131 spin_unlock(&gref_lock);
43132 }
43133
43134-static struct vm_operations_struct gntalloc_vmops = {
43135+static const struct vm_operations_struct gntalloc_vmops = {
43136 .close = gntalloc_vma_close,
43137 };
43138
43139diff -urNp linux-2.6.39.1/drivers/xen/gntdev.c linux-2.6.39.1/drivers/xen/gntdev.c
43140--- linux-2.6.39.1/drivers/xen/gntdev.c 2011-05-19 00:06:34.000000000 -0400
43141+++ linux-2.6.39.1/drivers/xen/gntdev.c 2011-05-22 19:36:32.000000000 -0400
43142@@ -340,7 +340,7 @@ static void gntdev_vma_close(struct vm_a
43143 gntdev_put_map(map);
43144 }
43145
43146-static struct vm_operations_struct gntdev_vmops = {
43147+static const struct vm_operations_struct gntdev_vmops = {
43148 .close = gntdev_vma_close,
43149 };
43150
43151@@ -404,7 +404,7 @@ static void mn_release(struct mmu_notifi
43152 spin_unlock(&priv->lock);
43153 }
43154
43155-struct mmu_notifier_ops gntdev_mmu_ops = {
43156+const struct mmu_notifier_ops gntdev_mmu_ops = {
43157 .release = mn_release,
43158 .invalidate_page = mn_invl_page,
43159 .invalidate_range_start = mn_invl_range_start,
43160diff -urNp linux-2.6.39.1/drivers/xen/xenfs/privcmd.c linux-2.6.39.1/drivers/xen/xenfs/privcmd.c
43161--- linux-2.6.39.1/drivers/xen/xenfs/privcmd.c 2011-05-19 00:06:34.000000000 -0400
43162+++ linux-2.6.39.1/drivers/xen/xenfs/privcmd.c 2011-05-22 19:36:32.000000000 -0400
43163@@ -268,7 +268,7 @@ static int mmap_return_errors(void *data
43164 return put_user(*mfnp, st->user++);
43165 }
43166
43167-static struct vm_operations_struct privcmd_vm_ops;
43168+static const struct vm_operations_struct privcmd_vm_ops;
43169
43170 static long privcmd_ioctl_mmap_batch(void __user *udata)
43171 {
43172@@ -369,7 +369,7 @@ static int privcmd_fault(struct vm_area_
43173 return VM_FAULT_SIGBUS;
43174 }
43175
43176-static struct vm_operations_struct privcmd_vm_ops = {
43177+static const struct vm_operations_struct privcmd_vm_ops = {
43178 .fault = privcmd_fault
43179 };
43180
43181diff -urNp linux-2.6.39.1/fs/9p/vfs_inode.c linux-2.6.39.1/fs/9p/vfs_inode.c
43182--- linux-2.6.39.1/fs/9p/vfs_inode.c 2011-05-19 00:06:34.000000000 -0400
43183+++ linux-2.6.39.1/fs/9p/vfs_inode.c 2011-05-22 19:36:32.000000000 -0400
43184@@ -1210,7 +1210,7 @@ static void *v9fs_vfs_follow_link(struct
43185 void
43186 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
43187 {
43188- char *s = nd_get_link(nd);
43189+ const char *s = nd_get_link(nd);
43190
43191 P9_DPRINTK(P9_DEBUG_VFS, " %s %s\n", dentry->d_name.name,
43192 IS_ERR(s) ? "<error>" : s);
43193diff -urNp linux-2.6.39.1/fs/aio.c linux-2.6.39.1/fs/aio.c
43194--- linux-2.6.39.1/fs/aio.c 2011-05-19 00:06:34.000000000 -0400
43195+++ linux-2.6.39.1/fs/aio.c 2011-06-03 01:00:34.000000000 -0400
43196@@ -119,7 +119,7 @@ static int aio_setup_ring(struct kioctx
43197 size += sizeof(struct io_event) * nr_events;
43198 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
43199
43200- if (nr_pages < 0)
43201+ if (nr_pages <= 0)
43202 return -EINVAL;
43203
43204 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
43205@@ -1088,6 +1088,8 @@ static int read_events(struct kioctx *ct
43206 struct aio_timeout to;
43207 int retry = 0;
43208
43209+ pax_track_stack();
43210+
43211 /* needed to zero any padding within an entry (there shouldn't be
43212 * any, but C is fun!
43213 */
43214@@ -1381,22 +1383,27 @@ static ssize_t aio_fsync(struct kiocb *i
43215 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
43216 {
43217 ssize_t ret;
43218+ struct iovec iovstack;
43219
43220 #ifdef CONFIG_COMPAT
43221 if (compat)
43222 ret = compat_rw_copy_check_uvector(type,
43223 (struct compat_iovec __user *)kiocb->ki_buf,
43224- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
43225+ kiocb->ki_nbytes, 1, &iovstack,
43226 &kiocb->ki_iovec);
43227 else
43228 #endif
43229 ret = rw_copy_check_uvector(type,
43230 (struct iovec __user *)kiocb->ki_buf,
43231- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
43232+ kiocb->ki_nbytes, 1, &iovstack,
43233 &kiocb->ki_iovec);
43234 if (ret < 0)
43235 goto out;
43236
43237+ if (kiocb->ki_iovec == &iovstack) {
43238+ kiocb->ki_inline_vec = iovstack;
43239+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
43240+ }
43241 kiocb->ki_nr_segs = kiocb->ki_nbytes;
43242 kiocb->ki_cur_seg = 0;
43243 /* ki_nbytes/left now reflect bytes instead of segs */
43244diff -urNp linux-2.6.39.1/fs/attr.c linux-2.6.39.1/fs/attr.c
43245--- linux-2.6.39.1/fs/attr.c 2011-05-19 00:06:34.000000000 -0400
43246+++ linux-2.6.39.1/fs/attr.c 2011-05-22 19:41:37.000000000 -0400
43247@@ -98,6 +98,7 @@ int inode_newsize_ok(const struct inode
43248 unsigned long limit;
43249
43250 limit = rlimit(RLIMIT_FSIZE);
43251+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
43252 if (limit != RLIM_INFINITY && offset > limit)
43253 goto out_sig;
43254 if (offset > inode->i_sb->s_maxbytes)
43255diff -urNp linux-2.6.39.1/fs/befs/linuxvfs.c linux-2.6.39.1/fs/befs/linuxvfs.c
43256--- linux-2.6.39.1/fs/befs/linuxvfs.c 2011-05-19 00:06:34.000000000 -0400
43257+++ linux-2.6.39.1/fs/befs/linuxvfs.c 2011-05-22 19:36:32.000000000 -0400
43258@@ -498,7 +498,7 @@ static void befs_put_link(struct dentry
43259 {
43260 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
43261 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
43262- char *link = nd_get_link(nd);
43263+ const char *link = nd_get_link(nd);
43264 if (!IS_ERR(link))
43265 kfree(link);
43266 }
43267diff -urNp linux-2.6.39.1/fs/binfmt_aout.c linux-2.6.39.1/fs/binfmt_aout.c
43268--- linux-2.6.39.1/fs/binfmt_aout.c 2011-05-19 00:06:34.000000000 -0400
43269+++ linux-2.6.39.1/fs/binfmt_aout.c 2011-05-22 19:41:37.000000000 -0400
43270@@ -16,6 +16,7 @@
43271 #include <linux/string.h>
43272 #include <linux/fs.h>
43273 #include <linux/file.h>
43274+#include <linux/security.h>
43275 #include <linux/stat.h>
43276 #include <linux/fcntl.h>
43277 #include <linux/ptrace.h>
43278@@ -86,6 +87,8 @@ static int aout_core_dump(struct coredum
43279 #endif
43280 # define START_STACK(u) ((void __user *)u.start_stack)
43281
43282+ memset(&dump, 0, sizeof(dump));
43283+
43284 fs = get_fs();
43285 set_fs(KERNEL_DS);
43286 has_dumped = 1;
43287@@ -97,10 +100,12 @@ static int aout_core_dump(struct coredum
43288
43289 /* If the size of the dump file exceeds the rlimit, then see what would happen
43290 if we wrote the stack, but not the data area. */
43291+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
43292 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
43293 dump.u_dsize = 0;
43294
43295 /* Make sure we have enough room to write the stack and data areas. */
43296+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
43297 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
43298 dump.u_ssize = 0;
43299
43300@@ -234,6 +239,8 @@ static int load_aout_binary(struct linux
43301 rlim = rlimit(RLIMIT_DATA);
43302 if (rlim >= RLIM_INFINITY)
43303 rlim = ~0;
43304+
43305+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
43306 if (ex.a_data + ex.a_bss > rlim)
43307 return -ENOMEM;
43308
43309@@ -262,6 +269,27 @@ static int load_aout_binary(struct linux
43310 install_exec_creds(bprm);
43311 current->flags &= ~PF_FORKNOEXEC;
43312
43313+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43314+ current->mm->pax_flags = 0UL;
43315+#endif
43316+
43317+#ifdef CONFIG_PAX_PAGEEXEC
43318+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
43319+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
43320+
43321+#ifdef CONFIG_PAX_EMUTRAMP
43322+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
43323+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
43324+#endif
43325+
43326+#ifdef CONFIG_PAX_MPROTECT
43327+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
43328+ current->mm->pax_flags |= MF_PAX_MPROTECT;
43329+#endif
43330+
43331+ }
43332+#endif
43333+
43334 if (N_MAGIC(ex) == OMAGIC) {
43335 unsigned long text_addr, map_size;
43336 loff_t pos;
43337@@ -334,7 +362,7 @@ static int load_aout_binary(struct linux
43338
43339 down_write(&current->mm->mmap_sem);
43340 error = do_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
43341- PROT_READ | PROT_WRITE | PROT_EXEC,
43342+ PROT_READ | PROT_WRITE,
43343 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
43344 fd_offset + ex.a_text);
43345 up_write(&current->mm->mmap_sem);
43346diff -urNp linux-2.6.39.1/fs/binfmt_elf.c linux-2.6.39.1/fs/binfmt_elf.c
43347--- linux-2.6.39.1/fs/binfmt_elf.c 2011-05-19 00:06:34.000000000 -0400
43348+++ linux-2.6.39.1/fs/binfmt_elf.c 2011-05-22 19:41:37.000000000 -0400
43349@@ -51,6 +51,10 @@ static int elf_core_dump(struct coredump
43350 #define elf_core_dump NULL
43351 #endif
43352
43353+#ifdef CONFIG_PAX_MPROTECT
43354+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
43355+#endif
43356+
43357 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
43358 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
43359 #else
43360@@ -70,6 +74,11 @@ static struct linux_binfmt elf_format =
43361 .load_binary = load_elf_binary,
43362 .load_shlib = load_elf_library,
43363 .core_dump = elf_core_dump,
43364+
43365+#ifdef CONFIG_PAX_MPROTECT
43366+ .handle_mprotect= elf_handle_mprotect,
43367+#endif
43368+
43369 .min_coredump = ELF_EXEC_PAGESIZE,
43370 };
43371
43372@@ -77,6 +86,8 @@ static struct linux_binfmt elf_format =
43373
43374 static int set_brk(unsigned long start, unsigned long end)
43375 {
43376+ unsigned long e = end;
43377+
43378 start = ELF_PAGEALIGN(start);
43379 end = ELF_PAGEALIGN(end);
43380 if (end > start) {
43381@@ -87,7 +98,7 @@ static int set_brk(unsigned long start,
43382 if (BAD_ADDR(addr))
43383 return addr;
43384 }
43385- current->mm->start_brk = current->mm->brk = end;
43386+ current->mm->start_brk = current->mm->brk = e;
43387 return 0;
43388 }
43389
43390@@ -148,12 +159,15 @@ create_elf_tables(struct linux_binprm *b
43391 elf_addr_t __user *u_rand_bytes;
43392 const char *k_platform = ELF_PLATFORM;
43393 const char *k_base_platform = ELF_BASE_PLATFORM;
43394- unsigned char k_rand_bytes[16];
43395+ u32 k_rand_bytes[4];
43396 int items;
43397 elf_addr_t *elf_info;
43398 int ei_index = 0;
43399 const struct cred *cred = current_cred();
43400 struct vm_area_struct *vma;
43401+ unsigned long saved_auxv[AT_VECTOR_SIZE];
43402+
43403+ pax_track_stack();
43404
43405 /*
43406 * In some cases (e.g. Hyper-Threading), we want to avoid L1
43407@@ -195,8 +209,12 @@ create_elf_tables(struct linux_binprm *b
43408 * Generate 16 random bytes for userspace PRNG seeding.
43409 */
43410 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
43411- u_rand_bytes = (elf_addr_t __user *)
43412- STACK_ALLOC(p, sizeof(k_rand_bytes));
43413+ srandom32(k_rand_bytes[0] ^ random32());
43414+ srandom32(k_rand_bytes[1] ^ random32());
43415+ srandom32(k_rand_bytes[2] ^ random32());
43416+ srandom32(k_rand_bytes[3] ^ random32());
43417+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
43418+ u_rand_bytes = (elf_addr_t __user *) p;
43419 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
43420 return -EFAULT;
43421
43422@@ -308,9 +326,11 @@ create_elf_tables(struct linux_binprm *b
43423 return -EFAULT;
43424 current->mm->env_end = p;
43425
43426+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
43427+
43428 /* Put the elf_info on the stack in the right place. */
43429 sp = (elf_addr_t __user *)envp + 1;
43430- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
43431+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
43432 return -EFAULT;
43433 return 0;
43434 }
43435@@ -381,10 +401,10 @@ static unsigned long load_elf_interp(str
43436 {
43437 struct elf_phdr *elf_phdata;
43438 struct elf_phdr *eppnt;
43439- unsigned long load_addr = 0;
43440+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
43441 int load_addr_set = 0;
43442 unsigned long last_bss = 0, elf_bss = 0;
43443- unsigned long error = ~0UL;
43444+ unsigned long error = -EINVAL;
43445 unsigned long total_size;
43446 int retval, i, size;
43447
43448@@ -430,6 +450,11 @@ static unsigned long load_elf_interp(str
43449 goto out_close;
43450 }
43451
43452+#ifdef CONFIG_PAX_SEGMEXEC
43453+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
43454+ pax_task_size = SEGMEXEC_TASK_SIZE;
43455+#endif
43456+
43457 eppnt = elf_phdata;
43458 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
43459 if (eppnt->p_type == PT_LOAD) {
43460@@ -473,8 +498,8 @@ static unsigned long load_elf_interp(str
43461 k = load_addr + eppnt->p_vaddr;
43462 if (BAD_ADDR(k) ||
43463 eppnt->p_filesz > eppnt->p_memsz ||
43464- eppnt->p_memsz > TASK_SIZE ||
43465- TASK_SIZE - eppnt->p_memsz < k) {
43466+ eppnt->p_memsz > pax_task_size ||
43467+ pax_task_size - eppnt->p_memsz < k) {
43468 error = -ENOMEM;
43469 goto out_close;
43470 }
43471@@ -528,6 +553,193 @@ out:
43472 return error;
43473 }
43474
43475+#if (defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)) && defined(CONFIG_PAX_SOFTMODE)
43476+static unsigned long pax_parse_softmode(const struct elf_phdr * const elf_phdata)
43477+{
43478+ unsigned long pax_flags = 0UL;
43479+
43480+#ifdef CONFIG_PAX_PAGEEXEC
43481+ if (elf_phdata->p_flags & PF_PAGEEXEC)
43482+ pax_flags |= MF_PAX_PAGEEXEC;
43483+#endif
43484+
43485+#ifdef CONFIG_PAX_SEGMEXEC
43486+ if (elf_phdata->p_flags & PF_SEGMEXEC)
43487+ pax_flags |= MF_PAX_SEGMEXEC;
43488+#endif
43489+
43490+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
43491+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43492+ if ((__supported_pte_mask & _PAGE_NX))
43493+ pax_flags &= ~MF_PAX_SEGMEXEC;
43494+ else
43495+ pax_flags &= ~MF_PAX_PAGEEXEC;
43496+ }
43497+#endif
43498+
43499+#ifdef CONFIG_PAX_EMUTRAMP
43500+ if (elf_phdata->p_flags & PF_EMUTRAMP)
43501+ pax_flags |= MF_PAX_EMUTRAMP;
43502+#endif
43503+
43504+#ifdef CONFIG_PAX_MPROTECT
43505+ if (elf_phdata->p_flags & PF_MPROTECT)
43506+ pax_flags |= MF_PAX_MPROTECT;
43507+#endif
43508+
43509+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43510+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
43511+ pax_flags |= MF_PAX_RANDMMAP;
43512+#endif
43513+
43514+ return pax_flags;
43515+}
43516+#endif
43517+
43518+#ifdef CONFIG_PAX_PT_PAX_FLAGS
43519+static unsigned long pax_parse_hardmode(const struct elf_phdr * const elf_phdata)
43520+{
43521+ unsigned long pax_flags = 0UL;
43522+
43523+#ifdef CONFIG_PAX_PAGEEXEC
43524+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
43525+ pax_flags |= MF_PAX_PAGEEXEC;
43526+#endif
43527+
43528+#ifdef CONFIG_PAX_SEGMEXEC
43529+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
43530+ pax_flags |= MF_PAX_SEGMEXEC;
43531+#endif
43532+
43533+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
43534+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43535+ if ((__supported_pte_mask & _PAGE_NX))
43536+ pax_flags &= ~MF_PAX_SEGMEXEC;
43537+ else
43538+ pax_flags &= ~MF_PAX_PAGEEXEC;
43539+ }
43540+#endif
43541+
43542+#ifdef CONFIG_PAX_EMUTRAMP
43543+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
43544+ pax_flags |= MF_PAX_EMUTRAMP;
43545+#endif
43546+
43547+#ifdef CONFIG_PAX_MPROTECT
43548+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
43549+ pax_flags |= MF_PAX_MPROTECT;
43550+#endif
43551+
43552+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43553+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
43554+ pax_flags |= MF_PAX_RANDMMAP;
43555+#endif
43556+
43557+ return pax_flags;
43558+}
43559+#endif
43560+
43561+#ifdef CONFIG_PAX_EI_PAX
43562+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
43563+{
43564+ unsigned long pax_flags = 0UL;
43565+
43566+#ifdef CONFIG_PAX_PAGEEXEC
43567+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
43568+ pax_flags |= MF_PAX_PAGEEXEC;
43569+#endif
43570+
43571+#ifdef CONFIG_PAX_SEGMEXEC
43572+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
43573+ pax_flags |= MF_PAX_SEGMEXEC;
43574+#endif
43575+
43576+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
43577+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43578+ if ((__supported_pte_mask & _PAGE_NX))
43579+ pax_flags &= ~MF_PAX_SEGMEXEC;
43580+ else
43581+ pax_flags &= ~MF_PAX_PAGEEXEC;
43582+ }
43583+#endif
43584+
43585+#ifdef CONFIG_PAX_EMUTRAMP
43586+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
43587+ pax_flags |= MF_PAX_EMUTRAMP;
43588+#endif
43589+
43590+#ifdef CONFIG_PAX_MPROTECT
43591+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
43592+ pax_flags |= MF_PAX_MPROTECT;
43593+#endif
43594+
43595+#ifdef CONFIG_PAX_ASLR
43596+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
43597+ pax_flags |= MF_PAX_RANDMMAP;
43598+#endif
43599+
43600+ return pax_flags;
43601+}
43602+#endif
43603+
43604+#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)
43605+static long pax_parse_elf_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
43606+{
43607+ unsigned long pax_flags = 0UL;
43608+
43609+#ifdef CONFIG_PAX_PT_PAX_FLAGS
43610+ unsigned long i;
43611+ int found_flags = 0;
43612+#endif
43613+
43614+#ifdef CONFIG_PAX_EI_PAX
43615+ pax_flags = pax_parse_ei_pax(elf_ex);
43616+#endif
43617+
43618+#ifdef CONFIG_PAX_PT_PAX_FLAGS
43619+ for (i = 0UL; i < elf_ex->e_phnum; i++)
43620+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
43621+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
43622+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
43623+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
43624+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
43625+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
43626+ return -EINVAL;
43627+
43628+#ifdef CONFIG_PAX_SOFTMODE
43629+ if (pax_softmode)
43630+ pax_flags = pax_parse_softmode(&elf_phdata[i]);
43631+ else
43632+#endif
43633+
43634+ pax_flags = pax_parse_hardmode(&elf_phdata[i]);
43635+ found_flags = 1;
43636+ break;
43637+ }
43638+#endif
43639+
43640+#if !defined(CONFIG_PAX_EI_PAX) && defined(CONFIG_PAX_PT_PAX_FLAGS)
43641+ if (found_flags == 0) {
43642+ struct elf_phdr phdr;
43643+ memset(&phdr, 0, sizeof(phdr));
43644+ phdr.p_flags = PF_NOEMUTRAMP;
43645+#ifdef CONFIG_PAX_SOFTMODE
43646+ if (pax_softmode)
43647+ pax_flags = pax_parse_softmode(&phdr);
43648+ else
43649+#endif
43650+ pax_flags = pax_parse_hardmode(&phdr);
43651+ }
43652+#endif
43653+
43654+ if (0 > pax_check_flags(&pax_flags))
43655+ return -EINVAL;
43656+
43657+ current->mm->pax_flags = pax_flags;
43658+ return 0;
43659+}
43660+#endif
43661+
43662 /*
43663 * These are the functions used to load ELF style executables and shared
43664 * libraries. There is no binary dependent code anywhere else.
43665@@ -544,6 +756,11 @@ static unsigned long randomize_stack_top
43666 {
43667 unsigned int random_variable = 0;
43668
43669+#ifdef CONFIG_PAX_RANDUSTACK
43670+ if (randomize_va_space)
43671+ return stack_top - current->mm->delta_stack;
43672+#endif
43673+
43674 if ((current->flags & PF_RANDOMIZE) &&
43675 !(current->personality & ADDR_NO_RANDOMIZE)) {
43676 random_variable = get_random_int() & STACK_RND_MASK;
43677@@ -562,7 +779,7 @@ static int load_elf_binary(struct linux_
43678 unsigned long load_addr = 0, load_bias = 0;
43679 int load_addr_set = 0;
43680 char * elf_interpreter = NULL;
43681- unsigned long error;
43682+ unsigned long error = 0;
43683 struct elf_phdr *elf_ppnt, *elf_phdata;
43684 unsigned long elf_bss, elf_brk;
43685 int retval, i;
43686@@ -572,11 +789,11 @@ static int load_elf_binary(struct linux_
43687 unsigned long start_code, end_code, start_data, end_data;
43688 unsigned long reloc_func_desc __maybe_unused = 0;
43689 int executable_stack = EXSTACK_DEFAULT;
43690- unsigned long def_flags = 0;
43691 struct {
43692 struct elfhdr elf_ex;
43693 struct elfhdr interp_elf_ex;
43694 } *loc;
43695+ unsigned long pax_task_size = TASK_SIZE;
43696
43697 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
43698 if (!loc) {
43699@@ -714,11 +931,81 @@ static int load_elf_binary(struct linux_
43700
43701 /* OK, This is the point of no return */
43702 current->flags &= ~PF_FORKNOEXEC;
43703- current->mm->def_flags = def_flags;
43704+
43705+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43706+ current->mm->pax_flags = 0UL;
43707+#endif
43708+
43709+#ifdef CONFIG_PAX_DLRESOLVE
43710+ current->mm->call_dl_resolve = 0UL;
43711+#endif
43712+
43713+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
43714+ current->mm->call_syscall = 0UL;
43715+#endif
43716+
43717+#ifdef CONFIG_PAX_ASLR
43718+ current->mm->delta_mmap = 0UL;
43719+ current->mm->delta_stack = 0UL;
43720+#endif
43721+
43722+ current->mm->def_flags = 0;
43723+
43724+#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)
43725+ if (0 > pax_parse_elf_flags(&loc->elf_ex, elf_phdata)) {
43726+ send_sig(SIGKILL, current, 0);
43727+ goto out_free_dentry;
43728+ }
43729+#endif
43730+
43731+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
43732+ pax_set_initial_flags(bprm);
43733+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
43734+ if (pax_set_initial_flags_func)
43735+ (pax_set_initial_flags_func)(bprm);
43736+#endif
43737+
43738+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
43739+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
43740+ current->mm->context.user_cs_limit = PAGE_SIZE;
43741+ current->mm->def_flags |= VM_PAGEEXEC;
43742+ }
43743+#endif
43744+
43745+#ifdef CONFIG_PAX_SEGMEXEC
43746+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
43747+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
43748+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
43749+ pax_task_size = SEGMEXEC_TASK_SIZE;
43750+ current->mm->def_flags |= VM_NOHUGEPAGE;
43751+ }
43752+#endif
43753+
43754+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
43755+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43756+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
43757+ put_cpu();
43758+ }
43759+#endif
43760
43761 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
43762 may depend on the personality. */
43763 SET_PERSONALITY(loc->elf_ex);
43764+
43765+#ifdef CONFIG_PAX_ASLR
43766+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43767+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
43768+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
43769+ }
43770+#endif
43771+
43772+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
43773+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43774+ executable_stack = EXSTACK_DISABLE_X;
43775+ current->personality &= ~READ_IMPLIES_EXEC;
43776+ } else
43777+#endif
43778+
43779 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
43780 current->personality |= READ_IMPLIES_EXEC;
43781
43782@@ -800,6 +1087,20 @@ static int load_elf_binary(struct linux_
43783 #else
43784 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
43785 #endif
43786+
43787+#ifdef CONFIG_PAX_RANDMMAP
43788+ /* PaX: randomize base address at the default exe base if requested */
43789+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
43790+#ifdef CONFIG_SPARC64
43791+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
43792+#else
43793+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
43794+#endif
43795+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
43796+ elf_flags |= MAP_FIXED;
43797+ }
43798+#endif
43799+
43800 }
43801
43802 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
43803@@ -832,9 +1133,9 @@ static int load_elf_binary(struct linux_
43804 * allowed task size. Note that p_filesz must always be
43805 * <= p_memsz so it is only necessary to check p_memsz.
43806 */
43807- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43808- elf_ppnt->p_memsz > TASK_SIZE ||
43809- TASK_SIZE - elf_ppnt->p_memsz < k) {
43810+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43811+ elf_ppnt->p_memsz > pax_task_size ||
43812+ pax_task_size - elf_ppnt->p_memsz < k) {
43813 /* set_brk can never work. Avoid overflows. */
43814 send_sig(SIGKILL, current, 0);
43815 retval = -EINVAL;
43816@@ -862,6 +1163,11 @@ static int load_elf_binary(struct linux_
43817 start_data += load_bias;
43818 end_data += load_bias;
43819
43820+#ifdef CONFIG_PAX_RANDMMAP
43821+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
43822+ elf_brk += PAGE_SIZE + ((pax_get_random_long() & ~PAGE_MASK) << 4);
43823+#endif
43824+
43825 /* Calling set_brk effectively mmaps the pages that we need
43826 * for the bss and break sections. We must do this before
43827 * mapping in the interpreter, to make sure it doesn't wind
43828@@ -873,9 +1179,11 @@ static int load_elf_binary(struct linux_
43829 goto out_free_dentry;
43830 }
43831 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
43832- send_sig(SIGSEGV, current, 0);
43833- retval = -EFAULT; /* Nobody gets to see this, but.. */
43834- goto out_free_dentry;
43835+ /*
43836+ * This bss-zeroing can fail if the ELF
43837+ * file specifies odd protections. So
43838+ * we don't check the return value
43839+ */
43840 }
43841
43842 if (elf_interpreter) {
43843@@ -1090,7 +1398,7 @@ out:
43844 * Decide what to dump of a segment, part, all or none.
43845 */
43846 static unsigned long vma_dump_size(struct vm_area_struct *vma,
43847- unsigned long mm_flags)
43848+ unsigned long mm_flags, long signr)
43849 {
43850 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
43851
43852@@ -1124,7 +1432,7 @@ static unsigned long vma_dump_size(struc
43853 if (vma->vm_file == NULL)
43854 return 0;
43855
43856- if (FILTER(MAPPED_PRIVATE))
43857+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
43858 goto whole;
43859
43860 /*
43861@@ -1346,9 +1654,9 @@ static void fill_auxv_note(struct memelf
43862 {
43863 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
43864 int i = 0;
43865- do
43866+ do {
43867 i += 2;
43868- while (auxv[i - 2] != AT_NULL);
43869+ } while (auxv[i - 2] != AT_NULL);
43870 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
43871 }
43872
43873@@ -1854,14 +2162,14 @@ static void fill_extnum_info(struct elfh
43874 }
43875
43876 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
43877- unsigned long mm_flags)
43878+ struct coredump_params *cprm)
43879 {
43880 struct vm_area_struct *vma;
43881 size_t size = 0;
43882
43883 for (vma = first_vma(current, gate_vma); vma != NULL;
43884 vma = next_vma(vma, gate_vma))
43885- size += vma_dump_size(vma, mm_flags);
43886+ size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43887 return size;
43888 }
43889
43890@@ -1955,7 +2263,7 @@ static int elf_core_dump(struct coredump
43891
43892 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
43893
43894- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
43895+ offset += elf_core_vma_data_size(gate_vma, cprm);
43896 offset += elf_core_extra_data_size();
43897 e_shoff = offset;
43898
43899@@ -1969,10 +2277,12 @@ static int elf_core_dump(struct coredump
43900 offset = dataoff;
43901
43902 size += sizeof(*elf);
43903+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
43904 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
43905 goto end_coredump;
43906
43907 size += sizeof(*phdr4note);
43908+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
43909 if (size > cprm->limit
43910 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
43911 goto end_coredump;
43912@@ -1986,7 +2296,7 @@ static int elf_core_dump(struct coredump
43913 phdr.p_offset = offset;
43914 phdr.p_vaddr = vma->vm_start;
43915 phdr.p_paddr = 0;
43916- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
43917+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43918 phdr.p_memsz = vma->vm_end - vma->vm_start;
43919 offset += phdr.p_filesz;
43920 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
43921@@ -1997,6 +2307,7 @@ static int elf_core_dump(struct coredump
43922 phdr.p_align = ELF_EXEC_PAGESIZE;
43923
43924 size += sizeof(phdr);
43925+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
43926 if (size > cprm->limit
43927 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
43928 goto end_coredump;
43929@@ -2021,7 +2332,7 @@ static int elf_core_dump(struct coredump
43930 unsigned long addr;
43931 unsigned long end;
43932
43933- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
43934+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43935
43936 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
43937 struct page *page;
43938@@ -2030,6 +2341,7 @@ static int elf_core_dump(struct coredump
43939 page = get_dump_page(addr);
43940 if (page) {
43941 void *kaddr = kmap(page);
43942+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
43943 stop = ((size += PAGE_SIZE) > cprm->limit) ||
43944 !dump_write(cprm->file, kaddr,
43945 PAGE_SIZE);
43946@@ -2047,6 +2359,7 @@ static int elf_core_dump(struct coredump
43947
43948 if (e_phnum == PN_XNUM) {
43949 size += sizeof(*shdr4extnum);
43950+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
43951 if (size > cprm->limit
43952 || !dump_write(cprm->file, shdr4extnum,
43953 sizeof(*shdr4extnum)))
43954@@ -2067,6 +2380,97 @@ out:
43955
43956 #endif /* CONFIG_ELF_CORE */
43957
43958+#ifdef CONFIG_PAX_MPROTECT
43959+/* PaX: non-PIC ELF libraries need relocations on their executable segments
43960+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
43961+ * we'll remove VM_MAYWRITE for good on RELRO segments.
43962+ *
43963+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
43964+ * basis because we want to allow the common case and not the special ones.
43965+ */
43966+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
43967+{
43968+ struct elfhdr elf_h;
43969+ struct elf_phdr elf_p;
43970+ unsigned long i;
43971+ unsigned long oldflags;
43972+ bool is_textrel_rw, is_textrel_rx, is_relro;
43973+
43974+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
43975+ return;
43976+
43977+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
43978+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
43979+
43980+#ifdef CONFIG_PAX_ELFRELOCS
43981+ /* possible TEXTREL */
43982+ is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
43983+ 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);
43984+#else
43985+ is_textrel_rw = false;
43986+ is_textrel_rx = false;
43987+#endif
43988+
43989+ /* possible RELRO */
43990+ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
43991+
43992+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
43993+ return;
43994+
43995+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
43996+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
43997+
43998+#ifdef CONFIG_PAX_ETEXECRELOCS
43999+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
44000+#else
44001+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
44002+#endif
44003+
44004+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
44005+ !elf_check_arch(&elf_h) ||
44006+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
44007+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
44008+ return;
44009+
44010+ for (i = 0UL; i < elf_h.e_phnum; i++) {
44011+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
44012+ return;
44013+ switch (elf_p.p_type) {
44014+ case PT_DYNAMIC:
44015+ if (!is_textrel_rw && !is_textrel_rx)
44016+ continue;
44017+ i = 0UL;
44018+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
44019+ elf_dyn dyn;
44020+
44021+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
44022+ return;
44023+ if (dyn.d_tag == DT_NULL)
44024+ return;
44025+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
44026+ gr_log_textrel(vma);
44027+ if (is_textrel_rw)
44028+ vma->vm_flags |= VM_MAYWRITE;
44029+ else
44030+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
44031+ vma->vm_flags &= ~VM_MAYWRITE;
44032+ return;
44033+ }
44034+ i++;
44035+ }
44036+ return;
44037+
44038+ case PT_GNU_RELRO:
44039+ if (!is_relro)
44040+ continue;
44041+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
44042+ vma->vm_flags &= ~VM_MAYWRITE;
44043+ return;
44044+ }
44045+ }
44046+}
44047+#endif
44048+
44049 static int __init init_elf_binfmt(void)
44050 {
44051 return register_binfmt(&elf_format);
44052diff -urNp linux-2.6.39.1/fs/binfmt_flat.c linux-2.6.39.1/fs/binfmt_flat.c
44053--- linux-2.6.39.1/fs/binfmt_flat.c 2011-05-19 00:06:34.000000000 -0400
44054+++ linux-2.6.39.1/fs/binfmt_flat.c 2011-05-22 19:36:32.000000000 -0400
44055@@ -567,7 +567,9 @@ static int load_flat_file(struct linux_b
44056 realdatastart = (unsigned long) -ENOMEM;
44057 printk("Unable to allocate RAM for process data, errno %d\n",
44058 (int)-realdatastart);
44059+ down_write(&current->mm->mmap_sem);
44060 do_munmap(current->mm, textpos, text_len);
44061+ up_write(&current->mm->mmap_sem);
44062 ret = realdatastart;
44063 goto err;
44064 }
44065@@ -591,8 +593,10 @@ static int load_flat_file(struct linux_b
44066 }
44067 if (IS_ERR_VALUE(result)) {
44068 printk("Unable to read data+bss, errno %d\n", (int)-result);
44069+ down_write(&current->mm->mmap_sem);
44070 do_munmap(current->mm, textpos, text_len);
44071 do_munmap(current->mm, realdatastart, len);
44072+ up_write(&current->mm->mmap_sem);
44073 ret = result;
44074 goto err;
44075 }
44076@@ -661,8 +665,10 @@ static int load_flat_file(struct linux_b
44077 }
44078 if (IS_ERR_VALUE(result)) {
44079 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
44080+ down_write(&current->mm->mmap_sem);
44081 do_munmap(current->mm, textpos, text_len + data_len + extra +
44082 MAX_SHARED_LIBS * sizeof(unsigned long));
44083+ up_write(&current->mm->mmap_sem);
44084 ret = result;
44085 goto err;
44086 }
44087diff -urNp linux-2.6.39.1/fs/bio.c linux-2.6.39.1/fs/bio.c
44088--- linux-2.6.39.1/fs/bio.c 2011-05-19 00:06:34.000000000 -0400
44089+++ linux-2.6.39.1/fs/bio.c 2011-05-22 19:36:32.000000000 -0400
44090@@ -1233,7 +1233,7 @@ static void bio_copy_kern_endio(struct b
44091 const int read = bio_data_dir(bio) == READ;
44092 struct bio_map_data *bmd = bio->bi_private;
44093 int i;
44094- char *p = bmd->sgvecs[0].iov_base;
44095+ char *p = (__force char *)bmd->sgvecs[0].iov_base;
44096
44097 __bio_for_each_segment(bvec, bio, i, 0) {
44098 char *addr = page_address(bvec->bv_page);
44099diff -urNp linux-2.6.39.1/fs/block_dev.c linux-2.6.39.1/fs/block_dev.c
44100--- linux-2.6.39.1/fs/block_dev.c 2011-06-03 00:04:14.000000000 -0400
44101+++ linux-2.6.39.1/fs/block_dev.c 2011-06-06 19:57:05.000000000 -0400
44102@@ -671,7 +671,7 @@ static bool bd_may_claim(struct block_de
44103 else if (bdev->bd_contains == bdev)
44104 return true; /* is a whole device which isn't held */
44105
44106- else if (whole->bd_holder == bd_may_claim)
44107+ else if (whole->bd_holder == (void *)bd_may_claim)
44108 return true; /* is a partition of a device that is being partitioned */
44109 else if (whole->bd_holder != NULL)
44110 return false; /* is a partition of a held device */
44111@@ -1272,8 +1272,8 @@ int blkdev_get(struct block_device *bdev
44112 * individual writeable reference is too fragile given the
44113 * way @mode is used in blkdev_get/put().
44114 */
44115- if ((disk->flags & GENHD_FL_BLOCK_EVENTS_ON_EXCL_WRITE) &&
44116- !res && (mode & FMODE_WRITE) && !bdev->bd_write_holder) {
44117+ if (!res && (mode & FMODE_WRITE) && !bdev->bd_write_holder &&
44118+ (disk->flags & GENHD_FL_BLOCK_EVENTS_ON_EXCL_WRITE)) {
44119 bdev->bd_write_holder = true;
44120 disk_block_events(disk);
44121 }
44122diff -urNp linux-2.6.39.1/fs/btrfs/compression.c linux-2.6.39.1/fs/btrfs/compression.c
44123--- linux-2.6.39.1/fs/btrfs/compression.c 2011-05-19 00:06:34.000000000 -0400
44124+++ linux-2.6.39.1/fs/btrfs/compression.c 2011-05-22 19:36:32.000000000 -0400
44125@@ -719,7 +719,7 @@ static int comp_num_workspace[BTRFS_COMP
44126 static atomic_t comp_alloc_workspace[BTRFS_COMPRESS_TYPES];
44127 static wait_queue_head_t comp_workspace_wait[BTRFS_COMPRESS_TYPES];
44128
44129-struct btrfs_compress_op *btrfs_compress_op[] = {
44130+const struct btrfs_compress_op *btrfs_compress_op[] = {
44131 &btrfs_zlib_compress,
44132 &btrfs_lzo_compress,
44133 };
44134diff -urNp linux-2.6.39.1/fs/btrfs/compression.h linux-2.6.39.1/fs/btrfs/compression.h
44135--- linux-2.6.39.1/fs/btrfs/compression.h 2011-05-19 00:06:34.000000000 -0400
44136+++ linux-2.6.39.1/fs/btrfs/compression.h 2011-05-22 19:36:32.000000000 -0400
44137@@ -77,7 +77,7 @@ struct btrfs_compress_op {
44138 size_t srclen, size_t destlen);
44139 };
44140
44141-extern struct btrfs_compress_op btrfs_zlib_compress;
44142-extern struct btrfs_compress_op btrfs_lzo_compress;
44143+extern const struct btrfs_compress_op btrfs_zlib_compress;
44144+extern const struct btrfs_compress_op btrfs_lzo_compress;
44145
44146 #endif
44147diff -urNp linux-2.6.39.1/fs/btrfs/ctree.c linux-2.6.39.1/fs/btrfs/ctree.c
44148--- linux-2.6.39.1/fs/btrfs/ctree.c 2011-05-19 00:06:34.000000000 -0400
44149+++ linux-2.6.39.1/fs/btrfs/ctree.c 2011-05-22 19:36:32.000000000 -0400
44150@@ -461,9 +461,12 @@ static noinline int __btrfs_cow_block(st
44151 free_extent_buffer(buf);
44152 add_root_to_dirty_list(root);
44153 } else {
44154- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
44155- parent_start = parent->start;
44156- else
44157+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
44158+ if (parent)
44159+ parent_start = parent->start;
44160+ else
44161+ parent_start = 0;
44162+ } else
44163 parent_start = 0;
44164
44165 WARN_ON(trans->transid != btrfs_header_generation(parent));
44166@@ -3647,7 +3650,6 @@ setup_items_for_insert(struct btrfs_tran
44167
44168 ret = 0;
44169 if (slot == 0) {
44170- struct btrfs_disk_key disk_key;
44171 btrfs_cpu_key_to_disk(&disk_key, cpu_key);
44172 ret = fixup_low_keys(trans, root, path, &disk_key, 1);
44173 }
44174diff -urNp linux-2.6.39.1/fs/btrfs/disk-io.c linux-2.6.39.1/fs/btrfs/disk-io.c
44175--- linux-2.6.39.1/fs/btrfs/disk-io.c 2011-05-19 00:06:34.000000000 -0400
44176+++ linux-2.6.39.1/fs/btrfs/disk-io.c 2011-05-22 19:36:32.000000000 -0400
44177@@ -42,7 +42,7 @@
44178 #include "tree-log.h"
44179 #include "free-space-cache.h"
44180
44181-static struct extent_io_ops btree_extent_io_ops;
44182+static const struct extent_io_ops btree_extent_io_ops;
44183 static void end_workqueue_fn(struct btrfs_work *work);
44184 static void free_fs_root(struct btrfs_root *root);
44185 static void btrfs_check_super_valid(struct btrfs_fs_info *fs_info,
44186@@ -3070,7 +3070,7 @@ static int btrfs_cleanup_transaction(str
44187 return 0;
44188 }
44189
44190-static struct extent_io_ops btree_extent_io_ops = {
44191+static const struct extent_io_ops btree_extent_io_ops = {
44192 .write_cache_pages_lock_hook = btree_lock_page_hook,
44193 .readpage_end_io_hook = btree_readpage_end_io_hook,
44194 .submit_bio_hook = btree_submit_bio_hook,
44195diff -urNp linux-2.6.39.1/fs/btrfs/extent_io.h linux-2.6.39.1/fs/btrfs/extent_io.h
44196--- linux-2.6.39.1/fs/btrfs/extent_io.h 2011-05-19 00:06:34.000000000 -0400
44197+++ linux-2.6.39.1/fs/btrfs/extent_io.h 2011-05-22 19:36:32.000000000 -0400
44198@@ -56,36 +56,36 @@ typedef int (extent_submit_bio_hook_t)(s
44199 struct bio *bio, int mirror_num,
44200 unsigned long bio_flags, u64 bio_offset);
44201 struct extent_io_ops {
44202- int (*fill_delalloc)(struct inode *inode, struct page *locked_page,
44203+ int (* const fill_delalloc)(struct inode *inode, struct page *locked_page,
44204 u64 start, u64 end, int *page_started,
44205 unsigned long *nr_written);
44206- int (*writepage_start_hook)(struct page *page, u64 start, u64 end);
44207- int (*writepage_io_hook)(struct page *page, u64 start, u64 end);
44208+ int (* const writepage_start_hook)(struct page *page, u64 start, u64 end);
44209+ int (* const writepage_io_hook)(struct page *page, u64 start, u64 end);
44210 extent_submit_bio_hook_t *submit_bio_hook;
44211- int (*merge_bio_hook)(struct page *page, unsigned long offset,
44212+ int (* const merge_bio_hook)(struct page *page, unsigned long offset,
44213 size_t size, struct bio *bio,
44214 unsigned long bio_flags);
44215- int (*readpage_io_hook)(struct page *page, u64 start, u64 end);
44216- int (*readpage_io_failed_hook)(struct bio *bio, struct page *page,
44217+ int (* const readpage_io_hook)(struct page *page, u64 start, u64 end);
44218+ int (* const readpage_io_failed_hook)(struct bio *bio, struct page *page,
44219 u64 start, u64 end,
44220 struct extent_state *state);
44221- int (*writepage_io_failed_hook)(struct bio *bio, struct page *page,
44222+ int (* const writepage_io_failed_hook)(struct bio *bio, struct page *page,
44223 u64 start, u64 end,
44224 struct extent_state *state);
44225- int (*readpage_end_io_hook)(struct page *page, u64 start, u64 end,
44226+ int (* const readpage_end_io_hook)(struct page *page, u64 start, u64 end,
44227 struct extent_state *state);
44228- int (*writepage_end_io_hook)(struct page *page, u64 start, u64 end,
44229+ int (* const writepage_end_io_hook)(struct page *page, u64 start, u64 end,
44230 struct extent_state *state, int uptodate);
44231- int (*set_bit_hook)(struct inode *inode, struct extent_state *state,
44232+ int (* const set_bit_hook)(struct inode *inode, struct extent_state *state,
44233 int *bits);
44234- int (*clear_bit_hook)(struct inode *inode, struct extent_state *state,
44235+ int (* const clear_bit_hook)(struct inode *inode, struct extent_state *state,
44236 int *bits);
44237- int (*merge_extent_hook)(struct inode *inode,
44238+ int (* const merge_extent_hook)(struct inode *inode,
44239 struct extent_state *new,
44240 struct extent_state *other);
44241- int (*split_extent_hook)(struct inode *inode,
44242+ int (* const split_extent_hook)(struct inode *inode,
44243 struct extent_state *orig, u64 split);
44244- int (*write_cache_pages_lock_hook)(struct page *page);
44245+ int (* const write_cache_pages_lock_hook)(struct page *page);
44246 };
44247
44248 struct extent_io_tree {
44249@@ -95,7 +95,7 @@ struct extent_io_tree {
44250 u64 dirty_bytes;
44251 spinlock_t lock;
44252 spinlock_t buffer_lock;
44253- struct extent_io_ops *ops;
44254+ const struct extent_io_ops *ops;
44255 };
44256
44257 struct extent_state {
44258diff -urNp linux-2.6.39.1/fs/btrfs/free-space-cache.c linux-2.6.39.1/fs/btrfs/free-space-cache.c
44259--- linux-2.6.39.1/fs/btrfs/free-space-cache.c 2011-05-19 00:06:34.000000000 -0400
44260+++ linux-2.6.39.1/fs/btrfs/free-space-cache.c 2011-05-22 19:36:32.000000000 -0400
44261@@ -1910,8 +1910,6 @@ u64 btrfs_alloc_from_cluster(struct btrf
44262 while(1) {
44263 if (entry->bytes < bytes ||
44264 (!entry->bitmap && entry->offset < min_start)) {
44265- struct rb_node *node;
44266-
44267 node = rb_next(&entry->offset_index);
44268 if (!node)
44269 break;
44270@@ -1925,7 +1923,6 @@ u64 btrfs_alloc_from_cluster(struct btrf
44271 cluster, entry, bytes,
44272 min_start);
44273 if (ret == 0) {
44274- struct rb_node *node;
44275 node = rb_next(&entry->offset_index);
44276 if (!node)
44277 break;
44278diff -urNp linux-2.6.39.1/fs/btrfs/inode.c linux-2.6.39.1/fs/btrfs/inode.c
44279--- linux-2.6.39.1/fs/btrfs/inode.c 2011-05-19 00:06:34.000000000 -0400
44280+++ linux-2.6.39.1/fs/btrfs/inode.c 2011-05-22 20:42:42.000000000 -0400
44281@@ -65,7 +65,7 @@ static const struct inode_operations btr
44282 static const struct address_space_operations btrfs_aops;
44283 static const struct address_space_operations btrfs_symlink_aops;
44284 static const struct file_operations btrfs_dir_file_operations;
44285-static struct extent_io_ops btrfs_extent_io_ops;
44286+static const struct extent_io_ops btrfs_extent_io_ops;
44287
44288 static struct kmem_cache *btrfs_inode_cachep;
44289 struct kmem_cache *btrfs_trans_handle_cachep;
44290@@ -6947,7 +6947,7 @@ fail:
44291 return -ENOMEM;
44292 }
44293
44294-static int btrfs_getattr(struct vfsmount *mnt,
44295+int btrfs_getattr(struct vfsmount *mnt,
44296 struct dentry *dentry, struct kstat *stat)
44297 {
44298 struct inode *inode = dentry->d_inode;
44299@@ -6959,6 +6959,14 @@ static int btrfs_getattr(struct vfsmount
44300 return 0;
44301 }
44302
44303+EXPORT_SYMBOL(btrfs_getattr);
44304+
44305+dev_t get_btrfs_dev_from_inode(struct inode *inode)
44306+{
44307+ return BTRFS_I(inode)->root->anon_super.s_dev;
44308+}
44309+EXPORT_SYMBOL(get_btrfs_dev_from_inode);
44310+
44311 /*
44312 * If a file is moved, it will inherit the cow and compression flags of the new
44313 * directory.
44314@@ -7488,7 +7496,7 @@ static const struct file_operations btrf
44315 .fsync = btrfs_sync_file,
44316 };
44317
44318-static struct extent_io_ops btrfs_extent_io_ops = {
44319+static const struct extent_io_ops btrfs_extent_io_ops = {
44320 .fill_delalloc = run_delalloc_range,
44321 .submit_bio_hook = btrfs_submit_bio_hook,
44322 .merge_bio_hook = btrfs_merge_bio_hook,
44323diff -urNp linux-2.6.39.1/fs/btrfs/ioctl.c linux-2.6.39.1/fs/btrfs/ioctl.c
44324--- linux-2.6.39.1/fs/btrfs/ioctl.c 2011-05-19 00:06:34.000000000 -0400
44325+++ linux-2.6.39.1/fs/btrfs/ioctl.c 2011-05-22 19:41:37.000000000 -0400
44326@@ -2361,9 +2361,12 @@ long btrfs_ioctl_space_info(struct btrfs
44327 for (i = 0; i < num_types; i++) {
44328 struct btrfs_space_info *tmp;
44329
44330+ /* Don't copy in more than we allocated */
44331 if (!slot_count)
44332 break;
44333
44334+ slot_count--;
44335+
44336 info = NULL;
44337 rcu_read_lock();
44338 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
44339@@ -2385,10 +2388,7 @@ long btrfs_ioctl_space_info(struct btrfs
44340 memcpy(dest, &space, sizeof(space));
44341 dest++;
44342 space_args.total_spaces++;
44343- slot_count--;
44344 }
44345- if (!slot_count)
44346- break;
44347 }
44348 up_read(&info->groups_sem);
44349 }
44350diff -urNp linux-2.6.39.1/fs/btrfs/lzo.c linux-2.6.39.1/fs/btrfs/lzo.c
44351--- linux-2.6.39.1/fs/btrfs/lzo.c 2011-05-19 00:06:34.000000000 -0400
44352+++ linux-2.6.39.1/fs/btrfs/lzo.c 2011-05-22 19:36:32.000000000 -0400
44353@@ -418,7 +418,7 @@ out:
44354 return ret;
44355 }
44356
44357-struct btrfs_compress_op btrfs_lzo_compress = {
44358+const struct btrfs_compress_op btrfs_lzo_compress = {
44359 .alloc_workspace = lzo_alloc_workspace,
44360 .free_workspace = lzo_free_workspace,
44361 .compress_pages = lzo_compress_pages,
44362diff -urNp linux-2.6.39.1/fs/btrfs/relocation.c linux-2.6.39.1/fs/btrfs/relocation.c
44363--- linux-2.6.39.1/fs/btrfs/relocation.c 2011-05-19 00:06:34.000000000 -0400
44364+++ linux-2.6.39.1/fs/btrfs/relocation.c 2011-05-22 19:36:32.000000000 -0400
44365@@ -1239,7 +1239,7 @@ static int __update_reloc_root(struct bt
44366 }
44367 spin_unlock(&rc->reloc_root_tree.lock);
44368
44369- BUG_ON((struct btrfs_root *)node->data != root);
44370+ BUG_ON(!node || (struct btrfs_root *)node->data != root);
44371
44372 if (!del) {
44373 spin_lock(&rc->reloc_root_tree.lock);
44374diff -urNp linux-2.6.39.1/fs/btrfs/zlib.c linux-2.6.39.1/fs/btrfs/zlib.c
44375--- linux-2.6.39.1/fs/btrfs/zlib.c 2011-05-19 00:06:34.000000000 -0400
44376+++ linux-2.6.39.1/fs/btrfs/zlib.c 2011-05-22 19:36:32.000000000 -0400
44377@@ -390,7 +390,7 @@ next:
44378 return ret;
44379 }
44380
44381-struct btrfs_compress_op btrfs_zlib_compress = {
44382+const struct btrfs_compress_op btrfs_zlib_compress = {
44383 .alloc_workspace = zlib_alloc_workspace,
44384 .free_workspace = zlib_free_workspace,
44385 .compress_pages = zlib_compress_pages,
44386diff -urNp linux-2.6.39.1/fs/cachefiles/bind.c linux-2.6.39.1/fs/cachefiles/bind.c
44387--- linux-2.6.39.1/fs/cachefiles/bind.c 2011-05-19 00:06:34.000000000 -0400
44388+++ linux-2.6.39.1/fs/cachefiles/bind.c 2011-05-22 19:36:32.000000000 -0400
44389@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachef
44390 args);
44391
44392 /* start by checking things over */
44393- ASSERT(cache->fstop_percent >= 0 &&
44394- cache->fstop_percent < cache->fcull_percent &&
44395+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
44396 cache->fcull_percent < cache->frun_percent &&
44397 cache->frun_percent < 100);
44398
44399- ASSERT(cache->bstop_percent >= 0 &&
44400- cache->bstop_percent < cache->bcull_percent &&
44401+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
44402 cache->bcull_percent < cache->brun_percent &&
44403 cache->brun_percent < 100);
44404
44405diff -urNp linux-2.6.39.1/fs/cachefiles/daemon.c linux-2.6.39.1/fs/cachefiles/daemon.c
44406--- linux-2.6.39.1/fs/cachefiles/daemon.c 2011-05-19 00:06:34.000000000 -0400
44407+++ linux-2.6.39.1/fs/cachefiles/daemon.c 2011-05-22 19:36:32.000000000 -0400
44408@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(st
44409 if (n > buflen)
44410 return -EMSGSIZE;
44411
44412- if (copy_to_user(_buffer, buffer, n) != 0)
44413+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
44414 return -EFAULT;
44415
44416 return n;
44417@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(s
44418 if (test_bit(CACHEFILES_DEAD, &cache->flags))
44419 return -EIO;
44420
44421- if (datalen < 0 || datalen > PAGE_SIZE - 1)
44422+ if (datalen > PAGE_SIZE - 1)
44423 return -EOPNOTSUPP;
44424
44425 /* drag the command string into the kernel so we can parse it */
44426@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struc
44427 if (args[0] != '%' || args[1] != '\0')
44428 return -EINVAL;
44429
44430- if (fstop < 0 || fstop >= cache->fcull_percent)
44431+ if (fstop >= cache->fcull_percent)
44432 return cachefiles_daemon_range_error(cache, args);
44433
44434 cache->fstop_percent = fstop;
44435@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struc
44436 if (args[0] != '%' || args[1] != '\0')
44437 return -EINVAL;
44438
44439- if (bstop < 0 || bstop >= cache->bcull_percent)
44440+ if (bstop >= cache->bcull_percent)
44441 return cachefiles_daemon_range_error(cache, args);
44442
44443 cache->bstop_percent = bstop;
44444diff -urNp linux-2.6.39.1/fs/cachefiles/internal.h linux-2.6.39.1/fs/cachefiles/internal.h
44445--- linux-2.6.39.1/fs/cachefiles/internal.h 2011-05-19 00:06:34.000000000 -0400
44446+++ linux-2.6.39.1/fs/cachefiles/internal.h 2011-05-22 19:36:32.000000000 -0400
44447@@ -57,7 +57,7 @@ struct cachefiles_cache {
44448 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
44449 struct rb_root active_nodes; /* active nodes (can't be culled) */
44450 rwlock_t active_lock; /* lock for active_nodes */
44451- atomic_t gravecounter; /* graveyard uniquifier */
44452+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
44453 unsigned frun_percent; /* when to stop culling (% files) */
44454 unsigned fcull_percent; /* when to start culling (% files) */
44455 unsigned fstop_percent; /* when to stop allocating (% files) */
44456@@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struc
44457 * proc.c
44458 */
44459 #ifdef CONFIG_CACHEFILES_HISTOGRAM
44460-extern atomic_t cachefiles_lookup_histogram[HZ];
44461-extern atomic_t cachefiles_mkdir_histogram[HZ];
44462-extern atomic_t cachefiles_create_histogram[HZ];
44463+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
44464+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
44465+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
44466
44467 extern int __init cachefiles_proc_init(void);
44468 extern void cachefiles_proc_cleanup(void);
44469 static inline
44470-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
44471+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
44472 {
44473 unsigned long jif = jiffies - start_jif;
44474 if (jif >= HZ)
44475 jif = HZ - 1;
44476- atomic_inc(&histogram[jif]);
44477+ atomic_inc_unchecked(&histogram[jif]);
44478 }
44479
44480 #else
44481diff -urNp linux-2.6.39.1/fs/cachefiles/namei.c linux-2.6.39.1/fs/cachefiles/namei.c
44482--- linux-2.6.39.1/fs/cachefiles/namei.c 2011-05-19 00:06:34.000000000 -0400
44483+++ linux-2.6.39.1/fs/cachefiles/namei.c 2011-05-22 19:36:32.000000000 -0400
44484@@ -318,7 +318,7 @@ try_again:
44485 /* first step is to make up a grave dentry in the graveyard */
44486 sprintf(nbuffer, "%08x%08x",
44487 (uint32_t) get_seconds(),
44488- (uint32_t) atomic_inc_return(&cache->gravecounter));
44489+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
44490
44491 /* do the multiway lock magic */
44492 trap = lock_rename(cache->graveyard, dir);
44493diff -urNp linux-2.6.39.1/fs/cachefiles/proc.c linux-2.6.39.1/fs/cachefiles/proc.c
44494--- linux-2.6.39.1/fs/cachefiles/proc.c 2011-05-19 00:06:34.000000000 -0400
44495+++ linux-2.6.39.1/fs/cachefiles/proc.c 2011-05-22 19:36:32.000000000 -0400
44496@@ -14,9 +14,9 @@
44497 #include <linux/seq_file.h>
44498 #include "internal.h"
44499
44500-atomic_t cachefiles_lookup_histogram[HZ];
44501-atomic_t cachefiles_mkdir_histogram[HZ];
44502-atomic_t cachefiles_create_histogram[HZ];
44503+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
44504+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
44505+atomic_unchecked_t cachefiles_create_histogram[HZ];
44506
44507 /*
44508 * display the latency histogram
44509@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(str
44510 return 0;
44511 default:
44512 index = (unsigned long) v - 3;
44513- x = atomic_read(&cachefiles_lookup_histogram[index]);
44514- y = atomic_read(&cachefiles_mkdir_histogram[index]);
44515- z = atomic_read(&cachefiles_create_histogram[index]);
44516+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
44517+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
44518+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
44519 if (x == 0 && y == 0 && z == 0)
44520 return 0;
44521
44522diff -urNp linux-2.6.39.1/fs/cachefiles/rdwr.c linux-2.6.39.1/fs/cachefiles/rdwr.c
44523--- linux-2.6.39.1/fs/cachefiles/rdwr.c 2011-05-19 00:06:34.000000000 -0400
44524+++ linux-2.6.39.1/fs/cachefiles/rdwr.c 2011-05-22 19:36:32.000000000 -0400
44525@@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache
44526 old_fs = get_fs();
44527 set_fs(KERNEL_DS);
44528 ret = file->f_op->write(
44529- file, (const void __user *) data, len, &pos);
44530+ file, (__force const void __user *) data, len, &pos);
44531 set_fs(old_fs);
44532 kunmap(page);
44533 if (ret != len)
44534diff -urNp linux-2.6.39.1/fs/ceph/addr.c linux-2.6.39.1/fs/ceph/addr.c
44535--- linux-2.6.39.1/fs/ceph/addr.c 2011-05-19 00:06:34.000000000 -0400
44536+++ linux-2.6.39.1/fs/ceph/addr.c 2011-05-22 19:36:32.000000000 -0400
44537@@ -1164,7 +1164,7 @@ out:
44538 return ret;
44539 }
44540
44541-static struct vm_operations_struct ceph_vmops = {
44542+static const struct vm_operations_struct ceph_vmops = {
44543 .fault = filemap_fault,
44544 .page_mkwrite = ceph_page_mkwrite,
44545 };
44546diff -urNp linux-2.6.39.1/fs/ceph/dir.c linux-2.6.39.1/fs/ceph/dir.c
44547--- linux-2.6.39.1/fs/ceph/dir.c 2011-05-19 00:06:34.000000000 -0400
44548+++ linux-2.6.39.1/fs/ceph/dir.c 2011-05-22 19:36:32.000000000 -0400
44549@@ -226,7 +226,7 @@ static int ceph_readdir(struct file *fil
44550 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
44551 struct ceph_mds_client *mdsc = fsc->mdsc;
44552 unsigned frag = fpos_frag(filp->f_pos);
44553- int off = fpos_off(filp->f_pos);
44554+ unsigned int off = fpos_off(filp->f_pos);
44555 int err;
44556 u32 ftype;
44557 struct ceph_mds_reply_info_parsed *rinfo;
44558@@ -360,7 +360,7 @@ more:
44559 rinfo = &fi->last_readdir->r_reply_info;
44560 dout("readdir frag %x num %d off %d chunkoff %d\n", frag,
44561 rinfo->dir_nr, off, fi->offset);
44562- while (off - fi->offset >= 0 && off - fi->offset < rinfo->dir_nr) {
44563+ while (off >= fi->offset && off - fi->offset < rinfo->dir_nr) {
44564 u64 pos = ceph_make_fpos(frag, off);
44565 struct ceph_mds_reply_inode *in =
44566 rinfo->dir_in[off - fi->offset].in;
44567diff -urNp linux-2.6.39.1/fs/cifs/cifs_debug.c linux-2.6.39.1/fs/cifs/cifs_debug.c
44568--- linux-2.6.39.1/fs/cifs/cifs_debug.c 2011-05-19 00:06:34.000000000 -0400
44569+++ linux-2.6.39.1/fs/cifs/cifs_debug.c 2011-05-22 19:36:32.000000000 -0400
44570@@ -279,25 +279,25 @@ static ssize_t cifs_stats_proc_write(str
44571 tcon = list_entry(tmp3,
44572 struct cifsTconInfo,
44573 tcon_list);
44574- atomic_set(&tcon->num_smbs_sent, 0);
44575- atomic_set(&tcon->num_writes, 0);
44576- atomic_set(&tcon->num_reads, 0);
44577- atomic_set(&tcon->num_oplock_brks, 0);
44578- atomic_set(&tcon->num_opens, 0);
44579- atomic_set(&tcon->num_posixopens, 0);
44580- atomic_set(&tcon->num_posixmkdirs, 0);
44581- atomic_set(&tcon->num_closes, 0);
44582- atomic_set(&tcon->num_deletes, 0);
44583- atomic_set(&tcon->num_mkdirs, 0);
44584- atomic_set(&tcon->num_rmdirs, 0);
44585- atomic_set(&tcon->num_renames, 0);
44586- atomic_set(&tcon->num_t2renames, 0);
44587- atomic_set(&tcon->num_ffirst, 0);
44588- atomic_set(&tcon->num_fnext, 0);
44589- atomic_set(&tcon->num_fclose, 0);
44590- atomic_set(&tcon->num_hardlinks, 0);
44591- atomic_set(&tcon->num_symlinks, 0);
44592- atomic_set(&tcon->num_locks, 0);
44593+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
44594+ atomic_set_unchecked(&tcon->num_writes, 0);
44595+ atomic_set_unchecked(&tcon->num_reads, 0);
44596+ atomic_set_unchecked(&tcon->num_oplock_brks, 0);
44597+ atomic_set_unchecked(&tcon->num_opens, 0);
44598+ atomic_set_unchecked(&tcon->num_posixopens, 0);
44599+ atomic_set_unchecked(&tcon->num_posixmkdirs, 0);
44600+ atomic_set_unchecked(&tcon->num_closes, 0);
44601+ atomic_set_unchecked(&tcon->num_deletes, 0);
44602+ atomic_set_unchecked(&tcon->num_mkdirs, 0);
44603+ atomic_set_unchecked(&tcon->num_rmdirs, 0);
44604+ atomic_set_unchecked(&tcon->num_renames, 0);
44605+ atomic_set_unchecked(&tcon->num_t2renames, 0);
44606+ atomic_set_unchecked(&tcon->num_ffirst, 0);
44607+ atomic_set_unchecked(&tcon->num_fnext, 0);
44608+ atomic_set_unchecked(&tcon->num_fclose, 0);
44609+ atomic_set_unchecked(&tcon->num_hardlinks, 0);
44610+ atomic_set_unchecked(&tcon->num_symlinks, 0);
44611+ atomic_set_unchecked(&tcon->num_locks, 0);
44612 }
44613 }
44614 }
44615@@ -357,41 +357,41 @@ static int cifs_stats_proc_show(struct s
44616 if (tcon->need_reconnect)
44617 seq_puts(m, "\tDISCONNECTED ");
44618 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
44619- atomic_read(&tcon->num_smbs_sent),
44620- atomic_read(&tcon->num_oplock_brks));
44621+ atomic_read_unchecked(&tcon->num_smbs_sent),
44622+ atomic_read_unchecked(&tcon->num_oplock_brks));
44623 seq_printf(m, "\nReads: %d Bytes: %lld",
44624- atomic_read(&tcon->num_reads),
44625+ atomic_read_unchecked(&tcon->num_reads),
44626 (long long)(tcon->bytes_read));
44627 seq_printf(m, "\nWrites: %d Bytes: %lld",
44628- atomic_read(&tcon->num_writes),
44629+ atomic_read_unchecked(&tcon->num_writes),
44630 (long long)(tcon->bytes_written));
44631 seq_printf(m, "\nFlushes: %d",
44632- atomic_read(&tcon->num_flushes));
44633+ atomic_read_unchecked(&tcon->num_flushes));
44634 seq_printf(m, "\nLocks: %d HardLinks: %d "
44635 "Symlinks: %d",
44636- atomic_read(&tcon->num_locks),
44637- atomic_read(&tcon->num_hardlinks),
44638- atomic_read(&tcon->num_symlinks));
44639+ atomic_read_unchecked(&tcon->num_locks),
44640+ atomic_read_unchecked(&tcon->num_hardlinks),
44641+ atomic_read_unchecked(&tcon->num_symlinks));
44642 seq_printf(m, "\nOpens: %d Closes: %d "
44643 "Deletes: %d",
44644- atomic_read(&tcon->num_opens),
44645- atomic_read(&tcon->num_closes),
44646- atomic_read(&tcon->num_deletes));
44647+ atomic_read_unchecked(&tcon->num_opens),
44648+ atomic_read_unchecked(&tcon->num_closes),
44649+ atomic_read_unchecked(&tcon->num_deletes));
44650 seq_printf(m, "\nPosix Opens: %d "
44651 "Posix Mkdirs: %d",
44652- atomic_read(&tcon->num_posixopens),
44653- atomic_read(&tcon->num_posixmkdirs));
44654+ atomic_read_unchecked(&tcon->num_posixopens),
44655+ atomic_read_unchecked(&tcon->num_posixmkdirs));
44656 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
44657- atomic_read(&tcon->num_mkdirs),
44658- atomic_read(&tcon->num_rmdirs));
44659+ atomic_read_unchecked(&tcon->num_mkdirs),
44660+ atomic_read_unchecked(&tcon->num_rmdirs));
44661 seq_printf(m, "\nRenames: %d T2 Renames %d",
44662- atomic_read(&tcon->num_renames),
44663- atomic_read(&tcon->num_t2renames));
44664+ atomic_read_unchecked(&tcon->num_renames),
44665+ atomic_read_unchecked(&tcon->num_t2renames));
44666 seq_printf(m, "\nFindFirst: %d FNext %d "
44667 "FClose %d",
44668- atomic_read(&tcon->num_ffirst),
44669- atomic_read(&tcon->num_fnext),
44670- atomic_read(&tcon->num_fclose));
44671+ atomic_read_unchecked(&tcon->num_ffirst),
44672+ atomic_read_unchecked(&tcon->num_fnext),
44673+ atomic_read_unchecked(&tcon->num_fclose));
44674 }
44675 }
44676 }
44677diff -urNp linux-2.6.39.1/fs/cifs/cifsglob.h linux-2.6.39.1/fs/cifs/cifsglob.h
44678--- linux-2.6.39.1/fs/cifs/cifsglob.h 2011-05-19 00:06:34.000000000 -0400
44679+++ linux-2.6.39.1/fs/cifs/cifsglob.h 2011-05-22 19:36:32.000000000 -0400
44680@@ -305,28 +305,28 @@ struct cifsTconInfo {
44681 __u16 Flags; /* optional support bits */
44682 enum statusEnum tidStatus;
44683 #ifdef CONFIG_CIFS_STATS
44684- atomic_t num_smbs_sent;
44685- atomic_t num_writes;
44686- atomic_t num_reads;
44687- atomic_t num_flushes;
44688- atomic_t num_oplock_brks;
44689- atomic_t num_opens;
44690- atomic_t num_closes;
44691- atomic_t num_deletes;
44692- atomic_t num_mkdirs;
44693- atomic_t num_posixopens;
44694- atomic_t num_posixmkdirs;
44695- atomic_t num_rmdirs;
44696- atomic_t num_renames;
44697- atomic_t num_t2renames;
44698- atomic_t num_ffirst;
44699- atomic_t num_fnext;
44700- atomic_t num_fclose;
44701- atomic_t num_hardlinks;
44702- atomic_t num_symlinks;
44703- atomic_t num_locks;
44704- atomic_t num_acl_get;
44705- atomic_t num_acl_set;
44706+ atomic_unchecked_t num_smbs_sent;
44707+ atomic_unchecked_t num_writes;
44708+ atomic_unchecked_t num_reads;
44709+ atomic_unchecked_t num_flushes;
44710+ atomic_unchecked_t num_oplock_brks;
44711+ atomic_unchecked_t num_opens;
44712+ atomic_unchecked_t num_closes;
44713+ atomic_unchecked_t num_deletes;
44714+ atomic_unchecked_t num_mkdirs;
44715+ atomic_unchecked_t num_posixopens;
44716+ atomic_unchecked_t num_posixmkdirs;
44717+ atomic_unchecked_t num_rmdirs;
44718+ atomic_unchecked_t num_renames;
44719+ atomic_unchecked_t num_t2renames;
44720+ atomic_unchecked_t num_ffirst;
44721+ atomic_unchecked_t num_fnext;
44722+ atomic_unchecked_t num_fclose;
44723+ atomic_unchecked_t num_hardlinks;
44724+ atomic_unchecked_t num_symlinks;
44725+ atomic_unchecked_t num_locks;
44726+ atomic_unchecked_t num_acl_get;
44727+ atomic_unchecked_t num_acl_set;
44728 #ifdef CONFIG_CIFS_STATS2
44729 unsigned long long time_writes;
44730 unsigned long long time_reads;
44731@@ -509,7 +509,7 @@ static inline char CIFS_DIR_SEP(const st
44732 }
44733
44734 #ifdef CONFIG_CIFS_STATS
44735-#define cifs_stats_inc atomic_inc
44736+#define cifs_stats_inc atomic_inc_unchecked
44737
44738 static inline void cifs_stats_bytes_written(struct cifsTconInfo *tcon,
44739 unsigned int bytes)
44740diff -urNp linux-2.6.39.1/fs/cifs/link.c linux-2.6.39.1/fs/cifs/link.c
44741--- linux-2.6.39.1/fs/cifs/link.c 2011-05-19 00:06:34.000000000 -0400
44742+++ linux-2.6.39.1/fs/cifs/link.c 2011-05-22 19:36:32.000000000 -0400
44743@@ -577,7 +577,7 @@ symlink_exit:
44744
44745 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
44746 {
44747- char *p = nd_get_link(nd);
44748+ const char *p = nd_get_link(nd);
44749 if (!IS_ERR(p))
44750 kfree(p);
44751 }
44752diff -urNp linux-2.6.39.1/fs/coda/cache.c linux-2.6.39.1/fs/coda/cache.c
44753--- linux-2.6.39.1/fs/coda/cache.c 2011-05-19 00:06:34.000000000 -0400
44754+++ linux-2.6.39.1/fs/coda/cache.c 2011-05-22 19:36:32.000000000 -0400
44755@@ -24,7 +24,7 @@
44756 #include "coda_linux.h"
44757 #include "coda_cache.h"
44758
44759-static atomic_t permission_epoch = ATOMIC_INIT(0);
44760+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
44761
44762 /* replace or extend an acl cache hit */
44763 void coda_cache_enter(struct inode *inode, int mask)
44764@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inod
44765 struct coda_inode_info *cii = ITOC(inode);
44766
44767 spin_lock(&cii->c_lock);
44768- cii->c_cached_epoch = atomic_read(&permission_epoch);
44769+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
44770 if (cii->c_uid != current_fsuid()) {
44771 cii->c_uid = current_fsuid();
44772 cii->c_cached_perm = mask;
44773@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode
44774 {
44775 struct coda_inode_info *cii = ITOC(inode);
44776 spin_lock(&cii->c_lock);
44777- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
44778+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
44779 spin_unlock(&cii->c_lock);
44780 }
44781
44782 /* remove all acl caches */
44783 void coda_cache_clear_all(struct super_block *sb)
44784 {
44785- atomic_inc(&permission_epoch);
44786+ atomic_inc_unchecked(&permission_epoch);
44787 }
44788
44789
44790@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode
44791 spin_lock(&cii->c_lock);
44792 hit = (mask & cii->c_cached_perm) == mask &&
44793 cii->c_uid == current_fsuid() &&
44794- cii->c_cached_epoch == atomic_read(&permission_epoch);
44795+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
44796 spin_unlock(&cii->c_lock);
44797
44798 return hit;
44799diff -urNp linux-2.6.39.1/fs/compat_binfmt_elf.c linux-2.6.39.1/fs/compat_binfmt_elf.c
44800--- linux-2.6.39.1/fs/compat_binfmt_elf.c 2011-05-19 00:06:34.000000000 -0400
44801+++ linux-2.6.39.1/fs/compat_binfmt_elf.c 2011-05-22 19:36:32.000000000 -0400
44802@@ -30,11 +30,13 @@
44803 #undef elf_phdr
44804 #undef elf_shdr
44805 #undef elf_note
44806+#undef elf_dyn
44807 #undef elf_addr_t
44808 #define elfhdr elf32_hdr
44809 #define elf_phdr elf32_phdr
44810 #define elf_shdr elf32_shdr
44811 #define elf_note elf32_note
44812+#define elf_dyn Elf32_Dyn
44813 #define elf_addr_t Elf32_Addr
44814
44815 /*
44816diff -urNp linux-2.6.39.1/fs/compat.c linux-2.6.39.1/fs/compat.c
44817--- linux-2.6.39.1/fs/compat.c 2011-05-19 00:06:34.000000000 -0400
44818+++ linux-2.6.39.1/fs/compat.c 2011-05-22 19:41:37.000000000 -0400
44819@@ -566,7 +566,7 @@ ssize_t compat_rw_copy_check_uvector(int
44820 goto out;
44821
44822 ret = -EINVAL;
44823- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
44824+ if (nr_segs > UIO_MAXIOV)
44825 goto out;
44826 if (nr_segs > fast_segs) {
44827 ret = -ENOMEM;
44828@@ -848,6 +848,7 @@ struct compat_old_linux_dirent {
44829
44830 struct compat_readdir_callback {
44831 struct compat_old_linux_dirent __user *dirent;
44832+ struct file * file;
44833 int result;
44834 };
44835
44836@@ -865,6 +866,10 @@ static int compat_fillonedir(void *__buf
44837 buf->result = -EOVERFLOW;
44838 return -EOVERFLOW;
44839 }
44840+
44841+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44842+ return 0;
44843+
44844 buf->result++;
44845 dirent = buf->dirent;
44846 if (!access_ok(VERIFY_WRITE, dirent,
44847@@ -897,6 +902,7 @@ asmlinkage long compat_sys_old_readdir(u
44848
44849 buf.result = 0;
44850 buf.dirent = dirent;
44851+ buf.file = file;
44852
44853 error = vfs_readdir(file, compat_fillonedir, &buf);
44854 if (buf.result)
44855@@ -917,6 +923,7 @@ struct compat_linux_dirent {
44856 struct compat_getdents_callback {
44857 struct compat_linux_dirent __user *current_dir;
44858 struct compat_linux_dirent __user *previous;
44859+ struct file * file;
44860 int count;
44861 int error;
44862 };
44863@@ -938,6 +945,10 @@ static int compat_filldir(void *__buf, c
44864 buf->error = -EOVERFLOW;
44865 return -EOVERFLOW;
44866 }
44867+
44868+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44869+ return 0;
44870+
44871 dirent = buf->previous;
44872 if (dirent) {
44873 if (__put_user(offset, &dirent->d_off))
44874@@ -985,6 +996,7 @@ asmlinkage long compat_sys_getdents(unsi
44875 buf.previous = NULL;
44876 buf.count = count;
44877 buf.error = 0;
44878+ buf.file = file;
44879
44880 error = vfs_readdir(file, compat_filldir, &buf);
44881 if (error >= 0)
44882@@ -1006,6 +1018,7 @@ out:
44883 struct compat_getdents_callback64 {
44884 struct linux_dirent64 __user *current_dir;
44885 struct linux_dirent64 __user *previous;
44886+ struct file * file;
44887 int count;
44888 int error;
44889 };
44890@@ -1022,6 +1035,10 @@ static int compat_filldir64(void * __buf
44891 buf->error = -EINVAL; /* only used if we fail.. */
44892 if (reclen > buf->count)
44893 return -EINVAL;
44894+
44895+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44896+ return 0;
44897+
44898 dirent = buf->previous;
44899
44900 if (dirent) {
44901@@ -1073,6 +1090,7 @@ asmlinkage long compat_sys_getdents64(un
44902 buf.previous = NULL;
44903 buf.count = count;
44904 buf.error = 0;
44905+ buf.file = file;
44906
44907 error = vfs_readdir(file, compat_filldir64, &buf);
44908 if (error >= 0)
44909@@ -1436,6 +1454,11 @@ int compat_do_execve(char * filename,
44910 compat_uptr_t __user *envp,
44911 struct pt_regs * regs)
44912 {
44913+#ifdef CONFIG_GRKERNSEC
44914+ struct file *old_exec_file;
44915+ struct acl_subject_label *old_acl;
44916+ struct rlimit old_rlim[RLIM_NLIMITS];
44917+#endif
44918 struct linux_binprm *bprm;
44919 struct file *file;
44920 struct files_struct *displaced;
44921@@ -1472,6 +1495,19 @@ int compat_do_execve(char * filename,
44922 bprm->filename = filename;
44923 bprm->interp = filename;
44924
44925+ if (gr_process_user_ban()) {
44926+ retval = -EPERM;
44927+ goto out_file;
44928+ }
44929+
44930+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
44931+ retval = -EAGAIN;
44932+ if (gr_handle_nproc())
44933+ goto out_file;
44934+ retval = -EACCES;
44935+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt))
44936+ goto out_file;
44937+
44938 retval = bprm_mm_init(bprm);
44939 if (retval)
44940 goto out_file;
44941@@ -1501,9 +1537,40 @@ int compat_do_execve(char * filename,
44942 if (retval < 0)
44943 goto out;
44944
44945+ if (!gr_tpe_allow(file)) {
44946+ retval = -EACCES;
44947+ goto out;
44948+ }
44949+
44950+ if (gr_check_crash_exec(file)) {
44951+ retval = -EACCES;
44952+ goto out;
44953+ }
44954+
44955+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
44956+
44957+ gr_handle_exec_args_compat(bprm, argv);
44958+
44959+#ifdef CONFIG_GRKERNSEC
44960+ old_acl = current->acl;
44961+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
44962+ old_exec_file = current->exec_file;
44963+ get_file(file);
44964+ current->exec_file = file;
44965+#endif
44966+
44967+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
44968+ bprm->unsafe & LSM_UNSAFE_SHARE);
44969+ if (retval < 0)
44970+ goto out_fail;
44971+
44972 retval = search_binary_handler(bprm, regs);
44973 if (retval < 0)
44974- goto out;
44975+ goto out_fail;
44976+#ifdef CONFIG_GRKERNSEC
44977+ if (old_exec_file)
44978+ fput(old_exec_file);
44979+#endif
44980
44981 /* execve succeeded */
44982 current->fs->in_exec = 0;
44983@@ -1514,6 +1581,14 @@ int compat_do_execve(char * filename,
44984 put_files_struct(displaced);
44985 return retval;
44986
44987+out_fail:
44988+#ifdef CONFIG_GRKERNSEC
44989+ current->acl = old_acl;
44990+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
44991+ fput(current->exec_file);
44992+ current->exec_file = old_exec_file;
44993+#endif
44994+
44995 out:
44996 if (bprm->mm) {
44997 acct_arg_size(bprm, 0);
44998@@ -1681,6 +1756,8 @@ int compat_core_sys_select(int n, compat
44999 struct fdtable *fdt;
45000 long stack_fds[SELECT_STACK_ALLOC/sizeof(long)];
45001
45002+ pax_track_stack();
45003+
45004 if (n < 0)
45005 goto out_nofds;
45006
45007diff -urNp linux-2.6.39.1/fs/compat_ioctl.c linux-2.6.39.1/fs/compat_ioctl.c
45008--- linux-2.6.39.1/fs/compat_ioctl.c 2011-05-19 00:06:34.000000000 -0400
45009+++ linux-2.6.39.1/fs/compat_ioctl.c 2011-05-22 19:36:32.000000000 -0400
45010@@ -208,6 +208,8 @@ static int do_video_set_spu_palette(unsi
45011
45012 err = get_user(palp, &up->palette);
45013 err |= get_user(length, &up->length);
45014+ if (err)
45015+ return -EFAULT;
45016
45017 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
45018 err = put_user(compat_ptr(palp), &up_native->palette);
45019@@ -1638,8 +1640,8 @@ asmlinkage long compat_sys_ioctl(unsigne
45020 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
45021 {
45022 unsigned int a, b;
45023- a = *(unsigned int *)p;
45024- b = *(unsigned int *)q;
45025+ a = *(const unsigned int *)p;
45026+ b = *(const unsigned int *)q;
45027 if (a > b)
45028 return 1;
45029 if (a < b)
45030diff -urNp linux-2.6.39.1/fs/configfs/dir.c linux-2.6.39.1/fs/configfs/dir.c
45031--- linux-2.6.39.1/fs/configfs/dir.c 2011-05-19 00:06:34.000000000 -0400
45032+++ linux-2.6.39.1/fs/configfs/dir.c 2011-05-22 19:36:32.000000000 -0400
45033@@ -1575,7 +1575,8 @@ static int configfs_readdir(struct file
45034 }
45035 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
45036 struct configfs_dirent *next;
45037- const char * name;
45038+ const unsigned char * name;
45039+ char d_name[sizeof(next->s_dentry->d_iname)];
45040 int len;
45041 struct inode *inode = NULL;
45042
45043@@ -1585,7 +1586,12 @@ static int configfs_readdir(struct file
45044 continue;
45045
45046 name = configfs_get_name(next);
45047- len = strlen(name);
45048+ if (next->s_dentry && name == next->s_dentry->d_iname) {
45049+ len = next->s_dentry->d_name.len;
45050+ memcpy(d_name, name, len);
45051+ name = d_name;
45052+ } else
45053+ len = strlen(name);
45054
45055 /*
45056 * We'll have a dentry and an inode for
45057diff -urNp linux-2.6.39.1/fs/configfs/file.c linux-2.6.39.1/fs/configfs/file.c
45058--- linux-2.6.39.1/fs/configfs/file.c 2011-05-19 00:06:34.000000000 -0400
45059+++ linux-2.6.39.1/fs/configfs/file.c 2011-05-22 19:36:32.000000000 -0400
45060@@ -215,7 +215,7 @@ static int check_perm(struct inode * ino
45061 struct config_item *item = configfs_get_config_item(file->f_path.dentry->d_parent);
45062 struct configfs_attribute * attr = to_attr(file->f_path.dentry);
45063 struct configfs_buffer * buffer;
45064- struct configfs_item_operations * ops = NULL;
45065+ struct configfs_item_operations *ops = NULL;
45066 int error = 0;
45067
45068 if (!item || !attr)
45069diff -urNp linux-2.6.39.1/fs/configfs/item.c linux-2.6.39.1/fs/configfs/item.c
45070--- linux-2.6.39.1/fs/configfs/item.c 2011-05-19 00:06:34.000000000 -0400
45071+++ linux-2.6.39.1/fs/configfs/item.c 2011-05-22 19:36:32.000000000 -0400
45072@@ -123,7 +123,7 @@ void config_item_init_type_name(struct c
45073 EXPORT_SYMBOL(config_item_init_type_name);
45074
45075 void config_group_init_type_name(struct config_group *group, const char *name,
45076- struct config_item_type *type)
45077+ struct config_item_type *type)
45078 {
45079 config_item_set_name(&group->cg_item, name);
45080 group->cg_item.ci_type = type;
45081diff -urNp linux-2.6.39.1/fs/dcache.c linux-2.6.39.1/fs/dcache.c
45082--- linux-2.6.39.1/fs/dcache.c 2011-05-19 00:06:34.000000000 -0400
45083+++ linux-2.6.39.1/fs/dcache.c 2011-05-22 19:36:32.000000000 -0400
45084@@ -3069,7 +3069,7 @@ void __init vfs_caches_init(unsigned lon
45085 mempages -= reserve;
45086
45087 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
45088- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
45089+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
45090
45091 dcache_init();
45092 inode_init();
45093diff -urNp linux-2.6.39.1/fs/dlm/lockspace.c linux-2.6.39.1/fs/dlm/lockspace.c
45094--- linux-2.6.39.1/fs/dlm/lockspace.c 2011-05-19 00:06:34.000000000 -0400
45095+++ linux-2.6.39.1/fs/dlm/lockspace.c 2011-05-22 19:36:32.000000000 -0400
45096@@ -200,7 +200,7 @@ static int dlm_uevent(struct kset *kset,
45097 return 0;
45098 }
45099
45100-static struct kset_uevent_ops dlm_uevent_ops = {
45101+static const struct kset_uevent_ops dlm_uevent_ops = {
45102 .uevent = dlm_uevent,
45103 };
45104
45105diff -urNp linux-2.6.39.1/fs/ecryptfs/inode.c linux-2.6.39.1/fs/ecryptfs/inode.c
45106--- linux-2.6.39.1/fs/ecryptfs/inode.c 2011-06-03 00:04:14.000000000 -0400
45107+++ linux-2.6.39.1/fs/ecryptfs/inode.c 2011-06-03 00:32:07.000000000 -0400
45108@@ -623,7 +623,7 @@ static int ecryptfs_readlink_lower(struc
45109 old_fs = get_fs();
45110 set_fs(get_ds());
45111 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
45112- (char __user *)lower_buf,
45113+ (__force char __user *)lower_buf,
45114 lower_bufsiz);
45115 set_fs(old_fs);
45116 if (rc < 0)
45117@@ -669,7 +669,7 @@ static void *ecryptfs_follow_link(struct
45118 }
45119 old_fs = get_fs();
45120 set_fs(get_ds());
45121- rc = dentry->d_inode->i_op->readlink(dentry, (char __user *)buf, len);
45122+ rc = dentry->d_inode->i_op->readlink(dentry, (__force char __user *)buf, len);
45123 set_fs(old_fs);
45124 if (rc < 0) {
45125 kfree(buf);
45126@@ -684,7 +684,7 @@ out:
45127 static void
45128 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
45129 {
45130- char *buf = nd_get_link(nd);
45131+ const char *buf = nd_get_link(nd);
45132 if (!IS_ERR(buf)) {
45133 /* Free the char* */
45134 kfree(buf);
45135diff -urNp linux-2.6.39.1/fs/ecryptfs/miscdev.c linux-2.6.39.1/fs/ecryptfs/miscdev.c
45136--- linux-2.6.39.1/fs/ecryptfs/miscdev.c 2011-05-19 00:06:34.000000000 -0400
45137+++ linux-2.6.39.1/fs/ecryptfs/miscdev.c 2011-05-22 19:36:32.000000000 -0400
45138@@ -328,7 +328,7 @@ check_list:
45139 goto out_unlock_msg_ctx;
45140 i = 5;
45141 if (msg_ctx->msg) {
45142- if (copy_to_user(&buf[i], packet_length, packet_length_size))
45143+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
45144 goto out_unlock_msg_ctx;
45145 i += packet_length_size;
45146 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
45147diff -urNp linux-2.6.39.1/fs/exec.c linux-2.6.39.1/fs/exec.c
45148--- linux-2.6.39.1/fs/exec.c 2011-05-19 00:06:34.000000000 -0400
45149+++ linux-2.6.39.1/fs/exec.c 2011-06-03 23:33:13.000000000 -0400
45150@@ -55,12 +55,24 @@
45151 #include <linux/fs_struct.h>
45152 #include <linux/pipe_fs_i.h>
45153 #include <linux/oom.h>
45154+#include <linux/random.h>
45155+#include <linux/seq_file.h>
45156+
45157+#ifdef CONFIG_PAX_REFCOUNT
45158+#include <linux/kallsyms.h>
45159+#include <linux/kdebug.h>
45160+#endif
45161
45162 #include <asm/uaccess.h>
45163 #include <asm/mmu_context.h>
45164 #include <asm/tlb.h>
45165 #include "internal.h"
45166
45167+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
45168+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
45169+EXPORT_SYMBOL(pax_set_initial_flags_func);
45170+#endif
45171+
45172 int core_uses_pid;
45173 char core_pattern[CORENAME_MAX_SIZE] = "core";
45174 unsigned int core_pipe_limit;
45175@@ -70,7 +82,7 @@ struct core_name {
45176 char *corename;
45177 int used, size;
45178 };
45179-static atomic_t call_count = ATOMIC_INIT(1);
45180+static atomic_unchecked_t call_count = ATOMIC_INIT(1);
45181
45182 /* The maximal length of core_pattern is also specified in sysctl.c */
45183
45184@@ -116,7 +128,7 @@ SYSCALL_DEFINE1(uselib, const char __use
45185 char *tmp = getname(library);
45186 int error = PTR_ERR(tmp);
45187 static const struct open_flags uselib_flags = {
45188- .open_flag = O_LARGEFILE | O_RDONLY | __FMODE_EXEC,
45189+ .open_flag = O_LARGEFILE | O_RDONLY | __FMODE_EXEC | FMODE_GREXEC,
45190 .acc_mode = MAY_READ | MAY_EXEC | MAY_OPEN,
45191 .intent = LOOKUP_OPEN
45192 };
45193@@ -190,18 +202,10 @@ struct page *get_arg_page(struct linux_b
45194 int write)
45195 {
45196 struct page *page;
45197- int ret;
45198
45199-#ifdef CONFIG_STACK_GROWSUP
45200- if (write) {
45201- ret = expand_stack_downwards(bprm->vma, pos);
45202- if (ret < 0)
45203- return NULL;
45204- }
45205-#endif
45206- ret = get_user_pages(current, bprm->mm, pos,
45207- 1, write, 1, &page, NULL);
45208- if (ret <= 0)
45209+ if (0 > expand_stack_downwards(bprm->vma, pos))
45210+ return NULL;
45211+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
45212 return NULL;
45213
45214 if (write) {
45215@@ -276,6 +280,11 @@ static int __bprm_mm_init(struct linux_b
45216 vma->vm_end = STACK_TOP_MAX;
45217 vma->vm_start = vma->vm_end - PAGE_SIZE;
45218 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
45219+
45220+#ifdef CONFIG_PAX_SEGMEXEC
45221+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
45222+#endif
45223+
45224 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
45225 INIT_LIST_HEAD(&vma->anon_vma_chain);
45226
45227@@ -290,6 +299,12 @@ static int __bprm_mm_init(struct linux_b
45228 mm->stack_vm = mm->total_vm = 1;
45229 up_write(&mm->mmap_sem);
45230 bprm->p = vma->vm_end - sizeof(void *);
45231+
45232+#ifdef CONFIG_PAX_RANDUSTACK
45233+ if (randomize_va_space)
45234+ bprm->p ^= (pax_get_random_long() & ~15) & ~PAGE_MASK;
45235+#endif
45236+
45237 return 0;
45238 err:
45239 up_write(&mm->mmap_sem);
45240@@ -525,7 +540,7 @@ int copy_strings_kernel(int argc, const
45241 int r;
45242 mm_segment_t oldfs = get_fs();
45243 set_fs(KERNEL_DS);
45244- r = copy_strings(argc, (const char __user *const __user *)argv, bprm);
45245+ r = copy_strings(argc, (__force const char __user *const __user *)argv, bprm);
45246 set_fs(oldfs);
45247 return r;
45248 }
45249@@ -555,7 +570,8 @@ static int shift_arg_pages(struct vm_are
45250 unsigned long new_end = old_end - shift;
45251 struct mmu_gather *tlb;
45252
45253- BUG_ON(new_start > new_end);
45254+ if (new_start >= new_end || new_start < mmap_min_addr)
45255+ return -ENOMEM;
45256
45257 /*
45258 * ensure there are no vmas between where we want to go
45259@@ -564,6 +580,10 @@ static int shift_arg_pages(struct vm_are
45260 if (vma != find_vma(mm, new_start))
45261 return -EFAULT;
45262
45263+#ifdef CONFIG_PAX_SEGMEXEC
45264+ BUG_ON(pax_find_mirror_vma(vma));
45265+#endif
45266+
45267 /*
45268 * cover the whole range: [new_start, old_end)
45269 */
45270@@ -644,10 +664,6 @@ int setup_arg_pages(struct linux_binprm
45271 stack_top = arch_align_stack(stack_top);
45272 stack_top = PAGE_ALIGN(stack_top);
45273
45274- if (unlikely(stack_top < mmap_min_addr) ||
45275- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
45276- return -ENOMEM;
45277-
45278 stack_shift = vma->vm_end - stack_top;
45279
45280 bprm->p -= stack_shift;
45281@@ -659,8 +675,28 @@ int setup_arg_pages(struct linux_binprm
45282 bprm->exec -= stack_shift;
45283
45284 down_write(&mm->mmap_sem);
45285+
45286+ /* Move stack pages down in memory. */
45287+ if (stack_shift) {
45288+ ret = shift_arg_pages(vma, stack_shift);
45289+ if (ret)
45290+ goto out_unlock;
45291+ }
45292+
45293 vm_flags = VM_STACK_FLAGS;
45294
45295+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45296+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45297+ vm_flags &= ~VM_EXEC;
45298+
45299+#ifdef CONFIG_PAX_MPROTECT
45300+ if (mm->pax_flags & MF_PAX_MPROTECT)
45301+ vm_flags &= ~VM_MAYEXEC;
45302+#endif
45303+
45304+ }
45305+#endif
45306+
45307 /*
45308 * Adjust stack execute permissions; explicitly enable for
45309 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
45310@@ -679,13 +715,6 @@ int setup_arg_pages(struct linux_binprm
45311 goto out_unlock;
45312 BUG_ON(prev != vma);
45313
45314- /* Move stack pages down in memory. */
45315- if (stack_shift) {
45316- ret = shift_arg_pages(vma, stack_shift);
45317- if (ret)
45318- goto out_unlock;
45319- }
45320-
45321 /* mprotect_fixup is overkill to remove the temporary stack flags */
45322 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
45323
45324@@ -725,7 +754,7 @@ struct file *open_exec(const char *name)
45325 struct file *file;
45326 int err;
45327 static const struct open_flags open_exec_flags = {
45328- .open_flag = O_LARGEFILE | O_RDONLY | __FMODE_EXEC,
45329+ .open_flag = O_LARGEFILE | O_RDONLY | __FMODE_EXEC | FMODE_GREXEC,
45330 .acc_mode = MAY_EXEC | MAY_OPEN,
45331 .intent = LOOKUP_OPEN
45332 };
45333@@ -766,7 +795,7 @@ int kernel_read(struct file *file, loff_
45334 old_fs = get_fs();
45335 set_fs(get_ds());
45336 /* The cast to a user pointer is valid due to the set_fs() */
45337- result = vfs_read(file, (void __user *)addr, count, &pos);
45338+ result = vfs_read(file, (__force void __user *)addr, count, &pos);
45339 set_fs(old_fs);
45340 return result;
45341 }
45342@@ -1188,7 +1217,7 @@ int check_unsafe_exec(struct linux_binpr
45343 }
45344 rcu_read_unlock();
45345
45346- if (p->fs->users > n_fs) {
45347+ if (atomic_read(&p->fs->users) > n_fs) {
45348 bprm->unsafe |= LSM_UNSAFE_SHARE;
45349 } else {
45350 res = -EAGAIN;
45351@@ -1384,6 +1413,11 @@ int do_execve(const char * filename,
45352 const char __user *const __user *envp,
45353 struct pt_regs * regs)
45354 {
45355+#ifdef CONFIG_GRKERNSEC
45356+ struct file *old_exec_file;
45357+ struct acl_subject_label *old_acl;
45358+ struct rlimit old_rlim[RLIM_NLIMITS];
45359+#endif
45360 struct linux_binprm *bprm;
45361 struct file *file;
45362 struct files_struct *displaced;
45363@@ -1420,6 +1454,23 @@ int do_execve(const char * filename,
45364 bprm->filename = filename;
45365 bprm->interp = filename;
45366
45367+ if (gr_process_user_ban()) {
45368+ retval = -EPERM;
45369+ goto out_file;
45370+ }
45371+
45372+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
45373+
45374+ if (gr_handle_nproc()) {
45375+ retval = -EAGAIN;
45376+ goto out_file;
45377+ }
45378+
45379+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
45380+ retval = -EACCES;
45381+ goto out_file;
45382+ }
45383+
45384 retval = bprm_mm_init(bprm);
45385 if (retval)
45386 goto out_file;
45387@@ -1449,9 +1500,40 @@ int do_execve(const char * filename,
45388 if (retval < 0)
45389 goto out;
45390
45391+ if (!gr_tpe_allow(file)) {
45392+ retval = -EACCES;
45393+ goto out;
45394+ }
45395+
45396+ if (gr_check_crash_exec(file)) {
45397+ retval = -EACCES;
45398+ goto out;
45399+ }
45400+
45401+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
45402+
45403+ gr_handle_exec_args(bprm, argv);
45404+
45405+#ifdef CONFIG_GRKERNSEC
45406+ old_acl = current->acl;
45407+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
45408+ old_exec_file = current->exec_file;
45409+ get_file(file);
45410+ current->exec_file = file;
45411+#endif
45412+
45413+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
45414+ bprm->unsafe & LSM_UNSAFE_SHARE);
45415+ if (retval < 0)
45416+ goto out_fail;
45417+
45418 retval = search_binary_handler(bprm,regs);
45419 if (retval < 0)
45420- goto out;
45421+ goto out_fail;
45422+#ifdef CONFIG_GRKERNSEC
45423+ if (old_exec_file)
45424+ fput(old_exec_file);
45425+#endif
45426
45427 /* execve succeeded */
45428 current->fs->in_exec = 0;
45429@@ -1462,6 +1544,14 @@ int do_execve(const char * filename,
45430 put_files_struct(displaced);
45431 return retval;
45432
45433+out_fail:
45434+#ifdef CONFIG_GRKERNSEC
45435+ current->acl = old_acl;
45436+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
45437+ fput(current->exec_file);
45438+ current->exec_file = old_exec_file;
45439+#endif
45440+
45441 out:
45442 if (bprm->mm) {
45443 acct_arg_size(bprm, 0);
45444@@ -1507,7 +1597,7 @@ static int expand_corename(struct core_n
45445 {
45446 char *old_corename = cn->corename;
45447
45448- cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
45449+ cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
45450 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
45451
45452 if (!cn->corename) {
45453@@ -1560,7 +1650,7 @@ static int format_corename(struct core_n
45454 int pid_in_pattern = 0;
45455 int err = 0;
45456
45457- cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
45458+ cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
45459 cn->corename = kmalloc(cn->size, GFP_KERNEL);
45460 cn->used = 0;
45461
45462@@ -1648,6 +1738,219 @@ out:
45463 return ispipe;
45464 }
45465
45466+int pax_check_flags(unsigned long *flags)
45467+{
45468+ int retval = 0;
45469+
45470+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
45471+ if (*flags & MF_PAX_SEGMEXEC)
45472+ {
45473+ *flags &= ~MF_PAX_SEGMEXEC;
45474+ retval = -EINVAL;
45475+ }
45476+#endif
45477+
45478+ if ((*flags & MF_PAX_PAGEEXEC)
45479+
45480+#ifdef CONFIG_PAX_PAGEEXEC
45481+ && (*flags & MF_PAX_SEGMEXEC)
45482+#endif
45483+
45484+ )
45485+ {
45486+ *flags &= ~MF_PAX_PAGEEXEC;
45487+ retval = -EINVAL;
45488+ }
45489+
45490+ if ((*flags & MF_PAX_MPROTECT)
45491+
45492+#ifdef CONFIG_PAX_MPROTECT
45493+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45494+#endif
45495+
45496+ )
45497+ {
45498+ *flags &= ~MF_PAX_MPROTECT;
45499+ retval = -EINVAL;
45500+ }
45501+
45502+ if ((*flags & MF_PAX_EMUTRAMP)
45503+
45504+#ifdef CONFIG_PAX_EMUTRAMP
45505+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45506+#endif
45507+
45508+ )
45509+ {
45510+ *flags &= ~MF_PAX_EMUTRAMP;
45511+ retval = -EINVAL;
45512+ }
45513+
45514+ return retval;
45515+}
45516+
45517+EXPORT_SYMBOL(pax_check_flags);
45518+
45519+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45520+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
45521+{
45522+ struct task_struct *tsk = current;
45523+ struct mm_struct *mm = current->mm;
45524+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
45525+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
45526+ char *path_exec = NULL;
45527+ char *path_fault = NULL;
45528+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
45529+
45530+ if (buffer_exec && buffer_fault) {
45531+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
45532+
45533+ down_read(&mm->mmap_sem);
45534+ vma = mm->mmap;
45535+ while (vma && (!vma_exec || !vma_fault)) {
45536+ if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
45537+ vma_exec = vma;
45538+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
45539+ vma_fault = vma;
45540+ vma = vma->vm_next;
45541+ }
45542+ if (vma_exec) {
45543+ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
45544+ if (IS_ERR(path_exec))
45545+ path_exec = "<path too long>";
45546+ else {
45547+ path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
45548+ if (path_exec) {
45549+ *path_exec = 0;
45550+ path_exec = buffer_exec;
45551+ } else
45552+ path_exec = "<path too long>";
45553+ }
45554+ }
45555+ if (vma_fault) {
45556+ start = vma_fault->vm_start;
45557+ end = vma_fault->vm_end;
45558+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
45559+ if (vma_fault->vm_file) {
45560+ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
45561+ if (IS_ERR(path_fault))
45562+ path_fault = "<path too long>";
45563+ else {
45564+ path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
45565+ if (path_fault) {
45566+ *path_fault = 0;
45567+ path_fault = buffer_fault;
45568+ } else
45569+ path_fault = "<path too long>";
45570+ }
45571+ } else
45572+ path_fault = "<anonymous mapping>";
45573+ }
45574+ up_read(&mm->mmap_sem);
45575+ }
45576+ if (tsk->signal->curr_ip)
45577+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
45578+ else
45579+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
45580+ printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
45581+ "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
45582+ task_uid(tsk), task_euid(tsk), pc, sp);
45583+ free_page((unsigned long)buffer_exec);
45584+ free_page((unsigned long)buffer_fault);
45585+ pax_report_insns(pc, sp);
45586+ do_coredump(SIGKILL, SIGKILL, regs);
45587+}
45588+#endif
45589+
45590+#ifdef CONFIG_PAX_REFCOUNT
45591+void pax_report_refcount_overflow(struct pt_regs *regs)
45592+{
45593+ if (current->signal->curr_ip)
45594+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45595+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
45596+ else
45597+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45598+ current->comm, task_pid_nr(current), current_uid(), current_euid());
45599+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
45600+ show_regs(regs);
45601+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
45602+}
45603+#endif
45604+
45605+#ifdef CONFIG_PAX_USERCOPY
45606+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
45607+int object_is_on_stack(const void *obj, unsigned long len)
45608+{
45609+ const void * const stack = task_stack_page(current);
45610+ const void * const stackend = stack + THREAD_SIZE;
45611+
45612+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45613+ const void *frame = NULL;
45614+ const void *oldframe;
45615+#endif
45616+
45617+ if (obj + len < obj)
45618+ return -1;
45619+
45620+ if (obj + len <= stack || stackend <= obj)
45621+ return 0;
45622+
45623+ if (obj < stack || stackend < obj + len)
45624+ return -1;
45625+
45626+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45627+ oldframe = __builtin_frame_address(1);
45628+ if (oldframe)
45629+ frame = __builtin_frame_address(2);
45630+ /*
45631+ low ----------------------------------------------> high
45632+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
45633+ ^----------------^
45634+ allow copies only within here
45635+ */
45636+ while (stack <= frame && frame < stackend) {
45637+ /* if obj + len extends past the last frame, this
45638+ check won't pass and the next frame will be 0,
45639+ causing us to bail out and correctly report
45640+ the copy as invalid
45641+ */
45642+ if (obj + len <= frame)
45643+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
45644+ oldframe = frame;
45645+ frame = *(const void * const *)frame;
45646+ }
45647+ return -1;
45648+#else
45649+ return 1;
45650+#endif
45651+}
45652+
45653+
45654+void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
45655+{
45656+ if (current->signal->curr_ip)
45657+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45658+ &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45659+ else
45660+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45661+ to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45662+ dump_stack();
45663+ gr_handle_kernel_exploit();
45664+ do_group_exit(SIGKILL);
45665+}
45666+#endif
45667+
45668+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
45669+void pax_track_stack(void)
45670+{
45671+ unsigned long sp = (unsigned long)&sp;
45672+ if (sp < current_thread_info()->lowest_stack &&
45673+ sp > (unsigned long)task_stack_page(current))
45674+ current_thread_info()->lowest_stack = sp;
45675+}
45676+EXPORT_SYMBOL(pax_track_stack);
45677+#endif
45678+
45679 static int zap_process(struct task_struct *start, int exit_code)
45680 {
45681 struct task_struct *t;
45682@@ -1858,17 +2161,17 @@ static void wait_for_dump_helpers(struct
45683 pipe = file->f_path.dentry->d_inode->i_pipe;
45684
45685 pipe_lock(pipe);
45686- pipe->readers++;
45687- pipe->writers--;
45688+ atomic_inc(&pipe->readers);
45689+ atomic_dec(&pipe->writers);
45690
45691- while ((pipe->readers > 1) && (!signal_pending(current))) {
45692+ while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
45693 wake_up_interruptible_sync(&pipe->wait);
45694 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
45695 pipe_wait(pipe);
45696 }
45697
45698- pipe->readers--;
45699- pipe->writers++;
45700+ atomic_dec(&pipe->readers);
45701+ atomic_inc(&pipe->writers);
45702 pipe_unlock(pipe);
45703
45704 }
45705@@ -1929,7 +2232,7 @@ void do_coredump(long signr, int exit_co
45706 int retval = 0;
45707 int flag = 0;
45708 int ispipe;
45709- static atomic_t core_dump_count = ATOMIC_INIT(0);
45710+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
45711 struct coredump_params cprm = {
45712 .signr = signr,
45713 .regs = regs,
45714@@ -1944,6 +2247,9 @@ void do_coredump(long signr, int exit_co
45715
45716 audit_core_dumps(signr);
45717
45718+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
45719+ gr_handle_brute_attach(current, cprm.mm_flags);
45720+
45721 binfmt = mm->binfmt;
45722 if (!binfmt || !binfmt->core_dump)
45723 goto fail;
45724@@ -1984,6 +2290,8 @@ void do_coredump(long signr, int exit_co
45725 goto fail_corename;
45726 }
45727
45728+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
45729+
45730 if (ispipe) {
45731 int dump_count;
45732 char **helper_argv;
45733@@ -2011,7 +2319,7 @@ void do_coredump(long signr, int exit_co
45734 }
45735 cprm.limit = RLIM_INFINITY;
45736
45737- dump_count = atomic_inc_return(&core_dump_count);
45738+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
45739 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
45740 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
45741 task_tgid_vnr(current), current->comm);
45742@@ -2081,7 +2389,7 @@ close_fail:
45743 filp_close(cprm.file, NULL);
45744 fail_dropcount:
45745 if (ispipe)
45746- atomic_dec(&core_dump_count);
45747+ atomic_dec_unchecked(&core_dump_count);
45748 fail_unlock:
45749 kfree(cn.corename);
45750 fail_corename:
45751diff -urNp linux-2.6.39.1/fs/ext2/balloc.c linux-2.6.39.1/fs/ext2/balloc.c
45752--- linux-2.6.39.1/fs/ext2/balloc.c 2011-05-19 00:06:34.000000000 -0400
45753+++ linux-2.6.39.1/fs/ext2/balloc.c 2011-05-22 19:41:37.000000000 -0400
45754@@ -1192,7 +1192,7 @@ static int ext2_has_free_blocks(struct e
45755
45756 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45757 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45758- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45759+ if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
45760 sbi->s_resuid != current_fsuid() &&
45761 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
45762 return 0;
45763diff -urNp linux-2.6.39.1/fs/ext3/balloc.c linux-2.6.39.1/fs/ext3/balloc.c
45764--- linux-2.6.39.1/fs/ext3/balloc.c 2011-05-19 00:06:34.000000000 -0400
45765+++ linux-2.6.39.1/fs/ext3/balloc.c 2011-05-22 19:41:37.000000000 -0400
45766@@ -1441,7 +1441,7 @@ static int ext3_has_free_blocks(struct e
45767
45768 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45769 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45770- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45771+ if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
45772 sbi->s_resuid != current_fsuid() &&
45773 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
45774 return 0;
45775diff -urNp linux-2.6.39.1/fs/ext4/balloc.c linux-2.6.39.1/fs/ext4/balloc.c
45776--- linux-2.6.39.1/fs/ext4/balloc.c 2011-05-19 00:06:34.000000000 -0400
45777+++ linux-2.6.39.1/fs/ext4/balloc.c 2011-05-22 19:41:37.000000000 -0400
45778@@ -522,7 +522,7 @@ static int ext4_has_free_blocks(struct e
45779 /* Hm, nope. Are (enough) root reserved blocks available? */
45780 if (sbi->s_resuid == current_fsuid() ||
45781 ((sbi->s_resgid != 0) && in_group_p(sbi->s_resgid)) ||
45782- capable(CAP_SYS_RESOURCE)) {
45783+ capable_nolog(CAP_SYS_RESOURCE)) {
45784 if (free_blocks >= (nblocks + dirty_blocks))
45785 return 1;
45786 }
45787diff -urNp linux-2.6.39.1/fs/ext4/ext4.h linux-2.6.39.1/fs/ext4/ext4.h
45788--- linux-2.6.39.1/fs/ext4/ext4.h 2011-06-03 00:04:14.000000000 -0400
45789+++ linux-2.6.39.1/fs/ext4/ext4.h 2011-06-03 00:32:07.000000000 -0400
45790@@ -1166,19 +1166,19 @@ struct ext4_sb_info {
45791 unsigned long s_mb_last_start;
45792
45793 /* stats for buddy allocator */
45794- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
45795- atomic_t s_bal_success; /* we found long enough chunks */
45796- atomic_t s_bal_allocated; /* in blocks */
45797- atomic_t s_bal_ex_scanned; /* total extents scanned */
45798- atomic_t s_bal_goals; /* goal hits */
45799- atomic_t s_bal_breaks; /* too long searches */
45800- atomic_t s_bal_2orders; /* 2^order hits */
45801+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
45802+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
45803+ atomic_unchecked_t s_bal_allocated; /* in blocks */
45804+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
45805+ atomic_unchecked_t s_bal_goals; /* goal hits */
45806+ atomic_unchecked_t s_bal_breaks; /* too long searches */
45807+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
45808 spinlock_t s_bal_lock;
45809 unsigned long s_mb_buddies_generated;
45810 unsigned long long s_mb_generation_time;
45811- atomic_t s_mb_lost_chunks;
45812- atomic_t s_mb_preallocated;
45813- atomic_t s_mb_discarded;
45814+ atomic_unchecked_t s_mb_lost_chunks;
45815+ atomic_unchecked_t s_mb_preallocated;
45816+ atomic_unchecked_t s_mb_discarded;
45817 atomic_t s_lock_busy;
45818
45819 /* locality groups */
45820diff -urNp linux-2.6.39.1/fs/ext4/mballoc.c linux-2.6.39.1/fs/ext4/mballoc.c
45821--- linux-2.6.39.1/fs/ext4/mballoc.c 2011-06-03 00:04:14.000000000 -0400
45822+++ linux-2.6.39.1/fs/ext4/mballoc.c 2011-06-03 00:32:07.000000000 -0400
45823@@ -1853,7 +1853,7 @@ void ext4_mb_simple_scan_group(struct ex
45824 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
45825
45826 if (EXT4_SB(sb)->s_mb_stats)
45827- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
45828+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
45829
45830 break;
45831 }
45832@@ -2147,7 +2147,7 @@ repeat:
45833 ac->ac_status = AC_STATUS_CONTINUE;
45834 ac->ac_flags |= EXT4_MB_HINT_FIRST;
45835 cr = 3;
45836- atomic_inc(&sbi->s_mb_lost_chunks);
45837+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
45838 goto repeat;
45839 }
45840 }
45841@@ -2190,6 +2190,8 @@ static int ext4_mb_seq_groups_show(struc
45842 ext4_grpblk_t counters[16];
45843 } sg;
45844
45845+ pax_track_stack();
45846+
45847 group--;
45848 if (group == 0)
45849 seq_printf(seq, "#%-5s: %-5s %-5s %-5s "
45850@@ -2613,25 +2615,25 @@ int ext4_mb_release(struct super_block *
45851 if (sbi->s_mb_stats) {
45852 printk(KERN_INFO
45853 "EXT4-fs: mballoc: %u blocks %u reqs (%u success)\n",
45854- atomic_read(&sbi->s_bal_allocated),
45855- atomic_read(&sbi->s_bal_reqs),
45856- atomic_read(&sbi->s_bal_success));
45857+ atomic_read_unchecked(&sbi->s_bal_allocated),
45858+ atomic_read_unchecked(&sbi->s_bal_reqs),
45859+ atomic_read_unchecked(&sbi->s_bal_success));
45860 printk(KERN_INFO
45861 "EXT4-fs: mballoc: %u extents scanned, %u goal hits, "
45862 "%u 2^N hits, %u breaks, %u lost\n",
45863- atomic_read(&sbi->s_bal_ex_scanned),
45864- atomic_read(&sbi->s_bal_goals),
45865- atomic_read(&sbi->s_bal_2orders),
45866- atomic_read(&sbi->s_bal_breaks),
45867- atomic_read(&sbi->s_mb_lost_chunks));
45868+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
45869+ atomic_read_unchecked(&sbi->s_bal_goals),
45870+ atomic_read_unchecked(&sbi->s_bal_2orders),
45871+ atomic_read_unchecked(&sbi->s_bal_breaks),
45872+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
45873 printk(KERN_INFO
45874 "EXT4-fs: mballoc: %lu generated and it took %Lu\n",
45875 sbi->s_mb_buddies_generated++,
45876 sbi->s_mb_generation_time);
45877 printk(KERN_INFO
45878 "EXT4-fs: mballoc: %u preallocated, %u discarded\n",
45879- atomic_read(&sbi->s_mb_preallocated),
45880- atomic_read(&sbi->s_mb_discarded));
45881+ atomic_read_unchecked(&sbi->s_mb_preallocated),
45882+ atomic_read_unchecked(&sbi->s_mb_discarded));
45883 }
45884
45885 free_percpu(sbi->s_locality_groups);
45886@@ -3107,16 +3109,16 @@ static void ext4_mb_collect_stats(struct
45887 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
45888
45889 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
45890- atomic_inc(&sbi->s_bal_reqs);
45891- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45892+ atomic_inc_unchecked(&sbi->s_bal_reqs);
45893+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45894 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
45895- atomic_inc(&sbi->s_bal_success);
45896- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
45897+ atomic_inc_unchecked(&sbi->s_bal_success);
45898+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
45899 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
45900 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
45901- atomic_inc(&sbi->s_bal_goals);
45902+ atomic_inc_unchecked(&sbi->s_bal_goals);
45903 if (ac->ac_found > sbi->s_mb_max_to_scan)
45904- atomic_inc(&sbi->s_bal_breaks);
45905+ atomic_inc_unchecked(&sbi->s_bal_breaks);
45906 }
45907
45908 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
45909@@ -3514,7 +3516,7 @@ ext4_mb_new_inode_pa(struct ext4_allocat
45910 trace_ext4_mb_new_inode_pa(ac, pa);
45911
45912 ext4_mb_use_inode_pa(ac, pa);
45913- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45914+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45915
45916 ei = EXT4_I(ac->ac_inode);
45917 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45918@@ -3574,7 +3576,7 @@ ext4_mb_new_group_pa(struct ext4_allocat
45919 trace_ext4_mb_new_group_pa(ac, pa);
45920
45921 ext4_mb_use_group_pa(ac, pa);
45922- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45923+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45924
45925 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45926 lg = ac->ac_lg;
45927@@ -3661,7 +3663,7 @@ ext4_mb_release_inode_pa(struct ext4_bud
45928 * from the bitmap and continue.
45929 */
45930 }
45931- atomic_add(free, &sbi->s_mb_discarded);
45932+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
45933
45934 return err;
45935 }
45936@@ -3679,7 +3681,7 @@ ext4_mb_release_group_pa(struct ext4_bud
45937 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
45938 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
45939 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
45940- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45941+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45942 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
45943
45944 return 0;
45945diff -urNp linux-2.6.39.1/fs/fcntl.c linux-2.6.39.1/fs/fcntl.c
45946--- linux-2.6.39.1/fs/fcntl.c 2011-05-19 00:06:34.000000000 -0400
45947+++ linux-2.6.39.1/fs/fcntl.c 2011-05-22 20:45:50.000000000 -0400
45948@@ -224,6 +224,11 @@ int __f_setown(struct file *filp, struct
45949 if (err)
45950 return err;
45951
45952+ if (gr_handle_chroot_fowner(pid, type))
45953+ return -ENOENT;
45954+ if (gr_check_protected_task_fowner(pid, type))
45955+ return -EACCES;
45956+
45957 f_modown(filp, pid, type, force);
45958 return 0;
45959 }
45960@@ -348,6 +353,7 @@ static long do_fcntl(int fd, unsigned in
45961 switch (cmd) {
45962 case F_DUPFD:
45963 case F_DUPFD_CLOEXEC:
45964+ gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
45965 if (arg >= rlimit(RLIMIT_NOFILE))
45966 break;
45967 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
45968@@ -835,14 +841,14 @@ static int __init fcntl_init(void)
45969 * Exceptions: O_NONBLOCK is a two bit define on parisc; O_NDELAY
45970 * is defined as O_NONBLOCK on some platforms and not on others.
45971 */
45972- BUILD_BUG_ON(19 - 1 /* for O_RDONLY being 0 */ != HWEIGHT32(
45973+ BUILD_BUG_ON(20 - 1 /* for O_RDONLY being 0 */ != HWEIGHT32(
45974 O_RDONLY | O_WRONLY | O_RDWR |
45975 O_CREAT | O_EXCL | O_NOCTTY |
45976 O_TRUNC | O_APPEND | /* O_NONBLOCK | */
45977 __O_SYNC | O_DSYNC | FASYNC |
45978 O_DIRECT | O_LARGEFILE | O_DIRECTORY |
45979 O_NOFOLLOW | O_NOATIME | O_CLOEXEC |
45980- __FMODE_EXEC | O_PATH
45981+ __FMODE_EXEC | O_PATH | FMODE_GREXEC
45982 ));
45983
45984 fasync_cache = kmem_cache_create("fasync_cache",
45985diff -urNp linux-2.6.39.1/fs/fifo.c linux-2.6.39.1/fs/fifo.c
45986--- linux-2.6.39.1/fs/fifo.c 2011-05-19 00:06:34.000000000 -0400
45987+++ linux-2.6.39.1/fs/fifo.c 2011-05-22 19:36:32.000000000 -0400
45988@@ -58,10 +58,10 @@ static int fifo_open(struct inode *inode
45989 */
45990 filp->f_op = &read_pipefifo_fops;
45991 pipe->r_counter++;
45992- if (pipe->readers++ == 0)
45993+ if (atomic_inc_return(&pipe->readers) == 1)
45994 wake_up_partner(inode);
45995
45996- if (!pipe->writers) {
45997+ if (!atomic_read(&pipe->writers)) {
45998 if ((filp->f_flags & O_NONBLOCK)) {
45999 /* suppress POLLHUP until we have
46000 * seen a writer */
46001@@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode
46002 * errno=ENXIO when there is no process reading the FIFO.
46003 */
46004 ret = -ENXIO;
46005- if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
46006+ if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
46007 goto err;
46008
46009 filp->f_op = &write_pipefifo_fops;
46010 pipe->w_counter++;
46011- if (!pipe->writers++)
46012+ if (atomic_inc_return(&pipe->writers) == 1)
46013 wake_up_partner(inode);
46014
46015- if (!pipe->readers) {
46016+ if (!atomic_read(&pipe->readers)) {
46017 wait_for_partner(inode, &pipe->r_counter);
46018 if (signal_pending(current))
46019 goto err_wr;
46020@@ -105,11 +105,11 @@ static int fifo_open(struct inode *inode
46021 */
46022 filp->f_op = &rdwr_pipefifo_fops;
46023
46024- pipe->readers++;
46025- pipe->writers++;
46026+ atomic_inc(&pipe->readers);
46027+ atomic_inc(&pipe->writers);
46028 pipe->r_counter++;
46029 pipe->w_counter++;
46030- if (pipe->readers == 1 || pipe->writers == 1)
46031+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
46032 wake_up_partner(inode);
46033 break;
46034
46035@@ -123,19 +123,19 @@ static int fifo_open(struct inode *inode
46036 return 0;
46037
46038 err_rd:
46039- if (!--pipe->readers)
46040+ if (atomic_dec_and_test(&pipe->readers))
46041 wake_up_interruptible(&pipe->wait);
46042 ret = -ERESTARTSYS;
46043 goto err;
46044
46045 err_wr:
46046- if (!--pipe->writers)
46047+ if (atomic_dec_and_test(&pipe->writers))
46048 wake_up_interruptible(&pipe->wait);
46049 ret = -ERESTARTSYS;
46050 goto err;
46051
46052 err:
46053- if (!pipe->readers && !pipe->writers)
46054+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
46055 free_pipe_info(inode);
46056
46057 err_nocleanup:
46058diff -urNp linux-2.6.39.1/fs/file.c linux-2.6.39.1/fs/file.c
46059--- linux-2.6.39.1/fs/file.c 2011-05-19 00:06:34.000000000 -0400
46060+++ linux-2.6.39.1/fs/file.c 2011-05-22 19:41:37.000000000 -0400
46061@@ -15,6 +15,7 @@
46062 #include <linux/slab.h>
46063 #include <linux/vmalloc.h>
46064 #include <linux/file.h>
46065+#include <linux/security.h>
46066 #include <linux/fdtable.h>
46067 #include <linux/bitops.h>
46068 #include <linux/interrupt.h>
46069@@ -254,6 +255,7 @@ int expand_files(struct files_struct *fi
46070 * N.B. For clone tasks sharing a files structure, this test
46071 * will limit the total number of files that can be opened.
46072 */
46073+ gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
46074 if (nr >= rlimit(RLIMIT_NOFILE))
46075 return -EMFILE;
46076
46077diff -urNp linux-2.6.39.1/fs/filesystems.c linux-2.6.39.1/fs/filesystems.c
46078--- linux-2.6.39.1/fs/filesystems.c 2011-05-19 00:06:34.000000000 -0400
46079+++ linux-2.6.39.1/fs/filesystems.c 2011-05-22 19:41:37.000000000 -0400
46080@@ -274,7 +274,12 @@ struct file_system_type *get_fs_type(con
46081 int len = dot ? dot - name : strlen(name);
46082
46083 fs = __get_fs_type(name, len);
46084+
46085+#ifdef CONFIG_GRKERNSEC_MODHARDEN
46086+ if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
46087+#else
46088 if (!fs && (request_module("%.*s", len, name) == 0))
46089+#endif
46090 fs = __get_fs_type(name, len);
46091
46092 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
46093diff -urNp linux-2.6.39.1/fs/fscache/cookie.c linux-2.6.39.1/fs/fscache/cookie.c
46094--- linux-2.6.39.1/fs/fscache/cookie.c 2011-05-19 00:06:34.000000000 -0400
46095+++ linux-2.6.39.1/fs/fscache/cookie.c 2011-05-22 19:36:32.000000000 -0400
46096@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire
46097 parent ? (char *) parent->def->name : "<no-parent>",
46098 def->name, netfs_data);
46099
46100- fscache_stat(&fscache_n_acquires);
46101+ fscache_stat_unchecked(&fscache_n_acquires);
46102
46103 /* if there's no parent cookie, then we don't create one here either */
46104 if (!parent) {
46105- fscache_stat(&fscache_n_acquires_null);
46106+ fscache_stat_unchecked(&fscache_n_acquires_null);
46107 _leave(" [no parent]");
46108 return NULL;
46109 }
46110@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire
46111 /* allocate and initialise a cookie */
46112 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
46113 if (!cookie) {
46114- fscache_stat(&fscache_n_acquires_oom);
46115+ fscache_stat_unchecked(&fscache_n_acquires_oom);
46116 _leave(" [ENOMEM]");
46117 return NULL;
46118 }
46119@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire
46120
46121 switch (cookie->def->type) {
46122 case FSCACHE_COOKIE_TYPE_INDEX:
46123- fscache_stat(&fscache_n_cookie_index);
46124+ fscache_stat_unchecked(&fscache_n_cookie_index);
46125 break;
46126 case FSCACHE_COOKIE_TYPE_DATAFILE:
46127- fscache_stat(&fscache_n_cookie_data);
46128+ fscache_stat_unchecked(&fscache_n_cookie_data);
46129 break;
46130 default:
46131- fscache_stat(&fscache_n_cookie_special);
46132+ fscache_stat_unchecked(&fscache_n_cookie_special);
46133 break;
46134 }
46135
46136@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire
46137 if (fscache_acquire_non_index_cookie(cookie) < 0) {
46138 atomic_dec(&parent->n_children);
46139 __fscache_cookie_put(cookie);
46140- fscache_stat(&fscache_n_acquires_nobufs);
46141+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
46142 _leave(" = NULL");
46143 return NULL;
46144 }
46145 }
46146
46147- fscache_stat(&fscache_n_acquires_ok);
46148+ fscache_stat_unchecked(&fscache_n_acquires_ok);
46149 _leave(" = %p", cookie);
46150 return cookie;
46151 }
46152@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_coo
46153 cache = fscache_select_cache_for_object(cookie->parent);
46154 if (!cache) {
46155 up_read(&fscache_addremove_sem);
46156- fscache_stat(&fscache_n_acquires_no_cache);
46157+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
46158 _leave(" = -ENOMEDIUM [no cache]");
46159 return -ENOMEDIUM;
46160 }
46161@@ -256,12 +256,12 @@ static int fscache_alloc_object(struct f
46162 object = cache->ops->alloc_object(cache, cookie);
46163 fscache_stat_d(&fscache_n_cop_alloc_object);
46164 if (IS_ERR(object)) {
46165- fscache_stat(&fscache_n_object_no_alloc);
46166+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
46167 ret = PTR_ERR(object);
46168 goto error;
46169 }
46170
46171- fscache_stat(&fscache_n_object_alloc);
46172+ fscache_stat_unchecked(&fscache_n_object_alloc);
46173
46174 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
46175
46176@@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fsca
46177 struct fscache_object *object;
46178 struct hlist_node *_p;
46179
46180- fscache_stat(&fscache_n_updates);
46181+ fscache_stat_unchecked(&fscache_n_updates);
46182
46183 if (!cookie) {
46184- fscache_stat(&fscache_n_updates_null);
46185+ fscache_stat_unchecked(&fscache_n_updates_null);
46186 _leave(" [no cookie]");
46187 return;
46188 }
46189@@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct
46190 struct fscache_object *object;
46191 unsigned long event;
46192
46193- fscache_stat(&fscache_n_relinquishes);
46194+ fscache_stat_unchecked(&fscache_n_relinquishes);
46195 if (retire)
46196- fscache_stat(&fscache_n_relinquishes_retire);
46197+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
46198
46199 if (!cookie) {
46200- fscache_stat(&fscache_n_relinquishes_null);
46201+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
46202 _leave(" [no cookie]");
46203 return;
46204 }
46205@@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct
46206
46207 /* wait for the cookie to finish being instantiated (or to fail) */
46208 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
46209- fscache_stat(&fscache_n_relinquishes_waitcrt);
46210+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
46211 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
46212 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
46213 }
46214diff -urNp linux-2.6.39.1/fs/fscache/internal.h linux-2.6.39.1/fs/fscache/internal.h
46215--- linux-2.6.39.1/fs/fscache/internal.h 2011-05-19 00:06:34.000000000 -0400
46216+++ linux-2.6.39.1/fs/fscache/internal.h 2011-05-22 19:36:32.000000000 -0400
46217@@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
46218 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
46219 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
46220
46221-extern atomic_t fscache_n_op_pend;
46222-extern atomic_t fscache_n_op_run;
46223-extern atomic_t fscache_n_op_enqueue;
46224-extern atomic_t fscache_n_op_deferred_release;
46225-extern atomic_t fscache_n_op_release;
46226-extern atomic_t fscache_n_op_gc;
46227-extern atomic_t fscache_n_op_cancelled;
46228-extern atomic_t fscache_n_op_rejected;
46229-
46230-extern atomic_t fscache_n_attr_changed;
46231-extern atomic_t fscache_n_attr_changed_ok;
46232-extern atomic_t fscache_n_attr_changed_nobufs;
46233-extern atomic_t fscache_n_attr_changed_nomem;
46234-extern atomic_t fscache_n_attr_changed_calls;
46235-
46236-extern atomic_t fscache_n_allocs;
46237-extern atomic_t fscache_n_allocs_ok;
46238-extern atomic_t fscache_n_allocs_wait;
46239-extern atomic_t fscache_n_allocs_nobufs;
46240-extern atomic_t fscache_n_allocs_intr;
46241-extern atomic_t fscache_n_allocs_object_dead;
46242-extern atomic_t fscache_n_alloc_ops;
46243-extern atomic_t fscache_n_alloc_op_waits;
46244-
46245-extern atomic_t fscache_n_retrievals;
46246-extern atomic_t fscache_n_retrievals_ok;
46247-extern atomic_t fscache_n_retrievals_wait;
46248-extern atomic_t fscache_n_retrievals_nodata;
46249-extern atomic_t fscache_n_retrievals_nobufs;
46250-extern atomic_t fscache_n_retrievals_intr;
46251-extern atomic_t fscache_n_retrievals_nomem;
46252-extern atomic_t fscache_n_retrievals_object_dead;
46253-extern atomic_t fscache_n_retrieval_ops;
46254-extern atomic_t fscache_n_retrieval_op_waits;
46255-
46256-extern atomic_t fscache_n_stores;
46257-extern atomic_t fscache_n_stores_ok;
46258-extern atomic_t fscache_n_stores_again;
46259-extern atomic_t fscache_n_stores_nobufs;
46260-extern atomic_t fscache_n_stores_oom;
46261-extern atomic_t fscache_n_store_ops;
46262-extern atomic_t fscache_n_store_calls;
46263-extern atomic_t fscache_n_store_pages;
46264-extern atomic_t fscache_n_store_radix_deletes;
46265-extern atomic_t fscache_n_store_pages_over_limit;
46266-
46267-extern atomic_t fscache_n_store_vmscan_not_storing;
46268-extern atomic_t fscache_n_store_vmscan_gone;
46269-extern atomic_t fscache_n_store_vmscan_busy;
46270-extern atomic_t fscache_n_store_vmscan_cancelled;
46271-
46272-extern atomic_t fscache_n_marks;
46273-extern atomic_t fscache_n_uncaches;
46274-
46275-extern atomic_t fscache_n_acquires;
46276-extern atomic_t fscache_n_acquires_null;
46277-extern atomic_t fscache_n_acquires_no_cache;
46278-extern atomic_t fscache_n_acquires_ok;
46279-extern atomic_t fscache_n_acquires_nobufs;
46280-extern atomic_t fscache_n_acquires_oom;
46281-
46282-extern atomic_t fscache_n_updates;
46283-extern atomic_t fscache_n_updates_null;
46284-extern atomic_t fscache_n_updates_run;
46285-
46286-extern atomic_t fscache_n_relinquishes;
46287-extern atomic_t fscache_n_relinquishes_null;
46288-extern atomic_t fscache_n_relinquishes_waitcrt;
46289-extern atomic_t fscache_n_relinquishes_retire;
46290-
46291-extern atomic_t fscache_n_cookie_index;
46292-extern atomic_t fscache_n_cookie_data;
46293-extern atomic_t fscache_n_cookie_special;
46294-
46295-extern atomic_t fscache_n_object_alloc;
46296-extern atomic_t fscache_n_object_no_alloc;
46297-extern atomic_t fscache_n_object_lookups;
46298-extern atomic_t fscache_n_object_lookups_negative;
46299-extern atomic_t fscache_n_object_lookups_positive;
46300-extern atomic_t fscache_n_object_lookups_timed_out;
46301-extern atomic_t fscache_n_object_created;
46302-extern atomic_t fscache_n_object_avail;
46303-extern atomic_t fscache_n_object_dead;
46304-
46305-extern atomic_t fscache_n_checkaux_none;
46306-extern atomic_t fscache_n_checkaux_okay;
46307-extern atomic_t fscache_n_checkaux_update;
46308-extern atomic_t fscache_n_checkaux_obsolete;
46309+extern atomic_unchecked_t fscache_n_op_pend;
46310+extern atomic_unchecked_t fscache_n_op_run;
46311+extern atomic_unchecked_t fscache_n_op_enqueue;
46312+extern atomic_unchecked_t fscache_n_op_deferred_release;
46313+extern atomic_unchecked_t fscache_n_op_release;
46314+extern atomic_unchecked_t fscache_n_op_gc;
46315+extern atomic_unchecked_t fscache_n_op_cancelled;
46316+extern atomic_unchecked_t fscache_n_op_rejected;
46317+
46318+extern atomic_unchecked_t fscache_n_attr_changed;
46319+extern atomic_unchecked_t fscache_n_attr_changed_ok;
46320+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
46321+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
46322+extern atomic_unchecked_t fscache_n_attr_changed_calls;
46323+
46324+extern atomic_unchecked_t fscache_n_allocs;
46325+extern atomic_unchecked_t fscache_n_allocs_ok;
46326+extern atomic_unchecked_t fscache_n_allocs_wait;
46327+extern atomic_unchecked_t fscache_n_allocs_nobufs;
46328+extern atomic_unchecked_t fscache_n_allocs_intr;
46329+extern atomic_unchecked_t fscache_n_allocs_object_dead;
46330+extern atomic_unchecked_t fscache_n_alloc_ops;
46331+extern atomic_unchecked_t fscache_n_alloc_op_waits;
46332+
46333+extern atomic_unchecked_t fscache_n_retrievals;
46334+extern atomic_unchecked_t fscache_n_retrievals_ok;
46335+extern atomic_unchecked_t fscache_n_retrievals_wait;
46336+extern atomic_unchecked_t fscache_n_retrievals_nodata;
46337+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
46338+extern atomic_unchecked_t fscache_n_retrievals_intr;
46339+extern atomic_unchecked_t fscache_n_retrievals_nomem;
46340+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
46341+extern atomic_unchecked_t fscache_n_retrieval_ops;
46342+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
46343+
46344+extern atomic_unchecked_t fscache_n_stores;
46345+extern atomic_unchecked_t fscache_n_stores_ok;
46346+extern atomic_unchecked_t fscache_n_stores_again;
46347+extern atomic_unchecked_t fscache_n_stores_nobufs;
46348+extern atomic_unchecked_t fscache_n_stores_oom;
46349+extern atomic_unchecked_t fscache_n_store_ops;
46350+extern atomic_unchecked_t fscache_n_store_calls;
46351+extern atomic_unchecked_t fscache_n_store_pages;
46352+extern atomic_unchecked_t fscache_n_store_radix_deletes;
46353+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
46354+
46355+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
46356+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
46357+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
46358+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
46359+
46360+extern atomic_unchecked_t fscache_n_marks;
46361+extern atomic_unchecked_t fscache_n_uncaches;
46362+
46363+extern atomic_unchecked_t fscache_n_acquires;
46364+extern atomic_unchecked_t fscache_n_acquires_null;
46365+extern atomic_unchecked_t fscache_n_acquires_no_cache;
46366+extern atomic_unchecked_t fscache_n_acquires_ok;
46367+extern atomic_unchecked_t fscache_n_acquires_nobufs;
46368+extern atomic_unchecked_t fscache_n_acquires_oom;
46369+
46370+extern atomic_unchecked_t fscache_n_updates;
46371+extern atomic_unchecked_t fscache_n_updates_null;
46372+extern atomic_unchecked_t fscache_n_updates_run;
46373+
46374+extern atomic_unchecked_t fscache_n_relinquishes;
46375+extern atomic_unchecked_t fscache_n_relinquishes_null;
46376+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
46377+extern atomic_unchecked_t fscache_n_relinquishes_retire;
46378+
46379+extern atomic_unchecked_t fscache_n_cookie_index;
46380+extern atomic_unchecked_t fscache_n_cookie_data;
46381+extern atomic_unchecked_t fscache_n_cookie_special;
46382+
46383+extern atomic_unchecked_t fscache_n_object_alloc;
46384+extern atomic_unchecked_t fscache_n_object_no_alloc;
46385+extern atomic_unchecked_t fscache_n_object_lookups;
46386+extern atomic_unchecked_t fscache_n_object_lookups_negative;
46387+extern atomic_unchecked_t fscache_n_object_lookups_positive;
46388+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
46389+extern atomic_unchecked_t fscache_n_object_created;
46390+extern atomic_unchecked_t fscache_n_object_avail;
46391+extern atomic_unchecked_t fscache_n_object_dead;
46392+
46393+extern atomic_unchecked_t fscache_n_checkaux_none;
46394+extern atomic_unchecked_t fscache_n_checkaux_okay;
46395+extern atomic_unchecked_t fscache_n_checkaux_update;
46396+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
46397
46398 extern atomic_t fscache_n_cop_alloc_object;
46399 extern atomic_t fscache_n_cop_lookup_object;
46400@@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t
46401 atomic_inc(stat);
46402 }
46403
46404+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
46405+{
46406+ atomic_inc_unchecked(stat);
46407+}
46408+
46409 static inline void fscache_stat_d(atomic_t *stat)
46410 {
46411 atomic_dec(stat);
46412@@ -267,6 +272,7 @@ extern const struct file_operations fsca
46413
46414 #define __fscache_stat(stat) (NULL)
46415 #define fscache_stat(stat) do {} while (0)
46416+#define fscache_stat_unchecked(stat) do {} while (0)
46417 #define fscache_stat_d(stat) do {} while (0)
46418 #endif
46419
46420diff -urNp linux-2.6.39.1/fs/fscache/object.c linux-2.6.39.1/fs/fscache/object.c
46421--- linux-2.6.39.1/fs/fscache/object.c 2011-05-19 00:06:34.000000000 -0400
46422+++ linux-2.6.39.1/fs/fscache/object.c 2011-05-22 19:36:32.000000000 -0400
46423@@ -128,7 +128,7 @@ static void fscache_object_state_machine
46424 /* update the object metadata on disk */
46425 case FSCACHE_OBJECT_UPDATING:
46426 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
46427- fscache_stat(&fscache_n_updates_run);
46428+ fscache_stat_unchecked(&fscache_n_updates_run);
46429 fscache_stat(&fscache_n_cop_update_object);
46430 object->cache->ops->update_object(object);
46431 fscache_stat_d(&fscache_n_cop_update_object);
46432@@ -217,7 +217,7 @@ static void fscache_object_state_machine
46433 spin_lock(&object->lock);
46434 object->state = FSCACHE_OBJECT_DEAD;
46435 spin_unlock(&object->lock);
46436- fscache_stat(&fscache_n_object_dead);
46437+ fscache_stat_unchecked(&fscache_n_object_dead);
46438 goto terminal_transit;
46439
46440 /* handle the parent cache of this object being withdrawn from
46441@@ -232,7 +232,7 @@ static void fscache_object_state_machine
46442 spin_lock(&object->lock);
46443 object->state = FSCACHE_OBJECT_DEAD;
46444 spin_unlock(&object->lock);
46445- fscache_stat(&fscache_n_object_dead);
46446+ fscache_stat_unchecked(&fscache_n_object_dead);
46447 goto terminal_transit;
46448
46449 /* complain about the object being woken up once it is
46450@@ -461,7 +461,7 @@ static void fscache_lookup_object(struct
46451 parent->cookie->def->name, cookie->def->name,
46452 object->cache->tag->name);
46453
46454- fscache_stat(&fscache_n_object_lookups);
46455+ fscache_stat_unchecked(&fscache_n_object_lookups);
46456 fscache_stat(&fscache_n_cop_lookup_object);
46457 ret = object->cache->ops->lookup_object(object);
46458 fscache_stat_d(&fscache_n_cop_lookup_object);
46459@@ -472,7 +472,7 @@ static void fscache_lookup_object(struct
46460 if (ret == -ETIMEDOUT) {
46461 /* probably stuck behind another object, so move this one to
46462 * the back of the queue */
46463- fscache_stat(&fscache_n_object_lookups_timed_out);
46464+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
46465 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46466 }
46467
46468@@ -495,7 +495,7 @@ void fscache_object_lookup_negative(stru
46469
46470 spin_lock(&object->lock);
46471 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46472- fscache_stat(&fscache_n_object_lookups_negative);
46473+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
46474
46475 /* transit here to allow write requests to begin stacking up
46476 * and read requests to begin returning ENODATA */
46477@@ -541,7 +541,7 @@ void fscache_obtained_object(struct fsca
46478 * result, in which case there may be data available */
46479 spin_lock(&object->lock);
46480 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46481- fscache_stat(&fscache_n_object_lookups_positive);
46482+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
46483
46484 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
46485
46486@@ -555,7 +555,7 @@ void fscache_obtained_object(struct fsca
46487 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46488 } else {
46489 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
46490- fscache_stat(&fscache_n_object_created);
46491+ fscache_stat_unchecked(&fscache_n_object_created);
46492
46493 object->state = FSCACHE_OBJECT_AVAILABLE;
46494 spin_unlock(&object->lock);
46495@@ -602,7 +602,7 @@ static void fscache_object_available(str
46496 fscache_enqueue_dependents(object);
46497
46498 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
46499- fscache_stat(&fscache_n_object_avail);
46500+ fscache_stat_unchecked(&fscache_n_object_avail);
46501
46502 _leave("");
46503 }
46504@@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(
46505 enum fscache_checkaux result;
46506
46507 if (!object->cookie->def->check_aux) {
46508- fscache_stat(&fscache_n_checkaux_none);
46509+ fscache_stat_unchecked(&fscache_n_checkaux_none);
46510 return FSCACHE_CHECKAUX_OKAY;
46511 }
46512
46513@@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(
46514 switch (result) {
46515 /* entry okay as is */
46516 case FSCACHE_CHECKAUX_OKAY:
46517- fscache_stat(&fscache_n_checkaux_okay);
46518+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
46519 break;
46520
46521 /* entry requires update */
46522 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
46523- fscache_stat(&fscache_n_checkaux_update);
46524+ fscache_stat_unchecked(&fscache_n_checkaux_update);
46525 break;
46526
46527 /* entry requires deletion */
46528 case FSCACHE_CHECKAUX_OBSOLETE:
46529- fscache_stat(&fscache_n_checkaux_obsolete);
46530+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
46531 break;
46532
46533 default:
46534diff -urNp linux-2.6.39.1/fs/fscache/operation.c linux-2.6.39.1/fs/fscache/operation.c
46535--- linux-2.6.39.1/fs/fscache/operation.c 2011-05-19 00:06:34.000000000 -0400
46536+++ linux-2.6.39.1/fs/fscache/operation.c 2011-05-22 19:36:32.000000000 -0400
46537@@ -17,7 +17,7 @@
46538 #include <linux/slab.h>
46539 #include "internal.h"
46540
46541-atomic_t fscache_op_debug_id;
46542+atomic_unchecked_t fscache_op_debug_id;
46543 EXPORT_SYMBOL(fscache_op_debug_id);
46544
46545 /**
46546@@ -40,7 +40,7 @@ void fscache_enqueue_operation(struct fs
46547 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
46548 ASSERTCMP(atomic_read(&op->usage), >, 0);
46549
46550- fscache_stat(&fscache_n_op_enqueue);
46551+ fscache_stat_unchecked(&fscache_n_op_enqueue);
46552 switch (op->flags & FSCACHE_OP_TYPE) {
46553 case FSCACHE_OP_ASYNC:
46554 _debug("queue async");
46555@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscach
46556 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
46557 if (op->processor)
46558 fscache_enqueue_operation(op);
46559- fscache_stat(&fscache_n_op_run);
46560+ fscache_stat_unchecked(&fscache_n_op_run);
46561 }
46562
46563 /*
46564@@ -104,11 +104,11 @@ int fscache_submit_exclusive_op(struct f
46565 if (object->n_ops > 1) {
46566 atomic_inc(&op->usage);
46567 list_add_tail(&op->pend_link, &object->pending_ops);
46568- fscache_stat(&fscache_n_op_pend);
46569+ fscache_stat_unchecked(&fscache_n_op_pend);
46570 } else if (!list_empty(&object->pending_ops)) {
46571 atomic_inc(&op->usage);
46572 list_add_tail(&op->pend_link, &object->pending_ops);
46573- fscache_stat(&fscache_n_op_pend);
46574+ fscache_stat_unchecked(&fscache_n_op_pend);
46575 fscache_start_operations(object);
46576 } else {
46577 ASSERTCMP(object->n_in_progress, ==, 0);
46578@@ -124,7 +124,7 @@ int fscache_submit_exclusive_op(struct f
46579 object->n_exclusive++; /* reads and writes must wait */
46580 atomic_inc(&op->usage);
46581 list_add_tail(&op->pend_link, &object->pending_ops);
46582- fscache_stat(&fscache_n_op_pend);
46583+ fscache_stat_unchecked(&fscache_n_op_pend);
46584 ret = 0;
46585 } else {
46586 /* not allowed to submit ops in any other state */
46587@@ -211,11 +211,11 @@ int fscache_submit_op(struct fscache_obj
46588 if (object->n_exclusive > 0) {
46589 atomic_inc(&op->usage);
46590 list_add_tail(&op->pend_link, &object->pending_ops);
46591- fscache_stat(&fscache_n_op_pend);
46592+ fscache_stat_unchecked(&fscache_n_op_pend);
46593 } else if (!list_empty(&object->pending_ops)) {
46594 atomic_inc(&op->usage);
46595 list_add_tail(&op->pend_link, &object->pending_ops);
46596- fscache_stat(&fscache_n_op_pend);
46597+ fscache_stat_unchecked(&fscache_n_op_pend);
46598 fscache_start_operations(object);
46599 } else {
46600 ASSERTCMP(object->n_exclusive, ==, 0);
46601@@ -227,12 +227,12 @@ int fscache_submit_op(struct fscache_obj
46602 object->n_ops++;
46603 atomic_inc(&op->usage);
46604 list_add_tail(&op->pend_link, &object->pending_ops);
46605- fscache_stat(&fscache_n_op_pend);
46606+ fscache_stat_unchecked(&fscache_n_op_pend);
46607 ret = 0;
46608 } else if (object->state == FSCACHE_OBJECT_DYING ||
46609 object->state == FSCACHE_OBJECT_LC_DYING ||
46610 object->state == FSCACHE_OBJECT_WITHDRAWING) {
46611- fscache_stat(&fscache_n_op_rejected);
46612+ fscache_stat_unchecked(&fscache_n_op_rejected);
46613 ret = -ENOBUFS;
46614 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
46615 fscache_report_unexpected_submission(object, op, ostate);
46616@@ -302,7 +302,7 @@ int fscache_cancel_op(struct fscache_ope
46617
46618 ret = -EBUSY;
46619 if (!list_empty(&op->pend_link)) {
46620- fscache_stat(&fscache_n_op_cancelled);
46621+ fscache_stat_unchecked(&fscache_n_op_cancelled);
46622 list_del_init(&op->pend_link);
46623 object->n_ops--;
46624 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
46625@@ -341,7 +341,7 @@ void fscache_put_operation(struct fscach
46626 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
46627 BUG();
46628
46629- fscache_stat(&fscache_n_op_release);
46630+ fscache_stat_unchecked(&fscache_n_op_release);
46631
46632 if (op->release) {
46633 op->release(op);
46634@@ -358,7 +358,7 @@ void fscache_put_operation(struct fscach
46635 * lock, and defer it otherwise */
46636 if (!spin_trylock(&object->lock)) {
46637 _debug("defer put");
46638- fscache_stat(&fscache_n_op_deferred_release);
46639+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
46640
46641 cache = object->cache;
46642 spin_lock(&cache->op_gc_list_lock);
46643@@ -420,7 +420,7 @@ void fscache_operation_gc(struct work_st
46644
46645 _debug("GC DEFERRED REL OBJ%x OP%x",
46646 object->debug_id, op->debug_id);
46647- fscache_stat(&fscache_n_op_gc);
46648+ fscache_stat_unchecked(&fscache_n_op_gc);
46649
46650 ASSERTCMP(atomic_read(&op->usage), ==, 0);
46651
46652diff -urNp linux-2.6.39.1/fs/fscache/page.c linux-2.6.39.1/fs/fscache/page.c
46653--- linux-2.6.39.1/fs/fscache/page.c 2011-05-19 00:06:34.000000000 -0400
46654+++ linux-2.6.39.1/fs/fscache/page.c 2011-05-22 19:36:32.000000000 -0400
46655@@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct
46656 val = radix_tree_lookup(&cookie->stores, page->index);
46657 if (!val) {
46658 rcu_read_unlock();
46659- fscache_stat(&fscache_n_store_vmscan_not_storing);
46660+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
46661 __fscache_uncache_page(cookie, page);
46662 return true;
46663 }
46664@@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct
46665 spin_unlock(&cookie->stores_lock);
46666
46667 if (xpage) {
46668- fscache_stat(&fscache_n_store_vmscan_cancelled);
46669- fscache_stat(&fscache_n_store_radix_deletes);
46670+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
46671+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46672 ASSERTCMP(xpage, ==, page);
46673 } else {
46674- fscache_stat(&fscache_n_store_vmscan_gone);
46675+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
46676 }
46677
46678 wake_up_bit(&cookie->flags, 0);
46679@@ -107,7 +107,7 @@ page_busy:
46680 /* we might want to wait here, but that could deadlock the allocator as
46681 * the work threads writing to the cache may all end up sleeping
46682 * on memory allocation */
46683- fscache_stat(&fscache_n_store_vmscan_busy);
46684+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
46685 return false;
46686 }
46687 EXPORT_SYMBOL(__fscache_maybe_release_page);
46688@@ -131,7 +131,7 @@ static void fscache_end_page_write(struc
46689 FSCACHE_COOKIE_STORING_TAG);
46690 if (!radix_tree_tag_get(&cookie->stores, page->index,
46691 FSCACHE_COOKIE_PENDING_TAG)) {
46692- fscache_stat(&fscache_n_store_radix_deletes);
46693+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46694 xpage = radix_tree_delete(&cookie->stores, page->index);
46695 }
46696 spin_unlock(&cookie->stores_lock);
46697@@ -152,7 +152,7 @@ static void fscache_attr_changed_op(stru
46698
46699 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
46700
46701- fscache_stat(&fscache_n_attr_changed_calls);
46702+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
46703
46704 if (fscache_object_is_active(object)) {
46705 fscache_set_op_state(op, "CallFS");
46706@@ -179,11 +179,11 @@ int __fscache_attr_changed(struct fscach
46707
46708 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46709
46710- fscache_stat(&fscache_n_attr_changed);
46711+ fscache_stat_unchecked(&fscache_n_attr_changed);
46712
46713 op = kzalloc(sizeof(*op), GFP_KERNEL);
46714 if (!op) {
46715- fscache_stat(&fscache_n_attr_changed_nomem);
46716+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
46717 _leave(" = -ENOMEM");
46718 return -ENOMEM;
46719 }
46720@@ -202,7 +202,7 @@ int __fscache_attr_changed(struct fscach
46721 if (fscache_submit_exclusive_op(object, op) < 0)
46722 goto nobufs;
46723 spin_unlock(&cookie->lock);
46724- fscache_stat(&fscache_n_attr_changed_ok);
46725+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
46726 fscache_put_operation(op);
46727 _leave(" = 0");
46728 return 0;
46729@@ -210,7 +210,7 @@ int __fscache_attr_changed(struct fscach
46730 nobufs:
46731 spin_unlock(&cookie->lock);
46732 kfree(op);
46733- fscache_stat(&fscache_n_attr_changed_nobufs);
46734+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
46735 _leave(" = %d", -ENOBUFS);
46736 return -ENOBUFS;
46737 }
46738@@ -246,7 +246,7 @@ static struct fscache_retrieval *fscache
46739 /* allocate a retrieval operation and attempt to submit it */
46740 op = kzalloc(sizeof(*op), GFP_NOIO);
46741 if (!op) {
46742- fscache_stat(&fscache_n_retrievals_nomem);
46743+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46744 return NULL;
46745 }
46746
46747@@ -275,13 +275,13 @@ static int fscache_wait_for_deferred_loo
46748 return 0;
46749 }
46750
46751- fscache_stat(&fscache_n_retrievals_wait);
46752+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
46753
46754 jif = jiffies;
46755 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
46756 fscache_wait_bit_interruptible,
46757 TASK_INTERRUPTIBLE) != 0) {
46758- fscache_stat(&fscache_n_retrievals_intr);
46759+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
46760 _leave(" = -ERESTARTSYS");
46761 return -ERESTARTSYS;
46762 }
46763@@ -299,8 +299,8 @@ static int fscache_wait_for_deferred_loo
46764 */
46765 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46766 struct fscache_retrieval *op,
46767- atomic_t *stat_op_waits,
46768- atomic_t *stat_object_dead)
46769+ atomic_unchecked_t *stat_op_waits,
46770+ atomic_unchecked_t *stat_object_dead)
46771 {
46772 int ret;
46773
46774@@ -308,7 +308,7 @@ static int fscache_wait_for_retrieval_ac
46775 goto check_if_dead;
46776
46777 _debug(">>> WT");
46778- fscache_stat(stat_op_waits);
46779+ fscache_stat_unchecked(stat_op_waits);
46780 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
46781 fscache_wait_bit_interruptible,
46782 TASK_INTERRUPTIBLE) < 0) {
46783@@ -325,7 +325,7 @@ static int fscache_wait_for_retrieval_ac
46784
46785 check_if_dead:
46786 if (unlikely(fscache_object_is_dead(object))) {
46787- fscache_stat(stat_object_dead);
46788+ fscache_stat_unchecked(stat_object_dead);
46789 return -ENOBUFS;
46790 }
46791 return 0;
46792@@ -352,7 +352,7 @@ int __fscache_read_or_alloc_page(struct
46793
46794 _enter("%p,%p,,,", cookie, page);
46795
46796- fscache_stat(&fscache_n_retrievals);
46797+ fscache_stat_unchecked(&fscache_n_retrievals);
46798
46799 if (hlist_empty(&cookie->backing_objects))
46800 goto nobufs;
46801@@ -386,7 +386,7 @@ int __fscache_read_or_alloc_page(struct
46802 goto nobufs_unlock;
46803 spin_unlock(&cookie->lock);
46804
46805- fscache_stat(&fscache_n_retrieval_ops);
46806+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
46807
46808 /* pin the netfs read context in case we need to do the actual netfs
46809 * read because we've encountered a cache read failure */
46810@@ -416,15 +416,15 @@ int __fscache_read_or_alloc_page(struct
46811
46812 error:
46813 if (ret == -ENOMEM)
46814- fscache_stat(&fscache_n_retrievals_nomem);
46815+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46816 else if (ret == -ERESTARTSYS)
46817- fscache_stat(&fscache_n_retrievals_intr);
46818+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
46819 else if (ret == -ENODATA)
46820- fscache_stat(&fscache_n_retrievals_nodata);
46821+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46822 else if (ret < 0)
46823- fscache_stat(&fscache_n_retrievals_nobufs);
46824+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46825 else
46826- fscache_stat(&fscache_n_retrievals_ok);
46827+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
46828
46829 fscache_put_retrieval(op);
46830 _leave(" = %d", ret);
46831@@ -434,7 +434,7 @@ nobufs_unlock:
46832 spin_unlock(&cookie->lock);
46833 kfree(op);
46834 nobufs:
46835- fscache_stat(&fscache_n_retrievals_nobufs);
46836+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46837 _leave(" = -ENOBUFS");
46838 return -ENOBUFS;
46839 }
46840@@ -472,7 +472,7 @@ int __fscache_read_or_alloc_pages(struct
46841
46842 _enter("%p,,%d,,,", cookie, *nr_pages);
46843
46844- fscache_stat(&fscache_n_retrievals);
46845+ fscache_stat_unchecked(&fscache_n_retrievals);
46846
46847 if (hlist_empty(&cookie->backing_objects))
46848 goto nobufs;
46849@@ -503,7 +503,7 @@ int __fscache_read_or_alloc_pages(struct
46850 goto nobufs_unlock;
46851 spin_unlock(&cookie->lock);
46852
46853- fscache_stat(&fscache_n_retrieval_ops);
46854+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
46855
46856 /* pin the netfs read context in case we need to do the actual netfs
46857 * read because we've encountered a cache read failure */
46858@@ -533,15 +533,15 @@ int __fscache_read_or_alloc_pages(struct
46859
46860 error:
46861 if (ret == -ENOMEM)
46862- fscache_stat(&fscache_n_retrievals_nomem);
46863+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46864 else if (ret == -ERESTARTSYS)
46865- fscache_stat(&fscache_n_retrievals_intr);
46866+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
46867 else if (ret == -ENODATA)
46868- fscache_stat(&fscache_n_retrievals_nodata);
46869+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46870 else if (ret < 0)
46871- fscache_stat(&fscache_n_retrievals_nobufs);
46872+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46873 else
46874- fscache_stat(&fscache_n_retrievals_ok);
46875+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
46876
46877 fscache_put_retrieval(op);
46878 _leave(" = %d", ret);
46879@@ -551,7 +551,7 @@ nobufs_unlock:
46880 spin_unlock(&cookie->lock);
46881 kfree(op);
46882 nobufs:
46883- fscache_stat(&fscache_n_retrievals_nobufs);
46884+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46885 _leave(" = -ENOBUFS");
46886 return -ENOBUFS;
46887 }
46888@@ -575,7 +575,7 @@ int __fscache_alloc_page(struct fscache_
46889
46890 _enter("%p,%p,,,", cookie, page);
46891
46892- fscache_stat(&fscache_n_allocs);
46893+ fscache_stat_unchecked(&fscache_n_allocs);
46894
46895 if (hlist_empty(&cookie->backing_objects))
46896 goto nobufs;
46897@@ -602,7 +602,7 @@ int __fscache_alloc_page(struct fscache_
46898 goto nobufs_unlock;
46899 spin_unlock(&cookie->lock);
46900
46901- fscache_stat(&fscache_n_alloc_ops);
46902+ fscache_stat_unchecked(&fscache_n_alloc_ops);
46903
46904 ret = fscache_wait_for_retrieval_activation(
46905 object, op,
46906@@ -618,11 +618,11 @@ int __fscache_alloc_page(struct fscache_
46907
46908 error:
46909 if (ret == -ERESTARTSYS)
46910- fscache_stat(&fscache_n_allocs_intr);
46911+ fscache_stat_unchecked(&fscache_n_allocs_intr);
46912 else if (ret < 0)
46913- fscache_stat(&fscache_n_allocs_nobufs);
46914+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46915 else
46916- fscache_stat(&fscache_n_allocs_ok);
46917+ fscache_stat_unchecked(&fscache_n_allocs_ok);
46918
46919 fscache_put_retrieval(op);
46920 _leave(" = %d", ret);
46921@@ -632,7 +632,7 @@ nobufs_unlock:
46922 spin_unlock(&cookie->lock);
46923 kfree(op);
46924 nobufs:
46925- fscache_stat(&fscache_n_allocs_nobufs);
46926+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46927 _leave(" = -ENOBUFS");
46928 return -ENOBUFS;
46929 }
46930@@ -675,7 +675,7 @@ static void fscache_write_op(struct fsca
46931
46932 spin_lock(&cookie->stores_lock);
46933
46934- fscache_stat(&fscache_n_store_calls);
46935+ fscache_stat_unchecked(&fscache_n_store_calls);
46936
46937 /* find a page to store */
46938 page = NULL;
46939@@ -686,7 +686,7 @@ static void fscache_write_op(struct fsca
46940 page = results[0];
46941 _debug("gang %d [%lx]", n, page->index);
46942 if (page->index > op->store_limit) {
46943- fscache_stat(&fscache_n_store_pages_over_limit);
46944+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
46945 goto superseded;
46946 }
46947
46948@@ -699,7 +699,7 @@ static void fscache_write_op(struct fsca
46949 spin_unlock(&object->lock);
46950
46951 fscache_set_op_state(&op->op, "Store");
46952- fscache_stat(&fscache_n_store_pages);
46953+ fscache_stat_unchecked(&fscache_n_store_pages);
46954 fscache_stat(&fscache_n_cop_write_page);
46955 ret = object->cache->ops->write_page(op, page);
46956 fscache_stat_d(&fscache_n_cop_write_page);
46957@@ -769,7 +769,7 @@ int __fscache_write_page(struct fscache_
46958 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46959 ASSERT(PageFsCache(page));
46960
46961- fscache_stat(&fscache_n_stores);
46962+ fscache_stat_unchecked(&fscache_n_stores);
46963
46964 op = kzalloc(sizeof(*op), GFP_NOIO);
46965 if (!op)
46966@@ -821,7 +821,7 @@ int __fscache_write_page(struct fscache_
46967 spin_unlock(&cookie->stores_lock);
46968 spin_unlock(&object->lock);
46969
46970- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
46971+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
46972 op->store_limit = object->store_limit;
46973
46974 if (fscache_submit_op(object, &op->op) < 0)
46975@@ -829,8 +829,8 @@ int __fscache_write_page(struct fscache_
46976
46977 spin_unlock(&cookie->lock);
46978 radix_tree_preload_end();
46979- fscache_stat(&fscache_n_store_ops);
46980- fscache_stat(&fscache_n_stores_ok);
46981+ fscache_stat_unchecked(&fscache_n_store_ops);
46982+ fscache_stat_unchecked(&fscache_n_stores_ok);
46983
46984 /* the work queue now carries its own ref on the object */
46985 fscache_put_operation(&op->op);
46986@@ -838,14 +838,14 @@ int __fscache_write_page(struct fscache_
46987 return 0;
46988
46989 already_queued:
46990- fscache_stat(&fscache_n_stores_again);
46991+ fscache_stat_unchecked(&fscache_n_stores_again);
46992 already_pending:
46993 spin_unlock(&cookie->stores_lock);
46994 spin_unlock(&object->lock);
46995 spin_unlock(&cookie->lock);
46996 radix_tree_preload_end();
46997 kfree(op);
46998- fscache_stat(&fscache_n_stores_ok);
46999+ fscache_stat_unchecked(&fscache_n_stores_ok);
47000 _leave(" = 0");
47001 return 0;
47002
47003@@ -864,14 +864,14 @@ nobufs:
47004 spin_unlock(&cookie->lock);
47005 radix_tree_preload_end();
47006 kfree(op);
47007- fscache_stat(&fscache_n_stores_nobufs);
47008+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
47009 _leave(" = -ENOBUFS");
47010 return -ENOBUFS;
47011
47012 nomem_free:
47013 kfree(op);
47014 nomem:
47015- fscache_stat(&fscache_n_stores_oom);
47016+ fscache_stat_unchecked(&fscache_n_stores_oom);
47017 _leave(" = -ENOMEM");
47018 return -ENOMEM;
47019 }
47020@@ -889,7 +889,7 @@ void __fscache_uncache_page(struct fscac
47021 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
47022 ASSERTCMP(page, !=, NULL);
47023
47024- fscache_stat(&fscache_n_uncaches);
47025+ fscache_stat_unchecked(&fscache_n_uncaches);
47026
47027 /* cache withdrawal may beat us to it */
47028 if (!PageFsCache(page))
47029@@ -942,7 +942,7 @@ void fscache_mark_pages_cached(struct fs
47030 unsigned long loop;
47031
47032 #ifdef CONFIG_FSCACHE_STATS
47033- atomic_add(pagevec->nr, &fscache_n_marks);
47034+ atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
47035 #endif
47036
47037 for (loop = 0; loop < pagevec->nr; loop++) {
47038diff -urNp linux-2.6.39.1/fs/fscache/stats.c linux-2.6.39.1/fs/fscache/stats.c
47039--- linux-2.6.39.1/fs/fscache/stats.c 2011-05-19 00:06:34.000000000 -0400
47040+++ linux-2.6.39.1/fs/fscache/stats.c 2011-05-22 19:36:32.000000000 -0400
47041@@ -18,95 +18,95 @@
47042 /*
47043 * operation counters
47044 */
47045-atomic_t fscache_n_op_pend;
47046-atomic_t fscache_n_op_run;
47047-atomic_t fscache_n_op_enqueue;
47048-atomic_t fscache_n_op_requeue;
47049-atomic_t fscache_n_op_deferred_release;
47050-atomic_t fscache_n_op_release;
47051-atomic_t fscache_n_op_gc;
47052-atomic_t fscache_n_op_cancelled;
47053-atomic_t fscache_n_op_rejected;
47054-
47055-atomic_t fscache_n_attr_changed;
47056-atomic_t fscache_n_attr_changed_ok;
47057-atomic_t fscache_n_attr_changed_nobufs;
47058-atomic_t fscache_n_attr_changed_nomem;
47059-atomic_t fscache_n_attr_changed_calls;
47060-
47061-atomic_t fscache_n_allocs;
47062-atomic_t fscache_n_allocs_ok;
47063-atomic_t fscache_n_allocs_wait;
47064-atomic_t fscache_n_allocs_nobufs;
47065-atomic_t fscache_n_allocs_intr;
47066-atomic_t fscache_n_allocs_object_dead;
47067-atomic_t fscache_n_alloc_ops;
47068-atomic_t fscache_n_alloc_op_waits;
47069-
47070-atomic_t fscache_n_retrievals;
47071-atomic_t fscache_n_retrievals_ok;
47072-atomic_t fscache_n_retrievals_wait;
47073-atomic_t fscache_n_retrievals_nodata;
47074-atomic_t fscache_n_retrievals_nobufs;
47075-atomic_t fscache_n_retrievals_intr;
47076-atomic_t fscache_n_retrievals_nomem;
47077-atomic_t fscache_n_retrievals_object_dead;
47078-atomic_t fscache_n_retrieval_ops;
47079-atomic_t fscache_n_retrieval_op_waits;
47080-
47081-atomic_t fscache_n_stores;
47082-atomic_t fscache_n_stores_ok;
47083-atomic_t fscache_n_stores_again;
47084-atomic_t fscache_n_stores_nobufs;
47085-atomic_t fscache_n_stores_oom;
47086-atomic_t fscache_n_store_ops;
47087-atomic_t fscache_n_store_calls;
47088-atomic_t fscache_n_store_pages;
47089-atomic_t fscache_n_store_radix_deletes;
47090-atomic_t fscache_n_store_pages_over_limit;
47091-
47092-atomic_t fscache_n_store_vmscan_not_storing;
47093-atomic_t fscache_n_store_vmscan_gone;
47094-atomic_t fscache_n_store_vmscan_busy;
47095-atomic_t fscache_n_store_vmscan_cancelled;
47096-
47097-atomic_t fscache_n_marks;
47098-atomic_t fscache_n_uncaches;
47099-
47100-atomic_t fscache_n_acquires;
47101-atomic_t fscache_n_acquires_null;
47102-atomic_t fscache_n_acquires_no_cache;
47103-atomic_t fscache_n_acquires_ok;
47104-atomic_t fscache_n_acquires_nobufs;
47105-atomic_t fscache_n_acquires_oom;
47106-
47107-atomic_t fscache_n_updates;
47108-atomic_t fscache_n_updates_null;
47109-atomic_t fscache_n_updates_run;
47110-
47111-atomic_t fscache_n_relinquishes;
47112-atomic_t fscache_n_relinquishes_null;
47113-atomic_t fscache_n_relinquishes_waitcrt;
47114-atomic_t fscache_n_relinquishes_retire;
47115-
47116-atomic_t fscache_n_cookie_index;
47117-atomic_t fscache_n_cookie_data;
47118-atomic_t fscache_n_cookie_special;
47119-
47120-atomic_t fscache_n_object_alloc;
47121-atomic_t fscache_n_object_no_alloc;
47122-atomic_t fscache_n_object_lookups;
47123-atomic_t fscache_n_object_lookups_negative;
47124-atomic_t fscache_n_object_lookups_positive;
47125-atomic_t fscache_n_object_lookups_timed_out;
47126-atomic_t fscache_n_object_created;
47127-atomic_t fscache_n_object_avail;
47128-atomic_t fscache_n_object_dead;
47129-
47130-atomic_t fscache_n_checkaux_none;
47131-atomic_t fscache_n_checkaux_okay;
47132-atomic_t fscache_n_checkaux_update;
47133-atomic_t fscache_n_checkaux_obsolete;
47134+atomic_unchecked_t fscache_n_op_pend;
47135+atomic_unchecked_t fscache_n_op_run;
47136+atomic_unchecked_t fscache_n_op_enqueue;
47137+atomic_unchecked_t fscache_n_op_requeue;
47138+atomic_unchecked_t fscache_n_op_deferred_release;
47139+atomic_unchecked_t fscache_n_op_release;
47140+atomic_unchecked_t fscache_n_op_gc;
47141+atomic_unchecked_t fscache_n_op_cancelled;
47142+atomic_unchecked_t fscache_n_op_rejected;
47143+
47144+atomic_unchecked_t fscache_n_attr_changed;
47145+atomic_unchecked_t fscache_n_attr_changed_ok;
47146+atomic_unchecked_t fscache_n_attr_changed_nobufs;
47147+atomic_unchecked_t fscache_n_attr_changed_nomem;
47148+atomic_unchecked_t fscache_n_attr_changed_calls;
47149+
47150+atomic_unchecked_t fscache_n_allocs;
47151+atomic_unchecked_t fscache_n_allocs_ok;
47152+atomic_unchecked_t fscache_n_allocs_wait;
47153+atomic_unchecked_t fscache_n_allocs_nobufs;
47154+atomic_unchecked_t fscache_n_allocs_intr;
47155+atomic_unchecked_t fscache_n_allocs_object_dead;
47156+atomic_unchecked_t fscache_n_alloc_ops;
47157+atomic_unchecked_t fscache_n_alloc_op_waits;
47158+
47159+atomic_unchecked_t fscache_n_retrievals;
47160+atomic_unchecked_t fscache_n_retrievals_ok;
47161+atomic_unchecked_t fscache_n_retrievals_wait;
47162+atomic_unchecked_t fscache_n_retrievals_nodata;
47163+atomic_unchecked_t fscache_n_retrievals_nobufs;
47164+atomic_unchecked_t fscache_n_retrievals_intr;
47165+atomic_unchecked_t fscache_n_retrievals_nomem;
47166+atomic_unchecked_t fscache_n_retrievals_object_dead;
47167+atomic_unchecked_t fscache_n_retrieval_ops;
47168+atomic_unchecked_t fscache_n_retrieval_op_waits;
47169+
47170+atomic_unchecked_t fscache_n_stores;
47171+atomic_unchecked_t fscache_n_stores_ok;
47172+atomic_unchecked_t fscache_n_stores_again;
47173+atomic_unchecked_t fscache_n_stores_nobufs;
47174+atomic_unchecked_t fscache_n_stores_oom;
47175+atomic_unchecked_t fscache_n_store_ops;
47176+atomic_unchecked_t fscache_n_store_calls;
47177+atomic_unchecked_t fscache_n_store_pages;
47178+atomic_unchecked_t fscache_n_store_radix_deletes;
47179+atomic_unchecked_t fscache_n_store_pages_over_limit;
47180+
47181+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
47182+atomic_unchecked_t fscache_n_store_vmscan_gone;
47183+atomic_unchecked_t fscache_n_store_vmscan_busy;
47184+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
47185+
47186+atomic_unchecked_t fscache_n_marks;
47187+atomic_unchecked_t fscache_n_uncaches;
47188+
47189+atomic_unchecked_t fscache_n_acquires;
47190+atomic_unchecked_t fscache_n_acquires_null;
47191+atomic_unchecked_t fscache_n_acquires_no_cache;
47192+atomic_unchecked_t fscache_n_acquires_ok;
47193+atomic_unchecked_t fscache_n_acquires_nobufs;
47194+atomic_unchecked_t fscache_n_acquires_oom;
47195+
47196+atomic_unchecked_t fscache_n_updates;
47197+atomic_unchecked_t fscache_n_updates_null;
47198+atomic_unchecked_t fscache_n_updates_run;
47199+
47200+atomic_unchecked_t fscache_n_relinquishes;
47201+atomic_unchecked_t fscache_n_relinquishes_null;
47202+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
47203+atomic_unchecked_t fscache_n_relinquishes_retire;
47204+
47205+atomic_unchecked_t fscache_n_cookie_index;
47206+atomic_unchecked_t fscache_n_cookie_data;
47207+atomic_unchecked_t fscache_n_cookie_special;
47208+
47209+atomic_unchecked_t fscache_n_object_alloc;
47210+atomic_unchecked_t fscache_n_object_no_alloc;
47211+atomic_unchecked_t fscache_n_object_lookups;
47212+atomic_unchecked_t fscache_n_object_lookups_negative;
47213+atomic_unchecked_t fscache_n_object_lookups_positive;
47214+atomic_unchecked_t fscache_n_object_lookups_timed_out;
47215+atomic_unchecked_t fscache_n_object_created;
47216+atomic_unchecked_t fscache_n_object_avail;
47217+atomic_unchecked_t fscache_n_object_dead;
47218+
47219+atomic_unchecked_t fscache_n_checkaux_none;
47220+atomic_unchecked_t fscache_n_checkaux_okay;
47221+atomic_unchecked_t fscache_n_checkaux_update;
47222+atomic_unchecked_t fscache_n_checkaux_obsolete;
47223
47224 atomic_t fscache_n_cop_alloc_object;
47225 atomic_t fscache_n_cop_lookup_object;
47226@@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq
47227 seq_puts(m, "FS-Cache statistics\n");
47228
47229 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
47230- atomic_read(&fscache_n_cookie_index),
47231- atomic_read(&fscache_n_cookie_data),
47232- atomic_read(&fscache_n_cookie_special));
47233+ atomic_read_unchecked(&fscache_n_cookie_index),
47234+ atomic_read_unchecked(&fscache_n_cookie_data),
47235+ atomic_read_unchecked(&fscache_n_cookie_special));
47236
47237 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
47238- atomic_read(&fscache_n_object_alloc),
47239- atomic_read(&fscache_n_object_no_alloc),
47240- atomic_read(&fscache_n_object_avail),
47241- atomic_read(&fscache_n_object_dead));
47242+ atomic_read_unchecked(&fscache_n_object_alloc),
47243+ atomic_read_unchecked(&fscache_n_object_no_alloc),
47244+ atomic_read_unchecked(&fscache_n_object_avail),
47245+ atomic_read_unchecked(&fscache_n_object_dead));
47246 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
47247- atomic_read(&fscache_n_checkaux_none),
47248- atomic_read(&fscache_n_checkaux_okay),
47249- atomic_read(&fscache_n_checkaux_update),
47250- atomic_read(&fscache_n_checkaux_obsolete));
47251+ atomic_read_unchecked(&fscache_n_checkaux_none),
47252+ atomic_read_unchecked(&fscache_n_checkaux_okay),
47253+ atomic_read_unchecked(&fscache_n_checkaux_update),
47254+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
47255
47256 seq_printf(m, "Pages : mrk=%u unc=%u\n",
47257- atomic_read(&fscache_n_marks),
47258- atomic_read(&fscache_n_uncaches));
47259+ atomic_read_unchecked(&fscache_n_marks),
47260+ atomic_read_unchecked(&fscache_n_uncaches));
47261
47262 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
47263 " oom=%u\n",
47264- atomic_read(&fscache_n_acquires),
47265- atomic_read(&fscache_n_acquires_null),
47266- atomic_read(&fscache_n_acquires_no_cache),
47267- atomic_read(&fscache_n_acquires_ok),
47268- atomic_read(&fscache_n_acquires_nobufs),
47269- atomic_read(&fscache_n_acquires_oom));
47270+ atomic_read_unchecked(&fscache_n_acquires),
47271+ atomic_read_unchecked(&fscache_n_acquires_null),
47272+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
47273+ atomic_read_unchecked(&fscache_n_acquires_ok),
47274+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
47275+ atomic_read_unchecked(&fscache_n_acquires_oom));
47276
47277 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
47278- atomic_read(&fscache_n_object_lookups),
47279- atomic_read(&fscache_n_object_lookups_negative),
47280- atomic_read(&fscache_n_object_lookups_positive),
47281- atomic_read(&fscache_n_object_created),
47282- atomic_read(&fscache_n_object_lookups_timed_out));
47283+ atomic_read_unchecked(&fscache_n_object_lookups),
47284+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
47285+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
47286+ atomic_read_unchecked(&fscache_n_object_created),
47287+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
47288
47289 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
47290- atomic_read(&fscache_n_updates),
47291- atomic_read(&fscache_n_updates_null),
47292- atomic_read(&fscache_n_updates_run));
47293+ atomic_read_unchecked(&fscache_n_updates),
47294+ atomic_read_unchecked(&fscache_n_updates_null),
47295+ atomic_read_unchecked(&fscache_n_updates_run));
47296
47297 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
47298- atomic_read(&fscache_n_relinquishes),
47299- atomic_read(&fscache_n_relinquishes_null),
47300- atomic_read(&fscache_n_relinquishes_waitcrt),
47301- atomic_read(&fscache_n_relinquishes_retire));
47302+ atomic_read_unchecked(&fscache_n_relinquishes),
47303+ atomic_read_unchecked(&fscache_n_relinquishes_null),
47304+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
47305+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
47306
47307 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
47308- atomic_read(&fscache_n_attr_changed),
47309- atomic_read(&fscache_n_attr_changed_ok),
47310- atomic_read(&fscache_n_attr_changed_nobufs),
47311- atomic_read(&fscache_n_attr_changed_nomem),
47312- atomic_read(&fscache_n_attr_changed_calls));
47313+ atomic_read_unchecked(&fscache_n_attr_changed),
47314+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
47315+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
47316+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
47317+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
47318
47319 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
47320- atomic_read(&fscache_n_allocs),
47321- atomic_read(&fscache_n_allocs_ok),
47322- atomic_read(&fscache_n_allocs_wait),
47323- atomic_read(&fscache_n_allocs_nobufs),
47324- atomic_read(&fscache_n_allocs_intr));
47325+ atomic_read_unchecked(&fscache_n_allocs),
47326+ atomic_read_unchecked(&fscache_n_allocs_ok),
47327+ atomic_read_unchecked(&fscache_n_allocs_wait),
47328+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
47329+ atomic_read_unchecked(&fscache_n_allocs_intr));
47330 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
47331- atomic_read(&fscache_n_alloc_ops),
47332- atomic_read(&fscache_n_alloc_op_waits),
47333- atomic_read(&fscache_n_allocs_object_dead));
47334+ atomic_read_unchecked(&fscache_n_alloc_ops),
47335+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
47336+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
47337
47338 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
47339 " int=%u oom=%u\n",
47340- atomic_read(&fscache_n_retrievals),
47341- atomic_read(&fscache_n_retrievals_ok),
47342- atomic_read(&fscache_n_retrievals_wait),
47343- atomic_read(&fscache_n_retrievals_nodata),
47344- atomic_read(&fscache_n_retrievals_nobufs),
47345- atomic_read(&fscache_n_retrievals_intr),
47346- atomic_read(&fscache_n_retrievals_nomem));
47347+ atomic_read_unchecked(&fscache_n_retrievals),
47348+ atomic_read_unchecked(&fscache_n_retrievals_ok),
47349+ atomic_read_unchecked(&fscache_n_retrievals_wait),
47350+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
47351+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
47352+ atomic_read_unchecked(&fscache_n_retrievals_intr),
47353+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
47354 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
47355- atomic_read(&fscache_n_retrieval_ops),
47356- atomic_read(&fscache_n_retrieval_op_waits),
47357- atomic_read(&fscache_n_retrievals_object_dead));
47358+ atomic_read_unchecked(&fscache_n_retrieval_ops),
47359+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
47360+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
47361
47362 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
47363- atomic_read(&fscache_n_stores),
47364- atomic_read(&fscache_n_stores_ok),
47365- atomic_read(&fscache_n_stores_again),
47366- atomic_read(&fscache_n_stores_nobufs),
47367- atomic_read(&fscache_n_stores_oom));
47368+ atomic_read_unchecked(&fscache_n_stores),
47369+ atomic_read_unchecked(&fscache_n_stores_ok),
47370+ atomic_read_unchecked(&fscache_n_stores_again),
47371+ atomic_read_unchecked(&fscache_n_stores_nobufs),
47372+ atomic_read_unchecked(&fscache_n_stores_oom));
47373 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
47374- atomic_read(&fscache_n_store_ops),
47375- atomic_read(&fscache_n_store_calls),
47376- atomic_read(&fscache_n_store_pages),
47377- atomic_read(&fscache_n_store_radix_deletes),
47378- atomic_read(&fscache_n_store_pages_over_limit));
47379+ atomic_read_unchecked(&fscache_n_store_ops),
47380+ atomic_read_unchecked(&fscache_n_store_calls),
47381+ atomic_read_unchecked(&fscache_n_store_pages),
47382+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
47383+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
47384
47385 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
47386- atomic_read(&fscache_n_store_vmscan_not_storing),
47387- atomic_read(&fscache_n_store_vmscan_gone),
47388- atomic_read(&fscache_n_store_vmscan_busy),
47389- atomic_read(&fscache_n_store_vmscan_cancelled));
47390+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
47391+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
47392+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
47393+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
47394
47395 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
47396- atomic_read(&fscache_n_op_pend),
47397- atomic_read(&fscache_n_op_run),
47398- atomic_read(&fscache_n_op_enqueue),
47399- atomic_read(&fscache_n_op_cancelled),
47400- atomic_read(&fscache_n_op_rejected));
47401+ atomic_read_unchecked(&fscache_n_op_pend),
47402+ atomic_read_unchecked(&fscache_n_op_run),
47403+ atomic_read_unchecked(&fscache_n_op_enqueue),
47404+ atomic_read_unchecked(&fscache_n_op_cancelled),
47405+ atomic_read_unchecked(&fscache_n_op_rejected));
47406 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
47407- atomic_read(&fscache_n_op_deferred_release),
47408- atomic_read(&fscache_n_op_release),
47409- atomic_read(&fscache_n_op_gc));
47410+ atomic_read_unchecked(&fscache_n_op_deferred_release),
47411+ atomic_read_unchecked(&fscache_n_op_release),
47412+ atomic_read_unchecked(&fscache_n_op_gc));
47413
47414 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
47415 atomic_read(&fscache_n_cop_alloc_object),
47416diff -urNp linux-2.6.39.1/fs/fs_struct.c linux-2.6.39.1/fs/fs_struct.c
47417--- linux-2.6.39.1/fs/fs_struct.c 2011-05-19 00:06:34.000000000 -0400
47418+++ linux-2.6.39.1/fs/fs_struct.c 2011-05-22 19:41:37.000000000 -0400
47419@@ -4,6 +4,7 @@
47420 #include <linux/path.h>
47421 #include <linux/slab.h>
47422 #include <linux/fs_struct.h>
47423+#include <linux/grsecurity.h>
47424 #include "internal.h"
47425
47426 static inline void path_get_longterm(struct path *path)
47427@@ -31,6 +32,7 @@ void set_fs_root(struct fs_struct *fs, s
47428 old_root = fs->root;
47429 fs->root = *path;
47430 path_get_longterm(path);
47431+ gr_set_chroot_entries(current, path);
47432 write_seqcount_end(&fs->seq);
47433 spin_unlock(&fs->lock);
47434 if (old_root.dentry)
47435@@ -74,6 +76,7 @@ void chroot_fs_refs(struct path *old_roo
47436 && fs->root.mnt == old_root->mnt) {
47437 path_get_longterm(new_root);
47438 fs->root = *new_root;
47439+ gr_set_chroot_entries(p, new_root);
47440 count++;
47441 }
47442 if (fs->pwd.dentry == old_root->dentry
47443@@ -109,7 +112,8 @@ void exit_fs(struct task_struct *tsk)
47444 spin_lock(&fs->lock);
47445 write_seqcount_begin(&fs->seq);
47446 tsk->fs = NULL;
47447- kill = !--fs->users;
47448+ gr_clear_chroot_entries(tsk);
47449+ kill = !atomic_dec_return(&fs->users);
47450 write_seqcount_end(&fs->seq);
47451 spin_unlock(&fs->lock);
47452 task_unlock(tsk);
47453@@ -123,7 +127,7 @@ struct fs_struct *copy_fs_struct(struct
47454 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
47455 /* We don't need to lock fs - think why ;-) */
47456 if (fs) {
47457- fs->users = 1;
47458+ atomic_set(&fs->users, 1);
47459 fs->in_exec = 0;
47460 spin_lock_init(&fs->lock);
47461 seqcount_init(&fs->seq);
47462@@ -132,6 +136,9 @@ struct fs_struct *copy_fs_struct(struct
47463 spin_lock(&old->lock);
47464 fs->root = old->root;
47465 path_get_longterm(&fs->root);
47466+ /* instead of calling gr_set_chroot_entries here,
47467+ we call it from every caller of this function
47468+ */
47469 fs->pwd = old->pwd;
47470 path_get_longterm(&fs->pwd);
47471 spin_unlock(&old->lock);
47472@@ -150,8 +157,9 @@ int unshare_fs_struct(void)
47473
47474 task_lock(current);
47475 spin_lock(&fs->lock);
47476- kill = !--fs->users;
47477+ kill = !atomic_dec_return(&fs->users);
47478 current->fs = new_fs;
47479+ gr_set_chroot_entries(current, &new_fs->root);
47480 spin_unlock(&fs->lock);
47481 task_unlock(current);
47482
47483@@ -170,7 +178,7 @@ EXPORT_SYMBOL(current_umask);
47484
47485 /* to be mentioned only in INIT_TASK */
47486 struct fs_struct init_fs = {
47487- .users = 1,
47488+ .users = ATOMIC_INIT(1),
47489 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
47490 .seq = SEQCNT_ZERO,
47491 .umask = 0022,
47492@@ -186,12 +194,13 @@ void daemonize_fs_struct(void)
47493 task_lock(current);
47494
47495 spin_lock(&init_fs.lock);
47496- init_fs.users++;
47497+ atomic_inc(&init_fs.users);
47498 spin_unlock(&init_fs.lock);
47499
47500 spin_lock(&fs->lock);
47501 current->fs = &init_fs;
47502- kill = !--fs->users;
47503+ gr_set_chroot_entries(current, &current->fs->root);
47504+ kill = !atomic_dec_return(&fs->users);
47505 spin_unlock(&fs->lock);
47506
47507 task_unlock(current);
47508diff -urNp linux-2.6.39.1/fs/fuse/cuse.c linux-2.6.39.1/fs/fuse/cuse.c
47509--- linux-2.6.39.1/fs/fuse/cuse.c 2011-05-19 00:06:34.000000000 -0400
47510+++ linux-2.6.39.1/fs/fuse/cuse.c 2011-05-22 19:36:32.000000000 -0400
47511@@ -538,8 +538,18 @@ static int cuse_channel_release(struct i
47512 return rc;
47513 }
47514
47515-static struct file_operations cuse_channel_fops; /* initialized during init */
47516-
47517+static const struct file_operations cuse_channel_fops = { /* initialized during init */
47518+ .owner = THIS_MODULE,
47519+ .llseek = no_llseek,
47520+ .read = do_sync_read,
47521+ .aio_read = fuse_dev_read,
47522+ .write = do_sync_write,
47523+ .aio_write = fuse_dev_write,
47524+ .poll = fuse_dev_poll,
47525+ .open = cuse_channel_open,
47526+ .release = cuse_channel_release,
47527+ .fasync = fuse_dev_fasync,
47528+};
47529
47530 /**************************************************************************
47531 * Misc stuff and module initializatiion
47532@@ -585,12 +595,6 @@ static int __init cuse_init(void)
47533 for (i = 0; i < CUSE_CONNTBL_LEN; i++)
47534 INIT_LIST_HEAD(&cuse_conntbl[i]);
47535
47536- /* inherit and extend fuse_dev_operations */
47537- cuse_channel_fops = fuse_dev_operations;
47538- cuse_channel_fops.owner = THIS_MODULE;
47539- cuse_channel_fops.open = cuse_channel_open;
47540- cuse_channel_fops.release = cuse_channel_release;
47541-
47542 cuse_class = class_create(THIS_MODULE, "cuse");
47543 if (IS_ERR(cuse_class))
47544 return PTR_ERR(cuse_class);
47545diff -urNp linux-2.6.39.1/fs/fuse/dev.c linux-2.6.39.1/fs/fuse/dev.c
47546--- linux-2.6.39.1/fs/fuse/dev.c 2011-05-19 00:06:34.000000000 -0400
47547+++ linux-2.6.39.1/fs/fuse/dev.c 2011-05-22 19:36:32.000000000 -0400
47548@@ -1181,7 +1181,7 @@ static ssize_t fuse_dev_do_read(struct f
47549 return err;
47550 }
47551
47552-static ssize_t fuse_dev_read(struct kiocb *iocb, const struct iovec *iov,
47553+ssize_t fuse_dev_read(struct kiocb *iocb, const struct iovec *iov,
47554 unsigned long nr_segs, loff_t pos)
47555 {
47556 struct fuse_copy_state cs;
47557@@ -1195,6 +1195,8 @@ static ssize_t fuse_dev_read(struct kioc
47558 return fuse_dev_do_read(fc, file, &cs, iov_length(iov, nr_segs));
47559 }
47560
47561+EXPORT_SYMBOL_GPL(fuse_dev_read);
47562+
47563 static int fuse_dev_pipe_buf_steal(struct pipe_inode_info *pipe,
47564 struct pipe_buffer *buf)
47565 {
47566@@ -1238,7 +1240,7 @@ static ssize_t fuse_dev_splice_read(stru
47567 ret = 0;
47568 pipe_lock(pipe);
47569
47570- if (!pipe->readers) {
47571+ if (!atomic_read(&pipe->readers)) {
47572 send_sig(SIGPIPE, current, 0);
47573 if (!ret)
47574 ret = -EPIPE;
47575@@ -1731,7 +1733,7 @@ static ssize_t fuse_dev_do_write(struct
47576 return err;
47577 }
47578
47579-static ssize_t fuse_dev_write(struct kiocb *iocb, const struct iovec *iov,
47580+ssize_t fuse_dev_write(struct kiocb *iocb, const struct iovec *iov,
47581 unsigned long nr_segs, loff_t pos)
47582 {
47583 struct fuse_copy_state cs;
47584@@ -1744,6 +1746,8 @@ static ssize_t fuse_dev_write(struct kio
47585 return fuse_dev_do_write(fc, &cs, iov_length(iov, nr_segs));
47586 }
47587
47588+EXPORT_SYMBOL_GPL(fuse_dev_write);
47589+
47590 static ssize_t fuse_dev_splice_write(struct pipe_inode_info *pipe,
47591 struct file *out, loff_t *ppos,
47592 size_t len, unsigned int flags)
47593@@ -1822,7 +1826,7 @@ out:
47594 return ret;
47595 }
47596
47597-static unsigned fuse_dev_poll(struct file *file, poll_table *wait)
47598+unsigned fuse_dev_poll(struct file *file, poll_table *wait)
47599 {
47600 unsigned mask = POLLOUT | POLLWRNORM;
47601 struct fuse_conn *fc = fuse_get_conn(file);
47602@@ -1841,6 +1845,8 @@ static unsigned fuse_dev_poll(struct fil
47603 return mask;
47604 }
47605
47606+EXPORT_SYMBOL_GPL(fuse_dev_poll);
47607+
47608 /*
47609 * Abort all requests on the given list (pending or processing)
47610 *
47611@@ -1977,7 +1983,7 @@ int fuse_dev_release(struct inode *inode
47612 }
47613 EXPORT_SYMBOL_GPL(fuse_dev_release);
47614
47615-static int fuse_dev_fasync(int fd, struct file *file, int on)
47616+int fuse_dev_fasync(int fd, struct file *file, int on)
47617 {
47618 struct fuse_conn *fc = fuse_get_conn(file);
47619 if (!fc)
47620@@ -1987,6 +1993,8 @@ static int fuse_dev_fasync(int fd, struc
47621 return fasync_helper(fd, file, on, &fc->fasync);
47622 }
47623
47624+EXPORT_SYMBOL_GPL(fuse_dev_fasync);
47625+
47626 const struct file_operations fuse_dev_operations = {
47627 .owner = THIS_MODULE,
47628 .llseek = no_llseek,
47629diff -urNp linux-2.6.39.1/fs/fuse/dir.c linux-2.6.39.1/fs/fuse/dir.c
47630--- linux-2.6.39.1/fs/fuse/dir.c 2011-05-19 00:06:34.000000000 -0400
47631+++ linux-2.6.39.1/fs/fuse/dir.c 2011-05-22 19:36:32.000000000 -0400
47632@@ -1147,7 +1147,7 @@ static char *read_link(struct dentry *de
47633 return link;
47634 }
47635
47636-static void free_link(char *link)
47637+static void free_link(const char *link)
47638 {
47639 if (!IS_ERR(link))
47640 free_page((unsigned long) link);
47641diff -urNp linux-2.6.39.1/fs/fuse/fuse_i.h linux-2.6.39.1/fs/fuse/fuse_i.h
47642--- linux-2.6.39.1/fs/fuse/fuse_i.h 2011-05-19 00:06:34.000000000 -0400
47643+++ linux-2.6.39.1/fs/fuse/fuse_i.h 2011-05-22 19:36:32.000000000 -0400
47644@@ -540,6 +540,16 @@ extern const struct file_operations fuse
47645
47646 extern const struct dentry_operations fuse_dentry_operations;
47647
47648+extern ssize_t fuse_dev_read(struct kiocb *iocb, const struct iovec *iov,
47649+ unsigned long nr_segs, loff_t pos);
47650+
47651+extern ssize_t fuse_dev_write(struct kiocb *iocb, const struct iovec *iov,
47652+ unsigned long nr_segs, loff_t pos);
47653+
47654+extern unsigned fuse_dev_poll(struct file *file, poll_table *wait);
47655+
47656+extern int fuse_dev_fasync(int fd, struct file *file, int on);
47657+
47658 /**
47659 * Inode to nodeid comparison.
47660 */
47661diff -urNp linux-2.6.39.1/fs/gfs2/ops_inode.c linux-2.6.39.1/fs/gfs2/ops_inode.c
47662--- linux-2.6.39.1/fs/gfs2/ops_inode.c 2011-05-19 00:06:34.000000000 -0400
47663+++ linux-2.6.39.1/fs/gfs2/ops_inode.c 2011-05-22 19:36:32.000000000 -0400
47664@@ -740,6 +740,8 @@ static int gfs2_rename(struct inode *odi
47665 unsigned int x;
47666 int error;
47667
47668+ pax_track_stack();
47669+
47670 if (ndentry->d_inode) {
47671 nip = GFS2_I(ndentry->d_inode);
47672 if (ip == nip)
47673@@ -1019,7 +1021,7 @@ out:
47674
47675 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
47676 {
47677- char *s = nd_get_link(nd);
47678+ const char *s = nd_get_link(nd);
47679 if (!IS_ERR(s))
47680 kfree(s);
47681 }
47682diff -urNp linux-2.6.39.1/fs/hfsplus/catalog.c linux-2.6.39.1/fs/hfsplus/catalog.c
47683--- linux-2.6.39.1/fs/hfsplus/catalog.c 2011-05-19 00:06:34.000000000 -0400
47684+++ linux-2.6.39.1/fs/hfsplus/catalog.c 2011-05-22 19:36:32.000000000 -0400
47685@@ -179,6 +179,8 @@ int hfsplus_find_cat(struct super_block
47686 int err;
47687 u16 type;
47688
47689+ pax_track_stack();
47690+
47691 hfsplus_cat_build_key(sb, fd->search_key, cnid, NULL);
47692 err = hfs_brec_read(fd, &tmp, sizeof(hfsplus_cat_entry));
47693 if (err)
47694@@ -210,6 +212,8 @@ int hfsplus_create_cat(u32 cnid, struct
47695 int entry_size;
47696 int err;
47697
47698+ pax_track_stack();
47699+
47700 dprint(DBG_CAT_MOD, "create_cat: %s,%u(%d)\n",
47701 str->name, cnid, inode->i_nlink);
47702 hfs_find_init(HFSPLUS_SB(sb)->cat_tree, &fd);
47703@@ -349,6 +353,8 @@ int hfsplus_rename_cat(u32 cnid,
47704 int entry_size, type;
47705 int err = 0;
47706
47707+ pax_track_stack();
47708+
47709 dprint(DBG_CAT_MOD, "rename_cat: %u - %lu,%s - %lu,%s\n",
47710 cnid, src_dir->i_ino, src_name->name,
47711 dst_dir->i_ino, dst_name->name);
47712diff -urNp linux-2.6.39.1/fs/hfsplus/dir.c linux-2.6.39.1/fs/hfsplus/dir.c
47713--- linux-2.6.39.1/fs/hfsplus/dir.c 2011-05-19 00:06:34.000000000 -0400
47714+++ linux-2.6.39.1/fs/hfsplus/dir.c 2011-05-22 19:36:32.000000000 -0400
47715@@ -129,6 +129,8 @@ static int hfsplus_readdir(struct file *
47716 struct hfsplus_readdir_data *rd;
47717 u16 type;
47718
47719+ pax_track_stack();
47720+
47721 if (filp->f_pos >= inode->i_size)
47722 return 0;
47723
47724diff -urNp linux-2.6.39.1/fs/hfsplus/inode.c linux-2.6.39.1/fs/hfsplus/inode.c
47725--- linux-2.6.39.1/fs/hfsplus/inode.c 2011-05-19 00:06:34.000000000 -0400
47726+++ linux-2.6.39.1/fs/hfsplus/inode.c 2011-05-22 19:36:32.000000000 -0400
47727@@ -489,6 +489,8 @@ int hfsplus_cat_read_inode(struct inode
47728 int res = 0;
47729 u16 type;
47730
47731+ pax_track_stack();
47732+
47733 type = hfs_bnode_read_u16(fd->bnode, fd->entryoffset);
47734
47735 HFSPLUS_I(inode)->linkid = 0;
47736@@ -552,6 +554,8 @@ int hfsplus_cat_write_inode(struct inode
47737 struct hfs_find_data fd;
47738 hfsplus_cat_entry entry;
47739
47740+ pax_track_stack();
47741+
47742 if (HFSPLUS_IS_RSRC(inode))
47743 main_inode = HFSPLUS_I(inode)->rsrc_inode;
47744
47745diff -urNp linux-2.6.39.1/fs/hfsplus/ioctl.c linux-2.6.39.1/fs/hfsplus/ioctl.c
47746--- linux-2.6.39.1/fs/hfsplus/ioctl.c 2011-05-19 00:06:34.000000000 -0400
47747+++ linux-2.6.39.1/fs/hfsplus/ioctl.c 2011-05-22 19:36:32.000000000 -0400
47748@@ -122,6 +122,8 @@ int hfsplus_setxattr(struct dentry *dent
47749 struct hfsplus_cat_file *file;
47750 int res;
47751
47752+ pax_track_stack();
47753+
47754 if (!S_ISREG(inode->i_mode) || HFSPLUS_IS_RSRC(inode))
47755 return -EOPNOTSUPP;
47756
47757@@ -166,6 +168,8 @@ ssize_t hfsplus_getxattr(struct dentry *
47758 struct hfsplus_cat_file *file;
47759 ssize_t res = 0;
47760
47761+ pax_track_stack();
47762+
47763 if (!S_ISREG(inode->i_mode) || HFSPLUS_IS_RSRC(inode))
47764 return -EOPNOTSUPP;
47765
47766diff -urNp linux-2.6.39.1/fs/hfsplus/super.c linux-2.6.39.1/fs/hfsplus/super.c
47767--- linux-2.6.39.1/fs/hfsplus/super.c 2011-05-19 00:06:34.000000000 -0400
47768+++ linux-2.6.39.1/fs/hfsplus/super.c 2011-05-22 19:36:32.000000000 -0400
47769@@ -340,6 +340,8 @@ static int hfsplus_fill_super(struct sup
47770 struct nls_table *nls = NULL;
47771 int err;
47772
47773+ pax_track_stack();
47774+
47775 err = -EINVAL;
47776 sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
47777 if (!sbi)
47778diff -urNp linux-2.6.39.1/fs/hugetlbfs/inode.c linux-2.6.39.1/fs/hugetlbfs/inode.c
47779--- linux-2.6.39.1/fs/hugetlbfs/inode.c 2011-05-19 00:06:34.000000000 -0400
47780+++ linux-2.6.39.1/fs/hugetlbfs/inode.c 2011-05-22 19:41:37.000000000 -0400
47781@@ -914,7 +914,7 @@ static struct file_system_type hugetlbfs
47782 .kill_sb = kill_litter_super,
47783 };
47784
47785-static struct vfsmount *hugetlbfs_vfsmount;
47786+struct vfsmount *hugetlbfs_vfsmount;
47787
47788 static int can_do_hugetlb_shm(void)
47789 {
47790diff -urNp linux-2.6.39.1/fs/inode.c linux-2.6.39.1/fs/inode.c
47791--- linux-2.6.39.1/fs/inode.c 2011-05-19 00:06:34.000000000 -0400
47792+++ linux-2.6.39.1/fs/inode.c 2011-05-22 19:36:32.000000000 -0400
47793@@ -862,8 +862,8 @@ unsigned int get_next_ino(void)
47794
47795 #ifdef CONFIG_SMP
47796 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
47797- static atomic_t shared_last_ino;
47798- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
47799+ static atomic_unchecked_t shared_last_ino;
47800+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
47801
47802 res = next - LAST_INO_BATCH;
47803 }
47804diff -urNp linux-2.6.39.1/fs/jbd/checkpoint.c linux-2.6.39.1/fs/jbd/checkpoint.c
47805--- linux-2.6.39.1/fs/jbd/checkpoint.c 2011-05-19 00:06:34.000000000 -0400
47806+++ linux-2.6.39.1/fs/jbd/checkpoint.c 2011-05-22 19:36:32.000000000 -0400
47807@@ -350,6 +350,8 @@ int log_do_checkpoint(journal_t *journal
47808 tid_t this_tid;
47809 int result;
47810
47811+ pax_track_stack();
47812+
47813 jbd_debug(1, "Start checkpoint\n");
47814
47815 /*
47816diff -urNp linux-2.6.39.1/fs/jffs2/compr_rtime.c linux-2.6.39.1/fs/jffs2/compr_rtime.c
47817--- linux-2.6.39.1/fs/jffs2/compr_rtime.c 2011-05-19 00:06:34.000000000 -0400
47818+++ linux-2.6.39.1/fs/jffs2/compr_rtime.c 2011-05-22 19:36:32.000000000 -0400
47819@@ -37,6 +37,8 @@ static int jffs2_rtime_compress(unsigned
47820 int outpos = 0;
47821 int pos=0;
47822
47823+ pax_track_stack();
47824+
47825 memset(positions,0,sizeof(positions));
47826
47827 while (pos < (*sourcelen) && outpos <= (*dstlen)-2) {
47828@@ -78,6 +80,8 @@ static int jffs2_rtime_decompress(unsign
47829 int outpos = 0;
47830 int pos=0;
47831
47832+ pax_track_stack();
47833+
47834 memset(positions,0,sizeof(positions));
47835
47836 while (outpos<destlen) {
47837diff -urNp linux-2.6.39.1/fs/jffs2/compr_rubin.c linux-2.6.39.1/fs/jffs2/compr_rubin.c
47838--- linux-2.6.39.1/fs/jffs2/compr_rubin.c 2011-05-19 00:06:34.000000000 -0400
47839+++ linux-2.6.39.1/fs/jffs2/compr_rubin.c 2011-05-22 19:36:32.000000000 -0400
47840@@ -314,6 +314,8 @@ static int jffs2_dynrubin_compress(unsig
47841 int ret;
47842 uint32_t mysrclen, mydstlen;
47843
47844+ pax_track_stack();
47845+
47846 mysrclen = *sourcelen;
47847 mydstlen = *dstlen - 8;
47848
47849diff -urNp linux-2.6.39.1/fs/jffs2/erase.c linux-2.6.39.1/fs/jffs2/erase.c
47850--- linux-2.6.39.1/fs/jffs2/erase.c 2011-05-19 00:06:34.000000000 -0400
47851+++ linux-2.6.39.1/fs/jffs2/erase.c 2011-05-22 19:36:32.000000000 -0400
47852@@ -439,7 +439,8 @@ static void jffs2_mark_erased_block(stru
47853 struct jffs2_unknown_node marker = {
47854 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
47855 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47856- .totlen = cpu_to_je32(c->cleanmarker_size)
47857+ .totlen = cpu_to_je32(c->cleanmarker_size),
47858+ .hdr_crc = cpu_to_je32(0)
47859 };
47860
47861 jffs2_prealloc_raw_node_refs(c, jeb, 1);
47862diff -urNp linux-2.6.39.1/fs/jffs2/wbuf.c linux-2.6.39.1/fs/jffs2/wbuf.c
47863--- linux-2.6.39.1/fs/jffs2/wbuf.c 2011-05-19 00:06:34.000000000 -0400
47864+++ linux-2.6.39.1/fs/jffs2/wbuf.c 2011-05-22 19:36:32.000000000 -0400
47865@@ -1012,7 +1012,8 @@ static const struct jffs2_unknown_node o
47866 {
47867 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
47868 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47869- .totlen = constant_cpu_to_je32(8)
47870+ .totlen = constant_cpu_to_je32(8),
47871+ .hdr_crc = constant_cpu_to_je32(0)
47872 };
47873
47874 /*
47875diff -urNp linux-2.6.39.1/fs/jffs2/xattr.c linux-2.6.39.1/fs/jffs2/xattr.c
47876--- linux-2.6.39.1/fs/jffs2/xattr.c 2011-05-19 00:06:34.000000000 -0400
47877+++ linux-2.6.39.1/fs/jffs2/xattr.c 2011-05-22 19:36:32.000000000 -0400
47878@@ -773,6 +773,8 @@ void jffs2_build_xattr_subsystem(struct
47879
47880 BUG_ON(!(c->flags & JFFS2_SB_FLAG_BUILDING));
47881
47882+ pax_track_stack();
47883+
47884 /* Phase.1 : Merge same xref */
47885 for (i=0; i < XREF_TMPHASH_SIZE; i++)
47886 xref_tmphash[i] = NULL;
47887diff -urNp linux-2.6.39.1/fs/jfs/super.c linux-2.6.39.1/fs/jfs/super.c
47888--- linux-2.6.39.1/fs/jfs/super.c 2011-05-19 00:06:34.000000000 -0400
47889+++ linux-2.6.39.1/fs/jfs/super.c 2011-06-07 18:07:24.000000000 -0400
47890@@ -803,7 +803,7 @@ static int __init init_jfs_fs(void)
47891
47892 jfs_inode_cachep =
47893 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
47894- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
47895+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
47896 init_once);
47897 if (jfs_inode_cachep == NULL)
47898 return -ENOMEM;
47899diff -urNp linux-2.6.39.1/fs/Kconfig.binfmt linux-2.6.39.1/fs/Kconfig.binfmt
47900--- linux-2.6.39.1/fs/Kconfig.binfmt 2011-05-19 00:06:34.000000000 -0400
47901+++ linux-2.6.39.1/fs/Kconfig.binfmt 2011-05-22 19:36:32.000000000 -0400
47902@@ -86,7 +86,7 @@ config HAVE_AOUT
47903
47904 config BINFMT_AOUT
47905 tristate "Kernel support for a.out and ECOFF binaries"
47906- depends on HAVE_AOUT
47907+ depends on HAVE_AOUT && BROKEN
47908 ---help---
47909 A.out (Assembler.OUTput) is a set of formats for libraries and
47910 executables used in the earliest versions of UNIX. Linux used
47911diff -urNp linux-2.6.39.1/fs/libfs.c linux-2.6.39.1/fs/libfs.c
47912--- linux-2.6.39.1/fs/libfs.c 2011-05-19 00:06:34.000000000 -0400
47913+++ linux-2.6.39.1/fs/libfs.c 2011-05-22 19:36:32.000000000 -0400
47914@@ -163,6 +163,9 @@ int dcache_readdir(struct file * filp, v
47915
47916 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
47917 struct dentry *next;
47918+ char d_name[sizeof(next->d_iname)];
47919+ const unsigned char *name;
47920+
47921 next = list_entry(p, struct dentry, d_u.d_child);
47922 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
47923 if (!simple_positive(next)) {
47924@@ -172,7 +175,12 @@ int dcache_readdir(struct file * filp, v
47925
47926 spin_unlock(&next->d_lock);
47927 spin_unlock(&dentry->d_lock);
47928- if (filldir(dirent, next->d_name.name,
47929+ name = next->d_name.name;
47930+ if (name == next->d_iname) {
47931+ memcpy(d_name, name, next->d_name.len);
47932+ name = d_name;
47933+ }
47934+ if (filldir(dirent, name,
47935 next->d_name.len, filp->f_pos,
47936 next->d_inode->i_ino,
47937 dt_type(next->d_inode)) < 0)
47938diff -urNp linux-2.6.39.1/fs/lockd/clntproc.c linux-2.6.39.1/fs/lockd/clntproc.c
47939--- linux-2.6.39.1/fs/lockd/clntproc.c 2011-05-19 00:06:34.000000000 -0400
47940+++ linux-2.6.39.1/fs/lockd/clntproc.c 2011-05-22 19:36:32.000000000 -0400
47941@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt
47942 /*
47943 * Cookie counter for NLM requests
47944 */
47945-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
47946+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
47947
47948 void nlmclnt_next_cookie(struct nlm_cookie *c)
47949 {
47950- u32 cookie = atomic_inc_return(&nlm_cookie);
47951+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
47952
47953 memcpy(c->data, &cookie, 4);
47954 c->len=4;
47955@@ -620,6 +620,8 @@ nlmclnt_reclaim(struct nlm_host *host, s
47956 struct nlm_rqst reqst, *req;
47957 int status;
47958
47959+ pax_track_stack();
47960+
47961 req = &reqst;
47962 memset(req, 0, sizeof(*req));
47963 locks_init_lock(&req->a_args.lock.fl);
47964diff -urNp linux-2.6.39.1/fs/lockd/svc.c linux-2.6.39.1/fs/lockd/svc.c
47965--- linux-2.6.39.1/fs/lockd/svc.c 2011-05-19 00:06:34.000000000 -0400
47966+++ linux-2.6.39.1/fs/lockd/svc.c 2011-05-22 19:36:32.000000000 -0400
47967@@ -41,7 +41,7 @@
47968
47969 static struct svc_program nlmsvc_program;
47970
47971-struct nlmsvc_binding * nlmsvc_ops;
47972+const struct nlmsvc_binding * nlmsvc_ops;
47973 EXPORT_SYMBOL_GPL(nlmsvc_ops);
47974
47975 static DEFINE_MUTEX(nlmsvc_mutex);
47976diff -urNp linux-2.6.39.1/fs/locks.c linux-2.6.39.1/fs/locks.c
47977--- linux-2.6.39.1/fs/locks.c 2011-05-19 00:06:34.000000000 -0400
47978+++ linux-2.6.39.1/fs/locks.c 2011-05-22 19:36:32.000000000 -0400
47979@@ -2033,16 +2033,16 @@ void locks_remove_flock(struct file *fil
47980 return;
47981
47982 if (filp->f_op && filp->f_op->flock) {
47983- struct file_lock fl = {
47984+ struct file_lock flock = {
47985 .fl_pid = current->tgid,
47986 .fl_file = filp,
47987 .fl_flags = FL_FLOCK,
47988 .fl_type = F_UNLCK,
47989 .fl_end = OFFSET_MAX,
47990 };
47991- filp->f_op->flock(filp, F_SETLKW, &fl);
47992- if (fl.fl_ops && fl.fl_ops->fl_release_private)
47993- fl.fl_ops->fl_release_private(&fl);
47994+ filp->f_op->flock(filp, F_SETLKW, &flock);
47995+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
47996+ flock.fl_ops->fl_release_private(&flock);
47997 }
47998
47999 lock_flocks();
48000diff -urNp linux-2.6.39.1/fs/logfs/super.c linux-2.6.39.1/fs/logfs/super.c
48001--- linux-2.6.39.1/fs/logfs/super.c 2011-05-19 00:06:34.000000000 -0400
48002+++ linux-2.6.39.1/fs/logfs/super.c 2011-05-22 19:36:32.000000000 -0400
48003@@ -266,6 +266,8 @@ static int logfs_recover_sb(struct super
48004 struct logfs_disk_super _ds1, *ds1 = &_ds1;
48005 int err, valid0, valid1;
48006
48007+ pax_track_stack();
48008+
48009 /* read first superblock */
48010 err = wbuf_read(sb, super->s_sb_ofs[0], sizeof(*ds0), ds0);
48011 if (err)
48012diff -urNp linux-2.6.39.1/fs/namei.c linux-2.6.39.1/fs/namei.c
48013--- linux-2.6.39.1/fs/namei.c 2011-06-03 00:04:14.000000000 -0400
48014+++ linux-2.6.39.1/fs/namei.c 2011-06-03 00:32:07.000000000 -0400
48015@@ -237,20 +237,30 @@ int generic_permission(struct inode *ino
48016 return ret;
48017
48018 /*
48019- * Read/write DACs are always overridable.
48020- * Executable DACs are overridable if at least one exec bit is set.
48021+ * Searching includes executable on directories, else just read.
48022 */
48023- if (!(mask & MAY_EXEC) || execute_ok(inode))
48024- if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
48025+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
48026+ if (mask == MAY_READ || (S_ISDIR(inode->i_mode) && !(mask & MAY_WRITE))) {
48027+#ifdef CONFIG_GRKERNSEC
48028+ if (flags & IPERM_FLAG_RCU)
48029+ return -ECHILD;
48030+#endif
48031+ if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
48032 return 0;
48033+ }
48034
48035 /*
48036- * Searching includes executable on directories, else just read.
48037+ * Read/write DACs are always overridable.
48038+ * Executable DACs are overridable if at least one exec bit is set.
48039 */
48040- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
48041- if (mask == MAY_READ || (S_ISDIR(inode->i_mode) && !(mask & MAY_WRITE)))
48042- if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
48043+ if (!(mask & MAY_EXEC) || execute_ok(inode)) {
48044+#ifdef CONFIG_GRKERNSEC
48045+ if (flags & IPERM_FLAG_RCU)
48046+ return -ECHILD;
48047+#endif
48048+ if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
48049 return 0;
48050+ }
48051
48052 return -EACCES;
48053 }
48054@@ -626,6 +636,9 @@ static inline int handle_reval_path(stru
48055 struct dentry *dentry = nd->path.dentry;
48056 int status;
48057
48058+ if (!(nd->flags & LOOKUP_PARENT) && !gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt))
48059+ return -ENOENT;
48060+
48061 if (likely(!(nd->flags & LOOKUP_JUMPED)))
48062 return 0;
48063
48064@@ -671,9 +684,16 @@ static inline int exec_permission(struct
48065 if (ret == -ECHILD)
48066 return ret;
48067
48068- if (ns_capable(ns, CAP_DAC_OVERRIDE) ||
48069- ns_capable(ns, CAP_DAC_READ_SEARCH))
48070+ if (ns_capable_nolog(ns, CAP_DAC_OVERRIDE))
48071 goto ok;
48072+ else {
48073+#ifdef CONFIG_GRKERNSEC
48074+ if (flags & IPERM_FLAG_RCU)
48075+ return -ECHILD;
48076+#endif
48077+ if (ns_capable(ns, CAP_DAC_READ_SEARCH) || ns_capable(ns, CAP_DAC_OVERRIDE))
48078+ goto ok;
48079+ }
48080
48081 return ret;
48082 ok:
48083@@ -781,11 +801,19 @@ follow_link(struct path *link, struct na
48084 return error;
48085 }
48086
48087+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
48088+ dentry->d_inode, dentry, nd->path.mnt)) {
48089+ error = -EACCES;
48090+ *p = ERR_PTR(error); /* no ->put_link(), please */
48091+ path_put(&nd->path);
48092+ return error;
48093+ }
48094+
48095 nd->last_type = LAST_BIND;
48096 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
48097 error = PTR_ERR(*p);
48098 if (!IS_ERR(*p)) {
48099- char *s = nd_get_link(nd);
48100+ const char *s = nd_get_link(nd);
48101 error = 0;
48102 if (s)
48103 error = __vfs_follow_link(nd, s);
48104@@ -1697,6 +1725,9 @@ static int do_path_lookup(int dfd, const
48105 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
48106
48107 if (likely(!retval)) {
48108+ if (*name != '/' && nd->path.dentry && nd->inode && !gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
48109+ return -ENOENT;
48110+
48111 if (unlikely(!audit_dummy_context())) {
48112 if (nd->path.dentry && nd->inode)
48113 audit_inode(name, nd->path.dentry);
48114@@ -2007,6 +2038,30 @@ int vfs_create(struct inode *dir, struct
48115 return error;
48116 }
48117
48118+/*
48119+ * Note that while the flag value (low two bits) for sys_open means:
48120+ * 00 - read-only
48121+ * 01 - write-only
48122+ * 10 - read-write
48123+ * 11 - special
48124+ * it is changed into
48125+ * 00 - no permissions needed
48126+ * 01 - read-permission
48127+ * 10 - write-permission
48128+ * 11 - read-write
48129+ * for the internal routines (ie open_namei()/follow_link() etc)
48130+ * This is more logical, and also allows the 00 "no perm needed"
48131+ * to be used for symlinks (where the permissions are checked
48132+ * later).
48133+ *
48134+*/
48135+static inline int open_to_namei_flags(int flag)
48136+{
48137+ if ((flag+1) & O_ACCMODE)
48138+ flag++;
48139+ return flag;
48140+}
48141+
48142 static int may_open(struct path *path, int acc_mode, int flag)
48143 {
48144 struct dentry *dentry = path->dentry;
48145@@ -2059,7 +2114,27 @@ static int may_open(struct path *path, i
48146 /*
48147 * Ensure there are no outstanding leases on the file.
48148 */
48149- return break_lease(inode, flag);
48150+ error = break_lease(inode, flag);
48151+
48152+ if (error)
48153+ return error;
48154+
48155+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode)) {
48156+ error = -EPERM;
48157+ goto exit;
48158+ }
48159+
48160+ if (gr_handle_rawio(inode)) {
48161+ error = -EPERM;
48162+ goto exit;
48163+ }
48164+
48165+ if (!gr_acl_handle_open(dentry, path->mnt, open_to_namei_flags(flag))) {
48166+ error = -EACCES;
48167+ goto exit;
48168+ }
48169+exit:
48170+ return error;
48171 }
48172
48173 static int handle_truncate(struct file *filp)
48174@@ -2085,30 +2160,6 @@ static int handle_truncate(struct file *
48175 }
48176
48177 /*
48178- * Note that while the flag value (low two bits) for sys_open means:
48179- * 00 - read-only
48180- * 01 - write-only
48181- * 10 - read-write
48182- * 11 - special
48183- * it is changed into
48184- * 00 - no permissions needed
48185- * 01 - read-permission
48186- * 10 - write-permission
48187- * 11 - read-write
48188- * for the internal routines (ie open_namei()/follow_link() etc)
48189- * This is more logical, and also allows the 00 "no perm needed"
48190- * to be used for symlinks (where the permissions are checked
48191- * later).
48192- *
48193-*/
48194-static inline int open_to_namei_flags(int flag)
48195-{
48196- if ((flag+1) & O_ACCMODE)
48197- flag++;
48198- return flag;
48199-}
48200-
48201-/*
48202 * Handle the last step of open()
48203 */
48204 static struct file *do_last(struct nameidata *nd, struct path *path,
48205@@ -2117,6 +2168,7 @@ static struct file *do_last(struct namei
48206 struct dentry *dir = nd->path.dentry;
48207 struct dentry *dentry;
48208 int open_flag = op->open_flag;
48209+ int flag = open_to_namei_flags(open_flag);
48210 int will_truncate = open_flag & O_TRUNC;
48211 int want_write = 0;
48212 int acc_mode = op->acc_mode;
48213@@ -2212,6 +2264,12 @@ static struct file *do_last(struct namei
48214 /* Negative dentry, just create the file */
48215 if (!dentry->d_inode) {
48216 int mode = op->mode;
48217+
48218+ if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, path->mnt, flag, mode)) {
48219+ error = -EACCES;
48220+ goto exit_mutex_unlock;
48221+ }
48222+
48223 if (!IS_POSIXACL(dir->d_inode))
48224 mode &= ~current_umask();
48225 /*
48226@@ -2235,6 +2293,8 @@ static struct file *do_last(struct namei
48227 error = vfs_create(dir->d_inode, dentry, mode, nd);
48228 if (error)
48229 goto exit_mutex_unlock;
48230+ else
48231+ gr_handle_create(path->dentry, path->mnt);
48232 mutex_unlock(&dir->d_inode->i_mutex);
48233 dput(nd->path.dentry);
48234 nd->path.dentry = dentry;
48235@@ -2244,6 +2304,14 @@ static struct file *do_last(struct namei
48236 /*
48237 * It already exists.
48238 */
48239+
48240+ /* only check if O_CREAT is specified, all other checks need to go
48241+ into may_open */
48242+ if (gr_handle_fifo(path->dentry, path->mnt, dir, flag, acc_mode)) {
48243+ error = -EACCES;
48244+ goto exit_mutex_unlock;
48245+ }
48246+
48247 mutex_unlock(&dir->d_inode->i_mutex);
48248 audit_inode(pathname, path->dentry);
48249
48250@@ -2530,6 +2598,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const
48251 error = may_mknod(mode);
48252 if (error)
48253 goto out_dput;
48254+
48255+ if (gr_handle_chroot_mknod(dentry, nd.path.mnt, mode)) {
48256+ error = -EPERM;
48257+ goto out_dput;
48258+ }
48259+
48260+ if (!gr_acl_handle_mknod(dentry, nd.path.dentry, nd.path.mnt, mode)) {
48261+ error = -EACCES;
48262+ goto out_dput;
48263+ }
48264+
48265 error = mnt_want_write(nd.path.mnt);
48266 if (error)
48267 goto out_dput;
48268@@ -2550,6 +2629,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const
48269 }
48270 out_drop_write:
48271 mnt_drop_write(nd.path.mnt);
48272+
48273+ if (!error)
48274+ gr_handle_create(dentry, nd.path.mnt);
48275 out_dput:
48276 dput(dentry);
48277 out_unlock:
48278@@ -2602,6 +2684,11 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const
48279 if (IS_ERR(dentry))
48280 goto out_unlock;
48281
48282+ if (!gr_acl_handle_mkdir(dentry, nd.path.dentry, nd.path.mnt)) {
48283+ error = -EACCES;
48284+ goto out_dput;
48285+ }
48286+
48287 if (!IS_POSIXACL(nd.path.dentry->d_inode))
48288 mode &= ~current_umask();
48289 error = mnt_want_write(nd.path.mnt);
48290@@ -2613,6 +2700,10 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const
48291 error = vfs_mkdir(nd.path.dentry->d_inode, dentry, mode);
48292 out_drop_write:
48293 mnt_drop_write(nd.path.mnt);
48294+
48295+ if (!error)
48296+ gr_handle_create(dentry, nd.path.mnt);
48297+
48298 out_dput:
48299 dput(dentry);
48300 out_unlock:
48301@@ -2692,6 +2783,8 @@ static long do_rmdir(int dfd, const char
48302 char * name;
48303 struct dentry *dentry;
48304 struct nameidata nd;
48305+ ino_t saved_ino = 0;
48306+ dev_t saved_dev = 0;
48307
48308 error = user_path_parent(dfd, pathname, &nd, &name);
48309 if (error)
48310@@ -2716,6 +2809,19 @@ static long do_rmdir(int dfd, const char
48311 error = PTR_ERR(dentry);
48312 if (IS_ERR(dentry))
48313 goto exit2;
48314+
48315+ if (dentry->d_inode != NULL) {
48316+ if (dentry->d_inode->i_nlink <= 1) {
48317+ saved_ino = dentry->d_inode->i_ino;
48318+ saved_dev = gr_get_dev_from_dentry(dentry);
48319+ }
48320+
48321+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
48322+ error = -EACCES;
48323+ goto exit3;
48324+ }
48325+ }
48326+
48327 error = mnt_want_write(nd.path.mnt);
48328 if (error)
48329 goto exit3;
48330@@ -2723,6 +2829,8 @@ static long do_rmdir(int dfd, const char
48331 if (error)
48332 goto exit4;
48333 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
48334+ if (!error && (saved_dev || saved_ino))
48335+ gr_handle_delete(saved_ino, saved_dev);
48336 exit4:
48337 mnt_drop_write(nd.path.mnt);
48338 exit3:
48339@@ -2785,6 +2893,8 @@ static long do_unlinkat(int dfd, const c
48340 struct dentry *dentry;
48341 struct nameidata nd;
48342 struct inode *inode = NULL;
48343+ ino_t saved_ino = 0;
48344+ dev_t saved_dev = 0;
48345
48346 error = user_path_parent(dfd, pathname, &nd, &name);
48347 if (error)
48348@@ -2804,8 +2914,17 @@ static long do_unlinkat(int dfd, const c
48349 if (nd.last.name[nd.last.len])
48350 goto slashes;
48351 inode = dentry->d_inode;
48352- if (inode)
48353+ if (inode) {
48354 ihold(inode);
48355+ if (inode->i_nlink <= 1) {
48356+ saved_ino = inode->i_ino;
48357+ saved_dev = gr_get_dev_from_dentry(dentry);
48358+ }
48359+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
48360+ error = -EACCES;
48361+ goto exit2;
48362+ }
48363+ }
48364 error = mnt_want_write(nd.path.mnt);
48365 if (error)
48366 goto exit2;
48367@@ -2813,6 +2932,8 @@ static long do_unlinkat(int dfd, const c
48368 if (error)
48369 goto exit3;
48370 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
48371+ if (!error && (saved_ino || saved_dev))
48372+ gr_handle_delete(saved_ino, saved_dev);
48373 exit3:
48374 mnt_drop_write(nd.path.mnt);
48375 exit2:
48376@@ -2890,6 +3011,11 @@ SYSCALL_DEFINE3(symlinkat, const char __
48377 if (IS_ERR(dentry))
48378 goto out_unlock;
48379
48380+ if (!gr_acl_handle_symlink(dentry, nd.path.dentry, nd.path.mnt, from)) {
48381+ error = -EACCES;
48382+ goto out_dput;
48383+ }
48384+
48385 error = mnt_want_write(nd.path.mnt);
48386 if (error)
48387 goto out_dput;
48388@@ -2897,6 +3023,8 @@ SYSCALL_DEFINE3(symlinkat, const char __
48389 if (error)
48390 goto out_drop_write;
48391 error = vfs_symlink(nd.path.dentry->d_inode, dentry, from);
48392+ if (!error)
48393+ gr_handle_create(dentry, nd.path.mnt);
48394 out_drop_write:
48395 mnt_drop_write(nd.path.mnt);
48396 out_dput:
48397@@ -3005,6 +3133,20 @@ SYSCALL_DEFINE5(linkat, int, olddfd, con
48398 error = PTR_ERR(new_dentry);
48399 if (IS_ERR(new_dentry))
48400 goto out_unlock;
48401+
48402+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
48403+ old_path.dentry->d_inode,
48404+ old_path.dentry->d_inode->i_mode, to)) {
48405+ error = -EACCES;
48406+ goto out_dput;
48407+ }
48408+
48409+ if (!gr_acl_handle_link(new_dentry, nd.path.dentry, nd.path.mnt,
48410+ old_path.dentry, old_path.mnt, to)) {
48411+ error = -EACCES;
48412+ goto out_dput;
48413+ }
48414+
48415 error = mnt_want_write(nd.path.mnt);
48416 if (error)
48417 goto out_dput;
48418@@ -3012,6 +3154,8 @@ SYSCALL_DEFINE5(linkat, int, olddfd, con
48419 if (error)
48420 goto out_drop_write;
48421 error = vfs_link(old_path.dentry, nd.path.dentry->d_inode, new_dentry);
48422+ if (!error)
48423+ gr_handle_create(new_dentry, nd.path.mnt);
48424 out_drop_write:
48425 mnt_drop_write(nd.path.mnt);
48426 out_dput:
48427@@ -3189,6 +3333,8 @@ SYSCALL_DEFINE4(renameat, int, olddfd, c
48428 char *to;
48429 int error;
48430
48431+ pax_track_stack();
48432+
48433 error = user_path_parent(olddfd, oldname, &oldnd, &from);
48434 if (error)
48435 goto exit;
48436@@ -3245,6 +3391,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, c
48437 if (new_dentry == trap)
48438 goto exit5;
48439
48440+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
48441+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
48442+ to);
48443+ if (error)
48444+ goto exit5;
48445+
48446 error = mnt_want_write(oldnd.path.mnt);
48447 if (error)
48448 goto exit5;
48449@@ -3254,6 +3406,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, c
48450 goto exit6;
48451 error = vfs_rename(old_dir->d_inode, old_dentry,
48452 new_dir->d_inode, new_dentry);
48453+ if (!error)
48454+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
48455+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
48456 exit6:
48457 mnt_drop_write(oldnd.path.mnt);
48458 exit5:
48459@@ -3279,6 +3434,8 @@ SYSCALL_DEFINE2(rename, const char __use
48460
48461 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
48462 {
48463+ char tmpbuf[64];
48464+ const char *newlink;
48465 int len;
48466
48467 len = PTR_ERR(link);
48468@@ -3288,7 +3445,14 @@ int vfs_readlink(struct dentry *dentry,
48469 len = strlen(link);
48470 if (len > (unsigned) buflen)
48471 len = buflen;
48472- if (copy_to_user(buffer, link, len))
48473+
48474+ if (len < sizeof(tmpbuf)) {
48475+ memcpy(tmpbuf, link, len);
48476+ newlink = tmpbuf;
48477+ } else
48478+ newlink = link;
48479+
48480+ if (copy_to_user(buffer, newlink, len))
48481 len = -EFAULT;
48482 out:
48483 return len;
48484diff -urNp linux-2.6.39.1/fs/namespace.c linux-2.6.39.1/fs/namespace.c
48485--- linux-2.6.39.1/fs/namespace.c 2011-05-19 00:06:34.000000000 -0400
48486+++ linux-2.6.39.1/fs/namespace.c 2011-05-22 20:43:58.000000000 -0400
48487@@ -1328,6 +1328,9 @@ static int do_umount(struct vfsmount *mn
48488 if (!(sb->s_flags & MS_RDONLY))
48489 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
48490 up_write(&sb->s_umount);
48491+
48492+ gr_log_remount(mnt->mnt_devname, retval);
48493+
48494 return retval;
48495 }
48496
48497@@ -1347,6 +1350,9 @@ static int do_umount(struct vfsmount *mn
48498 br_write_unlock(vfsmount_lock);
48499 up_write(&namespace_sem);
48500 release_mounts(&umount_list);
48501+
48502+ gr_log_unmount(mnt->mnt_devname, retval);
48503+
48504 return retval;
48505 }
48506
48507@@ -2338,6 +2344,16 @@ long do_mount(char *dev_name, char *dir_
48508 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
48509 MS_STRICTATIME);
48510
48511+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
48512+ retval = -EPERM;
48513+ goto dput_out;
48514+ }
48515+
48516+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
48517+ retval = -EPERM;
48518+ goto dput_out;
48519+ }
48520+
48521 if (flags & MS_REMOUNT)
48522 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
48523 data_page);
48524@@ -2352,6 +2368,9 @@ long do_mount(char *dev_name, char *dir_
48525 dev_name, data_page);
48526 dput_out:
48527 path_put(&path);
48528+
48529+ gr_log_mount(dev_name, dir_name, retval);
48530+
48531 return retval;
48532 }
48533
48534@@ -2575,6 +2594,11 @@ SYSCALL_DEFINE2(pivot_root, const char _
48535 if (error)
48536 goto out2;
48537
48538+ if (gr_handle_chroot_pivot()) {
48539+ error = -EPERM;
48540+ goto out2;
48541+ }
48542+
48543 get_fs_root(current->fs, &root);
48544 error = lock_mount(&old);
48545 if (error)
48546diff -urNp linux-2.6.39.1/fs/ncpfs/dir.c linux-2.6.39.1/fs/ncpfs/dir.c
48547--- linux-2.6.39.1/fs/ncpfs/dir.c 2011-05-19 00:06:34.000000000 -0400
48548+++ linux-2.6.39.1/fs/ncpfs/dir.c 2011-05-22 19:36:32.000000000 -0400
48549@@ -299,6 +299,8 @@ ncp_lookup_validate(struct dentry *dentr
48550 int res, val = 0, len;
48551 __u8 __name[NCP_MAXPATHLEN + 1];
48552
48553+ pax_track_stack();
48554+
48555 if (dentry == dentry->d_sb->s_root)
48556 return 1;
48557
48558@@ -844,6 +846,8 @@ static struct dentry *ncp_lookup(struct
48559 int error, res, len;
48560 __u8 __name[NCP_MAXPATHLEN + 1];
48561
48562+ pax_track_stack();
48563+
48564 error = -EIO;
48565 if (!ncp_conn_valid(server))
48566 goto finished;
48567@@ -931,6 +935,8 @@ int ncp_create_new(struct inode *dir, st
48568 PPRINTK("ncp_create_new: creating %s/%s, mode=%x\n",
48569 dentry->d_parent->d_name.name, dentry->d_name.name, mode);
48570
48571+ pax_track_stack();
48572+
48573 ncp_age_dentry(server, dentry);
48574 len = sizeof(__name);
48575 error = ncp_io2vol(server, __name, &len, dentry->d_name.name,
48576@@ -992,6 +998,8 @@ static int ncp_mkdir(struct inode *dir,
48577 int error, len;
48578 __u8 __name[NCP_MAXPATHLEN + 1];
48579
48580+ pax_track_stack();
48581+
48582 DPRINTK("ncp_mkdir: making %s/%s\n",
48583 dentry->d_parent->d_name.name, dentry->d_name.name);
48584
48585@@ -1135,6 +1143,8 @@ static int ncp_rename(struct inode *old_
48586 int old_len, new_len;
48587 __u8 __old_name[NCP_MAXPATHLEN + 1], __new_name[NCP_MAXPATHLEN + 1];
48588
48589+ pax_track_stack();
48590+
48591 DPRINTK("ncp_rename: %s/%s to %s/%s\n",
48592 old_dentry->d_parent->d_name.name, old_dentry->d_name.name,
48593 new_dentry->d_parent->d_name.name, new_dentry->d_name.name);
48594diff -urNp linux-2.6.39.1/fs/ncpfs/inode.c linux-2.6.39.1/fs/ncpfs/inode.c
48595--- linux-2.6.39.1/fs/ncpfs/inode.c 2011-05-19 00:06:34.000000000 -0400
48596+++ linux-2.6.39.1/fs/ncpfs/inode.c 2011-05-22 19:36:32.000000000 -0400
48597@@ -461,6 +461,8 @@ static int ncp_fill_super(struct super_b
48598 #endif
48599 struct ncp_entry_info finfo;
48600
48601+ pax_track_stack();
48602+
48603 data.wdog_pid = NULL;
48604 server = kzalloc(sizeof(struct ncp_server), GFP_KERNEL);
48605 if (!server)
48606diff -urNp linux-2.6.39.1/fs/nfs/inode.c linux-2.6.39.1/fs/nfs/inode.c
48607--- linux-2.6.39.1/fs/nfs/inode.c 2011-05-19 00:06:34.000000000 -0400
48608+++ linux-2.6.39.1/fs/nfs/inode.c 2011-05-22 19:36:32.000000000 -0400
48609@@ -999,16 +999,16 @@ static int nfs_size_need_update(const st
48610 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
48611 }
48612
48613-static atomic_long_t nfs_attr_generation_counter;
48614+static atomic_long_unchecked_t nfs_attr_generation_counter;
48615
48616 static unsigned long nfs_read_attr_generation_counter(void)
48617 {
48618- return atomic_long_read(&nfs_attr_generation_counter);
48619+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
48620 }
48621
48622 unsigned long nfs_inc_attr_generation_counter(void)
48623 {
48624- return atomic_long_inc_return(&nfs_attr_generation_counter);
48625+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
48626 }
48627
48628 void nfs_fattr_init(struct nfs_fattr *fattr)
48629diff -urNp linux-2.6.39.1/fs/nfs/nfs4proc.c linux-2.6.39.1/fs/nfs/nfs4proc.c
48630--- linux-2.6.39.1/fs/nfs/nfs4proc.c 2011-06-03 00:04:14.000000000 -0400
48631+++ linux-2.6.39.1/fs/nfs/nfs4proc.c 2011-06-03 00:32:07.000000000 -0400
48632@@ -5845,14 +5845,14 @@ struct nfs4_state_recovery_ops nfs41_nog
48633 };
48634 #endif /* CONFIG_NFS_V4_1 */
48635
48636-struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = {
48637+const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = {
48638 .sched_state_renewal = nfs4_proc_async_renew,
48639 .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked,
48640 .renew_lease = nfs4_proc_renew,
48641 };
48642
48643 #if defined(CONFIG_NFS_V4_1)
48644-struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = {
48645+const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = {
48646 .sched_state_renewal = nfs41_proc_async_sequence,
48647 .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked,
48648 .renew_lease = nfs4_proc_sequence,
48649diff -urNp linux-2.6.39.1/fs/nfsd/lockd.c linux-2.6.39.1/fs/nfsd/lockd.c
48650--- linux-2.6.39.1/fs/nfsd/lockd.c 2011-05-19 00:06:34.000000000 -0400
48651+++ linux-2.6.39.1/fs/nfsd/lockd.c 2011-05-22 19:36:32.000000000 -0400
48652@@ -60,7 +60,7 @@ nlm_fclose(struct file *filp)
48653 fput(filp);
48654 }
48655
48656-static struct nlmsvc_binding nfsd_nlm_ops = {
48657+static const struct nlmsvc_binding nfsd_nlm_ops = {
48658 .fopen = nlm_fopen, /* open file for locking */
48659 .fclose = nlm_fclose, /* close file */
48660 };
48661diff -urNp linux-2.6.39.1/fs/nfsd/nfs4state.c linux-2.6.39.1/fs/nfsd/nfs4state.c
48662--- linux-2.6.39.1/fs/nfsd/nfs4state.c 2011-05-19 00:06:34.000000000 -0400
48663+++ linux-2.6.39.1/fs/nfsd/nfs4state.c 2011-05-22 19:36:32.000000000 -0400
48664@@ -3784,6 +3784,8 @@ nfsd4_lock(struct svc_rqst *rqstp, struc
48665 unsigned int strhashval;
48666 int err;
48667
48668+ pax_track_stack();
48669+
48670 dprintk("NFSD: nfsd4_lock: start=%Ld length=%Ld\n",
48671 (long long) lock->lk_offset,
48672 (long long) lock->lk_length);
48673diff -urNp linux-2.6.39.1/fs/nfsd/nfs4xdr.c linux-2.6.39.1/fs/nfsd/nfs4xdr.c
48674--- linux-2.6.39.1/fs/nfsd/nfs4xdr.c 2011-05-19 00:06:34.000000000 -0400
48675+++ linux-2.6.39.1/fs/nfsd/nfs4xdr.c 2011-05-22 19:36:32.000000000 -0400
48676@@ -1793,6 +1793,8 @@ nfsd4_encode_fattr(struct svc_fh *fhp, s
48677 .dentry = dentry,
48678 };
48679
48680+ pax_track_stack();
48681+
48682 BUG_ON(bmval1 & NFSD_WRITEONLY_ATTRS_WORD1);
48683 BUG_ON(bmval0 & ~nfsd_suppattrs0(minorversion));
48684 BUG_ON(bmval1 & ~nfsd_suppattrs1(minorversion));
48685diff -urNp linux-2.6.39.1/fs/nfsd/nfsctl.c linux-2.6.39.1/fs/nfsd/nfsctl.c
48686--- linux-2.6.39.1/fs/nfsd/nfsctl.c 2011-05-19 00:06:34.000000000 -0400
48687+++ linux-2.6.39.1/fs/nfsd/nfsctl.c 2011-05-22 19:36:32.000000000 -0400
48688@@ -182,7 +182,7 @@ static int export_features_open(struct i
48689 return single_open(file, export_features_show, NULL);
48690 }
48691
48692-static struct file_operations export_features_operations = {
48693+static const struct file_operations export_features_operations = {
48694 .open = export_features_open,
48695 .read = seq_read,
48696 .llseek = seq_lseek,
48697diff -urNp linux-2.6.39.1/fs/nfsd/vfs.c linux-2.6.39.1/fs/nfsd/vfs.c
48698--- linux-2.6.39.1/fs/nfsd/vfs.c 2011-05-19 00:06:34.000000000 -0400
48699+++ linux-2.6.39.1/fs/nfsd/vfs.c 2011-05-22 19:36:32.000000000 -0400
48700@@ -898,7 +898,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, st
48701 } else {
48702 oldfs = get_fs();
48703 set_fs(KERNEL_DS);
48704- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
48705+ host_err = vfs_readv(file, (__force struct iovec __user *)vec, vlen, &offset);
48706 set_fs(oldfs);
48707 }
48708
48709@@ -1002,7 +1002,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, s
48710
48711 /* Write the data. */
48712 oldfs = get_fs(); set_fs(KERNEL_DS);
48713- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
48714+ host_err = vfs_writev(file, (__force struct iovec __user *)vec, vlen, &offset);
48715 set_fs(oldfs);
48716 if (host_err < 0)
48717 goto out_nfserr;
48718@@ -1525,7 +1525,7 @@ nfsd_readlink(struct svc_rqst *rqstp, st
48719 */
48720
48721 oldfs = get_fs(); set_fs(KERNEL_DS);
48722- host_err = inode->i_op->readlink(dentry, buf, *lenp);
48723+ host_err = inode->i_op->readlink(dentry, (__force char __user *)buf, *lenp);
48724 set_fs(oldfs);
48725
48726 if (host_err < 0)
48727diff -urNp linux-2.6.39.1/fs/nilfs2/segment.c linux-2.6.39.1/fs/nilfs2/segment.c
48728--- linux-2.6.39.1/fs/nilfs2/segment.c 2011-05-19 00:06:34.000000000 -0400
48729+++ linux-2.6.39.1/fs/nilfs2/segment.c 2011-05-22 19:36:32.000000000 -0400
48730@@ -555,7 +555,7 @@ static void nilfs_write_file_node_binfo(
48731 *vblocknr = binfo->bi_v.bi_vblocknr;
48732 }
48733
48734-static struct nilfs_sc_operations nilfs_sc_file_ops = {
48735+static const struct nilfs_sc_operations nilfs_sc_file_ops = {
48736 .collect_data = nilfs_collect_file_data,
48737 .collect_node = nilfs_collect_file_node,
48738 .collect_bmap = nilfs_collect_file_bmap,
48739@@ -604,7 +604,7 @@ static void nilfs_write_dat_node_binfo(s
48740 *binfo_dat = binfo->bi_dat;
48741 }
48742
48743-static struct nilfs_sc_operations nilfs_sc_dat_ops = {
48744+static const struct nilfs_sc_operations nilfs_sc_dat_ops = {
48745 .collect_data = nilfs_collect_dat_data,
48746 .collect_node = nilfs_collect_file_node,
48747 .collect_bmap = nilfs_collect_dat_bmap,
48748@@ -612,7 +612,7 @@ static struct nilfs_sc_operations nilfs_
48749 .write_node_binfo = nilfs_write_dat_node_binfo,
48750 };
48751
48752-static struct nilfs_sc_operations nilfs_sc_dsync_ops = {
48753+static const struct nilfs_sc_operations nilfs_sc_dsync_ops = {
48754 .collect_data = nilfs_collect_file_data,
48755 .collect_node = NULL,
48756 .collect_bmap = NULL,
48757@@ -971,7 +971,7 @@ static size_t nilfs_segctor_buffer_rest(
48758
48759 static int nilfs_segctor_scan_file(struct nilfs_sc_info *sci,
48760 struct inode *inode,
48761- struct nilfs_sc_operations *sc_ops)
48762+ const struct nilfs_sc_operations *sc_ops)
48763 {
48764 LIST_HEAD(data_buffers);
48765 LIST_HEAD(node_buffers);
48766@@ -1475,7 +1475,7 @@ nilfs_segctor_update_payload_blocknr(str
48767 sector_t blocknr;
48768 unsigned long nfinfo = segbuf->sb_sum.nfinfo;
48769 unsigned long nblocks = 0, ndatablk = 0;
48770- struct nilfs_sc_operations *sc_op = NULL;
48771+ const struct nilfs_sc_operations *sc_op = NULL;
48772 struct nilfs_segsum_pointer ssp;
48773 struct nilfs_finfo *finfo = NULL;
48774 union nilfs_binfo binfo;
48775diff -urNp linux-2.6.39.1/fs/notify/dnotify/dnotify.c linux-2.6.39.1/fs/notify/dnotify/dnotify.c
48776--- linux-2.6.39.1/fs/notify/dnotify/dnotify.c 2011-05-19 00:06:34.000000000 -0400
48777+++ linux-2.6.39.1/fs/notify/dnotify/dnotify.c 2011-05-22 19:36:32.000000000 -0400
48778@@ -151,7 +151,7 @@ static void dnotify_free_mark(struct fsn
48779 kmem_cache_free(dnotify_mark_cache, dn_mark);
48780 }
48781
48782-static struct fsnotify_ops dnotify_fsnotify_ops = {
48783+static const struct fsnotify_ops dnotify_fsnotify_ops = {
48784 .handle_event = dnotify_handle_event,
48785 .should_send_event = dnotify_should_send_event,
48786 .free_group_priv = NULL,
48787diff -urNp linux-2.6.39.1/fs/notify/notification.c linux-2.6.39.1/fs/notify/notification.c
48788--- linux-2.6.39.1/fs/notify/notification.c 2011-05-19 00:06:34.000000000 -0400
48789+++ linux-2.6.39.1/fs/notify/notification.c 2011-05-22 19:36:32.000000000 -0400
48790@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event
48791 * get set to 0 so it will never get 'freed'
48792 */
48793 static struct fsnotify_event *q_overflow_event;
48794-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48795+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48796
48797 /**
48798 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
48799@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = A
48800 */
48801 u32 fsnotify_get_cookie(void)
48802 {
48803- return atomic_inc_return(&fsnotify_sync_cookie);
48804+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
48805 }
48806 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
48807
48808diff -urNp linux-2.6.39.1/fs/ntfs/dir.c linux-2.6.39.1/fs/ntfs/dir.c
48809--- linux-2.6.39.1/fs/ntfs/dir.c 2011-05-19 00:06:34.000000000 -0400
48810+++ linux-2.6.39.1/fs/ntfs/dir.c 2011-05-22 19:36:32.000000000 -0400
48811@@ -1329,7 +1329,7 @@ find_next_index_buffer:
48812 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
48813 ~(s64)(ndir->itype.index.block_size - 1)));
48814 /* Bounds checks. */
48815- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48816+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48817 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
48818 "inode 0x%lx or driver bug.", vdir->i_ino);
48819 goto err_out;
48820diff -urNp linux-2.6.39.1/fs/ntfs/file.c linux-2.6.39.1/fs/ntfs/file.c
48821--- linux-2.6.39.1/fs/ntfs/file.c 2011-05-19 00:06:34.000000000 -0400
48822+++ linux-2.6.39.1/fs/ntfs/file.c 2011-05-22 19:36:32.000000000 -0400
48823@@ -2222,6 +2222,6 @@ const struct inode_operations ntfs_file_
48824 #endif /* NTFS_RW */
48825 };
48826
48827-const struct file_operations ntfs_empty_file_ops = {};
48828+const struct file_operations ntfs_empty_file_ops __read_only;
48829
48830-const struct inode_operations ntfs_empty_inode_ops = {};
48831+const struct inode_operations ntfs_empty_inode_ops __read_only;
48832diff -urNp linux-2.6.39.1/fs/ocfs2/cluster/heartbeat.c linux-2.6.39.1/fs/ocfs2/cluster/heartbeat.c
48833--- linux-2.6.39.1/fs/ocfs2/cluster/heartbeat.c 2011-05-19 00:06:34.000000000 -0400
48834+++ linux-2.6.39.1/fs/ocfs2/cluster/heartbeat.c 2011-05-22 19:36:32.000000000 -0400
48835@@ -2261,7 +2261,7 @@ static struct configfs_item_operations o
48836 .store_attribute = o2hb_heartbeat_group_store,
48837 };
48838
48839-static struct configfs_group_operations o2hb_heartbeat_group_group_ops = {
48840+static const struct configfs_group_operations o2hb_heartbeat_group_group_ops = {
48841 .make_item = o2hb_heartbeat_group_make_item,
48842 .drop_item = o2hb_heartbeat_group_drop_item,
48843 };
48844diff -urNp linux-2.6.39.1/fs/ocfs2/cluster/nodemanager.c linux-2.6.39.1/fs/ocfs2/cluster/nodemanager.c
48845--- linux-2.6.39.1/fs/ocfs2/cluster/nodemanager.c 2011-05-19 00:06:34.000000000 -0400
48846+++ linux-2.6.39.1/fs/ocfs2/cluster/nodemanager.c 2011-05-22 19:36:32.000000000 -0400
48847@@ -752,7 +752,7 @@ static void o2nm_node_group_drop_item(st
48848 config_item_put(item);
48849 }
48850
48851-static struct configfs_group_operations o2nm_node_group_group_ops = {
48852+static const struct configfs_group_operations o2nm_node_group_group_ops = {
48853 .make_item = o2nm_node_group_make_item,
48854 .drop_item = o2nm_node_group_drop_item,
48855 };
48856@@ -869,7 +869,7 @@ static void o2nm_cluster_group_drop_item
48857 config_item_put(item);
48858 }
48859
48860-static struct configfs_group_operations o2nm_cluster_group_group_ops = {
48861+static const struct configfs_group_operations o2nm_cluster_group_group_ops = {
48862 .make_group = o2nm_cluster_group_make_group,
48863 .drop_item = o2nm_cluster_group_drop_item,
48864 };
48865diff -urNp linux-2.6.39.1/fs/ocfs2/localalloc.c linux-2.6.39.1/fs/ocfs2/localalloc.c
48866--- linux-2.6.39.1/fs/ocfs2/localalloc.c 2011-05-19 00:06:34.000000000 -0400
48867+++ linux-2.6.39.1/fs/ocfs2/localalloc.c 2011-05-22 19:36:32.000000000 -0400
48868@@ -1283,7 +1283,7 @@ static int ocfs2_local_alloc_slide_windo
48869 goto bail;
48870 }
48871
48872- atomic_inc(&osb->alloc_stats.moves);
48873+ atomic_inc_unchecked(&osb->alloc_stats.moves);
48874
48875 bail:
48876 if (handle)
48877diff -urNp linux-2.6.39.1/fs/ocfs2/namei.c linux-2.6.39.1/fs/ocfs2/namei.c
48878--- linux-2.6.39.1/fs/ocfs2/namei.c 2011-05-19 00:06:34.000000000 -0400
48879+++ linux-2.6.39.1/fs/ocfs2/namei.c 2011-05-22 19:36:32.000000000 -0400
48880@@ -1063,6 +1063,8 @@ static int ocfs2_rename(struct inode *ol
48881 struct ocfs2_dir_lookup_result orphan_insert = { NULL, };
48882 struct ocfs2_dir_lookup_result target_insert = { NULL, };
48883
48884+ pax_track_stack();
48885+
48886 /* At some point it might be nice to break this function up a
48887 * bit. */
48888
48889diff -urNp linux-2.6.39.1/fs/ocfs2/ocfs2.h linux-2.6.39.1/fs/ocfs2/ocfs2.h
48890--- linux-2.6.39.1/fs/ocfs2/ocfs2.h 2011-05-19 00:06:34.000000000 -0400
48891+++ linux-2.6.39.1/fs/ocfs2/ocfs2.h 2011-05-22 19:36:32.000000000 -0400
48892@@ -235,11 +235,11 @@ enum ocfs2_vol_state
48893
48894 struct ocfs2_alloc_stats
48895 {
48896- atomic_t moves;
48897- atomic_t local_data;
48898- atomic_t bitmap_data;
48899- atomic_t bg_allocs;
48900- atomic_t bg_extends;
48901+ atomic_unchecked_t moves;
48902+ atomic_unchecked_t local_data;
48903+ atomic_unchecked_t bitmap_data;
48904+ atomic_unchecked_t bg_allocs;
48905+ atomic_unchecked_t bg_extends;
48906 };
48907
48908 enum ocfs2_local_alloc_state
48909diff -urNp linux-2.6.39.1/fs/ocfs2/stackglue.h linux-2.6.39.1/fs/ocfs2/stackglue.h
48910--- linux-2.6.39.1/fs/ocfs2/stackglue.h 2011-05-19 00:06:34.000000000 -0400
48911+++ linux-2.6.39.1/fs/ocfs2/stackglue.h 2011-05-22 19:36:32.000000000 -0400
48912@@ -221,13 +221,13 @@ struct ocfs2_stack_operations {
48913 };
48914
48915 /*
48916- * Each stack plugin must describe itself by registering a
48917+ * Each stack plugin must describe itself by registerin const g a
48918 * ocfs2_stack_plugin structure. This is only seen by stackglue and the
48919 * stack driver.
48920 */
48921 struct ocfs2_stack_plugin {
48922 char *sp_name;
48923- struct ocfs2_stack_operations *sp_ops;
48924+ const struct ocfs2_stack_operations *sp_ops;
48925 struct module *sp_owner;
48926
48927 /* These are managed by the stackglue code. */
48928diff -urNp linux-2.6.39.1/fs/ocfs2/stack_o2cb.c linux-2.6.39.1/fs/ocfs2/stack_o2cb.c
48929--- linux-2.6.39.1/fs/ocfs2/stack_o2cb.c 2011-05-19 00:06:34.000000000 -0400
48930+++ linux-2.6.39.1/fs/ocfs2/stack_o2cb.c 2011-06-07 18:07:24.000000000 -0400
48931@@ -358,7 +358,7 @@ static int o2cb_cluster_this_node(unsign
48932 return 0;
48933 }
48934
48935-static struct ocfs2_stack_operations o2cb_stack_ops = {
48936+static const struct ocfs2_stack_operations o2cb_stack_ops = {
48937 .connect = o2cb_cluster_connect,
48938 .disconnect = o2cb_cluster_disconnect,
48939 .this_node = o2cb_cluster_this_node,
48940diff -urNp linux-2.6.39.1/fs/ocfs2/stack_user.c linux-2.6.39.1/fs/ocfs2/stack_user.c
48941--- linux-2.6.39.1/fs/ocfs2/stack_user.c 2011-05-19 00:06:34.000000000 -0400
48942+++ linux-2.6.39.1/fs/ocfs2/stack_user.c 2011-05-22 19:36:32.000000000 -0400
48943@@ -399,7 +399,7 @@ static int ocfs2_control_do_setversion_m
48944 long major, minor;
48945 char *ptr = NULL;
48946 struct ocfs2_control_private *p = file->private_data;
48947- struct ocfs2_protocol_version *max =
48948+ const struct ocfs2_protocol_version *max =
48949 &ocfs2_user_plugin.sp_max_proto;
48950
48951 if (ocfs2_control_get_handshake_state(file) !=
48952@@ -861,7 +861,7 @@ static int user_cluster_this_node(unsign
48953 return 0;
48954 }
48955
48956-static struct ocfs2_stack_operations ocfs2_user_plugin_ops = {
48957+static const struct ocfs2_stack_operations ocfs2_user_plugin_ops = {
48958 .connect = user_cluster_connect,
48959 .disconnect = user_cluster_disconnect,
48960 .this_node = user_cluster_this_node,
48961diff -urNp linux-2.6.39.1/fs/ocfs2/suballoc.c linux-2.6.39.1/fs/ocfs2/suballoc.c
48962--- linux-2.6.39.1/fs/ocfs2/suballoc.c 2011-05-19 00:06:34.000000000 -0400
48963+++ linux-2.6.39.1/fs/ocfs2/suballoc.c 2011-05-22 19:36:32.000000000 -0400
48964@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(s
48965 mlog_errno(status);
48966 goto bail;
48967 }
48968- atomic_inc(&osb->alloc_stats.bg_extends);
48969+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
48970
48971 /* You should never ask for this much metadata */
48972 BUG_ON(bits_wanted >
48973@@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handl
48974 mlog_errno(status);
48975 goto bail;
48976 }
48977- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48978+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48979
48980 *suballoc_loc = res.sr_bg_blkno;
48981 *suballoc_bit_start = res.sr_bit_offset;
48982@@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_
48983 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
48984 res->sr_bits);
48985
48986- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48987+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48988
48989 BUG_ON(res->sr_bits != 1);
48990
48991@@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *hand
48992 mlog_errno(status);
48993 goto bail;
48994 }
48995- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48996+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48997
48998 BUG_ON(res.sr_bits != 1);
48999
49000@@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *han
49001 cluster_start,
49002 num_clusters);
49003 if (!status)
49004- atomic_inc(&osb->alloc_stats.local_data);
49005+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
49006 } else {
49007 if (min_clusters > (osb->bitmap_cpg - 1)) {
49008 /* The only paths asking for contiguousness
49009@@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *han
49010 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
49011 res.sr_bg_blkno,
49012 res.sr_bit_offset);
49013- atomic_inc(&osb->alloc_stats.bitmap_data);
49014+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
49015 *num_clusters = res.sr_bits;
49016 }
49017 }
49018diff -urNp linux-2.6.39.1/fs/ocfs2/super.c linux-2.6.39.1/fs/ocfs2/super.c
49019--- linux-2.6.39.1/fs/ocfs2/super.c 2011-05-19 00:06:34.000000000 -0400
49020+++ linux-2.6.39.1/fs/ocfs2/super.c 2011-05-22 19:36:32.000000000 -0400
49021@@ -299,11 +299,11 @@ static int ocfs2_osb_dump(struct ocfs2_s
49022 "%10s => GlobalAllocs: %d LocalAllocs: %d "
49023 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
49024 "Stats",
49025- atomic_read(&osb->alloc_stats.bitmap_data),
49026- atomic_read(&osb->alloc_stats.local_data),
49027- atomic_read(&osb->alloc_stats.bg_allocs),
49028- atomic_read(&osb->alloc_stats.moves),
49029- atomic_read(&osb->alloc_stats.bg_extends));
49030+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
49031+ atomic_read_unchecked(&osb->alloc_stats.local_data),
49032+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
49033+ atomic_read_unchecked(&osb->alloc_stats.moves),
49034+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
49035
49036 out += snprintf(buf + out, len - out,
49037 "%10s => State: %u Descriptor: %llu Size: %u bits "
49038@@ -2111,11 +2111,11 @@ static int ocfs2_initialize_super(struct
49039 spin_lock_init(&osb->osb_xattr_lock);
49040 ocfs2_init_steal_slots(osb);
49041
49042- atomic_set(&osb->alloc_stats.moves, 0);
49043- atomic_set(&osb->alloc_stats.local_data, 0);
49044- atomic_set(&osb->alloc_stats.bitmap_data, 0);
49045- atomic_set(&osb->alloc_stats.bg_allocs, 0);
49046- atomic_set(&osb->alloc_stats.bg_extends, 0);
49047+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
49048+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
49049+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
49050+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
49051+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
49052
49053 /* Copy the blockcheck stats from the superblock probe */
49054 osb->osb_ecc_stats = *stats;
49055diff -urNp linux-2.6.39.1/fs/ocfs2/symlink.c linux-2.6.39.1/fs/ocfs2/symlink.c
49056--- linux-2.6.39.1/fs/ocfs2/symlink.c 2011-05-19 00:06:34.000000000 -0400
49057+++ linux-2.6.39.1/fs/ocfs2/symlink.c 2011-05-22 19:36:32.000000000 -0400
49058@@ -142,7 +142,7 @@ bail:
49059
49060 static void ocfs2_fast_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
49061 {
49062- char *link = nd_get_link(nd);
49063+ const char *link = nd_get_link(nd);
49064 if (!IS_ERR(link))
49065 kfree(link);
49066 }
49067diff -urNp linux-2.6.39.1/fs/open.c linux-2.6.39.1/fs/open.c
49068--- linux-2.6.39.1/fs/open.c 2011-05-19 00:06:34.000000000 -0400
49069+++ linux-2.6.39.1/fs/open.c 2011-05-22 20:46:51.000000000 -0400
49070@@ -112,6 +112,10 @@ static long do_sys_truncate(const char _
49071 error = locks_verify_truncate(inode, NULL, length);
49072 if (!error)
49073 error = security_path_truncate(&path);
49074+
49075+ if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
49076+ error = -EACCES;
49077+
49078 if (!error)
49079 error = do_truncate(path.dentry, length, 0, NULL);
49080
49081@@ -358,6 +362,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, con
49082 if (__mnt_is_readonly(path.mnt))
49083 res = -EROFS;
49084
49085+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
49086+ res = -EACCES;
49087+
49088 out_path_release:
49089 path_put(&path);
49090 out:
49091@@ -384,6 +391,8 @@ SYSCALL_DEFINE1(chdir, const char __user
49092 if (error)
49093 goto dput_and_out;
49094
49095+ gr_log_chdir(path.dentry, path.mnt);
49096+
49097 set_fs_pwd(current->fs, &path);
49098
49099 dput_and_out:
49100@@ -410,6 +419,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd
49101 goto out_putf;
49102
49103 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
49104+
49105+ if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
49106+ error = -EPERM;
49107+
49108+ if (!error)
49109+ gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
49110+
49111 if (!error)
49112 set_fs_pwd(current->fs, &file->f_path);
49113 out_putf:
49114@@ -438,7 +454,18 @@ SYSCALL_DEFINE1(chroot, const char __use
49115 if (error)
49116 goto dput_and_out;
49117
49118+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
49119+ goto dput_and_out;
49120+
49121+ if (gr_handle_chroot_caps(&path)) {
49122+ error = -ENOMEM;
49123+ goto dput_and_out;
49124+ }
49125+
49126 set_fs_root(current->fs, &path);
49127+
49128+ gr_handle_chroot_chdir(&path);
49129+
49130 error = 0;
49131 dput_and_out:
49132 path_put(&path);
49133@@ -466,12 +493,25 @@ SYSCALL_DEFINE2(fchmod, unsigned int, fd
49134 err = mnt_want_write_file(file);
49135 if (err)
49136 goto out_putf;
49137+
49138 mutex_lock(&inode->i_mutex);
49139+
49140+ if (!gr_acl_handle_fchmod(dentry, file->f_vfsmnt, mode)) {
49141+ err = -EACCES;
49142+ goto out_unlock;
49143+ }
49144+
49145 err = security_path_chmod(dentry, file->f_vfsmnt, mode);
49146 if (err)
49147 goto out_unlock;
49148 if (mode == (mode_t) -1)
49149 mode = inode->i_mode;
49150+
49151+ if (gr_handle_chroot_chmod(dentry, file->f_vfsmnt, mode)) {
49152+ err = -EACCES;
49153+ goto out_unlock;
49154+ }
49155+
49156 newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
49157 newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
49158 err = notify_change(dentry, &newattrs);
49159@@ -499,12 +539,25 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
49160 error = mnt_want_write(path.mnt);
49161 if (error)
49162 goto dput_and_out;
49163+
49164 mutex_lock(&inode->i_mutex);
49165+
49166+ if (!gr_acl_handle_chmod(path.dentry, path.mnt, mode)) {
49167+ error = -EACCES;
49168+ goto out_unlock;
49169+ }
49170+
49171 error = security_path_chmod(path.dentry, path.mnt, mode);
49172 if (error)
49173 goto out_unlock;
49174 if (mode == (mode_t) -1)
49175 mode = inode->i_mode;
49176+
49177+ if (gr_handle_chroot_chmod(path.dentry, path.mnt, mode)) {
49178+ error = -EACCES;
49179+ goto out_unlock;
49180+ }
49181+
49182 newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
49183 newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
49184 error = notify_change(path.dentry, &newattrs);
49185@@ -528,6 +581,9 @@ static int chown_common(struct path *pat
49186 int error;
49187 struct iattr newattrs;
49188
49189+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
49190+ return -EACCES;
49191+
49192 newattrs.ia_valid = ATTR_CTIME;
49193 if (user != (uid_t) -1) {
49194 newattrs.ia_valid |= ATTR_UID;
49195@@ -998,7 +1054,10 @@ long do_sys_open(int dfd, const char __u
49196 if (!IS_ERR(tmp)) {
49197 fd = get_unused_fd_flags(flags);
49198 if (fd >= 0) {
49199- struct file *f = do_filp_open(dfd, tmp, &op, lookup);
49200+ struct file *f;
49201+ /* don't allow to be set by userland */
49202+ flags &= ~FMODE_GREXEC;
49203+ f = do_filp_open(dfd, tmp, &op, lookup);
49204 if (IS_ERR(f)) {
49205 put_unused_fd(fd);
49206 fd = PTR_ERR(f);
49207diff -urNp linux-2.6.39.1/fs/partitions/ldm.c linux-2.6.39.1/fs/partitions/ldm.c
49208--- linux-2.6.39.1/fs/partitions/ldm.c 2011-06-03 00:04:14.000000000 -0400
49209+++ linux-2.6.39.1/fs/partitions/ldm.c 2011-06-03 00:32:07.000000000 -0400
49210@@ -1311,6 +1311,7 @@ static bool ldm_frag_add (const u8 *data
49211 ldm_error ("A VBLK claims to have %d parts.", num);
49212 return false;
49213 }
49214+
49215 if (rec >= num) {
49216 ldm_error("REC value (%d) exceeds NUM value (%d)", rec, num);
49217 return false;
49218@@ -1322,7 +1323,7 @@ static bool ldm_frag_add (const u8 *data
49219 goto found;
49220 }
49221
49222- f = kmalloc (sizeof (*f) + size*num, GFP_KERNEL);
49223+ f = kmalloc (size*num + sizeof (*f), GFP_KERNEL);
49224 if (!f) {
49225 ldm_crit ("Out of memory.");
49226 return false;
49227diff -urNp linux-2.6.39.1/fs/pipe.c linux-2.6.39.1/fs/pipe.c
49228--- linux-2.6.39.1/fs/pipe.c 2011-05-19 00:06:34.000000000 -0400
49229+++ linux-2.6.39.1/fs/pipe.c 2011-05-22 19:41:37.000000000 -0400
49230@@ -420,9 +420,9 @@ redo:
49231 }
49232 if (bufs) /* More to do? */
49233 continue;
49234- if (!pipe->writers)
49235+ if (!atomic_read(&pipe->writers))
49236 break;
49237- if (!pipe->waiting_writers) {
49238+ if (!atomic_read(&pipe->waiting_writers)) {
49239 /* syscall merging: Usually we must not sleep
49240 * if O_NONBLOCK is set, or if we got some data.
49241 * But if a writer sleeps in kernel space, then
49242@@ -481,7 +481,7 @@ pipe_write(struct kiocb *iocb, const str
49243 mutex_lock(&inode->i_mutex);
49244 pipe = inode->i_pipe;
49245
49246- if (!pipe->readers) {
49247+ if (!atomic_read(&pipe->readers)) {
49248 send_sig(SIGPIPE, current, 0);
49249 ret = -EPIPE;
49250 goto out;
49251@@ -530,7 +530,7 @@ redo1:
49252 for (;;) {
49253 int bufs;
49254
49255- if (!pipe->readers) {
49256+ if (!atomic_read(&pipe->readers)) {
49257 send_sig(SIGPIPE, current, 0);
49258 if (!ret)
49259 ret = -EPIPE;
49260@@ -616,9 +616,9 @@ redo2:
49261 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
49262 do_wakeup = 0;
49263 }
49264- pipe->waiting_writers++;
49265+ atomic_inc(&pipe->waiting_writers);
49266 pipe_wait(pipe);
49267- pipe->waiting_writers--;
49268+ atomic_dec(&pipe->waiting_writers);
49269 }
49270 out:
49271 mutex_unlock(&inode->i_mutex);
49272@@ -685,7 +685,7 @@ pipe_poll(struct file *filp, poll_table
49273 mask = 0;
49274 if (filp->f_mode & FMODE_READ) {
49275 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
49276- if (!pipe->writers && filp->f_version != pipe->w_counter)
49277+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
49278 mask |= POLLHUP;
49279 }
49280
49281@@ -695,7 +695,7 @@ pipe_poll(struct file *filp, poll_table
49282 * Most Unices do not set POLLERR for FIFOs but on Linux they
49283 * behave exactly like pipes for poll().
49284 */
49285- if (!pipe->readers)
49286+ if (!atomic_read(&pipe->readers))
49287 mask |= POLLERR;
49288 }
49289
49290@@ -709,10 +709,10 @@ pipe_release(struct inode *inode, int de
49291
49292 mutex_lock(&inode->i_mutex);
49293 pipe = inode->i_pipe;
49294- pipe->readers -= decr;
49295- pipe->writers -= decw;
49296+ atomic_sub(decr, &pipe->readers);
49297+ atomic_sub(decw, &pipe->writers);
49298
49299- if (!pipe->readers && !pipe->writers) {
49300+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
49301 free_pipe_info(inode);
49302 } else {
49303 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
49304@@ -802,7 +802,7 @@ pipe_read_open(struct inode *inode, stru
49305
49306 if (inode->i_pipe) {
49307 ret = 0;
49308- inode->i_pipe->readers++;
49309+ atomic_inc(&inode->i_pipe->readers);
49310 }
49311
49312 mutex_unlock(&inode->i_mutex);
49313@@ -819,7 +819,7 @@ pipe_write_open(struct inode *inode, str
49314
49315 if (inode->i_pipe) {
49316 ret = 0;
49317- inode->i_pipe->writers++;
49318+ atomic_inc(&inode->i_pipe->writers);
49319 }
49320
49321 mutex_unlock(&inode->i_mutex);
49322@@ -837,9 +837,9 @@ pipe_rdwr_open(struct inode *inode, stru
49323 if (inode->i_pipe) {
49324 ret = 0;
49325 if (filp->f_mode & FMODE_READ)
49326- inode->i_pipe->readers++;
49327+ atomic_inc(&inode->i_pipe->readers);
49328 if (filp->f_mode & FMODE_WRITE)
49329- inode->i_pipe->writers++;
49330+ atomic_inc(&inode->i_pipe->writers);
49331 }
49332
49333 mutex_unlock(&inode->i_mutex);
49334@@ -931,7 +931,7 @@ void free_pipe_info(struct inode *inode)
49335 inode->i_pipe = NULL;
49336 }
49337
49338-static struct vfsmount *pipe_mnt __read_mostly;
49339+struct vfsmount *pipe_mnt __read_mostly;
49340
49341 /*
49342 * pipefs_dname() is called from d_path().
49343@@ -961,7 +961,8 @@ static struct inode * get_pipe_inode(voi
49344 goto fail_iput;
49345 inode->i_pipe = pipe;
49346
49347- pipe->readers = pipe->writers = 1;
49348+ atomic_set(&pipe->readers, 1);
49349+ atomic_set(&pipe->writers, 1);
49350 inode->i_fop = &rdwr_pipefifo_fops;
49351
49352 /*
49353diff -urNp linux-2.6.39.1/fs/proc/array.c linux-2.6.39.1/fs/proc/array.c
49354--- linux-2.6.39.1/fs/proc/array.c 2011-05-19 00:06:34.000000000 -0400
49355+++ linux-2.6.39.1/fs/proc/array.c 2011-05-22 19:41:37.000000000 -0400
49356@@ -60,6 +60,7 @@
49357 #include <linux/tty.h>
49358 #include <linux/string.h>
49359 #include <linux/mman.h>
49360+#include <linux/grsecurity.h>
49361 #include <linux/proc_fs.h>
49362 #include <linux/ioport.h>
49363 #include <linux/uaccess.h>
49364@@ -337,6 +338,21 @@ static void task_cpus_allowed(struct seq
49365 seq_putc(m, '\n');
49366 }
49367
49368+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
49369+static inline void task_pax(struct seq_file *m, struct task_struct *p)
49370+{
49371+ if (p->mm)
49372+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
49373+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
49374+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
49375+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
49376+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
49377+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
49378+ else
49379+ seq_printf(m, "PaX:\t-----\n");
49380+}
49381+#endif
49382+
49383 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
49384 struct pid *pid, struct task_struct *task)
49385 {
49386@@ -354,9 +370,24 @@ int proc_pid_status(struct seq_file *m,
49387 task_cpus_allowed(m, task);
49388 cpuset_task_status_allowed(m, task);
49389 task_context_switch_counts(m, task);
49390+
49391+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
49392+ task_pax(m, task);
49393+#endif
49394+
49395+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
49396+ task_grsec_rbac(m, task);
49397+#endif
49398+
49399 return 0;
49400 }
49401
49402+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49403+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49404+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
49405+ _mm->pax_flags & MF_PAX_SEGMEXEC))
49406+#endif
49407+
49408 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
49409 struct pid *pid, struct task_struct *task, int whole)
49410 {
49411@@ -375,9 +406,11 @@ static int do_task_stat(struct seq_file
49412 cputime_t cutime, cstime, utime, stime;
49413 cputime_t cgtime, gtime;
49414 unsigned long rsslim = 0;
49415- char tcomm[sizeof(task->comm)];
49416+ char tcomm[sizeof(task->comm)] = { 0 };
49417 unsigned long flags;
49418
49419+ pax_track_stack();
49420+
49421 state = *get_task_state(task);
49422 vsize = eip = esp = 0;
49423 permitted = ptrace_may_access(task, PTRACE_MODE_READ);
49424@@ -449,6 +482,19 @@ static int do_task_stat(struct seq_file
49425 gtime = task->gtime;
49426 }
49427
49428+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49429+ if (PAX_RAND_FLAGS(mm)) {
49430+ eip = 0;
49431+ esp = 0;
49432+ wchan = 0;
49433+ }
49434+#endif
49435+#ifdef CONFIG_GRKERNSEC_HIDESYM
49436+ wchan = 0;
49437+ eip =0;
49438+ esp =0;
49439+#endif
49440+
49441 /* scale priority and nice values from timeslices to -20..20 */
49442 /* to make it look like a "normal" Unix priority/nice value */
49443 priority = task_prio(task);
49444@@ -489,9 +535,15 @@ static int do_task_stat(struct seq_file
49445 vsize,
49446 mm ? get_mm_rss(mm) : 0,
49447 rsslim,
49448+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49449+ PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0),
49450+ PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0),
49451+ PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0),
49452+#else
49453 mm ? (permitted ? mm->start_code : 1) : 0,
49454 mm ? (permitted ? mm->end_code : 1) : 0,
49455 (permitted && mm) ? mm->start_stack : 0,
49456+#endif
49457 esp,
49458 eip,
49459 /* The signal information here is obsolete.
49460@@ -544,3 +596,18 @@ int proc_pid_statm(struct seq_file *m, s
49461
49462 return 0;
49463 }
49464+
49465+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49466+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
49467+{
49468+ u32 curr_ip = 0;
49469+ unsigned long flags;
49470+
49471+ if (lock_task_sighand(task, &flags)) {
49472+ curr_ip = task->signal->curr_ip;
49473+ unlock_task_sighand(task, &flags);
49474+ }
49475+
49476+ return sprintf(buffer, "%pI4\n", &curr_ip);
49477+}
49478+#endif
49479diff -urNp linux-2.6.39.1/fs/proc/base.c linux-2.6.39.1/fs/proc/base.c
49480--- linux-2.6.39.1/fs/proc/base.c 2011-05-19 00:06:34.000000000 -0400
49481+++ linux-2.6.39.1/fs/proc/base.c 2011-06-04 21:20:04.000000000 -0400
49482@@ -104,6 +104,22 @@ struct pid_entry {
49483 union proc_op op;
49484 };
49485
49486+struct getdents_callback {
49487+ struct linux_dirent __user * current_dir;
49488+ struct linux_dirent __user * previous;
49489+ struct file * file;
49490+ int count;
49491+ int error;
49492+};
49493+
49494+static int gr_fake_filldir(void * __buf, const char *name, int namlen,
49495+ loff_t offset, u64 ino, unsigned int d_type)
49496+{
49497+ struct getdents_callback * buf = (struct getdents_callback *) __buf;
49498+ buf->error = -EINVAL;
49499+ return 0;
49500+}
49501+
49502 #define NOD(NAME, MODE, IOP, FOP, OP) { \
49503 .name = (NAME), \
49504 .len = sizeof(NAME) - 1, \
49505@@ -206,6 +222,9 @@ static struct mm_struct *__check_mem_per
49506 if (task == current)
49507 return mm;
49508
49509+ if (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))
49510+ return ERR_PTR(-EPERM);
49511+
49512 /*
49513 * If current is actively ptrace'ing, and would also be
49514 * permitted to freshly attach with ptrace now, permit it.
49515@@ -279,6 +298,9 @@ static int proc_pid_cmdline(struct task_
49516 if (!mm->arg_end)
49517 goto out_mm; /* Shh! No looking before we're done */
49518
49519+ if (gr_acl_handle_procpidmem(task))
49520+ goto out_mm;
49521+
49522 len = mm->arg_end - mm->arg_start;
49523
49524 if (len > PAGE_SIZE)
49525@@ -306,12 +328,28 @@ out:
49526 return res;
49527 }
49528
49529+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49530+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49531+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
49532+ _mm->pax_flags & MF_PAX_SEGMEXEC))
49533+#endif
49534+
49535 static int proc_pid_auxv(struct task_struct *task, char *buffer)
49536 {
49537 struct mm_struct *mm = mm_for_maps(task);
49538 int res = PTR_ERR(mm);
49539 if (mm && !IS_ERR(mm)) {
49540 unsigned int nwords = 0;
49541+
49542+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49543+ /* allow if we're currently ptracing this task */
49544+ if (PAX_RAND_FLAGS(mm) &&
49545+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
49546+ mmput(mm);
49547+ return res;
49548+ }
49549+#endif
49550+
49551 do {
49552 nwords += 2;
49553 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
49554@@ -325,7 +363,7 @@ static int proc_pid_auxv(struct task_str
49555 }
49556
49557
49558-#ifdef CONFIG_KALLSYMS
49559+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49560 /*
49561 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
49562 * Returns the resolved symbol. If that fails, simply return the address.
49563@@ -364,7 +402,7 @@ static void unlock_trace(struct task_str
49564 mutex_unlock(&task->signal->cred_guard_mutex);
49565 }
49566
49567-#ifdef CONFIG_STACKTRACE
49568+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49569
49570 #define MAX_STACK_TRACE_DEPTH 64
49571
49572@@ -555,7 +593,7 @@ static int proc_pid_limits(struct task_s
49573 return count;
49574 }
49575
49576-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49577+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49578 static int proc_pid_syscall(struct task_struct *task, char *buffer)
49579 {
49580 long nr;
49581@@ -584,7 +622,7 @@ static int proc_pid_syscall(struct task_
49582 /************************************************************************/
49583
49584 /* permission checks */
49585-static int proc_fd_access_allowed(struct inode *inode)
49586+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
49587 {
49588 struct task_struct *task;
49589 int allowed = 0;
49590@@ -594,7 +632,10 @@ static int proc_fd_access_allowed(struct
49591 */
49592 task = get_proc_task(inode);
49593 if (task) {
49594- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
49595+ if (log)
49596+ allowed = ptrace_may_access_log(task, PTRACE_MODE_READ);
49597+ else
49598+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
49599 put_task_struct(task);
49600 }
49601 return allowed;
49602@@ -973,6 +1014,9 @@ static ssize_t environ_read(struct file
49603 if (!task)
49604 goto out_no_task;
49605
49606+ if (gr_acl_handle_procpidmem(task))
49607+ goto out;
49608+
49609 ret = -ENOMEM;
49610 page = (char *)__get_free_page(GFP_TEMPORARY);
49611 if (!page)
49612@@ -1660,7 +1704,7 @@ static void *proc_pid_follow_link(struct
49613 path_put(&nd->path);
49614
49615 /* Are we allowed to snoop on the tasks file descriptors? */
49616- if (!proc_fd_access_allowed(inode))
49617+ if (!proc_fd_access_allowed(inode,0))
49618 goto out;
49619
49620 error = PROC_I(inode)->op.proc_get_link(inode, &nd->path);
49621@@ -1699,8 +1743,18 @@ static int proc_pid_readlink(struct dent
49622 struct path path;
49623
49624 /* Are we allowed to snoop on the tasks file descriptors? */
49625- if (!proc_fd_access_allowed(inode))
49626- goto out;
49627+ /* logging this is needed for learning on chromium to work properly,
49628+ but we don't want to flood the logs from 'ps' which does a readlink
49629+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
49630+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
49631+ */
49632+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
49633+ if (!proc_fd_access_allowed(inode,0))
49634+ goto out;
49635+ } else {
49636+ if (!proc_fd_access_allowed(inode,1))
49637+ goto out;
49638+ }
49639
49640 error = PROC_I(inode)->op.proc_get_link(inode, &path);
49641 if (error)
49642@@ -1766,7 +1820,11 @@ static struct inode *proc_pid_make_inode
49643 rcu_read_lock();
49644 cred = __task_cred(task);
49645 inode->i_uid = cred->euid;
49646+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49647+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
49648+#else
49649 inode->i_gid = cred->egid;
49650+#endif
49651 rcu_read_unlock();
49652 }
49653 security_task_to_inode(task, inode);
49654@@ -1784,6 +1842,9 @@ static int pid_getattr(struct vfsmount *
49655 struct inode *inode = dentry->d_inode;
49656 struct task_struct *task;
49657 const struct cred *cred;
49658+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49659+ const struct cred *tmpcred = current_cred();
49660+#endif
49661
49662 generic_fillattr(inode, stat);
49663
49664@@ -1791,13 +1852,41 @@ static int pid_getattr(struct vfsmount *
49665 stat->uid = 0;
49666 stat->gid = 0;
49667 task = pid_task(proc_pid(inode), PIDTYPE_PID);
49668+
49669+ if (task && (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))) {
49670+ rcu_read_unlock();
49671+ return -ENOENT;
49672+ }
49673+
49674 if (task) {
49675+ cred = __task_cred(task);
49676+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49677+ if (!tmpcred->uid || (tmpcred->uid == cred->uid)
49678+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49679+ || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
49680+#endif
49681+ ) {
49682+#endif
49683 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49684+#ifdef CONFIG_GRKERNSEC_PROC_USER
49685+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49686+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49687+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49688+#endif
49689 task_dumpable(task)) {
49690- cred = __task_cred(task);
49691 stat->uid = cred->euid;
49692+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49693+ stat->gid = CONFIG_GRKERNSEC_PROC_GID;
49694+#else
49695 stat->gid = cred->egid;
49696+#endif
49697 }
49698+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49699+ } else {
49700+ rcu_read_unlock();
49701+ return -ENOENT;
49702+ }
49703+#endif
49704 }
49705 rcu_read_unlock();
49706 return 0;
49707@@ -1834,11 +1923,20 @@ static int pid_revalidate(struct dentry
49708
49709 if (task) {
49710 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49711+#ifdef CONFIG_GRKERNSEC_PROC_USER
49712+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49713+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49714+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49715+#endif
49716 task_dumpable(task)) {
49717 rcu_read_lock();
49718 cred = __task_cred(task);
49719 inode->i_uid = cred->euid;
49720+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49721+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
49722+#else
49723 inode->i_gid = cred->egid;
49724+#endif
49725 rcu_read_unlock();
49726 } else {
49727 inode->i_uid = 0;
49728@@ -1959,7 +2057,8 @@ static int proc_fd_info(struct inode *in
49729 int fd = proc_fd(inode);
49730
49731 if (task) {
49732- files = get_files_struct(task);
49733+ if (!gr_acl_handle_procpidmem(task))
49734+ files = get_files_struct(task);
49735 put_task_struct(task);
49736 }
49737 if (files) {
49738@@ -2219,15 +2318,25 @@ static const struct file_operations proc
49739 */
49740 static int proc_fd_permission(struct inode *inode, int mask, unsigned int flags)
49741 {
49742+ struct task_struct *task;
49743 int rv;
49744
49745 if (flags & IPERM_FLAG_RCU)
49746 return -ECHILD;
49747 rv = generic_permission(inode, mask, flags, NULL);
49748- if (rv == 0)
49749- return 0;
49750+
49751 if (task_pid(current) == proc_pid(inode))
49752 rv = 0;
49753+
49754+ task = get_proc_task(inode);
49755+ if (task == NULL)
49756+ return rv;
49757+
49758+ if (gr_acl_handle_procpidmem(task))
49759+ rv = -EACCES;
49760+
49761+ put_task_struct(task);
49762+
49763 return rv;
49764 }
49765
49766@@ -2337,6 +2446,9 @@ static struct dentry *proc_pident_lookup
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 /*
49774 * Yes, it does not scale. And it should not. Don't add
49775 * new entries into /proc/<tgid>/ without very good reasons.
49776@@ -2381,6 +2493,9 @@ static int proc_pident_readdir(struct fi
49777 if (!task)
49778 goto out_no_task;
49779
49780+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49781+ goto out;
49782+
49783 ret = 0;
49784 i = filp->f_pos;
49785 switch (i) {
49786@@ -2651,7 +2766,7 @@ static void *proc_self_follow_link(struc
49787 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
49788 void *cookie)
49789 {
49790- char *s = nd_get_link(nd);
49791+ const char *s = nd_get_link(nd);
49792 if (!IS_ERR(s))
49793 __putname(s);
49794 }
49795@@ -2835,7 +2950,7 @@ static const struct pid_entry tgid_base_
49796 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
49797 #endif
49798 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49799-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49800+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49801 INF("syscall", S_IRUGO, proc_pid_syscall),
49802 #endif
49803 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49804@@ -2860,10 +2975,10 @@ static const struct pid_entry tgid_base_
49805 #ifdef CONFIG_SECURITY
49806 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49807 #endif
49808-#ifdef CONFIG_KALLSYMS
49809+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49810 INF("wchan", S_IRUGO, proc_pid_wchan),
49811 #endif
49812-#ifdef CONFIG_STACKTRACE
49813+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49814 ONE("stack", S_IRUGO, proc_pid_stack),
49815 #endif
49816 #ifdef CONFIG_SCHEDSTATS
49817@@ -2894,6 +3009,9 @@ static const struct pid_entry tgid_base_
49818 #ifdef CONFIG_TASK_IO_ACCOUNTING
49819 INF("io", S_IRUGO, proc_tgid_io_accounting),
49820 #endif
49821+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49822+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
49823+#endif
49824 };
49825
49826 static int proc_tgid_base_readdir(struct file * filp,
49827@@ -3019,7 +3137,14 @@ static struct dentry *proc_pid_instantia
49828 if (!inode)
49829 goto out;
49830
49831+#ifdef CONFIG_GRKERNSEC_PROC_USER
49832+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
49833+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49834+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
49835+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
49836+#else
49837 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
49838+#endif
49839 inode->i_op = &proc_tgid_base_inode_operations;
49840 inode->i_fop = &proc_tgid_base_operations;
49841 inode->i_flags|=S_IMMUTABLE;
49842@@ -3061,7 +3186,11 @@ struct dentry *proc_pid_lookup(struct in
49843 if (!task)
49844 goto out;
49845
49846+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49847+ goto out_put_task;
49848+
49849 result = proc_pid_instantiate(dir, dentry, task, NULL);
49850+out_put_task:
49851 put_task_struct(task);
49852 out:
49853 return result;
49854@@ -3126,6 +3255,11 @@ int proc_pid_readdir(struct file * filp,
49855 {
49856 unsigned int nr;
49857 struct task_struct *reaper;
49858+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49859+ const struct cred *tmpcred = current_cred();
49860+ const struct cred *itercred;
49861+#endif
49862+ filldir_t __filldir = filldir;
49863 struct tgid_iter iter;
49864 struct pid_namespace *ns;
49865
49866@@ -3149,8 +3283,27 @@ int proc_pid_readdir(struct file * filp,
49867 for (iter = next_tgid(ns, iter);
49868 iter.task;
49869 iter.tgid += 1, iter = next_tgid(ns, iter)) {
49870+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49871+ rcu_read_lock();
49872+ itercred = __task_cred(iter.task);
49873+#endif
49874+ if (gr_pid_is_chrooted(iter.task) || gr_check_hidden_task(iter.task)
49875+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49876+ || (tmpcred->uid && (itercred->uid != tmpcred->uid)
49877+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49878+ && !in_group_p(CONFIG_GRKERNSEC_PROC_GID)
49879+#endif
49880+ )
49881+#endif
49882+ )
49883+ __filldir = &gr_fake_filldir;
49884+ else
49885+ __filldir = filldir;
49886+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49887+ rcu_read_unlock();
49888+#endif
49889 filp->f_pos = iter.tgid + TGID_OFFSET;
49890- if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
49891+ if (proc_pid_fill_cache(filp, dirent, __filldir, iter) < 0) {
49892 put_task_struct(iter.task);
49893 goto out;
49894 }
49895@@ -3177,7 +3330,7 @@ static const struct pid_entry tid_base_s
49896 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
49897 #endif
49898 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49899-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49900+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49901 INF("syscall", S_IRUGO, proc_pid_syscall),
49902 #endif
49903 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49904@@ -3201,10 +3354,10 @@ static const struct pid_entry tid_base_s
49905 #ifdef CONFIG_SECURITY
49906 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49907 #endif
49908-#ifdef CONFIG_KALLSYMS
49909+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49910 INF("wchan", S_IRUGO, proc_pid_wchan),
49911 #endif
49912-#ifdef CONFIG_STACKTRACE
49913+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49914 ONE("stack", S_IRUGO, proc_pid_stack),
49915 #endif
49916 #ifdef CONFIG_SCHEDSTATS
49917diff -urNp linux-2.6.39.1/fs/proc/cmdline.c linux-2.6.39.1/fs/proc/cmdline.c
49918--- linux-2.6.39.1/fs/proc/cmdline.c 2011-05-19 00:06:34.000000000 -0400
49919+++ linux-2.6.39.1/fs/proc/cmdline.c 2011-05-22 19:41:37.000000000 -0400
49920@@ -23,7 +23,11 @@ static const struct file_operations cmdl
49921
49922 static int __init proc_cmdline_init(void)
49923 {
49924+#ifdef CONFIG_GRKERNSEC_PROC_ADD
49925+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
49926+#else
49927 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
49928+#endif
49929 return 0;
49930 }
49931 module_init(proc_cmdline_init);
49932diff -urNp linux-2.6.39.1/fs/proc/devices.c linux-2.6.39.1/fs/proc/devices.c
49933--- linux-2.6.39.1/fs/proc/devices.c 2011-05-19 00:06:34.000000000 -0400
49934+++ linux-2.6.39.1/fs/proc/devices.c 2011-05-22 19:41:37.000000000 -0400
49935@@ -64,7 +64,11 @@ static const struct file_operations proc
49936
49937 static int __init proc_devices_init(void)
49938 {
49939+#ifdef CONFIG_GRKERNSEC_PROC_ADD
49940+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
49941+#else
49942 proc_create("devices", 0, NULL, &proc_devinfo_operations);
49943+#endif
49944 return 0;
49945 }
49946 module_init(proc_devices_init);
49947diff -urNp linux-2.6.39.1/fs/proc/inode.c linux-2.6.39.1/fs/proc/inode.c
49948--- linux-2.6.39.1/fs/proc/inode.c 2011-05-19 00:06:34.000000000 -0400
49949+++ linux-2.6.39.1/fs/proc/inode.c 2011-05-22 19:41:37.000000000 -0400
49950@@ -433,7 +433,11 @@ struct inode *proc_get_inode(struct supe
49951 if (de->mode) {
49952 inode->i_mode = de->mode;
49953 inode->i_uid = de->uid;
49954+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49955+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
49956+#else
49957 inode->i_gid = de->gid;
49958+#endif
49959 }
49960 if (de->size)
49961 inode->i_size = de->size;
49962diff -urNp linux-2.6.39.1/fs/proc/internal.h linux-2.6.39.1/fs/proc/internal.h
49963--- linux-2.6.39.1/fs/proc/internal.h 2011-05-19 00:06:34.000000000 -0400
49964+++ linux-2.6.39.1/fs/proc/internal.h 2011-05-22 19:41:37.000000000 -0400
49965@@ -51,6 +51,9 @@ extern int proc_pid_status(struct seq_fi
49966 struct pid *pid, struct task_struct *task);
49967 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
49968 struct pid *pid, struct task_struct *task);
49969+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49970+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
49971+#endif
49972 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
49973
49974 extern const struct file_operations proc_maps_operations;
49975diff -urNp linux-2.6.39.1/fs/proc/Kconfig linux-2.6.39.1/fs/proc/Kconfig
49976--- linux-2.6.39.1/fs/proc/Kconfig 2011-05-19 00:06:34.000000000 -0400
49977+++ linux-2.6.39.1/fs/proc/Kconfig 2011-05-22 19:41:37.000000000 -0400
49978@@ -30,12 +30,12 @@ config PROC_FS
49979
49980 config PROC_KCORE
49981 bool "/proc/kcore support" if !ARM
49982- depends on PROC_FS && MMU
49983+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
49984
49985 config PROC_VMCORE
49986 bool "/proc/vmcore support"
49987- depends on PROC_FS && CRASH_DUMP
49988- default y
49989+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
49990+ default n
49991 help
49992 Exports the dump image of crashed kernel in ELF format.
49993
49994@@ -59,8 +59,8 @@ config PROC_SYSCTL
49995 limited in memory.
49996
49997 config PROC_PAGE_MONITOR
49998- default y
49999- depends on PROC_FS && MMU
50000+ default n
50001+ depends on PROC_FS && MMU && !GRKERNSEC
50002 bool "Enable /proc page monitoring" if EXPERT
50003 help
50004 Various /proc files exist to monitor process memory utilization:
50005diff -urNp linux-2.6.39.1/fs/proc/kcore.c linux-2.6.39.1/fs/proc/kcore.c
50006--- linux-2.6.39.1/fs/proc/kcore.c 2011-05-19 00:06:34.000000000 -0400
50007+++ linux-2.6.39.1/fs/proc/kcore.c 2011-05-22 19:41:37.000000000 -0400
50008@@ -321,6 +321,8 @@ static void elf_kcore_store_hdr(char *bu
50009 off_t offset = 0;
50010 struct kcore_list *m;
50011
50012+ pax_track_stack();
50013+
50014 /* setup ELF header */
50015 elf = (struct elfhdr *) bufp;
50016 bufp += sizeof(struct elfhdr);
50017@@ -478,9 +480,10 @@ read_kcore(struct file *file, char __use
50018 * the addresses in the elf_phdr on our list.
50019 */
50020 start = kc_offset_to_vaddr(*fpos - elf_buflen);
50021- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
50022+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
50023+ if (tsz > buflen)
50024 tsz = buflen;
50025-
50026+
50027 while (buflen) {
50028 struct kcore_list *m;
50029
50030@@ -509,20 +512,23 @@ read_kcore(struct file *file, char __use
50031 kfree(elf_buf);
50032 } else {
50033 if (kern_addr_valid(start)) {
50034- unsigned long n;
50035+ char *elf_buf;
50036+ mm_segment_t oldfs;
50037
50038- n = copy_to_user(buffer, (char *)start, tsz);
50039- /*
50040- * We cannot distingush between fault on source
50041- * and fault on destination. When this happens
50042- * we clear too and hope it will trigger the
50043- * EFAULT again.
50044- */
50045- if (n) {
50046- if (clear_user(buffer + tsz - n,
50047- n))
50048+ elf_buf = kmalloc(tsz, GFP_KERNEL);
50049+ if (!elf_buf)
50050+ return -ENOMEM;
50051+ oldfs = get_fs();
50052+ set_fs(KERNEL_DS);
50053+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
50054+ set_fs(oldfs);
50055+ if (copy_to_user(buffer, elf_buf, tsz)) {
50056+ kfree(elf_buf);
50057 return -EFAULT;
50058+ }
50059 }
50060+ set_fs(oldfs);
50061+ kfree(elf_buf);
50062 } else {
50063 if (clear_user(buffer, tsz))
50064 return -EFAULT;
50065@@ -542,6 +548,9 @@ read_kcore(struct file *file, char __use
50066
50067 static int open_kcore(struct inode *inode, struct file *filp)
50068 {
50069+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
50070+ return -EPERM;
50071+#endif
50072 if (!capable(CAP_SYS_RAWIO))
50073 return -EPERM;
50074 if (kcore_need_update)
50075diff -urNp linux-2.6.39.1/fs/proc/meminfo.c linux-2.6.39.1/fs/proc/meminfo.c
50076--- linux-2.6.39.1/fs/proc/meminfo.c 2011-05-19 00:06:34.000000000 -0400
50077+++ linux-2.6.39.1/fs/proc/meminfo.c 2011-05-22 19:36:32.000000000 -0400
50078@@ -29,6 +29,8 @@ static int meminfo_proc_show(struct seq_
50079 unsigned long pages[NR_LRU_LISTS];
50080 int lru;
50081
50082+ pax_track_stack();
50083+
50084 /*
50085 * display in kilobytes.
50086 */
50087@@ -157,7 +159,7 @@ static int meminfo_proc_show(struct seq_
50088 vmi.used >> 10,
50089 vmi.largest_chunk >> 10
50090 #ifdef CONFIG_MEMORY_FAILURE
50091- ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
50092+ ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
50093 #endif
50094 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
50095 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
50096diff -urNp linux-2.6.39.1/fs/proc/nommu.c linux-2.6.39.1/fs/proc/nommu.c
50097--- linux-2.6.39.1/fs/proc/nommu.c 2011-05-19 00:06:34.000000000 -0400
50098+++ linux-2.6.39.1/fs/proc/nommu.c 2011-05-22 19:36:32.000000000 -0400
50099@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_
50100 if (len < 1)
50101 len = 1;
50102 seq_printf(m, "%*c", len, ' ');
50103- seq_path(m, &file->f_path, "");
50104+ seq_path(m, &file->f_path, "\n\\");
50105 }
50106
50107 seq_putc(m, '\n');
50108diff -urNp linux-2.6.39.1/fs/proc/proc_net.c linux-2.6.39.1/fs/proc/proc_net.c
50109--- linux-2.6.39.1/fs/proc/proc_net.c 2011-05-19 00:06:34.000000000 -0400
50110+++ linux-2.6.39.1/fs/proc/proc_net.c 2011-05-22 19:41:37.000000000 -0400
50111@@ -105,6 +105,17 @@ static struct net *get_proc_task_net(str
50112 struct task_struct *task;
50113 struct nsproxy *ns;
50114 struct net *net = NULL;
50115+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50116+ const struct cred *cred = current_cred();
50117+#endif
50118+
50119+#ifdef CONFIG_GRKERNSEC_PROC_USER
50120+ if (cred->fsuid)
50121+ return net;
50122+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50123+ if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
50124+ return net;
50125+#endif
50126
50127 rcu_read_lock();
50128 task = pid_task(proc_pid(dir), PIDTYPE_PID);
50129diff -urNp linux-2.6.39.1/fs/proc/proc_sysctl.c linux-2.6.39.1/fs/proc/proc_sysctl.c
50130--- linux-2.6.39.1/fs/proc/proc_sysctl.c 2011-05-19 00:06:34.000000000 -0400
50131+++ linux-2.6.39.1/fs/proc/proc_sysctl.c 2011-05-22 19:41:37.000000000 -0400
50132@@ -8,6 +8,8 @@
50133 #include <linux/namei.h>
50134 #include "internal.h"
50135
50136+extern __u32 gr_handle_sysctl(const struct ctl_table *table, const int op);
50137+
50138 static const struct dentry_operations proc_sys_dentry_operations;
50139 static const struct file_operations proc_sys_file_operations;
50140 static const struct inode_operations proc_sys_inode_operations;
50141@@ -111,6 +113,9 @@ static struct dentry *proc_sys_lookup(st
50142 if (!p)
50143 goto out;
50144
50145+ if (gr_handle_sysctl(p, MAY_EXEC))
50146+ goto out;
50147+
50148 err = ERR_PTR(-ENOMEM);
50149 inode = proc_sys_make_inode(dir->i_sb, h ? h : head, p);
50150 if (h)
50151@@ -230,6 +235,9 @@ static int scan(struct ctl_table_header
50152 if (*pos < file->f_pos)
50153 continue;
50154
50155+ if (gr_handle_sysctl(table, 0))
50156+ continue;
50157+
50158 res = proc_sys_fill_cache(file, dirent, filldir, head, table);
50159 if (res)
50160 return res;
50161@@ -358,6 +366,9 @@ static int proc_sys_getattr(struct vfsmo
50162 if (IS_ERR(head))
50163 return PTR_ERR(head);
50164
50165+ if (table && gr_handle_sysctl(table, MAY_EXEC))
50166+ return -ENOENT;
50167+
50168 generic_fillattr(inode, stat);
50169 if (table)
50170 stat->mode = (stat->mode & S_IFMT) | table->mode;
50171diff -urNp linux-2.6.39.1/fs/proc/root.c linux-2.6.39.1/fs/proc/root.c
50172--- linux-2.6.39.1/fs/proc/root.c 2011-05-19 00:06:34.000000000 -0400
50173+++ linux-2.6.39.1/fs/proc/root.c 2011-05-22 19:41:37.000000000 -0400
50174@@ -122,7 +122,15 @@ void __init proc_root_init(void)
50175 #ifdef CONFIG_PROC_DEVICETREE
50176 proc_device_tree_init();
50177 #endif
50178+#ifdef CONFIG_GRKERNSEC_PROC_ADD
50179+#ifdef CONFIG_GRKERNSEC_PROC_USER
50180+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
50181+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50182+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
50183+#endif
50184+#else
50185 proc_mkdir("bus", NULL);
50186+#endif
50187 proc_sys_init();
50188 }
50189
50190diff -urNp linux-2.6.39.1/fs/proc/task_mmu.c linux-2.6.39.1/fs/proc/task_mmu.c
50191--- linux-2.6.39.1/fs/proc/task_mmu.c 2011-05-19 00:06:34.000000000 -0400
50192+++ linux-2.6.39.1/fs/proc/task_mmu.c 2011-05-22 22:43:29.000000000 -0400
50193@@ -51,8 +51,13 @@ void task_mem(struct seq_file *m, struct
50194 "VmExe:\t%8lu kB\n"
50195 "VmLib:\t%8lu kB\n"
50196 "VmPTE:\t%8lu kB\n"
50197- "VmSwap:\t%8lu kB\n",
50198- hiwater_vm << (PAGE_SHIFT-10),
50199+ "VmSwap:\t%8lu kB\n"
50200+
50201+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
50202+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
50203+#endif
50204+
50205+ ,hiwater_vm << (PAGE_SHIFT-10),
50206 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
50207 mm->locked_vm << (PAGE_SHIFT-10),
50208 hiwater_rss << (PAGE_SHIFT-10),
50209@@ -60,7 +65,13 @@ void task_mem(struct seq_file *m, struct
50210 data << (PAGE_SHIFT-10),
50211 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
50212 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
50213- swap << (PAGE_SHIFT-10));
50214+ swap << (PAGE_SHIFT-10)
50215+
50216+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
50217+ , mm->context.user_cs_base, mm->context.user_cs_limit
50218+#endif
50219+
50220+ );
50221 }
50222
50223 unsigned long task_vsize(struct mm_struct *mm)
50224@@ -207,6 +218,12 @@ static int do_maps_open(struct inode *in
50225 return ret;
50226 }
50227
50228+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50229+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
50230+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
50231+ _mm->pax_flags & MF_PAX_SEGMEXEC))
50232+#endif
50233+
50234 static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
50235 {
50236 struct mm_struct *mm = vma->vm_mm;
50237@@ -225,13 +242,13 @@ static void show_map_vma(struct seq_file
50238 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
50239 }
50240
50241- /* We don't show the stack guard page in /proc/maps */
50242+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50243+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
50244+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
50245+#else
50246 start = vma->vm_start;
50247- if (stack_guard_page_start(vma, start))
50248- start += PAGE_SIZE;
50249 end = vma->vm_end;
50250- if (stack_guard_page_end(vma, end))
50251- end -= PAGE_SIZE;
50252+#endif
50253
50254 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
50255 start,
50256@@ -240,7 +257,11 @@ static void show_map_vma(struct seq_file
50257 flags & VM_WRITE ? 'w' : '-',
50258 flags & VM_EXEC ? 'x' : '-',
50259 flags & VM_MAYSHARE ? 's' : 'p',
50260+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50261+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
50262+#else
50263 pgoff,
50264+#endif
50265 MAJOR(dev), MINOR(dev), ino, &len);
50266
50267 /*
50268@@ -249,7 +270,7 @@ static void show_map_vma(struct seq_file
50269 */
50270 if (file) {
50271 pad_len_spaces(m, len);
50272- seq_path(m, &file->f_path, "\n");
50273+ seq_path(m, &file->f_path, "\n\\");
50274 } else {
50275 const char *name = arch_vma_name(vma);
50276 if (!name) {
50277@@ -257,8 +278,9 @@ static void show_map_vma(struct seq_file
50278 if (vma->vm_start <= mm->brk &&
50279 vma->vm_end >= mm->start_brk) {
50280 name = "[heap]";
50281- } else if (vma->vm_start <= mm->start_stack &&
50282- vma->vm_end >= mm->start_stack) {
50283+ } else if ((vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
50284+ (vma->vm_start <= mm->start_stack &&
50285+ vma->vm_end >= mm->start_stack)) {
50286 name = "[stack]";
50287 }
50288 } else {
50289@@ -433,11 +455,16 @@ static int show_smap(struct seq_file *m,
50290 };
50291
50292 memset(&mss, 0, sizeof mss);
50293- mss.vma = vma;
50294- /* mmap_sem is held in m_start */
50295- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
50296- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
50297-
50298+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50299+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
50300+#endif
50301+ mss.vma = vma;
50302+ /* mmap_sem is held in m_start */
50303+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
50304+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
50305+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50306+ }
50307+#endif
50308 show_map_vma(m, vma);
50309
50310 seq_printf(m,
50311@@ -455,7 +482,11 @@ static int show_smap(struct seq_file *m,
50312 "KernelPageSize: %8lu kB\n"
50313 "MMUPageSize: %8lu kB\n"
50314 "Locked: %8lu kB\n",
50315+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50316+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
50317+#else
50318 (vma->vm_end - vma->vm_start) >> 10,
50319+#endif
50320 mss.resident >> 10,
50321 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
50322 mss.shared_clean >> 10,
50323diff -urNp linux-2.6.39.1/fs/proc/task_nommu.c linux-2.6.39.1/fs/proc/task_nommu.c
50324--- linux-2.6.39.1/fs/proc/task_nommu.c 2011-05-19 00:06:34.000000000 -0400
50325+++ linux-2.6.39.1/fs/proc/task_nommu.c 2011-05-22 19:36:32.000000000 -0400
50326@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct
50327 else
50328 bytes += kobjsize(mm);
50329
50330- if (current->fs && current->fs->users > 1)
50331+ if (current->fs && atomic_read(&current->fs->users) > 1)
50332 sbytes += kobjsize(current->fs);
50333 else
50334 bytes += kobjsize(current->fs);
50335@@ -166,7 +166,7 @@ static int nommu_vma_show(struct seq_fil
50336
50337 if (file) {
50338 pad_len_spaces(m, len);
50339- seq_path(m, &file->f_path, "");
50340+ seq_path(m, &file->f_path, "\n\\");
50341 } else if (mm) {
50342 if (vma->vm_start <= mm->start_stack &&
50343 vma->vm_end >= mm->start_stack) {
50344diff -urNp linux-2.6.39.1/fs/quota/netlink.c linux-2.6.39.1/fs/quota/netlink.c
50345--- linux-2.6.39.1/fs/quota/netlink.c 2011-05-19 00:06:34.000000000 -0400
50346+++ linux-2.6.39.1/fs/quota/netlink.c 2011-05-22 19:36:32.000000000 -0400
50347@@ -33,7 +33,7 @@ static struct genl_family quota_genl_fam
50348 void quota_send_warning(short type, unsigned int id, dev_t dev,
50349 const char warntype)
50350 {
50351- static atomic_t seq;
50352+ static atomic_unchecked_t seq;
50353 struct sk_buff *skb;
50354 void *msg_head;
50355 int ret;
50356@@ -49,7 +49,7 @@ void quota_send_warning(short type, unsi
50357 "VFS: Not enough memory to send quota warning.\n");
50358 return;
50359 }
50360- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
50361+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
50362 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
50363 if (!msg_head) {
50364 printk(KERN_ERR
50365diff -urNp linux-2.6.39.1/fs/readdir.c linux-2.6.39.1/fs/readdir.c
50366--- linux-2.6.39.1/fs/readdir.c 2011-05-19 00:06:34.000000000 -0400
50367+++ linux-2.6.39.1/fs/readdir.c 2011-05-22 19:41:42.000000000 -0400
50368@@ -17,6 +17,7 @@
50369 #include <linux/security.h>
50370 #include <linux/syscalls.h>
50371 #include <linux/unistd.h>
50372+#include <linux/namei.h>
50373
50374 #include <asm/uaccess.h>
50375
50376@@ -67,6 +68,7 @@ struct old_linux_dirent {
50377
50378 struct readdir_callback {
50379 struct old_linux_dirent __user * dirent;
50380+ struct file * file;
50381 int result;
50382 };
50383
50384@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, cons
50385 buf->result = -EOVERFLOW;
50386 return -EOVERFLOW;
50387 }
50388+
50389+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50390+ return 0;
50391+
50392 buf->result++;
50393 dirent = buf->dirent;
50394 if (!access_ok(VERIFY_WRITE, dirent,
50395@@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned in
50396
50397 buf.result = 0;
50398 buf.dirent = dirent;
50399+ buf.file = file;
50400
50401 error = vfs_readdir(file, fillonedir, &buf);
50402 if (buf.result)
50403@@ -142,6 +149,7 @@ struct linux_dirent {
50404 struct getdents_callback {
50405 struct linux_dirent __user * current_dir;
50406 struct linux_dirent __user * previous;
50407+ struct file * file;
50408 int count;
50409 int error;
50410 };
50411@@ -163,6 +171,10 @@ static int filldir(void * __buf, const c
50412 buf->error = -EOVERFLOW;
50413 return -EOVERFLOW;
50414 }
50415+
50416+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50417+ return 0;
50418+
50419 dirent = buf->previous;
50420 if (dirent) {
50421 if (__put_user(offset, &dirent->d_off))
50422@@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int,
50423 buf.previous = NULL;
50424 buf.count = count;
50425 buf.error = 0;
50426+ buf.file = file;
50427
50428 error = vfs_readdir(file, filldir, &buf);
50429 if (error >= 0)
50430@@ -229,6 +242,7 @@ out:
50431 struct getdents_callback64 {
50432 struct linux_dirent64 __user * current_dir;
50433 struct linux_dirent64 __user * previous;
50434+ struct file *file;
50435 int count;
50436 int error;
50437 };
50438@@ -244,6 +258,10 @@ static int filldir64(void * __buf, const
50439 buf->error = -EINVAL; /* only used if we fail.. */
50440 if (reclen > buf->count)
50441 return -EINVAL;
50442+
50443+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50444+ return 0;
50445+
50446 dirent = buf->previous;
50447 if (dirent) {
50448 if (__put_user(offset, &dirent->d_off))
50449@@ -291,6 +309,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int
50450
50451 buf.current_dir = dirent;
50452 buf.previous = NULL;
50453+ buf.file = file;
50454 buf.count = count;
50455 buf.error = 0;
50456
50457diff -urNp linux-2.6.39.1/fs/reiserfs/dir.c linux-2.6.39.1/fs/reiserfs/dir.c
50458--- linux-2.6.39.1/fs/reiserfs/dir.c 2011-05-19 00:06:34.000000000 -0400
50459+++ linux-2.6.39.1/fs/reiserfs/dir.c 2011-05-22 19:36:32.000000000 -0400
50460@@ -66,6 +66,8 @@ int reiserfs_readdir_dentry(struct dentr
50461 struct reiserfs_dir_entry de;
50462 int ret = 0;
50463
50464+ pax_track_stack();
50465+
50466 reiserfs_write_lock(inode->i_sb);
50467
50468 reiserfs_check_lock_depth(inode->i_sb, "readdir");
50469diff -urNp linux-2.6.39.1/fs/reiserfs/do_balan.c linux-2.6.39.1/fs/reiserfs/do_balan.c
50470--- linux-2.6.39.1/fs/reiserfs/do_balan.c 2011-05-19 00:06:34.000000000 -0400
50471+++ linux-2.6.39.1/fs/reiserfs/do_balan.c 2011-05-22 19:36:32.000000000 -0400
50472@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb,
50473 return;
50474 }
50475
50476- atomic_inc(&(fs_generation(tb->tb_sb)));
50477+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
50478 do_balance_starts(tb);
50479
50480 /* balance leaf returns 0 except if combining L R and S into
50481diff -urNp linux-2.6.39.1/fs/reiserfs/item_ops.c linux-2.6.39.1/fs/reiserfs/item_ops.c
50482--- linux-2.6.39.1/fs/reiserfs/item_ops.c 2011-05-19 00:06:34.000000000 -0400
50483+++ linux-2.6.39.1/fs/reiserfs/item_ops.c 2011-05-22 19:36:32.000000000 -0400
50484@@ -102,7 +102,7 @@ static void sd_print_vi(struct virtual_i
50485 vi->vi_index, vi->vi_type, vi->vi_ih);
50486 }
50487
50488-static struct item_operations stat_data_ops = {
50489+static const struct item_operations stat_data_ops = {
50490 .bytes_number = sd_bytes_number,
50491 .decrement_key = sd_decrement_key,
50492 .is_left_mergeable = sd_is_left_mergeable,
50493@@ -196,7 +196,7 @@ static void direct_print_vi(struct virtu
50494 vi->vi_index, vi->vi_type, vi->vi_ih);
50495 }
50496
50497-static struct item_operations direct_ops = {
50498+static const struct item_operations direct_ops = {
50499 .bytes_number = direct_bytes_number,
50500 .decrement_key = direct_decrement_key,
50501 .is_left_mergeable = direct_is_left_mergeable,
50502@@ -341,7 +341,7 @@ static void indirect_print_vi(struct vir
50503 vi->vi_index, vi->vi_type, vi->vi_ih);
50504 }
50505
50506-static struct item_operations indirect_ops = {
50507+static const struct item_operations indirect_ops = {
50508 .bytes_number = indirect_bytes_number,
50509 .decrement_key = indirect_decrement_key,
50510 .is_left_mergeable = indirect_is_left_mergeable,
50511@@ -628,7 +628,7 @@ static void direntry_print_vi(struct vir
50512 printk("\n");
50513 }
50514
50515-static struct item_operations direntry_ops = {
50516+static const struct item_operations direntry_ops = {
50517 .bytes_number = direntry_bytes_number,
50518 .decrement_key = direntry_decrement_key,
50519 .is_left_mergeable = direntry_is_left_mergeable,
50520@@ -724,7 +724,7 @@ static void errcatch_print_vi(struct vir
50521 "Invalid item type observed, run fsck ASAP");
50522 }
50523
50524-static struct item_operations errcatch_ops = {
50525+static const struct item_operations errcatch_ops = {
50526 errcatch_bytes_number,
50527 errcatch_decrement_key,
50528 errcatch_is_left_mergeable,
50529@@ -746,7 +746,7 @@ static struct item_operations errcatch_o
50530 #error Item types must use disk-format assigned values.
50531 #endif
50532
50533-struct item_operations *item_ops[TYPE_ANY + 1] = {
50534+const struct item_operations * const item_ops[TYPE_ANY + 1] = {
50535 &stat_data_ops,
50536 &indirect_ops,
50537 &direct_ops,
50538diff -urNp linux-2.6.39.1/fs/reiserfs/journal.c linux-2.6.39.1/fs/reiserfs/journal.c
50539--- linux-2.6.39.1/fs/reiserfs/journal.c 2011-05-19 00:06:34.000000000 -0400
50540+++ linux-2.6.39.1/fs/reiserfs/journal.c 2011-05-22 19:36:32.000000000 -0400
50541@@ -2299,6 +2299,8 @@ static struct buffer_head *reiserfs_brea
50542 struct buffer_head *bh;
50543 int i, j;
50544
50545+ pax_track_stack();
50546+
50547 bh = __getblk(dev, block, bufsize);
50548 if (buffer_uptodate(bh))
50549 return (bh);
50550diff -urNp linux-2.6.39.1/fs/reiserfs/namei.c linux-2.6.39.1/fs/reiserfs/namei.c
50551--- linux-2.6.39.1/fs/reiserfs/namei.c 2011-05-19 00:06:34.000000000 -0400
50552+++ linux-2.6.39.1/fs/reiserfs/namei.c 2011-05-22 19:36:32.000000000 -0400
50553@@ -1225,6 +1225,8 @@ static int reiserfs_rename(struct inode
50554 unsigned long savelink = 1;
50555 struct timespec ctime;
50556
50557+ pax_track_stack();
50558+
50559 /* three balancings: (1) old name removal, (2) new name insertion
50560 and (3) maybe "save" link insertion
50561 stat data updates: (1) old directory,
50562diff -urNp linux-2.6.39.1/fs/reiserfs/procfs.c linux-2.6.39.1/fs/reiserfs/procfs.c
50563--- linux-2.6.39.1/fs/reiserfs/procfs.c 2011-05-19 00:06:34.000000000 -0400
50564+++ linux-2.6.39.1/fs/reiserfs/procfs.c 2011-05-22 19:36:32.000000000 -0400
50565@@ -113,7 +113,7 @@ static int show_super(struct seq_file *m
50566 "SMALL_TAILS " : "NO_TAILS ",
50567 replay_only(sb) ? "REPLAY_ONLY " : "",
50568 convert_reiserfs(sb) ? "CONV " : "",
50569- atomic_read(&r->s_generation_counter),
50570+ atomic_read_unchecked(&r->s_generation_counter),
50571 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
50572 SF(s_do_balance), SF(s_unneeded_left_neighbor),
50573 SF(s_good_search_by_key_reada), SF(s_bmaps),
50574@@ -299,6 +299,8 @@ static int show_journal(struct seq_file
50575 struct journal_params *jp = &rs->s_v1.s_journal;
50576 char b[BDEVNAME_SIZE];
50577
50578+ pax_track_stack();
50579+
50580 seq_printf(m, /* on-disk fields */
50581 "jp_journal_1st_block: \t%i\n"
50582 "jp_journal_dev: \t%s[%x]\n"
50583diff -urNp linux-2.6.39.1/fs/reiserfs/stree.c linux-2.6.39.1/fs/reiserfs/stree.c
50584--- linux-2.6.39.1/fs/reiserfs/stree.c 2011-05-19 00:06:34.000000000 -0400
50585+++ linux-2.6.39.1/fs/reiserfs/stree.c 2011-05-22 19:36:32.000000000 -0400
50586@@ -1196,6 +1196,8 @@ int reiserfs_delete_item(struct reiserfs
50587 int iter = 0;
50588 #endif
50589
50590+ pax_track_stack();
50591+
50592 BUG_ON(!th->t_trans_id);
50593
50594 init_tb_struct(th, &s_del_balance, sb, path,
50595@@ -1333,6 +1335,8 @@ void reiserfs_delete_solid_item(struct r
50596 int retval;
50597 int quota_cut_bytes = 0;
50598
50599+ pax_track_stack();
50600+
50601 BUG_ON(!th->t_trans_id);
50602
50603 le_key2cpu_key(&cpu_key, key);
50604@@ -1562,6 +1566,8 @@ int reiserfs_cut_from_item(struct reiser
50605 int quota_cut_bytes;
50606 loff_t tail_pos = 0;
50607
50608+ pax_track_stack();
50609+
50610 BUG_ON(!th->t_trans_id);
50611
50612 init_tb_struct(th, &s_cut_balance, inode->i_sb, path,
50613@@ -1957,6 +1963,8 @@ int reiserfs_paste_into_item(struct reis
50614 int retval;
50615 int fs_gen;
50616
50617+ pax_track_stack();
50618+
50619 BUG_ON(!th->t_trans_id);
50620
50621 fs_gen = get_generation(inode->i_sb);
50622@@ -2045,6 +2053,8 @@ int reiserfs_insert_item(struct reiserfs
50623 int fs_gen = 0;
50624 int quota_bytes = 0;
50625
50626+ pax_track_stack();
50627+
50628 BUG_ON(!th->t_trans_id);
50629
50630 if (inode) { /* Do we count quotas for item? */
50631diff -urNp linux-2.6.39.1/fs/reiserfs/super.c linux-2.6.39.1/fs/reiserfs/super.c
50632--- linux-2.6.39.1/fs/reiserfs/super.c 2011-05-19 00:06:34.000000000 -0400
50633+++ linux-2.6.39.1/fs/reiserfs/super.c 2011-05-22 19:36:32.000000000 -0400
50634@@ -927,6 +927,8 @@ static int reiserfs_parse_options(struct
50635 {.option_name = NULL}
50636 };
50637
50638+ pax_track_stack();
50639+
50640 *blocks = 0;
50641 if (!options || !*options)
50642 /* use default configuration: create tails, journaling on, no
50643diff -urNp linux-2.6.39.1/fs/select.c linux-2.6.39.1/fs/select.c
50644--- linux-2.6.39.1/fs/select.c 2011-05-19 00:06:34.000000000 -0400
50645+++ linux-2.6.39.1/fs/select.c 2011-05-22 19:41:42.000000000 -0400
50646@@ -20,6 +20,7 @@
50647 #include <linux/module.h>
50648 #include <linux/slab.h>
50649 #include <linux/poll.h>
50650+#include <linux/security.h>
50651 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
50652 #include <linux/file.h>
50653 #include <linux/fdtable.h>
50654@@ -403,6 +404,8 @@ int do_select(int n, fd_set_bits *fds, s
50655 int retval, i, timed_out = 0;
50656 unsigned long slack = 0;
50657
50658+ pax_track_stack();
50659+
50660 rcu_read_lock();
50661 retval = max_select_fd(n, fds);
50662 rcu_read_unlock();
50663@@ -528,6 +531,8 @@ int core_sys_select(int n, fd_set __user
50664 /* Allocate small arguments on the stack to save memory and be faster */
50665 long stack_fds[SELECT_STACK_ALLOC/sizeof(long)];
50666
50667+ pax_track_stack();
50668+
50669 ret = -EINVAL;
50670 if (n < 0)
50671 goto out_nofds;
50672@@ -837,6 +842,9 @@ int do_sys_poll(struct pollfd __user *uf
50673 struct poll_list *walk = head;
50674 unsigned long todo = nfds;
50675
50676+ pax_track_stack();
50677+
50678+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
50679 if (nfds > rlimit(RLIMIT_NOFILE))
50680 return -EINVAL;
50681
50682diff -urNp linux-2.6.39.1/fs/seq_file.c linux-2.6.39.1/fs/seq_file.c
50683--- linux-2.6.39.1/fs/seq_file.c 2011-05-19 00:06:34.000000000 -0400
50684+++ linux-2.6.39.1/fs/seq_file.c 2011-05-22 19:36:32.000000000 -0400
50685@@ -76,7 +76,8 @@ static int traverse(struct seq_file *m,
50686 return 0;
50687 }
50688 if (!m->buf) {
50689- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50690+ m->size = PAGE_SIZE;
50691+ m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
50692 if (!m->buf)
50693 return -ENOMEM;
50694 }
50695@@ -116,7 +117,8 @@ static int traverse(struct seq_file *m,
50696 Eoverflow:
50697 m->op->stop(m, p);
50698 kfree(m->buf);
50699- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50700+ m->size <<= 1;
50701+ m->buf = kmalloc(m->size, GFP_KERNEL);
50702 return !m->buf ? -ENOMEM : -EAGAIN;
50703 }
50704
50705@@ -169,7 +171,8 @@ ssize_t seq_read(struct file *file, char
50706 m->version = file->f_version;
50707 /* grab buffer if we didn't have one */
50708 if (!m->buf) {
50709- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50710+ m->size = PAGE_SIZE;
50711+ m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
50712 if (!m->buf)
50713 goto Enomem;
50714 }
50715@@ -210,7 +213,8 @@ ssize_t seq_read(struct file *file, char
50716 goto Fill;
50717 m->op->stop(m, p);
50718 kfree(m->buf);
50719- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50720+ m->size <<= 1;
50721+ m->buf = kmalloc(m->size, GFP_KERNEL);
50722 if (!m->buf)
50723 goto Enomem;
50724 m->count = 0;
50725diff -urNp linux-2.6.39.1/fs/splice.c linux-2.6.39.1/fs/splice.c
50726--- linux-2.6.39.1/fs/splice.c 2011-05-19 00:06:34.000000000 -0400
50727+++ linux-2.6.39.1/fs/splice.c 2011-05-22 19:36:32.000000000 -0400
50728@@ -186,7 +186,7 @@ ssize_t splice_to_pipe(struct pipe_inode
50729 pipe_lock(pipe);
50730
50731 for (;;) {
50732- if (!pipe->readers) {
50733+ if (!atomic_read(&pipe->readers)) {
50734 send_sig(SIGPIPE, current, 0);
50735 if (!ret)
50736 ret = -EPIPE;
50737@@ -240,9 +240,9 @@ ssize_t splice_to_pipe(struct pipe_inode
50738 do_wakeup = 0;
50739 }
50740
50741- pipe->waiting_writers++;
50742+ atomic_inc(&pipe->waiting_writers);
50743 pipe_wait(pipe);
50744- pipe->waiting_writers--;
50745+ atomic_dec(&pipe->waiting_writers);
50746 }
50747
50748 pipe_unlock(pipe);
50749@@ -316,6 +316,8 @@ __generic_file_splice_read(struct file *
50750 .spd_release = spd_release_page,
50751 };
50752
50753+ pax_track_stack();
50754+
50755 if (splice_grow_spd(pipe, &spd))
50756 return -ENOMEM;
50757
50758@@ -556,7 +558,7 @@ static ssize_t kernel_readv(struct file
50759 old_fs = get_fs();
50760 set_fs(get_ds());
50761 /* The cast to a user pointer is valid due to the set_fs() */
50762- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
50763+ res = vfs_readv(file, (__force const struct iovec __user *)vec, vlen, &pos);
50764 set_fs(old_fs);
50765
50766 return res;
50767@@ -571,7 +573,7 @@ static ssize_t kernel_write(struct file
50768 old_fs = get_fs();
50769 set_fs(get_ds());
50770 /* The cast to a user pointer is valid due to the set_fs() */
50771- res = vfs_write(file, (const char __user *)buf, count, &pos);
50772+ res = vfs_write(file, (__force const char __user *)buf, count, &pos);
50773 set_fs(old_fs);
50774
50775 return res;
50776@@ -599,6 +601,8 @@ ssize_t default_file_splice_read(struct
50777 .spd_release = spd_release_page,
50778 };
50779
50780+ pax_track_stack();
50781+
50782 if (splice_grow_spd(pipe, &spd))
50783 return -ENOMEM;
50784
50785@@ -622,7 +626,7 @@ ssize_t default_file_splice_read(struct
50786 goto err;
50787
50788 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
50789- vec[i].iov_base = (void __user *) page_address(page);
50790+ vec[i].iov_base = (__force void __user *) page_address(page);
50791 vec[i].iov_len = this_len;
50792 spd.pages[i] = page;
50793 spd.nr_pages++;
50794@@ -842,10 +846,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
50795 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
50796 {
50797 while (!pipe->nrbufs) {
50798- if (!pipe->writers)
50799+ if (!atomic_read(&pipe->writers))
50800 return 0;
50801
50802- if (!pipe->waiting_writers && sd->num_spliced)
50803+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
50804 return 0;
50805
50806 if (sd->flags & SPLICE_F_NONBLOCK)
50807@@ -1178,7 +1182,7 @@ ssize_t splice_direct_to_actor(struct fi
50808 * out of the pipe right after the splice_to_pipe(). So set
50809 * PIPE_READERS appropriately.
50810 */
50811- pipe->readers = 1;
50812+ atomic_set(&pipe->readers, 1);
50813
50814 current->splice_pipe = pipe;
50815 }
50816@@ -1615,6 +1619,8 @@ static long vmsplice_to_pipe(struct file
50817 };
50818 long ret;
50819
50820+ pax_track_stack();
50821+
50822 pipe = get_pipe_info(file);
50823 if (!pipe)
50824 return -EBADF;
50825@@ -1730,9 +1736,9 @@ static int ipipe_prep(struct pipe_inode_
50826 ret = -ERESTARTSYS;
50827 break;
50828 }
50829- if (!pipe->writers)
50830+ if (!atomic_read(&pipe->writers))
50831 break;
50832- if (!pipe->waiting_writers) {
50833+ if (!atomic_read(&pipe->waiting_writers)) {
50834 if (flags & SPLICE_F_NONBLOCK) {
50835 ret = -EAGAIN;
50836 break;
50837@@ -1764,7 +1770,7 @@ static int opipe_prep(struct pipe_inode_
50838 pipe_lock(pipe);
50839
50840 while (pipe->nrbufs >= pipe->buffers) {
50841- if (!pipe->readers) {
50842+ if (!atomic_read(&pipe->readers)) {
50843 send_sig(SIGPIPE, current, 0);
50844 ret = -EPIPE;
50845 break;
50846@@ -1777,9 +1783,9 @@ static int opipe_prep(struct pipe_inode_
50847 ret = -ERESTARTSYS;
50848 break;
50849 }
50850- pipe->waiting_writers++;
50851+ atomic_inc(&pipe->waiting_writers);
50852 pipe_wait(pipe);
50853- pipe->waiting_writers--;
50854+ atomic_dec(&pipe->waiting_writers);
50855 }
50856
50857 pipe_unlock(pipe);
50858@@ -1815,14 +1821,14 @@ retry:
50859 pipe_double_lock(ipipe, opipe);
50860
50861 do {
50862- if (!opipe->readers) {
50863+ if (!atomic_read(&opipe->readers)) {
50864 send_sig(SIGPIPE, current, 0);
50865 if (!ret)
50866 ret = -EPIPE;
50867 break;
50868 }
50869
50870- if (!ipipe->nrbufs && !ipipe->writers)
50871+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
50872 break;
50873
50874 /*
50875@@ -1922,7 +1928,7 @@ static int link_pipe(struct pipe_inode_i
50876 pipe_double_lock(ipipe, opipe);
50877
50878 do {
50879- if (!opipe->readers) {
50880+ if (!atomic_read(&opipe->readers)) {
50881 send_sig(SIGPIPE, current, 0);
50882 if (!ret)
50883 ret = -EPIPE;
50884@@ -1967,7 +1973,7 @@ static int link_pipe(struct pipe_inode_i
50885 * return EAGAIN if we have the potential of some data in the
50886 * future, otherwise just return 0
50887 */
50888- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
50889+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
50890 ret = -EAGAIN;
50891
50892 pipe_unlock(ipipe);
50893diff -urNp linux-2.6.39.1/fs/sysfs/file.c linux-2.6.39.1/fs/sysfs/file.c
50894--- linux-2.6.39.1/fs/sysfs/file.c 2011-05-19 00:06:34.000000000 -0400
50895+++ linux-2.6.39.1/fs/sysfs/file.c 2011-05-22 19:36:32.000000000 -0400
50896@@ -44,7 +44,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent
50897
50898 struct sysfs_open_dirent {
50899 atomic_t refcnt;
50900- atomic_t event;
50901+ atomic_unchecked_t event;
50902 wait_queue_head_t poll;
50903 struct list_head buffers; /* goes through sysfs_buffer.list */
50904 };
50905@@ -88,7 +88,7 @@ static int fill_read_buffer(struct dentr
50906 if (!sysfs_get_active(attr_sd))
50907 return -ENODEV;
50908
50909- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
50910+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
50911 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
50912
50913 sysfs_put_active(attr_sd);
50914@@ -294,7 +294,7 @@ static int sysfs_get_open_dirent(struct
50915 return -ENOMEM;
50916
50917 atomic_set(&new_od->refcnt, 0);
50918- atomic_set(&new_od->event, 1);
50919+ atomic_set_unchecked(&new_od->event, 1);
50920 init_waitqueue_head(&new_od->poll);
50921 INIT_LIST_HEAD(&new_od->buffers);
50922 goto retry;
50923@@ -444,7 +444,7 @@ static unsigned int sysfs_poll(struct fi
50924
50925 sysfs_put_active(attr_sd);
50926
50927- if (buffer->event != atomic_read(&od->event))
50928+ if (buffer->event != atomic_read_unchecked(&od->event))
50929 goto trigger;
50930
50931 return DEFAULT_POLLMASK;
50932@@ -463,7 +463,7 @@ void sysfs_notify_dirent(struct sysfs_di
50933
50934 od = sd->s_attr.open;
50935 if (od) {
50936- atomic_inc(&od->event);
50937+ atomic_inc_unchecked(&od->event);
50938 wake_up_interruptible(&od->poll);
50939 }
50940
50941diff -urNp linux-2.6.39.1/fs/sysfs/mount.c linux-2.6.39.1/fs/sysfs/mount.c
50942--- linux-2.6.39.1/fs/sysfs/mount.c 2011-05-19 00:06:34.000000000 -0400
50943+++ linux-2.6.39.1/fs/sysfs/mount.c 2011-05-22 19:41:42.000000000 -0400
50944@@ -36,7 +36,11 @@ struct sysfs_dirent sysfs_root = {
50945 .s_name = "",
50946 .s_count = ATOMIC_INIT(1),
50947 .s_flags = SYSFS_DIR | (KOBJ_NS_TYPE_NONE << SYSFS_NS_TYPE_SHIFT),
50948+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
50949+ .s_mode = S_IFDIR | S_IRWXU,
50950+#else
50951 .s_mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
50952+#endif
50953 .s_ino = 1,
50954 };
50955
50956diff -urNp linux-2.6.39.1/fs/sysfs/symlink.c linux-2.6.39.1/fs/sysfs/symlink.c
50957--- linux-2.6.39.1/fs/sysfs/symlink.c 2011-05-19 00:06:34.000000000 -0400
50958+++ linux-2.6.39.1/fs/sysfs/symlink.c 2011-05-22 19:36:32.000000000 -0400
50959@@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct de
50960
50961 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
50962 {
50963- char *page = nd_get_link(nd);
50964+ const char *page = nd_get_link(nd);
50965 if (!IS_ERR(page))
50966 free_page((unsigned long)page);
50967 }
50968diff -urNp linux-2.6.39.1/fs/udf/inode.c linux-2.6.39.1/fs/udf/inode.c
50969--- linux-2.6.39.1/fs/udf/inode.c 2011-05-19 00:06:34.000000000 -0400
50970+++ linux-2.6.39.1/fs/udf/inode.c 2011-05-22 19:36:32.000000000 -0400
50971@@ -560,6 +560,8 @@ static struct buffer_head *inode_getblk(
50972 int goal = 0, pgoal = iinfo->i_location.logicalBlockNum;
50973 int lastblock = 0;
50974
50975+ pax_track_stack();
50976+
50977 prev_epos.offset = udf_file_entry_alloc_offset(inode);
50978 prev_epos.block = iinfo->i_location;
50979 prev_epos.bh = NULL;
50980diff -urNp linux-2.6.39.1/fs/udf/misc.c linux-2.6.39.1/fs/udf/misc.c
50981--- linux-2.6.39.1/fs/udf/misc.c 2011-05-19 00:06:34.000000000 -0400
50982+++ linux-2.6.39.1/fs/udf/misc.c 2011-05-22 19:36:32.000000000 -0400
50983@@ -286,7 +286,7 @@ void udf_new_tag(char *data, uint16_t id
50984
50985 u8 udf_tag_checksum(const struct tag *t)
50986 {
50987- u8 *data = (u8 *)t;
50988+ const u8 *data = (const u8 *)t;
50989 u8 checksum = 0;
50990 int i;
50991 for (i = 0; i < sizeof(struct tag); ++i)
50992diff -urNp linux-2.6.39.1/fs/utimes.c linux-2.6.39.1/fs/utimes.c
50993--- linux-2.6.39.1/fs/utimes.c 2011-05-19 00:06:34.000000000 -0400
50994+++ linux-2.6.39.1/fs/utimes.c 2011-05-22 19:41:42.000000000 -0400
50995@@ -1,6 +1,7 @@
50996 #include <linux/compiler.h>
50997 #include <linux/file.h>
50998 #include <linux/fs.h>
50999+#include <linux/security.h>
51000 #include <linux/linkage.h>
51001 #include <linux/mount.h>
51002 #include <linux/namei.h>
51003@@ -101,6 +102,12 @@ static int utimes_common(struct path *pa
51004 goto mnt_drop_write_and_out;
51005 }
51006 }
51007+
51008+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
51009+ error = -EACCES;
51010+ goto mnt_drop_write_and_out;
51011+ }
51012+
51013 mutex_lock(&inode->i_mutex);
51014 error = notify_change(path->dentry, &newattrs);
51015 mutex_unlock(&inode->i_mutex);
51016diff -urNp linux-2.6.39.1/fs/xattr_acl.c linux-2.6.39.1/fs/xattr_acl.c
51017--- linux-2.6.39.1/fs/xattr_acl.c 2011-05-19 00:06:34.000000000 -0400
51018+++ linux-2.6.39.1/fs/xattr_acl.c 2011-05-22 19:36:32.000000000 -0400
51019@@ -17,8 +17,8 @@
51020 struct posix_acl *
51021 posix_acl_from_xattr(const void *value, size_t size)
51022 {
51023- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
51024- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
51025+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
51026+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
51027 int count;
51028 struct posix_acl *acl;
51029 struct posix_acl_entry *acl_e;
51030diff -urNp linux-2.6.39.1/fs/xattr.c linux-2.6.39.1/fs/xattr.c
51031--- linux-2.6.39.1/fs/xattr.c 2011-05-19 00:06:34.000000000 -0400
51032+++ linux-2.6.39.1/fs/xattr.c 2011-05-22 19:41:42.000000000 -0400
51033@@ -247,7 +247,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
51034 * Extended attribute SET operations
51035 */
51036 static long
51037-setxattr(struct dentry *d, const char __user *name, const void __user *value,
51038+setxattr(struct path *path, const char __user *name, const void __user *value,
51039 size_t size, int flags)
51040 {
51041 int error;
51042@@ -271,7 +271,13 @@ setxattr(struct dentry *d, const char __
51043 return PTR_ERR(kvalue);
51044 }
51045
51046- error = vfs_setxattr(d, kname, kvalue, size, flags);
51047+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
51048+ error = -EACCES;
51049+ goto out;
51050+ }
51051+
51052+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
51053+out:
51054 kfree(kvalue);
51055 return error;
51056 }
51057@@ -288,7 +294,7 @@ SYSCALL_DEFINE5(setxattr, const char __u
51058 return error;
51059 error = mnt_want_write(path.mnt);
51060 if (!error) {
51061- error = setxattr(path.dentry, name, value, size, flags);
51062+ error = setxattr(&path, name, value, size, flags);
51063 mnt_drop_write(path.mnt);
51064 }
51065 path_put(&path);
51066@@ -307,7 +313,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __
51067 return error;
51068 error = mnt_want_write(path.mnt);
51069 if (!error) {
51070- error = setxattr(path.dentry, name, value, size, flags);
51071+ error = setxattr(&path, name, value, size, flags);
51072 mnt_drop_write(path.mnt);
51073 }
51074 path_put(&path);
51075@@ -318,17 +324,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, cons
51076 const void __user *,value, size_t, size, int, flags)
51077 {
51078 struct file *f;
51079- struct dentry *dentry;
51080 int error = -EBADF;
51081
51082 f = fget(fd);
51083 if (!f)
51084 return error;
51085- dentry = f->f_path.dentry;
51086- audit_inode(NULL, dentry);
51087+ audit_inode(NULL, f->f_path.dentry);
51088 error = mnt_want_write_file(f);
51089 if (!error) {
51090- error = setxattr(dentry, name, value, size, flags);
51091+ error = setxattr(&f->f_path, name, value, size, flags);
51092 mnt_drop_write(f->f_path.mnt);
51093 }
51094 fput(f);
51095diff -urNp linux-2.6.39.1/fs/xfs/linux-2.6/xfs_ioctl32.c linux-2.6.39.1/fs/xfs/linux-2.6/xfs_ioctl32.c
51096--- linux-2.6.39.1/fs/xfs/linux-2.6/xfs_ioctl32.c 2011-05-19 00:06:34.000000000 -0400
51097+++ linux-2.6.39.1/fs/xfs/linux-2.6/xfs_ioctl32.c 2011-05-22 19:41:42.000000000 -0400
51098@@ -73,6 +73,7 @@ xfs_compat_ioc_fsgeometry_v1(
51099 xfs_fsop_geom_t fsgeo;
51100 int error;
51101
51102+ memset(&fsgeo, 0, sizeof(fsgeo));
51103 error = xfs_fs_geometry(mp, &fsgeo, 3);
51104 if (error)
51105 return -error;
51106diff -urNp linux-2.6.39.1/fs/xfs/linux-2.6/xfs_ioctl.c linux-2.6.39.1/fs/xfs/linux-2.6/xfs_ioctl.c
51107--- linux-2.6.39.1/fs/xfs/linux-2.6/xfs_ioctl.c 2011-05-19 00:06:34.000000000 -0400
51108+++ linux-2.6.39.1/fs/xfs/linux-2.6/xfs_ioctl.c 2011-05-22 19:36:32.000000000 -0400
51109@@ -128,7 +128,7 @@ xfs_find_handle(
51110 }
51111
51112 error = -EFAULT;
51113- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
51114+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
51115 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
51116 goto out_put;
51117
51118diff -urNp linux-2.6.39.1/fs/xfs/linux-2.6/xfs_iops.c linux-2.6.39.1/fs/xfs/linux-2.6/xfs_iops.c
51119--- linux-2.6.39.1/fs/xfs/linux-2.6/xfs_iops.c 2011-05-19 00:06:34.000000000 -0400
51120+++ linux-2.6.39.1/fs/xfs/linux-2.6/xfs_iops.c 2011-05-22 19:36:32.000000000 -0400
51121@@ -437,7 +437,7 @@ xfs_vn_put_link(
51122 struct nameidata *nd,
51123 void *p)
51124 {
51125- char *s = nd_get_link(nd);
51126+ const char *s = nd_get_link(nd);
51127
51128 if (!IS_ERR(s))
51129 kfree(s);
51130diff -urNp linux-2.6.39.1/fs/xfs/xfs_bmap.c linux-2.6.39.1/fs/xfs/xfs_bmap.c
51131--- linux-2.6.39.1/fs/xfs/xfs_bmap.c 2011-05-19 00:06:34.000000000 -0400
51132+++ linux-2.6.39.1/fs/xfs/xfs_bmap.c 2011-05-22 19:36:32.000000000 -0400
51133@@ -287,7 +287,7 @@ xfs_bmap_validate_ret(
51134 int nmap,
51135 int ret_nmap);
51136 #else
51137-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
51138+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
51139 #endif /* DEBUG */
51140
51141 STATIC int
51142diff -urNp linux-2.6.39.1/fs/xfs/xfs_dir2.c linux-2.6.39.1/fs/xfs/xfs_dir2.c
51143--- linux-2.6.39.1/fs/xfs/xfs_dir2.c 2011-05-19 00:06:34.000000000 -0400
51144+++ linux-2.6.39.1/fs/xfs/xfs_dir2.c 2011-05-22 19:36:32.000000000 -0400
51145@@ -85,7 +85,7 @@ xfs_ascii_ci_compname(
51146 return result;
51147 }
51148
51149-static struct xfs_nameops xfs_ascii_ci_nameops = {
51150+static const struct xfs_nameops xfs_ascii_ci_nameops = {
51151 .hashname = xfs_ascii_ci_hashname,
51152 .compname = xfs_ascii_ci_compname,
51153 };
51154diff -urNp linux-2.6.39.1/fs/xfs/xfs_dir2_sf.c linux-2.6.39.1/fs/xfs/xfs_dir2_sf.c
51155--- linux-2.6.39.1/fs/xfs/xfs_dir2_sf.c 2011-05-19 00:06:34.000000000 -0400
51156+++ linux-2.6.39.1/fs/xfs/xfs_dir2_sf.c 2011-05-22 19:36:32.000000000 -0400
51157@@ -780,7 +780,15 @@ xfs_dir2_sf_getdents(
51158 }
51159
51160 ino = xfs_dir2_sf_get_inumber(sfp, xfs_dir2_sf_inumberp(sfep));
51161- if (filldir(dirent, (char *)sfep->name, sfep->namelen,
51162+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
51163+ char name[sfep->namelen];
51164+ memcpy(name, sfep->name, sfep->namelen);
51165+ if (filldir(dirent, name, sfep->namelen,
51166+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
51167+ *offset = off & 0x7fffffff;
51168+ return 0;
51169+ }
51170+ } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
51171 off & 0x7fffffff, ino, DT_UNKNOWN)) {
51172 *offset = off & 0x7fffffff;
51173 return 0;
51174diff -urNp linux-2.6.39.1/grsecurity/gracl_alloc.c linux-2.6.39.1/grsecurity/gracl_alloc.c
51175--- linux-2.6.39.1/grsecurity/gracl_alloc.c 1969-12-31 19:00:00.000000000 -0500
51176+++ linux-2.6.39.1/grsecurity/gracl_alloc.c 2011-05-22 19:41:42.000000000 -0400
51177@@ -0,0 +1,105 @@
51178+#include <linux/kernel.h>
51179+#include <linux/mm.h>
51180+#include <linux/slab.h>
51181+#include <linux/vmalloc.h>
51182+#include <linux/gracl.h>
51183+#include <linux/grsecurity.h>
51184+
51185+static unsigned long alloc_stack_next = 1;
51186+static unsigned long alloc_stack_size = 1;
51187+static void **alloc_stack;
51188+
51189+static __inline__ int
51190+alloc_pop(void)
51191+{
51192+ if (alloc_stack_next == 1)
51193+ return 0;
51194+
51195+ kfree(alloc_stack[alloc_stack_next - 2]);
51196+
51197+ alloc_stack_next--;
51198+
51199+ return 1;
51200+}
51201+
51202+static __inline__ int
51203+alloc_push(void *buf)
51204+{
51205+ if (alloc_stack_next >= alloc_stack_size)
51206+ return 1;
51207+
51208+ alloc_stack[alloc_stack_next - 1] = buf;
51209+
51210+ alloc_stack_next++;
51211+
51212+ return 0;
51213+}
51214+
51215+void *
51216+acl_alloc(unsigned long len)
51217+{
51218+ void *ret = NULL;
51219+
51220+ if (!len || len > PAGE_SIZE)
51221+ goto out;
51222+
51223+ ret = kmalloc(len, GFP_KERNEL);
51224+
51225+ if (ret) {
51226+ if (alloc_push(ret)) {
51227+ kfree(ret);
51228+ ret = NULL;
51229+ }
51230+ }
51231+
51232+out:
51233+ return ret;
51234+}
51235+
51236+void *
51237+acl_alloc_num(unsigned long num, unsigned long len)
51238+{
51239+ if (!len || (num > (PAGE_SIZE / len)))
51240+ return NULL;
51241+
51242+ return acl_alloc(num * len);
51243+}
51244+
51245+void
51246+acl_free_all(void)
51247+{
51248+ if (gr_acl_is_enabled() || !alloc_stack)
51249+ return;
51250+
51251+ while (alloc_pop()) ;
51252+
51253+ if (alloc_stack) {
51254+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
51255+ kfree(alloc_stack);
51256+ else
51257+ vfree(alloc_stack);
51258+ }
51259+
51260+ alloc_stack = NULL;
51261+ alloc_stack_size = 1;
51262+ alloc_stack_next = 1;
51263+
51264+ return;
51265+}
51266+
51267+int
51268+acl_alloc_stack_init(unsigned long size)
51269+{
51270+ if ((size * sizeof (void *)) <= PAGE_SIZE)
51271+ alloc_stack =
51272+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
51273+ else
51274+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
51275+
51276+ alloc_stack_size = size;
51277+
51278+ if (!alloc_stack)
51279+ return 0;
51280+ else
51281+ return 1;
51282+}
51283diff -urNp linux-2.6.39.1/grsecurity/gracl.c linux-2.6.39.1/grsecurity/gracl.c
51284--- linux-2.6.39.1/grsecurity/gracl.c 1969-12-31 19:00:00.000000000 -0500
51285+++ linux-2.6.39.1/grsecurity/gracl.c 2011-06-11 16:26:18.000000000 -0400
51286@@ -0,0 +1,4109 @@
51287+#include <linux/kernel.h>
51288+#include <linux/module.h>
51289+#include <linux/sched.h>
51290+#include <linux/mm.h>
51291+#include <linux/file.h>
51292+#include <linux/fs.h>
51293+#include <linux/namei.h>
51294+#include <linux/mount.h>
51295+#include <linux/tty.h>
51296+#include <linux/proc_fs.h>
51297+#include <linux/lglock.h>
51298+#include <linux/slab.h>
51299+#include <linux/vmalloc.h>
51300+#include <linux/types.h>
51301+#include <linux/sysctl.h>
51302+#include <linux/netdevice.h>
51303+#include <linux/ptrace.h>
51304+#include <linux/gracl.h>
51305+#include <linux/gralloc.h>
51306+#include <linux/grsecurity.h>
51307+#include <linux/grinternal.h>
51308+#include <linux/pid_namespace.h>
51309+#include <linux/fdtable.h>
51310+#include <linux/percpu.h>
51311+
51312+#include <asm/uaccess.h>
51313+#include <asm/errno.h>
51314+#include <asm/mman.h>
51315+
51316+static struct acl_role_db acl_role_set;
51317+static struct name_db name_set;
51318+static struct inodev_db inodev_set;
51319+
51320+/* for keeping track of userspace pointers used for subjects, so we
51321+ can share references in the kernel as well
51322+*/
51323+
51324+static struct path real_root;
51325+
51326+static struct acl_subj_map_db subj_map_set;
51327+
51328+static struct acl_role_label *default_role;
51329+
51330+static struct acl_role_label *role_list;
51331+
51332+static u16 acl_sp_role_value;
51333+
51334+extern char *gr_shared_page[4];
51335+static DEFINE_MUTEX(gr_dev_mutex);
51336+DEFINE_RWLOCK(gr_inode_lock);
51337+
51338+struct gr_arg *gr_usermode;
51339+
51340+static unsigned int gr_status __read_only = GR_STATUS_INIT;
51341+
51342+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
51343+extern void gr_clear_learn_entries(void);
51344+
51345+#ifdef CONFIG_GRKERNSEC_RESLOG
51346+extern void gr_log_resource(const struct task_struct *task,
51347+ const int res, const unsigned long wanted, const int gt);
51348+#endif
51349+
51350+unsigned char *gr_system_salt;
51351+unsigned char *gr_system_sum;
51352+
51353+static struct sprole_pw **acl_special_roles = NULL;
51354+static __u16 num_sprole_pws = 0;
51355+
51356+static struct acl_role_label *kernel_role = NULL;
51357+
51358+static unsigned int gr_auth_attempts = 0;
51359+static unsigned long gr_auth_expires = 0UL;
51360+
51361+#ifdef CONFIG_NET
51362+extern struct vfsmount *sock_mnt;
51363+#endif
51364+
51365+extern struct vfsmount *pipe_mnt;
51366+extern struct vfsmount *shm_mnt;
51367+#ifdef CONFIG_HUGETLBFS
51368+extern struct vfsmount *hugetlbfs_vfsmount;
51369+#endif
51370+
51371+static struct acl_object_label *fakefs_obj_rw;
51372+static struct acl_object_label *fakefs_obj_rwx;
51373+
51374+extern int gr_init_uidset(void);
51375+extern void gr_free_uidset(void);
51376+extern void gr_remove_uid(uid_t uid);
51377+extern int gr_find_uid(uid_t uid);
51378+
51379+DECLARE_BRLOCK(vfsmount_lock);
51380+
51381+__inline__ int
51382+gr_acl_is_enabled(void)
51383+{
51384+ return (gr_status & GR_READY);
51385+}
51386+
51387+#ifdef CONFIG_BTRFS_FS
51388+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
51389+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
51390+#endif
51391+
51392+static inline dev_t __get_dev(const struct dentry *dentry)
51393+{
51394+#ifdef CONFIG_BTRFS_FS
51395+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
51396+ return get_btrfs_dev_from_inode(dentry->d_inode);
51397+ else
51398+#endif
51399+ return dentry->d_inode->i_sb->s_dev;
51400+}
51401+
51402+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
51403+{
51404+ return __get_dev(dentry);
51405+}
51406+
51407+static char gr_task_roletype_to_char(struct task_struct *task)
51408+{
51409+ switch (task->role->roletype &
51410+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
51411+ GR_ROLE_SPECIAL)) {
51412+ case GR_ROLE_DEFAULT:
51413+ return 'D';
51414+ case GR_ROLE_USER:
51415+ return 'U';
51416+ case GR_ROLE_GROUP:
51417+ return 'G';
51418+ case GR_ROLE_SPECIAL:
51419+ return 'S';
51420+ }
51421+
51422+ return 'X';
51423+}
51424+
51425+char gr_roletype_to_char(void)
51426+{
51427+ return gr_task_roletype_to_char(current);
51428+}
51429+
51430+__inline__ int
51431+gr_acl_tpe_check(void)
51432+{
51433+ if (unlikely(!(gr_status & GR_READY)))
51434+ return 0;
51435+ if (current->role->roletype & GR_ROLE_TPE)
51436+ return 1;
51437+ else
51438+ return 0;
51439+}
51440+
51441+int
51442+gr_handle_rawio(const struct inode *inode)
51443+{
51444+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
51445+ if (inode && S_ISBLK(inode->i_mode) &&
51446+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
51447+ !capable(CAP_SYS_RAWIO))
51448+ return 1;
51449+#endif
51450+ return 0;
51451+}
51452+
51453+static int
51454+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
51455+{
51456+ if (likely(lena != lenb))
51457+ return 0;
51458+
51459+ return !memcmp(a, b, lena);
51460+}
51461+
51462+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
51463+{
51464+ *buflen -= namelen;
51465+ if (*buflen < 0)
51466+ return -ENAMETOOLONG;
51467+ *buffer -= namelen;
51468+ memcpy(*buffer, str, namelen);
51469+ return 0;
51470+}
51471+
51472+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
51473+{
51474+ return prepend(buffer, buflen, name->name, name->len);
51475+}
51476+
51477+static int prepend_path(const struct path *path, struct path *root,
51478+ char **buffer, int *buflen)
51479+{
51480+ struct dentry *dentry = path->dentry;
51481+ struct vfsmount *vfsmnt = path->mnt;
51482+ bool slash = false;
51483+ int error = 0;
51484+
51485+ while (dentry != root->dentry || vfsmnt != root->mnt) {
51486+ struct dentry * parent;
51487+
51488+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
51489+ /* Global root? */
51490+ if (vfsmnt->mnt_parent == vfsmnt) {
51491+ goto out;
51492+ }
51493+ dentry = vfsmnt->mnt_mountpoint;
51494+ vfsmnt = vfsmnt->mnt_parent;
51495+ continue;
51496+ }
51497+ parent = dentry->d_parent;
51498+ prefetch(parent);
51499+ spin_lock(&dentry->d_lock);
51500+ error = prepend_name(buffer, buflen, &dentry->d_name);
51501+ spin_unlock(&dentry->d_lock);
51502+ if (!error)
51503+ error = prepend(buffer, buflen, "/", 1);
51504+ if (error)
51505+ break;
51506+
51507+ slash = true;
51508+ dentry = parent;
51509+ }
51510+
51511+out:
51512+ if (!error && !slash)
51513+ error = prepend(buffer, buflen, "/", 1);
51514+
51515+ return error;
51516+}
51517+
51518+/* this must be called with vfsmount_lock and rename_lock held */
51519+
51520+static char *__our_d_path(const struct path *path, struct path *root,
51521+ char *buf, int buflen)
51522+{
51523+ char *res = buf + buflen;
51524+ int error;
51525+
51526+ prepend(&res, &buflen, "\0", 1);
51527+ error = prepend_path(path, root, &res, &buflen);
51528+ if (error)
51529+ return ERR_PTR(error);
51530+
51531+ return res;
51532+}
51533+
51534+static char *
51535+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
51536+{
51537+ char *retval;
51538+
51539+ retval = __our_d_path(path, root, buf, buflen);
51540+ if (unlikely(IS_ERR(retval)))
51541+ retval = strcpy(buf, "<path too long>");
51542+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
51543+ retval[1] = '\0';
51544+
51545+ return retval;
51546+}
51547+
51548+static char *
51549+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51550+ char *buf, int buflen)
51551+{
51552+ struct path path;
51553+ char *res;
51554+
51555+ path.dentry = (struct dentry *)dentry;
51556+ path.mnt = (struct vfsmount *)vfsmnt;
51557+
51558+ /* we can use real_root.dentry, real_root.mnt, because this is only called
51559+ by the RBAC system */
51560+ res = gen_full_path(&path, &real_root, buf, buflen);
51561+
51562+ return res;
51563+}
51564+
51565+static char *
51566+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51567+ char *buf, int buflen)
51568+{
51569+ char *res;
51570+ struct path path;
51571+ struct path root;
51572+ struct task_struct *reaper = &init_task;
51573+
51574+ path.dentry = (struct dentry *)dentry;
51575+ path.mnt = (struct vfsmount *)vfsmnt;
51576+
51577+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
51578+ get_fs_root(reaper->fs, &root);
51579+
51580+ write_seqlock(&rename_lock);
51581+ br_read_lock(vfsmount_lock);
51582+ res = gen_full_path(&path, &root, buf, buflen);
51583+ br_read_unlock(vfsmount_lock);
51584+ write_sequnlock(&rename_lock);
51585+
51586+ path_put(&root);
51587+ return res;
51588+}
51589+
51590+static char *
51591+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51592+{
51593+ char *ret;
51594+ write_seqlock(&rename_lock);
51595+ br_read_lock(vfsmount_lock);
51596+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51597+ PAGE_SIZE);
51598+ br_read_unlock(vfsmount_lock);
51599+ write_sequnlock(&rename_lock);
51600+ return ret;
51601+}
51602+
51603+char *
51604+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
51605+{
51606+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51607+ PAGE_SIZE);
51608+}
51609+
51610+char *
51611+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
51612+{
51613+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
51614+ PAGE_SIZE);
51615+}
51616+
51617+char *
51618+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
51619+{
51620+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
51621+ PAGE_SIZE);
51622+}
51623+
51624+char *
51625+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
51626+{
51627+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
51628+ PAGE_SIZE);
51629+}
51630+
51631+char *
51632+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
51633+{
51634+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
51635+ PAGE_SIZE);
51636+}
51637+
51638+__inline__ __u32
51639+to_gr_audit(const __u32 reqmode)
51640+{
51641+ /* masks off auditable permission flags, then shifts them to create
51642+ auditing flags, and adds the special case of append auditing if
51643+ we're requesting write */
51644+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
51645+}
51646+
51647+struct acl_subject_label *
51648+lookup_subject_map(const struct acl_subject_label *userp)
51649+{
51650+ unsigned int index = shash(userp, subj_map_set.s_size);
51651+ struct subject_map *match;
51652+
51653+ match = subj_map_set.s_hash[index];
51654+
51655+ while (match && match->user != userp)
51656+ match = match->next;
51657+
51658+ if (match != NULL)
51659+ return match->kernel;
51660+ else
51661+ return NULL;
51662+}
51663+
51664+static void
51665+insert_subj_map_entry(struct subject_map *subjmap)
51666+{
51667+ unsigned int index = shash(subjmap->user, subj_map_set.s_size);
51668+ struct subject_map **curr;
51669+
51670+ subjmap->prev = NULL;
51671+
51672+ curr = &subj_map_set.s_hash[index];
51673+ if (*curr != NULL)
51674+ (*curr)->prev = subjmap;
51675+
51676+ subjmap->next = *curr;
51677+ *curr = subjmap;
51678+
51679+ return;
51680+}
51681+
51682+static struct acl_role_label *
51683+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
51684+ const gid_t gid)
51685+{
51686+ unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
51687+ struct acl_role_label *match;
51688+ struct role_allowed_ip *ipp;
51689+ unsigned int x;
51690+ u32 curr_ip = task->signal->curr_ip;
51691+
51692+ task->signal->saved_ip = curr_ip;
51693+
51694+ match = acl_role_set.r_hash[index];
51695+
51696+ while (match) {
51697+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
51698+ for (x = 0; x < match->domain_child_num; x++) {
51699+ if (match->domain_children[x] == uid)
51700+ goto found;
51701+ }
51702+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
51703+ break;
51704+ match = match->next;
51705+ }
51706+found:
51707+ if (match == NULL) {
51708+ try_group:
51709+ index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
51710+ match = acl_role_set.r_hash[index];
51711+
51712+ while (match) {
51713+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
51714+ for (x = 0; x < match->domain_child_num; x++) {
51715+ if (match->domain_children[x] == gid)
51716+ goto found2;
51717+ }
51718+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
51719+ break;
51720+ match = match->next;
51721+ }
51722+found2:
51723+ if (match == NULL)
51724+ match = default_role;
51725+ if (match->allowed_ips == NULL)
51726+ return match;
51727+ else {
51728+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51729+ if (likely
51730+ ((ntohl(curr_ip) & ipp->netmask) ==
51731+ (ntohl(ipp->addr) & ipp->netmask)))
51732+ return match;
51733+ }
51734+ match = default_role;
51735+ }
51736+ } else if (match->allowed_ips == NULL) {
51737+ return match;
51738+ } else {
51739+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51740+ if (likely
51741+ ((ntohl(curr_ip) & ipp->netmask) ==
51742+ (ntohl(ipp->addr) & ipp->netmask)))
51743+ return match;
51744+ }
51745+ goto try_group;
51746+ }
51747+
51748+ return match;
51749+}
51750+
51751+struct acl_subject_label *
51752+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
51753+ const struct acl_role_label *role)
51754+{
51755+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
51756+ struct acl_subject_label *match;
51757+
51758+ match = role->subj_hash[index];
51759+
51760+ while (match && (match->inode != ino || match->device != dev ||
51761+ (match->mode & GR_DELETED))) {
51762+ match = match->next;
51763+ }
51764+
51765+ if (match && !(match->mode & GR_DELETED))
51766+ return match;
51767+ else
51768+ return NULL;
51769+}
51770+
51771+struct acl_subject_label *
51772+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
51773+ const struct acl_role_label *role)
51774+{
51775+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
51776+ struct acl_subject_label *match;
51777+
51778+ match = role->subj_hash[index];
51779+
51780+ while (match && (match->inode != ino || match->device != dev ||
51781+ !(match->mode & GR_DELETED))) {
51782+ match = match->next;
51783+ }
51784+
51785+ if (match && (match->mode & GR_DELETED))
51786+ return match;
51787+ else
51788+ return NULL;
51789+}
51790+
51791+static struct acl_object_label *
51792+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
51793+ const struct acl_subject_label *subj)
51794+{
51795+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51796+ struct acl_object_label *match;
51797+
51798+ match = subj->obj_hash[index];
51799+
51800+ while (match && (match->inode != ino || match->device != dev ||
51801+ (match->mode & GR_DELETED))) {
51802+ match = match->next;
51803+ }
51804+
51805+ if (match && !(match->mode & GR_DELETED))
51806+ return match;
51807+ else
51808+ return NULL;
51809+}
51810+
51811+static struct acl_object_label *
51812+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
51813+ const struct acl_subject_label *subj)
51814+{
51815+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51816+ struct acl_object_label *match;
51817+
51818+ match = subj->obj_hash[index];
51819+
51820+ while (match && (match->inode != ino || match->device != dev ||
51821+ !(match->mode & GR_DELETED))) {
51822+ match = match->next;
51823+ }
51824+
51825+ if (match && (match->mode & GR_DELETED))
51826+ return match;
51827+
51828+ match = subj->obj_hash[index];
51829+
51830+ while (match && (match->inode != ino || match->device != dev ||
51831+ (match->mode & GR_DELETED))) {
51832+ match = match->next;
51833+ }
51834+
51835+ if (match && !(match->mode & GR_DELETED))
51836+ return match;
51837+ else
51838+ return NULL;
51839+}
51840+
51841+static struct name_entry *
51842+lookup_name_entry(const char *name)
51843+{
51844+ unsigned int len = strlen(name);
51845+ unsigned int key = full_name_hash(name, len);
51846+ unsigned int index = key % name_set.n_size;
51847+ struct name_entry *match;
51848+
51849+ match = name_set.n_hash[index];
51850+
51851+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
51852+ match = match->next;
51853+
51854+ return match;
51855+}
51856+
51857+static struct name_entry *
51858+lookup_name_entry_create(const char *name)
51859+{
51860+ unsigned int len = strlen(name);
51861+ unsigned int key = full_name_hash(name, len);
51862+ unsigned int index = key % name_set.n_size;
51863+ struct name_entry *match;
51864+
51865+ match = name_set.n_hash[index];
51866+
51867+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
51868+ !match->deleted))
51869+ match = match->next;
51870+
51871+ if (match && match->deleted)
51872+ return match;
51873+
51874+ match = name_set.n_hash[index];
51875+
51876+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
51877+ match->deleted))
51878+ match = match->next;
51879+
51880+ if (match && !match->deleted)
51881+ return match;
51882+ else
51883+ return NULL;
51884+}
51885+
51886+static struct inodev_entry *
51887+lookup_inodev_entry(const ino_t ino, const dev_t dev)
51888+{
51889+ unsigned int index = fhash(ino, dev, inodev_set.i_size);
51890+ struct inodev_entry *match;
51891+
51892+ match = inodev_set.i_hash[index];
51893+
51894+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
51895+ match = match->next;
51896+
51897+ return match;
51898+}
51899+
51900+static void
51901+insert_inodev_entry(struct inodev_entry *entry)
51902+{
51903+ unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
51904+ inodev_set.i_size);
51905+ struct inodev_entry **curr;
51906+
51907+ entry->prev = NULL;
51908+
51909+ curr = &inodev_set.i_hash[index];
51910+ if (*curr != NULL)
51911+ (*curr)->prev = entry;
51912+
51913+ entry->next = *curr;
51914+ *curr = entry;
51915+
51916+ return;
51917+}
51918+
51919+static void
51920+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
51921+{
51922+ unsigned int index =
51923+ rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
51924+ struct acl_role_label **curr;
51925+ struct acl_role_label *tmp;
51926+
51927+ curr = &acl_role_set.r_hash[index];
51928+
51929+ /* if role was already inserted due to domains and already has
51930+ a role in the same bucket as it attached, then we need to
51931+ combine these two buckets
51932+ */
51933+ if (role->next) {
51934+ tmp = role->next;
51935+ while (tmp->next)
51936+ tmp = tmp->next;
51937+ tmp->next = *curr;
51938+ } else
51939+ role->next = *curr;
51940+ *curr = role;
51941+
51942+ return;
51943+}
51944+
51945+static void
51946+insert_acl_role_label(struct acl_role_label *role)
51947+{
51948+ int i;
51949+
51950+ if (role_list == NULL) {
51951+ role_list = role;
51952+ role->prev = NULL;
51953+ } else {
51954+ role->prev = role_list;
51955+ role_list = role;
51956+ }
51957+
51958+ /* used for hash chains */
51959+ role->next = NULL;
51960+
51961+ if (role->roletype & GR_ROLE_DOMAIN) {
51962+ for (i = 0; i < role->domain_child_num; i++)
51963+ __insert_acl_role_label(role, role->domain_children[i]);
51964+ } else
51965+ __insert_acl_role_label(role, role->uidgid);
51966+}
51967+
51968+static int
51969+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
51970+{
51971+ struct name_entry **curr, *nentry;
51972+ struct inodev_entry *ientry;
51973+ unsigned int len = strlen(name);
51974+ unsigned int key = full_name_hash(name, len);
51975+ unsigned int index = key % name_set.n_size;
51976+
51977+ curr = &name_set.n_hash[index];
51978+
51979+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
51980+ curr = &((*curr)->next);
51981+
51982+ if (*curr != NULL)
51983+ return 1;
51984+
51985+ nentry = acl_alloc(sizeof (struct name_entry));
51986+ if (nentry == NULL)
51987+ return 0;
51988+ ientry = acl_alloc(sizeof (struct inodev_entry));
51989+ if (ientry == NULL)
51990+ return 0;
51991+ ientry->nentry = nentry;
51992+
51993+ nentry->key = key;
51994+ nentry->name = name;
51995+ nentry->inode = inode;
51996+ nentry->device = device;
51997+ nentry->len = len;
51998+ nentry->deleted = deleted;
51999+
52000+ nentry->prev = NULL;
52001+ curr = &name_set.n_hash[index];
52002+ if (*curr != NULL)
52003+ (*curr)->prev = nentry;
52004+ nentry->next = *curr;
52005+ *curr = nentry;
52006+
52007+ /* insert us into the table searchable by inode/dev */
52008+ insert_inodev_entry(ientry);
52009+
52010+ return 1;
52011+}
52012+
52013+static void
52014+insert_acl_obj_label(struct acl_object_label *obj,
52015+ struct acl_subject_label *subj)
52016+{
52017+ unsigned int index =
52018+ fhash(obj->inode, obj->device, subj->obj_hash_size);
52019+ struct acl_object_label **curr;
52020+
52021+
52022+ obj->prev = NULL;
52023+
52024+ curr = &subj->obj_hash[index];
52025+ if (*curr != NULL)
52026+ (*curr)->prev = obj;
52027+
52028+ obj->next = *curr;
52029+ *curr = obj;
52030+
52031+ return;
52032+}
52033+
52034+static void
52035+insert_acl_subj_label(struct acl_subject_label *obj,
52036+ struct acl_role_label *role)
52037+{
52038+ unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
52039+ struct acl_subject_label **curr;
52040+
52041+ obj->prev = NULL;
52042+
52043+ curr = &role->subj_hash[index];
52044+ if (*curr != NULL)
52045+ (*curr)->prev = obj;
52046+
52047+ obj->next = *curr;
52048+ *curr = obj;
52049+
52050+ return;
52051+}
52052+
52053+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
52054+
52055+static void *
52056+create_table(__u32 * len, int elementsize)
52057+{
52058+ unsigned int table_sizes[] = {
52059+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
52060+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
52061+ 4194301, 8388593, 16777213, 33554393, 67108859
52062+ };
52063+ void *newtable = NULL;
52064+ unsigned int pwr = 0;
52065+
52066+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
52067+ table_sizes[pwr] <= *len)
52068+ pwr++;
52069+
52070+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
52071+ return newtable;
52072+
52073+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
52074+ newtable =
52075+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
52076+ else
52077+ newtable = vmalloc(table_sizes[pwr] * elementsize);
52078+
52079+ *len = table_sizes[pwr];
52080+
52081+ return newtable;
52082+}
52083+
52084+static int
52085+init_variables(const struct gr_arg *arg)
52086+{
52087+ struct task_struct *reaper = &init_task;
52088+ unsigned int stacksize;
52089+
52090+ subj_map_set.s_size = arg->role_db.num_subjects;
52091+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
52092+ name_set.n_size = arg->role_db.num_objects;
52093+ inodev_set.i_size = arg->role_db.num_objects;
52094+
52095+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
52096+ !name_set.n_size || !inodev_set.i_size)
52097+ return 1;
52098+
52099+ if (!gr_init_uidset())
52100+ return 1;
52101+
52102+ /* set up the stack that holds allocation info */
52103+
52104+ stacksize = arg->role_db.num_pointers + 5;
52105+
52106+ if (!acl_alloc_stack_init(stacksize))
52107+ return 1;
52108+
52109+ /* grab reference for the real root dentry and vfsmount */
52110+ get_fs_root(reaper->fs, &real_root);
52111+
52112+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52113+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
52114+#endif
52115+
52116+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
52117+ if (fakefs_obj_rw == NULL)
52118+ return 1;
52119+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
52120+
52121+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
52122+ if (fakefs_obj_rwx == NULL)
52123+ return 1;
52124+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
52125+
52126+ subj_map_set.s_hash =
52127+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
52128+ acl_role_set.r_hash =
52129+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
52130+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
52131+ inodev_set.i_hash =
52132+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
52133+
52134+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
52135+ !name_set.n_hash || !inodev_set.i_hash)
52136+ return 1;
52137+
52138+ memset(subj_map_set.s_hash, 0,
52139+ sizeof(struct subject_map *) * subj_map_set.s_size);
52140+ memset(acl_role_set.r_hash, 0,
52141+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
52142+ memset(name_set.n_hash, 0,
52143+ sizeof (struct name_entry *) * name_set.n_size);
52144+ memset(inodev_set.i_hash, 0,
52145+ sizeof (struct inodev_entry *) * inodev_set.i_size);
52146+
52147+ return 0;
52148+}
52149+
52150+/* free information not needed after startup
52151+ currently contains user->kernel pointer mappings for subjects
52152+*/
52153+
52154+static void
52155+free_init_variables(void)
52156+{
52157+ __u32 i;
52158+
52159+ if (subj_map_set.s_hash) {
52160+ for (i = 0; i < subj_map_set.s_size; i++) {
52161+ if (subj_map_set.s_hash[i]) {
52162+ kfree(subj_map_set.s_hash[i]);
52163+ subj_map_set.s_hash[i] = NULL;
52164+ }
52165+ }
52166+
52167+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
52168+ PAGE_SIZE)
52169+ kfree(subj_map_set.s_hash);
52170+ else
52171+ vfree(subj_map_set.s_hash);
52172+ }
52173+
52174+ return;
52175+}
52176+
52177+static void
52178+free_variables(void)
52179+{
52180+ struct acl_subject_label *s;
52181+ struct acl_role_label *r;
52182+ struct task_struct *task, *task2;
52183+ unsigned int x;
52184+
52185+ gr_clear_learn_entries();
52186+
52187+ read_lock(&tasklist_lock);
52188+ do_each_thread(task2, task) {
52189+ task->acl_sp_role = 0;
52190+ task->acl_role_id = 0;
52191+ task->acl = NULL;
52192+ task->role = NULL;
52193+ } while_each_thread(task2, task);
52194+ read_unlock(&tasklist_lock);
52195+
52196+ /* release the reference to the real root dentry and vfsmount */
52197+ path_put(&real_root);
52198+
52199+ /* free all object hash tables */
52200+
52201+ FOR_EACH_ROLE_START(r)
52202+ if (r->subj_hash == NULL)
52203+ goto next_role;
52204+ FOR_EACH_SUBJECT_START(r, s, x)
52205+ if (s->obj_hash == NULL)
52206+ break;
52207+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52208+ kfree(s->obj_hash);
52209+ else
52210+ vfree(s->obj_hash);
52211+ FOR_EACH_SUBJECT_END(s, x)
52212+ FOR_EACH_NESTED_SUBJECT_START(r, s)
52213+ if (s->obj_hash == NULL)
52214+ break;
52215+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52216+ kfree(s->obj_hash);
52217+ else
52218+ vfree(s->obj_hash);
52219+ FOR_EACH_NESTED_SUBJECT_END(s)
52220+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
52221+ kfree(r->subj_hash);
52222+ else
52223+ vfree(r->subj_hash);
52224+ r->subj_hash = NULL;
52225+next_role:
52226+ FOR_EACH_ROLE_END(r)
52227+
52228+ acl_free_all();
52229+
52230+ if (acl_role_set.r_hash) {
52231+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
52232+ PAGE_SIZE)
52233+ kfree(acl_role_set.r_hash);
52234+ else
52235+ vfree(acl_role_set.r_hash);
52236+ }
52237+ if (name_set.n_hash) {
52238+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
52239+ PAGE_SIZE)
52240+ kfree(name_set.n_hash);
52241+ else
52242+ vfree(name_set.n_hash);
52243+ }
52244+
52245+ if (inodev_set.i_hash) {
52246+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
52247+ PAGE_SIZE)
52248+ kfree(inodev_set.i_hash);
52249+ else
52250+ vfree(inodev_set.i_hash);
52251+ }
52252+
52253+ gr_free_uidset();
52254+
52255+ memset(&name_set, 0, sizeof (struct name_db));
52256+ memset(&inodev_set, 0, sizeof (struct inodev_db));
52257+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
52258+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
52259+
52260+ default_role = NULL;
52261+ role_list = NULL;
52262+
52263+ return;
52264+}
52265+
52266+static __u32
52267+count_user_objs(struct acl_object_label *userp)
52268+{
52269+ struct acl_object_label o_tmp;
52270+ __u32 num = 0;
52271+
52272+ while (userp) {
52273+ if (copy_from_user(&o_tmp, userp,
52274+ sizeof (struct acl_object_label)))
52275+ break;
52276+
52277+ userp = o_tmp.prev;
52278+ num++;
52279+ }
52280+
52281+ return num;
52282+}
52283+
52284+static struct acl_subject_label *
52285+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
52286+
52287+static int
52288+copy_user_glob(struct acl_object_label *obj)
52289+{
52290+ struct acl_object_label *g_tmp, **guser;
52291+ unsigned int len;
52292+ char *tmp;
52293+
52294+ if (obj->globbed == NULL)
52295+ return 0;
52296+
52297+ guser = &obj->globbed;
52298+ while (*guser) {
52299+ g_tmp = (struct acl_object_label *)
52300+ acl_alloc(sizeof (struct acl_object_label));
52301+ if (g_tmp == NULL)
52302+ return -ENOMEM;
52303+
52304+ if (copy_from_user(g_tmp, *guser,
52305+ sizeof (struct acl_object_label)))
52306+ return -EFAULT;
52307+
52308+ len = strnlen_user(g_tmp->filename, PATH_MAX);
52309+
52310+ if (!len || len >= PATH_MAX)
52311+ return -EINVAL;
52312+
52313+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52314+ return -ENOMEM;
52315+
52316+ if (copy_from_user(tmp, g_tmp->filename, len))
52317+ return -EFAULT;
52318+ tmp[len-1] = '\0';
52319+ g_tmp->filename = tmp;
52320+
52321+ *guser = g_tmp;
52322+ guser = &(g_tmp->next);
52323+ }
52324+
52325+ return 0;
52326+}
52327+
52328+static int
52329+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
52330+ struct acl_role_label *role)
52331+{
52332+ struct acl_object_label *o_tmp;
52333+ unsigned int len;
52334+ int ret;
52335+ char *tmp;
52336+
52337+ while (userp) {
52338+ if ((o_tmp = (struct acl_object_label *)
52339+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
52340+ return -ENOMEM;
52341+
52342+ if (copy_from_user(o_tmp, userp,
52343+ sizeof (struct acl_object_label)))
52344+ return -EFAULT;
52345+
52346+ userp = o_tmp->prev;
52347+
52348+ len = strnlen_user(o_tmp->filename, PATH_MAX);
52349+
52350+ if (!len || len >= PATH_MAX)
52351+ return -EINVAL;
52352+
52353+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52354+ return -ENOMEM;
52355+
52356+ if (copy_from_user(tmp, o_tmp->filename, len))
52357+ return -EFAULT;
52358+ tmp[len-1] = '\0';
52359+ o_tmp->filename = tmp;
52360+
52361+ insert_acl_obj_label(o_tmp, subj);
52362+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
52363+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
52364+ return -ENOMEM;
52365+
52366+ ret = copy_user_glob(o_tmp);
52367+ if (ret)
52368+ return ret;
52369+
52370+ if (o_tmp->nested) {
52371+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
52372+ if (IS_ERR(o_tmp->nested))
52373+ return PTR_ERR(o_tmp->nested);
52374+
52375+ /* insert into nested subject list */
52376+ o_tmp->nested->next = role->hash->first;
52377+ role->hash->first = o_tmp->nested;
52378+ }
52379+ }
52380+
52381+ return 0;
52382+}
52383+
52384+static __u32
52385+count_user_subjs(struct acl_subject_label *userp)
52386+{
52387+ struct acl_subject_label s_tmp;
52388+ __u32 num = 0;
52389+
52390+ while (userp) {
52391+ if (copy_from_user(&s_tmp, userp,
52392+ sizeof (struct acl_subject_label)))
52393+ break;
52394+
52395+ userp = s_tmp.prev;
52396+ /* do not count nested subjects against this count, since
52397+ they are not included in the hash table, but are
52398+ attached to objects. We have already counted
52399+ the subjects in userspace for the allocation
52400+ stack
52401+ */
52402+ if (!(s_tmp.mode & GR_NESTED))
52403+ num++;
52404+ }
52405+
52406+ return num;
52407+}
52408+
52409+static int
52410+copy_user_allowedips(struct acl_role_label *rolep)
52411+{
52412+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
52413+
52414+ ruserip = rolep->allowed_ips;
52415+
52416+ while (ruserip) {
52417+ rlast = rtmp;
52418+
52419+ if ((rtmp = (struct role_allowed_ip *)
52420+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
52421+ return -ENOMEM;
52422+
52423+ if (copy_from_user(rtmp, ruserip,
52424+ sizeof (struct role_allowed_ip)))
52425+ return -EFAULT;
52426+
52427+ ruserip = rtmp->prev;
52428+
52429+ if (!rlast) {
52430+ rtmp->prev = NULL;
52431+ rolep->allowed_ips = rtmp;
52432+ } else {
52433+ rlast->next = rtmp;
52434+ rtmp->prev = rlast;
52435+ }
52436+
52437+ if (!ruserip)
52438+ rtmp->next = NULL;
52439+ }
52440+
52441+ return 0;
52442+}
52443+
52444+static int
52445+copy_user_transitions(struct acl_role_label *rolep)
52446+{
52447+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
52448+
52449+ unsigned int len;
52450+ char *tmp;
52451+
52452+ rusertp = rolep->transitions;
52453+
52454+ while (rusertp) {
52455+ rlast = rtmp;
52456+
52457+ if ((rtmp = (struct role_transition *)
52458+ acl_alloc(sizeof (struct role_transition))) == NULL)
52459+ return -ENOMEM;
52460+
52461+ if (copy_from_user(rtmp, rusertp,
52462+ sizeof (struct role_transition)))
52463+ return -EFAULT;
52464+
52465+ rusertp = rtmp->prev;
52466+
52467+ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
52468+
52469+ if (!len || len >= GR_SPROLE_LEN)
52470+ return -EINVAL;
52471+
52472+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52473+ return -ENOMEM;
52474+
52475+ if (copy_from_user(tmp, rtmp->rolename, len))
52476+ return -EFAULT;
52477+ tmp[len-1] = '\0';
52478+ rtmp->rolename = tmp;
52479+
52480+ if (!rlast) {
52481+ rtmp->prev = NULL;
52482+ rolep->transitions = rtmp;
52483+ } else {
52484+ rlast->next = rtmp;
52485+ rtmp->prev = rlast;
52486+ }
52487+
52488+ if (!rusertp)
52489+ rtmp->next = NULL;
52490+ }
52491+
52492+ return 0;
52493+}
52494+
52495+static struct acl_subject_label *
52496+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
52497+{
52498+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
52499+ unsigned int len;
52500+ char *tmp;
52501+ __u32 num_objs;
52502+ struct acl_ip_label **i_tmp, *i_utmp2;
52503+ struct gr_hash_struct ghash;
52504+ struct subject_map *subjmap;
52505+ unsigned int i_num;
52506+ int err;
52507+
52508+ s_tmp = lookup_subject_map(userp);
52509+
52510+ /* we've already copied this subject into the kernel, just return
52511+ the reference to it, and don't copy it over again
52512+ */
52513+ if (s_tmp)
52514+ return(s_tmp);
52515+
52516+ if ((s_tmp = (struct acl_subject_label *)
52517+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
52518+ return ERR_PTR(-ENOMEM);
52519+
52520+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
52521+ if (subjmap == NULL)
52522+ return ERR_PTR(-ENOMEM);
52523+
52524+ subjmap->user = userp;
52525+ subjmap->kernel = s_tmp;
52526+ insert_subj_map_entry(subjmap);
52527+
52528+ if (copy_from_user(s_tmp, userp,
52529+ sizeof (struct acl_subject_label)))
52530+ return ERR_PTR(-EFAULT);
52531+
52532+ len = strnlen_user(s_tmp->filename, PATH_MAX);
52533+
52534+ if (!len || len >= PATH_MAX)
52535+ return ERR_PTR(-EINVAL);
52536+
52537+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52538+ return ERR_PTR(-ENOMEM);
52539+
52540+ if (copy_from_user(tmp, s_tmp->filename, len))
52541+ return ERR_PTR(-EFAULT);
52542+ tmp[len-1] = '\0';
52543+ s_tmp->filename = tmp;
52544+
52545+ if (!strcmp(s_tmp->filename, "/"))
52546+ role->root_label = s_tmp;
52547+
52548+ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
52549+ return ERR_PTR(-EFAULT);
52550+
52551+ /* copy user and group transition tables */
52552+
52553+ if (s_tmp->user_trans_num) {
52554+ uid_t *uidlist;
52555+
52556+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
52557+ if (uidlist == NULL)
52558+ return ERR_PTR(-ENOMEM);
52559+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
52560+ return ERR_PTR(-EFAULT);
52561+
52562+ s_tmp->user_transitions = uidlist;
52563+ }
52564+
52565+ if (s_tmp->group_trans_num) {
52566+ gid_t *gidlist;
52567+
52568+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
52569+ if (gidlist == NULL)
52570+ return ERR_PTR(-ENOMEM);
52571+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
52572+ return ERR_PTR(-EFAULT);
52573+
52574+ s_tmp->group_transitions = gidlist;
52575+ }
52576+
52577+ /* set up object hash table */
52578+ num_objs = count_user_objs(ghash.first);
52579+
52580+ s_tmp->obj_hash_size = num_objs;
52581+ s_tmp->obj_hash =
52582+ (struct acl_object_label **)
52583+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
52584+
52585+ if (!s_tmp->obj_hash)
52586+ return ERR_PTR(-ENOMEM);
52587+
52588+ memset(s_tmp->obj_hash, 0,
52589+ s_tmp->obj_hash_size *
52590+ sizeof (struct acl_object_label *));
52591+
52592+ /* add in objects */
52593+ err = copy_user_objs(ghash.first, s_tmp, role);
52594+
52595+ if (err)
52596+ return ERR_PTR(err);
52597+
52598+ /* set pointer for parent subject */
52599+ if (s_tmp->parent_subject) {
52600+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
52601+
52602+ if (IS_ERR(s_tmp2))
52603+ return s_tmp2;
52604+
52605+ s_tmp->parent_subject = s_tmp2;
52606+ }
52607+
52608+ /* add in ip acls */
52609+
52610+ if (!s_tmp->ip_num) {
52611+ s_tmp->ips = NULL;
52612+ goto insert;
52613+ }
52614+
52615+ i_tmp =
52616+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
52617+ sizeof (struct acl_ip_label *));
52618+
52619+ if (!i_tmp)
52620+ return ERR_PTR(-ENOMEM);
52621+
52622+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
52623+ *(i_tmp + i_num) =
52624+ (struct acl_ip_label *)
52625+ acl_alloc(sizeof (struct acl_ip_label));
52626+ if (!*(i_tmp + i_num))
52627+ return ERR_PTR(-ENOMEM);
52628+
52629+ if (copy_from_user
52630+ (&i_utmp2, s_tmp->ips + i_num,
52631+ sizeof (struct acl_ip_label *)))
52632+ return ERR_PTR(-EFAULT);
52633+
52634+ if (copy_from_user
52635+ (*(i_tmp + i_num), i_utmp2,
52636+ sizeof (struct acl_ip_label)))
52637+ return ERR_PTR(-EFAULT);
52638+
52639+ if ((*(i_tmp + i_num))->iface == NULL)
52640+ continue;
52641+
52642+ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
52643+ if (!len || len >= IFNAMSIZ)
52644+ return ERR_PTR(-EINVAL);
52645+ tmp = acl_alloc(len);
52646+ if (tmp == NULL)
52647+ return ERR_PTR(-ENOMEM);
52648+ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
52649+ return ERR_PTR(-EFAULT);
52650+ (*(i_tmp + i_num))->iface = tmp;
52651+ }
52652+
52653+ s_tmp->ips = i_tmp;
52654+
52655+insert:
52656+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
52657+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
52658+ return ERR_PTR(-ENOMEM);
52659+
52660+ return s_tmp;
52661+}
52662+
52663+static int
52664+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
52665+{
52666+ struct acl_subject_label s_pre;
52667+ struct acl_subject_label * ret;
52668+ int err;
52669+
52670+ while (userp) {
52671+ if (copy_from_user(&s_pre, userp,
52672+ sizeof (struct acl_subject_label)))
52673+ return -EFAULT;
52674+
52675+ /* do not add nested subjects here, add
52676+ while parsing objects
52677+ */
52678+
52679+ if (s_pre.mode & GR_NESTED) {
52680+ userp = s_pre.prev;
52681+ continue;
52682+ }
52683+
52684+ ret = do_copy_user_subj(userp, role);
52685+
52686+ err = PTR_ERR(ret);
52687+ if (IS_ERR(ret))
52688+ return err;
52689+
52690+ insert_acl_subj_label(ret, role);
52691+
52692+ userp = s_pre.prev;
52693+ }
52694+
52695+ return 0;
52696+}
52697+
52698+static int
52699+copy_user_acl(struct gr_arg *arg)
52700+{
52701+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
52702+ struct sprole_pw *sptmp;
52703+ struct gr_hash_struct *ghash;
52704+ uid_t *domainlist;
52705+ unsigned int r_num;
52706+ unsigned int len;
52707+ char *tmp;
52708+ int err = 0;
52709+ __u16 i;
52710+ __u32 num_subjs;
52711+
52712+ /* we need a default and kernel role */
52713+ if (arg->role_db.num_roles < 2)
52714+ return -EINVAL;
52715+
52716+ /* copy special role authentication info from userspace */
52717+
52718+ num_sprole_pws = arg->num_sprole_pws;
52719+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
52720+
52721+ if (!acl_special_roles) {
52722+ err = -ENOMEM;
52723+ goto cleanup;
52724+ }
52725+
52726+ for (i = 0; i < num_sprole_pws; i++) {
52727+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
52728+ if (!sptmp) {
52729+ err = -ENOMEM;
52730+ goto cleanup;
52731+ }
52732+ if (copy_from_user(sptmp, arg->sprole_pws + i,
52733+ sizeof (struct sprole_pw))) {
52734+ err = -EFAULT;
52735+ goto cleanup;
52736+ }
52737+
52738+ len =
52739+ strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
52740+
52741+ if (!len || len >= GR_SPROLE_LEN) {
52742+ err = -EINVAL;
52743+ goto cleanup;
52744+ }
52745+
52746+ if ((tmp = (char *) acl_alloc(len)) == NULL) {
52747+ err = -ENOMEM;
52748+ goto cleanup;
52749+ }
52750+
52751+ if (copy_from_user(tmp, sptmp->rolename, len)) {
52752+ err = -EFAULT;
52753+ goto cleanup;
52754+ }
52755+ tmp[len-1] = '\0';
52756+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52757+ printk(KERN_ALERT "Copying special role %s\n", tmp);
52758+#endif
52759+ sptmp->rolename = tmp;
52760+ acl_special_roles[i] = sptmp;
52761+ }
52762+
52763+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
52764+
52765+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
52766+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
52767+
52768+ if (!r_tmp) {
52769+ err = -ENOMEM;
52770+ goto cleanup;
52771+ }
52772+
52773+ if (copy_from_user(&r_utmp2, r_utmp + r_num,
52774+ sizeof (struct acl_role_label *))) {
52775+ err = -EFAULT;
52776+ goto cleanup;
52777+ }
52778+
52779+ if (copy_from_user(r_tmp, r_utmp2,
52780+ sizeof (struct acl_role_label))) {
52781+ err = -EFAULT;
52782+ goto cleanup;
52783+ }
52784+
52785+ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
52786+
52787+ if (!len || len >= PATH_MAX) {
52788+ err = -EINVAL;
52789+ goto cleanup;
52790+ }
52791+
52792+ if ((tmp = (char *) acl_alloc(len)) == NULL) {
52793+ err = -ENOMEM;
52794+ goto cleanup;
52795+ }
52796+ if (copy_from_user(tmp, r_tmp->rolename, len)) {
52797+ err = -EFAULT;
52798+ goto cleanup;
52799+ }
52800+ tmp[len-1] = '\0';
52801+ r_tmp->rolename = tmp;
52802+
52803+ if (!strcmp(r_tmp->rolename, "default")
52804+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
52805+ default_role = r_tmp;
52806+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
52807+ kernel_role = r_tmp;
52808+ }
52809+
52810+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL) {
52811+ err = -ENOMEM;
52812+ goto cleanup;
52813+ }
52814+ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct))) {
52815+ err = -EFAULT;
52816+ goto cleanup;
52817+ }
52818+
52819+ r_tmp->hash = ghash;
52820+
52821+ num_subjs = count_user_subjs(r_tmp->hash->first);
52822+
52823+ r_tmp->subj_hash_size = num_subjs;
52824+ r_tmp->subj_hash =
52825+ (struct acl_subject_label **)
52826+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
52827+
52828+ if (!r_tmp->subj_hash) {
52829+ err = -ENOMEM;
52830+ goto cleanup;
52831+ }
52832+
52833+ err = copy_user_allowedips(r_tmp);
52834+ if (err)
52835+ goto cleanup;
52836+
52837+ /* copy domain info */
52838+ if (r_tmp->domain_children != NULL) {
52839+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
52840+ if (domainlist == NULL) {
52841+ err = -ENOMEM;
52842+ goto cleanup;
52843+ }
52844+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t))) {
52845+ err = -EFAULT;
52846+ goto cleanup;
52847+ }
52848+ r_tmp->domain_children = domainlist;
52849+ }
52850+
52851+ err = copy_user_transitions(r_tmp);
52852+ if (err)
52853+ goto cleanup;
52854+
52855+ memset(r_tmp->subj_hash, 0,
52856+ r_tmp->subj_hash_size *
52857+ sizeof (struct acl_subject_label *));
52858+
52859+ err = copy_user_subjs(r_tmp->hash->first, r_tmp);
52860+
52861+ if (err)
52862+ goto cleanup;
52863+
52864+ /* set nested subject list to null */
52865+ r_tmp->hash->first = NULL;
52866+
52867+ insert_acl_role_label(r_tmp);
52868+ }
52869+
52870+ goto return_err;
52871+ cleanup:
52872+ free_variables();
52873+ return_err:
52874+ return err;
52875+
52876+}
52877+
52878+static int
52879+gracl_init(struct gr_arg *args)
52880+{
52881+ int error = 0;
52882+
52883+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
52884+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
52885+
52886+ if (init_variables(args)) {
52887+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
52888+ error = -ENOMEM;
52889+ free_variables();
52890+ goto out;
52891+ }
52892+
52893+ error = copy_user_acl(args);
52894+ free_init_variables();
52895+ if (error) {
52896+ free_variables();
52897+ goto out;
52898+ }
52899+
52900+ if ((error = gr_set_acls(0))) {
52901+ free_variables();
52902+ goto out;
52903+ }
52904+
52905+ pax_open_kernel();
52906+ gr_status |= GR_READY;
52907+ pax_close_kernel();
52908+
52909+ out:
52910+ return error;
52911+}
52912+
52913+/* derived from glibc fnmatch() 0: match, 1: no match*/
52914+
52915+static int
52916+glob_match(const char *p, const char *n)
52917+{
52918+ char c;
52919+
52920+ while ((c = *p++) != '\0') {
52921+ switch (c) {
52922+ case '?':
52923+ if (*n == '\0')
52924+ return 1;
52925+ else if (*n == '/')
52926+ return 1;
52927+ break;
52928+ case '\\':
52929+ if (*n != c)
52930+ return 1;
52931+ break;
52932+ case '*':
52933+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
52934+ if (*n == '/')
52935+ return 1;
52936+ else if (c == '?') {
52937+ if (*n == '\0')
52938+ return 1;
52939+ else
52940+ ++n;
52941+ }
52942+ }
52943+ if (c == '\0') {
52944+ return 0;
52945+ } else {
52946+ const char *endp;
52947+
52948+ if ((endp = strchr(n, '/')) == NULL)
52949+ endp = n + strlen(n);
52950+
52951+ if (c == '[') {
52952+ for (--p; n < endp; ++n)
52953+ if (!glob_match(p, n))
52954+ return 0;
52955+ } else if (c == '/') {
52956+ while (*n != '\0' && *n != '/')
52957+ ++n;
52958+ if (*n == '/' && !glob_match(p, n + 1))
52959+ return 0;
52960+ } else {
52961+ for (--p; n < endp; ++n)
52962+ if (*n == c && !glob_match(p, n))
52963+ return 0;
52964+ }
52965+
52966+ return 1;
52967+ }
52968+ case '[':
52969+ {
52970+ int not;
52971+ char cold;
52972+
52973+ if (*n == '\0' || *n == '/')
52974+ return 1;
52975+
52976+ not = (*p == '!' || *p == '^');
52977+ if (not)
52978+ ++p;
52979+
52980+ c = *p++;
52981+ for (;;) {
52982+ unsigned char fn = (unsigned char)*n;
52983+
52984+ if (c == '\0')
52985+ return 1;
52986+ else {
52987+ if (c == fn)
52988+ goto matched;
52989+ cold = c;
52990+ c = *p++;
52991+
52992+ if (c == '-' && *p != ']') {
52993+ unsigned char cend = *p++;
52994+
52995+ if (cend == '\0')
52996+ return 1;
52997+
52998+ if (cold <= fn && fn <= cend)
52999+ goto matched;
53000+
53001+ c = *p++;
53002+ }
53003+ }
53004+
53005+ if (c == ']')
53006+ break;
53007+ }
53008+ if (!not)
53009+ return 1;
53010+ break;
53011+ matched:
53012+ while (c != ']') {
53013+ if (c == '\0')
53014+ return 1;
53015+
53016+ c = *p++;
53017+ }
53018+ if (not)
53019+ return 1;
53020+ }
53021+ break;
53022+ default:
53023+ if (c != *n)
53024+ return 1;
53025+ }
53026+
53027+ ++n;
53028+ }
53029+
53030+ if (*n == '\0')
53031+ return 0;
53032+
53033+ if (*n == '/')
53034+ return 0;
53035+
53036+ return 1;
53037+}
53038+
53039+static struct acl_object_label *
53040+chk_glob_label(struct acl_object_label *globbed,
53041+ struct dentry *dentry, struct vfsmount *mnt, char **path)
53042+{
53043+ struct acl_object_label *tmp;
53044+
53045+ if (*path == NULL)
53046+ *path = gr_to_filename_nolock(dentry, mnt);
53047+
53048+ tmp = globbed;
53049+
53050+ while (tmp) {
53051+ if (!glob_match(tmp->filename, *path))
53052+ return tmp;
53053+ tmp = tmp->next;
53054+ }
53055+
53056+ return NULL;
53057+}
53058+
53059+static struct acl_object_label *
53060+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53061+ const ino_t curr_ino, const dev_t curr_dev,
53062+ const struct acl_subject_label *subj, char **path, const int checkglob)
53063+{
53064+ struct acl_subject_label *tmpsubj;
53065+ struct acl_object_label *retval;
53066+ struct acl_object_label *retval2;
53067+
53068+ tmpsubj = (struct acl_subject_label *) subj;
53069+ read_lock(&gr_inode_lock);
53070+ do {
53071+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
53072+ if (retval) {
53073+ if (checkglob && retval->globbed) {
53074+ retval2 = chk_glob_label(retval->globbed, (struct dentry *)orig_dentry,
53075+ (struct vfsmount *)orig_mnt, path);
53076+ if (retval2)
53077+ retval = retval2;
53078+ }
53079+ break;
53080+ }
53081+ } while ((tmpsubj = tmpsubj->parent_subject));
53082+ read_unlock(&gr_inode_lock);
53083+
53084+ return retval;
53085+}
53086+
53087+static __inline__ struct acl_object_label *
53088+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53089+ struct dentry *curr_dentry,
53090+ const struct acl_subject_label *subj, char **path, const int checkglob)
53091+{
53092+ int newglob = checkglob;
53093+ ino_t inode;
53094+ dev_t device;
53095+
53096+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
53097+ as we don't want a / * rule to match instead of the / object
53098+ don't do this for create lookups that call this function though, since they're looking up
53099+ on the parent and thus need globbing checks on all paths
53100+ */
53101+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
53102+ newglob = GR_NO_GLOB;
53103+
53104+ spin_lock(&curr_dentry->d_lock);
53105+ inode = curr_dentry->d_inode->i_ino;
53106+ device = __get_dev(curr_dentry);
53107+ spin_unlock(&curr_dentry->d_lock);
53108+
53109+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
53110+}
53111+
53112+static struct acl_object_label *
53113+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53114+ const struct acl_subject_label *subj, char *path, const int checkglob)
53115+{
53116+ struct dentry *dentry = (struct dentry *) l_dentry;
53117+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53118+ struct acl_object_label *retval;
53119+ struct dentry *parent;
53120+
53121+ write_seqlock(&rename_lock);
53122+ br_read_lock(vfsmount_lock);
53123+
53124+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
53125+#ifdef CONFIG_NET
53126+ mnt == sock_mnt ||
53127+#endif
53128+#ifdef CONFIG_HUGETLBFS
53129+ (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
53130+#endif
53131+ /* ignore Eric Biederman */
53132+ IS_PRIVATE(l_dentry->d_inode))) {
53133+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
53134+ goto out;
53135+ }
53136+
53137+ for (;;) {
53138+ if (dentry == real_root.dentry && mnt == real_root.mnt)
53139+ break;
53140+
53141+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53142+ if (mnt->mnt_parent == mnt)
53143+ break;
53144+
53145+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53146+ if (retval != NULL)
53147+ goto out;
53148+
53149+ dentry = mnt->mnt_mountpoint;
53150+ mnt = mnt->mnt_parent;
53151+ continue;
53152+ }
53153+
53154+ parent = dentry->d_parent;
53155+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53156+ if (retval != NULL)
53157+ goto out;
53158+
53159+ dentry = parent;
53160+ }
53161+
53162+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53163+
53164+ /* real_root is pinned so we don't have to hold a reference */
53165+ if (retval == NULL)
53166+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
53167+out:
53168+ br_read_unlock(vfsmount_lock);
53169+ write_sequnlock(&rename_lock);
53170+
53171+ BUG_ON(retval == NULL);
53172+
53173+ return retval;
53174+}
53175+
53176+static __inline__ struct acl_object_label *
53177+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53178+ const struct acl_subject_label *subj)
53179+{
53180+ char *path = NULL;
53181+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
53182+}
53183+
53184+static __inline__ struct acl_object_label *
53185+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53186+ const struct acl_subject_label *subj)
53187+{
53188+ char *path = NULL;
53189+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
53190+}
53191+
53192+static __inline__ struct acl_object_label *
53193+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53194+ const struct acl_subject_label *subj, char *path)
53195+{
53196+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
53197+}
53198+
53199+static struct acl_subject_label *
53200+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53201+ const struct acl_role_label *role)
53202+{
53203+ struct dentry *dentry = (struct dentry *) l_dentry;
53204+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53205+ struct acl_subject_label *retval;
53206+ struct dentry *parent;
53207+
53208+ write_seqlock(&rename_lock);
53209+ br_read_lock(vfsmount_lock);
53210+
53211+ for (;;) {
53212+ if (dentry == real_root.dentry && mnt == real_root.mnt)
53213+ break;
53214+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53215+ if (mnt->mnt_parent == mnt)
53216+ break;
53217+
53218+ spin_lock(&dentry->d_lock);
53219+ read_lock(&gr_inode_lock);
53220+ retval =
53221+ lookup_acl_subj_label(dentry->d_inode->i_ino,
53222+ __get_dev(dentry), role);
53223+ read_unlock(&gr_inode_lock);
53224+ spin_unlock(&dentry->d_lock);
53225+ if (retval != NULL)
53226+ goto out;
53227+
53228+ dentry = mnt->mnt_mountpoint;
53229+ mnt = mnt->mnt_parent;
53230+ continue;
53231+ }
53232+
53233+ spin_lock(&dentry->d_lock);
53234+ read_lock(&gr_inode_lock);
53235+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53236+ __get_dev(dentry), role);
53237+ read_unlock(&gr_inode_lock);
53238+ parent = dentry->d_parent;
53239+ spin_unlock(&dentry->d_lock);
53240+
53241+ if (retval != NULL)
53242+ goto out;
53243+
53244+ dentry = parent;
53245+ }
53246+
53247+ spin_lock(&dentry->d_lock);
53248+ read_lock(&gr_inode_lock);
53249+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53250+ __get_dev(dentry), role);
53251+ read_unlock(&gr_inode_lock);
53252+ spin_unlock(&dentry->d_lock);
53253+
53254+ if (unlikely(retval == NULL)) {
53255+ /* real_root is pinned, we don't need to hold a reference */
53256+ read_lock(&gr_inode_lock);
53257+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
53258+ __get_dev(real_root.dentry), role);
53259+ read_unlock(&gr_inode_lock);
53260+ }
53261+out:
53262+ br_read_unlock(vfsmount_lock);
53263+ write_sequnlock(&rename_lock);
53264+
53265+ BUG_ON(retval == NULL);
53266+
53267+ return retval;
53268+}
53269+
53270+static void
53271+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
53272+{
53273+ struct task_struct *task = current;
53274+ const struct cred *cred = current_cred();
53275+
53276+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
53277+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53278+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53279+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
53280+
53281+ return;
53282+}
53283+
53284+static void
53285+gr_log_learn_sysctl(const char *path, const __u32 mode)
53286+{
53287+ struct task_struct *task = current;
53288+ const struct cred *cred = current_cred();
53289+
53290+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
53291+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53292+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53293+ 1UL, 1UL, path, (unsigned long) mode, &task->signal->saved_ip);
53294+
53295+ return;
53296+}
53297+
53298+static void
53299+gr_log_learn_id_change(const char type, const unsigned int real,
53300+ const unsigned int effective, const unsigned int fs)
53301+{
53302+ struct task_struct *task = current;
53303+ const struct cred *cred = current_cred();
53304+
53305+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
53306+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53307+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53308+ type, real, effective, fs, &task->signal->saved_ip);
53309+
53310+ return;
53311+}
53312+
53313+__u32
53314+gr_check_link(const struct dentry * new_dentry,
53315+ const struct dentry * parent_dentry,
53316+ const struct vfsmount * parent_mnt,
53317+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
53318+{
53319+ struct acl_object_label *obj;
53320+ __u32 oldmode, newmode;
53321+ __u32 needmode;
53322+
53323+ if (unlikely(!(gr_status & GR_READY)))
53324+ return (GR_CREATE | GR_LINK);
53325+
53326+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
53327+ oldmode = obj->mode;
53328+
53329+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53330+ oldmode |= (GR_CREATE | GR_LINK);
53331+
53332+ needmode = GR_CREATE | GR_AUDIT_CREATE | GR_SUPPRESS;
53333+ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
53334+ needmode |= GR_SETID | GR_AUDIT_SETID;
53335+
53336+ newmode =
53337+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
53338+ oldmode | needmode);
53339+
53340+ needmode = newmode & (GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC |
53341+ GR_SETID | GR_READ | GR_FIND | GR_DELETE |
53342+ GR_INHERIT | GR_AUDIT_INHERIT);
53343+
53344+ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID) && !(newmode & GR_SETID))
53345+ goto bad;
53346+
53347+ if ((oldmode & needmode) != needmode)
53348+ goto bad;
53349+
53350+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
53351+ if ((newmode & needmode) != needmode)
53352+ goto bad;
53353+
53354+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
53355+ return newmode;
53356+bad:
53357+ needmode = oldmode;
53358+ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
53359+ needmode |= GR_SETID;
53360+
53361+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
53362+ gr_log_learn(old_dentry, old_mnt, needmode);
53363+ return (GR_CREATE | GR_LINK);
53364+ } else if (newmode & GR_SUPPRESS)
53365+ return GR_SUPPRESS;
53366+ else
53367+ return 0;
53368+}
53369+
53370+__u32
53371+gr_search_file(const struct dentry * dentry, const __u32 mode,
53372+ const struct vfsmount * mnt)
53373+{
53374+ __u32 retval = mode;
53375+ struct acl_subject_label *curracl;
53376+ struct acl_object_label *currobj;
53377+
53378+ if (unlikely(!(gr_status & GR_READY)))
53379+ return (mode & ~GR_AUDITS);
53380+
53381+ curracl = current->acl;
53382+
53383+ currobj = chk_obj_label(dentry, mnt, curracl);
53384+ retval = currobj->mode & mode;
53385+
53386+ /* if we're opening a specified transfer file for writing
53387+ (e.g. /dev/initctl), then transfer our role to init
53388+ */
53389+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
53390+ current->role->roletype & GR_ROLE_PERSIST)) {
53391+ struct task_struct *task = init_pid_ns.child_reaper;
53392+
53393+ if (task->role != current->role) {
53394+ task->acl_sp_role = 0;
53395+ task->acl_role_id = current->acl_role_id;
53396+ task->role = current->role;
53397+ rcu_read_lock();
53398+ read_lock(&grsec_exec_file_lock);
53399+ gr_apply_subject_to_task(task);
53400+ read_unlock(&grsec_exec_file_lock);
53401+ rcu_read_unlock();
53402+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
53403+ }
53404+ }
53405+
53406+ if (unlikely
53407+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
53408+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
53409+ __u32 new_mode = mode;
53410+
53411+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53412+
53413+ retval = new_mode;
53414+
53415+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
53416+ new_mode |= GR_INHERIT;
53417+
53418+ if (!(mode & GR_NOLEARN))
53419+ gr_log_learn(dentry, mnt, new_mode);
53420+ }
53421+
53422+ return retval;
53423+}
53424+
53425+__u32
53426+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
53427+ const struct vfsmount * mnt, const __u32 mode)
53428+{
53429+ struct name_entry *match;
53430+ struct acl_object_label *matchpo;
53431+ struct acl_subject_label *curracl;
53432+ char *path;
53433+ __u32 retval;
53434+
53435+ if (unlikely(!(gr_status & GR_READY)))
53436+ return (mode & ~GR_AUDITS);
53437+
53438+ preempt_disable();
53439+ path = gr_to_filename_rbac(new_dentry, mnt);
53440+ match = lookup_name_entry_create(path);
53441+
53442+ if (!match)
53443+ goto check_parent;
53444+
53445+ curracl = current->acl;
53446+
53447+ read_lock(&gr_inode_lock);
53448+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
53449+ read_unlock(&gr_inode_lock);
53450+
53451+ if (matchpo) {
53452+ if ((matchpo->mode & mode) !=
53453+ (mode & ~(GR_AUDITS | GR_SUPPRESS))
53454+ && curracl->mode & (GR_LEARN | GR_INHERITLEARN)) {
53455+ __u32 new_mode = mode;
53456+
53457+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53458+
53459+ gr_log_learn(new_dentry, mnt, new_mode);
53460+
53461+ preempt_enable();
53462+ return new_mode;
53463+ }
53464+ preempt_enable();
53465+ return (matchpo->mode & mode);
53466+ }
53467+
53468+ check_parent:
53469+ curracl = current->acl;
53470+
53471+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
53472+ retval = matchpo->mode & mode;
53473+
53474+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
53475+ && (curracl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53476+ __u32 new_mode = mode;
53477+
53478+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53479+
53480+ gr_log_learn(new_dentry, mnt, new_mode);
53481+ preempt_enable();
53482+ return new_mode;
53483+ }
53484+
53485+ preempt_enable();
53486+ return retval;
53487+}
53488+
53489+int
53490+gr_check_hidden_task(const struct task_struct *task)
53491+{
53492+ if (unlikely(!(gr_status & GR_READY)))
53493+ return 0;
53494+
53495+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
53496+ return 1;
53497+
53498+ return 0;
53499+}
53500+
53501+int
53502+gr_check_protected_task(const struct task_struct *task)
53503+{
53504+ if (unlikely(!(gr_status & GR_READY) || !task))
53505+ return 0;
53506+
53507+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53508+ task->acl != current->acl)
53509+ return 1;
53510+
53511+ return 0;
53512+}
53513+
53514+int
53515+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
53516+{
53517+ struct task_struct *p;
53518+ int ret = 0;
53519+
53520+ if (unlikely(!(gr_status & GR_READY) || !pid))
53521+ return ret;
53522+
53523+ read_lock(&tasklist_lock);
53524+ do_each_pid_task(pid, type, p) {
53525+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53526+ p->acl != current->acl) {
53527+ ret = 1;
53528+ goto out;
53529+ }
53530+ } while_each_pid_task(pid, type, p);
53531+out:
53532+ read_unlock(&tasklist_lock);
53533+
53534+ return ret;
53535+}
53536+
53537+void
53538+gr_copy_label(struct task_struct *tsk)
53539+{
53540+ tsk->signal->used_accept = 0;
53541+ tsk->acl_sp_role = 0;
53542+ tsk->acl_role_id = current->acl_role_id;
53543+ tsk->acl = current->acl;
53544+ tsk->role = current->role;
53545+ tsk->signal->curr_ip = current->signal->curr_ip;
53546+ tsk->signal->saved_ip = current->signal->saved_ip;
53547+ if (current->exec_file)
53548+ get_file(current->exec_file);
53549+ tsk->exec_file = current->exec_file;
53550+ tsk->is_writable = current->is_writable;
53551+ if (unlikely(current->signal->used_accept)) {
53552+ current->signal->curr_ip = 0;
53553+ current->signal->saved_ip = 0;
53554+ }
53555+
53556+ return;
53557+}
53558+
53559+static void
53560+gr_set_proc_res(struct task_struct *task)
53561+{
53562+ struct acl_subject_label *proc;
53563+ unsigned short i;
53564+
53565+ proc = task->acl;
53566+
53567+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
53568+ return;
53569+
53570+ for (i = 0; i < RLIM_NLIMITS; i++) {
53571+ if (!(proc->resmask & (1 << i)))
53572+ continue;
53573+
53574+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
53575+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
53576+ }
53577+
53578+ return;
53579+}
53580+
53581+extern int __gr_process_user_ban(struct user_struct *user);
53582+
53583+int
53584+gr_check_user_change(int real, int effective, int fs)
53585+{
53586+ unsigned int i;
53587+ __u16 num;
53588+ uid_t *uidlist;
53589+ int curuid;
53590+ int realok = 0;
53591+ int effectiveok = 0;
53592+ int fsok = 0;
53593+
53594+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
53595+ struct user_struct *user;
53596+
53597+ if (real == -1)
53598+ goto skipit;
53599+
53600+ user = find_user(real);
53601+ if (user == NULL)
53602+ goto skipit;
53603+
53604+ if (__gr_process_user_ban(user)) {
53605+ /* for find_user */
53606+ free_uid(user);
53607+ return 1;
53608+ }
53609+
53610+ /* for find_user */
53611+ free_uid(user);
53612+
53613+skipit:
53614+#endif
53615+
53616+ if (unlikely(!(gr_status & GR_READY)))
53617+ return 0;
53618+
53619+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53620+ gr_log_learn_id_change('u', real, effective, fs);
53621+
53622+ num = current->acl->user_trans_num;
53623+ uidlist = current->acl->user_transitions;
53624+
53625+ if (uidlist == NULL)
53626+ return 0;
53627+
53628+ if (real == -1)
53629+ realok = 1;
53630+ if (effective == -1)
53631+ effectiveok = 1;
53632+ if (fs == -1)
53633+ fsok = 1;
53634+
53635+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
53636+ for (i = 0; i < num; i++) {
53637+ curuid = (int)uidlist[i];
53638+ if (real == curuid)
53639+ realok = 1;
53640+ if (effective == curuid)
53641+ effectiveok = 1;
53642+ if (fs == curuid)
53643+ fsok = 1;
53644+ }
53645+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
53646+ for (i = 0; i < num; i++) {
53647+ curuid = (int)uidlist[i];
53648+ if (real == curuid)
53649+ break;
53650+ if (effective == curuid)
53651+ break;
53652+ if (fs == curuid)
53653+ break;
53654+ }
53655+ /* not in deny list */
53656+ if (i == num) {
53657+ realok = 1;
53658+ effectiveok = 1;
53659+ fsok = 1;
53660+ }
53661+ }
53662+
53663+ if (realok && effectiveok && fsok)
53664+ return 0;
53665+ else {
53666+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53667+ return 1;
53668+ }
53669+}
53670+
53671+int
53672+gr_check_group_change(int real, int effective, int fs)
53673+{
53674+ unsigned int i;
53675+ __u16 num;
53676+ gid_t *gidlist;
53677+ int curgid;
53678+ int realok = 0;
53679+ int effectiveok = 0;
53680+ int fsok = 0;
53681+
53682+ if (unlikely(!(gr_status & GR_READY)))
53683+ return 0;
53684+
53685+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53686+ gr_log_learn_id_change('g', real, effective, fs);
53687+
53688+ num = current->acl->group_trans_num;
53689+ gidlist = current->acl->group_transitions;
53690+
53691+ if (gidlist == NULL)
53692+ return 0;
53693+
53694+ if (real == -1)
53695+ realok = 1;
53696+ if (effective == -1)
53697+ effectiveok = 1;
53698+ if (fs == -1)
53699+ fsok = 1;
53700+
53701+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
53702+ for (i = 0; i < num; i++) {
53703+ curgid = (int)gidlist[i];
53704+ if (real == curgid)
53705+ realok = 1;
53706+ if (effective == curgid)
53707+ effectiveok = 1;
53708+ if (fs == curgid)
53709+ fsok = 1;
53710+ }
53711+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
53712+ for (i = 0; i < num; i++) {
53713+ curgid = (int)gidlist[i];
53714+ if (real == curgid)
53715+ break;
53716+ if (effective == curgid)
53717+ break;
53718+ if (fs == curgid)
53719+ break;
53720+ }
53721+ /* not in deny list */
53722+ if (i == num) {
53723+ realok = 1;
53724+ effectiveok = 1;
53725+ fsok = 1;
53726+ }
53727+ }
53728+
53729+ if (realok && effectiveok && fsok)
53730+ return 0;
53731+ else {
53732+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53733+ return 1;
53734+ }
53735+}
53736+
53737+void
53738+gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
53739+{
53740+ struct acl_role_label *role = task->role;
53741+ struct acl_subject_label *subj = NULL;
53742+ struct acl_object_label *obj;
53743+ struct file *filp;
53744+
53745+ if (unlikely(!(gr_status & GR_READY)))
53746+ return;
53747+
53748+ filp = task->exec_file;
53749+
53750+ /* kernel process, we'll give them the kernel role */
53751+ if (unlikely(!filp)) {
53752+ task->role = kernel_role;
53753+ task->acl = kernel_role->root_label;
53754+ return;
53755+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
53756+ role = lookup_acl_role_label(task, uid, gid);
53757+
53758+ /* perform subject lookup in possibly new role
53759+ we can use this result below in the case where role == task->role
53760+ */
53761+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
53762+
53763+ /* if we changed uid/gid, but result in the same role
53764+ and are using inheritance, don't lose the inherited subject
53765+ if current subject is other than what normal lookup
53766+ would result in, we arrived via inheritance, don't
53767+ lose subject
53768+ */
53769+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
53770+ (subj == task->acl)))
53771+ task->acl = subj;
53772+
53773+ task->role = role;
53774+
53775+ task->is_writable = 0;
53776+
53777+ /* ignore additional mmap checks for processes that are writable
53778+ by the default ACL */
53779+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53780+ if (unlikely(obj->mode & GR_WRITE))
53781+ task->is_writable = 1;
53782+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
53783+ if (unlikely(obj->mode & GR_WRITE))
53784+ task->is_writable = 1;
53785+
53786+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53787+ printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53788+#endif
53789+
53790+ gr_set_proc_res(task);
53791+
53792+ return;
53793+}
53794+
53795+int
53796+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
53797+ const int unsafe_share)
53798+{
53799+ struct task_struct *task = current;
53800+ struct acl_subject_label *newacl;
53801+ struct acl_object_label *obj;
53802+ __u32 retmode;
53803+
53804+ if (unlikely(!(gr_status & GR_READY)))
53805+ return 0;
53806+
53807+ newacl = chk_subj_label(dentry, mnt, task->role);
53808+
53809+ task_lock(task);
53810+ if ((((task->ptrace & PT_PTRACED) || unsafe_share) &&
53811+ !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
53812+ !(task->role->roletype & GR_ROLE_GOD) &&
53813+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
53814+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN)))) {
53815+ task_unlock(task);
53816+ if (unsafe_share)
53817+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
53818+ else
53819+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
53820+ return -EACCES;
53821+ }
53822+ task_unlock(task);
53823+
53824+ obj = chk_obj_label(dentry, mnt, task->acl);
53825+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
53826+
53827+ if (!(task->acl->mode & GR_INHERITLEARN) &&
53828+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
53829+ if (obj->nested)
53830+ task->acl = obj->nested;
53831+ else
53832+ task->acl = newacl;
53833+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
53834+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
53835+
53836+ task->is_writable = 0;
53837+
53838+ /* ignore additional mmap checks for processes that are writable
53839+ by the default ACL */
53840+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
53841+ if (unlikely(obj->mode & GR_WRITE))
53842+ task->is_writable = 1;
53843+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
53844+ if (unlikely(obj->mode & GR_WRITE))
53845+ task->is_writable = 1;
53846+
53847+ gr_set_proc_res(task);
53848+
53849+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53850+ printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53851+#endif
53852+ return 0;
53853+}
53854+
53855+/* always called with valid inodev ptr */
53856+static void
53857+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
53858+{
53859+ struct acl_object_label *matchpo;
53860+ struct acl_subject_label *matchps;
53861+ struct acl_subject_label *subj;
53862+ struct acl_role_label *role;
53863+ unsigned int x;
53864+
53865+ FOR_EACH_ROLE_START(role)
53866+ FOR_EACH_SUBJECT_START(role, subj, x)
53867+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
53868+ matchpo->mode |= GR_DELETED;
53869+ FOR_EACH_SUBJECT_END(subj,x)
53870+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
53871+ if (subj->inode == ino && subj->device == dev)
53872+ subj->mode |= GR_DELETED;
53873+ FOR_EACH_NESTED_SUBJECT_END(subj)
53874+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
53875+ matchps->mode |= GR_DELETED;
53876+ FOR_EACH_ROLE_END(role)
53877+
53878+ inodev->nentry->deleted = 1;
53879+
53880+ return;
53881+}
53882+
53883+void
53884+gr_handle_delete(const ino_t ino, const dev_t dev)
53885+{
53886+ struct inodev_entry *inodev;
53887+
53888+ if (unlikely(!(gr_status & GR_READY)))
53889+ return;
53890+
53891+ write_lock(&gr_inode_lock);
53892+ inodev = lookup_inodev_entry(ino, dev);
53893+ if (inodev != NULL)
53894+ do_handle_delete(inodev, ino, dev);
53895+ write_unlock(&gr_inode_lock);
53896+
53897+ return;
53898+}
53899+
53900+static void
53901+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
53902+ const ino_t newinode, const dev_t newdevice,
53903+ struct acl_subject_label *subj)
53904+{
53905+ unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
53906+ struct acl_object_label *match;
53907+
53908+ match = subj->obj_hash[index];
53909+
53910+ while (match && (match->inode != oldinode ||
53911+ match->device != olddevice ||
53912+ !(match->mode & GR_DELETED)))
53913+ match = match->next;
53914+
53915+ if (match && (match->inode == oldinode)
53916+ && (match->device == olddevice)
53917+ && (match->mode & GR_DELETED)) {
53918+ if (match->prev == NULL) {
53919+ subj->obj_hash[index] = match->next;
53920+ if (match->next != NULL)
53921+ match->next->prev = NULL;
53922+ } else {
53923+ match->prev->next = match->next;
53924+ if (match->next != NULL)
53925+ match->next->prev = match->prev;
53926+ }
53927+ match->prev = NULL;
53928+ match->next = NULL;
53929+ match->inode = newinode;
53930+ match->device = newdevice;
53931+ match->mode &= ~GR_DELETED;
53932+
53933+ insert_acl_obj_label(match, subj);
53934+ }
53935+
53936+ return;
53937+}
53938+
53939+static void
53940+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
53941+ const ino_t newinode, const dev_t newdevice,
53942+ struct acl_role_label *role)
53943+{
53944+ unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
53945+ struct acl_subject_label *match;
53946+
53947+ match = role->subj_hash[index];
53948+
53949+ while (match && (match->inode != oldinode ||
53950+ match->device != olddevice ||
53951+ !(match->mode & GR_DELETED)))
53952+ match = match->next;
53953+
53954+ if (match && (match->inode == oldinode)
53955+ && (match->device == olddevice)
53956+ && (match->mode & GR_DELETED)) {
53957+ if (match->prev == NULL) {
53958+ role->subj_hash[index] = match->next;
53959+ if (match->next != NULL)
53960+ match->next->prev = NULL;
53961+ } else {
53962+ match->prev->next = match->next;
53963+ if (match->next != NULL)
53964+ match->next->prev = match->prev;
53965+ }
53966+ match->prev = NULL;
53967+ match->next = NULL;
53968+ match->inode = newinode;
53969+ match->device = newdevice;
53970+ match->mode &= ~GR_DELETED;
53971+
53972+ insert_acl_subj_label(match, role);
53973+ }
53974+
53975+ return;
53976+}
53977+
53978+static void
53979+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
53980+ const ino_t newinode, const dev_t newdevice)
53981+{
53982+ unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
53983+ struct inodev_entry *match;
53984+
53985+ match = inodev_set.i_hash[index];
53986+
53987+ while (match && (match->nentry->inode != oldinode ||
53988+ match->nentry->device != olddevice || !match->nentry->deleted))
53989+ match = match->next;
53990+
53991+ if (match && (match->nentry->inode == oldinode)
53992+ && (match->nentry->device == olddevice) &&
53993+ match->nentry->deleted) {
53994+ if (match->prev == NULL) {
53995+ inodev_set.i_hash[index] = match->next;
53996+ if (match->next != NULL)
53997+ match->next->prev = NULL;
53998+ } else {
53999+ match->prev->next = match->next;
54000+ if (match->next != NULL)
54001+ match->next->prev = match->prev;
54002+ }
54003+ match->prev = NULL;
54004+ match->next = NULL;
54005+ match->nentry->inode = newinode;
54006+ match->nentry->device = newdevice;
54007+ match->nentry->deleted = 0;
54008+
54009+ insert_inodev_entry(match);
54010+ }
54011+
54012+ return;
54013+}
54014+
54015+static void
54016+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
54017+ const struct vfsmount *mnt)
54018+{
54019+ struct acl_subject_label *subj;
54020+ struct acl_role_label *role;
54021+ unsigned int x;
54022+ ino_t ino = dentry->d_inode->i_ino;
54023+ dev_t dev = __get_dev(dentry);
54024+
54025+ FOR_EACH_ROLE_START(role)
54026+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
54027+
54028+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
54029+ if ((subj->inode == ino) && (subj->device == dev)) {
54030+ subj->inode = ino;
54031+ subj->device = dev;
54032+ }
54033+ FOR_EACH_NESTED_SUBJECT_END(subj)
54034+ FOR_EACH_SUBJECT_START(role, subj, x)
54035+ update_acl_obj_label(matchn->inode, matchn->device,
54036+ ino, dev, subj);
54037+ FOR_EACH_SUBJECT_END(subj,x)
54038+ FOR_EACH_ROLE_END(role)
54039+
54040+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
54041+
54042+ return;
54043+}
54044+
54045+void
54046+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
54047+{
54048+ struct name_entry *matchn;
54049+
54050+ if (unlikely(!(gr_status & GR_READY)))
54051+ return;
54052+
54053+ preempt_disable();
54054+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
54055+
54056+ if (unlikely((unsigned long)matchn)) {
54057+ write_lock(&gr_inode_lock);
54058+ do_handle_create(matchn, dentry, mnt);
54059+ write_unlock(&gr_inode_lock);
54060+ }
54061+ preempt_enable();
54062+
54063+ return;
54064+}
54065+
54066+void
54067+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
54068+ struct dentry *old_dentry,
54069+ struct dentry *new_dentry,
54070+ struct vfsmount *mnt, const __u8 replace)
54071+{
54072+ struct name_entry *matchn;
54073+ struct inodev_entry *inodev;
54074+ ino_t old_ino = old_dentry->d_inode->i_ino;
54075+ dev_t old_dev = __get_dev(old_dentry);
54076+
54077+ /* vfs_rename swaps the name and parent link for old_dentry and
54078+ new_dentry
54079+ at this point, old_dentry has the new name, parent link, and inode
54080+ for the renamed file
54081+ if a file is being replaced by a rename, new_dentry has the inode
54082+ and name for the replaced file
54083+ */
54084+
54085+ if (unlikely(!(gr_status & GR_READY)))
54086+ return;
54087+
54088+ preempt_disable();
54089+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
54090+
54091+ /* we wouldn't have to check d_inode if it weren't for
54092+ NFS silly-renaming
54093+ */
54094+
54095+ write_lock(&gr_inode_lock);
54096+ if (unlikely(replace && new_dentry->d_inode)) {
54097+ ino_t new_ino = new_dentry->d_inode->i_ino;
54098+ dev_t new_dev = __get_dev(new_dentry);
54099+
54100+ inodev = lookup_inodev_entry(new_ino, new_dev);
54101+ if (inodev != NULL && (new_dentry->d_inode->i_nlink <= 1))
54102+ do_handle_delete(inodev, new_ino, new_dev);
54103+ }
54104+
54105+ inodev = lookup_inodev_entry(old_ino, old_dev);
54106+ if (inodev != NULL && (old_dentry->d_inode->i_nlink <= 1))
54107+ do_handle_delete(inodev, old_ino, old_dev);
54108+
54109+ if (unlikely((unsigned long)matchn))
54110+ do_handle_create(matchn, old_dentry, mnt);
54111+
54112+ write_unlock(&gr_inode_lock);
54113+ preempt_enable();
54114+
54115+ return;
54116+}
54117+
54118+static int
54119+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
54120+ unsigned char **sum)
54121+{
54122+ struct acl_role_label *r;
54123+ struct role_allowed_ip *ipp;
54124+ struct role_transition *trans;
54125+ unsigned int i;
54126+ int found = 0;
54127+ u32 curr_ip = current->signal->curr_ip;
54128+
54129+ current->signal->saved_ip = curr_ip;
54130+
54131+ /* check transition table */
54132+
54133+ for (trans = current->role->transitions; trans; trans = trans->next) {
54134+ if (!strcmp(rolename, trans->rolename)) {
54135+ found = 1;
54136+ break;
54137+ }
54138+ }
54139+
54140+ if (!found)
54141+ return 0;
54142+
54143+ /* handle special roles that do not require authentication
54144+ and check ip */
54145+
54146+ FOR_EACH_ROLE_START(r)
54147+ if (!strcmp(rolename, r->rolename) &&
54148+ (r->roletype & GR_ROLE_SPECIAL)) {
54149+ found = 0;
54150+ if (r->allowed_ips != NULL) {
54151+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
54152+ if ((ntohl(curr_ip) & ipp->netmask) ==
54153+ (ntohl(ipp->addr) & ipp->netmask))
54154+ found = 1;
54155+ }
54156+ } else
54157+ found = 2;
54158+ if (!found)
54159+ return 0;
54160+
54161+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
54162+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
54163+ *salt = NULL;
54164+ *sum = NULL;
54165+ return 1;
54166+ }
54167+ }
54168+ FOR_EACH_ROLE_END(r)
54169+
54170+ for (i = 0; i < num_sprole_pws; i++) {
54171+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
54172+ *salt = acl_special_roles[i]->salt;
54173+ *sum = acl_special_roles[i]->sum;
54174+ return 1;
54175+ }
54176+ }
54177+
54178+ return 0;
54179+}
54180+
54181+static void
54182+assign_special_role(char *rolename)
54183+{
54184+ struct acl_object_label *obj;
54185+ struct acl_role_label *r;
54186+ struct acl_role_label *assigned = NULL;
54187+ struct task_struct *tsk;
54188+ struct file *filp;
54189+
54190+ FOR_EACH_ROLE_START(r)
54191+ if (!strcmp(rolename, r->rolename) &&
54192+ (r->roletype & GR_ROLE_SPECIAL)) {
54193+ assigned = r;
54194+ break;
54195+ }
54196+ FOR_EACH_ROLE_END(r)
54197+
54198+ if (!assigned)
54199+ return;
54200+
54201+ read_lock(&tasklist_lock);
54202+ read_lock(&grsec_exec_file_lock);
54203+
54204+ tsk = current->real_parent;
54205+ if (tsk == NULL)
54206+ goto out_unlock;
54207+
54208+ filp = tsk->exec_file;
54209+ if (filp == NULL)
54210+ goto out_unlock;
54211+
54212+ tsk->is_writable = 0;
54213+
54214+ tsk->acl_sp_role = 1;
54215+ tsk->acl_role_id = ++acl_sp_role_value;
54216+ tsk->role = assigned;
54217+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
54218+
54219+ /* ignore additional mmap checks for processes that are writable
54220+ by the default ACL */
54221+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54222+ if (unlikely(obj->mode & GR_WRITE))
54223+ tsk->is_writable = 1;
54224+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
54225+ if (unlikely(obj->mode & GR_WRITE))
54226+ tsk->is_writable = 1;
54227+
54228+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54229+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
54230+#endif
54231+
54232+out_unlock:
54233+ read_unlock(&grsec_exec_file_lock);
54234+ read_unlock(&tasklist_lock);
54235+ return;
54236+}
54237+
54238+int gr_check_secure_terminal(struct task_struct *task)
54239+{
54240+ struct task_struct *p, *p2, *p3;
54241+ struct files_struct *files;
54242+ struct fdtable *fdt;
54243+ struct file *our_file = NULL, *file;
54244+ int i;
54245+
54246+ if (task->signal->tty == NULL)
54247+ return 1;
54248+
54249+ files = get_files_struct(task);
54250+ if (files != NULL) {
54251+ rcu_read_lock();
54252+ fdt = files_fdtable(files);
54253+ for (i=0; i < fdt->max_fds; i++) {
54254+ file = fcheck_files(files, i);
54255+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
54256+ get_file(file);
54257+ our_file = file;
54258+ }
54259+ }
54260+ rcu_read_unlock();
54261+ put_files_struct(files);
54262+ }
54263+
54264+ if (our_file == NULL)
54265+ return 1;
54266+
54267+ read_lock(&tasklist_lock);
54268+ do_each_thread(p2, p) {
54269+ files = get_files_struct(p);
54270+ if (files == NULL ||
54271+ (p->signal && p->signal->tty == task->signal->tty)) {
54272+ if (files != NULL)
54273+ put_files_struct(files);
54274+ continue;
54275+ }
54276+ rcu_read_lock();
54277+ fdt = files_fdtable(files);
54278+ for (i=0; i < fdt->max_fds; i++) {
54279+ file = fcheck_files(files, i);
54280+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
54281+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
54282+ p3 = task;
54283+ while (p3->pid > 0) {
54284+ if (p3 == p)
54285+ break;
54286+ p3 = p3->real_parent;
54287+ }
54288+ if (p3 == p)
54289+ break;
54290+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
54291+ gr_handle_alertkill(p);
54292+ rcu_read_unlock();
54293+ put_files_struct(files);
54294+ read_unlock(&tasklist_lock);
54295+ fput(our_file);
54296+ return 0;
54297+ }
54298+ }
54299+ rcu_read_unlock();
54300+ put_files_struct(files);
54301+ } while_each_thread(p2, p);
54302+ read_unlock(&tasklist_lock);
54303+
54304+ fput(our_file);
54305+ return 1;
54306+}
54307+
54308+ssize_t
54309+write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
54310+{
54311+ struct gr_arg_wrapper uwrap;
54312+ unsigned char *sprole_salt = NULL;
54313+ unsigned char *sprole_sum = NULL;
54314+ int error = sizeof (struct gr_arg_wrapper);
54315+ int error2 = 0;
54316+
54317+ mutex_lock(&gr_dev_mutex);
54318+
54319+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
54320+ error = -EPERM;
54321+ goto out;
54322+ }
54323+
54324+ if (count != sizeof (struct gr_arg_wrapper)) {
54325+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
54326+ error = -EINVAL;
54327+ goto out;
54328+ }
54329+
54330+
54331+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
54332+ gr_auth_expires = 0;
54333+ gr_auth_attempts = 0;
54334+ }
54335+
54336+ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
54337+ error = -EFAULT;
54338+ goto out;
54339+ }
54340+
54341+ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
54342+ error = -EINVAL;
54343+ goto out;
54344+ }
54345+
54346+ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
54347+ error = -EFAULT;
54348+ goto out;
54349+ }
54350+
54351+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54352+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54353+ time_after(gr_auth_expires, get_seconds())) {
54354+ error = -EBUSY;
54355+ goto out;
54356+ }
54357+
54358+ /* if non-root trying to do anything other than use a special role,
54359+ do not attempt authentication, do not count towards authentication
54360+ locking
54361+ */
54362+
54363+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
54364+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54365+ current_uid()) {
54366+ error = -EPERM;
54367+ goto out;
54368+ }
54369+
54370+ /* ensure pw and special role name are null terminated */
54371+
54372+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
54373+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
54374+
54375+ /* Okay.
54376+ * We have our enough of the argument structure..(we have yet
54377+ * to copy_from_user the tables themselves) . Copy the tables
54378+ * only if we need them, i.e. for loading operations. */
54379+
54380+ switch (gr_usermode->mode) {
54381+ case GR_STATUS:
54382+ if (gr_status & GR_READY) {
54383+ error = 1;
54384+ if (!gr_check_secure_terminal(current))
54385+ error = 3;
54386+ } else
54387+ error = 2;
54388+ goto out;
54389+ case GR_SHUTDOWN:
54390+ if ((gr_status & GR_READY)
54391+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54392+ pax_open_kernel();
54393+ gr_status &= ~GR_READY;
54394+ pax_close_kernel();
54395+
54396+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
54397+ free_variables();
54398+ memset(gr_usermode, 0, sizeof (struct gr_arg));
54399+ memset(gr_system_salt, 0, GR_SALT_LEN);
54400+ memset(gr_system_sum, 0, GR_SHA_LEN);
54401+ } else if (gr_status & GR_READY) {
54402+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
54403+ error = -EPERM;
54404+ } else {
54405+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
54406+ error = -EAGAIN;
54407+ }
54408+ break;
54409+ case GR_ENABLE:
54410+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
54411+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
54412+ else {
54413+ if (gr_status & GR_READY)
54414+ error = -EAGAIN;
54415+ else
54416+ error = error2;
54417+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
54418+ }
54419+ break;
54420+ case GR_RELOAD:
54421+ if (!(gr_status & GR_READY)) {
54422+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
54423+ error = -EAGAIN;
54424+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54425+ preempt_disable();
54426+
54427+ pax_open_kernel();
54428+ gr_status &= ~GR_READY;
54429+ pax_close_kernel();
54430+
54431+ free_variables();
54432+ if (!(error2 = gracl_init(gr_usermode))) {
54433+ preempt_enable();
54434+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
54435+ } else {
54436+ preempt_enable();
54437+ error = error2;
54438+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54439+ }
54440+ } else {
54441+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54442+ error = -EPERM;
54443+ }
54444+ break;
54445+ case GR_SEGVMOD:
54446+ if (unlikely(!(gr_status & GR_READY))) {
54447+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
54448+ error = -EAGAIN;
54449+ break;
54450+ }
54451+
54452+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54453+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
54454+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
54455+ struct acl_subject_label *segvacl;
54456+ segvacl =
54457+ lookup_acl_subj_label(gr_usermode->segv_inode,
54458+ gr_usermode->segv_device,
54459+ current->role);
54460+ if (segvacl) {
54461+ segvacl->crashes = 0;
54462+ segvacl->expires = 0;
54463+ }
54464+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
54465+ gr_remove_uid(gr_usermode->segv_uid);
54466+ }
54467+ } else {
54468+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
54469+ error = -EPERM;
54470+ }
54471+ break;
54472+ case GR_SPROLE:
54473+ case GR_SPROLEPAM:
54474+ if (unlikely(!(gr_status & GR_READY))) {
54475+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
54476+ error = -EAGAIN;
54477+ break;
54478+ }
54479+
54480+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
54481+ current->role->expires = 0;
54482+ current->role->auth_attempts = 0;
54483+ }
54484+
54485+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54486+ time_after(current->role->expires, get_seconds())) {
54487+ error = -EBUSY;
54488+ goto out;
54489+ }
54490+
54491+ if (lookup_special_role_auth
54492+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
54493+ && ((!sprole_salt && !sprole_sum)
54494+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
54495+ char *p = "";
54496+ assign_special_role(gr_usermode->sp_role);
54497+ read_lock(&tasklist_lock);
54498+ if (current->real_parent)
54499+ p = current->real_parent->role->rolename;
54500+ read_unlock(&tasklist_lock);
54501+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
54502+ p, acl_sp_role_value);
54503+ } else {
54504+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
54505+ error = -EPERM;
54506+ if(!(current->role->auth_attempts++))
54507+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54508+
54509+ goto out;
54510+ }
54511+ break;
54512+ case GR_UNSPROLE:
54513+ if (unlikely(!(gr_status & GR_READY))) {
54514+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
54515+ error = -EAGAIN;
54516+ break;
54517+ }
54518+
54519+ if (current->role->roletype & GR_ROLE_SPECIAL) {
54520+ char *p = "";
54521+ int i = 0;
54522+
54523+ read_lock(&tasklist_lock);
54524+ if (current->real_parent) {
54525+ p = current->real_parent->role->rolename;
54526+ i = current->real_parent->acl_role_id;
54527+ }
54528+ read_unlock(&tasklist_lock);
54529+
54530+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
54531+ gr_set_acls(1);
54532+ } else {
54533+ error = -EPERM;
54534+ goto out;
54535+ }
54536+ break;
54537+ default:
54538+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
54539+ error = -EINVAL;
54540+ break;
54541+ }
54542+
54543+ if (error != -EPERM)
54544+ goto out;
54545+
54546+ if(!(gr_auth_attempts++))
54547+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54548+
54549+ out:
54550+ mutex_unlock(&gr_dev_mutex);
54551+ return error;
54552+}
54553+
54554+/* must be called with
54555+ rcu_read_lock();
54556+ read_lock(&tasklist_lock);
54557+ read_lock(&grsec_exec_file_lock);
54558+*/
54559+int gr_apply_subject_to_task(struct task_struct *task)
54560+{
54561+ struct acl_object_label *obj;
54562+ char *tmpname;
54563+ struct acl_subject_label *tmpsubj;
54564+ struct file *filp;
54565+ struct name_entry *nmatch;
54566+
54567+ filp = task->exec_file;
54568+ if (filp == NULL)
54569+ return 0;
54570+
54571+ /* the following is to apply the correct subject
54572+ on binaries running when the RBAC system
54573+ is enabled, when the binaries have been
54574+ replaced or deleted since their execution
54575+ -----
54576+ when the RBAC system starts, the inode/dev
54577+ from exec_file will be one the RBAC system
54578+ is unaware of. It only knows the inode/dev
54579+ of the present file on disk, or the absence
54580+ of it.
54581+ */
54582+ preempt_disable();
54583+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
54584+
54585+ nmatch = lookup_name_entry(tmpname);
54586+ preempt_enable();
54587+ tmpsubj = NULL;
54588+ if (nmatch) {
54589+ if (nmatch->deleted)
54590+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
54591+ else
54592+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
54593+ if (tmpsubj != NULL)
54594+ task->acl = tmpsubj;
54595+ }
54596+ if (tmpsubj == NULL)
54597+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
54598+ task->role);
54599+ if (task->acl) {
54600+ struct acl_subject_label *curr;
54601+ curr = task->acl;
54602+
54603+ task->is_writable = 0;
54604+ /* ignore additional mmap checks for processes that are writable
54605+ by the default ACL */
54606+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54607+ if (unlikely(obj->mode & GR_WRITE))
54608+ task->is_writable = 1;
54609+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54610+ if (unlikely(obj->mode & GR_WRITE))
54611+ task->is_writable = 1;
54612+
54613+ gr_set_proc_res(task);
54614+
54615+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54616+ printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54617+#endif
54618+ } else {
54619+ return 1;
54620+ }
54621+
54622+ return 0;
54623+}
54624+
54625+int
54626+gr_set_acls(const int type)
54627+{
54628+ struct task_struct *task, *task2;
54629+ struct acl_role_label *role = current->role;
54630+ __u16 acl_role_id = current->acl_role_id;
54631+ const struct cred *cred;
54632+ int ret;
54633+
54634+ rcu_read_lock();
54635+ read_lock(&tasklist_lock);
54636+ read_lock(&grsec_exec_file_lock);
54637+ do_each_thread(task2, task) {
54638+ /* check to see if we're called from the exit handler,
54639+ if so, only replace ACLs that have inherited the admin
54640+ ACL */
54641+
54642+ if (type && (task->role != role ||
54643+ task->acl_role_id != acl_role_id))
54644+ continue;
54645+
54646+ task->acl_role_id = 0;
54647+ task->acl_sp_role = 0;
54648+
54649+ if (task->exec_file) {
54650+ cred = __task_cred(task);
54651+ task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
54652+ ret = gr_apply_subject_to_task(task);
54653+ if (ret) {
54654+ read_unlock(&grsec_exec_file_lock);
54655+ read_unlock(&tasklist_lock);
54656+ rcu_read_unlock();
54657+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
54658+ return ret;
54659+ }
54660+ } else {
54661+ // it's a kernel process
54662+ task->role = kernel_role;
54663+ task->acl = kernel_role->root_label;
54664+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
54665+ task->acl->mode &= ~GR_PROCFIND;
54666+#endif
54667+ }
54668+ } while_each_thread(task2, task);
54669+ read_unlock(&grsec_exec_file_lock);
54670+ read_unlock(&tasklist_lock);
54671+ rcu_read_unlock();
54672+
54673+ return 0;
54674+}
54675+
54676+void
54677+gr_learn_resource(const struct task_struct *task,
54678+ const int res, const unsigned long wanted, const int gt)
54679+{
54680+ struct acl_subject_label *acl;
54681+ const struct cred *cred;
54682+
54683+ if (unlikely((gr_status & GR_READY) &&
54684+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
54685+ goto skip_reslog;
54686+
54687+#ifdef CONFIG_GRKERNSEC_RESLOG
54688+ gr_log_resource(task, res, wanted, gt);
54689+#endif
54690+ skip_reslog:
54691+
54692+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
54693+ return;
54694+
54695+ acl = task->acl;
54696+
54697+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
54698+ !(acl->resmask & (1 << (unsigned short) res))))
54699+ return;
54700+
54701+ if (wanted >= acl->res[res].rlim_cur) {
54702+ unsigned long res_add;
54703+
54704+ res_add = wanted;
54705+ switch (res) {
54706+ case RLIMIT_CPU:
54707+ res_add += GR_RLIM_CPU_BUMP;
54708+ break;
54709+ case RLIMIT_FSIZE:
54710+ res_add += GR_RLIM_FSIZE_BUMP;
54711+ break;
54712+ case RLIMIT_DATA:
54713+ res_add += GR_RLIM_DATA_BUMP;
54714+ break;
54715+ case RLIMIT_STACK:
54716+ res_add += GR_RLIM_STACK_BUMP;
54717+ break;
54718+ case RLIMIT_CORE:
54719+ res_add += GR_RLIM_CORE_BUMP;
54720+ break;
54721+ case RLIMIT_RSS:
54722+ res_add += GR_RLIM_RSS_BUMP;
54723+ break;
54724+ case RLIMIT_NPROC:
54725+ res_add += GR_RLIM_NPROC_BUMP;
54726+ break;
54727+ case RLIMIT_NOFILE:
54728+ res_add += GR_RLIM_NOFILE_BUMP;
54729+ break;
54730+ case RLIMIT_MEMLOCK:
54731+ res_add += GR_RLIM_MEMLOCK_BUMP;
54732+ break;
54733+ case RLIMIT_AS:
54734+ res_add += GR_RLIM_AS_BUMP;
54735+ break;
54736+ case RLIMIT_LOCKS:
54737+ res_add += GR_RLIM_LOCKS_BUMP;
54738+ break;
54739+ case RLIMIT_SIGPENDING:
54740+ res_add += GR_RLIM_SIGPENDING_BUMP;
54741+ break;
54742+ case RLIMIT_MSGQUEUE:
54743+ res_add += GR_RLIM_MSGQUEUE_BUMP;
54744+ break;
54745+ case RLIMIT_NICE:
54746+ res_add += GR_RLIM_NICE_BUMP;
54747+ break;
54748+ case RLIMIT_RTPRIO:
54749+ res_add += GR_RLIM_RTPRIO_BUMP;
54750+ break;
54751+ case RLIMIT_RTTIME:
54752+ res_add += GR_RLIM_RTTIME_BUMP;
54753+ break;
54754+ }
54755+
54756+ acl->res[res].rlim_cur = res_add;
54757+
54758+ if (wanted > acl->res[res].rlim_max)
54759+ acl->res[res].rlim_max = res_add;
54760+
54761+ /* only log the subject filename, since resource logging is supported for
54762+ single-subject learning only */
54763+ rcu_read_lock();
54764+ cred = __task_cred(task);
54765+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
54766+ task->role->roletype, cred->uid, cred->gid, acl->filename,
54767+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
54768+ "", (unsigned long) res, &task->signal->saved_ip);
54769+ rcu_read_unlock();
54770+ }
54771+
54772+ return;
54773+}
54774+
54775+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
54776+void
54777+pax_set_initial_flags(struct linux_binprm *bprm)
54778+{
54779+ struct task_struct *task = current;
54780+ struct acl_subject_label *proc;
54781+ unsigned long flags;
54782+
54783+ if (unlikely(!(gr_status & GR_READY)))
54784+ return;
54785+
54786+ flags = pax_get_flags(task);
54787+
54788+ proc = task->acl;
54789+
54790+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
54791+ flags &= ~MF_PAX_PAGEEXEC;
54792+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
54793+ flags &= ~MF_PAX_SEGMEXEC;
54794+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
54795+ flags &= ~MF_PAX_RANDMMAP;
54796+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
54797+ flags &= ~MF_PAX_EMUTRAMP;
54798+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
54799+ flags &= ~MF_PAX_MPROTECT;
54800+
54801+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
54802+ flags |= MF_PAX_PAGEEXEC;
54803+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
54804+ flags |= MF_PAX_SEGMEXEC;
54805+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
54806+ flags |= MF_PAX_RANDMMAP;
54807+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
54808+ flags |= MF_PAX_EMUTRAMP;
54809+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
54810+ flags |= MF_PAX_MPROTECT;
54811+
54812+ pax_set_flags(task, flags);
54813+
54814+ return;
54815+}
54816+#endif
54817+
54818+#ifdef CONFIG_SYSCTL
54819+/* Eric Biederman likes breaking userland ABI and every inode-based security
54820+ system to save 35kb of memory */
54821+
54822+/* we modify the passed in filename, but adjust it back before returning */
54823+static struct acl_object_label *gr_lookup_by_name(char *name, unsigned int len)
54824+{
54825+ struct name_entry *nmatch;
54826+ char *p, *lastp = NULL;
54827+ struct acl_object_label *obj = NULL, *tmp;
54828+ struct acl_subject_label *tmpsubj;
54829+ char c = '\0';
54830+
54831+ read_lock(&gr_inode_lock);
54832+
54833+ p = name + len - 1;
54834+ do {
54835+ nmatch = lookup_name_entry(name);
54836+ if (lastp != NULL)
54837+ *lastp = c;
54838+
54839+ if (nmatch == NULL)
54840+ goto next_component;
54841+ tmpsubj = current->acl;
54842+ do {
54843+ obj = lookup_acl_obj_label(nmatch->inode, nmatch->device, tmpsubj);
54844+ if (obj != NULL) {
54845+ tmp = obj->globbed;
54846+ while (tmp) {
54847+ if (!glob_match(tmp->filename, name)) {
54848+ obj = tmp;
54849+ goto found_obj;
54850+ }
54851+ tmp = tmp->next;
54852+ }
54853+ goto found_obj;
54854+ }
54855+ } while ((tmpsubj = tmpsubj->parent_subject));
54856+next_component:
54857+ /* end case */
54858+ if (p == name)
54859+ break;
54860+
54861+ while (*p != '/')
54862+ p--;
54863+ if (p == name)
54864+ lastp = p + 1;
54865+ else {
54866+ lastp = p;
54867+ p--;
54868+ }
54869+ c = *lastp;
54870+ *lastp = '\0';
54871+ } while (1);
54872+found_obj:
54873+ read_unlock(&gr_inode_lock);
54874+ /* obj returned will always be non-null */
54875+ return obj;
54876+}
54877+
54878+/* returns 0 when allowing, non-zero on error
54879+ op of 0 is used for readdir, so we don't log the names of hidden files
54880+*/
54881+__u32
54882+gr_handle_sysctl(const struct ctl_table *table, const int op)
54883+{
54884+ struct ctl_table *tmp;
54885+ const char *proc_sys = "/proc/sys";
54886+ char *path;
54887+ struct acl_object_label *obj;
54888+ unsigned short len = 0, pos = 0, depth = 0, i;
54889+ __u32 err = 0;
54890+ __u32 mode = 0;
54891+
54892+ if (unlikely(!(gr_status & GR_READY)))
54893+ return 0;
54894+
54895+ /* for now, ignore operations on non-sysctl entries if it's not a
54896+ readdir*/
54897+ if (table->child != NULL && op != 0)
54898+ return 0;
54899+
54900+ mode |= GR_FIND;
54901+ /* it's only a read if it's an entry, read on dirs is for readdir */
54902+ if (op & MAY_READ)
54903+ mode |= GR_READ;
54904+ if (op & MAY_WRITE)
54905+ mode |= GR_WRITE;
54906+
54907+ preempt_disable();
54908+
54909+ path = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
54910+
54911+ /* it's only a read/write if it's an actual entry, not a dir
54912+ (which are opened for readdir)
54913+ */
54914+
54915+ /* convert the requested sysctl entry into a pathname */
54916+
54917+ for (tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
54918+ len += strlen(tmp->procname);
54919+ len++;
54920+ depth++;
54921+ }
54922+
54923+ if ((len + depth + strlen(proc_sys) + 1) > PAGE_SIZE) {
54924+ /* deny */
54925+ goto out;
54926+ }
54927+
54928+ memset(path, 0, PAGE_SIZE);
54929+
54930+ memcpy(path, proc_sys, strlen(proc_sys));
54931+
54932+ pos += strlen(proc_sys);
54933+
54934+ for (; depth > 0; depth--) {
54935+ path[pos] = '/';
54936+ pos++;
54937+ for (i = 1, tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
54938+ if (depth == i) {
54939+ memcpy(path + pos, tmp->procname,
54940+ strlen(tmp->procname));
54941+ pos += strlen(tmp->procname);
54942+ }
54943+ i++;
54944+ }
54945+ }
54946+
54947+ obj = gr_lookup_by_name(path, pos);
54948+ err = obj->mode & (mode | to_gr_audit(mode) | GR_SUPPRESS);
54949+
54950+ if (unlikely((current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) &&
54951+ ((err & mode) != mode))) {
54952+ __u32 new_mode = mode;
54953+
54954+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
54955+
54956+ err = 0;
54957+ gr_log_learn_sysctl(path, new_mode);
54958+ } else if (!(err & GR_FIND) && !(err & GR_SUPPRESS) && op != 0) {
54959+ gr_log_hidden_sysctl(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, path);
54960+ err = -ENOENT;
54961+ } else if (!(err & GR_FIND)) {
54962+ err = -ENOENT;
54963+ } else if (((err & mode) & ~GR_FIND) != (mode & ~GR_FIND) && !(err & GR_SUPPRESS)) {
54964+ gr_log_str4(GR_DONT_AUDIT, GR_SYSCTL_ACL_MSG, "denied",
54965+ path, (mode & GR_READ) ? " reading" : "",
54966+ (mode & GR_WRITE) ? " writing" : "");
54967+ err = -EACCES;
54968+ } else if ((err & mode) != mode) {
54969+ err = -EACCES;
54970+ } else if ((((err & mode) & ~GR_FIND) == (mode & ~GR_FIND)) && (err & GR_AUDITS)) {
54971+ gr_log_str4(GR_DO_AUDIT, GR_SYSCTL_ACL_MSG, "successful",
54972+ path, (mode & GR_READ) ? " reading" : "",
54973+ (mode & GR_WRITE) ? " writing" : "");
54974+ err = 0;
54975+ } else
54976+ err = 0;
54977+
54978+ out:
54979+ preempt_enable();
54980+
54981+ return err;
54982+}
54983+#endif
54984+
54985+int
54986+gr_handle_proc_ptrace(struct task_struct *task)
54987+{
54988+ struct file *filp;
54989+ struct task_struct *tmp = task;
54990+ struct task_struct *curtemp = current;
54991+ __u32 retmode;
54992+
54993+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
54994+ if (unlikely(!(gr_status & GR_READY)))
54995+ return 0;
54996+#endif
54997+
54998+ read_lock(&tasklist_lock);
54999+ read_lock(&grsec_exec_file_lock);
55000+ filp = task->exec_file;
55001+
55002+ while (tmp->pid > 0) {
55003+ if (tmp == curtemp)
55004+ break;
55005+ tmp = tmp->real_parent;
55006+ }
55007+
55008+ if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
55009+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
55010+ read_unlock(&grsec_exec_file_lock);
55011+ read_unlock(&tasklist_lock);
55012+ return 1;
55013+ }
55014+
55015+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55016+ if (!(gr_status & GR_READY)) {
55017+ read_unlock(&grsec_exec_file_lock);
55018+ read_unlock(&tasklist_lock);
55019+ return 0;
55020+ }
55021+#endif
55022+
55023+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
55024+ read_unlock(&grsec_exec_file_lock);
55025+ read_unlock(&tasklist_lock);
55026+
55027+ if (retmode & GR_NOPTRACE)
55028+ return 1;
55029+
55030+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
55031+ && (current->acl != task->acl || (current->acl != current->role->root_label
55032+ && current->pid != task->pid)))
55033+ return 1;
55034+
55035+ return 0;
55036+}
55037+
55038+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
55039+{
55040+ if (unlikely(!(gr_status & GR_READY)))
55041+ return;
55042+
55043+ if (!(current->role->roletype & GR_ROLE_GOD))
55044+ return;
55045+
55046+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
55047+ p->role->rolename, gr_task_roletype_to_char(p),
55048+ p->acl->filename);
55049+}
55050+
55051+int
55052+gr_handle_ptrace(struct task_struct *task, const long request)
55053+{
55054+ struct task_struct *tmp = task;
55055+ struct task_struct *curtemp = current;
55056+ __u32 retmode;
55057+
55058+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55059+ if (unlikely(!(gr_status & GR_READY)))
55060+ return 0;
55061+#endif
55062+
55063+ read_lock(&tasklist_lock);
55064+ while (tmp->pid > 0) {
55065+ if (tmp == curtemp)
55066+ break;
55067+ tmp = tmp->real_parent;
55068+ }
55069+
55070+ if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
55071+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
55072+ read_unlock(&tasklist_lock);
55073+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55074+ return 1;
55075+ }
55076+ read_unlock(&tasklist_lock);
55077+
55078+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55079+ if (!(gr_status & GR_READY))
55080+ return 0;
55081+#endif
55082+
55083+ read_lock(&grsec_exec_file_lock);
55084+ if (unlikely(!task->exec_file)) {
55085+ read_unlock(&grsec_exec_file_lock);
55086+ return 0;
55087+ }
55088+
55089+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
55090+ read_unlock(&grsec_exec_file_lock);
55091+
55092+ if (retmode & GR_NOPTRACE) {
55093+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55094+ return 1;
55095+ }
55096+
55097+ if (retmode & GR_PTRACERD) {
55098+ switch (request) {
55099+ case PTRACE_POKETEXT:
55100+ case PTRACE_POKEDATA:
55101+ case PTRACE_POKEUSR:
55102+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
55103+ case PTRACE_SETREGS:
55104+ case PTRACE_SETFPREGS:
55105+#endif
55106+#ifdef CONFIG_X86
55107+ case PTRACE_SETFPXREGS:
55108+#endif
55109+#ifdef CONFIG_ALTIVEC
55110+ case PTRACE_SETVRREGS:
55111+#endif
55112+ return 1;
55113+ default:
55114+ return 0;
55115+ }
55116+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
55117+ !(current->role->roletype & GR_ROLE_GOD) &&
55118+ (current->acl != task->acl)) {
55119+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55120+ return 1;
55121+ }
55122+
55123+ return 0;
55124+}
55125+
55126+static int is_writable_mmap(const struct file *filp)
55127+{
55128+ struct task_struct *task = current;
55129+ struct acl_object_label *obj, *obj2;
55130+
55131+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
55132+ !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))) {
55133+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55134+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
55135+ task->role->root_label);
55136+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
55137+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
55138+ return 1;
55139+ }
55140+ }
55141+ return 0;
55142+}
55143+
55144+int
55145+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
55146+{
55147+ __u32 mode;
55148+
55149+ if (unlikely(!file || !(prot & PROT_EXEC)))
55150+ return 1;
55151+
55152+ if (is_writable_mmap(file))
55153+ return 0;
55154+
55155+ mode =
55156+ gr_search_file(file->f_path.dentry,
55157+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55158+ file->f_path.mnt);
55159+
55160+ if (!gr_tpe_allow(file))
55161+ return 0;
55162+
55163+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55164+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55165+ return 0;
55166+ } else if (unlikely(!(mode & GR_EXEC))) {
55167+ return 0;
55168+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55169+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55170+ return 1;
55171+ }
55172+
55173+ return 1;
55174+}
55175+
55176+int
55177+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
55178+{
55179+ __u32 mode;
55180+
55181+ if (unlikely(!file || !(prot & PROT_EXEC)))
55182+ return 1;
55183+
55184+ if (is_writable_mmap(file))
55185+ return 0;
55186+
55187+ mode =
55188+ gr_search_file(file->f_path.dentry,
55189+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55190+ file->f_path.mnt);
55191+
55192+ if (!gr_tpe_allow(file))
55193+ return 0;
55194+
55195+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55196+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55197+ return 0;
55198+ } else if (unlikely(!(mode & GR_EXEC))) {
55199+ return 0;
55200+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55201+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55202+ return 1;
55203+ }
55204+
55205+ return 1;
55206+}
55207+
55208+void
55209+gr_acl_handle_psacct(struct task_struct *task, const long code)
55210+{
55211+ unsigned long runtime;
55212+ unsigned long cputime;
55213+ unsigned int wday, cday;
55214+ __u8 whr, chr;
55215+ __u8 wmin, cmin;
55216+ __u8 wsec, csec;
55217+ struct timespec timeval;
55218+
55219+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
55220+ !(task->acl->mode & GR_PROCACCT)))
55221+ return;
55222+
55223+ do_posix_clock_monotonic_gettime(&timeval);
55224+ runtime = timeval.tv_sec - task->start_time.tv_sec;
55225+ wday = runtime / (3600 * 24);
55226+ runtime -= wday * (3600 * 24);
55227+ whr = runtime / 3600;
55228+ runtime -= whr * 3600;
55229+ wmin = runtime / 60;
55230+ runtime -= wmin * 60;
55231+ wsec = runtime;
55232+
55233+ cputime = (task->utime + task->stime) / HZ;
55234+ cday = cputime / (3600 * 24);
55235+ cputime -= cday * (3600 * 24);
55236+ chr = cputime / 3600;
55237+ cputime -= chr * 3600;
55238+ cmin = cputime / 60;
55239+ cputime -= cmin * 60;
55240+ csec = cputime;
55241+
55242+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
55243+
55244+ return;
55245+}
55246+
55247+void gr_set_kernel_label(struct task_struct *task)
55248+{
55249+ if (gr_status & GR_READY) {
55250+ task->role = kernel_role;
55251+ task->acl = kernel_role->root_label;
55252+ }
55253+ return;
55254+}
55255+
55256+#ifdef CONFIG_TASKSTATS
55257+int gr_is_taskstats_denied(int pid)
55258+{
55259+ struct task_struct *task;
55260+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55261+ const struct cred *cred;
55262+#endif
55263+ int ret = 0;
55264+
55265+ /* restrict taskstats viewing to un-chrooted root users
55266+ who have the 'view' subject flag if the RBAC system is enabled
55267+ */
55268+
55269+ rcu_read_lock();
55270+ read_lock(&tasklist_lock);
55271+ task = find_task_by_vpid(pid);
55272+ if (task) {
55273+#ifdef CONFIG_GRKERNSEC_CHROOT
55274+ if (proc_is_chrooted(task))
55275+ ret = -EACCES;
55276+#endif
55277+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55278+ cred = __task_cred(task);
55279+#ifdef CONFIG_GRKERNSEC_PROC_USER
55280+ if (cred->uid != 0)
55281+ ret = -EACCES;
55282+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55283+ if (cred->uid != 0 && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
55284+ ret = -EACCES;
55285+#endif
55286+#endif
55287+ if (gr_status & GR_READY) {
55288+ if (!(task->acl->mode & GR_VIEW))
55289+ ret = -EACCES;
55290+ }
55291+ } else
55292+ ret = -ENOENT;
55293+
55294+ read_unlock(&tasklist_lock);
55295+ rcu_read_unlock();
55296+
55297+ return ret;
55298+}
55299+#endif
55300+
55301+/* AUXV entries are filled via a descendant of search_binary_handler
55302+ after we've already applied the subject for the target
55303+*/
55304+int gr_acl_enable_at_secure(void)
55305+{
55306+ if (unlikely(!(gr_status & GR_READY)))
55307+ return 0;
55308+
55309+ if (current->acl->mode & GR_ATSECURE)
55310+ return 1;
55311+
55312+ return 0;
55313+}
55314+
55315+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
55316+{
55317+ struct task_struct *task = current;
55318+ struct dentry *dentry = file->f_path.dentry;
55319+ struct vfsmount *mnt = file->f_path.mnt;
55320+ struct acl_object_label *obj, *tmp;
55321+ struct acl_subject_label *subj;
55322+ unsigned int bufsize;
55323+ int is_not_root;
55324+ char *path;
55325+ dev_t dev = __get_dev(dentry);
55326+
55327+ if (unlikely(!(gr_status & GR_READY)))
55328+ return 1;
55329+
55330+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
55331+ return 1;
55332+
55333+ /* ignore Eric Biederman */
55334+ if (IS_PRIVATE(dentry->d_inode))
55335+ return 1;
55336+
55337+ subj = task->acl;
55338+ do {
55339+ obj = lookup_acl_obj_label(ino, dev, subj);
55340+ if (obj != NULL)
55341+ return (obj->mode & GR_FIND) ? 1 : 0;
55342+ } while ((subj = subj->parent_subject));
55343+
55344+ /* this is purely an optimization since we're looking for an object
55345+ for the directory we're doing a readdir on
55346+ if it's possible for any globbed object to match the entry we're
55347+ filling into the directory, then the object we find here will be
55348+ an anchor point with attached globbed objects
55349+ */
55350+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
55351+ if (obj->globbed == NULL)
55352+ return (obj->mode & GR_FIND) ? 1 : 0;
55353+
55354+ is_not_root = ((obj->filename[0] == '/') &&
55355+ (obj->filename[1] == '\0')) ? 0 : 1;
55356+ bufsize = PAGE_SIZE - namelen - is_not_root;
55357+
55358+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
55359+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
55360+ return 1;
55361+
55362+ preempt_disable();
55363+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
55364+ bufsize);
55365+
55366+ bufsize = strlen(path);
55367+
55368+ /* if base is "/", don't append an additional slash */
55369+ if (is_not_root)
55370+ *(path + bufsize) = '/';
55371+ memcpy(path + bufsize + is_not_root, name, namelen);
55372+ *(path + bufsize + namelen + is_not_root) = '\0';
55373+
55374+ tmp = obj->globbed;
55375+ while (tmp) {
55376+ if (!glob_match(tmp->filename, path)) {
55377+ preempt_enable();
55378+ return (tmp->mode & GR_FIND) ? 1 : 0;
55379+ }
55380+ tmp = tmp->next;
55381+ }
55382+ preempt_enable();
55383+ return (obj->mode & GR_FIND) ? 1 : 0;
55384+}
55385+
55386+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
55387+EXPORT_SYMBOL(gr_acl_is_enabled);
55388+#endif
55389+EXPORT_SYMBOL(gr_learn_resource);
55390+EXPORT_SYMBOL(gr_set_kernel_label);
55391+#ifdef CONFIG_SECURITY
55392+EXPORT_SYMBOL(gr_check_user_change);
55393+EXPORT_SYMBOL(gr_check_group_change);
55394+#endif
55395+
55396diff -urNp linux-2.6.39.1/grsecurity/gracl_cap.c linux-2.6.39.1/grsecurity/gracl_cap.c
55397--- linux-2.6.39.1/grsecurity/gracl_cap.c 1969-12-31 19:00:00.000000000 -0500
55398+++ linux-2.6.39.1/grsecurity/gracl_cap.c 2011-05-22 19:41:42.000000000 -0400
55399@@ -0,0 +1,139 @@
55400+#include <linux/kernel.h>
55401+#include <linux/module.h>
55402+#include <linux/sched.h>
55403+#include <linux/gracl.h>
55404+#include <linux/grsecurity.h>
55405+#include <linux/grinternal.h>
55406+
55407+static const char *captab_log[] = {
55408+ "CAP_CHOWN",
55409+ "CAP_DAC_OVERRIDE",
55410+ "CAP_DAC_READ_SEARCH",
55411+ "CAP_FOWNER",
55412+ "CAP_FSETID",
55413+ "CAP_KILL",
55414+ "CAP_SETGID",
55415+ "CAP_SETUID",
55416+ "CAP_SETPCAP",
55417+ "CAP_LINUX_IMMUTABLE",
55418+ "CAP_NET_BIND_SERVICE",
55419+ "CAP_NET_BROADCAST",
55420+ "CAP_NET_ADMIN",
55421+ "CAP_NET_RAW",
55422+ "CAP_IPC_LOCK",
55423+ "CAP_IPC_OWNER",
55424+ "CAP_SYS_MODULE",
55425+ "CAP_SYS_RAWIO",
55426+ "CAP_SYS_CHROOT",
55427+ "CAP_SYS_PTRACE",
55428+ "CAP_SYS_PACCT",
55429+ "CAP_SYS_ADMIN",
55430+ "CAP_SYS_BOOT",
55431+ "CAP_SYS_NICE",
55432+ "CAP_SYS_RESOURCE",
55433+ "CAP_SYS_TIME",
55434+ "CAP_SYS_TTY_CONFIG",
55435+ "CAP_MKNOD",
55436+ "CAP_LEASE",
55437+ "CAP_AUDIT_WRITE",
55438+ "CAP_AUDIT_CONTROL",
55439+ "CAP_SETFCAP",
55440+ "CAP_MAC_OVERRIDE",
55441+ "CAP_MAC_ADMIN",
55442+ "CAP_SYSLOG"
55443+};
55444+
55445+EXPORT_SYMBOL(gr_is_capable);
55446+EXPORT_SYMBOL(gr_is_capable_nolog);
55447+
55448+int
55449+gr_is_capable(const int cap)
55450+{
55451+ struct task_struct *task = current;
55452+ const struct cred *cred = current_cred();
55453+ struct acl_subject_label *curracl;
55454+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55455+ kernel_cap_t cap_audit = __cap_empty_set;
55456+
55457+ if (!gr_acl_is_enabled())
55458+ return 1;
55459+
55460+ curracl = task->acl;
55461+
55462+ cap_drop = curracl->cap_lower;
55463+ cap_mask = curracl->cap_mask;
55464+ cap_audit = curracl->cap_invert_audit;
55465+
55466+ while ((curracl = curracl->parent_subject)) {
55467+ /* if the cap isn't specified in the current computed mask but is specified in the
55468+ current level subject, and is lowered in the current level subject, then add
55469+ it to the set of dropped capabilities
55470+ otherwise, add the current level subject's mask to the current computed mask
55471+ */
55472+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55473+ cap_raise(cap_mask, cap);
55474+ if (cap_raised(curracl->cap_lower, cap))
55475+ cap_raise(cap_drop, cap);
55476+ if (cap_raised(curracl->cap_invert_audit, cap))
55477+ cap_raise(cap_audit, cap);
55478+ }
55479+ }
55480+
55481+ if (!cap_raised(cap_drop, cap)) {
55482+ if (cap_raised(cap_audit, cap))
55483+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
55484+ return 1;
55485+ }
55486+
55487+ curracl = task->acl;
55488+
55489+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
55490+ && cap_raised(cred->cap_effective, cap)) {
55491+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55492+ task->role->roletype, cred->uid,
55493+ cred->gid, task->exec_file ?
55494+ gr_to_filename(task->exec_file->f_path.dentry,
55495+ task->exec_file->f_path.mnt) : curracl->filename,
55496+ curracl->filename, 0UL,
55497+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
55498+ return 1;
55499+ }
55500+
55501+ if ((cap >= 0) && (cap < (sizeof(captab_log)/sizeof(captab_log[0]))) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
55502+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
55503+ return 0;
55504+}
55505+
55506+int
55507+gr_is_capable_nolog(const int cap)
55508+{
55509+ struct acl_subject_label *curracl;
55510+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55511+
55512+ if (!gr_acl_is_enabled())
55513+ return 1;
55514+
55515+ curracl = current->acl;
55516+
55517+ cap_drop = curracl->cap_lower;
55518+ cap_mask = curracl->cap_mask;
55519+
55520+ while ((curracl = curracl->parent_subject)) {
55521+ /* if the cap isn't specified in the current computed mask but is specified in the
55522+ current level subject, and is lowered in the current level subject, then add
55523+ it to the set of dropped capabilities
55524+ otherwise, add the current level subject's mask to the current computed mask
55525+ */
55526+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55527+ cap_raise(cap_mask, cap);
55528+ if (cap_raised(curracl->cap_lower, cap))
55529+ cap_raise(cap_drop, cap);
55530+ }
55531+ }
55532+
55533+ if (!cap_raised(cap_drop, cap))
55534+ return 1;
55535+
55536+ return 0;
55537+}
55538+
55539diff -urNp linux-2.6.39.1/grsecurity/gracl_fs.c linux-2.6.39.1/grsecurity/gracl_fs.c
55540--- linux-2.6.39.1/grsecurity/gracl_fs.c 1969-12-31 19:00:00.000000000 -0500
55541+++ linux-2.6.39.1/grsecurity/gracl_fs.c 2011-05-22 19:41:42.000000000 -0400
55542@@ -0,0 +1,431 @@
55543+#include <linux/kernel.h>
55544+#include <linux/sched.h>
55545+#include <linux/types.h>
55546+#include <linux/fs.h>
55547+#include <linux/file.h>
55548+#include <linux/stat.h>
55549+#include <linux/grsecurity.h>
55550+#include <linux/grinternal.h>
55551+#include <linux/gracl.h>
55552+
55553+__u32
55554+gr_acl_handle_hidden_file(const struct dentry * dentry,
55555+ const struct vfsmount * mnt)
55556+{
55557+ __u32 mode;
55558+
55559+ if (unlikely(!dentry->d_inode))
55560+ return GR_FIND;
55561+
55562+ mode =
55563+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
55564+
55565+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
55566+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55567+ return mode;
55568+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
55569+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55570+ return 0;
55571+ } else if (unlikely(!(mode & GR_FIND)))
55572+ return 0;
55573+
55574+ return GR_FIND;
55575+}
55576+
55577+__u32
55578+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
55579+ const int fmode)
55580+{
55581+ __u32 reqmode = GR_FIND;
55582+ __u32 mode;
55583+
55584+ if (unlikely(!dentry->d_inode))
55585+ return reqmode;
55586+
55587+ if (unlikely(fmode & O_APPEND))
55588+ reqmode |= GR_APPEND;
55589+ else if (unlikely(fmode & FMODE_WRITE))
55590+ reqmode |= GR_WRITE;
55591+ if (likely((fmode & FMODE_READ) && !(fmode & O_DIRECTORY)))
55592+ reqmode |= GR_READ;
55593+ if ((fmode & FMODE_GREXEC) && (fmode & __FMODE_EXEC))
55594+ reqmode &= ~GR_READ;
55595+ mode =
55596+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55597+ mnt);
55598+
55599+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55600+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55601+ reqmode & GR_READ ? " reading" : "",
55602+ reqmode & GR_WRITE ? " writing" : reqmode &
55603+ GR_APPEND ? " appending" : "");
55604+ return reqmode;
55605+ } else
55606+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55607+ {
55608+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55609+ reqmode & GR_READ ? " reading" : "",
55610+ reqmode & GR_WRITE ? " writing" : reqmode &
55611+ GR_APPEND ? " appending" : "");
55612+ return 0;
55613+ } else if (unlikely((mode & reqmode) != reqmode))
55614+ return 0;
55615+
55616+ return reqmode;
55617+}
55618+
55619+__u32
55620+gr_acl_handle_creat(const struct dentry * dentry,
55621+ const struct dentry * p_dentry,
55622+ const struct vfsmount * p_mnt, const int fmode,
55623+ const int imode)
55624+{
55625+ __u32 reqmode = GR_WRITE | GR_CREATE;
55626+ __u32 mode;
55627+
55628+ if (unlikely(fmode & O_APPEND))
55629+ reqmode |= GR_APPEND;
55630+ if (unlikely((fmode & FMODE_READ) && !(fmode & O_DIRECTORY)))
55631+ reqmode |= GR_READ;
55632+ if (unlikely((fmode & O_CREAT) && (imode & (S_ISUID | S_ISGID))))
55633+ reqmode |= GR_SETID;
55634+
55635+ mode =
55636+ gr_check_create(dentry, p_dentry, p_mnt,
55637+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55638+
55639+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55640+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55641+ reqmode & GR_READ ? " reading" : "",
55642+ reqmode & GR_WRITE ? " writing" : reqmode &
55643+ GR_APPEND ? " appending" : "");
55644+ return reqmode;
55645+ } else
55646+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55647+ {
55648+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55649+ reqmode & GR_READ ? " reading" : "",
55650+ reqmode & GR_WRITE ? " writing" : reqmode &
55651+ GR_APPEND ? " appending" : "");
55652+ return 0;
55653+ } else if (unlikely((mode & reqmode) != reqmode))
55654+ return 0;
55655+
55656+ return reqmode;
55657+}
55658+
55659+__u32
55660+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
55661+ const int fmode)
55662+{
55663+ __u32 mode, reqmode = GR_FIND;
55664+
55665+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
55666+ reqmode |= GR_EXEC;
55667+ if (fmode & S_IWOTH)
55668+ reqmode |= GR_WRITE;
55669+ if (fmode & S_IROTH)
55670+ reqmode |= GR_READ;
55671+
55672+ mode =
55673+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55674+ mnt);
55675+
55676+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55677+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55678+ reqmode & GR_READ ? " reading" : "",
55679+ reqmode & GR_WRITE ? " writing" : "",
55680+ reqmode & GR_EXEC ? " executing" : "");
55681+ return reqmode;
55682+ } else
55683+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55684+ {
55685+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55686+ reqmode & GR_READ ? " reading" : "",
55687+ reqmode & GR_WRITE ? " writing" : "",
55688+ reqmode & GR_EXEC ? " executing" : "");
55689+ return 0;
55690+ } else if (unlikely((mode & reqmode) != reqmode))
55691+ return 0;
55692+
55693+ return reqmode;
55694+}
55695+
55696+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
55697+{
55698+ __u32 mode;
55699+
55700+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
55701+
55702+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55703+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
55704+ return mode;
55705+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55706+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
55707+ return 0;
55708+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
55709+ return 0;
55710+
55711+ return (reqmode);
55712+}
55713+
55714+__u32
55715+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
55716+{
55717+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
55718+}
55719+
55720+__u32
55721+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
55722+{
55723+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
55724+}
55725+
55726+__u32
55727+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
55728+{
55729+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
55730+}
55731+
55732+__u32
55733+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
55734+{
55735+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
55736+}
55737+
55738+__u32
55739+gr_acl_handle_fchmod(const struct dentry *dentry, const struct vfsmount *mnt,
55740+ mode_t mode)
55741+{
55742+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
55743+ return 1;
55744+
55745+ if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
55746+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
55747+ GR_FCHMOD_ACL_MSG);
55748+ } else {
55749+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_FCHMOD_ACL_MSG);
55750+ }
55751+}
55752+
55753+__u32
55754+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
55755+ mode_t mode)
55756+{
55757+ if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
55758+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
55759+ GR_CHMOD_ACL_MSG);
55760+ } else {
55761+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
55762+ }
55763+}
55764+
55765+__u32
55766+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
55767+{
55768+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
55769+}
55770+
55771+__u32
55772+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
55773+{
55774+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
55775+}
55776+
55777+__u32
55778+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
55779+{
55780+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
55781+}
55782+
55783+__u32
55784+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
55785+{
55786+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
55787+ GR_UNIXCONNECT_ACL_MSG);
55788+}
55789+
55790+/* hardlinks require at minimum create permission,
55791+ any additional privilege required is based on the
55792+ privilege of the file being linked to
55793+*/
55794+__u32
55795+gr_acl_handle_link(const struct dentry * new_dentry,
55796+ const struct dentry * parent_dentry,
55797+ const struct vfsmount * parent_mnt,
55798+ const struct dentry * old_dentry,
55799+ const struct vfsmount * old_mnt, const char *to)
55800+{
55801+ __u32 mode;
55802+ __u32 needmode = GR_CREATE | GR_LINK;
55803+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
55804+
55805+ mode =
55806+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
55807+ old_mnt);
55808+
55809+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
55810+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55811+ return mode;
55812+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55813+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55814+ return 0;
55815+ } else if (unlikely((mode & needmode) != needmode))
55816+ return 0;
55817+
55818+ return 1;
55819+}
55820+
55821+__u32
55822+gr_acl_handle_symlink(const struct dentry * new_dentry,
55823+ const struct dentry * parent_dentry,
55824+ const struct vfsmount * parent_mnt, const char *from)
55825+{
55826+ __u32 needmode = GR_WRITE | GR_CREATE;
55827+ __u32 mode;
55828+
55829+ mode =
55830+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
55831+ GR_CREATE | GR_AUDIT_CREATE |
55832+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
55833+
55834+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
55835+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55836+ return mode;
55837+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55838+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55839+ return 0;
55840+ } else if (unlikely((mode & needmode) != needmode))
55841+ return 0;
55842+
55843+ return (GR_WRITE | GR_CREATE);
55844+}
55845+
55846+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)
55847+{
55848+ __u32 mode;
55849+
55850+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55851+
55852+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55853+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
55854+ return mode;
55855+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55856+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
55857+ return 0;
55858+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
55859+ return 0;
55860+
55861+ return (reqmode);
55862+}
55863+
55864+__u32
55865+gr_acl_handle_mknod(const struct dentry * new_dentry,
55866+ const struct dentry * parent_dentry,
55867+ const struct vfsmount * parent_mnt,
55868+ const int mode)
55869+{
55870+ __u32 reqmode = GR_WRITE | GR_CREATE;
55871+ if (unlikely(mode & (S_ISUID | S_ISGID)))
55872+ reqmode |= GR_SETID;
55873+
55874+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
55875+ reqmode, GR_MKNOD_ACL_MSG);
55876+}
55877+
55878+__u32
55879+gr_acl_handle_mkdir(const struct dentry *new_dentry,
55880+ const struct dentry *parent_dentry,
55881+ const struct vfsmount *parent_mnt)
55882+{
55883+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
55884+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
55885+}
55886+
55887+#define RENAME_CHECK_SUCCESS(old, new) \
55888+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
55889+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
55890+
55891+int
55892+gr_acl_handle_rename(struct dentry *new_dentry,
55893+ struct dentry *parent_dentry,
55894+ const struct vfsmount *parent_mnt,
55895+ struct dentry *old_dentry,
55896+ struct inode *old_parent_inode,
55897+ struct vfsmount *old_mnt, const char *newname)
55898+{
55899+ __u32 comp1, comp2;
55900+ int error = 0;
55901+
55902+ if (unlikely(!gr_acl_is_enabled()))
55903+ return 0;
55904+
55905+ if (!new_dentry->d_inode) {
55906+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
55907+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
55908+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
55909+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
55910+ GR_DELETE | GR_AUDIT_DELETE |
55911+ GR_AUDIT_READ | GR_AUDIT_WRITE |
55912+ GR_SUPPRESS, old_mnt);
55913+ } else {
55914+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
55915+ GR_CREATE | GR_DELETE |
55916+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
55917+ GR_AUDIT_READ | GR_AUDIT_WRITE |
55918+ GR_SUPPRESS, parent_mnt);
55919+ comp2 =
55920+ gr_search_file(old_dentry,
55921+ GR_READ | GR_WRITE | GR_AUDIT_READ |
55922+ GR_DELETE | GR_AUDIT_DELETE |
55923+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
55924+ }
55925+
55926+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
55927+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
55928+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
55929+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
55930+ && !(comp2 & GR_SUPPRESS)) {
55931+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
55932+ error = -EACCES;
55933+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
55934+ error = -EACCES;
55935+
55936+ return error;
55937+}
55938+
55939+void
55940+gr_acl_handle_exit(void)
55941+{
55942+ u16 id;
55943+ char *rolename;
55944+ struct file *exec_file;
55945+
55946+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
55947+ !(current->role->roletype & GR_ROLE_PERSIST))) {
55948+ id = current->acl_role_id;
55949+ rolename = current->role->rolename;
55950+ gr_set_acls(1);
55951+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
55952+ }
55953+
55954+ write_lock(&grsec_exec_file_lock);
55955+ exec_file = current->exec_file;
55956+ current->exec_file = NULL;
55957+ write_unlock(&grsec_exec_file_lock);
55958+
55959+ if (exec_file)
55960+ fput(exec_file);
55961+}
55962+
55963+int
55964+gr_acl_handle_procpidmem(const struct task_struct *task)
55965+{
55966+ if (unlikely(!gr_acl_is_enabled()))
55967+ return 0;
55968+
55969+ if (task != current && task->acl->mode & GR_PROTPROCFD)
55970+ return -EACCES;
55971+
55972+ return 0;
55973+}
55974diff -urNp linux-2.6.39.1/grsecurity/gracl_ip.c linux-2.6.39.1/grsecurity/gracl_ip.c
55975--- linux-2.6.39.1/grsecurity/gracl_ip.c 1969-12-31 19:00:00.000000000 -0500
55976+++ linux-2.6.39.1/grsecurity/gracl_ip.c 2011-05-22 22:47:31.000000000 -0400
55977@@ -0,0 +1,381 @@
55978+#include <linux/kernel.h>
55979+#include <asm/uaccess.h>
55980+#include <asm/errno.h>
55981+#include <net/sock.h>
55982+#include <linux/file.h>
55983+#include <linux/fs.h>
55984+#include <linux/net.h>
55985+#include <linux/in.h>
55986+#include <linux/skbuff.h>
55987+#include <linux/ip.h>
55988+#include <linux/udp.h>
55989+#include <linux/types.h>
55990+#include <linux/sched.h>
55991+#include <linux/netdevice.h>
55992+#include <linux/inetdevice.h>
55993+#include <linux/gracl.h>
55994+#include <linux/grsecurity.h>
55995+#include <linux/grinternal.h>
55996+
55997+#define GR_BIND 0x01
55998+#define GR_CONNECT 0x02
55999+#define GR_INVERT 0x04
56000+#define GR_BINDOVERRIDE 0x08
56001+#define GR_CONNECTOVERRIDE 0x10
56002+#define GR_SOCK_FAMILY 0x20
56003+
56004+static const char * gr_protocols[IPPROTO_MAX] = {
56005+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
56006+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
56007+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
56008+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
56009+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
56010+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
56011+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
56012+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
56013+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
56014+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
56015+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
56016+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
56017+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
56018+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
56019+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
56020+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
56021+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
56022+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
56023+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
56024+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
56025+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
56026+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
56027+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
56028+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
56029+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
56030+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
56031+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
56032+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
56033+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
56034+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
56035+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
56036+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
56037+ };
56038+
56039+static const char * gr_socktypes[SOCK_MAX] = {
56040+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
56041+ "unknown:7", "unknown:8", "unknown:9", "packet"
56042+ };
56043+
56044+static const char * gr_sockfamilies[AF_MAX+1] = {
56045+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
56046+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
56047+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
56048+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
56049+ };
56050+
56051+const char *
56052+gr_proto_to_name(unsigned char proto)
56053+{
56054+ return gr_protocols[proto];
56055+}
56056+
56057+const char *
56058+gr_socktype_to_name(unsigned char type)
56059+{
56060+ return gr_socktypes[type];
56061+}
56062+
56063+const char *
56064+gr_sockfamily_to_name(unsigned char family)
56065+{
56066+ return gr_sockfamilies[family];
56067+}
56068+
56069+int
56070+gr_search_socket(const int domain, const int type, const int protocol)
56071+{
56072+ struct acl_subject_label *curr;
56073+ const struct cred *cred = current_cred();
56074+
56075+ if (unlikely(!gr_acl_is_enabled()))
56076+ goto exit;
56077+
56078+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
56079+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
56080+ goto exit; // let the kernel handle it
56081+
56082+ curr = current->acl;
56083+
56084+ if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
56085+ /* the family is allowed, if this is PF_INET allow it only if
56086+ the extra sock type/protocol checks pass */
56087+ if (domain == PF_INET)
56088+ goto inet_check;
56089+ goto exit;
56090+ } else {
56091+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56092+ __u32 fakeip = 0;
56093+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56094+ current->role->roletype, cred->uid,
56095+ cred->gid, current->exec_file ?
56096+ gr_to_filename(current->exec_file->f_path.dentry,
56097+ current->exec_file->f_path.mnt) :
56098+ curr->filename, curr->filename,
56099+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
56100+ &current->signal->saved_ip);
56101+ goto exit;
56102+ }
56103+ goto exit_fail;
56104+ }
56105+
56106+inet_check:
56107+ /* the rest of this checking is for IPv4 only */
56108+ if (!curr->ips)
56109+ goto exit;
56110+
56111+ if ((curr->ip_type & (1 << type)) &&
56112+ (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
56113+ goto exit;
56114+
56115+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56116+ /* we don't place acls on raw sockets , and sometimes
56117+ dgram/ip sockets are opened for ioctl and not
56118+ bind/connect, so we'll fake a bind learn log */
56119+ if (type == SOCK_RAW || type == SOCK_PACKET) {
56120+ __u32 fakeip = 0;
56121+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56122+ current->role->roletype, cred->uid,
56123+ cred->gid, current->exec_file ?
56124+ gr_to_filename(current->exec_file->f_path.dentry,
56125+ current->exec_file->f_path.mnt) :
56126+ curr->filename, curr->filename,
56127+ &fakeip, 0, type,
56128+ protocol, GR_CONNECT, &current->signal->saved_ip);
56129+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
56130+ __u32 fakeip = 0;
56131+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56132+ current->role->roletype, cred->uid,
56133+ cred->gid, current->exec_file ?
56134+ gr_to_filename(current->exec_file->f_path.dentry,
56135+ current->exec_file->f_path.mnt) :
56136+ curr->filename, curr->filename,
56137+ &fakeip, 0, type,
56138+ protocol, GR_BIND, &current->signal->saved_ip);
56139+ }
56140+ /* we'll log when they use connect or bind */
56141+ goto exit;
56142+ }
56143+
56144+exit_fail:
56145+ if (domain == PF_INET)
56146+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
56147+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
56148+ else
56149+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
56150+ gr_socktype_to_name(type), protocol);
56151+
56152+ return 0;
56153+exit:
56154+ return 1;
56155+}
56156+
56157+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)
56158+{
56159+ if ((ip->mode & mode) &&
56160+ (ip_port >= ip->low) &&
56161+ (ip_port <= ip->high) &&
56162+ ((ntohl(ip_addr) & our_netmask) ==
56163+ (ntohl(our_addr) & our_netmask))
56164+ && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
56165+ && (ip->type & (1 << type))) {
56166+ if (ip->mode & GR_INVERT)
56167+ return 2; // specifically denied
56168+ else
56169+ return 1; // allowed
56170+ }
56171+
56172+ return 0; // not specifically allowed, may continue parsing
56173+}
56174+
56175+static int
56176+gr_search_connectbind(const int full_mode, struct sock *sk,
56177+ struct sockaddr_in *addr, const int type)
56178+{
56179+ char iface[IFNAMSIZ] = {0};
56180+ struct acl_subject_label *curr;
56181+ struct acl_ip_label *ip;
56182+ struct inet_sock *isk;
56183+ struct net_device *dev;
56184+ struct in_device *idev;
56185+ unsigned long i;
56186+ int ret;
56187+ int mode = full_mode & (GR_BIND | GR_CONNECT);
56188+ __u32 ip_addr = 0;
56189+ __u32 our_addr;
56190+ __u32 our_netmask;
56191+ char *p;
56192+ __u16 ip_port = 0;
56193+ const struct cred *cred = current_cred();
56194+
56195+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
56196+ return 0;
56197+
56198+ curr = current->acl;
56199+ isk = inet_sk(sk);
56200+
56201+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
56202+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
56203+ addr->sin_addr.s_addr = curr->inaddr_any_override;
56204+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
56205+ struct sockaddr_in saddr;
56206+ int err;
56207+
56208+ saddr.sin_family = AF_INET;
56209+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
56210+ saddr.sin_port = isk->inet_sport;
56211+
56212+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56213+ if (err)
56214+ return err;
56215+
56216+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56217+ if (err)
56218+ return err;
56219+ }
56220+
56221+ if (!curr->ips)
56222+ return 0;
56223+
56224+ ip_addr = addr->sin_addr.s_addr;
56225+ ip_port = ntohs(addr->sin_port);
56226+
56227+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56228+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56229+ current->role->roletype, cred->uid,
56230+ cred->gid, current->exec_file ?
56231+ gr_to_filename(current->exec_file->f_path.dentry,
56232+ current->exec_file->f_path.mnt) :
56233+ curr->filename, curr->filename,
56234+ &ip_addr, ip_port, type,
56235+ sk->sk_protocol, mode, &current->signal->saved_ip);
56236+ return 0;
56237+ }
56238+
56239+ for (i = 0; i < curr->ip_num; i++) {
56240+ ip = *(curr->ips + i);
56241+ if (ip->iface != NULL) {
56242+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
56243+ p = strchr(iface, ':');
56244+ if (p != NULL)
56245+ *p = '\0';
56246+ dev = dev_get_by_name(sock_net(sk), iface);
56247+ if (dev == NULL)
56248+ continue;
56249+ idev = in_dev_get(dev);
56250+ if (idev == NULL) {
56251+ dev_put(dev);
56252+ continue;
56253+ }
56254+ rcu_read_lock();
56255+ for_ifa(idev) {
56256+ if (!strcmp(ip->iface, ifa->ifa_label)) {
56257+ our_addr = ifa->ifa_address;
56258+ our_netmask = 0xffffffff;
56259+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56260+ if (ret == 1) {
56261+ rcu_read_unlock();
56262+ in_dev_put(idev);
56263+ dev_put(dev);
56264+ return 0;
56265+ } else if (ret == 2) {
56266+ rcu_read_unlock();
56267+ in_dev_put(idev);
56268+ dev_put(dev);
56269+ goto denied;
56270+ }
56271+ }
56272+ } endfor_ifa(idev);
56273+ rcu_read_unlock();
56274+ in_dev_put(idev);
56275+ dev_put(dev);
56276+ } else {
56277+ our_addr = ip->addr;
56278+ our_netmask = ip->netmask;
56279+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56280+ if (ret == 1)
56281+ return 0;
56282+ else if (ret == 2)
56283+ goto denied;
56284+ }
56285+ }
56286+
56287+denied:
56288+ if (mode == GR_BIND)
56289+ 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));
56290+ else if (mode == GR_CONNECT)
56291+ 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));
56292+
56293+ return -EACCES;
56294+}
56295+
56296+int
56297+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
56298+{
56299+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
56300+}
56301+
56302+int
56303+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
56304+{
56305+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
56306+}
56307+
56308+int gr_search_listen(struct socket *sock)
56309+{
56310+ struct sock *sk = sock->sk;
56311+ struct sockaddr_in addr;
56312+
56313+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56314+ addr.sin_port = inet_sk(sk)->inet_sport;
56315+
56316+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56317+}
56318+
56319+int gr_search_accept(struct socket *sock)
56320+{
56321+ struct sock *sk = sock->sk;
56322+ struct sockaddr_in addr;
56323+
56324+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56325+ addr.sin_port = inet_sk(sk)->inet_sport;
56326+
56327+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56328+}
56329+
56330+int
56331+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
56332+{
56333+ if (addr)
56334+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
56335+ else {
56336+ struct sockaddr_in sin;
56337+ const struct inet_sock *inet = inet_sk(sk);
56338+
56339+ sin.sin_addr.s_addr = inet->inet_daddr;
56340+ sin.sin_port = inet->inet_dport;
56341+
56342+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56343+ }
56344+}
56345+
56346+int
56347+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
56348+{
56349+ struct sockaddr_in sin;
56350+
56351+ if (unlikely(skb->len < sizeof (struct udphdr)))
56352+ return 0; // skip this packet
56353+
56354+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
56355+ sin.sin_port = udp_hdr(skb)->source;
56356+
56357+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56358+}
56359diff -urNp linux-2.6.39.1/grsecurity/gracl_learn.c linux-2.6.39.1/grsecurity/gracl_learn.c
56360--- linux-2.6.39.1/grsecurity/gracl_learn.c 1969-12-31 19:00:00.000000000 -0500
56361+++ linux-2.6.39.1/grsecurity/gracl_learn.c 2011-05-22 22:47:45.000000000 -0400
56362@@ -0,0 +1,210 @@
56363+#include <linux/kernel.h>
56364+#include <linux/mm.h>
56365+#include <linux/sched.h>
56366+#include <linux/poll.h>
56367+#include <linux/string.h>
56368+#include <linux/file.h>
56369+#include <linux/types.h>
56370+#include <linux/vmalloc.h>
56371+#include <linux/grinternal.h>
56372+
56373+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
56374+ size_t count, loff_t *ppos);
56375+extern int gr_acl_is_enabled(void);
56376+
56377+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
56378+static int gr_learn_attached;
56379+
56380+/* use a 512k buffer */
56381+#define LEARN_BUFFER_SIZE (512 * 1024)
56382+
56383+static DEFINE_SPINLOCK(gr_learn_lock);
56384+static DEFINE_MUTEX(gr_learn_user_mutex);
56385+
56386+/* we need to maintain two buffers, so that the kernel context of grlearn
56387+ uses a semaphore around the userspace copying, and the other kernel contexts
56388+ use a spinlock when copying into the buffer, since they cannot sleep
56389+*/
56390+static char *learn_buffer;
56391+static char *learn_buffer_user;
56392+static int learn_buffer_len;
56393+static int learn_buffer_user_len;
56394+
56395+static ssize_t
56396+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
56397+{
56398+ DECLARE_WAITQUEUE(wait, current);
56399+ ssize_t retval = 0;
56400+
56401+ add_wait_queue(&learn_wait, &wait);
56402+ set_current_state(TASK_INTERRUPTIBLE);
56403+ do {
56404+ mutex_lock(&gr_learn_user_mutex);
56405+ spin_lock(&gr_learn_lock);
56406+ if (learn_buffer_len)
56407+ break;
56408+ spin_unlock(&gr_learn_lock);
56409+ mutex_unlock(&gr_learn_user_mutex);
56410+ if (file->f_flags & O_NONBLOCK) {
56411+ retval = -EAGAIN;
56412+ goto out;
56413+ }
56414+ if (signal_pending(current)) {
56415+ retval = -ERESTARTSYS;
56416+ goto out;
56417+ }
56418+
56419+ schedule();
56420+ } while (1);
56421+
56422+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
56423+ learn_buffer_user_len = learn_buffer_len;
56424+ retval = learn_buffer_len;
56425+ learn_buffer_len = 0;
56426+
56427+ spin_unlock(&gr_learn_lock);
56428+
56429+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
56430+ retval = -EFAULT;
56431+
56432+ mutex_unlock(&gr_learn_user_mutex);
56433+out:
56434+ set_current_state(TASK_RUNNING);
56435+ remove_wait_queue(&learn_wait, &wait);
56436+ return retval;
56437+}
56438+
56439+static unsigned int
56440+poll_learn(struct file * file, poll_table * wait)
56441+{
56442+ poll_wait(file, &learn_wait, wait);
56443+
56444+ if (learn_buffer_len)
56445+ return (POLLIN | POLLRDNORM);
56446+
56447+ return 0;
56448+}
56449+
56450+void
56451+gr_clear_learn_entries(void)
56452+{
56453+ char *tmp;
56454+
56455+ mutex_lock(&gr_learn_user_mutex);
56456+ if (learn_buffer != NULL) {
56457+ spin_lock(&gr_learn_lock);
56458+ tmp = learn_buffer;
56459+ learn_buffer = NULL;
56460+ spin_unlock(&gr_learn_lock);
56461+ vfree(learn_buffer);
56462+ }
56463+ if (learn_buffer_user != NULL) {
56464+ vfree(learn_buffer_user);
56465+ learn_buffer_user = NULL;
56466+ }
56467+ learn_buffer_len = 0;
56468+ mutex_unlock(&gr_learn_user_mutex);
56469+
56470+ return;
56471+}
56472+
56473+void
56474+gr_add_learn_entry(const char *fmt, ...)
56475+{
56476+ va_list args;
56477+ unsigned int len;
56478+
56479+ if (!gr_learn_attached)
56480+ return;
56481+
56482+ spin_lock(&gr_learn_lock);
56483+
56484+ /* leave a gap at the end so we know when it's "full" but don't have to
56485+ compute the exact length of the string we're trying to append
56486+ */
56487+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
56488+ spin_unlock(&gr_learn_lock);
56489+ wake_up_interruptible(&learn_wait);
56490+ return;
56491+ }
56492+ if (learn_buffer == NULL) {
56493+ spin_unlock(&gr_learn_lock);
56494+ return;
56495+ }
56496+
56497+ va_start(args, fmt);
56498+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
56499+ va_end(args);
56500+
56501+ learn_buffer_len += len + 1;
56502+
56503+ spin_unlock(&gr_learn_lock);
56504+ wake_up_interruptible(&learn_wait);
56505+
56506+ return;
56507+}
56508+
56509+static int
56510+open_learn(struct inode *inode, struct file *file)
56511+{
56512+ if (file->f_mode & FMODE_READ && gr_learn_attached)
56513+ return -EBUSY;
56514+ if (file->f_mode & FMODE_READ) {
56515+ int retval = 0;
56516+ mutex_lock(&gr_learn_user_mutex);
56517+ if (learn_buffer == NULL)
56518+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
56519+ if (learn_buffer_user == NULL)
56520+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
56521+ if (learn_buffer == NULL) {
56522+ retval = -ENOMEM;
56523+ goto out_error;
56524+ }
56525+ if (learn_buffer_user == NULL) {
56526+ retval = -ENOMEM;
56527+ goto out_error;
56528+ }
56529+ learn_buffer_len = 0;
56530+ learn_buffer_user_len = 0;
56531+ gr_learn_attached = 1;
56532+out_error:
56533+ mutex_unlock(&gr_learn_user_mutex);
56534+ return retval;
56535+ }
56536+ return 0;
56537+}
56538+
56539+static int
56540+close_learn(struct inode *inode, struct file *file)
56541+{
56542+ char *tmp;
56543+
56544+ if (file->f_mode & FMODE_READ) {
56545+ mutex_lock(&gr_learn_user_mutex);
56546+ if (learn_buffer != NULL) {
56547+ spin_lock(&gr_learn_lock);
56548+ tmp = learn_buffer;
56549+ learn_buffer = NULL;
56550+ spin_unlock(&gr_learn_lock);
56551+ vfree(tmp);
56552+ }
56553+ if (learn_buffer_user != NULL) {
56554+ vfree(learn_buffer_user);
56555+ learn_buffer_user = NULL;
56556+ }
56557+ learn_buffer_len = 0;
56558+ learn_buffer_user_len = 0;
56559+ gr_learn_attached = 0;
56560+ mutex_unlock(&gr_learn_user_mutex);
56561+ }
56562+
56563+ return 0;
56564+}
56565+
56566+const struct file_operations grsec_fops = {
56567+ .read = read_learn,
56568+ .write = write_grsec_handler,
56569+ .open = open_learn,
56570+ .release = close_learn,
56571+ .poll = poll_learn,
56572+};
56573diff -urNp linux-2.6.39.1/grsecurity/gracl_res.c linux-2.6.39.1/grsecurity/gracl_res.c
56574--- linux-2.6.39.1/grsecurity/gracl_res.c 1969-12-31 19:00:00.000000000 -0500
56575+++ linux-2.6.39.1/grsecurity/gracl_res.c 2011-05-22 19:41:42.000000000 -0400
56576@@ -0,0 +1,68 @@
56577+#include <linux/kernel.h>
56578+#include <linux/sched.h>
56579+#include <linux/gracl.h>
56580+#include <linux/grinternal.h>
56581+
56582+static const char *restab_log[] = {
56583+ [RLIMIT_CPU] = "RLIMIT_CPU",
56584+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
56585+ [RLIMIT_DATA] = "RLIMIT_DATA",
56586+ [RLIMIT_STACK] = "RLIMIT_STACK",
56587+ [RLIMIT_CORE] = "RLIMIT_CORE",
56588+ [RLIMIT_RSS] = "RLIMIT_RSS",
56589+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
56590+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
56591+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
56592+ [RLIMIT_AS] = "RLIMIT_AS",
56593+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
56594+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
56595+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
56596+ [RLIMIT_NICE] = "RLIMIT_NICE",
56597+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
56598+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
56599+ [GR_CRASH_RES] = "RLIMIT_CRASH"
56600+};
56601+
56602+void
56603+gr_log_resource(const struct task_struct *task,
56604+ const int res, const unsigned long wanted, const int gt)
56605+{
56606+ const struct cred *cred;
56607+ unsigned long rlim;
56608+
56609+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
56610+ return;
56611+
56612+ // not yet supported resource
56613+ if (unlikely(!restab_log[res]))
56614+ return;
56615+
56616+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
56617+ rlim = task_rlimit_max(task, res);
56618+ else
56619+ rlim = task_rlimit(task, res);
56620+
56621+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
56622+ return;
56623+
56624+ rcu_read_lock();
56625+ cred = __task_cred(task);
56626+
56627+ if (res == RLIMIT_NPROC &&
56628+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
56629+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
56630+ goto out_rcu_unlock;
56631+ else if (res == RLIMIT_MEMLOCK &&
56632+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
56633+ goto out_rcu_unlock;
56634+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
56635+ goto out_rcu_unlock;
56636+ rcu_read_unlock();
56637+
56638+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
56639+
56640+ return;
56641+out_rcu_unlock:
56642+ rcu_read_unlock();
56643+ return;
56644+}
56645diff -urNp linux-2.6.39.1/grsecurity/gracl_segv.c linux-2.6.39.1/grsecurity/gracl_segv.c
56646--- linux-2.6.39.1/grsecurity/gracl_segv.c 1969-12-31 19:00:00.000000000 -0500
56647+++ linux-2.6.39.1/grsecurity/gracl_segv.c 2011-05-22 22:47:39.000000000 -0400
56648@@ -0,0 +1,299 @@
56649+#include <linux/kernel.h>
56650+#include <linux/mm.h>
56651+#include <asm/uaccess.h>
56652+#include <asm/errno.h>
56653+#include <asm/mman.h>
56654+#include <net/sock.h>
56655+#include <linux/file.h>
56656+#include <linux/fs.h>
56657+#include <linux/net.h>
56658+#include <linux/in.h>
56659+#include <linux/slab.h>
56660+#include <linux/types.h>
56661+#include <linux/sched.h>
56662+#include <linux/timer.h>
56663+#include <linux/gracl.h>
56664+#include <linux/grsecurity.h>
56665+#include <linux/grinternal.h>
56666+
56667+static struct crash_uid *uid_set;
56668+static unsigned short uid_used;
56669+static DEFINE_SPINLOCK(gr_uid_lock);
56670+extern rwlock_t gr_inode_lock;
56671+extern struct acl_subject_label *
56672+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
56673+ struct acl_role_label *role);
56674+
56675+#ifdef CONFIG_BTRFS_FS
56676+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
56677+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
56678+#endif
56679+
56680+static inline dev_t __get_dev(const struct dentry *dentry)
56681+{
56682+#ifdef CONFIG_BTRFS_FS
56683+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
56684+ return get_btrfs_dev_from_inode(dentry->d_inode);
56685+ else
56686+#endif
56687+ return dentry->d_inode->i_sb->s_dev;
56688+}
56689+
56690+int
56691+gr_init_uidset(void)
56692+{
56693+ uid_set =
56694+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
56695+ uid_used = 0;
56696+
56697+ return uid_set ? 1 : 0;
56698+}
56699+
56700+void
56701+gr_free_uidset(void)
56702+{
56703+ if (uid_set)
56704+ kfree(uid_set);
56705+
56706+ return;
56707+}
56708+
56709+int
56710+gr_find_uid(const uid_t uid)
56711+{
56712+ struct crash_uid *tmp = uid_set;
56713+ uid_t buid;
56714+ int low = 0, high = uid_used - 1, mid;
56715+
56716+ while (high >= low) {
56717+ mid = (low + high) >> 1;
56718+ buid = tmp[mid].uid;
56719+ if (buid == uid)
56720+ return mid;
56721+ if (buid > uid)
56722+ high = mid - 1;
56723+ if (buid < uid)
56724+ low = mid + 1;
56725+ }
56726+
56727+ return -1;
56728+}
56729+
56730+static __inline__ void
56731+gr_insertsort(void)
56732+{
56733+ unsigned short i, j;
56734+ struct crash_uid index;
56735+
56736+ for (i = 1; i < uid_used; i++) {
56737+ index = uid_set[i];
56738+ j = i;
56739+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
56740+ uid_set[j] = uid_set[j - 1];
56741+ j--;
56742+ }
56743+ uid_set[j] = index;
56744+ }
56745+
56746+ return;
56747+}
56748+
56749+static __inline__ void
56750+gr_insert_uid(const uid_t uid, const unsigned long expires)
56751+{
56752+ int loc;
56753+
56754+ if (uid_used == GR_UIDTABLE_MAX)
56755+ return;
56756+
56757+ loc = gr_find_uid(uid);
56758+
56759+ if (loc >= 0) {
56760+ uid_set[loc].expires = expires;
56761+ return;
56762+ }
56763+
56764+ uid_set[uid_used].uid = uid;
56765+ uid_set[uid_used].expires = expires;
56766+ uid_used++;
56767+
56768+ gr_insertsort();
56769+
56770+ return;
56771+}
56772+
56773+void
56774+gr_remove_uid(const unsigned short loc)
56775+{
56776+ unsigned short i;
56777+
56778+ for (i = loc + 1; i < uid_used; i++)
56779+ uid_set[i - 1] = uid_set[i];
56780+
56781+ uid_used--;
56782+
56783+ return;
56784+}
56785+
56786+int
56787+gr_check_crash_uid(const uid_t uid)
56788+{
56789+ int loc;
56790+ int ret = 0;
56791+
56792+ if (unlikely(!gr_acl_is_enabled()))
56793+ return 0;
56794+
56795+ spin_lock(&gr_uid_lock);
56796+ loc = gr_find_uid(uid);
56797+
56798+ if (loc < 0)
56799+ goto out_unlock;
56800+
56801+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
56802+ gr_remove_uid(loc);
56803+ else
56804+ ret = 1;
56805+
56806+out_unlock:
56807+ spin_unlock(&gr_uid_lock);
56808+ return ret;
56809+}
56810+
56811+static __inline__ int
56812+proc_is_setxid(const struct cred *cred)
56813+{
56814+ if (cred->uid != cred->euid || cred->uid != cred->suid ||
56815+ cred->uid != cred->fsuid)
56816+ return 1;
56817+ if (cred->gid != cred->egid || cred->gid != cred->sgid ||
56818+ cred->gid != cred->fsgid)
56819+ return 1;
56820+
56821+ return 0;
56822+}
56823+
56824+extern int gr_fake_force_sig(int sig, struct task_struct *t);
56825+
56826+void
56827+gr_handle_crash(struct task_struct *task, const int sig)
56828+{
56829+ struct acl_subject_label *curr;
56830+ struct acl_subject_label *curr2;
56831+ struct task_struct *tsk, *tsk2;
56832+ const struct cred *cred;
56833+ const struct cred *cred2;
56834+
56835+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
56836+ return;
56837+
56838+ if (unlikely(!gr_acl_is_enabled()))
56839+ return;
56840+
56841+ curr = task->acl;
56842+
56843+ if (!(curr->resmask & (1 << GR_CRASH_RES)))
56844+ return;
56845+
56846+ if (time_before_eq(curr->expires, get_seconds())) {
56847+ curr->expires = 0;
56848+ curr->crashes = 0;
56849+ }
56850+
56851+ curr->crashes++;
56852+
56853+ if (!curr->expires)
56854+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
56855+
56856+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
56857+ time_after(curr->expires, get_seconds())) {
56858+ rcu_read_lock();
56859+ cred = __task_cred(task);
56860+ if (cred->uid && proc_is_setxid(cred)) {
56861+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
56862+ spin_lock(&gr_uid_lock);
56863+ gr_insert_uid(cred->uid, curr->expires);
56864+ spin_unlock(&gr_uid_lock);
56865+ curr->expires = 0;
56866+ curr->crashes = 0;
56867+ read_lock(&tasklist_lock);
56868+ do_each_thread(tsk2, tsk) {
56869+ cred2 = __task_cred(tsk);
56870+ if (tsk != task && cred2->uid == cred->uid)
56871+ gr_fake_force_sig(SIGKILL, tsk);
56872+ } while_each_thread(tsk2, tsk);
56873+ read_unlock(&tasklist_lock);
56874+ } else {
56875+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
56876+ read_lock(&tasklist_lock);
56877+ do_each_thread(tsk2, tsk) {
56878+ if (likely(tsk != task)) {
56879+ curr2 = tsk->acl;
56880+
56881+ if (curr2->device == curr->device &&
56882+ curr2->inode == curr->inode)
56883+ gr_fake_force_sig(SIGKILL, tsk);
56884+ }
56885+ } while_each_thread(tsk2, tsk);
56886+ read_unlock(&tasklist_lock);
56887+ }
56888+ rcu_read_unlock();
56889+ }
56890+
56891+ return;
56892+}
56893+
56894+int
56895+gr_check_crash_exec(const struct file *filp)
56896+{
56897+ struct acl_subject_label *curr;
56898+
56899+ if (unlikely(!gr_acl_is_enabled()))
56900+ return 0;
56901+
56902+ read_lock(&gr_inode_lock);
56903+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
56904+ __get_dev(filp->f_path.dentry),
56905+ current->role);
56906+ read_unlock(&gr_inode_lock);
56907+
56908+ if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
56909+ (!curr->crashes && !curr->expires))
56910+ return 0;
56911+
56912+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
56913+ time_after(curr->expires, get_seconds()))
56914+ return 1;
56915+ else if (time_before_eq(curr->expires, get_seconds())) {
56916+ curr->crashes = 0;
56917+ curr->expires = 0;
56918+ }
56919+
56920+ return 0;
56921+}
56922+
56923+void
56924+gr_handle_alertkill(struct task_struct *task)
56925+{
56926+ struct acl_subject_label *curracl;
56927+ __u32 curr_ip;
56928+ struct task_struct *p, *p2;
56929+
56930+ if (unlikely(!gr_acl_is_enabled()))
56931+ return;
56932+
56933+ curracl = task->acl;
56934+ curr_ip = task->signal->curr_ip;
56935+
56936+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
56937+ read_lock(&tasklist_lock);
56938+ do_each_thread(p2, p) {
56939+ if (p->signal->curr_ip == curr_ip)
56940+ gr_fake_force_sig(SIGKILL, p);
56941+ } while_each_thread(p2, p);
56942+ read_unlock(&tasklist_lock);
56943+ } else if (curracl->mode & GR_KILLPROC)
56944+ gr_fake_force_sig(SIGKILL, task);
56945+
56946+ return;
56947+}
56948diff -urNp linux-2.6.39.1/grsecurity/gracl_shm.c linux-2.6.39.1/grsecurity/gracl_shm.c
56949--- linux-2.6.39.1/grsecurity/gracl_shm.c 1969-12-31 19:00:00.000000000 -0500
56950+++ linux-2.6.39.1/grsecurity/gracl_shm.c 2011-05-22 19:41:42.000000000 -0400
56951@@ -0,0 +1,40 @@
56952+#include <linux/kernel.h>
56953+#include <linux/mm.h>
56954+#include <linux/sched.h>
56955+#include <linux/file.h>
56956+#include <linux/ipc.h>
56957+#include <linux/gracl.h>
56958+#include <linux/grsecurity.h>
56959+#include <linux/grinternal.h>
56960+
56961+int
56962+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
56963+ const time_t shm_createtime, const uid_t cuid, const int shmid)
56964+{
56965+ struct task_struct *task;
56966+
56967+ if (!gr_acl_is_enabled())
56968+ return 1;
56969+
56970+ rcu_read_lock();
56971+ read_lock(&tasklist_lock);
56972+
56973+ task = find_task_by_vpid(shm_cprid);
56974+
56975+ if (unlikely(!task))
56976+ task = find_task_by_vpid(shm_lapid);
56977+
56978+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
56979+ (task->pid == shm_lapid)) &&
56980+ (task->acl->mode & GR_PROTSHM) &&
56981+ (task->acl != current->acl))) {
56982+ read_unlock(&tasklist_lock);
56983+ rcu_read_unlock();
56984+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
56985+ return 0;
56986+ }
56987+ read_unlock(&tasklist_lock);
56988+ rcu_read_unlock();
56989+
56990+ return 1;
56991+}
56992diff -urNp linux-2.6.39.1/grsecurity/grsec_chdir.c linux-2.6.39.1/grsecurity/grsec_chdir.c
56993--- linux-2.6.39.1/grsecurity/grsec_chdir.c 1969-12-31 19:00:00.000000000 -0500
56994+++ linux-2.6.39.1/grsecurity/grsec_chdir.c 2011-05-22 19:41:42.000000000 -0400
56995@@ -0,0 +1,19 @@
56996+#include <linux/kernel.h>
56997+#include <linux/sched.h>
56998+#include <linux/fs.h>
56999+#include <linux/file.h>
57000+#include <linux/grsecurity.h>
57001+#include <linux/grinternal.h>
57002+
57003+void
57004+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
57005+{
57006+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
57007+ if ((grsec_enable_chdir && grsec_enable_group &&
57008+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
57009+ !grsec_enable_group)) {
57010+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
57011+ }
57012+#endif
57013+ return;
57014+}
57015diff -urNp linux-2.6.39.1/grsecurity/grsec_chroot.c linux-2.6.39.1/grsecurity/grsec_chroot.c
57016--- linux-2.6.39.1/grsecurity/grsec_chroot.c 1969-12-31 19:00:00.000000000 -0500
57017+++ linux-2.6.39.1/grsecurity/grsec_chroot.c 2011-05-22 19:41:42.000000000 -0400
57018@@ -0,0 +1,355 @@
57019+#include <linux/kernel.h>
57020+#include <linux/module.h>
57021+#include <linux/sched.h>
57022+#include <linux/file.h>
57023+#include <linux/fs.h>
57024+#include <linux/mount.h>
57025+#include <linux/types.h>
57026+#include <linux/pid_namespace.h>
57027+#include <linux/grsecurity.h>
57028+#include <linux/grinternal.h>
57029+
57030+void gr_set_chroot_entries(struct task_struct *task, struct path *path)
57031+{
57032+#ifdef CONFIG_GRKERNSEC
57033+ if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
57034+ path->dentry != task->nsproxy->mnt_ns->root->mnt_root)
57035+ task->gr_is_chrooted = 1;
57036+ else
57037+ task->gr_is_chrooted = 0;
57038+
57039+ task->gr_chroot_dentry = path->dentry;
57040+#endif
57041+ return;
57042+}
57043+
57044+void gr_clear_chroot_entries(struct task_struct *task)
57045+{
57046+#ifdef CONFIG_GRKERNSEC
57047+ task->gr_is_chrooted = 0;
57048+ task->gr_chroot_dentry = NULL;
57049+#endif
57050+ return;
57051+}
57052+
57053+int
57054+gr_handle_chroot_unix(struct pid *pid)
57055+{
57056+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57057+ struct task_struct *p;
57058+
57059+ if (unlikely(!grsec_enable_chroot_unix))
57060+ return 1;
57061+
57062+ if (likely(!proc_is_chrooted(current)))
57063+ return 1;
57064+
57065+ rcu_read_lock();
57066+ read_lock(&tasklist_lock);
57067+ p = pid_task(pid, PIDTYPE_PID);
57068+ if (unlikely(p && !have_same_root(current, p))) {
57069+ read_unlock(&tasklist_lock);
57070+ rcu_read_unlock();
57071+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
57072+ return 0;
57073+ }
57074+ read_unlock(&tasklist_lock);
57075+ rcu_read_unlock();
57076+#endif
57077+ return 1;
57078+}
57079+
57080+int
57081+gr_handle_chroot_nice(void)
57082+{
57083+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57084+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
57085+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
57086+ return -EPERM;
57087+ }
57088+#endif
57089+ return 0;
57090+}
57091+
57092+int
57093+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
57094+{
57095+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57096+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
57097+ && proc_is_chrooted(current)) {
57098+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
57099+ return -EACCES;
57100+ }
57101+#endif
57102+ return 0;
57103+}
57104+
57105+int
57106+gr_handle_chroot_rawio(const struct inode *inode)
57107+{
57108+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57109+ if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
57110+ inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
57111+ return 1;
57112+#endif
57113+ return 0;
57114+}
57115+
57116+int
57117+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
57118+{
57119+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57120+ struct task_struct *p;
57121+ int ret = 0;
57122+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
57123+ return ret;
57124+
57125+ read_lock(&tasklist_lock);
57126+ do_each_pid_task(pid, type, p) {
57127+ if (!have_same_root(current, p)) {
57128+ ret = 1;
57129+ goto out;
57130+ }
57131+ } while_each_pid_task(pid, type, p);
57132+out:
57133+ read_unlock(&tasklist_lock);
57134+ return ret;
57135+#endif
57136+ return 0;
57137+}
57138+
57139+int
57140+gr_pid_is_chrooted(struct task_struct *p)
57141+{
57142+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57143+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
57144+ return 0;
57145+
57146+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
57147+ !have_same_root(current, p)) {
57148+ return 1;
57149+ }
57150+#endif
57151+ return 0;
57152+}
57153+
57154+EXPORT_SYMBOL(gr_pid_is_chrooted);
57155+
57156+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
57157+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
57158+{
57159+ struct path path, currentroot;
57160+ int ret = 0;
57161+
57162+ path.dentry = (struct dentry *)u_dentry;
57163+ path.mnt = (struct vfsmount *)u_mnt;
57164+ get_fs_root(current->fs, &currentroot);
57165+ if (path_is_under(&path, &currentroot))
57166+ ret = 1;
57167+ path_put(&currentroot);
57168+
57169+ return ret;
57170+}
57171+#endif
57172+
57173+int
57174+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
57175+{
57176+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
57177+ if (!grsec_enable_chroot_fchdir)
57178+ return 1;
57179+
57180+ if (!proc_is_chrooted(current))
57181+ return 1;
57182+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
57183+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
57184+ return 0;
57185+ }
57186+#endif
57187+ return 1;
57188+}
57189+
57190+int
57191+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57192+ const time_t shm_createtime)
57193+{
57194+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
57195+ struct pid *pid = NULL;
57196+ time_t starttime;
57197+
57198+ if (unlikely(!grsec_enable_chroot_shmat))
57199+ return 1;
57200+
57201+ if (likely(!proc_is_chrooted(current)))
57202+ return 1;
57203+
57204+ rcu_read_lock();
57205+ read_lock(&tasklist_lock);
57206+
57207+ pid = find_vpid(shm_cprid);
57208+ if (pid) {
57209+ struct task_struct *p;
57210+ p = pid_task(pid, PIDTYPE_PID);
57211+ if (p == NULL)
57212+ goto unlock;
57213+ starttime = p->start_time.tv_sec;
57214+ if (unlikely(!have_same_root(current, p) &&
57215+ time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime))) {
57216+ read_unlock(&tasklist_lock);
57217+ rcu_read_unlock();
57218+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57219+ return 0;
57220+ }
57221+ } else {
57222+ pid = find_vpid(shm_lapid);
57223+ if (pid) {
57224+ struct task_struct *p;
57225+ p = pid_task(pid, PIDTYPE_PID);
57226+ if (p == NULL)
57227+ goto unlock;
57228+ if (unlikely(!have_same_root(current, p))) {
57229+ read_unlock(&tasklist_lock);
57230+ rcu_read_unlock();
57231+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57232+ return 0;
57233+ }
57234+ }
57235+ }
57236+unlock:
57237+ read_unlock(&tasklist_lock);
57238+ rcu_read_unlock();
57239+#endif
57240+ return 1;
57241+}
57242+
57243+void
57244+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
57245+{
57246+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
57247+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
57248+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
57249+#endif
57250+ return;
57251+}
57252+
57253+int
57254+gr_handle_chroot_mknod(const struct dentry *dentry,
57255+ const struct vfsmount *mnt, const int mode)
57256+{
57257+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
57258+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
57259+ proc_is_chrooted(current)) {
57260+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
57261+ return -EPERM;
57262+ }
57263+#endif
57264+ return 0;
57265+}
57266+
57267+int
57268+gr_handle_chroot_mount(const struct dentry *dentry,
57269+ const struct vfsmount *mnt, const char *dev_name)
57270+{
57271+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57272+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
57273+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name, dentry, mnt);
57274+ return -EPERM;
57275+ }
57276+#endif
57277+ return 0;
57278+}
57279+
57280+int
57281+gr_handle_chroot_pivot(void)
57282+{
57283+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
57284+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
57285+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
57286+ return -EPERM;
57287+ }
57288+#endif
57289+ return 0;
57290+}
57291+
57292+int
57293+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
57294+{
57295+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
57296+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
57297+ !gr_is_outside_chroot(dentry, mnt)) {
57298+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
57299+ return -EPERM;
57300+ }
57301+#endif
57302+ return 0;
57303+}
57304+
57305+int
57306+gr_handle_chroot_caps(struct path *path)
57307+{
57308+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57309+ if (grsec_enable_chroot_caps && current->pid > 1 && current->fs != NULL &&
57310+ (init_task.fs->root.dentry != path->dentry) &&
57311+ (current->nsproxy->mnt_ns->root->mnt_root != path->dentry)) {
57312+
57313+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57314+ const struct cred *old = current_cred();
57315+ struct cred *new = prepare_creds();
57316+ if (new == NULL)
57317+ return 1;
57318+
57319+ new->cap_permitted = cap_drop(old->cap_permitted,
57320+ chroot_caps);
57321+ new->cap_inheritable = cap_drop(old->cap_inheritable,
57322+ chroot_caps);
57323+ new->cap_effective = cap_drop(old->cap_effective,
57324+ chroot_caps);
57325+
57326+ commit_creds(new);
57327+
57328+ return 0;
57329+ }
57330+#endif
57331+ return 0;
57332+}
57333+
57334+int
57335+gr_handle_chroot_sysctl(const int op)
57336+{
57337+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
57338+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
57339+ proc_is_chrooted(current))
57340+ return -EACCES;
57341+#endif
57342+ return 0;
57343+}
57344+
57345+void
57346+gr_handle_chroot_chdir(struct path *path)
57347+{
57348+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
57349+ if (grsec_enable_chroot_chdir)
57350+ set_fs_pwd(current->fs, path);
57351+#endif
57352+ return;
57353+}
57354+
57355+int
57356+gr_handle_chroot_chmod(const struct dentry *dentry,
57357+ const struct vfsmount *mnt, const int mode)
57358+{
57359+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
57360+ /* allow chmod +s on directories, but not files */
57361+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
57362+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
57363+ proc_is_chrooted(current)) {
57364+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
57365+ return -EPERM;
57366+ }
57367+#endif
57368+ return 0;
57369+}
57370+
57371+#ifdef CONFIG_SECURITY
57372+EXPORT_SYMBOL(gr_handle_chroot_caps);
57373+#endif
57374diff -urNp linux-2.6.39.1/grsecurity/grsec_disabled.c linux-2.6.39.1/grsecurity/grsec_disabled.c
57375--- linux-2.6.39.1/grsecurity/grsec_disabled.c 1969-12-31 19:00:00.000000000 -0500
57376+++ linux-2.6.39.1/grsecurity/grsec_disabled.c 2011-05-22 19:41:42.000000000 -0400
57377@@ -0,0 +1,447 @@
57378+#include <linux/kernel.h>
57379+#include <linux/module.h>
57380+#include <linux/sched.h>
57381+#include <linux/file.h>
57382+#include <linux/fs.h>
57383+#include <linux/kdev_t.h>
57384+#include <linux/net.h>
57385+#include <linux/in.h>
57386+#include <linux/ip.h>
57387+#include <linux/skbuff.h>
57388+#include <linux/sysctl.h>
57389+
57390+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
57391+void
57392+pax_set_initial_flags(struct linux_binprm *bprm)
57393+{
57394+ return;
57395+}
57396+#endif
57397+
57398+#ifdef CONFIG_SYSCTL
57399+__u32
57400+gr_handle_sysctl(const struct ctl_table * table, const int op)
57401+{
57402+ return 0;
57403+}
57404+#endif
57405+
57406+#ifdef CONFIG_TASKSTATS
57407+int gr_is_taskstats_denied(int pid)
57408+{
57409+ return 0;
57410+}
57411+#endif
57412+
57413+int
57414+gr_acl_is_enabled(void)
57415+{
57416+ return 0;
57417+}
57418+
57419+int
57420+gr_handle_rawio(const struct inode *inode)
57421+{
57422+ return 0;
57423+}
57424+
57425+void
57426+gr_acl_handle_psacct(struct task_struct *task, const long code)
57427+{
57428+ return;
57429+}
57430+
57431+int
57432+gr_handle_ptrace(struct task_struct *task, const long request)
57433+{
57434+ return 0;
57435+}
57436+
57437+int
57438+gr_handle_proc_ptrace(struct task_struct *task)
57439+{
57440+ return 0;
57441+}
57442+
57443+void
57444+gr_learn_resource(const struct task_struct *task,
57445+ const int res, const unsigned long wanted, const int gt)
57446+{
57447+ return;
57448+}
57449+
57450+int
57451+gr_set_acls(const int type)
57452+{
57453+ return 0;
57454+}
57455+
57456+int
57457+gr_check_hidden_task(const struct task_struct *tsk)
57458+{
57459+ return 0;
57460+}
57461+
57462+int
57463+gr_check_protected_task(const struct task_struct *task)
57464+{
57465+ return 0;
57466+}
57467+
57468+int
57469+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
57470+{
57471+ return 0;
57472+}
57473+
57474+void
57475+gr_copy_label(struct task_struct *tsk)
57476+{
57477+ return;
57478+}
57479+
57480+void
57481+gr_set_pax_flags(struct task_struct *task)
57482+{
57483+ return;
57484+}
57485+
57486+int
57487+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
57488+ const int unsafe_share)
57489+{
57490+ return 0;
57491+}
57492+
57493+void
57494+gr_handle_delete(const ino_t ino, const dev_t dev)
57495+{
57496+ return;
57497+}
57498+
57499+void
57500+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
57501+{
57502+ return;
57503+}
57504+
57505+void
57506+gr_handle_crash(struct task_struct *task, const int sig)
57507+{
57508+ return;
57509+}
57510+
57511+int
57512+gr_check_crash_exec(const struct file *filp)
57513+{
57514+ return 0;
57515+}
57516+
57517+int
57518+gr_check_crash_uid(const uid_t uid)
57519+{
57520+ return 0;
57521+}
57522+
57523+void
57524+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
57525+ struct dentry *old_dentry,
57526+ struct dentry *new_dentry,
57527+ struct vfsmount *mnt, const __u8 replace)
57528+{
57529+ return;
57530+}
57531+
57532+int
57533+gr_search_socket(const int family, const int type, const int protocol)
57534+{
57535+ return 1;
57536+}
57537+
57538+int
57539+gr_search_connectbind(const int mode, const struct socket *sock,
57540+ const struct sockaddr_in *addr)
57541+{
57542+ return 0;
57543+}
57544+
57545+int
57546+gr_is_capable(const int cap)
57547+{
57548+ return 1;
57549+}
57550+
57551+int
57552+gr_is_capable_nolog(const int cap)
57553+{
57554+ return 1;
57555+}
57556+
57557+void
57558+gr_handle_alertkill(struct task_struct *task)
57559+{
57560+ return;
57561+}
57562+
57563+__u32
57564+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
57565+{
57566+ return 1;
57567+}
57568+
57569+__u32
57570+gr_acl_handle_hidden_file(const struct dentry * dentry,
57571+ const struct vfsmount * mnt)
57572+{
57573+ return 1;
57574+}
57575+
57576+__u32
57577+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
57578+ const int fmode)
57579+{
57580+ return 1;
57581+}
57582+
57583+__u32
57584+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
57585+{
57586+ return 1;
57587+}
57588+
57589+__u32
57590+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
57591+{
57592+ return 1;
57593+}
57594+
57595+int
57596+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
57597+ unsigned int *vm_flags)
57598+{
57599+ return 1;
57600+}
57601+
57602+__u32
57603+gr_acl_handle_truncate(const struct dentry * dentry,
57604+ const struct vfsmount * mnt)
57605+{
57606+ return 1;
57607+}
57608+
57609+__u32
57610+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
57611+{
57612+ return 1;
57613+}
57614+
57615+__u32
57616+gr_acl_handle_access(const struct dentry * dentry,
57617+ const struct vfsmount * mnt, const int fmode)
57618+{
57619+ return 1;
57620+}
57621+
57622+__u32
57623+gr_acl_handle_fchmod(const struct dentry * dentry, const struct vfsmount * mnt,
57624+ mode_t mode)
57625+{
57626+ return 1;
57627+}
57628+
57629+__u32
57630+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
57631+ mode_t mode)
57632+{
57633+ return 1;
57634+}
57635+
57636+__u32
57637+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
57638+{
57639+ return 1;
57640+}
57641+
57642+__u32
57643+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
57644+{
57645+ return 1;
57646+}
57647+
57648+void
57649+grsecurity_init(void)
57650+{
57651+ return;
57652+}
57653+
57654+__u32
57655+gr_acl_handle_mknod(const struct dentry * new_dentry,
57656+ const struct dentry * parent_dentry,
57657+ const struct vfsmount * parent_mnt,
57658+ const int mode)
57659+{
57660+ return 1;
57661+}
57662+
57663+__u32
57664+gr_acl_handle_mkdir(const struct dentry * new_dentry,
57665+ const struct dentry * parent_dentry,
57666+ const struct vfsmount * parent_mnt)
57667+{
57668+ return 1;
57669+}
57670+
57671+__u32
57672+gr_acl_handle_symlink(const struct dentry * new_dentry,
57673+ const struct dentry * parent_dentry,
57674+ const struct vfsmount * parent_mnt, const char *from)
57675+{
57676+ return 1;
57677+}
57678+
57679+__u32
57680+gr_acl_handle_link(const struct dentry * new_dentry,
57681+ const struct dentry * parent_dentry,
57682+ const struct vfsmount * parent_mnt,
57683+ const struct dentry * old_dentry,
57684+ const struct vfsmount * old_mnt, const char *to)
57685+{
57686+ return 1;
57687+}
57688+
57689+int
57690+gr_acl_handle_rename(const struct dentry *new_dentry,
57691+ const struct dentry *parent_dentry,
57692+ const struct vfsmount *parent_mnt,
57693+ const struct dentry *old_dentry,
57694+ const struct inode *old_parent_inode,
57695+ const struct vfsmount *old_mnt, const char *newname)
57696+{
57697+ return 0;
57698+}
57699+
57700+int
57701+gr_acl_handle_filldir(const struct file *file, const char *name,
57702+ const int namelen, const ino_t ino)
57703+{
57704+ return 1;
57705+}
57706+
57707+int
57708+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57709+ const time_t shm_createtime, const uid_t cuid, const int shmid)
57710+{
57711+ return 1;
57712+}
57713+
57714+int
57715+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
57716+{
57717+ return 0;
57718+}
57719+
57720+int
57721+gr_search_accept(const struct socket *sock)
57722+{
57723+ return 0;
57724+}
57725+
57726+int
57727+gr_search_listen(const struct socket *sock)
57728+{
57729+ return 0;
57730+}
57731+
57732+int
57733+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
57734+{
57735+ return 0;
57736+}
57737+
57738+__u32
57739+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
57740+{
57741+ return 1;
57742+}
57743+
57744+__u32
57745+gr_acl_handle_creat(const struct dentry * dentry,
57746+ const struct dentry * p_dentry,
57747+ const struct vfsmount * p_mnt, const int fmode,
57748+ const int imode)
57749+{
57750+ return 1;
57751+}
57752+
57753+void
57754+gr_acl_handle_exit(void)
57755+{
57756+ return;
57757+}
57758+
57759+int
57760+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
57761+{
57762+ return 1;
57763+}
57764+
57765+void
57766+gr_set_role_label(const uid_t uid, const gid_t gid)
57767+{
57768+ return;
57769+}
57770+
57771+int
57772+gr_acl_handle_procpidmem(const struct task_struct *task)
57773+{
57774+ return 0;
57775+}
57776+
57777+int
57778+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
57779+{
57780+ return 0;
57781+}
57782+
57783+int
57784+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
57785+{
57786+ return 0;
57787+}
57788+
57789+void
57790+gr_set_kernel_label(struct task_struct *task)
57791+{
57792+ return;
57793+}
57794+
57795+int
57796+gr_check_user_change(int real, int effective, int fs)
57797+{
57798+ return 0;
57799+}
57800+
57801+int
57802+gr_check_group_change(int real, int effective, int fs)
57803+{
57804+ return 0;
57805+}
57806+
57807+int gr_acl_enable_at_secure(void)
57808+{
57809+ return 0;
57810+}
57811+
57812+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
57813+{
57814+ return dentry->d_inode->i_sb->s_dev;
57815+}
57816+
57817+EXPORT_SYMBOL(gr_is_capable);
57818+EXPORT_SYMBOL(gr_is_capable_nolog);
57819+EXPORT_SYMBOL(gr_learn_resource);
57820+EXPORT_SYMBOL(gr_set_kernel_label);
57821+#ifdef CONFIG_SECURITY
57822+EXPORT_SYMBOL(gr_check_user_change);
57823+EXPORT_SYMBOL(gr_check_group_change);
57824+#endif
57825diff -urNp linux-2.6.39.1/grsecurity/grsec_exec.c linux-2.6.39.1/grsecurity/grsec_exec.c
57826--- linux-2.6.39.1/grsecurity/grsec_exec.c 1969-12-31 19:00:00.000000000 -0500
57827+++ linux-2.6.39.1/grsecurity/grsec_exec.c 2011-05-22 22:41:29.000000000 -0400
57828@@ -0,0 +1,146 @@
57829+#include <linux/kernel.h>
57830+#include <linux/sched.h>
57831+#include <linux/file.h>
57832+#include <linux/binfmts.h>
57833+#include <linux/fs.h>
57834+#include <linux/types.h>
57835+#include <linux/grdefs.h>
57836+#include <linux/grinternal.h>
57837+#include <linux/capability.h>
57838+#include <linux/compat.h>
57839+
57840+#include <asm/uaccess.h>
57841+
57842+#ifdef CONFIG_GRKERNSEC_EXECLOG
57843+static char gr_exec_arg_buf[132];
57844+static DEFINE_MUTEX(gr_exec_arg_mutex);
57845+#endif
57846+
57847+int
57848+gr_handle_nproc(void)
57849+{
57850+#ifdef CONFIG_GRKERNSEC_EXECVE
57851+ const struct cred *cred = current_cred();
57852+ if (grsec_enable_execve && cred->user &&
57853+ (atomic_read(&cred->user->processes) > rlimit(RLIMIT_NPROC)) &&
57854+ !capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE)) {
57855+ gr_log_noargs(GR_DONT_AUDIT, GR_NPROC_MSG);
57856+ return -EAGAIN;
57857+ }
57858+#endif
57859+ return 0;
57860+}
57861+
57862+void
57863+gr_handle_exec_args(struct linux_binprm *bprm, const char __user *const __user *argv)
57864+{
57865+#ifdef CONFIG_GRKERNSEC_EXECLOG
57866+ char *grarg = gr_exec_arg_buf;
57867+ unsigned int i, x, execlen = 0;
57868+ char c;
57869+
57870+ if (!((grsec_enable_execlog && grsec_enable_group &&
57871+ in_group_p(grsec_audit_gid))
57872+ || (grsec_enable_execlog && !grsec_enable_group)))
57873+ return;
57874+
57875+ mutex_lock(&gr_exec_arg_mutex);
57876+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
57877+
57878+ if (unlikely(argv == NULL))
57879+ goto log;
57880+
57881+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
57882+ const char __user *p;
57883+ unsigned int len;
57884+
57885+ if (copy_from_user(&p, argv + i, sizeof(p)))
57886+ goto log;
57887+ if (!p)
57888+ goto log;
57889+ len = strnlen_user(p, 128 - execlen);
57890+ if (len > 128 - execlen)
57891+ len = 128 - execlen;
57892+ else if (len > 0)
57893+ len--;
57894+ if (copy_from_user(grarg + execlen, p, len))
57895+ goto log;
57896+
57897+ /* rewrite unprintable characters */
57898+ for (x = 0; x < len; x++) {
57899+ c = *(grarg + execlen + x);
57900+ if (c < 32 || c > 126)
57901+ *(grarg + execlen + x) = ' ';
57902+ }
57903+
57904+ execlen += len;
57905+ *(grarg + execlen) = ' ';
57906+ *(grarg + execlen + 1) = '\0';
57907+ execlen++;
57908+ }
57909+
57910+ log:
57911+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
57912+ bprm->file->f_path.mnt, grarg);
57913+ mutex_unlock(&gr_exec_arg_mutex);
57914+#endif
57915+ return;
57916+}
57917+
57918+#ifdef CONFIG_COMPAT
57919+void
57920+gr_handle_exec_args_compat(struct linux_binprm *bprm, compat_uptr_t __user *argv)
57921+{
57922+#ifdef CONFIG_GRKERNSEC_EXECLOG
57923+ char *grarg = gr_exec_arg_buf;
57924+ unsigned int i, x, execlen = 0;
57925+ char c;
57926+
57927+ if (!((grsec_enable_execlog && grsec_enable_group &&
57928+ in_group_p(grsec_audit_gid))
57929+ || (grsec_enable_execlog && !grsec_enable_group)))
57930+ return;
57931+
57932+ mutex_lock(&gr_exec_arg_mutex);
57933+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
57934+
57935+ if (unlikely(argv == NULL))
57936+ goto log;
57937+
57938+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
57939+ compat_uptr_t p;
57940+ unsigned int len;
57941+
57942+ if (get_user(p, argv + i))
57943+ goto log;
57944+ len = strnlen_user(compat_ptr(p), 128 - execlen);
57945+ if (len > 128 - execlen)
57946+ len = 128 - execlen;
57947+ else if (len > 0)
57948+ len--;
57949+ else
57950+ goto log;
57951+ if (copy_from_user(grarg + execlen, compat_ptr(p), len))
57952+ goto log;
57953+
57954+ /* rewrite unprintable characters */
57955+ for (x = 0; x < len; x++) {
57956+ c = *(grarg + execlen + x);
57957+ if (c < 32 || c > 126)
57958+ *(grarg + execlen + x) = ' ';
57959+ }
57960+
57961+ execlen += len;
57962+ *(grarg + execlen) = ' ';
57963+ *(grarg + execlen + 1) = '\0';
57964+ execlen++;
57965+ }
57966+
57967+ log:
57968+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
57969+ bprm->file->f_path.mnt, grarg);
57970+ mutex_unlock(&gr_exec_arg_mutex);
57971+#endif
57972+ return;
57973+}
57974+#endif
57975diff -urNp linux-2.6.39.1/grsecurity/grsec_fifo.c linux-2.6.39.1/grsecurity/grsec_fifo.c
57976--- linux-2.6.39.1/grsecurity/grsec_fifo.c 1969-12-31 19:00:00.000000000 -0500
57977+++ linux-2.6.39.1/grsecurity/grsec_fifo.c 2011-05-22 19:41:42.000000000 -0400
57978@@ -0,0 +1,24 @@
57979+#include <linux/kernel.h>
57980+#include <linux/sched.h>
57981+#include <linux/fs.h>
57982+#include <linux/file.h>
57983+#include <linux/grinternal.h>
57984+
57985+int
57986+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
57987+ const struct dentry *dir, const int flag, const int acc_mode)
57988+{
57989+#ifdef CONFIG_GRKERNSEC_FIFO
57990+ const struct cred *cred = current_cred();
57991+
57992+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
57993+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
57994+ (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
57995+ (cred->fsuid != dentry->d_inode->i_uid)) {
57996+ if (!inode_permission(dentry->d_inode, acc_mode))
57997+ gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
57998+ return -EACCES;
57999+ }
58000+#endif
58001+ return 0;
58002+}
58003diff -urNp linux-2.6.39.1/grsecurity/grsec_fork.c linux-2.6.39.1/grsecurity/grsec_fork.c
58004--- linux-2.6.39.1/grsecurity/grsec_fork.c 1969-12-31 19:00:00.000000000 -0500
58005+++ linux-2.6.39.1/grsecurity/grsec_fork.c 2011-05-22 19:41:42.000000000 -0400
58006@@ -0,0 +1,23 @@
58007+#include <linux/kernel.h>
58008+#include <linux/sched.h>
58009+#include <linux/grsecurity.h>
58010+#include <linux/grinternal.h>
58011+#include <linux/errno.h>
58012+
58013+void
58014+gr_log_forkfail(const int retval)
58015+{
58016+#ifdef CONFIG_GRKERNSEC_FORKFAIL
58017+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
58018+ switch (retval) {
58019+ case -EAGAIN:
58020+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
58021+ break;
58022+ case -ENOMEM:
58023+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
58024+ break;
58025+ }
58026+ }
58027+#endif
58028+ return;
58029+}
58030diff -urNp linux-2.6.39.1/grsecurity/grsec_init.c linux-2.6.39.1/grsecurity/grsec_init.c
58031--- linux-2.6.39.1/grsecurity/grsec_init.c 1969-12-31 19:00:00.000000000 -0500
58032+++ linux-2.6.39.1/grsecurity/grsec_init.c 2011-05-22 22:47:15.000000000 -0400
58033@@ -0,0 +1,269 @@
58034+#include <linux/kernel.h>
58035+#include <linux/sched.h>
58036+#include <linux/mm.h>
58037+#include <linux/gracl.h>
58038+#include <linux/slab.h>
58039+#include <linux/vmalloc.h>
58040+#include <linux/percpu.h>
58041+#include <linux/module.h>
58042+
58043+int grsec_enable_link;
58044+int grsec_enable_dmesg;
58045+int grsec_enable_harden_ptrace;
58046+int grsec_enable_fifo;
58047+int grsec_enable_execve;
58048+int grsec_enable_execlog;
58049+int grsec_enable_signal;
58050+int grsec_enable_forkfail;
58051+int grsec_enable_audit_ptrace;
58052+int grsec_enable_time;
58053+int grsec_enable_audit_textrel;
58054+int grsec_enable_group;
58055+int grsec_audit_gid;
58056+int grsec_enable_chdir;
58057+int grsec_enable_mount;
58058+int grsec_enable_rofs;
58059+int grsec_enable_chroot_findtask;
58060+int grsec_enable_chroot_mount;
58061+int grsec_enable_chroot_shmat;
58062+int grsec_enable_chroot_fchdir;
58063+int grsec_enable_chroot_double;
58064+int grsec_enable_chroot_pivot;
58065+int grsec_enable_chroot_chdir;
58066+int grsec_enable_chroot_chmod;
58067+int grsec_enable_chroot_mknod;
58068+int grsec_enable_chroot_nice;
58069+int grsec_enable_chroot_execlog;
58070+int grsec_enable_chroot_caps;
58071+int grsec_enable_chroot_sysctl;
58072+int grsec_enable_chroot_unix;
58073+int grsec_enable_tpe;
58074+int grsec_tpe_gid;
58075+int grsec_enable_blackhole;
58076+#ifdef CONFIG_IPV6_MODULE
58077+EXPORT_SYMBOL(grsec_enable_blackhole);
58078+#endif
58079+int grsec_lastack_retries;
58080+int grsec_enable_tpe_all;
58081+int grsec_enable_tpe_invert;
58082+int grsec_enable_socket_all;
58083+int grsec_socket_all_gid;
58084+int grsec_enable_socket_client;
58085+int grsec_socket_client_gid;
58086+int grsec_enable_socket_server;
58087+int grsec_socket_server_gid;
58088+int grsec_resource_logging;
58089+int grsec_disable_privio;
58090+int grsec_enable_log_rwxmaps;
58091+int grsec_lock;
58092+
58093+DEFINE_SPINLOCK(grsec_alert_lock);
58094+unsigned long grsec_alert_wtime = 0;
58095+unsigned long grsec_alert_fyet = 0;
58096+
58097+DEFINE_SPINLOCK(grsec_audit_lock);
58098+
58099+DEFINE_RWLOCK(grsec_exec_file_lock);
58100+
58101+char *gr_shared_page[4];
58102+
58103+char *gr_alert_log_fmt;
58104+char *gr_audit_log_fmt;
58105+char *gr_alert_log_buf;
58106+char *gr_audit_log_buf;
58107+
58108+extern struct gr_arg *gr_usermode;
58109+extern unsigned char *gr_system_salt;
58110+extern unsigned char *gr_system_sum;
58111+
58112+void __init
58113+grsecurity_init(void)
58114+{
58115+ int j;
58116+ /* create the per-cpu shared pages */
58117+
58118+#ifdef CONFIG_X86
58119+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
58120+#endif
58121+
58122+ for (j = 0; j < 4; j++) {
58123+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
58124+ if (gr_shared_page[j] == NULL) {
58125+ panic("Unable to allocate grsecurity shared page");
58126+ return;
58127+ }
58128+ }
58129+
58130+ /* allocate log buffers */
58131+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
58132+ if (!gr_alert_log_fmt) {
58133+ panic("Unable to allocate grsecurity alert log format buffer");
58134+ return;
58135+ }
58136+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
58137+ if (!gr_audit_log_fmt) {
58138+ panic("Unable to allocate grsecurity audit log format buffer");
58139+ return;
58140+ }
58141+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58142+ if (!gr_alert_log_buf) {
58143+ panic("Unable to allocate grsecurity alert log buffer");
58144+ return;
58145+ }
58146+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58147+ if (!gr_audit_log_buf) {
58148+ panic("Unable to allocate grsecurity audit log buffer");
58149+ return;
58150+ }
58151+
58152+ /* allocate memory for authentication structure */
58153+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
58154+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
58155+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
58156+
58157+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
58158+ panic("Unable to allocate grsecurity authentication structure");
58159+ return;
58160+ }
58161+
58162+
58163+#ifdef CONFIG_GRKERNSEC_IO
58164+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
58165+ grsec_disable_privio = 1;
58166+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58167+ grsec_disable_privio = 1;
58168+#else
58169+ grsec_disable_privio = 0;
58170+#endif
58171+#endif
58172+
58173+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
58174+ /* for backward compatibility, tpe_invert always defaults to on if
58175+ enabled in the kernel
58176+ */
58177+ grsec_enable_tpe_invert = 1;
58178+#endif
58179+
58180+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58181+#ifndef CONFIG_GRKERNSEC_SYSCTL
58182+ grsec_lock = 1;
58183+#endif
58184+
58185+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58186+ grsec_enable_audit_textrel = 1;
58187+#endif
58188+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58189+ grsec_enable_log_rwxmaps = 1;
58190+#endif
58191+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
58192+ grsec_enable_group = 1;
58193+ grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
58194+#endif
58195+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
58196+ grsec_enable_chdir = 1;
58197+#endif
58198+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
58199+ grsec_enable_harden_ptrace = 1;
58200+#endif
58201+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58202+ grsec_enable_mount = 1;
58203+#endif
58204+#ifdef CONFIG_GRKERNSEC_LINK
58205+ grsec_enable_link = 1;
58206+#endif
58207+#ifdef CONFIG_GRKERNSEC_DMESG
58208+ grsec_enable_dmesg = 1;
58209+#endif
58210+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
58211+ grsec_enable_blackhole = 1;
58212+ grsec_lastack_retries = 4;
58213+#endif
58214+#ifdef CONFIG_GRKERNSEC_FIFO
58215+ grsec_enable_fifo = 1;
58216+#endif
58217+#ifdef CONFIG_GRKERNSEC_EXECVE
58218+ grsec_enable_execve = 1;
58219+#endif
58220+#ifdef CONFIG_GRKERNSEC_EXECLOG
58221+ grsec_enable_execlog = 1;
58222+#endif
58223+#ifdef CONFIG_GRKERNSEC_SIGNAL
58224+ grsec_enable_signal = 1;
58225+#endif
58226+#ifdef CONFIG_GRKERNSEC_FORKFAIL
58227+ grsec_enable_forkfail = 1;
58228+#endif
58229+#ifdef CONFIG_GRKERNSEC_TIME
58230+ grsec_enable_time = 1;
58231+#endif
58232+#ifdef CONFIG_GRKERNSEC_RESLOG
58233+ grsec_resource_logging = 1;
58234+#endif
58235+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
58236+ grsec_enable_chroot_findtask = 1;
58237+#endif
58238+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
58239+ grsec_enable_chroot_unix = 1;
58240+#endif
58241+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
58242+ grsec_enable_chroot_mount = 1;
58243+#endif
58244+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
58245+ grsec_enable_chroot_fchdir = 1;
58246+#endif
58247+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
58248+ grsec_enable_chroot_shmat = 1;
58249+#endif
58250+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58251+ grsec_enable_audit_ptrace = 1;
58252+#endif
58253+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
58254+ grsec_enable_chroot_double = 1;
58255+#endif
58256+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
58257+ grsec_enable_chroot_pivot = 1;
58258+#endif
58259+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
58260+ grsec_enable_chroot_chdir = 1;
58261+#endif
58262+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
58263+ grsec_enable_chroot_chmod = 1;
58264+#endif
58265+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
58266+ grsec_enable_chroot_mknod = 1;
58267+#endif
58268+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58269+ grsec_enable_chroot_nice = 1;
58270+#endif
58271+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
58272+ grsec_enable_chroot_execlog = 1;
58273+#endif
58274+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58275+ grsec_enable_chroot_caps = 1;
58276+#endif
58277+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
58278+ grsec_enable_chroot_sysctl = 1;
58279+#endif
58280+#ifdef CONFIG_GRKERNSEC_TPE
58281+ grsec_enable_tpe = 1;
58282+ grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
58283+#ifdef CONFIG_GRKERNSEC_TPE_ALL
58284+ grsec_enable_tpe_all = 1;
58285+#endif
58286+#endif
58287+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58288+ grsec_enable_socket_all = 1;
58289+ grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
58290+#endif
58291+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58292+ grsec_enable_socket_client = 1;
58293+ grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
58294+#endif
58295+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58296+ grsec_enable_socket_server = 1;
58297+ grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
58298+#endif
58299+#endif
58300+
58301+ return;
58302+}
58303diff -urNp linux-2.6.39.1/grsecurity/grsec_link.c linux-2.6.39.1/grsecurity/grsec_link.c
58304--- linux-2.6.39.1/grsecurity/grsec_link.c 1969-12-31 19:00:00.000000000 -0500
58305+++ linux-2.6.39.1/grsecurity/grsec_link.c 2011-05-22 19:41:42.000000000 -0400
58306@@ -0,0 +1,43 @@
58307+#include <linux/kernel.h>
58308+#include <linux/sched.h>
58309+#include <linux/fs.h>
58310+#include <linux/file.h>
58311+#include <linux/grinternal.h>
58312+
58313+int
58314+gr_handle_follow_link(const struct inode *parent,
58315+ const struct inode *inode,
58316+ const struct dentry *dentry, const struct vfsmount *mnt)
58317+{
58318+#ifdef CONFIG_GRKERNSEC_LINK
58319+ const struct cred *cred = current_cred();
58320+
58321+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
58322+ (parent->i_mode & S_ISVTX) && (parent->i_uid != inode->i_uid) &&
58323+ (parent->i_mode & S_IWOTH) && (cred->fsuid != inode->i_uid)) {
58324+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
58325+ return -EACCES;
58326+ }
58327+#endif
58328+ return 0;
58329+}
58330+
58331+int
58332+gr_handle_hardlink(const struct dentry *dentry,
58333+ const struct vfsmount *mnt,
58334+ struct inode *inode, const int mode, const char *to)
58335+{
58336+#ifdef CONFIG_GRKERNSEC_LINK
58337+ const struct cred *cred = current_cred();
58338+
58339+ if (grsec_enable_link && cred->fsuid != inode->i_uid &&
58340+ (!S_ISREG(mode) || (mode & S_ISUID) ||
58341+ ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
58342+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
58343+ !capable(CAP_FOWNER) && cred->uid) {
58344+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
58345+ return -EPERM;
58346+ }
58347+#endif
58348+ return 0;
58349+}
58350diff -urNp linux-2.6.39.1/grsecurity/grsec_log.c linux-2.6.39.1/grsecurity/grsec_log.c
58351--- linux-2.6.39.1/grsecurity/grsec_log.c 1969-12-31 19:00:00.000000000 -0500
58352+++ linux-2.6.39.1/grsecurity/grsec_log.c 2011-05-22 19:41:42.000000000 -0400
58353@@ -0,0 +1,310 @@
58354+#include <linux/kernel.h>
58355+#include <linux/sched.h>
58356+#include <linux/file.h>
58357+#include <linux/tty.h>
58358+#include <linux/fs.h>
58359+#include <linux/grinternal.h>
58360+
58361+#ifdef CONFIG_TREE_PREEMPT_RCU
58362+#define DISABLE_PREEMPT() preempt_disable()
58363+#define ENABLE_PREEMPT() preempt_enable()
58364+#else
58365+#define DISABLE_PREEMPT()
58366+#define ENABLE_PREEMPT()
58367+#endif
58368+
58369+#define BEGIN_LOCKS(x) \
58370+ DISABLE_PREEMPT(); \
58371+ rcu_read_lock(); \
58372+ read_lock(&tasklist_lock); \
58373+ read_lock(&grsec_exec_file_lock); \
58374+ if (x != GR_DO_AUDIT) \
58375+ spin_lock(&grsec_alert_lock); \
58376+ else \
58377+ spin_lock(&grsec_audit_lock)
58378+
58379+#define END_LOCKS(x) \
58380+ if (x != GR_DO_AUDIT) \
58381+ spin_unlock(&grsec_alert_lock); \
58382+ else \
58383+ spin_unlock(&grsec_audit_lock); \
58384+ read_unlock(&grsec_exec_file_lock); \
58385+ read_unlock(&tasklist_lock); \
58386+ rcu_read_unlock(); \
58387+ ENABLE_PREEMPT(); \
58388+ if (x == GR_DONT_AUDIT) \
58389+ gr_handle_alertkill(current)
58390+
58391+enum {
58392+ FLOODING,
58393+ NO_FLOODING
58394+};
58395+
58396+extern char *gr_alert_log_fmt;
58397+extern char *gr_audit_log_fmt;
58398+extern char *gr_alert_log_buf;
58399+extern char *gr_audit_log_buf;
58400+
58401+static int gr_log_start(int audit)
58402+{
58403+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
58404+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
58405+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58406+
58407+ if (audit == GR_DO_AUDIT)
58408+ goto set_fmt;
58409+
58410+ if (!grsec_alert_wtime || jiffies - grsec_alert_wtime > CONFIG_GRKERNSEC_FLOODTIME * HZ) {
58411+ grsec_alert_wtime = jiffies;
58412+ grsec_alert_fyet = 0;
58413+ } else if ((jiffies - grsec_alert_wtime < CONFIG_GRKERNSEC_FLOODTIME * HZ) && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
58414+ grsec_alert_fyet++;
58415+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
58416+ grsec_alert_wtime = jiffies;
58417+ grsec_alert_fyet++;
58418+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
58419+ return FLOODING;
58420+ } else return FLOODING;
58421+
58422+set_fmt:
58423+ memset(buf, 0, PAGE_SIZE);
58424+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
58425+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
58426+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58427+ } else if (current->signal->curr_ip) {
58428+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
58429+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
58430+ } else if (gr_acl_is_enabled()) {
58431+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
58432+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58433+ } else {
58434+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
58435+ strcpy(buf, fmt);
58436+ }
58437+
58438+ return NO_FLOODING;
58439+}
58440+
58441+static void gr_log_middle(int audit, const char *msg, va_list ap)
58442+ __attribute__ ((format (printf, 2, 0)));
58443+
58444+static void gr_log_middle(int audit, const char *msg, va_list ap)
58445+{
58446+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58447+ unsigned int len = strlen(buf);
58448+
58449+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58450+
58451+ return;
58452+}
58453+
58454+static void gr_log_middle_varargs(int audit, const char *msg, ...)
58455+ __attribute__ ((format (printf, 2, 3)));
58456+
58457+static void gr_log_middle_varargs(int audit, const char *msg, ...)
58458+{
58459+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58460+ unsigned int len = strlen(buf);
58461+ va_list ap;
58462+
58463+ va_start(ap, msg);
58464+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58465+ va_end(ap);
58466+
58467+ return;
58468+}
58469+
58470+static void gr_log_end(int audit)
58471+{
58472+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58473+ unsigned int len = strlen(buf);
58474+
58475+ snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
58476+ printk("%s\n", buf);
58477+
58478+ return;
58479+}
58480+
58481+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
58482+{
58483+ int logtype;
58484+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
58485+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
58486+ void *voidptr = NULL;
58487+ int num1 = 0, num2 = 0;
58488+ unsigned long ulong1 = 0, ulong2 = 0;
58489+ struct dentry *dentry = NULL;
58490+ struct vfsmount *mnt = NULL;
58491+ struct file *file = NULL;
58492+ struct task_struct *task = NULL;
58493+ const struct cred *cred, *pcred;
58494+ va_list ap;
58495+
58496+ BEGIN_LOCKS(audit);
58497+ logtype = gr_log_start(audit);
58498+ if (logtype == FLOODING) {
58499+ END_LOCKS(audit);
58500+ return;
58501+ }
58502+ va_start(ap, argtypes);
58503+ switch (argtypes) {
58504+ case GR_TTYSNIFF:
58505+ task = va_arg(ap, struct task_struct *);
58506+ 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);
58507+ break;
58508+ case GR_SYSCTL_HIDDEN:
58509+ str1 = va_arg(ap, char *);
58510+ gr_log_middle_varargs(audit, msg, result, str1);
58511+ break;
58512+ case GR_RBAC:
58513+ dentry = va_arg(ap, struct dentry *);
58514+ mnt = va_arg(ap, struct vfsmount *);
58515+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
58516+ break;
58517+ case GR_RBAC_STR:
58518+ dentry = va_arg(ap, struct dentry *);
58519+ mnt = va_arg(ap, struct vfsmount *);
58520+ str1 = va_arg(ap, char *);
58521+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
58522+ break;
58523+ case GR_STR_RBAC:
58524+ str1 = va_arg(ap, char *);
58525+ dentry = va_arg(ap, struct dentry *);
58526+ mnt = va_arg(ap, struct vfsmount *);
58527+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
58528+ break;
58529+ case GR_RBAC_MODE2:
58530+ dentry = va_arg(ap, struct dentry *);
58531+ mnt = va_arg(ap, struct vfsmount *);
58532+ str1 = va_arg(ap, char *);
58533+ str2 = va_arg(ap, char *);
58534+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
58535+ break;
58536+ case GR_RBAC_MODE3:
58537+ dentry = va_arg(ap, struct dentry *);
58538+ mnt = va_arg(ap, struct vfsmount *);
58539+ str1 = va_arg(ap, char *);
58540+ str2 = va_arg(ap, char *);
58541+ str3 = va_arg(ap, char *);
58542+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
58543+ break;
58544+ case GR_FILENAME:
58545+ dentry = va_arg(ap, struct dentry *);
58546+ mnt = va_arg(ap, struct vfsmount *);
58547+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
58548+ break;
58549+ case GR_STR_FILENAME:
58550+ str1 = va_arg(ap, char *);
58551+ dentry = va_arg(ap, struct dentry *);
58552+ mnt = va_arg(ap, struct vfsmount *);
58553+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
58554+ break;
58555+ case GR_FILENAME_STR:
58556+ dentry = va_arg(ap, struct dentry *);
58557+ mnt = va_arg(ap, struct vfsmount *);
58558+ str1 = va_arg(ap, char *);
58559+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
58560+ break;
58561+ case GR_FILENAME_TWO_INT:
58562+ dentry = va_arg(ap, struct dentry *);
58563+ mnt = va_arg(ap, struct vfsmount *);
58564+ num1 = va_arg(ap, int);
58565+ num2 = va_arg(ap, int);
58566+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
58567+ break;
58568+ case GR_FILENAME_TWO_INT_STR:
58569+ dentry = va_arg(ap, struct dentry *);
58570+ mnt = va_arg(ap, struct vfsmount *);
58571+ num1 = va_arg(ap, int);
58572+ num2 = va_arg(ap, int);
58573+ str1 = va_arg(ap, char *);
58574+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
58575+ break;
58576+ case GR_TEXTREL:
58577+ file = va_arg(ap, struct file *);
58578+ ulong1 = va_arg(ap, unsigned long);
58579+ ulong2 = va_arg(ap, unsigned long);
58580+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
58581+ break;
58582+ case GR_PTRACE:
58583+ task = va_arg(ap, struct task_struct *);
58584+ 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);
58585+ break;
58586+ case GR_RESOURCE:
58587+ task = va_arg(ap, struct task_struct *);
58588+ cred = __task_cred(task);
58589+ pcred = __task_cred(task->real_parent);
58590+ ulong1 = va_arg(ap, unsigned long);
58591+ str1 = va_arg(ap, char *);
58592+ ulong2 = va_arg(ap, unsigned long);
58593+ 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);
58594+ break;
58595+ case GR_CAP:
58596+ task = va_arg(ap, struct task_struct *);
58597+ cred = __task_cred(task);
58598+ pcred = __task_cred(task->real_parent);
58599+ str1 = va_arg(ap, char *);
58600+ 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);
58601+ break;
58602+ case GR_SIG:
58603+ str1 = va_arg(ap, char *);
58604+ voidptr = va_arg(ap, void *);
58605+ gr_log_middle_varargs(audit, msg, str1, voidptr);
58606+ break;
58607+ case GR_SIG2:
58608+ task = va_arg(ap, struct task_struct *);
58609+ cred = __task_cred(task);
58610+ pcred = __task_cred(task->real_parent);
58611+ num1 = va_arg(ap, int);
58612+ 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);
58613+ break;
58614+ case GR_CRASH1:
58615+ task = va_arg(ap, struct task_struct *);
58616+ cred = __task_cred(task);
58617+ pcred = __task_cred(task->real_parent);
58618+ ulong1 = va_arg(ap, unsigned long);
58619+ 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);
58620+ break;
58621+ case GR_CRASH2:
58622+ task = va_arg(ap, struct task_struct *);
58623+ cred = __task_cred(task);
58624+ pcred = __task_cred(task->real_parent);
58625+ ulong1 = va_arg(ap, unsigned long);
58626+ 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);
58627+ break;
58628+ case GR_RWXMAP:
58629+ file = va_arg(ap, struct file *);
58630+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
58631+ break;
58632+ case GR_PSACCT:
58633+ {
58634+ unsigned int wday, cday;
58635+ __u8 whr, chr;
58636+ __u8 wmin, cmin;
58637+ __u8 wsec, csec;
58638+ char cur_tty[64] = { 0 };
58639+ char parent_tty[64] = { 0 };
58640+
58641+ task = va_arg(ap, struct task_struct *);
58642+ wday = va_arg(ap, unsigned int);
58643+ cday = va_arg(ap, unsigned int);
58644+ whr = va_arg(ap, int);
58645+ chr = va_arg(ap, int);
58646+ wmin = va_arg(ap, int);
58647+ cmin = va_arg(ap, int);
58648+ wsec = va_arg(ap, int);
58649+ csec = va_arg(ap, int);
58650+ ulong1 = va_arg(ap, unsigned long);
58651+ cred = __task_cred(task);
58652+ pcred = __task_cred(task->real_parent);
58653+
58654+ 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);
58655+ }
58656+ break;
58657+ default:
58658+ gr_log_middle(audit, msg, ap);
58659+ }
58660+ va_end(ap);
58661+ gr_log_end(audit);
58662+ END_LOCKS(audit);
58663+}
58664diff -urNp linux-2.6.39.1/grsecurity/grsec_mem.c linux-2.6.39.1/grsecurity/grsec_mem.c
58665--- linux-2.6.39.1/grsecurity/grsec_mem.c 1969-12-31 19:00:00.000000000 -0500
58666+++ linux-2.6.39.1/grsecurity/grsec_mem.c 2011-05-22 19:41:42.000000000 -0400
58667@@ -0,0 +1,33 @@
58668+#include <linux/kernel.h>
58669+#include <linux/sched.h>
58670+#include <linux/mm.h>
58671+#include <linux/mman.h>
58672+#include <linux/grinternal.h>
58673+
58674+void
58675+gr_handle_ioperm(void)
58676+{
58677+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
58678+ return;
58679+}
58680+
58681+void
58682+gr_handle_iopl(void)
58683+{
58684+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
58685+ return;
58686+}
58687+
58688+void
58689+gr_handle_mem_readwrite(u64 from, u64 to)
58690+{
58691+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
58692+ return;
58693+}
58694+
58695+void
58696+gr_handle_vm86(void)
58697+{
58698+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
58699+ return;
58700+}
58701diff -urNp linux-2.6.39.1/grsecurity/grsec_mount.c linux-2.6.39.1/grsecurity/grsec_mount.c
58702--- linux-2.6.39.1/grsecurity/grsec_mount.c 1969-12-31 19:00:00.000000000 -0500
58703+++ linux-2.6.39.1/grsecurity/grsec_mount.c 2011-05-22 19:41:42.000000000 -0400
58704@@ -0,0 +1,62 @@
58705+#include <linux/kernel.h>
58706+#include <linux/sched.h>
58707+#include <linux/mount.h>
58708+#include <linux/grsecurity.h>
58709+#include <linux/grinternal.h>
58710+
58711+void
58712+gr_log_remount(const char *devname, const int retval)
58713+{
58714+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58715+ if (grsec_enable_mount && (retval >= 0))
58716+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
58717+#endif
58718+ return;
58719+}
58720+
58721+void
58722+gr_log_unmount(const char *devname, const int retval)
58723+{
58724+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58725+ if (grsec_enable_mount && (retval >= 0))
58726+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
58727+#endif
58728+ return;
58729+}
58730+
58731+void
58732+gr_log_mount(const char *from, const char *to, const int retval)
58733+{
58734+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58735+ if (grsec_enable_mount && (retval >= 0))
58736+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from, to);
58737+#endif
58738+ return;
58739+}
58740+
58741+int
58742+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
58743+{
58744+#ifdef CONFIG_GRKERNSEC_ROFS
58745+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
58746+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
58747+ return -EPERM;
58748+ } else
58749+ return 0;
58750+#endif
58751+ return 0;
58752+}
58753+
58754+int
58755+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
58756+{
58757+#ifdef CONFIG_GRKERNSEC_ROFS
58758+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
58759+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
58760+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
58761+ return -EPERM;
58762+ } else
58763+ return 0;
58764+#endif
58765+ return 0;
58766+}
58767diff -urNp linux-2.6.39.1/grsecurity/grsec_pax.c linux-2.6.39.1/grsecurity/grsec_pax.c
58768--- linux-2.6.39.1/grsecurity/grsec_pax.c 1969-12-31 19:00:00.000000000 -0500
58769+++ linux-2.6.39.1/grsecurity/grsec_pax.c 2011-05-22 19:41:42.000000000 -0400
58770@@ -0,0 +1,36 @@
58771+#include <linux/kernel.h>
58772+#include <linux/sched.h>
58773+#include <linux/mm.h>
58774+#include <linux/file.h>
58775+#include <linux/grinternal.h>
58776+#include <linux/grsecurity.h>
58777+
58778+void
58779+gr_log_textrel(struct vm_area_struct * vma)
58780+{
58781+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58782+ if (grsec_enable_audit_textrel)
58783+ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
58784+#endif
58785+ return;
58786+}
58787+
58788+void
58789+gr_log_rwxmmap(struct file *file)
58790+{
58791+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58792+ if (grsec_enable_log_rwxmaps)
58793+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
58794+#endif
58795+ return;
58796+}
58797+
58798+void
58799+gr_log_rwxmprotect(struct file *file)
58800+{
58801+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58802+ if (grsec_enable_log_rwxmaps)
58803+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
58804+#endif
58805+ return;
58806+}
58807diff -urNp linux-2.6.39.1/grsecurity/grsec_ptrace.c linux-2.6.39.1/grsecurity/grsec_ptrace.c
58808--- linux-2.6.39.1/grsecurity/grsec_ptrace.c 1969-12-31 19:00:00.000000000 -0500
58809+++ linux-2.6.39.1/grsecurity/grsec_ptrace.c 2011-05-22 19:41:42.000000000 -0400
58810@@ -0,0 +1,14 @@
58811+#include <linux/kernel.h>
58812+#include <linux/sched.h>
58813+#include <linux/grinternal.h>
58814+#include <linux/grsecurity.h>
58815+
58816+void
58817+gr_audit_ptrace(struct task_struct *task)
58818+{
58819+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58820+ if (grsec_enable_audit_ptrace)
58821+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
58822+#endif
58823+ return;
58824+}
58825diff -urNp linux-2.6.39.1/grsecurity/grsec_sig.c linux-2.6.39.1/grsecurity/grsec_sig.c
58826--- linux-2.6.39.1/grsecurity/grsec_sig.c 1969-12-31 19:00:00.000000000 -0500
58827+++ linux-2.6.39.1/grsecurity/grsec_sig.c 2011-05-22 19:41:42.000000000 -0400
58828@@ -0,0 +1,203 @@
58829+#include <linux/kernel.h>
58830+#include <linux/sched.h>
58831+#include <linux/delay.h>
58832+#include <linux/grsecurity.h>
58833+#include <linux/grinternal.h>
58834+#include <linux/hardirq.h>
58835+
58836+char *signames[] = {
58837+ [SIGSEGV] = "Segmentation fault",
58838+ [SIGILL] = "Illegal instruction",
58839+ [SIGABRT] = "Abort",
58840+ [SIGBUS] = "Invalid alignment/Bus error"
58841+};
58842+
58843+void
58844+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
58845+{
58846+#ifdef CONFIG_GRKERNSEC_SIGNAL
58847+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
58848+ (sig == SIGABRT) || (sig == SIGBUS))) {
58849+ if (t->pid == current->pid) {
58850+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
58851+ } else {
58852+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
58853+ }
58854+ }
58855+#endif
58856+ return;
58857+}
58858+
58859+int
58860+gr_handle_signal(const struct task_struct *p, const int sig)
58861+{
58862+#ifdef CONFIG_GRKERNSEC
58863+ if (current->pid > 1 && gr_check_protected_task(p)) {
58864+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
58865+ return -EPERM;
58866+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
58867+ return -EPERM;
58868+ }
58869+#endif
58870+ return 0;
58871+}
58872+
58873+#ifdef CONFIG_GRKERNSEC
58874+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
58875+
58876+int gr_fake_force_sig(int sig, struct task_struct *t)
58877+{
58878+ unsigned long int flags;
58879+ int ret, blocked, ignored;
58880+ struct k_sigaction *action;
58881+
58882+ spin_lock_irqsave(&t->sighand->siglock, flags);
58883+ action = &t->sighand->action[sig-1];
58884+ ignored = action->sa.sa_handler == SIG_IGN;
58885+ blocked = sigismember(&t->blocked, sig);
58886+ if (blocked || ignored) {
58887+ action->sa.sa_handler = SIG_DFL;
58888+ if (blocked) {
58889+ sigdelset(&t->blocked, sig);
58890+ recalc_sigpending_and_wake(t);
58891+ }
58892+ }
58893+ if (action->sa.sa_handler == SIG_DFL)
58894+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
58895+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
58896+
58897+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
58898+
58899+ return ret;
58900+}
58901+#endif
58902+
58903+#ifdef CONFIG_GRKERNSEC_BRUTE
58904+#define GR_USER_BAN_TIME (15 * 60)
58905+
58906+static int __get_dumpable(unsigned long mm_flags)
58907+{
58908+ int ret;
58909+
58910+ ret = mm_flags & MMF_DUMPABLE_MASK;
58911+ return (ret >= 2) ? 2 : ret;
58912+}
58913+#endif
58914+
58915+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
58916+{
58917+#ifdef CONFIG_GRKERNSEC_BRUTE
58918+ uid_t uid = 0;
58919+
58920+ rcu_read_lock();
58921+ read_lock(&tasklist_lock);
58922+ read_lock(&grsec_exec_file_lock);
58923+ if (p->real_parent && p->real_parent->exec_file == p->exec_file)
58924+ p->real_parent->brute = 1;
58925+ else {
58926+ const struct cred *cred = __task_cred(p), *cred2;
58927+ struct task_struct *tsk, *tsk2;
58928+
58929+ if (!__get_dumpable(mm_flags) && cred->uid) {
58930+ struct user_struct *user;
58931+
58932+ uid = cred->uid;
58933+
58934+ /* this is put upon execution past expiration */
58935+ user = find_user(uid);
58936+ if (user == NULL)
58937+ goto unlock;
58938+ user->banned = 1;
58939+ user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
58940+ if (user->ban_expires == ~0UL)
58941+ user->ban_expires--;
58942+
58943+ do_each_thread(tsk2, tsk) {
58944+ cred2 = __task_cred(tsk);
58945+ if (tsk != p && cred2->uid == uid)
58946+ gr_fake_force_sig(SIGKILL, tsk);
58947+ } while_each_thread(tsk2, tsk);
58948+ }
58949+ }
58950+unlock:
58951+ read_unlock(&grsec_exec_file_lock);
58952+ read_unlock(&tasklist_lock);
58953+ rcu_read_unlock();
58954+
58955+ if (uid)
58956+ printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n", uid, GR_USER_BAN_TIME / 60);
58957+
58958+#endif
58959+ return;
58960+}
58961+
58962+void gr_handle_brute_check(void)
58963+{
58964+#ifdef CONFIG_GRKERNSEC_BRUTE
58965+ if (current->brute)
58966+ msleep(30 * 1000);
58967+#endif
58968+ return;
58969+}
58970+
58971+void gr_handle_kernel_exploit(void)
58972+{
58973+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
58974+ const struct cred *cred;
58975+ struct task_struct *tsk, *tsk2;
58976+ struct user_struct *user;
58977+ uid_t uid;
58978+
58979+ if (in_irq() || in_serving_softirq() || in_nmi())
58980+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
58981+
58982+ uid = current_uid();
58983+
58984+ if (uid == 0)
58985+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
58986+ else {
58987+ /* kill all the processes of this user, hold a reference
58988+ to their creds struct, and prevent them from creating
58989+ another process until system reset
58990+ */
58991+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n", uid);
58992+ /* we intentionally leak this ref */
58993+ user = get_uid(current->cred->user);
58994+ if (user) {
58995+ user->banned = 1;
58996+ user->ban_expires = ~0UL;
58997+ }
58998+
58999+ read_lock(&tasklist_lock);
59000+ do_each_thread(tsk2, tsk) {
59001+ cred = __task_cred(tsk);
59002+ if (cred->uid == uid)
59003+ gr_fake_force_sig(SIGKILL, tsk);
59004+ } while_each_thread(tsk2, tsk);
59005+ read_unlock(&tasklist_lock);
59006+ }
59007+#endif
59008+}
59009+
59010+int __gr_process_user_ban(struct user_struct *user)
59011+{
59012+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59013+ if (unlikely(user->banned)) {
59014+ if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
59015+ user->banned = 0;
59016+ user->ban_expires = 0;
59017+ free_uid(user);
59018+ } else
59019+ return -EPERM;
59020+ }
59021+#endif
59022+ return 0;
59023+}
59024+
59025+int gr_process_user_ban(void)
59026+{
59027+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59028+ return __gr_process_user_ban(current->cred->user);
59029+#endif
59030+ return 0;
59031+}
59032diff -urNp linux-2.6.39.1/grsecurity/grsec_sock.c linux-2.6.39.1/grsecurity/grsec_sock.c
59033--- linux-2.6.39.1/grsecurity/grsec_sock.c 1969-12-31 19:00:00.000000000 -0500
59034+++ linux-2.6.39.1/grsecurity/grsec_sock.c 2011-05-22 20:29:21.000000000 -0400
59035@@ -0,0 +1,244 @@
59036+#include <linux/kernel.h>
59037+#include <linux/module.h>
59038+#include <linux/sched.h>
59039+#include <linux/file.h>
59040+#include <linux/net.h>
59041+#include <linux/in.h>
59042+#include <linux/ip.h>
59043+#include <net/sock.h>
59044+#include <net/inet_sock.h>
59045+#include <linux/grsecurity.h>
59046+#include <linux/grinternal.h>
59047+#include <linux/gracl.h>
59048+
59049+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
59050+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
59051+
59052+EXPORT_SYMBOL(gr_search_udp_recvmsg);
59053+EXPORT_SYMBOL(gr_search_udp_sendmsg);
59054+
59055+#ifdef CONFIG_UNIX_MODULE
59056+EXPORT_SYMBOL(gr_acl_handle_unix);
59057+EXPORT_SYMBOL(gr_acl_handle_mknod);
59058+EXPORT_SYMBOL(gr_handle_chroot_unix);
59059+EXPORT_SYMBOL(gr_handle_create);
59060+#endif
59061+
59062+#ifdef CONFIG_GRKERNSEC
59063+#define gr_conn_table_size 32749
59064+struct conn_table_entry {
59065+ struct conn_table_entry *next;
59066+ struct signal_struct *sig;
59067+};
59068+
59069+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
59070+DEFINE_SPINLOCK(gr_conn_table_lock);
59071+
59072+extern const char * gr_socktype_to_name(unsigned char type);
59073+extern const char * gr_proto_to_name(unsigned char proto);
59074+extern const char * gr_sockfamily_to_name(unsigned char family);
59075+
59076+static __inline__ int
59077+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
59078+{
59079+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
59080+}
59081+
59082+static __inline__ int
59083+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
59084+ __u16 sport, __u16 dport)
59085+{
59086+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
59087+ sig->gr_sport == sport && sig->gr_dport == dport))
59088+ return 1;
59089+ else
59090+ return 0;
59091+}
59092+
59093+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
59094+{
59095+ struct conn_table_entry **match;
59096+ unsigned int index;
59097+
59098+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59099+ sig->gr_sport, sig->gr_dport,
59100+ gr_conn_table_size);
59101+
59102+ newent->sig = sig;
59103+
59104+ match = &gr_conn_table[index];
59105+ newent->next = *match;
59106+ *match = newent;
59107+
59108+ return;
59109+}
59110+
59111+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
59112+{
59113+ struct conn_table_entry *match, *last = NULL;
59114+ unsigned int index;
59115+
59116+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59117+ sig->gr_sport, sig->gr_dport,
59118+ gr_conn_table_size);
59119+
59120+ match = gr_conn_table[index];
59121+ while (match && !conn_match(match->sig,
59122+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
59123+ sig->gr_dport)) {
59124+ last = match;
59125+ match = match->next;
59126+ }
59127+
59128+ if (match) {
59129+ if (last)
59130+ last->next = match->next;
59131+ else
59132+ gr_conn_table[index] = NULL;
59133+ kfree(match);
59134+ }
59135+
59136+ return;
59137+}
59138+
59139+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
59140+ __u16 sport, __u16 dport)
59141+{
59142+ struct conn_table_entry *match;
59143+ unsigned int index;
59144+
59145+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
59146+
59147+ match = gr_conn_table[index];
59148+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
59149+ match = match->next;
59150+
59151+ if (match)
59152+ return match->sig;
59153+ else
59154+ return NULL;
59155+}
59156+
59157+#endif
59158+
59159+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
59160+{
59161+#ifdef CONFIG_GRKERNSEC
59162+ struct signal_struct *sig = task->signal;
59163+ struct conn_table_entry *newent;
59164+
59165+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
59166+ if (newent == NULL)
59167+ return;
59168+ /* no bh lock needed since we are called with bh disabled */
59169+ spin_lock(&gr_conn_table_lock);
59170+ gr_del_task_from_ip_table_nolock(sig);
59171+ sig->gr_saddr = inet->inet_rcv_saddr;
59172+ sig->gr_daddr = inet->inet_daddr;
59173+ sig->gr_sport = inet->inet_sport;
59174+ sig->gr_dport = inet->inet_dport;
59175+ gr_add_to_task_ip_table_nolock(sig, newent);
59176+ spin_unlock(&gr_conn_table_lock);
59177+#endif
59178+ return;
59179+}
59180+
59181+void gr_del_task_from_ip_table(struct task_struct *task)
59182+{
59183+#ifdef CONFIG_GRKERNSEC
59184+ spin_lock_bh(&gr_conn_table_lock);
59185+ gr_del_task_from_ip_table_nolock(task->signal);
59186+ spin_unlock_bh(&gr_conn_table_lock);
59187+#endif
59188+ return;
59189+}
59190+
59191+void
59192+gr_attach_curr_ip(const struct sock *sk)
59193+{
59194+#ifdef CONFIG_GRKERNSEC
59195+ struct signal_struct *p, *set;
59196+ const struct inet_sock *inet = inet_sk(sk);
59197+
59198+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
59199+ return;
59200+
59201+ set = current->signal;
59202+
59203+ spin_lock_bh(&gr_conn_table_lock);
59204+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
59205+ inet->inet_dport, inet->inet_sport);
59206+ if (unlikely(p != NULL)) {
59207+ set->curr_ip = p->curr_ip;
59208+ set->used_accept = 1;
59209+ gr_del_task_from_ip_table_nolock(p);
59210+ spin_unlock_bh(&gr_conn_table_lock);
59211+ return;
59212+ }
59213+ spin_unlock_bh(&gr_conn_table_lock);
59214+
59215+ set->curr_ip = inet->inet_daddr;
59216+ set->used_accept = 1;
59217+#endif
59218+ return;
59219+}
59220+
59221+int
59222+gr_handle_sock_all(const int family, const int type, const int protocol)
59223+{
59224+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59225+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
59226+ (family != AF_UNIX)) {
59227+ if (family == AF_INET)
59228+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
59229+ else
59230+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
59231+ return -EACCES;
59232+ }
59233+#endif
59234+ return 0;
59235+}
59236+
59237+int
59238+gr_handle_sock_server(const struct sockaddr *sck)
59239+{
59240+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59241+ if (grsec_enable_socket_server &&
59242+ in_group_p(grsec_socket_server_gid) &&
59243+ sck && (sck->sa_family != AF_UNIX) &&
59244+ (sck->sa_family != AF_LOCAL)) {
59245+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59246+ return -EACCES;
59247+ }
59248+#endif
59249+ return 0;
59250+}
59251+
59252+int
59253+gr_handle_sock_server_other(const struct sock *sck)
59254+{
59255+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59256+ if (grsec_enable_socket_server &&
59257+ in_group_p(grsec_socket_server_gid) &&
59258+ sck && (sck->sk_family != AF_UNIX) &&
59259+ (sck->sk_family != AF_LOCAL)) {
59260+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59261+ return -EACCES;
59262+ }
59263+#endif
59264+ return 0;
59265+}
59266+
59267+int
59268+gr_handle_sock_client(const struct sockaddr *sck)
59269+{
59270+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59271+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
59272+ sck && (sck->sa_family != AF_UNIX) &&
59273+ (sck->sa_family != AF_LOCAL)) {
59274+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
59275+ return -EACCES;
59276+ }
59277+#endif
59278+ return 0;
59279+}
59280diff -urNp linux-2.6.39.1/grsecurity/grsec_sysctl.c linux-2.6.39.1/grsecurity/grsec_sysctl.c
59281--- linux-2.6.39.1/grsecurity/grsec_sysctl.c 1969-12-31 19:00:00.000000000 -0500
59282+++ linux-2.6.39.1/grsecurity/grsec_sysctl.c 2011-05-22 19:41:42.000000000 -0400
59283@@ -0,0 +1,433 @@
59284+#include <linux/kernel.h>
59285+#include <linux/sched.h>
59286+#include <linux/sysctl.h>
59287+#include <linux/grsecurity.h>
59288+#include <linux/grinternal.h>
59289+
59290+int
59291+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
59292+{
59293+#ifdef CONFIG_GRKERNSEC_SYSCTL
59294+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
59295+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
59296+ return -EACCES;
59297+ }
59298+#endif
59299+ return 0;
59300+}
59301+
59302+#ifdef CONFIG_GRKERNSEC_ROFS
59303+static int __maybe_unused one = 1;
59304+#endif
59305+
59306+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
59307+struct ctl_table grsecurity_table[] = {
59308+#ifdef CONFIG_GRKERNSEC_SYSCTL
59309+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
59310+#ifdef CONFIG_GRKERNSEC_IO
59311+ {
59312+ .procname = "disable_priv_io",
59313+ .data = &grsec_disable_privio,
59314+ .maxlen = sizeof(int),
59315+ .mode = 0600,
59316+ .proc_handler = &proc_dointvec,
59317+ },
59318+#endif
59319+#endif
59320+#ifdef CONFIG_GRKERNSEC_LINK
59321+ {
59322+ .procname = "linking_restrictions",
59323+ .data = &grsec_enable_link,
59324+ .maxlen = sizeof(int),
59325+ .mode = 0600,
59326+ .proc_handler = &proc_dointvec,
59327+ },
59328+#endif
59329+#ifdef CONFIG_GRKERNSEC_FIFO
59330+ {
59331+ .procname = "fifo_restrictions",
59332+ .data = &grsec_enable_fifo,
59333+ .maxlen = sizeof(int),
59334+ .mode = 0600,
59335+ .proc_handler = &proc_dointvec,
59336+ },
59337+#endif
59338+#ifdef CONFIG_GRKERNSEC_EXECVE
59339+ {
59340+ .procname = "execve_limiting",
59341+ .data = &grsec_enable_execve,
59342+ .maxlen = sizeof(int),
59343+ .mode = 0600,
59344+ .proc_handler = &proc_dointvec,
59345+ },
59346+#endif
59347+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
59348+ {
59349+ .procname = "ip_blackhole",
59350+ .data = &grsec_enable_blackhole,
59351+ .maxlen = sizeof(int),
59352+ .mode = 0600,
59353+ .proc_handler = &proc_dointvec,
59354+ },
59355+ {
59356+ .procname = "lastack_retries",
59357+ .data = &grsec_lastack_retries,
59358+ .maxlen = sizeof(int),
59359+ .mode = 0600,
59360+ .proc_handler = &proc_dointvec,
59361+ },
59362+#endif
59363+#ifdef CONFIG_GRKERNSEC_EXECLOG
59364+ {
59365+ .procname = "exec_logging",
59366+ .data = &grsec_enable_execlog,
59367+ .maxlen = sizeof(int),
59368+ .mode = 0600,
59369+ .proc_handler = &proc_dointvec,
59370+ },
59371+#endif
59372+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59373+ {
59374+ .procname = "rwxmap_logging",
59375+ .data = &grsec_enable_log_rwxmaps,
59376+ .maxlen = sizeof(int),
59377+ .mode = 0600,
59378+ .proc_handler = &proc_dointvec,
59379+ },
59380+#endif
59381+#ifdef CONFIG_GRKERNSEC_SIGNAL
59382+ {
59383+ .procname = "signal_logging",
59384+ .data = &grsec_enable_signal,
59385+ .maxlen = sizeof(int),
59386+ .mode = 0600,
59387+ .proc_handler = &proc_dointvec,
59388+ },
59389+#endif
59390+#ifdef CONFIG_GRKERNSEC_FORKFAIL
59391+ {
59392+ .procname = "forkfail_logging",
59393+ .data = &grsec_enable_forkfail,
59394+ .maxlen = sizeof(int),
59395+ .mode = 0600,
59396+ .proc_handler = &proc_dointvec,
59397+ },
59398+#endif
59399+#ifdef CONFIG_GRKERNSEC_TIME
59400+ {
59401+ .procname = "timechange_logging",
59402+ .data = &grsec_enable_time,
59403+ .maxlen = sizeof(int),
59404+ .mode = 0600,
59405+ .proc_handler = &proc_dointvec,
59406+ },
59407+#endif
59408+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
59409+ {
59410+ .procname = "chroot_deny_shmat",
59411+ .data = &grsec_enable_chroot_shmat,
59412+ .maxlen = sizeof(int),
59413+ .mode = 0600,
59414+ .proc_handler = &proc_dointvec,
59415+ },
59416+#endif
59417+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
59418+ {
59419+ .procname = "chroot_deny_unix",
59420+ .data = &grsec_enable_chroot_unix,
59421+ .maxlen = sizeof(int),
59422+ .mode = 0600,
59423+ .proc_handler = &proc_dointvec,
59424+ },
59425+#endif
59426+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
59427+ {
59428+ .procname = "chroot_deny_mount",
59429+ .data = &grsec_enable_chroot_mount,
59430+ .maxlen = sizeof(int),
59431+ .mode = 0600,
59432+ .proc_handler = &proc_dointvec,
59433+ },
59434+#endif
59435+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
59436+ {
59437+ .procname = "chroot_deny_fchdir",
59438+ .data = &grsec_enable_chroot_fchdir,
59439+ .maxlen = sizeof(int),
59440+ .mode = 0600,
59441+ .proc_handler = &proc_dointvec,
59442+ },
59443+#endif
59444+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
59445+ {
59446+ .procname = "chroot_deny_chroot",
59447+ .data = &grsec_enable_chroot_double,
59448+ .maxlen = sizeof(int),
59449+ .mode = 0600,
59450+ .proc_handler = &proc_dointvec,
59451+ },
59452+#endif
59453+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
59454+ {
59455+ .procname = "chroot_deny_pivot",
59456+ .data = &grsec_enable_chroot_pivot,
59457+ .maxlen = sizeof(int),
59458+ .mode = 0600,
59459+ .proc_handler = &proc_dointvec,
59460+ },
59461+#endif
59462+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
59463+ {
59464+ .procname = "chroot_enforce_chdir",
59465+ .data = &grsec_enable_chroot_chdir,
59466+ .maxlen = sizeof(int),
59467+ .mode = 0600,
59468+ .proc_handler = &proc_dointvec,
59469+ },
59470+#endif
59471+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
59472+ {
59473+ .procname = "chroot_deny_chmod",
59474+ .data = &grsec_enable_chroot_chmod,
59475+ .maxlen = sizeof(int),
59476+ .mode = 0600,
59477+ .proc_handler = &proc_dointvec,
59478+ },
59479+#endif
59480+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
59481+ {
59482+ .procname = "chroot_deny_mknod",
59483+ .data = &grsec_enable_chroot_mknod,
59484+ .maxlen = sizeof(int),
59485+ .mode = 0600,
59486+ .proc_handler = &proc_dointvec,
59487+ },
59488+#endif
59489+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59490+ {
59491+ .procname = "chroot_restrict_nice",
59492+ .data = &grsec_enable_chroot_nice,
59493+ .maxlen = sizeof(int),
59494+ .mode = 0600,
59495+ .proc_handler = &proc_dointvec,
59496+ },
59497+#endif
59498+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
59499+ {
59500+ .procname = "chroot_execlog",
59501+ .data = &grsec_enable_chroot_execlog,
59502+ .maxlen = sizeof(int),
59503+ .mode = 0600,
59504+ .proc_handler = &proc_dointvec,
59505+ },
59506+#endif
59507+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59508+ {
59509+ .procname = "chroot_caps",
59510+ .data = &grsec_enable_chroot_caps,
59511+ .maxlen = sizeof(int),
59512+ .mode = 0600,
59513+ .proc_handler = &proc_dointvec,
59514+ },
59515+#endif
59516+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
59517+ {
59518+ .procname = "chroot_deny_sysctl",
59519+ .data = &grsec_enable_chroot_sysctl,
59520+ .maxlen = sizeof(int),
59521+ .mode = 0600,
59522+ .proc_handler = &proc_dointvec,
59523+ },
59524+#endif
59525+#ifdef CONFIG_GRKERNSEC_TPE
59526+ {
59527+ .procname = "tpe",
59528+ .data = &grsec_enable_tpe,
59529+ .maxlen = sizeof(int),
59530+ .mode = 0600,
59531+ .proc_handler = &proc_dointvec,
59532+ },
59533+ {
59534+ .procname = "tpe_gid",
59535+ .data = &grsec_tpe_gid,
59536+ .maxlen = sizeof(int),
59537+ .mode = 0600,
59538+ .proc_handler = &proc_dointvec,
59539+ },
59540+#endif
59541+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59542+ {
59543+ .procname = "tpe_invert",
59544+ .data = &grsec_enable_tpe_invert,
59545+ .maxlen = sizeof(int),
59546+ .mode = 0600,
59547+ .proc_handler = &proc_dointvec,
59548+ },
59549+#endif
59550+#ifdef CONFIG_GRKERNSEC_TPE_ALL
59551+ {
59552+ .procname = "tpe_restrict_all",
59553+ .data = &grsec_enable_tpe_all,
59554+ .maxlen = sizeof(int),
59555+ .mode = 0600,
59556+ .proc_handler = &proc_dointvec,
59557+ },
59558+#endif
59559+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59560+ {
59561+ .procname = "socket_all",
59562+ .data = &grsec_enable_socket_all,
59563+ .maxlen = sizeof(int),
59564+ .mode = 0600,
59565+ .proc_handler = &proc_dointvec,
59566+ },
59567+ {
59568+ .procname = "socket_all_gid",
59569+ .data = &grsec_socket_all_gid,
59570+ .maxlen = sizeof(int),
59571+ .mode = 0600,
59572+ .proc_handler = &proc_dointvec,
59573+ },
59574+#endif
59575+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59576+ {
59577+ .procname = "socket_client",
59578+ .data = &grsec_enable_socket_client,
59579+ .maxlen = sizeof(int),
59580+ .mode = 0600,
59581+ .proc_handler = &proc_dointvec,
59582+ },
59583+ {
59584+ .procname = "socket_client_gid",
59585+ .data = &grsec_socket_client_gid,
59586+ .maxlen = sizeof(int),
59587+ .mode = 0600,
59588+ .proc_handler = &proc_dointvec,
59589+ },
59590+#endif
59591+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59592+ {
59593+ .procname = "socket_server",
59594+ .data = &grsec_enable_socket_server,
59595+ .maxlen = sizeof(int),
59596+ .mode = 0600,
59597+ .proc_handler = &proc_dointvec,
59598+ },
59599+ {
59600+ .procname = "socket_server_gid",
59601+ .data = &grsec_socket_server_gid,
59602+ .maxlen = sizeof(int),
59603+ .mode = 0600,
59604+ .proc_handler = &proc_dointvec,
59605+ },
59606+#endif
59607+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
59608+ {
59609+ .procname = "audit_group",
59610+ .data = &grsec_enable_group,
59611+ .maxlen = sizeof(int),
59612+ .mode = 0600,
59613+ .proc_handler = &proc_dointvec,
59614+ },
59615+ {
59616+ .procname = "audit_gid",
59617+ .data = &grsec_audit_gid,
59618+ .maxlen = sizeof(int),
59619+ .mode = 0600,
59620+ .proc_handler = &proc_dointvec,
59621+ },
59622+#endif
59623+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
59624+ {
59625+ .procname = "audit_chdir",
59626+ .data = &grsec_enable_chdir,
59627+ .maxlen = sizeof(int),
59628+ .mode = 0600,
59629+ .proc_handler = &proc_dointvec,
59630+ },
59631+#endif
59632+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59633+ {
59634+ .procname = "audit_mount",
59635+ .data = &grsec_enable_mount,
59636+ .maxlen = sizeof(int),
59637+ .mode = 0600,
59638+ .proc_handler = &proc_dointvec,
59639+ },
59640+#endif
59641+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59642+ {
59643+ .procname = "audit_textrel",
59644+ .data = &grsec_enable_audit_textrel,
59645+ .maxlen = sizeof(int),
59646+ .mode = 0600,
59647+ .proc_handler = &proc_dointvec,
59648+ },
59649+#endif
59650+#ifdef CONFIG_GRKERNSEC_DMESG
59651+ {
59652+ .procname = "dmesg",
59653+ .data = &grsec_enable_dmesg,
59654+ .maxlen = sizeof(int),
59655+ .mode = 0600,
59656+ .proc_handler = &proc_dointvec,
59657+ },
59658+#endif
59659+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59660+ {
59661+ .procname = "chroot_findtask",
59662+ .data = &grsec_enable_chroot_findtask,
59663+ .maxlen = sizeof(int),
59664+ .mode = 0600,
59665+ .proc_handler = &proc_dointvec,
59666+ },
59667+#endif
59668+#ifdef CONFIG_GRKERNSEC_RESLOG
59669+ {
59670+ .procname = "resource_logging",
59671+ .data = &grsec_resource_logging,
59672+ .maxlen = sizeof(int),
59673+ .mode = 0600,
59674+ .proc_handler = &proc_dointvec,
59675+ },
59676+#endif
59677+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59678+ {
59679+ .procname = "audit_ptrace",
59680+ .data = &grsec_enable_audit_ptrace,
59681+ .maxlen = sizeof(int),
59682+ .mode = 0600,
59683+ .proc_handler = &proc_dointvec,
59684+ },
59685+#endif
59686+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
59687+ {
59688+ .procname = "harden_ptrace",
59689+ .data = &grsec_enable_harden_ptrace,
59690+ .maxlen = sizeof(int),
59691+ .mode = 0600,
59692+ .proc_handler = &proc_dointvec,
59693+ },
59694+#endif
59695+ {
59696+ .procname = "grsec_lock",
59697+ .data = &grsec_lock,
59698+ .maxlen = sizeof(int),
59699+ .mode = 0600,
59700+ .proc_handler = &proc_dointvec,
59701+ },
59702+#endif
59703+#ifdef CONFIG_GRKERNSEC_ROFS
59704+ {
59705+ .procname = "romount_protect",
59706+ .data = &grsec_enable_rofs,
59707+ .maxlen = sizeof(int),
59708+ .mode = 0600,
59709+ .proc_handler = &proc_dointvec_minmax,
59710+ .extra1 = &one,
59711+ .extra2 = &one,
59712+ },
59713+#endif
59714+ { }
59715+};
59716+#endif
59717diff -urNp linux-2.6.39.1/grsecurity/grsec_time.c linux-2.6.39.1/grsecurity/grsec_time.c
59718--- linux-2.6.39.1/grsecurity/grsec_time.c 1969-12-31 19:00:00.000000000 -0500
59719+++ linux-2.6.39.1/grsecurity/grsec_time.c 2011-05-22 19:41:42.000000000 -0400
59720@@ -0,0 +1,16 @@
59721+#include <linux/kernel.h>
59722+#include <linux/sched.h>
59723+#include <linux/grinternal.h>
59724+#include <linux/module.h>
59725+
59726+void
59727+gr_log_timechange(void)
59728+{
59729+#ifdef CONFIG_GRKERNSEC_TIME
59730+ if (grsec_enable_time)
59731+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
59732+#endif
59733+ return;
59734+}
59735+
59736+EXPORT_SYMBOL(gr_log_timechange);
59737diff -urNp linux-2.6.39.1/grsecurity/grsec_tpe.c linux-2.6.39.1/grsecurity/grsec_tpe.c
59738--- linux-2.6.39.1/grsecurity/grsec_tpe.c 1969-12-31 19:00:00.000000000 -0500
59739+++ linux-2.6.39.1/grsecurity/grsec_tpe.c 2011-05-22 19:41:42.000000000 -0400
59740@@ -0,0 +1,39 @@
59741+#include <linux/kernel.h>
59742+#include <linux/sched.h>
59743+#include <linux/file.h>
59744+#include <linux/fs.h>
59745+#include <linux/grinternal.h>
59746+
59747+extern int gr_acl_tpe_check(void);
59748+
59749+int
59750+gr_tpe_allow(const struct file *file)
59751+{
59752+#ifdef CONFIG_GRKERNSEC
59753+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
59754+ const struct cred *cred = current_cred();
59755+
59756+ if (cred->uid && ((grsec_enable_tpe &&
59757+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59758+ ((grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid)) ||
59759+ (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid)))
59760+#else
59761+ in_group_p(grsec_tpe_gid)
59762+#endif
59763+ ) || gr_acl_tpe_check()) &&
59764+ (inode->i_uid || (!inode->i_uid && ((inode->i_mode & S_IWGRP) ||
59765+ (inode->i_mode & S_IWOTH))))) {
59766+ gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt);
59767+ return 0;
59768+ }
59769+#ifdef CONFIG_GRKERNSEC_TPE_ALL
59770+ if (cred->uid && grsec_enable_tpe && grsec_enable_tpe_all &&
59771+ ((inode->i_uid && (inode->i_uid != cred->uid)) ||
59772+ (inode->i_mode & S_IWGRP) || (inode->i_mode & S_IWOTH))) {
59773+ gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt);
59774+ return 0;
59775+ }
59776+#endif
59777+#endif
59778+ return 1;
59779+}
59780diff -urNp linux-2.6.39.1/grsecurity/grsum.c linux-2.6.39.1/grsecurity/grsum.c
59781--- linux-2.6.39.1/grsecurity/grsum.c 1969-12-31 19:00:00.000000000 -0500
59782+++ linux-2.6.39.1/grsecurity/grsum.c 2011-05-22 19:41:42.000000000 -0400
59783@@ -0,0 +1,61 @@
59784+#include <linux/err.h>
59785+#include <linux/kernel.h>
59786+#include <linux/sched.h>
59787+#include <linux/mm.h>
59788+#include <linux/scatterlist.h>
59789+#include <linux/crypto.h>
59790+#include <linux/gracl.h>
59791+
59792+
59793+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
59794+#error "crypto and sha256 must be built into the kernel"
59795+#endif
59796+
59797+int
59798+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
59799+{
59800+ char *p;
59801+ struct crypto_hash *tfm;
59802+ struct hash_desc desc;
59803+ struct scatterlist sg;
59804+ unsigned char temp_sum[GR_SHA_LEN];
59805+ volatile int retval = 0;
59806+ volatile int dummy = 0;
59807+ unsigned int i;
59808+
59809+ sg_init_table(&sg, 1);
59810+
59811+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
59812+ if (IS_ERR(tfm)) {
59813+ /* should never happen, since sha256 should be built in */
59814+ return 1;
59815+ }
59816+
59817+ desc.tfm = tfm;
59818+ desc.flags = 0;
59819+
59820+ crypto_hash_init(&desc);
59821+
59822+ p = salt;
59823+ sg_set_buf(&sg, p, GR_SALT_LEN);
59824+ crypto_hash_update(&desc, &sg, sg.length);
59825+
59826+ p = entry->pw;
59827+ sg_set_buf(&sg, p, strlen(p));
59828+
59829+ crypto_hash_update(&desc, &sg, sg.length);
59830+
59831+ crypto_hash_final(&desc, temp_sum);
59832+
59833+ memset(entry->pw, 0, GR_PW_LEN);
59834+
59835+ for (i = 0; i < GR_SHA_LEN; i++)
59836+ if (sum[i] != temp_sum[i])
59837+ retval = 1;
59838+ else
59839+ dummy = 1; // waste a cycle
59840+
59841+ crypto_free_hash(tfm);
59842+
59843+ return retval;
59844+}
59845diff -urNp linux-2.6.39.1/grsecurity/Kconfig linux-2.6.39.1/grsecurity/Kconfig
59846--- linux-2.6.39.1/grsecurity/Kconfig 1969-12-31 19:00:00.000000000 -0500
59847+++ linux-2.6.39.1/grsecurity/Kconfig 2011-05-22 19:41:42.000000000 -0400
59848@@ -0,0 +1,1045 @@
59849+#
59850+# grecurity configuration
59851+#
59852+
59853+menu "Grsecurity"
59854+
59855+config GRKERNSEC
59856+ bool "Grsecurity"
59857+ select CRYPTO
59858+ select CRYPTO_SHA256
59859+ help
59860+ If you say Y here, you will be able to configure many features
59861+ that will enhance the security of your system. It is highly
59862+ recommended that you say Y here and read through the help
59863+ for each option so that you fully understand the features and
59864+ can evaluate their usefulness for your machine.
59865+
59866+choice
59867+ prompt "Security Level"
59868+ depends on GRKERNSEC
59869+ default GRKERNSEC_CUSTOM
59870+
59871+config GRKERNSEC_LOW
59872+ bool "Low"
59873+ select GRKERNSEC_LINK
59874+ select GRKERNSEC_FIFO
59875+ select GRKERNSEC_EXECVE
59876+ select GRKERNSEC_RANDNET
59877+ select GRKERNSEC_DMESG
59878+ select GRKERNSEC_CHROOT
59879+ select GRKERNSEC_CHROOT_CHDIR
59880+
59881+ help
59882+ If you choose this option, several of the grsecurity options will
59883+ be enabled that will give you greater protection against a number
59884+ of attacks, while assuring that none of your software will have any
59885+ conflicts with the additional security measures. If you run a lot
59886+ of unusual software, or you are having problems with the higher
59887+ security levels, you should say Y here. With this option, the
59888+ following features are enabled:
59889+
59890+ - Linking restrictions
59891+ - FIFO restrictions
59892+ - Enforcing RLIMIT_NPROC on execve
59893+ - Restricted dmesg
59894+ - Enforced chdir("/") on chroot
59895+ - Runtime module disabling
59896+
59897+config GRKERNSEC_MEDIUM
59898+ bool "Medium"
59899+ select PAX
59900+ select PAX_EI_PAX
59901+ select PAX_PT_PAX_FLAGS
59902+ select PAX_HAVE_ACL_FLAGS
59903+ select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
59904+ select GRKERNSEC_CHROOT
59905+ select GRKERNSEC_CHROOT_SYSCTL
59906+ select GRKERNSEC_LINK
59907+ select GRKERNSEC_FIFO
59908+ select GRKERNSEC_EXECVE
59909+ select GRKERNSEC_DMESG
59910+ select GRKERNSEC_RANDNET
59911+ select GRKERNSEC_FORKFAIL
59912+ select GRKERNSEC_TIME
59913+ select GRKERNSEC_SIGNAL
59914+ select GRKERNSEC_CHROOT
59915+ select GRKERNSEC_CHROOT_UNIX
59916+ select GRKERNSEC_CHROOT_MOUNT
59917+ select GRKERNSEC_CHROOT_PIVOT
59918+ select GRKERNSEC_CHROOT_DOUBLE
59919+ select GRKERNSEC_CHROOT_CHDIR
59920+ select GRKERNSEC_CHROOT_MKNOD
59921+ select GRKERNSEC_PROC
59922+ select GRKERNSEC_PROC_USERGROUP
59923+ select PAX_RANDUSTACK
59924+ select PAX_ASLR
59925+ select PAX_RANDMMAP
59926+ select PAX_REFCOUNT if (X86 || SPARC64)
59927+ select PAX_USERCOPY if ((X86 || SPARC32 || SPARC64 || PPC) && (SLAB || SLUB || SLOB))
59928+
59929+ help
59930+ If you say Y here, several features in addition to those included
59931+ in the low additional security level will be enabled. These
59932+ features provide even more security to your system, though in rare
59933+ cases they may be incompatible with very old or poorly written
59934+ software. If you enable this option, make sure that your auth
59935+ service (identd) is running as gid 1001. With this option,
59936+ the following features (in addition to those provided in the
59937+ low additional security level) will be enabled:
59938+
59939+ - Failed fork logging
59940+ - Time change logging
59941+ - Signal logging
59942+ - Deny mounts in chroot
59943+ - Deny double chrooting
59944+ - Deny sysctl writes in chroot
59945+ - Deny mknod in chroot
59946+ - Deny access to abstract AF_UNIX sockets out of chroot
59947+ - Deny pivot_root in chroot
59948+ - Denied writes of /dev/kmem, /dev/mem, and /dev/port
59949+ - /proc restrictions with special GID set to 10 (usually wheel)
59950+ - Address Space Layout Randomization (ASLR)
59951+ - Prevent exploitation of most refcount overflows
59952+ - Bounds checking of copying between the kernel and userland
59953+
59954+config GRKERNSEC_HIGH
59955+ bool "High"
59956+ select GRKERNSEC_LINK
59957+ select GRKERNSEC_FIFO
59958+ select GRKERNSEC_EXECVE
59959+ select GRKERNSEC_DMESG
59960+ select GRKERNSEC_FORKFAIL
59961+ select GRKERNSEC_TIME
59962+ select GRKERNSEC_SIGNAL
59963+ select GRKERNSEC_CHROOT
59964+ select GRKERNSEC_CHROOT_SHMAT
59965+ select GRKERNSEC_CHROOT_UNIX
59966+ select GRKERNSEC_CHROOT_MOUNT
59967+ select GRKERNSEC_CHROOT_FCHDIR
59968+ select GRKERNSEC_CHROOT_PIVOT
59969+ select GRKERNSEC_CHROOT_DOUBLE
59970+ select GRKERNSEC_CHROOT_CHDIR
59971+ select GRKERNSEC_CHROOT_MKNOD
59972+ select GRKERNSEC_CHROOT_CAPS
59973+ select GRKERNSEC_CHROOT_SYSCTL
59974+ select GRKERNSEC_CHROOT_FINDTASK
59975+ select GRKERNSEC_SYSFS_RESTRICT
59976+ select GRKERNSEC_PROC
59977+ select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
59978+ select GRKERNSEC_HIDESYM
59979+ select GRKERNSEC_BRUTE
59980+ select GRKERNSEC_PROC_USERGROUP
59981+ select GRKERNSEC_KMEM
59982+ select GRKERNSEC_RESLOG
59983+ select GRKERNSEC_RANDNET
59984+ select GRKERNSEC_PROC_ADD
59985+ select GRKERNSEC_CHROOT_CHMOD
59986+ select GRKERNSEC_CHROOT_NICE
59987+ select GRKERNSEC_AUDIT_MOUNT
59988+ select GRKERNSEC_MODHARDEN if (MODULES)
59989+ select GRKERNSEC_HARDEN_PTRACE
59990+ select GRKERNSEC_VM86 if (X86_32)
59991+ select GRKERNSEC_KERN_LOCKOUT if (X86)
59992+ select PAX
59993+ select PAX_RANDUSTACK
59994+ select PAX_ASLR
59995+ select PAX_RANDMMAP
59996+ select PAX_NOEXEC
59997+ select PAX_MPROTECT
59998+ select PAX_EI_PAX
59999+ select PAX_PT_PAX_FLAGS
60000+ select PAX_HAVE_ACL_FLAGS
60001+ select PAX_KERNEXEC if ((PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN)
60002+ select PAX_MEMORY_UDEREF if (X86 && !XEN)
60003+ select PAX_RANDKSTACK if (X86_TSC && X86)
60004+ select PAX_SEGMEXEC if (X86_32)
60005+ select PAX_PAGEEXEC
60006+ select PAX_EMUPLT if (ALPHA || PARISC || SPARC32 || SPARC64)
60007+ select PAX_EMUTRAMP if (PARISC)
60008+ select PAX_EMUSIGRT if (PARISC)
60009+ select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
60010+ select PAX_ELFRELOCS if (PAX_ETEXECRELOCS || (IA64 || PPC || X86))
60011+ select PAX_REFCOUNT if (X86 || SPARC64)
60012+ select PAX_USERCOPY if ((X86 || PPC || SPARC32 || SPARC64) && (SLAB || SLUB || SLOB))
60013+ help
60014+ If you say Y here, many of the features of grsecurity will be
60015+ enabled, which will protect you against many kinds of attacks
60016+ against your system. The heightened security comes at a cost
60017+ of an increased chance of incompatibilities with rare software
60018+ on your machine. Since this security level enables PaX, you should
60019+ view <http://pax.grsecurity.net> and read about the PaX
60020+ project. While you are there, download chpax and run it on
60021+ binaries that cause problems with PaX. Also remember that
60022+ since the /proc restrictions are enabled, you must run your
60023+ identd as gid 1001. This security level enables the following
60024+ features in addition to those listed in the low and medium
60025+ security levels:
60026+
60027+ - Additional /proc restrictions
60028+ - Chmod restrictions in chroot
60029+ - No signals, ptrace, or viewing of processes outside of chroot
60030+ - Capability restrictions in chroot
60031+ - Deny fchdir out of chroot
60032+ - Priority restrictions in chroot
60033+ - Segmentation-based implementation of PaX
60034+ - Mprotect restrictions
60035+ - Removal of addresses from /proc/<pid>/[smaps|maps|stat]
60036+ - Kernel stack randomization
60037+ - Mount/unmount/remount logging
60038+ - Kernel symbol hiding
60039+ - Prevention of memory exhaustion-based exploits
60040+ - Hardening of module auto-loading
60041+ - Ptrace restrictions
60042+ - Restricted vm86 mode
60043+ - Restricted sysfs/debugfs
60044+ - Active kernel exploit response
60045+
60046+config GRKERNSEC_CUSTOM
60047+ bool "Custom"
60048+ help
60049+ If you say Y here, you will be able to configure every grsecurity
60050+ option, which allows you to enable many more features that aren't
60051+ covered in the basic security levels. These additional features
60052+ include TPE, socket restrictions, and the sysctl system for
60053+ grsecurity. It is advised that you read through the help for
60054+ each option to determine its usefulness in your situation.
60055+
60056+endchoice
60057+
60058+menu "Address Space Protection"
60059+depends on GRKERNSEC
60060+
60061+config GRKERNSEC_KMEM
60062+ bool "Deny writing to /dev/kmem, /dev/mem, and /dev/port"
60063+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
60064+ help
60065+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
60066+ be written to via mmap or otherwise to modify the running kernel.
60067+ /dev/port will also not be allowed to be opened. If you have module
60068+ support disabled, enabling this will close up four ways that are
60069+ currently used to insert malicious code into the running kernel.
60070+ Even with all these features enabled, we still highly recommend that
60071+ you use the RBAC system, as it is still possible for an attacker to
60072+ modify the running kernel through privileged I/O granted by ioperm/iopl.
60073+ If you are not using XFree86, you may be able to stop this additional
60074+ case by enabling the 'Disable privileged I/O' option. Though nothing
60075+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
60076+ but only to video memory, which is the only writing we allow in this
60077+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
60078+ not be allowed to mprotect it with PROT_WRITE later.
60079+ It is highly recommended that you say Y here if you meet all the
60080+ conditions above.
60081+
60082+config GRKERNSEC_VM86
60083+ bool "Restrict VM86 mode"
60084+ depends on X86_32
60085+
60086+ help
60087+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
60088+ make use of a special execution mode on 32bit x86 processors called
60089+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
60090+ video cards and will still work with this option enabled. The purpose
60091+ of the option is to prevent exploitation of emulation errors in
60092+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
60093+ Nearly all users should be able to enable this option.
60094+
60095+config GRKERNSEC_IO
60096+ bool "Disable privileged I/O"
60097+ depends on X86
60098+ select RTC_CLASS
60099+ select RTC_INTF_DEV
60100+ select RTC_DRV_CMOS
60101+
60102+ help
60103+ If you say Y here, all ioperm and iopl calls will return an error.
60104+ Ioperm and iopl can be used to modify the running kernel.
60105+ Unfortunately, some programs need this access to operate properly,
60106+ the most notable of which are XFree86 and hwclock. hwclock can be
60107+ remedied by having RTC support in the kernel, so real-time
60108+ clock support is enabled if this option is enabled, to ensure
60109+ that hwclock operates correctly. XFree86 still will not
60110+ operate correctly with this option enabled, so DO NOT CHOOSE Y
60111+ IF YOU USE XFree86. If you use XFree86 and you still want to
60112+ protect your kernel against modification, use the RBAC system.
60113+
60114+config GRKERNSEC_PROC_MEMMAP
60115+ bool "Remove addresses from /proc/<pid>/[smaps|maps|stat]"
60116+ default y if (PAX_NOEXEC || PAX_ASLR)
60117+ depends on PAX_NOEXEC || PAX_ASLR
60118+ help
60119+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
60120+ give no information about the addresses of its mappings if
60121+ PaX features that rely on random addresses are enabled on the task.
60122+ If you use PaX it is greatly recommended that you say Y here as it
60123+ closes up a hole that makes the full ASLR useless for suid
60124+ binaries.
60125+
60126+config GRKERNSEC_BRUTE
60127+ bool "Deter exploit bruteforcing"
60128+ help
60129+ If you say Y here, attempts to bruteforce exploits against forking
60130+ daemons such as apache or sshd, as well as against suid/sgid binaries
60131+ will be deterred. When a child of a forking daemon is killed by PaX
60132+ or crashes due to an illegal instruction or other suspicious signal,
60133+ the parent process will be delayed 30 seconds upon every subsequent
60134+ fork until the administrator is able to assess the situation and
60135+ restart the daemon.
60136+ In the suid/sgid case, the attempt is logged, the user has all their
60137+ processes terminated, and they are prevented from executing any further
60138+ processes for 15 minutes.
60139+ It is recommended that you also enable signal logging in the auditing
60140+ section so that logs are generated when a process triggers a suspicious
60141+ signal.
60142+
60143+config GRKERNSEC_MODHARDEN
60144+ bool "Harden module auto-loading"
60145+ depends on MODULES
60146+ help
60147+ If you say Y here, module auto-loading in response to use of some
60148+ feature implemented by an unloaded module will be restricted to
60149+ root users. Enabling this option helps defend against attacks
60150+ by unprivileged users who abuse the auto-loading behavior to
60151+ cause a vulnerable module to load that is then exploited.
60152+
60153+ If this option prevents a legitimate use of auto-loading for a
60154+ non-root user, the administrator can execute modprobe manually
60155+ with the exact name of the module mentioned in the alert log.
60156+ Alternatively, the administrator can add the module to the list
60157+ of modules loaded at boot by modifying init scripts.
60158+
60159+ Modification of init scripts will most likely be needed on
60160+ Ubuntu servers with encrypted home directory support enabled,
60161+ as the first non-root user logging in will cause the ecb(aes),
60162+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
60163+
60164+config GRKERNSEC_HIDESYM
60165+ bool "Hide kernel symbols"
60166+ help
60167+ If you say Y here, getting information on loaded modules, and
60168+ displaying all kernel symbols through a syscall will be restricted
60169+ to users with CAP_SYS_MODULE. For software compatibility reasons,
60170+ /proc/kallsyms will be restricted to the root user. The RBAC
60171+ system can hide that entry even from root.
60172+
60173+ This option also prevents leaking of kernel addresses through
60174+ several /proc entries.
60175+
60176+ Note that this option is only effective provided the following
60177+ conditions are met:
60178+ 1) The kernel using grsecurity is not precompiled by some distribution
60179+ 2) You have also enabled GRKERNSEC_DMESG
60180+ 3) You are using the RBAC system and hiding other files such as your
60181+ kernel image and System.map. Alternatively, enabling this option
60182+ causes the permissions on /boot, /lib/modules, and the kernel
60183+ source directory to change at compile time to prevent
60184+ reading by non-root users.
60185+ If the above conditions are met, this option will aid in providing a
60186+ useful protection against local kernel exploitation of overflows
60187+ and arbitrary read/write vulnerabilities.
60188+
60189+config GRKERNSEC_KERN_LOCKOUT
60190+ bool "Active kernel exploit response"
60191+ depends on X86
60192+ help
60193+ If you say Y here, when a PaX alert is triggered due to suspicious
60194+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
60195+ or an OOPs occurs due to bad memory accesses, instead of just
60196+ terminating the offending process (and potentially allowing
60197+ a subsequent exploit from the same user), we will take one of two
60198+ actions:
60199+ If the user was root, we will panic the system
60200+ If the user was non-root, we will log the attempt, terminate
60201+ all processes owned by the user, then prevent them from creating
60202+ any new processes until the system is restarted
60203+ This deters repeated kernel exploitation/bruteforcing attempts
60204+ and is useful for later forensics.
60205+
60206+endmenu
60207+menu "Role Based Access Control Options"
60208+depends on GRKERNSEC
60209+
60210+config GRKERNSEC_RBAC_DEBUG
60211+ bool
60212+
60213+config GRKERNSEC_NO_RBAC
60214+ bool "Disable RBAC system"
60215+ help
60216+ If you say Y here, the /dev/grsec device will be removed from the kernel,
60217+ preventing the RBAC system from being enabled. You should only say Y
60218+ here if you have no intention of using the RBAC system, so as to prevent
60219+ an attacker with root access from misusing the RBAC system to hide files
60220+ and processes when loadable module support and /dev/[k]mem have been
60221+ locked down.
60222+
60223+config GRKERNSEC_ACL_HIDEKERN
60224+ bool "Hide kernel processes"
60225+ help
60226+ If you say Y here, all kernel threads will be hidden to all
60227+ processes but those whose subject has the "view hidden processes"
60228+ flag.
60229+
60230+config GRKERNSEC_ACL_MAXTRIES
60231+ int "Maximum tries before password lockout"
60232+ default 3
60233+ help
60234+ This option enforces the maximum number of times a user can attempt
60235+ to authorize themselves with the grsecurity RBAC system before being
60236+ denied the ability to attempt authorization again for a specified time.
60237+ The lower the number, the harder it will be to brute-force a password.
60238+
60239+config GRKERNSEC_ACL_TIMEOUT
60240+ int "Time to wait after max password tries, in seconds"
60241+ default 30
60242+ help
60243+ This option specifies the time the user must wait after attempting to
60244+ authorize to the RBAC system with the maximum number of invalid
60245+ passwords. The higher the number, the harder it will be to brute-force
60246+ a password.
60247+
60248+endmenu
60249+menu "Filesystem Protections"
60250+depends on GRKERNSEC
60251+
60252+config GRKERNSEC_PROC
60253+ bool "Proc restrictions"
60254+ help
60255+ If you say Y here, the permissions of the /proc filesystem
60256+ will be altered to enhance system security and privacy. You MUST
60257+ choose either a user only restriction or a user and group restriction.
60258+ Depending upon the option you choose, you can either restrict users to
60259+ see only the processes they themselves run, or choose a group that can
60260+ view all processes and files normally restricted to root if you choose
60261+ the "restrict to user only" option. NOTE: If you're running identd as
60262+ a non-root user, you will have to run it as the group you specify here.
60263+
60264+config GRKERNSEC_PROC_USER
60265+ bool "Restrict /proc to user only"
60266+ depends on GRKERNSEC_PROC
60267+ help
60268+ If you say Y here, non-root users will only be able to view their own
60269+ processes, and restricts them from viewing network-related information,
60270+ and viewing kernel symbol and module information.
60271+
60272+config GRKERNSEC_PROC_USERGROUP
60273+ bool "Allow special group"
60274+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
60275+ help
60276+ If you say Y here, you will be able to select a group that will be
60277+ able to view all processes and network-related information. If you've
60278+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
60279+ remain hidden. This option is useful if you want to run identd as
60280+ a non-root user.
60281+
60282+config GRKERNSEC_PROC_GID
60283+ int "GID for special group"
60284+ depends on GRKERNSEC_PROC_USERGROUP
60285+ default 1001
60286+
60287+config GRKERNSEC_PROC_ADD
60288+ bool "Additional restrictions"
60289+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
60290+ help
60291+ If you say Y here, additional restrictions will be placed on
60292+ /proc that keep normal users from viewing device information and
60293+ slabinfo information that could be useful for exploits.
60294+
60295+config GRKERNSEC_LINK
60296+ bool "Linking restrictions"
60297+ help
60298+ If you say Y here, /tmp race exploits will be prevented, since users
60299+ will no longer be able to follow symlinks owned by other users in
60300+ world-writable +t directories (e.g. /tmp), unless the owner of the
60301+ symlink is the owner of the directory. users will also not be
60302+ able to hardlink to files they do not own. If the sysctl option is
60303+ enabled, a sysctl option with name "linking_restrictions" is created.
60304+
60305+config GRKERNSEC_FIFO
60306+ bool "FIFO restrictions"
60307+ help
60308+ If you say Y here, users will not be able to write to FIFOs they don't
60309+ own in world-writable +t directories (e.g. /tmp), unless the owner of
60310+ the FIFO is the same owner of the directory it's held in. If the sysctl
60311+ option is enabled, a sysctl option with name "fifo_restrictions" is
60312+ created.
60313+
60314+config GRKERNSEC_SYSFS_RESTRICT
60315+ bool "Sysfs/debugfs restriction"
60316+ depends on SYSFS
60317+ help
60318+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
60319+ any filesystem normally mounted under it (e.g. debugfs) will only
60320+ be accessible by root. These filesystems generally provide access
60321+ to hardware and debug information that isn't appropriate for unprivileged
60322+ users of the system. Sysfs and debugfs have also become a large source
60323+ of new vulnerabilities, ranging from infoleaks to local compromise.
60324+ There has been very little oversight with an eye toward security involved
60325+ in adding new exporters of information to these filesystems, so their
60326+ use is discouraged.
60327+ This option is equivalent to a chmod 0700 of the mount paths.
60328+
60329+config GRKERNSEC_ROFS
60330+ bool "Runtime read-only mount protection"
60331+ help
60332+ If you say Y here, a sysctl option with name "romount_protect" will
60333+ be created. By setting this option to 1 at runtime, filesystems
60334+ will be protected in the following ways:
60335+ * No new writable mounts will be allowed
60336+ * Existing read-only mounts won't be able to be remounted read/write
60337+ * Write operations will be denied on all block devices
60338+ This option acts independently of grsec_lock: once it is set to 1,
60339+ it cannot be turned off. Therefore, please be mindful of the resulting
60340+ behavior if this option is enabled in an init script on a read-only
60341+ filesystem. This feature is mainly intended for secure embedded systems.
60342+
60343+config GRKERNSEC_CHROOT
60344+ bool "Chroot jail restrictions"
60345+ help
60346+ If you say Y here, you will be able to choose several options that will
60347+ make breaking out of a chrooted jail much more difficult. If you
60348+ encounter no software incompatibilities with the following options, it
60349+ is recommended that you enable each one.
60350+
60351+config GRKERNSEC_CHROOT_MOUNT
60352+ bool "Deny mounts"
60353+ depends on GRKERNSEC_CHROOT
60354+ help
60355+ If you say Y here, processes inside a chroot will not be able to
60356+ mount or remount filesystems. If the sysctl option is enabled, a
60357+ sysctl option with name "chroot_deny_mount" is created.
60358+
60359+config GRKERNSEC_CHROOT_DOUBLE
60360+ bool "Deny double-chroots"
60361+ depends on GRKERNSEC_CHROOT
60362+ help
60363+ If you say Y here, processes inside a chroot will not be able to chroot
60364+ again outside the chroot. This is a widely used method of breaking
60365+ out of a chroot jail and should not be allowed. If the sysctl
60366+ option is enabled, a sysctl option with name
60367+ "chroot_deny_chroot" is created.
60368+
60369+config GRKERNSEC_CHROOT_PIVOT
60370+ bool "Deny pivot_root in chroot"
60371+ depends on GRKERNSEC_CHROOT
60372+ help
60373+ If you say Y here, processes inside a chroot will not be able to use
60374+ a function called pivot_root() that was introduced in Linux 2.3.41. It
60375+ works similar to chroot in that it changes the root filesystem. This
60376+ function could be misused in a chrooted process to attempt to break out
60377+ of the chroot, and therefore should not be allowed. If the sysctl
60378+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
60379+ created.
60380+
60381+config GRKERNSEC_CHROOT_CHDIR
60382+ bool "Enforce chdir(\"/\") on all chroots"
60383+ depends on GRKERNSEC_CHROOT
60384+ help
60385+ If you say Y here, the current working directory of all newly-chrooted
60386+ applications will be set to the the root directory of the chroot.
60387+ The man page on chroot(2) states:
60388+ Note that this call does not change the current working
60389+ directory, so that `.' can be outside the tree rooted at
60390+ `/'. In particular, the super-user can escape from a
60391+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
60392+
60393+ It is recommended that you say Y here, since it's not known to break
60394+ any software. If the sysctl option is enabled, a sysctl option with
60395+ name "chroot_enforce_chdir" is created.
60396+
60397+config GRKERNSEC_CHROOT_CHMOD
60398+ bool "Deny (f)chmod +s"
60399+ depends on GRKERNSEC_CHROOT
60400+ help
60401+ If you say Y here, processes inside a chroot will not be able to chmod
60402+ or fchmod files to make them have suid or sgid bits. This protects
60403+ against another published method of breaking a chroot. If the sysctl
60404+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
60405+ created.
60406+
60407+config GRKERNSEC_CHROOT_FCHDIR
60408+ bool "Deny fchdir out of chroot"
60409+ depends on GRKERNSEC_CHROOT
60410+ help
60411+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
60412+ to a file descriptor of the chrooting process that points to a directory
60413+ outside the filesystem will be stopped. If the sysctl option
60414+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
60415+
60416+config GRKERNSEC_CHROOT_MKNOD
60417+ bool "Deny mknod"
60418+ depends on GRKERNSEC_CHROOT
60419+ help
60420+ If you say Y here, processes inside a chroot will not be allowed to
60421+ mknod. The problem with using mknod inside a chroot is that it
60422+ would allow an attacker to create a device entry that is the same
60423+ as one on the physical root of your system, which could range from
60424+ anything from the console device to a device for your harddrive (which
60425+ they could then use to wipe the drive or steal data). It is recommended
60426+ that you say Y here, unless you run into software incompatibilities.
60427+ If the sysctl option is enabled, a sysctl option with name
60428+ "chroot_deny_mknod" is created.
60429+
60430+config GRKERNSEC_CHROOT_SHMAT
60431+ bool "Deny shmat() out of chroot"
60432+ depends on GRKERNSEC_CHROOT
60433+ help
60434+ If you say Y here, processes inside a chroot will not be able to attach
60435+ to shared memory segments that were created outside of the chroot jail.
60436+ It is recommended that you say Y here. If the sysctl option is enabled,
60437+ a sysctl option with name "chroot_deny_shmat" is created.
60438+
60439+config GRKERNSEC_CHROOT_UNIX
60440+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
60441+ depends on GRKERNSEC_CHROOT
60442+ help
60443+ If you say Y here, processes inside a chroot will not be able to
60444+ connect to abstract (meaning not belonging to a filesystem) Unix
60445+ domain sockets that were bound outside of a chroot. It is recommended
60446+ that you say Y here. If the sysctl option is enabled, a sysctl option
60447+ with name "chroot_deny_unix" is created.
60448+
60449+config GRKERNSEC_CHROOT_FINDTASK
60450+ bool "Protect outside processes"
60451+ depends on GRKERNSEC_CHROOT
60452+ help
60453+ If you say Y here, processes inside a chroot will not be able to
60454+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
60455+ getsid, or view any process outside of the chroot. If the sysctl
60456+ option is enabled, a sysctl option with name "chroot_findtask" is
60457+ created.
60458+
60459+config GRKERNSEC_CHROOT_NICE
60460+ bool "Restrict priority changes"
60461+ depends on GRKERNSEC_CHROOT
60462+ help
60463+ If you say Y here, processes inside a chroot will not be able to raise
60464+ the priority of processes in the chroot, or alter the priority of
60465+ processes outside the chroot. This provides more security than simply
60466+ removing CAP_SYS_NICE from the process' capability set. If the
60467+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
60468+ is created.
60469+
60470+config GRKERNSEC_CHROOT_SYSCTL
60471+ bool "Deny sysctl writes"
60472+ depends on GRKERNSEC_CHROOT
60473+ help
60474+ If you say Y here, an attacker in a chroot will not be able to
60475+ write to sysctl entries, either by sysctl(2) or through a /proc
60476+ interface. It is strongly recommended that you say Y here. If the
60477+ sysctl option is enabled, a sysctl option with name
60478+ "chroot_deny_sysctl" is created.
60479+
60480+config GRKERNSEC_CHROOT_CAPS
60481+ bool "Capability restrictions"
60482+ depends on GRKERNSEC_CHROOT
60483+ help
60484+ If you say Y here, the capabilities on all root processes within a
60485+ chroot jail will be lowered to stop module insertion, raw i/o,
60486+ system and net admin tasks, rebooting the system, modifying immutable
60487+ files, modifying IPC owned by another, and changing the system time.
60488+ This is left an option because it can break some apps. Disable this
60489+ if your chrooted apps are having problems performing those kinds of
60490+ tasks. If the sysctl option is enabled, a sysctl option with
60491+ name "chroot_caps" is created.
60492+
60493+endmenu
60494+menu "Kernel Auditing"
60495+depends on GRKERNSEC
60496+
60497+config GRKERNSEC_AUDIT_GROUP
60498+ bool "Single group for auditing"
60499+ help
60500+ If you say Y here, the exec, chdir, and (un)mount logging features
60501+ will only operate on a group you specify. This option is recommended
60502+ if you only want to watch certain users instead of having a large
60503+ amount of logs from the entire system. If the sysctl option is enabled,
60504+ a sysctl option with name "audit_group" is created.
60505+
60506+config GRKERNSEC_AUDIT_GID
60507+ int "GID for auditing"
60508+ depends on GRKERNSEC_AUDIT_GROUP
60509+ default 1007
60510+
60511+config GRKERNSEC_EXECLOG
60512+ bool "Exec logging"
60513+ help
60514+ If you say Y here, all execve() calls will be logged (since the
60515+ other exec*() calls are frontends to execve(), all execution
60516+ will be logged). Useful for shell-servers that like to keep track
60517+ of their users. If the sysctl option is enabled, a sysctl option with
60518+ name "exec_logging" is created.
60519+ WARNING: This option when enabled will produce a LOT of logs, especially
60520+ on an active system.
60521+
60522+config GRKERNSEC_RESLOG
60523+ bool "Resource logging"
60524+ help
60525+ If you say Y here, all attempts to overstep resource limits will
60526+ be logged with the resource name, the requested size, and the current
60527+ limit. It is highly recommended that you say Y here. If the sysctl
60528+ option is enabled, a sysctl option with name "resource_logging" is
60529+ created. If the RBAC system is enabled, the sysctl value is ignored.
60530+
60531+config GRKERNSEC_CHROOT_EXECLOG
60532+ bool "Log execs within chroot"
60533+ help
60534+ If you say Y here, all executions inside a chroot jail will be logged
60535+ to syslog. This can cause a large amount of logs if certain
60536+ applications (eg. djb's daemontools) are installed on the system, and
60537+ is therefore left as an option. If the sysctl option is enabled, a
60538+ sysctl option with name "chroot_execlog" is created.
60539+
60540+config GRKERNSEC_AUDIT_PTRACE
60541+ bool "Ptrace logging"
60542+ help
60543+ If you say Y here, all attempts to attach to a process via ptrace
60544+ will be logged. If the sysctl option is enabled, a sysctl option
60545+ with name "audit_ptrace" is created.
60546+
60547+config GRKERNSEC_AUDIT_CHDIR
60548+ bool "Chdir logging"
60549+ help
60550+ If you say Y here, all chdir() calls will be logged. If the sysctl
60551+ option is enabled, a sysctl option with name "audit_chdir" is created.
60552+
60553+config GRKERNSEC_AUDIT_MOUNT
60554+ bool "(Un)Mount logging"
60555+ help
60556+ If you say Y here, all mounts and unmounts will be logged. If the
60557+ sysctl option is enabled, a sysctl option with name "audit_mount" is
60558+ created.
60559+
60560+config GRKERNSEC_SIGNAL
60561+ bool "Signal logging"
60562+ help
60563+ If you say Y here, certain important signals will be logged, such as
60564+ SIGSEGV, which will as a result inform you of when a error in a program
60565+ occurred, which in some cases could mean a possible exploit attempt.
60566+ If the sysctl option is enabled, a sysctl option with name
60567+ "signal_logging" is created.
60568+
60569+config GRKERNSEC_FORKFAIL
60570+ bool "Fork failure logging"
60571+ help
60572+ If you say Y here, all failed fork() attempts will be logged.
60573+ This could suggest a fork bomb, or someone attempting to overstep
60574+ their process limit. If the sysctl option is enabled, a sysctl option
60575+ with name "forkfail_logging" is created.
60576+
60577+config GRKERNSEC_TIME
60578+ bool "Time change logging"
60579+ help
60580+ If you say Y here, any changes of the system clock will be logged.
60581+ If the sysctl option is enabled, a sysctl option with name
60582+ "timechange_logging" is created.
60583+
60584+config GRKERNSEC_PROC_IPADDR
60585+ bool "/proc/<pid>/ipaddr support"
60586+ help
60587+ If you say Y here, a new entry will be added to each /proc/<pid>
60588+ directory that contains the IP address of the person using the task.
60589+ The IP is carried across local TCP and AF_UNIX stream sockets.
60590+ This information can be useful for IDS/IPSes to perform remote response
60591+ to a local attack. The entry is readable by only the owner of the
60592+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
60593+ the RBAC system), and thus does not create privacy concerns.
60594+
60595+config GRKERNSEC_RWXMAP_LOG
60596+ bool 'Denied RWX mmap/mprotect logging'
60597+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
60598+ help
60599+ If you say Y here, calls to mmap() and mprotect() with explicit
60600+ usage of PROT_WRITE and PROT_EXEC together will be logged when
60601+ denied by the PAX_MPROTECT feature. If the sysctl option is
60602+ enabled, a sysctl option with name "rwxmap_logging" is created.
60603+
60604+config GRKERNSEC_AUDIT_TEXTREL
60605+ bool 'ELF text relocations logging (READ HELP)'
60606+ depends on PAX_MPROTECT
60607+ help
60608+ If you say Y here, text relocations will be logged with the filename
60609+ of the offending library or binary. The purpose of the feature is
60610+ to help Linux distribution developers get rid of libraries and
60611+ binaries that need text relocations which hinder the future progress
60612+ of PaX. Only Linux distribution developers should say Y here, and
60613+ never on a production machine, as this option creates an information
60614+ leak that could aid an attacker in defeating the randomization of
60615+ a single memory region. If the sysctl option is enabled, a sysctl
60616+ option with name "audit_textrel" is created.
60617+
60618+endmenu
60619+
60620+menu "Executable Protections"
60621+depends on GRKERNSEC
60622+
60623+config GRKERNSEC_EXECVE
60624+ bool "Enforce RLIMIT_NPROC on execs"
60625+ help
60626+ If you say Y here, users with a resource limit on processes will
60627+ have the value checked during execve() calls. The current system
60628+ only checks the system limit during fork() calls. If the sysctl option
60629+ is enabled, a sysctl option with name "execve_limiting" is created.
60630+
60631+config GRKERNSEC_DMESG
60632+ bool "Dmesg(8) restriction"
60633+ help
60634+ If you say Y here, non-root users will not be able to use dmesg(8)
60635+ to view up to the last 4kb of messages in the kernel's log buffer.
60636+ The kernel's log buffer often contains kernel addresses and other
60637+ identifying information useful to an attacker in fingerprinting a
60638+ system for a targeted exploit.
60639+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
60640+ created.
60641+
60642+config GRKERNSEC_HARDEN_PTRACE
60643+ bool "Deter ptrace-based process snooping"
60644+ help
60645+ If you say Y here, TTY sniffers and other malicious monitoring
60646+ programs implemented through ptrace will be defeated. If you
60647+ have been using the RBAC system, this option has already been
60648+ enabled for several years for all users, with the ability to make
60649+ fine-grained exceptions.
60650+
60651+ This option only affects the ability of non-root users to ptrace
60652+ processes that are not a descendent of the ptracing process.
60653+ This means that strace ./binary and gdb ./binary will still work,
60654+ but attaching to arbitrary processes will not. If the sysctl
60655+ option is enabled, a sysctl option with name "harden_ptrace" is
60656+ created.
60657+
60658+config GRKERNSEC_TPE
60659+ bool "Trusted Path Execution (TPE)"
60660+ help
60661+ If you say Y here, you will be able to choose a gid to add to the
60662+ supplementary groups of users you want to mark as "untrusted."
60663+ These users will not be able to execute any files that are not in
60664+ root-owned directories writable only by root. If the sysctl option
60665+ is enabled, a sysctl option with name "tpe" is created.
60666+
60667+config GRKERNSEC_TPE_ALL
60668+ bool "Partially restrict all non-root users"
60669+ depends on GRKERNSEC_TPE
60670+ help
60671+ If you say Y here, all non-root users will be covered under
60672+ a weaker TPE restriction. This is separate from, and in addition to,
60673+ the main TPE options that you have selected elsewhere. Thus, if a
60674+ "trusted" GID is chosen, this restriction applies to even that GID.
60675+ Under this restriction, all non-root users will only be allowed to
60676+ execute files in directories they own that are not group or
60677+ world-writable, or in directories owned by root and writable only by
60678+ root. If the sysctl option is enabled, a sysctl option with name
60679+ "tpe_restrict_all" is created.
60680+
60681+config GRKERNSEC_TPE_INVERT
60682+ bool "Invert GID option"
60683+ depends on GRKERNSEC_TPE
60684+ help
60685+ If you say Y here, the group you specify in the TPE configuration will
60686+ decide what group TPE restrictions will be *disabled* for. This
60687+ option is useful if you want TPE restrictions to be applied to most
60688+ users on the system. If the sysctl option is enabled, a sysctl option
60689+ with name "tpe_invert" is created. Unlike other sysctl options, this
60690+ entry will default to on for backward-compatibility.
60691+
60692+config GRKERNSEC_TPE_GID
60693+ int "GID for untrusted users"
60694+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
60695+ default 1005
60696+ help
60697+ Setting this GID determines what group TPE restrictions will be
60698+ *enabled* for. If the sysctl option is enabled, a sysctl option
60699+ with name "tpe_gid" is created.
60700+
60701+config GRKERNSEC_TPE_GID
60702+ int "GID for trusted users"
60703+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
60704+ default 1005
60705+ help
60706+ Setting this GID determines what group TPE restrictions will be
60707+ *disabled* for. If the sysctl option is enabled, a sysctl option
60708+ with name "tpe_gid" is created.
60709+
60710+endmenu
60711+menu "Network Protections"
60712+depends on GRKERNSEC
60713+
60714+config GRKERNSEC_RANDNET
60715+ bool "Larger entropy pools"
60716+ help
60717+ If you say Y here, the entropy pools used for many features of Linux
60718+ and grsecurity will be doubled in size. Since several grsecurity
60719+ features use additional randomness, it is recommended that you say Y
60720+ here. Saying Y here has a similar effect as modifying
60721+ /proc/sys/kernel/random/poolsize.
60722+
60723+config GRKERNSEC_BLACKHOLE
60724+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
60725+ help
60726+ If you say Y here, neither TCP resets nor ICMP
60727+ destination-unreachable packets will be sent in response to packets
60728+ sent to ports for which no associated listening process exists.
60729+ This feature supports both IPV4 and IPV6 and exempts the
60730+ loopback interface from blackholing. Enabling this feature
60731+ makes a host more resilient to DoS attacks and reduces network
60732+ visibility against scanners.
60733+
60734+ The blackhole feature as-implemented is equivalent to the FreeBSD
60735+ blackhole feature, as it prevents RST responses to all packets, not
60736+ just SYNs. Under most application behavior this causes no
60737+ problems, but applications (like haproxy) may not close certain
60738+ connections in a way that cleanly terminates them on the remote
60739+ end, leaving the remote host in LAST_ACK state. Because of this
60740+ side-effect and to prevent intentional LAST_ACK DoSes, this
60741+ feature also adds automatic mitigation against such attacks.
60742+ The mitigation drastically reduces the amount of time a socket
60743+ can spend in LAST_ACK state. If you're using haproxy and not
60744+ all servers it connects to have this option enabled, consider
60745+ disabling this feature on the haproxy host.
60746+
60747+ If the sysctl option is enabled, two sysctl options with names
60748+ "ip_blackhole" and "lastack_retries" will be created.
60749+ While "ip_blackhole" takes the standard zero/non-zero on/off
60750+ toggle, "lastack_retries" uses the same kinds of values as
60751+ "tcp_retries1" and "tcp_retries2". The default value of 4
60752+ prevents a socket from lasting more than 45 seconds in LAST_ACK
60753+ state.
60754+
60755+config GRKERNSEC_SOCKET
60756+ bool "Socket restrictions"
60757+ help
60758+ If you say Y here, you will be able to choose from several options.
60759+ If you assign a GID on your system and add it to the supplementary
60760+ groups of users you want to restrict socket access to, this patch
60761+ will perform up to three things, based on the option(s) you choose.
60762+
60763+config GRKERNSEC_SOCKET_ALL
60764+ bool "Deny any sockets to group"
60765+ depends on GRKERNSEC_SOCKET
60766+ help
60767+ If you say Y here, you will be able to choose a GID of whose users will
60768+ be unable to connect to other hosts from your machine or run server
60769+ applications from your machine. If the sysctl option is enabled, a
60770+ sysctl option with name "socket_all" is created.
60771+
60772+config GRKERNSEC_SOCKET_ALL_GID
60773+ int "GID to deny all sockets for"
60774+ depends on GRKERNSEC_SOCKET_ALL
60775+ default 1004
60776+ help
60777+ Here you can choose the GID to disable socket access for. Remember to
60778+ add the users you want socket access disabled for to the GID
60779+ specified here. If the sysctl option is enabled, a sysctl option
60780+ with name "socket_all_gid" is created.
60781+
60782+config GRKERNSEC_SOCKET_CLIENT
60783+ bool "Deny client sockets to group"
60784+ depends on GRKERNSEC_SOCKET
60785+ help
60786+ If you say Y here, you will be able to choose a GID of whose users will
60787+ be unable to connect to other hosts from your machine, but will be
60788+ able to run servers. If this option is enabled, all users in the group
60789+ you specify will have to use passive mode when initiating ftp transfers
60790+ from the shell on your machine. If the sysctl option is enabled, a
60791+ sysctl option with name "socket_client" is created.
60792+
60793+config GRKERNSEC_SOCKET_CLIENT_GID
60794+ int "GID to deny client sockets for"
60795+ depends on GRKERNSEC_SOCKET_CLIENT
60796+ default 1003
60797+ help
60798+ Here you can choose the GID to disable client socket access for.
60799+ Remember to add the users you want client socket access disabled for to
60800+ the GID specified here. If the sysctl option is enabled, a sysctl
60801+ option with name "socket_client_gid" is created.
60802+
60803+config GRKERNSEC_SOCKET_SERVER
60804+ bool "Deny server sockets to group"
60805+ depends on GRKERNSEC_SOCKET
60806+ help
60807+ If you say Y here, you will be able to choose a GID of whose users will
60808+ be unable to run server applications from your machine. If the sysctl
60809+ option is enabled, a sysctl option with name "socket_server" is created.
60810+
60811+config GRKERNSEC_SOCKET_SERVER_GID
60812+ int "GID to deny server sockets for"
60813+ depends on GRKERNSEC_SOCKET_SERVER
60814+ default 1002
60815+ help
60816+ Here you can choose the GID to disable server socket access for.
60817+ Remember to add the users you want server socket access disabled for to
60818+ the GID specified here. If the sysctl option is enabled, a sysctl
60819+ option with name "socket_server_gid" is created.
60820+
60821+endmenu
60822+menu "Sysctl support"
60823+depends on GRKERNSEC && SYSCTL
60824+
60825+config GRKERNSEC_SYSCTL
60826+ bool "Sysctl support"
60827+ help
60828+ If you say Y here, you will be able to change the options that
60829+ grsecurity runs with at bootup, without having to recompile your
60830+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
60831+ to enable (1) or disable (0) various features. All the sysctl entries
60832+ are mutable until the "grsec_lock" entry is set to a non-zero value.
60833+ All features enabled in the kernel configuration are disabled at boot
60834+ if you do not say Y to the "Turn on features by default" option.
60835+ All options should be set at startup, and the grsec_lock entry should
60836+ be set to a non-zero value after all the options are set.
60837+ *THIS IS EXTREMELY IMPORTANT*
60838+
60839+config GRKERNSEC_SYSCTL_DISTRO
60840+ bool "Extra sysctl support for distro makers (READ HELP)"
60841+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
60842+ help
60843+ If you say Y here, additional sysctl options will be created
60844+ for features that affect processes running as root. Therefore,
60845+ it is critical when using this option that the grsec_lock entry be
60846+ enabled after boot. Only distros with prebuilt kernel packages
60847+ with this option enabled that can ensure grsec_lock is enabled
60848+ after boot should use this option.
60849+ *Failure to set grsec_lock after boot makes all grsec features
60850+ this option covers useless*
60851+
60852+ Currently this option creates the following sysctl entries:
60853+ "Disable Privileged I/O": "disable_priv_io"
60854+
60855+config GRKERNSEC_SYSCTL_ON
60856+ bool "Turn on features by default"
60857+ depends on GRKERNSEC_SYSCTL
60858+ help
60859+ If you say Y here, instead of having all features enabled in the
60860+ kernel configuration disabled at boot time, the features will be
60861+ enabled at boot time. It is recommended you say Y here unless
60862+ there is some reason you would want all sysctl-tunable features to
60863+ be disabled by default. As mentioned elsewhere, it is important
60864+ to enable the grsec_lock entry once you have finished modifying
60865+ the sysctl entries.
60866+
60867+endmenu
60868+menu "Logging Options"
60869+depends on GRKERNSEC
60870+
60871+config GRKERNSEC_FLOODTIME
60872+ int "Seconds in between log messages (minimum)"
60873+ default 10
60874+ help
60875+ This option allows you to enforce the number of seconds between
60876+ grsecurity log messages. The default should be suitable for most
60877+ people, however, if you choose to change it, choose a value small enough
60878+ to allow informative logs to be produced, but large enough to
60879+ prevent flooding.
60880+
60881+config GRKERNSEC_FLOODBURST
60882+ int "Number of messages in a burst (maximum)"
60883+ default 4
60884+ help
60885+ This option allows you to choose the maximum number of messages allowed
60886+ within the flood time interval you chose in a separate option. The
60887+ default should be suitable for most people, however if you find that
60888+ many of your logs are being interpreted as flooding, you may want to
60889+ raise this value.
60890+
60891+endmenu
60892+
60893+endmenu
60894diff -urNp linux-2.6.39.1/grsecurity/Makefile linux-2.6.39.1/grsecurity/Makefile
60895--- linux-2.6.39.1/grsecurity/Makefile 1969-12-31 19:00:00.000000000 -0500
60896+++ linux-2.6.39.1/grsecurity/Makefile 2011-05-24 20:26:54.000000000 -0400
60897@@ -0,0 +1,33 @@
60898+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
60899+# during 2001-2009 it has been completely redesigned by Brad Spengler
60900+# into an RBAC system
60901+#
60902+# All code in this directory and various hooks inserted throughout the kernel
60903+# are copyright Brad Spengler - Open Source Security, Inc., and released
60904+# under the GPL v2 or higher
60905+
60906+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
60907+ grsec_mount.o grsec_sig.o grsec_sock.o grsec_sysctl.o \
60908+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
60909+
60910+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
60911+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
60912+ gracl_learn.o grsec_log.o
60913+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
60914+
60915+ifdef CONFIG_NET
60916+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
60917+endif
60918+
60919+ifndef CONFIG_GRKERNSEC
60920+obj-y += grsec_disabled.o
60921+endif
60922+
60923+ifdef CONFIG_GRKERNSEC_HIDESYM
60924+extra-y := grsec_hidesym.o
60925+$(obj)/grsec_hidesym.o:
60926+ @-chmod -f 500 /boot
60927+ @-chmod -f 500 /lib/modules
60928+ @-chmod -f 700 .
60929+ @echo ' grsec: protected kernel image paths'
60930+endif
60931diff -urNp linux-2.6.39.1/include/acpi/acpi_drivers.h linux-2.6.39.1/include/acpi/acpi_drivers.h
60932--- linux-2.6.39.1/include/acpi/acpi_drivers.h 2011-05-19 00:06:34.000000000 -0400
60933+++ linux-2.6.39.1/include/acpi/acpi_drivers.h 2011-05-22 19:36:32.000000000 -0400
60934@@ -119,8 +119,8 @@ void pci_acpi_crs_quirks(void);
60935 Dock Station
60936 -------------------------------------------------------------------------- */
60937 struct acpi_dock_ops {
60938- acpi_notify_handler handler;
60939- acpi_notify_handler uevent;
60940+ const acpi_notify_handler handler;
60941+ const acpi_notify_handler uevent;
60942 };
60943
60944 #if defined(CONFIG_ACPI_DOCK) || defined(CONFIG_ACPI_DOCK_MODULE)
60945@@ -128,7 +128,7 @@ extern int is_dock_device(acpi_handle ha
60946 extern int register_dock_notifier(struct notifier_block *nb);
60947 extern void unregister_dock_notifier(struct notifier_block *nb);
60948 extern int register_hotplug_dock_device(acpi_handle handle,
60949- struct acpi_dock_ops *ops,
60950+ const struct acpi_dock_ops *ops,
60951 void *context);
60952 extern void unregister_hotplug_dock_device(acpi_handle handle);
60953 #else
60954@@ -144,7 +144,7 @@ static inline void unregister_dock_notif
60955 {
60956 }
60957 static inline int register_hotplug_dock_device(acpi_handle handle,
60958- struct acpi_dock_ops *ops,
60959+ const struct acpi_dock_ops *ops,
60960 void *context)
60961 {
60962 return -ENODEV;
60963diff -urNp linux-2.6.39.1/include/acpi/processor.h linux-2.6.39.1/include/acpi/processor.h
60964--- linux-2.6.39.1/include/acpi/processor.h 2011-05-19 00:06:34.000000000 -0400
60965+++ linux-2.6.39.1/include/acpi/processor.h 2011-05-22 19:36:32.000000000 -0400
60966@@ -344,7 +344,7 @@ extern struct cpuidle_driver acpi_idle_d
60967
60968 /* in processor_thermal.c */
60969 int acpi_processor_get_limit_info(struct acpi_processor *pr);
60970-extern struct thermal_cooling_device_ops processor_cooling_ops;
60971+extern const struct thermal_cooling_device_ops processor_cooling_ops;
60972 #ifdef CONFIG_CPU_FREQ
60973 void acpi_thermal_cpufreq_init(void);
60974 void acpi_thermal_cpufreq_exit(void);
60975diff -urNp linux-2.6.39.1/include/asm-generic/atomic-long.h linux-2.6.39.1/include/asm-generic/atomic-long.h
60976--- linux-2.6.39.1/include/asm-generic/atomic-long.h 2011-05-19 00:06:34.000000000 -0400
60977+++ linux-2.6.39.1/include/asm-generic/atomic-long.h 2011-05-22 19:36:32.000000000 -0400
60978@@ -22,6 +22,12 @@
60979
60980 typedef atomic64_t atomic_long_t;
60981
60982+#ifdef CONFIG_PAX_REFCOUNT
60983+typedef atomic64_unchecked_t atomic_long_unchecked_t;
60984+#else
60985+typedef atomic64_t atomic_long_unchecked_t;
60986+#endif
60987+
60988 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
60989
60990 static inline long atomic_long_read(atomic_long_t *l)
60991@@ -31,6 +37,15 @@ static inline long atomic_long_read(atom
60992 return (long)atomic64_read(v);
60993 }
60994
60995+#ifdef CONFIG_PAX_REFCOUNT
60996+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
60997+{
60998+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60999+
61000+ return (long)atomic64_read_unchecked(v);
61001+}
61002+#endif
61003+
61004 static inline void atomic_long_set(atomic_long_t *l, long i)
61005 {
61006 atomic64_t *v = (atomic64_t *)l;
61007@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomi
61008 atomic64_set(v, i);
61009 }
61010
61011+#ifdef CONFIG_PAX_REFCOUNT
61012+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
61013+{
61014+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61015+
61016+ atomic64_set_unchecked(v, i);
61017+}
61018+#endif
61019+
61020 static inline void atomic_long_inc(atomic_long_t *l)
61021 {
61022 atomic64_t *v = (atomic64_t *)l;
61023@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomi
61024 atomic64_inc(v);
61025 }
61026
61027+#ifdef CONFIG_PAX_REFCOUNT
61028+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
61029+{
61030+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61031+
61032+ atomic64_inc_unchecked(v);
61033+}
61034+#endif
61035+
61036 static inline void atomic_long_dec(atomic_long_t *l)
61037 {
61038 atomic64_t *v = (atomic64_t *)l;
61039@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomi
61040 atomic64_dec(v);
61041 }
61042
61043+#ifdef CONFIG_PAX_REFCOUNT
61044+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
61045+{
61046+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61047+
61048+ atomic64_dec_unchecked(v);
61049+}
61050+#endif
61051+
61052 static inline void atomic_long_add(long i, atomic_long_t *l)
61053 {
61054 atomic64_t *v = (atomic64_t *)l;
61055@@ -59,6 +101,15 @@ static inline void atomic_long_add(long
61056 atomic64_add(i, v);
61057 }
61058
61059+#ifdef CONFIG_PAX_REFCOUNT
61060+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
61061+{
61062+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61063+
61064+ atomic64_add_unchecked(i, v);
61065+}
61066+#endif
61067+
61068 static inline void atomic_long_sub(long i, atomic_long_t *l)
61069 {
61070 atomic64_t *v = (atomic64_t *)l;
61071@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long
61072 atomic64_sub(i, v);
61073 }
61074
61075+#ifdef CONFIG_PAX_REFCOUNT
61076+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
61077+{
61078+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61079+
61080+ atomic64_sub_unchecked(i, v);
61081+}
61082+#endif
61083+
61084 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
61085 {
61086 atomic64_t *v = (atomic64_t *)l;
61087@@ -115,6 +175,15 @@ static inline long atomic_long_inc_retur
61088 return (long)atomic64_inc_return(v);
61089 }
61090
61091+#ifdef CONFIG_PAX_REFCOUNT
61092+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
61093+{
61094+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61095+
61096+ return (long)atomic64_inc_return_unchecked(v);
61097+}
61098+#endif
61099+
61100 static inline long atomic_long_dec_return(atomic_long_t *l)
61101 {
61102 atomic64_t *v = (atomic64_t *)l;
61103@@ -140,6 +209,12 @@ static inline long atomic_long_add_unles
61104
61105 typedef atomic_t atomic_long_t;
61106
61107+#ifdef CONFIG_PAX_REFCOUNT
61108+typedef atomic_unchecked_t atomic_long_unchecked_t;
61109+#else
61110+typedef atomic_t atomic_long_unchecked_t;
61111+#endif
61112+
61113 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
61114 static inline long atomic_long_read(atomic_long_t *l)
61115 {
61116@@ -148,6 +223,15 @@ static inline long atomic_long_read(atom
61117 return (long)atomic_read(v);
61118 }
61119
61120+#ifdef CONFIG_PAX_REFCOUNT
61121+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
61122+{
61123+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61124+
61125+ return (long)atomic_read_unchecked(v);
61126+}
61127+#endif
61128+
61129 static inline void atomic_long_set(atomic_long_t *l, long i)
61130 {
61131 atomic_t *v = (atomic_t *)l;
61132@@ -155,6 +239,15 @@ static inline void atomic_long_set(atomi
61133 atomic_set(v, i);
61134 }
61135
61136+#ifdef CONFIG_PAX_REFCOUNT
61137+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
61138+{
61139+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61140+
61141+ atomic_set_unchecked(v, i);
61142+}
61143+#endif
61144+
61145 static inline void atomic_long_inc(atomic_long_t *l)
61146 {
61147 atomic_t *v = (atomic_t *)l;
61148@@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomi
61149 atomic_inc(v);
61150 }
61151
61152+#ifdef CONFIG_PAX_REFCOUNT
61153+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
61154+{
61155+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61156+
61157+ atomic_inc_unchecked(v);
61158+}
61159+#endif
61160+
61161 static inline void atomic_long_dec(atomic_long_t *l)
61162 {
61163 atomic_t *v = (atomic_t *)l;
61164@@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomi
61165 atomic_dec(v);
61166 }
61167
61168+#ifdef CONFIG_PAX_REFCOUNT
61169+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
61170+{
61171+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61172+
61173+ atomic_dec_unchecked(v);
61174+}
61175+#endif
61176+
61177 static inline void atomic_long_add(long i, atomic_long_t *l)
61178 {
61179 atomic_t *v = (atomic_t *)l;
61180@@ -176,6 +287,15 @@ static inline void atomic_long_add(long
61181 atomic_add(i, v);
61182 }
61183
61184+#ifdef CONFIG_PAX_REFCOUNT
61185+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
61186+{
61187+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61188+
61189+ atomic_add_unchecked(i, v);
61190+}
61191+#endif
61192+
61193 static inline void atomic_long_sub(long i, atomic_long_t *l)
61194 {
61195 atomic_t *v = (atomic_t *)l;
61196@@ -183,6 +303,15 @@ static inline void atomic_long_sub(long
61197 atomic_sub(i, v);
61198 }
61199
61200+#ifdef CONFIG_PAX_REFCOUNT
61201+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
61202+{
61203+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61204+
61205+ atomic_sub_unchecked(i, v);
61206+}
61207+#endif
61208+
61209 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
61210 {
61211 atomic_t *v = (atomic_t *)l;
61212@@ -232,6 +361,15 @@ static inline long atomic_long_inc_retur
61213 return (long)atomic_inc_return(v);
61214 }
61215
61216+#ifdef CONFIG_PAX_REFCOUNT
61217+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
61218+{
61219+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61220+
61221+ return (long)atomic_inc_return_unchecked(v);
61222+}
61223+#endif
61224+
61225 static inline long atomic_long_dec_return(atomic_long_t *l)
61226 {
61227 atomic_t *v = (atomic_t *)l;
61228@@ -255,4 +393,49 @@ static inline long atomic_long_add_unles
61229
61230 #endif /* BITS_PER_LONG == 64 */
61231
61232+#ifdef CONFIG_PAX_REFCOUNT
61233+static inline void pax_refcount_needs_these_functions(void)
61234+{
61235+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
61236+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
61237+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
61238+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
61239+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
61240+ atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
61241+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
61242+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
61243+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
61244+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
61245+ atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
61246+
61247+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
61248+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
61249+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
61250+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
61251+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
61252+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
61253+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
61254+}
61255+#else
61256+#define atomic_read_unchecked(v) atomic_read(v)
61257+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
61258+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
61259+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
61260+#define atomic_inc_unchecked(v) atomic_inc(v)
61261+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
61262+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
61263+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
61264+#define atomic_dec_unchecked(v) atomic_dec(v)
61265+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
61266+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
61267+
61268+#define atomic_long_read_unchecked(v) atomic_long_read(v)
61269+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
61270+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
61271+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
61272+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
61273+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
61274+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
61275+#endif
61276+
61277 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
61278diff -urNp linux-2.6.39.1/include/asm-generic/cache.h linux-2.6.39.1/include/asm-generic/cache.h
61279--- linux-2.6.39.1/include/asm-generic/cache.h 2011-05-19 00:06:34.000000000 -0400
61280+++ linux-2.6.39.1/include/asm-generic/cache.h 2011-05-22 19:36:32.000000000 -0400
61281@@ -6,7 +6,7 @@
61282 * cache lines need to provide their own cache.h.
61283 */
61284
61285-#define L1_CACHE_SHIFT 5
61286-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
61287+#define L1_CACHE_SHIFT 5U
61288+#define L1_CACHE_BYTES (1U << L1_CACHE_SHIFT)
61289
61290 #endif /* __ASM_GENERIC_CACHE_H */
61291diff -urNp linux-2.6.39.1/include/asm-generic/dma-mapping-common.h linux-2.6.39.1/include/asm-generic/dma-mapping-common.h
61292--- linux-2.6.39.1/include/asm-generic/dma-mapping-common.h 2011-05-19 00:06:34.000000000 -0400
61293+++ linux-2.6.39.1/include/asm-generic/dma-mapping-common.h 2011-05-22 19:36:32.000000000 -0400
61294@@ -11,7 +11,7 @@ static inline dma_addr_t dma_map_single_
61295 enum dma_data_direction dir,
61296 struct dma_attrs *attrs)
61297 {
61298- struct dma_map_ops *ops = get_dma_ops(dev);
61299+ const struct dma_map_ops *ops = get_dma_ops(dev);
61300 dma_addr_t addr;
61301
61302 kmemcheck_mark_initialized(ptr, size);
61303@@ -30,7 +30,7 @@ static inline void dma_unmap_single_attr
61304 enum dma_data_direction dir,
61305 struct dma_attrs *attrs)
61306 {
61307- struct dma_map_ops *ops = get_dma_ops(dev);
61308+ const struct dma_map_ops *ops = get_dma_ops(dev);
61309
61310 BUG_ON(!valid_dma_direction(dir));
61311 if (ops->unmap_page)
61312@@ -42,7 +42,7 @@ static inline int dma_map_sg_attrs(struc
61313 int nents, enum dma_data_direction dir,
61314 struct dma_attrs *attrs)
61315 {
61316- struct dma_map_ops *ops = get_dma_ops(dev);
61317+ const struct dma_map_ops *ops = get_dma_ops(dev);
61318 int i, ents;
61319 struct scatterlist *s;
61320
61321@@ -59,7 +59,7 @@ static inline void dma_unmap_sg_attrs(st
61322 int nents, enum dma_data_direction dir,
61323 struct dma_attrs *attrs)
61324 {
61325- struct dma_map_ops *ops = get_dma_ops(dev);
61326+ const struct dma_map_ops *ops = get_dma_ops(dev);
61327
61328 BUG_ON(!valid_dma_direction(dir));
61329 debug_dma_unmap_sg(dev, sg, nents, dir);
61330@@ -71,7 +71,7 @@ static inline dma_addr_t dma_map_page(st
61331 size_t offset, size_t size,
61332 enum dma_data_direction dir)
61333 {
61334- struct dma_map_ops *ops = get_dma_ops(dev);
61335+ const struct dma_map_ops *ops = get_dma_ops(dev);
61336 dma_addr_t addr;
61337
61338 kmemcheck_mark_initialized(page_address(page) + offset, size);
61339@@ -85,7 +85,7 @@ static inline dma_addr_t dma_map_page(st
61340 static inline void dma_unmap_page(struct device *dev, dma_addr_t addr,
61341 size_t size, enum dma_data_direction dir)
61342 {
61343- struct dma_map_ops *ops = get_dma_ops(dev);
61344+ const struct dma_map_ops *ops = get_dma_ops(dev);
61345
61346 BUG_ON(!valid_dma_direction(dir));
61347 if (ops->unmap_page)
61348@@ -97,7 +97,7 @@ static inline void dma_sync_single_for_c
61349 size_t size,
61350 enum dma_data_direction dir)
61351 {
61352- struct dma_map_ops *ops = get_dma_ops(dev);
61353+ const struct dma_map_ops *ops = get_dma_ops(dev);
61354
61355 BUG_ON(!valid_dma_direction(dir));
61356 if (ops->sync_single_for_cpu)
61357@@ -109,7 +109,7 @@ static inline void dma_sync_single_for_d
61358 dma_addr_t addr, size_t size,
61359 enum dma_data_direction dir)
61360 {
61361- struct dma_map_ops *ops = get_dma_ops(dev);
61362+ const struct dma_map_ops *ops = get_dma_ops(dev);
61363
61364 BUG_ON(!valid_dma_direction(dir));
61365 if (ops->sync_single_for_device)
61366@@ -139,7 +139,7 @@ static inline void
61367 dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
61368 int nelems, enum dma_data_direction dir)
61369 {
61370- struct dma_map_ops *ops = get_dma_ops(dev);
61371+ const struct dma_map_ops *ops = get_dma_ops(dev);
61372
61373 BUG_ON(!valid_dma_direction(dir));
61374 if (ops->sync_sg_for_cpu)
61375@@ -151,7 +151,7 @@ static inline void
61376 dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
61377 int nelems, enum dma_data_direction dir)
61378 {
61379- struct dma_map_ops *ops = get_dma_ops(dev);
61380+ const struct dma_map_ops *ops = get_dma_ops(dev);
61381
61382 BUG_ON(!valid_dma_direction(dir));
61383 if (ops->sync_sg_for_device)
61384diff -urNp linux-2.6.39.1/include/asm-generic/int-l64.h linux-2.6.39.1/include/asm-generic/int-l64.h
61385--- linux-2.6.39.1/include/asm-generic/int-l64.h 2011-05-19 00:06:34.000000000 -0400
61386+++ linux-2.6.39.1/include/asm-generic/int-l64.h 2011-05-22 19:36:32.000000000 -0400
61387@@ -46,6 +46,8 @@ typedef unsigned int u32;
61388 typedef signed long s64;
61389 typedef unsigned long u64;
61390
61391+typedef unsigned int intoverflow_t __attribute__ ((mode(TI)));
61392+
61393 #define S8_C(x) x
61394 #define U8_C(x) x ## U
61395 #define S16_C(x) x
61396diff -urNp linux-2.6.39.1/include/asm-generic/int-ll64.h linux-2.6.39.1/include/asm-generic/int-ll64.h
61397--- linux-2.6.39.1/include/asm-generic/int-ll64.h 2011-05-19 00:06:34.000000000 -0400
61398+++ linux-2.6.39.1/include/asm-generic/int-ll64.h 2011-05-22 19:36:32.000000000 -0400
61399@@ -51,6 +51,8 @@ typedef unsigned int u32;
61400 typedef signed long long s64;
61401 typedef unsigned long long u64;
61402
61403+typedef unsigned long long intoverflow_t;
61404+
61405 #define S8_C(x) x
61406 #define U8_C(x) x ## U
61407 #define S16_C(x) x
61408diff -urNp linux-2.6.39.1/include/asm-generic/kmap_types.h linux-2.6.39.1/include/asm-generic/kmap_types.h
61409--- linux-2.6.39.1/include/asm-generic/kmap_types.h 2011-05-19 00:06:34.000000000 -0400
61410+++ linux-2.6.39.1/include/asm-generic/kmap_types.h 2011-05-22 19:36:32.000000000 -0400
61411@@ -29,10 +29,11 @@ KMAP_D(16) KM_IRQ_PTE,
61412 KMAP_D(17) KM_NMI,
61413 KMAP_D(18) KM_NMI_PTE,
61414 KMAP_D(19) KM_KDB,
61415+KMAP_D(20) KM_CLEARPAGE,
61416 /*
61417 * Remember to update debug_kmap_atomic() when adding new kmap types!
61418 */
61419-KMAP_D(20) KM_TYPE_NR
61420+KMAP_D(21) KM_TYPE_NR
61421 };
61422
61423 #undef KMAP_D
61424diff -urNp linux-2.6.39.1/include/asm-generic/pgtable.h linux-2.6.39.1/include/asm-generic/pgtable.h
61425--- linux-2.6.39.1/include/asm-generic/pgtable.h 2011-05-19 00:06:34.000000000 -0400
61426+++ linux-2.6.39.1/include/asm-generic/pgtable.h 2011-05-22 19:36:32.000000000 -0400
61427@@ -447,6 +447,14 @@ static inline int pmd_write(pmd_t pmd)
61428 #endif /* __HAVE_ARCH_PMD_WRITE */
61429 #endif
61430
61431+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
61432+static inline unsigned long pax_open_kernel(void) { return 0; }
61433+#endif
61434+
61435+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
61436+static inline unsigned long pax_close_kernel(void) { return 0; }
61437+#endif
61438+
61439 #endif /* !__ASSEMBLY__ */
61440
61441 #endif /* _ASM_GENERIC_PGTABLE_H */
61442diff -urNp linux-2.6.39.1/include/asm-generic/pgtable-nopmd.h linux-2.6.39.1/include/asm-generic/pgtable-nopmd.h
61443--- linux-2.6.39.1/include/asm-generic/pgtable-nopmd.h 2011-05-19 00:06:34.000000000 -0400
61444+++ linux-2.6.39.1/include/asm-generic/pgtable-nopmd.h 2011-05-22 19:36:32.000000000 -0400
61445@@ -1,14 +1,19 @@
61446 #ifndef _PGTABLE_NOPMD_H
61447 #define _PGTABLE_NOPMD_H
61448
61449-#ifndef __ASSEMBLY__
61450-
61451 #include <asm-generic/pgtable-nopud.h>
61452
61453-struct mm_struct;
61454-
61455 #define __PAGETABLE_PMD_FOLDED
61456
61457+#define PMD_SHIFT PUD_SHIFT
61458+#define PTRS_PER_PMD 1
61459+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
61460+#define PMD_MASK (~(PMD_SIZE-1))
61461+
61462+#ifndef __ASSEMBLY__
61463+
61464+struct mm_struct;
61465+
61466 /*
61467 * Having the pmd type consist of a pud gets the size right, and allows
61468 * us to conceptually access the pud entry that this pmd is folded into
61469@@ -16,11 +21,6 @@ struct mm_struct;
61470 */
61471 typedef struct { pud_t pud; } pmd_t;
61472
61473-#define PMD_SHIFT PUD_SHIFT
61474-#define PTRS_PER_PMD 1
61475-#define PMD_SIZE (1UL << PMD_SHIFT)
61476-#define PMD_MASK (~(PMD_SIZE-1))
61477-
61478 /*
61479 * The "pud_xxx()" functions here are trivial for a folded two-level
61480 * setup: the pmd is never bad, and a pmd always exists (as it's folded
61481diff -urNp linux-2.6.39.1/include/asm-generic/pgtable-nopud.h linux-2.6.39.1/include/asm-generic/pgtable-nopud.h
61482--- linux-2.6.39.1/include/asm-generic/pgtable-nopud.h 2011-05-19 00:06:34.000000000 -0400
61483+++ linux-2.6.39.1/include/asm-generic/pgtable-nopud.h 2011-05-22 19:36:32.000000000 -0400
61484@@ -1,10 +1,15 @@
61485 #ifndef _PGTABLE_NOPUD_H
61486 #define _PGTABLE_NOPUD_H
61487
61488-#ifndef __ASSEMBLY__
61489-
61490 #define __PAGETABLE_PUD_FOLDED
61491
61492+#define PUD_SHIFT PGDIR_SHIFT
61493+#define PTRS_PER_PUD 1
61494+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
61495+#define PUD_MASK (~(PUD_SIZE-1))
61496+
61497+#ifndef __ASSEMBLY__
61498+
61499 /*
61500 * Having the pud type consist of a pgd gets the size right, and allows
61501 * us to conceptually access the pgd entry that this pud is folded into
61502@@ -12,11 +17,6 @@
61503 */
61504 typedef struct { pgd_t pgd; } pud_t;
61505
61506-#define PUD_SHIFT PGDIR_SHIFT
61507-#define PTRS_PER_PUD 1
61508-#define PUD_SIZE (1UL << PUD_SHIFT)
61509-#define PUD_MASK (~(PUD_SIZE-1))
61510-
61511 /*
61512 * The "pgd_xxx()" functions here are trivial for a folded two-level
61513 * setup: the pud is never bad, and a pud always exists (as it's folded
61514diff -urNp linux-2.6.39.1/include/asm-generic/vmlinux.lds.h linux-2.6.39.1/include/asm-generic/vmlinux.lds.h
61515--- linux-2.6.39.1/include/asm-generic/vmlinux.lds.h 2011-05-19 00:06:34.000000000 -0400
61516+++ linux-2.6.39.1/include/asm-generic/vmlinux.lds.h 2011-05-22 19:36:32.000000000 -0400
61517@@ -213,6 +213,7 @@
61518 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
61519 VMLINUX_SYMBOL(__start_rodata) = .; \
61520 *(.rodata) *(.rodata.*) \
61521+ *(.data..read_only) \
61522 *(__vermagic) /* Kernel version magic */ \
61523 . = ALIGN(8); \
61524 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
61525@@ -707,14 +708,15 @@
61526 * section in the linker script will go there too. @phdr should have
61527 * a leading colon.
61528 *
61529- * Note that this macros defines __per_cpu_load as an absolute symbol.
61530+ * Note that this macros defines per_cpu_load as an absolute symbol.
61531 * If there is no need to put the percpu section at a predetermined
61532 * address, use PERCPU().
61533 */
61534 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
61535- VMLINUX_SYMBOL(__per_cpu_load) = .; \
61536- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
61537+ per_cpu_load = .; \
61538+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
61539 - LOAD_OFFSET) { \
61540+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
61541 VMLINUX_SYMBOL(__per_cpu_start) = .; \
61542 *(.data..percpu..first) \
61543 . = ALIGN(PAGE_SIZE); \
61544@@ -726,7 +728,7 @@
61545 *(.data..percpu..shared_aligned) \
61546 VMLINUX_SYMBOL(__per_cpu_end) = .; \
61547 } phdr \
61548- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
61549+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
61550
61551 /**
61552 * PERCPU - define output section for percpu area, simple version
61553diff -urNp linux-2.6.39.1/include/drm/drmP.h linux-2.6.39.1/include/drm/drmP.h
61554--- linux-2.6.39.1/include/drm/drmP.h 2011-05-19 00:06:34.000000000 -0400
61555+++ linux-2.6.39.1/include/drm/drmP.h 2011-05-22 19:41:42.000000000 -0400
61556@@ -73,6 +73,7 @@
61557 #include <linux/workqueue.h>
61558 #include <linux/poll.h>
61559 #include <asm/pgalloc.h>
61560+#include <asm/local.h>
61561 #include "drm.h"
61562
61563 #include <linux/idr.h>
61564@@ -908,7 +909,7 @@ struct drm_driver {
61565 uint32_t handle);
61566
61567 /* Driver private ops for this object */
61568- struct vm_operations_struct *gem_vm_ops;
61569+ const struct vm_operations_struct *gem_vm_ops;
61570
61571 int major;
61572 int minor;
61573@@ -1023,7 +1024,7 @@ struct drm_device {
61574
61575 /** \name Usage Counters */
61576 /*@{ */
61577- int open_count; /**< Outstanding files open */
61578+ local_t open_count; /**< Outstanding files open */
61579 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
61580 atomic_t vma_count; /**< Outstanding vma areas open */
61581 int buf_use; /**< Buffers in use -- cannot alloc */
61582@@ -1034,7 +1035,7 @@ struct drm_device {
61583 /*@{ */
61584 unsigned long counters;
61585 enum drm_stat_type types[15];
61586- atomic_t counts[15];
61587+ atomic_unchecked_t counts[15];
61588 /*@} */
61589
61590 struct list_head filelist;
61591diff -urNp linux-2.6.39.1/include/linux/a.out.h linux-2.6.39.1/include/linux/a.out.h
61592--- linux-2.6.39.1/include/linux/a.out.h 2011-05-19 00:06:34.000000000 -0400
61593+++ linux-2.6.39.1/include/linux/a.out.h 2011-05-22 19:36:32.000000000 -0400
61594@@ -39,6 +39,14 @@ enum machine_type {
61595 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
61596 };
61597
61598+/* Constants for the N_FLAGS field */
61599+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
61600+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
61601+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
61602+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
61603+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
61604+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
61605+
61606 #if !defined (N_MAGIC)
61607 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
61608 #endif
61609diff -urNp linux-2.6.39.1/include/linux/atmdev.h linux-2.6.39.1/include/linux/atmdev.h
61610--- linux-2.6.39.1/include/linux/atmdev.h 2011-05-19 00:06:34.000000000 -0400
61611+++ linux-2.6.39.1/include/linux/atmdev.h 2011-05-22 19:36:32.000000000 -0400
61612@@ -237,7 +237,7 @@ struct compat_atm_iobuf {
61613 #endif
61614
61615 struct k_atm_aal_stats {
61616-#define __HANDLE_ITEM(i) atomic_t i
61617+#define __HANDLE_ITEM(i) atomic_unchecked_t i
61618 __AAL_STAT_ITEMS
61619 #undef __HANDLE_ITEM
61620 };
61621diff -urNp linux-2.6.39.1/include/linux/binfmts.h linux-2.6.39.1/include/linux/binfmts.h
61622--- linux-2.6.39.1/include/linux/binfmts.h 2011-05-19 00:06:34.000000000 -0400
61623+++ linux-2.6.39.1/include/linux/binfmts.h 2011-05-22 19:36:32.000000000 -0400
61624@@ -92,6 +92,7 @@ struct linux_binfmt {
61625 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
61626 int (*load_shlib)(struct file *);
61627 int (*core_dump)(struct coredump_params *cprm);
61628+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
61629 unsigned long min_coredump; /* minimal dump size */
61630 };
61631
61632diff -urNp linux-2.6.39.1/include/linux/blkdev.h linux-2.6.39.1/include/linux/blkdev.h
61633--- linux-2.6.39.1/include/linux/blkdev.h 2011-06-03 00:04:14.000000000 -0400
61634+++ linux-2.6.39.1/include/linux/blkdev.h 2011-06-03 00:32:08.000000000 -0400
61635@@ -1292,22 +1292,22 @@ queue_max_integrity_segments(struct requ
61636 #endif /* CONFIG_BLK_DEV_INTEGRITY */
61637
61638 struct block_device_operations {
61639- int (*open) (struct block_device *, fmode_t);
61640- int (*release) (struct gendisk *, fmode_t);
61641- int (*ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
61642- int (*compat_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
61643- int (*direct_access) (struct block_device *, sector_t,
61644+ int (* const open) (struct block_device *, fmode_t);
61645+ int (* const release) (struct gendisk *, fmode_t);
61646+ int (* const ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
61647+ int (* const compat_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
61648+ int (* const direct_access) (struct block_device *, sector_t,
61649 void **, unsigned long *);
61650- unsigned int (*check_events) (struct gendisk *disk,
61651+ unsigned int (* const check_events) (struct gendisk *disk,
61652 unsigned int clearing);
61653 /* ->media_changed() is DEPRECATED, use ->check_events() instead */
61654- int (*media_changed) (struct gendisk *);
61655- void (*unlock_native_capacity) (struct gendisk *);
61656- int (*revalidate_disk) (struct gendisk *);
61657- int (*getgeo)(struct block_device *, struct hd_geometry *);
61658+ int (* const media_changed) (struct gendisk *);
61659+ void (* const unlock_native_capacity) (struct gendisk *);
61660+ int (* const revalidate_disk) (struct gendisk *);
61661+ int (* const getgeo)(struct block_device *, struct hd_geometry *);
61662 /* this callback is with swap_lock and sometimes page table lock held */
61663- void (*swap_slot_free_notify) (struct block_device *, unsigned long);
61664- struct module *owner;
61665+ void (* const swap_slot_free_notify) (struct block_device *, unsigned long);
61666+ struct module * const owner;
61667 };
61668
61669 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
61670diff -urNp linux-2.6.39.1/include/linux/blktrace_api.h linux-2.6.39.1/include/linux/blktrace_api.h
61671--- linux-2.6.39.1/include/linux/blktrace_api.h 2011-05-19 00:06:34.000000000 -0400
61672+++ linux-2.6.39.1/include/linux/blktrace_api.h 2011-05-22 19:36:32.000000000 -0400
61673@@ -161,7 +161,7 @@ struct blk_trace {
61674 struct dentry *dir;
61675 struct dentry *dropped_file;
61676 struct dentry *msg_file;
61677- atomic_t dropped;
61678+ atomic_unchecked_t dropped;
61679 };
61680
61681 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
61682diff -urNp linux-2.6.39.1/include/linux/byteorder/little_endian.h linux-2.6.39.1/include/linux/byteorder/little_endian.h
61683--- linux-2.6.39.1/include/linux/byteorder/little_endian.h 2011-05-19 00:06:34.000000000 -0400
61684+++ linux-2.6.39.1/include/linux/byteorder/little_endian.h 2011-05-22 19:36:32.000000000 -0400
61685@@ -42,51 +42,51 @@
61686
61687 static inline __le64 __cpu_to_le64p(const __u64 *p)
61688 {
61689- return (__force __le64)*p;
61690+ return (__force const __le64)*p;
61691 }
61692 static inline __u64 __le64_to_cpup(const __le64 *p)
61693 {
61694- return (__force __u64)*p;
61695+ return (__force const __u64)*p;
61696 }
61697 static inline __le32 __cpu_to_le32p(const __u32 *p)
61698 {
61699- return (__force __le32)*p;
61700+ return (__force const __le32)*p;
61701 }
61702 static inline __u32 __le32_to_cpup(const __le32 *p)
61703 {
61704- return (__force __u32)*p;
61705+ return (__force const __u32)*p;
61706 }
61707 static inline __le16 __cpu_to_le16p(const __u16 *p)
61708 {
61709- return (__force __le16)*p;
61710+ return (__force const __le16)*p;
61711 }
61712 static inline __u16 __le16_to_cpup(const __le16 *p)
61713 {
61714- return (__force __u16)*p;
61715+ return (__force const __u16)*p;
61716 }
61717 static inline __be64 __cpu_to_be64p(const __u64 *p)
61718 {
61719- return (__force __be64)__swab64p(p);
61720+ return (__force const __be64)__swab64p(p);
61721 }
61722 static inline __u64 __be64_to_cpup(const __be64 *p)
61723 {
61724- return __swab64p((__u64 *)p);
61725+ return __swab64p((const __u64 *)p);
61726 }
61727 static inline __be32 __cpu_to_be32p(const __u32 *p)
61728 {
61729- return (__force __be32)__swab32p(p);
61730+ return (__force const __be32)__swab32p(p);
61731 }
61732 static inline __u32 __be32_to_cpup(const __be32 *p)
61733 {
61734- return __swab32p((__u32 *)p);
61735+ return __swab32p((const __u32 *)p);
61736 }
61737 static inline __be16 __cpu_to_be16p(const __u16 *p)
61738 {
61739- return (__force __be16)__swab16p(p);
61740+ return (__force const __be16)__swab16p(p);
61741 }
61742 static inline __u16 __be16_to_cpup(const __be16 *p)
61743 {
61744- return __swab16p((__u16 *)p);
61745+ return __swab16p((const __u16 *)p);
61746 }
61747 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
61748 #define __le64_to_cpus(x) do { (void)(x); } while (0)
61749diff -urNp linux-2.6.39.1/include/linux/cache.h linux-2.6.39.1/include/linux/cache.h
61750--- linux-2.6.39.1/include/linux/cache.h 2011-05-19 00:06:34.000000000 -0400
61751+++ linux-2.6.39.1/include/linux/cache.h 2011-05-22 19:36:32.000000000 -0400
61752@@ -16,6 +16,10 @@
61753 #define __read_mostly
61754 #endif
61755
61756+#ifndef __read_only
61757+#define __read_only __read_mostly
61758+#endif
61759+
61760 #ifndef ____cacheline_aligned
61761 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
61762 #endif
61763diff -urNp linux-2.6.39.1/include/linux/capability.h linux-2.6.39.1/include/linux/capability.h
61764--- linux-2.6.39.1/include/linux/capability.h 2011-05-19 00:06:34.000000000 -0400
61765+++ linux-2.6.39.1/include/linux/capability.h 2011-05-22 21:02:47.000000000 -0400
61766@@ -547,6 +547,9 @@ extern bool capable(int cap);
61767 extern bool ns_capable(struct user_namespace *ns, int cap);
61768 extern bool task_ns_capable(struct task_struct *t, int cap);
61769 extern bool nsown_capable(int cap);
61770+extern bool task_ns_capable_nolog(struct task_struct *t, int cap);
61771+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
61772+extern bool capable_nolog(int cap);
61773
61774 /* audit system wants to get cap info from files as well */
61775 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
61776diff -urNp linux-2.6.39.1/include/linux/compiler-gcc4.h linux-2.6.39.1/include/linux/compiler-gcc4.h
61777--- linux-2.6.39.1/include/linux/compiler-gcc4.h 2011-05-19 00:06:34.000000000 -0400
61778+++ linux-2.6.39.1/include/linux/compiler-gcc4.h 2011-05-22 19:36:32.000000000 -0400
61779@@ -46,6 +46,11 @@
61780 #define __noclone __attribute__((__noclone__))
61781
61782 #endif
61783+
61784+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
61785+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
61786+#define __bos0(ptr) __bos((ptr), 0)
61787+#define __bos1(ptr) __bos((ptr), 1)
61788 #endif
61789
61790 #if __GNUC_MINOR__ > 0
61791diff -urNp linux-2.6.39.1/include/linux/compiler.h linux-2.6.39.1/include/linux/compiler.h
61792--- linux-2.6.39.1/include/linux/compiler.h 2011-05-19 00:06:34.000000000 -0400
61793+++ linux-2.6.39.1/include/linux/compiler.h 2011-05-22 19:36:32.000000000 -0400
61794@@ -273,6 +273,22 @@ void ftrace_likely_update(struct ftrace_
61795 #define __cold
61796 #endif
61797
61798+#ifndef __alloc_size
61799+#define __alloc_size
61800+#endif
61801+
61802+#ifndef __bos
61803+#define __bos
61804+#endif
61805+
61806+#ifndef __bos0
61807+#define __bos0
61808+#endif
61809+
61810+#ifndef __bos1
61811+#define __bos1
61812+#endif
61813+
61814 /* Simple shorthand for a section definition */
61815 #ifndef __section
61816 # define __section(S) __attribute__ ((__section__(#S)))
61817@@ -306,6 +322,7 @@ void ftrace_likely_update(struct ftrace_
61818 * use is to mediate communication between process-level code and irq/NMI
61819 * handlers, all running on the same CPU.
61820 */
61821-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
61822+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
61823+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
61824
61825 #endif /* __LINUX_COMPILER_H */
61826diff -urNp linux-2.6.39.1/include/linux/concap.h linux-2.6.39.1/include/linux/concap.h
61827--- linux-2.6.39.1/include/linux/concap.h 2011-05-19 00:06:34.000000000 -0400
61828+++ linux-2.6.39.1/include/linux/concap.h 2011-05-22 19:36:32.000000000 -0400
61829@@ -30,7 +30,7 @@ struct concap_device_ops;
61830 struct concap_proto{
61831 struct net_device *net_dev; /* net device using our service */
61832 struct concap_device_ops *dops; /* callbacks provided by device */
61833- struct concap_proto_ops *pops; /* callbacks provided by us */
61834+ const struct concap_proto_ops *pops; /* callbacks provided by us */
61835 spinlock_t lock;
61836 int flags;
61837 void *proto_data; /* protocol specific private data, to
61838diff -urNp linux-2.6.39.1/include/linux/configfs.h linux-2.6.39.1/include/linux/configfs.h
61839--- linux-2.6.39.1/include/linux/configfs.h 2011-05-19 00:06:34.000000000 -0400
61840+++ linux-2.6.39.1/include/linux/configfs.h 2011-05-22 19:36:32.000000000 -0400
61841@@ -82,7 +82,7 @@ extern void config_item_put(struct confi
61842 struct config_item_type {
61843 struct module *ct_owner;
61844 struct configfs_item_operations *ct_item_ops;
61845- struct configfs_group_operations *ct_group_ops;
61846+ const struct configfs_group_operations *ct_group_ops;
61847 struct configfs_attribute **ct_attrs;
61848 };
61849
61850diff -urNp linux-2.6.39.1/include/linux/cpuset.h linux-2.6.39.1/include/linux/cpuset.h
61851--- linux-2.6.39.1/include/linux/cpuset.h 2011-05-19 00:06:34.000000000 -0400
61852+++ linux-2.6.39.1/include/linux/cpuset.h 2011-05-22 19:36:32.000000000 -0400
61853@@ -118,7 +118,7 @@ static inline void put_mems_allowed(void
61854 * nodemask.
61855 */
61856 smp_mb();
61857- --ACCESS_ONCE(current->mems_allowed_change_disable);
61858+ --ACCESS_ONCE_RW(current->mems_allowed_change_disable);
61859 }
61860
61861 static inline void set_mems_allowed(nodemask_t nodemask)
61862diff -urNp linux-2.6.39.1/include/linux/dca.h linux-2.6.39.1/include/linux/dca.h
61863--- linux-2.6.39.1/include/linux/dca.h 2011-05-19 00:06:34.000000000 -0400
61864+++ linux-2.6.39.1/include/linux/dca.h 2011-05-22 19:36:32.000000000 -0400
61865@@ -34,7 +34,7 @@ void dca_unregister_notify(struct notifi
61866
61867 struct dca_provider {
61868 struct list_head node;
61869- struct dca_ops *ops;
61870+ const struct dca_ops *ops;
61871 struct device *cd;
61872 int id;
61873 };
61874@@ -53,7 +53,7 @@ struct dca_ops {
61875 int (*dev_managed) (struct dca_provider *, struct device *);
61876 };
61877
61878-struct dca_provider *alloc_dca_provider(struct dca_ops *ops, int priv_size);
61879+struct dca_provider *alloc_dca_provider(const struct dca_ops *ops, int priv_size);
61880 void free_dca_provider(struct dca_provider *dca);
61881 int register_dca_provider(struct dca_provider *dca, struct device *dev);
61882 void unregister_dca_provider(struct dca_provider *dca, struct device *dev);
61883diff -urNp linux-2.6.39.1/include/linux/decompress/mm.h linux-2.6.39.1/include/linux/decompress/mm.h
61884--- linux-2.6.39.1/include/linux/decompress/mm.h 2011-05-19 00:06:34.000000000 -0400
61885+++ linux-2.6.39.1/include/linux/decompress/mm.h 2011-05-22 19:36:33.000000000 -0400
61886@@ -77,7 +77,7 @@ static void free(void *where)
61887 * warnings when not needed (indeed large_malloc / large_free are not
61888 * needed by inflate */
61889
61890-#define malloc(a) kmalloc(a, GFP_KERNEL)
61891+#define malloc(a) kmalloc((a), GFP_KERNEL)
61892 #define free(a) kfree(a)
61893
61894 #define large_malloc(a) vmalloc(a)
61895diff -urNp linux-2.6.39.1/include/linux/dma-mapping.h linux-2.6.39.1/include/linux/dma-mapping.h
61896--- linux-2.6.39.1/include/linux/dma-mapping.h 2011-05-19 00:06:34.000000000 -0400
61897+++ linux-2.6.39.1/include/linux/dma-mapping.h 2011-05-22 19:36:33.000000000 -0400
61898@@ -16,40 +16,40 @@ enum dma_data_direction {
61899 };
61900
61901 struct dma_map_ops {
61902- void* (*alloc_coherent)(struct device *dev, size_t size,
61903+ void* (* const alloc_coherent)(struct device *dev, size_t size,
61904 dma_addr_t *dma_handle, gfp_t gfp);
61905- void (*free_coherent)(struct device *dev, size_t size,
61906+ void (* const free_coherent)(struct device *dev, size_t size,
61907 void *vaddr, dma_addr_t dma_handle);
61908- dma_addr_t (*map_page)(struct device *dev, struct page *page,
61909+ dma_addr_t (* const map_page)(struct device *dev, struct page *page,
61910 unsigned long offset, size_t size,
61911 enum dma_data_direction dir,
61912 struct dma_attrs *attrs);
61913- void (*unmap_page)(struct device *dev, dma_addr_t dma_handle,
61914+ void (* const unmap_page)(struct device *dev, dma_addr_t dma_handle,
61915 size_t size, enum dma_data_direction dir,
61916 struct dma_attrs *attrs);
61917- int (*map_sg)(struct device *dev, struct scatterlist *sg,
61918+ int (* const map_sg)(struct device *dev, struct scatterlist *sg,
61919 int nents, enum dma_data_direction dir,
61920 struct dma_attrs *attrs);
61921- void (*unmap_sg)(struct device *dev,
61922+ void (* const unmap_sg)(struct device *dev,
61923 struct scatterlist *sg, int nents,
61924 enum dma_data_direction dir,
61925 struct dma_attrs *attrs);
61926- void (*sync_single_for_cpu)(struct device *dev,
61927+ void (* const sync_single_for_cpu)(struct device *dev,
61928 dma_addr_t dma_handle, size_t size,
61929 enum dma_data_direction dir);
61930- void (*sync_single_for_device)(struct device *dev,
61931+ void (* const sync_single_for_device)(struct device *dev,
61932 dma_addr_t dma_handle, size_t size,
61933 enum dma_data_direction dir);
61934- void (*sync_sg_for_cpu)(struct device *dev,
61935+ void (* const sync_sg_for_cpu)(struct device *dev,
61936 struct scatterlist *sg, int nents,
61937 enum dma_data_direction dir);
61938- void (*sync_sg_for_device)(struct device *dev,
61939+ void (* const sync_sg_for_device)(struct device *dev,
61940 struct scatterlist *sg, int nents,
61941 enum dma_data_direction dir);
61942- int (*mapping_error)(struct device *dev, dma_addr_t dma_addr);
61943- int (*dma_supported)(struct device *dev, u64 mask);
61944- int (*set_dma_mask)(struct device *dev, u64 mask);
61945- int is_phys;
61946+ int (* const mapping_error)(struct device *dev, dma_addr_t dma_addr);
61947+ int (* const dma_supported)(struct device *dev, u64 mask);
61948+ int (* set_dma_mask)(struct device *dev, u64 mask);
61949+ const int is_phys;
61950 };
61951
61952 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
61953diff -urNp linux-2.6.39.1/include/linux/elf.h linux-2.6.39.1/include/linux/elf.h
61954--- linux-2.6.39.1/include/linux/elf.h 2011-05-19 00:06:34.000000000 -0400
61955+++ linux-2.6.39.1/include/linux/elf.h 2011-05-22 19:36:33.000000000 -0400
61956@@ -49,6 +49,17 @@ typedef __s64 Elf64_Sxword;
61957 #define PT_GNU_EH_FRAME 0x6474e550
61958
61959 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
61960+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
61961+
61962+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
61963+
61964+/* Constants for the e_flags field */
61965+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
61966+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
61967+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
61968+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
61969+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
61970+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
61971
61972 /*
61973 * Extended Numbering
61974@@ -106,6 +117,8 @@ typedef __s64 Elf64_Sxword;
61975 #define DT_DEBUG 21
61976 #define DT_TEXTREL 22
61977 #define DT_JMPREL 23
61978+#define DT_FLAGS 30
61979+ #define DF_TEXTREL 0x00000004
61980 #define DT_ENCODING 32
61981 #define OLD_DT_LOOS 0x60000000
61982 #define DT_LOOS 0x6000000d
61983@@ -252,6 +265,19 @@ typedef struct elf64_hdr {
61984 #define PF_W 0x2
61985 #define PF_X 0x1
61986
61987+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
61988+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
61989+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
61990+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
61991+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
61992+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
61993+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
61994+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
61995+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
61996+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
61997+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
61998+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
61999+
62000 typedef struct elf32_phdr{
62001 Elf32_Word p_type;
62002 Elf32_Off p_offset;
62003@@ -344,6 +370,8 @@ typedef struct elf64_shdr {
62004 #define EI_OSABI 7
62005 #define EI_PAD 8
62006
62007+#define EI_PAX 14
62008+
62009 #define ELFMAG0 0x7f /* EI_MAG */
62010 #define ELFMAG1 'E'
62011 #define ELFMAG2 'L'
62012@@ -421,6 +449,7 @@ extern Elf32_Dyn _DYNAMIC [];
62013 #define elf_note elf32_note
62014 #define elf_addr_t Elf32_Off
62015 #define Elf_Half Elf32_Half
62016+#define elf_dyn Elf32_Dyn
62017
62018 #else
62019
62020@@ -431,6 +460,7 @@ extern Elf64_Dyn _DYNAMIC [];
62021 #define elf_note elf64_note
62022 #define elf_addr_t Elf64_Off
62023 #define Elf_Half Elf64_Half
62024+#define elf_dyn Elf64_Dyn
62025
62026 #endif
62027
62028diff -urNp linux-2.6.39.1/include/linux/enclosure.h linux-2.6.39.1/include/linux/enclosure.h
62029--- linux-2.6.39.1/include/linux/enclosure.h 2011-05-19 00:06:34.000000000 -0400
62030+++ linux-2.6.39.1/include/linux/enclosure.h 2011-05-22 19:36:33.000000000 -0400
62031@@ -98,7 +98,7 @@ struct enclosure_device {
62032 void *scratch;
62033 struct list_head node;
62034 struct device edev;
62035- struct enclosure_component_callbacks *cb;
62036+ const struct enclosure_component_callbacks *cb;
62037 int components;
62038 struct enclosure_component component[0];
62039 };
62040diff -urNp linux-2.6.39.1/include/linux/fscache-cache.h linux-2.6.39.1/include/linux/fscache-cache.h
62041--- linux-2.6.39.1/include/linux/fscache-cache.h 2011-05-19 00:06:34.000000000 -0400
62042+++ linux-2.6.39.1/include/linux/fscache-cache.h 2011-05-22 19:36:33.000000000 -0400
62043@@ -113,7 +113,7 @@ struct fscache_operation {
62044 #endif
62045 };
62046
62047-extern atomic_t fscache_op_debug_id;
62048+extern atomic_unchecked_t fscache_op_debug_id;
62049 extern void fscache_op_work_func(struct work_struct *work);
62050
62051 extern void fscache_enqueue_operation(struct fscache_operation *);
62052@@ -133,7 +133,7 @@ static inline void fscache_operation_ini
62053 {
62054 INIT_WORK(&op->work, fscache_op_work_func);
62055 atomic_set(&op->usage, 1);
62056- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
62057+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
62058 op->processor = processor;
62059 op->release = release;
62060 INIT_LIST_HEAD(&op->pend_link);
62061diff -urNp linux-2.6.39.1/include/linux/fs.h linux-2.6.39.1/include/linux/fs.h
62062--- linux-2.6.39.1/include/linux/fs.h 2011-05-19 00:06:34.000000000 -0400
62063+++ linux-2.6.39.1/include/linux/fs.h 2011-05-22 19:41:42.000000000 -0400
62064@@ -108,6 +108,11 @@ struct inodes_stat_t {
62065 /* File was opened by fanotify and shouldn't generate fanotify events */
62066 #define FMODE_NONOTIFY ((__force fmode_t)0x1000000)
62067
62068+/* Hack for grsec so as not to require read permission simply to execute
62069+ * a binary
62070+ */
62071+#define FMODE_GREXEC ((__force fmode_t)0x2000000)
62072+
62073 /*
62074 * The below are the various read and write types that we support. Some of
62075 * them include behavioral modifiers that send information down to the
62076@@ -575,41 +580,41 @@ typedef int (*read_actor_t)(read_descrip
62077 unsigned long, unsigned long);
62078
62079 struct address_space_operations {
62080- int (*writepage)(struct page *page, struct writeback_control *wbc);
62081- int (*readpage)(struct file *, struct page *);
62082+ int (* const writepage)(struct page *page, struct writeback_control *wbc);
62083+ int (* const readpage)(struct file *, struct page *);
62084
62085 /* Write back some dirty pages from this mapping. */
62086- int (*writepages)(struct address_space *, struct writeback_control *);
62087+ int (* const writepages)(struct address_space *, struct writeback_control *);
62088
62089 /* Set a page dirty. Return true if this dirtied it */
62090- int (*set_page_dirty)(struct page *page);
62091+ int (* const set_page_dirty)(struct page *page);
62092
62093- int (*readpages)(struct file *filp, struct address_space *mapping,
62094+ int (* const readpages)(struct file *filp, struct address_space *mapping,
62095 struct list_head *pages, unsigned nr_pages);
62096
62097- int (*write_begin)(struct file *, struct address_space *mapping,
62098+ int (* const write_begin)(struct file *, struct address_space *mapping,
62099 loff_t pos, unsigned len, unsigned flags,
62100 struct page **pagep, void **fsdata);
62101- int (*write_end)(struct file *, struct address_space *mapping,
62102+ int (* const write_end)(struct file *, struct address_space *mapping,
62103 loff_t pos, unsigned len, unsigned copied,
62104 struct page *page, void *fsdata);
62105
62106 /* Unfortunately this kludge is needed for FIBMAP. Don't use it */
62107- sector_t (*bmap)(struct address_space *, sector_t);
62108- void (*invalidatepage) (struct page *, unsigned long);
62109- int (*releasepage) (struct page *, gfp_t);
62110- void (*freepage)(struct page *);
62111- ssize_t (*direct_IO)(int, struct kiocb *, const struct iovec *iov,
62112+ sector_t (* const bmap)(struct address_space *, sector_t);
62113+ void (* const invalidatepage) (struct page *, unsigned long);
62114+ int (* const releasepage) (struct page *, gfp_t);
62115+ void (* const freepage)(struct page *);
62116+ ssize_t (* const direct_IO)(int, struct kiocb *, const struct iovec *iov,
62117 loff_t offset, unsigned long nr_segs);
62118- int (*get_xip_mem)(struct address_space *, pgoff_t, int,
62119+ int (* const get_xip_mem)(struct address_space *, pgoff_t, int,
62120 void **, unsigned long *);
62121 /* migrate the contents of a page to the specified target */
62122- int (*migratepage) (struct address_space *,
62123+ int (* const migratepage) (struct address_space *,
62124 struct page *, struct page *);
62125- int (*launder_page) (struct page *);
62126- int (*is_partially_uptodate) (struct page *, read_descriptor_t *,
62127+ int (* const launder_page) (struct page *);
62128+ int (* const is_partially_uptodate) (struct page *, read_descriptor_t *,
62129 unsigned long);
62130- int (*error_remove_page)(struct address_space *, struct page *);
62131+ int (* const error_remove_page)(struct address_space *, struct page *);
62132 };
62133
62134 extern const struct address_space_operations empty_aops;
62135@@ -1060,17 +1065,17 @@ static inline int file_check_writeable(s
62136 typedef struct files_struct *fl_owner_t;
62137
62138 struct file_lock_operations {
62139- void (*fl_copy_lock)(struct file_lock *, struct file_lock *);
62140- void (*fl_release_private)(struct file_lock *);
62141+ void (* const fl_copy_lock)(struct file_lock *, struct file_lock *);
62142+ void (* const fl_release_private)(struct file_lock *);
62143 };
62144
62145 struct lock_manager_operations {
62146- int (*fl_compare_owner)(struct file_lock *, struct file_lock *);
62147- void (*fl_notify)(struct file_lock *); /* unblock callback */
62148- int (*fl_grant)(struct file_lock *, struct file_lock *, int);
62149- void (*fl_release_private)(struct file_lock *);
62150- void (*fl_break)(struct file_lock *);
62151- int (*fl_change)(struct file_lock **, int);
62152+ int (* const fl_compare_owner)(struct file_lock *, struct file_lock *);
62153+ void (* const fl_notify)(struct file_lock *); /* unblock callback */
62154+ int (* const fl_grant)(struct file_lock *, struct file_lock *, int);
62155+ void (* const fl_release_private)(struct file_lock *);
62156+ void (* const fl_break)(struct file_lock *);
62157+ int (* const fl_change)(struct file_lock **, int);
62158 };
62159
62160 struct lock_manager {
62161@@ -1611,31 +1616,31 @@ extern ssize_t vfs_writev(struct file *,
62162 unsigned long, loff_t *);
62163
62164 struct super_operations {
62165- struct inode *(*alloc_inode)(struct super_block *sb);
62166- void (*destroy_inode)(struct inode *);
62167+ struct inode *(* const alloc_inode)(struct super_block *sb);
62168+ void (* const destroy_inode)(struct inode *);
62169
62170- void (*dirty_inode) (struct inode *);
62171- int (*write_inode) (struct inode *, struct writeback_control *wbc);
62172- int (*drop_inode) (struct inode *);
62173- void (*evict_inode) (struct inode *);
62174- void (*put_super) (struct super_block *);
62175- void (*write_super) (struct super_block *);
62176- int (*sync_fs)(struct super_block *sb, int wait);
62177- int (*freeze_fs) (struct super_block *);
62178- int (*unfreeze_fs) (struct super_block *);
62179- int (*statfs) (struct dentry *, struct kstatfs *);
62180- int (*remount_fs) (struct super_block *, int *, char *);
62181- void (*umount_begin) (struct super_block *);
62182-
62183- int (*show_options)(struct seq_file *, struct vfsmount *);
62184- int (*show_devname)(struct seq_file *, struct vfsmount *);
62185- int (*show_path)(struct seq_file *, struct vfsmount *);
62186- int (*show_stats)(struct seq_file *, struct vfsmount *);
62187+ void (* const dirty_inode) (struct inode *);
62188+ int (* const write_inode) (struct inode *, struct writeback_control *wbc);
62189+ int (* const drop_inode) (struct inode *);
62190+ void (* const evict_inode) (struct inode *);
62191+ void (* const put_super) (struct super_block *);
62192+ void (* const write_super) (struct super_block *);
62193+ int (* const sync_fs)(struct super_block *sb, int wait);
62194+ int (* const freeze_fs) (struct super_block *);
62195+ int (* const unfreeze_fs) (struct super_block *);
62196+ int (* const statfs) (struct dentry *, struct kstatfs *);
62197+ int (* const remount_fs) (struct super_block *, int *, char *);
62198+ void (* const umount_begin) (struct super_block *);
62199+
62200+ int (* const show_options)(struct seq_file *, struct vfsmount *);
62201+ int (* const show_devname)(struct seq_file *, struct vfsmount *);
62202+ int (* const show_path)(struct seq_file *, struct vfsmount *);
62203+ int (* const show_stats)(struct seq_file *, struct vfsmount *);
62204 #ifdef CONFIG_QUOTA
62205- ssize_t (*quota_read)(struct super_block *, int, char *, size_t, loff_t);
62206- ssize_t (*quota_write)(struct super_block *, int, const char *, size_t, loff_t);
62207+ ssize_t (* const quota_read)(struct super_block *, int, char *, size_t, loff_t);
62208+ ssize_t (* const quota_write)(struct super_block *, int, const char *, size_t, loff_t);
62209 #endif
62210- int (*bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t);
62211+ int (* const bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t);
62212 };
62213
62214 /*
62215diff -urNp linux-2.6.39.1/include/linux/fs_struct.h linux-2.6.39.1/include/linux/fs_struct.h
62216--- linux-2.6.39.1/include/linux/fs_struct.h 2011-05-19 00:06:34.000000000 -0400
62217+++ linux-2.6.39.1/include/linux/fs_struct.h 2011-05-22 19:36:33.000000000 -0400
62218@@ -6,7 +6,7 @@
62219 #include <linux/seqlock.h>
62220
62221 struct fs_struct {
62222- int users;
62223+ atomic_t users;
62224 spinlock_t lock;
62225 seqcount_t seq;
62226 int umask;
62227diff -urNp linux-2.6.39.1/include/linux/ftrace_event.h linux-2.6.39.1/include/linux/ftrace_event.h
62228--- linux-2.6.39.1/include/linux/ftrace_event.h 2011-05-19 00:06:34.000000000 -0400
62229+++ linux-2.6.39.1/include/linux/ftrace_event.h 2011-05-22 19:36:33.000000000 -0400
62230@@ -235,7 +235,7 @@ extern int trace_define_field(struct ftr
62231 extern int trace_add_event_call(struct ftrace_event_call *call);
62232 extern void trace_remove_event_call(struct ftrace_event_call *call);
62233
62234-#define is_signed_type(type) (((type)(-1)) < 0)
62235+#define is_signed_type(type) (((type)(-1)) < (type)1)
62236
62237 int trace_set_clr_event(const char *system, const char *event, int set);
62238
62239diff -urNp linux-2.6.39.1/include/linux/ftrace.h linux-2.6.39.1/include/linux/ftrace.h
62240--- linux-2.6.39.1/include/linux/ftrace.h 2011-05-19 00:06:34.000000000 -0400
62241+++ linux-2.6.39.1/include/linux/ftrace.h 2011-05-22 19:36:33.000000000 -0400
62242@@ -140,7 +140,7 @@ extern void
62243 unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
62244 void *data);
62245 extern void
62246-unregister_ftrace_function_probe_func(char *glob, struct ftrace_probe_ops *ops);
62247+unregister_ftrace_function_probe_func(char *glob, const struct ftrace_probe_ops *ops);
62248 extern void unregister_ftrace_function_probe_all(char *glob);
62249
62250 extern int ftrace_text_reserved(void *start, void *end);
62251diff -urNp linux-2.6.39.1/include/linux/genhd.h linux-2.6.39.1/include/linux/genhd.h
62252--- linux-2.6.39.1/include/linux/genhd.h 2011-06-03 00:04:14.000000000 -0400
62253+++ linux-2.6.39.1/include/linux/genhd.h 2011-06-03 00:32:08.000000000 -0400
62254@@ -184,7 +184,7 @@ struct gendisk {
62255 struct kobject *slave_dir;
62256
62257 struct timer_rand_state *random;
62258- atomic_t sync_io; /* RAID */
62259+ atomic_unchecked_t sync_io; /* RAID */
62260 struct disk_events *ev;
62261 #ifdef CONFIG_BLK_DEV_INTEGRITY
62262 struct blk_integrity *integrity;
62263diff -urNp linux-2.6.39.1/include/linux/gracl.h linux-2.6.39.1/include/linux/gracl.h
62264--- linux-2.6.39.1/include/linux/gracl.h 1969-12-31 19:00:00.000000000 -0500
62265+++ linux-2.6.39.1/include/linux/gracl.h 2011-05-22 19:41:42.000000000 -0400
62266@@ -0,0 +1,317 @@
62267+#ifndef GR_ACL_H
62268+#define GR_ACL_H
62269+
62270+#include <linux/grdefs.h>
62271+#include <linux/resource.h>
62272+#include <linux/capability.h>
62273+#include <linux/dcache.h>
62274+#include <asm/resource.h>
62275+
62276+/* Major status information */
62277+
62278+#define GR_VERSION "grsecurity 2.2.2"
62279+#define GRSECURITY_VERSION 0x2202
62280+
62281+enum {
62282+ GR_SHUTDOWN = 0,
62283+ GR_ENABLE = 1,
62284+ GR_SPROLE = 2,
62285+ GR_RELOAD = 3,
62286+ GR_SEGVMOD = 4,
62287+ GR_STATUS = 5,
62288+ GR_UNSPROLE = 6,
62289+ GR_PASSSET = 7,
62290+ GR_SPROLEPAM = 8,
62291+};
62292+
62293+/* Password setup definitions
62294+ * kernel/grhash.c */
62295+enum {
62296+ GR_PW_LEN = 128,
62297+ GR_SALT_LEN = 16,
62298+ GR_SHA_LEN = 32,
62299+};
62300+
62301+enum {
62302+ GR_SPROLE_LEN = 64,
62303+};
62304+
62305+enum {
62306+ GR_NO_GLOB = 0,
62307+ GR_REG_GLOB,
62308+ GR_CREATE_GLOB
62309+};
62310+
62311+#define GR_NLIMITS 32
62312+
62313+/* Begin Data Structures */
62314+
62315+struct sprole_pw {
62316+ unsigned char *rolename;
62317+ unsigned char salt[GR_SALT_LEN];
62318+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
62319+};
62320+
62321+struct name_entry {
62322+ __u32 key;
62323+ ino_t inode;
62324+ dev_t device;
62325+ char *name;
62326+ __u16 len;
62327+ __u8 deleted;
62328+ struct name_entry *prev;
62329+ struct name_entry *next;
62330+};
62331+
62332+struct inodev_entry {
62333+ struct name_entry *nentry;
62334+ struct inodev_entry *prev;
62335+ struct inodev_entry *next;
62336+};
62337+
62338+struct acl_role_db {
62339+ struct acl_role_label **r_hash;
62340+ __u32 r_size;
62341+};
62342+
62343+struct inodev_db {
62344+ struct inodev_entry **i_hash;
62345+ __u32 i_size;
62346+};
62347+
62348+struct name_db {
62349+ struct name_entry **n_hash;
62350+ __u32 n_size;
62351+};
62352+
62353+struct crash_uid {
62354+ uid_t uid;
62355+ unsigned long expires;
62356+};
62357+
62358+struct gr_hash_struct {
62359+ void **table;
62360+ void **nametable;
62361+ void *first;
62362+ __u32 table_size;
62363+ __u32 used_size;
62364+ int type;
62365+};
62366+
62367+/* Userspace Grsecurity ACL data structures */
62368+
62369+struct acl_subject_label {
62370+ char *filename;
62371+ ino_t inode;
62372+ dev_t device;
62373+ __u32 mode;
62374+ kernel_cap_t cap_mask;
62375+ kernel_cap_t cap_lower;
62376+ kernel_cap_t cap_invert_audit;
62377+
62378+ struct rlimit res[GR_NLIMITS];
62379+ __u32 resmask;
62380+
62381+ __u8 user_trans_type;
62382+ __u8 group_trans_type;
62383+ uid_t *user_transitions;
62384+ gid_t *group_transitions;
62385+ __u16 user_trans_num;
62386+ __u16 group_trans_num;
62387+
62388+ __u32 sock_families[2];
62389+ __u32 ip_proto[8];
62390+ __u32 ip_type;
62391+ struct acl_ip_label **ips;
62392+ __u32 ip_num;
62393+ __u32 inaddr_any_override;
62394+
62395+ __u32 crashes;
62396+ unsigned long expires;
62397+
62398+ struct acl_subject_label *parent_subject;
62399+ struct gr_hash_struct *hash;
62400+ struct acl_subject_label *prev;
62401+ struct acl_subject_label *next;
62402+
62403+ struct acl_object_label **obj_hash;
62404+ __u32 obj_hash_size;
62405+ __u16 pax_flags;
62406+};
62407+
62408+struct role_allowed_ip {
62409+ __u32 addr;
62410+ __u32 netmask;
62411+
62412+ struct role_allowed_ip *prev;
62413+ struct role_allowed_ip *next;
62414+};
62415+
62416+struct role_transition {
62417+ char *rolename;
62418+
62419+ struct role_transition *prev;
62420+ struct role_transition *next;
62421+};
62422+
62423+struct acl_role_label {
62424+ char *rolename;
62425+ uid_t uidgid;
62426+ __u16 roletype;
62427+
62428+ __u16 auth_attempts;
62429+ unsigned long expires;
62430+
62431+ struct acl_subject_label *root_label;
62432+ struct gr_hash_struct *hash;
62433+
62434+ struct acl_role_label *prev;
62435+ struct acl_role_label *next;
62436+
62437+ struct role_transition *transitions;
62438+ struct role_allowed_ip *allowed_ips;
62439+ uid_t *domain_children;
62440+ __u16 domain_child_num;
62441+
62442+ struct acl_subject_label **subj_hash;
62443+ __u32 subj_hash_size;
62444+};
62445+
62446+struct user_acl_role_db {
62447+ struct acl_role_label **r_table;
62448+ __u32 num_pointers; /* Number of allocations to track */
62449+ __u32 num_roles; /* Number of roles */
62450+ __u32 num_domain_children; /* Number of domain children */
62451+ __u32 num_subjects; /* Number of subjects */
62452+ __u32 num_objects; /* Number of objects */
62453+};
62454+
62455+struct acl_object_label {
62456+ char *filename;
62457+ ino_t inode;
62458+ dev_t device;
62459+ __u32 mode;
62460+
62461+ struct acl_subject_label *nested;
62462+ struct acl_object_label *globbed;
62463+
62464+ /* next two structures not used */
62465+
62466+ struct acl_object_label *prev;
62467+ struct acl_object_label *next;
62468+};
62469+
62470+struct acl_ip_label {
62471+ char *iface;
62472+ __u32 addr;
62473+ __u32 netmask;
62474+ __u16 low, high;
62475+ __u8 mode;
62476+ __u32 type;
62477+ __u32 proto[8];
62478+
62479+ /* next two structures not used */
62480+
62481+ struct acl_ip_label *prev;
62482+ struct acl_ip_label *next;
62483+};
62484+
62485+struct gr_arg {
62486+ struct user_acl_role_db role_db;
62487+ unsigned char pw[GR_PW_LEN];
62488+ unsigned char salt[GR_SALT_LEN];
62489+ unsigned char sum[GR_SHA_LEN];
62490+ unsigned char sp_role[GR_SPROLE_LEN];
62491+ struct sprole_pw *sprole_pws;
62492+ dev_t segv_device;
62493+ ino_t segv_inode;
62494+ uid_t segv_uid;
62495+ __u16 num_sprole_pws;
62496+ __u16 mode;
62497+};
62498+
62499+struct gr_arg_wrapper {
62500+ struct gr_arg *arg;
62501+ __u32 version;
62502+ __u32 size;
62503+};
62504+
62505+struct subject_map {
62506+ struct acl_subject_label *user;
62507+ struct acl_subject_label *kernel;
62508+ struct subject_map *prev;
62509+ struct subject_map *next;
62510+};
62511+
62512+struct acl_subj_map_db {
62513+ struct subject_map **s_hash;
62514+ __u32 s_size;
62515+};
62516+
62517+/* End Data Structures Section */
62518+
62519+/* Hash functions generated by empirical testing by Brad Spengler
62520+ Makes good use of the low bits of the inode. Generally 0-1 times
62521+ in loop for successful match. 0-3 for unsuccessful match.
62522+ Shift/add algorithm with modulus of table size and an XOR*/
62523+
62524+static __inline__ unsigned int
62525+rhash(const uid_t uid, const __u16 type, const unsigned int sz)
62526+{
62527+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
62528+}
62529+
62530+ static __inline__ unsigned int
62531+shash(const struct acl_subject_label *userp, const unsigned int sz)
62532+{
62533+ return ((const unsigned long)userp % sz);
62534+}
62535+
62536+static __inline__ unsigned int
62537+fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
62538+{
62539+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
62540+}
62541+
62542+static __inline__ unsigned int
62543+nhash(const char *name, const __u16 len, const unsigned int sz)
62544+{
62545+ return full_name_hash((const unsigned char *)name, len) % sz;
62546+}
62547+
62548+#define FOR_EACH_ROLE_START(role) \
62549+ role = role_list; \
62550+ while (role) {
62551+
62552+#define FOR_EACH_ROLE_END(role) \
62553+ role = role->prev; \
62554+ }
62555+
62556+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
62557+ subj = NULL; \
62558+ iter = 0; \
62559+ while (iter < role->subj_hash_size) { \
62560+ if (subj == NULL) \
62561+ subj = role->subj_hash[iter]; \
62562+ if (subj == NULL) { \
62563+ iter++; \
62564+ continue; \
62565+ }
62566+
62567+#define FOR_EACH_SUBJECT_END(subj,iter) \
62568+ subj = subj->next; \
62569+ if (subj == NULL) \
62570+ iter++; \
62571+ }
62572+
62573+
62574+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
62575+ subj = role->hash->first; \
62576+ while (subj != NULL) {
62577+
62578+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
62579+ subj = subj->next; \
62580+ }
62581+
62582+#endif
62583+
62584diff -urNp linux-2.6.39.1/include/linux/gralloc.h linux-2.6.39.1/include/linux/gralloc.h
62585--- linux-2.6.39.1/include/linux/gralloc.h 1969-12-31 19:00:00.000000000 -0500
62586+++ linux-2.6.39.1/include/linux/gralloc.h 2011-05-22 19:41:42.000000000 -0400
62587@@ -0,0 +1,9 @@
62588+#ifndef __GRALLOC_H
62589+#define __GRALLOC_H
62590+
62591+void acl_free_all(void);
62592+int acl_alloc_stack_init(unsigned long size);
62593+void *acl_alloc(unsigned long len);
62594+void *acl_alloc_num(unsigned long num, unsigned long len);
62595+
62596+#endif
62597diff -urNp linux-2.6.39.1/include/linux/grdefs.h linux-2.6.39.1/include/linux/grdefs.h
62598--- linux-2.6.39.1/include/linux/grdefs.h 1969-12-31 19:00:00.000000000 -0500
62599+++ linux-2.6.39.1/include/linux/grdefs.h 2011-06-11 16:24:51.000000000 -0400
62600@@ -0,0 +1,140 @@
62601+#ifndef GRDEFS_H
62602+#define GRDEFS_H
62603+
62604+/* Begin grsecurity status declarations */
62605+
62606+enum {
62607+ GR_READY = 0x01,
62608+ GR_STATUS_INIT = 0x00 // disabled state
62609+};
62610+
62611+/* Begin ACL declarations */
62612+
62613+/* Role flags */
62614+
62615+enum {
62616+ GR_ROLE_USER = 0x0001,
62617+ GR_ROLE_GROUP = 0x0002,
62618+ GR_ROLE_DEFAULT = 0x0004,
62619+ GR_ROLE_SPECIAL = 0x0008,
62620+ GR_ROLE_AUTH = 0x0010,
62621+ GR_ROLE_NOPW = 0x0020,
62622+ GR_ROLE_GOD = 0x0040,
62623+ GR_ROLE_LEARN = 0x0080,
62624+ GR_ROLE_TPE = 0x0100,
62625+ GR_ROLE_DOMAIN = 0x0200,
62626+ GR_ROLE_PAM = 0x0400,
62627+ GR_ROLE_PERSIST = 0x0800
62628+};
62629+
62630+/* ACL Subject and Object mode flags */
62631+enum {
62632+ GR_DELETED = 0x80000000
62633+};
62634+
62635+/* ACL Object-only mode flags */
62636+enum {
62637+ GR_READ = 0x00000001,
62638+ GR_APPEND = 0x00000002,
62639+ GR_WRITE = 0x00000004,
62640+ GR_EXEC = 0x00000008,
62641+ GR_FIND = 0x00000010,
62642+ GR_INHERIT = 0x00000020,
62643+ GR_SETID = 0x00000040,
62644+ GR_CREATE = 0x00000080,
62645+ GR_DELETE = 0x00000100,
62646+ GR_LINK = 0x00000200,
62647+ GR_AUDIT_READ = 0x00000400,
62648+ GR_AUDIT_APPEND = 0x00000800,
62649+ GR_AUDIT_WRITE = 0x00001000,
62650+ GR_AUDIT_EXEC = 0x00002000,
62651+ GR_AUDIT_FIND = 0x00004000,
62652+ GR_AUDIT_INHERIT= 0x00008000,
62653+ GR_AUDIT_SETID = 0x00010000,
62654+ GR_AUDIT_CREATE = 0x00020000,
62655+ GR_AUDIT_DELETE = 0x00040000,
62656+ GR_AUDIT_LINK = 0x00080000,
62657+ GR_PTRACERD = 0x00100000,
62658+ GR_NOPTRACE = 0x00200000,
62659+ GR_SUPPRESS = 0x00400000,
62660+ GR_NOLEARN = 0x00800000,
62661+ GR_INIT_TRANSFER= 0x01000000
62662+};
62663+
62664+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
62665+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
62666+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
62667+
62668+/* ACL subject-only mode flags */
62669+enum {
62670+ GR_KILL = 0x00000001,
62671+ GR_VIEW = 0x00000002,
62672+ GR_PROTECTED = 0x00000004,
62673+ GR_LEARN = 0x00000008,
62674+ GR_OVERRIDE = 0x00000010,
62675+ /* just a placeholder, this mode is only used in userspace */
62676+ GR_DUMMY = 0x00000020,
62677+ GR_PROTSHM = 0x00000040,
62678+ GR_KILLPROC = 0x00000080,
62679+ GR_KILLIPPROC = 0x00000100,
62680+ /* just a placeholder, this mode is only used in userspace */
62681+ GR_NOTROJAN = 0x00000200,
62682+ GR_PROTPROCFD = 0x00000400,
62683+ GR_PROCACCT = 0x00000800,
62684+ GR_RELAXPTRACE = 0x00001000,
62685+ GR_NESTED = 0x00002000,
62686+ GR_INHERITLEARN = 0x00004000,
62687+ GR_PROCFIND = 0x00008000,
62688+ GR_POVERRIDE = 0x00010000,
62689+ GR_KERNELAUTH = 0x00020000,
62690+ GR_ATSECURE = 0x00040000,
62691+ GR_SHMEXEC = 0x00080000
62692+};
62693+
62694+enum {
62695+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
62696+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
62697+ GR_PAX_ENABLE_MPROTECT = 0x0004,
62698+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
62699+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
62700+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
62701+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
62702+ GR_PAX_DISABLE_MPROTECT = 0x0400,
62703+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
62704+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
62705+};
62706+
62707+enum {
62708+ GR_ID_USER = 0x01,
62709+ GR_ID_GROUP = 0x02,
62710+};
62711+
62712+enum {
62713+ GR_ID_ALLOW = 0x01,
62714+ GR_ID_DENY = 0x02,
62715+};
62716+
62717+#define GR_CRASH_RES 31
62718+#define GR_UIDTABLE_MAX 500
62719+
62720+/* begin resource learning section */
62721+enum {
62722+ GR_RLIM_CPU_BUMP = 60,
62723+ GR_RLIM_FSIZE_BUMP = 50000,
62724+ GR_RLIM_DATA_BUMP = 10000,
62725+ GR_RLIM_STACK_BUMP = 1000,
62726+ GR_RLIM_CORE_BUMP = 10000,
62727+ GR_RLIM_RSS_BUMP = 500000,
62728+ GR_RLIM_NPROC_BUMP = 1,
62729+ GR_RLIM_NOFILE_BUMP = 5,
62730+ GR_RLIM_MEMLOCK_BUMP = 50000,
62731+ GR_RLIM_AS_BUMP = 500000,
62732+ GR_RLIM_LOCKS_BUMP = 2,
62733+ GR_RLIM_SIGPENDING_BUMP = 5,
62734+ GR_RLIM_MSGQUEUE_BUMP = 10000,
62735+ GR_RLIM_NICE_BUMP = 1,
62736+ GR_RLIM_RTPRIO_BUMP = 1,
62737+ GR_RLIM_RTTIME_BUMP = 1000000
62738+};
62739+
62740+#endif
62741diff -urNp linux-2.6.39.1/include/linux/grinternal.h linux-2.6.39.1/include/linux/grinternal.h
62742--- linux-2.6.39.1/include/linux/grinternal.h 1969-12-31 19:00:00.000000000 -0500
62743+++ linux-2.6.39.1/include/linux/grinternal.h 2011-05-22 19:41:42.000000000 -0400
62744@@ -0,0 +1,219 @@
62745+#ifndef __GRINTERNAL_H
62746+#define __GRINTERNAL_H
62747+
62748+#ifdef CONFIG_GRKERNSEC
62749+
62750+#include <linux/fs.h>
62751+#include <linux/mnt_namespace.h>
62752+#include <linux/nsproxy.h>
62753+#include <linux/gracl.h>
62754+#include <linux/grdefs.h>
62755+#include <linux/grmsg.h>
62756+
62757+void gr_add_learn_entry(const char *fmt, ...)
62758+ __attribute__ ((format (printf, 1, 2)));
62759+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
62760+ const struct vfsmount *mnt);
62761+__u32 gr_check_create(const struct dentry *new_dentry,
62762+ const struct dentry *parent,
62763+ const struct vfsmount *mnt, const __u32 mode);
62764+int gr_check_protected_task(const struct task_struct *task);
62765+__u32 to_gr_audit(const __u32 reqmode);
62766+int gr_set_acls(const int type);
62767+int gr_apply_subject_to_task(struct task_struct *task);
62768+int gr_acl_is_enabled(void);
62769+char gr_roletype_to_char(void);
62770+
62771+void gr_handle_alertkill(struct task_struct *task);
62772+char *gr_to_filename(const struct dentry *dentry,
62773+ const struct vfsmount *mnt);
62774+char *gr_to_filename1(const struct dentry *dentry,
62775+ const struct vfsmount *mnt);
62776+char *gr_to_filename2(const struct dentry *dentry,
62777+ const struct vfsmount *mnt);
62778+char *gr_to_filename3(const struct dentry *dentry,
62779+ const struct vfsmount *mnt);
62780+
62781+extern int grsec_enable_harden_ptrace;
62782+extern int grsec_enable_link;
62783+extern int grsec_enable_fifo;
62784+extern int grsec_enable_execve;
62785+extern int grsec_enable_shm;
62786+extern int grsec_enable_execlog;
62787+extern int grsec_enable_signal;
62788+extern int grsec_enable_audit_ptrace;
62789+extern int grsec_enable_forkfail;
62790+extern int grsec_enable_time;
62791+extern int grsec_enable_rofs;
62792+extern int grsec_enable_chroot_shmat;
62793+extern int grsec_enable_chroot_findtask;
62794+extern int grsec_enable_chroot_mount;
62795+extern int grsec_enable_chroot_double;
62796+extern int grsec_enable_chroot_pivot;
62797+extern int grsec_enable_chroot_chdir;
62798+extern int grsec_enable_chroot_chmod;
62799+extern int grsec_enable_chroot_mknod;
62800+extern int grsec_enable_chroot_fchdir;
62801+extern int grsec_enable_chroot_nice;
62802+extern int grsec_enable_chroot_execlog;
62803+extern int grsec_enable_chroot_caps;
62804+extern int grsec_enable_chroot_sysctl;
62805+extern int grsec_enable_chroot_unix;
62806+extern int grsec_enable_tpe;
62807+extern int grsec_tpe_gid;
62808+extern int grsec_enable_tpe_all;
62809+extern int grsec_enable_tpe_invert;
62810+extern int grsec_enable_socket_all;
62811+extern int grsec_socket_all_gid;
62812+extern int grsec_enable_socket_client;
62813+extern int grsec_socket_client_gid;
62814+extern int grsec_enable_socket_server;
62815+extern int grsec_socket_server_gid;
62816+extern int grsec_audit_gid;
62817+extern int grsec_enable_group;
62818+extern int grsec_enable_audit_textrel;
62819+extern int grsec_enable_log_rwxmaps;
62820+extern int grsec_enable_mount;
62821+extern int grsec_enable_chdir;
62822+extern int grsec_resource_logging;
62823+extern int grsec_enable_blackhole;
62824+extern int grsec_lastack_retries;
62825+extern int grsec_lock;
62826+
62827+extern spinlock_t grsec_alert_lock;
62828+extern unsigned long grsec_alert_wtime;
62829+extern unsigned long grsec_alert_fyet;
62830+
62831+extern spinlock_t grsec_audit_lock;
62832+
62833+extern rwlock_t grsec_exec_file_lock;
62834+
62835+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
62836+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
62837+ (tsk)->exec_file->f_vfsmnt) : "/")
62838+
62839+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
62840+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
62841+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62842+
62843+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
62844+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
62845+ (tsk)->exec_file->f_vfsmnt) : "/")
62846+
62847+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
62848+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
62849+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62850+
62851+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
62852+
62853+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
62854+
62855+#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
62856+ (task)->pid, (cred)->uid, \
62857+ (cred)->euid, (cred)->gid, (cred)->egid, \
62858+ gr_parent_task_fullpath(task), \
62859+ (task)->real_parent->comm, (task)->real_parent->pid, \
62860+ (pcred)->uid, (pcred)->euid, \
62861+ (pcred)->gid, (pcred)->egid
62862+
62863+#define GR_CHROOT_CAPS {{ \
62864+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
62865+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
62866+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
62867+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
62868+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
62869+ CAP_TO_MASK(CAP_IPC_OWNER) , 0 }}
62870+
62871+#define security_learn(normal_msg,args...) \
62872+({ \
62873+ read_lock(&grsec_exec_file_lock); \
62874+ gr_add_learn_entry(normal_msg "\n", ## args); \
62875+ read_unlock(&grsec_exec_file_lock); \
62876+})
62877+
62878+enum {
62879+ GR_DO_AUDIT,
62880+ GR_DONT_AUDIT,
62881+ /* used for non-audit messages that we shouldn't kill the task on */
62882+ GR_DONT_AUDIT_GOOD
62883+};
62884+
62885+enum {
62886+ GR_TTYSNIFF,
62887+ GR_RBAC,
62888+ GR_RBAC_STR,
62889+ GR_STR_RBAC,
62890+ GR_RBAC_MODE2,
62891+ GR_RBAC_MODE3,
62892+ GR_FILENAME,
62893+ GR_SYSCTL_HIDDEN,
62894+ GR_NOARGS,
62895+ GR_ONE_INT,
62896+ GR_ONE_INT_TWO_STR,
62897+ GR_ONE_STR,
62898+ GR_STR_INT,
62899+ GR_TWO_STR_INT,
62900+ GR_TWO_INT,
62901+ GR_TWO_U64,
62902+ GR_THREE_INT,
62903+ GR_FIVE_INT_TWO_STR,
62904+ GR_TWO_STR,
62905+ GR_THREE_STR,
62906+ GR_FOUR_STR,
62907+ GR_STR_FILENAME,
62908+ GR_FILENAME_STR,
62909+ GR_FILENAME_TWO_INT,
62910+ GR_FILENAME_TWO_INT_STR,
62911+ GR_TEXTREL,
62912+ GR_PTRACE,
62913+ GR_RESOURCE,
62914+ GR_CAP,
62915+ GR_SIG,
62916+ GR_SIG2,
62917+ GR_CRASH1,
62918+ GR_CRASH2,
62919+ GR_PSACCT,
62920+ GR_RWXMAP
62921+};
62922+
62923+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
62924+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
62925+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
62926+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
62927+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
62928+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
62929+#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)
62930+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
62931+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
62932+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
62933+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
62934+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
62935+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
62936+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
62937+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
62938+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
62939+#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)
62940+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
62941+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
62942+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
62943+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
62944+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
62945+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
62946+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
62947+#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)
62948+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
62949+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
62950+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
62951+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
62952+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
62953+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
62954+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
62955+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
62956+#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)
62957+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
62958+
62959+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
62960+
62961+#endif
62962+
62963+#endif
62964diff -urNp linux-2.6.39.1/include/linux/grmsg.h linux-2.6.39.1/include/linux/grmsg.h
62965--- linux-2.6.39.1/include/linux/grmsg.h 1969-12-31 19:00:00.000000000 -0500
62966+++ linux-2.6.39.1/include/linux/grmsg.h 2011-05-22 19:41:42.000000000 -0400
62967@@ -0,0 +1,108 @@
62968+#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"
62969+#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"
62970+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
62971+#define GR_STOPMOD_MSG "denied modification of module state by "
62972+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
62973+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
62974+#define GR_IOPERM_MSG "denied use of ioperm() by "
62975+#define GR_IOPL_MSG "denied use of iopl() by "
62976+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
62977+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
62978+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
62979+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
62980+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
62981+#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"
62982+#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"
62983+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
62984+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
62985+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
62986+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
62987+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
62988+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
62989+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
62990+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
62991+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
62992+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
62993+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
62994+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
62995+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
62996+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
62997+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
62998+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
62999+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
63000+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
63001+#define GR_NPROC_MSG "denied overstep of process limit by "
63002+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
63003+#define GR_EXEC_TPE_MSG "denied untrusted exec of %.950s by "
63004+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
63005+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
63006+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
63007+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
63008+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
63009+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
63010+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
63011+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
63012+#define GR_FCHMOD_ACL_MSG "%s fchmod of %.950s by "
63013+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
63014+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
63015+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
63016+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
63017+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
63018+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
63019+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
63020+#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"
63021+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbaged by "
63022+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
63023+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
63024+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
63025+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
63026+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
63027+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
63028+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
63029+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
63030+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
63031+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
63032+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
63033+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
63034+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
63035+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
63036+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
63037+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
63038+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
63039+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
63040+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
63041+#define GR_FAILFORK_MSG "failed fork with errno %s by "
63042+#define GR_NICE_CHROOT_MSG "denied priority change by "
63043+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
63044+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
63045+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
63046+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
63047+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
63048+#define GR_TIME_MSG "time set by "
63049+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
63050+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
63051+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
63052+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
63053+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
63054+#define GR_BIND_MSG "denied bind() by "
63055+#define GR_CONNECT_MSG "denied connect() by "
63056+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
63057+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
63058+#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"
63059+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
63060+#define GR_CAP_ACL_MSG "use of %s denied for "
63061+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
63062+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
63063+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
63064+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
63065+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
63066+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
63067+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
63068+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
63069+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
63070+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
63071+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
63072+#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
63073+#define GR_VM86_MSG "denied use of vm86 by "
63074+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
63075+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
63076diff -urNp linux-2.6.39.1/include/linux/grsecurity.h linux-2.6.39.1/include/linux/grsecurity.h
63077--- linux-2.6.39.1/include/linux/grsecurity.h 1969-12-31 19:00:00.000000000 -0500
63078+++ linux-2.6.39.1/include/linux/grsecurity.h 2011-05-22 19:41:42.000000000 -0400
63079@@ -0,0 +1,212 @@
63080+#ifndef GR_SECURITY_H
63081+#define GR_SECURITY_H
63082+#include <linux/fs.h>
63083+#include <linux/fs_struct.h>
63084+#include <linux/binfmts.h>
63085+#include <linux/gracl.h>
63086+#include <linux/compat.h>
63087+
63088+/* notify of brain-dead configs */
63089+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
63090+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
63091+#endif
63092+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
63093+#error "CONFIG_PAX_NOEXEC enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled."
63094+#endif
63095+#if defined(CONFIG_PAX_ASLR) && (defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
63096+#error "CONFIG_PAX_ASLR enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled."
63097+#endif
63098+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
63099+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
63100+#endif
63101+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
63102+#error "CONFIG_PAX enabled, but no PaX options are enabled."
63103+#endif
63104+
63105+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
63106+void gr_handle_brute_check(void);
63107+void gr_handle_kernel_exploit(void);
63108+int gr_process_user_ban(void);
63109+
63110+char gr_roletype_to_char(void);
63111+
63112+int gr_acl_enable_at_secure(void);
63113+
63114+int gr_check_user_change(int real, int effective, int fs);
63115+int gr_check_group_change(int real, int effective, int fs);
63116+
63117+void gr_del_task_from_ip_table(struct task_struct *p);
63118+
63119+int gr_pid_is_chrooted(struct task_struct *p);
63120+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
63121+int gr_handle_chroot_nice(void);
63122+int gr_handle_chroot_sysctl(const int op);
63123+int gr_handle_chroot_setpriority(struct task_struct *p,
63124+ const int niceval);
63125+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
63126+int gr_handle_chroot_chroot(const struct dentry *dentry,
63127+ const struct vfsmount *mnt);
63128+int gr_handle_chroot_caps(struct path *path);
63129+void gr_handle_chroot_chdir(struct path *path);
63130+int gr_handle_chroot_chmod(const struct dentry *dentry,
63131+ const struct vfsmount *mnt, const int mode);
63132+int gr_handle_chroot_mknod(const struct dentry *dentry,
63133+ const struct vfsmount *mnt, const int mode);
63134+int gr_handle_chroot_mount(const struct dentry *dentry,
63135+ const struct vfsmount *mnt,
63136+ const char *dev_name);
63137+int gr_handle_chroot_pivot(void);
63138+int gr_handle_chroot_unix(struct pid *pid);
63139+
63140+int gr_handle_rawio(const struct inode *inode);
63141+int gr_handle_nproc(void);
63142+
63143+void gr_handle_ioperm(void);
63144+void gr_handle_iopl(void);
63145+
63146+int gr_tpe_allow(const struct file *file);
63147+
63148+void gr_set_chroot_entries(struct task_struct *task, struct path *path);
63149+void gr_clear_chroot_entries(struct task_struct *task);
63150+
63151+void gr_log_forkfail(const int retval);
63152+void gr_log_timechange(void);
63153+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
63154+void gr_log_chdir(const struct dentry *dentry,
63155+ const struct vfsmount *mnt);
63156+void gr_log_chroot_exec(const struct dentry *dentry,
63157+ const struct vfsmount *mnt);
63158+void gr_handle_exec_args(struct linux_binprm *bprm, const char __user *const __user *argv);
63159+#ifdef CONFIG_COMPAT
63160+void gr_handle_exec_args_compat(struct linux_binprm *bprm, compat_uptr_t __user *argv);
63161+#endif
63162+void gr_log_remount(const char *devname, const int retval);
63163+void gr_log_unmount(const char *devname, const int retval);
63164+void gr_log_mount(const char *from, const char *to, const int retval);
63165+void gr_log_textrel(struct vm_area_struct *vma);
63166+void gr_log_rwxmmap(struct file *file);
63167+void gr_log_rwxmprotect(struct file *file);
63168+
63169+int gr_handle_follow_link(const struct inode *parent,
63170+ const struct inode *inode,
63171+ const struct dentry *dentry,
63172+ const struct vfsmount *mnt);
63173+int gr_handle_fifo(const struct dentry *dentry,
63174+ const struct vfsmount *mnt,
63175+ const struct dentry *dir, const int flag,
63176+ const int acc_mode);
63177+int gr_handle_hardlink(const struct dentry *dentry,
63178+ const struct vfsmount *mnt,
63179+ struct inode *inode,
63180+ const int mode, const char *to);
63181+
63182+int gr_is_capable(const int cap);
63183+int gr_is_capable_nolog(const int cap);
63184+void gr_learn_resource(const struct task_struct *task, const int limit,
63185+ const unsigned long wanted, const int gt);
63186+void gr_copy_label(struct task_struct *tsk);
63187+void gr_handle_crash(struct task_struct *task, const int sig);
63188+int gr_handle_signal(const struct task_struct *p, const int sig);
63189+int gr_check_crash_uid(const uid_t uid);
63190+int gr_check_protected_task(const struct task_struct *task);
63191+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
63192+int gr_acl_handle_mmap(const struct file *file,
63193+ const unsigned long prot);
63194+int gr_acl_handle_mprotect(const struct file *file,
63195+ const unsigned long prot);
63196+int gr_check_hidden_task(const struct task_struct *tsk);
63197+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
63198+ const struct vfsmount *mnt);
63199+__u32 gr_acl_handle_utime(const struct dentry *dentry,
63200+ const struct vfsmount *mnt);
63201+__u32 gr_acl_handle_access(const struct dentry *dentry,
63202+ const struct vfsmount *mnt, const int fmode);
63203+__u32 gr_acl_handle_fchmod(const struct dentry *dentry,
63204+ const struct vfsmount *mnt, mode_t mode);
63205+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
63206+ const struct vfsmount *mnt, mode_t mode);
63207+__u32 gr_acl_handle_chown(const struct dentry *dentry,
63208+ const struct vfsmount *mnt);
63209+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
63210+ const struct vfsmount *mnt);
63211+int gr_handle_ptrace(struct task_struct *task, const long request);
63212+int gr_handle_proc_ptrace(struct task_struct *task);
63213+__u32 gr_acl_handle_execve(const struct dentry *dentry,
63214+ const struct vfsmount *mnt);
63215+int gr_check_crash_exec(const struct file *filp);
63216+int gr_acl_is_enabled(void);
63217+void gr_set_kernel_label(struct task_struct *task);
63218+void gr_set_role_label(struct task_struct *task, const uid_t uid,
63219+ const gid_t gid);
63220+int gr_set_proc_label(const struct dentry *dentry,
63221+ const struct vfsmount *mnt,
63222+ const int unsafe_share);
63223+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
63224+ const struct vfsmount *mnt);
63225+__u32 gr_acl_handle_open(const struct dentry *dentry,
63226+ const struct vfsmount *mnt, const int fmode);
63227+__u32 gr_acl_handle_creat(const struct dentry *dentry,
63228+ const struct dentry *p_dentry,
63229+ const struct vfsmount *p_mnt, const int fmode,
63230+ const int imode);
63231+void gr_handle_create(const struct dentry *dentry,
63232+ const struct vfsmount *mnt);
63233+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
63234+ const struct dentry *parent_dentry,
63235+ const struct vfsmount *parent_mnt,
63236+ const int mode);
63237+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
63238+ const struct dentry *parent_dentry,
63239+ const struct vfsmount *parent_mnt);
63240+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
63241+ const struct vfsmount *mnt);
63242+void gr_handle_delete(const ino_t ino, const dev_t dev);
63243+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
63244+ const struct vfsmount *mnt);
63245+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
63246+ const struct dentry *parent_dentry,
63247+ const struct vfsmount *parent_mnt,
63248+ const char *from);
63249+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
63250+ const struct dentry *parent_dentry,
63251+ const struct vfsmount *parent_mnt,
63252+ const struct dentry *old_dentry,
63253+ const struct vfsmount *old_mnt, const char *to);
63254+int gr_acl_handle_rename(struct dentry *new_dentry,
63255+ struct dentry *parent_dentry,
63256+ const struct vfsmount *parent_mnt,
63257+ struct dentry *old_dentry,
63258+ struct inode *old_parent_inode,
63259+ struct vfsmount *old_mnt, const char *newname);
63260+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
63261+ struct dentry *old_dentry,
63262+ struct dentry *new_dentry,
63263+ struct vfsmount *mnt, const __u8 replace);
63264+__u32 gr_check_link(const struct dentry *new_dentry,
63265+ const struct dentry *parent_dentry,
63266+ const struct vfsmount *parent_mnt,
63267+ const struct dentry *old_dentry,
63268+ const struct vfsmount *old_mnt);
63269+int gr_acl_handle_filldir(const struct file *file, const char *name,
63270+ const unsigned int namelen, const ino_t ino);
63271+
63272+__u32 gr_acl_handle_unix(const struct dentry *dentry,
63273+ const struct vfsmount *mnt);
63274+void gr_acl_handle_exit(void);
63275+void gr_acl_handle_psacct(struct task_struct *task, const long code);
63276+int gr_acl_handle_procpidmem(const struct task_struct *task);
63277+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
63278+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
63279+void gr_audit_ptrace(struct task_struct *task);
63280+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
63281+
63282+#ifdef CONFIG_GRKERNSEC
63283+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
63284+void gr_handle_vm86(void);
63285+void gr_handle_mem_readwrite(u64 from, u64 to);
63286+
63287+extern int grsec_enable_dmesg;
63288+extern int grsec_disable_privio;
63289+#endif
63290+
63291+#endif
63292diff -urNp linux-2.6.39.1/include/linux/grsock.h linux-2.6.39.1/include/linux/grsock.h
63293--- linux-2.6.39.1/include/linux/grsock.h 1969-12-31 19:00:00.000000000 -0500
63294+++ linux-2.6.39.1/include/linux/grsock.h 2011-05-22 19:41:42.000000000 -0400
63295@@ -0,0 +1,19 @@
63296+#ifndef __GRSOCK_H
63297+#define __GRSOCK_H
63298+
63299+extern void gr_attach_curr_ip(const struct sock *sk);
63300+extern int gr_handle_sock_all(const int family, const int type,
63301+ const int protocol);
63302+extern int gr_handle_sock_server(const struct sockaddr *sck);
63303+extern int gr_handle_sock_server_other(const struct sock *sck);
63304+extern int gr_handle_sock_client(const struct sockaddr *sck);
63305+extern int gr_search_connect(struct socket * sock,
63306+ struct sockaddr_in * addr);
63307+extern int gr_search_bind(struct socket * sock,
63308+ struct sockaddr_in * addr);
63309+extern int gr_search_listen(struct socket * sock);
63310+extern int gr_search_accept(struct socket * sock);
63311+extern int gr_search_socket(const int domain, const int type,
63312+ const int protocol);
63313+
63314+#endif
63315diff -urNp linux-2.6.39.1/include/linux/highmem.h linux-2.6.39.1/include/linux/highmem.h
63316--- linux-2.6.39.1/include/linux/highmem.h 2011-05-19 00:06:34.000000000 -0400
63317+++ linux-2.6.39.1/include/linux/highmem.h 2011-05-22 19:36:33.000000000 -0400
63318@@ -185,6 +185,18 @@ static inline void clear_highpage(struct
63319 kunmap_atomic(kaddr, KM_USER0);
63320 }
63321
63322+static inline void sanitize_highpage(struct page *page)
63323+{
63324+ void *kaddr;
63325+ unsigned long flags;
63326+
63327+ local_irq_save(flags);
63328+ kaddr = kmap_atomic(page, KM_CLEARPAGE);
63329+ clear_page(kaddr);
63330+ kunmap_atomic(kaddr, KM_CLEARPAGE);
63331+ local_irq_restore(flags);
63332+}
63333+
63334 static inline void zero_user_segments(struct page *page,
63335 unsigned start1, unsigned end1,
63336 unsigned start2, unsigned end2)
63337diff -urNp linux-2.6.39.1/include/linux/i2o.h linux-2.6.39.1/include/linux/i2o.h
63338--- linux-2.6.39.1/include/linux/i2o.h 2011-05-19 00:06:34.000000000 -0400
63339+++ linux-2.6.39.1/include/linux/i2o.h 2011-05-22 19:36:33.000000000 -0400
63340@@ -564,7 +564,7 @@ struct i2o_controller {
63341 struct i2o_device *exec; /* Executive */
63342 #if BITS_PER_LONG == 64
63343 spinlock_t context_list_lock; /* lock for context_list */
63344- atomic_t context_list_counter; /* needed for unique contexts */
63345+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
63346 struct list_head context_list; /* list of context id's
63347 and pointers */
63348 #endif
63349diff -urNp linux-2.6.39.1/include/linux/if_phonet.h linux-2.6.39.1/include/linux/if_phonet.h
63350--- linux-2.6.39.1/include/linux/if_phonet.h 2011-05-19 00:06:34.000000000 -0400
63351+++ linux-2.6.39.1/include/linux/if_phonet.h 2011-05-22 19:36:33.000000000 -0400
63352@@ -13,7 +13,7 @@
63353 #define PHONET_DEV_MTU PHONET_MAX_MTU
63354
63355 #ifdef __KERNEL__
63356-extern struct header_ops phonet_header_ops;
63357+extern const struct header_ops phonet_header_ops;
63358 #endif
63359
63360 #endif
63361diff -urNp linux-2.6.39.1/include/linux/init.h linux-2.6.39.1/include/linux/init.h
63362--- linux-2.6.39.1/include/linux/init.h 2011-05-19 00:06:34.000000000 -0400
63363+++ linux-2.6.39.1/include/linux/init.h 2011-05-22 19:36:33.000000000 -0400
63364@@ -293,13 +293,13 @@ void __init parse_early_options(char *cm
63365
63366 /* Each module must use one module_init(). */
63367 #define module_init(initfn) \
63368- static inline initcall_t __inittest(void) \
63369+ static inline __used initcall_t __inittest(void) \
63370 { return initfn; } \
63371 int init_module(void) __attribute__((alias(#initfn)));
63372
63373 /* This is only required if you want to be unloadable. */
63374 #define module_exit(exitfn) \
63375- static inline exitcall_t __exittest(void) \
63376+ static inline __used exitcall_t __exittest(void) \
63377 { return exitfn; } \
63378 void cleanup_module(void) __attribute__((alias(#exitfn)));
63379
63380diff -urNp linux-2.6.39.1/include/linux/init_task.h linux-2.6.39.1/include/linux/init_task.h
63381--- linux-2.6.39.1/include/linux/init_task.h 2011-05-19 00:06:34.000000000 -0400
63382+++ linux-2.6.39.1/include/linux/init_task.h 2011-05-22 19:36:33.000000000 -0400
63383@@ -83,6 +83,12 @@ extern struct group_info init_groups;
63384 #define INIT_IDS
63385 #endif
63386
63387+#ifdef CONFIG_X86
63388+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
63389+#else
63390+#define INIT_TASK_THREAD_INFO
63391+#endif
63392+
63393 /*
63394 * Because of the reduced scope of CAP_SETPCAP when filesystem
63395 * capabilities are in effect, it is safe to allow CAP_SETPCAP to
63396@@ -163,6 +169,7 @@ extern struct cred init_cred;
63397 RCU_INIT_POINTER(.cred, &init_cred), \
63398 .comm = "swapper", \
63399 .thread = INIT_THREAD, \
63400+ INIT_TASK_THREAD_INFO \
63401 .fs = &init_fs, \
63402 .files = &init_files, \
63403 .signal = &init_signals, \
63404diff -urNp linux-2.6.39.1/include/linux/interrupt.h linux-2.6.39.1/include/linux/interrupt.h
63405--- linux-2.6.39.1/include/linux/interrupt.h 2011-05-19 00:06:34.000000000 -0400
63406+++ linux-2.6.39.1/include/linux/interrupt.h 2011-05-22 19:36:33.000000000 -0400
63407@@ -422,7 +422,7 @@ enum
63408 /* map softirq index to softirq name. update 'softirq_to_name' in
63409 * kernel/softirq.c when adding a new softirq.
63410 */
63411-extern char *softirq_to_name[NR_SOFTIRQS];
63412+extern const char * const softirq_to_name[NR_SOFTIRQS];
63413
63414 /* softirq mask and active fields moved to irq_cpustat_t in
63415 * asm/hardirq.h to get better cache usage. KAO
63416@@ -430,12 +430,12 @@ extern char *softirq_to_name[NR_SOFTIRQS
63417
63418 struct softirq_action
63419 {
63420- void (*action)(struct softirq_action *);
63421+ void (*action)(void);
63422 };
63423
63424 asmlinkage void do_softirq(void);
63425 asmlinkage void __do_softirq(void);
63426-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
63427+extern void open_softirq(int nr, void (*action)(void));
63428 extern void softirq_init(void);
63429 static inline void __raise_softirq_irqoff(unsigned int nr)
63430 {
63431diff -urNp linux-2.6.39.1/include/linux/iommu.h linux-2.6.39.1/include/linux/iommu.h
63432--- linux-2.6.39.1/include/linux/iommu.h 2011-05-19 00:06:34.000000000 -0400
63433+++ linux-2.6.39.1/include/linux/iommu.h 2011-05-22 19:36:33.000000000 -0400
63434@@ -49,7 +49,7 @@ struct iommu_ops {
63435
63436 #ifdef CONFIG_IOMMU_API
63437
63438-extern void register_iommu(struct iommu_ops *ops);
63439+extern void register_iommu(const struct iommu_ops *ops);
63440 extern bool iommu_found(void);
63441 extern struct iommu_domain *iommu_domain_alloc(void);
63442 extern void iommu_domain_free(struct iommu_domain *domain);
63443diff -urNp linux-2.6.39.1/include/linux/ipmi.h linux-2.6.39.1/include/linux/ipmi.h
63444--- linux-2.6.39.1/include/linux/ipmi.h 2011-05-19 00:06:34.000000000 -0400
63445+++ linux-2.6.39.1/include/linux/ipmi.h 2011-05-22 19:36:33.000000000 -0400
63446@@ -282,7 +282,7 @@ struct ipmi_user_hndl {
63447
63448 /* Create a new user of the IPMI layer on the given interface number. */
63449 int ipmi_create_user(unsigned int if_num,
63450- struct ipmi_user_hndl *handler,
63451+ const struct ipmi_user_hndl *handler,
63452 void *handler_data,
63453 ipmi_user_t *user);
63454
63455diff -urNp linux-2.6.39.1/include/linux/kallsyms.h linux-2.6.39.1/include/linux/kallsyms.h
63456--- linux-2.6.39.1/include/linux/kallsyms.h 2011-05-19 00:06:34.000000000 -0400
63457+++ linux-2.6.39.1/include/linux/kallsyms.h 2011-05-22 22:52:54.000000000 -0400
63458@@ -15,7 +15,8 @@
63459
63460 struct module;
63461
63462-#ifdef CONFIG_KALLSYMS
63463+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
63464+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63465 /* Lookup the address for a symbol. Returns 0 if not found. */
63466 unsigned long kallsyms_lookup_name(const char *name);
63467
63468@@ -99,6 +100,16 @@ static inline int lookup_symbol_attrs(un
63469 /* Stupid that this does nothing, but I didn't create this mess. */
63470 #define __print_symbol(fmt, addr)
63471 #endif /*CONFIG_KALLSYMS*/
63472+#else /* when included by kallsyms.c, vsnprintf.c, or
63473+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
63474+extern void __print_symbol(const char *fmt, unsigned long address);
63475+extern int sprint_backtrace(char *buffer, unsigned long address);
63476+extern int sprint_symbol(char *buffer, unsigned long address);
63477+const char *kallsyms_lookup(unsigned long addr,
63478+ unsigned long *symbolsize,
63479+ unsigned long *offset,
63480+ char **modname, char *namebuf);
63481+#endif
63482
63483 /* This macro allows us to keep printk typechecking */
63484 static void __check_printsym_format(const char *fmt, ...)
63485diff -urNp linux-2.6.39.1/include/linux/kgdb.h linux-2.6.39.1/include/linux/kgdb.h
63486--- linux-2.6.39.1/include/linux/kgdb.h 2011-05-19 00:06:34.000000000 -0400
63487+++ linux-2.6.39.1/include/linux/kgdb.h 2011-05-22 19:36:33.000000000 -0400
63488@@ -53,7 +53,7 @@ extern int kgdb_connected;
63489 extern int kgdb_io_module_registered;
63490
63491 extern atomic_t kgdb_setting_breakpoint;
63492-extern atomic_t kgdb_cpu_doing_single_step;
63493+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
63494
63495 extern struct task_struct *kgdb_usethread;
63496 extern struct task_struct *kgdb_contthread;
63497@@ -269,22 +269,22 @@ struct kgdb_arch {
63498 */
63499 struct kgdb_io {
63500 const char *name;
63501- int (*read_char) (void);
63502- void (*write_char) (u8);
63503- void (*flush) (void);
63504- int (*init) (void);
63505- void (*pre_exception) (void);
63506- void (*post_exception) (void);
63507+ int (* const read_char) (void);
63508+ void (* const write_char) (u8);
63509+ void (* const flush) (void);
63510+ int (* const init) (void);
63511+ void (* const pre_exception) (void);
63512+ void (* const post_exception) (void);
63513 int is_console;
63514 };
63515
63516-extern struct kgdb_arch arch_kgdb_ops;
63517+extern const struct kgdb_arch arch_kgdb_ops;
63518
63519 extern unsigned long __weak kgdb_arch_pc(int exception, struct pt_regs *regs);
63520
63521-extern int kgdb_register_io_module(struct kgdb_io *local_kgdb_io_ops);
63522-extern void kgdb_unregister_io_module(struct kgdb_io *local_kgdb_io_ops);
63523-extern struct kgdb_io *dbg_io_ops;
63524+extern int kgdb_register_io_module(const struct kgdb_io *local_kgdb_io_ops);
63525+extern void kgdb_unregister_io_module(const struct kgdb_io *local_kgdb_io_ops);
63526+extern const struct kgdb_io *dbg_io_ops;
63527
63528 extern int kgdb_hex2long(char **ptr, unsigned long *long_val);
63529 extern char *kgdb_mem2hex(char *mem, char *buf, int count);
63530diff -urNp linux-2.6.39.1/include/linux/kmod.h linux-2.6.39.1/include/linux/kmod.h
63531--- linux-2.6.39.1/include/linux/kmod.h 2011-05-19 00:06:34.000000000 -0400
63532+++ linux-2.6.39.1/include/linux/kmod.h 2011-05-22 19:41:42.000000000 -0400
63533@@ -33,6 +33,8 @@ extern char modprobe_path[]; /* for sysc
63534 * usually useless though. */
63535 extern int __request_module(bool wait, const char *name, ...) \
63536 __attribute__((format(printf, 2, 3)));
63537+extern int ___request_module(bool wait, char *param_name, const char *name, ...) \
63538+ __attribute__((format(printf, 3, 4)));
63539 #define request_module(mod...) __request_module(true, mod)
63540 #define request_module_nowait(mod...) __request_module(false, mod)
63541 #define try_then_request_module(x, mod...) \
63542diff -urNp linux-2.6.39.1/include/linux/kvm_host.h linux-2.6.39.1/include/linux/kvm_host.h
63543--- linux-2.6.39.1/include/linux/kvm_host.h 2011-05-19 00:06:34.000000000 -0400
63544+++ linux-2.6.39.1/include/linux/kvm_host.h 2011-05-22 19:36:33.000000000 -0400
63545@@ -302,7 +302,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vc
63546 void vcpu_load(struct kvm_vcpu *vcpu);
63547 void vcpu_put(struct kvm_vcpu *vcpu);
63548
63549-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63550+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63551 struct module *module);
63552 void kvm_exit(void);
63553
63554@@ -442,7 +442,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(
63555 struct kvm_guest_debug *dbg);
63556 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
63557
63558-int kvm_arch_init(void *opaque);
63559+int kvm_arch_init(const void *opaque);
63560 void kvm_arch_exit(void);
63561
63562 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
63563diff -urNp linux-2.6.39.1/include/linux/lapb.h linux-2.6.39.1/include/linux/lapb.h
63564--- linux-2.6.39.1/include/linux/lapb.h 2011-05-19 00:06:34.000000000 -0400
63565+++ linux-2.6.39.1/include/linux/lapb.h 2011-05-22 19:36:33.000000000 -0400
63566@@ -44,7 +44,7 @@ struct lapb_parms_struct {
63567 unsigned int mode;
63568 };
63569
63570-extern int lapb_register(struct net_device *dev, struct lapb_register_struct *callbacks);
63571+extern int lapb_register(struct net_device *dev, const struct lapb_register_struct *callbacks);
63572 extern int lapb_unregister(struct net_device *dev);
63573 extern int lapb_getparms(struct net_device *dev, struct lapb_parms_struct *parms);
63574 extern int lapb_setparms(struct net_device *dev, struct lapb_parms_struct *parms);
63575diff -urNp linux-2.6.39.1/include/linux/lcd.h linux-2.6.39.1/include/linux/lcd.h
63576--- linux-2.6.39.1/include/linux/lcd.h 2011-05-19 00:06:34.000000000 -0400
63577+++ linux-2.6.39.1/include/linux/lcd.h 2011-05-22 19:36:33.000000000 -0400
63578@@ -60,7 +60,7 @@ struct lcd_device {
63579 points to something in the body of that driver, it is also invalid. */
63580 struct mutex ops_lock;
63581 /* If this is NULL, the backing module is unloaded */
63582- struct lcd_ops *ops;
63583+ const struct lcd_ops *ops;
63584 /* Serialise access to set_power method */
63585 struct mutex update_lock;
63586 /* The framebuffer notifier block */
63587@@ -101,7 +101,7 @@ static inline void lcd_set_power(struct
63588 }
63589
63590 extern struct lcd_device *lcd_device_register(const char *name,
63591- struct device *parent, void *devdata, struct lcd_ops *ops);
63592+ struct device *parent, void *devdata, const struct lcd_ops *ops);
63593 extern void lcd_device_unregister(struct lcd_device *ld);
63594
63595 #define to_lcd_device(obj) container_of(obj, struct lcd_device, dev)
63596diff -urNp linux-2.6.39.1/include/linux/libata.h linux-2.6.39.1/include/linux/libata.h
63597--- linux-2.6.39.1/include/linux/libata.h 2011-05-19 00:06:34.000000000 -0400
63598+++ linux-2.6.39.1/include/linux/libata.h 2011-05-22 19:36:33.000000000 -0400
63599@@ -524,11 +524,11 @@ struct ata_ioports {
63600
63601 struct ata_host {
63602 spinlock_t lock;
63603- struct device *dev;
63604+ struct device *dev;
63605 void __iomem * const *iomap;
63606 unsigned int n_ports;
63607 void *private_data;
63608- struct ata_port_operations *ops;
63609+ const struct ata_port_operations *ops;
63610 unsigned long flags;
63611
63612 struct mutex eh_mutex;
63613@@ -719,7 +719,7 @@ struct ata_link {
63614
63615 struct ata_port {
63616 struct Scsi_Host *scsi_host; /* our co-allocated scsi host */
63617- struct ata_port_operations *ops;
63618+ const struct ata_port_operations *ops;
63619 spinlock_t *lock;
63620 /* Flags owned by the EH context. Only EH should touch these once the
63621 port is active */
63622@@ -907,7 +907,7 @@ struct ata_port_info {
63623 unsigned long pio_mask;
63624 unsigned long mwdma_mask;
63625 unsigned long udma_mask;
63626- struct ata_port_operations *port_ops;
63627+ const struct ata_port_operations *port_ops;
63628 void *private_data;
63629 };
63630
63631@@ -931,7 +931,7 @@ extern const unsigned long sata_deb_timi
63632 extern const unsigned long sata_deb_timing_hotplug[];
63633 extern const unsigned long sata_deb_timing_long[];
63634
63635-extern struct ata_port_operations ata_dummy_port_ops;
63636+extern const struct ata_port_operations ata_dummy_port_ops;
63637 extern const struct ata_port_info ata_dummy_port_info;
63638
63639 static inline const unsigned long *
63640@@ -977,7 +977,7 @@ extern int ata_host_activate(struct ata_
63641 struct scsi_host_template *sht);
63642 extern void ata_host_detach(struct ata_host *host);
63643 extern void ata_host_init(struct ata_host *, struct device *,
63644- unsigned long, struct ata_port_operations *);
63645+ unsigned long, const struct ata_port_operations *);
63646 extern int ata_scsi_detect(struct scsi_host_template *sht);
63647 extern int ata_scsi_ioctl(struct scsi_device *dev, int cmd, void __user *arg);
63648 extern int ata_scsi_queuecmd(struct Scsi_Host *h, struct scsi_cmnd *cmd);
63649diff -urNp linux-2.6.39.1/include/linux/lockd/bind.h linux-2.6.39.1/include/linux/lockd/bind.h
63650--- linux-2.6.39.1/include/linux/lockd/bind.h 2011-05-19 00:06:34.000000000 -0400
63651+++ linux-2.6.39.1/include/linux/lockd/bind.h 2011-05-22 19:36:33.000000000 -0400
63652@@ -23,13 +23,13 @@ struct svc_rqst;
63653 * This is the set of functions for lockd->nfsd communication
63654 */
63655 struct nlmsvc_binding {
63656- __be32 (*fopen)(struct svc_rqst *,
63657+ __be32 (* const fopen)(struct svc_rqst *,
63658 struct nfs_fh *,
63659 struct file **);
63660- void (*fclose)(struct file *);
63661+ void (* const fclose)(struct file *);
63662 };
63663
63664-extern struct nlmsvc_binding * nlmsvc_ops;
63665+extern const struct nlmsvc_binding * nlmsvc_ops;
63666
63667 /*
63668 * Similar to nfs_client_initdata, but without the NFS-specific
63669diff -urNp linux-2.6.39.1/include/linux/mfd/abx500.h linux-2.6.39.1/include/linux/mfd/abx500.h
63670--- linux-2.6.39.1/include/linux/mfd/abx500.h 2011-05-19 00:06:34.000000000 -0400
63671+++ linux-2.6.39.1/include/linux/mfd/abx500.h 2011-05-22 19:36:33.000000000 -0400
63672@@ -227,6 +227,6 @@ struct abx500_ops {
63673 int (*startup_irq_enabled) (struct device *, unsigned int);
63674 };
63675
63676-int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
63677+int abx500_register_ops(struct device *core_dev, const struct abx500_ops *ops);
63678 void abx500_remove_ops(struct device *dev);
63679 #endif
63680diff -urNp linux-2.6.39.1/include/linux/mm.h linux-2.6.39.1/include/linux/mm.h
63681--- linux-2.6.39.1/include/linux/mm.h 2011-05-19 00:06:34.000000000 -0400
63682+++ linux-2.6.39.1/include/linux/mm.h 2011-05-22 19:36:33.000000000 -0400
63683@@ -113,7 +113,14 @@ extern unsigned int kobjsize(const void
63684
63685 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
63686 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
63687+
63688+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
63689+#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
63690+#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
63691+#else
63692 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
63693+#endif
63694+
63695 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
63696 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
63697
63698@@ -1010,34 +1017,6 @@ int set_page_dirty(struct page *page);
63699 int set_page_dirty_lock(struct page *page);
63700 int clear_page_dirty_for_io(struct page *page);
63701
63702-/* Is the vma a continuation of the stack vma above it? */
63703-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
63704-{
63705- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
63706-}
63707-
63708-static inline int stack_guard_page_start(struct vm_area_struct *vma,
63709- unsigned long addr)
63710-{
63711- return (vma->vm_flags & VM_GROWSDOWN) &&
63712- (vma->vm_start == addr) &&
63713- !vma_growsdown(vma->vm_prev, addr);
63714-}
63715-
63716-/* Is the vma a continuation of the stack vma below it? */
63717-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
63718-{
63719- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
63720-}
63721-
63722-static inline int stack_guard_page_end(struct vm_area_struct *vma,
63723- unsigned long addr)
63724-{
63725- return (vma->vm_flags & VM_GROWSUP) &&
63726- (vma->vm_end == addr) &&
63727- !vma_growsup(vma->vm_next, addr);
63728-}
63729-
63730 extern unsigned long move_page_tables(struct vm_area_struct *vma,
63731 unsigned long old_addr, struct vm_area_struct *new_vma,
63732 unsigned long new_addr, unsigned long len);
63733@@ -1189,6 +1168,15 @@ struct shrinker {
63734 extern void register_shrinker(struct shrinker *);
63735 extern void unregister_shrinker(struct shrinker *);
63736
63737+#ifdef CONFIG_MMU
63738+pgprot_t vm_get_page_prot(unsigned long vm_flags);
63739+#else
63740+static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
63741+{
63742+ return __pgprot(0);
63743+}
63744+#endif
63745+
63746 int vma_wants_writenotify(struct vm_area_struct *vma);
63747
63748 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
63749@@ -1476,6 +1464,7 @@ out:
63750 }
63751
63752 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
63753+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
63754
63755 extern unsigned long do_brk(unsigned long, unsigned long);
63756
63757@@ -1532,6 +1521,10 @@ extern struct vm_area_struct * find_vma(
63758 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
63759 struct vm_area_struct **pprev);
63760
63761+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
63762+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
63763+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
63764+
63765 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
63766 NULL if none. Assume start_addr < end_addr. */
63767 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
63768@@ -1548,15 +1541,6 @@ static inline unsigned long vma_pages(st
63769 return (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
63770 }
63771
63772-#ifdef CONFIG_MMU
63773-pgprot_t vm_get_page_prot(unsigned long vm_flags);
63774-#else
63775-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
63776-{
63777- return __pgprot(0);
63778-}
63779-#endif
63780-
63781 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
63782 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
63783 unsigned long pfn, unsigned long size, pgprot_t);
63784@@ -1668,7 +1652,7 @@ extern int unpoison_memory(unsigned long
63785 extern int sysctl_memory_failure_early_kill;
63786 extern int sysctl_memory_failure_recovery;
63787 extern void shake_page(struct page *p, int access);
63788-extern atomic_long_t mce_bad_pages;
63789+extern atomic_long_unchecked_t mce_bad_pages;
63790 extern int soft_offline_page(struct page *page, int flags);
63791
63792 extern void dump_page(struct page *page);
63793@@ -1682,5 +1666,11 @@ extern void copy_user_huge_page(struct p
63794 unsigned int pages_per_huge_page);
63795 #endif /* CONFIG_TRANSPARENT_HUGEPAGE || CONFIG_HUGETLBFS */
63796
63797+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
63798+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
63799+#else
63800+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
63801+#endif
63802+
63803 #endif /* __KERNEL__ */
63804 #endif /* _LINUX_MM_H */
63805diff -urNp linux-2.6.39.1/include/linux/mm_types.h linux-2.6.39.1/include/linux/mm_types.h
63806--- linux-2.6.39.1/include/linux/mm_types.h 2011-05-19 00:06:34.000000000 -0400
63807+++ linux-2.6.39.1/include/linux/mm_types.h 2011-05-22 19:36:33.000000000 -0400
63808@@ -183,6 +183,8 @@ struct vm_area_struct {
63809 #ifdef CONFIG_NUMA
63810 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
63811 #endif
63812+
63813+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
63814 };
63815
63816 struct core_thread {
63817@@ -317,6 +319,24 @@ struct mm_struct {
63818 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
63819 pgtable_t pmd_huge_pte; /* protected by page_table_lock */
63820 #endif
63821+
63822+#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63823+ unsigned long pax_flags;
63824+#endif
63825+
63826+#ifdef CONFIG_PAX_DLRESOLVE
63827+ unsigned long call_dl_resolve;
63828+#endif
63829+
63830+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
63831+ unsigned long call_syscall;
63832+#endif
63833+
63834+#ifdef CONFIG_PAX_ASLR
63835+ unsigned long delta_mmap; /* randomized offset */
63836+ unsigned long delta_stack; /* randomized offset */
63837+#endif
63838+
63839 };
63840
63841 /* Future-safe accessor for struct mm_struct's cpu_vm_mask. */
63842diff -urNp linux-2.6.39.1/include/linux/mmu_notifier.h linux-2.6.39.1/include/linux/mmu_notifier.h
63843--- linux-2.6.39.1/include/linux/mmu_notifier.h 2011-05-19 00:06:34.000000000 -0400
63844+++ linux-2.6.39.1/include/linux/mmu_notifier.h 2011-05-22 19:36:33.000000000 -0400
63845@@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destr
63846 */
63847 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
63848 ({ \
63849- pte_t __pte; \
63850+ pte_t ___pte; \
63851 struct vm_area_struct *___vma = __vma; \
63852 unsigned long ___address = __address; \
63853- __pte = ptep_clear_flush(___vma, ___address, __ptep); \
63854+ ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
63855 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
63856- __pte; \
63857+ ___pte; \
63858 })
63859
63860 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
63861diff -urNp linux-2.6.39.1/include/linux/mmzone.h linux-2.6.39.1/include/linux/mmzone.h
63862--- linux-2.6.39.1/include/linux/mmzone.h 2011-05-19 00:06:34.000000000 -0400
63863+++ linux-2.6.39.1/include/linux/mmzone.h 2011-05-22 19:36:33.000000000 -0400
63864@@ -355,7 +355,7 @@ struct zone {
63865 unsigned long flags; /* zone flags, see below */
63866
63867 /* Zone statistics */
63868- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63869+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63870
63871 /*
63872 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
63873diff -urNp linux-2.6.39.1/include/linux/mod_devicetable.h linux-2.6.39.1/include/linux/mod_devicetable.h
63874--- linux-2.6.39.1/include/linux/mod_devicetable.h 2011-05-19 00:06:34.000000000 -0400
63875+++ linux-2.6.39.1/include/linux/mod_devicetable.h 2011-05-22 19:36:33.000000000 -0400
63876@@ -12,7 +12,7 @@
63877 typedef unsigned long kernel_ulong_t;
63878 #endif
63879
63880-#define PCI_ANY_ID (~0)
63881+#define PCI_ANY_ID ((__u16)~0)
63882
63883 struct pci_device_id {
63884 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
63885@@ -131,7 +131,7 @@ struct usb_device_id {
63886 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
63887 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
63888
63889-#define HID_ANY_ID (~0)
63890+#define HID_ANY_ID (~0U)
63891
63892 struct hid_device_id {
63893 __u16 bus;
63894diff -urNp linux-2.6.39.1/include/linux/module.h linux-2.6.39.1/include/linux/module.h
63895--- linux-2.6.39.1/include/linux/module.h 2011-05-19 00:06:34.000000000 -0400
63896+++ linux-2.6.39.1/include/linux/module.h 2011-05-22 19:36:33.000000000 -0400
63897@@ -324,19 +324,16 @@ struct module
63898 int (*init)(void);
63899
63900 /* If this is non-NULL, vfree after init() returns */
63901- void *module_init;
63902+ void *module_init_rx, *module_init_rw;
63903
63904 /* Here is the actual code + data, vfree'd on unload. */
63905- void *module_core;
63906+ void *module_core_rx, *module_core_rw;
63907
63908 /* Here are the sizes of the init and core sections */
63909- unsigned int init_size, core_size;
63910+ unsigned int init_size_rw, core_size_rw;
63911
63912 /* The size of the executable code in each section. */
63913- unsigned int init_text_size, core_text_size;
63914-
63915- /* Size of RO sections of the module (text+rodata) */
63916- unsigned int init_ro_size, core_ro_size;
63917+ unsigned int init_size_rx, core_size_rx;
63918
63919 /* Arch-specific module values */
63920 struct mod_arch_specific arch;
63921@@ -441,16 +438,46 @@ bool is_module_address(unsigned long add
63922 bool is_module_percpu_address(unsigned long addr);
63923 bool is_module_text_address(unsigned long addr);
63924
63925+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
63926+{
63927+
63928+#ifdef CONFIG_PAX_KERNEXEC
63929+ if (ktla_ktva(addr) >= (unsigned long)start &&
63930+ ktla_ktva(addr) < (unsigned long)start + size)
63931+ return 1;
63932+#endif
63933+
63934+ return ((void *)addr >= start && (void *)addr < start + size);
63935+}
63936+
63937+static inline int within_module_core_rx(unsigned long addr, struct module *mod)
63938+{
63939+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
63940+}
63941+
63942+static inline int within_module_core_rw(unsigned long addr, struct module *mod)
63943+{
63944+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
63945+}
63946+
63947+static inline int within_module_init_rx(unsigned long addr, struct module *mod)
63948+{
63949+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
63950+}
63951+
63952+static inline int within_module_init_rw(unsigned long addr, struct module *mod)
63953+{
63954+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
63955+}
63956+
63957 static inline int within_module_core(unsigned long addr, struct module *mod)
63958 {
63959- return (unsigned long)mod->module_core <= addr &&
63960- addr < (unsigned long)mod->module_core + mod->core_size;
63961+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
63962 }
63963
63964 static inline int within_module_init(unsigned long addr, struct module *mod)
63965 {
63966- return (unsigned long)mod->module_init <= addr &&
63967- addr < (unsigned long)mod->module_init + mod->init_size;
63968+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
63969 }
63970
63971 /* Search for module by name: must hold module_mutex. */
63972diff -urNp linux-2.6.39.1/include/linux/moduleloader.h linux-2.6.39.1/include/linux/moduleloader.h
63973--- linux-2.6.39.1/include/linux/moduleloader.h 2011-05-19 00:06:34.000000000 -0400
63974+++ linux-2.6.39.1/include/linux/moduleloader.h 2011-05-22 19:36:33.000000000 -0400
63975@@ -20,9 +20,21 @@ unsigned int arch_mod_section_prepend(st
63976 sections. Returns NULL on failure. */
63977 void *module_alloc(unsigned long size);
63978
63979+#ifdef CONFIG_PAX_KERNEXEC
63980+void *module_alloc_exec(unsigned long size);
63981+#else
63982+#define module_alloc_exec(x) module_alloc(x)
63983+#endif
63984+
63985 /* Free memory returned from module_alloc. */
63986 void module_free(struct module *mod, void *module_region);
63987
63988+#ifdef CONFIG_PAX_KERNEXEC
63989+void module_free_exec(struct module *mod, void *module_region);
63990+#else
63991+#define module_free_exec(x, y) module_free((x), (y))
63992+#endif
63993+
63994 /* Apply the given relocation to the (simplified) ELF. Return -error
63995 or 0. */
63996 int apply_relocate(Elf_Shdr *sechdrs,
63997diff -urNp linux-2.6.39.1/include/linux/moduleparam.h linux-2.6.39.1/include/linux/moduleparam.h
63998--- linux-2.6.39.1/include/linux/moduleparam.h 2011-05-19 00:06:34.000000000 -0400
63999+++ linux-2.6.39.1/include/linux/moduleparam.h 2011-05-22 19:36:33.000000000 -0400
64000@@ -255,7 +255,7 @@ static inline void __kernel_param_unlock
64001 * @len is usually just sizeof(string).
64002 */
64003 #define module_param_string(name, string, len, perm) \
64004- static const struct kparam_string __param_string_##name \
64005+ static const struct kparam_string __param_string_##name __used \
64006 = { len, string }; \
64007 __module_param_call(MODULE_PARAM_PREFIX, name, \
64008 &param_ops_string, \
64009@@ -285,48 +285,48 @@ static inline void destroy_params(const
64010 #define __param_check(name, p, type) \
64011 static inline type *__check_##name(void) { return(p); }
64012
64013-extern struct kernel_param_ops param_ops_byte;
64014+extern const struct kernel_param_ops param_ops_byte;
64015 extern int param_set_byte(const char *val, const struct kernel_param *kp);
64016 extern int param_get_byte(char *buffer, const struct kernel_param *kp);
64017 #define param_check_byte(name, p) __param_check(name, p, unsigned char)
64018
64019-extern struct kernel_param_ops param_ops_short;
64020+extern const struct kernel_param_ops param_ops_short;
64021 extern int param_set_short(const char *val, const struct kernel_param *kp);
64022 extern int param_get_short(char *buffer, const struct kernel_param *kp);
64023 #define param_check_short(name, p) __param_check(name, p, short)
64024
64025-extern struct kernel_param_ops param_ops_ushort;
64026+extern const struct kernel_param_ops param_ops_ushort;
64027 extern int param_set_ushort(const char *val, const struct kernel_param *kp);
64028 extern int param_get_ushort(char *buffer, const struct kernel_param *kp);
64029 #define param_check_ushort(name, p) __param_check(name, p, unsigned short)
64030
64031-extern struct kernel_param_ops param_ops_int;
64032+extern const struct kernel_param_ops param_ops_int;
64033 extern int param_set_int(const char *val, const struct kernel_param *kp);
64034 extern int param_get_int(char *buffer, const struct kernel_param *kp);
64035 #define param_check_int(name, p) __param_check(name, p, int)
64036
64037-extern struct kernel_param_ops param_ops_uint;
64038+extern const struct kernel_param_ops param_ops_uint;
64039 extern int param_set_uint(const char *val, const struct kernel_param *kp);
64040 extern int param_get_uint(char *buffer, const struct kernel_param *kp);
64041 #define param_check_uint(name, p) __param_check(name, p, unsigned int)
64042
64043-extern struct kernel_param_ops param_ops_long;
64044+extern const struct kernel_param_ops param_ops_long;
64045 extern int param_set_long(const char *val, const struct kernel_param *kp);
64046 extern int param_get_long(char *buffer, const struct kernel_param *kp);
64047 #define param_check_long(name, p) __param_check(name, p, long)
64048
64049-extern struct kernel_param_ops param_ops_ulong;
64050+extern const struct kernel_param_ops param_ops_ulong;
64051 extern int param_set_ulong(const char *val, const struct kernel_param *kp);
64052 extern int param_get_ulong(char *buffer, const struct kernel_param *kp);
64053 #define param_check_ulong(name, p) __param_check(name, p, unsigned long)
64054
64055-extern struct kernel_param_ops param_ops_charp;
64056+extern const struct kernel_param_ops param_ops_charp;
64057 extern int param_set_charp(const char *val, const struct kernel_param *kp);
64058 extern int param_get_charp(char *buffer, const struct kernel_param *kp);
64059 #define param_check_charp(name, p) __param_check(name, p, char *)
64060
64061 /* For historical reasons "bool" parameters can be (unsigned) "int". */
64062-extern struct kernel_param_ops param_ops_bool;
64063+extern const struct kernel_param_ops param_ops_bool;
64064 extern int param_set_bool(const char *val, const struct kernel_param *kp);
64065 extern int param_get_bool(char *buffer, const struct kernel_param *kp);
64066 #define param_check_bool(name, p) \
64067@@ -337,7 +337,7 @@ extern int param_get_bool(char *buffer,
64068 !__same_type((p), int *)); \
64069 }
64070
64071-extern struct kernel_param_ops param_ops_invbool;
64072+extern const struct kernel_param_ops param_ops_invbool;
64073 extern int param_set_invbool(const char *val, const struct kernel_param *kp);
64074 extern int param_get_invbool(char *buffer, const struct kernel_param *kp);
64075 #define param_check_invbool(name, p) __param_check(name, p, bool)
64076@@ -370,7 +370,7 @@ extern int param_get_invbool(char *buffe
64077 * module_param_named() for why this might be necessary.
64078 */
64079 #define module_param_array_named(name, array, type, nump, perm) \
64080- static const struct kparam_array __param_arr_##name \
64081+ static const struct kparam_array __param_arr_##name __used \
64082 = { ARRAY_SIZE(array), nump, &param_ops_##type, \
64083 sizeof(array[0]), array }; \
64084 __module_param_call(MODULE_PARAM_PREFIX, name, \
64085@@ -379,9 +379,9 @@ extern int param_get_invbool(char *buffe
64086 __same_type(array[0], bool), perm); \
64087 __MODULE_PARM_TYPE(name, "array of " #type)
64088
64089-extern struct kernel_param_ops param_array_ops;
64090+extern const struct kernel_param_ops param_array_ops;
64091
64092-extern struct kernel_param_ops param_ops_string;
64093+extern const struct kernel_param_ops param_ops_string;
64094 extern int param_set_copystring(const char *val, const struct kernel_param *);
64095 extern int param_get_string(char *buffer, const struct kernel_param *kp);
64096
64097diff -urNp linux-2.6.39.1/include/linux/mutex.h linux-2.6.39.1/include/linux/mutex.h
64098--- linux-2.6.39.1/include/linux/mutex.h 2011-05-19 00:06:34.000000000 -0400
64099+++ linux-2.6.39.1/include/linux/mutex.h 2011-05-22 19:36:33.000000000 -0400
64100@@ -51,7 +51,7 @@ struct mutex {
64101 spinlock_t wait_lock;
64102 struct list_head wait_list;
64103 #if defined(CONFIG_DEBUG_MUTEXES) || defined(CONFIG_SMP)
64104- struct thread_info *owner;
64105+ struct task_struct *owner;
64106 #endif
64107 #ifdef CONFIG_DEBUG_MUTEXES
64108 const char *name;
64109diff -urNp linux-2.6.39.1/include/linux/namei.h linux-2.6.39.1/include/linux/namei.h
64110--- linux-2.6.39.1/include/linux/namei.h 2011-05-19 00:06:34.000000000 -0400
64111+++ linux-2.6.39.1/include/linux/namei.h 2011-05-22 19:36:33.000000000 -0400
64112@@ -24,7 +24,7 @@ struct nameidata {
64113 unsigned seq;
64114 int last_type;
64115 unsigned depth;
64116- char *saved_names[MAX_NESTED_LINKS + 1];
64117+ const char *saved_names[MAX_NESTED_LINKS + 1];
64118
64119 /* Intent data */
64120 union {
64121@@ -91,12 +91,12 @@ extern int follow_up(struct path *);
64122 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
64123 extern void unlock_rename(struct dentry *, struct dentry *);
64124
64125-static inline void nd_set_link(struct nameidata *nd, char *path)
64126+static inline void nd_set_link(struct nameidata *nd, const char *path)
64127 {
64128 nd->saved_names[nd->depth] = path;
64129 }
64130
64131-static inline char *nd_get_link(struct nameidata *nd)
64132+static inline const char *nd_get_link(const struct nameidata *nd)
64133 {
64134 return nd->saved_names[nd->depth];
64135 }
64136diff -urNp linux-2.6.39.1/include/linux/netfilter/xt_gradm.h linux-2.6.39.1/include/linux/netfilter/xt_gradm.h
64137--- linux-2.6.39.1/include/linux/netfilter/xt_gradm.h 1969-12-31 19:00:00.000000000 -0500
64138+++ linux-2.6.39.1/include/linux/netfilter/xt_gradm.h 2011-05-22 19:41:42.000000000 -0400
64139@@ -0,0 +1,9 @@
64140+#ifndef _LINUX_NETFILTER_XT_GRADM_H
64141+#define _LINUX_NETFILTER_XT_GRADM_H 1
64142+
64143+struct xt_gradm_mtinfo {
64144+ __u16 flags;
64145+ __u16 invflags;
64146+};
64147+
64148+#endif
64149diff -urNp linux-2.6.39.1/include/linux/oprofile.h linux-2.6.39.1/include/linux/oprofile.h
64150--- linux-2.6.39.1/include/linux/oprofile.h 2011-05-19 00:06:34.000000000 -0400
64151+++ linux-2.6.39.1/include/linux/oprofile.h 2011-05-22 19:36:33.000000000 -0400
64152@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super
64153 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
64154 char const * name, ulong * val);
64155
64156-/** Create a file for read-only access to an atomic_t. */
64157+/** Create a file for read-only access to an atomic_unchecked_t. */
64158 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
64159- char const * name, atomic_t * val);
64160+ char const * name, atomic_unchecked_t * val);
64161
64162 /** create a directory */
64163 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
64164diff -urNp linux-2.6.39.1/include/linux/padata.h linux-2.6.39.1/include/linux/padata.h
64165--- linux-2.6.39.1/include/linux/padata.h 2011-05-19 00:06:34.000000000 -0400
64166+++ linux-2.6.39.1/include/linux/padata.h 2011-05-22 19:36:33.000000000 -0400
64167@@ -129,7 +129,7 @@ struct parallel_data {
64168 struct padata_instance *pinst;
64169 struct padata_parallel_queue __percpu *pqueue;
64170 struct padata_serial_queue __percpu *squeue;
64171- atomic_t seq_nr;
64172+ atomic_unchecked_t seq_nr;
64173 atomic_t reorder_objects;
64174 atomic_t refcnt;
64175 unsigned int max_seq_nr;
64176diff -urNp linux-2.6.39.1/include/linux/pci.h linux-2.6.39.1/include/linux/pci.h
64177--- linux-2.6.39.1/include/linux/pci.h 2011-05-19 00:06:34.000000000 -0400
64178+++ linux-2.6.39.1/include/linux/pci.h 2011-05-22 19:36:33.000000000 -0400
64179@@ -411,7 +411,7 @@ struct pci_bus {
64180 struct resource *resource[PCI_BRIDGE_RESOURCE_NUM];
64181 struct list_head resources; /* address space routed to this bus */
64182
64183- struct pci_ops *ops; /* configuration access functions */
64184+ const struct pci_ops *ops; /* configuration access functions */
64185 void *sysdata; /* hook for sys-specific extension */
64186 struct proc_dir_entry *procdir; /* directory entry in /proc/bus/pci */
64187
64188@@ -550,7 +550,7 @@ struct pci_driver {
64189 int (*resume_early) (struct pci_dev *dev);
64190 int (*resume) (struct pci_dev *dev); /* Device woken up */
64191 void (*shutdown) (struct pci_dev *dev);
64192- struct pci_error_handlers *err_handler;
64193+ const struct pci_error_handlers *err_handler;
64194 struct device_driver driver;
64195 struct pci_dynids dynids;
64196 };
64197@@ -639,7 +639,7 @@ void pcibios_scan_specific_bus(int busn)
64198 extern struct pci_bus *pci_find_bus(int domain, int busnr);
64199 void pci_bus_add_devices(const struct pci_bus *bus);
64200 struct pci_bus *pci_scan_bus_parented(struct device *parent, int bus,
64201- struct pci_ops *ops, void *sysdata);
64202+ const struct pci_ops *ops, void *sysdata);
64203 static inline struct pci_bus * __devinit pci_scan_bus(int bus, struct pci_ops *ops,
64204 void *sysdata)
64205 {
64206@@ -650,7 +650,7 @@ static inline struct pci_bus * __devinit
64207 return root_bus;
64208 }
64209 struct pci_bus *pci_create_bus(struct device *parent, int bus,
64210- struct pci_ops *ops, void *sysdata);
64211+ const struct pci_ops *ops, void *sysdata);
64212 struct pci_bus *pci_add_new_bus(struct pci_bus *parent, struct pci_dev *dev,
64213 int busnr);
64214 void pcie_update_link_speed(struct pci_bus *bus, u16 link_status);
64215@@ -727,7 +727,7 @@ int pci_bus_write_config_word(struct pci
64216 int where, u16 val);
64217 int pci_bus_write_config_dword(struct pci_bus *bus, unsigned int devfn,
64218 int where, u32 val);
64219-struct pci_ops *pci_bus_set_ops(struct pci_bus *bus, struct pci_ops *ops);
64220+const struct pci_ops *pci_bus_set_ops(struct pci_bus *bus, const struct pci_ops *ops);
64221
64222 static inline int pci_read_config_byte(struct pci_dev *dev, int where, u8 *val)
64223 {
64224diff -urNp linux-2.6.39.1/include/linux/perf_event.h linux-2.6.39.1/include/linux/perf_event.h
64225--- linux-2.6.39.1/include/linux/perf_event.h 2011-05-19 00:06:34.000000000 -0400
64226+++ linux-2.6.39.1/include/linux/perf_event.h 2011-05-22 19:36:33.000000000 -0400
64227@@ -759,8 +759,8 @@ struct perf_event {
64228
64229 enum perf_event_active_state state;
64230 unsigned int attach_state;
64231- local64_t count;
64232- atomic64_t child_count;
64233+ local64_t count; /* PaX: fix it one day */
64234+ atomic64_unchecked_t child_count;
64235
64236 /*
64237 * These are the total time in nanoseconds that the event
64238@@ -811,8 +811,8 @@ struct perf_event {
64239 * These accumulate total time (in nanoseconds) that children
64240 * events have been enabled and running, respectively.
64241 */
64242- atomic64_t child_total_time_enabled;
64243- atomic64_t child_total_time_running;
64244+ atomic64_unchecked_t child_total_time_enabled;
64245+ atomic64_unchecked_t child_total_time_running;
64246
64247 /*
64248 * Protect attach/detach and child_list:
64249@@ -1090,9 +1090,9 @@ void perf_event_task_sched_out(struct ta
64250 }
64251
64252 extern void perf_event_mmap(struct vm_area_struct *vma);
64253-extern struct perf_guest_info_callbacks *perf_guest_cbs;
64254-extern int perf_register_guest_info_callbacks(struct perf_guest_info_callbacks *callbacks);
64255-extern int perf_unregister_guest_info_callbacks(struct perf_guest_info_callbacks *callbacks);
64256+extern const struct perf_guest_info_callbacks *perf_guest_cbs;
64257+extern int perf_register_guest_info_callbacks(const struct perf_guest_info_callbacks *callbacks);
64258+extern int perf_unregister_guest_info_callbacks(const struct perf_guest_info_callbacks *callbacks);
64259
64260 extern void perf_event_comm(struct task_struct *tsk);
64261 extern void perf_event_fork(struct task_struct *tsk);
64262diff -urNp linux-2.6.39.1/include/linux/pipe_fs_i.h linux-2.6.39.1/include/linux/pipe_fs_i.h
64263--- linux-2.6.39.1/include/linux/pipe_fs_i.h 2011-05-19 00:06:34.000000000 -0400
64264+++ linux-2.6.39.1/include/linux/pipe_fs_i.h 2011-05-22 19:36:33.000000000 -0400
64265@@ -46,9 +46,9 @@ struct pipe_buffer {
64266 struct pipe_inode_info {
64267 wait_queue_head_t wait;
64268 unsigned int nrbufs, curbuf, buffers;
64269- unsigned int readers;
64270- unsigned int writers;
64271- unsigned int waiting_writers;
64272+ atomic_t readers;
64273+ atomic_t writers;
64274+ atomic_t waiting_writers;
64275 unsigned int r_counter;
64276 unsigned int w_counter;
64277 struct page *tmp_page;
64278diff -urNp linux-2.6.39.1/include/linux/pm.h linux-2.6.39.1/include/linux/pm.h
64279--- linux-2.6.39.1/include/linux/pm.h 2011-05-19 00:06:34.000000000 -0400
64280+++ linux-2.6.39.1/include/linux/pm.h 2011-05-22 19:36:33.000000000 -0400
64281@@ -268,7 +268,7 @@ const struct dev_pm_ops name = { \
64282 * runtime PM, make the pm member point to generic_subsys_pm_ops.
64283 */
64284 #ifdef CONFIG_PM
64285-extern struct dev_pm_ops generic_subsys_pm_ops;
64286+extern const struct dev_pm_ops generic_subsys_pm_ops;
64287 #define GENERIC_SUBSYS_PM_OPS (&generic_subsys_pm_ops)
64288 #else
64289 #define GENERIC_SUBSYS_PM_OPS NULL
64290@@ -471,7 +471,7 @@ extern void update_pm_runtime_accounting
64291 * subsystem-level and driver-level callbacks.
64292 */
64293 struct dev_power_domain {
64294- struct dev_pm_ops ops;
64295+ const struct dev_pm_ops ops;
64296 };
64297
64298 /*
64299diff -urNp linux-2.6.39.1/include/linux/pm_runtime.h linux-2.6.39.1/include/linux/pm_runtime.h
64300--- linux-2.6.39.1/include/linux/pm_runtime.h 2011-05-19 00:06:34.000000000 -0400
64301+++ linux-2.6.39.1/include/linux/pm_runtime.h 2011-05-22 19:36:33.000000000 -0400
64302@@ -94,7 +94,7 @@ static inline bool pm_runtime_callbacks_
64303
64304 static inline void pm_runtime_mark_last_busy(struct device *dev)
64305 {
64306- ACCESS_ONCE(dev->power.last_busy) = jiffies;
64307+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
64308 }
64309
64310 #else /* !CONFIG_PM_RUNTIME */
64311diff -urNp linux-2.6.39.1/include/linux/poison.h linux-2.6.39.1/include/linux/poison.h
64312--- linux-2.6.39.1/include/linux/poison.h 2011-05-19 00:06:34.000000000 -0400
64313+++ linux-2.6.39.1/include/linux/poison.h 2011-05-22 19:36:33.000000000 -0400
64314@@ -19,8 +19,8 @@
64315 * under normal circumstances, used to verify that nobody uses
64316 * non-initialized list entries.
64317 */
64318-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
64319-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
64320+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
64321+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
64322
64323 /********** include/linux/timer.h **********/
64324 /*
64325diff -urNp linux-2.6.39.1/include/linux/posix-timers.h linux-2.6.39.1/include/linux/posix-timers.h
64326--- linux-2.6.39.1/include/linux/posix-timers.h 2011-05-19 00:06:34.000000000 -0400
64327+++ linux-2.6.39.1/include/linux/posix-timers.h 2011-05-22 19:36:33.000000000 -0400
64328@@ -102,10 +102,10 @@ struct k_clock {
64329 struct itimerspec * cur_setting);
64330 };
64331
64332-extern struct k_clock clock_posix_cpu;
64333-extern struct k_clock clock_posix_dynamic;
64334+extern const struct k_clock clock_posix_cpu;
64335+extern const struct k_clock clock_posix_dynamic;
64336
64337-void posix_timers_register_clock(const clockid_t clock_id, struct k_clock *new_clock);
64338+void posix_timers_register_clock(const clockid_t clock_id, const struct k_clock *new_clock);
64339
64340 /* function to call to trigger timer event */
64341 int posix_timer_event(struct k_itimer *timr, int si_private);
64342diff -urNp linux-2.6.39.1/include/linux/proc_fs.h linux-2.6.39.1/include/linux/proc_fs.h
64343--- linux-2.6.39.1/include/linux/proc_fs.h 2011-05-19 00:06:34.000000000 -0400
64344+++ linux-2.6.39.1/include/linux/proc_fs.h 2011-05-22 19:41:42.000000000 -0400
64345@@ -155,6 +155,19 @@ static inline struct proc_dir_entry *pro
64346 return proc_create_data(name, mode, parent, proc_fops, NULL);
64347 }
64348
64349+static inline struct proc_dir_entry *proc_create_grsec(const char *name, mode_t mode,
64350+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
64351+{
64352+#ifdef CONFIG_GRKERNSEC_PROC_USER
64353+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
64354+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64355+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
64356+#else
64357+ return proc_create_data(name, mode, parent, proc_fops, NULL);
64358+#endif
64359+}
64360+
64361+
64362 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
64363 mode_t mode, struct proc_dir_entry *base,
64364 read_proc_t *read_proc, void * data)
64365diff -urNp linux-2.6.39.1/include/linux/ptrace.h linux-2.6.39.1/include/linux/ptrace.h
64366--- linux-2.6.39.1/include/linux/ptrace.h 2011-05-19 00:06:34.000000000 -0400
64367+++ linux-2.6.39.1/include/linux/ptrace.h 2011-05-22 19:41:42.000000000 -0400
64368@@ -115,10 +115,10 @@ extern void __ptrace_unlink(struct task_
64369 extern void exit_ptrace(struct task_struct *tracer);
64370 #define PTRACE_MODE_READ 1
64371 #define PTRACE_MODE_ATTACH 2
64372-/* Returns 0 on success, -errno on denial. */
64373-extern int __ptrace_may_access(struct task_struct *task, unsigned int mode);
64374 /* Returns true on success, false on denial. */
64375 extern bool ptrace_may_access(struct task_struct *task, unsigned int mode);
64376+/* Returns true on success, false on denial. */
64377+extern bool ptrace_may_access_log(struct task_struct *task, unsigned int mode);
64378
64379 static inline int ptrace_reparented(struct task_struct *child)
64380 {
64381diff -urNp linux-2.6.39.1/include/linux/random.h linux-2.6.39.1/include/linux/random.h
64382--- linux-2.6.39.1/include/linux/random.h 2011-05-19 00:06:34.000000000 -0400
64383+++ linux-2.6.39.1/include/linux/random.h 2011-05-22 19:36:33.000000000 -0400
64384@@ -80,12 +80,17 @@ void srandom32(u32 seed);
64385
64386 u32 prandom32(struct rnd_state *);
64387
64388+static inline unsigned long pax_get_random_long(void)
64389+{
64390+ return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
64391+}
64392+
64393 /*
64394 * Handle minimum values for seeds
64395 */
64396 static inline u32 __seed(u32 x, u32 m)
64397 {
64398- return (x < m) ? x + m : x;
64399+ return (x <= m) ? x + m + 1 : x;
64400 }
64401
64402 /**
64403diff -urNp linux-2.6.39.1/include/linux/reboot.h linux-2.6.39.1/include/linux/reboot.h
64404--- linux-2.6.39.1/include/linux/reboot.h 2011-05-19 00:06:34.000000000 -0400
64405+++ linux-2.6.39.1/include/linux/reboot.h 2011-05-22 19:36:33.000000000 -0400
64406@@ -47,9 +47,9 @@ extern int unregister_reboot_notifier(st
64407 * Architecture-specific implementations of sys_reboot commands.
64408 */
64409
64410-extern void machine_restart(char *cmd);
64411-extern void machine_halt(void);
64412-extern void machine_power_off(void);
64413+extern void machine_restart(char *cmd) __noreturn;
64414+extern void machine_halt(void) __noreturn;
64415+extern void machine_power_off(void) __noreturn;
64416
64417 extern void machine_shutdown(void);
64418 struct pt_regs;
64419@@ -60,9 +60,9 @@ extern void machine_crash_shutdown(struc
64420 */
64421
64422 extern void kernel_restart_prepare(char *cmd);
64423-extern void kernel_restart(char *cmd);
64424-extern void kernel_halt(void);
64425-extern void kernel_power_off(void);
64426+extern void kernel_restart(char *cmd) __noreturn;
64427+extern void kernel_halt(void) __noreturn;
64428+extern void kernel_power_off(void) __noreturn;
64429
64430 extern int C_A_D; /* for sysctl */
64431 void ctrl_alt_del(void);
64432@@ -76,7 +76,7 @@ extern int orderly_poweroff(bool force);
64433 * Emergency restart, callable from an interrupt handler.
64434 */
64435
64436-extern void emergency_restart(void);
64437+extern void emergency_restart(void) __noreturn;
64438 #include <asm/emergency-restart.h>
64439
64440 #endif
64441diff -urNp linux-2.6.39.1/include/linux/reiserfs_fs.h linux-2.6.39.1/include/linux/reiserfs_fs.h
64442--- linux-2.6.39.1/include/linux/reiserfs_fs.h 2011-05-19 00:06:34.000000000 -0400
64443+++ linux-2.6.39.1/include/linux/reiserfs_fs.h 2011-05-22 19:36:33.000000000 -0400
64444@@ -1406,7 +1406,7 @@ static inline loff_t max_reiserfs_offset
64445 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
64446
64447 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
64448-#define get_generation(s) atomic_read (&fs_generation(s))
64449+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
64450 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
64451 #define __fs_changed(gen,s) (gen != get_generation (s))
64452 #define fs_changed(gen,s) \
64453@@ -1618,24 +1618,24 @@ static inline struct super_block *sb_fro
64454 */
64455
64456 struct item_operations {
64457- int (*bytes_number) (struct item_head * ih, int block_size);
64458- void (*decrement_key) (struct cpu_key *);
64459- int (*is_left_mergeable) (struct reiserfs_key * ih,
64460+ int (* const bytes_number) (struct item_head * ih, int block_size);
64461+ void (* const decrement_key) (struct cpu_key *);
64462+ int (* const is_left_mergeable) (struct reiserfs_key * ih,
64463 unsigned long bsize);
64464- void (*print_item) (struct item_head *, char *item);
64465- void (*check_item) (struct item_head *, char *item);
64466+ void (* const print_item) (struct item_head *, char *item);
64467+ void (* const check_item) (struct item_head *, char *item);
64468
64469- int (*create_vi) (struct virtual_node * vn, struct virtual_item * vi,
64470+ int (* const create_vi) (struct virtual_node * vn, struct virtual_item * vi,
64471 int is_affected, int insert_size);
64472- int (*check_left) (struct virtual_item * vi, int free,
64473+ int (* const check_left) (struct virtual_item * vi, int free,
64474 int start_skip, int end_skip);
64475- int (*check_right) (struct virtual_item * vi, int free);
64476- int (*part_size) (struct virtual_item * vi, int from, int to);
64477- int (*unit_num) (struct virtual_item * vi);
64478- void (*print_vi) (struct virtual_item * vi);
64479+ int (* const check_right) (struct virtual_item * vi, int free);
64480+ int (* const part_size) (struct virtual_item * vi, int from, int to);
64481+ int (* const unit_num) (struct virtual_item * vi);
64482+ void (* const print_vi) (struct virtual_item * vi);
64483 };
64484
64485-extern struct item_operations *item_ops[TYPE_ANY + 1];
64486+extern const struct item_operations * const item_ops[TYPE_ANY + 1];
64487
64488 #define op_bytes_number(ih,bsize) item_ops[le_ih_k_type (ih)]->bytes_number (ih, bsize)
64489 #define op_is_left_mergeable(key,bsize) item_ops[le_key_k_type (le_key_version (key), key)]->is_left_mergeable (key, bsize)
64490diff -urNp linux-2.6.39.1/include/linux/reiserfs_fs_sb.h linux-2.6.39.1/include/linux/reiserfs_fs_sb.h
64491--- linux-2.6.39.1/include/linux/reiserfs_fs_sb.h 2011-05-19 00:06:34.000000000 -0400
64492+++ linux-2.6.39.1/include/linux/reiserfs_fs_sb.h 2011-05-22 19:36:33.000000000 -0400
64493@@ -386,7 +386,7 @@ struct reiserfs_sb_info {
64494 /* Comment? -Hans */
64495 wait_queue_head_t s_wait;
64496 /* To be obsoleted soon by per buffer seals.. -Hans */
64497- atomic_t s_generation_counter; // increased by one every time the
64498+ atomic_unchecked_t s_generation_counter; // increased by one every time the
64499 // tree gets re-balanced
64500 unsigned long s_properties; /* File system properties. Currently holds
64501 on-disk FS format */
64502diff -urNp linux-2.6.39.1/include/linux/rmap.h linux-2.6.39.1/include/linux/rmap.h
64503--- linux-2.6.39.1/include/linux/rmap.h 2011-05-19 00:06:34.000000000 -0400
64504+++ linux-2.6.39.1/include/linux/rmap.h 2011-05-22 19:36:33.000000000 -0400
64505@@ -119,8 +119,8 @@ static inline void anon_vma_unlock(struc
64506 void anon_vma_init(void); /* create anon_vma_cachep */
64507 int anon_vma_prepare(struct vm_area_struct *);
64508 void unlink_anon_vmas(struct vm_area_struct *);
64509-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
64510-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
64511+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
64512+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
64513 void __anon_vma_link(struct vm_area_struct *);
64514
64515 static inline void anon_vma_merge(struct vm_area_struct *vma,
64516diff -urNp linux-2.6.39.1/include/linux/sched.h linux-2.6.39.1/include/linux/sched.h
64517--- linux-2.6.39.1/include/linux/sched.h 2011-05-19 00:06:34.000000000 -0400
64518+++ linux-2.6.39.1/include/linux/sched.h 2011-06-03 23:34:26.000000000 -0400
64519@@ -100,6 +100,7 @@ struct bio_list;
64520 struct fs_struct;
64521 struct perf_event_context;
64522 struct blk_plug;
64523+struct linux_binprm;
64524
64525 /*
64526 * List of flags we want to share for kernel threads,
64527@@ -360,7 +361,7 @@ extern signed long schedule_timeout_inte
64528 extern signed long schedule_timeout_killable(signed long timeout);
64529 extern signed long schedule_timeout_uninterruptible(signed long timeout);
64530 asmlinkage void schedule(void);
64531-extern int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner);
64532+extern int mutex_spin_on_owner(struct mutex *lock, struct task_struct *owner);
64533
64534 struct nsproxy;
64535 struct user_namespace;
64536@@ -381,10 +382,13 @@ struct user_namespace;
64537 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
64538
64539 extern int sysctl_max_map_count;
64540+extern unsigned long sysctl_heap_stack_gap;
64541
64542 #include <linux/aio.h>
64543
64544 #ifdef CONFIG_MMU
64545+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
64546+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
64547 extern void arch_pick_mmap_layout(struct mm_struct *mm);
64548 extern unsigned long
64549 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
64550@@ -629,6 +633,17 @@ struct signal_struct {
64551 #ifdef CONFIG_TASKSTATS
64552 struct taskstats *stats;
64553 #endif
64554+
64555+#ifdef CONFIG_GRKERNSEC
64556+ u32 curr_ip;
64557+ u32 saved_ip;
64558+ u32 gr_saddr;
64559+ u32 gr_daddr;
64560+ u16 gr_sport;
64561+ u16 gr_dport;
64562+ u8 used_accept:1;
64563+#endif
64564+
64565 #ifdef CONFIG_AUDIT
64566 unsigned audit_tty;
64567 struct tty_audit_buf *tty_audit_buf;
64568@@ -701,6 +716,11 @@ struct user_struct {
64569 struct key *session_keyring; /* UID's default session keyring */
64570 #endif
64571
64572+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
64573+ unsigned int banned;
64574+ unsigned long ban_expires;
64575+#endif
64576+
64577 /* Hash table maintenance information */
64578 struct hlist_node uidhash_node;
64579 uid_t uid;
64580@@ -1310,8 +1330,8 @@ struct task_struct {
64581 struct list_head thread_group;
64582
64583 struct completion *vfork_done; /* for vfork() */
64584- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
64585- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64586+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
64587+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64588
64589 cputime_t utime, stime, utimescaled, stimescaled;
64590 cputime_t gtime;
64591@@ -1327,13 +1347,6 @@ struct task_struct {
64592 struct task_cputime cputime_expires;
64593 struct list_head cpu_timers[3];
64594
64595-/* process credentials */
64596- const struct cred __rcu *real_cred; /* objective and real subjective task
64597- * credentials (COW) */
64598- const struct cred __rcu *cred; /* effective (overridable) subjective task
64599- * credentials (COW) */
64600- struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
64601-
64602 char comm[TASK_COMM_LEN]; /* executable name excluding path
64603 - access with [gs]et_task_comm (which lock
64604 it with task_lock())
64605@@ -1350,8 +1363,16 @@ struct task_struct {
64606 #endif
64607 /* CPU-specific state of this task */
64608 struct thread_struct thread;
64609+/* thread_info moved to task_struct */
64610+#ifdef CONFIG_X86
64611+ struct thread_info tinfo;
64612+#endif
64613 /* filesystem information */
64614 struct fs_struct *fs;
64615+
64616+ const struct cred __rcu *cred; /* effective (overridable) subjective task
64617+ * credentials (COW) */
64618+
64619 /* open file information */
64620 struct files_struct *files;
64621 /* namespaces */
64622@@ -1398,6 +1419,11 @@ struct task_struct {
64623 struct rt_mutex_waiter *pi_blocked_on;
64624 #endif
64625
64626+/* process credentials */
64627+ const struct cred __rcu *real_cred; /* objective and real subjective task
64628+ * credentials (COW) */
64629+ struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
64630+
64631 #ifdef CONFIG_DEBUG_MUTEXES
64632 /* mutex deadlock detection */
64633 struct mutex_waiter *blocked_on;
64634@@ -1508,6 +1534,21 @@ struct task_struct {
64635 unsigned long default_timer_slack_ns;
64636
64637 struct list_head *scm_work_list;
64638+
64639+#ifdef CONFIG_GRKERNSEC
64640+ /* grsecurity */
64641+ struct dentry *gr_chroot_dentry;
64642+ struct acl_subject_label *acl;
64643+ struct acl_role_label *role;
64644+ struct file *exec_file;
64645+ u16 acl_role_id;
64646+ /* is this the task that authenticated to the special role */
64647+ u8 acl_sp_role;
64648+ u8 is_writable;
64649+ u8 brute;
64650+ u8 gr_is_chrooted;
64651+#endif
64652+
64653 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
64654 /* Index of current stored address in ret_stack */
64655 int curr_ret_stack;
64656@@ -1542,6 +1583,57 @@ struct task_struct {
64657 #endif
64658 };
64659
64660+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
64661+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
64662+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
64663+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
64664+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
64665+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
64666+
64667+#ifdef CONFIG_PAX_SOFTMODE
64668+extern unsigned int pax_softmode;
64669+#endif
64670+
64671+extern int pax_check_flags(unsigned long *);
64672+
64673+/* if tsk != current then task_lock must be held on it */
64674+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
64675+static inline unsigned long pax_get_flags(struct task_struct *tsk)
64676+{
64677+ if (likely(tsk->mm))
64678+ return tsk->mm->pax_flags;
64679+ else
64680+ return 0UL;
64681+}
64682+
64683+/* if tsk != current then task_lock must be held on it */
64684+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
64685+{
64686+ if (likely(tsk->mm)) {
64687+ tsk->mm->pax_flags = flags;
64688+ return 0;
64689+ }
64690+ return -EINVAL;
64691+}
64692+#endif
64693+
64694+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
64695+extern void pax_set_initial_flags(struct linux_binprm *bprm);
64696+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
64697+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
64698+#endif
64699+
64700+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
64701+void pax_report_insns(void *pc, void *sp);
64702+void pax_report_refcount_overflow(struct pt_regs *regs);
64703+void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type);
64704+
64705+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
64706+extern void pax_track_stack(void);
64707+#else
64708+static inline void pax_track_stack(void) {}
64709+#endif
64710+
64711 /* Future-safe accessor for struct task_struct's cpus_allowed. */
64712 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
64713
64714@@ -2009,7 +2101,9 @@ void yield(void);
64715 extern struct exec_domain default_exec_domain;
64716
64717 union thread_union {
64718+#ifndef CONFIG_X86
64719 struct thread_info thread_info;
64720+#endif
64721 unsigned long stack[THREAD_SIZE/sizeof(long)];
64722 };
64723
64724@@ -2179,7 +2273,7 @@ extern void __cleanup_sighand(struct sig
64725 extern void exit_itimers(struct signal_struct *);
64726 extern void flush_itimer_signals(void);
64727
64728-extern NORET_TYPE void do_group_exit(int);
64729+extern NORET_TYPE void do_group_exit(int) ATTRIB_NORET;
64730
64731 extern void daemonize(const char *, ...);
64732 extern int allow_signal(int);
64733@@ -2320,13 +2414,17 @@ static inline unsigned long *end_of_stac
64734
64735 #endif
64736
64737-static inline int object_is_on_stack(void *obj)
64738+static inline int object_starts_on_stack(void *obj)
64739 {
64740- void *stack = task_stack_page(current);
64741+ const void *stack = task_stack_page(current);
64742
64743 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
64744 }
64745
64746+#ifdef CONFIG_PAX_USERCOPY
64747+extern int object_is_on_stack(const void *obj, unsigned long len);
64748+#endif
64749+
64750 extern void thread_info_cache_init(void);
64751
64752 #ifdef CONFIG_DEBUG_STACK_USAGE
64753diff -urNp linux-2.6.39.1/include/linux/screen_info.h linux-2.6.39.1/include/linux/screen_info.h
64754--- linux-2.6.39.1/include/linux/screen_info.h 2011-05-19 00:06:34.000000000 -0400
64755+++ linux-2.6.39.1/include/linux/screen_info.h 2011-05-22 19:36:33.000000000 -0400
64756@@ -43,7 +43,8 @@ struct screen_info {
64757 __u16 pages; /* 0x32 */
64758 __u16 vesa_attributes; /* 0x34 */
64759 __u32 capabilities; /* 0x36 */
64760- __u8 _reserved[6]; /* 0x3a */
64761+ __u16 vesapm_size; /* 0x3a */
64762+ __u8 _reserved[4]; /* 0x3c */
64763 } __attribute__((packed));
64764
64765 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
64766diff -urNp linux-2.6.39.1/include/linux/security.h linux-2.6.39.1/include/linux/security.h
64767--- linux-2.6.39.1/include/linux/security.h 2011-05-19 00:06:34.000000000 -0400
64768+++ linux-2.6.39.1/include/linux/security.h 2011-05-22 19:41:42.000000000 -0400
64769@@ -36,6 +36,7 @@
64770 #include <linux/key.h>
64771 #include <linux/xfrm.h>
64772 #include <linux/slab.h>
64773+#include <linux/grsecurity.h>
64774 #include <net/flow.h>
64775
64776 /* Maximum number of letters for an LSM name string */
64777diff -urNp linux-2.6.39.1/include/linux/shm.h linux-2.6.39.1/include/linux/shm.h
64778--- linux-2.6.39.1/include/linux/shm.h 2011-05-19 00:06:34.000000000 -0400
64779+++ linux-2.6.39.1/include/linux/shm.h 2011-05-22 19:41:42.000000000 -0400
64780@@ -95,6 +95,10 @@ struct shmid_kernel /* private to the ke
64781 pid_t shm_cprid;
64782 pid_t shm_lprid;
64783 struct user_struct *mlock_user;
64784+#ifdef CONFIG_GRKERNSEC
64785+ time_t shm_createtime;
64786+ pid_t shm_lapid;
64787+#endif
64788 };
64789
64790 /* shm_mode upper byte flags */
64791diff -urNp linux-2.6.39.1/include/linux/skbuff.h linux-2.6.39.1/include/linux/skbuff.h
64792--- linux-2.6.39.1/include/linux/skbuff.h 2011-05-19 00:06:34.000000000 -0400
64793+++ linux-2.6.39.1/include/linux/skbuff.h 2011-05-22 19:36:33.000000000 -0400
64794@@ -592,7 +592,7 @@ static inline struct skb_shared_hwtstamp
64795 */
64796 static inline int skb_queue_empty(const struct sk_buff_head *list)
64797 {
64798- return list->next == (struct sk_buff *)list;
64799+ return list->next == (const struct sk_buff *)list;
64800 }
64801
64802 /**
64803@@ -605,7 +605,7 @@ static inline int skb_queue_empty(const
64804 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
64805 const struct sk_buff *skb)
64806 {
64807- return skb->next == (struct sk_buff *)list;
64808+ return skb->next == (const struct sk_buff *)list;
64809 }
64810
64811 /**
64812@@ -618,7 +618,7 @@ static inline bool skb_queue_is_last(con
64813 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
64814 const struct sk_buff *skb)
64815 {
64816- return skb->prev == (struct sk_buff *)list;
64817+ return skb->prev == (const struct sk_buff *)list;
64818 }
64819
64820 /**
64821@@ -1435,7 +1435,7 @@ static inline int pskb_network_may_pull(
64822 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
64823 */
64824 #ifndef NET_SKB_PAD
64825-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
64826+#define NET_SKB_PAD max(_AC(32,U), L1_CACHE_BYTES)
64827 #endif
64828
64829 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
64830diff -urNp linux-2.6.39.1/include/linux/slab_def.h linux-2.6.39.1/include/linux/slab_def.h
64831--- linux-2.6.39.1/include/linux/slab_def.h 2011-05-19 00:06:34.000000000 -0400
64832+++ linux-2.6.39.1/include/linux/slab_def.h 2011-05-22 19:36:33.000000000 -0400
64833@@ -96,10 +96,10 @@ struct kmem_cache {
64834 unsigned long node_allocs;
64835 unsigned long node_frees;
64836 unsigned long node_overflow;
64837- atomic_t allochit;
64838- atomic_t allocmiss;
64839- atomic_t freehit;
64840- atomic_t freemiss;
64841+ atomic_unchecked_t allochit;
64842+ atomic_unchecked_t allocmiss;
64843+ atomic_unchecked_t freehit;
64844+ atomic_unchecked_t freemiss;
64845
64846 /*
64847 * If debugging is enabled, then the allocator can add additional
64848diff -urNp linux-2.6.39.1/include/linux/slab.h linux-2.6.39.1/include/linux/slab.h
64849--- linux-2.6.39.1/include/linux/slab.h 2011-05-19 00:06:34.000000000 -0400
64850+++ linux-2.6.39.1/include/linux/slab.h 2011-05-23 17:07:00.000000000 -0400
64851@@ -11,12 +11,20 @@
64852
64853 #include <linux/gfp.h>
64854 #include <linux/types.h>
64855+#include <linux/err.h>
64856
64857 /*
64858 * Flags to pass to kmem_cache_create().
64859 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
64860 */
64861 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
64862+
64863+#ifdef CONFIG_PAX_USERCOPY
64864+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
64865+#else
64866+#define SLAB_USERCOPY 0x00000000UL
64867+#endif
64868+
64869 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
64870 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
64871 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
64872@@ -87,10 +95,13 @@
64873 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
64874 * Both make kfree a no-op.
64875 */
64876-#define ZERO_SIZE_PTR ((void *)16)
64877+#define ZERO_SIZE_PTR \
64878+({ \
64879+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
64880+ (void *)(-MAX_ERRNO-1L); \
64881+})
64882
64883-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
64884- (unsigned long)ZERO_SIZE_PTR)
64885+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
64886
64887 /*
64888 * struct kmem_cache related prototypes
64889@@ -141,6 +152,7 @@ void * __must_check krealloc(const void
64890 void kfree(const void *);
64891 void kzfree(const void *);
64892 size_t ksize(const void *);
64893+void check_object_size(const void *ptr, unsigned long n, bool to);
64894
64895 /*
64896 * Allocator specific definitions. These are mainly used to establish optimized
64897@@ -333,4 +345,59 @@ static inline void *kzalloc_node(size_t
64898
64899 void __init kmem_cache_init_late(void);
64900
64901+#define kmalloc(x, y) \
64902+({ \
64903+ void *___retval; \
64904+ intoverflow_t ___x = (intoverflow_t)x; \
64905+ if (WARN(___x > ULONG_MAX, "kmalloc size overflow\n")) \
64906+ ___retval = NULL; \
64907+ else \
64908+ ___retval = kmalloc((size_t)___x, (y)); \
64909+ ___retval; \
64910+})
64911+
64912+#define kmalloc_node(x, y, z) \
64913+({ \
64914+ void *___retval; \
64915+ intoverflow_t ___x = (intoverflow_t)x; \
64916+ if (WARN(___x > ULONG_MAX, "kmalloc_node size overflow\n"))\
64917+ ___retval = NULL; \
64918+ else \
64919+ ___retval = kmalloc_node((size_t)___x, (y), (z));\
64920+ ___retval; \
64921+})
64922+
64923+#define kzalloc(x, y) \
64924+({ \
64925+ void *___retval; \
64926+ intoverflow_t ___x = (intoverflow_t)x; \
64927+ if (WARN(___x > ULONG_MAX, "kzalloc size overflow\n")) \
64928+ ___retval = NULL; \
64929+ else \
64930+ ___retval = kzalloc((size_t)___x, (y)); \
64931+ ___retval; \
64932+})
64933+
64934+#define __krealloc(x, y, z) \
64935+({ \
64936+ void *___retval; \
64937+ intoverflow_t ___y = (intoverflow_t)y; \
64938+ if (WARN(___y > ULONG_MAX, "__krealloc size overflow\n"))\
64939+ ___retval = NULL; \
64940+ else \
64941+ ___retval = __krealloc((x), (size_t)___y, (z)); \
64942+ ___retval; \
64943+})
64944+
64945+#define krealloc(x, y, z) \
64946+({ \
64947+ void *___retval; \
64948+ intoverflow_t ___y = (intoverflow_t)y; \
64949+ if (WARN(___y > ULONG_MAX, "krealloc size overflow\n")) \
64950+ ___retval = NULL; \
64951+ else \
64952+ ___retval = krealloc((x), (size_t)___y, (z)); \
64953+ ___retval; \
64954+})
64955+
64956 #endif /* _LINUX_SLAB_H */
64957diff -urNp linux-2.6.39.1/include/linux/slub_def.h linux-2.6.39.1/include/linux/slub_def.h
64958--- linux-2.6.39.1/include/linux/slub_def.h 2011-05-19 00:06:34.000000000 -0400
64959+++ linux-2.6.39.1/include/linux/slub_def.h 2011-05-22 19:36:33.000000000 -0400
64960@@ -84,7 +84,7 @@ struct kmem_cache {
64961 struct kmem_cache_order_objects max;
64962 struct kmem_cache_order_objects min;
64963 gfp_t allocflags; /* gfp flags to use on each alloc */
64964- int refcount; /* Refcount for slab cache destroy */
64965+ atomic_t refcount; /* Refcount for slab cache destroy */
64966 void (*ctor)(void *);
64967 int inuse; /* Offset to metadata */
64968 int align; /* Alignment */
64969diff -urNp linux-2.6.39.1/include/linux/sonet.h linux-2.6.39.1/include/linux/sonet.h
64970--- linux-2.6.39.1/include/linux/sonet.h 2011-05-19 00:06:34.000000000 -0400
64971+++ linux-2.6.39.1/include/linux/sonet.h 2011-05-22 19:36:33.000000000 -0400
64972@@ -61,7 +61,7 @@ struct sonet_stats {
64973 #include <asm/atomic.h>
64974
64975 struct k_sonet_stats {
64976-#define __HANDLE_ITEM(i) atomic_t i
64977+#define __HANDLE_ITEM(i) atomic_unchecked_t i
64978 __SONET_ITEMS
64979 #undef __HANDLE_ITEM
64980 };
64981diff -urNp linux-2.6.39.1/include/linux/ssb/ssb_driver_gige.h linux-2.6.39.1/include/linux/ssb/ssb_driver_gige.h
64982--- linux-2.6.39.1/include/linux/ssb/ssb_driver_gige.h 2011-05-19 00:06:34.000000000 -0400
64983+++ linux-2.6.39.1/include/linux/ssb/ssb_driver_gige.h 2011-05-22 19:36:33.000000000 -0400
64984@@ -44,7 +44,7 @@ struct ssb_gige {
64985
64986 /* The PCI controller device. */
64987 struct pci_controller pci_controller;
64988- struct pci_ops pci_ops;
64989+ const struct pci_ops pci_ops;
64990 struct resource mem_resource;
64991 struct resource io_resource;
64992 };
64993diff -urNp linux-2.6.39.1/include/linux/sunrpc/clnt.h linux-2.6.39.1/include/linux/sunrpc/clnt.h
64994--- linux-2.6.39.1/include/linux/sunrpc/clnt.h 2011-05-19 00:06:34.000000000 -0400
64995+++ linux-2.6.39.1/include/linux/sunrpc/clnt.h 2011-05-22 19:36:33.000000000 -0400
64996@@ -169,9 +169,9 @@ static inline unsigned short rpc_get_por
64997 {
64998 switch (sap->sa_family) {
64999 case AF_INET:
65000- return ntohs(((struct sockaddr_in *)sap)->sin_port);
65001+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
65002 case AF_INET6:
65003- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
65004+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
65005 }
65006 return 0;
65007 }
65008@@ -204,7 +204,7 @@ static inline bool __rpc_cmp_addr4(const
65009 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
65010 const struct sockaddr *src)
65011 {
65012- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
65013+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
65014 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
65015
65016 dsin->sin_family = ssin->sin_family;
65017@@ -301,7 +301,7 @@ static inline u32 rpc_get_scope_id(const
65018 if (sa->sa_family != AF_INET6)
65019 return 0;
65020
65021- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
65022+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
65023 }
65024
65025 #endif /* __KERNEL__ */
65026diff -urNp linux-2.6.39.1/include/linux/sunrpc/svc_rdma.h linux-2.6.39.1/include/linux/sunrpc/svc_rdma.h
65027--- linux-2.6.39.1/include/linux/sunrpc/svc_rdma.h 2011-05-19 00:06:34.000000000 -0400
65028+++ linux-2.6.39.1/include/linux/sunrpc/svc_rdma.h 2011-05-22 19:36:33.000000000 -0400
65029@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
65030 extern unsigned int svcrdma_max_requests;
65031 extern unsigned int svcrdma_max_req_size;
65032
65033-extern atomic_t rdma_stat_recv;
65034-extern atomic_t rdma_stat_read;
65035-extern atomic_t rdma_stat_write;
65036-extern atomic_t rdma_stat_sq_starve;
65037-extern atomic_t rdma_stat_rq_starve;
65038-extern atomic_t rdma_stat_rq_poll;
65039-extern atomic_t rdma_stat_rq_prod;
65040-extern atomic_t rdma_stat_sq_poll;
65041-extern atomic_t rdma_stat_sq_prod;
65042+extern atomic_unchecked_t rdma_stat_recv;
65043+extern atomic_unchecked_t rdma_stat_read;
65044+extern atomic_unchecked_t rdma_stat_write;
65045+extern atomic_unchecked_t rdma_stat_sq_starve;
65046+extern atomic_unchecked_t rdma_stat_rq_starve;
65047+extern atomic_unchecked_t rdma_stat_rq_poll;
65048+extern atomic_unchecked_t rdma_stat_rq_prod;
65049+extern atomic_unchecked_t rdma_stat_sq_poll;
65050+extern atomic_unchecked_t rdma_stat_sq_prod;
65051
65052 #define RPCRDMA_VERSION 1
65053
65054diff -urNp linux-2.6.39.1/include/linux/suspend.h linux-2.6.39.1/include/linux/suspend.h
65055--- linux-2.6.39.1/include/linux/suspend.h 2011-05-19 00:06:34.000000000 -0400
65056+++ linux-2.6.39.1/include/linux/suspend.h 2011-05-22 19:36:33.000000000 -0400
65057@@ -106,15 +106,15 @@ typedef int __bitwise suspend_state_t;
65058 * which require special recovery actions in that situation.
65059 */
65060 struct platform_suspend_ops {
65061- int (*valid)(suspend_state_t state);
65062- int (*begin)(suspend_state_t state);
65063- int (*prepare)(void);
65064- int (*prepare_late)(void);
65065- int (*enter)(suspend_state_t state);
65066- void (*wake)(void);
65067- void (*finish)(void);
65068- void (*end)(void);
65069- void (*recover)(void);
65070+ int (* const valid)(suspend_state_t state);
65071+ int (* const begin)(suspend_state_t state);
65072+ int (* const prepare)(void);
65073+ int (* const prepare_late)(void);
65074+ int (* const enter)(suspend_state_t state);
65075+ void (* const wake)(void);
65076+ void (* const finish)(void);
65077+ void (* const end)(void);
65078+ void (* const recover)(void);
65079 };
65080
65081 #ifdef CONFIG_SUSPEND
65082@@ -217,16 +217,16 @@ extern void mark_free_pages(struct zone
65083 * platforms which require special recovery actions in that situation.
65084 */
65085 struct platform_hibernation_ops {
65086- int (*begin)(void);
65087- void (*end)(void);
65088- int (*pre_snapshot)(void);
65089- void (*finish)(void);
65090- int (*prepare)(void);
65091- int (*enter)(void);
65092- void (*leave)(void);
65093- int (*pre_restore)(void);
65094- void (*restore_cleanup)(void);
65095- void (*recover)(void);
65096+ int (* const begin)(void);
65097+ void (* const end)(void);
65098+ int (* const pre_snapshot)(void);
65099+ void (* const finish)(void);
65100+ int (* const prepare)(void);
65101+ int (* const enter)(void);
65102+ void (* const leave)(void);
65103+ int (* const pre_restore)(void);
65104+ void (* const restore_cleanup)(void);
65105+ void (* const recover)(void);
65106 };
65107
65108 #ifdef CONFIG_HIBERNATION
65109diff -urNp linux-2.6.39.1/include/linux/sysctl.h linux-2.6.39.1/include/linux/sysctl.h
65110--- linux-2.6.39.1/include/linux/sysctl.h 2011-05-19 00:06:34.000000000 -0400
65111+++ linux-2.6.39.1/include/linux/sysctl.h 2011-05-22 19:41:42.000000000 -0400
65112@@ -155,7 +155,11 @@ enum
65113 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
65114 };
65115
65116-
65117+#ifdef CONFIG_PAX_SOFTMODE
65118+enum {
65119+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
65120+};
65121+#endif
65122
65123 /* CTL_VM names: */
65124 enum
65125@@ -967,6 +971,8 @@ typedef int proc_handler (struct ctl_tab
65126
65127 extern int proc_dostring(struct ctl_table *, int,
65128 void __user *, size_t *, loff_t *);
65129+extern int proc_dostring_modpriv(struct ctl_table *, int,
65130+ void __user *, size_t *, loff_t *);
65131 extern int proc_dointvec(struct ctl_table *, int,
65132 void __user *, size_t *, loff_t *);
65133 extern int proc_dointvec_minmax(struct ctl_table *, int,
65134diff -urNp linux-2.6.39.1/include/linux/sysfs.h linux-2.6.39.1/include/linux/sysfs.h
65135--- linux-2.6.39.1/include/linux/sysfs.h 2011-05-19 00:06:34.000000000 -0400
65136+++ linux-2.6.39.1/include/linux/sysfs.h 2011-05-22 19:36:33.000000000 -0400
65137@@ -110,8 +110,8 @@ struct bin_attribute {
65138 #define sysfs_bin_attr_init(bin_attr) sysfs_attr_init(&(bin_attr)->attr)
65139
65140 struct sysfs_ops {
65141- ssize_t (*show)(struct kobject *, struct attribute *,char *);
65142- ssize_t (*store)(struct kobject *,struct attribute *,const char *, size_t);
65143+ ssize_t (* const show)(struct kobject *, struct attribute *,char *);
65144+ ssize_t (* const store)(struct kobject *,struct attribute *,const char *, size_t);
65145 };
65146
65147 struct sysfs_dirent;
65148diff -urNp linux-2.6.39.1/include/linux/tty.h linux-2.6.39.1/include/linux/tty.h
65149--- linux-2.6.39.1/include/linux/tty.h 2011-05-19 00:06:34.000000000 -0400
65150+++ linux-2.6.39.1/include/linux/tty.h 2011-05-22 19:36:33.000000000 -0400
65151@@ -13,6 +13,7 @@
65152 #include <linux/tty_driver.h>
65153 #include <linux/tty_ldisc.h>
65154 #include <linux/mutex.h>
65155+#include <linux/poll.h>
65156
65157 #include <asm/system.h>
65158
65159@@ -466,7 +467,6 @@ extern int tty_perform_flush(struct tty_
65160 extern dev_t tty_devnum(struct tty_struct *tty);
65161 extern void proc_clear_tty(struct task_struct *p);
65162 extern struct tty_struct *get_current_tty(void);
65163-extern void tty_default_fops(struct file_operations *fops);
65164 extern struct tty_struct *alloc_tty_struct(void);
65165 extern int tty_add_file(struct tty_struct *tty, struct file *file);
65166 extern void free_tty_struct(struct tty_struct *tty);
65167@@ -529,6 +529,18 @@ extern void tty_ldisc_begin(void);
65168 /* This last one is just for the tty layer internals and shouldn't be used elsewhere */
65169 extern void tty_ldisc_enable(struct tty_struct *tty);
65170
65171+/* tty_io.c */
65172+extern ssize_t tty_read(struct file *, char __user *, size_t, loff_t *);
65173+extern ssize_t tty_write(struct file *, const char __user *, size_t, loff_t *);
65174+extern unsigned int tty_poll(struct file *, poll_table *);
65175+#ifdef CONFIG_COMPAT
65176+extern long tty_compat_ioctl(struct file *file, unsigned int cmd,
65177+ unsigned long arg);
65178+#else
65179+#define tty_compat_ioctl NULL
65180+#endif
65181+extern int tty_release(struct inode *, struct file *);
65182+extern int tty_fasync(int fd, struct file *filp, int on);
65183
65184 /* n_tty.c */
65185 extern struct tty_ldisc_ops tty_ldisc_N_TTY;
65186diff -urNp linux-2.6.39.1/include/linux/tty_ldisc.h linux-2.6.39.1/include/linux/tty_ldisc.h
65187--- linux-2.6.39.1/include/linux/tty_ldisc.h 2011-05-19 00:06:34.000000000 -0400
65188+++ linux-2.6.39.1/include/linux/tty_ldisc.h 2011-05-22 19:36:33.000000000 -0400
65189@@ -148,7 +148,7 @@ struct tty_ldisc_ops {
65190
65191 struct module *owner;
65192
65193- int refcount;
65194+ atomic_t refcount;
65195 };
65196
65197 struct tty_ldisc {
65198diff -urNp linux-2.6.39.1/include/linux/types.h linux-2.6.39.1/include/linux/types.h
65199--- linux-2.6.39.1/include/linux/types.h 2011-05-19 00:06:34.000000000 -0400
65200+++ linux-2.6.39.1/include/linux/types.h 2011-05-22 19:36:33.000000000 -0400
65201@@ -213,10 +213,26 @@ typedef struct {
65202 int counter;
65203 } atomic_t;
65204
65205+#ifdef CONFIG_PAX_REFCOUNT
65206+typedef struct {
65207+ int counter;
65208+} atomic_unchecked_t;
65209+#else
65210+typedef atomic_t atomic_unchecked_t;
65211+#endif
65212+
65213 #ifdef CONFIG_64BIT
65214 typedef struct {
65215 long counter;
65216 } atomic64_t;
65217+
65218+#ifdef CONFIG_PAX_REFCOUNT
65219+typedef struct {
65220+ long counter;
65221+} atomic64_unchecked_t;
65222+#else
65223+typedef atomic64_t atomic64_unchecked_t;
65224+#endif
65225 #endif
65226
65227 struct list_head {
65228diff -urNp linux-2.6.39.1/include/linux/uaccess.h linux-2.6.39.1/include/linux/uaccess.h
65229--- linux-2.6.39.1/include/linux/uaccess.h 2011-05-19 00:06:34.000000000 -0400
65230+++ linux-2.6.39.1/include/linux/uaccess.h 2011-05-22 19:36:33.000000000 -0400
65231@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_
65232 long ret; \
65233 mm_segment_t old_fs = get_fs(); \
65234 \
65235- set_fs(KERNEL_DS); \
65236 pagefault_disable(); \
65237+ set_fs(KERNEL_DS); \
65238 ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
65239- pagefault_enable(); \
65240 set_fs(old_fs); \
65241+ pagefault_enable(); \
65242 ret; \
65243 })
65244
65245@@ -93,8 +93,8 @@ static inline unsigned long __copy_from_
65246 * Safely read from address @src to the buffer at @dst. If a kernel fault
65247 * happens, handle that and return -EFAULT.
65248 */
65249-extern long probe_kernel_read(void *dst, void *src, size_t size);
65250-extern long __probe_kernel_read(void *dst, void *src, size_t size);
65251+extern long probe_kernel_read(void *dst, const void *src, size_t size);
65252+extern long __probe_kernel_read(void *dst, const void *src, size_t size);
65253
65254 /*
65255 * probe_kernel_write(): safely attempt to write to a location
65256@@ -105,7 +105,7 @@ extern long __probe_kernel_read(void *ds
65257 * Safely write to address @dst from the buffer at @src. If a kernel fault
65258 * happens, handle that and return -EFAULT.
65259 */
65260-extern long notrace probe_kernel_write(void *dst, void *src, size_t size);
65261-extern long notrace __probe_kernel_write(void *dst, void *src, size_t size);
65262+extern long notrace probe_kernel_write(void *dst, const void *src, size_t size);
65263+extern long notrace __probe_kernel_write(void *dst, const void *src, size_t size);
65264
65265 #endif /* __LINUX_UACCESS_H__ */
65266diff -urNp linux-2.6.39.1/include/linux/unaligned/access_ok.h linux-2.6.39.1/include/linux/unaligned/access_ok.h
65267--- linux-2.6.39.1/include/linux/unaligned/access_ok.h 2011-05-19 00:06:34.000000000 -0400
65268+++ linux-2.6.39.1/include/linux/unaligned/access_ok.h 2011-05-22 19:36:33.000000000 -0400
65269@@ -6,32 +6,32 @@
65270
65271 static inline u16 get_unaligned_le16(const void *p)
65272 {
65273- return le16_to_cpup((__le16 *)p);
65274+ return le16_to_cpup((const __le16 *)p);
65275 }
65276
65277 static inline u32 get_unaligned_le32(const void *p)
65278 {
65279- return le32_to_cpup((__le32 *)p);
65280+ return le32_to_cpup((const __le32 *)p);
65281 }
65282
65283 static inline u64 get_unaligned_le64(const void *p)
65284 {
65285- return le64_to_cpup((__le64 *)p);
65286+ return le64_to_cpup((const __le64 *)p);
65287 }
65288
65289 static inline u16 get_unaligned_be16(const void *p)
65290 {
65291- return be16_to_cpup((__be16 *)p);
65292+ return be16_to_cpup((const __be16 *)p);
65293 }
65294
65295 static inline u32 get_unaligned_be32(const void *p)
65296 {
65297- return be32_to_cpup((__be32 *)p);
65298+ return be32_to_cpup((const __be32 *)p);
65299 }
65300
65301 static inline u64 get_unaligned_be64(const void *p)
65302 {
65303- return be64_to_cpup((__be64 *)p);
65304+ return be64_to_cpup((const __be64 *)p);
65305 }
65306
65307 static inline void put_unaligned_le16(u16 val, void *p)
65308diff -urNp linux-2.6.39.1/include/linux/usb/hcd.h linux-2.6.39.1/include/linux/usb/hcd.h
65309--- linux-2.6.39.1/include/linux/usb/hcd.h 2011-05-19 00:06:34.000000000 -0400
65310+++ linux-2.6.39.1/include/linux/usb/hcd.h 2011-05-22 19:36:33.000000000 -0400
65311@@ -615,7 +615,7 @@ struct usb_mon_operations {
65312 /* void (*urb_unlink)(struct usb_bus *bus, struct urb *urb); */
65313 };
65314
65315-extern struct usb_mon_operations *mon_ops;
65316+extern const struct usb_mon_operations *mon_ops;
65317
65318 static inline void usbmon_urb_submit(struct usb_bus *bus, struct urb *urb)
65319 {
65320@@ -637,7 +637,7 @@ static inline void usbmon_urb_complete(s
65321 (*mon_ops->urb_complete)(bus, urb, status);
65322 }
65323
65324-int usb_mon_register(struct usb_mon_operations *ops);
65325+int usb_mon_register(const struct usb_mon_operations *ops);
65326 void usb_mon_deregister(void);
65327
65328 #else
65329diff -urNp linux-2.6.39.1/include/linux/usb/intel_mid_otg.h linux-2.6.39.1/include/linux/usb/intel_mid_otg.h
65330--- linux-2.6.39.1/include/linux/usb/intel_mid_otg.h 2011-05-19 00:06:34.000000000 -0400
65331+++ linux-2.6.39.1/include/linux/usb/intel_mid_otg.h 2011-05-22 19:36:33.000000000 -0400
65332@@ -115,7 +115,7 @@ struct intel_mid_otg_xceiv {
65333 void __iomem *base;
65334
65335 /* ops to access ulpi */
65336- struct iotg_ulpi_access_ops ulpi_ops;
65337+ const struct iotg_ulpi_access_ops ulpi_ops;
65338
65339 /* atomic notifier for interrupt context */
65340 struct atomic_notifier_head iotg_notifier;
65341diff -urNp linux-2.6.39.1/include/linux/usb/ulpi.h linux-2.6.39.1/include/linux/usb/ulpi.h
65342--- linux-2.6.39.1/include/linux/usb/ulpi.h 2011-05-19 00:06:34.000000000 -0400
65343+++ linux-2.6.39.1/include/linux/usb/ulpi.h 2011-05-22 19:36:33.000000000 -0400
65344@@ -186,7 +186,7 @@ struct otg_transceiver *otg_ulpi_create(
65345
65346 #ifdef CONFIG_USB_ULPI_VIEWPORT
65347 /* access ops for controllers with a viewport register */
65348-extern struct otg_io_access_ops ulpi_viewport_access_ops;
65349+extern const struct otg_io_access_ops ulpi_viewport_access_ops;
65350 #endif
65351
65352 #endif /* __LINUX_USB_ULPI_H */
65353diff -urNp linux-2.6.39.1/include/linux/vga_switcheroo.h linux-2.6.39.1/include/linux/vga_switcheroo.h
65354--- linux-2.6.39.1/include/linux/vga_switcheroo.h 2011-05-19 00:06:34.000000000 -0400
65355+++ linux-2.6.39.1/include/linux/vga_switcheroo.h 2011-05-22 19:36:33.000000000 -0400
65356@@ -39,7 +39,7 @@ int vga_switcheroo_register_client(struc
65357 void vga_switcheroo_client_fb_set(struct pci_dev *dev,
65358 struct fb_info *info);
65359
65360-int vga_switcheroo_register_handler(struct vga_switcheroo_handler *handler);
65361+int vga_switcheroo_register_handler(const struct vga_switcheroo_handler *handler);
65362 void vga_switcheroo_unregister_handler(void);
65363
65364 int vga_switcheroo_process_delayed_switch(void);
65365@@ -52,7 +52,7 @@ static inline int vga_switcheroo_registe
65366 void (*reprobe)(struct pci_dev *dev),
65367 bool (*can_switch)(struct pci_dev *dev)) { return 0; }
65368 static inline void vga_switcheroo_client_fb_set(struct pci_dev *dev, struct fb_info *info) {}
65369-static inline int vga_switcheroo_register_handler(struct vga_switcheroo_handler *handler) { return 0; }
65370+static inline int vga_switcheroo_register_handler(const struct vga_switcheroo_handler *handler) { return 0; }
65371 static inline void vga_switcheroo_unregister_handler(void) {}
65372 static inline int vga_switcheroo_process_delayed_switch(void) { return 0; }
65373
65374diff -urNp linux-2.6.39.1/include/linux/virtio.h linux-2.6.39.1/include/linux/virtio.h
65375--- linux-2.6.39.1/include/linux/virtio.h 2011-05-19 00:06:34.000000000 -0400
65376+++ linux-2.6.39.1/include/linux/virtio.h 2011-05-22 19:36:33.000000000 -0400
65377@@ -102,7 +102,7 @@ struct virtio_device {
65378 int index;
65379 struct device dev;
65380 struct virtio_device_id id;
65381- struct virtio_config_ops *config;
65382+ const struct virtio_config_ops *config;
65383 struct list_head vqs;
65384 /* Note that this is a Linux set_bit-style bitmap. */
65385 unsigned long features[1];
65386diff -urNp linux-2.6.39.1/include/linux/vmalloc.h linux-2.6.39.1/include/linux/vmalloc.h
65387--- linux-2.6.39.1/include/linux/vmalloc.h 2011-05-19 00:06:34.000000000 -0400
65388+++ linux-2.6.39.1/include/linux/vmalloc.h 2011-05-22 19:36:33.000000000 -0400
65389@@ -13,6 +13,11 @@ struct vm_area_struct; /* vma defining
65390 #define VM_MAP 0x00000004 /* vmap()ed pages */
65391 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
65392 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
65393+
65394+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
65395+#define VM_KERNEXEC 0x00000020 /* allocate from executable kernel memory range */
65396+#endif
65397+
65398 /* bits [20..32] reserved for arch specific ioremap internals */
65399
65400 /*
65401@@ -155,4 +160,103 @@ pcpu_free_vm_areas(struct vm_struct **vm
65402 # endif
65403 #endif
65404
65405+#define vmalloc(x) \
65406+({ \
65407+ void *___retval; \
65408+ intoverflow_t ___x = (intoverflow_t)x; \
65409+ if (WARN(___x > ULONG_MAX, "vmalloc size overflow\n")) \
65410+ ___retval = NULL; \
65411+ else \
65412+ ___retval = vmalloc((unsigned long)___x); \
65413+ ___retval; \
65414+})
65415+
65416+#define vzalloc(x) \
65417+({ \
65418+ void *___retval; \
65419+ intoverflow_t ___x = (intoverflow_t)x; \
65420+ if (WARN(___x > ULONG_MAX, "vzalloc size overflow\n")) \
65421+ ___retval = NULL; \
65422+ else \
65423+ ___retval = vzalloc((unsigned long)___x); \
65424+ ___retval; \
65425+})
65426+
65427+#define __vmalloc(x, y, z) \
65428+({ \
65429+ void *___retval; \
65430+ intoverflow_t ___x = (intoverflow_t)x; \
65431+ if (WARN(___x > ULONG_MAX, "__vmalloc size overflow\n"))\
65432+ ___retval = NULL; \
65433+ else \
65434+ ___retval = __vmalloc((unsigned long)___x, (y), (z));\
65435+ ___retval; \
65436+})
65437+
65438+#define vmalloc_user(x) \
65439+({ \
65440+ void *___retval; \
65441+ intoverflow_t ___x = (intoverflow_t)x; \
65442+ if (WARN(___x > ULONG_MAX, "vmalloc_user size overflow\n"))\
65443+ ___retval = NULL; \
65444+ else \
65445+ ___retval = vmalloc_user((unsigned long)___x); \
65446+ ___retval; \
65447+})
65448+
65449+#define vmalloc_exec(x) \
65450+({ \
65451+ void *___retval; \
65452+ intoverflow_t ___x = (intoverflow_t)x; \
65453+ if (WARN(___x > ULONG_MAX, "vmalloc_exec size overflow\n"))\
65454+ ___retval = NULL; \
65455+ else \
65456+ ___retval = vmalloc_exec((unsigned long)___x); \
65457+ ___retval; \
65458+})
65459+
65460+#define vmalloc_node(x, y) \
65461+({ \
65462+ void *___retval; \
65463+ intoverflow_t ___x = (intoverflow_t)x; \
65464+ if (WARN(___x > ULONG_MAX, "vmalloc_node size overflow\n"))\
65465+ ___retval = NULL; \
65466+ else \
65467+ ___retval = vmalloc_node((unsigned long)___x, (y));\
65468+ ___retval; \
65469+})
65470+
65471+#define vzalloc_node(x, y) \
65472+({ \
65473+ void *___retval; \
65474+ intoverflow_t ___x = (intoverflow_t)x; \
65475+ if (WARN(___x > ULONG_MAX, "vzalloc_node size overflow\n"))\
65476+ ___retval = NULL; \
65477+ else \
65478+ ___retval = vzalloc_node((unsigned long)___x, (y));\
65479+ ___retval; \
65480+})
65481+
65482+#define vmalloc_32(x) \
65483+({ \
65484+ void *___retval; \
65485+ intoverflow_t ___x = (intoverflow_t)x; \
65486+ if (WARN(___x > ULONG_MAX, "vmalloc_32 size overflow\n"))\
65487+ ___retval = NULL; \
65488+ else \
65489+ ___retval = vmalloc_32((unsigned long)___x); \
65490+ ___retval; \
65491+})
65492+
65493+#define vmalloc_32_user(x) \
65494+({ \
65495+void *___retval; \
65496+ intoverflow_t ___x = (intoverflow_t)x; \
65497+ if (WARN(___x > ULONG_MAX, "vmalloc_32_user size overflow\n"))\
65498+ ___retval = NULL; \
65499+ else \
65500+ ___retval = vmalloc_32_user((unsigned long)___x);\
65501+ ___retval; \
65502+})
65503+
65504 #endif /* _LINUX_VMALLOC_H */
65505diff -urNp linux-2.6.39.1/include/linux/vmstat.h linux-2.6.39.1/include/linux/vmstat.h
65506--- linux-2.6.39.1/include/linux/vmstat.h 2011-05-19 00:06:34.000000000 -0400
65507+++ linux-2.6.39.1/include/linux/vmstat.h 2011-05-22 19:36:33.000000000 -0400
65508@@ -147,18 +147,18 @@ static inline void vm_events_fold_cpu(in
65509 /*
65510 * Zone based page accounting with per cpu differentials.
65511 */
65512-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65513+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65514
65515 static inline void zone_page_state_add(long x, struct zone *zone,
65516 enum zone_stat_item item)
65517 {
65518- atomic_long_add(x, &zone->vm_stat[item]);
65519- atomic_long_add(x, &vm_stat[item]);
65520+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
65521+ atomic_long_add_unchecked(x, &vm_stat[item]);
65522 }
65523
65524 static inline unsigned long global_page_state(enum zone_stat_item item)
65525 {
65526- long x = atomic_long_read(&vm_stat[item]);
65527+ long x = atomic_long_read_unchecked(&vm_stat[item]);
65528 #ifdef CONFIG_SMP
65529 if (x < 0)
65530 x = 0;
65531@@ -169,7 +169,7 @@ static inline unsigned long global_page_
65532 static inline unsigned long zone_page_state(struct zone *zone,
65533 enum zone_stat_item item)
65534 {
65535- long x = atomic_long_read(&zone->vm_stat[item]);
65536+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
65537 #ifdef CONFIG_SMP
65538 if (x < 0)
65539 x = 0;
65540@@ -186,7 +186,7 @@ static inline unsigned long zone_page_st
65541 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
65542 enum zone_stat_item item)
65543 {
65544- long x = atomic_long_read(&zone->vm_stat[item]);
65545+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
65546
65547 #ifdef CONFIG_SMP
65548 int cpu;
65549@@ -280,8 +280,8 @@ static inline void __mod_zone_page_state
65550
65551 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
65552 {
65553- atomic_long_inc(&zone->vm_stat[item]);
65554- atomic_long_inc(&vm_stat[item]);
65555+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
65556+ atomic_long_inc_unchecked(&vm_stat[item]);
65557 }
65558
65559 static inline void __inc_zone_page_state(struct page *page,
65560@@ -292,8 +292,8 @@ static inline void __inc_zone_page_state
65561
65562 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
65563 {
65564- atomic_long_dec(&zone->vm_stat[item]);
65565- atomic_long_dec(&vm_stat[item]);
65566+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
65567+ atomic_long_dec_unchecked(&vm_stat[item]);
65568 }
65569
65570 static inline void __dec_zone_page_state(struct page *page,
65571diff -urNp linux-2.6.39.1/include/media/saa7146_vv.h linux-2.6.39.1/include/media/saa7146_vv.h
65572--- linux-2.6.39.1/include/media/saa7146_vv.h 2011-05-19 00:06:34.000000000 -0400
65573+++ linux-2.6.39.1/include/media/saa7146_vv.h 2011-05-22 19:36:33.000000000 -0400
65574@@ -202,13 +202,13 @@ void saa7146_set_gpio(struct saa7146_dev
65575
65576 /* from saa7146_video.c */
65577 extern const struct v4l2_ioctl_ops saa7146_video_ioctl_ops;
65578-extern struct saa7146_use_ops saa7146_video_uops;
65579+extern const struct saa7146_use_ops saa7146_video_uops;
65580 int saa7146_start_preview(struct saa7146_fh *fh);
65581 int saa7146_stop_preview(struct saa7146_fh *fh);
65582 long saa7146_video_do_ioctl(struct file *file, unsigned int cmd, void *arg);
65583
65584 /* from saa7146_vbi.c */
65585-extern struct saa7146_use_ops saa7146_vbi_uops;
65586+extern const struct saa7146_use_ops saa7146_vbi_uops;
65587
65588 /* resource management functions */
65589 int saa7146_res_get(struct saa7146_fh *fh, unsigned int bit);
65590diff -urNp linux-2.6.39.1/include/media/v4l2-device.h linux-2.6.39.1/include/media/v4l2-device.h
65591--- linux-2.6.39.1/include/media/v4l2-device.h 2011-05-19 00:06:34.000000000 -0400
65592+++ linux-2.6.39.1/include/media/v4l2-device.h 2011-05-22 19:36:33.000000000 -0400
65593@@ -95,7 +95,7 @@ int __must_check v4l2_device_register(st
65594 this function returns 0. If the name ends with a digit (e.g. cx18),
65595 then the name will be set to cx18-0 since cx180 looks really odd. */
65596 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
65597- atomic_t *instance);
65598+ atomic_unchecked_t *instance);
65599
65600 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
65601 Since the parent disappears this ensures that v4l2_dev doesn't have an
65602diff -urNp linux-2.6.39.1/include/net/caif/cfctrl.h linux-2.6.39.1/include/net/caif/cfctrl.h
65603--- linux-2.6.39.1/include/net/caif/cfctrl.h 2011-05-19 00:06:34.000000000 -0400
65604+++ linux-2.6.39.1/include/net/caif/cfctrl.h 2011-05-22 19:36:33.000000000 -0400
65605@@ -101,8 +101,8 @@ struct cfctrl_request_info {
65606 struct cfctrl {
65607 struct cfsrvl serv;
65608 struct cfctrl_rsp res;
65609- atomic_t req_seq_no;
65610- atomic_t rsp_seq_no;
65611+ atomic_unchecked_t req_seq_no;
65612+ atomic_unchecked_t rsp_seq_no;
65613 struct list_head list;
65614 /* Protects from simultaneous access to first_req list */
65615 spinlock_t info_list_lock;
65616diff -urNp linux-2.6.39.1/include/net/flow.h linux-2.6.39.1/include/net/flow.h
65617--- linux-2.6.39.1/include/net/flow.h 2011-05-19 00:06:34.000000000 -0400
65618+++ linux-2.6.39.1/include/net/flow.h 2011-05-22 19:36:33.000000000 -0400
65619@@ -167,6 +167,6 @@ extern struct flow_cache_object *flow_ca
65620 u8 dir, flow_resolve_t resolver, void *ctx);
65621
65622 extern void flow_cache_flush(void);
65623-extern atomic_t flow_cache_genid;
65624+extern atomic_unchecked_t flow_cache_genid;
65625
65626 #endif
65627diff -urNp linux-2.6.39.1/include/net/inetpeer.h linux-2.6.39.1/include/net/inetpeer.h
65628--- linux-2.6.39.1/include/net/inetpeer.h 2011-05-19 00:06:34.000000000 -0400
65629+++ linux-2.6.39.1/include/net/inetpeer.h 2011-05-22 19:36:33.000000000 -0400
65630@@ -43,8 +43,8 @@ struct inet_peer {
65631 */
65632 union {
65633 struct {
65634- atomic_t rid; /* Frag reception counter */
65635- atomic_t ip_id_count; /* IP ID for the next packet */
65636+ atomic_unchecked_t rid; /* Frag reception counter */
65637+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
65638 __u32 tcp_ts;
65639 __u32 tcp_ts_stamp;
65640 u32 metrics[RTAX_MAX];
65641@@ -108,7 +108,7 @@ static inline __u16 inet_getid(struct in
65642 {
65643 more++;
65644 inet_peer_refcheck(p);
65645- return atomic_add_return(more, &p->ip_id_count) - more;
65646+ return atomic_add_return_unchecked(more, &p->ip_id_count) - more;
65647 }
65648
65649 #endif /* _NET_INETPEER_H */
65650diff -urNp linux-2.6.39.1/include/net/ip_fib.h linux-2.6.39.1/include/net/ip_fib.h
65651--- linux-2.6.39.1/include/net/ip_fib.h 2011-05-19 00:06:34.000000000 -0400
65652+++ linux-2.6.39.1/include/net/ip_fib.h 2011-05-22 19:36:33.000000000 -0400
65653@@ -146,7 +146,7 @@ extern __be32 fib_info_update_nh_saddr(s
65654
65655 #define FIB_RES_SADDR(net, res) \
65656 ((FIB_RES_NH(res).nh_saddr_genid == \
65657- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
65658+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
65659 FIB_RES_NH(res).nh_saddr : \
65660 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
65661 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
65662diff -urNp linux-2.6.39.1/include/net/ip_vs.h linux-2.6.39.1/include/net/ip_vs.h
65663--- linux-2.6.39.1/include/net/ip_vs.h 2011-05-19 00:06:34.000000000 -0400
65664+++ linux-2.6.39.1/include/net/ip_vs.h 2011-05-22 19:36:33.000000000 -0400
65665@@ -512,7 +512,7 @@ struct ip_vs_conn {
65666 struct ip_vs_conn *control; /* Master control connection */
65667 atomic_t n_control; /* Number of controlled ones */
65668 struct ip_vs_dest *dest; /* real server */
65669- atomic_t in_pkts; /* incoming packet counter */
65670+ atomic_unchecked_t in_pkts; /* incoming packet counter */
65671
65672 /* packet transmitter for different forwarding methods. If it
65673 mangles the packet, it must return NF_DROP or better NF_STOLEN,
65674@@ -650,7 +650,7 @@ struct ip_vs_dest {
65675 __be16 port; /* port number of the server */
65676 union nf_inet_addr addr; /* IP address of the server */
65677 volatile unsigned flags; /* dest status flags */
65678- atomic_t conn_flags; /* flags to copy to conn */
65679+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
65680 atomic_t weight; /* server weight */
65681
65682 atomic_t refcnt; /* reference counter */
65683diff -urNp linux-2.6.39.1/include/net/irda/ircomm_tty.h linux-2.6.39.1/include/net/irda/ircomm_tty.h
65684--- linux-2.6.39.1/include/net/irda/ircomm_tty.h 2011-05-19 00:06:34.000000000 -0400
65685+++ linux-2.6.39.1/include/net/irda/ircomm_tty.h 2011-05-22 19:36:33.000000000 -0400
65686@@ -35,6 +35,7 @@
65687 #include <linux/termios.h>
65688 #include <linux/timer.h>
65689 #include <linux/tty.h> /* struct tty_struct */
65690+#include <asm/local.h>
65691
65692 #include <net/irda/irias_object.h>
65693 #include <net/irda/ircomm_core.h>
65694@@ -105,8 +106,8 @@ struct ircomm_tty_cb {
65695 unsigned short close_delay;
65696 unsigned short closing_wait; /* time to wait before closing */
65697
65698- int open_count;
65699- int blocked_open; /* # of blocked opens */
65700+ local_t open_count;
65701+ local_t blocked_open; /* # of blocked opens */
65702
65703 /* Protect concurent access to :
65704 * o self->open_count
65705diff -urNp linux-2.6.39.1/include/net/iucv/af_iucv.h linux-2.6.39.1/include/net/iucv/af_iucv.h
65706--- linux-2.6.39.1/include/net/iucv/af_iucv.h 2011-05-19 00:06:34.000000000 -0400
65707+++ linux-2.6.39.1/include/net/iucv/af_iucv.h 2011-05-22 19:36:33.000000000 -0400
65708@@ -87,7 +87,7 @@ struct iucv_sock {
65709 struct iucv_sock_list {
65710 struct hlist_head head;
65711 rwlock_t lock;
65712- atomic_t autobind_name;
65713+ atomic_unchecked_t autobind_name;
65714 };
65715
65716 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
65717diff -urNp linux-2.6.39.1/include/net/neighbour.h linux-2.6.39.1/include/net/neighbour.h
65718--- linux-2.6.39.1/include/net/neighbour.h 2011-05-19 00:06:34.000000000 -0400
65719+++ linux-2.6.39.1/include/net/neighbour.h 2011-05-22 19:36:33.000000000 -0400
65720@@ -118,12 +118,12 @@ struct neighbour {
65721
65722 struct neigh_ops {
65723 int family;
65724- void (*solicit)(struct neighbour *, struct sk_buff*);
65725- void (*error_report)(struct neighbour *, struct sk_buff*);
65726- int (*output)(struct sk_buff*);
65727- int (*connected_output)(struct sk_buff*);
65728- int (*hh_output)(struct sk_buff*);
65729- int (*queue_xmit)(struct sk_buff*);
65730+ void (* const solicit)(struct neighbour *, struct sk_buff*);
65731+ void (* const error_report)(struct neighbour *, struct sk_buff*);
65732+ int (* const output)(struct sk_buff*);
65733+ int (* const connected_output)(struct sk_buff*);
65734+ int (* const hh_output)(struct sk_buff*);
65735+ int (* const queue_xmit)(struct sk_buff*);
65736 };
65737
65738 struct pneigh_entry {
65739diff -urNp linux-2.6.39.1/include/net/netfilter/nf_conntrack_ecache.h linux-2.6.39.1/include/net/netfilter/nf_conntrack_ecache.h
65740--- linux-2.6.39.1/include/net/netfilter/nf_conntrack_ecache.h 2011-05-19 00:06:34.000000000 -0400
65741+++ linux-2.6.39.1/include/net/netfilter/nf_conntrack_ecache.h 2011-05-22 19:36:33.000000000 -0400
65742@@ -95,7 +95,7 @@ nf_conntrack_eventmask_report(unsigned i
65743 int report)
65744 {
65745 int ret = 0;
65746- struct nf_ct_event_notifier *notify;
65747+ const struct nf_ct_event_notifier *notify;
65748 struct nf_conntrack_ecache *e;
65749
65750 rcu_read_lock();
65751@@ -174,7 +174,7 @@ nf_ct_expect_event_report(enum ip_conntr
65752 u32 pid,
65753 int report)
65754 {
65755- struct nf_exp_event_notifier *notify;
65756+ const struct nf_exp_event_notifier *notify;
65757 struct nf_conntrack_ecache *e;
65758
65759 rcu_read_lock();
65760diff -urNp linux-2.6.39.1/include/net/netlink.h linux-2.6.39.1/include/net/netlink.h
65761--- linux-2.6.39.1/include/net/netlink.h 2011-05-19 00:06:34.000000000 -0400
65762+++ linux-2.6.39.1/include/net/netlink.h 2011-05-22 19:36:33.000000000 -0400
65763@@ -562,7 +562,7 @@ static inline void *nlmsg_get_pos(struct
65764 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
65765 {
65766 if (mark)
65767- skb_trim(skb, (unsigned char *) mark - skb->data);
65768+ skb_trim(skb, (const unsigned char *) mark - skb->data);
65769 }
65770
65771 /**
65772diff -urNp linux-2.6.39.1/include/net/netns/ipv4.h linux-2.6.39.1/include/net/netns/ipv4.h
65773--- linux-2.6.39.1/include/net/netns/ipv4.h 2011-05-19 00:06:34.000000000 -0400
65774+++ linux-2.6.39.1/include/net/netns/ipv4.h 2011-05-22 19:36:33.000000000 -0400
65775@@ -54,8 +54,8 @@ struct netns_ipv4 {
65776 int sysctl_rt_cache_rebuild_count;
65777 int current_rt_cache_rebuild_count;
65778
65779- atomic_t rt_genid;
65780- atomic_t dev_addr_genid;
65781+ atomic_unchecked_t rt_genid;
65782+ atomic_unchecked_t dev_addr_genid;
65783
65784 #ifdef CONFIG_IP_MROUTE
65785 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
65786diff -urNp linux-2.6.39.1/include/net/sctp/sctp.h linux-2.6.39.1/include/net/sctp/sctp.h
65787--- linux-2.6.39.1/include/net/sctp/sctp.h 2011-05-19 00:06:34.000000000 -0400
65788+++ linux-2.6.39.1/include/net/sctp/sctp.h 2011-05-22 19:36:33.000000000 -0400
65789@@ -316,9 +316,9 @@ do { \
65790
65791 #else /* SCTP_DEBUG */
65792
65793-#define SCTP_DEBUG_PRINTK(whatever...)
65794-#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
65795-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
65796+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
65797+#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
65798+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
65799 #define SCTP_ENABLE_DEBUG
65800 #define SCTP_DISABLE_DEBUG
65801 #define SCTP_ASSERT(expr, str, func)
65802diff -urNp linux-2.6.39.1/include/net/sock.h linux-2.6.39.1/include/net/sock.h
65803--- linux-2.6.39.1/include/net/sock.h 2011-05-19 00:06:34.000000000 -0400
65804+++ linux-2.6.39.1/include/net/sock.h 2011-05-22 19:36:33.000000000 -0400
65805@@ -277,7 +277,7 @@ struct sock {
65806 #ifdef CONFIG_RPS
65807 __u32 sk_rxhash;
65808 #endif
65809- atomic_t sk_drops;
65810+ atomic_unchecked_t sk_drops;
65811 int sk_rcvbuf;
65812
65813 struct sk_filter __rcu *sk_filter;
65814diff -urNp linux-2.6.39.1/include/net/tcp.h linux-2.6.39.1/include/net/tcp.h
65815--- linux-2.6.39.1/include/net/tcp.h 2011-05-19 00:06:34.000000000 -0400
65816+++ linux-2.6.39.1/include/net/tcp.h 2011-05-22 19:36:33.000000000 -0400
65817@@ -1374,7 +1374,7 @@ enum tcp_seq_states {
65818 struct tcp_seq_afinfo {
65819 char *name;
65820 sa_family_t family;
65821- struct file_operations seq_fops;
65822+ struct file_operations seq_fops; /* cannot be const */
65823 struct seq_operations seq_ops;
65824 };
65825
65826diff -urNp linux-2.6.39.1/include/net/udp.h linux-2.6.39.1/include/net/udp.h
65827--- linux-2.6.39.1/include/net/udp.h 2011-05-19 00:06:34.000000000 -0400
65828+++ linux-2.6.39.1/include/net/udp.h 2011-05-22 19:36:33.000000000 -0400
65829@@ -234,7 +234,7 @@ struct udp_seq_afinfo {
65830 char *name;
65831 sa_family_t family;
65832 struct udp_table *udp_table;
65833- struct file_operations seq_fops;
65834+ struct file_operations seq_fops; /* cannot be const */
65835 struct seq_operations seq_ops;
65836 };
65837
65838diff -urNp linux-2.6.39.1/include/net/xfrm.h linux-2.6.39.1/include/net/xfrm.h
65839--- linux-2.6.39.1/include/net/xfrm.h 2011-05-19 00:06:34.000000000 -0400
65840+++ linux-2.6.39.1/include/net/xfrm.h 2011-05-22 19:36:33.000000000 -0400
65841@@ -505,7 +505,7 @@ struct xfrm_policy {
65842 struct timer_list timer;
65843
65844 struct flow_cache_object flo;
65845- atomic_t genid;
65846+ atomic_unchecked_t genid;
65847 u32 priority;
65848 u32 index;
65849 struct xfrm_mark mark;
65850diff -urNp linux-2.6.39.1/include/pcmcia/ss.h linux-2.6.39.1/include/pcmcia/ss.h
65851--- linux-2.6.39.1/include/pcmcia/ss.h 2011-05-19 00:06:34.000000000 -0400
65852+++ linux-2.6.39.1/include/pcmcia/ss.h 2011-05-22 19:36:33.000000000 -0400
65853@@ -241,9 +241,9 @@ struct pcmcia_socket {
65854 * "select PCCARD_NONSTATIC" in Kconfig.
65855 *
65856 */
65857-extern struct pccard_resource_ops pccard_static_ops;
65858+extern const struct pccard_resource_ops pccard_static_ops;
65859 #if defined(CONFIG_PCMCIA) || defined(CONFIG_PCMCIA_MODULE)
65860-extern struct pccard_resource_ops pccard_iodyn_ops;
65861+extern const struct pccard_resource_ops pccard_iodyn_ops;
65862 extern struct pccard_resource_ops pccard_nonstatic_ops;
65863 #else
65864 /* If PCMCIA is not used, but only CARDBUS, these functions are not used
65865diff -urNp linux-2.6.39.1/include/rdma/ib_verbs.h linux-2.6.39.1/include/rdma/ib_verbs.h
65866--- linux-2.6.39.1/include/rdma/ib_verbs.h 2011-05-19 00:06:34.000000000 -0400
65867+++ linux-2.6.39.1/include/rdma/ib_verbs.h 2011-05-22 19:36:33.000000000 -0400
65868@@ -1149,7 +1149,7 @@ struct ib_device {
65869 struct ib_mad *in_mad,
65870 struct ib_mad *out_mad);
65871
65872- struct ib_dma_mapping_ops *dma_ops;
65873+ const struct ib_dma_mapping_ops *dma_ops;
65874
65875 struct module *owner;
65876 struct device dev;
65877diff -urNp linux-2.6.39.1/include/scsi/libfc.h linux-2.6.39.1/include/scsi/libfc.h
65878--- linux-2.6.39.1/include/scsi/libfc.h 2011-05-19 00:06:34.000000000 -0400
65879+++ linux-2.6.39.1/include/scsi/libfc.h 2011-05-22 19:36:33.000000000 -0400
65880@@ -202,7 +202,7 @@ struct fc_rport_priv {
65881 struct mutex rp_mutex;
65882 struct delayed_work retry_work;
65883 enum fc_rport_event event;
65884- struct fc_rport_operations *ops;
65885+ const struct fc_rport_operations *ops;
65886 struct list_head peers;
65887 struct work_struct event_work;
65888 u32 supported_classes;
65889diff -urNp linux-2.6.39.1/include/scsi/scsi_device.h linux-2.6.39.1/include/scsi/scsi_device.h
65890--- linux-2.6.39.1/include/scsi/scsi_device.h 2011-05-19 00:06:34.000000000 -0400
65891+++ linux-2.6.39.1/include/scsi/scsi_device.h 2011-05-22 19:36:33.000000000 -0400
65892@@ -161,9 +161,9 @@ struct scsi_device {
65893 unsigned int max_device_blocked; /* what device_blocked counts down from */
65894 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
65895
65896- atomic_t iorequest_cnt;
65897- atomic_t iodone_cnt;
65898- atomic_t ioerr_cnt;
65899+ atomic_unchecked_t iorequest_cnt;
65900+ atomic_unchecked_t iodone_cnt;
65901+ atomic_unchecked_t ioerr_cnt;
65902
65903 struct device sdev_gendev,
65904 sdev_dev;
65905diff -urNp linux-2.6.39.1/include/sound/ac97_codec.h linux-2.6.39.1/include/sound/ac97_codec.h
65906--- linux-2.6.39.1/include/sound/ac97_codec.h 2011-05-19 00:06:34.000000000 -0400
65907+++ linux-2.6.39.1/include/sound/ac97_codec.h 2011-05-22 19:36:33.000000000 -0400
65908@@ -424,15 +424,15 @@
65909 struct snd_ac97;
65910
65911 struct snd_ac97_build_ops {
65912- int (*build_3d) (struct snd_ac97 *ac97);
65913- int (*build_specific) (struct snd_ac97 *ac97);
65914- int (*build_spdif) (struct snd_ac97 *ac97);
65915- int (*build_post_spdif) (struct snd_ac97 *ac97);
65916+ int (* const build_3d) (struct snd_ac97 *ac97);
65917+ int (* const build_specific) (struct snd_ac97 *ac97);
65918+ int (* const build_spdif) (struct snd_ac97 *ac97);
65919+ int (* const build_post_spdif) (struct snd_ac97 *ac97);
65920 #ifdef CONFIG_PM
65921- void (*suspend) (struct snd_ac97 *ac97);
65922- void (*resume) (struct snd_ac97 *ac97);
65923+ void (* const suspend) (struct snd_ac97 *ac97);
65924+ void (* const resume) (struct snd_ac97 *ac97);
65925 #endif
65926- void (*update_jacks) (struct snd_ac97 *ac97); /* for jack-sharing */
65927+ void (* const update_jacks) (struct snd_ac97 *ac97); /* for jack-sharing */
65928 };
65929
65930 struct snd_ac97_bus_ops {
65931@@ -446,7 +446,7 @@ struct snd_ac97_bus_ops {
65932
65933 struct snd_ac97_bus {
65934 /* -- lowlevel (hardware) driver specific -- */
65935- struct snd_ac97_bus_ops *ops;
65936+ const struct snd_ac97_bus_ops *ops;
65937 void *private_data;
65938 void (*private_free) (struct snd_ac97_bus *bus);
65939 /* --- */
65940@@ -556,7 +556,7 @@ static inline int ac97_can_spdif(struct
65941
65942 /* functions */
65943 /* create new AC97 bus */
65944-int snd_ac97_bus(struct snd_card *card, int num, struct snd_ac97_bus_ops *ops,
65945+int snd_ac97_bus(struct snd_card *card, int num, const struct snd_ac97_bus_ops *ops,
65946 void *private_data, struct snd_ac97_bus **rbus);
65947 /* create mixer controls */
65948 int snd_ac97_mixer(struct snd_ac97_bus *bus, struct snd_ac97_template *template,
65949diff -urNp linux-2.6.39.1/include/sound/core.h linux-2.6.39.1/include/sound/core.h
65950--- linux-2.6.39.1/include/sound/core.h 2011-05-19 00:06:34.000000000 -0400
65951+++ linux-2.6.39.1/include/sound/core.h 2011-05-22 19:36:33.000000000 -0400
65952@@ -88,7 +88,7 @@ struct snd_device {
65953 snd_device_state_t state; /* state of the device */
65954 snd_device_type_t type; /* device type */
65955 void *device_data; /* device structure */
65956- struct snd_device_ops *ops; /* operations */
65957+ const struct snd_device_ops *ops; /* operations */
65958 };
65959
65960 #define snd_device(n) list_entry(n, struct snd_device, list)
65961@@ -301,7 +301,7 @@ int snd_card_file_remove(struct snd_card
65962 /* device.c */
65963
65964 int snd_device_new(struct snd_card *card, snd_device_type_t type,
65965- void *device_data, struct snd_device_ops *ops);
65966+ void *device_data, const struct snd_device_ops *ops);
65967 int snd_device_register(struct snd_card *card, void *device_data);
65968 int snd_device_register_all(struct snd_card *card);
65969 int snd_device_disconnect(struct snd_card *card, void *device_data);
65970diff -urNp linux-2.6.39.1/include/sound/pcm.h linux-2.6.39.1/include/sound/pcm.h
65971--- linux-2.6.39.1/include/sound/pcm.h 2011-05-19 00:06:34.000000000 -0400
65972+++ linux-2.6.39.1/include/sound/pcm.h 2011-05-22 19:36:33.000000000 -0400
65973@@ -379,7 +379,7 @@ struct snd_pcm_substream {
65974 unsigned int dma_buf_id;
65975 size_t dma_max;
65976 /* -- hardware operations -- */
65977- struct snd_pcm_ops *ops;
65978+ const struct snd_pcm_ops *ops;
65979 /* -- runtime information -- */
65980 struct snd_pcm_runtime *runtime;
65981 /* -- timer section -- */
65982@@ -845,7 +845,7 @@ const unsigned char *snd_pcm_format_sile
65983 int snd_pcm_format_set_silence(snd_pcm_format_t format, void *buf, unsigned int frames);
65984 snd_pcm_format_t snd_pcm_build_linear_format(int width, int unsignd, int big_endian);
65985
65986-void snd_pcm_set_ops(struct snd_pcm * pcm, int direction, struct snd_pcm_ops *ops);
65987+void snd_pcm_set_ops(struct snd_pcm * pcm, int direction, const struct snd_pcm_ops *ops);
65988 void snd_pcm_set_sync(struct snd_pcm_substream *substream);
65989 int snd_pcm_lib_interleave_len(struct snd_pcm_substream *substream);
65990 int snd_pcm_lib_ioctl(struct snd_pcm_substream *substream,
65991diff -urNp linux-2.6.39.1/include/sound/rawmidi.h linux-2.6.39.1/include/sound/rawmidi.h
65992--- linux-2.6.39.1/include/sound/rawmidi.h 2011-05-19 00:06:34.000000000 -0400
65993+++ linux-2.6.39.1/include/sound/rawmidi.h 2011-05-22 19:36:33.000000000 -0400
65994@@ -100,7 +100,7 @@ struct snd_rawmidi_substream {
65995 struct snd_rawmidi_runtime *runtime;
65996 struct pid *pid;
65997 /* hardware layer */
65998- struct snd_rawmidi_ops *ops;
65999+ const struct snd_rawmidi_ops *ops;
66000 };
66001
66002 struct snd_rawmidi_file {
66003@@ -127,7 +127,7 @@ struct snd_rawmidi {
66004 int ossreg;
66005 #endif
66006
66007- struct snd_rawmidi_global_ops *ops;
66008+ const struct snd_rawmidi_global_ops *ops;
66009
66010 struct snd_rawmidi_str streams[2];
66011
66012@@ -151,7 +151,7 @@ int snd_rawmidi_new(struct snd_card *car
66013 int output_count, int input_count,
66014 struct snd_rawmidi **rmidi);
66015 void snd_rawmidi_set_ops(struct snd_rawmidi *rmidi, int stream,
66016- struct snd_rawmidi_ops *ops);
66017+ const struct snd_rawmidi_ops *ops);
66018
66019 /* callbacks */
66020
66021diff -urNp linux-2.6.39.1/include/sound/seq_device.h linux-2.6.39.1/include/sound/seq_device.h
66022--- linux-2.6.39.1/include/sound/seq_device.h 2011-05-19 00:06:34.000000000 -0400
66023+++ linux-2.6.39.1/include/sound/seq_device.h 2011-05-22 19:36:33.000000000 -0400
66024@@ -69,7 +69,7 @@ struct snd_seq_dev_ops {
66025 */
66026 void snd_seq_device_load_drivers(void);
66027 int snd_seq_device_new(struct snd_card *card, int device, char *id, int argsize, struct snd_seq_device **result);
66028-int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry, int argsize);
66029+int snd_seq_device_register_driver(char *id, const struct snd_seq_dev_ops *entry, int argsize);
66030 int snd_seq_device_unregister_driver(char *id);
66031
66032 #define SNDRV_SEQ_DEVICE_ARGPTR(dev) (void *)((char *)(dev) + sizeof(struct snd_seq_device))
66033diff -urNp linux-2.6.39.1/include/sound/snd_wavefront.h linux-2.6.39.1/include/sound/snd_wavefront.h
66034--- linux-2.6.39.1/include/sound/snd_wavefront.h 2011-05-19 00:06:34.000000000 -0400
66035+++ linux-2.6.39.1/include/sound/snd_wavefront.h 2011-05-22 19:36:33.000000000 -0400
66036@@ -37,8 +37,8 @@ struct _snd_wavefront_midi {
66037 #define MPU_ACK 0xFE
66038 #define UART_MODE_ON 0x3F
66039
66040-extern struct snd_rawmidi_ops snd_wavefront_midi_output;
66041-extern struct snd_rawmidi_ops snd_wavefront_midi_input;
66042+extern const struct snd_rawmidi_ops snd_wavefront_midi_output;
66043+extern const struct snd_rawmidi_ops snd_wavefront_midi_input;
66044
66045 extern void snd_wavefront_midi_enable_virtual (snd_wavefront_card_t *);
66046 extern void snd_wavefront_midi_disable_virtual (snd_wavefront_card_t *);
66047diff -urNp linux-2.6.39.1/include/sound/soc.h linux-2.6.39.1/include/sound/soc.h
66048--- linux-2.6.39.1/include/sound/soc.h 2011-05-19 00:06:34.000000000 -0400
66049+++ linux-2.6.39.1/include/sound/soc.h 2011-05-22 19:36:33.000000000 -0400
66050@@ -245,7 +245,7 @@ struct snd_soc_jack_gpio;
66051
66052 typedef int (*hw_write_t)(void *,const char* ,int);
66053
66054-extern struct snd_ac97_bus_ops soc_ac97_ops;
66055+extern const struct snd_ac97_bus_ops soc_ac97_ops;
66056
66057 enum snd_soc_control_type {
66058 SND_SOC_CUSTOM,
66059diff -urNp linux-2.6.39.1/include/sound/ymfpci.h linux-2.6.39.1/include/sound/ymfpci.h
66060--- linux-2.6.39.1/include/sound/ymfpci.h 2011-05-19 00:06:34.000000000 -0400
66061+++ linux-2.6.39.1/include/sound/ymfpci.h 2011-05-22 19:36:33.000000000 -0400
66062@@ -358,7 +358,7 @@ struct snd_ymfpci {
66063 spinlock_t reg_lock;
66064 spinlock_t voice_lock;
66065 wait_queue_head_t interrupt_sleep;
66066- atomic_t interrupt_sleep_count;
66067+ atomic_unchecked_t interrupt_sleep_count;
66068 struct snd_info_entry *proc_entry;
66069 const struct firmware *dsp_microcode;
66070 const struct firmware *controller_microcode;
66071diff -urNp linux-2.6.39.1/include/target/target_core_base.h linux-2.6.39.1/include/target/target_core_base.h
66072--- linux-2.6.39.1/include/target/target_core_base.h 2011-06-03 00:04:14.000000000 -0400
66073+++ linux-2.6.39.1/include/target/target_core_base.h 2011-06-03 00:32:08.000000000 -0400
66074@@ -432,8 +432,8 @@ struct se_transport_task {
66075 atomic_t t_task_cdbs_left;
66076 atomic_t t_task_cdbs_ex_left;
66077 atomic_t t_task_cdbs_timeout_left;
66078- atomic_t t_task_cdbs_sent;
66079- atomic_t t_transport_aborted;
66080+ atomic_unchecked_t t_task_cdbs_sent;
66081+ atomic_unchecked_t t_transport_aborted;
66082 atomic_t t_transport_active;
66083 atomic_t t_transport_complete;
66084 atomic_t t_transport_queue_active;
66085@@ -774,7 +774,7 @@ struct se_device {
66086 atomic_t active_cmds;
66087 atomic_t simple_cmds;
66088 atomic_t depth_left;
66089- atomic_t dev_ordered_id;
66090+ atomic_unchecked_t dev_ordered_id;
66091 atomic_t dev_tur_active;
66092 atomic_t execute_tasks;
66093 atomic_t dev_status_thr_count;
66094diff -urNp linux-2.6.39.1/include/trace/events/irq.h linux-2.6.39.1/include/trace/events/irq.h
66095--- linux-2.6.39.1/include/trace/events/irq.h 2011-05-19 00:06:34.000000000 -0400
66096+++ linux-2.6.39.1/include/trace/events/irq.h 2011-05-22 19:36:33.000000000 -0400
66097@@ -36,7 +36,7 @@ struct softirq_action;
66098 */
66099 TRACE_EVENT(irq_handler_entry,
66100
66101- TP_PROTO(int irq, struct irqaction *action),
66102+ TP_PROTO(int irq, const struct irqaction *action),
66103
66104 TP_ARGS(irq, action),
66105
66106@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
66107 */
66108 TRACE_EVENT(irq_handler_exit,
66109
66110- TP_PROTO(int irq, struct irqaction *action, int ret),
66111+ TP_PROTO(int irq, const struct irqaction *action, int ret),
66112
66113 TP_ARGS(irq, action, ret),
66114
66115diff -urNp linux-2.6.39.1/include/video/udlfb.h linux-2.6.39.1/include/video/udlfb.h
66116--- linux-2.6.39.1/include/video/udlfb.h 2011-05-19 00:06:34.000000000 -0400
66117+++ linux-2.6.39.1/include/video/udlfb.h 2011-05-22 19:36:33.000000000 -0400
66118@@ -51,10 +51,10 @@ struct dlfb_data {
66119 int base8;
66120 u32 pseudo_palette[256];
66121 /* blit-only rendering path metrics, exposed through sysfs */
66122- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
66123- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
66124- atomic_t bytes_sent; /* to usb, after compression including overhead */
66125- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
66126+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
66127+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
66128+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
66129+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
66130 };
66131
66132 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
66133diff -urNp linux-2.6.39.1/include/video/uvesafb.h linux-2.6.39.1/include/video/uvesafb.h
66134--- linux-2.6.39.1/include/video/uvesafb.h 2011-05-19 00:06:34.000000000 -0400
66135+++ linux-2.6.39.1/include/video/uvesafb.h 2011-05-22 19:36:33.000000000 -0400
66136@@ -177,6 +177,7 @@ struct uvesafb_par {
66137 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
66138 u8 pmi_setpal; /* PMI for palette changes */
66139 u16 *pmi_base; /* protected mode interface location */
66140+ u8 *pmi_code; /* protected mode code location */
66141 void *pmi_start;
66142 void *pmi_pal;
66143 u8 *vbe_state_orig; /*
66144diff -urNp linux-2.6.39.1/init/do_mounts.c linux-2.6.39.1/init/do_mounts.c
66145--- linux-2.6.39.1/init/do_mounts.c 2011-05-19 00:06:34.000000000 -0400
66146+++ linux-2.6.39.1/init/do_mounts.c 2011-05-22 19:36:33.000000000 -0400
66147@@ -287,7 +287,7 @@ static void __init get_fs_names(char *pa
66148
66149 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
66150 {
66151- int err = sys_mount(name, "/root", fs, flags, data);
66152+ int err = sys_mount((__force char __user *)name, (__force char __user *)"/root", (__force char __user *)fs, flags, (__force void __user *)data);
66153 if (err)
66154 return err;
66155
66156@@ -383,18 +383,18 @@ void __init change_floppy(char *fmt, ...
66157 va_start(args, fmt);
66158 vsprintf(buf, fmt, args);
66159 va_end(args);
66160- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
66161+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
66162 if (fd >= 0) {
66163 sys_ioctl(fd, FDEJECT, 0);
66164 sys_close(fd);
66165 }
66166 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
66167- fd = sys_open("/dev/console", O_RDWR, 0);
66168+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
66169 if (fd >= 0) {
66170 sys_ioctl(fd, TCGETS, (long)&termios);
66171 termios.c_lflag &= ~ICANON;
66172 sys_ioctl(fd, TCSETSF, (long)&termios);
66173- sys_read(fd, &c, 1);
66174+ sys_read(fd, (char __user *)&c, 1);
66175 termios.c_lflag |= ICANON;
66176 sys_ioctl(fd, TCSETSF, (long)&termios);
66177 sys_close(fd);
66178@@ -488,6 +488,6 @@ void __init prepare_namespace(void)
66179 mount_root();
66180 out:
66181 devtmpfs_mount("dev");
66182- sys_mount(".", "/", NULL, MS_MOVE, NULL);
66183+ sys_mount((__force char __user *)".", (__force char __user *)"/", NULL, MS_MOVE, NULL);
66184 sys_chroot((const char __user __force *)".");
66185 }
66186diff -urNp linux-2.6.39.1/init/do_mounts.h linux-2.6.39.1/init/do_mounts.h
66187--- linux-2.6.39.1/init/do_mounts.h 2011-05-19 00:06:34.000000000 -0400
66188+++ linux-2.6.39.1/init/do_mounts.h 2011-05-22 19:36:33.000000000 -0400
66189@@ -15,15 +15,15 @@ extern int root_mountflags;
66190
66191 static inline int create_dev(char *name, dev_t dev)
66192 {
66193- sys_unlink(name);
66194- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
66195+ sys_unlink((__force char __user *)name);
66196+ return sys_mknod((__force char __user *)name, S_IFBLK|0600, new_encode_dev(dev));
66197 }
66198
66199 #if BITS_PER_LONG == 32
66200 static inline u32 bstat(char *name)
66201 {
66202 struct stat64 stat;
66203- if (sys_stat64(name, &stat) != 0)
66204+ if (sys_stat64((__force char __user *)name, (__force struct stat64 __user *)&stat) != 0)
66205 return 0;
66206 if (!S_ISBLK(stat.st_mode))
66207 return 0;
66208diff -urNp linux-2.6.39.1/init/do_mounts_initrd.c linux-2.6.39.1/init/do_mounts_initrd.c
66209--- linux-2.6.39.1/init/do_mounts_initrd.c 2011-05-19 00:06:34.000000000 -0400
66210+++ linux-2.6.39.1/init/do_mounts_initrd.c 2011-05-22 19:36:33.000000000 -0400
66211@@ -44,13 +44,13 @@ static void __init handle_initrd(void)
66212 create_dev("/dev/root.old", Root_RAM0);
66213 /* mount initrd on rootfs' /root */
66214 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
66215- sys_mkdir("/old", 0700);
66216- root_fd = sys_open("/", 0, 0);
66217- old_fd = sys_open("/old", 0, 0);
66218+ sys_mkdir((__force const char __user *)"/old", 0700);
66219+ root_fd = sys_open((__force const char __user *)"/", 0, 0);
66220+ old_fd = sys_open((__force const char __user *)"/old", 0, 0);
66221 /* move initrd over / and chdir/chroot in initrd root */
66222- sys_chdir("/root");
66223- sys_mount(".", "/", NULL, MS_MOVE, NULL);
66224- sys_chroot(".");
66225+ sys_chdir((__force const char __user *)"/root");
66226+ sys_mount((__force char __user *)".", (__force char __user *)"/", NULL, MS_MOVE, NULL);
66227+ sys_chroot((__force const char __user *)".");
66228
66229 /*
66230 * In case that a resume from disk is carried out by linuxrc or one of
66231@@ -67,15 +67,15 @@ static void __init handle_initrd(void)
66232
66233 /* move initrd to rootfs' /old */
66234 sys_fchdir(old_fd);
66235- sys_mount("/", ".", NULL, MS_MOVE, NULL);
66236+ sys_mount((__force char __user *)"/", (__force char __user *)".", NULL, MS_MOVE, NULL);
66237 /* switch root and cwd back to / of rootfs */
66238 sys_fchdir(root_fd);
66239- sys_chroot(".");
66240+ sys_chroot((__force const char __user *)".");
66241 sys_close(old_fd);
66242 sys_close(root_fd);
66243
66244 if (new_decode_dev(real_root_dev) == Root_RAM0) {
66245- sys_chdir("/old");
66246+ sys_chdir((__force const char __user *)"/old");
66247 return;
66248 }
66249
66250@@ -83,17 +83,17 @@ static void __init handle_initrd(void)
66251 mount_root();
66252
66253 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
66254- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
66255+ error = sys_mount((__force char __user *)"/old", (__force char __user *)"/root/initrd", NULL, MS_MOVE, NULL);
66256 if (!error)
66257 printk("okay\n");
66258 else {
66259- int fd = sys_open("/dev/root.old", O_RDWR, 0);
66260+ int fd = sys_open((__force const char __user *)"/dev/root.old", O_RDWR, 0);
66261 if (error == -ENOENT)
66262 printk("/initrd does not exist. Ignored.\n");
66263 else
66264 printk("failed\n");
66265 printk(KERN_NOTICE "Unmounting old root\n");
66266- sys_umount("/old", MNT_DETACH);
66267+ sys_umount((__force char __user *)"/old", MNT_DETACH);
66268 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
66269 if (fd < 0) {
66270 error = fd;
66271@@ -116,11 +116,11 @@ int __init initrd_load(void)
66272 * mounted in the normal path.
66273 */
66274 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
66275- sys_unlink("/initrd.image");
66276+ sys_unlink((__force const char __user *)"/initrd.image");
66277 handle_initrd();
66278 return 1;
66279 }
66280 }
66281- sys_unlink("/initrd.image");
66282+ sys_unlink((__force const char __user *)"/initrd.image");
66283 return 0;
66284 }
66285diff -urNp linux-2.6.39.1/init/do_mounts_md.c linux-2.6.39.1/init/do_mounts_md.c
66286--- linux-2.6.39.1/init/do_mounts_md.c 2011-05-19 00:06:34.000000000 -0400
66287+++ linux-2.6.39.1/init/do_mounts_md.c 2011-05-22 19:36:33.000000000 -0400
66288@@ -170,7 +170,7 @@ static void __init md_setup_drive(void)
66289 partitioned ? "_d" : "", minor,
66290 md_setup_args[ent].device_names);
66291
66292- fd = sys_open(name, 0, 0);
66293+ fd = sys_open((__force char __user *)name, 0, 0);
66294 if (fd < 0) {
66295 printk(KERN_ERR "md: open failed - cannot start "
66296 "array %s\n", name);
66297@@ -233,7 +233,7 @@ static void __init md_setup_drive(void)
66298 * array without it
66299 */
66300 sys_close(fd);
66301- fd = sys_open(name, 0, 0);
66302+ fd = sys_open((__force char __user *)name, 0, 0);
66303 sys_ioctl(fd, BLKRRPART, 0);
66304 }
66305 sys_close(fd);
66306diff -urNp linux-2.6.39.1/init/initramfs.c linux-2.6.39.1/init/initramfs.c
66307--- linux-2.6.39.1/init/initramfs.c 2011-05-19 00:06:34.000000000 -0400
66308+++ linux-2.6.39.1/init/initramfs.c 2011-05-22 19:36:33.000000000 -0400
66309@@ -74,7 +74,7 @@ static void __init free_hash(void)
66310 }
66311 }
66312
66313-static long __init do_utime(char __user *filename, time_t mtime)
66314+static long __init do_utime(__force char __user *filename, time_t mtime)
66315 {
66316 struct timespec t[2];
66317
66318@@ -109,7 +109,7 @@ static void __init dir_utime(void)
66319 struct dir_entry *de, *tmp;
66320 list_for_each_entry_safe(de, tmp, &dir_list, list) {
66321 list_del(&de->list);
66322- do_utime(de->name, de->mtime);
66323+ do_utime((__force char __user *)de->name, de->mtime);
66324 kfree(de->name);
66325 kfree(de);
66326 }
66327@@ -271,7 +271,7 @@ static int __init maybe_link(void)
66328 if (nlink >= 2) {
66329 char *old = find_link(major, minor, ino, mode, collected);
66330 if (old)
66331- return (sys_link(old, collected) < 0) ? -1 : 1;
66332+ return (sys_link((__force char __user *)old, (__force char __user *)collected) < 0) ? -1 : 1;
66333 }
66334 return 0;
66335 }
66336@@ -280,11 +280,11 @@ static void __init clean_path(char *path
66337 {
66338 struct stat st;
66339
66340- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
66341+ if (!sys_newlstat((__force char __user *)path, (__force struct stat __user *)&st) && (st.st_mode^mode) & S_IFMT) {
66342 if (S_ISDIR(st.st_mode))
66343- sys_rmdir(path);
66344+ sys_rmdir((__force char __user *)path);
66345 else
66346- sys_unlink(path);
66347+ sys_unlink((__force char __user *)path);
66348 }
66349 }
66350
66351@@ -305,7 +305,7 @@ static int __init do_name(void)
66352 int openflags = O_WRONLY|O_CREAT;
66353 if (ml != 1)
66354 openflags |= O_TRUNC;
66355- wfd = sys_open(collected, openflags, mode);
66356+ wfd = sys_open((__force char __user *)collected, openflags, mode);
66357
66358 if (wfd >= 0) {
66359 sys_fchown(wfd, uid, gid);
66360@@ -317,17 +317,17 @@ static int __init do_name(void)
66361 }
66362 }
66363 } else if (S_ISDIR(mode)) {
66364- sys_mkdir(collected, mode);
66365- sys_chown(collected, uid, gid);
66366- sys_chmod(collected, mode);
66367+ sys_mkdir((__force char __user *)collected, mode);
66368+ sys_chown((__force char __user *)collected, uid, gid);
66369+ sys_chmod((__force char __user *)collected, mode);
66370 dir_add(collected, mtime);
66371 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
66372 S_ISFIFO(mode) || S_ISSOCK(mode)) {
66373 if (maybe_link() == 0) {
66374- sys_mknod(collected, mode, rdev);
66375- sys_chown(collected, uid, gid);
66376- sys_chmod(collected, mode);
66377- do_utime(collected, mtime);
66378+ sys_mknod((__force char __user *)collected, mode, rdev);
66379+ sys_chown((__force char __user *)collected, uid, gid);
66380+ sys_chmod((__force char __user *)collected, mode);
66381+ do_utime((__force char __user *)collected, mtime);
66382 }
66383 }
66384 return 0;
66385@@ -336,15 +336,15 @@ static int __init do_name(void)
66386 static int __init do_copy(void)
66387 {
66388 if (count >= body_len) {
66389- sys_write(wfd, victim, body_len);
66390+ sys_write(wfd, (__force char __user *)victim, body_len);
66391 sys_close(wfd);
66392- do_utime(vcollected, mtime);
66393+ do_utime((__force char __user *)vcollected, mtime);
66394 kfree(vcollected);
66395 eat(body_len);
66396 state = SkipIt;
66397 return 0;
66398 } else {
66399- sys_write(wfd, victim, count);
66400+ sys_write(wfd, (__force char __user *)victim, count);
66401 body_len -= count;
66402 eat(count);
66403 return 1;
66404@@ -355,9 +355,9 @@ static int __init do_symlink(void)
66405 {
66406 collected[N_ALIGN(name_len) + body_len] = '\0';
66407 clean_path(collected, 0);
66408- sys_symlink(collected + N_ALIGN(name_len), collected);
66409- sys_lchown(collected, uid, gid);
66410- do_utime(collected, mtime);
66411+ sys_symlink((__force char __user *)collected + N_ALIGN(name_len), (__force char __user *)collected);
66412+ sys_lchown((__force char __user *)collected, uid, gid);
66413+ do_utime((__force char __user *)collected, mtime);
66414 state = SkipIt;
66415 next_state = Reset;
66416 return 0;
66417diff -urNp linux-2.6.39.1/init/Kconfig linux-2.6.39.1/init/Kconfig
66418--- linux-2.6.39.1/init/Kconfig 2011-05-19 00:06:34.000000000 -0400
66419+++ linux-2.6.39.1/init/Kconfig 2011-05-22 19:36:33.000000000 -0400
66420@@ -1202,7 +1202,7 @@ config SLUB_DEBUG
66421
66422 config COMPAT_BRK
66423 bool "Disable heap randomization"
66424- default y
66425+ default n
66426 help
66427 Randomizing heap placement makes heap exploits harder, but it
66428 also breaks ancient binaries (including anything libc5 based).
66429diff -urNp linux-2.6.39.1/init/main.c linux-2.6.39.1/init/main.c
66430--- linux-2.6.39.1/init/main.c 2011-06-03 00:04:14.000000000 -0400
66431+++ linux-2.6.39.1/init/main.c 2011-06-03 00:32:08.000000000 -0400
66432@@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void)
66433 extern void tc_init(void);
66434 #endif
66435
66436+extern void grsecurity_init(void);
66437+
66438 /*
66439 * Debug helper: via this flag we know that we are in 'early bootup code'
66440 * where only the boot processor is running with IRQ disabled. This means
66441@@ -149,6 +151,49 @@ static int __init set_reset_devices(char
66442
66443 __setup("reset_devices", set_reset_devices);
66444
66445+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
66446+extern char pax_enter_kernel_user[];
66447+extern char pax_exit_kernel_user[];
66448+extern pgdval_t clone_pgd_mask;
66449+#endif
66450+
66451+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
66452+static int __init setup_pax_nouderef(char *str)
66453+{
66454+#ifdef CONFIG_X86_32
66455+ unsigned int cpu;
66456+ struct desc_struct *gdt;
66457+
66458+ for (cpu = 0; cpu < NR_CPUS; cpu++) {
66459+ gdt = get_cpu_gdt_table(cpu);
66460+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
66461+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
66462+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
66463+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
66464+ }
66465+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
66466+#else
66467+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
66468+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
66469+ clone_pgd_mask = ~(pgdval_t)0UL;
66470+#endif
66471+
66472+ return 0;
66473+}
66474+early_param("pax_nouderef", setup_pax_nouderef);
66475+#endif
66476+
66477+#ifdef CONFIG_PAX_SOFTMODE
66478+unsigned int pax_softmode;
66479+
66480+static int __init setup_pax_softmode(char *str)
66481+{
66482+ get_option(&str, &pax_softmode);
66483+ return 1;
66484+}
66485+__setup("pax_softmode=", setup_pax_softmode);
66486+#endif
66487+
66488 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
66489 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
66490 static const char *panic_later, *panic_param;
66491@@ -663,6 +708,7 @@ int __init_or_module do_one_initcall(ini
66492 {
66493 int count = preempt_count();
66494 int ret;
66495+ const char *msg1 = "", *msg2 = "";
66496
66497 if (initcall_debug)
66498 ret = do_one_initcall_debug(fn);
66499@@ -675,15 +721,15 @@ int __init_or_module do_one_initcall(ini
66500 sprintf(msgbuf, "error code %d ", ret);
66501
66502 if (preempt_count() != count) {
66503- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
66504+ msg1 = " preemption imbalance";
66505 preempt_count() = count;
66506 }
66507 if (irqs_disabled()) {
66508- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
66509+ msg2 = " disabled interrupts";
66510 local_irq_enable();
66511 }
66512- if (msgbuf[0]) {
66513- printk("initcall %pF returned with %s\n", fn, msgbuf);
66514+ if (msgbuf[0] || *msg1 || *msg2) {
66515+ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
66516 }
66517
66518 return ret;
66519@@ -801,7 +847,7 @@ static int __init kernel_init(void * unu
66520 do_basic_setup();
66521
66522 /* Open the /dev/console on the rootfs, this should never fail */
66523- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
66524+ if (sys_open((__force const char __user *) "/dev/console", O_RDWR, 0) < 0)
66525 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
66526
66527 (void) sys_dup(0);
66528@@ -814,11 +860,13 @@ static int __init kernel_init(void * unu
66529 if (!ramdisk_execute_command)
66530 ramdisk_execute_command = "/init";
66531
66532- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
66533+ if (sys_access((__force const char __user *) ramdisk_execute_command, 0) != 0) {
66534 ramdisk_execute_command = NULL;
66535 prepare_namespace();
66536 }
66537
66538+ grsecurity_init();
66539+
66540 /*
66541 * Ok, we have completed the initial bootup, and
66542 * we're essentially up and running. Get rid of the
66543diff -urNp linux-2.6.39.1/ipc/mqueue.c linux-2.6.39.1/ipc/mqueue.c
66544--- linux-2.6.39.1/ipc/mqueue.c 2011-05-19 00:06:34.000000000 -0400
66545+++ linux-2.6.39.1/ipc/mqueue.c 2011-05-22 19:41:42.000000000 -0400
66546@@ -154,6 +154,7 @@ static struct inode *mqueue_get_inode(st
66547 mq_bytes = (mq_msg_tblsz +
66548 (info->attr.mq_maxmsg * info->attr.mq_msgsize));
66549
66550+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
66551 spin_lock(&mq_lock);
66552 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
66553 u->mq_bytes + mq_bytes >
66554diff -urNp linux-2.6.39.1/ipc/sem.c linux-2.6.39.1/ipc/sem.c
66555--- linux-2.6.39.1/ipc/sem.c 2011-05-19 00:06:34.000000000 -0400
66556+++ linux-2.6.39.1/ipc/sem.c 2011-05-22 19:36:33.000000000 -0400
66557@@ -854,6 +854,8 @@ static int semctl_main(struct ipc_namesp
66558 int nsems;
66559 struct list_head tasks;
66560
66561+ pax_track_stack();
66562+
66563 sma = sem_lock_check(ns, semid);
66564 if (IS_ERR(sma))
66565 return PTR_ERR(sma);
66566@@ -1301,6 +1303,8 @@ SYSCALL_DEFINE4(semtimedop, int, semid,
66567 struct ipc_namespace *ns;
66568 struct list_head tasks;
66569
66570+ pax_track_stack();
66571+
66572 ns = current->nsproxy->ipc_ns;
66573
66574 if (nsops < 1 || semid < 0)
66575diff -urNp linux-2.6.39.1/ipc/shm.c linux-2.6.39.1/ipc/shm.c
66576--- linux-2.6.39.1/ipc/shm.c 2011-05-19 00:06:34.000000000 -0400
66577+++ linux-2.6.39.1/ipc/shm.c 2011-05-22 19:41:42.000000000 -0400
66578@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_name
66579 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
66580 #endif
66581
66582+#ifdef CONFIG_GRKERNSEC
66583+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66584+ const time_t shm_createtime, const uid_t cuid,
66585+ const int shmid);
66586+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66587+ const time_t shm_createtime);
66588+#endif
66589+
66590 void shm_init_ns(struct ipc_namespace *ns)
66591 {
66592 ns->shm_ctlmax = SHMMAX;
66593@@ -401,6 +409,14 @@ static int newseg(struct ipc_namespace *
66594 shp->shm_lprid = 0;
66595 shp->shm_atim = shp->shm_dtim = 0;
66596 shp->shm_ctim = get_seconds();
66597+#ifdef CONFIG_GRKERNSEC
66598+ {
66599+ struct timespec timeval;
66600+ do_posix_clock_monotonic_gettime(&timeval);
66601+
66602+ shp->shm_createtime = timeval.tv_sec;
66603+ }
66604+#endif
66605 shp->shm_segsz = size;
66606 shp->shm_nattch = 0;
66607 shp->shm_file = file;
66608@@ -762,8 +778,6 @@ SYSCALL_DEFINE3(shmctl, int, shmid, int,
66609 case SHM_LOCK:
66610 case SHM_UNLOCK:
66611 {
66612- struct file *uninitialized_var(shm_file);
66613-
66614 lru_add_drain_all(); /* drain pagevecs to lru lists */
66615
66616 shp = shm_lock_check(ns, shmid);
66617@@ -896,9 +910,21 @@ long do_shmat(int shmid, char __user *sh
66618 if (err)
66619 goto out_unlock;
66620
66621+#ifdef CONFIG_GRKERNSEC
66622+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
66623+ shp->shm_perm.cuid, shmid) ||
66624+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
66625+ err = -EACCES;
66626+ goto out_unlock;
66627+ }
66628+#endif
66629+
66630 path = shp->shm_file->f_path;
66631 path_get(&path);
66632 shp->shm_nattch++;
66633+#ifdef CONFIG_GRKERNSEC
66634+ shp->shm_lapid = current->pid;
66635+#endif
66636 size = i_size_read(path.dentry->d_inode);
66637 shm_unlock(shp);
66638
66639diff -urNp linux-2.6.39.1/kernel/acct.c linux-2.6.39.1/kernel/acct.c
66640--- linux-2.6.39.1/kernel/acct.c 2011-05-19 00:06:34.000000000 -0400
66641+++ linux-2.6.39.1/kernel/acct.c 2011-05-22 19:36:33.000000000 -0400
66642@@ -570,7 +570,7 @@ static void do_acct_process(struct bsd_a
66643 */
66644 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
66645 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
66646- file->f_op->write(file, (char *)&ac,
66647+ file->f_op->write(file, (__force char __user *)&ac,
66648 sizeof(acct_t), &file->f_pos);
66649 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
66650 set_fs(fs);
66651diff -urNp linux-2.6.39.1/kernel/audit.c linux-2.6.39.1/kernel/audit.c
66652--- linux-2.6.39.1/kernel/audit.c 2011-05-19 00:06:34.000000000 -0400
66653+++ linux-2.6.39.1/kernel/audit.c 2011-05-22 19:36:33.000000000 -0400
66654@@ -112,7 +112,7 @@ u32 audit_sig_sid = 0;
66655 3) suppressed due to audit_rate_limit
66656 4) suppressed due to audit_backlog_limit
66657 */
66658-static atomic_t audit_lost = ATOMIC_INIT(0);
66659+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
66660
66661 /* The netlink socket. */
66662 static struct sock *audit_sock;
66663@@ -234,7 +234,7 @@ void audit_log_lost(const char *message)
66664 unsigned long now;
66665 int print;
66666
66667- atomic_inc(&audit_lost);
66668+ atomic_inc_unchecked(&audit_lost);
66669
66670 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
66671
66672@@ -253,7 +253,7 @@ void audit_log_lost(const char *message)
66673 printk(KERN_WARNING
66674 "audit: audit_lost=%d audit_rate_limit=%d "
66675 "audit_backlog_limit=%d\n",
66676- atomic_read(&audit_lost),
66677+ atomic_read_unchecked(&audit_lost),
66678 audit_rate_limit,
66679 audit_backlog_limit);
66680 audit_panic(message);
66681@@ -686,7 +686,7 @@ static int audit_receive_msg(struct sk_b
66682 status_set.pid = audit_pid;
66683 status_set.rate_limit = audit_rate_limit;
66684 status_set.backlog_limit = audit_backlog_limit;
66685- status_set.lost = atomic_read(&audit_lost);
66686+ status_set.lost = atomic_read_unchecked(&audit_lost);
66687 status_set.backlog = skb_queue_len(&audit_skb_queue);
66688 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
66689 &status_set, sizeof(status_set));
66690diff -urNp linux-2.6.39.1/kernel/auditsc.c linux-2.6.39.1/kernel/auditsc.c
66691--- linux-2.6.39.1/kernel/auditsc.c 2011-05-19 00:06:34.000000000 -0400
66692+++ linux-2.6.39.1/kernel/auditsc.c 2011-05-22 19:36:33.000000000 -0400
66693@@ -2111,7 +2111,7 @@ int auditsc_get_stamp(struct audit_conte
66694 }
66695
66696 /* global counter which is incremented every time something logs in */
66697-static atomic_t session_id = ATOMIC_INIT(0);
66698+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
66699
66700 /**
66701 * audit_set_loginuid - set a task's audit_context loginuid
66702@@ -2124,7 +2124,7 @@ static atomic_t session_id = ATOMIC_INIT
66703 */
66704 int audit_set_loginuid(struct task_struct *task, uid_t loginuid)
66705 {
66706- unsigned int sessionid = atomic_inc_return(&session_id);
66707+ unsigned int sessionid = atomic_inc_return_unchecked(&session_id);
66708 struct audit_context *context = task->audit_context;
66709
66710 if (context && context->in_syscall) {
66711diff -urNp linux-2.6.39.1/kernel/capability.c linux-2.6.39.1/kernel/capability.c
66712--- linux-2.6.39.1/kernel/capability.c 2011-05-19 00:06:34.000000000 -0400
66713+++ linux-2.6.39.1/kernel/capability.c 2011-05-22 21:02:23.000000000 -0400
66714@@ -206,6 +206,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_
66715 * before modification is attempted and the application
66716 * fails.
66717 */
66718+ if (tocopy > ARRAY_SIZE(kdata))
66719+ return -EFAULT;
66720+
66721 if (copy_to_user(dataptr, kdata, tocopy
66722 * sizeof(struct __user_cap_data_struct))) {
66723 return -EFAULT;
66724@@ -378,7 +381,7 @@ bool ns_capable(struct user_namespace *n
66725 BUG();
66726 }
66727
66728- if (security_capable(ns, current_cred(), cap) == 0) {
66729+ if (security_capable(ns, current_cred(), cap) == 0 && gr_is_capable(cap)) {
66730 current->flags |= PF_SUPERPRIV;
66731 return true;
66732 }
66733@@ -386,6 +389,27 @@ bool ns_capable(struct user_namespace *n
66734 }
66735 EXPORT_SYMBOL(ns_capable);
66736
66737+bool ns_capable_nolog(struct user_namespace *ns, int cap)
66738+{
66739+ if (unlikely(!cap_valid(cap))) {
66740+ printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
66741+ BUG();
66742+ }
66743+
66744+ if (security_capable(ns, current_cred(), cap) == 0 && gr_is_capable_nolog(cap)) {
66745+ current->flags |= PF_SUPERPRIV;
66746+ return true;
66747+ }
66748+ return false;
66749+}
66750+EXPORT_SYMBOL(ns_capable_nolog);
66751+
66752+bool capable_nolog(int cap)
66753+{
66754+ return ns_capable_nolog(&init_user_ns, cap);
66755+}
66756+EXPORT_SYMBOL(capable_nolog);
66757+
66758 /**
66759 * task_ns_capable - Determine whether current task has a superior
66760 * capability targeted at a specific task's user namespace.
66761@@ -400,6 +424,12 @@ bool task_ns_capable(struct task_struct
66762 }
66763 EXPORT_SYMBOL(task_ns_capable);
66764
66765+bool task_ns_capable_nolog(struct task_struct *t, int cap)
66766+{
66767+ return ns_capable_nolog(task_cred_xxx(t, user)->user_ns, cap);
66768+}
66769+EXPORT_SYMBOL(task_ns_capable_nolog);
66770+
66771 /**
66772 * nsown_capable - Check superior capability to one's own user_ns
66773 * @cap: The capability in question
66774diff -urNp linux-2.6.39.1/kernel/cgroup.c linux-2.6.39.1/kernel/cgroup.c
66775--- linux-2.6.39.1/kernel/cgroup.c 2011-05-19 00:06:34.000000000 -0400
66776+++ linux-2.6.39.1/kernel/cgroup.c 2011-05-22 19:36:33.000000000 -0400
66777@@ -598,6 +598,8 @@ static struct css_set *find_css_set(
66778 struct hlist_head *hhead;
66779 struct cg_cgroup_link *link;
66780
66781+ pax_track_stack();
66782+
66783 /* First see if we already have a cgroup group that matches
66784 * the desired set */
66785 read_lock(&css_set_lock);
66786diff -urNp linux-2.6.39.1/kernel/compat.c linux-2.6.39.1/kernel/compat.c
66787--- linux-2.6.39.1/kernel/compat.c 2011-05-19 00:06:34.000000000 -0400
66788+++ linux-2.6.39.1/kernel/compat.c 2011-05-22 19:41:42.000000000 -0400
66789@@ -13,6 +13,7 @@
66790
66791 #include <linux/linkage.h>
66792 #include <linux/compat.h>
66793+#include <linux/module.h>
66794 #include <linux/errno.h>
66795 #include <linux/time.h>
66796 #include <linux/signal.h>
66797diff -urNp linux-2.6.39.1/kernel/configs.c linux-2.6.39.1/kernel/configs.c
66798--- linux-2.6.39.1/kernel/configs.c 2011-05-19 00:06:34.000000000 -0400
66799+++ linux-2.6.39.1/kernel/configs.c 2011-05-22 19:41:42.000000000 -0400
66800@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
66801 struct proc_dir_entry *entry;
66802
66803 /* create the current config file */
66804+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
66805+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
66806+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
66807+ &ikconfig_file_ops);
66808+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66809+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
66810+ &ikconfig_file_ops);
66811+#endif
66812+#else
66813 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
66814 &ikconfig_file_ops);
66815+#endif
66816+
66817 if (!entry)
66818 return -ENOMEM;
66819
66820diff -urNp linux-2.6.39.1/kernel/cred.c linux-2.6.39.1/kernel/cred.c
66821--- linux-2.6.39.1/kernel/cred.c 2011-05-19 00:06:34.000000000 -0400
66822+++ linux-2.6.39.1/kernel/cred.c 2011-05-22 19:41:42.000000000 -0400
66823@@ -158,6 +158,8 @@ static void put_cred_rcu(struct rcu_head
66824 */
66825 void __put_cred(struct cred *cred)
66826 {
66827+ pax_track_stack();
66828+
66829 kdebug("__put_cred(%p{%d,%d})", cred,
66830 atomic_read(&cred->usage),
66831 read_cred_subscribers(cred));
66832@@ -182,6 +184,8 @@ void exit_creds(struct task_struct *tsk)
66833 {
66834 struct cred *cred;
66835
66836+ pax_track_stack();
66837+
66838 kdebug("exit_creds(%u,%p,%p,{%d,%d})", tsk->pid, tsk->real_cred, tsk->cred,
66839 atomic_read(&tsk->cred->usage),
66840 read_cred_subscribers(tsk->cred));
66841@@ -220,6 +224,8 @@ const struct cred *get_task_cred(struct
66842 {
66843 const struct cred *cred;
66844
66845+ pax_track_stack();
66846+
66847 rcu_read_lock();
66848
66849 do {
66850@@ -239,6 +245,8 @@ struct cred *cred_alloc_blank(void)
66851 {
66852 struct cred *new;
66853
66854+ pax_track_stack();
66855+
66856 new = kmem_cache_zalloc(cred_jar, GFP_KERNEL);
66857 if (!new)
66858 return NULL;
66859@@ -287,6 +295,8 @@ struct cred *prepare_creds(void)
66860 const struct cred *old;
66861 struct cred *new;
66862
66863+ pax_track_stack();
66864+
66865 validate_process_creds();
66866
66867 new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
66868@@ -333,6 +343,8 @@ struct cred *prepare_exec_creds(void)
66869 struct thread_group_cred *tgcred = NULL;
66870 struct cred *new;
66871
66872+ pax_track_stack();
66873+
66874 #ifdef CONFIG_KEYS
66875 tgcred = kmalloc(sizeof(*tgcred), GFP_KERNEL);
66876 if (!tgcred)
66877@@ -385,6 +397,8 @@ int copy_creds(struct task_struct *p, un
66878 struct cred *new;
66879 int ret;
66880
66881+ pax_track_stack();
66882+
66883 if (
66884 #ifdef CONFIG_KEYS
66885 !p->cred->thread_keyring &&
66886@@ -475,6 +489,8 @@ int commit_creds(struct cred *new)
66887 struct task_struct *task = current;
66888 const struct cred *old = task->real_cred;
66889
66890+ pax_track_stack();
66891+
66892 kdebug("commit_creds(%p{%d,%d})", new,
66893 atomic_read(&new->usage),
66894 read_cred_subscribers(new));
66895@@ -489,6 +505,8 @@ int commit_creds(struct cred *new)
66896
66897 get_cred(new); /* we will require a ref for the subj creds too */
66898
66899+ gr_set_role_label(task, new->uid, new->gid);
66900+
66901 /* dumpability changes */
66902 if (old->euid != new->euid ||
66903 old->egid != new->egid ||
66904@@ -551,6 +569,8 @@ EXPORT_SYMBOL(commit_creds);
66905 */
66906 void abort_creds(struct cred *new)
66907 {
66908+ pax_track_stack();
66909+
66910 kdebug("abort_creds(%p{%d,%d})", new,
66911 atomic_read(&new->usage),
66912 read_cred_subscribers(new));
66913@@ -574,6 +594,8 @@ const struct cred *override_creds(const
66914 {
66915 const struct cred *old = current->cred;
66916
66917+ pax_track_stack();
66918+
66919 kdebug("override_creds(%p{%d,%d})", new,
66920 atomic_read(&new->usage),
66921 read_cred_subscribers(new));
66922@@ -603,6 +625,8 @@ void revert_creds(const struct cred *old
66923 {
66924 const struct cred *override = current->cred;
66925
66926+ pax_track_stack();
66927+
66928 kdebug("revert_creds(%p{%d,%d})", old,
66929 atomic_read(&old->usage),
66930 read_cred_subscribers(old));
66931@@ -649,6 +673,8 @@ struct cred *prepare_kernel_cred(struct
66932 const struct cred *old;
66933 struct cred *new;
66934
66935+ pax_track_stack();
66936+
66937 new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
66938 if (!new)
66939 return NULL;
66940@@ -703,6 +729,8 @@ EXPORT_SYMBOL(prepare_kernel_cred);
66941 */
66942 int set_security_override(struct cred *new, u32 secid)
66943 {
66944+ pax_track_stack();
66945+
66946 return security_kernel_act_as(new, secid);
66947 }
66948 EXPORT_SYMBOL(set_security_override);
66949@@ -722,6 +750,8 @@ int set_security_override_from_ctx(struc
66950 u32 secid;
66951 int ret;
66952
66953+ pax_track_stack();
66954+
66955 ret = security_secctx_to_secid(secctx, strlen(secctx), &secid);
66956 if (ret < 0)
66957 return ret;
66958diff -urNp linux-2.6.39.1/kernel/debug/debug_core.c linux-2.6.39.1/kernel/debug/debug_core.c
66959--- linux-2.6.39.1/kernel/debug/debug_core.c 2011-05-19 00:06:34.000000000 -0400
66960+++ linux-2.6.39.1/kernel/debug/debug_core.c 2011-05-22 19:36:33.000000000 -0400
66961@@ -72,7 +72,7 @@ int kgdb_io_module_registered;
66962 /* Guard for recursive entry */
66963 static int exception_level;
66964
66965-struct kgdb_io *dbg_io_ops;
66966+const struct kgdb_io *dbg_io_ops;
66967 static DEFINE_SPINLOCK(kgdb_registration_lock);
66968
66969 /* kgdb console driver is loaded */
66970@@ -119,7 +119,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_loc
66971 */
66972 static atomic_t masters_in_kgdb;
66973 static atomic_t slaves_in_kgdb;
66974-static atomic_t kgdb_break_tasklet_var;
66975+static atomic_unchecked_t kgdb_break_tasklet_var;
66976 atomic_t kgdb_setting_breakpoint;
66977
66978 struct task_struct *kgdb_usethread;
66979@@ -129,7 +129,7 @@ int kgdb_single_step;
66980 static pid_t kgdb_sstep_pid;
66981
66982 /* to keep track of the CPU which is doing the single stepping*/
66983-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
66984+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
66985
66986 /*
66987 * If you are debugging a problem where roundup (the collection of
66988@@ -542,7 +542,7 @@ return_normal:
66989 * kernel will only try for the value of sstep_tries before
66990 * giving up and continuing on.
66991 */
66992- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
66993+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
66994 (kgdb_info[cpu].task &&
66995 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
66996 atomic_set(&kgdb_active, -1);
66997@@ -636,8 +636,8 @@ cpu_master_loop:
66998 }
66999
67000 kgdb_restore:
67001- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
67002- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
67003+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
67004+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
67005 if (kgdb_info[sstep_cpu].task)
67006 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
67007 else
67008@@ -834,18 +834,18 @@ static void kgdb_unregister_callbacks(vo
67009 static void kgdb_tasklet_bpt(unsigned long ing)
67010 {
67011 kgdb_breakpoint();
67012- atomic_set(&kgdb_break_tasklet_var, 0);
67013+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
67014 }
67015
67016 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
67017
67018 void kgdb_schedule_breakpoint(void)
67019 {
67020- if (atomic_read(&kgdb_break_tasklet_var) ||
67021+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
67022 atomic_read(&kgdb_active) != -1 ||
67023 atomic_read(&kgdb_setting_breakpoint))
67024 return;
67025- atomic_inc(&kgdb_break_tasklet_var);
67026+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
67027 tasklet_schedule(&kgdb_tasklet_breakpoint);
67028 }
67029 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
67030@@ -864,7 +864,7 @@ static void kgdb_initial_breakpoint(void
67031 *
67032 * Register it with the KGDB core.
67033 */
67034-int kgdb_register_io_module(struct kgdb_io *new_dbg_io_ops)
67035+int kgdb_register_io_module(const struct kgdb_io *new_dbg_io_ops)
67036 {
67037 int err;
67038
67039@@ -909,7 +909,7 @@ EXPORT_SYMBOL_GPL(kgdb_register_io_modul
67040 *
67041 * Unregister it with the KGDB core.
67042 */
67043-void kgdb_unregister_io_module(struct kgdb_io *old_dbg_io_ops)
67044+void kgdb_unregister_io_module(const struct kgdb_io *old_dbg_io_ops)
67045 {
67046 BUG_ON(kgdb_connected);
67047
67048diff -urNp linux-2.6.39.1/kernel/debug/kdb/kdb_main.c linux-2.6.39.1/kernel/debug/kdb/kdb_main.c
67049--- linux-2.6.39.1/kernel/debug/kdb/kdb_main.c 2011-05-19 00:06:34.000000000 -0400
67050+++ linux-2.6.39.1/kernel/debug/kdb/kdb_main.c 2011-05-22 19:36:33.000000000 -0400
67051@@ -1980,7 +1980,7 @@ static int kdb_lsmod(int argc, const cha
67052 list_for_each_entry(mod, kdb_modules, list) {
67053
67054 kdb_printf("%-20s%8u 0x%p ", mod->name,
67055- mod->core_size, (void *)mod);
67056+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
67057 #ifdef CONFIG_MODULE_UNLOAD
67058 kdb_printf("%4d ", module_refcount(mod));
67059 #endif
67060@@ -1990,7 +1990,7 @@ static int kdb_lsmod(int argc, const cha
67061 kdb_printf(" (Loading)");
67062 else
67063 kdb_printf(" (Live)");
67064- kdb_printf(" 0x%p", mod->module_core);
67065+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
67066
67067 #ifdef CONFIG_MODULE_UNLOAD
67068 {
67069diff -urNp linux-2.6.39.1/kernel/exit.c linux-2.6.39.1/kernel/exit.c
67070--- linux-2.6.39.1/kernel/exit.c 2011-05-19 00:06:34.000000000 -0400
67071+++ linux-2.6.39.1/kernel/exit.c 2011-05-22 20:02:30.000000000 -0400
67072@@ -57,6 +57,10 @@
67073 #include <asm/pgtable.h>
67074 #include <asm/mmu_context.h>
67075
67076+#ifdef CONFIG_GRKERNSEC
67077+extern rwlock_t grsec_exec_file_lock;
67078+#endif
67079+
67080 static void exit_mm(struct task_struct * tsk);
67081
67082 static void __unhash_process(struct task_struct *p, bool group_dead)
67083@@ -169,6 +173,8 @@ void release_task(struct task_struct * p
67084 struct task_struct *leader;
67085 int zap_leader;
67086 repeat:
67087+ gr_del_task_from_ip_table(p);
67088+
67089 tracehook_prepare_release_task(p);
67090 /* don't need to get the RCU readlock here - the process is dead and
67091 * can't be modifying its own credentials. But shut RCU-lockdep up */
67092@@ -338,11 +344,22 @@ static void reparent_to_kthreadd(void)
67093 {
67094 write_lock_irq(&tasklist_lock);
67095
67096+#ifdef CONFIG_GRKERNSEC
67097+ write_lock(&grsec_exec_file_lock);
67098+ if (current->exec_file) {
67099+ fput(current->exec_file);
67100+ current->exec_file = NULL;
67101+ }
67102+ write_unlock(&grsec_exec_file_lock);
67103+#endif
67104+
67105 ptrace_unlink(current);
67106 /* Reparent to init */
67107 current->real_parent = current->parent = kthreadd_task;
67108 list_move_tail(&current->sibling, &current->real_parent->children);
67109
67110+ gr_set_kernel_label(current);
67111+
67112 /* Set the exit signal to SIGCHLD so we signal init on exit */
67113 current->exit_signal = SIGCHLD;
67114
67115@@ -394,7 +411,7 @@ int allow_signal(int sig)
67116 * know it'll be handled, so that they don't get converted to
67117 * SIGKILL or just silently dropped.
67118 */
67119- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
67120+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
67121 recalc_sigpending();
67122 spin_unlock_irq(&current->sighand->siglock);
67123 return 0;
67124@@ -430,6 +447,17 @@ void daemonize(const char *name, ...)
67125 vsnprintf(current->comm, sizeof(current->comm), name, args);
67126 va_end(args);
67127
67128+#ifdef CONFIG_GRKERNSEC
67129+ write_lock(&grsec_exec_file_lock);
67130+ if (current->exec_file) {
67131+ fput(current->exec_file);
67132+ current->exec_file = NULL;
67133+ }
67134+ write_unlock(&grsec_exec_file_lock);
67135+#endif
67136+
67137+ gr_set_kernel_label(current);
67138+
67139 /*
67140 * If we were started as result of loading a module, close all of the
67141 * user space pages. We don't need them, and if we didn't close them
67142@@ -905,15 +933,8 @@ NORET_TYPE void do_exit(long code)
67143 struct task_struct *tsk = current;
67144 int group_dead;
67145
67146- profile_task_exit(tsk);
67147-
67148- WARN_ON(atomic_read(&tsk->fs_excl));
67149- WARN_ON(blk_needs_flush_plug(tsk));
67150-
67151 if (unlikely(in_interrupt()))
67152 panic("Aiee, killing interrupt handler!");
67153- if (unlikely(!tsk->pid))
67154- panic("Attempted to kill the idle task!");
67155
67156 /*
67157 * If do_exit is called because this processes oopsed, it's possible
67158@@ -924,6 +945,14 @@ NORET_TYPE void do_exit(long code)
67159 */
67160 set_fs(USER_DS);
67161
67162+ profile_task_exit(tsk);
67163+
67164+ WARN_ON(atomic_read(&tsk->fs_excl));
67165+ WARN_ON(blk_needs_flush_plug(tsk));
67166+
67167+ if (unlikely(!tsk->pid))
67168+ panic("Attempted to kill the idle task!");
67169+
67170 tracehook_report_exit(&code);
67171
67172 validate_creds_for_do_exit(tsk);
67173@@ -984,6 +1013,9 @@ NORET_TYPE void do_exit(long code)
67174 tsk->exit_code = code;
67175 taskstats_exit(tsk, group_dead);
67176
67177+ gr_acl_handle_psacct(tsk, code);
67178+ gr_acl_handle_exit();
67179+
67180 exit_mm(tsk);
67181
67182 if (group_dead)
67183diff -urNp linux-2.6.39.1/kernel/fork.c linux-2.6.39.1/kernel/fork.c
67184--- linux-2.6.39.1/kernel/fork.c 2011-05-19 00:06:34.000000000 -0400
67185+++ linux-2.6.39.1/kernel/fork.c 2011-05-22 19:41:42.000000000 -0400
67186@@ -287,7 +287,7 @@ static struct task_struct *dup_task_stru
67187 *stackend = STACK_END_MAGIC; /* for overflow detection */
67188
67189 #ifdef CONFIG_CC_STACKPROTECTOR
67190- tsk->stack_canary = get_random_int();
67191+ tsk->stack_canary = pax_get_random_long();
67192 #endif
67193
67194 /* One for us, one for whoever does the "release_task()" (usually parent) */
67195@@ -309,13 +309,78 @@ out:
67196 }
67197
67198 #ifdef CONFIG_MMU
67199+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct vm_area_struct *mpnt)
67200+{
67201+ struct vm_area_struct *tmp;
67202+ unsigned long charge;
67203+ struct mempolicy *pol;
67204+ struct file *file;
67205+
67206+ charge = 0;
67207+ if (mpnt->vm_flags & VM_ACCOUNT) {
67208+ unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
67209+ if (security_vm_enough_memory(len))
67210+ goto fail_nomem;
67211+ charge = len;
67212+ }
67213+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67214+ if (!tmp)
67215+ goto fail_nomem;
67216+ *tmp = *mpnt;
67217+ tmp->vm_mm = mm;
67218+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
67219+ pol = mpol_dup(vma_policy(mpnt));
67220+ if (IS_ERR(pol))
67221+ goto fail_nomem_policy;
67222+ vma_set_policy(tmp, pol);
67223+ if (anon_vma_fork(tmp, mpnt))
67224+ goto fail_nomem_anon_vma_fork;
67225+ tmp->vm_flags &= ~VM_LOCKED;
67226+ tmp->vm_next = tmp->vm_prev = NULL;
67227+ tmp->vm_mirror = NULL;
67228+ file = tmp->vm_file;
67229+ if (file) {
67230+ struct inode *inode = file->f_path.dentry->d_inode;
67231+ struct address_space *mapping = file->f_mapping;
67232+
67233+ get_file(file);
67234+ if (tmp->vm_flags & VM_DENYWRITE)
67235+ atomic_dec(&inode->i_writecount);
67236+ spin_lock(&mapping->i_mmap_lock);
67237+ if (tmp->vm_flags & VM_SHARED)
67238+ mapping->i_mmap_writable++;
67239+ tmp->vm_truncate_count = mpnt->vm_truncate_count;
67240+ flush_dcache_mmap_lock(mapping);
67241+ /* insert tmp into the share list, just after mpnt */
67242+ vma_prio_tree_add(tmp, mpnt);
67243+ flush_dcache_mmap_unlock(mapping);
67244+ spin_unlock(&mapping->i_mmap_lock);
67245+ }
67246+
67247+ /*
67248+ * Clear hugetlb-related page reserves for children. This only
67249+ * affects MAP_PRIVATE mappings. Faults generated by the child
67250+ * are not guaranteed to succeed, even if read-only
67251+ */
67252+ if (is_vm_hugetlb_page(tmp))
67253+ reset_vma_resv_huge_pages(tmp);
67254+
67255+ return tmp;
67256+
67257+fail_nomem_anon_vma_fork:
67258+ mpol_put(pol);
67259+fail_nomem_policy:
67260+ kmem_cache_free(vm_area_cachep, tmp);
67261+fail_nomem:
67262+ vm_unacct_memory(charge);
67263+ return NULL;
67264+}
67265+
67266 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67267 {
67268 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
67269 struct rb_node **rb_link, *rb_parent;
67270 int retval;
67271- unsigned long charge;
67272- struct mempolicy *pol;
67273
67274 down_write(&oldmm->mmap_sem);
67275 flush_cache_dup_mm(oldmm);
67276@@ -327,8 +392,8 @@ static int dup_mmap(struct mm_struct *mm
67277 mm->locked_vm = 0;
67278 mm->mmap = NULL;
67279 mm->mmap_cache = NULL;
67280- mm->free_area_cache = oldmm->mmap_base;
67281- mm->cached_hole_size = ~0UL;
67282+ mm->free_area_cache = oldmm->free_area_cache;
67283+ mm->cached_hole_size = oldmm->cached_hole_size;
67284 mm->map_count = 0;
67285 cpumask_clear(mm_cpumask(mm));
67286 mm->mm_rb = RB_ROOT;
67287@@ -344,8 +409,6 @@ static int dup_mmap(struct mm_struct *mm
67288
67289 prev = NULL;
67290 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
67291- struct file *file;
67292-
67293 if (mpnt->vm_flags & VM_DONTCOPY) {
67294 long pages = vma_pages(mpnt);
67295 mm->total_vm -= pages;
67296@@ -353,56 +416,13 @@ static int dup_mmap(struct mm_struct *mm
67297 -pages);
67298 continue;
67299 }
67300- charge = 0;
67301- if (mpnt->vm_flags & VM_ACCOUNT) {
67302- unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
67303- if (security_vm_enough_memory(len))
67304- goto fail_nomem;
67305- charge = len;
67306- }
67307- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67308- if (!tmp)
67309- goto fail_nomem;
67310- *tmp = *mpnt;
67311- INIT_LIST_HEAD(&tmp->anon_vma_chain);
67312- pol = mpol_dup(vma_policy(mpnt));
67313- retval = PTR_ERR(pol);
67314- if (IS_ERR(pol))
67315- goto fail_nomem_policy;
67316- vma_set_policy(tmp, pol);
67317- tmp->vm_mm = mm;
67318- if (anon_vma_fork(tmp, mpnt))
67319- goto fail_nomem_anon_vma_fork;
67320- tmp->vm_flags &= ~VM_LOCKED;
67321- tmp->vm_next = tmp->vm_prev = NULL;
67322- file = tmp->vm_file;
67323- if (file) {
67324- struct inode *inode = file->f_path.dentry->d_inode;
67325- struct address_space *mapping = file->f_mapping;
67326-
67327- get_file(file);
67328- if (tmp->vm_flags & VM_DENYWRITE)
67329- atomic_dec(&inode->i_writecount);
67330- spin_lock(&mapping->i_mmap_lock);
67331- if (tmp->vm_flags & VM_SHARED)
67332- mapping->i_mmap_writable++;
67333- tmp->vm_truncate_count = mpnt->vm_truncate_count;
67334- flush_dcache_mmap_lock(mapping);
67335- /* insert tmp into the share list, just after mpnt */
67336- vma_prio_tree_add(tmp, mpnt);
67337- flush_dcache_mmap_unlock(mapping);
67338- spin_unlock(&mapping->i_mmap_lock);
67339+ tmp = dup_vma(mm, mpnt);
67340+ if (!tmp) {
67341+ retval = -ENOMEM;
67342+ goto out;
67343 }
67344
67345 /*
67346- * Clear hugetlb-related page reserves for children. This only
67347- * affects MAP_PRIVATE mappings. Faults generated by the child
67348- * are not guaranteed to succeed, even if read-only
67349- */
67350- if (is_vm_hugetlb_page(tmp))
67351- reset_vma_resv_huge_pages(tmp);
67352-
67353- /*
67354 * Link in the new vma and copy the page table entries.
67355 */
67356 *pprev = tmp;
67357@@ -423,6 +443,31 @@ static int dup_mmap(struct mm_struct *mm
67358 if (retval)
67359 goto out;
67360 }
67361+
67362+#ifdef CONFIG_PAX_SEGMEXEC
67363+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
67364+ struct vm_area_struct *mpnt_m;
67365+
67366+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
67367+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
67368+
67369+ if (!mpnt->vm_mirror)
67370+ continue;
67371+
67372+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
67373+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
67374+ mpnt->vm_mirror = mpnt_m;
67375+ } else {
67376+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
67377+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
67378+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
67379+ mpnt->vm_mirror->vm_mirror = mpnt;
67380+ }
67381+ }
67382+ BUG_ON(mpnt_m);
67383+ }
67384+#endif
67385+
67386 /* a new mm has just been created */
67387 arch_dup_mmap(oldmm, mm);
67388 retval = 0;
67389@@ -431,14 +476,6 @@ out:
67390 flush_tlb_mm(oldmm);
67391 up_write(&oldmm->mmap_sem);
67392 return retval;
67393-fail_nomem_anon_vma_fork:
67394- mpol_put(pol);
67395-fail_nomem_policy:
67396- kmem_cache_free(vm_area_cachep, tmp);
67397-fail_nomem:
67398- retval = -ENOMEM;
67399- vm_unacct_memory(charge);
67400- goto out;
67401 }
67402
67403 static inline int mm_alloc_pgd(struct mm_struct * mm)
67404@@ -785,13 +822,14 @@ static int copy_fs(unsigned long clone_f
67405 spin_unlock(&fs->lock);
67406 return -EAGAIN;
67407 }
67408- fs->users++;
67409+ atomic_inc(&fs->users);
67410 spin_unlock(&fs->lock);
67411 return 0;
67412 }
67413 tsk->fs = copy_fs_struct(fs);
67414 if (!tsk->fs)
67415 return -ENOMEM;
67416+ gr_set_chroot_entries(tsk, &tsk->fs->root);
67417 return 0;
67418 }
67419
67420@@ -1049,10 +1087,13 @@ static struct task_struct *copy_process(
67421 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
67422 #endif
67423 retval = -EAGAIN;
67424+
67425+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
67426+
67427 if (atomic_read(&p->real_cred->user->processes) >=
67428 task_rlimit(p, RLIMIT_NPROC)) {
67429- if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
67430- p->real_cred->user != INIT_USER)
67431+ if (p->real_cred->user != INIT_USER &&
67432+ !capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE))
67433 goto bad_fork_free;
67434 }
67435
67436@@ -1200,6 +1241,8 @@ static struct task_struct *copy_process(
67437 goto bad_fork_free_pid;
67438 }
67439
67440+ gr_copy_label(p);
67441+
67442 p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
67443 /*
67444 * Clear TID on mm_release()?
67445@@ -1360,6 +1403,8 @@ bad_fork_cleanup_count:
67446 bad_fork_free:
67447 free_task(p);
67448 fork_out:
67449+ gr_log_forkfail(retval);
67450+
67451 return ERR_PTR(retval);
67452 }
67453
67454@@ -1448,6 +1493,8 @@ long do_fork(unsigned long clone_flags,
67455 if (clone_flags & CLONE_PARENT_SETTID)
67456 put_user(nr, parent_tidptr);
67457
67458+ gr_handle_brute_check();
67459+
67460 if (clone_flags & CLONE_VFORK) {
67461 p->vfork_done = &vfork;
67462 init_completion(&vfork);
67463@@ -1549,7 +1596,7 @@ static int unshare_fs(unsigned long unsh
67464 return 0;
67465
67466 /* don't need lock here; in the worst case we'll do useless copy */
67467- if (fs->users == 1)
67468+ if (atomic_read(&fs->users) == 1)
67469 return 0;
67470
67471 *new_fsp = copy_fs_struct(fs);
67472@@ -1636,7 +1683,8 @@ SYSCALL_DEFINE1(unshare, unsigned long,
67473 fs = current->fs;
67474 spin_lock(&fs->lock);
67475 current->fs = new_fs;
67476- if (--fs->users)
67477+ gr_set_chroot_entries(current, &current->fs->root);
67478+ if (atomic_dec_return(&fs->users))
67479 new_fs = NULL;
67480 else
67481 new_fs = fs;
67482diff -urNp linux-2.6.39.1/kernel/futex.c linux-2.6.39.1/kernel/futex.c
67483--- linux-2.6.39.1/kernel/futex.c 2011-05-19 00:06:34.000000000 -0400
67484+++ linux-2.6.39.1/kernel/futex.c 2011-05-22 22:41:57.000000000 -0400
67485@@ -54,6 +54,7 @@
67486 #include <linux/mount.h>
67487 #include <linux/pagemap.h>
67488 #include <linux/syscalls.h>
67489+#include <linux/ptrace.h>
67490 #include <linux/signal.h>
67491 #include <linux/module.h>
67492 #include <linux/magic.h>
67493@@ -236,6 +237,11 @@ get_futex_key(u32 __user *uaddr, int fsh
67494 struct page *page, *page_head;
67495 int err;
67496
67497+#ifdef CONFIG_PAX_SEGMEXEC
67498+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
67499+ return -EFAULT;
67500+#endif
67501+
67502 /*
67503 * The futex address must be "naturally" aligned.
67504 */
67505@@ -1833,6 +1839,8 @@ static int futex_wait(u32 __user *uaddr,
67506 struct futex_q q = futex_q_init;
67507 int ret;
67508
67509+ pax_track_stack();
67510+
67511 if (!bitset)
67512 return -EINVAL;
67513 q.bitset = bitset;
67514@@ -2229,6 +2237,8 @@ static int futex_wait_requeue_pi(u32 __u
67515 struct futex_q q = futex_q_init;
67516 int res, ret;
67517
67518+ pax_track_stack();
67519+
67520 if (!bitset)
67521 return -EINVAL;
67522
67523@@ -2401,7 +2411,9 @@ SYSCALL_DEFINE3(get_robust_list, int, pi
67524 {
67525 struct robust_list_head __user *head;
67526 unsigned long ret;
67527+#ifndef CONFIG_GRKERNSEC_PROC_MEMMAP
67528 const struct cred *cred = current_cred(), *pcred;
67529+#endif
67530
67531 if (!futex_cmpxchg_enabled)
67532 return -ENOSYS;
67533@@ -2417,6 +2429,10 @@ SYSCALL_DEFINE3(get_robust_list, int, pi
67534 if (!p)
67535 goto err_unlock;
67536 ret = -EPERM;
67537+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67538+ if (!ptrace_may_access(p, PTRACE_MODE_READ))
67539+ goto err_unlock;
67540+#else
67541 pcred = __task_cred(p);
67542 /* If victim is in different user_ns, then uids are not
67543 comparable, so we must have CAP_SYS_PTRACE */
67544@@ -2431,6 +2447,7 @@ SYSCALL_DEFINE3(get_robust_list, int, pi
67545 !ns_capable(pcred->user->user_ns, CAP_SYS_PTRACE))
67546 goto err_unlock;
67547 ok:
67548+#endif
67549 head = p->robust_list;
67550 rcu_read_unlock();
67551 }
67552@@ -2682,6 +2699,7 @@ static int __init futex_init(void)
67553 {
67554 u32 curval;
67555 int i;
67556+ mm_segment_t oldfs;
67557
67558 /*
67559 * This will fail and we want it. Some arch implementations do
67560@@ -2693,8 +2711,11 @@ static int __init futex_init(void)
67561 * implementation, the non-functional ones will return
67562 * -ENOSYS.
67563 */
67564+ oldfs = get_fs();
67565+ set_fs(USER_DS);
67566 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
67567 futex_cmpxchg_enabled = 1;
67568+ set_fs(oldfs);
67569
67570 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
67571 plist_head_init(&futex_queues[i].chain, &futex_queues[i].lock);
67572diff -urNp linux-2.6.39.1/kernel/futex_compat.c linux-2.6.39.1/kernel/futex_compat.c
67573--- linux-2.6.39.1/kernel/futex_compat.c 2011-05-19 00:06:34.000000000 -0400
67574+++ linux-2.6.39.1/kernel/futex_compat.c 2011-05-22 22:42:09.000000000 -0400
67575@@ -10,6 +10,7 @@
67576 #include <linux/compat.h>
67577 #include <linux/nsproxy.h>
67578 #include <linux/futex.h>
67579+#include <linux/ptrace.h>
67580
67581 #include <asm/uaccess.h>
67582
67583@@ -136,7 +137,10 @@ compat_sys_get_robust_list(int pid, comp
67584 {
67585 struct compat_robust_list_head __user *head;
67586 unsigned long ret;
67587- const struct cred *cred = current_cred(), *pcred;
67588+#ifndef CONFIG_GRKERNSEC_PROC_MEMMAP
67589+ const struct cred *cred = current_cred();
67590+ const struct cred *pcred;
67591+#endif
67592
67593 if (!futex_cmpxchg_enabled)
67594 return -ENOSYS;
67595@@ -152,6 +156,10 @@ compat_sys_get_robust_list(int pid, comp
67596 if (!p)
67597 goto err_unlock;
67598 ret = -EPERM;
67599+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67600+ if (!ptrace_may_access(p, PTRACE_MODE_READ))
67601+ goto err_unlock;
67602+#else
67603 pcred = __task_cred(p);
67604 /* If victim is in different user_ns, then uids are not
67605 comparable, so we must have CAP_SYS_PTRACE */
67606@@ -166,6 +174,7 @@ compat_sys_get_robust_list(int pid, comp
67607 !ns_capable(pcred->user->user_ns, CAP_SYS_PTRACE))
67608 goto err_unlock;
67609 ok:
67610+#endif
67611 head = p->compat_robust_list;
67612 rcu_read_unlock();
67613 }
67614diff -urNp linux-2.6.39.1/kernel/gcov/base.c linux-2.6.39.1/kernel/gcov/base.c
67615--- linux-2.6.39.1/kernel/gcov/base.c 2011-05-19 00:06:34.000000000 -0400
67616+++ linux-2.6.39.1/kernel/gcov/base.c 2011-05-22 19:36:33.000000000 -0400
67617@@ -102,11 +102,6 @@ void gcov_enable_events(void)
67618 }
67619
67620 #ifdef CONFIG_MODULES
67621-static inline int within(void *addr, void *start, unsigned long size)
67622-{
67623- return ((addr >= start) && (addr < start + size));
67624-}
67625-
67626 /* Update list and generate events when modules are unloaded. */
67627 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
67628 void *data)
67629@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct n
67630 prev = NULL;
67631 /* Remove entries located in module from linked list. */
67632 for (info = gcov_info_head; info; info = info->next) {
67633- if (within(info, mod->module_core, mod->core_size)) {
67634+ if (within_module_core_rw((unsigned long)info, mod)) {
67635 if (prev)
67636 prev->next = info->next;
67637 else
67638diff -urNp linux-2.6.39.1/kernel/hrtimer.c linux-2.6.39.1/kernel/hrtimer.c
67639--- linux-2.6.39.1/kernel/hrtimer.c 2011-05-19 00:06:34.000000000 -0400
67640+++ linux-2.6.39.1/kernel/hrtimer.c 2011-05-22 19:36:33.000000000 -0400
67641@@ -1383,7 +1383,7 @@ void hrtimer_peek_ahead_timers(void)
67642 local_irq_restore(flags);
67643 }
67644
67645-static void run_hrtimer_softirq(struct softirq_action *h)
67646+static void run_hrtimer_softirq(void)
67647 {
67648 hrtimer_peek_ahead_timers();
67649 }
67650diff -urNp linux-2.6.39.1/kernel/jump_label.c linux-2.6.39.1/kernel/jump_label.c
67651--- linux-2.6.39.1/kernel/jump_label.c 2011-05-19 00:06:34.000000000 -0400
67652+++ linux-2.6.39.1/kernel/jump_label.c 2011-05-22 19:36:33.000000000 -0400
67653@@ -49,6 +49,17 @@ void jump_label_unlock(void)
67654 mutex_unlock(&jump_label_mutex);
67655 }
67656
67657+static void jump_label_swap(void *a, void *b, int size)
67658+{
67659+ struct jump_entry t;
67660+
67661+ t = *(struct jump_entry *)a;
67662+ pax_open_kernel();
67663+ *(struct jump_entry *)a = *(struct jump_entry *)b;
67664+ *(struct jump_entry *)b = t;
67665+ pax_close_kernel();
67666+}
67667+
67668 static int jump_label_cmp(const void *a, const void *b)
67669 {
67670 const struct jump_entry *jea = a;
67671@@ -70,7 +81,7 @@ sort_jump_label_entries(struct jump_entr
67672
67673 size = (((unsigned long)stop - (unsigned long)start)
67674 / sizeof(struct jump_entry));
67675- sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
67676+ sort(start, size, sizeof(struct jump_entry), jump_label_cmp, jump_label_swap);
67677 }
67678
67679 static struct jump_label_entry *get_jump_label_entry(jump_label_t key)
67680@@ -407,8 +418,11 @@ static void remove_jump_label_module_ini
67681 count = e_module->nr_entries;
67682 iter = e_module->table;
67683 while (count--) {
67684- if (within_module_init(iter->code, mod))
67685+ if (within_module_init(iter->code, mod)) {
67686+ pax_open_kernel();
67687 iter->key = 0;
67688+ pax_close_kernel();
67689+ }
67690 iter++;
67691 }
67692 }
67693diff -urNp linux-2.6.39.1/kernel/kallsyms.c linux-2.6.39.1/kernel/kallsyms.c
67694--- linux-2.6.39.1/kernel/kallsyms.c 2011-05-19 00:06:34.000000000 -0400
67695+++ linux-2.6.39.1/kernel/kallsyms.c 2011-05-22 19:41:42.000000000 -0400
67696@@ -11,6 +11,9 @@
67697 * Changed the compression method from stem compression to "table lookup"
67698 * compression (see scripts/kallsyms.c for a more complete description)
67699 */
67700+#ifdef CONFIG_GRKERNSEC_HIDESYM
67701+#define __INCLUDED_BY_HIDESYM 1
67702+#endif
67703 #include <linux/kallsyms.h>
67704 #include <linux/module.h>
67705 #include <linux/init.h>
67706@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_mark
67707
67708 static inline int is_kernel_inittext(unsigned long addr)
67709 {
67710+ if (system_state != SYSTEM_BOOTING)
67711+ return 0;
67712+
67713 if (addr >= (unsigned long)_sinittext
67714 && addr <= (unsigned long)_einittext)
67715 return 1;
67716 return 0;
67717 }
67718
67719+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67720+#ifdef CONFIG_MODULES
67721+static inline int is_module_text(unsigned long addr)
67722+{
67723+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
67724+ return 1;
67725+
67726+ addr = ktla_ktva(addr);
67727+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
67728+}
67729+#else
67730+static inline int is_module_text(unsigned long addr)
67731+{
67732+ return 0;
67733+}
67734+#endif
67735+#endif
67736+
67737 static inline int is_kernel_text(unsigned long addr)
67738 {
67739 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
67740@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigne
67741
67742 static inline int is_kernel(unsigned long addr)
67743 {
67744+
67745+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67746+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
67747+ return 1;
67748+
67749+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
67750+#else
67751 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
67752+#endif
67753+
67754 return 1;
67755 return in_gate_area_no_mm(addr);
67756 }
67757
67758 static int is_ksym_addr(unsigned long addr)
67759 {
67760+
67761+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67762+ if (is_module_text(addr))
67763+ return 0;
67764+#endif
67765+
67766 if (all_var)
67767 return is_kernel(addr);
67768
67769@@ -454,7 +493,6 @@ static unsigned long get_ksymbol_core(st
67770
67771 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
67772 {
67773- iter->name[0] = '\0';
67774 iter->nameoff = get_symbol_offset(new_pos);
67775 iter->pos = new_pos;
67776 }
67777@@ -502,6 +540,11 @@ static int s_show(struct seq_file *m, vo
67778 {
67779 struct kallsym_iter *iter = m->private;
67780
67781+#ifdef CONFIG_GRKERNSEC_HIDESYM
67782+ if (current_uid())
67783+ return 0;
67784+#endif
67785+
67786 /* Some debugging symbols have no name. Ignore them. */
67787 if (!iter->name[0])
67788 return 0;
67789@@ -540,7 +583,7 @@ static int kallsyms_open(struct inode *i
67790 struct kallsym_iter *iter;
67791 int ret;
67792
67793- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
67794+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
67795 if (!iter)
67796 return -ENOMEM;
67797 reset_iter(iter, 0);
67798diff -urNp linux-2.6.39.1/kernel/kmod.c linux-2.6.39.1/kernel/kmod.c
67799--- linux-2.6.39.1/kernel/kmod.c 2011-05-19 00:06:34.000000000 -0400
67800+++ linux-2.6.39.1/kernel/kmod.c 2011-05-22 19:41:42.000000000 -0400
67801@@ -65,13 +65,12 @@ char modprobe_path[KMOD_PATH_LEN] = "/sb
67802 * If module auto-loading support is disabled then this function
67803 * becomes a no-operation.
67804 */
67805-int __request_module(bool wait, const char *fmt, ...)
67806+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
67807 {
67808- va_list args;
67809 char module_name[MODULE_NAME_LEN];
67810 unsigned int max_modprobes;
67811 int ret;
67812- char *argv[] = { modprobe_path, "-q", "--", module_name, NULL };
67813+ char *argv[] = { modprobe_path, "-q", "--", module_name, module_param, NULL };
67814 static char *envp[] = { "HOME=/",
67815 "TERM=linux",
67816 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
67817@@ -80,9 +79,7 @@ int __request_module(bool wait, const ch
67818 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
67819 static int kmod_loop_msg;
67820
67821- va_start(args, fmt);
67822- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
67823- va_end(args);
67824+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
67825 if (ret >= MODULE_NAME_LEN)
67826 return -ENAMETOOLONG;
67827
67828@@ -90,6 +87,20 @@ int __request_module(bool wait, const ch
67829 if (ret)
67830 return ret;
67831
67832+#ifdef CONFIG_GRKERNSEC_MODHARDEN
67833+ if (!current_uid()) {
67834+ /* hack to workaround consolekit/udisks stupidity */
67835+ read_lock(&tasklist_lock);
67836+ if (!strcmp(current->comm, "mount") &&
67837+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
67838+ read_unlock(&tasklist_lock);
67839+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
67840+ return -EPERM;
67841+ }
67842+ read_unlock(&tasklist_lock);
67843+ }
67844+#endif
67845+
67846 /* If modprobe needs a service that is in a module, we get a recursive
67847 * loop. Limit the number of running kmod threads to max_threads/2 or
67848 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
67849@@ -123,6 +134,47 @@ int __request_module(bool wait, const ch
67850 atomic_dec(&kmod_concurrent);
67851 return ret;
67852 }
67853+
67854+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
67855+{
67856+ va_list args;
67857+ int ret;
67858+
67859+ va_start(args, fmt);
67860+ ret = ____request_module(wait, module_param, fmt, args);
67861+ va_end(args);
67862+
67863+ return ret;
67864+}
67865+
67866+int __request_module(bool wait, const char *fmt, ...)
67867+{
67868+ va_list args;
67869+ int ret;
67870+
67871+#ifdef CONFIG_GRKERNSEC_MODHARDEN
67872+ if (current_uid()) {
67873+ char module_param[MODULE_NAME_LEN];
67874+
67875+ memset(module_param, 0, sizeof(module_param));
67876+
67877+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
67878+
67879+ va_start(args, fmt);
67880+ ret = ____request_module(wait, module_param, fmt, args);
67881+ va_end(args);
67882+
67883+ return ret;
67884+ }
67885+#endif
67886+
67887+ va_start(args, fmt);
67888+ ret = ____request_module(wait, NULL, fmt, args);
67889+ va_end(args);
67890+
67891+ return ret;
67892+}
67893+
67894 EXPORT_SYMBOL(__request_module);
67895 #endif /* CONFIG_MODULES */
67896
67897diff -urNp linux-2.6.39.1/kernel/kprobes.c linux-2.6.39.1/kernel/kprobes.c
67898--- linux-2.6.39.1/kernel/kprobes.c 2011-05-19 00:06:34.000000000 -0400
67899+++ linux-2.6.39.1/kernel/kprobes.c 2011-05-22 19:36:33.000000000 -0400
67900@@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_
67901 * kernel image and loaded module images reside. This is required
67902 * so x86_64 can correctly handle the %rip-relative fixups.
67903 */
67904- kip->insns = module_alloc(PAGE_SIZE);
67905+ kip->insns = module_alloc_exec(PAGE_SIZE);
67906 if (!kip->insns) {
67907 kfree(kip);
67908 return NULL;
67909@@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(st
67910 */
67911 if (!list_is_singular(&kip->list)) {
67912 list_del(&kip->list);
67913- module_free(NULL, kip->insns);
67914+ module_free_exec(NULL, kip->insns);
67915 kfree(kip);
67916 }
67917 return 1;
67918@@ -1936,7 +1936,7 @@ static int __init init_kprobes(void)
67919 {
67920 int i, err = 0;
67921 unsigned long offset = 0, size = 0;
67922- char *modname, namebuf[128];
67923+ char *modname, namebuf[KSYM_NAME_LEN];
67924 const char *symbol_name;
67925 void *addr;
67926 struct kprobe_blackpoint *kb;
67927@@ -2062,7 +2062,7 @@ static int __kprobes show_kprobe_addr(st
67928 const char *sym = NULL;
67929 unsigned int i = *(loff_t *) v;
67930 unsigned long offset = 0;
67931- char *modname, namebuf[128];
67932+ char *modname, namebuf[KSYM_NAME_LEN];
67933
67934 head = &kprobe_table[i];
67935 preempt_disable();
67936diff -urNp linux-2.6.39.1/kernel/lockdep.c linux-2.6.39.1/kernel/lockdep.c
67937--- linux-2.6.39.1/kernel/lockdep.c 2011-05-19 00:06:34.000000000 -0400
67938+++ linux-2.6.39.1/kernel/lockdep.c 2011-05-22 19:36:33.000000000 -0400
67939@@ -571,6 +571,10 @@ static int static_obj(void *obj)
67940 end = (unsigned long) &_end,
67941 addr = (unsigned long) obj;
67942
67943+#ifdef CONFIG_PAX_KERNEXEC
67944+ start = ktla_ktva(start);
67945+#endif
67946+
67947 /*
67948 * static variable?
67949 */
67950@@ -706,6 +710,7 @@ register_lock_class(struct lockdep_map *
67951 if (!static_obj(lock->key)) {
67952 debug_locks_off();
67953 printk("INFO: trying to register non-static key.\n");
67954+ printk("lock:%pS key:%pS.\n", lock, lock->key);
67955 printk("the code is fine but needs lockdep annotation.\n");
67956 printk("turning off the locking correctness validator.\n");
67957 dump_stack();
67958@@ -2752,7 +2757,7 @@ static int __lock_acquire(struct lockdep
67959 if (!class)
67960 return 0;
67961 }
67962- atomic_inc((atomic_t *)&class->ops);
67963+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
67964 if (very_verbose(class)) {
67965 printk("\nacquire class [%p] %s", class->key, class->name);
67966 if (class->name_version > 1)
67967diff -urNp linux-2.6.39.1/kernel/lockdep_proc.c linux-2.6.39.1/kernel/lockdep_proc.c
67968--- linux-2.6.39.1/kernel/lockdep_proc.c 2011-05-19 00:06:34.000000000 -0400
67969+++ linux-2.6.39.1/kernel/lockdep_proc.c 2011-05-22 19:36:33.000000000 -0400
67970@@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, v
67971
67972 static void print_name(struct seq_file *m, struct lock_class *class)
67973 {
67974- char str[128];
67975+ char str[KSYM_NAME_LEN];
67976 const char *name = class->name;
67977
67978 if (!name) {
67979diff -urNp linux-2.6.39.1/kernel/module.c linux-2.6.39.1/kernel/module.c
67980--- linux-2.6.39.1/kernel/module.c 2011-05-19 00:06:34.000000000 -0400
67981+++ linux-2.6.39.1/kernel/module.c 2011-05-22 19:41:42.000000000 -0400
67982@@ -57,6 +57,7 @@
67983 #include <linux/kmemleak.h>
67984 #include <linux/jump_label.h>
67985 #include <linux/pfn.h>
67986+#include <linux/grsecurity.h>
67987
67988 #define CREATE_TRACE_POINTS
67989 #include <trace/events/module.h>
67990@@ -118,7 +119,8 @@ static BLOCKING_NOTIFIER_HEAD(module_not
67991
67992 /* Bounds of module allocation, for speeding __module_address.
67993 * Protected by module_mutex. */
67994-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
67995+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
67996+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
67997
67998 int register_module_notifier(struct notifier_block * nb)
67999 {
68000@@ -282,7 +284,7 @@ bool each_symbol(bool (*fn)(const struct
68001 return true;
68002
68003 list_for_each_entry_rcu(mod, &modules, list) {
68004- struct symsearch arr[] = {
68005+ struct symsearch modarr[] = {
68006 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
68007 NOT_GPL_ONLY, false },
68008 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
68009@@ -304,7 +306,7 @@ bool each_symbol(bool (*fn)(const struct
68010 #endif
68011 };
68012
68013- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
68014+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
68015 return true;
68016 }
68017 return false;
68018@@ -415,7 +417,7 @@ static inline void __percpu *mod_percpu(
68019 static int percpu_modalloc(struct module *mod,
68020 unsigned long size, unsigned long align)
68021 {
68022- if (align > PAGE_SIZE) {
68023+ if (align-1 >= PAGE_SIZE) {
68024 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
68025 mod->name, align, PAGE_SIZE);
68026 align = PAGE_SIZE;
68027@@ -1143,7 +1145,7 @@ resolve_symbol_wait(struct module *mod,
68028 */
68029 #ifdef CONFIG_SYSFS
68030
68031-#ifdef CONFIG_KALLSYMS
68032+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
68033 static inline bool sect_empty(const Elf_Shdr *sect)
68034 {
68035 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
68036@@ -1612,17 +1614,17 @@ void unset_section_ro_nx(struct module *
68037 {
68038 unsigned long total_pages;
68039
68040- if (mod->module_core == module_region) {
68041+ if (mod->module_core_rx == module_region) {
68042 /* Set core as NX+RW */
68043- total_pages = MOD_NUMBER_OF_PAGES(mod->module_core, mod->core_size);
68044- set_memory_nx((unsigned long)mod->module_core, total_pages);
68045- set_memory_rw((unsigned long)mod->module_core, total_pages);
68046+ total_pages = MOD_NUMBER_OF_PAGES(mod->module_core_rx, mod->core_size_rx);
68047+ set_memory_nx((unsigned long)mod->module_core_rx, total_pages);
68048+ set_memory_rw((unsigned long)mod->module_core_rx, total_pages);
68049
68050- } else if (mod->module_init == module_region) {
68051+ } else if (mod->module_init_rx == module_region) {
68052 /* Set init as NX+RW */
68053- total_pages = MOD_NUMBER_OF_PAGES(mod->module_init, mod->init_size);
68054- set_memory_nx((unsigned long)mod->module_init, total_pages);
68055- set_memory_rw((unsigned long)mod->module_init, total_pages);
68056+ total_pages = MOD_NUMBER_OF_PAGES(mod->module_init_rx, mod->init_size_rx);
68057+ set_memory_nx((unsigned long)mod->module_init_rx, total_pages);
68058+ set_memory_rw((unsigned long)mod->module_init_rx, total_pages);
68059 }
68060 }
68061
68062@@ -1633,14 +1635,14 @@ void set_all_modules_text_rw()
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_rw);
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_rw);
68081 }
68082 }
68083@@ -1654,14 +1656,14 @@ void set_all_modules_text_ro()
68084
68085 mutex_lock(&module_mutex);
68086 list_for_each_entry_rcu(mod, &modules, list) {
68087- if ((mod->module_core) && (mod->core_text_size)) {
68088- set_page_attributes(mod->module_core,
68089- mod->module_core + mod->core_text_size,
68090+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
68091+ set_page_attributes(mod->module_core_rx,
68092+ mod->module_core_rx + mod->core_size_rx,
68093 set_memory_ro);
68094 }
68095- if ((mod->module_init) && (mod->init_text_size)) {
68096- set_page_attributes(mod->module_init,
68097- mod->module_init + mod->init_text_size,
68098+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
68099+ set_page_attributes(mod->module_init_rx,
68100+ mod->module_init_rx + mod->init_size_rx,
68101 set_memory_ro);
68102 }
68103 }
68104@@ -1696,17 +1698,20 @@ static void free_module(struct module *m
68105 destroy_params(mod->kp, mod->num_kp);
68106
68107 /* This may be NULL, but that's OK */
68108- unset_section_ro_nx(mod, mod->module_init);
68109- module_free(mod, mod->module_init);
68110+ unset_section_ro_nx(mod, mod->module_init_rx);
68111+ module_free(mod, mod->module_init_rw);
68112+ module_free_exec(mod, mod->module_init_rx);
68113 kfree(mod->args);
68114 percpu_modfree(mod);
68115
68116 /* Free lock-classes: */
68117- lockdep_free_key_range(mod->module_core, mod->core_size);
68118+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
68119+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
68120
68121 /* Finally, free the core (containing the module structure) */
68122- unset_section_ro_nx(mod, mod->module_core);
68123- module_free(mod, mod->module_core);
68124+ unset_section_ro_nx(mod, mod->module_core_rx);
68125+ module_free_exec(mod, mod->module_core_rx);
68126+ module_free(mod, mod->module_core_rw);
68127
68128 #ifdef CONFIG_MPU
68129 update_protections(current->mm);
68130@@ -1775,10 +1780,31 @@ static int simplify_symbols(struct modul
68131 unsigned int i;
68132 int ret = 0;
68133 const struct kernel_symbol *ksym;
68134+#ifdef CONFIG_GRKERNSEC_MODHARDEN
68135+ int is_fs_load = 0;
68136+ int register_filesystem_found = 0;
68137+ char *p;
68138+
68139+ p = strstr(mod->args, "grsec_modharden_fs");
68140+ if (p) {
68141+ char *endptr = p + strlen("grsec_modharden_fs");
68142+ /* copy \0 as well */
68143+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
68144+ is_fs_load = 1;
68145+ }
68146+#endif
68147
68148 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
68149 const char *name = info->strtab + sym[i].st_name;
68150
68151+#ifdef CONFIG_GRKERNSEC_MODHARDEN
68152+ /* it's a real shame this will never get ripped and copied
68153+ upstream! ;(
68154+ */
68155+ if (is_fs_load && !strcmp(name, "register_filesystem"))
68156+ register_filesystem_found = 1;
68157+#endif
68158+
68159 switch (sym[i].st_shndx) {
68160 case SHN_COMMON:
68161 /* We compiled with -fno-common. These are not
68162@@ -1799,7 +1825,9 @@ static int simplify_symbols(struct modul
68163 ksym = resolve_symbol_wait(mod, info, name);
68164 /* Ok if resolved. */
68165 if (ksym && !IS_ERR(ksym)) {
68166+ pax_open_kernel();
68167 sym[i].st_value = ksym->value;
68168+ pax_close_kernel();
68169 break;
68170 }
68171
68172@@ -1818,11 +1846,20 @@ static int simplify_symbols(struct modul
68173 secbase = (unsigned long)mod_percpu(mod);
68174 else
68175 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
68176+ pax_open_kernel();
68177 sym[i].st_value += secbase;
68178+ pax_close_kernel();
68179 break;
68180 }
68181 }
68182
68183+#ifdef CONFIG_GRKERNSEC_MODHARDEN
68184+ if (is_fs_load && !register_filesystem_found) {
68185+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
68186+ ret = -EPERM;
68187+ }
68188+#endif
68189+
68190 return ret;
68191 }
68192
68193@@ -1906,22 +1943,12 @@ static void layout_sections(struct modul
68194 || s->sh_entsize != ~0UL
68195 || strstarts(sname, ".init"))
68196 continue;
68197- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
68198+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68199+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
68200+ else
68201+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
68202 DEBUGP("\t%s\n", name);
68203 }
68204- switch (m) {
68205- case 0: /* executable */
68206- mod->core_size = debug_align(mod->core_size);
68207- mod->core_text_size = mod->core_size;
68208- break;
68209- case 1: /* RO: text and ro-data */
68210- mod->core_size = debug_align(mod->core_size);
68211- mod->core_ro_size = mod->core_size;
68212- break;
68213- case 3: /* whole core */
68214- mod->core_size = debug_align(mod->core_size);
68215- break;
68216- }
68217 }
68218
68219 DEBUGP("Init section allocation order:\n");
68220@@ -1935,23 +1962,13 @@ static void layout_sections(struct modul
68221 || s->sh_entsize != ~0UL
68222 || !strstarts(sname, ".init"))
68223 continue;
68224- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
68225- | INIT_OFFSET_MASK);
68226+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68227+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
68228+ else
68229+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
68230+ s->sh_entsize |= INIT_OFFSET_MASK;
68231 DEBUGP("\t%s\n", sname);
68232 }
68233- switch (m) {
68234- case 0: /* executable */
68235- mod->init_size = debug_align(mod->init_size);
68236- mod->init_text_size = mod->init_size;
68237- break;
68238- case 1: /* RO: text and ro-data */
68239- mod->init_size = debug_align(mod->init_size);
68240- mod->init_ro_size = mod->init_size;
68241- break;
68242- case 3: /* whole init */
68243- mod->init_size = debug_align(mod->init_size);
68244- break;
68245- }
68246 }
68247 }
68248
68249@@ -2119,7 +2136,7 @@ static void layout_symtab(struct module
68250
68251 /* Put symbol section at end of init part of module. */
68252 symsect->sh_flags |= SHF_ALLOC;
68253- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
68254+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
68255 info->index.sym) | INIT_OFFSET_MASK;
68256 DEBUGP("\t%s\n", info->secstrings + symsect->sh_name);
68257
68258@@ -2136,19 +2153,19 @@ static void layout_symtab(struct module
68259 }
68260
68261 /* Append room for core symbols at end of core part. */
68262- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
68263- mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
68264+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
68265+ mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
68266
68267 /* Put string table section at end of init part of module. */
68268 strsect->sh_flags |= SHF_ALLOC;
68269- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
68270+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
68271 info->index.str) | INIT_OFFSET_MASK;
68272 DEBUGP("\t%s\n", info->secstrings + strsect->sh_name);
68273
68274 /* Append room for core symbols' strings at end of core part. */
68275- info->stroffs = mod->core_size;
68276+ info->stroffs = mod->core_size_rx;
68277 __set_bit(0, info->strmap);
68278- mod->core_size += bitmap_weight(info->strmap, strsect->sh_size);
68279+ mod->core_size_rx += bitmap_weight(info->strmap, strsect->sh_size);
68280 }
68281
68282 static void add_kallsyms(struct module *mod, const struct load_info *info)
68283@@ -2164,11 +2181,13 @@ static void add_kallsyms(struct module *
68284 /* Make sure we get permanent strtab: don't use info->strtab. */
68285 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
68286
68287+ pax_open_kernel();
68288+
68289 /* Set types up while we still have access to sections. */
68290 for (i = 0; i < mod->num_symtab; i++)
68291 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
68292
68293- mod->core_symtab = dst = mod->module_core + info->symoffs;
68294+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
68295 src = mod->symtab;
68296 *dst = *src;
68297 for (ndst = i = 1; i < mod->num_symtab; ++i, ++src) {
68298@@ -2181,10 +2200,12 @@ static void add_kallsyms(struct module *
68299 }
68300 mod->core_num_syms = ndst;
68301
68302- mod->core_strtab = s = mod->module_core + info->stroffs;
68303+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
68304 for (*s = 0, i = 1; i < info->sechdrs[info->index.str].sh_size; ++i)
68305 if (test_bit(i, info->strmap))
68306 *++s = mod->strtab[i];
68307+
68308+ pax_close_kernel();
68309 }
68310 #else
68311 static inline void layout_symtab(struct module *mod, struct load_info *info)
68312@@ -2213,17 +2234,33 @@ static void dynamic_debug_remove(struct
68313 ddebug_remove_module(debug->modname);
68314 }
68315
68316-static void *module_alloc_update_bounds(unsigned long size)
68317+static void *module_alloc_update_bounds_rw(unsigned long size)
68318 {
68319 void *ret = module_alloc(size);
68320
68321 if (ret) {
68322 mutex_lock(&module_mutex);
68323 /* Update module bounds. */
68324- if ((unsigned long)ret < module_addr_min)
68325- module_addr_min = (unsigned long)ret;
68326- if ((unsigned long)ret + size > module_addr_max)
68327- module_addr_max = (unsigned long)ret + size;
68328+ if ((unsigned long)ret < module_addr_min_rw)
68329+ module_addr_min_rw = (unsigned long)ret;
68330+ if ((unsigned long)ret + size > module_addr_max_rw)
68331+ module_addr_max_rw = (unsigned long)ret + size;
68332+ mutex_unlock(&module_mutex);
68333+ }
68334+ return ret;
68335+}
68336+
68337+static void *module_alloc_update_bounds_rx(unsigned long size)
68338+{
68339+ void *ret = module_alloc_exec(size);
68340+
68341+ if (ret) {
68342+ mutex_lock(&module_mutex);
68343+ /* Update module bounds. */
68344+ if ((unsigned long)ret < module_addr_min_rx)
68345+ module_addr_min_rx = (unsigned long)ret;
68346+ if ((unsigned long)ret + size > module_addr_max_rx)
68347+ module_addr_max_rx = (unsigned long)ret + size;
68348 mutex_unlock(&module_mutex);
68349 }
68350 return ret;
68351@@ -2516,7 +2553,7 @@ static int move_module(struct module *mo
68352 void *ptr;
68353
68354 /* Do the allocs. */
68355- ptr = module_alloc_update_bounds(mod->core_size);
68356+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
68357 /*
68358 * The pointer to this block is stored in the module structure
68359 * which is inside the block. Just mark it as not being a
68360@@ -2526,23 +2563,50 @@ static int move_module(struct module *mo
68361 if (!ptr)
68362 return -ENOMEM;
68363
68364- memset(ptr, 0, mod->core_size);
68365- mod->module_core = ptr;
68366+ memset(ptr, 0, mod->core_size_rw);
68367+ mod->module_core_rw = ptr;
68368
68369- ptr = module_alloc_update_bounds(mod->init_size);
68370+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
68371 /*
68372 * The pointer to this block is stored in the module structure
68373 * which is inside the block. This block doesn't need to be
68374 * scanned as it contains data and code that will be freed
68375 * after the module is initialized.
68376 */
68377- kmemleak_ignore(ptr);
68378- if (!ptr && mod->init_size) {
68379- module_free(mod, mod->module_core);
68380+ kmemleak_not_leak(ptr);
68381+ if (!ptr && mod->init_size_rw) {
68382+ module_free(mod, mod->module_core_rw);
68383 return -ENOMEM;
68384 }
68385- memset(ptr, 0, mod->init_size);
68386- mod->module_init = ptr;
68387+ memset(ptr, 0, mod->init_size_rw);
68388+ mod->module_init_rw = ptr;
68389+
68390+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
68391+ kmemleak_not_leak(ptr);
68392+ if (!ptr) {
68393+ module_free(mod, mod->module_init_rw);
68394+ module_free(mod, mod->module_core_rw);
68395+ return -ENOMEM;
68396+ }
68397+
68398+ pax_open_kernel();
68399+ memset(ptr, 0, mod->core_size_rx);
68400+ pax_close_kernel();
68401+ mod->module_core_rx = ptr;
68402+
68403+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
68404+ kmemleak_not_leak(ptr);
68405+ if (!ptr && mod->init_size_rx) {
68406+ module_free_exec(mod, mod->module_core_rx);
68407+ module_free(mod, mod->module_init_rw);
68408+ module_free(mod, mod->module_core_rw);
68409+ return -ENOMEM;
68410+ }
68411+
68412+ pax_open_kernel();
68413+ memset(ptr, 0, mod->init_size_rx);
68414+ pax_close_kernel();
68415+ mod->module_init_rx = ptr;
68416
68417 /* Transfer each section which specifies SHF_ALLOC */
68418 DEBUGP("final section addresses:\n");
68419@@ -2553,16 +2617,45 @@ static int move_module(struct module *mo
68420 if (!(shdr->sh_flags & SHF_ALLOC))
68421 continue;
68422
68423- if (shdr->sh_entsize & INIT_OFFSET_MASK)
68424- dest = mod->module_init
68425- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68426- else
68427- dest = mod->module_core + shdr->sh_entsize;
68428+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
68429+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
68430+ dest = mod->module_init_rw
68431+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68432+ else
68433+ dest = mod->module_init_rx
68434+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68435+ } else {
68436+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
68437+ dest = mod->module_core_rw + shdr->sh_entsize;
68438+ else
68439+ dest = mod->module_core_rx + shdr->sh_entsize;
68440+ }
68441+
68442+ if (shdr->sh_type != SHT_NOBITS) {
68443+
68444+#ifdef CONFIG_PAX_KERNEXEC
68445+#ifdef CONFIG_X86_64
68446+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
68447+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
68448+#endif
68449+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
68450+ pax_open_kernel();
68451+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
68452+ pax_close_kernel();
68453+ } else
68454+#endif
68455
68456- if (shdr->sh_type != SHT_NOBITS)
68457 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
68458+ }
68459 /* Update sh_addr to point to copy in image. */
68460- shdr->sh_addr = (unsigned long)dest;
68461+
68462+#ifdef CONFIG_PAX_KERNEXEC
68463+ if (shdr->sh_flags & SHF_EXECINSTR)
68464+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
68465+ else
68466+#endif
68467+
68468+ shdr->sh_addr = (unsigned long)dest;
68469 DEBUGP("\t0x%lx %s\n",
68470 shdr->sh_addr, info->secstrings + shdr->sh_name);
68471 }
68472@@ -2613,12 +2706,12 @@ static void flush_module_icache(const st
68473 * Do it before processing of module parameters, so the module
68474 * can provide parameter accessor functions of its own.
68475 */
68476- if (mod->module_init)
68477- flush_icache_range((unsigned long)mod->module_init,
68478- (unsigned long)mod->module_init
68479- + mod->init_size);
68480- flush_icache_range((unsigned long)mod->module_core,
68481- (unsigned long)mod->module_core + mod->core_size);
68482+ if (mod->module_init_rx)
68483+ flush_icache_range((unsigned long)mod->module_init_rx,
68484+ (unsigned long)mod->module_init_rx
68485+ + mod->init_size_rx);
68486+ flush_icache_range((unsigned long)mod->module_core_rx,
68487+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
68488
68489 set_fs(old_fs);
68490 }
68491@@ -2690,8 +2783,10 @@ static void module_deallocate(struct mod
68492 {
68493 kfree(info->strmap);
68494 percpu_modfree(mod);
68495- module_free(mod, mod->module_init);
68496- module_free(mod, mod->module_core);
68497+ module_free_exec(mod, mod->module_init_rx);
68498+ module_free_exec(mod, mod->module_core_rx);
68499+ module_free(mod, mod->module_init_rw);
68500+ module_free(mod, mod->module_core_rw);
68501 }
68502
68503 static int post_relocation(struct module *mod, const struct load_info *info)
68504@@ -2748,9 +2843,38 @@ static struct module *load_module(void _
68505 if (err)
68506 goto free_unload;
68507
68508+ /* Now copy in args */
68509+ mod->args = strndup_user(uargs, ~0UL >> 1);
68510+ if (IS_ERR(mod->args)) {
68511+ err = PTR_ERR(mod->args);
68512+ goto free_unload;
68513+ }
68514+
68515 /* Set up MODINFO_ATTR fields */
68516 setup_modinfo(mod, &info);
68517
68518+#ifdef CONFIG_GRKERNSEC_MODHARDEN
68519+ {
68520+ char *p, *p2;
68521+
68522+ if (strstr(mod->args, "grsec_modharden_netdev")) {
68523+ 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);
68524+ err = -EPERM;
68525+ goto free_modinfo;
68526+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
68527+ p += strlen("grsec_modharden_normal");
68528+ p2 = strstr(p, "_");
68529+ if (p2) {
68530+ *p2 = '\0';
68531+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
68532+ *p2 = '_';
68533+ }
68534+ err = -EPERM;
68535+ goto free_modinfo;
68536+ }
68537+ }
68538+#endif
68539+
68540 /* Fix up syms, so that st_value is a pointer to location. */
68541 err = simplify_symbols(mod, &info);
68542 if (err < 0)
68543@@ -2766,13 +2890,6 @@ static struct module *load_module(void _
68544
68545 flush_module_icache(mod);
68546
68547- /* Now copy in args */
68548- mod->args = strndup_user(uargs, ~0UL >> 1);
68549- if (IS_ERR(mod->args)) {
68550- err = PTR_ERR(mod->args);
68551- goto free_arch_cleanup;
68552- }
68553-
68554 /* Mark state as coming so strong_try_module_get() ignores us. */
68555 mod->state = MODULE_STATE_COMING;
68556
68557@@ -2832,11 +2949,10 @@ static struct module *load_module(void _
68558 unlock:
68559 mutex_unlock(&module_mutex);
68560 synchronize_sched();
68561- kfree(mod->args);
68562- free_arch_cleanup:
68563 module_arch_cleanup(mod);
68564 free_modinfo:
68565 free_modinfo(mod);
68566+ kfree(mod->args);
68567 free_unload:
68568 module_unload_free(mod);
68569 free_module:
68570@@ -2877,16 +2993,16 @@ SYSCALL_DEFINE3(init_module, void __user
68571 MODULE_STATE_COMING, mod);
68572
68573 /* Set RO and NX regions for core */
68574- set_section_ro_nx(mod->module_core,
68575- mod->core_text_size,
68576- mod->core_ro_size,
68577- mod->core_size);
68578+ set_section_ro_nx(mod->module_core_rx,
68579+ mod->core_size_rx,
68580+ mod->core_size_rx,
68581+ mod->core_size_rx);
68582
68583 /* Set RO and NX regions for init */
68584- set_section_ro_nx(mod->module_init,
68585- mod->init_text_size,
68586- mod->init_ro_size,
68587- mod->init_size);
68588+ set_section_ro_nx(mod->module_init_rx,
68589+ mod->init_size_rx,
68590+ mod->init_size_rx,
68591+ mod->init_size_rx);
68592
68593 do_mod_ctors(mod);
68594 /* Start the module */
68595@@ -2931,11 +3047,13 @@ SYSCALL_DEFINE3(init_module, void __user
68596 mod->symtab = mod->core_symtab;
68597 mod->strtab = mod->core_strtab;
68598 #endif
68599- unset_section_ro_nx(mod, mod->module_init);
68600- module_free(mod, mod->module_init);
68601- mod->module_init = NULL;
68602- mod->init_size = 0;
68603- mod->init_text_size = 0;
68604+ unset_section_ro_nx(mod, mod->module_init_rx);
68605+ module_free(mod, mod->module_init_rw);
68606+ module_free_exec(mod, mod->module_init_rx);
68607+ mod->module_init_rw = NULL;
68608+ mod->module_init_rx = NULL;
68609+ mod->init_size_rw = 0;
68610+ mod->init_size_rx = 0;
68611 mutex_unlock(&module_mutex);
68612
68613 return 0;
68614@@ -2966,10 +3084,16 @@ static const char *get_ksymbol(struct mo
68615 unsigned long nextval;
68616
68617 /* At worse, next value is at end of module */
68618- if (within_module_init(addr, mod))
68619- nextval = (unsigned long)mod->module_init+mod->init_text_size;
68620+ if (within_module_init_rx(addr, mod))
68621+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
68622+ else if (within_module_init_rw(addr, mod))
68623+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
68624+ else if (within_module_core_rx(addr, mod))
68625+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
68626+ else if (within_module_core_rw(addr, mod))
68627+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
68628 else
68629- nextval = (unsigned long)mod->module_core+mod->core_text_size;
68630+ return NULL;
68631
68632 /* Scan for closest preceding symbol, and next symbol. (ELF
68633 starts real symbols at 1). */
68634@@ -3215,7 +3339,7 @@ static int m_show(struct seq_file *m, vo
68635 char buf[8];
68636
68637 seq_printf(m, "%s %u",
68638- mod->name, mod->init_size + mod->core_size);
68639+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
68640 print_unload_info(m, mod);
68641
68642 /* Informative for users. */
68643@@ -3224,7 +3348,7 @@ static int m_show(struct seq_file *m, vo
68644 mod->state == MODULE_STATE_COMING ? "Loading":
68645 "Live");
68646 /* Used by oprofile and other similar tools. */
68647- seq_printf(m, " 0x%pK", mod->module_core);
68648+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
68649
68650 /* Taints info */
68651 if (mod->taints)
68652@@ -3260,7 +3384,17 @@ static const struct file_operations proc
68653
68654 static int __init proc_modules_init(void)
68655 {
68656+#ifndef CONFIG_GRKERNSEC_HIDESYM
68657+#ifdef CONFIG_GRKERNSEC_PROC_USER
68658+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
68659+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68660+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
68661+#else
68662 proc_create("modules", 0, NULL, &proc_modules_operations);
68663+#endif
68664+#else
68665+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
68666+#endif
68667 return 0;
68668 }
68669 module_init(proc_modules_init);
68670@@ -3319,12 +3453,12 @@ struct module *__module_address(unsigned
68671 {
68672 struct module *mod;
68673
68674- if (addr < module_addr_min || addr > module_addr_max)
68675+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
68676+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
68677 return NULL;
68678
68679 list_for_each_entry_rcu(mod, &modules, list)
68680- if (within_module_core(addr, mod)
68681- || within_module_init(addr, mod))
68682+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
68683 return mod;
68684 return NULL;
68685 }
68686@@ -3358,11 +3492,20 @@ bool is_module_text_address(unsigned lon
68687 */
68688 struct module *__module_text_address(unsigned long addr)
68689 {
68690- struct module *mod = __module_address(addr);
68691+ struct module *mod;
68692+
68693+#ifdef CONFIG_X86_32
68694+ addr = ktla_ktva(addr);
68695+#endif
68696+
68697+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
68698+ return NULL;
68699+
68700+ mod = __module_address(addr);
68701+
68702 if (mod) {
68703 /* Make sure it's within the text section. */
68704- if (!within(addr, mod->module_init, mod->init_text_size)
68705- && !within(addr, mod->module_core, mod->core_text_size))
68706+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
68707 mod = NULL;
68708 }
68709 return mod;
68710diff -urNp linux-2.6.39.1/kernel/mutex.c linux-2.6.39.1/kernel/mutex.c
68711--- linux-2.6.39.1/kernel/mutex.c 2011-05-19 00:06:34.000000000 -0400
68712+++ linux-2.6.39.1/kernel/mutex.c 2011-05-22 19:36:33.000000000 -0400
68713@@ -160,7 +160,7 @@ __mutex_lock_common(struct mutex *lock,
68714 */
68715
68716 for (;;) {
68717- struct thread_info *owner;
68718+ struct task_struct *owner;
68719
68720 /*
68721 * If we own the BKL, then don't spin. The owner of
68722@@ -205,7 +205,7 @@ __mutex_lock_common(struct mutex *lock,
68723 spin_lock_mutex(&lock->wait_lock, flags);
68724
68725 debug_mutex_lock_common(lock, &waiter);
68726- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
68727+ debug_mutex_add_waiter(lock, &waiter, task);
68728
68729 /* add waiting tasks to the end of the waitqueue (FIFO): */
68730 list_add_tail(&waiter.list, &lock->wait_list);
68731@@ -234,8 +234,7 @@ __mutex_lock_common(struct mutex *lock,
68732 * TASK_UNINTERRUPTIBLE case.)
68733 */
68734 if (unlikely(signal_pending_state(state, task))) {
68735- mutex_remove_waiter(lock, &waiter,
68736- task_thread_info(task));
68737+ mutex_remove_waiter(lock, &waiter, task);
68738 mutex_release(&lock->dep_map, 1, ip);
68739 spin_unlock_mutex(&lock->wait_lock, flags);
68740
68741@@ -256,7 +255,7 @@ __mutex_lock_common(struct mutex *lock,
68742 done:
68743 lock_acquired(&lock->dep_map, ip);
68744 /* got the lock - rejoice! */
68745- mutex_remove_waiter(lock, &waiter, current_thread_info());
68746+ mutex_remove_waiter(lock, &waiter, task);
68747 mutex_set_owner(lock);
68748
68749 /* set it to 0 if there are no waiters left: */
68750diff -urNp linux-2.6.39.1/kernel/mutex-debug.c linux-2.6.39.1/kernel/mutex-debug.c
68751--- linux-2.6.39.1/kernel/mutex-debug.c 2011-05-19 00:06:34.000000000 -0400
68752+++ linux-2.6.39.1/kernel/mutex-debug.c 2011-05-22 19:36:33.000000000 -0400
68753@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mute
68754 }
68755
68756 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68757- struct thread_info *ti)
68758+ struct task_struct *task)
68759 {
68760 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
68761
68762 /* Mark the current thread as blocked on the lock: */
68763- ti->task->blocked_on = waiter;
68764+ task->blocked_on = waiter;
68765 }
68766
68767 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68768- struct thread_info *ti)
68769+ struct task_struct *task)
68770 {
68771 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
68772- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
68773- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
68774- ti->task->blocked_on = NULL;
68775+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
68776+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
68777+ task->blocked_on = NULL;
68778
68779 list_del_init(&waiter->list);
68780 waiter->task = NULL;
68781@@ -75,7 +75,7 @@ void debug_mutex_unlock(struct mutex *lo
68782 return;
68783
68784 DEBUG_LOCKS_WARN_ON(lock->magic != lock);
68785- DEBUG_LOCKS_WARN_ON(lock->owner != current_thread_info());
68786+ DEBUG_LOCKS_WARN_ON(lock->owner != current);
68787 DEBUG_LOCKS_WARN_ON(!lock->wait_list.prev && !lock->wait_list.next);
68788 mutex_clear_owner(lock);
68789 }
68790diff -urNp linux-2.6.39.1/kernel/mutex-debug.h linux-2.6.39.1/kernel/mutex-debug.h
68791--- linux-2.6.39.1/kernel/mutex-debug.h 2011-05-19 00:06:34.000000000 -0400
68792+++ linux-2.6.39.1/kernel/mutex-debug.h 2011-05-22 19:36:33.000000000 -0400
68793@@ -20,16 +20,16 @@ extern void debug_mutex_wake_waiter(stru
68794 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
68795 extern void debug_mutex_add_waiter(struct mutex *lock,
68796 struct mutex_waiter *waiter,
68797- struct thread_info *ti);
68798+ struct task_struct *task);
68799 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68800- struct thread_info *ti);
68801+ struct task_struct *task);
68802 extern void debug_mutex_unlock(struct mutex *lock);
68803 extern void debug_mutex_init(struct mutex *lock, const char *name,
68804 struct lock_class_key *key);
68805
68806 static inline void mutex_set_owner(struct mutex *lock)
68807 {
68808- lock->owner = current_thread_info();
68809+ lock->owner = current;
68810 }
68811
68812 static inline void mutex_clear_owner(struct mutex *lock)
68813diff -urNp linux-2.6.39.1/kernel/mutex.h linux-2.6.39.1/kernel/mutex.h
68814--- linux-2.6.39.1/kernel/mutex.h 2011-05-19 00:06:34.000000000 -0400
68815+++ linux-2.6.39.1/kernel/mutex.h 2011-05-22 19:36:33.000000000 -0400
68816@@ -19,7 +19,7 @@
68817 #ifdef CONFIG_SMP
68818 static inline void mutex_set_owner(struct mutex *lock)
68819 {
68820- lock->owner = current_thread_info();
68821+ lock->owner = current;
68822 }
68823
68824 static inline void mutex_clear_owner(struct mutex *lock)
68825diff -urNp linux-2.6.39.1/kernel/padata.c linux-2.6.39.1/kernel/padata.c
68826--- linux-2.6.39.1/kernel/padata.c 2011-05-19 00:06:34.000000000 -0400
68827+++ linux-2.6.39.1/kernel/padata.c 2011-05-22 19:36:33.000000000 -0400
68828@@ -132,10 +132,10 @@ int padata_do_parallel(struct padata_ins
68829 padata->pd = pd;
68830 padata->cb_cpu = cb_cpu;
68831
68832- if (unlikely(atomic_read(&pd->seq_nr) == pd->max_seq_nr))
68833- atomic_set(&pd->seq_nr, -1);
68834+ if (unlikely(atomic_read_unchecked(&pd->seq_nr) == pd->max_seq_nr))
68835+ atomic_set_unchecked(&pd->seq_nr, -1);
68836
68837- padata->seq_nr = atomic_inc_return(&pd->seq_nr);
68838+ padata->seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
68839
68840 target_cpu = padata_cpu_hash(padata);
68841 queue = per_cpu_ptr(pd->pqueue, target_cpu);
68842@@ -444,7 +444,7 @@ static struct parallel_data *padata_allo
68843 padata_init_pqueues(pd);
68844 padata_init_squeues(pd);
68845 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
68846- atomic_set(&pd->seq_nr, -1);
68847+ atomic_set_unchecked(&pd->seq_nr, -1);
68848 atomic_set(&pd->reorder_objects, 0);
68849 atomic_set(&pd->refcnt, 0);
68850 pd->pinst = pinst;
68851diff -urNp linux-2.6.39.1/kernel/panic.c linux-2.6.39.1/kernel/panic.c
68852--- linux-2.6.39.1/kernel/panic.c 2011-05-19 00:06:34.000000000 -0400
68853+++ linux-2.6.39.1/kernel/panic.c 2011-05-22 19:41:42.000000000 -0400
68854@@ -369,7 +369,7 @@ static void warn_slowpath_common(const c
68855 const char *board;
68856
68857 printk(KERN_WARNING "------------[ cut here ]------------\n");
68858- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
68859+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
68860 board = dmi_get_system_info(DMI_PRODUCT_NAME);
68861 if (board)
68862 printk(KERN_WARNING "Hardware name: %s\n", board);
68863@@ -424,7 +424,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
68864 */
68865 void __stack_chk_fail(void)
68866 {
68867- panic("stack-protector: Kernel stack is corrupted in: %p\n",
68868+ dump_stack();
68869+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
68870 __builtin_return_address(0));
68871 }
68872 EXPORT_SYMBOL(__stack_chk_fail);
68873diff -urNp linux-2.6.39.1/kernel/params.c linux-2.6.39.1/kernel/params.c
68874--- linux-2.6.39.1/kernel/params.c 2011-05-19 00:06:34.000000000 -0400
68875+++ linux-2.6.39.1/kernel/params.c 2011-05-22 19:36:33.000000000 -0400
68876@@ -234,7 +234,7 @@ int parse_args(const char *name,
68877 { \
68878 return sprintf(buffer, format, *((type *)kp->arg)); \
68879 } \
68880- struct kernel_param_ops param_ops_##name = { \
68881+ const struct kernel_param_ops param_ops_##name = { \
68882 .set = param_set_##name, \
68883 .get = param_get_##name, \
68884 }; \
68885@@ -286,7 +286,7 @@ static void param_free_charp(void *arg)
68886 maybe_kfree_parameter(*((char **)arg));
68887 }
68888
68889-struct kernel_param_ops param_ops_charp = {
68890+const struct kernel_param_ops param_ops_charp = {
68891 .set = param_set_charp,
68892 .get = param_get_charp,
68893 .free = param_free_charp,
68894@@ -334,7 +334,7 @@ int param_get_bool(char *buffer, const s
68895 }
68896 EXPORT_SYMBOL(param_get_bool);
68897
68898-struct kernel_param_ops param_ops_bool = {
68899+const struct kernel_param_ops param_ops_bool = {
68900 .set = param_set_bool,
68901 .get = param_get_bool,
68902 };
68903@@ -362,7 +362,7 @@ int param_get_invbool(char *buffer, cons
68904 }
68905 EXPORT_SYMBOL(param_get_invbool);
68906
68907-struct kernel_param_ops param_ops_invbool = {
68908+const struct kernel_param_ops param_ops_invbool = {
68909 .set = param_set_invbool,
68910 .get = param_get_invbool,
68911 };
68912@@ -460,7 +460,7 @@ static void param_array_free(void *arg)
68913 arr->ops->free(arr->elem + arr->elemsize * i);
68914 }
68915
68916-struct kernel_param_ops param_array_ops = {
68917+const struct kernel_param_ops param_array_ops = {
68918 .set = param_array_set,
68919 .get = param_array_get,
68920 .free = param_array_free,
68921@@ -488,7 +488,7 @@ int param_get_string(char *buffer, const
68922 }
68923 EXPORT_SYMBOL(param_get_string);
68924
68925-struct kernel_param_ops param_ops_string = {
68926+const struct kernel_param_ops param_ops_string = {
68927 .set = param_set_copystring,
68928 .get = param_get_string,
68929 };
68930diff -urNp linux-2.6.39.1/kernel/perf_event.c linux-2.6.39.1/kernel/perf_event.c
68931--- linux-2.6.39.1/kernel/perf_event.c 2011-05-19 00:06:34.000000000 -0400
68932+++ linux-2.6.39.1/kernel/perf_event.c 2011-05-22 19:36:33.000000000 -0400
68933@@ -170,7 +170,7 @@ int perf_proc_update_handler(struct ctl_
68934 return 0;
68935 }
68936
68937-static atomic64_t perf_event_id;
68938+static atomic64_unchecked_t perf_event_id;
68939
68940 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
68941 enum event_type_t event_type);
68942@@ -2496,7 +2496,7 @@ static void __perf_event_read(void *info
68943
68944 static inline u64 perf_event_count(struct perf_event *event)
68945 {
68946- return local64_read(&event->count) + atomic64_read(&event->child_count);
68947+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
68948 }
68949
68950 static u64 perf_event_read(struct perf_event *event)
68951@@ -3031,9 +3031,9 @@ u64 perf_event_read_value(struct perf_ev
68952 mutex_lock(&event->child_mutex);
68953 total += perf_event_read(event);
68954 *enabled += event->total_time_enabled +
68955- atomic64_read(&event->child_total_time_enabled);
68956+ atomic64_read_unchecked(&event->child_total_time_enabled);
68957 *running += event->total_time_running +
68958- atomic64_read(&event->child_total_time_running);
68959+ atomic64_read_unchecked(&event->child_total_time_running);
68960
68961 list_for_each_entry(child, &event->child_list, child_list) {
68962 total += perf_event_read(child);
68963@@ -3396,10 +3396,10 @@ void perf_event_update_userpage(struct p
68964 userpg->offset -= local64_read(&event->hw.prev_count);
68965
68966 userpg->time_enabled = event->total_time_enabled +
68967- atomic64_read(&event->child_total_time_enabled);
68968+ atomic64_read_unchecked(&event->child_total_time_enabled);
68969
68970 userpg->time_running = event->total_time_running +
68971- atomic64_read(&event->child_total_time_running);
68972+ atomic64_read_unchecked(&event->child_total_time_running);
68973
68974 barrier();
68975 ++userpg->lock;
68976@@ -3884,16 +3884,16 @@ static void perf_pending_event(struct ir
68977 * Later on, we might change it to a list if there is
68978 * another virtualization implementation supporting the callbacks.
68979 */
68980-struct perf_guest_info_callbacks *perf_guest_cbs;
68981+const struct perf_guest_info_callbacks *perf_guest_cbs;
68982
68983-int perf_register_guest_info_callbacks(struct perf_guest_info_callbacks *cbs)
68984+int perf_register_guest_info_callbacks(const struct perf_guest_info_callbacks *cbs)
68985 {
68986 perf_guest_cbs = cbs;
68987 return 0;
68988 }
68989 EXPORT_SYMBOL_GPL(perf_register_guest_info_callbacks);
68990
68991-int perf_unregister_guest_info_callbacks(struct perf_guest_info_callbacks *cbs)
68992+int perf_unregister_guest_info_callbacks(const struct perf_guest_info_callbacks *cbs)
68993 {
68994 perf_guest_cbs = NULL;
68995 return 0;
68996@@ -4196,11 +4196,11 @@ static void perf_output_read_one(struct
68997 values[n++] = perf_event_count(event);
68998 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
68999 values[n++] = enabled +
69000- atomic64_read(&event->child_total_time_enabled);
69001+ atomic64_read_unchecked(&event->child_total_time_enabled);
69002 }
69003 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
69004 values[n++] = running +
69005- atomic64_read(&event->child_total_time_running);
69006+ atomic64_read_unchecked(&event->child_total_time_running);
69007 }
69008 if (read_format & PERF_FORMAT_ID)
69009 values[n++] = primary_event_id(event);
69010@@ -6201,7 +6201,7 @@ perf_event_alloc(struct perf_event_attr
69011 event->parent = parent_event;
69012
69013 event->ns = get_pid_ns(current->nsproxy->pid_ns);
69014- event->id = atomic64_inc_return(&perf_event_id);
69015+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
69016
69017 event->state = PERF_EVENT_STATE_INACTIVE;
69018
69019@@ -6724,10 +6724,10 @@ static void sync_child_event(struct perf
69020 /*
69021 * Add back the child's count to the parent's count:
69022 */
69023- atomic64_add(child_val, &parent_event->child_count);
69024- atomic64_add(child_event->total_time_enabled,
69025+ atomic64_add_unchecked(child_val, &parent_event->child_count);
69026+ atomic64_add_unchecked(child_event->total_time_enabled,
69027 &parent_event->child_total_time_enabled);
69028- atomic64_add(child_event->total_time_running,
69029+ atomic64_add_unchecked(child_event->total_time_running,
69030 &parent_event->child_total_time_running);
69031
69032 /*
69033diff -urNp linux-2.6.39.1/kernel/pid.c linux-2.6.39.1/kernel/pid.c
69034--- linux-2.6.39.1/kernel/pid.c 2011-05-19 00:06:34.000000000 -0400
69035+++ linux-2.6.39.1/kernel/pid.c 2011-05-22 19:41:42.000000000 -0400
69036@@ -33,6 +33,7 @@
69037 #include <linux/rculist.h>
69038 #include <linux/bootmem.h>
69039 #include <linux/hash.h>
69040+#include <linux/security.h>
69041 #include <linux/pid_namespace.h>
69042 #include <linux/init_task.h>
69043 #include <linux/syscalls.h>
69044@@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT
69045
69046 int pid_max = PID_MAX_DEFAULT;
69047
69048-#define RESERVED_PIDS 300
69049+#define RESERVED_PIDS 500
69050
69051 int pid_max_min = RESERVED_PIDS + 1;
69052 int pid_max_max = PID_MAX_LIMIT;
69053@@ -419,8 +420,15 @@ EXPORT_SYMBOL(pid_task);
69054 */
69055 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
69056 {
69057+ struct task_struct *task;
69058+
69059 rcu_lockdep_assert(rcu_read_lock_held());
69060- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
69061+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
69062+
69063+ if (gr_pid_is_chrooted(task))
69064+ return NULL;
69065+
69066+ return task;
69067 }
69068
69069 struct task_struct *find_task_by_vpid(pid_t vnr)
69070diff -urNp linux-2.6.39.1/kernel/posix-cpu-timers.c linux-2.6.39.1/kernel/posix-cpu-timers.c
69071--- linux-2.6.39.1/kernel/posix-cpu-timers.c 2011-05-19 00:06:34.000000000 -0400
69072+++ linux-2.6.39.1/kernel/posix-cpu-timers.c 2011-05-22 19:41:42.000000000 -0400
69073@@ -6,6 +6,7 @@
69074 #include <linux/posix-timers.h>
69075 #include <linux/errno.h>
69076 #include <linux/math64.h>
69077+#include <linux/security.h>
69078 #include <asm/uaccess.h>
69079 #include <linux/kernel_stat.h>
69080 #include <trace/events/timer.h>
69081@@ -1590,7 +1591,7 @@ static int thread_cpu_timer_create(struc
69082 return posix_cpu_timer_create(timer);
69083 }
69084
69085-struct k_clock clock_posix_cpu = {
69086+const struct k_clock clock_posix_cpu = {
69087 .clock_getres = posix_cpu_clock_getres,
69088 .clock_set = posix_cpu_clock_set,
69089 .clock_get = posix_cpu_clock_get,
69090@@ -1604,14 +1605,14 @@ struct k_clock clock_posix_cpu = {
69091
69092 static __init int init_posix_cpu_timers(void)
69093 {
69094- struct k_clock process = {
69095+ const struct k_clock process = {
69096 .clock_getres = process_cpu_clock_getres,
69097 .clock_get = process_cpu_clock_get,
69098 .timer_create = process_cpu_timer_create,
69099 .nsleep = process_cpu_nsleep,
69100 .nsleep_restart = process_cpu_nsleep_restart,
69101 };
69102- struct k_clock thread = {
69103+ const struct k_clock thread = {
69104 .clock_getres = thread_cpu_clock_getres,
69105 .clock_get = thread_cpu_clock_get,
69106 .timer_create = thread_cpu_timer_create,
69107diff -urNp linux-2.6.39.1/kernel/posix-timers.c linux-2.6.39.1/kernel/posix-timers.c
69108--- linux-2.6.39.1/kernel/posix-timers.c 2011-05-19 00:06:34.000000000 -0400
69109+++ linux-2.6.39.1/kernel/posix-timers.c 2011-05-22 20:13:41.000000000 -0400
69110@@ -43,6 +43,7 @@
69111 #include <linux/idr.h>
69112 #include <linux/posix-clock.h>
69113 #include <linux/posix-timers.h>
69114+#include <linux/grsecurity.h>
69115 #include <linux/syscalls.h>
69116 #include <linux/wait.h>
69117 #include <linux/workqueue.h>
69118@@ -227,7 +228,7 @@ static int posix_get_boottime(const cloc
69119 */
69120 static __init int init_posix_timers(void)
69121 {
69122- struct k_clock clock_realtime = {
69123+ const struct k_clock clock_realtime = {
69124 .clock_getres = hrtimer_get_res,
69125 .clock_get = posix_clock_realtime_get,
69126 .clock_set = posix_clock_realtime_set,
69127@@ -239,7 +240,7 @@ static __init int init_posix_timers(void
69128 .timer_get = common_timer_get,
69129 .timer_del = common_timer_del,
69130 };
69131- struct k_clock clock_monotonic = {
69132+ const struct k_clock clock_monotonic = {
69133 .clock_getres = hrtimer_get_res,
69134 .clock_get = posix_ktime_get_ts,
69135 .nsleep = common_nsleep,
69136@@ -249,19 +250,19 @@ static __init int init_posix_timers(void
69137 .timer_get = common_timer_get,
69138 .timer_del = common_timer_del,
69139 };
69140- struct k_clock clock_monotonic_raw = {
69141+ const struct k_clock clock_monotonic_raw = {
69142 .clock_getres = hrtimer_get_res,
69143 .clock_get = posix_get_monotonic_raw,
69144 };
69145- struct k_clock clock_realtime_coarse = {
69146+ const struct k_clock clock_realtime_coarse = {
69147 .clock_getres = posix_get_coarse_res,
69148 .clock_get = posix_get_realtime_coarse,
69149 };
69150- struct k_clock clock_monotonic_coarse = {
69151+ const struct k_clock clock_monotonic_coarse = {
69152 .clock_getres = posix_get_coarse_res,
69153 .clock_get = posix_get_monotonic_coarse,
69154 };
69155- struct k_clock clock_boottime = {
69156+ const struct k_clock clock_boottime = {
69157 .clock_getres = hrtimer_get_res,
69158 .clock_get = posix_get_boottime,
69159 .nsleep = common_nsleep,
69160@@ -272,6 +273,8 @@ static __init int init_posix_timers(void
69161 .timer_del = common_timer_del,
69162 };
69163
69164+ pax_track_stack();
69165+
69166 posix_timers_register_clock(CLOCK_REALTIME, &clock_realtime);
69167 posix_timers_register_clock(CLOCK_MONOTONIC, &clock_monotonic);
69168 posix_timers_register_clock(CLOCK_MONOTONIC_RAW, &clock_monotonic_raw);
69169@@ -454,7 +457,7 @@ static struct pid *good_sigevent(sigeven
69170 }
69171
69172 void posix_timers_register_clock(const clockid_t clock_id,
69173- struct k_clock *new_clock)
69174+ const struct k_clock *new_clock)
69175 {
69176 if ((unsigned) clock_id >= MAX_CLOCKS) {
69177 printk(KERN_WARNING "POSIX clock register failed for clock_id %d\n",
69178@@ -506,7 +509,7 @@ static void release_posix_timer(struct k
69179 kmem_cache_free(posix_timers_cache, tmr);
69180 }
69181
69182-static struct k_clock *clockid_to_kclock(const clockid_t id)
69183+static const struct k_clock *clockid_to_kclock(const clockid_t id)
69184 {
69185 if (id < 0)
69186 return (id & CLOCKFD_MASK) == CLOCKFD ?
69187@@ -529,7 +532,7 @@ SYSCALL_DEFINE3(timer_create, const cloc
69188 struct sigevent __user *, timer_event_spec,
69189 timer_t __user *, created_timer_id)
69190 {
69191- struct k_clock *kc = clockid_to_kclock(which_clock);
69192+ const struct k_clock *kc = clockid_to_kclock(which_clock);
69193 struct k_itimer *new_timer;
69194 int error, new_timer_id;
69195 sigevent_t event;
69196@@ -714,7 +717,7 @@ SYSCALL_DEFINE2(timer_gettime, timer_t,
69197 {
69198 struct itimerspec cur_setting;
69199 struct k_itimer *timr;
69200- struct k_clock *kc;
69201+ const struct k_clock *kc;
69202 unsigned long flags;
69203 int ret = 0;
69204
69205@@ -822,7 +825,7 @@ SYSCALL_DEFINE4(timer_settime, timer_t,
69206 int error = 0;
69207 unsigned long flag;
69208 struct itimerspec *rtn = old_setting ? &old_spec : NULL;
69209- struct k_clock *kc;
69210+ const struct k_clock *kc;
69211
69212 if (!new_setting)
69213 return -EINVAL;
69214@@ -868,7 +871,7 @@ static int common_timer_del(struct k_iti
69215
69216 static inline int timer_delete_hook(struct k_itimer *timer)
69217 {
69218- struct k_clock *kc = clockid_to_kclock(timer->it_clock);
69219+ const struct k_clock *kc = clockid_to_kclock(timer->it_clock);
69220
69221 if (WARN_ON_ONCE(!kc || !kc->timer_del))
69222 return -EINVAL;
69223@@ -947,7 +950,7 @@ void exit_itimers(struct signal_struct *
69224 SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
69225 const struct timespec __user *, tp)
69226 {
69227- struct k_clock *kc = clockid_to_kclock(which_clock);
69228+ const struct k_clock *kc = clockid_to_kclock(which_clock);
69229 struct timespec new_tp;
69230
69231 if (!kc || !kc->clock_set)
69232@@ -956,13 +959,20 @@ SYSCALL_DEFINE2(clock_settime, const clo
69233 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
69234 return -EFAULT;
69235
69236+ /* only the CLOCK_REALTIME clock can be set, all other clocks
69237+ have their clock_set fptr set to a nosettime dummy function
69238+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
69239+ call common_clock_set, which calls do_sys_settimeofday, which
69240+ we hook
69241+ */
69242+
69243 return kc->clock_set(which_clock, &new_tp);
69244 }
69245
69246 SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock,
69247 struct timespec __user *,tp)
69248 {
69249- struct k_clock *kc = clockid_to_kclock(which_clock);
69250+ const struct k_clock *kc = clockid_to_kclock(which_clock);
69251 struct timespec kernel_tp;
69252 int error;
69253
69254@@ -980,7 +990,7 @@ SYSCALL_DEFINE2(clock_gettime, const clo
69255 SYSCALL_DEFINE2(clock_adjtime, const clockid_t, which_clock,
69256 struct timex __user *, utx)
69257 {
69258- struct k_clock *kc = clockid_to_kclock(which_clock);
69259+ const struct k_clock *kc = clockid_to_kclock(which_clock);
69260 struct timex ktx;
69261 int err;
69262
69263@@ -1003,7 +1013,7 @@ SYSCALL_DEFINE2(clock_adjtime, const clo
69264 SYSCALL_DEFINE2(clock_getres, const clockid_t, which_clock,
69265 struct timespec __user *, tp)
69266 {
69267- struct k_clock *kc = clockid_to_kclock(which_clock);
69268+ const struct k_clock *kc = clockid_to_kclock(which_clock);
69269 struct timespec rtn_tp;
69270 int error;
69271
69272@@ -1033,7 +1043,7 @@ SYSCALL_DEFINE4(clock_nanosleep, const c
69273 const struct timespec __user *, rqtp,
69274 struct timespec __user *, rmtp)
69275 {
69276- struct k_clock *kc = clockid_to_kclock(which_clock);
69277+ const struct k_clock *kc = clockid_to_kclock(which_clock);
69278 struct timespec t;
69279
69280 if (!kc)
69281@@ -1057,7 +1067,7 @@ SYSCALL_DEFINE4(clock_nanosleep, const c
69282 long clock_nanosleep_restart(struct restart_block *restart_block)
69283 {
69284 clockid_t which_clock = restart_block->nanosleep.index;
69285- struct k_clock *kc = clockid_to_kclock(which_clock);
69286+ const struct k_clock *kc = clockid_to_kclock(which_clock);
69287
69288 if (WARN_ON_ONCE(!kc || !kc->nsleep_restart))
69289 return -EINVAL;
69290diff -urNp linux-2.6.39.1/kernel/power/poweroff.c linux-2.6.39.1/kernel/power/poweroff.c
69291--- linux-2.6.39.1/kernel/power/poweroff.c 2011-05-19 00:06:34.000000000 -0400
69292+++ linux-2.6.39.1/kernel/power/poweroff.c 2011-05-22 19:36:33.000000000 -0400
69293@@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_powerof
69294 .enable_mask = SYSRQ_ENABLE_BOOT,
69295 };
69296
69297-static int pm_sysrq_init(void)
69298+static int __init pm_sysrq_init(void)
69299 {
69300 register_sysrq_key('o', &sysrq_poweroff_op);
69301 return 0;
69302diff -urNp linux-2.6.39.1/kernel/power/process.c linux-2.6.39.1/kernel/power/process.c
69303--- linux-2.6.39.1/kernel/power/process.c 2011-05-19 00:06:34.000000000 -0400
69304+++ linux-2.6.39.1/kernel/power/process.c 2011-05-22 19:36:33.000000000 -0400
69305@@ -41,6 +41,7 @@ static int try_to_freeze_tasks(bool sig_
69306 u64 elapsed_csecs64;
69307 unsigned int elapsed_csecs;
69308 bool wakeup = false;
69309+ bool timedout = false;
69310
69311 do_gettimeofday(&start);
69312
69313@@ -51,6 +52,8 @@ static int try_to_freeze_tasks(bool sig_
69314
69315 while (true) {
69316 todo = 0;
69317+ if (time_after(jiffies, end_time))
69318+ timedout = true;
69319 read_lock(&tasklist_lock);
69320 do_each_thread(g, p) {
69321 if (frozen(p) || !freezable(p))
69322@@ -71,9 +74,13 @@ static int try_to_freeze_tasks(bool sig_
69323 * try_to_stop() after schedule() in ptrace/signal
69324 * stop sees TIF_FREEZE.
69325 */
69326- if (!task_is_stopped_or_traced(p) &&
69327- !freezer_should_skip(p))
69328+ if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
69329 todo++;
69330+ if (timedout) {
69331+ printk(KERN_ERR "Task refusing to freeze:\n");
69332+ sched_show_task(p);
69333+ }
69334+ }
69335 } while_each_thread(g, p);
69336 read_unlock(&tasklist_lock);
69337
69338@@ -82,7 +89,7 @@ static int try_to_freeze_tasks(bool sig_
69339 todo += wq_busy;
69340 }
69341
69342- if (!todo || time_after(jiffies, end_time))
69343+ if (!todo || timedout)
69344 break;
69345
69346 if (pm_wakeup_pending()) {
69347diff -urNp linux-2.6.39.1/kernel/printk.c linux-2.6.39.1/kernel/printk.c
69348--- linux-2.6.39.1/kernel/printk.c 2011-05-19 00:06:34.000000000 -0400
69349+++ linux-2.6.39.1/kernel/printk.c 2011-05-22 19:41:42.000000000 -0400
69350@@ -284,12 +284,17 @@ static int check_syslog_permissions(int
69351 if (from_file && type != SYSLOG_ACTION_OPEN)
69352 return 0;
69353
69354+#ifdef CONFIG_GRKERNSEC_DMESG
69355+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
69356+ return -EPERM;
69357+#endif
69358+
69359 if (syslog_action_restricted(type)) {
69360 if (capable(CAP_SYSLOG))
69361 return 0;
69362 /* For historical reasons, accept CAP_SYS_ADMIN too, with a warning */
69363 if (capable(CAP_SYS_ADMIN)) {
69364- WARN_ONCE(1, "Attempt to access syslog with CAP_SYS_ADMIN "
69365+ printk_once(KERN_WARNING "Attempt to access syslog with CAP_SYS_ADMIN "
69366 "but no CAP_SYSLOG (deprecated).\n");
69367 return 0;
69368 }
69369diff -urNp linux-2.6.39.1/kernel/profile.c linux-2.6.39.1/kernel/profile.c
69370--- linux-2.6.39.1/kernel/profile.c 2011-05-19 00:06:34.000000000 -0400
69371+++ linux-2.6.39.1/kernel/profile.c 2011-05-22 19:36:33.000000000 -0400
69372@@ -39,7 +39,7 @@ struct profile_hit {
69373 /* Oprofile timer tick hook */
69374 static int (*timer_hook)(struct pt_regs *) __read_mostly;
69375
69376-static atomic_t *prof_buffer;
69377+static atomic_unchecked_t *prof_buffer;
69378 static unsigned long prof_len, prof_shift;
69379
69380 int prof_on __read_mostly;
69381@@ -283,7 +283,7 @@ static void profile_flip_buffers(void)
69382 hits[i].pc = 0;
69383 continue;
69384 }
69385- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69386+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69387 hits[i].hits = hits[i].pc = 0;
69388 }
69389 }
69390@@ -346,9 +346,9 @@ void profile_hits(int type, void *__pc,
69391 * Add the current hit(s) and flush the write-queue out
69392 * to the global buffer:
69393 */
69394- atomic_add(nr_hits, &prof_buffer[pc]);
69395+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
69396 for (i = 0; i < NR_PROFILE_HIT; ++i) {
69397- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69398+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69399 hits[i].pc = hits[i].hits = 0;
69400 }
69401 out:
69402@@ -426,7 +426,7 @@ void profile_hits(int type, void *__pc,
69403 if (prof_on != type || !prof_buffer)
69404 return;
69405 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
69406- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69407+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69408 }
69409 #endif /* !CONFIG_SMP */
69410 EXPORT_SYMBOL_GPL(profile_hits);
69411@@ -517,7 +517,7 @@ read_profile(struct file *file, char __u
69412 return -EFAULT;
69413 buf++; p++; count--; read++;
69414 }
69415- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
69416+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
69417 if (copy_to_user(buf, (void *)pnt, count))
69418 return -EFAULT;
69419 read += count;
69420@@ -548,7 +548,7 @@ static ssize_t write_profile(struct file
69421 }
69422 #endif
69423 profile_discard_flip_buffers();
69424- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
69425+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
69426 return count;
69427 }
69428
69429diff -urNp linux-2.6.39.1/kernel/ptrace.c linux-2.6.39.1/kernel/ptrace.c
69430--- linux-2.6.39.1/kernel/ptrace.c 2011-05-19 00:06:34.000000000 -0400
69431+++ linux-2.6.39.1/kernel/ptrace.c 2011-05-23 17:07:00.000000000 -0400
69432@@ -117,7 +117,8 @@ int ptrace_check_attach(struct task_stru
69433 return ret;
69434 }
69435
69436-int __ptrace_may_access(struct task_struct *task, unsigned int mode)
69437+static int __ptrace_may_access(struct task_struct *task, unsigned int mode,
69438+ unsigned int log)
69439 {
69440 const struct cred *cred = current_cred(), *tcred;
69441
69442@@ -143,7 +144,8 @@ int __ptrace_may_access(struct task_stru
69443 cred->gid == tcred->sgid &&
69444 cred->gid == tcred->gid))
69445 goto ok;
69446- if (ns_capable(tcred->user->user_ns, CAP_SYS_PTRACE))
69447+ if ((!log && ns_capable_nolog(tcred->user->user_ns, CAP_SYS_PTRACE)) ||
69448+ (log && ns_capable(tcred->user->user_ns, CAP_SYS_PTRACE)))
69449 goto ok;
69450 rcu_read_unlock();
69451 return -EPERM;
69452@@ -152,7 +154,9 @@ ok:
69453 smp_rmb();
69454 if (task->mm)
69455 dumpable = get_dumpable(task->mm);
69456- if (!dumpable && !task_ns_capable(task, CAP_SYS_PTRACE))
69457+ if (!dumpable &&
69458+ ((!log && !task_ns_capable_nolog(task, CAP_SYS_PTRACE)) ||
69459+ (log && !task_ns_capable(task, CAP_SYS_PTRACE))))
69460 return -EPERM;
69461
69462 return security_ptrace_access_check(task, mode);
69463@@ -162,7 +166,16 @@ bool ptrace_may_access(struct task_struc
69464 {
69465 int err;
69466 task_lock(task);
69467- err = __ptrace_may_access(task, mode);
69468+ err = __ptrace_may_access(task, mode, 0);
69469+ task_unlock(task);
69470+ return !err;
69471+}
69472+
69473+bool ptrace_may_access_log(struct task_struct *task, unsigned int mode)
69474+{
69475+ int err;
69476+ task_lock(task);
69477+ err = __ptrace_may_access(task, mode, 1);
69478 task_unlock(task);
69479 return !err;
69480 }
69481@@ -189,7 +202,7 @@ static int ptrace_attach(struct task_str
69482 goto out;
69483
69484 task_lock(task);
69485- retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH);
69486+ retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH, 1);
69487 task_unlock(task);
69488 if (retval)
69489 goto unlock_creds;
69490@@ -202,7 +215,7 @@ static int ptrace_attach(struct task_str
69491 goto unlock_tasklist;
69492
69493 task->ptrace = PT_PTRACED;
69494- if (task_ns_capable(task, CAP_SYS_PTRACE))
69495+ if (task_ns_capable_nolog(task, CAP_SYS_PTRACE))
69496 task->ptrace |= PT_PTRACE_CAP;
69497
69498 __ptrace_link(task, current);
69499@@ -362,6 +375,8 @@ int ptrace_readdata(struct task_struct *
69500 {
69501 int copied = 0;
69502
69503+ pax_track_stack();
69504+
69505 while (len > 0) {
69506 char buf[128];
69507 int this_len, retval;
69508@@ -373,7 +388,7 @@ int ptrace_readdata(struct task_struct *
69509 break;
69510 return -EIO;
69511 }
69512- if (copy_to_user(dst, buf, retval))
69513+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
69514 return -EFAULT;
69515 copied += retval;
69516 src += retval;
69517@@ -387,6 +402,8 @@ int ptrace_writedata(struct task_struct
69518 {
69519 int copied = 0;
69520
69521+ pax_track_stack();
69522+
69523 while (len > 0) {
69524 char buf[128];
69525 int this_len, retval;
69526@@ -569,9 +586,11 @@ int ptrace_request(struct task_struct *c
69527 {
69528 int ret = -EIO;
69529 siginfo_t siginfo;
69530- void __user *datavp = (void __user *) data;
69531+ void __user *datavp = (__force void __user *) data;
69532 unsigned long __user *datalp = datavp;
69533
69534+ pax_track_stack();
69535+
69536 switch (request) {
69537 case PTRACE_PEEKTEXT:
69538 case PTRACE_PEEKDATA:
69539@@ -717,14 +736,21 @@ SYSCALL_DEFINE4(ptrace, long, request, l
69540 goto out;
69541 }
69542
69543+ if (gr_handle_ptrace(child, request)) {
69544+ ret = -EPERM;
69545+ goto out_put_task_struct;
69546+ }
69547+
69548 if (request == PTRACE_ATTACH) {
69549 ret = ptrace_attach(child);
69550 /*
69551 * Some architectures need to do book-keeping after
69552 * a ptrace attach.
69553 */
69554- if (!ret)
69555+ if (!ret) {
69556 arch_ptrace_attach(child);
69557+ gr_audit_ptrace(child);
69558+ }
69559 goto out_put_task_struct;
69560 }
69561
69562@@ -749,7 +775,7 @@ int generic_ptrace_peekdata(struct task_
69563 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
69564 if (copied != sizeof(tmp))
69565 return -EIO;
69566- return put_user(tmp, (unsigned long __user *)data);
69567+ return put_user(tmp, (__force unsigned long __user *)data);
69568 }
69569
69570 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
69571@@ -772,6 +798,8 @@ int compat_ptrace_request(struct task_st
69572 siginfo_t siginfo;
69573 int ret;
69574
69575+ pax_track_stack();
69576+
69577 switch (request) {
69578 case PTRACE_PEEKTEXT:
69579 case PTRACE_PEEKDATA:
69580@@ -859,14 +887,21 @@ asmlinkage long compat_sys_ptrace(compat
69581 goto out;
69582 }
69583
69584+ if (gr_handle_ptrace(child, request)) {
69585+ ret = -EPERM;
69586+ goto out_put_task_struct;
69587+ }
69588+
69589 if (request == PTRACE_ATTACH) {
69590 ret = ptrace_attach(child);
69591 /*
69592 * Some architectures need to do book-keeping after
69593 * a ptrace attach.
69594 */
69595- if (!ret)
69596+ if (!ret) {
69597 arch_ptrace_attach(child);
69598+ gr_audit_ptrace(child);
69599+ }
69600 goto out_put_task_struct;
69601 }
69602
69603diff -urNp linux-2.6.39.1/kernel/rcutorture.c linux-2.6.39.1/kernel/rcutorture.c
69604--- linux-2.6.39.1/kernel/rcutorture.c 2011-05-19 00:06:34.000000000 -0400
69605+++ linux-2.6.39.1/kernel/rcutorture.c 2011-05-22 19:36:33.000000000 -0400
69606@@ -138,12 +138,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_
69607 { 0 };
69608 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
69609 { 0 };
69610-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69611-static atomic_t n_rcu_torture_alloc;
69612-static atomic_t n_rcu_torture_alloc_fail;
69613-static atomic_t n_rcu_torture_free;
69614-static atomic_t n_rcu_torture_mberror;
69615-static atomic_t n_rcu_torture_error;
69616+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69617+static atomic_unchecked_t n_rcu_torture_alloc;
69618+static atomic_unchecked_t n_rcu_torture_alloc_fail;
69619+static atomic_unchecked_t n_rcu_torture_free;
69620+static atomic_unchecked_t n_rcu_torture_mberror;
69621+static atomic_unchecked_t n_rcu_torture_error;
69622 static long n_rcu_torture_boost_ktrerror;
69623 static long n_rcu_torture_boost_rterror;
69624 static long n_rcu_torture_boost_allocerror;
69625@@ -225,11 +225,11 @@ rcu_torture_alloc(void)
69626
69627 spin_lock_bh(&rcu_torture_lock);
69628 if (list_empty(&rcu_torture_freelist)) {
69629- atomic_inc(&n_rcu_torture_alloc_fail);
69630+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
69631 spin_unlock_bh(&rcu_torture_lock);
69632 return NULL;
69633 }
69634- atomic_inc(&n_rcu_torture_alloc);
69635+ atomic_inc_unchecked(&n_rcu_torture_alloc);
69636 p = rcu_torture_freelist.next;
69637 list_del_init(p);
69638 spin_unlock_bh(&rcu_torture_lock);
69639@@ -242,7 +242,7 @@ rcu_torture_alloc(void)
69640 static void
69641 rcu_torture_free(struct rcu_torture *p)
69642 {
69643- atomic_inc(&n_rcu_torture_free);
69644+ atomic_inc_unchecked(&n_rcu_torture_free);
69645 spin_lock_bh(&rcu_torture_lock);
69646 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
69647 spin_unlock_bh(&rcu_torture_lock);
69648@@ -362,7 +362,7 @@ rcu_torture_cb(struct rcu_head *p)
69649 i = rp->rtort_pipe_count;
69650 if (i > RCU_TORTURE_PIPE_LEN)
69651 i = RCU_TORTURE_PIPE_LEN;
69652- atomic_inc(&rcu_torture_wcount[i]);
69653+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
69654 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
69655 rp->rtort_mbtest = 0;
69656 rcu_torture_free(rp);
69657@@ -409,7 +409,7 @@ static void rcu_sync_torture_deferred_fr
69658 i = rp->rtort_pipe_count;
69659 if (i > RCU_TORTURE_PIPE_LEN)
69660 i = RCU_TORTURE_PIPE_LEN;
69661- atomic_inc(&rcu_torture_wcount[i]);
69662+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
69663 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
69664 rp->rtort_mbtest = 0;
69665 list_del(&rp->rtort_free);
69666@@ -882,7 +882,7 @@ rcu_torture_writer(void *arg)
69667 i = old_rp->rtort_pipe_count;
69668 if (i > RCU_TORTURE_PIPE_LEN)
69669 i = RCU_TORTURE_PIPE_LEN;
69670- atomic_inc(&rcu_torture_wcount[i]);
69671+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
69672 old_rp->rtort_pipe_count++;
69673 cur_ops->deferred_free(old_rp);
69674 }
69675@@ -951,7 +951,7 @@ static void rcu_torture_timer(unsigned l
69676 return;
69677 }
69678 if (p->rtort_mbtest == 0)
69679- atomic_inc(&n_rcu_torture_mberror);
69680+ atomic_inc_unchecked(&n_rcu_torture_mberror);
69681 spin_lock(&rand_lock);
69682 cur_ops->read_delay(&rand);
69683 n_rcu_torture_timers++;
69684@@ -1013,7 +1013,7 @@ rcu_torture_reader(void *arg)
69685 continue;
69686 }
69687 if (p->rtort_mbtest == 0)
69688- atomic_inc(&n_rcu_torture_mberror);
69689+ atomic_inc_unchecked(&n_rcu_torture_mberror);
69690 cur_ops->read_delay(&rand);
69691 preempt_disable();
69692 pipe_count = p->rtort_pipe_count;
69693@@ -1072,10 +1072,10 @@ rcu_torture_printk(char *page)
69694 rcu_torture_current,
69695 rcu_torture_current_version,
69696 list_empty(&rcu_torture_freelist),
69697- atomic_read(&n_rcu_torture_alloc),
69698- atomic_read(&n_rcu_torture_alloc_fail),
69699- atomic_read(&n_rcu_torture_free),
69700- atomic_read(&n_rcu_torture_mberror),
69701+ atomic_read_unchecked(&n_rcu_torture_alloc),
69702+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
69703+ atomic_read_unchecked(&n_rcu_torture_free),
69704+ atomic_read_unchecked(&n_rcu_torture_mberror),
69705 n_rcu_torture_boost_ktrerror,
69706 n_rcu_torture_boost_rterror,
69707 n_rcu_torture_boost_allocerror,
69708@@ -1083,7 +1083,7 @@ rcu_torture_printk(char *page)
69709 n_rcu_torture_boost_failure,
69710 n_rcu_torture_boosts,
69711 n_rcu_torture_timers);
69712- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
69713+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
69714 n_rcu_torture_boost_ktrerror != 0 ||
69715 n_rcu_torture_boost_rterror != 0 ||
69716 n_rcu_torture_boost_allocerror != 0 ||
69717@@ -1093,7 +1093,7 @@ rcu_torture_printk(char *page)
69718 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
69719 if (i > 1) {
69720 cnt += sprintf(&page[cnt], "!!! ");
69721- atomic_inc(&n_rcu_torture_error);
69722+ atomic_inc_unchecked(&n_rcu_torture_error);
69723 WARN_ON_ONCE(1);
69724 }
69725 cnt += sprintf(&page[cnt], "Reader Pipe: ");
69726@@ -1107,7 +1107,7 @@ rcu_torture_printk(char *page)
69727 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
69728 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
69729 cnt += sprintf(&page[cnt], " %d",
69730- atomic_read(&rcu_torture_wcount[i]));
69731+ atomic_read_unchecked(&rcu_torture_wcount[i]));
69732 }
69733 cnt += sprintf(&page[cnt], "\n");
69734 if (cur_ops->stats)
69735@@ -1415,7 +1415,7 @@ rcu_torture_cleanup(void)
69736
69737 if (cur_ops->cleanup)
69738 cur_ops->cleanup();
69739- if (atomic_read(&n_rcu_torture_error))
69740+ if (atomic_read_unchecked(&n_rcu_torture_error))
69741 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
69742 else
69743 rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS");
69744@@ -1479,11 +1479,11 @@ rcu_torture_init(void)
69745
69746 rcu_torture_current = NULL;
69747 rcu_torture_current_version = 0;
69748- atomic_set(&n_rcu_torture_alloc, 0);
69749- atomic_set(&n_rcu_torture_alloc_fail, 0);
69750- atomic_set(&n_rcu_torture_free, 0);
69751- atomic_set(&n_rcu_torture_mberror, 0);
69752- atomic_set(&n_rcu_torture_error, 0);
69753+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
69754+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
69755+ atomic_set_unchecked(&n_rcu_torture_free, 0);
69756+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
69757+ atomic_set_unchecked(&n_rcu_torture_error, 0);
69758 n_rcu_torture_boost_ktrerror = 0;
69759 n_rcu_torture_boost_rterror = 0;
69760 n_rcu_torture_boost_allocerror = 0;
69761@@ -1491,7 +1491,7 @@ rcu_torture_init(void)
69762 n_rcu_torture_boost_failure = 0;
69763 n_rcu_torture_boosts = 0;
69764 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
69765- atomic_set(&rcu_torture_wcount[i], 0);
69766+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
69767 for_each_possible_cpu(cpu) {
69768 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
69769 per_cpu(rcu_torture_count, cpu)[i] = 0;
69770diff -urNp linux-2.6.39.1/kernel/rcutree.c linux-2.6.39.1/kernel/rcutree.c
69771--- linux-2.6.39.1/kernel/rcutree.c 2011-05-19 00:06:34.000000000 -0400
69772+++ linux-2.6.39.1/kernel/rcutree.c 2011-05-22 19:36:33.000000000 -0400
69773@@ -1389,7 +1389,7 @@ __rcu_process_callbacks(struct rcu_state
69774 /*
69775 * Do softirq processing for the current CPU.
69776 */
69777-static void rcu_process_callbacks(struct softirq_action *unused)
69778+static void rcu_process_callbacks(void)
69779 {
69780 /*
69781 * Memory references from any prior RCU read-side critical sections
69782diff -urNp linux-2.6.39.1/kernel/rcutree_plugin.h linux-2.6.39.1/kernel/rcutree_plugin.h
69783--- linux-2.6.39.1/kernel/rcutree_plugin.h 2011-05-19 00:06:34.000000000 -0400
69784+++ linux-2.6.39.1/kernel/rcutree_plugin.h 2011-05-22 19:36:33.000000000 -0400
69785@@ -730,7 +730,7 @@ void synchronize_rcu_expedited(void)
69786
69787 /* Clean up and exit. */
69788 smp_mb(); /* ensure expedited GP seen before counter increment. */
69789- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
69790+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
69791 unlock_mb_ret:
69792 mutex_unlock(&sync_rcu_preempt_exp_mutex);
69793 mb_ret:
69794@@ -1025,8 +1025,8 @@ EXPORT_SYMBOL_GPL(synchronize_sched_expe
69795
69796 #else /* #ifndef CONFIG_SMP */
69797
69798-static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
69799-static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
69800+static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
69801+static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
69802
69803 static int synchronize_sched_expedited_cpu_stop(void *data)
69804 {
69805@@ -1081,7 +1081,7 @@ void synchronize_sched_expedited(void)
69806 int firstsnap, s, snap, trycount = 0;
69807
69808 /* Note that atomic_inc_return() implies full memory barrier. */
69809- firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
69810+ firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
69811 get_online_cpus();
69812
69813 /*
69814@@ -1102,7 +1102,7 @@ void synchronize_sched_expedited(void)
69815 }
69816
69817 /* Check to see if someone else did our work for us. */
69818- s = atomic_read(&sync_sched_expedited_done);
69819+ s = atomic_read_unchecked(&sync_sched_expedited_done);
69820 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
69821 smp_mb(); /* ensure test happens before caller kfree */
69822 return;
69823@@ -1117,7 +1117,7 @@ void synchronize_sched_expedited(void)
69824 * grace period works for us.
69825 */
69826 get_online_cpus();
69827- snap = atomic_read(&sync_sched_expedited_started) - 1;
69828+ snap = atomic_read_unchecked(&sync_sched_expedited_started) - 1;
69829 smp_mb(); /* ensure read is before try_stop_cpus(). */
69830 }
69831
69832@@ -1128,12 +1128,12 @@ void synchronize_sched_expedited(void)
69833 * than we did beat us to the punch.
69834 */
69835 do {
69836- s = atomic_read(&sync_sched_expedited_done);
69837+ s = atomic_read_unchecked(&sync_sched_expedited_done);
69838 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
69839 smp_mb(); /* ensure test happens before caller kfree */
69840 break;
69841 }
69842- } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
69843+ } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
69844
69845 put_online_cpus();
69846 }
69847diff -urNp linux-2.6.39.1/kernel/relay.c linux-2.6.39.1/kernel/relay.c
69848--- linux-2.6.39.1/kernel/relay.c 2011-05-19 00:06:34.000000000 -0400
69849+++ linux-2.6.39.1/kernel/relay.c 2011-05-22 19:36:33.000000000 -0400
69850@@ -1236,6 +1236,8 @@ static ssize_t subbuf_splice_actor(struc
69851 };
69852 ssize_t ret;
69853
69854+ pax_track_stack();
69855+
69856 if (rbuf->subbufs_produced == rbuf->subbufs_consumed)
69857 return 0;
69858 if (splice_grow_spd(pipe, &spd))
69859diff -urNp linux-2.6.39.1/kernel/resource.c linux-2.6.39.1/kernel/resource.c
69860--- linux-2.6.39.1/kernel/resource.c 2011-05-19 00:06:34.000000000 -0400
69861+++ linux-2.6.39.1/kernel/resource.c 2011-05-22 19:41:42.000000000 -0400
69862@@ -133,8 +133,18 @@ static const struct file_operations proc
69863
69864 static int __init ioresources_init(void)
69865 {
69866+#ifdef CONFIG_GRKERNSEC_PROC_ADD
69867+#ifdef CONFIG_GRKERNSEC_PROC_USER
69868+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
69869+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
69870+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69871+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
69872+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
69873+#endif
69874+#else
69875 proc_create("ioports", 0, NULL, &proc_ioports_operations);
69876 proc_create("iomem", 0, NULL, &proc_iomem_operations);
69877+#endif
69878 return 0;
69879 }
69880 __initcall(ioresources_init);
69881diff -urNp linux-2.6.39.1/kernel/rtmutex-tester.c linux-2.6.39.1/kernel/rtmutex-tester.c
69882--- linux-2.6.39.1/kernel/rtmutex-tester.c 2011-05-19 00:06:34.000000000 -0400
69883+++ linux-2.6.39.1/kernel/rtmutex-tester.c 2011-05-22 19:36:33.000000000 -0400
69884@@ -20,7 +20,7 @@
69885 #define MAX_RT_TEST_MUTEXES 8
69886
69887 static spinlock_t rttest_lock;
69888-static atomic_t rttest_event;
69889+static atomic_unchecked_t rttest_event;
69890
69891 struct test_thread_data {
69892 int opcode;
69893@@ -61,7 +61,7 @@ static int handle_op(struct test_thread_
69894
69895 case RTTEST_LOCKCONT:
69896 td->mutexes[td->opdata] = 1;
69897- td->event = atomic_add_return(1, &rttest_event);
69898+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69899 return 0;
69900
69901 case RTTEST_RESET:
69902@@ -74,7 +74,7 @@ static int handle_op(struct test_thread_
69903 return 0;
69904
69905 case RTTEST_RESETEVENT:
69906- atomic_set(&rttest_event, 0);
69907+ atomic_set_unchecked(&rttest_event, 0);
69908 return 0;
69909
69910 default:
69911@@ -91,9 +91,9 @@ static int handle_op(struct test_thread_
69912 return ret;
69913
69914 td->mutexes[id] = 1;
69915- td->event = atomic_add_return(1, &rttest_event);
69916+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69917 rt_mutex_lock(&mutexes[id]);
69918- td->event = atomic_add_return(1, &rttest_event);
69919+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69920 td->mutexes[id] = 4;
69921 return 0;
69922
69923@@ -104,9 +104,9 @@ static int handle_op(struct test_thread_
69924 return ret;
69925
69926 td->mutexes[id] = 1;
69927- td->event = atomic_add_return(1, &rttest_event);
69928+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69929 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
69930- td->event = atomic_add_return(1, &rttest_event);
69931+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69932 td->mutexes[id] = ret ? 0 : 4;
69933 return ret ? -EINTR : 0;
69934
69935@@ -115,9 +115,9 @@ static int handle_op(struct test_thread_
69936 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
69937 return ret;
69938
69939- td->event = atomic_add_return(1, &rttest_event);
69940+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69941 rt_mutex_unlock(&mutexes[id]);
69942- td->event = atomic_add_return(1, &rttest_event);
69943+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69944 td->mutexes[id] = 0;
69945 return 0;
69946
69947@@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mu
69948 break;
69949
69950 td->mutexes[dat] = 2;
69951- td->event = atomic_add_return(1, &rttest_event);
69952+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69953 break;
69954
69955 default:
69956@@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mu
69957 return;
69958
69959 td->mutexes[dat] = 3;
69960- td->event = atomic_add_return(1, &rttest_event);
69961+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69962 break;
69963
69964 case RTTEST_LOCKNOWAIT:
69965@@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mu
69966 return;
69967
69968 td->mutexes[dat] = 1;
69969- td->event = atomic_add_return(1, &rttest_event);
69970+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69971 return;
69972
69973 default:
69974diff -urNp linux-2.6.39.1/kernel/sched_autogroup.c linux-2.6.39.1/kernel/sched_autogroup.c
69975--- linux-2.6.39.1/kernel/sched_autogroup.c 2011-05-19 00:06:34.000000000 -0400
69976+++ linux-2.6.39.1/kernel/sched_autogroup.c 2011-05-22 19:36:33.000000000 -0400
69977@@ -7,7 +7,7 @@
69978
69979 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
69980 static struct autogroup autogroup_default;
69981-static atomic_t autogroup_seq_nr;
69982+static atomic_unchecked_t autogroup_seq_nr;
69983
69984 static void __init autogroup_init(struct task_struct *init_task)
69985 {
69986@@ -78,7 +78,7 @@ static inline struct autogroup *autogrou
69987
69988 kref_init(&ag->kref);
69989 init_rwsem(&ag->lock);
69990- ag->id = atomic_inc_return(&autogroup_seq_nr);
69991+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
69992 ag->tg = tg;
69993 #ifdef CONFIG_RT_GROUP_SCHED
69994 /*
69995diff -urNp linux-2.6.39.1/kernel/sched.c linux-2.6.39.1/kernel/sched.c
69996--- linux-2.6.39.1/kernel/sched.c 2011-05-19 00:06:34.000000000 -0400
69997+++ linux-2.6.39.1/kernel/sched.c 2011-05-23 17:07:00.000000000 -0400
69998@@ -4078,6 +4078,8 @@ asmlinkage void __sched schedule(void)
69999 struct rq *rq;
70000 int cpu;
70001
70002+ pax_track_stack();
70003+
70004 need_resched:
70005 preempt_disable();
70006 cpu = smp_processor_id();
70007@@ -4165,7 +4167,7 @@ EXPORT_SYMBOL(schedule);
70008 * Look out! "owner" is an entirely speculative pointer
70009 * access and not reliable.
70010 */
70011-int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner)
70012+int mutex_spin_on_owner(struct mutex *lock, struct task_struct *owner)
70013 {
70014 unsigned int cpu;
70015 struct rq *rq;
70016@@ -4179,10 +4181,10 @@ int mutex_spin_on_owner(struct mutex *lo
70017 * DEBUG_PAGEALLOC could have unmapped it if
70018 * the mutex owner just released it and exited.
70019 */
70020- if (probe_kernel_address(&owner->cpu, cpu))
70021+ if (probe_kernel_address(&task_thread_info(owner)->cpu, cpu))
70022 return 0;
70023 #else
70024- cpu = owner->cpu;
70025+ cpu = task_thread_info(owner)->cpu;
70026 #endif
70027
70028 /*
70029@@ -4219,7 +4221,7 @@ int mutex_spin_on_owner(struct mutex *lo
70030 /*
70031 * Is that owner really running on that cpu?
70032 */
70033- if (task_thread_info(rq->curr) != owner || need_resched())
70034+ if (rq->curr != owner || need_resched())
70035 return 0;
70036
70037 arch_mutex_cpu_relax();
70038@@ -4778,6 +4780,8 @@ int can_nice(const struct task_struct *p
70039 /* convert nice value [19,-20] to rlimit style value [1,40] */
70040 int nice_rlim = 20 - nice;
70041
70042+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
70043+
70044 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
70045 capable(CAP_SYS_NICE));
70046 }
70047@@ -4811,7 +4815,8 @@ SYSCALL_DEFINE1(nice, int, increment)
70048 if (nice > 19)
70049 nice = 19;
70050
70051- if (increment < 0 && !can_nice(current, nice))
70052+ if (increment < 0 && (!can_nice(current, nice) ||
70053+ gr_handle_chroot_nice()))
70054 return -EPERM;
70055
70056 retval = security_task_setnice(current, nice);
70057@@ -4957,6 +4962,7 @@ recheck:
70058 unsigned long rlim_rtprio =
70059 task_rlimit(p, RLIMIT_RTPRIO);
70060
70061+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
70062 /* can't set/change the rt policy */
70063 if (policy != p->policy && !rlim_rtprio)
70064 return -EPERM;
70065@@ -7164,7 +7170,7 @@ static void init_sched_groups_power(int
70066 long power;
70067 int weight;
70068
70069- WARN_ON(!sd || !sd->groups);
70070+ BUG_ON(!sd || !sd->groups);
70071
70072 if (cpu != group_first_cpu(sd->groups))
70073 return;
70074diff -urNp linux-2.6.39.1/kernel/sched_fair.c linux-2.6.39.1/kernel/sched_fair.c
70075--- linux-2.6.39.1/kernel/sched_fair.c 2011-05-19 00:06:34.000000000 -0400
70076+++ linux-2.6.39.1/kernel/sched_fair.c 2011-05-22 19:36:33.000000000 -0400
70077@@ -3999,7 +3999,7 @@ static void nohz_idle_balance(int this_c
70078 * run_rebalance_domains is triggered when needed from the scheduler tick.
70079 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
70080 */
70081-static void run_rebalance_domains(struct softirq_action *h)
70082+static void run_rebalance_domains(void)
70083 {
70084 int this_cpu = smp_processor_id();
70085 struct rq *this_rq = cpu_rq(this_cpu);
70086diff -urNp linux-2.6.39.1/kernel/signal.c linux-2.6.39.1/kernel/signal.c
70087--- linux-2.6.39.1/kernel/signal.c 2011-05-19 00:06:34.000000000 -0400
70088+++ linux-2.6.39.1/kernel/signal.c 2011-05-23 17:07:00.000000000 -0400
70089@@ -45,12 +45,12 @@ static struct kmem_cache *sigqueue_cache
70090
70091 int print_fatal_signals __read_mostly;
70092
70093-static void __user *sig_handler(struct task_struct *t, int sig)
70094+static __sighandler_t sig_handler(struct task_struct *t, int sig)
70095 {
70096 return t->sighand->action[sig - 1].sa.sa_handler;
70097 }
70098
70099-static int sig_handler_ignored(void __user *handler, int sig)
70100+static int sig_handler_ignored(__sighandler_t handler, int sig)
70101 {
70102 /* Is it explicitly or implicitly ignored? */
70103 return handler == SIG_IGN ||
70104@@ -60,7 +60,7 @@ static int sig_handler_ignored(void __us
70105 static int sig_task_ignored(struct task_struct *t, int sig,
70106 int from_ancestor_ns)
70107 {
70108- void __user *handler;
70109+ __sighandler_t handler;
70110
70111 handler = sig_handler(t, sig);
70112
70113@@ -243,6 +243,9 @@ __sigqueue_alloc(int sig, struct task_st
70114 atomic_inc(&user->sigpending);
70115 rcu_read_unlock();
70116
70117+ if (!override_rlimit)
70118+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
70119+
70120 if (override_rlimit ||
70121 atomic_read(&user->sigpending) <=
70122 task_rlimit(t, RLIMIT_SIGPENDING)) {
70123@@ -367,7 +370,7 @@ flush_signal_handlers(struct task_struct
70124
70125 int unhandled_signal(struct task_struct *tsk, int sig)
70126 {
70127- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
70128+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
70129 if (is_global_init(tsk))
70130 return 1;
70131 if (handler != SIG_IGN && handler != SIG_DFL)
70132@@ -693,6 +696,9 @@ static int check_kill_permission(int sig
70133 }
70134 }
70135
70136+ if (gr_handle_signal(t, sig))
70137+ return -EPERM;
70138+
70139 return security_task_kill(t, info, sig, 0);
70140 }
70141
70142@@ -1041,7 +1047,7 @@ __group_send_sig_info(int sig, struct si
70143 return send_signal(sig, info, p, 1);
70144 }
70145
70146-static int
70147+int
70148 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70149 {
70150 return send_signal(sig, info, t, 0);
70151@@ -1078,6 +1084,7 @@ force_sig_info(int sig, struct siginfo *
70152 unsigned long int flags;
70153 int ret, blocked, ignored;
70154 struct k_sigaction *action;
70155+ int is_unhandled = 0;
70156
70157 spin_lock_irqsave(&t->sighand->siglock, flags);
70158 action = &t->sighand->action[sig-1];
70159@@ -1092,9 +1099,18 @@ force_sig_info(int sig, struct siginfo *
70160 }
70161 if (action->sa.sa_handler == SIG_DFL)
70162 t->signal->flags &= ~SIGNAL_UNKILLABLE;
70163+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
70164+ is_unhandled = 1;
70165 ret = specific_send_sig_info(sig, info, t);
70166 spin_unlock_irqrestore(&t->sighand->siglock, flags);
70167
70168+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
70169+ normal operation */
70170+ if (is_unhandled) {
70171+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
70172+ gr_handle_crash(t, sig);
70173+ }
70174+
70175 return ret;
70176 }
70177
70178@@ -1153,8 +1169,11 @@ int group_send_sig_info(int sig, struct
70179 ret = check_kill_permission(sig, info, p);
70180 rcu_read_unlock();
70181
70182- if (!ret && sig)
70183+ if (!ret && sig) {
70184 ret = do_send_sig_info(sig, info, p, true);
70185+ if (!ret)
70186+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
70187+ }
70188
70189 return ret;
70190 }
70191@@ -1718,6 +1737,8 @@ void ptrace_notify(int exit_code)
70192 {
70193 siginfo_t info;
70194
70195+ pax_track_stack();
70196+
70197 BUG_ON((exit_code & (0x7f | ~0xffff)) != SIGTRAP);
70198
70199 memset(&info, 0, sizeof info);
70200diff -urNp linux-2.6.39.1/kernel/smp.c linux-2.6.39.1/kernel/smp.c
70201--- linux-2.6.39.1/kernel/smp.c 2011-05-19 00:06:34.000000000 -0400
70202+++ linux-2.6.39.1/kernel/smp.c 2011-05-22 19:36:33.000000000 -0400
70203@@ -583,22 +583,22 @@ int smp_call_function(smp_call_func_t fu
70204 }
70205 EXPORT_SYMBOL(smp_call_function);
70206
70207-void ipi_call_lock(void)
70208+void ipi_call_lock(void) __acquires(call_function.lock)
70209 {
70210 raw_spin_lock(&call_function.lock);
70211 }
70212
70213-void ipi_call_unlock(void)
70214+void ipi_call_unlock(void) __releases(call_function.lock)
70215 {
70216 raw_spin_unlock(&call_function.lock);
70217 }
70218
70219-void ipi_call_lock_irq(void)
70220+void ipi_call_lock_irq(void) __acquires(call_function.lock)
70221 {
70222 raw_spin_lock_irq(&call_function.lock);
70223 }
70224
70225-void ipi_call_unlock_irq(void)
70226+void ipi_call_unlock_irq(void) __releases(call_function.lock)
70227 {
70228 raw_spin_unlock_irq(&call_function.lock);
70229 }
70230diff -urNp linux-2.6.39.1/kernel/softirq.c linux-2.6.39.1/kernel/softirq.c
70231--- linux-2.6.39.1/kernel/softirq.c 2011-05-19 00:06:34.000000000 -0400
70232+++ linux-2.6.39.1/kernel/softirq.c 2011-05-22 19:36:33.000000000 -0400
70233@@ -56,7 +56,7 @@ static struct softirq_action softirq_vec
70234
70235 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
70236
70237-char *softirq_to_name[NR_SOFTIRQS] = {
70238+const char * const softirq_to_name[NR_SOFTIRQS] = {
70239 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
70240 "TASKLET", "SCHED", "HRTIMER", "RCU"
70241 };
70242@@ -206,7 +206,7 @@ EXPORT_SYMBOL(local_bh_enable_ip);
70243
70244 asmlinkage void __do_softirq(void)
70245 {
70246- struct softirq_action *h;
70247+ const struct softirq_action *h;
70248 __u32 pending;
70249 int max_restart = MAX_SOFTIRQ_RESTART;
70250 int cpu;
70251@@ -235,7 +235,7 @@ restart:
70252 kstat_incr_softirqs_this_cpu(vec_nr);
70253
70254 trace_softirq_entry(vec_nr);
70255- h->action(h);
70256+ h->action();
70257 trace_softirq_exit(vec_nr);
70258 if (unlikely(prev_count != preempt_count())) {
70259 printk(KERN_ERR "huh, entered softirq %u %s %p"
70260@@ -377,7 +377,7 @@ void raise_softirq(unsigned int nr)
70261 local_irq_restore(flags);
70262 }
70263
70264-void open_softirq(int nr, void (*action)(struct softirq_action *))
70265+void open_softirq(int nr, void (*action)(void))
70266 {
70267 softirq_vec[nr].action = action;
70268 }
70269@@ -433,7 +433,7 @@ void __tasklet_hi_schedule_first(struct
70270
70271 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
70272
70273-static void tasklet_action(struct softirq_action *a)
70274+static void tasklet_action(void)
70275 {
70276 struct tasklet_struct *list;
70277
70278@@ -468,7 +468,7 @@ static void tasklet_action(struct softir
70279 }
70280 }
70281
70282-static void tasklet_hi_action(struct softirq_action *a)
70283+static void tasklet_hi_action(void)
70284 {
70285 struct tasklet_struct *list;
70286
70287diff -urNp linux-2.6.39.1/kernel/sys.c linux-2.6.39.1/kernel/sys.c
70288--- linux-2.6.39.1/kernel/sys.c 2011-05-19 00:06:34.000000000 -0400
70289+++ linux-2.6.39.1/kernel/sys.c 2011-05-22 21:08:10.000000000 -0400
70290@@ -154,6 +154,12 @@ static int set_one_prio(struct task_stru
70291 error = -EACCES;
70292 goto out;
70293 }
70294+
70295+ if (gr_handle_chroot_setpriority(p, niceval)) {
70296+ error = -EACCES;
70297+ goto out;
70298+ }
70299+
70300 no_nice = security_task_setnice(p, niceval);
70301 if (no_nice) {
70302 error = no_nice;
70303@@ -538,6 +544,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, g
70304 goto error;
70305 }
70306
70307+ if (gr_check_group_change(new->gid, new->egid, -1))
70308+ goto error;
70309+
70310 if (rgid != (gid_t) -1 ||
70311 (egid != (gid_t) -1 && egid != old->gid))
70312 new->sgid = new->egid;
70313@@ -567,6 +576,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
70314 old = current_cred();
70315
70316 retval = -EPERM;
70317+
70318+ if (gr_check_group_change(gid, gid, gid))
70319+ goto error;
70320+
70321 if (nsown_capable(CAP_SETGID))
70322 new->gid = new->egid = new->sgid = new->fsgid = gid;
70323 else if (gid == old->gid || gid == old->sgid)
70324@@ -647,6 +660,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, u
70325 goto error;
70326 }
70327
70328+ if (gr_check_user_change(new->uid, new->euid, -1))
70329+ goto error;
70330+
70331 if (new->uid != old->uid) {
70332 retval = set_user(new);
70333 if (retval < 0)
70334@@ -691,6 +707,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
70335 old = current_cred();
70336
70337 retval = -EPERM;
70338+
70339+ if (gr_check_crash_uid(uid))
70340+ goto error;
70341+ if (gr_check_user_change(uid, uid, uid))
70342+ goto error;
70343+
70344 if (nsown_capable(CAP_SETUID)) {
70345 new->suid = new->uid = uid;
70346 if (uid != old->uid) {
70347@@ -745,6 +767,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid,
70348 goto error;
70349 }
70350
70351+ if (gr_check_user_change(ruid, euid, -1))
70352+ goto error;
70353+
70354 if (ruid != (uid_t) -1) {
70355 new->uid = ruid;
70356 if (ruid != old->uid) {
70357@@ -809,6 +834,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid,
70358 goto error;
70359 }
70360
70361+ if (gr_check_group_change(rgid, egid, -1))
70362+ goto error;
70363+
70364 if (rgid != (gid_t) -1)
70365 new->gid = rgid;
70366 if (egid != (gid_t) -1)
70367@@ -855,6 +883,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70368 old = current_cred();
70369 old_fsuid = old->fsuid;
70370
70371+ if (gr_check_user_change(-1, -1, uid))
70372+ goto error;
70373+
70374 if (uid == old->uid || uid == old->euid ||
70375 uid == old->suid || uid == old->fsuid ||
70376 nsown_capable(CAP_SETUID)) {
70377@@ -865,6 +896,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70378 }
70379 }
70380
70381+error:
70382 abort_creds(new);
70383 return old_fsuid;
70384
70385@@ -891,12 +923,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
70386 if (gid == old->gid || gid == old->egid ||
70387 gid == old->sgid || gid == old->fsgid ||
70388 nsown_capable(CAP_SETGID)) {
70389+ if (gr_check_group_change(-1, -1, gid))
70390+ goto error;
70391+
70392 if (gid != old_fsgid) {
70393 new->fsgid = gid;
70394 goto change_okay;
70395 }
70396 }
70397
70398+error:
70399 abort_creds(new);
70400 return old_fsgid;
70401
70402@@ -1643,7 +1679,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsi
70403 error = get_dumpable(me->mm);
70404 break;
70405 case PR_SET_DUMPABLE:
70406- if (arg2 < 0 || arg2 > 1) {
70407+ if (arg2 > 1) {
70408 error = -EINVAL;
70409 break;
70410 }
70411diff -urNp linux-2.6.39.1/kernel/sysctl.c linux-2.6.39.1/kernel/sysctl.c
70412--- linux-2.6.39.1/kernel/sysctl.c 2011-05-19 00:06:34.000000000 -0400
70413+++ linux-2.6.39.1/kernel/sysctl.c 2011-05-22 20:23:10.000000000 -0400
70414@@ -84,6 +84,13 @@
70415
70416
70417 #if defined(CONFIG_SYSCTL)
70418+#include <linux/grsecurity.h>
70419+#include <linux/grinternal.h>
70420+
70421+extern __u32 gr_handle_sysctl(const ctl_table *table, const int op);
70422+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
70423+ const int op);
70424+extern int gr_handle_chroot_sysctl(const int op);
70425
70426 /* External variables not in a header file. */
70427 extern int sysctl_overcommit_memory;
70428@@ -196,6 +203,7 @@ static int sysrq_sysctl_handler(ctl_tabl
70429 }
70430
70431 #endif
70432+extern struct ctl_table grsecurity_table[];
70433
70434 static struct ctl_table root_table[];
70435 static struct ctl_table_root sysctl_table_root;
70436@@ -225,6 +233,20 @@ extern struct ctl_table epoll_table[];
70437 int sysctl_legacy_va_layout;
70438 #endif
70439
70440+#ifdef CONFIG_PAX_SOFTMODE
70441+static ctl_table pax_table[] = {
70442+ {
70443+ .procname = "softmode",
70444+ .data = &pax_softmode,
70445+ .maxlen = sizeof(unsigned int),
70446+ .mode = 0600,
70447+ .proc_handler = &proc_dointvec,
70448+ },
70449+
70450+ { }
70451+};
70452+#endif
70453+
70454 /* The default sysctl tables: */
70455
70456 static struct ctl_table root_table[] = {
70457@@ -271,6 +293,22 @@ static int max_extfrag_threshold = 1000;
70458 #endif
70459
70460 static struct ctl_table kern_table[] = {
70461+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
70462+ {
70463+ .procname = "grsecurity",
70464+ .mode = 0500,
70465+ .child = grsecurity_table,
70466+ },
70467+#endif
70468+
70469+#ifdef CONFIG_PAX_SOFTMODE
70470+ {
70471+ .procname = "pax",
70472+ .mode = 0500,
70473+ .child = pax_table,
70474+ },
70475+#endif
70476+
70477 {
70478 .procname = "sched_child_runs_first",
70479 .data = &sysctl_sched_child_runs_first,
70480@@ -545,7 +583,7 @@ static struct ctl_table kern_table[] = {
70481 .data = &modprobe_path,
70482 .maxlen = KMOD_PATH_LEN,
70483 .mode = 0644,
70484- .proc_handler = proc_dostring,
70485+ .proc_handler = proc_dostring_modpriv,
70486 },
70487 {
70488 .procname = "modules_disabled",
70489@@ -707,16 +745,20 @@ static struct ctl_table kern_table[] = {
70490 .extra1 = &zero,
70491 .extra2 = &one,
70492 },
70493+#endif
70494 {
70495 .procname = "kptr_restrict",
70496 .data = &kptr_restrict,
70497 .maxlen = sizeof(int),
70498 .mode = 0644,
70499 .proc_handler = proc_dmesg_restrict,
70500+#ifdef CONFIG_GRKERNSEC_HIDESYM
70501+ .extra1 = &two,
70502+#else
70503 .extra1 = &zero,
70504+#endif
70505 .extra2 = &two,
70506 },
70507-#endif
70508 {
70509 .procname = "ngroups_max",
70510 .data = &ngroups_max,
70511@@ -1189,6 +1231,13 @@ static struct ctl_table vm_table[] = {
70512 .proc_handler = proc_dointvec_minmax,
70513 .extra1 = &zero,
70514 },
70515+ {
70516+ .procname = "heap_stack_gap",
70517+ .data = &sysctl_heap_stack_gap,
70518+ .maxlen = sizeof(sysctl_heap_stack_gap),
70519+ .mode = 0644,
70520+ .proc_handler = proc_doulongvec_minmax,
70521+ },
70522 #else
70523 {
70524 .procname = "nr_trim_pages",
70525@@ -1698,6 +1747,17 @@ static int test_perm(int mode, int op)
70526 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
70527 {
70528 int mode;
70529+ int error;
70530+
70531+ if (table->parent != NULL && table->parent->procname != NULL &&
70532+ table->procname != NULL &&
70533+ gr_handle_sysctl_mod(table->parent->procname, table->procname, op))
70534+ return -EACCES;
70535+ if (gr_handle_chroot_sysctl(op))
70536+ return -EACCES;
70537+ error = gr_handle_sysctl(table, op);
70538+ if (error)
70539+ return error;
70540
70541 if (root->permissions)
70542 mode = root->permissions(root, current->nsproxy, table);
70543@@ -2102,6 +2162,16 @@ int proc_dostring(struct ctl_table *tabl
70544 buffer, lenp, ppos);
70545 }
70546
70547+int proc_dostring_modpriv(struct ctl_table *table, int write,
70548+ void __user *buffer, size_t *lenp, loff_t *ppos)
70549+{
70550+ if (write && !capable(CAP_SYS_MODULE))
70551+ return -EPERM;
70552+
70553+ return _proc_do_string(table->data, table->maxlen, write,
70554+ buffer, lenp, ppos);
70555+}
70556+
70557 static size_t proc_skip_spaces(char **buf)
70558 {
70559 size_t ret;
70560@@ -2207,6 +2277,8 @@ static int proc_put_long(void __user **b
70561 len = strlen(tmp);
70562 if (len > *size)
70563 len = *size;
70564+ if (len > sizeof(tmp))
70565+ len = sizeof(tmp);
70566 if (copy_to_user(*buf, tmp, len))
70567 return -EFAULT;
70568 *size -= len;
70569@@ -2523,8 +2595,11 @@ static int __do_proc_doulongvec_minmax(v
70570 *i = val;
70571 } else {
70572 val = convdiv * (*i) / convmul;
70573- if (!first)
70574+ if (!first) {
70575 err = proc_put_char(&buffer, &left, '\t');
70576+ if (err)
70577+ break;
70578+ }
70579 err = proc_put_long(&buffer, &left, val, false);
70580 if (err)
70581 break;
70582@@ -2919,6 +2994,12 @@ int proc_dostring(struct ctl_table *tabl
70583 return -ENOSYS;
70584 }
70585
70586+int proc_dostring_modpriv(struct ctl_table *table, int write,
70587+ void __user *buffer, size_t *lenp, loff_t *ppos)
70588+{
70589+ return -ENOSYS;
70590+}
70591+
70592 int proc_dointvec(struct ctl_table *table, int write,
70593 void __user *buffer, size_t *lenp, loff_t *ppos)
70594 {
70595@@ -2975,6 +3056,7 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
70596 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
70597 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
70598 EXPORT_SYMBOL(proc_dostring);
70599+EXPORT_SYMBOL(proc_dostring_modpriv);
70600 EXPORT_SYMBOL(proc_doulongvec_minmax);
70601 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
70602 EXPORT_SYMBOL(register_sysctl_table);
70603diff -urNp linux-2.6.39.1/kernel/sysctl_check.c linux-2.6.39.1/kernel/sysctl_check.c
70604--- linux-2.6.39.1/kernel/sysctl_check.c 2011-05-19 00:06:34.000000000 -0400
70605+++ linux-2.6.39.1/kernel/sysctl_check.c 2011-05-22 19:41:42.000000000 -0400
70606@@ -129,6 +129,7 @@ int sysctl_check_table(struct nsproxy *n
70607 set_fail(&fail, table, "Directory with extra2");
70608 } else {
70609 if ((table->proc_handler == proc_dostring) ||
70610+ (table->proc_handler == proc_dostring_modpriv) ||
70611 (table->proc_handler == proc_dointvec) ||
70612 (table->proc_handler == proc_dointvec_minmax) ||
70613 (table->proc_handler == proc_dointvec_jiffies) ||
70614diff -urNp linux-2.6.39.1/kernel/taskstats.c linux-2.6.39.1/kernel/taskstats.c
70615--- linux-2.6.39.1/kernel/taskstats.c 2011-05-19 00:06:34.000000000 -0400
70616+++ linux-2.6.39.1/kernel/taskstats.c 2011-05-22 19:41:42.000000000 -0400
70617@@ -27,9 +27,12 @@
70618 #include <linux/cgroup.h>
70619 #include <linux/fs.h>
70620 #include <linux/file.h>
70621+#include <linux/grsecurity.h>
70622 #include <net/genetlink.h>
70623 #include <asm/atomic.h>
70624
70625+extern int gr_is_taskstats_denied(int pid);
70626+
70627 /*
70628 * Maximum length of a cpumask that can be specified in
70629 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
70630@@ -549,6 +552,9 @@ err:
70631
70632 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
70633 {
70634+ if (gr_is_taskstats_denied(current->pid))
70635+ return -EACCES;
70636+
70637 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
70638 return cmd_attr_register_cpumask(info);
70639 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
70640diff -urNp linux-2.6.39.1/kernel/time/posix-clock.c linux-2.6.39.1/kernel/time/posix-clock.c
70641--- linux-2.6.39.1/kernel/time/posix-clock.c 2011-05-19 00:06:34.000000000 -0400
70642+++ linux-2.6.39.1/kernel/time/posix-clock.c 2011-05-22 19:36:33.000000000 -0400
70643@@ -433,7 +433,7 @@ static int pc_timer_settime(struct k_iti
70644 return err;
70645 }
70646
70647-struct k_clock clock_posix_dynamic = {
70648+const struct k_clock clock_posix_dynamic = {
70649 .clock_getres = pc_clock_getres,
70650 .clock_set = pc_clock_settime,
70651 .clock_get = pc_clock_gettime,
70652diff -urNp linux-2.6.39.1/kernel/time/tick-broadcast.c linux-2.6.39.1/kernel/time/tick-broadcast.c
70653--- linux-2.6.39.1/kernel/time/tick-broadcast.c 2011-05-19 00:06:34.000000000 -0400
70654+++ linux-2.6.39.1/kernel/time/tick-broadcast.c 2011-05-22 19:36:33.000000000 -0400
70655@@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct cl
70656 * then clear the broadcast bit.
70657 */
70658 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
70659- int cpu = smp_processor_id();
70660+ cpu = smp_processor_id();
70661
70662 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
70663 tick_broadcast_clear_oneshot(cpu);
70664diff -urNp linux-2.6.39.1/kernel/time/timekeeping.c linux-2.6.39.1/kernel/time/timekeeping.c
70665--- linux-2.6.39.1/kernel/time/timekeeping.c 2011-05-19 00:06:34.000000000 -0400
70666+++ linux-2.6.39.1/kernel/time/timekeeping.c 2011-05-22 20:40:50.000000000 -0400
70667@@ -14,6 +14,7 @@
70668 #include <linux/init.h>
70669 #include <linux/mm.h>
70670 #include <linux/sched.h>
70671+#include <linux/grsecurity.h>
70672 #include <linux/syscore_ops.h>
70673 #include <linux/clocksource.h>
70674 #include <linux/jiffies.h>
70675@@ -361,6 +362,8 @@ int do_settimeofday(const struct timespe
70676 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
70677 return -EINVAL;
70678
70679+ gr_log_timechange();
70680+
70681 write_seqlock_irqsave(&xtime_lock, flags);
70682
70683 timekeeping_forward_now();
70684diff -urNp linux-2.6.39.1/kernel/time/timer_list.c linux-2.6.39.1/kernel/time/timer_list.c
70685--- linux-2.6.39.1/kernel/time/timer_list.c 2011-05-19 00:06:34.000000000 -0400
70686+++ linux-2.6.39.1/kernel/time/timer_list.c 2011-05-22 19:41:42.000000000 -0400
70687@@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base,
70688
70689 static void print_name_offset(struct seq_file *m, void *sym)
70690 {
70691+#ifdef CONFIG_GRKERNSEC_HIDESYM
70692+ SEQ_printf(m, "<%p>", NULL);
70693+#else
70694 char symname[KSYM_NAME_LEN];
70695
70696 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
70697 SEQ_printf(m, "<%pK>", sym);
70698 else
70699 SEQ_printf(m, "%s", symname);
70700+#endif
70701 }
70702
70703 static void
70704@@ -112,7 +116,11 @@ next_one:
70705 static void
70706 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
70707 {
70708+#ifdef CONFIG_GRKERNSEC_HIDESYM
70709+ SEQ_printf(m, " .base: %p\n", NULL);
70710+#else
70711 SEQ_printf(m, " .base: %pK\n", base);
70712+#endif
70713 SEQ_printf(m, " .index: %d\n",
70714 base->index);
70715 SEQ_printf(m, " .resolution: %Lu nsecs\n",
70716@@ -293,7 +301,11 @@ static int __init init_timer_list_procfs
70717 {
70718 struct proc_dir_entry *pe;
70719
70720+#ifdef CONFIG_GRKERNSEC_PROC_ADD
70721+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
70722+#else
70723 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
70724+#endif
70725 if (!pe)
70726 return -ENOMEM;
70727 return 0;
70728diff -urNp linux-2.6.39.1/kernel/time/timer_stats.c linux-2.6.39.1/kernel/time/timer_stats.c
70729--- linux-2.6.39.1/kernel/time/timer_stats.c 2011-05-19 00:06:34.000000000 -0400
70730+++ linux-2.6.39.1/kernel/time/timer_stats.c 2011-05-22 19:41:42.000000000 -0400
70731@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
70732 static unsigned long nr_entries;
70733 static struct entry entries[MAX_ENTRIES];
70734
70735-static atomic_t overflow_count;
70736+static atomic_unchecked_t overflow_count;
70737
70738 /*
70739 * The entries are in a hash-table, for fast lookup:
70740@@ -140,7 +140,7 @@ static void reset_entries(void)
70741 nr_entries = 0;
70742 memset(entries, 0, sizeof(entries));
70743 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
70744- atomic_set(&overflow_count, 0);
70745+ atomic_set_unchecked(&overflow_count, 0);
70746 }
70747
70748 static struct entry *alloc_entry(void)
70749@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *time
70750 if (likely(entry))
70751 entry->count++;
70752 else
70753- atomic_inc(&overflow_count);
70754+ atomic_inc_unchecked(&overflow_count);
70755
70756 out_unlock:
70757 raw_spin_unlock_irqrestore(lock, flags);
70758@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *time
70759
70760 static void print_name_offset(struct seq_file *m, unsigned long addr)
70761 {
70762+#ifdef CONFIG_GRKERNSEC_HIDESYM
70763+ seq_printf(m, "<%p>", NULL);
70764+#else
70765 char symname[KSYM_NAME_LEN];
70766
70767 if (lookup_symbol_name(addr, symname) < 0)
70768 seq_printf(m, "<%p>", (void *)addr);
70769 else
70770 seq_printf(m, "%s", symname);
70771+#endif
70772 }
70773
70774 static int tstats_show(struct seq_file *m, void *v)
70775@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *
70776
70777 seq_puts(m, "Timer Stats Version: v0.2\n");
70778 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
70779- if (atomic_read(&overflow_count))
70780+ if (atomic_read_unchecked(&overflow_count))
70781 seq_printf(m, "Overflow: %d entries\n",
70782- atomic_read(&overflow_count));
70783+ atomic_read_unchecked(&overflow_count));
70784
70785 for (i = 0; i < nr_entries; i++) {
70786 entry = entries + i;
70787@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(voi
70788 {
70789 struct proc_dir_entry *pe;
70790
70791+#ifdef CONFIG_GRKERNSEC_PROC_ADD
70792+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
70793+#else
70794 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
70795+#endif
70796 if (!pe)
70797 return -ENOMEM;
70798 return 0;
70799diff -urNp linux-2.6.39.1/kernel/time.c linux-2.6.39.1/kernel/time.c
70800--- linux-2.6.39.1/kernel/time.c 2011-05-19 00:06:34.000000000 -0400
70801+++ linux-2.6.39.1/kernel/time.c 2011-05-22 19:41:42.000000000 -0400
70802@@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct tim
70803 return error;
70804
70805 if (tz) {
70806+ /* we log in do_settimeofday called below, so don't log twice
70807+ */
70808+ if (!tv)
70809+ gr_log_timechange();
70810+
70811 /* SMP safe, global irq locking makes it work. */
70812 sys_tz = *tz;
70813 update_vsyscall_tz();
70814diff -urNp linux-2.6.39.1/kernel/timer.c linux-2.6.39.1/kernel/timer.c
70815--- linux-2.6.39.1/kernel/timer.c 2011-05-19 00:06:34.000000000 -0400
70816+++ linux-2.6.39.1/kernel/timer.c 2011-05-22 19:36:33.000000000 -0400
70817@@ -1305,7 +1305,7 @@ void update_process_times(int user_tick)
70818 /*
70819 * This function runs timers and the timer-tq in bottom half context.
70820 */
70821-static void run_timer_softirq(struct softirq_action *h)
70822+static void run_timer_softirq(void)
70823 {
70824 struct tvec_base *base = __this_cpu_read(tvec_bases);
70825
70826diff -urNp linux-2.6.39.1/kernel/trace/blktrace.c linux-2.6.39.1/kernel/trace/blktrace.c
70827--- linux-2.6.39.1/kernel/trace/blktrace.c 2011-05-19 00:06:34.000000000 -0400
70828+++ linux-2.6.39.1/kernel/trace/blktrace.c 2011-05-22 19:36:33.000000000 -0400
70829@@ -321,7 +321,7 @@ static ssize_t blk_dropped_read(struct f
70830 struct blk_trace *bt = filp->private_data;
70831 char buf[16];
70832
70833- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
70834+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
70835
70836 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
70837 }
70838@@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(str
70839 return 1;
70840
70841 bt = buf->chan->private_data;
70842- atomic_inc(&bt->dropped);
70843+ atomic_inc_unchecked(&bt->dropped);
70844 return 0;
70845 }
70846
70847@@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_qu
70848
70849 bt->dir = dir;
70850 bt->dev = dev;
70851- atomic_set(&bt->dropped, 0);
70852+ atomic_set_unchecked(&bt->dropped, 0);
70853
70854 ret = -EIO;
70855 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
70856diff -urNp linux-2.6.39.1/kernel/trace/ftrace.c linux-2.6.39.1/kernel/trace/ftrace.c
70857--- linux-2.6.39.1/kernel/trace/ftrace.c 2011-06-03 00:04:14.000000000 -0400
70858+++ linux-2.6.39.1/kernel/trace/ftrace.c 2011-06-03 00:32:08.000000000 -0400
70859@@ -1107,13 +1107,18 @@ ftrace_code_disable(struct module *mod,
70860
70861 ip = rec->ip;
70862
70863+ ret = ftrace_arch_code_modify_prepare();
70864+ FTRACE_WARN_ON(ret);
70865+ if (ret)
70866+ return 0;
70867+
70868 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
70869+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
70870 if (ret) {
70871 ftrace_bug(ret, ip);
70872 rec->flags |= FTRACE_FL_FAILED;
70873- return 0;
70874 }
70875- return 1;
70876+ return ret ? 0 : 1;
70877 }
70878
70879 /*
70880@@ -2011,7 +2016,7 @@ static void ftrace_free_entry_rcu(struct
70881
70882 int
70883 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
70884- void *data)
70885+ void *data)
70886 {
70887 struct ftrace_func_probe *entry;
70888 struct ftrace_page *pg;
70889@@ -2083,7 +2088,7 @@ enum {
70890 };
70891
70892 static void
70893-__unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
70894+__unregister_ftrace_function_probe(char *glob, const struct ftrace_probe_ops *ops,
70895 void *data, int flags)
70896 {
70897 struct ftrace_func_probe *entry;
70898@@ -2144,7 +2149,7 @@ unregister_ftrace_function_probe(char *g
70899 }
70900
70901 void
70902-unregister_ftrace_function_probe_func(char *glob, struct ftrace_probe_ops *ops)
70903+unregister_ftrace_function_probe_func(char *glob, const struct ftrace_probe_ops *ops)
70904 {
70905 __unregister_ftrace_function_probe(glob, ops, NULL, PROBE_TEST_FUNC);
70906 }
70907diff -urNp linux-2.6.39.1/kernel/trace/trace.c linux-2.6.39.1/kernel/trace/trace.c
70908--- linux-2.6.39.1/kernel/trace/trace.c 2011-05-19 00:06:34.000000000 -0400
70909+++ linux-2.6.39.1/kernel/trace/trace.c 2011-05-22 19:36:33.000000000 -0400
70910@@ -3330,6 +3330,8 @@ static ssize_t tracing_splice_read_pipe(
70911 size_t rem;
70912 unsigned int i;
70913
70914+ pax_track_stack();
70915+
70916 if (splice_grow_spd(pipe, &spd))
70917 return -ENOMEM;
70918
70919@@ -3813,6 +3815,8 @@ tracing_buffers_splice_read(struct file
70920 int entries, size, i;
70921 size_t ret;
70922
70923+ pax_track_stack();
70924+
70925 if (splice_grow_spd(pipe, &spd))
70926 return -ENOMEM;
70927
70928@@ -3981,10 +3985,9 @@ static const struct file_operations trac
70929 };
70930 #endif
70931
70932-static struct dentry *d_tracer;
70933-
70934 struct dentry *tracing_init_dentry(void)
70935 {
70936+ static struct dentry *d_tracer;
70937 static int once;
70938
70939 if (d_tracer)
70940@@ -4004,10 +4007,9 @@ struct dentry *tracing_init_dentry(void)
70941 return d_tracer;
70942 }
70943
70944-static struct dentry *d_percpu;
70945-
70946 struct dentry *tracing_dentry_percpu(void)
70947 {
70948+ static struct dentry *d_percpu;
70949 static int once;
70950 struct dentry *d_tracer;
70951
70952diff -urNp linux-2.6.39.1/kernel/trace/trace_events.c linux-2.6.39.1/kernel/trace/trace_events.c
70953--- linux-2.6.39.1/kernel/trace/trace_events.c 2011-05-19 00:06:34.000000000 -0400
70954+++ linux-2.6.39.1/kernel/trace/trace_events.c 2011-05-22 19:36:33.000000000 -0400
70955@@ -1241,10 +1241,10 @@ static LIST_HEAD(ftrace_module_file_list
70956 struct ftrace_module_file_ops {
70957 struct list_head list;
70958 struct module *mod;
70959- struct file_operations id;
70960- struct file_operations enable;
70961- struct file_operations format;
70962- struct file_operations filter;
70963+ struct file_operations id; /* cannot be const, see trace_create_file_ops() */
70964+ struct file_operations enable; /* cannot be const, see trace_create_file_ops() */
70965+ struct file_operations format; /* cannot be const, see trace_create_file_ops() */
70966+ struct file_operations filter; /* cannot be const, see trace_create_file_ops() */
70967 };
70968
70969 static struct ftrace_module_file_ops *
70970diff -urNp linux-2.6.39.1/kernel/trace/trace_functions.c linux-2.6.39.1/kernel/trace/trace_functions.c
70971--- linux-2.6.39.1/kernel/trace/trace_functions.c 2011-05-19 00:06:34.000000000 -0400
70972+++ linux-2.6.39.1/kernel/trace/trace_functions.c 2011-05-22 19:36:33.000000000 -0400
70973@@ -308,7 +308,7 @@ ftrace_trace_onoff_print(struct seq_file
70974 static int
70975 ftrace_trace_onoff_unreg(char *glob, char *cmd, char *param)
70976 {
70977- struct ftrace_probe_ops *ops;
70978+ const struct ftrace_probe_ops *ops;
70979
70980 /* we register both traceon and traceoff to this callback */
70981 if (strcmp(cmd, "traceon") == 0)
70982diff -urNp linux-2.6.39.1/kernel/trace/trace_mmiotrace.c linux-2.6.39.1/kernel/trace/trace_mmiotrace.c
70983--- linux-2.6.39.1/kernel/trace/trace_mmiotrace.c 2011-05-19 00:06:34.000000000 -0400
70984+++ linux-2.6.39.1/kernel/trace/trace_mmiotrace.c 2011-05-22 19:36:33.000000000 -0400
70985@@ -24,7 +24,7 @@ struct header_iter {
70986 static struct trace_array *mmio_trace_array;
70987 static bool overrun_detected;
70988 static unsigned long prev_overruns;
70989-static atomic_t dropped_count;
70990+static atomic_unchecked_t dropped_count;
70991
70992 static void mmio_reset_data(struct trace_array *tr)
70993 {
70994@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iter
70995
70996 static unsigned long count_overruns(struct trace_iterator *iter)
70997 {
70998- unsigned long cnt = atomic_xchg(&dropped_count, 0);
70999+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
71000 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
71001
71002 if (over > prev_overruns)
71003@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct
71004 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
71005 sizeof(*entry), 0, pc);
71006 if (!event) {
71007- atomic_inc(&dropped_count);
71008+ atomic_inc_unchecked(&dropped_count);
71009 return;
71010 }
71011 entry = ring_buffer_event_data(event);
71012@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct
71013 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
71014 sizeof(*entry), 0, pc);
71015 if (!event) {
71016- atomic_inc(&dropped_count);
71017+ atomic_inc_unchecked(&dropped_count);
71018 return;
71019 }
71020 entry = ring_buffer_event_data(event);
71021diff -urNp linux-2.6.39.1/kernel/trace/trace_output.c linux-2.6.39.1/kernel/trace/trace_output.c
71022--- linux-2.6.39.1/kernel/trace/trace_output.c 2011-05-19 00:06:34.000000000 -0400
71023+++ linux-2.6.39.1/kernel/trace/trace_output.c 2011-05-22 19:36:33.000000000 -0400
71024@@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s,
71025
71026 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
71027 if (!IS_ERR(p)) {
71028- p = mangle_path(s->buffer + s->len, p, "\n");
71029+ p = mangle_path(s->buffer + s->len, p, "\n\\");
71030 if (p) {
71031 s->len = p - s->buffer;
71032 return 1;
71033diff -urNp linux-2.6.39.1/kernel/trace/trace_stack.c linux-2.6.39.1/kernel/trace/trace_stack.c
71034--- linux-2.6.39.1/kernel/trace/trace_stack.c 2011-05-19 00:06:34.000000000 -0400
71035+++ linux-2.6.39.1/kernel/trace/trace_stack.c 2011-05-22 19:36:33.000000000 -0400
71036@@ -50,7 +50,7 @@ static inline void check_stack(void)
71037 return;
71038
71039 /* we do not handle interrupt stacks yet */
71040- if (!object_is_on_stack(&this_size))
71041+ if (!object_starts_on_stack(&this_size))
71042 return;
71043
71044 local_irq_save(flags);
71045diff -urNp linux-2.6.39.1/kernel/trace/trace_workqueue.c linux-2.6.39.1/kernel/trace/trace_workqueue.c
71046--- linux-2.6.39.1/kernel/trace/trace_workqueue.c 2011-05-19 00:06:34.000000000 -0400
71047+++ linux-2.6.39.1/kernel/trace/trace_workqueue.c 2011-05-22 19:36:33.000000000 -0400
71048@@ -22,7 +22,7 @@ struct cpu_workqueue_stats {
71049 int cpu;
71050 pid_t pid;
71051 /* Can be inserted from interrupt or user context, need to be atomic */
71052- atomic_t inserted;
71053+ atomic_unchecked_t inserted;
71054 /*
71055 * Don't need to be atomic, works are serialized in a single workqueue thread
71056 * on a single CPU.
71057@@ -60,7 +60,7 @@ probe_workqueue_insertion(void *ignore,
71058 spin_lock_irqsave(&workqueue_cpu_stat(cpu)->lock, flags);
71059 list_for_each_entry(node, &workqueue_cpu_stat(cpu)->list, list) {
71060 if (node->pid == wq_thread->pid) {
71061- atomic_inc(&node->inserted);
71062+ atomic_inc_unchecked(&node->inserted);
71063 goto found;
71064 }
71065 }
71066@@ -210,7 +210,7 @@ static int workqueue_stat_show(struct se
71067 tsk = get_pid_task(pid, PIDTYPE_PID);
71068 if (tsk) {
71069 seq_printf(s, "%3d %6d %6u %s\n", cws->cpu,
71070- atomic_read(&cws->inserted), cws->executed,
71071+ atomic_read_unchecked(&cws->inserted), cws->executed,
71072 tsk->comm);
71073 put_task_struct(tsk);
71074 }
71075diff -urNp linux-2.6.39.1/lib/bug.c linux-2.6.39.1/lib/bug.c
71076--- linux-2.6.39.1/lib/bug.c 2011-05-19 00:06:34.000000000 -0400
71077+++ linux-2.6.39.1/lib/bug.c 2011-05-22 19:36:33.000000000 -0400
71078@@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned l
71079 return BUG_TRAP_TYPE_NONE;
71080
71081 bug = find_bug(bugaddr);
71082+ if (!bug)
71083+ return BUG_TRAP_TYPE_NONE;
71084
71085 file = NULL;
71086 line = 0;
71087diff -urNp linux-2.6.39.1/lib/debugobjects.c linux-2.6.39.1/lib/debugobjects.c
71088--- linux-2.6.39.1/lib/debugobjects.c 2011-05-19 00:06:34.000000000 -0400
71089+++ linux-2.6.39.1/lib/debugobjects.c 2011-05-22 19:36:33.000000000 -0400
71090@@ -284,7 +284,7 @@ static void debug_object_is_on_stack(voi
71091 if (limit > 4)
71092 return;
71093
71094- is_on_stack = object_is_on_stack(addr);
71095+ is_on_stack = object_starts_on_stack(addr);
71096 if (is_on_stack == onstack)
71097 return;
71098
71099diff -urNp linux-2.6.39.1/lib/dma-debug.c linux-2.6.39.1/lib/dma-debug.c
71100--- linux-2.6.39.1/lib/dma-debug.c 2011-05-19 00:06:34.000000000 -0400
71101+++ linux-2.6.39.1/lib/dma-debug.c 2011-05-22 19:36:33.000000000 -0400
71102@@ -862,7 +862,7 @@ out:
71103
71104 static void check_for_stack(struct device *dev, void *addr)
71105 {
71106- if (object_is_on_stack(addr))
71107+ if (object_starts_on_stack(addr))
71108 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
71109 "stack [addr=%p]\n", addr);
71110 }
71111diff -urNp linux-2.6.39.1/lib/inflate.c linux-2.6.39.1/lib/inflate.c
71112--- linux-2.6.39.1/lib/inflate.c 2011-05-19 00:06:34.000000000 -0400
71113+++ linux-2.6.39.1/lib/inflate.c 2011-05-22 19:36:33.000000000 -0400
71114@@ -269,7 +269,7 @@ static void free(void *where)
71115 malloc_ptr = free_mem_ptr;
71116 }
71117 #else
71118-#define malloc(a) kmalloc(a, GFP_KERNEL)
71119+#define malloc(a) kmalloc((a), GFP_KERNEL)
71120 #define free(a) kfree(a)
71121 #endif
71122
71123diff -urNp linux-2.6.39.1/lib/Kconfig.debug linux-2.6.39.1/lib/Kconfig.debug
71124--- linux-2.6.39.1/lib/Kconfig.debug 2011-05-19 00:06:34.000000000 -0400
71125+++ linux-2.6.39.1/lib/Kconfig.debug 2011-05-22 19:41:42.000000000 -0400
71126@@ -1078,6 +1078,7 @@ config LATENCYTOP
71127 depends on DEBUG_KERNEL
71128 depends on STACKTRACE_SUPPORT
71129 depends on PROC_FS
71130+ depends on !GRKERNSEC_HIDESYM
71131 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE
71132 select KALLSYMS
71133 select KALLSYMS_ALL
71134diff -urNp linux-2.6.39.1/lib/kref.c linux-2.6.39.1/lib/kref.c
71135--- linux-2.6.39.1/lib/kref.c 2011-05-19 00:06:34.000000000 -0400
71136+++ linux-2.6.39.1/lib/kref.c 2011-05-22 19:36:33.000000000 -0400
71137@@ -52,7 +52,7 @@ void kref_get(struct kref *kref)
71138 */
71139 int kref_put(struct kref *kref, void (*release)(struct kref *kref))
71140 {
71141- WARN_ON(release == NULL);
71142+ BUG_ON(release == NULL);
71143 WARN_ON(release == (void (*)(struct kref *))kfree);
71144
71145 if (atomic_dec_and_test(&kref->refcount)) {
71146diff -urNp linux-2.6.39.1/lib/radix-tree.c linux-2.6.39.1/lib/radix-tree.c
71147--- linux-2.6.39.1/lib/radix-tree.c 2011-05-19 00:06:34.000000000 -0400
71148+++ linux-2.6.39.1/lib/radix-tree.c 2011-05-22 19:36:33.000000000 -0400
71149@@ -80,7 +80,7 @@ struct radix_tree_preload {
71150 int nr;
71151 struct radix_tree_node *nodes[RADIX_TREE_MAX_PATH];
71152 };
71153-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
71154+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
71155
71156 static inline void *ptr_to_indirect(void *ptr)
71157 {
71158diff -urNp linux-2.6.39.1/lib/vsprintf.c linux-2.6.39.1/lib/vsprintf.c
71159--- linux-2.6.39.1/lib/vsprintf.c 2011-05-19 00:06:34.000000000 -0400
71160+++ linux-2.6.39.1/lib/vsprintf.c 2011-05-22 20:54:59.000000000 -0400
71161@@ -16,6 +16,9 @@
71162 * - scnprintf and vscnprintf
71163 */
71164
71165+#ifdef CONFIG_GRKERNSEC_HIDESYM
71166+#define __INCLUDED_BY_HIDESYM 1
71167+#endif
71168 #include <stdarg.h>
71169 #include <linux/module.h>
71170 #include <linux/types.h>
71171@@ -435,7 +438,7 @@ char *symbol_string(char *buf, char *end
71172 char sym[KSYM_SYMBOL_LEN];
71173 if (ext == 'B')
71174 sprint_backtrace(sym, value);
71175- else if (ext != 'f' && ext != 's')
71176+ else if (ext != 'f' && ext != 's' && ext != 'a')
71177 sprint_symbol(sym, value);
71178 else
71179 kallsyms_lookup(value, NULL, NULL, NULL, sym);
71180@@ -797,7 +800,11 @@ char *uuid_string(char *buf, char *end,
71181 return string(buf, end, uuid, spec);
71182 }
71183
71184+#ifdef CONFIG_GRKERNSEC_HIDESYM
71185+int kptr_restrict __read_mostly = 2;
71186+#else
71187 int kptr_restrict __read_mostly;
71188+#endif
71189
71190 /*
71191 * Show a '%p' thing. A kernel extension is that the '%p' is followed
71192@@ -811,6 +818,8 @@ int kptr_restrict __read_mostly;
71193 * - 'S' For symbolic direct pointers with offset
71194 * - 's' For symbolic direct pointers without offset
71195 * - 'B' For backtraced symbolic direct pointers with offset
71196+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
71197+ * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
71198 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
71199 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
71200 * - 'M' For a 6-byte MAC address, it prints the address in the
71201@@ -855,12 +864,12 @@ char *pointer(const char *fmt, char *buf
71202 {
71203 if (!ptr && *fmt != 'K') {
71204 /*
71205- * Print (null) with the same width as a pointer so it makes
71206+ * Print (nil) with the same width as a pointer so it makes
71207 * tabular output look nice.
71208 */
71209 if (spec.field_width == -1)
71210 spec.field_width = 2 * sizeof(void *);
71211- return string(buf, end, "(null)", spec);
71212+ return string(buf, end, "(nil)", spec);
71213 }
71214
71215 switch (*fmt) {
71216@@ -870,6 +879,13 @@ char *pointer(const char *fmt, char *buf
71217 /* Fallthrough */
71218 case 'S':
71219 case 's':
71220+#ifdef CONFIG_GRKERNSEC_HIDESYM
71221+ break;
71222+#else
71223+ return symbol_string(buf, end, ptr, spec, *fmt);
71224+#endif
71225+ case 'A':
71226+ case 'a':
71227 case 'B':
71228 return symbol_string(buf, end, ptr, spec, *fmt);
71229 case 'R':
71230@@ -1632,11 +1648,11 @@ int bstr_printf(char *buf, size_t size,
71231 typeof(type) value; \
71232 if (sizeof(type) == 8) { \
71233 args = PTR_ALIGN(args, sizeof(u32)); \
71234- *(u32 *)&value = *(u32 *)args; \
71235- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
71236+ *(u32 *)&value = *(const u32 *)args; \
71237+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
71238 } else { \
71239 args = PTR_ALIGN(args, sizeof(type)); \
71240- value = *(typeof(type) *)args; \
71241+ value = *(const typeof(type) *)args; \
71242 } \
71243 args += sizeof(type); \
71244 value; \
71245@@ -1699,7 +1715,7 @@ int bstr_printf(char *buf, size_t size,
71246 case FORMAT_TYPE_STR: {
71247 const char *str_arg = args;
71248 args += strlen(str_arg) + 1;
71249- str = string(str, end, (char *)str_arg, spec);
71250+ str = string(str, end, str_arg, spec);
71251 break;
71252 }
71253
71254diff -urNp linux-2.6.39.1/localversion-grsec linux-2.6.39.1/localversion-grsec
71255--- linux-2.6.39.1/localversion-grsec 1969-12-31 19:00:00.000000000 -0500
71256+++ linux-2.6.39.1/localversion-grsec 2011-05-22 19:41:42.000000000 -0400
71257@@ -0,0 +1 @@
71258+-grsec
71259diff -urNp linux-2.6.39.1/Makefile linux-2.6.39.1/Makefile
71260--- linux-2.6.39.1/Makefile 2011-06-03 00:04:13.000000000 -0400
71261+++ linux-2.6.39.1/Makefile 2011-06-04 17:40:47.000000000 -0400
71262@@ -237,8 +237,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH"
71263
71264 HOSTCC = gcc
71265 HOSTCXX = g++
71266-HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
71267-HOSTCXXFLAGS = -O2
71268+HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
71269+HOSTCFLAGS += $(call cc-option, -Wno-empty-body)
71270+HOSTCXXFLAGS = -O2 -fno-delete-null-pointer-checks
71271
71272 # Decide whether to build built-in, modular, or both.
71273 # Normally, just do built-in.
71274@@ -356,10 +357,12 @@ LINUXINCLUDE := -I$(srctree)/arch/$(h
71275 KBUILD_CPPFLAGS := -D__KERNEL__
71276
71277 KBUILD_CFLAGS := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
71278+ -W -Wno-unused-parameter -Wno-missing-field-initializers \
71279 -fno-strict-aliasing -fno-common \
71280 -Werror-implicit-function-declaration \
71281 -Wno-format-security \
71282 -fno-delete-null-pointer-checks
71283+KBUILD_CFLAGS += $(call cc-option, -Wno-empty-body)
71284 KBUILD_AFLAGS_KERNEL :=
71285 KBUILD_CFLAGS_KERNEL :=
71286 KBUILD_AFLAGS := -D__ASSEMBLY__
71287@@ -685,7 +688,7 @@ export mod_strip_cmd
71288
71289
71290 ifeq ($(KBUILD_EXTMOD),)
71291-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
71292+core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
71293
71294 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
71295 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
71296@@ -931,7 +934,19 @@ include/config/kernel.release: include/c
71297 # version.h and scripts_basic is processed / created.
71298
71299 # Listed in dependency order
71300-PHONY += prepare archprepare prepare0 prepare1 prepare2 prepare3
71301+PHONY += prepare archprepare prepare0 prepare1 prepare2 prepare3 pax-plugin
71302+
71303+ifeq ($(CONFIG_PAX_MEMORY_STACKLEAK),y)
71304+KBUILD_CFLAGS += $(call cc-ifversion, -ge, 0405, -fplugin=$(objtree)/tools/gcc/pax_plugin.so -fplugin-arg-pax_plugin-track-lowest-sp=100)
71305+endif
71306+pax-plugin:
71307+ifneq (,$(findstring pax_plugin, $(KBUILD_CFLAGS)))
71308+ $(Q)$(MAKE) $(build)=tools/gcc
71309+else
71310+ifeq ($(CONFIG_PAX_MEMORY_STACKLEAK),y)
71311+ $(Q)echo "warning, your gcc does not support plugins, PAX_MEMORY_STACKLEAK will be less secure"
71312+endif
71313+endif
71314
71315 # prepare3 is used to check if we are building in a separate output directory,
71316 # and if so do:
71317@@ -947,7 +962,7 @@ ifneq ($(KBUILD_SRC),)
71318 endif
71319
71320 # prepare2 creates a makefile if using a separate output directory
71321-prepare2: prepare3 outputmakefile
71322+prepare2: prepare3 outputmakefile pax-plugin
71323
71324 prepare1: prepare2 include/linux/version.h include/generated/utsrelease.h \
71325 include/config/auto.conf
71326diff -urNp linux-2.6.39.1/mm/filemap.c linux-2.6.39.1/mm/filemap.c
71327--- linux-2.6.39.1/mm/filemap.c 2011-05-19 00:06:34.000000000 -0400
71328+++ linux-2.6.39.1/mm/filemap.c 2011-05-22 19:41:42.000000000 -0400
71329@@ -1724,7 +1724,7 @@ int generic_file_mmap(struct file * file
71330 struct address_space *mapping = file->f_mapping;
71331
71332 if (!mapping->a_ops->readpage)
71333- return -ENOEXEC;
71334+ return -ENODEV;
71335 file_accessed(file);
71336 vma->vm_ops = &generic_file_vm_ops;
71337 vma->vm_flags |= VM_CAN_NONLINEAR;
71338@@ -2120,6 +2120,7 @@ inline int generic_write_checks(struct f
71339 *pos = i_size_read(inode);
71340
71341 if (limit != RLIM_INFINITY) {
71342+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
71343 if (*pos >= limit) {
71344 send_sig(SIGXFSZ, current, 0);
71345 return -EFBIG;
71346diff -urNp linux-2.6.39.1/mm/fremap.c linux-2.6.39.1/mm/fremap.c
71347--- linux-2.6.39.1/mm/fremap.c 2011-05-19 00:06:34.000000000 -0400
71348+++ linux-2.6.39.1/mm/fremap.c 2011-05-22 19:36:33.000000000 -0400
71349@@ -156,6 +156,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsign
71350 retry:
71351 vma = find_vma(mm, start);
71352
71353+#ifdef CONFIG_PAX_SEGMEXEC
71354+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
71355+ goto out;
71356+#endif
71357+
71358 /*
71359 * Make sure the vma is shared, that it supports prefaulting,
71360 * and that the remapped range is valid and fully within
71361@@ -224,7 +229,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsign
71362 /*
71363 * drop PG_Mlocked flag for over-mapped range
71364 */
71365- unsigned int saved_flags = vma->vm_flags;
71366+ unsigned long saved_flags = vma->vm_flags;
71367 munlock_vma_pages_range(vma, start, start + size);
71368 vma->vm_flags = saved_flags;
71369 }
71370diff -urNp linux-2.6.39.1/mm/highmem.c linux-2.6.39.1/mm/highmem.c
71371--- linux-2.6.39.1/mm/highmem.c 2011-05-19 00:06:34.000000000 -0400
71372+++ linux-2.6.39.1/mm/highmem.c 2011-05-22 19:36:33.000000000 -0400
71373@@ -125,9 +125,10 @@ static void flush_all_zero_pkmaps(void)
71374 * So no dangers, even with speculative execution.
71375 */
71376 page = pte_page(pkmap_page_table[i]);
71377+ pax_open_kernel();
71378 pte_clear(&init_mm, (unsigned long)page_address(page),
71379 &pkmap_page_table[i]);
71380-
71381+ pax_close_kernel();
71382 set_page_address(page, NULL);
71383 need_flush = 1;
71384 }
71385@@ -186,9 +187,11 @@ start:
71386 }
71387 }
71388 vaddr = PKMAP_ADDR(last_pkmap_nr);
71389+
71390+ pax_open_kernel();
71391 set_pte_at(&init_mm, vaddr,
71392 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
71393-
71394+ pax_close_kernel();
71395 pkmap_count[last_pkmap_nr] = 1;
71396 set_page_address(page, (void *)vaddr);
71397
71398diff -urNp linux-2.6.39.1/mm/huge_memory.c linux-2.6.39.1/mm/huge_memory.c
71399--- linux-2.6.39.1/mm/huge_memory.c 2011-05-19 00:06:34.000000000 -0400
71400+++ linux-2.6.39.1/mm/huge_memory.c 2011-05-22 19:36:33.000000000 -0400
71401@@ -702,7 +702,7 @@ out:
71402 * run pte_offset_map on the pmd, if an huge pmd could
71403 * materialize from under us from a different thread.
71404 */
71405- if (unlikely(__pte_alloc(mm, vma, pmd, address)))
71406+ if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
71407 return VM_FAULT_OOM;
71408 /* if an huge pmd materialized from under us just retry later */
71409 if (unlikely(pmd_trans_huge(*pmd)))
71410diff -urNp linux-2.6.39.1/mm/hugetlb.c linux-2.6.39.1/mm/hugetlb.c
71411--- linux-2.6.39.1/mm/hugetlb.c 2011-05-19 00:06:34.000000000 -0400
71412+++ linux-2.6.39.1/mm/hugetlb.c 2011-05-22 19:36:33.000000000 -0400
71413@@ -2331,6 +2331,27 @@ static int unmap_ref_private(struct mm_s
71414 return 1;
71415 }
71416
71417+#ifdef CONFIG_PAX_SEGMEXEC
71418+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
71419+{
71420+ struct mm_struct *mm = vma->vm_mm;
71421+ struct vm_area_struct *vma_m;
71422+ unsigned long address_m;
71423+ pte_t *ptep_m;
71424+
71425+ vma_m = pax_find_mirror_vma(vma);
71426+ if (!vma_m)
71427+ return;
71428+
71429+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71430+ address_m = address + SEGMEXEC_TASK_SIZE;
71431+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
71432+ get_page(page_m);
71433+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
71434+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
71435+}
71436+#endif
71437+
71438 /*
71439 * Hugetlb_cow() should be called with page lock of the original hugepage held.
71440 */
71441@@ -2432,6 +2453,11 @@ retry_avoidcopy:
71442 make_huge_pte(vma, new_page, 1));
71443 page_remove_rmap(old_page);
71444 hugepage_add_new_anon_rmap(new_page, vma, address);
71445+
71446+#ifdef CONFIG_PAX_SEGMEXEC
71447+ pax_mirror_huge_pte(vma, address, new_page);
71448+#endif
71449+
71450 /* Make the old page be freed below */
71451 new_page = old_page;
71452 mmu_notifier_invalidate_range_end(mm,
71453@@ -2583,6 +2609,10 @@ retry:
71454 && (vma->vm_flags & VM_SHARED)));
71455 set_huge_pte_at(mm, address, ptep, new_pte);
71456
71457+#ifdef CONFIG_PAX_SEGMEXEC
71458+ pax_mirror_huge_pte(vma, address, page);
71459+#endif
71460+
71461 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
71462 /* Optimization, do the COW without a second fault */
71463 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
71464@@ -2612,6 +2642,10 @@ int hugetlb_fault(struct mm_struct *mm,
71465 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
71466 struct hstate *h = hstate_vma(vma);
71467
71468+#ifdef CONFIG_PAX_SEGMEXEC
71469+ struct vm_area_struct *vma_m;
71470+#endif
71471+
71472 ptep = huge_pte_offset(mm, address);
71473 if (ptep) {
71474 entry = huge_ptep_get(ptep);
71475@@ -2623,6 +2657,26 @@ int hugetlb_fault(struct mm_struct *mm,
71476 VM_FAULT_SET_HINDEX(h - hstates);
71477 }
71478
71479+#ifdef CONFIG_PAX_SEGMEXEC
71480+ vma_m = pax_find_mirror_vma(vma);
71481+ if (vma_m) {
71482+ unsigned long address_m;
71483+
71484+ if (vma->vm_start > vma_m->vm_start) {
71485+ address_m = address;
71486+ address -= SEGMEXEC_TASK_SIZE;
71487+ vma = vma_m;
71488+ h = hstate_vma(vma);
71489+ } else
71490+ address_m = address + SEGMEXEC_TASK_SIZE;
71491+
71492+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
71493+ return VM_FAULT_OOM;
71494+ address_m &= HPAGE_MASK;
71495+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
71496+ }
71497+#endif
71498+
71499 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
71500 if (!ptep)
71501 return VM_FAULT_OOM;
71502diff -urNp linux-2.6.39.1/mm/Kconfig linux-2.6.39.1/mm/Kconfig
71503--- linux-2.6.39.1/mm/Kconfig 2011-05-19 00:06:34.000000000 -0400
71504+++ linux-2.6.39.1/mm/Kconfig 2011-05-22 19:41:42.000000000 -0400
71505@@ -240,7 +240,7 @@ config KSM
71506 config DEFAULT_MMAP_MIN_ADDR
71507 int "Low address space to protect from user allocation"
71508 depends on MMU
71509- default 4096
71510+ default 65536
71511 help
71512 This is the portion of low virtual memory which should be protected
71513 from userspace allocation. Keeping a user from writing to low pages
71514diff -urNp linux-2.6.39.1/mm/kmemleak.c linux-2.6.39.1/mm/kmemleak.c
71515--- linux-2.6.39.1/mm/kmemleak.c 2011-06-03 00:04:14.000000000 -0400
71516+++ linux-2.6.39.1/mm/kmemleak.c 2011-06-03 00:32:08.000000000 -0400
71517@@ -357,7 +357,7 @@ static void print_unreferenced(struct se
71518
71519 for (i = 0; i < object->trace_len; i++) {
71520 void *ptr = (void *)object->trace[i];
71521- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
71522+ seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
71523 }
71524 }
71525
71526diff -urNp linux-2.6.39.1/mm/maccess.c linux-2.6.39.1/mm/maccess.c
71527--- linux-2.6.39.1/mm/maccess.c 2011-05-19 00:06:34.000000000 -0400
71528+++ linux-2.6.39.1/mm/maccess.c 2011-05-22 19:36:33.000000000 -0400
71529@@ -15,10 +15,10 @@
71530 * happens, handle that and return -EFAULT.
71531 */
71532
71533-long __weak probe_kernel_read(void *dst, void *src, size_t size)
71534+long __weak probe_kernel_read(void *dst, const void *src, size_t size)
71535 __attribute__((alias("__probe_kernel_read")));
71536
71537-long __probe_kernel_read(void *dst, void *src, size_t size)
71538+long __probe_kernel_read(void *dst, const void *src, size_t size)
71539 {
71540 long ret;
71541 mm_segment_t old_fs = get_fs();
71542@@ -43,10 +43,10 @@ EXPORT_SYMBOL_GPL(probe_kernel_read);
71543 * Safely write to address @dst from the buffer at @src. If a kernel fault
71544 * happens, handle that and return -EFAULT.
71545 */
71546-long __weak probe_kernel_write(void *dst, void *src, size_t size)
71547+long __weak probe_kernel_write(void *dst, const void *src, size_t size)
71548 __attribute__((alias("__probe_kernel_write")));
71549
71550-long __probe_kernel_write(void *dst, void *src, size_t size)
71551+long __probe_kernel_write(void *dst, const void *src, size_t size)
71552 {
71553 long ret;
71554 mm_segment_t old_fs = get_fs();
71555diff -urNp linux-2.6.39.1/mm/madvise.c linux-2.6.39.1/mm/madvise.c
71556--- linux-2.6.39.1/mm/madvise.c 2011-05-19 00:06:34.000000000 -0400
71557+++ linux-2.6.39.1/mm/madvise.c 2011-05-22 19:36:33.000000000 -0400
71558@@ -45,6 +45,10 @@ static long madvise_behavior(struct vm_a
71559 pgoff_t pgoff;
71560 unsigned long new_flags = vma->vm_flags;
71561
71562+#ifdef CONFIG_PAX_SEGMEXEC
71563+ struct vm_area_struct *vma_m;
71564+#endif
71565+
71566 switch (behavior) {
71567 case MADV_NORMAL:
71568 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
71569@@ -110,6 +114,13 @@ success:
71570 /*
71571 * vm_flags is protected by the mmap_sem held in write mode.
71572 */
71573+
71574+#ifdef CONFIG_PAX_SEGMEXEC
71575+ vma_m = pax_find_mirror_vma(vma);
71576+ if (vma_m)
71577+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
71578+#endif
71579+
71580 vma->vm_flags = new_flags;
71581
71582 out:
71583@@ -168,6 +179,11 @@ static long madvise_dontneed(struct vm_a
71584 struct vm_area_struct ** prev,
71585 unsigned long start, unsigned long end)
71586 {
71587+
71588+#ifdef CONFIG_PAX_SEGMEXEC
71589+ struct vm_area_struct *vma_m;
71590+#endif
71591+
71592 *prev = vma;
71593 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
71594 return -EINVAL;
71595@@ -180,6 +196,21 @@ static long madvise_dontneed(struct vm_a
71596 zap_page_range(vma, start, end - start, &details);
71597 } else
71598 zap_page_range(vma, start, end - start, NULL);
71599+
71600+#ifdef CONFIG_PAX_SEGMEXEC
71601+ vma_m = pax_find_mirror_vma(vma);
71602+ if (vma_m) {
71603+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
71604+ struct zap_details details = {
71605+ .nonlinear_vma = vma_m,
71606+ .last_index = ULONG_MAX,
71607+ };
71608+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
71609+ } else
71610+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
71611+ }
71612+#endif
71613+
71614 return 0;
71615 }
71616
71617@@ -376,6 +407,16 @@ SYSCALL_DEFINE3(madvise, unsigned long,
71618 if (end < start)
71619 goto out;
71620
71621+#ifdef CONFIG_PAX_SEGMEXEC
71622+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
71623+ if (end > SEGMEXEC_TASK_SIZE)
71624+ goto out;
71625+ } else
71626+#endif
71627+
71628+ if (end > TASK_SIZE)
71629+ goto out;
71630+
71631 error = 0;
71632 if (end == start)
71633 goto out;
71634diff -urNp linux-2.6.39.1/mm/memory.c linux-2.6.39.1/mm/memory.c
71635--- linux-2.6.39.1/mm/memory.c 2011-05-19 00:06:34.000000000 -0400
71636+++ linux-2.6.39.1/mm/memory.c 2011-05-22 19:36:33.000000000 -0400
71637@@ -259,8 +259,12 @@ static inline void free_pmd_range(struct
71638 return;
71639
71640 pmd = pmd_offset(pud, start);
71641+
71642+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
71643 pud_clear(pud);
71644 pmd_free_tlb(tlb, pmd, start);
71645+#endif
71646+
71647 }
71648
71649 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71650@@ -291,9 +295,12 @@ static inline void free_pud_range(struct
71651 if (end - 1 > ceiling - 1)
71652 return;
71653
71654+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
71655 pud = pud_offset(pgd, start);
71656 pgd_clear(pgd);
71657 pud_free_tlb(tlb, pud, start);
71658+#endif
71659+
71660 }
71661
71662 /*
71663@@ -1410,12 +1417,6 @@ no_page_table:
71664 return page;
71665 }
71666
71667-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
71668-{
71669- return stack_guard_page_start(vma, addr) ||
71670- stack_guard_page_end(vma, addr+PAGE_SIZE);
71671-}
71672-
71673 /**
71674 * __get_user_pages() - pin user pages in memory
71675 * @tsk: task_struct of target task
71676@@ -1488,10 +1489,10 @@ int __get_user_pages(struct task_struct
71677 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
71678 i = 0;
71679
71680- do {
71681+ while (nr_pages) {
71682 struct vm_area_struct *vma;
71683
71684- vma = find_extend_vma(mm, start);
71685+ vma = find_vma(mm, start);
71686 if (!vma && in_gate_area(mm, start)) {
71687 unsigned long pg = start & PAGE_MASK;
71688 pgd_t *pgd;
71689@@ -1539,7 +1540,7 @@ int __get_user_pages(struct task_struct
71690 goto next_page;
71691 }
71692
71693- if (!vma ||
71694+ if (!vma || start < vma->vm_start ||
71695 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
71696 !(vm_flags & vma->vm_flags))
71697 return i ? : -EFAULT;
71698@@ -1566,11 +1567,6 @@ int __get_user_pages(struct task_struct
71699 int ret;
71700 unsigned int fault_flags = 0;
71701
71702- /* For mlock, just skip the stack guard page. */
71703- if (foll_flags & FOLL_MLOCK) {
71704- if (stack_guard_page(vma, start))
71705- goto next_page;
71706- }
71707 if (foll_flags & FOLL_WRITE)
71708 fault_flags |= FAULT_FLAG_WRITE;
71709 if (nonblocking)
71710@@ -1644,7 +1640,7 @@ next_page:
71711 start += PAGE_SIZE;
71712 nr_pages--;
71713 } while (nr_pages && start < vma->vm_end);
71714- } while (nr_pages);
71715+ }
71716 return i;
71717 }
71718 EXPORT_SYMBOL(__get_user_pages);
71719@@ -1795,6 +1791,10 @@ static int insert_page(struct vm_area_st
71720 page_add_file_rmap(page);
71721 set_pte_at(mm, addr, pte, mk_pte(page, prot));
71722
71723+#ifdef CONFIG_PAX_SEGMEXEC
71724+ pax_mirror_file_pte(vma, addr, page, ptl);
71725+#endif
71726+
71727 retval = 0;
71728 pte_unmap_unlock(pte, ptl);
71729 return retval;
71730@@ -1829,10 +1829,22 @@ out:
71731 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
71732 struct page *page)
71733 {
71734+
71735+#ifdef CONFIG_PAX_SEGMEXEC
71736+ struct vm_area_struct *vma_m;
71737+#endif
71738+
71739 if (addr < vma->vm_start || addr >= vma->vm_end)
71740 return -EFAULT;
71741 if (!page_count(page))
71742 return -EINVAL;
71743+
71744+#ifdef CONFIG_PAX_SEGMEXEC
71745+ vma_m = pax_find_mirror_vma(vma);
71746+ if (vma_m)
71747+ vma_m->vm_flags |= VM_INSERTPAGE;
71748+#endif
71749+
71750 vma->vm_flags |= VM_INSERTPAGE;
71751 return insert_page(vma, addr, page, vma->vm_page_prot);
71752 }
71753@@ -1918,6 +1930,7 @@ int vm_insert_mixed(struct vm_area_struc
71754 unsigned long pfn)
71755 {
71756 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
71757+ BUG_ON(vma->vm_mirror);
71758
71759 if (addr < vma->vm_start || addr >= vma->vm_end)
71760 return -EFAULT;
71761@@ -2233,6 +2246,186 @@ static inline void cow_user_page(struct
71762 copy_user_highpage(dst, src, va, vma);
71763 }
71764
71765+#ifdef CONFIG_PAX_SEGMEXEC
71766+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
71767+{
71768+ struct mm_struct *mm = vma->vm_mm;
71769+ spinlock_t *ptl;
71770+ pte_t *pte, entry;
71771+
71772+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
71773+ entry = *pte;
71774+ if (!pte_present(entry)) {
71775+ if (!pte_none(entry)) {
71776+ BUG_ON(pte_file(entry));
71777+ free_swap_and_cache(pte_to_swp_entry(entry));
71778+ pte_clear_not_present_full(mm, address, pte, 0);
71779+ }
71780+ } else {
71781+ struct page *page;
71782+
71783+ flush_cache_page(vma, address, pte_pfn(entry));
71784+ entry = ptep_clear_flush(vma, address, pte);
71785+ BUG_ON(pte_dirty(entry));
71786+ page = vm_normal_page(vma, address, entry);
71787+ if (page) {
71788+ update_hiwater_rss(mm);
71789+ if (PageAnon(page))
71790+ dec_mm_counter_fast(mm, MM_ANONPAGES);
71791+ else
71792+ dec_mm_counter_fast(mm, MM_FILEPAGES);
71793+ page_remove_rmap(page);
71794+ page_cache_release(page);
71795+ }
71796+ }
71797+ pte_unmap_unlock(pte, ptl);
71798+}
71799+
71800+/* PaX: if vma is mirrored, synchronize the mirror's PTE
71801+ *
71802+ * the ptl of the lower mapped page is held on entry and is not released on exit
71803+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
71804+ */
71805+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
71806+{
71807+ struct mm_struct *mm = vma->vm_mm;
71808+ unsigned long address_m;
71809+ spinlock_t *ptl_m;
71810+ struct vm_area_struct *vma_m;
71811+ pmd_t *pmd_m;
71812+ pte_t *pte_m, entry_m;
71813+
71814+ BUG_ON(!page_m || !PageAnon(page_m));
71815+
71816+ vma_m = pax_find_mirror_vma(vma);
71817+ if (!vma_m)
71818+ return;
71819+
71820+ BUG_ON(!PageLocked(page_m));
71821+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71822+ address_m = address + SEGMEXEC_TASK_SIZE;
71823+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71824+ pte_m = pte_offset_map(pmd_m, address_m);
71825+ ptl_m = pte_lockptr(mm, pmd_m);
71826+ if (ptl != ptl_m) {
71827+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71828+ if (!pte_none(*pte_m))
71829+ goto out;
71830+ }
71831+
71832+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
71833+ page_cache_get(page_m);
71834+ page_add_anon_rmap(page_m, vma_m, address_m);
71835+ inc_mm_counter_fast(mm, MM_ANONPAGES);
71836+ set_pte_at(mm, address_m, pte_m, entry_m);
71837+ update_mmu_cache(vma_m, address_m, entry_m);
71838+out:
71839+ if (ptl != ptl_m)
71840+ spin_unlock(ptl_m);
71841+ pte_unmap(pte_m);
71842+ unlock_page(page_m);
71843+}
71844+
71845+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
71846+{
71847+ struct mm_struct *mm = vma->vm_mm;
71848+ unsigned long address_m;
71849+ spinlock_t *ptl_m;
71850+ struct vm_area_struct *vma_m;
71851+ pmd_t *pmd_m;
71852+ pte_t *pte_m, entry_m;
71853+
71854+ BUG_ON(!page_m || PageAnon(page_m));
71855+
71856+ vma_m = pax_find_mirror_vma(vma);
71857+ if (!vma_m)
71858+ return;
71859+
71860+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71861+ address_m = address + SEGMEXEC_TASK_SIZE;
71862+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71863+ pte_m = pte_offset_map(pmd_m, address_m);
71864+ ptl_m = pte_lockptr(mm, pmd_m);
71865+ if (ptl != ptl_m) {
71866+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71867+ if (!pte_none(*pte_m))
71868+ goto out;
71869+ }
71870+
71871+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
71872+ page_cache_get(page_m);
71873+ page_add_file_rmap(page_m);
71874+ inc_mm_counter_fast(mm, MM_FILEPAGES);
71875+ set_pte_at(mm, address_m, pte_m, entry_m);
71876+ update_mmu_cache(vma_m, address_m, entry_m);
71877+out:
71878+ if (ptl != ptl_m)
71879+ spin_unlock(ptl_m);
71880+ pte_unmap(pte_m);
71881+}
71882+
71883+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
71884+{
71885+ struct mm_struct *mm = vma->vm_mm;
71886+ unsigned long address_m;
71887+ spinlock_t *ptl_m;
71888+ struct vm_area_struct *vma_m;
71889+ pmd_t *pmd_m;
71890+ pte_t *pte_m, entry_m;
71891+
71892+ vma_m = pax_find_mirror_vma(vma);
71893+ if (!vma_m)
71894+ return;
71895+
71896+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71897+ address_m = address + SEGMEXEC_TASK_SIZE;
71898+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71899+ pte_m = pte_offset_map(pmd_m, address_m);
71900+ ptl_m = pte_lockptr(mm, pmd_m);
71901+ if (ptl != ptl_m) {
71902+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71903+ if (!pte_none(*pte_m))
71904+ goto out;
71905+ }
71906+
71907+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
71908+ set_pte_at(mm, address_m, pte_m, entry_m);
71909+out:
71910+ if (ptl != ptl_m)
71911+ spin_unlock(ptl_m);
71912+ pte_unmap(pte_m);
71913+}
71914+
71915+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
71916+{
71917+ struct page *page_m;
71918+ pte_t entry;
71919+
71920+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
71921+ goto out;
71922+
71923+ entry = *pte;
71924+ page_m = vm_normal_page(vma, address, entry);
71925+ if (!page_m)
71926+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
71927+ else if (PageAnon(page_m)) {
71928+ if (pax_find_mirror_vma(vma)) {
71929+ pte_unmap_unlock(pte, ptl);
71930+ lock_page(page_m);
71931+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
71932+ if (pte_same(entry, *pte))
71933+ pax_mirror_anon_pte(vma, address, page_m, ptl);
71934+ else
71935+ unlock_page(page_m);
71936+ }
71937+ } else
71938+ pax_mirror_file_pte(vma, address, page_m, ptl);
71939+
71940+out:
71941+ pte_unmap_unlock(pte, ptl);
71942+}
71943+#endif
71944+
71945 /*
71946 * This routine handles present pages, when users try to write
71947 * to a shared page. It is done by copying the page to a new address
71948@@ -2444,6 +2637,12 @@ gotten:
71949 */
71950 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
71951 if (likely(pte_same(*page_table, orig_pte))) {
71952+
71953+#ifdef CONFIG_PAX_SEGMEXEC
71954+ if (pax_find_mirror_vma(vma))
71955+ BUG_ON(!trylock_page(new_page));
71956+#endif
71957+
71958 if (old_page) {
71959 if (!PageAnon(old_page)) {
71960 dec_mm_counter_fast(mm, MM_FILEPAGES);
71961@@ -2495,6 +2694,10 @@ gotten:
71962 page_remove_rmap(old_page);
71963 }
71964
71965+#ifdef CONFIG_PAX_SEGMEXEC
71966+ pax_mirror_anon_pte(vma, address, new_page, ptl);
71967+#endif
71968+
71969 /* Free the old page.. */
71970 new_page = old_page;
71971 ret |= VM_FAULT_WRITE;
71972@@ -2905,6 +3108,11 @@ static int do_swap_page(struct mm_struct
71973 swap_free(entry);
71974 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
71975 try_to_free_swap(page);
71976+
71977+#ifdef CONFIG_PAX_SEGMEXEC
71978+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
71979+#endif
71980+
71981 unlock_page(page);
71982 if (swapcache) {
71983 /*
71984@@ -2928,6 +3136,11 @@ static int do_swap_page(struct mm_struct
71985
71986 /* No need to invalidate - it was non-present before */
71987 update_mmu_cache(vma, address, page_table);
71988+
71989+#ifdef CONFIG_PAX_SEGMEXEC
71990+ pax_mirror_anon_pte(vma, address, page, ptl);
71991+#endif
71992+
71993 unlock:
71994 pte_unmap_unlock(page_table, ptl);
71995 out:
71996@@ -2947,40 +3160,6 @@ out_release:
71997 }
71998
71999 /*
72000- * This is like a special single-page "expand_{down|up}wards()",
72001- * except we must first make sure that 'address{-|+}PAGE_SIZE'
72002- * doesn't hit another vma.
72003- */
72004-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
72005-{
72006- address &= PAGE_MASK;
72007- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
72008- struct vm_area_struct *prev = vma->vm_prev;
72009-
72010- /*
72011- * Is there a mapping abutting this one below?
72012- *
72013- * That's only ok if it's the same stack mapping
72014- * that has gotten split..
72015- */
72016- if (prev && prev->vm_end == address)
72017- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
72018-
72019- expand_stack(vma, address - PAGE_SIZE);
72020- }
72021- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
72022- struct vm_area_struct *next = vma->vm_next;
72023-
72024- /* As VM_GROWSDOWN but s/below/above/ */
72025- if (next && next->vm_start == address + PAGE_SIZE)
72026- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
72027-
72028- expand_upwards(vma, address + PAGE_SIZE);
72029- }
72030- return 0;
72031-}
72032-
72033-/*
72034 * We enter with non-exclusive mmap_sem (to exclude vma changes,
72035 * but allow concurrent faults), and pte mapped but not yet locked.
72036 * We return with mmap_sem still held, but pte unmapped and unlocked.
72037@@ -2989,27 +3168,23 @@ static int do_anonymous_page(struct mm_s
72038 unsigned long address, pte_t *page_table, pmd_t *pmd,
72039 unsigned int flags)
72040 {
72041- struct page *page;
72042+ struct page *page = NULL;
72043 spinlock_t *ptl;
72044 pte_t entry;
72045
72046- pte_unmap(page_table);
72047-
72048- /* Check if we need to add a guard page to the stack */
72049- if (check_stack_guard_page(vma, address) < 0)
72050- return VM_FAULT_SIGBUS;
72051-
72052- /* Use the zero-page for reads */
72053 if (!(flags & FAULT_FLAG_WRITE)) {
72054 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
72055 vma->vm_page_prot));
72056- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72057+ ptl = pte_lockptr(mm, pmd);
72058+ spin_lock(ptl);
72059 if (!pte_none(*page_table))
72060 goto unlock;
72061 goto setpte;
72062 }
72063
72064 /* Allocate our own private page. */
72065+ pte_unmap(page_table);
72066+
72067 if (unlikely(anon_vma_prepare(vma)))
72068 goto oom;
72069 page = alloc_zeroed_user_highpage_movable(vma, address);
72070@@ -3028,6 +3203,11 @@ static int do_anonymous_page(struct mm_s
72071 if (!pte_none(*page_table))
72072 goto release;
72073
72074+#ifdef CONFIG_PAX_SEGMEXEC
72075+ if (pax_find_mirror_vma(vma))
72076+ BUG_ON(!trylock_page(page));
72077+#endif
72078+
72079 inc_mm_counter_fast(mm, MM_ANONPAGES);
72080 page_add_new_anon_rmap(page, vma, address);
72081 setpte:
72082@@ -3035,6 +3215,12 @@ setpte:
72083
72084 /* No need to invalidate - it was non-present before */
72085 update_mmu_cache(vma, address, page_table);
72086+
72087+#ifdef CONFIG_PAX_SEGMEXEC
72088+ if (page)
72089+ pax_mirror_anon_pte(vma, address, page, ptl);
72090+#endif
72091+
72092 unlock:
72093 pte_unmap_unlock(page_table, ptl);
72094 return 0;
72095@@ -3172,6 +3358,12 @@ static int __do_fault(struct mm_struct *
72096 */
72097 /* Only go through if we didn't race with anybody else... */
72098 if (likely(pte_same(*page_table, orig_pte))) {
72099+
72100+#ifdef CONFIG_PAX_SEGMEXEC
72101+ if (anon && pax_find_mirror_vma(vma))
72102+ BUG_ON(!trylock_page(page));
72103+#endif
72104+
72105 flush_icache_page(vma, page);
72106 entry = mk_pte(page, vma->vm_page_prot);
72107 if (flags & FAULT_FLAG_WRITE)
72108@@ -3191,6 +3383,14 @@ static int __do_fault(struct mm_struct *
72109
72110 /* no need to invalidate: a not-present page won't be cached */
72111 update_mmu_cache(vma, address, page_table);
72112+
72113+#ifdef CONFIG_PAX_SEGMEXEC
72114+ if (anon)
72115+ pax_mirror_anon_pte(vma, address, page, ptl);
72116+ else
72117+ pax_mirror_file_pte(vma, address, page, ptl);
72118+#endif
72119+
72120 } else {
72121 if (charged)
72122 mem_cgroup_uncharge_page(page);
72123@@ -3338,6 +3538,12 @@ int handle_pte_fault(struct mm_struct *m
72124 if (flags & FAULT_FLAG_WRITE)
72125 flush_tlb_fix_spurious_fault(vma, address);
72126 }
72127+
72128+#ifdef CONFIG_PAX_SEGMEXEC
72129+ pax_mirror_pte(vma, address, pte, pmd, ptl);
72130+ return 0;
72131+#endif
72132+
72133 unlock:
72134 pte_unmap_unlock(pte, ptl);
72135 return 0;
72136@@ -3354,6 +3560,10 @@ int handle_mm_fault(struct mm_struct *mm
72137 pmd_t *pmd;
72138 pte_t *pte;
72139
72140+#ifdef CONFIG_PAX_SEGMEXEC
72141+ struct vm_area_struct *vma_m;
72142+#endif
72143+
72144 __set_current_state(TASK_RUNNING);
72145
72146 count_vm_event(PGFAULT);
72147@@ -3364,6 +3574,34 @@ int handle_mm_fault(struct mm_struct *mm
72148 if (unlikely(is_vm_hugetlb_page(vma)))
72149 return hugetlb_fault(mm, vma, address, flags);
72150
72151+#ifdef CONFIG_PAX_SEGMEXEC
72152+ vma_m = pax_find_mirror_vma(vma);
72153+ if (vma_m) {
72154+ unsigned long address_m;
72155+ pgd_t *pgd_m;
72156+ pud_t *pud_m;
72157+ pmd_t *pmd_m;
72158+
72159+ if (vma->vm_start > vma_m->vm_start) {
72160+ address_m = address;
72161+ address -= SEGMEXEC_TASK_SIZE;
72162+ vma = vma_m;
72163+ } else
72164+ address_m = address + SEGMEXEC_TASK_SIZE;
72165+
72166+ pgd_m = pgd_offset(mm, address_m);
72167+ pud_m = pud_alloc(mm, pgd_m, address_m);
72168+ if (!pud_m)
72169+ return VM_FAULT_OOM;
72170+ pmd_m = pmd_alloc(mm, pud_m, address_m);
72171+ if (!pmd_m)
72172+ return VM_FAULT_OOM;
72173+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
72174+ return VM_FAULT_OOM;
72175+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
72176+ }
72177+#endif
72178+
72179 pgd = pgd_offset(mm, address);
72180 pud = pud_alloc(mm, pgd, address);
72181 if (!pud)
72182@@ -3393,7 +3631,7 @@ int handle_mm_fault(struct mm_struct *mm
72183 * run pte_offset_map on the pmd, if an huge pmd could
72184 * materialize from under us from a different thread.
72185 */
72186- if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
72187+ if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
72188 return VM_FAULT_OOM;
72189 /* if an huge pmd materialized from under us just retry later */
72190 if (unlikely(pmd_trans_huge(*pmd)))
72191@@ -3497,7 +3735,7 @@ static int __init gate_vma_init(void)
72192 gate_vma.vm_start = FIXADDR_USER_START;
72193 gate_vma.vm_end = FIXADDR_USER_END;
72194 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
72195- gate_vma.vm_page_prot = __P101;
72196+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
72197 /*
72198 * Make sure the vDSO gets into every core dump.
72199 * Dumping its contents makes post-mortem fully interpretable later
72200diff -urNp linux-2.6.39.1/mm/memory-failure.c linux-2.6.39.1/mm/memory-failure.c
72201--- linux-2.6.39.1/mm/memory-failure.c 2011-05-19 00:06:34.000000000 -0400
72202+++ linux-2.6.39.1/mm/memory-failure.c 2011-05-22 19:36:33.000000000 -0400
72203@@ -58,7 +58,7 @@ int sysctl_memory_failure_early_kill __r
72204
72205 int sysctl_memory_failure_recovery __read_mostly = 1;
72206
72207-atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
72208+atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
72209
72210 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
72211
72212@@ -1012,7 +1012,7 @@ int __memory_failure(unsigned long pfn,
72213 }
72214
72215 nr_pages = 1 << compound_trans_order(hpage);
72216- atomic_long_add(nr_pages, &mce_bad_pages);
72217+ atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
72218
72219 /*
72220 * We need/can do nothing about count=0 pages.
72221@@ -1042,7 +1042,7 @@ int __memory_failure(unsigned long pfn,
72222 if (!PageHWPoison(hpage)
72223 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
72224 || (p != hpage && TestSetPageHWPoison(hpage))) {
72225- atomic_long_sub(nr_pages, &mce_bad_pages);
72226+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72227 return 0;
72228 }
72229 set_page_hwpoison_huge_page(hpage);
72230@@ -1100,7 +1100,7 @@ int __memory_failure(unsigned long pfn,
72231 }
72232 if (hwpoison_filter(p)) {
72233 if (TestClearPageHWPoison(p))
72234- atomic_long_sub(nr_pages, &mce_bad_pages);
72235+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72236 unlock_page(hpage);
72237 put_page(hpage);
72238 return 0;
72239@@ -1226,7 +1226,7 @@ int unpoison_memory(unsigned long pfn)
72240 return 0;
72241 }
72242 if (TestClearPageHWPoison(p))
72243- atomic_long_sub(nr_pages, &mce_bad_pages);
72244+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72245 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
72246 return 0;
72247 }
72248@@ -1240,7 +1240,7 @@ int unpoison_memory(unsigned long pfn)
72249 */
72250 if (TestClearPageHWPoison(page)) {
72251 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
72252- atomic_long_sub(nr_pages, &mce_bad_pages);
72253+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72254 freeit = 1;
72255 if (PageHuge(page))
72256 clear_page_hwpoison_huge_page(page);
72257@@ -1353,7 +1353,7 @@ static int soft_offline_huge_page(struct
72258 }
72259 done:
72260 if (!PageHWPoison(hpage))
72261- atomic_long_add(1 << compound_trans_order(hpage), &mce_bad_pages);
72262+ atomic_long_add_unchecked(1 << compound_trans_order(hpage), &mce_bad_pages);
72263 set_page_hwpoison_huge_page(hpage);
72264 dequeue_hwpoisoned_huge_page(hpage);
72265 /* keep elevated page count for bad page */
72266@@ -1482,7 +1482,7 @@ int soft_offline_page(struct page *page,
72267 return ret;
72268
72269 done:
72270- atomic_long_add(1, &mce_bad_pages);
72271+ atomic_long_add_unchecked(1, &mce_bad_pages);
72272 SetPageHWPoison(page);
72273 /* keep elevated page count for bad page */
72274 return ret;
72275diff -urNp linux-2.6.39.1/mm/mempolicy.c linux-2.6.39.1/mm/mempolicy.c
72276--- linux-2.6.39.1/mm/mempolicy.c 2011-05-19 00:06:34.000000000 -0400
72277+++ linux-2.6.39.1/mm/mempolicy.c 2011-05-22 19:41:42.000000000 -0400
72278@@ -643,6 +643,10 @@ static int mbind_range(struct mm_struct
72279 unsigned long vmstart;
72280 unsigned long vmend;
72281
72282+#ifdef CONFIG_PAX_SEGMEXEC
72283+ struct vm_area_struct *vma_m;
72284+#endif
72285+
72286 vma = find_vma_prev(mm, start, &prev);
72287 if (!vma || vma->vm_start > start)
72288 return -EFAULT;
72289@@ -673,6 +677,16 @@ static int mbind_range(struct mm_struct
72290 err = policy_vma(vma, new_pol);
72291 if (err)
72292 goto out;
72293+
72294+#ifdef CONFIG_PAX_SEGMEXEC
72295+ vma_m = pax_find_mirror_vma(vma);
72296+ if (vma_m) {
72297+ err = policy_vma(vma_m, new_pol);
72298+ if (err)
72299+ goto out;
72300+ }
72301+#endif
72302+
72303 }
72304
72305 out:
72306@@ -1106,6 +1120,17 @@ static long do_mbind(unsigned long start
72307
72308 if (end < start)
72309 return -EINVAL;
72310+
72311+#ifdef CONFIG_PAX_SEGMEXEC
72312+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
72313+ if (end > SEGMEXEC_TASK_SIZE)
72314+ return -EINVAL;
72315+ } else
72316+#endif
72317+
72318+ if (end > TASK_SIZE)
72319+ return -EINVAL;
72320+
72321 if (end == start)
72322 return 0;
72323
72324@@ -1324,6 +1349,14 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pi
72325 if (!mm)
72326 goto out;
72327
72328+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
72329+ if (mm != current->mm &&
72330+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
72331+ err = -EPERM;
72332+ goto out;
72333+ }
72334+#endif
72335+
72336 /*
72337 * Check if this process has the right to modify the specified
72338 * process. The right exists if the process has administrative
72339@@ -1333,8 +1366,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pi
72340 rcu_read_lock();
72341 tcred = __task_cred(task);
72342 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
72343- cred->uid != tcred->suid && cred->uid != tcred->uid &&
72344- !capable(CAP_SYS_NICE)) {
72345+ cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
72346 rcu_read_unlock();
72347 err = -EPERM;
72348 goto out;
72349@@ -2634,7 +2666,7 @@ int show_numa_map(struct seq_file *m, vo
72350
72351 if (file) {
72352 seq_printf(m, " file=");
72353- seq_path(m, &file->f_path, "\n\t= ");
72354+ seq_path(m, &file->f_path, "\n\t\\= ");
72355 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
72356 seq_printf(m, " heap");
72357 } else if (vma->vm_start <= mm->start_stack &&
72358diff -urNp linux-2.6.39.1/mm/migrate.c linux-2.6.39.1/mm/migrate.c
72359--- linux-2.6.39.1/mm/migrate.c 2011-05-19 00:06:34.000000000 -0400
72360+++ linux-2.6.39.1/mm/migrate.c 2011-05-22 19:41:42.000000000 -0400
72361@@ -1133,6 +1133,8 @@ static int do_pages_move(struct mm_struc
72362 unsigned long chunk_start;
72363 int err;
72364
72365+ pax_track_stack();
72366+
72367 task_nodes = cpuset_mems_allowed(task);
72368
72369 err = -ENOMEM;
72370@@ -1317,6 +1319,14 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid,
72371 if (!mm)
72372 return -EINVAL;
72373
72374+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
72375+ if (mm != current->mm &&
72376+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
72377+ err = -EPERM;
72378+ goto out;
72379+ }
72380+#endif
72381+
72382 /*
72383 * Check if this process has the right to modify the specified
72384 * process. The right exists if the process has administrative
72385@@ -1326,8 +1336,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid,
72386 rcu_read_lock();
72387 tcred = __task_cred(task);
72388 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
72389- cred->uid != tcred->suid && cred->uid != tcred->uid &&
72390- !capable(CAP_SYS_NICE)) {
72391+ cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
72392 rcu_read_unlock();
72393 err = -EPERM;
72394 goto out;
72395diff -urNp linux-2.6.39.1/mm/mlock.c linux-2.6.39.1/mm/mlock.c
72396--- linux-2.6.39.1/mm/mlock.c 2011-05-19 00:06:34.000000000 -0400
72397+++ linux-2.6.39.1/mm/mlock.c 2011-05-22 19:41:42.000000000 -0400
72398@@ -13,6 +13,7 @@
72399 #include <linux/pagemap.h>
72400 #include <linux/mempolicy.h>
72401 #include <linux/syscalls.h>
72402+#include <linux/security.h>
72403 #include <linux/sched.h>
72404 #include <linux/module.h>
72405 #include <linux/rmap.h>
72406@@ -377,6 +378,9 @@ static int do_mlock(unsigned long start,
72407 return -EINVAL;
72408 if (end == start)
72409 return 0;
72410+ if (end > TASK_SIZE)
72411+ return -EINVAL;
72412+
72413 vma = find_vma_prev(current->mm, start, &prev);
72414 if (!vma || vma->vm_start > start)
72415 return -ENOMEM;
72416@@ -387,6 +391,11 @@ static int do_mlock(unsigned long start,
72417 for (nstart = start ; ; ) {
72418 unsigned int newflags;
72419
72420+#ifdef CONFIG_PAX_SEGMEXEC
72421+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
72422+ break;
72423+#endif
72424+
72425 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
72426
72427 newflags = vma->vm_flags | VM_LOCKED;
72428@@ -492,6 +501,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, st
72429 lock_limit >>= PAGE_SHIFT;
72430
72431 /* check against resource limits */
72432+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
72433 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
72434 error = do_mlock(start, len, 1);
72435 up_write(&current->mm->mmap_sem);
72436@@ -515,17 +525,23 @@ SYSCALL_DEFINE2(munlock, unsigned long,
72437 static int do_mlockall(int flags)
72438 {
72439 struct vm_area_struct * vma, * prev = NULL;
72440- unsigned int def_flags = 0;
72441
72442 if (flags & MCL_FUTURE)
72443- def_flags = VM_LOCKED;
72444- current->mm->def_flags = def_flags;
72445+ current->mm->def_flags |= VM_LOCKED;
72446+ else
72447+ current->mm->def_flags &= ~VM_LOCKED;
72448 if (flags == MCL_FUTURE)
72449 goto out;
72450
72451 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
72452- unsigned int newflags;
72453+ unsigned long newflags;
72454+
72455+#ifdef CONFIG_PAX_SEGMEXEC
72456+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
72457+ break;
72458+#endif
72459
72460+ BUG_ON(vma->vm_end > TASK_SIZE);
72461 newflags = vma->vm_flags | VM_LOCKED;
72462 if (!(flags & MCL_CURRENT))
72463 newflags &= ~VM_LOCKED;
72464@@ -557,6 +573,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
72465 lock_limit >>= PAGE_SHIFT;
72466
72467 ret = -ENOMEM;
72468+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
72469 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
72470 capable(CAP_IPC_LOCK))
72471 ret = do_mlockall(flags);
72472diff -urNp linux-2.6.39.1/mm/mmap.c linux-2.6.39.1/mm/mmap.c
72473--- linux-2.6.39.1/mm/mmap.c 2011-05-19 00:06:34.000000000 -0400
72474+++ linux-2.6.39.1/mm/mmap.c 2011-05-22 19:41:42.000000000 -0400
72475@@ -46,6 +46,16 @@
72476 #define arch_rebalance_pgtables(addr, len) (addr)
72477 #endif
72478
72479+static inline void verify_mm_writelocked(struct mm_struct *mm)
72480+{
72481+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
72482+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
72483+ up_read(&mm->mmap_sem);
72484+ BUG();
72485+ }
72486+#endif
72487+}
72488+
72489 static void unmap_region(struct mm_struct *mm,
72490 struct vm_area_struct *vma, struct vm_area_struct *prev,
72491 unsigned long start, unsigned long end);
72492@@ -71,22 +81,32 @@ static void unmap_region(struct mm_struc
72493 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
72494 *
72495 */
72496-pgprot_t protection_map[16] = {
72497+pgprot_t protection_map[16] __read_only = {
72498 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
72499 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
72500 };
72501
72502 pgprot_t vm_get_page_prot(unsigned long vm_flags)
72503 {
72504- return __pgprot(pgprot_val(protection_map[vm_flags &
72505+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
72506 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
72507 pgprot_val(arch_vm_get_page_prot(vm_flags)));
72508+
72509+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72510+ if (!(__supported_pte_mask & _PAGE_NX) &&
72511+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
72512+ (vm_flags & (VM_READ | VM_WRITE)))
72513+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
72514+#endif
72515+
72516+ return prot;
72517 }
72518 EXPORT_SYMBOL(vm_get_page_prot);
72519
72520 int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
72521 int sysctl_overcommit_ratio = 50; /* default is 50% */
72522 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
72523+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
72524 struct percpu_counter vm_committed_as;
72525
72526 /*
72527@@ -232,6 +252,7 @@ static struct vm_area_struct *remove_vma
72528 struct vm_area_struct *next = vma->vm_next;
72529
72530 might_sleep();
72531+ BUG_ON(vma->vm_mirror);
72532 if (vma->vm_ops && vma->vm_ops->close)
72533 vma->vm_ops->close(vma);
72534 if (vma->vm_file) {
72535@@ -276,6 +297,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
72536 * not page aligned -Ram Gupta
72537 */
72538 rlim = rlimit(RLIMIT_DATA);
72539+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
72540 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
72541 (mm->end_data - mm->start_data) > rlim)
72542 goto out;
72543@@ -719,6 +741,12 @@ static int
72544 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
72545 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
72546 {
72547+
72548+#ifdef CONFIG_PAX_SEGMEXEC
72549+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
72550+ return 0;
72551+#endif
72552+
72553 if (is_mergeable_vma(vma, file, vm_flags) &&
72554 is_mergeable_anon_vma(anon_vma, vma->anon_vma)) {
72555 if (vma->vm_pgoff == vm_pgoff)
72556@@ -738,6 +766,12 @@ static int
72557 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
72558 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
72559 {
72560+
72561+#ifdef CONFIG_PAX_SEGMEXEC
72562+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
72563+ return 0;
72564+#endif
72565+
72566 if (is_mergeable_vma(vma, file, vm_flags) &&
72567 is_mergeable_anon_vma(anon_vma, vma->anon_vma)) {
72568 pgoff_t vm_pglen;
72569@@ -780,13 +814,20 @@ can_vma_merge_after(struct vm_area_struc
72570 struct vm_area_struct *vma_merge(struct mm_struct *mm,
72571 struct vm_area_struct *prev, unsigned long addr,
72572 unsigned long end, unsigned long vm_flags,
72573- struct anon_vma *anon_vma, struct file *file,
72574+ struct anon_vma *anon_vma, struct file *file,
72575 pgoff_t pgoff, struct mempolicy *policy)
72576 {
72577 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
72578 struct vm_area_struct *area, *next;
72579 int err;
72580
72581+#ifdef CONFIG_PAX_SEGMEXEC
72582+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
72583+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
72584+
72585+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
72586+#endif
72587+
72588 /*
72589 * We later require that vma->vm_flags == vm_flags,
72590 * so this tests vma->vm_flags & VM_SPECIAL, too.
72591@@ -802,6 +843,15 @@ struct vm_area_struct *vma_merge(struct
72592 if (next && next->vm_end == end) /* cases 6, 7, 8 */
72593 next = next->vm_next;
72594
72595+#ifdef CONFIG_PAX_SEGMEXEC
72596+ if (prev)
72597+ prev_m = pax_find_mirror_vma(prev);
72598+ if (area)
72599+ area_m = pax_find_mirror_vma(area);
72600+ if (next)
72601+ next_m = pax_find_mirror_vma(next);
72602+#endif
72603+
72604 /*
72605 * Can it merge with the predecessor?
72606 */
72607@@ -821,9 +871,24 @@ struct vm_area_struct *vma_merge(struct
72608 /* cases 1, 6 */
72609 err = vma_adjust(prev, prev->vm_start,
72610 next->vm_end, prev->vm_pgoff, NULL);
72611- } else /* cases 2, 5, 7 */
72612+
72613+#ifdef CONFIG_PAX_SEGMEXEC
72614+ if (!err && prev_m)
72615+ err = vma_adjust(prev_m, prev_m->vm_start,
72616+ next_m->vm_end, prev_m->vm_pgoff, NULL);
72617+#endif
72618+
72619+ } else { /* cases 2, 5, 7 */
72620 err = vma_adjust(prev, prev->vm_start,
72621 end, prev->vm_pgoff, NULL);
72622+
72623+#ifdef CONFIG_PAX_SEGMEXEC
72624+ if (!err && prev_m)
72625+ err = vma_adjust(prev_m, prev_m->vm_start,
72626+ end_m, prev_m->vm_pgoff, NULL);
72627+#endif
72628+
72629+ }
72630 if (err)
72631 return NULL;
72632 khugepaged_enter_vma_merge(prev);
72633@@ -837,12 +902,27 @@ struct vm_area_struct *vma_merge(struct
72634 mpol_equal(policy, vma_policy(next)) &&
72635 can_vma_merge_before(next, vm_flags,
72636 anon_vma, file, pgoff+pglen)) {
72637- if (prev && addr < prev->vm_end) /* case 4 */
72638+ if (prev && addr < prev->vm_end) { /* case 4 */
72639 err = vma_adjust(prev, prev->vm_start,
72640 addr, prev->vm_pgoff, NULL);
72641- else /* cases 3, 8 */
72642+
72643+#ifdef CONFIG_PAX_SEGMEXEC
72644+ if (!err && prev_m)
72645+ err = vma_adjust(prev_m, prev_m->vm_start,
72646+ addr_m, prev_m->vm_pgoff, NULL);
72647+#endif
72648+
72649+ } else { /* cases 3, 8 */
72650 err = vma_adjust(area, addr, next->vm_end,
72651 next->vm_pgoff - pglen, NULL);
72652+
72653+#ifdef CONFIG_PAX_SEGMEXEC
72654+ if (!err && area_m)
72655+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
72656+ next_m->vm_pgoff - pglen, NULL);
72657+#endif
72658+
72659+ }
72660 if (err)
72661 return NULL;
72662 khugepaged_enter_vma_merge(area);
72663@@ -958,14 +1038,11 @@ none:
72664 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
72665 struct file *file, long pages)
72666 {
72667- const unsigned long stack_flags
72668- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
72669-
72670 if (file) {
72671 mm->shared_vm += pages;
72672 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
72673 mm->exec_vm += pages;
72674- } else if (flags & stack_flags)
72675+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
72676 mm->stack_vm += pages;
72677 if (flags & (VM_RESERVED|VM_IO))
72678 mm->reserved_vm += pages;
72679@@ -992,7 +1069,7 @@ unsigned long do_mmap_pgoff(struct file
72680 * (the exception is when the underlying filesystem is noexec
72681 * mounted, in which case we dont add PROT_EXEC.)
72682 */
72683- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
72684+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
72685 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
72686 prot |= PROT_EXEC;
72687
72688@@ -1018,7 +1095,7 @@ unsigned long do_mmap_pgoff(struct file
72689 /* Obtain the address to map to. we verify (or select) it and ensure
72690 * that it represents a valid section of the address space.
72691 */
72692- addr = get_unmapped_area(file, addr, len, pgoff, flags);
72693+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
72694 if (addr & ~PAGE_MASK)
72695 return addr;
72696
72697@@ -1029,6 +1106,36 @@ unsigned long do_mmap_pgoff(struct file
72698 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
72699 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
72700
72701+#ifdef CONFIG_PAX_MPROTECT
72702+ if (mm->pax_flags & MF_PAX_MPROTECT) {
72703+#ifndef CONFIG_PAX_MPROTECT_COMPAT
72704+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
72705+ gr_log_rwxmmap(file);
72706+
72707+#ifdef CONFIG_PAX_EMUPLT
72708+ vm_flags &= ~VM_EXEC;
72709+#else
72710+ return -EPERM;
72711+#endif
72712+
72713+ }
72714+
72715+ if (!(vm_flags & VM_EXEC))
72716+ vm_flags &= ~VM_MAYEXEC;
72717+#else
72718+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
72719+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
72720+#endif
72721+ else
72722+ vm_flags &= ~VM_MAYWRITE;
72723+ }
72724+#endif
72725+
72726+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72727+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
72728+ vm_flags &= ~VM_PAGEEXEC;
72729+#endif
72730+
72731 if (flags & MAP_LOCKED)
72732 if (!can_do_mlock())
72733 return -EPERM;
72734@@ -1040,6 +1147,7 @@ unsigned long do_mmap_pgoff(struct file
72735 locked += mm->locked_vm;
72736 lock_limit = rlimit(RLIMIT_MEMLOCK);
72737 lock_limit >>= PAGE_SHIFT;
72738+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
72739 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
72740 return -EAGAIN;
72741 }
72742@@ -1110,6 +1218,9 @@ unsigned long do_mmap_pgoff(struct file
72743 if (error)
72744 return error;
72745
72746+ if (!gr_acl_handle_mmap(file, prot))
72747+ return -EACCES;
72748+
72749 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
72750 }
72751 EXPORT_SYMBOL(do_mmap_pgoff);
72752@@ -1187,10 +1298,10 @@ SYSCALL_DEFINE1(old_mmap, struct mmap_ar
72753 */
72754 int vma_wants_writenotify(struct vm_area_struct *vma)
72755 {
72756- unsigned int vm_flags = vma->vm_flags;
72757+ unsigned long vm_flags = vma->vm_flags;
72758
72759 /* If it was private or non-writable, the write bit is already clear */
72760- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
72761+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
72762 return 0;
72763
72764 /* The backer wishes to know when pages are first written to? */
72765@@ -1239,14 +1350,24 @@ unsigned long mmap_region(struct file *f
72766 unsigned long charged = 0;
72767 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
72768
72769+#ifdef CONFIG_PAX_SEGMEXEC
72770+ struct vm_area_struct *vma_m = NULL;
72771+#endif
72772+
72773+ /*
72774+ * mm->mmap_sem is required to protect against another thread
72775+ * changing the mappings in case we sleep.
72776+ */
72777+ verify_mm_writelocked(mm);
72778+
72779 /* Clear old maps */
72780 error = -ENOMEM;
72781-munmap_back:
72782 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72783 if (vma && vma->vm_start < addr + len) {
72784 if (do_munmap(mm, addr, len))
72785 return -ENOMEM;
72786- goto munmap_back;
72787+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72788+ BUG_ON(vma && vma->vm_start < addr + len);
72789 }
72790
72791 /* Check against address space limit. */
72792@@ -1295,6 +1416,16 @@ munmap_back:
72793 goto unacct_error;
72794 }
72795
72796+#ifdef CONFIG_PAX_SEGMEXEC
72797+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
72798+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72799+ if (!vma_m) {
72800+ error = -ENOMEM;
72801+ goto free_vma;
72802+ }
72803+ }
72804+#endif
72805+
72806 vma->vm_mm = mm;
72807 vma->vm_start = addr;
72808 vma->vm_end = addr + len;
72809@@ -1318,6 +1449,19 @@ munmap_back:
72810 error = file->f_op->mmap(file, vma);
72811 if (error)
72812 goto unmap_and_free_vma;
72813+
72814+#ifdef CONFIG_PAX_SEGMEXEC
72815+ if (vma_m && (vm_flags & VM_EXECUTABLE))
72816+ added_exe_file_vma(mm);
72817+#endif
72818+
72819+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72820+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
72821+ vma->vm_flags |= VM_PAGEEXEC;
72822+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
72823+ }
72824+#endif
72825+
72826 if (vm_flags & VM_EXECUTABLE)
72827 added_exe_file_vma(mm);
72828
72829@@ -1353,6 +1497,11 @@ munmap_back:
72830 vma_link(mm, vma, prev, rb_link, rb_parent);
72831 file = vma->vm_file;
72832
72833+#ifdef CONFIG_PAX_SEGMEXEC
72834+ if (vma_m)
72835+ BUG_ON(pax_mirror_vma(vma_m, vma));
72836+#endif
72837+
72838 /* Once vma denies write, undo our temporary denial count */
72839 if (correct_wcount)
72840 atomic_inc(&inode->i_writecount);
72841@@ -1361,6 +1510,7 @@ out:
72842
72843 mm->total_vm += len >> PAGE_SHIFT;
72844 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
72845+ track_exec_limit(mm, addr, addr + len, vm_flags);
72846 if (vm_flags & VM_LOCKED) {
72847 if (!mlock_vma_pages_range(vma, addr, addr + len))
72848 mm->locked_vm += (len >> PAGE_SHIFT);
72849@@ -1378,6 +1528,12 @@ unmap_and_free_vma:
72850 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
72851 charged = 0;
72852 free_vma:
72853+
72854+#ifdef CONFIG_PAX_SEGMEXEC
72855+ if (vma_m)
72856+ kmem_cache_free(vm_area_cachep, vma_m);
72857+#endif
72858+
72859 kmem_cache_free(vm_area_cachep, vma);
72860 unacct_error:
72861 if (charged)
72862@@ -1385,6 +1541,44 @@ unacct_error:
72863 return error;
72864 }
72865
72866+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
72867+{
72868+ if (!vma) {
72869+#ifdef CONFIG_STACK_GROWSUP
72870+ if (addr > sysctl_heap_stack_gap)
72871+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
72872+ else
72873+ vma = find_vma(current->mm, 0);
72874+ if (vma && (vma->vm_flags & VM_GROWSUP))
72875+ return false;
72876+#endif
72877+ return true;
72878+ }
72879+
72880+ if (addr + len > vma->vm_start)
72881+ return false;
72882+
72883+ if (vma->vm_flags & VM_GROWSDOWN)
72884+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
72885+#ifdef CONFIG_STACK_GROWSUP
72886+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
72887+ return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
72888+#endif
72889+
72890+ return true;
72891+}
72892+
72893+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
72894+{
72895+ if (vma->vm_start < len)
72896+ return -ENOMEM;
72897+ if (!(vma->vm_flags & VM_GROWSDOWN))
72898+ return vma->vm_start - len;
72899+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
72900+ return vma->vm_start - len - sysctl_heap_stack_gap;
72901+ return -ENOMEM;
72902+}
72903+
72904 /* Get an address range which is currently unmapped.
72905 * For shmat() with addr=0.
72906 *
72907@@ -1411,18 +1605,23 @@ arch_get_unmapped_area(struct file *filp
72908 if (flags & MAP_FIXED)
72909 return addr;
72910
72911+#ifdef CONFIG_PAX_RANDMMAP
72912+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
72913+#endif
72914+
72915 if (addr) {
72916 addr = PAGE_ALIGN(addr);
72917- vma = find_vma(mm, addr);
72918- if (TASK_SIZE - len >= addr &&
72919- (!vma || addr + len <= vma->vm_start))
72920- return addr;
72921+ if (TASK_SIZE - len >= addr) {
72922+ vma = find_vma(mm, addr);
72923+ if (check_heap_stack_gap(vma, addr, len))
72924+ return addr;
72925+ }
72926 }
72927 if (len > mm->cached_hole_size) {
72928- start_addr = addr = mm->free_area_cache;
72929+ start_addr = addr = mm->free_area_cache;
72930 } else {
72931- start_addr = addr = TASK_UNMAPPED_BASE;
72932- mm->cached_hole_size = 0;
72933+ start_addr = addr = mm->mmap_base;
72934+ mm->cached_hole_size = 0;
72935 }
72936
72937 full_search:
72938@@ -1433,34 +1632,40 @@ full_search:
72939 * Start a new search - just in case we missed
72940 * some holes.
72941 */
72942- if (start_addr != TASK_UNMAPPED_BASE) {
72943- addr = TASK_UNMAPPED_BASE;
72944- start_addr = addr;
72945+ if (start_addr != mm->mmap_base) {
72946+ start_addr = addr = mm->mmap_base;
72947 mm->cached_hole_size = 0;
72948 goto full_search;
72949 }
72950 return -ENOMEM;
72951 }
72952- if (!vma || addr + len <= vma->vm_start) {
72953- /*
72954- * Remember the place where we stopped the search:
72955- */
72956- mm->free_area_cache = addr + len;
72957- return addr;
72958- }
72959+ if (check_heap_stack_gap(vma, addr, len))
72960+ break;
72961 if (addr + mm->cached_hole_size < vma->vm_start)
72962 mm->cached_hole_size = vma->vm_start - addr;
72963 addr = vma->vm_end;
72964 }
72965+
72966+ /*
72967+ * Remember the place where we stopped the search:
72968+ */
72969+ mm->free_area_cache = addr + len;
72970+ return addr;
72971 }
72972 #endif
72973
72974 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
72975 {
72976+
72977+#ifdef CONFIG_PAX_SEGMEXEC
72978+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
72979+ return;
72980+#endif
72981+
72982 /*
72983 * Is this a new hole at the lowest possible address?
72984 */
72985- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache) {
72986+ if (addr >= mm->mmap_base && addr < mm->free_area_cache) {
72987 mm->free_area_cache = addr;
72988 mm->cached_hole_size = ~0UL;
72989 }
72990@@ -1478,7 +1683,7 @@ arch_get_unmapped_area_topdown(struct fi
72991 {
72992 struct vm_area_struct *vma;
72993 struct mm_struct *mm = current->mm;
72994- unsigned long addr = addr0;
72995+ unsigned long base = mm->mmap_base, addr = addr0;
72996
72997 /* requested length too big for entire address space */
72998 if (len > TASK_SIZE)
72999@@ -1487,13 +1692,18 @@ arch_get_unmapped_area_topdown(struct fi
73000 if (flags & MAP_FIXED)
73001 return addr;
73002
73003+#ifdef CONFIG_PAX_RANDMMAP
73004+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
73005+#endif
73006+
73007 /* requesting a specific address */
73008 if (addr) {
73009 addr = PAGE_ALIGN(addr);
73010- vma = find_vma(mm, addr);
73011- if (TASK_SIZE - len >= addr &&
73012- (!vma || addr + len <= vma->vm_start))
73013- return addr;
73014+ if (TASK_SIZE - len >= addr) {
73015+ vma = find_vma(mm, addr);
73016+ if (check_heap_stack_gap(vma, addr, len))
73017+ return addr;
73018+ }
73019 }
73020
73021 /* check if free_area_cache is useful for us */
73022@@ -1508,7 +1718,7 @@ arch_get_unmapped_area_topdown(struct fi
73023 /* make sure it can fit in the remaining address space */
73024 if (addr > len) {
73025 vma = find_vma(mm, addr-len);
73026- if (!vma || addr <= vma->vm_start)
73027+ if (check_heap_stack_gap(vma, addr - len, len))
73028 /* remember the address as a hint for next time */
73029 return (mm->free_area_cache = addr-len);
73030 }
73031@@ -1525,7 +1735,7 @@ arch_get_unmapped_area_topdown(struct fi
73032 * return with success:
73033 */
73034 vma = find_vma(mm, addr);
73035- if (!vma || addr+len <= vma->vm_start)
73036+ if (check_heap_stack_gap(vma, addr, len))
73037 /* remember the address as a hint for next time */
73038 return (mm->free_area_cache = addr);
73039
73040@@ -1534,8 +1744,8 @@ arch_get_unmapped_area_topdown(struct fi
73041 mm->cached_hole_size = vma->vm_start - addr;
73042
73043 /* try just below the current vma->vm_start */
73044- addr = vma->vm_start-len;
73045- } while (len < vma->vm_start);
73046+ addr = skip_heap_stack_gap(vma, len);
73047+ } while (!IS_ERR_VALUE(addr));
73048
73049 bottomup:
73050 /*
73051@@ -1544,13 +1754,21 @@ bottomup:
73052 * can happen with large stack limits and large mmap()
73053 * allocations.
73054 */
73055+ mm->mmap_base = TASK_UNMAPPED_BASE;
73056+
73057+#ifdef CONFIG_PAX_RANDMMAP
73058+ if (mm->pax_flags & MF_PAX_RANDMMAP)
73059+ mm->mmap_base += mm->delta_mmap;
73060+#endif
73061+
73062+ mm->free_area_cache = mm->mmap_base;
73063 mm->cached_hole_size = ~0UL;
73064- mm->free_area_cache = TASK_UNMAPPED_BASE;
73065 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
73066 /*
73067 * Restore the topdown base:
73068 */
73069- mm->free_area_cache = mm->mmap_base;
73070+ mm->mmap_base = base;
73071+ mm->free_area_cache = base;
73072 mm->cached_hole_size = ~0UL;
73073
73074 return addr;
73075@@ -1559,6 +1777,12 @@ bottomup:
73076
73077 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
73078 {
73079+
73080+#ifdef CONFIG_PAX_SEGMEXEC
73081+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
73082+ return;
73083+#endif
73084+
73085 /*
73086 * Is this a new hole at the highest possible address?
73087 */
73088@@ -1566,8 +1790,10 @@ void arch_unmap_area_topdown(struct mm_s
73089 mm->free_area_cache = addr;
73090
73091 /* dont allow allocations above current base */
73092- if (mm->free_area_cache > mm->mmap_base)
73093+ if (mm->free_area_cache > mm->mmap_base) {
73094 mm->free_area_cache = mm->mmap_base;
73095+ mm->cached_hole_size = ~0UL;
73096+ }
73097 }
73098
73099 unsigned long
73100@@ -1675,6 +1901,28 @@ out:
73101 return prev ? prev->vm_next : vma;
73102 }
73103
73104+#ifdef CONFIG_PAX_SEGMEXEC
73105+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
73106+{
73107+ struct vm_area_struct *vma_m;
73108+
73109+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
73110+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
73111+ BUG_ON(vma->vm_mirror);
73112+ return NULL;
73113+ }
73114+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
73115+ vma_m = vma->vm_mirror;
73116+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
73117+ BUG_ON(vma->vm_file != vma_m->vm_file);
73118+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
73119+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
73120+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
73121+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
73122+ return vma_m;
73123+}
73124+#endif
73125+
73126 /*
73127 * Verify that the stack growth is acceptable and
73128 * update accounting. This is shared with both the
73129@@ -1691,6 +1939,7 @@ static int acct_stack_growth(struct vm_a
73130 return -ENOMEM;
73131
73132 /* Stack limit test */
73133+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
73134 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
73135 return -ENOMEM;
73136
73137@@ -1701,6 +1950,7 @@ static int acct_stack_growth(struct vm_a
73138 locked = mm->locked_vm + grow;
73139 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
73140 limit >>= PAGE_SHIFT;
73141+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
73142 if (locked > limit && !capable(CAP_IPC_LOCK))
73143 return -ENOMEM;
73144 }
73145@@ -1731,37 +1981,48 @@ static int acct_stack_growth(struct vm_a
73146 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
73147 * vma is the last one with address > vma->vm_end. Have to extend vma.
73148 */
73149+#ifndef CONFIG_IA64
73150+static
73151+#endif
73152 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
73153 {
73154 int error;
73155+ bool locknext;
73156
73157 if (!(vma->vm_flags & VM_GROWSUP))
73158 return -EFAULT;
73159
73160+ /* Also guard against wrapping around to address 0. */
73161+ if (address < PAGE_ALIGN(address+1))
73162+ address = PAGE_ALIGN(address+1);
73163+ else
73164+ return -ENOMEM;
73165+
73166 /*
73167 * We must make sure the anon_vma is allocated
73168 * so that the anon_vma locking is not a noop.
73169 */
73170 if (unlikely(anon_vma_prepare(vma)))
73171 return -ENOMEM;
73172+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
73173+ if (locknext && anon_vma_prepare(vma->vm_next))
73174+ return -ENOMEM;
73175 vma_lock_anon_vma(vma);
73176+ if (locknext)
73177+ vma_lock_anon_vma(vma->vm_next);
73178
73179 /*
73180 * vma->vm_start/vm_end cannot change under us because the caller
73181 * is required to hold the mmap_sem in read mode. We need the
73182- * anon_vma lock to serialize against concurrent expand_stacks.
73183- * Also guard against wrapping around to address 0.
73184+ * anon_vma locks to serialize against concurrent expand_stacks
73185+ * and expand_upwards.
73186 */
73187- if (address < PAGE_ALIGN(address+4))
73188- address = PAGE_ALIGN(address+4);
73189- else {
73190- vma_unlock_anon_vma(vma);
73191- return -ENOMEM;
73192- }
73193 error = 0;
73194
73195 /* Somebody else might have raced and expanded it already */
73196- if (address > vma->vm_end) {
73197+ 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)
73198+ error = -ENOMEM;
73199+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
73200 unsigned long size, grow;
73201
73202 size = address - vma->vm_start;
73203@@ -1776,6 +2037,8 @@ int expand_upwards(struct vm_area_struct
73204 }
73205 }
73206 }
73207+ if (locknext)
73208+ vma_unlock_anon_vma(vma->vm_next);
73209 vma_unlock_anon_vma(vma);
73210 khugepaged_enter_vma_merge(vma);
73211 return error;
73212@@ -1789,6 +2052,8 @@ static int expand_downwards(struct vm_ar
73213 unsigned long address)
73214 {
73215 int error;
73216+ bool lockprev = false;
73217+ struct vm_area_struct *prev;
73218
73219 /*
73220 * We must make sure the anon_vma is allocated
73221@@ -1802,6 +2067,15 @@ static int expand_downwards(struct vm_ar
73222 if (error)
73223 return error;
73224
73225+ prev = vma->vm_prev;
73226+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
73227+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
73228+#endif
73229+ if (lockprev && anon_vma_prepare(prev))
73230+ return -ENOMEM;
73231+ if (lockprev)
73232+ vma_lock_anon_vma(prev);
73233+
73234 vma_lock_anon_vma(vma);
73235
73236 /*
73237@@ -1811,9 +2085,17 @@ static int expand_downwards(struct vm_ar
73238 */
73239
73240 /* Somebody else might have raced and expanded it already */
73241- if (address < vma->vm_start) {
73242+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
73243+ error = -ENOMEM;
73244+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
73245 unsigned long size, grow;
73246
73247+#ifdef CONFIG_PAX_SEGMEXEC
73248+ struct vm_area_struct *vma_m;
73249+
73250+ vma_m = pax_find_mirror_vma(vma);
73251+#endif
73252+
73253 size = vma->vm_end - address;
73254 grow = (vma->vm_start - address) >> PAGE_SHIFT;
73255
73256@@ -1823,11 +2105,22 @@ static int expand_downwards(struct vm_ar
73257 if (!error) {
73258 vma->vm_start = address;
73259 vma->vm_pgoff -= grow;
73260+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
73261+
73262+#ifdef CONFIG_PAX_SEGMEXEC
73263+ if (vma_m) {
73264+ vma_m->vm_start -= grow << PAGE_SHIFT;
73265+ vma_m->vm_pgoff -= grow;
73266+ }
73267+#endif
73268+
73269 perf_event_mmap(vma);
73270 }
73271 }
73272 }
73273 vma_unlock_anon_vma(vma);
73274+ if (lockprev)
73275+ vma_unlock_anon_vma(prev);
73276 khugepaged_enter_vma_merge(vma);
73277 return error;
73278 }
73279@@ -1902,6 +2195,13 @@ static void remove_vma_list(struct mm_st
73280 do {
73281 long nrpages = vma_pages(vma);
73282
73283+#ifdef CONFIG_PAX_SEGMEXEC
73284+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
73285+ vma = remove_vma(vma);
73286+ continue;
73287+ }
73288+#endif
73289+
73290 mm->total_vm -= nrpages;
73291 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
73292 vma = remove_vma(vma);
73293@@ -1947,6 +2247,16 @@ detach_vmas_to_be_unmapped(struct mm_str
73294 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
73295 vma->vm_prev = NULL;
73296 do {
73297+
73298+#ifdef CONFIG_PAX_SEGMEXEC
73299+ if (vma->vm_mirror) {
73300+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
73301+ vma->vm_mirror->vm_mirror = NULL;
73302+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
73303+ vma->vm_mirror = NULL;
73304+ }
73305+#endif
73306+
73307 rb_erase(&vma->vm_rb, &mm->mm_rb);
73308 mm->map_count--;
73309 tail_vma = vma;
73310@@ -1975,14 +2285,33 @@ static int __split_vma(struct mm_struct
73311 struct vm_area_struct *new;
73312 int err = -ENOMEM;
73313
73314+#ifdef CONFIG_PAX_SEGMEXEC
73315+ struct vm_area_struct *vma_m, *new_m = NULL;
73316+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
73317+#endif
73318+
73319 if (is_vm_hugetlb_page(vma) && (addr &
73320 ~(huge_page_mask(hstate_vma(vma)))))
73321 return -EINVAL;
73322
73323+#ifdef CONFIG_PAX_SEGMEXEC
73324+ vma_m = pax_find_mirror_vma(vma);
73325+#endif
73326+
73327 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73328 if (!new)
73329 goto out_err;
73330
73331+#ifdef CONFIG_PAX_SEGMEXEC
73332+ if (vma_m) {
73333+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73334+ if (!new_m) {
73335+ kmem_cache_free(vm_area_cachep, new);
73336+ goto out_err;
73337+ }
73338+ }
73339+#endif
73340+
73341 /* most fields are the same, copy all, and then fixup */
73342 *new = *vma;
73343
73344@@ -1995,6 +2324,22 @@ static int __split_vma(struct mm_struct
73345 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
73346 }
73347
73348+#ifdef CONFIG_PAX_SEGMEXEC
73349+ if (vma_m) {
73350+ *new_m = *vma_m;
73351+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
73352+ new_m->vm_mirror = new;
73353+ new->vm_mirror = new_m;
73354+
73355+ if (new_below)
73356+ new_m->vm_end = addr_m;
73357+ else {
73358+ new_m->vm_start = addr_m;
73359+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
73360+ }
73361+ }
73362+#endif
73363+
73364 pol = mpol_dup(vma_policy(vma));
73365 if (IS_ERR(pol)) {
73366 err = PTR_ERR(pol);
73367@@ -2020,6 +2365,42 @@ static int __split_vma(struct mm_struct
73368 else
73369 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
73370
73371+#ifdef CONFIG_PAX_SEGMEXEC
73372+ if (!err && vma_m) {
73373+ if (anon_vma_clone(new_m, vma_m))
73374+ goto out_free_mpol;
73375+
73376+ mpol_get(pol);
73377+ vma_set_policy(new_m, pol);
73378+
73379+ if (new_m->vm_file) {
73380+ get_file(new_m->vm_file);
73381+ if (vma_m->vm_flags & VM_EXECUTABLE)
73382+ added_exe_file_vma(mm);
73383+ }
73384+
73385+ if (new_m->vm_ops && new_m->vm_ops->open)
73386+ new_m->vm_ops->open(new_m);
73387+
73388+ if (new_below)
73389+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
73390+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
73391+ else
73392+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
73393+
73394+ if (err) {
73395+ if (new_m->vm_ops && new_m->vm_ops->close)
73396+ new_m->vm_ops->close(new_m);
73397+ if (new_m->vm_file) {
73398+ if (vma_m->vm_flags & VM_EXECUTABLE)
73399+ removed_exe_file_vma(mm);
73400+ fput(new_m->vm_file);
73401+ }
73402+ mpol_put(pol);
73403+ }
73404+ }
73405+#endif
73406+
73407 /* Success. */
73408 if (!err)
73409 return 0;
73410@@ -2032,10 +2413,18 @@ static int __split_vma(struct mm_struct
73411 removed_exe_file_vma(mm);
73412 fput(new->vm_file);
73413 }
73414- unlink_anon_vmas(new);
73415 out_free_mpol:
73416 mpol_put(pol);
73417 out_free_vma:
73418+
73419+#ifdef CONFIG_PAX_SEGMEXEC
73420+ if (new_m) {
73421+ unlink_anon_vmas(new_m);
73422+ kmem_cache_free(vm_area_cachep, new_m);
73423+ }
73424+#endif
73425+
73426+ unlink_anon_vmas(new);
73427 kmem_cache_free(vm_area_cachep, new);
73428 out_err:
73429 return err;
73430@@ -2048,6 +2437,15 @@ static int __split_vma(struct mm_struct
73431 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73432 unsigned long addr, int new_below)
73433 {
73434+
73435+#ifdef CONFIG_PAX_SEGMEXEC
73436+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
73437+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
73438+ if (mm->map_count >= sysctl_max_map_count-1)
73439+ return -ENOMEM;
73440+ } else
73441+#endif
73442+
73443 if (mm->map_count >= sysctl_max_map_count)
73444 return -ENOMEM;
73445
73446@@ -2059,11 +2457,30 @@ int split_vma(struct mm_struct *mm, stru
73447 * work. This now handles partial unmappings.
73448 * Jeremy Fitzhardinge <jeremy@goop.org>
73449 */
73450+#ifdef CONFIG_PAX_SEGMEXEC
73451+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73452+{
73453+ int ret = __do_munmap(mm, start, len);
73454+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
73455+ return ret;
73456+
73457+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
73458+}
73459+
73460+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73461+#else
73462 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73463+#endif
73464 {
73465 unsigned long end;
73466 struct vm_area_struct *vma, *prev, *last;
73467
73468+ /*
73469+ * mm->mmap_sem is required to protect against another thread
73470+ * changing the mappings in case we sleep.
73471+ */
73472+ verify_mm_writelocked(mm);
73473+
73474 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
73475 return -EINVAL;
73476
73477@@ -2137,6 +2554,8 @@ int do_munmap(struct mm_struct *mm, unsi
73478 /* Fix up all other VM information */
73479 remove_vma_list(mm, vma);
73480
73481+ track_exec_limit(mm, start, end, 0UL);
73482+
73483 return 0;
73484 }
73485
73486@@ -2149,22 +2568,18 @@ SYSCALL_DEFINE2(munmap, unsigned long, a
73487
73488 profile_munmap(addr);
73489
73490+#ifdef CONFIG_PAX_SEGMEXEC
73491+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
73492+ (len > SEGMEXEC_TASK_SIZE || addr > SEGMEXEC_TASK_SIZE-len))
73493+ return -EINVAL;
73494+#endif
73495+
73496 down_write(&mm->mmap_sem);
73497 ret = do_munmap(mm, addr, len);
73498 up_write(&mm->mmap_sem);
73499 return ret;
73500 }
73501
73502-static inline void verify_mm_writelocked(struct mm_struct *mm)
73503-{
73504-#ifdef CONFIG_DEBUG_VM
73505- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
73506- WARN_ON(1);
73507- up_read(&mm->mmap_sem);
73508- }
73509-#endif
73510-}
73511-
73512 /*
73513 * this is really a simplified "do_mmap". it only handles
73514 * anonymous maps. eventually we may be able to do some
73515@@ -2178,6 +2593,7 @@ unsigned long do_brk(unsigned long addr,
73516 struct rb_node ** rb_link, * rb_parent;
73517 pgoff_t pgoff = addr >> PAGE_SHIFT;
73518 int error;
73519+ unsigned long charged;
73520
73521 len = PAGE_ALIGN(len);
73522 if (!len)
73523@@ -2189,16 +2605,30 @@ unsigned long do_brk(unsigned long addr,
73524
73525 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
73526
73527+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
73528+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
73529+ flags &= ~VM_EXEC;
73530+
73531+#ifdef CONFIG_PAX_MPROTECT
73532+ if (mm->pax_flags & MF_PAX_MPROTECT)
73533+ flags &= ~VM_MAYEXEC;
73534+#endif
73535+
73536+ }
73537+#endif
73538+
73539 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
73540 if (error & ~PAGE_MASK)
73541 return error;
73542
73543+ charged = len >> PAGE_SHIFT;
73544+
73545 /*
73546 * mlock MCL_FUTURE?
73547 */
73548 if (mm->def_flags & VM_LOCKED) {
73549 unsigned long locked, lock_limit;
73550- locked = len >> PAGE_SHIFT;
73551+ locked = charged;
73552 locked += mm->locked_vm;
73553 lock_limit = rlimit(RLIMIT_MEMLOCK);
73554 lock_limit >>= PAGE_SHIFT;
73555@@ -2215,22 +2645,22 @@ unsigned long do_brk(unsigned long addr,
73556 /*
73557 * Clear old maps. this also does some error checking for us
73558 */
73559- munmap_back:
73560 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73561 if (vma && vma->vm_start < addr + len) {
73562 if (do_munmap(mm, addr, len))
73563 return -ENOMEM;
73564- goto munmap_back;
73565+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73566+ BUG_ON(vma && vma->vm_start < addr + len);
73567 }
73568
73569 /* Check against address space limits *after* clearing old maps... */
73570- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
73571+ if (!may_expand_vm(mm, charged))
73572 return -ENOMEM;
73573
73574 if (mm->map_count > sysctl_max_map_count)
73575 return -ENOMEM;
73576
73577- if (security_vm_enough_memory(len >> PAGE_SHIFT))
73578+ if (security_vm_enough_memory(charged))
73579 return -ENOMEM;
73580
73581 /* Can we just expand an old private anonymous mapping? */
73582@@ -2244,7 +2674,7 @@ unsigned long do_brk(unsigned long addr,
73583 */
73584 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73585 if (!vma) {
73586- vm_unacct_memory(len >> PAGE_SHIFT);
73587+ vm_unacct_memory(charged);
73588 return -ENOMEM;
73589 }
73590
73591@@ -2258,11 +2688,12 @@ unsigned long do_brk(unsigned long addr,
73592 vma_link(mm, vma, prev, rb_link, rb_parent);
73593 out:
73594 perf_event_mmap(vma);
73595- mm->total_vm += len >> PAGE_SHIFT;
73596+ mm->total_vm += charged;
73597 if (flags & VM_LOCKED) {
73598 if (!mlock_vma_pages_range(vma, addr, addr + len))
73599- mm->locked_vm += (len >> PAGE_SHIFT);
73600+ mm->locked_vm += charged;
73601 }
73602+ track_exec_limit(mm, addr, addr + len, flags);
73603 return addr;
73604 }
73605
73606@@ -2309,8 +2740,10 @@ void exit_mmap(struct mm_struct *mm)
73607 * Walk the list again, actually closing and freeing it,
73608 * with preemption enabled, without holding any MM locks.
73609 */
73610- while (vma)
73611+ while (vma) {
73612+ vma->vm_mirror = NULL;
73613 vma = remove_vma(vma);
73614+ }
73615
73616 BUG_ON(mm->nr_ptes > (FIRST_USER_ADDRESS+PMD_SIZE-1)>>PMD_SHIFT);
73617 }
73618@@ -2324,6 +2757,13 @@ int insert_vm_struct(struct mm_struct *
73619 struct vm_area_struct * __vma, * prev;
73620 struct rb_node ** rb_link, * rb_parent;
73621
73622+#ifdef CONFIG_PAX_SEGMEXEC
73623+ struct vm_area_struct *vma_m = NULL;
73624+#endif
73625+
73626+ if (security_file_mmap(NULL, 0, 0, 0, vma->vm_start, 1))
73627+ return -EPERM;
73628+
73629 /*
73630 * The vm_pgoff of a purely anonymous vma should be irrelevant
73631 * until its first write fault, when page's anon_vma and index
73632@@ -2346,7 +2786,22 @@ int insert_vm_struct(struct mm_struct *
73633 if ((vma->vm_flags & VM_ACCOUNT) &&
73634 security_vm_enough_memory_mm(mm, vma_pages(vma)))
73635 return -ENOMEM;
73636+
73637+#ifdef CONFIG_PAX_SEGMEXEC
73638+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
73639+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73640+ if (!vma_m)
73641+ return -ENOMEM;
73642+ }
73643+#endif
73644+
73645 vma_link(mm, vma, prev, rb_link, rb_parent);
73646+
73647+#ifdef CONFIG_PAX_SEGMEXEC
73648+ if (vma_m)
73649+ BUG_ON(pax_mirror_vma(vma_m, vma));
73650+#endif
73651+
73652 return 0;
73653 }
73654
73655@@ -2364,6 +2819,8 @@ struct vm_area_struct *copy_vma(struct v
73656 struct rb_node **rb_link, *rb_parent;
73657 struct mempolicy *pol;
73658
73659+ BUG_ON(vma->vm_mirror);
73660+
73661 /*
73662 * If anonymous vma has not yet been faulted, update new pgoff
73663 * to match new location, to increase its chance of merging.
73664@@ -2413,6 +2870,39 @@ struct vm_area_struct *copy_vma(struct v
73665 kmem_cache_free(vm_area_cachep, new_vma);
73666 return NULL;
73667 }
73668+
73669+#ifdef CONFIG_PAX_SEGMEXEC
73670+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
73671+{
73672+ struct vm_area_struct *prev_m;
73673+ struct rb_node **rb_link_m, *rb_parent_m;
73674+ struct mempolicy *pol_m;
73675+
73676+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
73677+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
73678+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
73679+ *vma_m = *vma;
73680+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
73681+ if (anon_vma_clone(vma_m, vma))
73682+ return -ENOMEM;
73683+ pol_m = vma_policy(vma_m);
73684+ mpol_get(pol_m);
73685+ vma_set_policy(vma_m, pol_m);
73686+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
73687+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
73688+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
73689+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
73690+ if (vma_m->vm_file)
73691+ get_file(vma_m->vm_file);
73692+ if (vma_m->vm_ops && vma_m->vm_ops->open)
73693+ vma_m->vm_ops->open(vma_m);
73694+ find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
73695+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
73696+ vma_m->vm_mirror = vma;
73697+ vma->vm_mirror = vma_m;
73698+ return 0;
73699+}
73700+#endif
73701
73702 /*
73703 * Return true if the calling process may expand its vm space by the passed
73704@@ -2424,7 +2914,7 @@ int may_expand_vm(struct mm_struct *mm,
73705 unsigned long lim;
73706
73707 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
73708-
73709+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
73710 if (cur + npages > lim)
73711 return 0;
73712 return 1;
73713@@ -2495,6 +2985,22 @@ int install_special_mapping(struct mm_st
73714 vma->vm_start = addr;
73715 vma->vm_end = addr + len;
73716
73717+#ifdef CONFIG_PAX_MPROTECT
73718+ if (mm->pax_flags & MF_PAX_MPROTECT) {
73719+#ifndef CONFIG_PAX_MPROTECT_COMPAT
73720+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
73721+ return -EPERM;
73722+ if (!(vm_flags & VM_EXEC))
73723+ vm_flags &= ~VM_MAYEXEC;
73724+#else
73725+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
73726+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
73727+#endif
73728+ else
73729+ vm_flags &= ~VM_MAYWRITE;
73730+ }
73731+#endif
73732+
73733 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
73734 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
73735
73736diff -urNp linux-2.6.39.1/mm/mprotect.c linux-2.6.39.1/mm/mprotect.c
73737--- linux-2.6.39.1/mm/mprotect.c 2011-05-19 00:06:34.000000000 -0400
73738+++ linux-2.6.39.1/mm/mprotect.c 2011-05-22 19:41:42.000000000 -0400
73739@@ -23,10 +23,16 @@
73740 #include <linux/mmu_notifier.h>
73741 #include <linux/migrate.h>
73742 #include <linux/perf_event.h>
73743+
73744+#ifdef CONFIG_PAX_MPROTECT
73745+#include <linux/elf.h>
73746+#endif
73747+
73748 #include <asm/uaccess.h>
73749 #include <asm/pgtable.h>
73750 #include <asm/cacheflush.h>
73751 #include <asm/tlbflush.h>
73752+#include <asm/mmu_context.h>
73753
73754 #ifndef pgprot_modify
73755 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
73756@@ -141,6 +147,48 @@ static void change_protection(struct vm_
73757 flush_tlb_range(vma, start, end);
73758 }
73759
73760+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
73761+/* called while holding the mmap semaphor for writing except stack expansion */
73762+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
73763+{
73764+ unsigned long oldlimit, newlimit = 0UL;
73765+
73766+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
73767+ return;
73768+
73769+ spin_lock(&mm->page_table_lock);
73770+ oldlimit = mm->context.user_cs_limit;
73771+ if ((prot & VM_EXEC) && oldlimit < end)
73772+ /* USER_CS limit moved up */
73773+ newlimit = end;
73774+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
73775+ /* USER_CS limit moved down */
73776+ newlimit = start;
73777+
73778+ if (newlimit) {
73779+ mm->context.user_cs_limit = newlimit;
73780+
73781+#ifdef CONFIG_SMP
73782+ wmb();
73783+ cpus_clear(mm->context.cpu_user_cs_mask);
73784+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
73785+#endif
73786+
73787+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
73788+ }
73789+ spin_unlock(&mm->page_table_lock);
73790+ if (newlimit == end) {
73791+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
73792+
73793+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
73794+ if (is_vm_hugetlb_page(vma))
73795+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
73796+ else
73797+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
73798+ }
73799+}
73800+#endif
73801+
73802 int
73803 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73804 unsigned long start, unsigned long end, unsigned long newflags)
73805@@ -153,11 +201,29 @@ mprotect_fixup(struct vm_area_struct *vm
73806 int error;
73807 int dirty_accountable = 0;
73808
73809+#ifdef CONFIG_PAX_SEGMEXEC
73810+ struct vm_area_struct *vma_m = NULL;
73811+ unsigned long start_m, end_m;
73812+
73813+ start_m = start + SEGMEXEC_TASK_SIZE;
73814+ end_m = end + SEGMEXEC_TASK_SIZE;
73815+#endif
73816+
73817 if (newflags == oldflags) {
73818 *pprev = vma;
73819 return 0;
73820 }
73821
73822+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
73823+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
73824+
73825+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
73826+ return -ENOMEM;
73827+
73828+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
73829+ return -ENOMEM;
73830+ }
73831+
73832 /*
73833 * If we make a private mapping writable we increase our commit;
73834 * but (without finer accounting) cannot reduce our commit if we
73835@@ -174,6 +240,42 @@ mprotect_fixup(struct vm_area_struct *vm
73836 }
73837 }
73838
73839+#ifdef CONFIG_PAX_SEGMEXEC
73840+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
73841+ if (start != vma->vm_start) {
73842+ error = split_vma(mm, vma, start, 1);
73843+ if (error)
73844+ goto fail;
73845+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
73846+ *pprev = (*pprev)->vm_next;
73847+ }
73848+
73849+ if (end != vma->vm_end) {
73850+ error = split_vma(mm, vma, end, 0);
73851+ if (error)
73852+ goto fail;
73853+ }
73854+
73855+ if (pax_find_mirror_vma(vma)) {
73856+ error = __do_munmap(mm, start_m, end_m - start_m);
73857+ if (error)
73858+ goto fail;
73859+ } else {
73860+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73861+ if (!vma_m) {
73862+ error = -ENOMEM;
73863+ goto fail;
73864+ }
73865+ vma->vm_flags = newflags;
73866+ error = pax_mirror_vma(vma_m, vma);
73867+ if (error) {
73868+ vma->vm_flags = oldflags;
73869+ goto fail;
73870+ }
73871+ }
73872+ }
73873+#endif
73874+
73875 /*
73876 * First try to merge with previous and/or next vma.
73877 */
73878@@ -204,9 +306,21 @@ success:
73879 * vm_flags and vm_page_prot are protected by the mmap_sem
73880 * held in write mode.
73881 */
73882+
73883+#ifdef CONFIG_PAX_SEGMEXEC
73884+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
73885+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
73886+#endif
73887+
73888 vma->vm_flags = newflags;
73889+
73890+#ifdef CONFIG_PAX_MPROTECT
73891+ if (mm->binfmt && mm->binfmt->handle_mprotect)
73892+ mm->binfmt->handle_mprotect(vma, newflags);
73893+#endif
73894+
73895 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
73896- vm_get_page_prot(newflags));
73897+ vm_get_page_prot(vma->vm_flags));
73898
73899 if (vma_wants_writenotify(vma)) {
73900 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
73901@@ -248,6 +362,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
73902 end = start + len;
73903 if (end <= start)
73904 return -ENOMEM;
73905+
73906+#ifdef CONFIG_PAX_SEGMEXEC
73907+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
73908+ if (end > SEGMEXEC_TASK_SIZE)
73909+ return -EINVAL;
73910+ } else
73911+#endif
73912+
73913+ if (end > TASK_SIZE)
73914+ return -EINVAL;
73915+
73916 if (!arch_validate_prot(prot))
73917 return -EINVAL;
73918
73919@@ -255,7 +380,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
73920 /*
73921 * Does the application expect PROT_READ to imply PROT_EXEC:
73922 */
73923- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
73924+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
73925 prot |= PROT_EXEC;
73926
73927 vm_flags = calc_vm_prot_bits(prot);
73928@@ -287,6 +412,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
73929 if (start > vma->vm_start)
73930 prev = vma;
73931
73932+#ifdef CONFIG_PAX_MPROTECT
73933+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
73934+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
73935+#endif
73936+
73937 for (nstart = start ; ; ) {
73938 unsigned long newflags;
73939
73940@@ -296,6 +426,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
73941
73942 /* newflags >> 4 shift VM_MAY% in place of VM_% */
73943 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
73944+ if (prot & (PROT_WRITE | PROT_EXEC))
73945+ gr_log_rwxmprotect(vma->vm_file);
73946+
73947+ error = -EACCES;
73948+ goto out;
73949+ }
73950+
73951+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
73952 error = -EACCES;
73953 goto out;
73954 }
73955@@ -310,6 +448,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
73956 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
73957 if (error)
73958 goto out;
73959+
73960+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
73961+
73962 nstart = tmp;
73963
73964 if (nstart < prev->vm_end)
73965diff -urNp linux-2.6.39.1/mm/mremap.c linux-2.6.39.1/mm/mremap.c
73966--- linux-2.6.39.1/mm/mremap.c 2011-05-19 00:06:34.000000000 -0400
73967+++ linux-2.6.39.1/mm/mremap.c 2011-05-22 19:36:33.000000000 -0400
73968@@ -114,6 +114,12 @@ static void move_ptes(struct vm_area_str
73969 continue;
73970 pte = ptep_clear_flush(vma, old_addr, old_pte);
73971 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
73972+
73973+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
73974+ if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
73975+ pte = pte_exprotect(pte);
73976+#endif
73977+
73978 set_pte_at(mm, new_addr, new_pte, pte);
73979 }
73980
73981@@ -273,6 +279,11 @@ static struct vm_area_struct *vma_to_res
73982 if (is_vm_hugetlb_page(vma))
73983 goto Einval;
73984
73985+#ifdef CONFIG_PAX_SEGMEXEC
73986+ if (pax_find_mirror_vma(vma))
73987+ goto Einval;
73988+#endif
73989+
73990 /* We can't remap across vm area boundaries */
73991 if (old_len > vma->vm_end - addr)
73992 goto Efault;
73993@@ -329,20 +340,25 @@ static unsigned long mremap_to(unsigned
73994 unsigned long ret = -EINVAL;
73995 unsigned long charged = 0;
73996 unsigned long map_flags;
73997+ unsigned long pax_task_size = TASK_SIZE;
73998
73999 if (new_addr & ~PAGE_MASK)
74000 goto out;
74001
74002- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
74003+#ifdef CONFIG_PAX_SEGMEXEC
74004+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
74005+ pax_task_size = SEGMEXEC_TASK_SIZE;
74006+#endif
74007+
74008+ pax_task_size -= PAGE_SIZE;
74009+
74010+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
74011 goto out;
74012
74013 /* Check if the location we're moving into overlaps the
74014 * old location at all, and fail if it does.
74015 */
74016- if ((new_addr <= addr) && (new_addr+new_len) > addr)
74017- goto out;
74018-
74019- if ((addr <= new_addr) && (addr+old_len) > new_addr)
74020+ if (addr + old_len > new_addr && new_addr + new_len > addr)
74021 goto out;
74022
74023 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
74024@@ -414,6 +430,7 @@ unsigned long do_mremap(unsigned long ad
74025 struct vm_area_struct *vma;
74026 unsigned long ret = -EINVAL;
74027 unsigned long charged = 0;
74028+ unsigned long pax_task_size = TASK_SIZE;
74029
74030 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
74031 goto out;
74032@@ -432,6 +449,17 @@ unsigned long do_mremap(unsigned long ad
74033 if (!new_len)
74034 goto out;
74035
74036+#ifdef CONFIG_PAX_SEGMEXEC
74037+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
74038+ pax_task_size = SEGMEXEC_TASK_SIZE;
74039+#endif
74040+
74041+ pax_task_size -= PAGE_SIZE;
74042+
74043+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
74044+ old_len > pax_task_size || addr > pax_task_size-old_len)
74045+ goto out;
74046+
74047 if (flags & MREMAP_FIXED) {
74048 if (flags & MREMAP_MAYMOVE)
74049 ret = mremap_to(addr, old_len, new_addr, new_len);
74050@@ -481,6 +509,7 @@ unsigned long do_mremap(unsigned long ad
74051 addr + new_len);
74052 }
74053 ret = addr;
74054+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
74055 goto out;
74056 }
74057 }
74058@@ -507,7 +536,13 @@ unsigned long do_mremap(unsigned long ad
74059 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
74060 if (ret)
74061 goto out;
74062+
74063+ map_flags = vma->vm_flags;
74064 ret = move_vma(vma, addr, old_len, new_len, new_addr);
74065+ if (!(ret & ~PAGE_MASK)) {
74066+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
74067+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
74068+ }
74069 }
74070 out:
74071 if (ret & ~PAGE_MASK)
74072diff -urNp linux-2.6.39.1/mm/nobootmem.c linux-2.6.39.1/mm/nobootmem.c
74073--- linux-2.6.39.1/mm/nobootmem.c 2011-05-19 00:06:34.000000000 -0400
74074+++ linux-2.6.39.1/mm/nobootmem.c 2011-05-22 19:36:33.000000000 -0400
74075@@ -110,19 +110,30 @@ static void __init __free_pages_memory(u
74076 unsigned long __init free_all_memory_core_early(int nodeid)
74077 {
74078 int i;
74079- u64 start, end;
74080+ u64 start, end, startrange, endrange;
74081 unsigned long count = 0;
74082- struct range *range = NULL;
74083+ struct range *range = NULL, rangerange = { 0, 0 };
74084 int nr_range;
74085
74086 nr_range = get_free_all_memory_range(&range, nodeid);
74087+ startrange = __pa(range) >> PAGE_SHIFT;
74088+ endrange = (__pa(range + nr_range) - 1) >> PAGE_SHIFT;
74089
74090 for (i = 0; i < nr_range; i++) {
74091 start = range[i].start;
74092 end = range[i].end;
74093+ if (start <= endrange && startrange < end) {
74094+ BUG_ON(rangerange.start | rangerange.end);
74095+ rangerange = range[i];
74096+ continue;
74097+ }
74098 count += end - start;
74099 __free_pages_memory(start, end);
74100 }
74101+ start = rangerange.start;
74102+ end = rangerange.end;
74103+ count += end - start;
74104+ __free_pages_memory(start, end);
74105
74106 return count;
74107 }
74108diff -urNp linux-2.6.39.1/mm/nommu.c linux-2.6.39.1/mm/nommu.c
74109--- linux-2.6.39.1/mm/nommu.c 2011-05-19 00:06:34.000000000 -0400
74110+++ linux-2.6.39.1/mm/nommu.c 2011-05-22 19:36:33.000000000 -0400
74111@@ -63,7 +63,6 @@ int sysctl_overcommit_memory = OVERCOMMI
74112 int sysctl_overcommit_ratio = 50; /* default is 50% */
74113 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
74114 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
74115-int heap_stack_gap = 0;
74116
74117 atomic_long_t mmap_pages_allocated;
74118
74119@@ -833,15 +832,6 @@ struct vm_area_struct *find_vma(struct m
74120 EXPORT_SYMBOL(find_vma);
74121
74122 /*
74123- * find a VMA
74124- * - we don't extend stack VMAs under NOMMU conditions
74125- */
74126-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
74127-{
74128- return find_vma(mm, addr);
74129-}
74130-
74131-/*
74132 * expand a stack to a given address
74133 * - not supported under NOMMU conditions
74134 */
74135@@ -1563,6 +1553,7 @@ int split_vma(struct mm_struct *mm, stru
74136
74137 /* most fields are the same, copy all, and then fixup */
74138 *new = *vma;
74139+ INIT_LIST_HEAD(&new->anon_vma_chain);
74140 *region = *vma->vm_region;
74141 new->vm_region = region;
74142
74143diff -urNp linux-2.6.39.1/mm/page_alloc.c linux-2.6.39.1/mm/page_alloc.c
74144--- linux-2.6.39.1/mm/page_alloc.c 2011-06-03 00:04:14.000000000 -0400
74145+++ linux-2.6.39.1/mm/page_alloc.c 2011-06-03 00:32:08.000000000 -0400
74146@@ -650,6 +650,10 @@ static bool free_pages_prepare(struct pa
74147 int i;
74148 int bad = 0;
74149
74150+#ifdef CONFIG_PAX_MEMORY_SANITIZE
74151+ unsigned long index = 1UL << order;
74152+#endif
74153+
74154 trace_mm_page_free_direct(page, order);
74155 kmemcheck_free_shadow(page, order);
74156
74157@@ -665,6 +669,12 @@ static bool free_pages_prepare(struct pa
74158 debug_check_no_obj_freed(page_address(page),
74159 PAGE_SIZE << order);
74160 }
74161+
74162+#ifdef CONFIG_PAX_MEMORY_SANITIZE
74163+ for (; index; --index)
74164+ sanitize_highpage(page + index - 1);
74165+#endif
74166+
74167 arch_free_page(page, order);
74168 kernel_map_pages(page, 1 << order, 0);
74169
74170@@ -780,8 +790,10 @@ static int prep_new_page(struct page *pa
74171 arch_alloc_page(page, order);
74172 kernel_map_pages(page, 1 << order, 1);
74173
74174+#ifndef CONFIG_PAX_MEMORY_SANITIZE
74175 if (gfp_flags & __GFP_ZERO)
74176 prep_zero_page(page, order, gfp_flags);
74177+#endif
74178
74179 if (order && (gfp_flags & __GFP_COMP))
74180 prep_compound_page(page, order);
74181@@ -2504,6 +2516,8 @@ void __show_free_areas(unsigned int filt
74182 int cpu;
74183 struct zone *zone;
74184
74185+ pax_track_stack();
74186+
74187 for_each_populated_zone(zone) {
74188 if (skip_free_areas_zone(filter, zone))
74189 continue;
74190diff -urNp linux-2.6.39.1/mm/percpu.c linux-2.6.39.1/mm/percpu.c
74191--- linux-2.6.39.1/mm/percpu.c 2011-05-19 00:06:34.000000000 -0400
74192+++ linux-2.6.39.1/mm/percpu.c 2011-05-22 19:36:33.000000000 -0400
74193@@ -121,7 +121,7 @@ static unsigned int pcpu_first_unit_cpu
74194 static unsigned int pcpu_last_unit_cpu __read_mostly;
74195
74196 /* the address of the first chunk which starts with the kernel static area */
74197-void *pcpu_base_addr __read_mostly;
74198+void *pcpu_base_addr __read_only;
74199 EXPORT_SYMBOL_GPL(pcpu_base_addr);
74200
74201 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
74202diff -urNp linux-2.6.39.1/mm/rmap.c linux-2.6.39.1/mm/rmap.c
74203--- linux-2.6.39.1/mm/rmap.c 2011-05-19 00:06:34.000000000 -0400
74204+++ linux-2.6.39.1/mm/rmap.c 2011-05-22 19:36:33.000000000 -0400
74205@@ -131,6 +131,10 @@ int anon_vma_prepare(struct vm_area_stru
74206 struct anon_vma *anon_vma = vma->anon_vma;
74207 struct anon_vma_chain *avc;
74208
74209+#ifdef CONFIG_PAX_SEGMEXEC
74210+ struct anon_vma_chain *avc_m = NULL;
74211+#endif
74212+
74213 might_sleep();
74214 if (unlikely(!anon_vma)) {
74215 struct mm_struct *mm = vma->vm_mm;
74216@@ -140,6 +144,12 @@ int anon_vma_prepare(struct vm_area_stru
74217 if (!avc)
74218 goto out_enomem;
74219
74220+#ifdef CONFIG_PAX_SEGMEXEC
74221+ avc_m = anon_vma_chain_alloc();
74222+ if (!avc_m)
74223+ goto out_enomem_free_avc;
74224+#endif
74225+
74226 anon_vma = find_mergeable_anon_vma(vma);
74227 allocated = NULL;
74228 if (!anon_vma) {
74229@@ -153,6 +163,21 @@ int anon_vma_prepare(struct vm_area_stru
74230 /* page_table_lock to protect against threads */
74231 spin_lock(&mm->page_table_lock);
74232 if (likely(!vma->anon_vma)) {
74233+
74234+#ifdef CONFIG_PAX_SEGMEXEC
74235+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
74236+
74237+ if (vma_m) {
74238+ BUG_ON(vma_m->anon_vma);
74239+ vma_m->anon_vma = anon_vma;
74240+ avc_m->anon_vma = anon_vma;
74241+ avc_m->vma = vma;
74242+ list_add(&avc_m->same_vma, &vma_m->anon_vma_chain);
74243+ list_add(&avc_m->same_anon_vma, &anon_vma->head);
74244+ avc_m = NULL;
74245+ }
74246+#endif
74247+
74248 vma->anon_vma = anon_vma;
74249 avc->anon_vma = anon_vma;
74250 avc->vma = vma;
74251@@ -166,12 +191,24 @@ int anon_vma_prepare(struct vm_area_stru
74252
74253 if (unlikely(allocated))
74254 put_anon_vma(allocated);
74255+
74256+#ifdef CONFIG_PAX_SEGMEXEC
74257+ if (unlikely(avc_m))
74258+ anon_vma_chain_free(avc_m);
74259+#endif
74260+
74261 if (unlikely(avc))
74262 anon_vma_chain_free(avc);
74263 }
74264 return 0;
74265
74266 out_enomem_free_avc:
74267+
74268+#ifdef CONFIG_PAX_SEGMEXEC
74269+ if (avc_m)
74270+ anon_vma_chain_free(avc_m);
74271+#endif
74272+
74273 anon_vma_chain_free(avc);
74274 out_enomem:
74275 return -ENOMEM;
74276@@ -198,7 +235,7 @@ static void anon_vma_chain_link(struct v
74277 * Attach the anon_vmas from src to dst.
74278 * Returns 0 on success, -ENOMEM on failure.
74279 */
74280-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
74281+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
74282 {
74283 struct anon_vma_chain *avc, *pavc;
74284
74285@@ -220,7 +257,7 @@ int anon_vma_clone(struct vm_area_struct
74286 * the corresponding VMA in the parent process is attached to.
74287 * Returns 0 on success, non-zero on failure.
74288 */
74289-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
74290+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
74291 {
74292 struct anon_vma_chain *avc;
74293 struct anon_vma *anon_vma;
74294diff -urNp linux-2.6.39.1/mm/shmem.c linux-2.6.39.1/mm/shmem.c
74295--- linux-2.6.39.1/mm/shmem.c 2011-06-03 00:04:14.000000000 -0400
74296+++ linux-2.6.39.1/mm/shmem.c 2011-06-03 00:32:08.000000000 -0400
74297@@ -31,7 +31,7 @@
74298 #include <linux/percpu_counter.h>
74299 #include <linux/swap.h>
74300
74301-static struct vfsmount *shm_mnt;
74302+struct vfsmount *shm_mnt;
74303
74304 #ifdef CONFIG_SHMEM
74305 /*
74306@@ -1087,6 +1087,8 @@ static int shmem_writepage(struct page *
74307 goto unlock;
74308 }
74309 entry = shmem_swp_entry(info, index, NULL);
74310+ if (!entry)
74311+ goto unlock;
74312 if (entry->val) {
74313 /*
74314 * The more uptodate page coming down from a stacked
74315@@ -1158,6 +1160,8 @@ static struct page *shmem_swapin(swp_ent
74316 struct vm_area_struct pvma;
74317 struct page *page;
74318
74319+ pax_track_stack();
74320+
74321 spol = mpol_cond_copy(&mpol,
74322 mpol_shared_policy_lookup(&info->policy, idx));
74323
74324@@ -2014,7 +2018,7 @@ static int shmem_symlink(struct inode *d
74325
74326 info = SHMEM_I(inode);
74327 inode->i_size = len-1;
74328- if (len <= (char *)inode - (char *)info) {
74329+ if (len <= (char *)inode - (char *)info && len <= 64) {
74330 /* do it inline */
74331 memcpy(info, symname, len);
74332 inode->i_op = &shmem_symlink_inline_operations;
74333@@ -2362,8 +2366,7 @@ int shmem_fill_super(struct super_block
74334 int err = -ENOMEM;
74335
74336 /* Round up to L1_CACHE_BYTES to resist false sharing */
74337- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
74338- L1_CACHE_BYTES), GFP_KERNEL);
74339+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
74340 if (!sbinfo)
74341 return -ENOMEM;
74342
74343diff -urNp linux-2.6.39.1/mm/slab.c linux-2.6.39.1/mm/slab.c
74344--- linux-2.6.39.1/mm/slab.c 2011-05-19 00:06:34.000000000 -0400
74345+++ linux-2.6.39.1/mm/slab.c 2011-05-22 19:41:42.000000000 -0400
74346@@ -150,7 +150,7 @@
74347
74348 /* Legal flag mask for kmem_cache_create(). */
74349 #if DEBUG
74350-# define CREATE_MASK (SLAB_RED_ZONE | \
74351+# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
74352 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
74353 SLAB_CACHE_DMA | \
74354 SLAB_STORE_USER | \
74355@@ -158,7 +158,7 @@
74356 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
74357 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
74358 #else
74359-# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
74360+# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
74361 SLAB_CACHE_DMA | \
74362 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
74363 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
74364@@ -287,7 +287,7 @@ struct kmem_list3 {
74365 * Need this for bootstrapping a per node allocator.
74366 */
74367 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
74368-static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
74369+static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
74370 #define CACHE_CACHE 0
74371 #define SIZE_AC MAX_NUMNODES
74372 #define SIZE_L3 (2 * MAX_NUMNODES)
74373@@ -388,10 +388,10 @@ static void kmem_list3_init(struct kmem_
74374 if ((x)->max_freeable < i) \
74375 (x)->max_freeable = i; \
74376 } while (0)
74377-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
74378-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
74379-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
74380-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
74381+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
74382+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
74383+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
74384+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
74385 #else
74386 #define STATS_INC_ACTIVE(x) do { } while (0)
74387 #define STATS_DEC_ACTIVE(x) do { } while (0)
74388@@ -537,7 +537,7 @@ static inline void *index_to_obj(struct
74389 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
74390 */
74391 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
74392- const struct slab *slab, void *obj)
74393+ const struct slab *slab, const void *obj)
74394 {
74395 u32 offset = (obj - slab->s_mem);
74396 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
74397@@ -563,7 +563,7 @@ struct cache_names {
74398 static struct cache_names __initdata cache_names[] = {
74399 #define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
74400 #include <linux/kmalloc_sizes.h>
74401- {NULL,}
74402+ {NULL}
74403 #undef CACHE
74404 };
74405
74406@@ -1529,7 +1529,7 @@ void __init kmem_cache_init(void)
74407 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
74408 sizes[INDEX_AC].cs_size,
74409 ARCH_KMALLOC_MINALIGN,
74410- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74411+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74412 NULL);
74413
74414 if (INDEX_AC != INDEX_L3) {
74415@@ -1537,7 +1537,7 @@ void __init kmem_cache_init(void)
74416 kmem_cache_create(names[INDEX_L3].name,
74417 sizes[INDEX_L3].cs_size,
74418 ARCH_KMALLOC_MINALIGN,
74419- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74420+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74421 NULL);
74422 }
74423
74424@@ -1555,7 +1555,7 @@ void __init kmem_cache_init(void)
74425 sizes->cs_cachep = kmem_cache_create(names->name,
74426 sizes->cs_size,
74427 ARCH_KMALLOC_MINALIGN,
74428- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74429+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74430 NULL);
74431 }
74432 #ifdef CONFIG_ZONE_DMA
74433@@ -4270,10 +4270,10 @@ static int s_show(struct seq_file *m, vo
74434 }
74435 /* cpu stats */
74436 {
74437- unsigned long allochit = atomic_read(&cachep->allochit);
74438- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
74439- unsigned long freehit = atomic_read(&cachep->freehit);
74440- unsigned long freemiss = atomic_read(&cachep->freemiss);
74441+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
74442+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
74443+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
74444+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
74445
74446 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
74447 allochit, allocmiss, freehit, freemiss);
74448@@ -4530,15 +4530,66 @@ static const struct file_operations proc
74449
74450 static int __init slab_proc_init(void)
74451 {
74452- proc_create("slabinfo",S_IWUSR|S_IRUGO,NULL,&proc_slabinfo_operations);
74453+ mode_t gr_mode = S_IRUGO;
74454+
74455+#ifdef CONFIG_GRKERNSEC_PROC_ADD
74456+ gr_mode = S_IRUSR;
74457+#endif
74458+
74459+ proc_create("slabinfo",S_IWUSR|gr_mode,NULL,&proc_slabinfo_operations);
74460 #ifdef CONFIG_DEBUG_SLAB_LEAK
74461- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
74462+ proc_create("slab_allocators", gr_mode, NULL, &proc_slabstats_operations);
74463 #endif
74464 return 0;
74465 }
74466 module_init(slab_proc_init);
74467 #endif
74468
74469+void check_object_size(const void *ptr, unsigned long n, bool to)
74470+{
74471+
74472+#ifdef CONFIG_PAX_USERCOPY
74473+ struct page *page;
74474+ struct kmem_cache *cachep = NULL;
74475+ struct slab *slabp;
74476+ unsigned int objnr;
74477+ unsigned long offset;
74478+
74479+ if (!n)
74480+ return;
74481+
74482+ if (ZERO_OR_NULL_PTR(ptr))
74483+ goto report;
74484+
74485+ if (!virt_addr_valid(ptr))
74486+ return;
74487+
74488+ page = virt_to_head_page(ptr);
74489+
74490+ if (!PageSlab(page)) {
74491+ if (object_is_on_stack(ptr, n) == -1)
74492+ goto report;
74493+ return;
74494+ }
74495+
74496+ cachep = page_get_cache(page);
74497+ if (!(cachep->flags & SLAB_USERCOPY))
74498+ goto report;
74499+
74500+ slabp = page_get_slab(page);
74501+ objnr = obj_to_index(cachep, slabp, ptr);
74502+ BUG_ON(objnr >= cachep->num);
74503+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
74504+ if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
74505+ return;
74506+
74507+report:
74508+ pax_report_usercopy(ptr, n, to, cachep ? cachep->name : NULL);
74509+#endif
74510+
74511+}
74512+EXPORT_SYMBOL(check_object_size);
74513+
74514 /**
74515 * ksize - get the actual amount of memory allocated for a given object
74516 * @objp: Pointer to the object
74517diff -urNp linux-2.6.39.1/mm/slob.c linux-2.6.39.1/mm/slob.c
74518--- linux-2.6.39.1/mm/slob.c 2011-05-19 00:06:34.000000000 -0400
74519+++ linux-2.6.39.1/mm/slob.c 2011-05-22 19:36:33.000000000 -0400
74520@@ -29,7 +29,7 @@
74521 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
74522 * alloc_pages() directly, allocating compound pages so the page order
74523 * does not have to be separately tracked, and also stores the exact
74524- * allocation size in page->private so that it can be used to accurately
74525+ * allocation size in slob_page->size so that it can be used to accurately
74526 * provide ksize(). These objects are detected in kfree() because slob_page()
74527 * is false for them.
74528 *
74529@@ -58,6 +58,7 @@
74530 */
74531
74532 #include <linux/kernel.h>
74533+#include <linux/sched.h>
74534 #include <linux/slab.h>
74535 #include <linux/mm.h>
74536 #include <linux/swap.h> /* struct reclaim_state */
74537@@ -102,7 +103,8 @@ struct slob_page {
74538 unsigned long flags; /* mandatory */
74539 atomic_t _count; /* mandatory */
74540 slobidx_t units; /* free units left in page */
74541- unsigned long pad[2];
74542+ unsigned long pad[1];
74543+ unsigned long size; /* size when >=PAGE_SIZE */
74544 slob_t *free; /* first free slob_t in page */
74545 struct list_head list; /* linked list of free pages */
74546 };
74547@@ -135,7 +137,7 @@ static LIST_HEAD(free_slob_large);
74548 */
74549 static inline int is_slob_page(struct slob_page *sp)
74550 {
74551- return PageSlab((struct page *)sp);
74552+ return PageSlab((struct page *)sp) && !sp->size;
74553 }
74554
74555 static inline void set_slob_page(struct slob_page *sp)
74556@@ -150,7 +152,7 @@ static inline void clear_slob_page(struc
74557
74558 static inline struct slob_page *slob_page(const void *addr)
74559 {
74560- return (struct slob_page *)virt_to_page(addr);
74561+ return (struct slob_page *)virt_to_head_page(addr);
74562 }
74563
74564 /*
74565@@ -210,7 +212,7 @@ static void set_slob(slob_t *s, slobidx_
74566 /*
74567 * Return the size of a slob block.
74568 */
74569-static slobidx_t slob_units(slob_t *s)
74570+static slobidx_t slob_units(const slob_t *s)
74571 {
74572 if (s->units > 0)
74573 return s->units;
74574@@ -220,7 +222,7 @@ static slobidx_t slob_units(slob_t *s)
74575 /*
74576 * Return the next free slob block pointer after this one.
74577 */
74578-static slob_t *slob_next(slob_t *s)
74579+static slob_t *slob_next(const slob_t *s)
74580 {
74581 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
74582 slobidx_t next;
74583@@ -235,7 +237,7 @@ static slob_t *slob_next(slob_t *s)
74584 /*
74585 * Returns true if s is the last free block in its page.
74586 */
74587-static int slob_last(slob_t *s)
74588+static int slob_last(const slob_t *s)
74589 {
74590 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
74591 }
74592@@ -254,6 +256,7 @@ static void *slob_new_pages(gfp_t gfp, i
74593 if (!page)
74594 return NULL;
74595
74596+ set_slob_page(page);
74597 return page_address(page);
74598 }
74599
74600@@ -370,11 +373,11 @@ static void *slob_alloc(size_t size, gfp
74601 if (!b)
74602 return NULL;
74603 sp = slob_page(b);
74604- set_slob_page(sp);
74605
74606 spin_lock_irqsave(&slob_lock, flags);
74607 sp->units = SLOB_UNITS(PAGE_SIZE);
74608 sp->free = b;
74609+ sp->size = 0;
74610 INIT_LIST_HEAD(&sp->list);
74611 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
74612 set_slob_page_free(sp, slob_list);
74613@@ -476,10 +479,9 @@ out:
74614 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
74615 */
74616
74617-void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74618+static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
74619 {
74620- unsigned int *m;
74621- int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74622+ slob_t *m;
74623 void *ret;
74624
74625 lockdep_trace_alloc(gfp);
74626@@ -492,7 +494,10 @@ void *__kmalloc_node(size_t size, gfp_t
74627
74628 if (!m)
74629 return NULL;
74630- *m = size;
74631+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
74632+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
74633+ m[0].units = size;
74634+ m[1].units = align;
74635 ret = (void *)m + align;
74636
74637 trace_kmalloc_node(_RET_IP_, ret,
74638@@ -504,9 +509,9 @@ void *__kmalloc_node(size_t size, gfp_t
74639 gfp |= __GFP_COMP;
74640 ret = slob_new_pages(gfp, order, node);
74641 if (ret) {
74642- struct page *page;
74643- page = virt_to_page(ret);
74644- page->private = size;
74645+ struct slob_page *sp;
74646+ sp = slob_page(ret);
74647+ sp->size = size;
74648 }
74649
74650 trace_kmalloc_node(_RET_IP_, ret,
74651@@ -516,6 +521,13 @@ void *__kmalloc_node(size_t size, gfp_t
74652 kmemleak_alloc(ret, size, 1, gfp);
74653 return ret;
74654 }
74655+
74656+void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74657+{
74658+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74659+
74660+ return __kmalloc_node_align(size, gfp, node, align);
74661+}
74662 EXPORT_SYMBOL(__kmalloc_node);
74663
74664 void kfree(const void *block)
74665@@ -531,13 +543,81 @@ void kfree(const void *block)
74666 sp = slob_page(block);
74667 if (is_slob_page(sp)) {
74668 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74669- unsigned int *m = (unsigned int *)(block - align);
74670- slob_free(m, *m + align);
74671- } else
74672+ slob_t *m = (slob_t *)(block - align);
74673+ slob_free(m, m[0].units + align);
74674+ } else {
74675+ clear_slob_page(sp);
74676+ free_slob_page(sp);
74677+ sp->size = 0;
74678 put_page(&sp->page);
74679+ }
74680 }
74681 EXPORT_SYMBOL(kfree);
74682
74683+void check_object_size(const void *ptr, unsigned long n, bool to)
74684+{
74685+
74686+#ifdef CONFIG_PAX_USERCOPY
74687+ struct slob_page *sp;
74688+ const slob_t *free;
74689+ const void *base;
74690+
74691+ if (!n)
74692+ return;
74693+
74694+ if (ZERO_OR_NULL_PTR(ptr))
74695+ goto report;
74696+
74697+ if (!virt_addr_valid(ptr))
74698+ return;
74699+
74700+ sp = slob_page(ptr);
74701+ if (!PageSlab((struct page*)sp)) {
74702+ if (object_is_on_stack(ptr, n) == -1)
74703+ goto report;
74704+ return;
74705+ }
74706+
74707+ if (sp->size) {
74708+ base = page_address(&sp->page);
74709+ if (base <= ptr && n <= sp->size - (ptr - base))
74710+ return;
74711+ goto report;
74712+ }
74713+
74714+ /* some tricky double walking to find the chunk */
74715+ base = (void *)((unsigned long)ptr & PAGE_MASK);
74716+ free = sp->free;
74717+
74718+ while (!slob_last(free) && (void *)free <= ptr) {
74719+ base = free + slob_units(free);
74720+ free = slob_next(free);
74721+ }
74722+
74723+ while (base < (void *)free) {
74724+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
74725+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
74726+ int offset;
74727+
74728+ if (ptr < base + align)
74729+ goto report;
74730+
74731+ offset = ptr - base - align;
74732+ if (offset < m) {
74733+ if (n <= m - offset)
74734+ return;
74735+ goto report;
74736+ }
74737+ base += size;
74738+ }
74739+
74740+report:
74741+ pax_report_usercopy(ptr, n, to, NULL);
74742+#endif
74743+
74744+}
74745+EXPORT_SYMBOL(check_object_size);
74746+
74747 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
74748 size_t ksize(const void *block)
74749 {
74750@@ -550,10 +630,10 @@ size_t ksize(const void *block)
74751 sp = slob_page(block);
74752 if (is_slob_page(sp)) {
74753 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74754- unsigned int *m = (unsigned int *)(block - align);
74755- return SLOB_UNITS(*m) * SLOB_UNIT;
74756+ slob_t *m = (slob_t *)(block - align);
74757+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
74758 } else
74759- return sp->page.private;
74760+ return sp->size;
74761 }
74762 EXPORT_SYMBOL(ksize);
74763
74764@@ -608,17 +688,25 @@ void *kmem_cache_alloc_node(struct kmem_
74765 {
74766 void *b;
74767
74768+#ifdef CONFIG_PAX_USERCOPY
74769+ b = __kmalloc_node_align(c->size, flags, node, c->align);
74770+#else
74771 if (c->size < PAGE_SIZE) {
74772 b = slob_alloc(c->size, flags, c->align, node);
74773 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
74774 SLOB_UNITS(c->size) * SLOB_UNIT,
74775 flags, node);
74776 } else {
74777+ struct slob_page *sp;
74778+
74779 b = slob_new_pages(flags, get_order(c->size), node);
74780+ sp = slob_page(b);
74781+ sp->size = c->size;
74782 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
74783 PAGE_SIZE << get_order(c->size),
74784 flags, node);
74785 }
74786+#endif
74787
74788 if (c->ctor)
74789 c->ctor(b);
74790@@ -630,10 +718,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
74791
74792 static void __kmem_cache_free(void *b, int size)
74793 {
74794- if (size < PAGE_SIZE)
74795+ struct slob_page *sp = slob_page(b);
74796+
74797+ if (is_slob_page(sp))
74798 slob_free(b, size);
74799- else
74800+ else {
74801+ clear_slob_page(sp);
74802+ free_slob_page(sp);
74803+ sp->size = 0;
74804 slob_free_pages(b, get_order(size));
74805+ }
74806 }
74807
74808 static void kmem_rcu_free(struct rcu_head *head)
74809@@ -646,14 +740,23 @@ static void kmem_rcu_free(struct rcu_hea
74810
74811 void kmem_cache_free(struct kmem_cache *c, void *b)
74812 {
74813+ int size = c->size;
74814+
74815+#ifdef CONFIG_PAX_USERCOPY
74816+ if (size + c->align < PAGE_SIZE) {
74817+ size += c->align;
74818+ b -= c->align;
74819+ }
74820+#endif
74821+
74822 kmemleak_free_recursive(b, c->flags);
74823 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
74824 struct slob_rcu *slob_rcu;
74825- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
74826- slob_rcu->size = c->size;
74827+ slob_rcu = b + (size - sizeof(struct slob_rcu));
74828+ slob_rcu->size = size;
74829 call_rcu(&slob_rcu->head, kmem_rcu_free);
74830 } else {
74831- __kmem_cache_free(b, c->size);
74832+ __kmem_cache_free(b, size);
74833 }
74834
74835 trace_kmem_cache_free(_RET_IP_, b);
74836diff -urNp linux-2.6.39.1/mm/slub.c linux-2.6.39.1/mm/slub.c
74837--- linux-2.6.39.1/mm/slub.c 2011-06-03 00:04:14.000000000 -0400
74838+++ linux-2.6.39.1/mm/slub.c 2011-06-03 00:32:08.000000000 -0400
74839@@ -431,7 +431,7 @@ static void print_track(const char *s, s
74840 if (!t->addr)
74841 return;
74842
74843- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
74844+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
74845 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
74846 }
74847
74848@@ -2183,6 +2183,8 @@ void kmem_cache_free(struct kmem_cache *
74849
74850 page = virt_to_head_page(x);
74851
74852+ BUG_ON(!PageSlab(page));
74853+
74854 slab_free(s, page, x, _RET_IP_);
74855
74856 trace_kmem_cache_free(_RET_IP_, x);
74857@@ -2216,7 +2218,7 @@ static int slub_min_objects;
74858 * Merge control. If this is set then no merging of slab caches will occur.
74859 * (Could be removed. This was introduced to pacify the merge skeptics.)
74860 */
74861-static int slub_nomerge;
74862+static int slub_nomerge = 1;
74863
74864 /*
74865 * Calculate the order of allocation given an slab object size.
74866@@ -2644,7 +2646,7 @@ static int kmem_cache_open(struct kmem_c
74867 * list to avoid pounding the page allocator excessively.
74868 */
74869 set_min_partial(s, ilog2(s->size));
74870- s->refcount = 1;
74871+ atomic_set(&s->refcount, 1);
74872 #ifdef CONFIG_NUMA
74873 s->remote_node_defrag_ratio = 1000;
74874 #endif
74875@@ -2750,8 +2752,7 @@ static inline int kmem_cache_close(struc
74876 void kmem_cache_destroy(struct kmem_cache *s)
74877 {
74878 down_write(&slub_lock);
74879- s->refcount--;
74880- if (!s->refcount) {
74881+ if (atomic_dec_and_test(&s->refcount)) {
74882 list_del(&s->list);
74883 if (kmem_cache_close(s)) {
74884 printk(KERN_ERR "SLUB %s: %s called for cache that "
74885@@ -2961,6 +2962,46 @@ void *__kmalloc_node(size_t size, gfp_t
74886 EXPORT_SYMBOL(__kmalloc_node);
74887 #endif
74888
74889+void check_object_size(const void *ptr, unsigned long n, bool to)
74890+{
74891+
74892+#ifdef CONFIG_PAX_USERCOPY
74893+ struct page *page;
74894+ struct kmem_cache *s = NULL;
74895+ unsigned long offset;
74896+
74897+ if (!n)
74898+ return;
74899+
74900+ if (ZERO_OR_NULL_PTR(ptr))
74901+ goto report;
74902+
74903+ if (!virt_addr_valid(ptr))
74904+ return;
74905+
74906+ page = virt_to_head_page(ptr);
74907+
74908+ if (!PageSlab(page)) {
74909+ if (object_is_on_stack(ptr, n) == -1)
74910+ goto report;
74911+ return;
74912+ }
74913+
74914+ s = page->slab;
74915+ if (!(s->flags & SLAB_USERCOPY))
74916+ goto report;
74917+
74918+ offset = (ptr - page_address(page)) % s->size;
74919+ if (offset <= s->objsize && n <= s->objsize - offset)
74920+ return;
74921+
74922+report:
74923+ pax_report_usercopy(ptr, n, to, s ? s->name : NULL);
74924+#endif
74925+
74926+}
74927+EXPORT_SYMBOL(check_object_size);
74928+
74929 size_t ksize(const void *object)
74930 {
74931 struct page *page;
74932@@ -3205,7 +3246,7 @@ static void __init kmem_cache_bootstrap_
74933 int node;
74934
74935 list_add(&s->list, &slab_caches);
74936- s->refcount = -1;
74937+ atomic_set(&s->refcount, -1);
74938
74939 for_each_node_state(node, N_NORMAL_MEMORY) {
74940 struct kmem_cache_node *n = get_node(s, node);
74941@@ -3322,17 +3363,17 @@ void __init kmem_cache_init(void)
74942
74943 /* Caches that are not of the two-to-the-power-of size */
74944 if (KMALLOC_MIN_SIZE <= 32) {
74945- kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
74946+ kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
74947 caches++;
74948 }
74949
74950 if (KMALLOC_MIN_SIZE <= 64) {
74951- kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
74952+ kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
74953 caches++;
74954 }
74955
74956 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
74957- kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
74958+ kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
74959 caches++;
74960 }
74961
74962@@ -3400,7 +3441,7 @@ static int slab_unmergeable(struct kmem_
74963 /*
74964 * We may have set a slab to be unmergeable during bootstrap.
74965 */
74966- if (s->refcount < 0)
74967+ if (atomic_read(&s->refcount) < 0)
74968 return 1;
74969
74970 return 0;
74971@@ -3459,7 +3500,7 @@ struct kmem_cache *kmem_cache_create(con
74972 down_write(&slub_lock);
74973 s = find_mergeable(size, align, flags, name, ctor);
74974 if (s) {
74975- s->refcount++;
74976+ atomic_inc(&s->refcount);
74977 /*
74978 * Adjust the object sizes so that we clear
74979 * the complete object on kzalloc.
74980@@ -3468,7 +3509,7 @@ struct kmem_cache *kmem_cache_create(con
74981 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
74982
74983 if (sysfs_slab_alias(s, name)) {
74984- s->refcount--;
74985+ atomic_dec(&s->refcount);
74986 goto err;
74987 }
74988 up_write(&slub_lock);
74989@@ -4201,7 +4242,7 @@ SLAB_ATTR_RO(ctor);
74990
74991 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
74992 {
74993- return sprintf(buf, "%d\n", s->refcount - 1);
74994+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
74995 }
74996 SLAB_ATTR_RO(aliases);
74997
74998@@ -4945,7 +4986,13 @@ static const struct file_operations proc
74999
75000 static int __init slab_proc_init(void)
75001 {
75002- proc_create("slabinfo", S_IRUGO, NULL, &proc_slabinfo_operations);
75003+ mode_t gr_mode = S_IRUGO;
75004+
75005+#ifdef CONFIG_GRKERNSEC_PROC_ADD
75006+ gr_mode = S_IRUSR;
75007+#endif
75008+
75009+ proc_create("slabinfo", gr_mode, NULL, &proc_slabinfo_operations);
75010 return 0;
75011 }
75012 module_init(slab_proc_init);
75013diff -urNp linux-2.6.39.1/mm/swapfile.c linux-2.6.39.1/mm/swapfile.c
75014--- linux-2.6.39.1/mm/swapfile.c 2011-05-19 00:06:34.000000000 -0400
75015+++ linux-2.6.39.1/mm/swapfile.c 2011-05-22 19:36:33.000000000 -0400
75016@@ -61,7 +61,7 @@ static DEFINE_MUTEX(swapon_mutex);
75017
75018 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
75019 /* Activity counter to indicate that a swapon or swapoff has occurred */
75020-static atomic_t proc_poll_event = ATOMIC_INIT(0);
75021+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
75022
75023 static inline unsigned char swap_count(unsigned char ent)
75024 {
75025@@ -1669,7 +1669,7 @@ SYSCALL_DEFINE1(swapoff, const char __us
75026 }
75027 filp_close(swap_file, NULL);
75028 err = 0;
75029- atomic_inc(&proc_poll_event);
75030+ atomic_inc_unchecked(&proc_poll_event);
75031 wake_up_interruptible(&proc_poll_wait);
75032
75033 out_dput:
75034@@ -1690,8 +1690,8 @@ static unsigned swaps_poll(struct file *
75035
75036 poll_wait(file, &proc_poll_wait, wait);
75037
75038- if (s->event != atomic_read(&proc_poll_event)) {
75039- s->event = atomic_read(&proc_poll_event);
75040+ if (s->event != atomic_read_unchecked(&proc_poll_event)) {
75041+ s->event = atomic_read_unchecked(&proc_poll_event);
75042 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
75043 }
75044
75045@@ -1797,7 +1797,7 @@ static int swaps_open(struct inode *inod
75046 }
75047
75048 s->seq.private = s;
75049- s->event = atomic_read(&proc_poll_event);
75050+ s->event = atomic_read_unchecked(&proc_poll_event);
75051 return ret;
75052 }
75053
75054@@ -2131,7 +2131,7 @@ SYSCALL_DEFINE2(swapon, const char __use
75055 (p->flags & SWP_DISCARDABLE) ? "D" : "");
75056
75057 mutex_unlock(&swapon_mutex);
75058- atomic_inc(&proc_poll_event);
75059+ atomic_inc_unchecked(&proc_poll_event);
75060 wake_up_interruptible(&proc_poll_wait);
75061
75062 if (S_ISREG(inode->i_mode))
75063diff -urNp linux-2.6.39.1/mm/util.c linux-2.6.39.1/mm/util.c
75064--- linux-2.6.39.1/mm/util.c 2011-05-19 00:06:34.000000000 -0400
75065+++ linux-2.6.39.1/mm/util.c 2011-05-23 17:07:00.000000000 -0400
75066@@ -112,6 +112,7 @@ EXPORT_SYMBOL(memdup_user);
75067 * allocated buffer. Use this if you don't want to free the buffer immediately
75068 * like, for example, with RCU.
75069 */
75070+#undef __krealloc
75071 void *__krealloc(const void *p, size_t new_size, gfp_t flags)
75072 {
75073 void *ret;
75074@@ -145,6 +146,7 @@ EXPORT_SYMBOL(__krealloc);
75075 * behaves exactly like kmalloc(). If @size is 0 and @p is not a
75076 * %NULL pointer, the object pointed to is freed.
75077 */
75078+#undef krealloc
75079 void *krealloc(const void *p, size_t new_size, gfp_t flags)
75080 {
75081 void *ret;
75082@@ -219,6 +221,12 @@ EXPORT_SYMBOL(strndup_user);
75083 void arch_pick_mmap_layout(struct mm_struct *mm)
75084 {
75085 mm->mmap_base = TASK_UNMAPPED_BASE;
75086+
75087+#ifdef CONFIG_PAX_RANDMMAP
75088+ if (mm->pax_flags & MF_PAX_RANDMMAP)
75089+ mm->mmap_base += mm->delta_mmap;
75090+#endif
75091+
75092 mm->get_unmapped_area = arch_get_unmapped_area;
75093 mm->unmap_area = arch_unmap_area;
75094 }
75095diff -urNp linux-2.6.39.1/mm/vmalloc.c linux-2.6.39.1/mm/vmalloc.c
75096--- linux-2.6.39.1/mm/vmalloc.c 2011-05-19 00:06:34.000000000 -0400
75097+++ linux-2.6.39.1/mm/vmalloc.c 2011-05-22 19:36:33.000000000 -0400
75098@@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd,
75099
75100 pte = pte_offset_kernel(pmd, addr);
75101 do {
75102- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
75103- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
75104+
75105+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75106+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
75107+ BUG_ON(!pte_exec(*pte));
75108+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
75109+ continue;
75110+ }
75111+#endif
75112+
75113+ {
75114+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
75115+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
75116+ }
75117 } while (pte++, addr += PAGE_SIZE, addr != end);
75118 }
75119
75120@@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, un
75121 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
75122 {
75123 pte_t *pte;
75124+ int ret = -ENOMEM;
75125
75126 /*
75127 * nr is a running index into the array which helps higher level
75128@@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, un
75129 pte = pte_alloc_kernel(pmd, addr);
75130 if (!pte)
75131 return -ENOMEM;
75132+
75133+ pax_open_kernel();
75134 do {
75135 struct page *page = pages[*nr];
75136
75137- if (WARN_ON(!pte_none(*pte)))
75138- return -EBUSY;
75139- if (WARN_ON(!page))
75140- return -ENOMEM;
75141+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75142+ if (pgprot_val(prot) & _PAGE_NX)
75143+#endif
75144+
75145+ if (WARN_ON(!pte_none(*pte))) {
75146+ ret = -EBUSY;
75147+ goto out;
75148+ }
75149+ if (WARN_ON(!page)) {
75150+ ret = -ENOMEM;
75151+ goto out;
75152+ }
75153 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
75154 (*nr)++;
75155 } while (pte++, addr += PAGE_SIZE, addr != end);
75156- return 0;
75157+ ret = 0;
75158+out:
75159+ pax_close_kernel();
75160+ return ret;
75161 }
75162
75163 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
75164@@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void
75165 * and fall back on vmalloc() if that fails. Others
75166 * just put it in the vmalloc space.
75167 */
75168-#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
75169+#ifdef CONFIG_MODULES
75170+#ifdef MODULES_VADDR
75171 unsigned long addr = (unsigned long)x;
75172 if (addr >= MODULES_VADDR && addr < MODULES_END)
75173 return 1;
75174 #endif
75175+
75176+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75177+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
75178+ return 1;
75179+#endif
75180+
75181+#endif
75182+
75183 return is_vmalloc_addr(x);
75184 }
75185
75186@@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void
75187
75188 if (!pgd_none(*pgd)) {
75189 pud_t *pud = pud_offset(pgd, addr);
75190+#ifdef CONFIG_X86
75191+ if (!pud_large(*pud))
75192+#endif
75193 if (!pud_none(*pud)) {
75194 pmd_t *pmd = pmd_offset(pud, addr);
75195+#ifdef CONFIG_X86
75196+ if (!pmd_large(*pmd))
75197+#endif
75198 if (!pmd_none(*pmd)) {
75199 pte_t *ptep, pte;
75200
75201@@ -1296,6 +1336,16 @@ static struct vm_struct *__get_vm_area_n
75202 struct vm_struct *area;
75203
75204 BUG_ON(in_interrupt());
75205+
75206+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75207+ if (flags & VM_KERNEXEC) {
75208+ if (start != VMALLOC_START || end != VMALLOC_END)
75209+ return NULL;
75210+ start = (unsigned long)MODULES_EXEC_VADDR;
75211+ end = (unsigned long)MODULES_EXEC_END;
75212+ }
75213+#endif
75214+
75215 if (flags & VM_IOREMAP) {
75216 int bit = fls(size);
75217
75218@@ -1514,6 +1564,11 @@ void *vmap(struct page **pages, unsigned
75219 if (count > totalram_pages)
75220 return NULL;
75221
75222+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75223+ if (!(pgprot_val(prot) & _PAGE_NX))
75224+ flags |= VM_KERNEXEC;
75225+#endif
75226+
75227 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
75228 __builtin_return_address(0));
75229 if (!area)
75230@@ -1610,6 +1665,13 @@ void *__vmalloc_node_range(unsigned long
75231 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
75232 return NULL;
75233
75234+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75235+ if (!(pgprot_val(prot) & _PAGE_NX))
75236+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_KERNEXEC, VMALLOC_START, VMALLOC_END,
75237+ node, gfp_mask, caller);
75238+ else
75239+#endif
75240+
75241 area = __get_vm_area_node(size, align, VM_ALLOC, start, end, node,
75242 gfp_mask, caller);
75243
75244@@ -1649,6 +1711,7 @@ static void *__vmalloc_node(unsigned lon
75245 gfp_mask, prot, node, caller);
75246 }
75247
75248+#undef __vmalloc
75249 void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot)
75250 {
75251 return __vmalloc_node(size, 1, gfp_mask, prot, -1,
75252@@ -1672,6 +1735,7 @@ static inline void *__vmalloc_node_flags
75253 * For tight control over page level allocator and protection flags
75254 * use __vmalloc() instead.
75255 */
75256+#undef vmalloc
75257 void *vmalloc(unsigned long size)
75258 {
75259 return __vmalloc_node_flags(size, -1, GFP_KERNEL | __GFP_HIGHMEM);
75260@@ -1688,6 +1752,7 @@ EXPORT_SYMBOL(vmalloc);
75261 * For tight control over page level allocator and protection flags
75262 * use __vmalloc() instead.
75263 */
75264+#undef vzalloc
75265 void *vzalloc(unsigned long size)
75266 {
75267 return __vmalloc_node_flags(size, -1,
75268@@ -1702,6 +1767,7 @@ EXPORT_SYMBOL(vzalloc);
75269 * The resulting memory area is zeroed so it can be mapped to userspace
75270 * without leaking data.
75271 */
75272+#undef vmalloc_user
75273 void *vmalloc_user(unsigned long size)
75274 {
75275 struct vm_struct *area;
75276@@ -1729,6 +1795,7 @@ EXPORT_SYMBOL(vmalloc_user);
75277 * For tight control over page level allocator and protection flags
75278 * use __vmalloc() instead.
75279 */
75280+#undef vmalloc_node
75281 void *vmalloc_node(unsigned long size, int node)
75282 {
75283 return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL,
75284@@ -1748,6 +1815,7 @@ EXPORT_SYMBOL(vmalloc_node);
75285 * For tight control over page level allocator and protection flags
75286 * use __vmalloc_node() instead.
75287 */
75288+#undef vzalloc_node
75289 void *vzalloc_node(unsigned long size, int node)
75290 {
75291 return __vmalloc_node_flags(size, node,
75292@@ -1770,10 +1838,10 @@ EXPORT_SYMBOL(vzalloc_node);
75293 * For tight control over page level allocator and protection flags
75294 * use __vmalloc() instead.
75295 */
75296-
75297+#undef vmalloc_exec
75298 void *vmalloc_exec(unsigned long size)
75299 {
75300- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
75301+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
75302 -1, __builtin_return_address(0));
75303 }
75304
75305@@ -1792,6 +1860,7 @@ void *vmalloc_exec(unsigned long size)
75306 * Allocate enough 32bit PA addressable pages to cover @size from the
75307 * page level allocator and map them into contiguous kernel virtual space.
75308 */
75309+#undef vmalloc_32
75310 void *vmalloc_32(unsigned long size)
75311 {
75312 return __vmalloc_node(size, 1, GFP_VMALLOC32, PAGE_KERNEL,
75313@@ -1806,6 +1875,7 @@ EXPORT_SYMBOL(vmalloc_32);
75314 * The resulting memory area is 32bit addressable and zeroed so it can be
75315 * mapped to userspace without leaking data.
75316 */
75317+#undef vmalloc_32_user
75318 void *vmalloc_32_user(unsigned long size)
75319 {
75320 struct vm_struct *area;
75321@@ -2068,6 +2138,8 @@ int remap_vmalloc_range(struct vm_area_s
75322 unsigned long uaddr = vma->vm_start;
75323 unsigned long usize = vma->vm_end - vma->vm_start;
75324
75325+ BUG_ON(vma->vm_mirror);
75326+
75327 if ((PAGE_SIZE-1) & (unsigned long)addr)
75328 return -EINVAL;
75329
75330diff -urNp linux-2.6.39.1/mm/vmstat.c linux-2.6.39.1/mm/vmstat.c
75331--- linux-2.6.39.1/mm/vmstat.c 2011-05-19 00:06:34.000000000 -0400
75332+++ linux-2.6.39.1/mm/vmstat.c 2011-05-22 19:41:42.000000000 -0400
75333@@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
75334 *
75335 * vm_stat contains the global counters
75336 */
75337-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
75338+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
75339 EXPORT_SYMBOL(vm_stat);
75340
75341 #ifdef CONFIG_SMP
75342@@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
75343 v = p->vm_stat_diff[i];
75344 p->vm_stat_diff[i] = 0;
75345 local_irq_restore(flags);
75346- atomic_long_add(v, &zone->vm_stat[i]);
75347+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
75348 global_diff[i] += v;
75349 #ifdef CONFIG_NUMA
75350 /* 3 seconds idle till flush */
75351@@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
75352
75353 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
75354 if (global_diff[i])
75355- atomic_long_add(global_diff[i], &vm_stat[i]);
75356+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
75357 }
75358
75359 #endif
75360@@ -1205,10 +1205,20 @@ static int __init setup_vmstat(void)
75361 start_cpu_timer(cpu);
75362 #endif
75363 #ifdef CONFIG_PROC_FS
75364- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
75365- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
75366- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
75367- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
75368+ {
75369+ mode_t gr_mode = S_IRUGO;
75370+#ifdef CONFIG_GRKERNSEC_PROC_ADD
75371+ gr_mode = S_IRUSR;
75372+#endif
75373+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
75374+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
75375+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
75376+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
75377+#else
75378+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
75379+#endif
75380+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
75381+ }
75382 #endif
75383 return 0;
75384 }
75385diff -urNp linux-2.6.39.1/net/8021q/vlan.c linux-2.6.39.1/net/8021q/vlan.c
75386--- linux-2.6.39.1/net/8021q/vlan.c 2011-05-19 00:06:34.000000000 -0400
75387+++ linux-2.6.39.1/net/8021q/vlan.c 2011-05-22 19:36:33.000000000 -0400
75388@@ -592,8 +592,7 @@ static int vlan_ioctl_handler(struct net
75389 err = -EPERM;
75390 if (!capable(CAP_NET_ADMIN))
75391 break;
75392- if ((args.u.name_type >= 0) &&
75393- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
75394+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
75395 struct vlan_net *vn;
75396
75397 vn = net_generic(net, vlan_net_id);
75398diff -urNp linux-2.6.39.1/net/atm/atm_misc.c linux-2.6.39.1/net/atm/atm_misc.c
75399--- linux-2.6.39.1/net/atm/atm_misc.c 2011-05-19 00:06:34.000000000 -0400
75400+++ linux-2.6.39.1/net/atm/atm_misc.c 2011-05-22 19:36:33.000000000 -0400
75401@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int
75402 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
75403 return 1;
75404 atm_return(vcc, truesize);
75405- atomic_inc(&vcc->stats->rx_drop);
75406+ atomic_inc_unchecked(&vcc->stats->rx_drop);
75407 return 0;
75408 }
75409 EXPORT_SYMBOL(atm_charge);
75410@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct
75411 }
75412 }
75413 atm_return(vcc, guess);
75414- atomic_inc(&vcc->stats->rx_drop);
75415+ atomic_inc_unchecked(&vcc->stats->rx_drop);
75416 return NULL;
75417 }
75418 EXPORT_SYMBOL(atm_alloc_charge);
75419@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
75420
75421 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
75422 {
75423-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
75424+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
75425 __SONET_ITEMS
75426 #undef __HANDLE_ITEM
75427 }
75428@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
75429
75430 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
75431 {
75432-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
75433+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
75434 __SONET_ITEMS
75435 #undef __HANDLE_ITEM
75436 }
75437diff -urNp linux-2.6.39.1/net/atm/mpoa_caches.c linux-2.6.39.1/net/atm/mpoa_caches.c
75438--- linux-2.6.39.1/net/atm/mpoa_caches.c 2011-05-19 00:06:34.000000000 -0400
75439+++ linux-2.6.39.1/net/atm/mpoa_caches.c 2011-05-22 19:36:33.000000000 -0400
75440@@ -255,6 +255,8 @@ static void check_resolving_entries(stru
75441 struct timeval now;
75442 struct k_message msg;
75443
75444+ pax_track_stack();
75445+
75446 do_gettimeofday(&now);
75447
75448 read_lock_bh(&client->ingress_lock);
75449diff -urNp linux-2.6.39.1/net/atm/proc.c linux-2.6.39.1/net/atm/proc.c
75450--- linux-2.6.39.1/net/atm/proc.c 2011-05-19 00:06:34.000000000 -0400
75451+++ linux-2.6.39.1/net/atm/proc.c 2011-05-22 19:41:42.000000000 -0400
75452@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *s
75453 const struct k_atm_aal_stats *stats)
75454 {
75455 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
75456- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
75457- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
75458- atomic_read(&stats->rx_drop));
75459+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
75460+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
75461+ atomic_read_unchecked(&stats->rx_drop));
75462 }
75463
75464 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
75465@@ -191,7 +191,12 @@ static void vcc_info(struct seq_file *se
75466 {
75467 struct sock *sk = sk_atm(vcc);
75468
75469+#ifdef CONFIG_GRKERNSEC_HIDESYM
75470+ seq_printf(seq, "%p ", NULL);
75471+#else
75472 seq_printf(seq, "%p ", vcc);
75473+#endif
75474+
75475 if (!vcc->dev)
75476 seq_printf(seq, "Unassigned ");
75477 else
75478@@ -218,7 +223,11 @@ static void svc_info(struct seq_file *se
75479 {
75480 if (!vcc->dev)
75481 seq_printf(seq, sizeof(void *) == 4 ?
75482+#ifdef CONFIG_GRKERNSEC_HIDESYM
75483+ "N/A@%p%10s" : "N/A@%p%2s", NULL, "");
75484+#else
75485 "N/A@%p%10s" : "N/A@%p%2s", vcc, "");
75486+#endif
75487 else
75488 seq_printf(seq, "%3d %3d %5d ",
75489 vcc->dev->number, vcc->vpi, vcc->vci);
75490diff -urNp linux-2.6.39.1/net/atm/resources.c linux-2.6.39.1/net/atm/resources.c
75491--- linux-2.6.39.1/net/atm/resources.c 2011-05-19 00:06:34.000000000 -0400
75492+++ linux-2.6.39.1/net/atm/resources.c 2011-05-22 19:36:33.000000000 -0400
75493@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
75494 static void copy_aal_stats(struct k_atm_aal_stats *from,
75495 struct atm_aal_stats *to)
75496 {
75497-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
75498+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
75499 __AAL_STAT_ITEMS
75500 #undef __HANDLE_ITEM
75501 }
75502@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_
75503 static void subtract_aal_stats(struct k_atm_aal_stats *from,
75504 struct atm_aal_stats *to)
75505 {
75506-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
75507+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
75508 __AAL_STAT_ITEMS
75509 #undef __HANDLE_ITEM
75510 }
75511diff -urNp linux-2.6.39.1/net/batman-adv/hard-interface.c linux-2.6.39.1/net/batman-adv/hard-interface.c
75512--- linux-2.6.39.1/net/batman-adv/hard-interface.c 2011-05-19 00:06:34.000000000 -0400
75513+++ linux-2.6.39.1/net/batman-adv/hard-interface.c 2011-05-22 19:36:33.000000000 -0400
75514@@ -339,8 +339,8 @@ int hardif_enable_interface(struct hard_
75515 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
75516 dev_add_pack(&hard_iface->batman_adv_ptype);
75517
75518- atomic_set(&hard_iface->seqno, 1);
75519- atomic_set(&hard_iface->frag_seqno, 1);
75520+ atomic_set_unchecked(&hard_iface->seqno, 1);
75521+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
75522 bat_info(hard_iface->soft_iface, "Adding interface: %s\n",
75523 hard_iface->net_dev->name);
75524
75525diff -urNp linux-2.6.39.1/net/batman-adv/routing.c linux-2.6.39.1/net/batman-adv/routing.c
75526--- linux-2.6.39.1/net/batman-adv/routing.c 2011-05-19 00:06:34.000000000 -0400
75527+++ linux-2.6.39.1/net/batman-adv/routing.c 2011-05-22 19:36:33.000000000 -0400
75528@@ -625,7 +625,7 @@ void receive_bat_packet(struct ethhdr *e
75529 return;
75530
75531 /* could be changed by schedule_own_packet() */
75532- if_incoming_seqno = atomic_read(&if_incoming->seqno);
75533+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
75534
75535 has_directlink_flag = (batman_packet->flags & DIRECTLINK ? 1 : 0);
75536
75537diff -urNp linux-2.6.39.1/net/batman-adv/send.c linux-2.6.39.1/net/batman-adv/send.c
75538--- linux-2.6.39.1/net/batman-adv/send.c 2011-05-19 00:06:34.000000000 -0400
75539+++ linux-2.6.39.1/net/batman-adv/send.c 2011-05-22 19:36:33.000000000 -0400
75540@@ -277,7 +277,7 @@ void schedule_own_packet(struct hard_ifa
75541
75542 /* change sequence number to network order */
75543 batman_packet->seqno =
75544- htonl((uint32_t)atomic_read(&hard_iface->seqno));
75545+ htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
75546
75547 if (vis_server == VIS_TYPE_SERVER_SYNC)
75548 batman_packet->flags |= VIS_SERVER;
75549@@ -291,7 +291,7 @@ void schedule_own_packet(struct hard_ifa
75550 else
75551 batman_packet->gw_flags = 0;
75552
75553- atomic_inc(&hard_iface->seqno);
75554+ atomic_inc_unchecked(&hard_iface->seqno);
75555
75556 slide_own_bcast_window(hard_iface);
75557 send_time = own_send_time(bat_priv);
75558diff -urNp linux-2.6.39.1/net/batman-adv/soft-interface.c linux-2.6.39.1/net/batman-adv/soft-interface.c
75559--- linux-2.6.39.1/net/batman-adv/soft-interface.c 2011-05-19 00:06:34.000000000 -0400
75560+++ linux-2.6.39.1/net/batman-adv/soft-interface.c 2011-05-22 19:36:33.000000000 -0400
75561@@ -386,7 +386,7 @@ int interface_tx(struct sk_buff *skb, st
75562
75563 /* set broadcast sequence number */
75564 bcast_packet->seqno =
75565- htonl(atomic_inc_return(&bat_priv->bcast_seqno));
75566+ htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
75567
75568 add_bcast_packet_to_list(bat_priv, skb);
75569
75570@@ -579,7 +579,7 @@ struct net_device *softif_create(char *n
75571 atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);
75572
75573 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
75574- atomic_set(&bat_priv->bcast_seqno, 1);
75575+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
75576 atomic_set(&bat_priv->hna_local_changed, 0);
75577
75578 bat_priv->primary_if = NULL;
75579diff -urNp linux-2.6.39.1/net/batman-adv/types.h linux-2.6.39.1/net/batman-adv/types.h
75580--- linux-2.6.39.1/net/batman-adv/types.h 2011-05-19 00:06:34.000000000 -0400
75581+++ linux-2.6.39.1/net/batman-adv/types.h 2011-05-22 19:36:33.000000000 -0400
75582@@ -38,8 +38,8 @@ struct hard_iface {
75583 int16_t if_num;
75584 char if_status;
75585 struct net_device *net_dev;
75586- atomic_t seqno;
75587- atomic_t frag_seqno;
75588+ atomic_unchecked_t seqno;
75589+ atomic_unchecked_t frag_seqno;
75590 unsigned char *packet_buff;
75591 int packet_len;
75592 struct kobject *hardif_obj;
75593@@ -141,7 +141,7 @@ struct bat_priv {
75594 atomic_t orig_interval; /* uint */
75595 atomic_t hop_penalty; /* uint */
75596 atomic_t log_level; /* uint */
75597- atomic_t bcast_seqno;
75598+ atomic_unchecked_t bcast_seqno;
75599 atomic_t bcast_queue_left;
75600 atomic_t batman_queue_left;
75601 char num_ifaces;
75602diff -urNp linux-2.6.39.1/net/batman-adv/unicast.c linux-2.6.39.1/net/batman-adv/unicast.c
75603--- linux-2.6.39.1/net/batman-adv/unicast.c 2011-05-19 00:06:34.000000000 -0400
75604+++ linux-2.6.39.1/net/batman-adv/unicast.c 2011-05-22 19:36:33.000000000 -0400
75605@@ -263,7 +263,7 @@ int frag_send_skb(struct sk_buff *skb, s
75606 frag1->flags = UNI_FRAG_HEAD | large_tail;
75607 frag2->flags = large_tail;
75608
75609- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
75610+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
75611 frag1->seqno = htons(seqno - 1);
75612 frag2->seqno = htons(seqno);
75613
75614diff -urNp linux-2.6.39.1/net/bluetooth/l2cap_sock.c linux-2.6.39.1/net/bluetooth/l2cap_sock.c
75615--- linux-2.6.39.1/net/bluetooth/l2cap_sock.c 2011-05-19 00:06:34.000000000 -0400
75616+++ linux-2.6.39.1/net/bluetooth/l2cap_sock.c 2011-06-12 06:36:08.000000000 -0400
75617@@ -446,6 +446,7 @@ static int l2cap_sock_getsockopt_old(str
75618 break;
75619 }
75620
75621+ memset(&cinfo, 0, sizeof(cinfo));
75622 cinfo.hci_handle = l2cap_pi(sk)->conn->hcon->handle;
75623 memcpy(cinfo.dev_class, l2cap_pi(sk)->conn->hcon->dev_class, 3);
75624
75625diff -urNp linux-2.6.39.1/net/bluetooth/rfcomm/sock.c linux-2.6.39.1/net/bluetooth/rfcomm/sock.c
75626--- linux-2.6.39.1/net/bluetooth/rfcomm/sock.c 2011-05-19 00:06:34.000000000 -0400
75627+++ linux-2.6.39.1/net/bluetooth/rfcomm/sock.c 2011-06-12 06:36:42.000000000 -0400
75628@@ -787,6 +787,7 @@ static int rfcomm_sock_getsockopt_old(st
75629
75630 l2cap_sk = rfcomm_pi(sk)->dlc->session->sock->sk;
75631
75632+ memset(&cinfo, 0, sizeof(cinfo));
75633 cinfo.hci_handle = l2cap_pi(l2cap_sk)->conn->hcon->handle;
75634 memcpy(cinfo.dev_class, l2cap_pi(l2cap_sk)->conn->hcon->dev_class, 3);
75635
75636diff -urNp linux-2.6.39.1/net/bridge/br_multicast.c linux-2.6.39.1/net/bridge/br_multicast.c
75637--- linux-2.6.39.1/net/bridge/br_multicast.c 2011-05-19 00:06:34.000000000 -0400
75638+++ linux-2.6.39.1/net/bridge/br_multicast.c 2011-05-22 19:36:33.000000000 -0400
75639@@ -1482,7 +1482,7 @@ static int br_multicast_ipv6_rcv(struct
75640 nexthdr = ip6h->nexthdr;
75641 offset = ipv6_skip_exthdr(skb, sizeof(*ip6h), &nexthdr);
75642
75643- if (offset < 0 || nexthdr != IPPROTO_ICMPV6)
75644+ if (nexthdr != IPPROTO_ICMPV6)
75645 return 0;
75646
75647 /* Okay, we found ICMPv6 header */
75648diff -urNp linux-2.6.39.1/net/bridge/netfilter/ebtables.c linux-2.6.39.1/net/bridge/netfilter/ebtables.c
75649--- linux-2.6.39.1/net/bridge/netfilter/ebtables.c 2011-05-19 00:06:34.000000000 -0400
75650+++ linux-2.6.39.1/net/bridge/netfilter/ebtables.c 2011-05-22 19:36:33.000000000 -0400
75651@@ -1512,7 +1512,7 @@ static int do_ebt_get_ctl(struct sock *s
75652 tmp.valid_hooks = t->table->valid_hooks;
75653 }
75654 mutex_unlock(&ebt_mutex);
75655- if (copy_to_user(user, &tmp, *len) != 0){
75656+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
75657 BUGPRINT("c2u Didn't work\n");
75658 ret = -EFAULT;
75659 break;
75660@@ -1780,6 +1780,8 @@ static int compat_copy_everything_to_use
75661 int ret;
75662 void __user *pos;
75663
75664+ pax_track_stack();
75665+
75666 memset(&tinfo, 0, sizeof(tinfo));
75667
75668 if (cmd == EBT_SO_GET_ENTRIES) {
75669diff -urNp linux-2.6.39.1/net/caif/caif_socket.c linux-2.6.39.1/net/caif/caif_socket.c
75670--- linux-2.6.39.1/net/caif/caif_socket.c 2011-05-19 00:06:34.000000000 -0400
75671+++ linux-2.6.39.1/net/caif/caif_socket.c 2011-05-22 19:36:33.000000000 -0400
75672@@ -48,18 +48,19 @@ static struct dentry *debugfsdir;
75673 #ifdef CONFIG_DEBUG_FS
75674 struct debug_fs_counter {
75675 atomic_t caif_nr_socks;
75676- atomic_t num_connect_req;
75677- atomic_t num_connect_resp;
75678- atomic_t num_connect_fail_resp;
75679- atomic_t num_disconnect;
75680- atomic_t num_remote_shutdown_ind;
75681- atomic_t num_tx_flow_off_ind;
75682- atomic_t num_tx_flow_on_ind;
75683- atomic_t num_rx_flow_off;
75684- atomic_t num_rx_flow_on;
75685+ atomic_unchecked_t num_connect_req;
75686+ atomic_unchecked_t num_connect_resp;
75687+ atomic_unchecked_t num_connect_fail_resp;
75688+ atomic_unchecked_t num_disconnect;
75689+ atomic_unchecked_t num_remote_shutdown_ind;
75690+ atomic_unchecked_t num_tx_flow_off_ind;
75691+ atomic_unchecked_t num_tx_flow_on_ind;
75692+ atomic_unchecked_t num_rx_flow_off;
75693+ atomic_unchecked_t num_rx_flow_on;
75694 };
75695 static struct debug_fs_counter cnt;
75696 #define dbfs_atomic_inc(v) atomic_inc(v)
75697+#define dbfs_atomic_inc_unchecked(v) atomic_inc_unchecked(v)
75698 #define dbfs_atomic_dec(v) atomic_dec(v)
75699 #else
75700 #define dbfs_atomic_inc(v)
75701@@ -159,7 +160,7 @@ static int caif_queue_rcv_skb(struct soc
75702 atomic_read(&cf_sk->sk.sk_rmem_alloc),
75703 sk_rcvbuf_lowwater(cf_sk));
75704 set_rx_flow_off(cf_sk);
75705- dbfs_atomic_inc(&cnt.num_rx_flow_off);
75706+ dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
75707 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
75708 }
75709
75710@@ -169,7 +170,7 @@ static int caif_queue_rcv_skb(struct soc
75711 if (!sk_rmem_schedule(sk, skb->truesize) && rx_flow_is_on(cf_sk)) {
75712 set_rx_flow_off(cf_sk);
75713 pr_debug("sending flow OFF due to rmem_schedule\n");
75714- dbfs_atomic_inc(&cnt.num_rx_flow_off);
75715+ dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
75716 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
75717 }
75718 skb->dev = NULL;
75719@@ -218,21 +219,21 @@ static void caif_ctrl_cb(struct cflayer
75720 switch (flow) {
75721 case CAIF_CTRLCMD_FLOW_ON_IND:
75722 /* OK from modem to start sending again */
75723- dbfs_atomic_inc(&cnt.num_tx_flow_on_ind);
75724+ dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_on_ind);
75725 set_tx_flow_on(cf_sk);
75726 cf_sk->sk.sk_state_change(&cf_sk->sk);
75727 break;
75728
75729 case CAIF_CTRLCMD_FLOW_OFF_IND:
75730 /* Modem asks us to shut up */
75731- dbfs_atomic_inc(&cnt.num_tx_flow_off_ind);
75732+ dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_off_ind);
75733 set_tx_flow_off(cf_sk);
75734 cf_sk->sk.sk_state_change(&cf_sk->sk);
75735 break;
75736
75737 case CAIF_CTRLCMD_INIT_RSP:
75738 /* We're now connected */
75739- dbfs_atomic_inc(&cnt.num_connect_resp);
75740+ dbfs_atomic_inc_unchecked(&cnt.num_connect_resp);
75741 cf_sk->sk.sk_state = CAIF_CONNECTED;
75742 set_tx_flow_on(cf_sk);
75743 cf_sk->sk.sk_state_change(&cf_sk->sk);
75744@@ -247,7 +248,7 @@ static void caif_ctrl_cb(struct cflayer
75745
75746 case CAIF_CTRLCMD_INIT_FAIL_RSP:
75747 /* Connect request failed */
75748- dbfs_atomic_inc(&cnt.num_connect_fail_resp);
75749+ dbfs_atomic_inc_unchecked(&cnt.num_connect_fail_resp);
75750 cf_sk->sk.sk_err = ECONNREFUSED;
75751 cf_sk->sk.sk_state = CAIF_DISCONNECTED;
75752 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
75753@@ -261,7 +262,7 @@ static void caif_ctrl_cb(struct cflayer
75754
75755 case CAIF_CTRLCMD_REMOTE_SHUTDOWN_IND:
75756 /* Modem has closed this connection, or device is down. */
75757- dbfs_atomic_inc(&cnt.num_remote_shutdown_ind);
75758+ dbfs_atomic_inc_unchecked(&cnt.num_remote_shutdown_ind);
75759 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
75760 cf_sk->sk.sk_err = ECONNRESET;
75761 set_rx_flow_on(cf_sk);
75762@@ -281,7 +282,7 @@ static void caif_check_flow_release(stru
75763 return;
75764
75765 if (atomic_read(&sk->sk_rmem_alloc) <= sk_rcvbuf_lowwater(cf_sk)) {
75766- dbfs_atomic_inc(&cnt.num_rx_flow_on);
75767+ dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_on);
75768 set_rx_flow_on(cf_sk);
75769 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_ON_REQ);
75770 }
75771@@ -864,7 +865,7 @@ static int caif_connect(struct socket *s
75772 /*ifindex = id of the interface.*/
75773 cf_sk->conn_req.ifindex = cf_sk->sk.sk_bound_dev_if;
75774
75775- dbfs_atomic_inc(&cnt.num_connect_req);
75776+ dbfs_atomic_inc_unchecked(&cnt.num_connect_req);
75777 cf_sk->layer.receive = caif_sktrecv_cb;
75778 err = caif_connect_client(&cf_sk->conn_req,
75779 &cf_sk->layer, &ifindex, &headroom, &tailroom);
75780@@ -952,7 +953,7 @@ static int caif_release(struct socket *s
75781 spin_unlock(&sk->sk_receive_queue.lock);
75782 sock->sk = NULL;
75783
75784- dbfs_atomic_inc(&cnt.num_disconnect);
75785+ dbfs_atomic_inc_unchecked(&cnt.num_disconnect);
75786
75787 if (cf_sk->debugfs_socket_dir != NULL)
75788 debugfs_remove_recursive(cf_sk->debugfs_socket_dir);
75789diff -urNp linux-2.6.39.1/net/caif/cfctrl.c linux-2.6.39.1/net/caif/cfctrl.c
75790--- linux-2.6.39.1/net/caif/cfctrl.c 2011-05-19 00:06:34.000000000 -0400
75791+++ linux-2.6.39.1/net/caif/cfctrl.c 2011-05-22 19:36:33.000000000 -0400
75792@@ -9,6 +9,7 @@
75793 #include <linux/stddef.h>
75794 #include <linux/spinlock.h>
75795 #include <linux/slab.h>
75796+#include <linux/sched.h>
75797 #include <net/caif/caif_layer.h>
75798 #include <net/caif/cfpkt.h>
75799 #include <net/caif/cfctrl.h>
75800@@ -46,8 +47,8 @@ struct cflayer *cfctrl_create(void)
75801 dev_info.id = 0xff;
75802 memset(this, 0, sizeof(*this));
75803 cfsrvl_init(&this->serv, 0, &dev_info, false);
75804- atomic_set(&this->req_seq_no, 1);
75805- atomic_set(&this->rsp_seq_no, 1);
75806+ atomic_set_unchecked(&this->req_seq_no, 1);
75807+ atomic_set_unchecked(&this->rsp_seq_no, 1);
75808 this->serv.layer.receive = cfctrl_recv;
75809 sprintf(this->serv.layer.name, "ctrl");
75810 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
75811@@ -116,8 +117,8 @@ void cfctrl_insert_req(struct cfctrl *ct
75812 struct cfctrl_request_info *req)
75813 {
75814 spin_lock(&ctrl->info_list_lock);
75815- atomic_inc(&ctrl->req_seq_no);
75816- req->sequence_no = atomic_read(&ctrl->req_seq_no);
75817+ atomic_inc_unchecked(&ctrl->req_seq_no);
75818+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
75819 list_add_tail(&req->list, &ctrl->list);
75820 spin_unlock(&ctrl->info_list_lock);
75821 }
75822@@ -136,7 +137,7 @@ struct cfctrl_request_info *cfctrl_remov
75823 if (p != first)
75824 pr_warn("Requests are not received in order\n");
75825
75826- atomic_set(&ctrl->rsp_seq_no,
75827+ atomic_set_unchecked(&ctrl->rsp_seq_no,
75828 p->sequence_no);
75829 list_del(&p->list);
75830 goto out;
75831@@ -385,6 +386,7 @@ static int cfctrl_recv(struct cflayer *l
75832 struct cfctrl *cfctrl = container_obj(layer);
75833 struct cfctrl_request_info rsp, *req;
75834
75835+ pax_track_stack();
75836
75837 cfpkt_extr_head(pkt, &cmdrsp, 1);
75838 cmd = cmdrsp & CFCTRL_CMD_MASK;
75839diff -urNp linux-2.6.39.1/net/can/bcm.c linux-2.6.39.1/net/can/bcm.c
75840--- linux-2.6.39.1/net/can/bcm.c 2011-05-19 00:06:34.000000000 -0400
75841+++ linux-2.6.39.1/net/can/bcm.c 2011-05-22 19:41:42.000000000 -0400
75842@@ -165,9 +165,15 @@ static int bcm_proc_show(struct seq_file
75843 struct bcm_sock *bo = bcm_sk(sk);
75844 struct bcm_op *op;
75845
75846+#ifdef CONFIG_GRKERNSEC_HIDESYM
75847+ seq_printf(m, ">>> socket %p", NULL);
75848+ seq_printf(m, " / sk %p", NULL);
75849+ seq_printf(m, " / bo %p", NULL);
75850+#else
75851 seq_printf(m, ">>> socket %p", sk->sk_socket);
75852 seq_printf(m, " / sk %p", sk);
75853 seq_printf(m, " / bo %p", bo);
75854+#endif
75855 seq_printf(m, " / dropped %lu", bo->dropped_usr_msgs);
75856 seq_printf(m, " / bound %s", bcm_proc_getifname(ifname, bo->ifindex));
75857 seq_printf(m, " <<<\n");
75858diff -urNp linux-2.6.39.1/net/core/datagram.c linux-2.6.39.1/net/core/datagram.c
75859--- linux-2.6.39.1/net/core/datagram.c 2011-05-19 00:06:34.000000000 -0400
75860+++ linux-2.6.39.1/net/core/datagram.c 2011-05-22 19:36:33.000000000 -0400
75861@@ -285,7 +285,7 @@ int skb_kill_datagram(struct sock *sk, s
75862 }
75863
75864 kfree_skb(skb);
75865- atomic_inc(&sk->sk_drops);
75866+ atomic_inc_unchecked(&sk->sk_drops);
75867 sk_mem_reclaim_partial(sk);
75868
75869 return err;
75870diff -urNp linux-2.6.39.1/net/core/dev.c linux-2.6.39.1/net/core/dev.c
75871--- linux-2.6.39.1/net/core/dev.c 2011-06-03 00:04:14.000000000 -0400
75872+++ linux-2.6.39.1/net/core/dev.c 2011-06-03 00:32:08.000000000 -0400
75873@@ -1125,10 +1125,14 @@ void dev_load(struct net *net, const cha
75874 if (no_module && capable(CAP_NET_ADMIN))
75875 no_module = request_module("netdev-%s", name);
75876 if (no_module && capable(CAP_SYS_MODULE)) {
75877+#ifdef CONFIG_GRKERNSEC_MODHARDEN
75878+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
75879+#else
75880 if (!request_module("%s", name))
75881 pr_err("Loading kernel module for a network device "
75882 "with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s "
75883 "instead\n", name);
75884+#endif
75885 }
75886 }
75887 EXPORT_SYMBOL(dev_load);
75888@@ -1957,7 +1961,7 @@ struct dev_gso_cb {
75889
75890 static void dev_gso_skb_destructor(struct sk_buff *skb)
75891 {
75892- struct dev_gso_cb *cb;
75893+ const struct dev_gso_cb *cb;
75894
75895 do {
75896 struct sk_buff *nskb = skb->next;
75897@@ -2901,7 +2905,7 @@ int netif_rx_ni(struct sk_buff *skb)
75898 }
75899 EXPORT_SYMBOL(netif_rx_ni);
75900
75901-static void net_tx_action(struct softirq_action *h)
75902+static void net_tx_action(void)
75903 {
75904 struct softnet_data *sd = &__get_cpu_var(softnet_data);
75905
75906@@ -3765,7 +3769,7 @@ void netif_napi_del(struct napi_struct *
75907 }
75908 EXPORT_SYMBOL(netif_napi_del);
75909
75910-static void net_rx_action(struct softirq_action *h)
75911+static void net_rx_action(void)
75912 {
75913 struct softnet_data *sd = &__get_cpu_var(softnet_data);
75914 unsigned long time_limit = jiffies + 2;
75915diff -urNp linux-2.6.39.1/net/core/flow.c linux-2.6.39.1/net/core/flow.c
75916--- linux-2.6.39.1/net/core/flow.c 2011-05-19 00:06:34.000000000 -0400
75917+++ linux-2.6.39.1/net/core/flow.c 2011-05-22 19:36:34.000000000 -0400
75918@@ -60,7 +60,7 @@ struct flow_cache {
75919 struct timer_list rnd_timer;
75920 };
75921
75922-atomic_t flow_cache_genid = ATOMIC_INIT(0);
75923+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
75924 EXPORT_SYMBOL(flow_cache_genid);
75925 static struct flow_cache flow_cache_global;
75926 static struct kmem_cache *flow_cachep __read_mostly;
75927@@ -85,7 +85,7 @@ static void flow_cache_new_hashrnd(unsig
75928
75929 static int flow_entry_valid(struct flow_cache_entry *fle)
75930 {
75931- if (atomic_read(&flow_cache_genid) != fle->genid)
75932+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
75933 return 0;
75934 if (fle->object && !fle->object->ops->check(fle->object))
75935 return 0;
75936@@ -253,7 +253,7 @@ flow_cache_lookup(struct net *net, const
75937 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
75938 fcp->hash_count++;
75939 }
75940- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
75941+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
75942 flo = fle->object;
75943 if (!flo)
75944 goto ret_object;
75945@@ -274,7 +274,7 @@ nocache:
75946 }
75947 flo = resolver(net, key, family, dir, flo, ctx);
75948 if (fle) {
75949- fle->genid = atomic_read(&flow_cache_genid);
75950+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
75951 if (!IS_ERR(flo))
75952 fle->object = flo;
75953 else
75954diff -urNp linux-2.6.39.1/net/core/skbuff.c linux-2.6.39.1/net/core/skbuff.c
75955--- linux-2.6.39.1/net/core/skbuff.c 2011-06-03 00:04:14.000000000 -0400
75956+++ linux-2.6.39.1/net/core/skbuff.c 2011-06-03 00:32:08.000000000 -0400
75957@@ -1542,6 +1542,8 @@ int skb_splice_bits(struct sk_buff *skb,
75958 struct sock *sk = skb->sk;
75959 int ret = 0;
75960
75961+ pax_track_stack();
75962+
75963 if (splice_grow_spd(pipe, &spd))
75964 return -ENOMEM;
75965
75966diff -urNp linux-2.6.39.1/net/core/sock.c linux-2.6.39.1/net/core/sock.c
75967--- linux-2.6.39.1/net/core/sock.c 2011-05-19 00:06:34.000000000 -0400
75968+++ linux-2.6.39.1/net/core/sock.c 2011-05-22 19:36:34.000000000 -0400
75969@@ -291,7 +291,7 @@ int sock_queue_rcv_skb(struct sock *sk,
75970 */
75971 if (atomic_read(&sk->sk_rmem_alloc) + skb->truesize >=
75972 (unsigned)sk->sk_rcvbuf) {
75973- atomic_inc(&sk->sk_drops);
75974+ atomic_inc_unchecked(&sk->sk_drops);
75975 return -ENOMEM;
75976 }
75977
75978@@ -300,7 +300,7 @@ int sock_queue_rcv_skb(struct sock *sk,
75979 return err;
75980
75981 if (!sk_rmem_schedule(sk, skb->truesize)) {
75982- atomic_inc(&sk->sk_drops);
75983+ atomic_inc_unchecked(&sk->sk_drops);
75984 return -ENOBUFS;
75985 }
75986
75987@@ -320,7 +320,7 @@ int sock_queue_rcv_skb(struct sock *sk,
75988 skb_dst_force(skb);
75989
75990 spin_lock_irqsave(&list->lock, flags);
75991- skb->dropcount = atomic_read(&sk->sk_drops);
75992+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
75993 __skb_queue_tail(list, skb);
75994 spin_unlock_irqrestore(&list->lock, flags);
75995
75996@@ -340,7 +340,7 @@ int sk_receive_skb(struct sock *sk, stru
75997 skb->dev = NULL;
75998
75999 if (sk_rcvqueues_full(sk, skb)) {
76000- atomic_inc(&sk->sk_drops);
76001+ atomic_inc_unchecked(&sk->sk_drops);
76002 goto discard_and_relse;
76003 }
76004 if (nested)
76005@@ -358,7 +358,7 @@ int sk_receive_skb(struct sock *sk, stru
76006 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
76007 } else if (sk_add_backlog(sk, skb)) {
76008 bh_unlock_sock(sk);
76009- atomic_inc(&sk->sk_drops);
76010+ atomic_inc_unchecked(&sk->sk_drops);
76011 goto discard_and_relse;
76012 }
76013
76014@@ -934,7 +934,7 @@ int sock_getsockopt(struct socket *sock,
76015 return -ENOTCONN;
76016 if (lv < len)
76017 return -EINVAL;
76018- if (copy_to_user(optval, address, len))
76019+ if (len > sizeof(address) || copy_to_user(optval, address, len))
76020 return -EFAULT;
76021 goto lenout;
76022 }
76023@@ -967,7 +967,7 @@ int sock_getsockopt(struct socket *sock,
76024
76025 if (len > lv)
76026 len = lv;
76027- if (copy_to_user(optval, &v, len))
76028+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
76029 return -EFAULT;
76030 lenout:
76031 if (put_user(len, optlen))
76032@@ -2023,7 +2023,7 @@ void sock_init_data(struct socket *sock,
76033 */
76034 smp_wmb();
76035 atomic_set(&sk->sk_refcnt, 1);
76036- atomic_set(&sk->sk_drops, 0);
76037+ atomic_set_unchecked(&sk->sk_drops, 0);
76038 }
76039 EXPORT_SYMBOL(sock_init_data);
76040
76041diff -urNp linux-2.6.39.1/net/decnet/sysctl_net_decnet.c linux-2.6.39.1/net/decnet/sysctl_net_decnet.c
76042--- linux-2.6.39.1/net/decnet/sysctl_net_decnet.c 2011-05-19 00:06:34.000000000 -0400
76043+++ linux-2.6.39.1/net/decnet/sysctl_net_decnet.c 2011-05-22 19:36:34.000000000 -0400
76044@@ -173,7 +173,7 @@ static int dn_node_address_handler(ctl_t
76045
76046 if (len > *lenp) len = *lenp;
76047
76048- if (copy_to_user(buffer, addr, len))
76049+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
76050 return -EFAULT;
76051
76052 *lenp = len;
76053@@ -236,7 +236,7 @@ static int dn_def_dev_handler(ctl_table
76054
76055 if (len > *lenp) len = *lenp;
76056
76057- if (copy_to_user(buffer, devname, len))
76058+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
76059 return -EFAULT;
76060
76061 *lenp = len;
76062diff -urNp linux-2.6.39.1/net/econet/Kconfig linux-2.6.39.1/net/econet/Kconfig
76063--- linux-2.6.39.1/net/econet/Kconfig 2011-05-19 00:06:34.000000000 -0400
76064+++ linux-2.6.39.1/net/econet/Kconfig 2011-05-22 19:41:42.000000000 -0400
76065@@ -4,7 +4,7 @@
76066
76067 config ECONET
76068 tristate "Acorn Econet/AUN protocols (EXPERIMENTAL)"
76069- depends on EXPERIMENTAL && INET
76070+ depends on EXPERIMENTAL && INET && BROKEN
76071 ---help---
76072 Econet is a fairly old and slow networking protocol mainly used by
76073 Acorn computers to access file and print servers. It uses native
76074diff -urNp linux-2.6.39.1/net/ipv4/fib_frontend.c linux-2.6.39.1/net/ipv4/fib_frontend.c
76075--- linux-2.6.39.1/net/ipv4/fib_frontend.c 2011-05-19 00:06:34.000000000 -0400
76076+++ linux-2.6.39.1/net/ipv4/fib_frontend.c 2011-05-22 19:36:34.000000000 -0400
76077@@ -968,12 +968,12 @@ static int fib_inetaddr_event(struct not
76078 #ifdef CONFIG_IP_ROUTE_MULTIPATH
76079 fib_sync_up(dev);
76080 #endif
76081- atomic_inc(&net->ipv4.dev_addr_genid);
76082+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76083 rt_cache_flush(dev_net(dev), -1);
76084 break;
76085 case NETDEV_DOWN:
76086 fib_del_ifaddr(ifa, NULL);
76087- atomic_inc(&net->ipv4.dev_addr_genid);
76088+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76089 if (ifa->ifa_dev->ifa_list == NULL) {
76090 /* Last address was deleted from this interface.
76091 * Disable IP.
76092@@ -1009,7 +1009,7 @@ static int fib_netdev_event(struct notif
76093 #ifdef CONFIG_IP_ROUTE_MULTIPATH
76094 fib_sync_up(dev);
76095 #endif
76096- atomic_inc(&net->ipv4.dev_addr_genid);
76097+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76098 rt_cache_flush(dev_net(dev), -1);
76099 break;
76100 case NETDEV_DOWN:
76101diff -urNp linux-2.6.39.1/net/ipv4/fib_semantics.c linux-2.6.39.1/net/ipv4/fib_semantics.c
76102--- linux-2.6.39.1/net/ipv4/fib_semantics.c 2011-05-19 00:06:34.000000000 -0400
76103+++ linux-2.6.39.1/net/ipv4/fib_semantics.c 2011-05-22 19:36:34.000000000 -0400
76104@@ -701,7 +701,7 @@ __be32 fib_info_update_nh_saddr(struct n
76105 nh->nh_saddr = inet_select_addr(nh->nh_dev,
76106 nh->nh_gw,
76107 nh->nh_parent->fib_scope);
76108- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
76109+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
76110
76111 return nh->nh_saddr;
76112 }
76113diff -urNp linux-2.6.39.1/net/ipv4/inet_diag.c linux-2.6.39.1/net/ipv4/inet_diag.c
76114--- linux-2.6.39.1/net/ipv4/inet_diag.c 2011-05-19 00:06:34.000000000 -0400
76115+++ linux-2.6.39.1/net/ipv4/inet_diag.c 2011-05-22 19:41:42.000000000 -0400
76116@@ -114,8 +114,14 @@ static int inet_csk_diag_fill(struct soc
76117 r->idiag_retrans = 0;
76118
76119 r->id.idiag_if = sk->sk_bound_dev_if;
76120+
76121+#ifdef CONFIG_GRKERNSEC_HIDESYM
76122+ r->id.idiag_cookie[0] = 0;
76123+ r->id.idiag_cookie[1] = 0;
76124+#else
76125 r->id.idiag_cookie[0] = (u32)(unsigned long)sk;
76126 r->id.idiag_cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
76127+#endif
76128
76129 r->id.idiag_sport = inet->inet_sport;
76130 r->id.idiag_dport = inet->inet_dport;
76131@@ -201,8 +207,15 @@ static int inet_twsk_diag_fill(struct in
76132 r->idiag_family = tw->tw_family;
76133 r->idiag_retrans = 0;
76134 r->id.idiag_if = tw->tw_bound_dev_if;
76135+
76136+#ifdef CONFIG_GRKERNSEC_HIDESYM
76137+ r->id.idiag_cookie[0] = 0;
76138+ r->id.idiag_cookie[1] = 0;
76139+#else
76140 r->id.idiag_cookie[0] = (u32)(unsigned long)tw;
76141 r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
76142+#endif
76143+
76144 r->id.idiag_sport = tw->tw_sport;
76145 r->id.idiag_dport = tw->tw_dport;
76146 r->id.idiag_src[0] = tw->tw_rcv_saddr;
76147@@ -285,12 +298,14 @@ static int inet_diag_get_exact(struct sk
76148 if (sk == NULL)
76149 goto unlock;
76150
76151+#ifndef CONFIG_GRKERNSEC_HIDESYM
76152 err = -ESTALE;
76153 if ((req->id.idiag_cookie[0] != INET_DIAG_NOCOOKIE ||
76154 req->id.idiag_cookie[1] != INET_DIAG_NOCOOKIE) &&
76155 ((u32)(unsigned long)sk != req->id.idiag_cookie[0] ||
76156 (u32)((((unsigned long)sk) >> 31) >> 1) != req->id.idiag_cookie[1]))
76157 goto out;
76158+#endif
76159
76160 err = -ENOMEM;
76161 rep = alloc_skb(NLMSG_SPACE((sizeof(struct inet_diag_msg) +
76162@@ -582,8 +597,14 @@ static int inet_diag_fill_req(struct sk_
76163 r->idiag_retrans = req->retrans;
76164
76165 r->id.idiag_if = sk->sk_bound_dev_if;
76166+
76167+#ifdef CONFIG_GRKERNSEC_HIDESYM
76168+ r->id.idiag_cookie[0] = 0;
76169+ r->id.idiag_cookie[1] = 0;
76170+#else
76171 r->id.idiag_cookie[0] = (u32)(unsigned long)req;
76172 r->id.idiag_cookie[1] = (u32)(((unsigned long)req >> 31) >> 1);
76173+#endif
76174
76175 tmo = req->expires - jiffies;
76176 if (tmo < 0)
76177diff -urNp linux-2.6.39.1/net/ipv4/inet_hashtables.c linux-2.6.39.1/net/ipv4/inet_hashtables.c
76178--- linux-2.6.39.1/net/ipv4/inet_hashtables.c 2011-05-19 00:06:34.000000000 -0400
76179+++ linux-2.6.39.1/net/ipv4/inet_hashtables.c 2011-05-22 19:41:42.000000000 -0400
76180@@ -18,11 +18,14 @@
76181 #include <linux/sched.h>
76182 #include <linux/slab.h>
76183 #include <linux/wait.h>
76184+#include <linux/security.h>
76185
76186 #include <net/inet_connection_sock.h>
76187 #include <net/inet_hashtables.h>
76188 #include <net/ip.h>
76189
76190+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
76191+
76192 /*
76193 * Allocate and initialize a new local port bind bucket.
76194 * The bindhash mutex for snum's hash chain must be held here.
76195@@ -529,6 +532,8 @@ ok:
76196 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
76197 spin_unlock(&head->lock);
76198
76199+ gr_update_task_in_ip_table(current, inet_sk(sk));
76200+
76201 if (tw) {
76202 inet_twsk_deschedule(tw, death_row);
76203 while (twrefcnt) {
76204diff -urNp linux-2.6.39.1/net/ipv4/inetpeer.c linux-2.6.39.1/net/ipv4/inetpeer.c
76205--- linux-2.6.39.1/net/ipv4/inetpeer.c 2011-05-19 00:06:34.000000000 -0400
76206+++ linux-2.6.39.1/net/ipv4/inetpeer.c 2011-05-22 19:36:34.000000000 -0400
76207@@ -467,6 +467,8 @@ struct inet_peer *inet_getpeer(struct in
76208 unsigned int sequence;
76209 int invalidated;
76210
76211+ pax_track_stack();
76212+
76213 /* Look up for the address quickly, lockless.
76214 * Because of a concurrent writer, we might not find an existing entry.
76215 */
76216@@ -504,8 +506,8 @@ struct inet_peer *inet_getpeer(struct in
76217 if (p) {
76218 p->daddr = *daddr;
76219 atomic_set(&p->refcnt, 1);
76220- atomic_set(&p->rid, 0);
76221- atomic_set(&p->ip_id_count, secure_ip_id(daddr->addr.a4));
76222+ atomic_set_unchecked(&p->rid, 0);
76223+ atomic_set_unchecked(&p->ip_id_count, secure_ip_id(daddr->addr.a4));
76224 p->tcp_ts_stamp = 0;
76225 p->metrics[RTAX_LOCK-1] = INETPEER_METRICS_NEW;
76226 p->rate_tokens = 0;
76227diff -urNp linux-2.6.39.1/net/ipv4/ip_fragment.c linux-2.6.39.1/net/ipv4/ip_fragment.c
76228--- linux-2.6.39.1/net/ipv4/ip_fragment.c 2011-05-19 00:06:34.000000000 -0400
76229+++ linux-2.6.39.1/net/ipv4/ip_fragment.c 2011-05-22 19:36:34.000000000 -0400
76230@@ -297,7 +297,7 @@ static inline int ip_frag_too_far(struct
76231 return 0;
76232
76233 start = qp->rid;
76234- end = atomic_inc_return(&peer->rid);
76235+ end = atomic_inc_return_unchecked(&peer->rid);
76236 qp->rid = end;
76237
76238 rc = qp->q.fragments && (end - start) > max;
76239diff -urNp linux-2.6.39.1/net/ipv4/ip_sockglue.c linux-2.6.39.1/net/ipv4/ip_sockglue.c
76240--- linux-2.6.39.1/net/ipv4/ip_sockglue.c 2011-05-19 00:06:34.000000000 -0400
76241+++ linux-2.6.39.1/net/ipv4/ip_sockglue.c 2011-05-22 19:36:34.000000000 -0400
76242@@ -1064,6 +1064,8 @@ static int do_ip_getsockopt(struct sock
76243 int val;
76244 int len;
76245
76246+ pax_track_stack();
76247+
76248 if (level != SOL_IP)
76249 return -EOPNOTSUPP;
76250
76251diff -urNp linux-2.6.39.1/net/ipv4/netfilter/nf_nat_snmp_basic.c linux-2.6.39.1/net/ipv4/netfilter/nf_nat_snmp_basic.c
76252--- linux-2.6.39.1/net/ipv4/netfilter/nf_nat_snmp_basic.c 2011-05-19 00:06:34.000000000 -0400
76253+++ linux-2.6.39.1/net/ipv4/netfilter/nf_nat_snmp_basic.c 2011-05-22 19:36:34.000000000 -0400
76254@@ -399,7 +399,7 @@ static unsigned char asn1_octets_decode(
76255
76256 *len = 0;
76257
76258- *octets = kmalloc(eoc - ctx->pointer, GFP_ATOMIC);
76259+ *octets = kmalloc((eoc - ctx->pointer), GFP_ATOMIC);
76260 if (*octets == NULL) {
76261 if (net_ratelimit())
76262 pr_notice("OOM in bsalg (%d)\n", __LINE__);
76263diff -urNp linux-2.6.39.1/net/ipv4/raw.c linux-2.6.39.1/net/ipv4/raw.c
76264--- linux-2.6.39.1/net/ipv4/raw.c 2011-05-19 00:06:34.000000000 -0400
76265+++ linux-2.6.39.1/net/ipv4/raw.c 2011-05-22 19:41:42.000000000 -0400
76266@@ -302,7 +302,7 @@ static int raw_rcv_skb(struct sock * sk,
76267 int raw_rcv(struct sock *sk, struct sk_buff *skb)
76268 {
76269 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
76270- atomic_inc(&sk->sk_drops);
76271+ atomic_inc_unchecked(&sk->sk_drops);
76272 kfree_skb(skb);
76273 return NET_RX_DROP;
76274 }
76275@@ -730,15 +730,19 @@ static int raw_init(struct sock *sk)
76276
76277 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
76278 {
76279+ struct icmp_filter filter;
76280+
76281 if (optlen > sizeof(struct icmp_filter))
76282 optlen = sizeof(struct icmp_filter);
76283- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
76284+ if (copy_from_user(&filter, optval, optlen))
76285 return -EFAULT;
76286+ memcpy(&raw_sk(sk)->filter, &filter, sizeof(filter));
76287 return 0;
76288 }
76289
76290 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
76291 {
76292+ struct icmp_filter filter;
76293 int len, ret = -EFAULT;
76294
76295 if (get_user(len, optlen))
76296@@ -749,8 +753,9 @@ static int raw_geticmpfilter(struct sock
76297 if (len > sizeof(struct icmp_filter))
76298 len = sizeof(struct icmp_filter);
76299 ret = -EFAULT;
76300+ memcpy(&filter, &raw_sk(sk)->filter, len);
76301 if (put_user(len, optlen) ||
76302- copy_to_user(optval, &raw_sk(sk)->filter, len))
76303+ copy_to_user(optval, &filter, len))
76304 goto out;
76305 ret = 0;
76306 out: return ret;
76307@@ -978,7 +983,13 @@ static void raw_sock_seq_show(struct seq
76308 sk_wmem_alloc_get(sp),
76309 sk_rmem_alloc_get(sp),
76310 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76311- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
76312+ atomic_read(&sp->sk_refcnt),
76313+#ifdef CONFIG_GRKERNSEC_HIDESYM
76314+ NULL,
76315+#else
76316+ sp,
76317+#endif
76318+ atomic_read_unchecked(&sp->sk_drops));
76319 }
76320
76321 static int raw_seq_show(struct seq_file *seq, void *v)
76322diff -urNp linux-2.6.39.1/net/ipv4/route.c linux-2.6.39.1/net/ipv4/route.c
76323--- linux-2.6.39.1/net/ipv4/route.c 2011-05-19 00:06:34.000000000 -0400
76324+++ linux-2.6.39.1/net/ipv4/route.c 2011-05-22 19:36:34.000000000 -0400
76325@@ -303,7 +303,7 @@ static inline unsigned int rt_hash(__be3
76326
76327 static inline int rt_genid(struct net *net)
76328 {
76329- return atomic_read(&net->ipv4.rt_genid);
76330+ return atomic_read_unchecked(&net->ipv4.rt_genid);
76331 }
76332
76333 #ifdef CONFIG_PROC_FS
76334@@ -831,7 +831,7 @@ static void rt_cache_invalidate(struct n
76335 unsigned char shuffle;
76336
76337 get_random_bytes(&shuffle, sizeof(shuffle));
76338- atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
76339+ atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
76340 }
76341
76342 /*
76343@@ -2835,7 +2835,7 @@ static int rt_fill_info(struct net *net,
76344 rt->peer->pmtu_expires - jiffies : 0;
76345 if (rt->peer) {
76346 inet_peer_refcheck(rt->peer);
76347- id = atomic_read(&rt->peer->ip_id_count) & 0xffff;
76348+ id = atomic_read_unchecked(&rt->peer->ip_id_count) & 0xffff;
76349 if (rt->peer->tcp_ts_stamp) {
76350 ts = rt->peer->tcp_ts;
76351 tsage = get_seconds() - rt->peer->tcp_ts_stamp;
76352diff -urNp linux-2.6.39.1/net/ipv4/tcp.c linux-2.6.39.1/net/ipv4/tcp.c
76353--- linux-2.6.39.1/net/ipv4/tcp.c 2011-05-19 00:06:34.000000000 -0400
76354+++ linux-2.6.39.1/net/ipv4/tcp.c 2011-05-22 19:36:34.000000000 -0400
76355@@ -2121,6 +2121,8 @@ static int do_tcp_setsockopt(struct sock
76356 int val;
76357 int err = 0;
76358
76359+ pax_track_stack();
76360+
76361 /* These are data/string values, all the others are ints */
76362 switch (optname) {
76363 case TCP_CONGESTION: {
76364@@ -2500,6 +2502,8 @@ static int do_tcp_getsockopt(struct sock
76365 struct tcp_sock *tp = tcp_sk(sk);
76366 int val, len;
76367
76368+ pax_track_stack();
76369+
76370 if (get_user(len, optlen))
76371 return -EFAULT;
76372
76373diff -urNp linux-2.6.39.1/net/ipv4/tcp_ipv4.c linux-2.6.39.1/net/ipv4/tcp_ipv4.c
76374--- linux-2.6.39.1/net/ipv4/tcp_ipv4.c 2011-05-19 00:06:34.000000000 -0400
76375+++ linux-2.6.39.1/net/ipv4/tcp_ipv4.c 2011-05-22 19:41:42.000000000 -0400
76376@@ -86,6 +86,9 @@ int sysctl_tcp_tw_reuse __read_mostly;
76377 int sysctl_tcp_low_latency __read_mostly;
76378 EXPORT_SYMBOL(sysctl_tcp_low_latency);
76379
76380+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76381+extern int grsec_enable_blackhole;
76382+#endif
76383
76384 #ifdef CONFIG_TCP_MD5SIG
76385 static struct tcp_md5sig_key *tcp_v4_md5_do_lookup(struct sock *sk,
76386@@ -1594,6 +1597,9 @@ int tcp_v4_do_rcv(struct sock *sk, struc
76387 return 0;
76388
76389 reset:
76390+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76391+ if (!grsec_enable_blackhole)
76392+#endif
76393 tcp_v4_send_reset(rsk, skb);
76394 discard:
76395 kfree_skb(skb);
76396@@ -1656,12 +1662,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
76397 TCP_SKB_CB(skb)->sacked = 0;
76398
76399 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
76400- if (!sk)
76401+ if (!sk) {
76402+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76403+ ret = 1;
76404+#endif
76405 goto no_tcp_socket;
76406-
76407+ }
76408 process:
76409- if (sk->sk_state == TCP_TIME_WAIT)
76410+ if (sk->sk_state == TCP_TIME_WAIT) {
76411+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76412+ ret = 2;
76413+#endif
76414 goto do_time_wait;
76415+ }
76416
76417 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
76418 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
76419@@ -1711,6 +1724,10 @@ no_tcp_socket:
76420 bad_packet:
76421 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
76422 } else {
76423+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76424+ if (!grsec_enable_blackhole || (ret == 1 &&
76425+ (skb->dev->flags & IFF_LOOPBACK)))
76426+#endif
76427 tcp_v4_send_reset(NULL, skb);
76428 }
76429
76430@@ -2374,7 +2391,11 @@ static void get_openreq4(struct sock *sk
76431 0, /* non standard timer */
76432 0, /* open_requests have no inode */
76433 atomic_read(&sk->sk_refcnt),
76434+#ifdef CONFIG_GRKERNSEC_HIDESYM
76435+ NULL,
76436+#else
76437 req,
76438+#endif
76439 len);
76440 }
76441
76442@@ -2424,7 +2445,12 @@ static void get_tcp4_sock(struct sock *s
76443 sock_i_uid(sk),
76444 icsk->icsk_probes_out,
76445 sock_i_ino(sk),
76446- atomic_read(&sk->sk_refcnt), sk,
76447+ atomic_read(&sk->sk_refcnt),
76448+#ifdef CONFIG_GRKERNSEC_HIDESYM
76449+ NULL,
76450+#else
76451+ sk,
76452+#endif
76453 jiffies_to_clock_t(icsk->icsk_rto),
76454 jiffies_to_clock_t(icsk->icsk_ack.ato),
76455 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
76456@@ -2452,7 +2478,13 @@ static void get_timewait4_sock(struct in
76457 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p%n",
76458 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
76459 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
76460- atomic_read(&tw->tw_refcnt), tw, len);
76461+ atomic_read(&tw->tw_refcnt),
76462+#ifdef CONFIG_GRKERNSEC_HIDESYM
76463+ NULL,
76464+#else
76465+ tw,
76466+#endif
76467+ len);
76468 }
76469
76470 #define TMPSZ 150
76471diff -urNp linux-2.6.39.1/net/ipv4/tcp_minisocks.c linux-2.6.39.1/net/ipv4/tcp_minisocks.c
76472--- linux-2.6.39.1/net/ipv4/tcp_minisocks.c 2011-05-19 00:06:34.000000000 -0400
76473+++ linux-2.6.39.1/net/ipv4/tcp_minisocks.c 2011-05-22 19:41:42.000000000 -0400
76474@@ -27,6 +27,10 @@
76475 #include <net/inet_common.h>
76476 #include <net/xfrm.h>
76477
76478+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76479+extern int grsec_enable_blackhole;
76480+#endif
76481+
76482 int sysctl_tcp_syncookies __read_mostly = 1;
76483 EXPORT_SYMBOL(sysctl_tcp_syncookies);
76484
76485@@ -745,6 +749,10 @@ listen_overflow:
76486
76487 embryonic_reset:
76488 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
76489+
76490+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76491+ if (!grsec_enable_blackhole)
76492+#endif
76493 if (!(flg & TCP_FLAG_RST))
76494 req->rsk_ops->send_reset(sk, skb);
76495
76496diff -urNp linux-2.6.39.1/net/ipv4/tcp_output.c linux-2.6.39.1/net/ipv4/tcp_output.c
76497--- linux-2.6.39.1/net/ipv4/tcp_output.c 2011-05-19 00:06:34.000000000 -0400
76498+++ linux-2.6.39.1/net/ipv4/tcp_output.c 2011-05-22 19:36:34.000000000 -0400
76499@@ -2421,6 +2421,8 @@ struct sk_buff *tcp_make_synack(struct s
76500 int mss;
76501 int s_data_desired = 0;
76502
76503+ pax_track_stack();
76504+
76505 if (cvp != NULL && cvp->s_data_constant && cvp->s_data_desired)
76506 s_data_desired = cvp->s_data_desired;
76507 skb = sock_wmalloc(sk, MAX_TCP_HEADER + 15 + s_data_desired, 1, GFP_ATOMIC);
76508diff -urNp linux-2.6.39.1/net/ipv4/tcp_probe.c linux-2.6.39.1/net/ipv4/tcp_probe.c
76509--- linux-2.6.39.1/net/ipv4/tcp_probe.c 2011-05-19 00:06:34.000000000 -0400
76510+++ linux-2.6.39.1/net/ipv4/tcp_probe.c 2011-05-22 19:36:34.000000000 -0400
76511@@ -202,7 +202,7 @@ static ssize_t tcpprobe_read(struct file
76512 if (cnt + width >= len)
76513 break;
76514
76515- if (copy_to_user(buf + cnt, tbuf, width))
76516+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
76517 return -EFAULT;
76518 cnt += width;
76519 }
76520diff -urNp linux-2.6.39.1/net/ipv4/tcp_timer.c linux-2.6.39.1/net/ipv4/tcp_timer.c
76521--- linux-2.6.39.1/net/ipv4/tcp_timer.c 2011-05-19 00:06:34.000000000 -0400
76522+++ linux-2.6.39.1/net/ipv4/tcp_timer.c 2011-05-22 19:41:42.000000000 -0400
76523@@ -22,6 +22,10 @@
76524 #include <linux/gfp.h>
76525 #include <net/tcp.h>
76526
76527+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76528+extern int grsec_lastack_retries;
76529+#endif
76530+
76531 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
76532 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
76533 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
76534@@ -199,6 +203,13 @@ static int tcp_write_timeout(struct sock
76535 }
76536 }
76537
76538+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76539+ if ((sk->sk_state == TCP_LAST_ACK) &&
76540+ (grsec_lastack_retries > 0) &&
76541+ (grsec_lastack_retries < retry_until))
76542+ retry_until = grsec_lastack_retries;
76543+#endif
76544+
76545 if (retransmits_timed_out(sk, retry_until,
76546 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
76547 /* Has it gone just too far? */
76548diff -urNp linux-2.6.39.1/net/ipv4/udp.c linux-2.6.39.1/net/ipv4/udp.c
76549--- linux-2.6.39.1/net/ipv4/udp.c 2011-05-19 00:06:34.000000000 -0400
76550+++ linux-2.6.39.1/net/ipv4/udp.c 2011-05-22 19:41:42.000000000 -0400
76551@@ -86,6 +86,7 @@
76552 #include <linux/types.h>
76553 #include <linux/fcntl.h>
76554 #include <linux/module.h>
76555+#include <linux/security.h>
76556 #include <linux/socket.h>
76557 #include <linux/sockios.h>
76558 #include <linux/igmp.h>
76559@@ -107,6 +108,10 @@
76560 #include <net/xfrm.h>
76561 #include "udp_impl.h"
76562
76563+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76564+extern int grsec_enable_blackhole;
76565+#endif
76566+
76567 struct udp_table udp_table __read_mostly;
76568 EXPORT_SYMBOL(udp_table);
76569
76570@@ -564,6 +569,9 @@ found:
76571 return s;
76572 }
76573
76574+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
76575+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
76576+
76577 /*
76578 * This routine is called by the ICMP module when it gets some
76579 * sort of error condition. If err < 0 then the socket should
76580@@ -853,9 +861,18 @@ int udp_sendmsg(struct kiocb *iocb, stru
76581 dport = usin->sin_port;
76582 if (dport == 0)
76583 return -EINVAL;
76584+
76585+ err = gr_search_udp_sendmsg(sk, usin);
76586+ if (err)
76587+ return err;
76588 } else {
76589 if (sk->sk_state != TCP_ESTABLISHED)
76590 return -EDESTADDRREQ;
76591+
76592+ err = gr_search_udp_sendmsg(sk, NULL);
76593+ if (err)
76594+ return err;
76595+
76596 daddr = inet->inet_daddr;
76597 dport = inet->inet_dport;
76598 /* Open fast path for connected socket.
76599@@ -1090,7 +1107,7 @@ static unsigned int first_packet_length(
76600 udp_lib_checksum_complete(skb)) {
76601 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
76602 IS_UDPLITE(sk));
76603- atomic_inc(&sk->sk_drops);
76604+ atomic_inc_unchecked(&sk->sk_drops);
76605 __skb_unlink(skb, rcvq);
76606 __skb_queue_tail(&list_kill, skb);
76607 }
76608@@ -1176,6 +1193,10 @@ try_again:
76609 if (!skb)
76610 goto out;
76611
76612+ err = gr_search_udp_recvmsg(sk, skb);
76613+ if (err)
76614+ goto out_free;
76615+
76616 ulen = skb->len - sizeof(struct udphdr);
76617 if (len > ulen)
76618 len = ulen;
76619@@ -1472,7 +1493,7 @@ int udp_queue_rcv_skb(struct sock *sk, s
76620
76621 drop:
76622 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
76623- atomic_inc(&sk->sk_drops);
76624+ atomic_inc_unchecked(&sk->sk_drops);
76625 kfree_skb(skb);
76626 return -1;
76627 }
76628@@ -1491,7 +1512,7 @@ static void flush_stack(struct sock **st
76629 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
76630
76631 if (!skb1) {
76632- atomic_inc(&sk->sk_drops);
76633+ atomic_inc_unchecked(&sk->sk_drops);
76634 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
76635 IS_UDPLITE(sk));
76636 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
76637@@ -1660,6 +1681,9 @@ int __udp4_lib_rcv(struct sk_buff *skb,
76638 goto csum_error;
76639
76640 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
76641+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76642+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
76643+#endif
76644 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
76645
76646 /*
76647@@ -2087,8 +2111,13 @@ static void udp4_format_sock(struct sock
76648 sk_wmem_alloc_get(sp),
76649 sk_rmem_alloc_get(sp),
76650 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76651- atomic_read(&sp->sk_refcnt), sp,
76652- atomic_read(&sp->sk_drops), len);
76653+ atomic_read(&sp->sk_refcnt),
76654+#ifdef CONFIG_GRKERNSEC_HIDESYM
76655+ NULL,
76656+#else
76657+ sp,
76658+#endif
76659+ atomic_read_unchecked(&sp->sk_drops), len);
76660 }
76661
76662 int udp4_seq_show(struct seq_file *seq, void *v)
76663diff -urNp linux-2.6.39.1/net/ipv6/inet6_connection_sock.c linux-2.6.39.1/net/ipv6/inet6_connection_sock.c
76664--- linux-2.6.39.1/net/ipv6/inet6_connection_sock.c 2011-05-19 00:06:34.000000000 -0400
76665+++ linux-2.6.39.1/net/ipv6/inet6_connection_sock.c 2011-05-22 19:36:34.000000000 -0400
76666@@ -178,7 +178,7 @@ void __inet6_csk_dst_store(struct sock *
76667 #ifdef CONFIG_XFRM
76668 {
76669 struct rt6_info *rt = (struct rt6_info *)dst;
76670- rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
76671+ rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
76672 }
76673 #endif
76674 }
76675@@ -193,7 +193,7 @@ struct dst_entry *__inet6_csk_dst_check(
76676 #ifdef CONFIG_XFRM
76677 if (dst) {
76678 struct rt6_info *rt = (struct rt6_info *)dst;
76679- if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
76680+ if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
76681 __sk_dst_reset(sk);
76682 dst = NULL;
76683 }
76684diff -urNp linux-2.6.39.1/net/ipv6/ipv6_sockglue.c linux-2.6.39.1/net/ipv6/ipv6_sockglue.c
76685--- linux-2.6.39.1/net/ipv6/ipv6_sockglue.c 2011-05-19 00:06:34.000000000 -0400
76686+++ linux-2.6.39.1/net/ipv6/ipv6_sockglue.c 2011-05-22 19:36:34.000000000 -0400
76687@@ -129,6 +129,8 @@ static int do_ipv6_setsockopt(struct soc
76688 int val, valbool;
76689 int retv = -ENOPROTOOPT;
76690
76691+ pax_track_stack();
76692+
76693 if (optval == NULL)
76694 val=0;
76695 else {
76696@@ -919,6 +921,8 @@ static int do_ipv6_getsockopt(struct soc
76697 int len;
76698 int val;
76699
76700+ pax_track_stack();
76701+
76702 if (ip6_mroute_opt(optname))
76703 return ip6_mroute_getsockopt(sk, optname, optval, optlen);
76704
76705diff -urNp linux-2.6.39.1/net/ipv6/raw.c linux-2.6.39.1/net/ipv6/raw.c
76706--- linux-2.6.39.1/net/ipv6/raw.c 2011-05-19 00:06:34.000000000 -0400
76707+++ linux-2.6.39.1/net/ipv6/raw.c 2011-05-22 19:41:42.000000000 -0400
76708@@ -376,7 +376,7 @@ static inline int rawv6_rcv_skb(struct s
76709 {
76710 if ((raw6_sk(sk)->checksum || rcu_dereference_raw(sk->sk_filter)) &&
76711 skb_checksum_complete(skb)) {
76712- atomic_inc(&sk->sk_drops);
76713+ atomic_inc_unchecked(&sk->sk_drops);
76714 kfree_skb(skb);
76715 return NET_RX_DROP;
76716 }
76717@@ -403,7 +403,7 @@ int rawv6_rcv(struct sock *sk, struct sk
76718 struct raw6_sock *rp = raw6_sk(sk);
76719
76720 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
76721- atomic_inc(&sk->sk_drops);
76722+ atomic_inc_unchecked(&sk->sk_drops);
76723 kfree_skb(skb);
76724 return NET_RX_DROP;
76725 }
76726@@ -427,7 +427,7 @@ int rawv6_rcv(struct sock *sk, struct sk
76727
76728 if (inet->hdrincl) {
76729 if (skb_checksum_complete(skb)) {
76730- atomic_inc(&sk->sk_drops);
76731+ atomic_inc_unchecked(&sk->sk_drops);
76732 kfree_skb(skb);
76733 return NET_RX_DROP;
76734 }
76735@@ -601,7 +601,7 @@ out:
76736 return err;
76737 }
76738
76739-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
76740+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
76741 struct flowi6 *fl6, struct dst_entry **dstp,
76742 unsigned int flags)
76743 {
76744@@ -742,6 +742,8 @@ static int rawv6_sendmsg(struct kiocb *i
76745 u16 proto;
76746 int err;
76747
76748+ pax_track_stack();
76749+
76750 /* Rough check on arithmetic overflow,
76751 better check is made in ip6_append_data().
76752 */
76753@@ -909,12 +911,15 @@ do_confirm:
76754 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
76755 char __user *optval, int optlen)
76756 {
76757+ struct icmp6_filter filter;
76758+
76759 switch (optname) {
76760 case ICMPV6_FILTER:
76761 if (optlen > sizeof(struct icmp6_filter))
76762 optlen = sizeof(struct icmp6_filter);
76763- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
76764+ if (copy_from_user(&filter, optval, optlen))
76765 return -EFAULT;
76766+ memcpy(&raw6_sk(sk)->filter, &filter, optlen);
76767 return 0;
76768 default:
76769 return -ENOPROTOOPT;
76770@@ -926,6 +931,7 @@ static int rawv6_seticmpfilter(struct so
76771 static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
76772 char __user *optval, int __user *optlen)
76773 {
76774+ struct icmp6_filter filter;
76775 int len;
76776
76777 switch (optname) {
76778@@ -938,7 +944,8 @@ static int rawv6_geticmpfilter(struct so
76779 len = sizeof(struct icmp6_filter);
76780 if (put_user(len, optlen))
76781 return -EFAULT;
76782- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
76783+ memcpy(&filter, &raw6_sk(sk)->filter, len);
76784+ if (copy_to_user(optval, &filter, len))
76785 return -EFAULT;
76786 return 0;
76787 default:
76788@@ -1252,7 +1259,13 @@ static void raw6_sock_seq_show(struct se
76789 0, 0L, 0,
76790 sock_i_uid(sp), 0,
76791 sock_i_ino(sp),
76792- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
76793+ atomic_read(&sp->sk_refcnt),
76794+#ifdef CONFIG_GRKERNSEC_HIDESYM
76795+ NULL,
76796+#else
76797+ sp,
76798+#endif
76799+ atomic_read_unchecked(&sp->sk_drops));
76800 }
76801
76802 static int raw6_seq_show(struct seq_file *seq, void *v)
76803diff -urNp linux-2.6.39.1/net/ipv6/tcp_ipv6.c linux-2.6.39.1/net/ipv6/tcp_ipv6.c
76804--- linux-2.6.39.1/net/ipv6/tcp_ipv6.c 2011-05-19 00:06:34.000000000 -0400
76805+++ linux-2.6.39.1/net/ipv6/tcp_ipv6.c 2011-05-22 19:41:42.000000000 -0400
76806@@ -92,6 +92,10 @@ static struct tcp_md5sig_key *tcp_v6_md5
76807 }
76808 #endif
76809
76810+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76811+extern int grsec_enable_blackhole;
76812+#endif
76813+
76814 static void tcp_v6_hash(struct sock *sk)
76815 {
76816 if (sk->sk_state != TCP_CLOSE) {
76817@@ -1660,6 +1664,9 @@ static int tcp_v6_do_rcv(struct sock *sk
76818 return 0;
76819
76820 reset:
76821+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76822+ if (!grsec_enable_blackhole)
76823+#endif
76824 tcp_v6_send_reset(sk, skb);
76825 discard:
76826 if (opt_skb)
76827@@ -1739,12 +1746,20 @@ static int tcp_v6_rcv(struct sk_buff *sk
76828 TCP_SKB_CB(skb)->sacked = 0;
76829
76830 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
76831- if (!sk)
76832+ if (!sk) {
76833+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76834+ ret = 1;
76835+#endif
76836 goto no_tcp_socket;
76837+ }
76838
76839 process:
76840- if (sk->sk_state == TCP_TIME_WAIT)
76841+ if (sk->sk_state == TCP_TIME_WAIT) {
76842+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76843+ ret = 2;
76844+#endif
76845 goto do_time_wait;
76846+ }
76847
76848 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
76849 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
76850@@ -1792,6 +1807,10 @@ no_tcp_socket:
76851 bad_packet:
76852 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
76853 } else {
76854+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76855+ if (!grsec_enable_blackhole || (ret == 1 &&
76856+ (skb->dev->flags & IFF_LOOPBACK)))
76857+#endif
76858 tcp_v6_send_reset(NULL, skb);
76859 }
76860
76861@@ -2052,7 +2071,13 @@ static void get_openreq6(struct seq_file
76862 uid,
76863 0, /* non standard timer */
76864 0, /* open_requests have no inode */
76865- 0, req);
76866+ 0,
76867+#ifdef CONFIG_GRKERNSEC_HIDESYM
76868+ NULL
76869+#else
76870+ req
76871+#endif
76872+ );
76873 }
76874
76875 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
76876@@ -2102,7 +2127,12 @@ static void get_tcp6_sock(struct seq_fil
76877 sock_i_uid(sp),
76878 icsk->icsk_probes_out,
76879 sock_i_ino(sp),
76880- atomic_read(&sp->sk_refcnt), sp,
76881+ atomic_read(&sp->sk_refcnt),
76882+#ifdef CONFIG_GRKERNSEC_HIDESYM
76883+ NULL,
76884+#else
76885+ sp,
76886+#endif
76887 jiffies_to_clock_t(icsk->icsk_rto),
76888 jiffies_to_clock_t(icsk->icsk_ack.ato),
76889 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
76890@@ -2137,7 +2167,13 @@ static void get_timewait6_sock(struct se
76891 dest->s6_addr32[2], dest->s6_addr32[3], destp,
76892 tw->tw_substate, 0, 0,
76893 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
76894- atomic_read(&tw->tw_refcnt), tw);
76895+ atomic_read(&tw->tw_refcnt),
76896+#ifdef CONFIG_GRKERNSEC_HIDESYM
76897+ NULL
76898+#else
76899+ tw
76900+#endif
76901+ );
76902 }
76903
76904 static int tcp6_seq_show(struct seq_file *seq, void *v)
76905diff -urNp linux-2.6.39.1/net/ipv6/udp.c linux-2.6.39.1/net/ipv6/udp.c
76906--- linux-2.6.39.1/net/ipv6/udp.c 2011-05-19 00:06:34.000000000 -0400
76907+++ linux-2.6.39.1/net/ipv6/udp.c 2011-05-22 19:41:42.000000000 -0400
76908@@ -50,6 +50,10 @@
76909 #include <linux/seq_file.h>
76910 #include "udp_impl.h"
76911
76912+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76913+extern int grsec_enable_blackhole;
76914+#endif
76915+
76916 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
76917 {
76918 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
76919@@ -545,7 +549,7 @@ int udpv6_queue_rcv_skb(struct sock * sk
76920
76921 return 0;
76922 drop:
76923- atomic_inc(&sk->sk_drops);
76924+ atomic_inc_unchecked(&sk->sk_drops);
76925 drop_no_sk_drops_inc:
76926 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
76927 kfree_skb(skb);
76928@@ -621,7 +625,7 @@ static void flush_stack(struct sock **st
76929 continue;
76930 }
76931 drop:
76932- atomic_inc(&sk->sk_drops);
76933+ atomic_inc_unchecked(&sk->sk_drops);
76934 UDP6_INC_STATS_BH(sock_net(sk),
76935 UDP_MIB_RCVBUFERRORS, IS_UDPLITE(sk));
76936 UDP6_INC_STATS_BH(sock_net(sk),
76937@@ -776,6 +780,9 @@ int __udp6_lib_rcv(struct sk_buff *skb,
76938 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS,
76939 proto == IPPROTO_UDPLITE);
76940
76941+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76942+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
76943+#endif
76944 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
76945
76946 kfree_skb(skb);
76947@@ -792,7 +799,7 @@ int __udp6_lib_rcv(struct sk_buff *skb,
76948 if (!sock_owned_by_user(sk))
76949 udpv6_queue_rcv_skb(sk, skb);
76950 else if (sk_add_backlog(sk, skb)) {
76951- atomic_inc(&sk->sk_drops);
76952+ atomic_inc_unchecked(&sk->sk_drops);
76953 bh_unlock_sock(sk);
76954 sock_put(sk);
76955 goto discard;
76956@@ -1403,8 +1410,13 @@ static void udp6_sock_seq_show(struct se
76957 0, 0L, 0,
76958 sock_i_uid(sp), 0,
76959 sock_i_ino(sp),
76960- atomic_read(&sp->sk_refcnt), sp,
76961- atomic_read(&sp->sk_drops));
76962+ atomic_read(&sp->sk_refcnt),
76963+#ifdef CONFIG_GRKERNSEC_HIDESYM
76964+ NULL,
76965+#else
76966+ sp,
76967+#endif
76968+ atomic_read_unchecked(&sp->sk_drops));
76969 }
76970
76971 int udp6_seq_show(struct seq_file *seq, void *v)
76972diff -urNp linux-2.6.39.1/net/irda/ircomm/ircomm_tty.c linux-2.6.39.1/net/irda/ircomm/ircomm_tty.c
76973--- linux-2.6.39.1/net/irda/ircomm/ircomm_tty.c 2011-05-19 00:06:34.000000000 -0400
76974+++ linux-2.6.39.1/net/irda/ircomm/ircomm_tty.c 2011-05-22 19:36:34.000000000 -0400
76975@@ -281,16 +281,16 @@ static int ircomm_tty_block_til_ready(st
76976 add_wait_queue(&self->open_wait, &wait);
76977
76978 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
76979- __FILE__,__LINE__, tty->driver->name, self->open_count );
76980+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
76981
76982 /* As far as I can see, we protect open_count - Jean II */
76983 spin_lock_irqsave(&self->spinlock, flags);
76984 if (!tty_hung_up_p(filp)) {
76985 extra_count = 1;
76986- self->open_count--;
76987+ local_dec(&self->open_count);
76988 }
76989 spin_unlock_irqrestore(&self->spinlock, flags);
76990- self->blocked_open++;
76991+ local_inc(&self->blocked_open);
76992
76993 while (1) {
76994 if (tty->termios->c_cflag & CBAUD) {
76995@@ -330,7 +330,7 @@ static int ircomm_tty_block_til_ready(st
76996 }
76997
76998 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
76999- __FILE__,__LINE__, tty->driver->name, self->open_count );
77000+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
77001
77002 schedule();
77003 }
77004@@ -341,13 +341,13 @@ static int ircomm_tty_block_til_ready(st
77005 if (extra_count) {
77006 /* ++ is not atomic, so this should be protected - Jean II */
77007 spin_lock_irqsave(&self->spinlock, flags);
77008- self->open_count++;
77009+ local_inc(&self->open_count);
77010 spin_unlock_irqrestore(&self->spinlock, flags);
77011 }
77012- self->blocked_open--;
77013+ local_dec(&self->blocked_open);
77014
77015 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
77016- __FILE__,__LINE__, tty->driver->name, self->open_count);
77017+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
77018
77019 if (!retval)
77020 self->flags |= ASYNC_NORMAL_ACTIVE;
77021@@ -416,14 +416,14 @@ static int ircomm_tty_open(struct tty_st
77022 }
77023 /* ++ is not atomic, so this should be protected - Jean II */
77024 spin_lock_irqsave(&self->spinlock, flags);
77025- self->open_count++;
77026+ local_inc(&self->open_count);
77027
77028 tty->driver_data = self;
77029 self->tty = tty;
77030 spin_unlock_irqrestore(&self->spinlock, flags);
77031
77032 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
77033- self->line, self->open_count);
77034+ self->line, local_read(&self->open_count));
77035
77036 /* Not really used by us, but lets do it anyway */
77037 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
77038@@ -509,7 +509,7 @@ static void ircomm_tty_close(struct tty_
77039 return;
77040 }
77041
77042- if ((tty->count == 1) && (self->open_count != 1)) {
77043+ if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
77044 /*
77045 * Uh, oh. tty->count is 1, which means that the tty
77046 * structure will be freed. state->count should always
77047@@ -519,16 +519,16 @@ static void ircomm_tty_close(struct tty_
77048 */
77049 IRDA_DEBUG(0, "%s(), bad serial port count; "
77050 "tty->count is 1, state->count is %d\n", __func__ ,
77051- self->open_count);
77052- self->open_count = 1;
77053+ local_read(&self->open_count));
77054+ local_set(&self->open_count, 1);
77055 }
77056
77057- if (--self->open_count < 0) {
77058+ if (local_dec_return(&self->open_count) < 0) {
77059 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
77060- __func__, self->line, self->open_count);
77061- self->open_count = 0;
77062+ __func__, self->line, local_read(&self->open_count));
77063+ local_set(&self->open_count, 0);
77064 }
77065- if (self->open_count) {
77066+ if (local_read(&self->open_count)) {
77067 spin_unlock_irqrestore(&self->spinlock, flags);
77068
77069 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
77070@@ -560,7 +560,7 @@ static void ircomm_tty_close(struct tty_
77071 tty->closing = 0;
77072 self->tty = NULL;
77073
77074- if (self->blocked_open) {
77075+ if (local_read(&self->blocked_open)) {
77076 if (self->close_delay)
77077 schedule_timeout_interruptible(self->close_delay);
77078 wake_up_interruptible(&self->open_wait);
77079@@ -1012,7 +1012,7 @@ static void ircomm_tty_hangup(struct tty
77080 spin_lock_irqsave(&self->spinlock, flags);
77081 self->flags &= ~ASYNC_NORMAL_ACTIVE;
77082 self->tty = NULL;
77083- self->open_count = 0;
77084+ local_set(&self->open_count, 0);
77085 spin_unlock_irqrestore(&self->spinlock, flags);
77086
77087 wake_up_interruptible(&self->open_wait);
77088@@ -1364,7 +1364,7 @@ static void ircomm_tty_line_info(struct
77089 seq_putc(m, '\n');
77090
77091 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
77092- seq_printf(m, "Open count: %d\n", self->open_count);
77093+ seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
77094 seq_printf(m, "Max data size: %d\n", self->max_data_size);
77095 seq_printf(m, "Max header size: %d\n", self->max_header_size);
77096
77097diff -urNp linux-2.6.39.1/net/iucv/af_iucv.c linux-2.6.39.1/net/iucv/af_iucv.c
77098--- linux-2.6.39.1/net/iucv/af_iucv.c 2011-05-19 00:06:34.000000000 -0400
77099+++ linux-2.6.39.1/net/iucv/af_iucv.c 2011-05-22 19:36:34.000000000 -0400
77100@@ -653,10 +653,10 @@ static int iucv_sock_autobind(struct soc
77101
77102 write_lock_bh(&iucv_sk_list.lock);
77103
77104- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
77105+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
77106 while (__iucv_get_sock_by_name(name)) {
77107 sprintf(name, "%08x",
77108- atomic_inc_return(&iucv_sk_list.autobind_name));
77109+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
77110 }
77111
77112 write_unlock_bh(&iucv_sk_list.lock);
77113diff -urNp linux-2.6.39.1/net/key/af_key.c linux-2.6.39.1/net/key/af_key.c
77114--- linux-2.6.39.1/net/key/af_key.c 2011-05-19 00:06:34.000000000 -0400
77115+++ linux-2.6.39.1/net/key/af_key.c 2011-05-22 19:41:42.000000000 -0400
77116@@ -2481,6 +2481,8 @@ static int pfkey_migrate(struct sock *sk
77117 struct xfrm_migrate m[XFRM_MAX_DEPTH];
77118 struct xfrm_kmaddress k;
77119
77120+ pax_track_stack();
77121+
77122 if (!present_and_same_family(ext_hdrs[SADB_EXT_ADDRESS_SRC - 1],
77123 ext_hdrs[SADB_EXT_ADDRESS_DST - 1]) ||
77124 !ext_hdrs[SADB_X_EXT_POLICY - 1]) {
77125@@ -3016,10 +3018,10 @@ static int pfkey_send_policy_notify(stru
77126 static u32 get_acqseq(void)
77127 {
77128 u32 res;
77129- static atomic_t acqseq;
77130+ static atomic_unchecked_t acqseq;
77131
77132 do {
77133- res = atomic_inc_return(&acqseq);
77134+ res = atomic_inc_return_unchecked(&acqseq);
77135 } while (!res);
77136 return res;
77137 }
77138@@ -3657,7 +3659,11 @@ static int pfkey_seq_show(struct seq_fil
77139 seq_printf(f ,"sk RefCnt Rmem Wmem User Inode\n");
77140 else
77141 seq_printf(f ,"%p %-6d %-6u %-6u %-6u %-6lu\n",
77142+#ifdef CONFIG_GRKERNSEC_HIDESYM
77143+ NULL,
77144+#else
77145 s,
77146+#endif
77147 atomic_read(&s->sk_refcnt),
77148 sk_rmem_alloc_get(s),
77149 sk_wmem_alloc_get(s),
77150diff -urNp linux-2.6.39.1/net/l2tp/l2tp_ip.c linux-2.6.39.1/net/l2tp/l2tp_ip.c
77151--- linux-2.6.39.1/net/l2tp/l2tp_ip.c 2011-05-19 00:06:34.000000000 -0400
77152+++ linux-2.6.39.1/net/l2tp/l2tp_ip.c 2011-05-22 19:36:34.000000000 -0400
77153@@ -625,7 +625,7 @@ static struct inet_protosw l2tp_ip_proto
77154 .no_check = 0,
77155 };
77156
77157-static struct net_protocol l2tp_ip_protocol __read_mostly = {
77158+static const struct net_protocol l2tp_ip_protocol = {
77159 .handler = l2tp_ip_recv,
77160 };
77161
77162diff -urNp linux-2.6.39.1/net/lapb/lapb_iface.c linux-2.6.39.1/net/lapb/lapb_iface.c
77163--- linux-2.6.39.1/net/lapb/lapb_iface.c 2011-05-19 00:06:34.000000000 -0400
77164+++ linux-2.6.39.1/net/lapb/lapb_iface.c 2011-05-22 19:36:34.000000000 -0400
77165@@ -138,8 +138,7 @@ static struct lapb_cb *lapb_create_cb(vo
77166 out:
77167 return lapb;
77168 }
77169-
77170-int lapb_register(struct net_device *dev, struct lapb_register_struct *callbacks)
77171+int lapb_register(struct net_device *dev, const struct lapb_register_struct *callbacks)
77172 {
77173 struct lapb_cb *lapb;
77174 int rc = LAPB_BADTOKEN;
77175diff -urNp linux-2.6.39.1/net/mac80211/cfg.c linux-2.6.39.1/net/mac80211/cfg.c
77176--- linux-2.6.39.1/net/mac80211/cfg.c 2011-06-03 00:04:14.000000000 -0400
77177+++ linux-2.6.39.1/net/mac80211/cfg.c 2011-06-03 00:32:08.000000000 -0400
77178@@ -2031,7 +2031,7 @@ static void ieee80211_get_ringparam(stru
77179 drv_get_ringparam(local, tx, tx_max, rx, rx_max);
77180 }
77181
77182-struct cfg80211_ops mac80211_config_ops = {
77183+const struct cfg80211_ops mac80211_config_ops = {
77184 .add_virtual_intf = ieee80211_add_iface,
77185 .del_virtual_intf = ieee80211_del_iface,
77186 .change_virtual_intf = ieee80211_change_iface,
77187diff -urNp linux-2.6.39.1/net/mac80211/cfg.h linux-2.6.39.1/net/mac80211/cfg.h
77188--- linux-2.6.39.1/net/mac80211/cfg.h 2011-05-19 00:06:34.000000000 -0400
77189+++ linux-2.6.39.1/net/mac80211/cfg.h 2011-05-22 19:36:34.000000000 -0400
77190@@ -4,6 +4,6 @@
77191 #ifndef __CFG_H
77192 #define __CFG_H
77193
77194-extern struct cfg80211_ops mac80211_config_ops;
77195+extern const struct cfg80211_ops mac80211_config_ops;
77196
77197 #endif /* __CFG_H */
77198diff -urNp linux-2.6.39.1/net/mac80211/debugfs_sta.c linux-2.6.39.1/net/mac80211/debugfs_sta.c
77199--- linux-2.6.39.1/net/mac80211/debugfs_sta.c 2011-05-19 00:06:34.000000000 -0400
77200+++ linux-2.6.39.1/net/mac80211/debugfs_sta.c 2011-05-22 19:36:34.000000000 -0400
77201@@ -115,6 +115,8 @@ static ssize_t sta_agg_status_read(struc
77202 struct tid_ampdu_rx *tid_rx;
77203 struct tid_ampdu_tx *tid_tx;
77204
77205+ pax_track_stack();
77206+
77207 rcu_read_lock();
77208
77209 p += scnprintf(p, sizeof(buf) + buf - p, "next dialog_token: %#02x\n",
77210@@ -215,6 +217,8 @@ static ssize_t sta_ht_capa_read(struct f
77211 struct sta_info *sta = file->private_data;
77212 struct ieee80211_sta_ht_cap *htc = &sta->sta.ht_cap;
77213
77214+ pax_track_stack();
77215+
77216 p += scnprintf(p, sizeof(buf) + buf - p, "ht %ssupported\n",
77217 htc->ht_supported ? "" : "not ");
77218 if (htc->ht_supported) {
77219diff -urNp linux-2.6.39.1/net/mac80211/ieee80211_i.h linux-2.6.39.1/net/mac80211/ieee80211_i.h
77220--- linux-2.6.39.1/net/mac80211/ieee80211_i.h 2011-05-19 00:06:34.000000000 -0400
77221+++ linux-2.6.39.1/net/mac80211/ieee80211_i.h 2011-05-22 19:36:34.000000000 -0400
77222@@ -27,6 +27,7 @@
77223 #include <net/ieee80211_radiotap.h>
77224 #include <net/cfg80211.h>
77225 #include <net/mac80211.h>
77226+#include <asm/local.h>
77227 #include "key.h"
77228 #include "sta_info.h"
77229
77230@@ -714,7 +715,7 @@ struct ieee80211_local {
77231 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
77232 spinlock_t queue_stop_reason_lock;
77233
77234- int open_count;
77235+ local_t open_count;
77236 int monitors, cooked_mntrs;
77237 /* number of interfaces with corresponding FIF_ flags */
77238 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
77239diff -urNp linux-2.6.39.1/net/mac80211/iface.c linux-2.6.39.1/net/mac80211/iface.c
77240--- linux-2.6.39.1/net/mac80211/iface.c 2011-05-19 00:06:34.000000000 -0400
77241+++ linux-2.6.39.1/net/mac80211/iface.c 2011-05-22 19:36:34.000000000 -0400
77242@@ -211,7 +211,7 @@ static int ieee80211_do_open(struct net_
77243 break;
77244 }
77245
77246- if (local->open_count == 0) {
77247+ if (local_read(&local->open_count) == 0) {
77248 res = drv_start(local);
77249 if (res)
77250 goto err_del_bss;
77251@@ -235,7 +235,7 @@ static int ieee80211_do_open(struct net_
77252 memcpy(dev->perm_addr, dev->dev_addr, ETH_ALEN);
77253
77254 if (!is_valid_ether_addr(dev->dev_addr)) {
77255- if (!local->open_count)
77256+ if (!local_read(&local->open_count))
77257 drv_stop(local);
77258 return -EADDRNOTAVAIL;
77259 }
77260@@ -327,7 +327,7 @@ static int ieee80211_do_open(struct net_
77261 mutex_unlock(&local->mtx);
77262
77263 if (coming_up)
77264- local->open_count++;
77265+ local_inc(&local->open_count);
77266
77267 if (hw_reconf_flags) {
77268 ieee80211_hw_config(local, hw_reconf_flags);
77269@@ -347,7 +347,7 @@ static int ieee80211_do_open(struct net_
77270 err_del_interface:
77271 drv_remove_interface(local, &sdata->vif);
77272 err_stop:
77273- if (!local->open_count)
77274+ if (!local_read(&local->open_count))
77275 drv_stop(local);
77276 err_del_bss:
77277 sdata->bss = NULL;
77278@@ -474,7 +474,7 @@ static void ieee80211_do_stop(struct iee
77279 }
77280
77281 if (going_down)
77282- local->open_count--;
77283+ local_dec(&local->open_count);
77284
77285 switch (sdata->vif.type) {
77286 case NL80211_IFTYPE_AP_VLAN:
77287@@ -533,7 +533,7 @@ static void ieee80211_do_stop(struct iee
77288
77289 ieee80211_recalc_ps(local, -1);
77290
77291- if (local->open_count == 0) {
77292+ if (local_read(&local->open_count) == 0) {
77293 if (local->ops->napi_poll)
77294 napi_disable(&local->napi);
77295 ieee80211_clear_tx_pending(local);
77296diff -urNp linux-2.6.39.1/net/mac80211/main.c linux-2.6.39.1/net/mac80211/main.c
77297--- linux-2.6.39.1/net/mac80211/main.c 2011-05-19 00:06:34.000000000 -0400
77298+++ linux-2.6.39.1/net/mac80211/main.c 2011-05-22 19:36:34.000000000 -0400
77299@@ -215,7 +215,7 @@ int ieee80211_hw_config(struct ieee80211
77300 local->hw.conf.power_level = power;
77301 }
77302
77303- if (changed && local->open_count) {
77304+ if (changed && local_read(&local->open_count)) {
77305 ret = drv_config(local, changed);
77306 /*
77307 * Goal:
77308diff -urNp linux-2.6.39.1/net/mac80211/mlme.c linux-2.6.39.1/net/mac80211/mlme.c
77309--- linux-2.6.39.1/net/mac80211/mlme.c 2011-06-03 00:04:14.000000000 -0400
77310+++ linux-2.6.39.1/net/mac80211/mlme.c 2011-06-03 00:32:08.000000000 -0400
77311@@ -1431,6 +1431,8 @@ static bool ieee80211_assoc_success(stru
77312 bool have_higher_than_11mbit = false;
77313 u16 ap_ht_cap_flags;
77314
77315+ pax_track_stack();
77316+
77317 /* AssocResp and ReassocResp have identical structure */
77318
77319 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
77320diff -urNp linux-2.6.39.1/net/mac80211/pm.c linux-2.6.39.1/net/mac80211/pm.c
77321--- linux-2.6.39.1/net/mac80211/pm.c 2011-05-19 00:06:34.000000000 -0400
77322+++ linux-2.6.39.1/net/mac80211/pm.c 2011-05-22 19:36:34.000000000 -0400
77323@@ -95,7 +95,7 @@ int __ieee80211_suspend(struct ieee80211
77324 }
77325
77326 /* stop hardware - this must stop RX */
77327- if (local->open_count)
77328+ if (local_read(&local->open_count))
77329 ieee80211_stop_device(local);
77330
77331 local->suspended = true;
77332diff -urNp linux-2.6.39.1/net/mac80211/rate.c linux-2.6.39.1/net/mac80211/rate.c
77333--- linux-2.6.39.1/net/mac80211/rate.c 2011-05-19 00:06:34.000000000 -0400
77334+++ linux-2.6.39.1/net/mac80211/rate.c 2011-05-22 19:36:34.000000000 -0400
77335@@ -371,7 +371,7 @@ int ieee80211_init_rate_ctrl_alg(struct
77336
77337 ASSERT_RTNL();
77338
77339- if (local->open_count)
77340+ if (local_read(&local->open_count))
77341 return -EBUSY;
77342
77343 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
77344diff -urNp linux-2.6.39.1/net/mac80211/rc80211_pid_debugfs.c linux-2.6.39.1/net/mac80211/rc80211_pid_debugfs.c
77345--- linux-2.6.39.1/net/mac80211/rc80211_pid_debugfs.c 2011-05-19 00:06:34.000000000 -0400
77346+++ linux-2.6.39.1/net/mac80211/rc80211_pid_debugfs.c 2011-05-22 19:36:34.000000000 -0400
77347@@ -192,7 +192,7 @@ static ssize_t rate_control_pid_events_r
77348
77349 spin_unlock_irqrestore(&events->lock, status);
77350
77351- if (copy_to_user(buf, pb, p))
77352+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
77353 return -EFAULT;
77354
77355 return p;
77356diff -urNp linux-2.6.39.1/net/mac80211/util.c linux-2.6.39.1/net/mac80211/util.c
77357--- linux-2.6.39.1/net/mac80211/util.c 2011-05-19 00:06:34.000000000 -0400
77358+++ linux-2.6.39.1/net/mac80211/util.c 2011-05-22 19:36:34.000000000 -0400
77359@@ -1129,7 +1129,7 @@ int ieee80211_reconfig(struct ieee80211_
77360 local->resuming = true;
77361
77362 /* restart hardware */
77363- if (local->open_count) {
77364+ if (local_read(&local->open_count)) {
77365 /*
77366 * Upon resume hardware can sometimes be goofy due to
77367 * various platform / driver / bus issues, so restarting
77368diff -urNp linux-2.6.39.1/net/netfilter/ipvs/ip_vs_conn.c linux-2.6.39.1/net/netfilter/ipvs/ip_vs_conn.c
77369--- linux-2.6.39.1/net/netfilter/ipvs/ip_vs_conn.c 2011-05-19 00:06:34.000000000 -0400
77370+++ linux-2.6.39.1/net/netfilter/ipvs/ip_vs_conn.c 2011-05-22 19:36:34.000000000 -0400
77371@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, s
77372 /* Increase the refcnt counter of the dest */
77373 atomic_inc(&dest->refcnt);
77374
77375- conn_flags = atomic_read(&dest->conn_flags);
77376+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
77377 if (cp->protocol != IPPROTO_UDP)
77378 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
77379 /* Bind with the destination and its corresponding transmitter */
77380@@ -861,7 +861,7 @@ ip_vs_conn_new(const struct ip_vs_conn_p
77381 atomic_set(&cp->refcnt, 1);
77382
77383 atomic_set(&cp->n_control, 0);
77384- atomic_set(&cp->in_pkts, 0);
77385+ atomic_set_unchecked(&cp->in_pkts, 0);
77386
77387 atomic_inc(&ipvs->conn_count);
77388 if (flags & IP_VS_CONN_F_NO_CPORT)
77389@@ -1141,7 +1141,7 @@ static inline int todrop_entry(struct ip
77390
77391 /* Don't drop the entry if its number of incoming packets is not
77392 located in [0, 8] */
77393- i = atomic_read(&cp->in_pkts);
77394+ i = atomic_read_unchecked(&cp->in_pkts);
77395 if (i > 8 || i < 0) return 0;
77396
77397 if (!todrop_rate[i]) return 0;
77398diff -urNp linux-2.6.39.1/net/netfilter/ipvs/ip_vs_core.c linux-2.6.39.1/net/netfilter/ipvs/ip_vs_core.c
77399--- linux-2.6.39.1/net/netfilter/ipvs/ip_vs_core.c 2011-05-19 00:06:34.000000000 -0400
77400+++ linux-2.6.39.1/net/netfilter/ipvs/ip_vs_core.c 2011-05-22 19:36:34.000000000 -0400
77401@@ -563,7 +563,7 @@ int ip_vs_leave(struct ip_vs_service *sv
77402 ret = cp->packet_xmit(skb, cp, pd->pp);
77403 /* do not touch skb anymore */
77404
77405- atomic_inc(&cp->in_pkts);
77406+ atomic_inc_unchecked(&cp->in_pkts);
77407 ip_vs_conn_put(cp);
77408 return ret;
77409 }
77410@@ -1633,7 +1633,7 @@ ip_vs_in(unsigned int hooknum, struct sk
77411 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
77412 pkts = sysctl_sync_threshold(ipvs);
77413 else
77414- pkts = atomic_add_return(1, &cp->in_pkts);
77415+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
77416
77417 if ((ipvs->sync_state & IP_VS_STATE_MASTER) &&
77418 cp->protocol == IPPROTO_SCTP) {
77419diff -urNp linux-2.6.39.1/net/netfilter/ipvs/ip_vs_ctl.c linux-2.6.39.1/net/netfilter/ipvs/ip_vs_ctl.c
77420--- linux-2.6.39.1/net/netfilter/ipvs/ip_vs_ctl.c 2011-05-19 00:06:34.000000000 -0400
77421+++ linux-2.6.39.1/net/netfilter/ipvs/ip_vs_ctl.c 2011-05-22 19:36:34.000000000 -0400
77422@@ -782,7 +782,7 @@ __ip_vs_update_dest(struct ip_vs_service
77423 ip_vs_rs_hash(ipvs, dest);
77424 write_unlock_bh(&ipvs->rs_lock);
77425 }
77426- atomic_set(&dest->conn_flags, conn_flags);
77427+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
77428
77429 /* bind the service */
77430 if (!dest->svc) {
77431@@ -2027,7 +2027,7 @@ static int ip_vs_info_seq_show(struct se
77432 " %-7s %-6d %-10d %-10d\n",
77433 &dest->addr.in6,
77434 ntohs(dest->port),
77435- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
77436+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
77437 atomic_read(&dest->weight),
77438 atomic_read(&dest->activeconns),
77439 atomic_read(&dest->inactconns));
77440@@ -2038,7 +2038,7 @@ static int ip_vs_info_seq_show(struct se
77441 "%-7s %-6d %-10d %-10d\n",
77442 ntohl(dest->addr.ip),
77443 ntohs(dest->port),
77444- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
77445+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
77446 atomic_read(&dest->weight),
77447 atomic_read(&dest->activeconns),
77448 atomic_read(&dest->inactconns));
77449@@ -2287,6 +2287,8 @@ do_ip_vs_set_ctl(struct sock *sk, int cm
77450 struct ip_vs_dest_user *udest_compat;
77451 struct ip_vs_dest_user_kern udest;
77452
77453+ pax_track_stack();
77454+
77455 if (!capable(CAP_NET_ADMIN))
77456 return -EPERM;
77457
77458@@ -2501,7 +2503,7 @@ __ip_vs_get_dest_entries(struct net *net
77459
77460 entry.addr = dest->addr.ip;
77461 entry.port = dest->port;
77462- entry.conn_flags = atomic_read(&dest->conn_flags);
77463+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
77464 entry.weight = atomic_read(&dest->weight);
77465 entry.u_threshold = dest->u_threshold;
77466 entry.l_threshold = dest->l_threshold;
77467@@ -3029,7 +3031,7 @@ static int ip_vs_genl_fill_dest(struct s
77468 NLA_PUT_U16(skb, IPVS_DEST_ATTR_PORT, dest->port);
77469
77470 NLA_PUT_U32(skb, IPVS_DEST_ATTR_FWD_METHOD,
77471- atomic_read(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
77472+ atomic_read_unchecked(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
77473 NLA_PUT_U32(skb, IPVS_DEST_ATTR_WEIGHT, atomic_read(&dest->weight));
77474 NLA_PUT_U32(skb, IPVS_DEST_ATTR_U_THRESH, dest->u_threshold);
77475 NLA_PUT_U32(skb, IPVS_DEST_ATTR_L_THRESH, dest->l_threshold);
77476diff -urNp linux-2.6.39.1/net/netfilter/ipvs/ip_vs_sync.c linux-2.6.39.1/net/netfilter/ipvs/ip_vs_sync.c
77477--- linux-2.6.39.1/net/netfilter/ipvs/ip_vs_sync.c 2011-05-19 00:06:34.000000000 -0400
77478+++ linux-2.6.39.1/net/netfilter/ipvs/ip_vs_sync.c 2011-05-22 19:36:34.000000000 -0400
77479@@ -648,7 +648,7 @@ control:
77480 * i.e only increment in_pkts for Templates.
77481 */
77482 if (cp->flags & IP_VS_CONN_F_TEMPLATE) {
77483- int pkts = atomic_add_return(1, &cp->in_pkts);
77484+ int pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
77485
77486 if (pkts % sysctl_sync_period(ipvs) != 1)
77487 return;
77488@@ -794,7 +794,7 @@ static void ip_vs_proc_conn(struct net *
77489
77490 if (opt)
77491 memcpy(&cp->in_seq, opt, sizeof(*opt));
77492- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
77493+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
77494 cp->state = state;
77495 cp->old_state = cp->state;
77496 /*
77497diff -urNp linux-2.6.39.1/net/netfilter/ipvs/ip_vs_xmit.c linux-2.6.39.1/net/netfilter/ipvs/ip_vs_xmit.c
77498--- linux-2.6.39.1/net/netfilter/ipvs/ip_vs_xmit.c 2011-05-19 00:06:34.000000000 -0400
77499+++ linux-2.6.39.1/net/netfilter/ipvs/ip_vs_xmit.c 2011-05-22 19:36:34.000000000 -0400
77500@@ -1127,7 +1127,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, str
77501 else
77502 rc = NF_ACCEPT;
77503 /* do not touch skb anymore */
77504- atomic_inc(&cp->in_pkts);
77505+ atomic_inc_unchecked(&cp->in_pkts);
77506 goto out;
77507 }
77508
77509@@ -1245,7 +1245,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb,
77510 else
77511 rc = NF_ACCEPT;
77512 /* do not touch skb anymore */
77513- atomic_inc(&cp->in_pkts);
77514+ atomic_inc_unchecked(&cp->in_pkts);
77515 goto out;
77516 }
77517
77518diff -urNp linux-2.6.39.1/net/netfilter/Kconfig linux-2.6.39.1/net/netfilter/Kconfig
77519--- linux-2.6.39.1/net/netfilter/Kconfig 2011-05-19 00:06:34.000000000 -0400
77520+++ linux-2.6.39.1/net/netfilter/Kconfig 2011-05-22 19:41:42.000000000 -0400
77521@@ -781,6 +781,16 @@ config NETFILTER_XT_MATCH_ESP
77522
77523 To compile it as a module, choose M here. If unsure, say N.
77524
77525+config NETFILTER_XT_MATCH_GRADM
77526+ tristate '"gradm" match support'
77527+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
77528+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
77529+ ---help---
77530+ The gradm match allows to match on grsecurity RBAC being enabled.
77531+ It is useful when iptables rules are applied early on bootup to
77532+ prevent connections to the machine (except from a trusted host)
77533+ while the RBAC system is disabled.
77534+
77535 config NETFILTER_XT_MATCH_HASHLIMIT
77536 tristate '"hashlimit" match support'
77537 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
77538diff -urNp linux-2.6.39.1/net/netfilter/Makefile linux-2.6.39.1/net/netfilter/Makefile
77539--- linux-2.6.39.1/net/netfilter/Makefile 2011-05-19 00:06:34.000000000 -0400
77540+++ linux-2.6.39.1/net/netfilter/Makefile 2011-05-22 20:40:16.000000000 -0400
77541@@ -81,6 +81,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DCCP) +=
77542 obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
77543 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
77544 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
77545+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
77546 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
77547 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
77548 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
77549diff -urNp linux-2.6.39.1/net/netfilter/nfnetlink_log.c linux-2.6.39.1/net/netfilter/nfnetlink_log.c
77550--- linux-2.6.39.1/net/netfilter/nfnetlink_log.c 2011-05-19 00:06:34.000000000 -0400
77551+++ linux-2.6.39.1/net/netfilter/nfnetlink_log.c 2011-05-22 19:36:35.000000000 -0400
77552@@ -70,7 +70,7 @@ struct nfulnl_instance {
77553 };
77554
77555 static DEFINE_SPINLOCK(instances_lock);
77556-static atomic_t global_seq;
77557+static atomic_unchecked_t global_seq;
77558
77559 #define INSTANCE_BUCKETS 16
77560 static struct hlist_head instance_table[INSTANCE_BUCKETS];
77561@@ -506,7 +506,7 @@ __build_packet_message(struct nfulnl_ins
77562 /* global sequence number */
77563 if (inst->flags & NFULNL_CFG_F_SEQ_GLOBAL)
77564 NLA_PUT_BE32(inst->skb, NFULA_SEQ_GLOBAL,
77565- htonl(atomic_inc_return(&global_seq)));
77566+ htonl(atomic_inc_return_unchecked(&global_seq)));
77567
77568 if (data_len) {
77569 struct nlattr *nla;
77570diff -urNp linux-2.6.39.1/net/netfilter/nfnetlink_queue.c linux-2.6.39.1/net/netfilter/nfnetlink_queue.c
77571--- linux-2.6.39.1/net/netfilter/nfnetlink_queue.c 2011-05-19 00:06:34.000000000 -0400
77572+++ linux-2.6.39.1/net/netfilter/nfnetlink_queue.c 2011-05-22 19:36:35.000000000 -0400
77573@@ -58,7 +58,7 @@ struct nfqnl_instance {
77574 */
77575 spinlock_t lock;
77576 unsigned int queue_total;
77577- atomic_t id_sequence; /* 'sequence' of pkt ids */
77578+ atomic_unchecked_t id_sequence; /* 'sequence' of pkt ids */
77579 struct list_head queue_list; /* packets in queue */
77580 };
77581
77582@@ -272,7 +272,7 @@ nfqnl_build_packet_message(struct nfqnl_
77583 nfmsg->version = NFNETLINK_V0;
77584 nfmsg->res_id = htons(queue->queue_num);
77585
77586- entry->id = atomic_inc_return(&queue->id_sequence);
77587+ entry->id = atomic_inc_return_unchecked(&queue->id_sequence);
77588 pmsg.packet_id = htonl(entry->id);
77589 pmsg.hw_protocol = entskb->protocol;
77590 pmsg.hook = entry->hook;
77591@@ -869,7 +869,7 @@ static int seq_show(struct seq_file *s,
77592 inst->peer_pid, inst->queue_total,
77593 inst->copy_mode, inst->copy_range,
77594 inst->queue_dropped, inst->queue_user_dropped,
77595- atomic_read(&inst->id_sequence), 1);
77596+ atomic_read_unchecked(&inst->id_sequence), 1);
77597 }
77598
77599 static const struct seq_operations nfqnl_seq_ops = {
77600diff -urNp linux-2.6.39.1/net/netfilter/xt_gradm.c linux-2.6.39.1/net/netfilter/xt_gradm.c
77601--- linux-2.6.39.1/net/netfilter/xt_gradm.c 1969-12-31 19:00:00.000000000 -0500
77602+++ linux-2.6.39.1/net/netfilter/xt_gradm.c 2011-05-22 19:41:42.000000000 -0400
77603@@ -0,0 +1,51 @@
77604+/*
77605+ * gradm match for netfilter
77606